[Libreoffice-commits] core.git: vcl/inc vcl/unx
Caolán McNamara
caolanm at redhat.com
Sun Jun 19 16:23:31 UTC 2016
vcl/inc/unx/gtk/glomenu.h | 10 ++++++++++
vcl/inc/unx/gtk/gtksalmenu.hxx | 1 +
vcl/unx/gtk/glomenu.cxx | 37 +++++++++++++++++++++++++++++++++++++
vcl/unx/gtk/gtksalmenu.cxx | 32 ++++++++++++++++++++++++++++++++
4 files changed, 80 insertions(+)
New commits:
commit 1409b974003ca69e4682507f5d34c55f346b864a
Author: Caolán McNamara <caolanm at redhat.com>
Date: Fri Jun 17 21:15:20 2016 +0100
Resolve: tdf#100429 gtk3: set custom icons in native gtk menus
Change-Id: I4798274f38c34c99d6f22f3c7959ebd9673a8966
diff --git a/vcl/inc/unx/gtk/glomenu.h b/vcl/inc/unx/gtk/glomenu.h
index b2ed606..5586aa4 100644
--- a/vcl/inc/unx/gtk/glomenu.h
+++ b/vcl/inc/unx/gtk/glomenu.h
@@ -69,11 +69,21 @@ void g_lo_menu_set_label (GLOMenu
gint position,
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,
gint section,
gint position,
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,
gint section,
gint position);
diff --git a/vcl/inc/unx/gtk/gtksalmenu.hxx b/vcl/inc/unx/gtk/gtksalmenu.hxx
index ba2c858..74f03dd 100644
--- a/vcl/inc/unx/gtk/gtksalmenu.hxx
+++ b/vcl/inc/unx/gtk/gtksalmenu.hxx
@@ -93,6 +93,7 @@ public:
bool IsItemVisible( unsigned nPos );
void NativeSetItemText( unsigned nSection, unsigned nItemPos, const OUString& rText );
+ void NativeSetItemIcon( unsigned nSection, unsigned nItemPos, const Image& rImage );
bool NativeSetItemCommand( unsigned nSection,
unsigned nItemPos,
sal_uInt16 nId,
diff --git a/vcl/unx/gtk/glomenu.cxx b/vcl/unx/gtk/glomenu.cxx
index bf2b701..ffa43e5 100644
--- a/vcl/unx/gtk/glomenu.cxx
+++ b/vcl/unx/gtk/glomenu.cxx
@@ -229,6 +229,23 @@ g_lo_menu_set_label (GLOMenu *menu,
}
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
g_lo_menu_set_label_to_item_in_section (GLOMenu *menu,
gint section,
gint position,
@@ -248,6 +265,26 @@ g_lo_menu_set_label_to_item_in_section (GLOMenu *menu,
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 *
g_lo_menu_get_label_from_item_in_section (GLOMenu *menu,
gint section,
diff --git a/vcl/unx/gtk/gtksalmenu.cxx b/vcl/unx/gtk/gtksalmenu.cxx
index 19fd6a0..af48f1b 100644
--- a/vcl/unx/gtk/gtksalmenu.cxx
+++ b/vcl/unx/gtk/gtksalmenu.cxx
@@ -18,6 +18,7 @@
#include <unx/gtk/gloactiongroup.h>
#include <vcl/floatwin.hxx>
#include <vcl/menu.hxx>
+#include <vcl/pngwrite.hxx>
#include <unx/gtk/gtkinst.hxx>
#if GTK_CHECK_VERSION(3,0,0)
@@ -236,6 +237,7 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
// Get internal menu item values.
OUString aText = pVCLMenu->GetItemText( nId );
+ Image aImage = pVCLMenu->GetItemImage( nId );
bool bEnabled = pVCLMenu->IsItemEnabled( nId );
vcl::KeyCode nAccelKey = pVCLMenu->GetAccelKey( nId );
bool bChecked = pVCLMenu->IsItemChecked( nId );
@@ -252,6 +254,8 @@ void GtkSalMenu::ImplUpdate(bool bRecurse, bool bRemoveDisabledEntries)
// Force updating of native menu labels.
NativeSetItemText( nSection, nItemPos, aText );
+ if (!!aImage)
+ NativeSetItemIcon( nSection, nItemPos, aImage );
NativeSetAccelerator( nSection, nItemPos, nAccelKey, nAccelKey.GetName( GetFrame()->GetWindow() ) );
if ( g_strcmp0( aNativeCommand, "" ) != 0 && pSalMenuItem->mpSubMenu == nullptr )
@@ -844,6 +848,34 @@ void GtkSalMenu::NativeSetItemText( unsigned nSection, unsigned nItemPos, const
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 )
{
SolarMutexGuard aGuard;
More information about the Libreoffice-commits
mailing list