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
This commit is contained in:
Vadim Zeitlin
2008-04-06 15:55:42 +00:00
parent 9b8d875536
commit fa7134b05a
7 changed files with 9 additions and 7 deletions

View File

@@ -311,6 +311,7 @@ All (GUI):
- Freeze() and Thaw() now recursively freeze/thaw the children too. - Freeze() and Thaw() now recursively freeze/thaw the children too.
- Generalized wxScrolledWindow into wxScrolled<T> template that can derive - Generalized wxScrolledWindow into wxScrolled<T> template that can derive
from any window class, not just wxPanel. from any window class, not just wxPanel.
- Allow having menu separators with ids != wxID_SEPARATOR (Jeff Tupper)
wxGTK: wxGTK:

View File

@@ -68,7 +68,7 @@ public:
} }
// append a separator to the menu // append a separator to the menu
wxMenuItem* AppendSeparator() { return Append(wxID_SEPARATOR, wxEmptyString); } wxMenuItem* AppendSeparator() { return Append(wxID_SEPARATOR); }
// append a check item // append a check item
wxMenuItem* AppendCheckItem(int itemid, wxMenuItem* AppendCheckItem(int itemid,

View File

@@ -56,7 +56,6 @@ public:
// get/set id // get/set id
void SetId(int itemid) { m_id = itemid; } void SetId(int itemid) { m_id = itemid; }
int GetId() const { return m_id; } int GetId() const { return m_id; }
bool IsSeparator() const { return m_id == wxID_SEPARATOR; }
// the item's text (or name) // the item's text (or name)
// //
@@ -81,6 +80,7 @@ public:
// what kind of menu item we are // what kind of menu item we are
wxItemKind GetKind() const { return m_kind; } wxItemKind GetKind() const { return m_kind; }
void SetKind(wxItemKind kind) { m_kind = 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; } virtual void SetCheckable(bool checkable) { m_kind = checkable ? wxITEM_CHECK : wxITEM_NORMAL; }
bool IsCheckable() const bool IsCheckable() const

View File

@@ -47,7 +47,8 @@ public:
@param parentMenu @param parentMenu
Menu that the menu item belongs to. Menu that the menu item belongs to.
@param id @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 @param text
Text for the menu item, as shown on the menu. An accelerator 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 key can be specified using the ampersand " character. In order to embed an

View File

@@ -360,7 +360,7 @@ bool wxFrameBase::ShowMenuHelp(int menuId)
if ( menuId != wxID_SEPARATOR && menuId != -3 /* wxID_TITLE */ ) if ( menuId != wxID_SEPARATOR && menuId != -3 /* wxID_TITLE */ )
{ {
const wxMenuItem * const item = FindItemInMenuBar(menuId); const wxMenuItem * const item = FindItemInMenuBar(menuId);
if ( item ) if ( item && !item->IsSeparator() )
helpString = item->GetHelp(); helpString = item->GetHelp();
// notice that it's ok if we don't find the item because it might // notice that it's ok if we don't find the item because it might

View File

@@ -284,7 +284,7 @@ void wxMenuItem::DestroyItem(bool full)
wxMenuItemDisarmCallback, (XtPointer) this); wxMenuItemDisarmCallback, (XtPointer) this);
} }
} }
else if (GetId() == wxID_SEPARATOR) else if (IsSeparator())
{ {
; // Nothing ; // Nothing

View File

@@ -170,7 +170,7 @@ void wxMenuItem::Init()
ResetOwnerDrawn(); ResetOwnerDrawn();
// switch ownerdraw back on if using a non default margin // switch ownerdraw back on if using a non default margin
if ( GetId() != wxID_SEPARATOR ) if ( !IsSeparator() )
SetMarginWidth(GetMarginWidth()); SetMarginWidth(GetMarginWidth());
// tell the owner drawing code to show the accel string as well // 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 // fix that RTTI is always getting the correct state (separators cannot be checked, but the call below
// returns true // returns true
if ( GetId() == wxID_SEPARATOR ) if ( IsSeparator() )
return false ; return false ;
int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetMSWId(), MF_BYCOMMAND); int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetMSWId(), MF_BYCOMMAND);