[sapwood] support GTK+ 2.x and GTK+ 3.x



commit d3c35c346a25156d5553aaf7134686be47a9b426
Author: Sven Herzberg <herzi gnome-de org>
Date:   Mon Jun 7 14:39:47 2010 +0200

    support GTK+ 2.x and GTK+ 3.x
    
    This patch adds a compile-time selection between GTK+ 2.x and GTK+ 3.x
    
    * configure.in: add "--with-gtk" (2,3,auto) to select the GTK+ platform
    * demos/buttonbox.c: stop using deprecated API
    * engine/Makefile.am: remove the definition of enginedir (this is in the
      platform detection in configure.in now)
    * engine/sapwood-style.c: stop using deprecated APIs
    * engine/sapwood-style.h: migrate to single include statements
    * protocol/Makefile.am: add a task to be implemented later
    * protocol/sapwood-proto.h: migrate to single include statements

 configure.in             |   42 ++++++++++++++++++++++++++++++-------
 demos/buttonbox.c        |    4 +-
 engine/Makefile.am       |    2 -
 engine/sapwood-style.c   |   51 ++++++++++++++++++++++++++++------------------
 engine/sapwood-style.h   |    7 +++--
 protocol/Makefile.am     |    1 +
 protocol/sapwood-proto.h |    3 +-
 7 files changed, 74 insertions(+), 36 deletions(-)
---
diff --git a/configure.in b/configure.in
index bd36a9b..409a3d3 100644
--- a/configure.in
+++ b/configure.in
@@ -89,16 +89,42 @@ dnl Initialize libtool
 AM_DISABLE_STATIC
 AM_PROG_LIBTOOL
 
-PKG_CHECK_MODULES(GTK, gtk+-2.0 >= 2.8)
+AC_ARG_WITH([gtk],AS_HELP_STRING([--with-gtk],[select version of GTK+ to build against @<:@2; 3; auto (default)@:>@])],
+            [],[with_gtk=auto])
+
+if test "$with_gtk" != "2"; then
+    PKG_CHECK_MODULES(GTK,[gtk+-3.0],[have_gtk3=yes],[have_gtk3=no])
+    if test "$with_gtk" != "auto" && test "$have_gtk3" = "no"; then
+        AC_MSG_ERROR([GTK+ 3.x was not found])
+    fi
+fi
+
+if test -z "$GTK_CFLAGS"; then
+    PKG_CHECK_MODULES(GTK,[gtk+-2.0 >= 2.8],[have_gtk2=yes],[have_gtk2=no])
+    if test "$with_gtk" != "auto" && test "$have_gtk2" = "no"; then
+        AC_MSG_ERROR([GTK+ 2.x was not found])
+    elif test "$have_gtk2" = "no"; then
+        AC_MSG_ERROR([neither GTK+ 2.x nor GTK+ 3.x was found])
+    fi
+fi
 
-GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
-AC_SUBST(GTK_CFLAGS)
-AC_SUBST(GTK_LIBS)
-AC_SUBST(GTK_VERSION)
+if test "${have_gtk2}" == "yes"; then
+    GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-2.0`
+    AC_SUBST(GTK_VERSION)
+    enginedir='$(libdir)/gtk-2.0/$(GTK_VERSION)/engines'
+    AC_SUBST(enginedir)
+    gdk_package=gdk-2.0
+fi
+
+if test "${have_gtk3}" == "yes"; then
+    GTK_VERSION=`$PKG_CONFIG --variable=gtk_binary_version gtk+-3.0`
+    AC_SUBST(GTK_VERSION)
+    enginedir='$(libdir)/gtk-3.0/$(GTK_VERSION)/engines'
+    AC_SUBST(enginedir)
+    gdk_package=gdk-3.0
+fi
 
-PKG_CHECK_MODULES(GDK, gdk-2.0 >= 1.3.12)
-AC_SUBST(GDK_CFLAGS)
-AC_SUBST(GDK_LIBS)
+PKG_CHECK_MODULES(GDK, $gdk_package)
 
 PKG_CHECK_MODULES(GIO,[gio-2.0])
 
diff --git a/demos/buttonbox.c b/demos/buttonbox.c
index dd1bf9d..22d853f 100644
--- a/demos/buttonbox.c
+++ b/demos/buttonbox.c
@@ -111,9 +111,9 @@ main (int argc, char **argv)
 
 	  widget = gtk_button_new_with_label (button->label);
 	  if (button->pack_end)
-	    gtk_box_pack_end_defaults (GTK_BOX (bbox), widget);
+	    gtk_box_pack_end (GTK_BOX (bbox), widget, TRUE, TRUE, 0);
 	  else
-	    gtk_box_pack_start_defaults (GTK_BOX (bbox), widget);
+	    gtk_container_add (GTK_CONTAINER (bbox), widget);
 	  gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (bbox), widget,
 					      button->is_secondary);
 	}
diff --git a/engine/Makefile.am b/engine/Makefile.am
index 095f298..3243621 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -4,8 +4,6 @@ INCLUDES = $(GTK_CFLAGS) \
 	   -DSAPWOOD_SERVER=\"$(daemondir)/sapwood-server\" \
 	   -I$(top_srcdir)/protocol
 
-enginedir = $(libdir)/gtk-2.0/$(GTK_VERSION)/engines
-
 engine_LTLIBRARIES=libsapwood.la
 noinst_LTLIBRARIES=libsapwood-client.la
 
diff --git a/engine/sapwood-style.c b/engine/sapwood-style.c
index a20de2c..9cbb2bb 100644
--- a/engine/sapwood-style.c
+++ b/engine/sapwood-style.c
@@ -36,6 +36,13 @@
 #define LOG(...)
 #endif
 
+#if !GTK_CHECK_VERSION(2,18,0)
+#define gtk_widget_get_state(w)    GTK_WIDGET_STATE(w)
+#define gtk_widget_has_focus(w)    GTK_WIDGET_HAS_FOCUS(w)
+#define gtk_widget_is_drawable(w)  GTK_WIDGET_DRAWABLE(w)
+#define gtk_widget_is_sensitive(w) GTK_WIDGET_IS_SENSITIVE(w)
+#endif
+
 G_DEFINE_DYNAMIC_TYPE (SapwoodStyle, sapwood_style, GTK_TYPE_STYLE);
 
 #ifdef ENABLE_DEBUG
@@ -189,8 +196,8 @@ check_child_position (GtkWidget      *child,
     {
       GtkWidget *widget = l->data;
 
-      if (!GTK_WIDGET_DRAWABLE (widget))
-	continue;
+      if (!gtk_widget_is_drawable (widget))
+        continue;
 
       /* XXX Should we consider the lower right corner instead, for
        * right/bottom? */
@@ -236,7 +243,7 @@ check_buttonbox_child_position (GtkWidget      *child,
       GtkBoxChild *child_info = l->data;
       GtkWidget *widget = child_info->widget;
 
-      if (child_info->is_secondary == secondary && GTK_WIDGET_DRAWABLE (widget))
+      if (child_info->is_secondary == secondary && gtk_widget_is_drawable (widget))
 	children = g_list_prepend (children, widget);
     }
 
@@ -797,6 +804,7 @@ draw_diamond (GtkStyle     *style,
       style, window, state, shadow, area, widget, detail, x, y, width, height);
 }
 
+#if !GTK_CHECK_VERSION(2,90,1)
 static void
 draw_string (GtkStyle     *style,
              GdkWindow    *window,
@@ -843,6 +851,7 @@ draw_string (GtkStyle     *style,
       gdk_gc_set_clip_rectangle (style->fg_gc[state], NULL);
     }
 }
+#endif
 
 static void
 maybe_check_submenu_state (GtkMenuItem    *menu_item,
@@ -864,7 +873,7 @@ maybe_check_submenu_state (GtkMenuItem    *menu_item,
       GtkWidget *sub_item;
 
       sub_item = GTK_MENU_SHELL (menu_item->submenu)->active_menu_item;
-      if (sub_item && GTK_WIDGET_STATE (sub_item) != GTK_STATE_NORMAL)
+      if (sub_item && gtk_widget_get_state (sub_item) != GTK_STATE_NORMAL)
 	match_data->state = GTK_STATE_SELECTED;
     }
 
@@ -873,22 +882,22 @@ maybe_check_submenu_state (GtkMenuItem    *menu_item,
    * menu items inside the hildon-desktop custom menu widget. */
   if (!GTK_IS_MENU (GTK_WIDGET (menu_item)->parent) &&
       !gtk_widget_is_focus (GTK_WIDGET (menu_item)) &&
-      GTK_WIDGET_STATE (menu_item) != GTK_STATE_NORMAL)
+      gtk_widget_get_state (GTK_WIDGET (menu_item)) != GTK_STATE_NORMAL)
     match_data->state = GTK_STATE_SELECTED;
 }
 
 static void
 draw_box (GtkStyle     *style,
-	  GdkWindow    *window,
- 	  GtkStateType  state,
- 	  GtkShadowType shadow,
- 	  GdkRectangle *area,
- 	  GtkWidget    *widget,
-	  const gchar  *detail,
-	  gint          x,
-	  gint          y,
-	  gint          width,
-	  gint          height)
+          GdkWindow    *window,
+          GtkStateType  state,
+          GtkShadowType shadow,
+          GdkRectangle *area,
+          GtkWidget    *widget,
+          const gchar  *detail,
+          gint          x,
+          gint          y,
+          gint          width,
+          gint          height)
 {
   ThemeMatchData match_data;
 
@@ -972,7 +981,7 @@ maybe_check_cursor_position (GtkTreeView *treeview,
    *   state    = SELECTED / NORMAL
    *   shadow   = NONE
    */
-  if (!GTK_WIDGET_HAS_FOCUS (treeview))
+  if (!gtk_widget_has_focus (GTK_WIDGET (treeview)))
     match_data->shadow = GTK_SHADOW_OUT;
 }
 
@@ -1005,10 +1014,10 @@ draw_flat_box (GtkStyle     *style,
   /* Hack because Gtk doesn't give us the correct widget state */
   if (widget && GTK_IS_ENTRY(widget))
   {
-    if (!GTK_WIDGET_IS_SENSITIVE(widget))
+    if (!gtk_widget_is_sensitive (widget))
       state = GTK_STATE_INSENSITIVE;
 
-    if (GTK_WIDGET_HAS_FOCUS(widget))
+    if (gtk_widget_has_focus (widget))
       state = GTK_STATE_ACTIVE;
   }
 
@@ -1065,7 +1074,7 @@ draw_check (GtkStyle     *style,
    * use the FOCUS rules, but this is not possible due to technical limitations
    * in how focus is drawn in sapwood */
   if (GTK_IS_CHECK_BUTTON (widget) &&
-      GTK_WIDGET_HAS_FOCUS (widget))
+      gtk_widget_has_focus (widget))
     match_data.state = GTK_STATE_ACTIVE;
 
   if (!draw_simple_image (style, window, area, widget, &match_data, TRUE,
@@ -1111,7 +1120,7 @@ draw_option (GtkStyle      *style,
    * use the FOCUS rules, but this is not possible due to technical limitations
    * in how focus is drawn in sapwood */
   if (GTK_IS_RADIO_BUTTON (widget) &&
-      GTK_WIDGET_HAS_FOCUS (widget))
+      gtk_widget_has_focus (widget))
     match_data.state = GTK_STATE_ACTIVE;
 
   if (!draw_simple_image (style, window, area, widget, &match_data, TRUE,
@@ -1662,7 +1671,9 @@ sapwood_style_class_init (SapwoodStyleClass *klass)
   style_class->draw_shadow = draw_shadow;
   style_class->draw_arrow = draw_arrow;
   style_class->draw_diamond = draw_diamond;
+#if !GTK_CHECK_VERSION(2,90,1)
   style_class->draw_string = draw_string;
+#endif
   style_class->draw_box = draw_box;
   style_class->draw_flat_box = draw_flat_box;
   style_class->draw_check = draw_check;
diff --git a/engine/sapwood-style.h b/engine/sapwood-style.h
index 009fe77..05ebfda 100644
--- a/engine/sapwood-style.h
+++ b/engine/sapwood-style.h
@@ -1,6 +1,7 @@
 /* GTK+ Sapwood Engine
  * Copyright (C) 1998-2000 Red Hat, Inc.
  * Copyright (C) 2005 Nokia Corporation
+ * Copyright (C) 2010 Sven Herzberg
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -17,15 +18,15 @@
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  *
- * Written by Tommi Komulainen <tommi komulainen nokia com> based on 
- * code by Owen Taylor <otaylor redhat com> and 
+ * Written by Tommi Komulainen <tommi komulainen nokia com> based on
+ * code by Owen Taylor <otaylor redhat com> and
  * Carsten Haitzler <raster rasterman com>
  */
 
 #ifndef __SAPWOOD_STYLE_H__
 #define __SAPWOOD_STYLE_H__
 
-#include <gtk/gtkstyle.h>
+#include <gtk/gtk.h>
 
 typedef struct _SapwoodStyle SapwoodStyle;
 typedef struct _SapwoodStyleClass SapwoodStyleClass;
diff --git a/protocol/Makefile.am b/protocol/Makefile.am
index 1d9f9ce..ca5cdce 100644
--- a/protocol/Makefile.am
+++ b/protocol/Makefile.am
@@ -1,5 +1,6 @@
 include $(top_srcdir)/Makefile.decl
 
+# FIXME: use a path header for the server
 INCLUDES = \
     $(GTK_CFLAGS) \
     -DSAPWOOD_SERVER=\"$(daemondir)/sapwood-server\"
diff --git a/protocol/sapwood-proto.h b/protocol/sapwood-proto.h
index 5412937..0d3242e 100644
--- a/protocol/sapwood-proto.h
+++ b/protocol/sapwood-proto.h
@@ -1,5 +1,6 @@
 /* GTK+ Sapwood Engine
  * Copyright (C) 2005 Nokia Corporation
+ * Copyright (C) 2010 Sven Herzberg
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -22,7 +23,7 @@
 #ifndef PIXBUF_PROTO_H
 #define PIXBUF_PROTO_H 1
 
-#include <gdk/gdktypes.h>
+#include <gdk/gdk.h>
 
 G_BEGIN_DECLS
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]