X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/275c4ae474731bc5d77168b7615828a72a63dd5e..050c9e3c90c58b05d5b3f7384d1556ca9669f13e:/src/generic/grid.cpp diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 4581b3cf38..e2b9e35807 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -2020,7 +2020,7 @@ wxGridCellRenderer* wxGridCellAttr::GetRenderer(wxGrid* grid, int row, int col) { wxGridCellRenderer* renderer = NULL; - if ( m_defGridAttr != this || grid == NULL ) + if ( m_defGridAttr == this || grid == NULL ) { renderer = m_renderer; // use local attribute if ( renderer ) @@ -2088,6 +2088,9 @@ void wxGridCellAttrData::SetAttr(wxGridCellAttr *attr, int row, int col) } else { + // free the old attribute + m_attrs[(size_t)n].attr->DecRef(); + if ( attr ) { // change the attribute @@ -3607,6 +3610,8 @@ void wxGrid::Create() wxDefaultSize ); SetTargetWindow( m_gridWin ); + + Init(); } @@ -3624,7 +3629,9 @@ bool wxGrid::CreateGrid( int numRows, int numCols, m_table->SetView( this ); m_ownTable = TRUE; m_selection = new wxGridSelection( this, selmode ); - Init(); + + CalcDimensions(); + m_created = TRUE; return m_created; @@ -3632,12 +3639,10 @@ bool wxGrid::CreateGrid( int numRows, int numCols, void wxGrid::SetSelectionMode(wxGrid::wxGridSelectionModes selmode) { - if ( !m_created ) - { - wxFAIL_MSG( wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") ); - } - else - m_selection->SetSelectionMode( selmode ); + wxCHECK_RET( m_created, + wxT("Called wxGrid::SetSelectionMode() before calling CreateGrid()") ); + + m_selection->SetSelectionMode( selmode ); } bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, @@ -3664,7 +3669,9 @@ bool wxGrid::SetTable( wxGridTableBase *table, bool takeOwnership, if (takeOwnership) m_ownTable = TRUE; m_selection = new wxGridSelection( this, selmode ); - Init(); + + CalcDimensions(); + m_created = TRUE; } @@ -3746,8 +3753,6 @@ void wxGrid::Init() m_extraWidth = m_extraHeight = 50; - - CalcDimensions(); } // ---------------------------------------------------------------------------- @@ -5449,11 +5454,14 @@ bool wxGrid::DeleteCols( int pos, int numCols, bool WXUNUSED(updateLabels) ) // Generate a grid event based on a mouse event and // return the result of ProcessEvent() // -bool wxGrid::SendEvent( const wxEventType type, +int wxGrid::SendEvent( const wxEventType type, int row, int col, 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); @@ -5467,9 +5475,12 @@ bool wxGrid::SendEvent( const wxEventType type, mouseEv.ShiftDown(), mouseEv.AltDown(), 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! wxGridRangeSelectEvent gridEvt( GetId(), @@ -5483,9 +5494,11 @@ bool wxGrid::SendEvent( const wxEventType type, mouseEv.AltDown(), mouseEv.MetaDown() ); - return GetEventHandler()->ProcessEvent(gridEvt); + claimed = GetEventHandler()->ProcessEvent(gridEvt); + vetoed = !gridEvt.IsAllowed(); + } - else + else { wxGridEvent gridEvt( GetId(), type, @@ -5498,17 +5511,27 @@ bool wxGrid::SendEvent( const wxEventType type, mouseEv.ShiftDown(), mouseEv.AltDown(), 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 // of ProcessEvent(). // -bool wxGrid::SendEvent( const wxEventType type, +int wxGrid::SendEvent( const wxEventType type, int row, int col ) { + bool claimed; + bool vetoed= FALSE; + if ( type == wxEVT_GRID_ROW_SIZE || type == wxEVT_GRID_COL_SIZE ) { int rowOrCol = (row == -1 ? col : row); @@ -5518,7 +5541,8 @@ bool wxGrid::SendEvent( const wxEventType type, this, rowOrCol ); - return GetEventHandler()->ProcessEvent(gridEvt); + claimed = GetEventHandler()->ProcessEvent(gridEvt); + vetoed = !gridEvt.IsAllowed(); } else { @@ -5527,8 +5551,14 @@ bool wxGrid::SendEvent( const wxEventType type, this, 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 +6608,12 @@ void wxGrid::EnableCellEditControl( bool enable ) if ( enable != m_cellEditCtrlEnabled ) { - // TODO allow the app to Veto() this event? - SendEvent(enable ? wxEVT_GRID_EDITOR_SHOWN : wxEVT_GRID_EDITOR_HIDDEN); - 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(), _T("can't enable editing for this cell!") ); @@ -6594,7 +6624,10 @@ void wxGrid::EnableCellEditControl( bool enable ) } else { - HideCellEditControl(); + //FIXME:add veto support + SendEvent( wxEVT_GRID_EDITOR_HIDDEN); + + HideCellEditControl(); SaveEditControlValue(); // do it after HideCellEditControl() @@ -6740,6 +6773,8 @@ void wxGrid::SaveEditControlValue() int row = m_currentCellCoords.GetRow(); int col = m_currentCellCoords.GetCol(); + wxString oldval = GetCellValue(row,col); + wxGridCellAttr* attr = GetCellAttr(row, col); wxGridCellEditor* editor = attr->GetEditor(this, row, col); bool changed = editor->EndEdit(row, col, this); @@ -6749,9 +6784,13 @@ void wxGrid::SaveEditControlValue() if (changed) { - SendEvent( wxEVT_GRID_CELL_CHANGE, + if ( SendEvent( wxEVT_GRID_CELL_CHANGE, m_currentCellCoords.GetRow(), - m_currentCellCoords.GetCol() ); + m_currentCellCoords.GetCol() ) < 0 ) { + + //Event has been veto set the data back. + SetCellValue(row,col,oldval); + } } } }