support for vetoing grid cell editing (patch 469049)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12270 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -48,6 +48,7 @@ All (GUI):
|
|||||||
- new wxCalendarCtrl styles added (S<>ren Erland Vest<73>)
|
- new wxCalendarCtrl styles added (S<>ren Erland Vest<73>)
|
||||||
- wxWizard changes: loading from WXR support, help button (Robert Cavanaugh)
|
- wxWizard changes: loading from WXR support, help button (Robert Cavanaugh)
|
||||||
- wxDirSelector() added (Paul A. Thiessen)
|
- wxDirSelector() added (Paul A. Thiessen)
|
||||||
|
- wxGrid cell editing veto support (Roger Gammans)
|
||||||
|
|
||||||
wxHTML:
|
wxHTML:
|
||||||
|
|
||||||
|
@@ -1775,9 +1775,9 @@ protected:
|
|||||||
bool Redimension( wxGridTableMessage& );
|
bool Redimension( wxGridTableMessage& );
|
||||||
|
|
||||||
|
|
||||||
bool SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
|
int SendEvent( const wxEventType, int row, int col, wxMouseEvent& );
|
||||||
bool SendEvent( const wxEventType, int row, int col );
|
int SendEvent( const wxEventType, int row, int col );
|
||||||
bool SendEvent( const wxEventType type)
|
int SendEvent( const wxEventType type)
|
||||||
{
|
{
|
||||||
return SendEvent(type,
|
return SendEvent(type,
|
||||||
m_currentCellCoords.GetRow(),
|
m_currentCellCoords.GetRow(),
|
||||||
|
@@ -249,6 +249,8 @@ GridFrame::GridFrame()
|
|||||||
grid->SetCellValue( 0, 2, "Blah" );
|
grid->SetCellValue( 0, 2, "Blah" );
|
||||||
grid->SetCellValue( 0, 3, "Read only" );
|
grid->SetCellValue( 0, 3, "Read only" );
|
||||||
grid->SetReadOnly( 0, 3 );
|
grid->SetReadOnly( 0, 3 );
|
||||||
|
|
||||||
|
grid->SetCellValue( 0, 4, "Can veto edit this cell" );
|
||||||
|
|
||||||
grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
|
grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
|
||||||
|
|
||||||
@@ -808,6 +810,17 @@ void GridFrame::OnCellValueChanged( wxGridEvent& ev )
|
|||||||
|
|
||||||
void GridFrame::OnEditorShown( wxGridEvent& ev )
|
void GridFrame::OnEditorShown( wxGridEvent& ev )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ( (ev.GetCol() == 4) &&
|
||||||
|
(ev.GetRow() == 0) &&
|
||||||
|
(wxMessageBox(_T("Are you sure you wish to edit this cell"),
|
||||||
|
_T("Checking"),wxYES_NO) == wxNO ) ) {
|
||||||
|
|
||||||
|
ev.Veto();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
wxLogMessage( wxT("Cell editor shown.") );
|
wxLogMessage( wxT("Cell editor shown.") );
|
||||||
|
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
@@ -815,6 +828,16 @@ void GridFrame::OnEditorShown( wxGridEvent& ev )
|
|||||||
|
|
||||||
void GridFrame::OnEditorHidden( wxGridEvent& ev )
|
void GridFrame::OnEditorHidden( wxGridEvent& ev )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if ( (ev.GetCol() == 4) &&
|
||||||
|
(ev.GetRow() == 0) &&
|
||||||
|
(wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
|
||||||
|
_T("Checking"),wxYES_NO) == wxNO ) ) {
|
||||||
|
|
||||||
|
ev.Veto();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wxLogMessage( wxT("Cell editor hidden.") );
|
wxLogMessage( wxT("Cell editor hidden.") );
|
||||||
|
|
||||||
ev.Skip();
|
ev.Skip();
|
||||||
|
@@ -5449,11 +5449,14 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) )
|
|||||||
// Generate a grid event based on a mouse event and
|
// Generate a grid event based on a mouse event and
|
||||||
// return the result of ProcessEvent()
|
// return the result of ProcessEvent()
|
||||||
//
|
//
|
||||||
bool wxGrid::SendEvent( const wxEventType type,
|
int wxGrid::SendEvent( const wxEventType type,
|
||||||
int row, int col,
|
int row, int col,
|
||||||
wxMouseEvent& mouseEv )
|
wxMouseEvent& mouseEv )
|
||||||
{
|
{
|
||||||
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
bool claimed;
|
||||||
|
bool vetoed= false;
|
||||||
|
|
||||||
|
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
||||||
{
|
{
|
||||||
int rowOrCol = (row == -1 ? col : row);
|
int rowOrCol = (row == -1 ? col : row);
|
||||||
|
|
||||||
@@ -5467,9 +5470,12 @@ bool wxGrid::SendEvent( const wxEventType type,
|
|||||||
mouseEv.ShiftDown(),
|
mouseEv.ShiftDown(),
|
||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
return GetEventHandler()->ProcessEvent(gridEvt);
|
|
||||||
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
|
vetoed = !gridEvt.IsAllowed();
|
||||||
|
|
||||||
}
|
}
|
||||||
else if ( type == wxEVT_GRID_RANGE_SELECT )
|
else if ( type == wxEVT_GRID_RANGE_SELECT )
|
||||||
{
|
{
|
||||||
// Right now, it should _never_ end up here!
|
// Right now, it should _never_ end up here!
|
||||||
wxGridRangeSelectEvent gridEvt( GetId(),
|
wxGridRangeSelectEvent gridEvt( GetId(),
|
||||||
@@ -5483,9 +5489,11 @@ bool wxGrid::SendEvent( const wxEventType type,
|
|||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
|
|
||||||
return GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
|
vetoed = !gridEvt.IsAllowed();
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxGridEvent gridEvt( GetId(),
|
wxGridEvent gridEvt( GetId(),
|
||||||
type,
|
type,
|
||||||
@@ -5498,17 +5506,27 @@ bool wxGrid::SendEvent( const wxEventType type,
|
|||||||
mouseEv.ShiftDown(),
|
mouseEv.ShiftDown(),
|
||||||
mouseEv.AltDown(),
|
mouseEv.AltDown(),
|
||||||
mouseEv.MetaDown() );
|
mouseEv.MetaDown() );
|
||||||
return GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
|
vetoed = !gridEvt.IsAllowed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A Veto'd event may not be `claimed' so test this first
|
||||||
|
if (vetoed) return -1;
|
||||||
|
return claimed ? 1 : 0;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Generate a grid event of specified type and return the result
|
// Generate a grid event of specified type and return the result
|
||||||
// of ProcessEvent().
|
// of ProcessEvent().
|
||||||
//
|
//
|
||||||
bool wxGrid::SendEvent( const wxEventType type,
|
int wxGrid::SendEvent( const wxEventType type,
|
||||||
int row, int col )
|
int row, int col )
|
||||||
{
|
{
|
||||||
|
bool claimed;
|
||||||
|
bool vetoed= false;
|
||||||
|
|
||||||
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE )
|
||||||
{
|
{
|
||||||
int rowOrCol = (row == -1 ? col : row);
|
int rowOrCol = (row == -1 ? col : row);
|
||||||
@@ -5518,7 +5536,8 @@ bool wxGrid::SendEvent( const wxEventType type,
|
|||||||
this,
|
this,
|
||||||
rowOrCol );
|
rowOrCol );
|
||||||
|
|
||||||
return GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
|
vetoed = !gridEvt.IsAllowed();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -5527,8 +5546,14 @@ bool wxGrid::SendEvent( const wxEventType type,
|
|||||||
this,
|
this,
|
||||||
row, col );
|
row, col );
|
||||||
|
|
||||||
return GetEventHandler()->ProcessEvent(gridEvt);
|
claimed = GetEventHandler()->ProcessEvent(gridEvt);
|
||||||
}
|
vetoed = !gridEvt.IsAllowed();
|
||||||
|
}
|
||||||
|
|
||||||
|
// A Veto'd event may not be `claimed' so test this first
|
||||||
|
if (vetoed) return -1;
|
||||||
|
return claimed ? 1 : 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -6578,12 +6603,12 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
|
|
||||||
if ( enable != m_cellEditCtrlEnabled )
|
if ( enable != m_cellEditCtrlEnabled )
|
||||||
{
|
{
|
||||||
// TODO allow the app to Veto() this event?
|
|
||||||
SendEvent(enable ? wxEVT_GRID_EDITOR_SHOWN : wxEVT_GRID_EDITOR_HIDDEN);
|
|
||||||
|
|
||||||
if ( enable )
|
if ( enable )
|
||||||
{
|
{
|
||||||
// this should be checked by the caller!
|
if (SendEvent( wxEVT_GRID_EDITOR_SHOWN) <0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// this should be checked by the caller!
|
||||||
wxASSERT_MSG( CanEnableCellControl(),
|
wxASSERT_MSG( CanEnableCellControl(),
|
||||||
_T("can't enable editing for this cell!") );
|
_T("can't enable editing for this cell!") );
|
||||||
|
|
||||||
@@ -6594,7 +6619,10 @@ void wxGrid::EnableCellEditControl( bool enable )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HideCellEditControl();
|
//FIXME:add veto support
|
||||||
|
SendEvent( wxEVT_GRID_EDITOR_HIDDEN);
|
||||||
|
|
||||||
|
HideCellEditControl();
|
||||||
SaveEditControlValue();
|
SaveEditControlValue();
|
||||||
|
|
||||||
// do it after HideCellEditControl()
|
// do it after HideCellEditControl()
|
||||||
@@ -6740,6 +6768,8 @@ void wxGrid::SaveEditControlValue()
|
|||||||
int row = m_currentCellCoords.GetRow();
|
int row = m_currentCellCoords.GetRow();
|
||||||
int col = m_currentCellCoords.GetCol();
|
int col = m_currentCellCoords.GetCol();
|
||||||
|
|
||||||
|
wxString oldval = GetCellValue(row,col);
|
||||||
|
|
||||||
wxGridCellAttr* attr = GetCellAttr(row, col);
|
wxGridCellAttr* attr = GetCellAttr(row, col);
|
||||||
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
wxGridCellEditor* editor = attr->GetEditor(this, row, col);
|
||||||
bool changed = editor->EndEdit(row, col, this);
|
bool changed = editor->EndEdit(row, col, this);
|
||||||
@@ -6749,9 +6779,13 @@ void wxGrid::SaveEditControlValue()
|
|||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
SendEvent( wxEVT_GRID_CELL_CHANGE,
|
if ( SendEvent( wxEVT_GRID_CELL_CHANGE,
|
||||||
m_currentCellCoords.GetRow(),
|
m_currentCellCoords.GetRow(),
|
||||||
m_currentCellCoords.GetCol() );
|
m_currentCellCoords.GetCol() ) < 0 ) {
|
||||||
|
|
||||||
|
//Event has been veto set the data back.
|
||||||
|
SetCellValue(row,col,oldval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user