X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/da5a641fc8a83c8b00ac157004f47e93dd08dcc8..4a745e76b15b375c5600aefdb005f39c3f0d73b6:/src/generic/grid.cpp?ds=sidebyside diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index c516ec9072..1b1ed6c604 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -224,12 +224,13 @@ public: wxID_ANY, wxDefaultPosition, wxDefaultSize, - owner->CanDragColMove() ? wxHD_DRAGDROP : 0) + wxHD_ALLOW_HIDE | + (owner->CanDragColMove() ? wxHD_ALLOW_REORDER : 0)) { } protected: - virtual wxHeaderColumn& GetColumn(unsigned int idx) + virtual const wxHeaderColumn& GetColumn(unsigned int idx) const { return m_columns[idx]; } @@ -267,6 +268,23 @@ private: return true; } + // overridden to react to the actions using the columns popup menu + virtual void UpdateColumnVisibility(unsigned int idx, bool show) + { + GetOwner()->SetColSize(idx, show ? wxGRID_AUTOSIZE : 0); + + // as this is done by the user we should notify the main program about + // it + GetOwner()->SendEvent(wxEVT_GRID_COL_SIZE, -1, idx); + } + + // overridden to react to the columns order changes in the customization + // dialog + virtual void UpdateColumnsOrder(const wxArrayInt& order) + { + GetOwner()->SetColumnsOrder(order); + } + // event handlers forwarding wxHeaderCtrl events to wxGrid void OnClick(wxHeaderCtrlEvent& event) @@ -4806,7 +4824,7 @@ wxGrid::SetTable(wxGridTableBase *table, m_numCols = table->GetNumberCols(); if ( m_useNativeHeader ) - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); m_table = table; m_table->SetView( this ); @@ -5279,7 +5297,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) m_numCols += numCols; if ( m_useNativeHeader ) - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); if ( !m_colAt.IsEmpty() ) { @@ -5347,7 +5365,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int oldNumCols = m_numCols; m_numCols += numCols; if ( m_useNativeHeader ) - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); if ( !m_colAt.IsEmpty() ) { @@ -5402,7 +5420,7 @@ bool wxGrid::Redimension( wxGridTableMessage& msg ) int numCols = msg.GetCommandInt2(); m_numCols -= numCols; if ( m_useNativeHeader ) - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); if ( !m_colAt.IsEmpty() ) { @@ -5863,7 +5881,7 @@ void wxGrid::UpdateColumnSortingIndicator(int col) wxCHECK_RET( col != wxNOT_FOUND, "invalid column index" ); if ( m_useNativeHeader ) - GetColHeader()->UpdateColumn(col); + GetGridColHeader()->UpdateColumn(col); else if ( m_nativeColumnLabels ) m_colWindow->Refresh(); //else: sorting indicator display not yet implemented in grid version @@ -6842,19 +6860,43 @@ void wxGrid::DoEndMoveCol(int pos) m_dragRowOrCol = -1; } -void wxGrid::UpdateColumnRights() +void wxGrid::RefreshAfterColPosChange() { - if ( m_colWidths.empty() ) - return; - - int colRight = 0; - for ( int colPos = 0; colPos < m_numCols; colPos++ ) + // recalculate the column rights as the column positions have changed, + // unless we calculate them dynamically because all columns widths are the + // same and it's easy to do + if ( !m_colWidths.empty() ) { - int colID = GetColAt( colPos ); + int colRight = 0; + for ( int colPos = 0; colPos < m_numCols; colPos++ ) + { + int colID = GetColAt( colPos ); - colRight += m_colWidths[colID]; - m_colRights[colID] = colRight; + colRight += m_colWidths[colID]; + m_colRights[colID] = colRight; + } } + + // and make the changes visible + if ( m_useNativeHeader ) + { + if ( m_colAt.empty() ) + GetGridColHeader()->ResetColumnsOrder(); + else + GetGridColHeader()->SetColumnsOrder(m_colAt); + } + else + { + m_colWindow->Refresh(); + } + m_gridWin->Refresh(); +} + +void wxGrid::SetColumnsOrder(const wxArrayInt& order) +{ + m_colAt = order; + + RefreshAfterColPosChange(); } void wxGrid::SetColPos(int idx, int pos) @@ -6869,25 +6911,14 @@ void wxGrid::SetColPos(int idx, int pos) wxHeaderCtrl::MoveColumnInOrderArray(m_colAt, idx, pos); - // also recalculate the column rights as the column positions have changed - UpdateColumnRights(); - - // and make the changes visible - if ( m_useNativeHeader ) - GetColHeader()->SetColumnsOrder(m_colAt); - else - m_colWindow->Refresh(); - m_gridWin->Refresh(); + RefreshAfterColPosChange(); } void wxGrid::ResetColPos() { m_colAt.clear(); - if ( m_useNativeHeader ) - GetColHeader()->ResetColumnsOrder(); - else - m_colWindow->Refresh(); + RefreshAfterColPosChange(); } void wxGrid::EnableDragColMove( bool enable ) @@ -6898,7 +6929,7 @@ void wxGrid::EnableDragColMove( bool enable ) if ( m_useNativeHeader ) { // update all columns to make them [not] reorderable - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); } m_canDragColMove = enable; @@ -8183,7 +8214,7 @@ void wxGrid::UseNativeColHeader(bool native) CreateColumnWindow(); if ( m_useNativeHeader ) - GetColHeader()->SetColumnCount(m_numCols); + GetGridColHeader()->SetColumnCount(m_numCols); CalcWindowSizes(); } @@ -9567,7 +9598,7 @@ void wxGrid::SetColLabelValue( int col, const wxString& s ) { if ( m_useNativeHeader ) { - GetColHeader()->UpdateColumn(col); + GetGridColHeader()->UpdateColumn(col); } else { @@ -10408,7 +10439,7 @@ void wxGrid::SetColSize( int col, int width ) const int diff = width - m_colWidths[col]; m_colWidths[col] = width; if ( m_useNativeHeader ) - GetColHeader()->UpdateColumn(col); + GetGridColHeader()->UpdateColumn(col); //else: will be refreshed when the header is redrawn for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ ) @@ -10575,7 +10606,7 @@ wxGrid::AutoSizeColOrRow(int colOrRow, bool setAsMin, wxGridDirection direction) { if ( m_useNativeHeader ) { - GetColHeader()->UpdateColumn(col); + GetGridColHeader()->UpdateColumn(col); } else {