return s;
}
+ // ------ row and col sizes
void SetDefaultRowSize( int height, bool resizeExistingRows = false );
void SetRowSize( int row, int height );
- void SetDefaultColSize( int width, bool resizeExistingCols = false );
+ void HideRow(int row) { SetRowSize(row, 0); }
+ void ShowRow(int row) { SetRowSize(row, -1); }
+ void SetDefaultColSize( int width, bool resizeExistingCols = false );
void SetColSize( int col, int width );
+ void HideCol(int col) { SetColSize(col, 0); }
+ void ShowCol(int col) { SetColSize(col, -1); }
+
+
+ // ------- columns (only, for now) reordering
// columns index <-> positions mapping: by default, the position of the
// column is the same as its index, but the columns can also be reordered
return wxNOT_FOUND;
}
+ // reset the columns positions to the default order
+ void ResetColPos();
// automatically size the column or row to fit to its contents, if
// the sorting indicator to effectively show
void UpdateColumnSortingIndicator(int col);
+ // update column right positions after their order changed (does nothing if
+ // we only use the default widths as in this case m_colRights is not used
+ // neither)
+ void UpdateColumnRights();
+
// return the position (not index) of the column at the given logical pixel
// position
/**
Sets the width of the specified column.
- Notice that this function does not refresh the grid, you need to call
- ForceRefresh() to make the changes take effect immediately.
-
@param col
The column index.
@param width
- The new column width in pixels or a negative value to fit the
- column width to its label width.
+ The new column width in pixels, 0 to hide the column or -1 to fit
+ the column width to its label width.
*/
void SetColSize(int col, int width);
+ /**
+ Hides the specified column.
+
+ To show the column later you need to call SetColSize() with non-0
+ width or ShowCol().
+
+ @param col
+ The column index.
+ */
+ void HideCol(int col);
+
+ /**
+ Shows the previously hidden column by resizing it to non-0 size.
+
+ @see HideCol(), SetColSize()
+ */
+ void ShowCol(int col);
+
+
/**
Sets the default width for columns in the grid.
*/
void SetRowSize(int row, int height);
+ /**
+ Hides the specified row.
+
+ To show the row later you need to call SetRowSize() with non-0
+ width or ShowRow().
+
+ @param col
+ The row index.
+ */
+ void HideRow(int col);
+
+ /**
+ Shows the previously hidden row by resizing it to non-0 size.
+
+ @see HideRow(), SetRowSize()
+ */
+ void ShowRow(int col);
+
//@}
*/
void SetColPos(int colID, int newPos);
+ /**
+ Resets the position of the columns to the default.
+ */
+ void ResetColPos();
+
//@}
m_grid->EnableDragColMove(m_chkEnableColMove->IsChecked());
}
+ void OnShowHideColumn(wxCommandEvent& event)
+ {
+ int col = m_txtColShowHide->GetCol();
+ if ( col != -1 )
+ m_grid->SetColSize(col, event.GetId() == wxID_ADD ? -1 : 0);
+ }
+
void OnMoveColumn(wxCommandEvent&)
{
int col = m_txtColIndex->GetCol();
*m_chkEnableColMove;
ColIndexEntry *m_txtColIndex,
- *m_txtColPos;
+ *m_txtColPos,
+ *m_txtColShowHide;
wxStaticText *m_statOrder;
TabularGridFrame::OnUpdateDrawNativeLabelsUI)
EVT_BUTTON(wxID_APPLY, TabularGridFrame::OnMoveColumn)
+ EVT_BUTTON(wxID_ADD, TabularGridFrame::OnShowHideColumn)
+ EVT_BUTTON(wxID_DELETE, TabularGridFrame::OnShowHideColumn)
EVT_GRID_COL_SORT(TabularGridFrame::OnGridColSort)
EVT_GRID_COL_MOVE(TabularGridFrame::OnGridColMove)
sizerShowCols->Add(m_statOrder, flagsHorz);
sizerColumns->Add(sizerShowCols, wxSizerFlags().Expand().Border(wxTOP));
+ wxSizer * const sizerShowHide = new wxBoxSizer(wxHORIZONTAL);
+ sizerShowHide->Add(new wxStaticText(panel, wxID_ANY, "Show/hide column:"),
+ flagsHorz);
+ m_txtColShowHide = new ColIndexEntry(panel);
+ sizerShowHide->Add(m_txtColShowHide, flagsHorz);
+ sizerShowHide->Add(new wxButton(panel, wxID_ADD, "&Show"), flagsHorz);
+ sizerShowHide->Add(new wxButton(panel, wxID_DELETE, "&Hide"), flagsHorz);
+ sizerColumns->Add(sizerShowHide, wxSizerFlags().Expand().Border(wxTOP));
+
sizerControls->Add(sizerColumns, wxSizerFlags(1).Expand().Border());
sizerTop->Add(sizerControls, wxSizerFlags().Expand().Border());
virtual int GetFlags() const
{
- int flags = 0;
+ // we can't know in advance whether we can sort by this column or not
+ // with wxGrid API so suppose we can by default
+ int flags = wxCOL_SORTABLE;
if ( m_grid->CanDragColSize() )
flags |= wxCOL_RESIZABLE;
if ( m_grid->CanDragColMove() )
flags |= wxCOL_REORDERABLE;
+ if ( GetWidth() == 0 )
+ flags |= wxCOL_HIDDEN;
return flags;
}
// cell it might want to save that stuff to might no longer exist.
HideCellEditControl();
-#if 0
- // if we were using the default widths/heights so far, we must change them
- // now
- if ( m_colWidths.IsEmpty() )
- {
- InitColWidths();
- }
-
- if ( m_rowHeights.IsEmpty() )
- {
- InitRowHeights();
- }
-#endif
-
switch ( msg.GetId() )
{
case wxGRIDTABLE_NOTIFY_ROWS_INSERTED:
m_dragRowOrCol = -1;
}
+void wxGrid::UpdateColumnRights()
+{
+ if ( m_colWidths.empty() )
+ return;
+
+ int colRight = 0;
+ for ( int colPos = 0; colPos < m_numCols; colPos++ )
+ {
+ int colID = GetColAt( colPos );
+
+ colRight += m_colWidths[colID];
+ m_colRights[colID] = colRight;
+ }
+}
+
void wxGrid::SetColPos(int idx, int pos)
{
// we're going to need m_colAt now, initialize it if needed
wxHeaderCtrl::MoveColumnInOrderArray(m_colAt, idx, pos);
- // also recalculate the column rights
- if ( !m_colWidths.IsEmpty() )
- {
- int colRight = 0;
- int colPos;
- for ( colPos = 0; colPos < m_numCols; colPos++ )
- {
- int colID = GetColAt( colPos );
-
- colRight += m_colWidths[colID];
- m_colRights[colID] = colRight;
- }
- }
+ // also recalculate the column rights as the column positions have changed
+ UpdateColumnRights();
// and make the changes visible
if ( m_useNativeHeader )
m_gridWin->Refresh();
}
-
+void wxGrid::ResetColPos()
+{
+ m_colAt.clear();
+}
void wxGrid::EnableDragColMove( bool enable )
{
if ( m_canDragColMove == enable )
return;
- m_canDragColMove = enable;
-
- if ( !m_canDragColMove )
+ if ( m_useNativeHeader )
{
- m_colAt.Clear();
+ // update all columns to make them [not] reorderable
+ GetColHeader()->SetColumnCount(m_numCols);
+ }
- //Recalculate the column rights
- if ( !m_colWidths.IsEmpty() )
- {
- int colRight = 0;
- int colPos;
- for ( colPos = 0; colPos < m_numCols; colPos++ )
- {
- colRight += m_colWidths[colPos];
- m_colRights[colPos] = colRight;
- }
- }
+ m_canDragColMove = enable;
- m_colWindow->Refresh();
- m_gridWin->Refresh();
- }
+ // we use to call ResetColPos() from here if !enable but this doesn't seem
+ // right as it would mean there would be no way to "freeze" the current
+ // columns order by disabling moving them after putting them in the desired
+ // order, whereas now you can always call ResetColPos() manually if needed
}
// we intentionally don't test whether the width is less than
// GetColMinimalWidth() here but we do compare it with
// GetColMinimalAcceptableWidth() as otherwise things currently break (see
- // #651)
- if ( width < GetColMinimalAcceptableWidth() )
+ // #651) -- and we also always allow the width of 0 as it has the special
+ // sense of hiding the column
+ if ( width > 0 && width < GetColMinimalAcceptableWidth() )
return;
if ( m_colWidths.IsEmpty() )
InitColWidths();
}
- int w = wxMax( 0, width );
- int diff = w - m_colWidths[col];
- m_colWidths[col] = w;
+ const int diff = width - m_colWidths[col];
+ m_colWidths[col] = width;
+ if ( m_useNativeHeader )
+ GetColHeader()->UpdateColumn(col);
+ //else: will be refreshed when the header is redrawn
for ( int colPos = GetColPos(col); colPos < m_numCols; colPos++ )
{