diff --git a/include/wx/osx/menu.h b/include/wx/osx/menu.h index 009efb04a4..26544dc415 100644 --- a/include/wx/osx/menu.h +++ b/include/wx/osx/menu.h @@ -66,6 +66,12 @@ public: // containing this position. bool OSXGetRadioGroupRange(int pos, int *start, int *end) const; +#if wxUSE_MENUBAR + virtual void Attach(wxMenuBarBase *menubar) wxOVERRIDE; +#endif + + void SetupBitmaps(); + protected: // hide special menu items like exit, preferences etc // that are expected in the app menu @@ -163,6 +169,9 @@ public: static void MacSetCommonMenuBar(wxMenuBar* menubar) { s_macCommonMenuBar=menubar; } static wxMenuBar* MacGetCommonMenuBar() { return s_macCommonMenuBar; } + virtual void Attach(wxFrame *frame) wxOVERRIDE; + void SetupBitmaps(); + static WXHMENU MacGetWindowMenuHMenu() { return s_macWindowMenuHandle ; } diff --git a/include/wx/osx/menuitem.h b/include/wx/osx/menuitem.h index 44f22ff15e..63f207f943 100644 --- a/include/wx/osx/menuitem.h +++ b/include/wx/osx/menuitem.h @@ -16,7 +16,7 @@ // ---------------------------------------------------------------------------- #include "wx/defs.h" -#include "wx/bitmap.h" +#include "wx/bmpbndl.h" #include "wx/vector.h" // ---------------------------------------------------------------------------- @@ -49,8 +49,8 @@ public: void RemoveHiddenItems(); #endif // wxUSE_ACCEL - virtual void SetBitmap(const wxBitmap& bitmap) ; - virtual const wxBitmap& GetBitmap() const { return m_bitmap; } + virtual void SetBitmap(const wxBitmapBundle& bitmap) ; + virtual wxBitmap GetBitmap() const; // Implementation only from now on. @@ -64,7 +64,7 @@ public: private: void UncheckRadio() ; - wxBitmap m_bitmap; // Bitmap for menuitem, if any + wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any wxMenuItemImpl* m_peer; diff --git a/src/osx/menu_osx.cpp b/src/osx/menu_osx.cpp index 8ff64ee79d..ec05d0aa8c 100644 --- a/src/osx/menu_osx.cpp +++ b/src/osx/menu_osx.cpp @@ -155,7 +155,17 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *item, size_t pos) #if wxUSE_MENUBAR // if we're already attached to the menubar, we must update it if ( IsAttached() && GetMenuBar()->IsAttached() ) + { + if ( item->IsSubMenu() ) + { + item->GetSubMenu()->SetupBitmaps(); + } + if ( !item->IsSeparator() ) + { + item->UpdateItemBitmap(); + } GetMenuBar()->Refresh(); + } #endif // wxUSE_MENUBAR if ( check ) @@ -399,6 +409,36 @@ void wxMenu::HandleMenuClosed() DoHandleMenuOpenedOrClosed(wxEVT_MENU_CLOSE); } +#if wxUSE_MENUBAR +void wxMenu::Attach(wxMenuBarBase *menubar) +{ + wxMenuBase::Attach(menubar); + + if (menubar->IsAttached()) + { + SetupBitmaps(); + } +} +#endif + +void wxMenu::SetupBitmaps() +{ + for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst(); + node; + node = node->GetNext() ) + { + wxMenuItem *item = node->GetData(); + if ( item->IsSubMenu() ) + { + item->GetSubMenu()->SetupBitmaps(); + } + if ( !item->IsSeparator() ) + { + item->UpdateItemBitmap(); + } + } +} + #if wxUSE_MENUBAR // Menu Bar @@ -625,6 +665,21 @@ wxString wxMenuBar::GetMenuLabel(size_t pos) const return GetMenu(pos)->GetTitle(); } +void wxMenuBar::SetupBitmaps() +{ + for ( wxMenuList::const_iterator it = m_menus.begin(); it != m_menus.end(); ++it ) + { + (*it)->SetupBitmaps(); + } +} + +void wxMenuBar::Attach(wxFrame *frame) +{ + wxMenuBarBase::Attach(frame); + + SetupBitmaps(); +} + // --------------------------------------------------------------------------- // wxMenuBar construction // --------------------------------------------------------------------------- diff --git a/src/osx/menuitem_osx.cpp b/src/osx/menuitem_osx.cpp index 2d6487d358..a1bb0e75f0 100644 --- a/src/osx/menuitem_osx.cpp +++ b/src/osx/menuitem_osx.cpp @@ -70,10 +70,26 @@ wxMenuItem::~wxMenuItem() // change item state // ----------------- -void wxMenuItem::SetBitmap(const wxBitmap& bitmap) +void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap) { m_bitmap = bitmap; - UpdateItemBitmap(); +} + +wxBitmap wxMenuItem::GetBitmap() const +{ + wxBitmap bmp; + if ( m_bitmap.IsOk() ) + { + if (m_parentMenu && m_parentMenu->GetWindow()) + { + bmp = m_bitmap.GetBitmapFor(m_parentMenu->GetWindow()); + } + else + { + bmp = m_bitmap.GetBitmap(wxDefaultSize); + } + } + return bmp; } void wxMenuItem::Enable(bool bDoEnable) @@ -167,7 +183,7 @@ void wxMenuItem::UpdateItemBitmap() if ( m_bitmap.IsOk() ) { - GetPeer()->SetBitmap( m_bitmap ); + GetPeer()->SetBitmap(GetBitmap()); } } diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 99cbfe1c7c..4792406b22 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -871,6 +871,8 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) bool wxWindowMac::DoPopupMenu(wxMenu *menu, int x, int y) { #ifndef __WXUNIVERSAL__ + menu->SetupBitmaps(); + if ( x == wxDefaultCoord && y == wxDefaultCoord ) { wxPoint mouse = wxGetMousePosition();