wxBitmapBundle for wxMenuItem on Mac

This commit is contained in:
Alexander Koshelev
2022-02-03 11:18:34 +03:00
parent 27be2ed641
commit 337940f009
5 changed files with 89 additions and 7 deletions

View File

@@ -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 ; }

View File

@@ -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;

View File

@@ -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
// ---------------------------------------------------------------------------

View File

@@ -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());
}
}

View File

@@ -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();