Kaydet (Commit) 1409b974 authored tarafından Caolán McNamara's avatar Caolán McNamara

Resolve: tdf#100429 gtk3: set custom icons in native gtk menus

Change-Id: I4798274f38c34c99d6f22f3c7959ebd9673a8966
üst 0e2a6561
...@@ -69,11 +69,21 @@ void g_lo_menu_set_label (GLOMenu ...@@ -69,11 +69,21 @@ void g_lo_menu_set_label (GLOMenu
gint position, gint position,
const gchar *label); const gchar *label);
void g_lo_menu_set_icon (GLOMenu *menu,
gint position,
const GIcon *icon);
void g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, void g_lo_menu_set_label_to_item_in_section (GLOMenu *menu,
gint section, gint section,
gint position, gint position,
const gchar *label); const gchar *label);
void g_lo_menu_set_icon_to_item_in_section (GLOMenu *menu,
gint section,
gint position,
const GIcon *icon);
gchar * g_lo_menu_get_label_from_item_in_section (GLOMenu *menu, gchar * g_lo_menu_get_label_from_item_in_section (GLOMenu *menu,
gint section, gint section,
gint position); gint position);
......
...@@ -93,6 +93,7 @@ public: ...@@ -93,6 +93,7 @@ public:
bool IsItemVisible( unsigned nPos ); bool IsItemVisible( unsigned nPos );
void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText ); void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText );
void NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage );
bool NativeSetItemCommand( unsigned nSection, bool NativeSetItemCommand( unsigned nSection,
unsigned nItemPos, unsigned nItemPos,
sal_uInt16 nId, sal_uInt16 nId,
......
...@@ -228,6 +228,23 @@ g_lo_menu_set_label (GLOMenu *menu, ...@@ -228,6 +228,23 @@ g_lo_menu_set_label (GLOMenu *menu,
g_lo_menu_set_attribute_value (menu, position, G_MENU_ATTRIBUTE_LABEL, value); g_lo_menu_set_attribute_value (menu, position, G_MENU_ATTRIBUTE_LABEL, value);
} }
void
g_lo_menu_set_icon (GLOMenu *menu,
gint position,
const GIcon *icon)
{
g_return_if_fail (G_IS_LO_MENU (menu));
GVariant *value;
if (icon != nullptr)
value = g_icon_serialize (const_cast<GIcon*>(icon));
else
value = nullptr;
g_lo_menu_set_attribute_value (menu, position, G_MENU_ATTRIBUTE_ICON, value);
}
void void
g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, g_lo_menu_set_label_to_item_in_section (GLOMenu *menu,
gint section, gint section,
...@@ -248,6 +265,26 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu *menu, ...@@ -248,6 +265,26 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu *menu,
g_object_unref (model); g_object_unref (model);
} }
void
g_lo_menu_set_icon_to_item_in_section (GLOMenu *menu,
gint section,
gint position,
const GIcon *icon)
{
g_return_if_fail (G_IS_LO_MENU (menu));
GLOMenu *model = g_lo_menu_get_section (menu, section);
g_return_if_fail (model != nullptr);
g_lo_menu_set_icon (model, position, icon);
// Notify the update.
g_menu_model_items_changed (G_MENU_MODEL (model), position, 1, 1);
g_object_unref (model);
}
gchar * gchar *
g_lo_menu_get_label_from_item_in_section (GLOMenu *menu, g_lo_menu_get_label_from_item_in_section (GLOMenu *menu,
gint section, gint section,
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <unx/gtk/gloactiongroup.h> #include <unx/gtk/gloactiongroup.h>
#include <vcl/floatwin.hxx> #include <vcl/floatwin.hxx>
#include <vcl/menu.hxx> #include <vcl/menu.hxx>
#include <vcl/pngwrite.hxx>
#include <unx/gtk/gtkinst.hxx> #include <unx/gtk/gtkinst.hxx>
#if GTK_CHECK_VERSION(3,0,0) #if GTK_CHECK_VERSION(3,0,0)
...@@ -236,6 +237,7 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries) ...@@ -236,6 +237,7 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
// Get internal menu item values. // Get internal menu item values.
OUString aText = pVCLMenu->GetItemText( nId ); OUString aText = pVCLMenu->GetItemText( nId );
Image aImage = pVCLMenu->GetItemImage( nId );
bool bEnabled = pVCLMenu->IsItemEnabled( nId ); bool bEnabled = pVCLMenu->IsItemEnabled( nId );
vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey( nId ); vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey( nId );
bool bChecked = pVCLMenu->IsItemChecked( nId ); bool bChecked = pVCLMenu->IsItemChecked( nId );
...@@ -252,6 +254,8 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries) ...@@ -252,6 +254,8 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
// Force updating of native menu labels. // Force updating of native menu labels.
NativeSetItemText( nSection, nItemPos, aText ); NativeSetItemText( nSection, nItemPos, aText );
if (!!aImage)
NativeSetItemIcon( nSection, nItemPos, aImage );
NativeSetAccelerator( nSection, nItemPos, nAccelKey, nAccelKey.GetName( GetFrame()->GetWindow() ) ); NativeSetAccelerator( nSection, nItemPos, nAccelKey, nAccelKey.GetName( GetFrame()->GetWindow() ) );
if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == nullptr ) if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == nullptr )
...@@ -844,6 +848,34 @@ void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, const ...@@ -844,6 +848,34 @@ void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, const
g_free( aLabel ); g_free( aLabel );
} }
namespace
{
void DestroyMemoryStream(gpointer data)
{
SvMemoryStream* pMemStm = reinterpret_cast<SvMemoryStream*>(data);
delete pMemStm;
}
}
void GtkSalMenu::NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage )
{
SolarMutexGuard aGuard;
SvMemoryStream* pMemStm = new SvMemoryStream;
vcl::PNGWriter aWriter(rImage.GetBitmapEx());
aWriter.Write(*pMemStm);
GBytes *pBytes = g_bytes_new_with_free_func(pMemStm->GetData(),
pMemStm->Seek(STREAM_SEEK_TO_END),
DestroyMemoryStream,
pMemStm);
GIcon *pIcon = g_bytes_icon_new(pBytes);
g_lo_menu_set_icon_to_item_in_section( G_LO_MENU( mpMenuModel ), nSection, nItemPos, pIcon );
g_object_unref(pIcon);
g_bytes_unref(pBytes);
}
void GtkSalMenu::NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, const OUString& rKeyName ) void GtkSalMenu::NativeSetAccelerator( unsigned nSection, unsigned nItemPos, const vcl::KeyCode& rKeyCode, const OUString& rKeyName )
{ {
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment