Allow disabling hiding columns when using wxHeaderCtrl in wxGrid
Add wxGrid::DisableHidingColumns() method which can be used to prevent wxHeaderCtrl from allowing the user to hide columns interactively, which is something it allows to do by default, unlike the "built-in" wxGrid header. Also add EnableHidingColumns() and CanHideColumns() for consistency with the other similar methods. Closes https://github.com/wxWidgets/wxWidgets/pull/1554
This commit is contained in:
committed by
Vadim Zeitlin
parent
4302c6b8ba
commit
e26d90028b
@@ -1359,6 +1359,11 @@ public:
|
||||
void DisableDragColMove() { EnableDragColMove( false ); }
|
||||
bool CanDragColMove() const { return m_canDragColMove; }
|
||||
|
||||
// interactive column hiding (enabled by default, works only for native header)
|
||||
bool EnableHidingColumns( bool enable = true );
|
||||
void DisableHidingColumns() { EnableHidingColumns(false); }
|
||||
bool CanHideColumns() { return m_canHideColumns; }
|
||||
|
||||
// interactive resizing of grid cells (enabled by default)
|
||||
void EnableDragGridSize(bool enable = true);
|
||||
void DisableDragGridSize() { EnableDragGridSize(false); }
|
||||
@@ -2172,6 +2177,7 @@ protected:
|
||||
bool m_canDragRowSize;
|
||||
bool m_canDragColSize;
|
||||
bool m_canDragColMove;
|
||||
bool m_canHideColumns;
|
||||
bool m_canDragGridSize;
|
||||
bool m_canDragCell;
|
||||
|
||||
|
@@ -147,7 +147,7 @@ public:
|
||||
wxID_ANY,
|
||||
wxDefaultPosition,
|
||||
wxDefaultSize,
|
||||
wxHD_ALLOW_HIDE |
|
||||
(owner->CanHideColumns() ? wxHD_ALLOW_HIDE : 0) |
|
||||
(owner->CanDragColMove() ? wxHD_ALLOW_REORDER : 0))
|
||||
{
|
||||
}
|
||||
|
@@ -3707,6 +3707,13 @@ public:
|
||||
*/
|
||||
bool CanDragRowSize(int row) const;
|
||||
|
||||
/**
|
||||
Returns @true if columns can be hidden from the popup menu of the native header.
|
||||
|
||||
@since 3.1.3
|
||||
*/
|
||||
bool CanHideColumns() const;
|
||||
|
||||
/**
|
||||
Disable interactive resizing of the specified column.
|
||||
|
||||
@@ -3765,6 +3772,15 @@ public:
|
||||
*/
|
||||
void DisableDragRowSize();
|
||||
|
||||
/**
|
||||
Disables column hiding from the header popup menu.
|
||||
|
||||
Equivalent to passing @false to EnableHidingColumns().
|
||||
|
||||
@since 3.1.3
|
||||
*/
|
||||
void DisableHidingColumns();
|
||||
|
||||
/**
|
||||
Enables or disables cell dragging with the mouse.
|
||||
*/
|
||||
@@ -3801,6 +3817,28 @@ public:
|
||||
*/
|
||||
void EnableDragRowSize(bool enable = true);
|
||||
|
||||
/**
|
||||
Enables or disables column hiding from the header popup menu.
|
||||
|
||||
Note that currently the popup menu can only be shown when using
|
||||
wxHeaderCtrl, i.e. if UseNativeColHeader() had been called.
|
||||
|
||||
If the native header is not used, this method always simply returns
|
||||
@false without doing anything, as hiding columns is not supported
|
||||
anyhow. If @a enable value is the same as CanHideColumns(), it also
|
||||
returns @false to indicate that nothing was done. Otherwise, it returns
|
||||
@true to indicate that the value of this option was successfully
|
||||
changed.
|
||||
|
||||
The main use case for this method is to disallow hiding the columns
|
||||
interactively when using the native header.
|
||||
|
||||
@since 3.1.3
|
||||
|
||||
@see DisableHidingColumns()
|
||||
*/
|
||||
bool EnableHidingColumns(bool enable = true);
|
||||
|
||||
/**
|
||||
Returns the column ID of the specified column position.
|
||||
*/
|
||||
|
@@ -154,6 +154,7 @@ wxBEGIN_EVENT_TABLE( GridFrame, wxFrame )
|
||||
EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing )
|
||||
EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing )
|
||||
EVT_MENU( ID_TOGGLECOLMOVING, GridFrame::ToggleColMoving )
|
||||
EVT_MENU( ID_TOGGLECOLHIDING, GridFrame::ToggleColHiding )
|
||||
EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
|
||||
EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
|
||||
EVT_MENU( ID_COLNATIVEHEADER, GridFrame::SetNativeColHeader )
|
||||
@@ -298,6 +299,7 @@ GridFrame::GridFrame()
|
||||
viewMenu->AppendCheckItem(ID_TOGGLEROWSIZING, "Ro&w drag-resize");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLECOLSIZING, "C&ol drag-resize");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLECOLMOVING, "Col drag-&move");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLECOLHIDING, "Col hiding popup menu");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLEGRIDSIZING, "&Grid drag-resize");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL, "&Grid drag-cell");
|
||||
viewMenu->AppendCheckItem(ID_TOGGLEGRIDLINES, "&Grid Lines");
|
||||
@@ -634,6 +636,7 @@ void GridFrame::SetDefaults()
|
||||
GetMenuBar()->Check( ID_TOGGLEROWSIZING, true );
|
||||
GetMenuBar()->Check( ID_TOGGLECOLSIZING, true );
|
||||
GetMenuBar()->Check( ID_TOGGLECOLMOVING, false );
|
||||
GetMenuBar()->Check( ID_TOGGLECOLHIDING, true );
|
||||
GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
|
||||
GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
|
||||
GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
|
||||
@@ -693,6 +696,15 @@ void GridFrame::ToggleColMoving( wxCommandEvent& WXUNUSED(ev) )
|
||||
GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING ) );
|
||||
}
|
||||
|
||||
void GridFrame::ToggleColHiding( wxCommandEvent& WXUNUSED(ev) )
|
||||
{
|
||||
if ( !grid->EnableHidingColumns(
|
||||
GetMenuBar()->IsChecked( ID_TOGGLECOLHIDING ) ) )
|
||||
{
|
||||
GetMenuBar()->Check( ID_TOGGLECOLHIDING, grid->CanHideColumns() );
|
||||
}
|
||||
}
|
||||
|
||||
void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) )
|
||||
{
|
||||
grid->EnableDragGridSize(
|
||||
|
@@ -36,6 +36,7 @@ class GridFrame : public wxFrame
|
||||
void ToggleRowSizing( wxCommandEvent& );
|
||||
void ToggleColSizing( wxCommandEvent& );
|
||||
void ToggleColMoving( wxCommandEvent& );
|
||||
void ToggleColHiding( wxCommandEvent& );
|
||||
void ToggleGridSizing( wxCommandEvent& );
|
||||
void ToggleGridDragCell ( wxCommandEvent& );
|
||||
void SetNativeColHeader ( wxCommandEvent& );
|
||||
@@ -140,6 +141,7 @@ public:
|
||||
ID_TOGGLEROWSIZING,
|
||||
ID_TOGGLECOLSIZING,
|
||||
ID_TOGGLECOLMOVING,
|
||||
ID_TOGGLECOLHIDING,
|
||||
ID_TOGGLEGRIDSIZING,
|
||||
ID_TOGGLEGRIDDRAGCELL,
|
||||
ID_TOGGLEGRIDLINES,
|
||||
|
@@ -2607,6 +2607,7 @@ void wxGrid::Init()
|
||||
m_gridFrozenBorderPenWidth = 2;
|
||||
|
||||
m_canDragColMove = false;
|
||||
m_canHideColumns = true;
|
||||
|
||||
m_cursorMode = WXGRID_CURSOR_SELECT_CELL;
|
||||
m_winCapture = NULL;
|
||||
@@ -4829,6 +4830,18 @@ bool wxGrid::EnableDragColMove( bool enable )
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxGrid::EnableHidingColumns(bool enable)
|
||||
{
|
||||
if ( m_canHideColumns == enable || !m_useNativeHeader )
|
||||
return false;
|
||||
|
||||
GetGridColHeader()->ToggleWindowStyle(wxHD_ALLOW_HIDE);
|
||||
|
||||
m_canHideColumns = enable;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxGrid::InitializeFrozenWindows()
|
||||
{
|
||||
// frozen row windows
|
||||
|
Reference in New Issue
Block a user