[Libreoffice-commits] core.git: sfx2/source vcl/inc vcl/source vcl/unx

Simon Steinbeiss simon.steinbeiss at elfenbeinturm.at
Mon Oct 26 13:23:58 UTC 2015


 sfx2/source/appl/shutdowniconunx.cxx |   80 ++++---------------
 vcl/inc/svids.hrc                    |    3 
 vcl/source/src/images.src            |  120 ----------------------------
 vcl/unx/gtk/window/gtksalframe.cxx   |  146 ++++-------------------------------
 4 files changed, 35 insertions(+), 314 deletions(-)

New commits:
commit ac5b2047ca72677d6beaf58ddaa8fdcda7236292
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Oct 26 13:41:32 2015 +0100

    Let Gtk handle icon names instead of ResMgr for window and trayicon
    
    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 <bjoern.michaelsen at canonical.com>
    Tested-by: Björn Michaelsen <bjoern.michaelsen at canonical.com>

diff --git a/sfx2/source/appl/shutdowniconunx.cxx b/sfx2/source/appl/shutdowniconunx.cxx
index 2de5654..fc2921c 100644
--- a/sfx2/source/appl/shutdowniconunx.cxx
+++ b/sfx2/source/appl/shutdowniconunx.cxx
@@ -27,8 +27,6 @@
 #include <glib.h>
 #include <osl/mutex.hxx>
 #include <osl/module.hxx>
-#include <vcl/bitmapex.hxx>
-#include <vcl/bmpacc.hxx>
 #include "tools/rc.hxx"
 #include <sfx2/app.hxx>
 #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<guchar *>(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<GdkPixbufDestroyNotify>(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);
diff --git a/vcl/inc/svids.hrc b/vcl/inc/svids.hrc
index f427b20..62e3203 100644
--- a/vcl/inc/svids.hrc
+++ b/vcl/inc/svids.hrc
@@ -181,9 +181,6 @@
 #define SV_ICON_SIZE32_START                21000
 #define SV_ICON_SIZE16_START                23000
 
-#define SV_ICON_LARGE_START                 24000
-#define SV_ICON_SMALL_START                 25000
-
 #define SV_ICON_ID_OFFICE                       1
 #define SV_ICON_ID_TEXT                         2
 #define SV_ICON_ID_TEXT_TEMPLATE                3
diff --git a/vcl/source/src/images.src b/vcl/source/src/images.src
index 8ab82c2..88d35c1 100644
--- a/vcl/source/src/images.src
+++ b/vcl/source/src/images.src
@@ -274,126 +274,6 @@ Bitmap (SV_ICON_SIZE16_START + SV_ICON_ID_TEMPLATE)
     File = "mainapp_16_8.png" ;
 };
 
-Bitmap (SV_ICON_LARGE_START)
-{
-    File = "mainapp_32.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START)
-{
-    File = "mainapp_16.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_OFFICE)
-{
-    File = "mainapp_32.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_OFFICE)
-{
-    File = "mainapp_16.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_TEXT)
-{
-    File = "lx03251.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_TEXT)
-{
-    File = "sx03251.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_TEXT_TEMPLATE)
-{
-    File = "lx03255.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_TEXT_TEMPLATE)
-{
-    File = "sx03255.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_SPREADSHEET)
-{
-    File = "lx03250.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_SPREADSHEET)
-{
-    File = "sx03250.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_SPREADSHEET_TEMPLATE)
-{
-    File = "lx03254.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_SPREADSHEET_TEMPLATE)
-{
-    File = "sx03254.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_DRAWING)
-{
-    File = "lx03246.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_DRAWING)
-{
-    File = "sx03246.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_PRESENTATION)
-{
-    File = "lx03249.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_PRESENTATION)
-{
-    File = "sx03249.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_MASTER_DOCUMENT)
-{
-    File = "lx03248.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_MASTER_DOCUMENT)
-{
-    File = "sx03248.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_DATABASE)
-{
-    File = "lx03245.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_DATABASE)
-{
-    File = "sx03245.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_FORMULA)
-{
-    File = "lx03247.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_FORMULA)
-{
-    File = "sx03247.png" ;
-};
-
-Bitmap (SV_ICON_LARGE_START + SV_ICON_ID_TEMPLATE)
-{
-    File = "lx03242.png" ;
-};
-
-Bitmap (SV_ICON_SMALL_START + SV_ICON_ID_TEMPLATE)
-{
-    File = "sx03242.png" ;
-};
-
 Bitmap SV_DISCLOSURE_PLUS
 {
     File = "plus.png";
diff --git a/vcl/unx/gtk/window/gtksalframe.cxx b/vcl/unx/gtk/window/gtksalframe.cxx
index e2d5507..fa6a31b 100644
--- a/vcl/unx/gtk/window/gtksalframe.cxx
+++ b/vcl/unx/gtk/window/gtksalframe.cxx
@@ -56,7 +56,6 @@
 
 #include <dlfcn.h>
 #include <vcl/salbtype.hxx>
-#include <vcl/bitmapex.hxx>
 #include <impbmp.hxx>
 #include <svids.hrc>
 #include <sal/macros.h>
@@ -1655,141 +1654,30 @@ getRow( BitmapBuffer *pBuffer, sal_uLong nRow )
         return pBuffer->mpBits + ( pBuffer->mnHeight - nRow - 1 ) * pBuffer->mnScanlineSize;
 }
 
-static GdkPixbuf *
-bitmapToPixbuf( SalBitmap *pSalBitmap, SalBitmap *pSalAlpha )
-{
-    g_return_val_if_fail( pSalBitmap != NULL, NULL );
-    g_return_val_if_fail( pSalAlpha != NULL, NULL );
-
-    BitmapBuffer *pBitmap = pSalBitmap->AcquireBuffer( BITMAP_READ_ACCESS );
-    g_return_val_if_fail( pBitmap != NULL, NULL );
-    g_return_val_if_fail( pBitmap->mnBitCount == 24 || pBitmap->mnBitCount == 32, NULL );
-
-    BitmapBuffer *pAlpha = pSalAlpha->AcquireBuffer( BITMAP_READ_ACCESS );
-    g_return_val_if_fail( pAlpha != NULL, NULL );
-    g_return_val_if_fail( pAlpha->mnBitCount == 8, NULL );
-
-    Size aSize = pSalBitmap->GetSize();
-    g_return_val_if_fail( pSalAlpha->GetSize() == aSize, NULL );
-
-    int nX, nY;
-    guchar *pPixbufData = static_cast<guchar *>(g_malloc (4 * aSize.Width() * aSize.Height() ));
-    guchar *pDestData = pPixbufData;
-
-    for( nY = 0; nY < pBitmap->mnHeight; nY++ )
-    {
-        sal_uInt8 *pData = getRow( pBitmap, nY );
-        sal_uInt8 *pAlphaData = getRow( pAlpha, nY );
-
-        for( nX = 0; nX < pBitmap->mnWidth; nX++ )
-        {
-            BitmapColor aColor;
-            if (pBitmap->mnFormat == BMP_FORMAT_24BIT_TC_BGR)
-            {
-                aColor = BitmapColor(pData[2], pData[1], pData[0]);
-                pData += 3;
-            }
-            else if (pBitmap->mnFormat == BMP_FORMAT_24BIT_TC_RGB)
-            {
-                aColor = BitmapColor(pData[0], pData[1], pData[2]);
-                pData += 3;
-            }
-            else
-            {
-                pBitmap->maColorMask.GetColorFor32Bit(aColor, pData);
-                pData += 4;
-            }
-            *pDestData++ = aColor.GetRed();
-            *pDestData++ = aColor.GetGreen();
-            *pDestData++ = aColor.GetBlue();
-            *pDestData++ = 255 - *pAlphaData++;
-        }
-    }
-
-    pSalBitmap->ReleaseBuffer( pBitmap, BITMAP_READ_ACCESS );
-    pSalAlpha->ReleaseBuffer( pAlpha, BITMAP_READ_ACCESS );
-
-    return gdk_pixbuf_new_from_data( pPixbufData,
-                                     GDK_COLORSPACE_RGB, true, 8,
-                                     aSize.Width(), aSize.Height(),
-                                     aSize.Width() * 4,
-                                     reinterpret_cast<GdkPixbufDestroyNotify>(g_free),
-                                     NULL );
-}
-
 void GtkSalFrame::SetIcon( sal_uInt16 nIcon )
 {
     if( (m_nStyle & (SalFrameStyleFlags::PLUG|SalFrameStyleFlags::SYSTEMCHILD|SalFrameStyleFlags::FLOAT|SalFrameStyleFlags::INTRO|SalFrameStyleFlags::OWNERDRAWDECORATION))
         || ! m_pWindow )
         return;
 
-    if( !ImplGetResMgr() )
-        return;
-
-    GdkPixbuf *pBuf;
-    GList *pIcons = NULL;
-
-    sal_uInt16 nOffsets[2] = { SV_ICON_SMALL_START, SV_ICON_LARGE_START };
-    sal_uInt16 nIndex;
-
-    for( nIndex = 0; nIndex < sizeof(nOffsets)/ sizeof(sal_uInt16); nIndex++ )
-    {
-        // #i44723# workaround gcc temporary problem
-        ResId aResId( nOffsets[nIndex] + nIcon, *ImplGetResMgr() );
-        BitmapEx aIcon( aResId );
-
-        // #i81083# convert to 24bit/8bit alpha bitmap
-        Bitmap aBmp = aIcon.GetBitmap();
-        if( aBmp.GetBitCount() != 24 || ! aIcon.IsAlpha() )
-        {
-            if( aBmp.GetBitCount() != 24 )
-                aBmp.Convert( BMP_CONVERSION_24BIT );
-            AlphaMask aMask;
-            if( ! aIcon.IsAlpha() )
-            {
-                switch( aIcon.GetTransparentType() )
-                {
-                    case TRANSPARENT_NONE:
-                    {
-                        sal_uInt8 nTrans = 0;
-                        aMask = AlphaMask( aBmp.GetSizePixel(), &nTrans );
-                    }
-                    break;
-                    case TRANSPARENT_COLOR:
-                        aMask = AlphaMask( aBmp.CreateMask( aIcon.GetTransparentColor() ) );
-                    break;
-                    case TRANSPARENT_BITMAP:
-                        aMask = AlphaMask( aIcon.GetMask() );
-                    break;
-                    default:
-                        OSL_FAIL( "unhandled transparent type" );
-                    break;
-                }
-            }
-            else
-                aMask = aIcon.GetAlpha();
-            aIcon = BitmapEx( aBmp, aMask );
-        }
-
-        ImpBitmap *pIconImpBitmap = aIcon.ImplGetBitmapImpBitmap();
-        ImpBitmap *pIconImpMask   = aIcon.ImplGetMaskImpBitmap();
-
-        if( pIconImpBitmap && pIconImpMask )
-        {
-            SalBitmap *pIconBitmap =
-                pIconImpBitmap->ImplGetSalBitmap();
-            SalBitmap *pIconMask =
-                pIconImpMask->ImplGetSalBitmap();
-
-            if( ( pBuf = bitmapToPixbuf( pIconBitmap, pIconMask ) ) )
-                pIcons = g_list_prepend( pIcons, pBuf );
-        }
-    }
-
-    gtk_window_set_icon_list( GTK_WINDOW(m_pWindow), pIcons );
+    gchar* appicon;
+
+    if (nIcon == SV_ICON_ID_TEXT)
+        appicon = g_strdup ("libreoffice-writer");
+    else if (nIcon == SV_ICON_ID_SPREADSHEET)
+        appicon = g_strdup ("libreoffice-calc");
+    else if (nIcon == SV_ICON_ID_DRAWING)
+        appicon = g_strdup ("libreoffice-draw");
+    else if (nIcon == SV_ICON_ID_PRESENTATION)
+        appicon = g_strdup ("libreoffice-impress");
+    else if (nIcon == SV_ICON_ID_DATABASE)
+        appicon = g_strdup ("libreoffice-base");
+    else if (nIcon == SV_ICON_ID_FORMULA)
+        appicon = g_strdup ("libreoffice-math");
+    else
+        appicon = g_strdup ("libreoffice-main");
 
-    g_list_foreach( pIcons, reinterpret_cast<GFunc>(g_object_unref), NULL );
-    g_list_free( pIcons );
+    gtk_window_set_icon_name (GTK_WINDOW (m_pWindow), appicon);
 }
 
 void GtkSalFrame::SetMenu( SalMenu* pSalMenu )


More information about the Libreoffice-commits mailing list