[Libreoffice-commits] .: Branch 'feature/gtk3' - 4 commits - vcl/inc vcl/unx

Lucas Baudin lbaudin at kemper.freedesktop.org
Mon Oct 24 05:23:46 PDT 2011


 vcl/inc/unx/gtk/gtkgdi.hxx                    |   12 ++-
 vcl/inc/vcl/sysdata.hxx                       |    1 
 vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx |   90 ++++++++++++++++++++++----
 3 files changed, 85 insertions(+), 18 deletions(-)

New commits:
commit 38069129838811512e4dfc5ec459d46779bb96bf
Author: Lucas Baudin <xapantu at gmail.com>
Date:   Mon Oct 24 14:23:18 2011 +0200

    gtk3: add <cstddef> to vcl/inc/vcl/sysdata.hxx, it seems that g++ 4.6.1 doesn't like to have 'NULL' in plan C++ without this include

diff --git a/vcl/inc/vcl/sysdata.hxx b/vcl/inc/vcl/sysdata.hxx
index 59a174d..4e4e71f 100644
--- a/vcl/inc/vcl/sysdata.hxx
+++ b/vcl/inc/vcl/sysdata.hxx
@@ -30,6 +30,7 @@
 #define _SV_SYSDATA_HXX
 
 #include <vector>
+#include <cstddef>
 
 #ifdef QUARTZ
 // predeclare the native classes to avoid header/include problems
commit a94ac9b347f004d0dd7b793c1da8e14c6eef9e34
Author: Lucas Baudin <xapantu at gmail.com>
Date:   Sat Oct 22 18:07:07 2011 +0200

    gtk3: Use some static variable in GtkSalGraphics in order to avoid re-loading all GtkStylaContexts

diff --git a/vcl/inc/unx/gtk/gtkgdi.hxx b/vcl/inc/unx/gtk/gtkgdi.hxx
index 6ca6c47..4604751 100644
--- a/vcl/inc/unx/gtk/gtkgdi.hxx
+++ b/vcl/inc/unx/gtk/gtkgdi.hxx
@@ -66,16 +66,17 @@ public:
     void updateSettings( AllSettings& rSettings );
 private:
     GtkWidget       *mpWindow;
-    GtkStyleContext *mpButtonStyle;
-    GtkStyleContext *mpEntryStyle;
-    GtkStyleContext *mpScrollbarStyle;
-    GtkStyleContext *mpToolbarStyle;
-    GtkStyleContext *mpToolButtonStyle;
-    GtkStyleContext *mpCheckButtonStyle;
+    static GtkStyleContext *mpButtonStyle;
+    static GtkStyleContext *mpEntryStyle;
+    static GtkStyleContext *mpScrollbarStyle;
+    static GtkStyleContext *mpToolbarStyle;
+    static GtkStyleContext *mpToolButtonStyle;
+    static GtkStyleContext *mpCheckButtonStyle;
     void renderAreaToPix( cairo_t* cr, cairo_rectangle_t* rect );
     void drawStyleContext( GtkStyleContext* style, GtkStateFlags flags,
             const Rectangle& rControlRegion, bool render_background = true );
     void getStyleContext( GtkStyleContext** style, GtkWidget* widget );
+    static bool style_loaded;
 };
 
 #else
diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index a5877dd..fb88bc4 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -34,6 +34,13 @@
 #include <unx/gtk/gtkinst.hxx>
 #include <unx/gtk/gtkgdi.hxx>
 
+GtkStyleContext* GtkSalGraphics::mpButtonStyle = NULL;
+GtkStyleContext* GtkSalGraphics::mpEntryStyle = NULL;
+GtkStyleContext* GtkSalGraphics::mpScrollbarStyle = NULL;
+GtkStyleContext* GtkSalGraphics::mpToolbarStyle = NULL;
+GtkStyleContext* GtkSalGraphics::mpToolButtonStyle = NULL;
+GtkStyleContext* GtkSalGraphics::mpCheckButtonStyle = NULL;
+bool GtkSalGraphics::style_loaded = false;
 /************************************************************************
  * State conversion
  ************************************************************************/
@@ -107,11 +114,11 @@ void GtkSalGraphics::drawStyleContext( GtkStyleContext* style, GtkStateFlags fla
          */
         gtk_render_background(gtk_widget_get_style_context(mpWindow),
                 cr,
-                -2, -2,
-                rControlRegion.GetWidth() + 6, rControlRegion.GetHeight() + 6);
+                1, -2,
+                rControlRegion.GetWidth(), rControlRegion.GetHeight() + 6);
         gtk_render_background(mpToolbarStyle, cr,
-                -4, -4,
-                rControlRegion.GetWidth() + 8, rControlRegion.GetHeight() + 8);
+                1, -4,
+                rControlRegion.GetWidth(), rControlRegion.GetHeight() + 8);
     }
 
     gtk_style_context_set_state(style, flags);
@@ -556,7 +563,7 @@ void GtkSalGraphics::getStyleContext(GtkStyleContext** style, GtkWidget* widget)
 {
     *style = gtk_widget_get_style_context(widget);
     g_object_ref(*style);
-    //gtk_widget_destroy(widget);
+    gtk_widget_destroy(widget);
 }
 
 GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
@@ -565,6 +572,9 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
       mpWindow( pWindow )
 {
 
+    if(style_loaded)
+        return;
+    style_loaded = true;
     gtk_init(NULL, NULL);
     /* Load the GtkStyleContexts, it might be a bit slow, but usually,
      * gtk apps create a lot of widgets at startup, so, it shouldn't be
commit d8be64b02a5ec468a76fbbcab6afdb1f87329ecf
Author: Lucas Baudin <xapantu at gmail.com>
Date:   Sat Oct 22 17:45:27 2011 +0200

    gtk3: add toolbar rendering, there is some graphical bugs if you have more than one row in the toolbar (is it detectable in GtkSalGraphices?)

diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index b021036..a5877dd 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -92,7 +92,27 @@ void GtkSalGraphics::drawStyleContext( GtkStyleContext* style, GtkStateFlags fla
     rect.width = rControlRegion.GetWidth() + 2;
 
     if(render_background)
-        gtk_render_background(gtk_widget_get_style_context(mpWindow), cr, 0, 0, rControlRegion.GetWidth() + 2, rControlRegion.GetHeight() + 2);
+        gtk_render_background(gtk_widget_get_style_context(mpWindow),
+                cr,
+                0, 0,
+                rControlRegion.GetWidth() + 2, rControlRegion.GetHeight() + 2);
+    
+    else if(style == mpToolButtonStyle)
+    {
+        /* For toolbuttons, we need to re-draw the toolbar. We also need to re-draw
+         * the window background which is under the toolbar.
+         *
+         * FIXME: the width and height of the toolbar are hardcoded, it would be better
+         * if we could get the size, and the coords of the parent before re-drawing.
+         */
+        gtk_render_background(gtk_widget_get_style_context(mpWindow),
+                cr,
+                -2, -2,
+                rControlRegion.GetWidth() + 6, rControlRegion.GetHeight() + 6);
+        gtk_render_background(mpToolbarStyle, cr,
+                -4, -4,
+                rControlRegion.GetWidth() + 8, rControlRegion.GetHeight() + 8);
+    }
 
     gtk_style_context_set_state(style, flags);
 
@@ -136,7 +156,10 @@ sal_Bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart
             drawStyleContext(mpToolbarStyle, flags, rControlRegion);
             return sal_True;
         case PART_BUTTON:
-            drawStyleContext(mpToolButtonStyle, flags, rControlRegion);
+            /* For all checkbuttons in the toolbars */
+            flags = (GtkStateFlags)(flags |
+                    ( (aValue.getTristateVal() == BUTTONVALUE_ON) ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL));
+            drawStyleContext(mpToolButtonStyle, flags, rControlRegion, false);
             return sal_True;
         }
         break;
@@ -518,7 +541,9 @@ sal_Bool GtkSalGraphics::IsNativeControlSupported( ControlType nType, ControlPar
     if(   (nType == CTRL_PUSHBUTTON && nPart == PART_ENTIRE_CONTROL)
        || (nType == CTRL_CHECKBOX && nPart == PART_ENTIRE_CONTROL)
        || nType == CTRL_SCROLLBAR
-       || nType == CTRL_EDITBOX /*||
+       || nType == CTRL_EDITBOX
+       || (nType == CTRL_TOOLBAR && nPart == PART_ENTIRE_CONTROL)
+       || (nType == CTRL_TOOLBAR && nPart == PART_BUTTON)/*||
             segfault with recent code, needs investigating nType == CTRL_TOOLBAR*/ )
         return sal_True;
     return sal_False;
@@ -531,7 +556,7 @@ void GtkSalGraphics::getStyleContext(GtkStyleContext** style, GtkWidget* widget)
 {
     *style = gtk_widget_get_style_context(widget);
     g_object_ref(*style);
-    gtk_widget_destroy(widget);
+    //gtk_widget_destroy(widget);
 }
 
 GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
@@ -546,13 +571,25 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
      * too slow */
     GtkWidget* toolbar = gtk_toolbar_new();
     GtkWidget* toolbutton = gtk_button_new();
-    //gtk_container_add(GTK_CONTAINER(toolbar), GTK_WIDGET(toolbutton));
     getStyleContext(&mpEntryStyle, gtk_entry_new());
     getStyleContext(&mpButtonStyle, gtk_button_new());
     getStyleContext(&mpToolbarStyle, toolbar);
+    
     gtk_style_context_add_class(mpToolbarStyle, "primary-toolbar");
+    gtk_style_context_add_class(mpToolbarStyle, "toolbar");
     getStyleContext(&mpToolButtonStyle, GTK_WIDGET(toolbutton));
-    gtk_style_context_add_class(mpToolButtonStyle, "button"); /* TODO */
+
+    /* Create a widget path for our toolbutton widget */
+    GtkWidgetPath* path = gtk_widget_path_new ();
+    gtk_widget_path_append_type(path, GTK_TYPE_TOOLBAR);
+    gtk_widget_path_append_type(path, GTK_TYPE_TOOL_BUTTON);
+    gtk_widget_path_append_type(path, GTK_TYPE_BUTTON);
+
+    gtk_widget_path_iter_add_class (path, 0, "primary-toolbar");
+    gtk_widget_path_iter_add_class (path, 0, "toolbar");
+    gtk_widget_path_iter_add_class (path, 2, "button");
+    gtk_style_context_set_path(mpToolButtonStyle, path);
+
     getStyleContext(&mpScrollbarStyle, gtk_vscrollbar_new(NULL));
     getStyleContext(&mpCheckButtonStyle, gtk_check_button_new());
     gtk_style_context_add_class(mpCheckButtonStyle, "check");
commit 9a8c097459622e6436da87077efc5990c9002ba6
Author: Lucas Baudin <xapantu at gmail.com>
Date:   Fri Oct 21 22:21:39 2011 +0200

    gtk3: Use CheckBox style (there is still a problem with the hover stage)

diff --git a/vcl/inc/unx/gtk/gtkgdi.hxx b/vcl/inc/unx/gtk/gtkgdi.hxx
index 589a109..6ca6c47 100644
--- a/vcl/inc/unx/gtk/gtkgdi.hxx
+++ b/vcl/inc/unx/gtk/gtkgdi.hxx
@@ -71,6 +71,7 @@ private:
     GtkStyleContext *mpScrollbarStyle;
     GtkStyleContext *mpToolbarStyle;
     GtkStyleContext *mpToolButtonStyle;
+    GtkStyleContext *mpCheckButtonStyle;
     void renderAreaToPix( cairo_t* cr, cairo_rectangle_t* rect );
     void drawStyleContext( GtkStyleContext* style, GtkStateFlags flags,
             const Rectangle& rControlRegion, bool render_background = true );
diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index 6058924..b021036 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -96,19 +96,28 @@ void GtkSalGraphics::drawStyleContext( GtkStyleContext* style, GtkStateFlags fla
 
     gtk_style_context_set_state(style, flags);
 
-    gtk_render_background(style, cr,
-            1, 1,
-            rControlRegion.GetWidth(), rControlRegion.GetHeight());
-    gtk_render_frame(style, cr,
-            1, 1,
-            rControlRegion.GetWidth(), rControlRegion.GetHeight());
+    if(!(style == mpCheckButtonStyle))
+    {
+        gtk_render_background(style, cr,
+                1, 1,
+                rControlRegion.GetWidth(), rControlRegion.GetHeight());
+        gtk_render_frame(style, cr,
+                1, 1,
+                rControlRegion.GetWidth(), rControlRegion.GetHeight());
+    }
+    else
+    {
+        gtk_render_check(style, cr,
+                1, 1,
+                rControlRegion.GetWidth(), rControlRegion.GetHeight());
+    }
 
     renderAreaToPix(cr, &rect);
     cairo_destroy(cr);
 }
 
 sal_Bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
-                                            ControlState nState, const ImplControlValue&,
+                                            ControlState nState, const ImplControlValue& aValue,
                                             const rtl::OUString& )
 {
     GtkStateFlags flags;
@@ -131,6 +140,10 @@ sal_Bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart
             return sal_True;
         }
         break;
+    case CTRL_CHECKBOX:
+        flags = (GtkStateFlags)(flags | ( (aValue.getTristateVal() == BUTTONVALUE_ON) ? GTK_STATE_FLAG_ACTIVE : GTK_STATE_FLAG_NORMAL));
+        drawStyleContext(mpCheckButtonStyle, flags, rControlRegion);
+        return sal_True;
     case CTRL_PUSHBUTTON:
         drawStyleContext(mpButtonStyle, flags, rControlRegion);
         return sal_True;
@@ -502,7 +515,10 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings )
 
 sal_Bool GtkSalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
 {
-    if((nType == CTRL_PUSHBUTTON && nPart == PART_ENTIRE_CONTROL) || nType == CTRL_SCROLLBAR || nType == CTRL_EDITBOX /*||
+    if(   (nType == CTRL_PUSHBUTTON && nPart == PART_ENTIRE_CONTROL)
+       || (nType == CTRL_CHECKBOX && nPart == PART_ENTIRE_CONTROL)
+       || nType == CTRL_SCROLLBAR
+       || nType == CTRL_EDITBOX /*||
             segfault with recent code, needs investigating nType == CTRL_TOOLBAR*/ )
         return sal_True;
     return sal_False;
@@ -538,6 +554,8 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
     getStyleContext(&mpToolButtonStyle, GTK_WIDGET(toolbutton));
     gtk_style_context_add_class(mpToolButtonStyle, "button"); /* TODO */
     getStyleContext(&mpScrollbarStyle, gtk_vscrollbar_new(NULL));
+    getStyleContext(&mpCheckButtonStyle, gtk_check_button_new());
+    gtk_style_context_add_class(mpCheckButtonStyle, "check");
 }
 
 
@@ -567,7 +585,6 @@ void GtkSalGraphics::copyArea( long nDestX, long nDestY,
                                long nSrcWidth, long nSrcHeight,
                                sal_uInt16 nFlags )
 {
-    return;
     mpFrame->pushIgnoreDamage();
     SvpSalGraphics::copyArea( nDestX, nDestY, nSrcX, nSrcY, nSrcWidth, nSrcHeight, nFlags );
     mpFrame->popIgnoreDamage();


More information about the Libreoffice-commits mailing list