From fa7134b05abb0d8df4b800762aa9d040bfd689a4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 6 Apr 2008 15:55:42 +0000 Subject: [PATCH] use kind, not id, of a menu item to test whether it's a separator: this allows having separators with ids other than wxID_SEPARATOR in case it's useful to distinguish between them (patch 1929039) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/menu.h | 2 +- include/wx/menuitem.h | 2 +- interface/menuitem.h | 3 ++- src/common/framecmn.cpp | 2 +- src/motif/menuitem.cpp | 2 +- src/msw/menuitem.cpp | 4 ++-- 7 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index af74dc4..5a21ed1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -311,6 +311,7 @@ All (GUI): - Freeze() and Thaw() now recursively freeze/thaw the children too. - Generalized wxScrolledWindow into wxScrolled template that can derive from any window class, not just wxPanel. +- Allow having menu separators with ids != wxID_SEPARATOR (Jeff Tupper) wxGTK: diff --git a/include/wx/menu.h b/include/wx/menu.h index 00fcd59..8cae2e1 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -68,7 +68,7 @@ public: } // append a separator to the menu - wxMenuItem* AppendSeparator() { return Append(wxID_SEPARATOR, wxEmptyString); } + wxMenuItem* AppendSeparator() { return Append(wxID_SEPARATOR); } // append a check item wxMenuItem* AppendCheckItem(int itemid, diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 677aa31..1da5f65 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -56,7 +56,6 @@ public: // get/set id void SetId(int itemid) { m_id = itemid; } int GetId() const { return m_id; } - bool IsSeparator() const { return m_id == wxID_SEPARATOR; } // the item's text (or name) // @@ -81,6 +80,7 @@ public: // what kind of menu item we are wxItemKind GetKind() const { return m_kind; } void SetKind(wxItemKind kind) { m_kind = kind; } + bool IsSeparator() const { return m_kind == wxITEM_SEPARATOR; } virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; } bool IsCheckable() const diff --git a/interface/menuitem.h b/interface/menuitem.h index 4ee4df3..9296ab2 100644 --- a/interface/menuitem.h +++ b/interface/menuitem.h @@ -47,7 +47,8 @@ public: @param parentMenu Menu that the menu item belongs to. @param id - Identifier for this menu item, or wxID_SEPARATOR to indicate a separator. + Identifier for this menu item. May be wxID_SEPARATOR, in which case the + given kind is ignored and taken to be wxITEM_SEPARATOR instead. @param text Text for the menu item, as shown on the menu. An accelerator key can be specified using the ampersand " character. In order to embed an diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index c1a25b5..710742f 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -360,7 +360,7 @@ bool wxFrameBase::ShowMenuHelp(int menuId) if ( menuId != wxID_SEPARATOR && menuId != -3 /* wxID_TITLE */ ) { const wxMenuItem * const item = FindItemInMenuBar(menuId); - if ( item ) + if ( item && !item->IsSeparator() ) helpString = item->GetHelp(); // notice that it's ok if we don't find the item because it might diff --git a/src/motif/menuitem.cpp b/src/motif/menuitem.cpp index 6fbfb08..e830c00 100644 --- a/src/motif/menuitem.cpp +++ b/src/motif/menuitem.cpp @@ -284,7 +284,7 @@ void wxMenuItem::DestroyItem(bool full) wxMenuItemDisarmCallback, (XtPointer) this); } } - else if (GetId() == wxID_SEPARATOR) + else if (IsSeparator()) { ; // Nothing diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 32b92ee..d5ef1dc 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -170,7 +170,7 @@ void wxMenuItem::Init() ResetOwnerDrawn(); // switch ownerdraw back on if using a non default margin - if ( GetId() != wxID_SEPARATOR ) + if ( !IsSeparator() ) SetMarginWidth(GetMarginWidth()); // tell the owner drawing code to show the accel string as well @@ -203,7 +203,7 @@ bool wxMenuItem::IsChecked() const { // fix that RTTI is always getting the correct state (separators cannot be checked, but the call below // returns true - if ( GetId() == wxID_SEPARATOR ) + if ( IsSeparator() ) return false ; int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetMSWId(), MF_BYCOMMAND); -- 2.7.4