From ddd0db9619bb3b8d7dc5e67f2a0b99052fb565d5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 30 Dec 2008 23:19:06 +0000 Subject: [PATCH] extract AddColumnsItems() from ShowColumnsMenu() to make it possible to reuse it in custom menu git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57677 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/headerctrl.h | 11 +++++++++++ interface/wx/headerctrl.h | 29 +++++++++++++++++++++++++++++ src/common/headerctrlcmn.cpp | 22 ++++++++++++++-------- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/include/wx/headerctrl.h b/include/wx/headerctrl.h index a95d094cb3..64ca3c4540 100644 --- a/include/wx/headerctrl.h +++ b/include/wx/headerctrl.h @@ -130,6 +130,17 @@ public: // with wxHD_ALLOW_HIDE style bool ShowColumnsMenu(const wxPoint& pt, const wxString& title = wxString()); + // append the entries for all our columns to the given menu, with the + // currently visible columns being checked + // + // this is used by ShowColumnsMenu() but can also be used if you use your + // own custom columns menu but nevertheless want to show all the columns in + // it + // + // the ids of the items corresponding to the columns are consecutive and + // start from idColumnsBase + void AddColumnsItems(wxMenu& menu, int idColumnsBase = 0); + // show the columns customization dialog and return true if something was // changed using it (in which case UpdateColumnVisibility() and/or // UpdateColumnsOrder() will have been called) diff --git a/interface/wx/headerctrl.h b/interface/wx/headerctrl.h index 02eed62ee4..c718467c17 100644 --- a/interface/wx/headerctrl.h +++ b/interface/wx/headerctrl.h @@ -327,6 +327,35 @@ public: */ int ShowColumnsMenu(const wxPoint& pt, const wxString& title = wxString()); + /** + Helper function appending the checkable items corresponding to all the + columns to the given menu. + + This function is used by ShowColumnsMenu() but can also be used if you + show your own custom columns menu and still want all the columns shown + in it. It appends menu items with column labels as their text and + consecutive ids starting from @a idColumnsBase to the menu and checks + the items corresponding to the currently visible columns. + + Example of use: + @code + wxMenu menu; + menu.Append(100, "Some custom command"); + menu.AppendSeparator(); + AddColumnsItems(menu, 200); + const int rc = GetPopupMenuSelectionFromUser(menu, pt); + if ( rc >= 200 ) + ... toggle visibility of the column rc-200 ... + @endcode + + @param menu + The menu to append the items to. It may be currently empty or not. + @param idColumnsBase + The id for the menu item corresponding to the first column, the + other ones are consecutive starting from it. It should be positive. + */ + void AddColumnsItems(wxMenu& menu, int idColumnsBase = 0); + /** Show the column customization dialog. diff --git a/src/common/headerctrlcmn.cpp b/src/common/headerctrlcmn.cpp index bc5fd71f60..bf24b04564 100644 --- a/src/common/headerctrlcmn.cpp +++ b/src/common/headerctrlcmn.cpp @@ -263,6 +263,18 @@ wxHeaderCtrlBase::DoResizeColumnIndices(wxArrayInt& colIndices, unsigned int cou // wxHeaderCtrl extra UI // ---------------------------------------------------------------------------- +void wxHeaderCtrlBase::AddColumnsItems(wxMenu& menu, int idColumnsBase) +{ + const unsigned count = GetColumnCount(); + for ( unsigned n = 0; n < count; n++ ) + { + const wxHeaderColumn& col = GetColumn(n); + menu.AppendCheckItem(idColumnsBase + n, col.GetTitle()); + if ( col.IsShown() ) + menu.Check(n, true); + } +} + bool wxHeaderCtrlBase::ShowColumnsMenu(const wxPoint& pt, const wxString& title) { // construct the menu with the entries for all columns @@ -270,17 +282,11 @@ bool wxHeaderCtrlBase::ShowColumnsMenu(const wxPoint& pt, const wxString& title) 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); - } + AddColumnsItems(menu); // ... and an extra one to show the customization dialog if the user is // allowed to reorder the columns too + const unsigned count = GetColumnCount(); if ( HasFlag(wxHD_ALLOW_REORDER) ) { menu.AppendSeparator();