wxBitmapBundle for wxMenuItem on GTK
This commit is contained in:
@@ -75,6 +75,8 @@ public:
|
|||||||
|
|
||||||
void Attach(wxMenuBarBase *menubar) wxOVERRIDE;
|
void Attach(wxMenuBarBase *menubar) wxOVERRIDE;
|
||||||
|
|
||||||
|
void SetupBitmaps(wxWindow *win);
|
||||||
|
|
||||||
void SetLayoutDirection(wxLayoutDirection dir);
|
void SetLayoutDirection(wxLayoutDirection dir);
|
||||||
wxLayoutDirection GetLayoutDirection() const;
|
wxLayoutDirection GetLayoutDirection() const;
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#ifndef _WX_GTKMENUITEM_H_
|
#ifndef _WX_GTKMENUITEM_H_
|
||||||
#define _WX_GTKMENUITEM_H_
|
#define _WX_GTKMENUITEM_H_
|
||||||
|
|
||||||
#include "wx/bitmap.h"
|
#include "wx/bmpbndl.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// wxMenuItem
|
// wxMenuItem
|
||||||
@@ -31,8 +31,10 @@ public:
|
|||||||
virtual void Enable( bool enable = true ) wxOVERRIDE;
|
virtual void Enable( bool enable = true ) wxOVERRIDE;
|
||||||
virtual void Check( bool check = true ) wxOVERRIDE;
|
virtual void Check( bool check = true ) wxOVERRIDE;
|
||||||
virtual bool IsChecked() const wxOVERRIDE;
|
virtual bool IsChecked() const wxOVERRIDE;
|
||||||
virtual void SetBitmap(const wxBitmap& bitmap);
|
virtual void SetBitmap(const wxBitmapBundle& bitmap);
|
||||||
virtual const wxBitmap& GetBitmap() const { return m_bitmap; }
|
virtual wxBitmap GetBitmap() const;
|
||||||
|
const wxBitmapBundle& GetBitmapBundle() const { return m_bitmap; }
|
||||||
|
void SetupBitmaps(wxWindow *win);
|
||||||
|
|
||||||
#if wxUSE_ACCEL
|
#if wxUSE_ACCEL
|
||||||
virtual void AddExtraAccel(const wxAcceleratorEntry& accel) wxOVERRIDE;
|
virtual void AddExtraAccel(const wxAcceleratorEntry& accel) wxOVERRIDE;
|
||||||
@@ -61,7 +63,7 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxBitmap m_bitmap; // Bitmap for menuitem, if any
|
wxBitmapBundle m_bitmap; // Bitmap for menuitem, if any
|
||||||
GtkWidget *m_menuItem; // GtkMenuItem
|
GtkWidget *m_menuItem; // GtkMenuItem
|
||||||
|
|
||||||
wxDECLARE_DYNAMIC_CLASS(wxMenuItem);
|
wxDECLARE_DYNAMIC_CLASS(wxMenuItem);
|
||||||
|
|||||||
@@ -251,6 +251,8 @@ AttachToFrame(wxMenu* menu, wxFrame* frame)
|
|||||||
AttachToFrame(menuitem->GetSubMenu(), frame);
|
AttachToFrame(menuitem->GetSubMenu(), frame);
|
||||||
node = node->GetNext();
|
node = node->GetNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
menu->SetupBitmaps(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
@@ -664,6 +666,8 @@ void wxMenuItem::SetMenuItem(GtkWidget* menuItem)
|
|||||||
m_menuItem = menuItem;
|
m_menuItem = menuItem;
|
||||||
if (menuItem)
|
if (menuItem)
|
||||||
g_object_ref(menuItem);
|
g_object_ref(menuItem);
|
||||||
|
if (m_menuItem && m_parentMenu && m_parentMenu->GetWindow())
|
||||||
|
SetupBitmaps(m_parentMenu->GetWindow());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuItem::SetItemLabel( const wxString& str )
|
void wxMenuItem::SetItemLabel( const wxString& str )
|
||||||
@@ -752,7 +756,7 @@ void wxMenuItem::ClearExtraAccels()
|
|||||||
|
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
|
void wxMenuItem::SetBitmap(const wxBitmapBundle& bitmap)
|
||||||
{
|
{
|
||||||
if (m_kind == wxITEM_NORMAL)
|
if (m_kind == wxITEM_NORMAL)
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
@@ -762,6 +766,36 @@ void wxMenuItem::SetBitmap(const wxBitmap& bitmap)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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::SetupBitmaps(wxWindow *win)
|
||||||
|
{
|
||||||
|
#ifndef __WXGTK4__
|
||||||
|
if ( m_menuItem && m_bitmap.IsOk() )
|
||||||
|
{
|
||||||
|
GtkWidget* image = wxGtkImage::New(win);
|
||||||
|
WX_GTK_IMAGE(image)->Set(m_bitmap);
|
||||||
|
gtk_widget_show(image);
|
||||||
|
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(m_menuItem), image);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void wxMenuItem::Check( bool check )
|
void wxMenuItem::Check( bool check )
|
||||||
{
|
{
|
||||||
wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
|
wxCHECK_RET( m_menuItem, wxT("invalid menu item") );
|
||||||
@@ -1000,14 +1034,9 @@ void wxMenu::GtkAppend(wxMenuItem* mitem, int pos)
|
|||||||
menuItem = gtk_menu_item_new_with_label("");
|
menuItem = gtk_menu_item_new_with_label("");
|
||||||
#else
|
#else
|
||||||
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
||||||
const wxBitmap& bitmap = mitem->GetBitmap();
|
if (mitem->GetBitmapBundle().IsOk())
|
||||||
if (bitmap.IsOk())
|
|
||||||
{
|
{
|
||||||
GtkWidget* image = wxGtkImage::New();
|
|
||||||
WX_GTK_IMAGE(image)->Set(bitmap);
|
|
||||||
menuItem = gtk_image_menu_item_new_with_label("");
|
menuItem = gtk_image_menu_item_new_with_label("");
|
||||||
gtk_widget_show(image);
|
|
||||||
gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menuItem), image);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -1110,6 +1139,20 @@ void wxMenu::Attach(wxMenuBarBase *menubar)
|
|||||||
SetLayoutDirection(menubar->GetLayoutDirection());
|
SetLayoutDirection(menubar->GetLayoutDirection());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxMenu::SetupBitmaps(wxWindow *win)
|
||||||
|
{
|
||||||
|
wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst();
|
||||||
|
while (node)
|
||||||
|
{
|
||||||
|
wxMenuItem *menuitem = node->GetData();
|
||||||
|
if (menuitem->IsSubMenu())
|
||||||
|
menuitem->GetSubMenu()->SetupBitmaps(win);
|
||||||
|
if (menuitem->GetKind() == wxITEM_NORMAL)
|
||||||
|
menuitem->SetupBitmaps(win);
|
||||||
|
node = node->GetNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// helpers
|
// helpers
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|||||||
@@ -5869,6 +5869,8 @@ bool wxWindowGTK::DoPopupMenu( wxMenu *menu, int x, int y )
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
|
wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") );
|
||||||
|
|
||||||
|
menu->SetupBitmaps(this);
|
||||||
|
|
||||||
wxPopupMenuPositionCallbackData data;
|
wxPopupMenuPositionCallbackData data;
|
||||||
gpointer userdata;
|
gpointer userdata;
|
||||||
GtkMenuPositionFunc posfunc;
|
GtkMenuPositionFunc posfunc;
|
||||||
|
|||||||
Reference in New Issue
Block a user