added a helper function to show the popup menu allowing to configure the columns in header control
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57356 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
565382de29
commit
e8f25dbbce
@ -86,6 +86,10 @@ public:
|
||||
DoUpdate(idx);
|
||||
}
|
||||
|
||||
|
||||
// columns order
|
||||
// -------------
|
||||
|
||||
// set the columns order: the array defines the column index which appears
|
||||
// the given position, it must have GetColumnCount() elements and contain
|
||||
// all indices exactly once
|
||||
@ -110,6 +114,17 @@ public:
|
||||
unsigned int pos);
|
||||
|
||||
|
||||
// UI helpers
|
||||
// ----------
|
||||
|
||||
// show the popup menu containing all columns with check marks for the ones
|
||||
// which are currently shown -- this is meant to be called from
|
||||
// EVT_HEADER_RIGHT_CLICK handler and should toggle the visibility of the
|
||||
// n-th column if the function returns valid column index and not wxID_NONE
|
||||
// which is returned if the user cancels the menu
|
||||
int ShowColumnsMenu(const wxString& title = wxString());
|
||||
|
||||
|
||||
// implementation only from now on
|
||||
// -------------------------------
|
||||
|
||||
|
@ -296,6 +296,24 @@ public:
|
||||
unsigned int idx,
|
||||
unsigned int pos);
|
||||
|
||||
/**
|
||||
Show the popup menu allowing the user to show or hide the columns.
|
||||
|
||||
This functions shows the popup menu containing all columns with check
|
||||
marks for the ones which are currently shown at the current mouse
|
||||
position. It is meant to be called from EVT_HEADER_RIGHT_CLICK handler
|
||||
and should toggle the visibility of the n-th column if the function
|
||||
returns valid column index and not wxID_NONE which is returned if the
|
||||
user cancels the menu.
|
||||
|
||||
@param title
|
||||
The title for the menu if not empty.
|
||||
@return
|
||||
A valid column index or wxID_NONE if the user didn't select any
|
||||
column.
|
||||
*/
|
||||
int ShowColumnsMenu(const wxString& title = wxString());
|
||||
|
||||
protected:
|
||||
/**
|
||||
Method to be implemented by the derived classes to return the
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "wx/aboutdlg.h"
|
||||
|
||||
#include "wx/grid.h"
|
||||
#include "wx/headerctrl.h"
|
||||
#include "wx/generic/gridctrl.h"
|
||||
|
||||
#include "griddemo.h"
|
||||
@ -1797,6 +1798,20 @@ private:
|
||||
event.Skip();
|
||||
}
|
||||
|
||||
void OnColRightClick(wxHeaderCtrlEvent&)
|
||||
{
|
||||
int col = m_grid->GetGridColHeader()->ShowColumnsMenu("Columns:");
|
||||
if ( col == wxID_NONE )
|
||||
return;
|
||||
|
||||
if ( m_grid->IsColShown(col) )
|
||||
m_grid->HideCol(col);
|
||||
else
|
||||
m_grid->ShowCol(col);
|
||||
|
||||
UpdateOrderAndVisibility();
|
||||
}
|
||||
|
||||
void UpdateOrderAndVisibility()
|
||||
{
|
||||
wxString s;
|
||||
@ -1880,6 +1895,14 @@ TabularGridFrame::TabularGridFrame()
|
||||
m_grid->UseNativeColHeader();
|
||||
m_grid->HideRowLabels();
|
||||
|
||||
m_grid->GetGridColHeader()->Connect
|
||||
(
|
||||
wxEVT_COMMAND_HEADER_RIGHT_CLICK,
|
||||
wxHeaderCtrlEventHandler(TabularGridFrame::OnColRightClick),
|
||||
NULL,
|
||||
this
|
||||
);
|
||||
|
||||
// add it and the other controls to the frame
|
||||
wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
|
||||
sizerTop->Add(m_grid, wxSizerFlags(1).Expand().Border());
|
||||
@ -1926,7 +1949,7 @@ TabularGridFrame::TabularGridFrame()
|
||||
wxSizer * const sizerShowCols = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizerShowCols->Add(new wxStaticText(panel, wxID_ANY, "Current order:"),
|
||||
flagsHorz);
|
||||
m_statOrder = new wxStaticText(panel, wxID_ANY, "<default>");
|
||||
m_statOrder = new wxStaticText(panel, wxID_ANY, "<<< default >>>");
|
||||
sizerShowCols->Add(m_statOrder, flagsHorz);
|
||||
sizerShowCols->Add(new wxButton(panel, wxID_RESET, "&Reset order"));
|
||||
sizerColumns->Add(sizerShowCols, wxSizerFlags().Expand().Border(wxTOP));
|
||||
|
@ -226,6 +226,29 @@ wxHeaderCtrlBase::DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int cou
|
||||
wxASSERT_MSG( colIndices.size() == count, "logic error" );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxHeaderCtrl extra UI
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
int wxHeaderCtrlBase::ShowColumnsMenu(const wxString& title)
|
||||
{
|
||||
wxMenu menu;
|
||||
if ( !title.empty() )
|
||||
menu.SetTitle(title);
|
||||
|
||||
const unsigned count = GetColumnCount();
|
||||
for ( unsigned n = 0; n < count; n++ )
|
||||
{
|
||||
const wxHeaderColumn& col = GetColumn(n);
|
||||
menu.AppendCheckItem(n, col.GetTitle());
|
||||
if ( col.IsShown() )
|
||||
menu.Check(n, true);
|
||||
}
|
||||
|
||||
return GetPopupMenuSelectionFromUser(menu,
|
||||
ScreenToClient(wxGetMousePosition()));
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// wxHeaderCtrlSimple implementation
|
||||
// ============================================================================
|
||||
|
Loading…
Reference in New Issue
Block a user