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
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
// -------------------------------
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
#include "wx/aboutdlg.h"
#include "wx/grid.h"
+#include "wx/headerctrl.h"
#include "wx/generic/gridctrl.h"
#include "griddemo.h"
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;
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());
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));
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
// ============================================================================