[Xfce4-commits] <xfce4-panel:nick/gtk3> Added GTK+-2 version if libxfce4panel.

Peter de Ridder noreply at xfce.org
Sun Mar 24 21:26:01 CET 2013


Updating branch refs/heads/nick/gtk3
         to cdbbcdceba06edfb5bfe92d7f1348a662debd534 (commit)
       from 12c8c133f9a08d350987f01ef3ada7824708a254 (commit)

commit cdbbcdceba06edfb5bfe92d7f1348a662debd534
Author: Peter de Ridder <peter at xfce.org>
Date:   Sun Mar 24 21:10:18 2013 +0100

    Added GTK+-2 version if libxfce4panel.

 configure.ac.in                                    |   15 +-
 libxfce4panel/Makefile.am                          |   57 ++++-
 libxfce4panel/libxfce4panel-1.0.pc.in              |    4 +-
 ...fce4panel-1.0.pc.in => libxfce4panel-2.0.pc.in} |    2 +-
 libxfce4panel/xfce-arrow-button.c                  |  108 +++++++
 libxfce4panel/xfce-hvbox.c                         |  306 ++++++++++++++++++++
 libxfce4panel/xfce-hvbox.h                         |   77 +++++
 libxfce4panel/xfce-panel-image.c                   |  111 +++++++-
 libxfce4panel/xfce-panel-plugin.c                  |   11 +
 9 files changed, 680 insertions(+), 11 deletions(-)

diff --git a/configure.ac.in b/configure.ac.in
index b8cecd0..28767b8 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -9,7 +9,7 @@ dnl ***************************
 dnl *** Version information ***
 dnl ***************************
 m4_define([libxfce4panel_verinfo], [4:0:0]) dnl current:revision:age
-m4_define([libxfce4panel_version_api], [1.0])
+m4_define([libxfce4panel_version_api], [2.0])
 m4_define([xfce4_panel_config_version], [2])
 m4_define([xfce4_panel_version_major], [4])
 m4_define([xfce4_panel_version_minor], [10])
@@ -138,6 +138,17 @@ XDT_CHECK_PACKAGE([DBUS], [dbus-glib-1], [0.73])
 XDT_CHECK_PACKAGE([CAIRO], [cairo], [1.0.0])
 XDT_CHECK_PACKAGE([LIBWNCK], [libwnck-3.0], [3.0])
 
+dnl ***********************************************************
+dnl *** Optional support for a GTK+2 version of the library ***
+dnl ***********************************************************
+XDT_CHECK_OPTIONAL_PACKAGE([GTK2],
+                           [gtk+-2.0], [2.20.0], [gtk2],
+                           [GTK+ 2 support])
+if "x$GTK2_FOUND" = "xyes" ; then
+    XDT_CHECK_PACKAGE([LIBXFCE4UI2], [libxfce4ui-1], [4.9.0])
+fi
+AM_CONDITIONAL([ENABLE_GTK2_LIBRARY], [test "x$GTK2_FOUND" = "xyes"])
+
 dnl **********************************
 dnl *** Optional GIO UNIX features ***
 dnl **********************************
@@ -227,6 +238,7 @@ icons/48x48/Makefile
 icons/scalable/Makefile
 libxfce4panel/Makefile
 libxfce4panel/libxfce4panel-1.0.pc
+libxfce4panel/libxfce4panel-2.0.pc
 libxfce4panel/libxfce4panel-config.h
 migrate/Makefile
 migrate/default.xml
@@ -255,4 +267,5 @@ echo "Build Configuration:"
 echo
 echo "* Debug Support:          $enable_debug"
 echo "* GNU Visibility:         $have_gnuc_visibility"
+echo "* GTK+ 2 Support:         $GTK2_FOUND"
 echo
diff --git a/libxfce4panel/Makefile.am b/libxfce4panel/Makefile.am
index 0da0b1d..029e7f4 100644
--- a/libxfce4panel/Makefile.am
+++ b/libxfce4panel/Makefile.am
@@ -7,7 +7,7 @@ AM_CPPFLAGS = \
 	$(PLATFORM_CPPFLAGS)
 
 lib_LTLIBRARIES = \
-	libxfce4panel-1.0.la
+	libxfce4panel-2.0.la
 
 libxfce4panel_public_built_sources = \
 	libxfce4panel-enum-types.h
@@ -39,7 +39,7 @@ libxfce4panel_include_HEADERS = \
 	$(libxfce4panel_public_built_sources) \
 	$(libxfce4panel_headers)
 
-libxfce4panel_1_0_la_SOURCES = \
+libxfce4panel_2_0_la_SOURCES = \
 	$(libxfce4panel_built_sources) \
 	$(libxfce4panel_headers) \
 	libxfce4panel-config.c \
@@ -49,19 +49,19 @@ libxfce4panel_1_0_la_SOURCES = \
 	xfce-panel-plugin-provider.c \
 	xfce-panel-image.c
 
-libxfce4panel_1_0_la_CFLAGS =	 \
+libxfce4panel_2_0_la_CFLAGS =	 \
 	$(GTK_CFLAGS) \
 	$(LIBXFCE4UTIL_CFLAGS) \
 	$(PLATFORM_CFLAGS)
 
-libxfce4panel_1_0_la_LDFLAGS = \
+libxfce4panel_2_0_la_LDFLAGS = \
 	-no-undefined \
 	-export-dynamic \
 	-version-info $(LIBXFCE4PANEL_VERINFO) \
 	-export-symbols-regex '^[^_].*' \
 	$(PLATFORM_LDFLAGS)
 
-libxfce4panel_1_0_la_LIBADD = \
+libxfce4panel_2_0_la_LIBADD = \
 	$(GTK_LIBS) \
 	$(LIBXFCE4UTIL_LIBS) \
 	-lm
@@ -73,6 +73,53 @@ pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = libxfce4panel-$(LIBXFCE4PANEL_VERSION_API).pc
 
 #
+# Gtk+ 2 support library
+#
+if ENABLE_GTK2_LIBRARY
+
+lib_LTLIBRARIES += libxfce4panel-1.0.la
+
+libxfce4panel1_includedir = \
+	$(includedir)/xfce4/libxfce4panel-1.0/libxfce4panel
+
+libxfce4panel1_include_HEADERS = \
+	$(libxfce4panel_public_built_sources) \
+	$(libxfce4panel_headers) \
+	xfce-hvbox.h
+
+libxfce4panel_1_0_la_SOURCES = \
+	$(libxfce4panel_built_sources) \
+	$(libxfce4panel_headers) \
+	libxfce4panel-config.c \
+	xfce-arrow-button.c \
+	xfce-hvbox.c \
+	xfce-panel-convenience.c \
+	xfce-panel-plugin.c \
+	xfce-panel-plugin-provider.c \
+	xfce-panel-image.c
+
+libxfce4panel_1_0_la_CFLAGS =	 \
+	$(GTK2_CFLAGS) \
+	$(LIBXFCE4UTIL_CFLAGS) \
+	$(PLATFORM_CFLAGS)
+
+libxfce4panel_1_0_la_LDFLAGS = \
+	-no-undefined \
+	-export-dynamic \
+	-version-info $(LIBXFCE4PANEL_VERINFO) \
+	-export-symbols-regex '^[^_].*' \
+	$(PLATFORM_LDFLAGS)
+
+libxfce4panel_1_0_la_LIBADD = \
+	$(GTK2_LIBS) \
+	$(LIBXFCE4UTIL_LIBS) \
+	-lm
+
+pkgconfig_DATA += libxfce4panel-1.0.pc
+
+endif
+
+#
 # Build sources
 #
 if MAINTAINER_MODE
diff --git a/libxfce4panel/libxfce4panel-1.0.pc.in b/libxfce4panel/libxfce4panel-1.0.pc.in
index a54205d..d30feda 100644
--- a/libxfce4panel/libxfce4panel-1.0.pc.in
+++ b/libxfce4panel/libxfce4panel-1.0.pc.in
@@ -8,5 +8,5 @@ Name: libxfce4panel
 Description: Library for the Xfce Panel
 Requires: gtk+-2.0 gmodule-2.0 glib-2.0 libxfce4util-1.0
 Version: @PACKAGE_VERSION@
-Libs: -L${libdir} -lxfce4panel- at LIBXFCE4PANEL_VERSION_API@
-Cflags: -I${includedir}/xfce4/libxfce4panel- at LIBXFCE4PANEL_VERSION_API@
+Libs: -L${libdir} -lxfce4panel-1.0
+Cflags: -I${includedir}/xfce4/libxfce4panel-1.0
diff --git a/libxfce4panel/libxfce4panel-1.0.pc.in b/libxfce4panel/libxfce4panel-2.0.pc.in
similarity index 85%
copy from libxfce4panel/libxfce4panel-1.0.pc.in
copy to libxfce4panel/libxfce4panel-2.0.pc.in
index a54205d..1358023 100644
--- a/libxfce4panel/libxfce4panel-1.0.pc.in
+++ b/libxfce4panel/libxfce4panel-2.0.pc.in
@@ -6,7 +6,7 @@ localedir=@localedir@
 
 Name: libxfce4panel
 Description: Library for the Xfce Panel
-Requires: gtk+-2.0 gmodule-2.0 glib-2.0 libxfce4util-1.0
+Requires: gtk+-3.0 gmodule-2.0 glib-2.0 libxfce4util-1.0
 Version: @PACKAGE_VERSION@
 Libs: -L${libdir} -lxfce4panel- at LIBXFCE4PANEL_VERSION_API@
 Cflags: -I${includedir}/xfce4/libxfce4panel- at LIBXFCE4PANEL_VERSION_API@
diff --git a/libxfce4panel/xfce-arrow-button.c b/libxfce4panel/xfce-arrow-button.c
index c4162ca..bbf2369 100644
--- a/libxfce4panel/xfce-arrow-button.c
+++ b/libxfce4panel/xfce-arrow-button.c
@@ -75,6 +75,7 @@ static void     xfce_arrow_button_get_property         (GObject               *o
                                                         GValue                *value,
                                                         GParamSpec            *pspec);
 static void     xfce_arrow_button_finalize             (GObject               *object);
+#if GTK_CHECK_VERSION (3, 0, 0)
 static gboolean xfce_arrow_button_draw                 (GtkWidget             *widget,
                                                         cairo_t               *cr);
 static void     xfce_arrow_button_get_preferred_width  (GtkWidget             *widget,
@@ -83,6 +84,12 @@ static void     xfce_arrow_button_get_preferred_width  (GtkWidget             *w
 static void     xfce_arrow_button_get_preferred_height (GtkWidget             *widget,
                                                         gint                  *minimal_height,
                                                         gint                  *natural_height);
+#else
+static gboolean xfce_arrow_button_expose_event         (GtkWidget             *widget,
+                                                        GdkEventExpose        *event);
+static void     xfce_arrow_button_size_request         (GtkWidget             *widget,
+                                                        GtkRequisition        *requisition);
+#endif
 static void     xfce_arrow_button_size_allocate        (GtkWidget             *widget,
                                                         GtkAllocation         *allocation);
 
@@ -128,9 +135,14 @@ xfce_arrow_button_class_init (XfceArrowButtonClass * klass)
   gobject_class->finalize = xfce_arrow_button_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
+#if GTK_CHECK_VERSION (3, 0, 0)
   gtkwidget_class->draw = xfce_arrow_button_draw;
   gtkwidget_class->get_preferred_width = xfce_arrow_button_get_preferred_width;
   gtkwidget_class->get_preferred_height = xfce_arrow_button_get_preferred_height;
+#else
+  gtkwidget_class->expose_event = xfce_arrow_button_expose_event;
+  gtkwidget_class->size_request = xfce_arrow_button_size_request;
+#endif
   gtkwidget_class->size_allocate = xfce_arrow_button_size_allocate;
 
   /**
@@ -246,6 +258,7 @@ xfce_arrow_button_finalize (GObject *object)
 
 
 
+#if GTK_CHECK_VERSION (3, 0, 0)
 static gboolean
 xfce_arrow_button_draw (GtkWidget *widget,
                         cairo_t   *cr)
@@ -381,6 +394,101 @@ xfce_arrow_button_get_preferred_height (GtkWidget *widget,
       *natural_height += ARROW_WIDTH;
     }
 }
+#endif
+
+
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+static gboolean
+xfce_arrow_button_expose_event (GtkWidget      *widget,
+                                GdkEventExpose *event)
+{
+  XfceArrowButton *button = XFCE_ARROW_BUTTON (widget);
+  GtkWidget       *child;
+  gint             x, y, width;
+
+  /* draw the button */
+  (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->expose_event) (widget, event);
+
+  if (button->priv->arrow_type != GTK_ARROW_NONE
+      && GTK_WIDGET_DRAWABLE (widget))
+    {
+      child = gtk_bin_get_child (GTK_BIN (widget));
+      if (child != NULL && GTK_WIDGET_VISIBLE (child))
+        {
+          if (button->priv->arrow_type == GTK_ARROW_UP
+              || button->priv->arrow_type == GTK_ARROW_DOWN)
+            {
+              width = ARROW_WIDTH;
+              x = widget->allocation.x + widget->style->xthickness;
+              y = widget->allocation.y + (widget->allocation.height - width) / 2;
+            }
+          else
+            {
+              width = ARROW_WIDTH;
+              x = widget->allocation.x + (widget->allocation.width - width) / 2;
+              y = widget->allocation.y + widget->style->ythickness;
+            }
+        }
+      else
+        {
+          width = MIN (widget->allocation.height - 2 * widget->style->ythickness,
+                       widget->allocation.width  - 2 * widget->style->xthickness);
+          width = CLAMP (width, 1, ARROW_WIDTH);
+
+          x = widget->allocation.x + (widget->allocation.width - width) / 2;
+          y = widget->allocation.y + (widget->allocation.height - width) / 2;
+        }
+
+      gtk_paint_arrow (widget->style, widget->window,
+                       GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
+                       &(event->area), widget, "xfce_arrow_button",
+                       button->priv->arrow_type, FALSE,
+                       x, y, width, width);
+    }
+
+  return TRUE;
+}
+
+
+
+static void
+xfce_arrow_button_size_request (GtkWidget      *widget,
+                                GtkRequisition *requisition)
+{
+  XfceArrowButton *button = XFCE_ARROW_BUTTON (widget);
+  GtkWidget *child;
+
+  child = gtk_bin_get_child (GTK_BIN (widget));
+  if (child != NULL && GTK_WIDGET_VISIBLE (child))
+    {
+      /* use gtk for the widget size */
+      (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->size_request) (widget, requisition);
+
+      /* reserve space for the arrow */
+      switch (button->priv->arrow_type)
+        {
+        case GTK_ARROW_UP:
+        case GTK_ARROW_DOWN:
+          requisition->width += ARROW_WIDTH;
+          break;
+
+        case GTK_ARROW_LEFT:
+        case GTK_ARROW_RIGHT:
+          requisition->height += ARROW_WIDTH;
+          break;
+
+        default:
+          break;
+        }
+    }
+  else if (button->priv->arrow_type != GTK_ARROW_NONE)
+    {
+      requisition->height = ARROW_WIDTH + 2 * widget->style->xthickness;
+      requisition->width = ARROW_WIDTH + 2 * widget->style->ythickness;
+    }
+}
+#endif
 
 
 
diff --git a/libxfce4panel/xfce-hvbox.c b/libxfce4panel/xfce-hvbox.c
new file mode 100644
index 0000000..33f482b
--- /dev/null
+++ b/libxfce4panel/xfce-hvbox.c
@@ -0,0 +1,306 @@
+/*
+ * This file is partly based on OBox
+ * Copyright (C) 2002      Red Hat Inc. based on GtkHBox
+ *
+ * Copyright (C) 2006-2007 Jasper Huijsmans <jasper at xfce.org>
+ * Copyright (C) 2006      Jani Monoses <jani at ubuntu.com>
+ * Copyright (C) 2007-2010 Nick Schermer <nick at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+
+#include <libxfce4panel/xfce-panel-macros.h>
+#include <libxfce4panel/xfce-hvbox.h>
+#include <libxfce4panel/libxfce4panel-alias.h>
+
+
+
+/**
+ * SECTION: xfce-hvbox
+ * @title: XfceHVBox
+ * @short_description: Container widget with configurable orientation
+ * @include: libxfce4panel/libxfce4panel.h
+ *
+ * #XfceHVBox is a #GtkBox widget that allows the user to change
+ * its orientation. It is in fact a combination of #GtkHBox and #GtkVBox.
+ *
+ * If your code depends on Gtk+ 2.16 or later, if it better to use
+ * the normal #GtkBox widgets in combination with
+ * gtk_orientable_set_orientation().
+ *
+ * See also: #GtkOrientable and #GtkBox.
+ **/
+
+
+
+#if !GTK_CHECK_VERSION (2, 16, 0)
+enum
+{
+  PROP_0,
+  PROP_ORIENTATION
+};
+
+static void      xfce_hvbox_get_property (GObject        *object,
+                                          guint           prop_id,
+                                          GValue         *value,
+                                          GParamSpec     *pspec);
+static void      xfce_hvbox_set_property (GObject        *object,
+                                          guint           prop_id,
+                                          const GValue   *value,
+                                          GParamSpec     *pspec);
+static gpointer xfce_hvbox_get_class     (XfceHVBox      *hvbox);
+static void     xfce_hvbox_size_request  (GtkWidget      *widget,
+                                          GtkRequisition *requisition);
+static void     xfce_hvbox_size_allocate (GtkWidget      *widget,
+                                          GtkAllocation  *allocation);
+#endif
+
+
+
+G_DEFINE_TYPE (XfceHVBox, xfce_hvbox, GTK_TYPE_BOX)
+
+
+
+static void
+xfce_hvbox_class_init (XfceHVBoxClass *klass)
+{
+#if !GTK_CHECK_VERSION (2, 16, 0)
+  GObjectClass   *gobject_class;
+  GtkWidgetClass *gtkwidget_class;
+
+  gobject_class = G_OBJECT_CLASS (klass);
+  gobject_class->get_property = xfce_hvbox_get_property;
+  gobject_class->set_property = xfce_hvbox_set_property;
+
+  gtkwidget_class = GTK_WIDGET_CLASS (klass);
+  gtkwidget_class->size_request  = xfce_hvbox_size_request;
+  gtkwidget_class->size_allocate = xfce_hvbox_size_allocate;
+
+  /**
+   * XfceHVBox:orientation:
+   *
+   * The orientation of the #XfceHVBox. When compiled with Gtk+ 2.16,
+   * this is the orientation property of the #GtkOrientable.
+   **/
+  g_object_class_install_property (gobject_class,
+                                   PROP_ORIENTATION,
+                                   g_param_spec_enum ("orientation",
+                                                      "Orientation",
+                                                      "Orientation of the box",
+                                                      GTK_TYPE_ORIENTATION,
+                                                      GTK_ORIENTATION_HORIZONTAL,
+                                                      G_PARAM_READWRITE
+                                                      | G_PARAM_STATIC_STRINGS));
+#endif
+}
+
+
+
+static void
+xfce_hvbox_init (XfceHVBox *hvbox)
+{
+  /* initialize variables */
+  hvbox->orientation = GTK_ORIENTATION_HORIZONTAL;
+}
+
+
+
+#if !GTK_CHECK_VERSION (2, 16, 0)
+static void
+xfce_hvbox_get_property (GObject    *object,
+                         guint       prop_id,
+                         GValue     *value,
+                         GParamSpec *pspec)
+{
+  XfceHVBox *hvbox = XFCE_HVBOX (object);
+
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      g_value_set_enum (value, hvbox->orientation);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+
+static void
+xfce_hvbox_set_property (GObject      *object,
+                         guint         prop_id,
+                         const GValue *value,
+                         GParamSpec   *pspec)
+{
+  XfceHVBox *hvbox = XFCE_HVBOX (object);
+
+  switch (prop_id)
+    {
+    case PROP_ORIENTATION:
+      xfce_hvbox_set_orientation (hvbox, g_value_get_enum (value));
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+
+static gpointer
+xfce_hvbox_get_class (XfceHVBox *hvbox)
+{
+  GType    type;
+  gpointer klass;
+
+  if (hvbox->orientation == GTK_ORIENTATION_HORIZONTAL)
+    type = GTK_TYPE_HBOX;
+  else
+    type = GTK_TYPE_VBOX;
+
+  /* peek the class, this only works if the class already exists */
+  klass = g_type_class_peek (type);
+
+  /* return the type or create the class */
+  return klass ? klass : g_type_class_ref (type);
+}
+
+
+
+static void
+xfce_hvbox_size_request (GtkWidget      *widget,
+                         GtkRequisition *requisition)
+{
+  gpointer klass;
+
+  /* get the widget class */
+  klass = xfce_hvbox_get_class (XFCE_HVBOX (widget));
+
+  /* request the size */
+  (*GTK_WIDGET_CLASS (klass)->size_request) (widget, requisition);
+}
+
+
+
+static void
+xfce_hvbox_size_allocate (GtkWidget     *widget,
+                          GtkAllocation *allocation)
+{
+  gpointer klass;
+
+  /* get the widget class */
+  klass = xfce_hvbox_get_class (XFCE_HVBOX (widget));
+
+  /* allocate the size */
+  (*GTK_WIDGET_CLASS (klass)->size_allocate) (widget, allocation);
+}
+#endif
+
+
+
+/**
+ * xfce_hvbox_new:
+ * @orientation : Orientation of the #XfceHVBox
+ * @homogeneous : whether all children should be allocated the same size
+ * @spacing     : spacing between #XfceHVBox children
+ *
+ * Creates a new #XfceHVBox container widget.
+ *
+ * Returns: the newly allocated #XfceHVBox container widget.
+ **/
+GtkWidget *
+xfce_hvbox_new (GtkOrientation orientation,
+                gboolean       homogeneous,
+                gint           spacing)
+{
+  XfceHVBox *box;
+
+  /* create new object */
+  box = g_object_new (XFCE_TYPE_HVBOX,
+#if GTK_CHECK_VERSION (2, 16, 0)
+                      "orientation", orientation,
+#endif
+                      "homogeneous", homogeneous,
+                      "spacing", spacing, NULL);
+
+  /* store the orientation */
+  box->orientation = orientation;
+
+  return GTK_WIDGET (box);
+}
+
+
+
+/**
+ * xfce_hvbox_set_orientation:
+ * @hvbox       : #XfceHVBox
+ * @orientation : the new orientation of the #XfceHVBox
+ *
+ * Set the new orientation of the #XfceHVBox container widget.
+ **/
+void
+xfce_hvbox_set_orientation (XfceHVBox      *hvbox,
+                            GtkOrientation  orientation)
+{
+  g_return_if_fail (XFCE_IS_HVBOX (hvbox));
+
+  if (G_LIKELY (hvbox->orientation != orientation))
+    {
+      /* store new orientation */
+      hvbox->orientation = orientation;
+
+#if GTK_CHECK_VERSION (2, 16, 0)
+      gtk_orientable_set_orientation (GTK_ORIENTABLE (hvbox), orientation);
+#else
+      gtk_widget_queue_resize (GTK_WIDGET (hvbox));
+#endif
+    }
+}
+
+
+
+/**
+ * xfce_hvbox_get_orientation:
+ * @hvbox       : #XfceHVBox
+ *
+ * Get the current orientation of the @hvbox.
+ *
+ * Returns: the current orientation of the #XfceHVBox.
+ **/
+GtkOrientation
+xfce_hvbox_get_orientation (XfceHVBox *hvbox)
+{
+  g_return_val_if_fail (XFCE_IS_HVBOX (hvbox), GTK_ORIENTATION_HORIZONTAL);
+
+#if GTK_CHECK_VERSION (2, 16, 0)
+  return gtk_orientable_get_orientation (GTK_ORIENTABLE (hvbox));
+#else
+  return hvbox->orientation;
+#endif
+}
+
+
+
+#define __XFCE_HVBOX_C__
+#include <libxfce4panel/libxfce4panel-aliasdef.c>
diff --git a/libxfce4panel/xfce-hvbox.h b/libxfce4panel/xfce-hvbox.h
new file mode 100644
index 0000000..f3b464c
--- /dev/null
+++ b/libxfce4panel/xfce-hvbox.h
@@ -0,0 +1,77 @@
+/*
+ * This file is partly based on OBox
+ * Copyright (C) 2002      Red Hat Inc. based on GtkHBox
+ *
+ * Copyright (C) 2006-2007 Jasper Huijsmans <jasper at xfce.org>
+ * Copyright (C) 2006      Jani Monoses <jani at ubuntu.com>
+ * Copyright (C) 2007-2010 Nick Schermer <nick at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/* #if !defined(LIBXFCE4PANEL_INSIDE_LIBXFCE4PANEL_H) && !defined(LIBXFCE4PANEL_COMPILATION)
+#error "Only <libxfce4panel/libxfce4panel.h> can be included directly, this file may disappear or change contents"
+#endif */
+
+#ifndef __XFCE_HVBOX_H__
+#define __XFCE_HVBOX_H__
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfceHVBoxClass XfceHVBoxClass;
+typedef struct _XfceHVBox      XfceHVBox;
+
+#define XFCE_TYPE_HVBOX            (xfce_hvbox_get_type())
+#define XFCE_HVBOX(obj)            (G_TYPE_CHECK_INSTANCE_CAST (obj, XFCE_TYPE_HVBOX, XfceHVBox))
+#define XFCE_HVBOX_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST (klass, XFCE_TYPE_HVBOX, XfceHVBoxClass))
+#define XFCE_IS_HVBOX(obj)         (G_TYPE_CHECK_INSTANCE_TYPE (obj, XFCE_TYPE_HVBOX))
+#define XFCE_IS_HVBOX_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_HVBOX))
+#define XFCE_HVBOX_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_HVBOX, XfceHVBoxClass))
+
+struct _XfceHVBoxClass
+{
+  /*< private >*/
+  GtkBoxClass __parent__;
+};
+
+/**
+ * XfceHVBox:
+ *
+ * This struct contain private data only and should be accessed by
+ * the functions below.
+ **/
+struct _XfceHVBox
+{
+  /*< private >*/
+  GtkBox __parent__;
+
+  GtkOrientation orientation;
+};
+
+GType           xfce_hvbox_get_type         (void) G_GNUC_CONST;
+
+GtkWidget      *xfce_hvbox_new              (GtkOrientation  orientation,
+                                             gboolean        homogeneous,
+                                             gint            spacing) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+void            xfce_hvbox_set_orientation  (XfceHVBox      *hvbox,
+                                             GtkOrientation  orientation);
+GtkOrientation  xfce_hvbox_get_orientation  (XfceHVBox      *hvbox);
+
+G_END_DECLS
+
+#endif /* !__XFCE_HVBOX_H__ */
diff --git a/libxfce4panel/xfce-panel-image.c b/libxfce4panel/xfce-panel-image.c
index 1945836..2c5ba5b 100644
--- a/libxfce4panel/xfce-panel-image.c
+++ b/libxfce4panel/xfce-panel-image.c
@@ -114,16 +114,26 @@ static void       xfce_panel_image_set_property         (GObject         *object
                                                          const GValue    *value,
                                                          GParamSpec      *pspec);
 static void       xfce_panel_image_finalize             (GObject         *object);
+#if GTK_CHECK_VERSION (3, 0, 0)
 static void       xfce_panel_image_get_preferred_width  (GtkWidget       *widget,
                                                          gint            *minimal_width,
                                                          gint            *natural_width);
 static void       xfce_panel_image_get_preferred_height (GtkWidget       *widget,
                                                          gint            *minimal_height,
                                                          gint            *natural_height);
+#else
+static void       xfce_panel_image_size_request         (GtkWidget       *widget,
+                                                         GtkRequisition  *requisition);
+#endif
 static void       xfce_panel_image_size_allocate        (GtkWidget       *widget,
                                                          GtkAllocation   *allocation);
+#if GTK_CHECK_VERSION (3, 0, 0)
 static gboolean   xfce_panel_image_draw                 (GtkWidget       *widget,
                                                          cairo_t         *cr);
+#else
+static gboolean   xfce_panel_image_expose_event         (GtkWidget       *widget,
+                                                         GdkEventExpose  *event);
+#endif
 static void       xfce_panel_image_style_set            (GtkWidget       *widget,
                                                          GtkStyle        *previous_style);
 static gboolean   xfce_panel_image_load                 (gpointer         data);
@@ -152,10 +162,18 @@ xfce_panel_image_class_init (XfcePanelImageClass *klass)
   gobject_class->finalize = xfce_panel_image_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
+#if GTK_CHECK_VERSION (3, 0, 0)
   gtkwidget_class->get_preferred_width = xfce_panel_image_get_preferred_width;
   gtkwidget_class->get_preferred_height = xfce_panel_image_get_preferred_height;
+#else
+  gtkwidget_class->size_request = xfce_panel_image_size_request;
+#endif
   gtkwidget_class->size_allocate = xfce_panel_image_size_allocate;
+#if GTK_CHECK_VERSION (3, 0, 0)
   gtkwidget_class->draw = xfce_panel_image_draw;
+#else
+  gtkwidget_class->expose_event = xfce_panel_image_expose_event;
+#endif
   gtkwidget_class->style_set = xfce_panel_image_style_set;
 
   g_object_class_install_property (gobject_class,
@@ -285,7 +303,8 @@ xfce_panel_image_finalize (GObject *object)
 
 
 
-static void       
+#if GTK_CHECK_VERSION (3, 0, 0)
+static void
 xfce_panel_image_get_preferred_width (GtkWidget *widget,
                                       gint      *minimal_width,
                                       gint      *natural_width)
@@ -308,7 +327,7 @@ xfce_panel_image_get_preferred_width (GtkWidget *widget,
 
 
 
-static void       
+static void
 xfce_panel_image_get_preferred_height (GtkWidget *widget,
                                        gint      *minimal_height,
                                        gint      *natural_height)
@@ -328,6 +347,34 @@ xfce_panel_image_get_preferred_height (GtkWidget *widget,
 
   *natural_height = *minimal_height;
 }
+#endif
+
+
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+static void
+xfce_panel_image_size_request (GtkWidget      *widget,
+                               GtkRequisition *requisition)
+{
+  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
+
+  if (priv->size > 0)
+    {
+      requisition->width = priv->size;
+      requisition->height = priv->size;
+    }
+  else if (priv->pixbuf != NULL)
+    {
+      requisition->width = gdk_pixbuf_get_width (priv->pixbuf);
+      requisition->height = gdk_pixbuf_get_height (priv->pixbuf);
+    }
+  else
+    {
+      requisition->width = widget->allocation.width;
+      requisition->height = widget->allocation.height;
+    }
+}
+#endif
 
 
 
@@ -369,6 +416,7 @@ xfce_panel_image_size_allocate (GtkWidget     *widget,
 
 
 
+#if GTK_CHECK_VERSION (3, 0, 0)
 static gboolean
 xfce_panel_image_draw (GtkWidget *widget,
                        cairo_t   *cr)
@@ -415,6 +463,65 @@ xfce_panel_image_draw (GtkWidget *widget,
 
   return FALSE;
 }
+#endif
+
+
+
+#if !GTK_CHECK_VERSION (3, 0, 0)
+static gboolean
+xfce_panel_image_expose_event (GtkWidget      *widget,
+                               GdkEventExpose *event)
+{
+  XfcePanelImagePrivate *priv = XFCE_PANEL_IMAGE (widget)->priv;
+  gint                   source_width, source_height;
+  gint                   dest_x, dest_y;
+  GtkIconSource         *source;
+  GdkPixbuf             *rendered = NULL;
+  GdkPixbuf             *pixbuf = priv->cache;
+  cairo_t               *cr;
+
+  if (G_LIKELY (pixbuf != NULL))
+    {
+      /* get the size of the cache pixbuf */
+      source_width = gdk_pixbuf_get_width (pixbuf);
+      source_height = gdk_pixbuf_get_height (pixbuf);
+
+      /* position */
+      dest_x = widget->allocation.x + (priv->width - source_width) / 2;
+      dest_y = widget->allocation.y + (priv->height - source_height) / 2;
+
+      if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
+        {
+          source = gtk_icon_source_new ();
+          gtk_icon_source_set_pixbuf (source, pixbuf);
+
+          rendered = gtk_style_render_icon (widget->style,
+                                            source,
+                                            gtk_widget_get_direction (widget),
+                                            GTK_WIDGET_STATE (widget),
+                                            -1, widget, "xfce-panel-image");
+          gtk_icon_source_free (source);
+
+          if (G_LIKELY (rendered != NULL))
+            pixbuf = rendered;
+        }
+
+      /* draw the pixbuf */
+      cr = gdk_cairo_create (gtk_widget_get_window (widget));
+      if (G_LIKELY (cr != NULL))
+        {
+          gdk_cairo_set_source_pixbuf (cr, pixbuf, dest_x, dest_y);
+          cairo_paint (cr);
+          cairo_destroy (cr);
+        }
+
+      if (rendered != NULL)
+        g_object_unref (G_OBJECT (rendered));
+    }
+
+  return FALSE;
+}
+#endif
 
 
 
diff --git a/libxfce4panel/xfce-panel-plugin.c b/libxfce4panel/xfce-panel-plugin.c
index 50607a5..336bdfe 100644
--- a/libxfce4panel/xfce-panel-plugin.c
+++ b/libxfce4panel/xfce-panel-plugin.c
@@ -28,7 +28,9 @@
 #endif
 
 #include <gtk/gtk.h>
+#if GTK_CHECK_VERSION (3, 0, 0)
 #include <gtk/gtkx.h>
+#endif
 #include <glib.h>
 #include <libxfce4util/libxfce4util.h>
 
@@ -2434,7 +2436,11 @@ xfce_panel_plugin_position_widget (XfcePanelPlugin *plugin,
     gtk_widget_realize (attach_widget);
 
   /* get the menu/widget size request */
+#if GTK_CHECK_VERSION (3, 0, 0)
   gtk_widget_get_preferred_size (menu_widget, &requisition, NULL);
+#else
+  gtk_widget_size_request (menu_widget, &requisition);
+#endif
 
   /* get the root position of the attach widget */
   toplevel = gtk_widget_get_toplevel (attach_widget);
@@ -2444,8 +2450,13 @@ xfce_panel_plugin_position_widget (XfcePanelPlugin *plugin,
   plug = gtk_widget_get_ancestor (attach_widget, GTK_TYPE_PLUG);
   if (plug != NULL)
     {
+#if GTK_CHECK_VERSION (3, 0, 0)
        gdk_window_get_geometry (gtk_plug_get_socket_window (GTK_PLUG (plug)),
                                 &px, &py, NULL, NULL);
+#else
+       gdk_window_get_geometry (gtk_plug_get_socket_window (GTK_PLUG (plug)),
+                                &px, &py, NULL, NULL, NULL);
+#endif
 
        *x += px;
        *y += py;


More information about the Xfce4-commits mailing list