X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1aecefa501029a2b25e719f42ecd8dd1ef07aaf4..6f26925422c2de7938509657eb981d6f752a6249:/src/common/menucmn.cpp?ds=sidebyside diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 883870a714..4c7abae78d 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -59,6 +59,39 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, wxItemKind kind, wxMenu *subMenu) { + switch ( id ) + { + case wxID_ANY: + m_id = wxWindow::NewControlId(); + break; + + case wxID_SEPARATOR: + m_id = wxID_SEPARATOR; + + // there is a lot of existing code just doing Append(wxID_SEPARATOR) + // and it makes sense to omit the following optional parameters, + // including the kind one which doesn't default to wxITEM_SEPARATOR, + // of course, so override it here + kind = wxITEM_SEPARATOR; + break; + + case wxID_NONE: + // (popup) menu titles in wxMSW use this ID to indicate that + // it's not a real menu item, so we don't want the check below to + // apply to it + m_id = id; + break; + + default: + // ids are limited to 16 bits under MSW so portable code shouldn't + // use ids outside of this range (negative ids generated by wx are + // fine though) + wxASSERT_MSG( (id >= 0 && id < SHRT_MAX) || + (id >= wxID_AUTO_LOWEST && id <= wxID_AUTO_HIGHEST), + wxS("invalid id value") ); + m_id = id; + } + // notice that parentMenu can be NULL: the item can be attached to the menu // later with SetMenu() @@ -66,12 +99,7 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, m_subMenu = subMenu; m_isEnabled = true; m_isChecked = false; - m_id = id; m_kind = kind; - if (m_id == wxID_ANY) - m_id = wxWindow::NewControlId(); - if (m_id == wxID_SEPARATOR) - m_kind = wxITEM_SEPARATOR; SetItemLabel(text); SetHelp(help); @@ -514,23 +542,18 @@ void wxMenuBase::SetInvokingWindow(wxWindow *win) m_invokingWindow = win; } -wxWindow *wxMenuBase::GetInvokingWindow() const +wxWindow *wxMenuBase::GetWindow() const { - // only the popup menu itself has a non-NULL invoking window so recurse - // upwards until we find it + // only the top level menus have non-NULL invoking window or a pointer to + // the menu bar so recurse upwards until we find it const wxMenuBase *menu = this; while ( menu->GetParent() ) { menu = menu->GetParent(); } - // menu is a top level menu here - return menu->m_invokingWindow; -} - -wxWindow *wxMenuBase::GetWindow() const -{ - return GetMenuBar() ? GetMenuBar()->GetFrame() : GetInvokingWindow(); + return menu->GetMenuBar() ? menu->GetMenuBar()->GetFrame() + : menu->GetInvokingWindow(); } // ----------------------------------------------------------------------------