From ac5b2047ca72677d6beaf58ddaa8fdcda7236292 Mon Sep 17 00:00:00 2001 From: Simon Steinbeiss Date: Mon, 26 Oct 2015 13:41:32 +0100 Subject: Let Gtk handle icon names instead of ResMgr for window and trayicon MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The icons in the themes should be deleted in a second step and the defines should be transformed into an ENUM and stored in one place. Furthermore we will have to decide whether to live with gtkimagemenuitem despite its deprecation in Gtk3.10 or whether to pack GtkImages and GtkLabels in GtkBoxes inside GtkMenuItems and live with the additional padding, which potentially looks horrible. Change-Id: I8dec44375e40a4d2b6668792bc4b813efe83ff31 Reviewed-on: https://gerrit.libreoffice.org/19601 Reviewed-by: Björn Michaelsen Tested-by: Björn Michaelsen --- sfx2/source/appl/shutdowniconunx.cxx | 80 ++++++++---------------------------- 1 file changed, 18 insertions(+), 62 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/appl/shutdowniconunx.cxx b/sfx2/source/appl/shutdowniconunx.cxx index 2de5654fe28a..fc2921cb788e 100644 --- a/sfx2/source/appl/shutdowniconunx.cxx +++ b/sfx2/source/appl/shutdowniconunx.cxx @@ -27,8 +27,6 @@ #include #include #include -#include -#include #include "tools/rc.hxx" #include #include "app.hrc" @@ -42,9 +40,6 @@ #endif // Cut/paste from vcl/inc/svids.hrc -#define SV_ICON_SMALL_START 25000 - -#define SV_ICON_ID_OFFICE 1 #define SV_ICON_ID_TEXT 2 #define SV_ICON_ID_SPREADSHEET 4 #define SV_ICON_ID_DRAWING 6 @@ -108,57 +103,6 @@ static void menu_deactivate_cb( GtkWidget *pMenu ) gtk_menu_popdown( GTK_MENU( pMenu ) ); } -static GdkPixbuf * ResIdToPixbuf( sal_uInt16 nResId ) -{ - ResId aResId( nResId, *pVCLResMgr ); - BitmapEx aIcon( aResId ); - Bitmap pInSalBitmap = aIcon.GetBitmap(); - AlphaMask pInSalAlpha = aIcon.GetAlpha(); - - if( pInSalBitmap.GetBitCount() != 24 ) - pInSalBitmap.Convert( BMP_CONVERSION_24BIT ); - - Bitmap::ScopedReadAccess pSalBitmap(pInSalBitmap); - AlphaMask::ScopedReadAccess pSalAlpha(pInSalAlpha); - - g_return_val_if_fail( pSalBitmap, NULL ); - - Size aSize( pSalBitmap->Width(), pSalBitmap->Height() ); - if (pSalAlpha) - g_return_val_if_fail( Size( pSalAlpha->Width(), pSalAlpha->Height() ) == aSize, NULL ); - - int nX, nY; - guchar *pPixbufData = static_cast(g_malloc( 4 * aSize.Width() * aSize.Height() )); - guchar *pDestData = pPixbufData; - - for( nY = 0; nY < pSalBitmap->Height(); nY++ ) - { - for( nX = 0; nX < pSalBitmap->Width(); nX++ ) - { - BitmapColor aPix; - aPix = pSalBitmap->GetPixel( nY, nX ); - pDestData[0] = aPix.GetRed(); - pDestData[1] = aPix.GetGreen(); - pDestData[2] = aPix.GetBlue(); - if (pSalAlpha) - { - aPix = pSalAlpha->GetPixel( nY, nX ); - pDestData[3] = 255 - aPix.GetIndex(); - } - else - pDestData[3] = 255; - pDestData += 4; - } - } - - return gdk_pixbuf_new_from_data( pPixbufData, - GDK_COLORSPACE_RGB, sal_True, 8, - aSize.Width(), aSize.Height(), - aSize.Width() * 4, - reinterpret_cast(g_free), - NULL ); -} - extern "C" { static void oustring_delete (gpointer data, GClosure * /* closure */) @@ -183,10 +127,24 @@ static void add_item( GtkMenuShell *pMenuShell, const char *pAsciiURL, RTL_TEXTENCODING_UTF8); } - GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_SMALL_START + nResId ); - GtkWidget *pImage = gtk_image_new_from_pixbuf( pPixbuf ); - g_object_unref( G_OBJECT( pPixbuf ) ); + gchar* appicon; + + if (nResId == SV_ICON_ID_TEXT) + appicon = g_strdup ("libreoffice-writer"); + else if (nResId == SV_ICON_ID_SPREADSHEET) + appicon = g_strdup ("libreoffice-calc"); + else if (nResId == SV_ICON_ID_DRAWING) + appicon = g_strdup ("libreoffice-draw"); + else if (nResId == SV_ICON_ID_PRESENTATION) + appicon = g_strdup ("libreoffice-impress"); + else if (nResId == SV_ICON_ID_DATABASE) + appicon = g_strdup ("libreoffice-base"); + else if (nResId == SV_ICON_ID_FORMULA) + appicon = g_strdup ("libreoffice-math"); + else + appicon = g_strdup ("libreoffice-main"); + GtkWidget *pImage = gtk_image_new_from_icon_name (appicon, GTK_ICON_SIZE_MENU); GtkWidget *pMenuItem = gtk_image_menu_item_new_with_label( aLabel.getStr() ); gtk_image_menu_item_set_image( GTK_IMAGE_MENU_ITEM( pMenuItem ), pImage ); g_signal_connect_data( pMenuItem, "activate", pFnCallback, pURL, @@ -383,9 +341,7 @@ void plugin_init_sys_tray() pVCLResMgr = ResMgr::CreateResMgr("vcl"); - GdkPixbuf *pPixbuf = ResIdToPixbuf( SV_ICON_SMALL_START + SV_ICON_ID_OFFICE ); - pTrayIcon = gtk_status_icon_new_from_pixbuf(pPixbuf); - g_object_unref( pPixbuf ); + pTrayIcon = gtk_status_icon_new_from_icon_name ("libreoffice-main"); g_object_set (pTrayIcon, "title", aLabel.getStr(), "tooltip_text", aLabel.getStr(), NULL); -- cgit