X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ea16d351278be2c3a9c0ffeedea84085f089f64b..cef55d6485619c56fb7af4c2cc23e8bbcb86b74f:/src/msw/menuitem.cpp diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 2acfe24a1b..25958f2c6e 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: menuitem.cpp +// Name: src/msw/menuitem.cpp // Purpose: wxMenuItem implementation // Author: Vadim Zeitlin // Modified by: @@ -17,10 +17,6 @@ // headers // --------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "menuitem.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -30,20 +26,19 @@ #if wxUSE_MENUS +#include "wx/menuitem.h" + #ifndef WX_PRECOMP #include "wx/font.h" #include "wx/bitmap.h" #include "wx/settings.h" - #include "wx/font.h" #include "wx/window.h" #include "wx/accel.h" - #include "wx/menu.h" #include "wx/string.h" + #include "wx/log.h" + #include "wx/menu.h" #endif -#include "wx/menuitem.h" -#include "wx/log.h" - #if wxUSE_ACCEL #include "wx/accel.h" #endif // wxUSE_ACCEL @@ -82,7 +77,7 @@ UINT GetMenuState(HMENU hMenu, UINT id, UINT flags) ; bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & ) { const wxMenuItem * mitem = dynamic_cast(object) ; - if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().IsEmpty() ) + if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().empty() ) { // we don't stream out the first two items for menus with a title, they will be reconstructed if ( mitem->GetMenu()->FindItemByPosition(0) == mitem || mitem->GetMenu()->FindItemByPosition(1) == mitem ) @@ -92,24 +87,24 @@ bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersist } wxBEGIN_ENUM( wxItemKind ) - wxENUM_MEMBER( wxITEM_SEPARATOR ) - wxENUM_MEMBER( wxITEM_NORMAL ) - wxENUM_MEMBER( wxITEM_CHECK ) - wxENUM_MEMBER( wxITEM_RADIO ) + wxENUM_MEMBER( wxITEM_SEPARATOR ) + wxENUM_MEMBER( wxITEM_NORMAL ) + wxENUM_MEMBER( wxITEM_CHECK ) + wxENUM_MEMBER( wxITEM_RADIO ) wxEND_ENUM( wxItemKind ) IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuItem, wxObject,"wx/menuitem.h",wxMenuItemStreamingCallback) wxBEGIN_PROPERTIES_TABLE(wxMenuItem) - wxPROPERTY( Parent,wxMenu*, SetMenu, GetMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) - wxPROPERTY( Id,int, SetId, GetId, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxPROPERTY( Parent,wxMenu*, SetMenu, GetMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxPROPERTY( Id,int, SetId, GetId, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) wxPROPERTY( Text, wxString , SetText, GetText, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) wxPROPERTY( Help, wxString , SetHelp, GetHelp, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) wxREADONLY_PROPERTY( Kind, wxItemKind , GetKind , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) - wxPROPERTY( SubMenu,wxMenu*, SetSubMenu, GetSubMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) - wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) - wxPROPERTY( Checked , bool , Check , IsChecked , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) - wxPROPERTY( Checkable , bool , SetCheckable , IsCheckable , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( SubMenu,wxMenu*, SetSubMenu, GetSubMenu, EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxPROPERTY( Enabled , bool , Enable , IsEnabled , wxxVariant((bool)true) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( Checked , bool , Check , IsChecked , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxPROPERTY( Checkable , bool , SetCheckable , IsCheckable , wxxVariant((bool)false) , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) wxEND_PROPERTIES_TABLE() wxBEGIN_HANDLERS_TABLE(wxMenuItem) @@ -159,21 +154,25 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, void wxMenuItem::Init() { m_radioGroup.start = -1; - m_isRadioGroupStart = FALSE; + m_isRadioGroupStart = false; #if wxUSE_OWNER_DRAWN - // set default menu colors - #define SYS_COLOR(c) (wxSystemSettings::GetColour(wxSYS_COLOUR_##c)) - SetTextColour(SYS_COLOR(MENUTEXT)); - SetBackgroundColour(SYS_COLOR(MENU)); + // when the color is not valid, wxOwnerDraw takes the default ones. + // If we set the colors here and they are changed by the user during + // the execution, then the colors are not updated until the application + // is restarted and our menus look bad + SetTextColour(wxNullColour); + SetBackgroundColour(wxNullColour); - #undef SYS_COLOR - - // we don't want normal items be owner-drawn + // setting default colors switched ownerdraw on: switch it off again ResetOwnerDrawn(); - // tell the owner drawing code to to show the accel string as well + // switch ownerdraw back on if using a non default margin + if ( GetId() != wxID_SEPARATOR ) + SetMarginWidth(GetMarginWidth()); + + // tell the owner drawing code to show the accel string as well SetAccelString(m_text.AfterFirst(_T('\t'))); #endif // wxUSE_OWNER_DRAWN } @@ -196,7 +195,7 @@ int wxMenuItem::GetRealId() const 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 if ( GetId() == wxID_SEPARATOR ) return false ; @@ -217,7 +216,7 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) void wxMenuItem::SetAsRadioGroupStart() { - m_isRadioGroupStart = TRUE; + m_isRadioGroupStart = true; } void wxMenuItem::SetRadioGroupStart(int start) @@ -318,7 +317,7 @@ void wxMenuItem::Check(bool check) { if ( n != pos ) { - node->GetData()->m_isChecked = FALSE; + node->GetData()->m_isChecked = false; } node = node->GetNext(); @@ -330,7 +329,7 @@ void wxMenuItem::Check(bool check) GetRealId(), MF_BYCOMMAND | flags) == (DWORD)-1 ) { - wxLogLastError(wxT("CheckMenuItem")); + wxFAIL_MSG( _T("CheckMenuItem() failed, item not in the menu?") ); } } @@ -399,9 +398,9 @@ void wxMenuItem::SetText(const wxString& text) info.cbSize = sizeof(info); info.fMask = MIIM_TYPE; info.fType = MFT_STRING; - info.cch = text.Length(); + info.cch = text.length(); info.dwTypeData = (LPTSTR) data ; - if ( !SetMenuItemInfo(hMenu, id, FALSE, & info) ) + if ( !::SetMenuItemInfo(hMenu, id, FALSE, & info) ) { wxLogLastError(wxT("SetMenuItemInfo")); }