X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39d2f9a7c866338762ca974209219f40d4420af6..12ac619f42b81420980aec14afc9433af6f911dc:/src/msw/menu.cpp diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 6bce598d97..cf6c36043a 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -17,7 +17,7 @@ // headers // --------------------------------------------------------------------------- -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "menu.h" #endif @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -112,8 +113,99 @@ UINT GetMenuState(HMENU hMenu, UINT id, UINT flags) // implementation // ============================================================================ +#include + +WX_DEFINE_LIST( wxMenuInfoList ) ; + +#if wxUSE_EXTENDED_RTTI + +WX_DEFINE_FLAGS( wxMenuStyle ) + +wxBEGIN_FLAGS( wxMenuStyle ) + wxFLAGS_MEMBER(wxMENU_TEAROFF) +wxEND_FLAGS( wxMenuStyle ) + +IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenu, wxEvtHandler,"wx/menu.h") + +wxCOLLECTION_TYPE_INFO( wxMenuItem * , wxMenuItemList ) ; + +template<> void wxCollectionToVariantArray( wxMenuItemList const &theList, wxxVariantArray &value) +{ + wxListCollectionToVariantArray( theList , value ) ; +} + +wxBEGIN_PROPERTIES_TABLE(wxMenu) + wxEVENT_PROPERTY( Select , wxEVT_COMMAND_MENU_SELECTED , wxCommandEvent) + wxPROPERTY( Title, wxString , SetTitle, GetTitle, wxString(), 0 /*flags*/ , wxT("Helpstring") , wxT("group") ) + wxREADONLY_PROPERTY_FLAGS( MenuStyle , wxMenuStyle , long , GetStyle , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style + wxPROPERTY_COLLECTION( MenuItems , wxMenuItemList , wxMenuItem* , Append , GetMenuItems , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) +wxEND_PROPERTIES_TABLE() + +wxBEGIN_HANDLERS_TABLE(wxMenu) +wxEND_HANDLERS_TABLE() + +wxDIRECT_CONSTRUCTOR_2( wxMenu , wxString , Title , long , MenuStyle ) + +WX_DEFINE_FLAGS( wxMenuBarStyle ) + +wxBEGIN_FLAGS( wxMenuBarStyle ) + wxFLAGS_MEMBER(wxMB_DOCKABLE) +wxEND_FLAGS( wxMenuBarStyle ) + +// the negative id would lead the window (its superclass !) to vetoe streaming out otherwise +bool wxMenuBarStreamingCallback( const wxObject *WXUNUSED(object), wxWriter * , wxPersister * , wxxVariantArray & ) +{ + return true ; +} + +IMPLEMENT_DYNAMIC_CLASS_XTI_CALLBACK(wxMenuBar, wxWindow ,"wx/menu.h",wxMenuBarStreamingCallback) + +IMPLEMENT_DYNAMIC_CLASS_XTI(wxMenuInfo, wxObject , "wx/menu.h" ) + +wxBEGIN_PROPERTIES_TABLE(wxMenuInfo) + wxREADONLY_PROPERTY( Menu , wxMenu* , GetMenu , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) + wxREADONLY_PROPERTY( Title , wxString , GetTitle , wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) +wxEND_PROPERTIES_TABLE() + +wxBEGIN_HANDLERS_TABLE(wxMenuInfo) +wxEND_HANDLERS_TABLE() + +wxCONSTRUCTOR_2( wxMenuInfo , wxMenu* , Menu , wxString , Title ) + +wxCOLLECTION_TYPE_INFO( wxMenuInfo * , wxMenuInfoList ) ; + +template<> void wxCollectionToVariantArray( wxMenuInfoList const &theList, wxxVariantArray &value) +{ + wxListCollectionToVariantArray( theList , value ) ; +} + +wxBEGIN_PROPERTIES_TABLE(wxMenuBar) + wxPROPERTY_COLLECTION( MenuInfos , wxMenuInfoList , wxMenuInfo* , Append , GetMenuInfos , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) +wxEND_PROPERTIES_TABLE() + +wxBEGIN_HANDLERS_TABLE(wxMenuBar) +wxEND_HANDLERS_TABLE() + +wxCONSTRUCTOR_DUMMY( wxMenuBar ) + +#else IMPLEMENT_DYNAMIC_CLASS(wxMenu, wxEvtHandler) IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxWindow) +IMPLEMENT_DYNAMIC_CLASS(wxMenuInfo, wxObject) +#endif + +const wxMenuInfoList& wxMenuBar::GetMenuInfos() const +{ + wxMenuInfoList* list = const_cast< wxMenuInfoList* >( &m_menuInfos ) ; + WX_CLEAR_LIST( wxMenuInfoList , *list ) ; + for( size_t i = 0 ; i < GetMenuCount() ; ++i ) + { + wxMenuInfo* info = new wxMenuInfo() ; + info->Create( const_cast(this)->GetMenu(i) , GetLabelTop(i) ) ; + list->Append( info ) ; + } + return m_menuInfos ; +} // --------------------------------------------------------------------------- // wxMenu construction, adding and removing menu items @@ -615,7 +707,10 @@ wxMenuBar::~wxMenuBar() { // In Windows CE, the menubar is always associated // with a toolbar, which destroys the menu implicitly. -#ifndef __WXWINCE__ +#ifdef __WXWINCE__ + if (GetToolBar()) + GetToolBar()->SetMenuBar(NULL); +#else // we should free Windows resources only if Windows doesn't do it for us // which happens if we're attached to a frame if (m_hMenu && !IsAttached()) @@ -646,6 +741,10 @@ void wxMenuBar::Refresh() WXHMENU wxMenuBar::Create() { + // Note: this totally doesn't work on Smartphone, + // since you have to use resources. + // We'll have to find another way to add a menu + // by changing/adding menu items to an existing menu. #ifdef __WXWINCE__ if ( m_hMenu != 0 ) return m_hMenu; @@ -670,9 +769,11 @@ WXHMENU wxMenuBar::Create() tbButton.dwData = (DWORD)hPopupMenu; wxString label = wxStripMenuCodes(GetLabelTop(i)); tbButton.iString = (int) label.c_str(); + + int position = i; tbButton.idCommand = NewControlId(); - if (!::SendMessage(hCommandBar, TB_INSERTBUTTON, i, (LPARAM)&tbButton)) + if (!::SendMessage(hCommandBar, TB_INSERTBUTTON, position, (LPARAM)&tbButton)) { wxLogLastError(wxT("TB_INSERTBUTTON")); } @@ -788,7 +889,7 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetLabelTop") ); - return m_titles[pos]; + return wxMenuItem::GetLabelFromText(m_titles[pos]); } // ---------------------------------------------------------------------------