Add wxGrid::DoEnableCellEditControl() with bool return value
Checking the new function return value is simpler than checking the value of m_cellEditCtrlEnabled after calling EnableCellEditControl(). Do this now also when starting editing using the mouse, as it was simply forgotten before and so StartingClick() was still called even if editing was vetoed. Also add DoDisableCellEditControl(), but this one exists purely for the symmetry.
This commit is contained in:
@@ -2912,6 +2912,14 @@ private:
|
|||||||
void DoShowCellEditControl();
|
void DoShowCellEditControl();
|
||||||
void DoHideCellEditControl();
|
void DoHideCellEditControl();
|
||||||
|
|
||||||
|
// Unconditionally try showing the editor for the current cell.
|
||||||
|
//
|
||||||
|
// Returns false if the user code vetoed wxEVT_GRID_EDITOR_SHOWN.
|
||||||
|
bool DoEnableCellEditControl();
|
||||||
|
|
||||||
|
// Unconditionally disable (accepting the changes) the editor.
|
||||||
|
void DoDisableCellEditControl();
|
||||||
|
|
||||||
// Accept the changes in the edit control, i.e. save them to the table and
|
// Accept the changes in the edit control, i.e. save them to the table and
|
||||||
// dismiss the editor. Also reset m_cellEditCtrlEnabled.
|
// dismiss the editor. Also reset m_cellEditCtrlEnabled.
|
||||||
void DoAcceptCellEditControl();
|
void DoAcceptCellEditControl();
|
||||||
|
@@ -4657,8 +4657,8 @@ wxGrid::DoGridCellLeftUp(wxMouseEvent& event,
|
|||||||
if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl() )
|
if ( coords == m_currentCellCoords && m_waitForSlowClick && CanEnableCellControl() )
|
||||||
{
|
{
|
||||||
ClearSelection();
|
ClearSelection();
|
||||||
EnableCellEditControl();
|
|
||||||
|
|
||||||
|
if ( DoEnableCellEditControl() )
|
||||||
GetCurrentCellEditorPtr()->StartingClick();
|
GetCurrentCellEditorPtr()->StartingClick();
|
||||||
|
|
||||||
m_waitForSlowClick = false;
|
m_waitForSlowClick = false;
|
||||||
@@ -5968,18 +5968,14 @@ void wxGrid::OnChar( wxKeyEvent& event )
|
|||||||
|
|
||||||
// <F2> is special and will always start editing, for
|
// <F2> is special and will always start editing, for
|
||||||
// other keys - ask the editor itself
|
// other keys - ask the editor itself
|
||||||
if ( (event.GetKeyCode() == WXK_F2 && !event.HasModifiers())
|
const bool specialEditKey = event.GetKeyCode() == WXK_F2 &&
|
||||||
|| editor->IsAcceptedKey(event) )
|
!event.HasModifiers();
|
||||||
|
if ( specialEditKey || editor->IsAcceptedKey(event) )
|
||||||
{
|
{
|
||||||
// ensure cell is visble
|
// ensure cell is visble
|
||||||
MakeCellVisible(m_currentCellCoords);
|
MakeCellVisible(m_currentCellCoords);
|
||||||
EnableCellEditControl();
|
|
||||||
|
|
||||||
// a problem can arise if the cell is not completely
|
if ( DoEnableCellEditControl() && !specialEditKey )
|
||||||
// visible (even after calling MakeCellVisible the
|
|
||||||
// control is not created and calling StartingKey will
|
|
||||||
// crash the app
|
|
||||||
if ( event.GetKeyCode() != WXK_F2 && editor->IsCreated() && m_cellEditCtrlEnabled )
|
|
||||||
editor->StartingKey(event);
|
editor->StartingKey(event);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -7150,20 +7146,32 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
// this should be checked by the caller!
|
// this should be checked by the caller!
|
||||||
wxCHECK_RET( CanEnableCellControl(), wxT("can't enable editing for this cell!") );
|
wxCHECK_RET( CanEnableCellControl(), wxT("can't enable editing for this cell!") );
|
||||||
|
|
||||||
|
DoEnableCellEditControl();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DoDisableCellEditControl();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxGrid::DoEnableCellEditControl()
|
||||||
|
{
|
||||||
if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN) == -1 )
|
if ( SendEvent(wxEVT_GRID_EDITOR_SHOWN) == -1 )
|
||||||
return;
|
return false;
|
||||||
|
|
||||||
m_cellEditCtrlEnabled = true;
|
m_cellEditCtrlEnabled = true;
|
||||||
|
|
||||||
DoShowCellEditControl();
|
DoShowCellEditControl();
|
||||||
}
|
|
||||||
else
|
return true;
|
||||||
{
|
}
|
||||||
|
|
||||||
|
void wxGrid::DoDisableCellEditControl()
|
||||||
|
{
|
||||||
SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
|
SendEvent(wxEVT_GRID_EDITOR_HIDDEN);
|
||||||
|
|
||||||
DoAcceptCellEditControl();
|
DoAcceptCellEditControl();
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxGrid::IsCurrentCellReadOnly() const
|
bool wxGrid::IsCurrentCellReadOnly() const
|
||||||
|
Reference in New Issue
Block a user