[PATCH] [GTK3] Add button rendering

Lucas Baudin xapantu at gmail.com
Tue Aug 16 11:20:24 PDT 2011


---
 vcl/Library_vclplug_gtk3.mk                   |    1 +
 vcl/inc/unx/gtk/gtkgdi.hxx                    |   10 +++
 vcl/unx/gtk/window/gtkframe.cxx               |   13 ---
 vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx |  100 ++++++++++++++++++++++++-
 4 files changed, 109 insertions(+), 15 deletions(-)

diff --git a/vcl/Library_vclplug_gtk3.mk b/vcl/Library_vclplug_gtk3.mk
index 4642923..e71cb81 100644
--- a/vcl/Library_vclplug_gtk3.mk
+++ b/vcl/Library_vclplug_gtk3.mk
@@ -116,6 +116,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_gtk3,\
     vcl/unx/gtk3/app/gtk3gtksys \
     vcl/unx/gtk3/window/gtk3gtkframe \
     vcl/unx/gtk3/window/gtk3gtkobject \
+    vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk \
 ))
 
 ifeq ($(OS),LINUX)
diff --git a/vcl/inc/unx/gtk/gtkgdi.hxx b/vcl/inc/unx/gtk/gtkgdi.hxx
index 83d4aa8..47f4e34 100644
--- a/vcl/inc/unx/gtk/gtkgdi.hxx
+++ b/vcl/inc/unx/gtk/gtkgdi.hxx
@@ -47,6 +47,16 @@ class GtkSalFrame;
 class GtkSalGraphics : public X11SalGraphics {
 public:
     GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow );
+    virtual sal_Bool        drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
+                                           ControlState nState, const ImplControlValue& aValue,
+                                           const rtl::OUString& rCaption );
+    virtual sal_Bool        IsNativeControlSupported( ControlType nType, ControlPart nPart );
+    virtual sal_Bool        getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
+                                                const ImplControlValue& aValue, const rtl::OUString& rCaption,
+                                                Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion );
+private:
+    GtkWidget           *m_pWindow;
+    GtkStyleContext* m_buttonStyle;
 };
 #else
 
diff --git a/vcl/unx/gtk/window/gtkframe.cxx b/vcl/unx/gtk/window/gtkframe.cxx
index faa8a71..fb20689 100644
--- a/vcl/unx/gtk/window/gtkframe.cxx
+++ b/vcl/unx/gtk/window/gtkframe.cxx
@@ -3880,17 +3880,4 @@ gboolean GtkSalFrame::IMHandler::signalIMDeleteSurrounding( GtkIMContext*, gint
     return sal_False;
 }
 
-#ifdef GTK_GRAPHICS_DISABLED
-
-void GtkData::initNWF() {}
-void GtkData::deInitNWF() {}
-
-GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
-    : X11SalGraphics()
-{
-    Init( pFrame, GDK_WINDOW_XID( widget_get_window( pWindow ) ),
-          gdk_x11_screen_get_screen_number( gtk_widget_get_screen( pWindow ) ) );
-}
-
-#endif
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
index aa68cc2..637be5f 100644
--- a/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
+++ b/vcl/unx/gtk3/gdi/gtk3salnativewidgets-gtk.cxx
@@ -26,7 +26,103 @@
  * instead of those above.
  */
 
-#include "../../headless/svpdi.hxx"
-#include "../../headless/svpdi.hxx"
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_vcl.hxx"
+
+#include <unx/gtk/gtkframe.hxx>
+#include <unx/gtk/gtkdata.hxx>
+#include <unx/gtk/gtkinst.hxx>
+#include <unx/gtk/gtkgdi.hxx>
+
+/************************************************************************
+ * State conversion
+ ************************************************************************/
+static void NWConvertVCLStateToGTKState( ControlState nVCLState,
+            GtkStateFlags* nGTKState, GtkShadowType* nGTKShadow )
+{
+    *nGTKShadow = GTK_SHADOW_OUT;
+    *nGTKState = GTK_STATE_FLAG_INSENSITIVE;
+
+    if ( nVCLState & CTRL_STATE_ENABLED )
+    {
+        if ( nVCLState & CTRL_STATE_PRESSED )
+        {
+            *nGTKState = GTK_STATE_FLAG_ACTIVE;
+            *nGTKShadow = GTK_SHADOW_IN;
+        }
+        else if ( nVCLState & CTRL_STATE_ROLLOVER )
+        {
+            *nGTKState = GTK_STATE_FLAG_PRELIGHT;
+            *nGTKShadow = GTK_SHADOW_OUT;
+        }
+        else
+        {
+            *nGTKState = GTK_STATE_FLAG_NORMAL;
+            *nGTKShadow = GTK_SHADOW_OUT;
+        }
+    }
+}
+
+void GtkData::initNWF() {}
+void GtkData::deInitNWF() {}
+
+GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow )
+    : X11SalGraphics()
+{
+    m_pWindow = pWindow;
+    m_buttonStyle = NULL;
+    Init( pFrame, GDK_WINDOW_XID( widget_get_window( pWindow ) ),
+          gdk_x11_screen_get_screen_number( gtk_widget_get_screen( pWindow ) ) );
+}
+
+sal_Bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion,
+                                            ControlState nState, const ImplControlValue& aValue,
+                                            const rtl::OUString& rCaption )
+{
+    GtkStateFlags flags;
+    GtkShadowType shadow;
+    NWConvertVCLStateToGTKState(nState, &flags, &shadow);
+    cairo_t* cr = gdk_cairo_create(gtk_widget_get_window(m_pWindow));
+    switch(nType)
+    {
+    case CTRL_PUSHBUTTON:
+        if(!GTK_IS_STYLE_CONTEXT(m_buttonStyle))
+        {
+            m_buttonStyle = gtk_widget_get_style_context(gtk_button_new());
+        }
+
+        gtk_style_context_set_state(m_buttonStyle, flags);
+
+        gtk_render_background(m_buttonStyle, cr,
+                rControlRegion.Left(), rControlRegion.Top(),
+                rControlRegion.GetWidth(), rControlRegion.GetHeight());
+        gtk_render_frame(m_buttonStyle, cr,
+                rControlRegion.Left(), rControlRegion.Top(),
+                rControlRegion.GetWidth(), rControlRegion.GetHeight());
+
+        return sal_True;
+    default:
+        return sal_False;
+    }
+    cairo_destroy(cr);
+}
+
+sal_Bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState,
+                                                const ImplControlValue& aValue, const rtl::OUString& rCaption,
+                                                Rectangle &rNativeBoundingRegion, Rectangle &rNativeContentRegion )
+{
+    switch(nType)
+    {
+    default:
+        return sal_False;
+    }
+}
+
+sal_Bool GtkSalGraphics::IsNativeControlSupported( ControlType nType, ControlPart nPart )
+{
+    if(nType == CTRL_PUSHBUTTON)
+        return sal_True;
+    return sal_False;
+}
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
-- 
1.7.4.1


--=-Ly1FX1aWXZX/JbKBduka--



More information about the LibreOffice mailing list