[Xfce4-commits] <xfce4-panel:nick/gtk3> Port the arrow button.

Nick Schermer noreply at xfce.org
Sun Mar 17 13:38:05 CET 2013


Updating branch refs/heads/nick/gtk3
         to 5fbae9e7610c038015d0bbb2bed50b5493c700a2 (commit)
       from 4bc82a149c8adb6de61f0e9b76e8a684c6fbd7da (commit)

commit 5fbae9e7610c038015d0bbb2bed50b5493c700a2
Author: Nick Schermer <nick at xfce.org>
Date:   Mon May 7 18:20:29 2012 +0200

    Port the arrow button.

 libxfce4panel/xfce-arrow-button.c |  108 +++++++++++++++++++++++++------------
 1 files changed, 74 insertions(+), 34 deletions(-)

diff --git a/libxfce4panel/xfce-arrow-button.c b/libxfce4panel/xfce-arrow-button.c
index 01eb2d2..a85fb17 100644
--- a/libxfce4panel/xfce-arrow-button.c
+++ b/libxfce4panel/xfce-arrow-button.c
@@ -66,21 +66,25 @@ enum
   PROP_ARROW_TYPE
 };
 
-static void     xfce_arrow_button_set_property  (GObject               *object,
-                                                 guint                  prop_id,
-                                                 const GValue          *value,
-                                                 GParamSpec            *pspec);
-static void     xfce_arrow_button_get_property  (GObject               *object,
-                                                 guint                  prop_id,
-                                                 GValue                *value,
-                                                 GParamSpec            *pspec);
-static void     xfce_arrow_button_finalize      (GObject               *object);
-static gboolean xfce_arrow_button_expose_event  (GtkWidget             *widget,
-                                                 GdkEventExpose        *event);
-static void     xfce_arrow_button_size_request  (GtkWidget             *widget,
-                                                 GtkRequisition        *requisition);
-static void     xfce_arrow_button_size_allocate (GtkWidget             *widget,
-                                                 GtkAllocation         *allocation);
+static void     xfce_arrow_button_set_property         (GObject               *object,
+                                                        guint                  prop_id,
+                                                        const GValue          *value,
+                                                        GParamSpec            *pspec);
+static void     xfce_arrow_button_get_property         (GObject               *object,
+                                                        guint                  prop_id,
+                                                        GValue                *value,
+                                                        GParamSpec            *pspec);
+static void     xfce_arrow_button_finalize             (GObject               *object);
+static gboolean xfce_arrow_button_draw                 (GtkWidget             *widget,
+                                                        cairo_t               *cr);
+static void     xfce_arrow_button_get_preferred_width  (GtkWidget             *widget,
+                                                        gint                  *minimal_width,
+                                                        gint                  *natural_width);
+static void     xfce_arrow_button_get_preferred_height (GtkWidget             *widget,
+                                                        gint                  *minimal_height,
+                                                        gint                  *natural_height);
+static void     xfce_arrow_button_size_allocate        (GtkWidget             *widget,
+                                                        GtkAllocation         *allocation);
 
 
 
@@ -124,8 +128,9 @@ xfce_arrow_button_class_init (XfceArrowButtonClass * klass)
   gobject_class->finalize = xfce_arrow_button_finalize;
 
   gtkwidget_class = GTK_WIDGET_CLASS (klass);
-  gtkwidget_class->expose_event = xfce_arrow_button_expose_event;
-  gtkwidget_class->size_request = xfce_arrow_button_size_request;
+  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;
   gtkwidget_class->size_allocate = xfce_arrow_button_size_allocate;
 
   /**
@@ -241,15 +246,15 @@ xfce_arrow_button_finalize (GObject *object)
 
 
 static gboolean
-xfce_arrow_button_expose_event (GtkWidget      *widget,
-                                GdkEventExpose *event)
+xfce_arrow_button_draw (GtkWidget *widget,
+                        cairo_t   *cr)
 {
   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);
+  (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->draw) (widget, cr);
 
   if (button->priv->arrow_type != GTK_ARROW_NONE
       && GTK_WIDGET_DRAWABLE (widget))
@@ -293,30 +298,65 @@ xfce_arrow_button_expose_event (GtkWidget      *widget,
 
 
 
-static void
-xfce_arrow_button_size_request (GtkWidget      *widget,
-                                GtkRequisition *requisition)
+static void     
+xfce_arrow_button_get_preferred_width (GtkWidget *widget,
+                                       gint      *minimal_width,
+                                       gint      *natural_width)
 {
   XfceArrowButton *button = XFCE_ARROW_BUTTON (widget);
-  GtkWidget *child;
+  GtkWidget       *child;
+
+  /* use gtk for the widget size */
+  (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->get_preferred_width) (widget, minimal_width, natural_width);
 
   child = gtk_bin_get_child (GTK_BIN (widget));
-  if (child != NULL && GTK_WIDGET_VISIBLE (child))
+  if (child != NULL 
+      && gtk_widget_get_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;
+          *minimal_width += ARROW_WIDTH;
+          *natural_width += ARROW_WIDTH;
+          break;
+
+        default:
           break;
+        }
+    }
+  else if (button->priv->arrow_type != GTK_ARROW_NONE)
+    {
+      *minimal_width += ARROW_WIDTH;
+      *natural_width += ARROW_WIDTH;
+    }
+}
+
 
-        case GTK_ARROW_LEFT:
-        case GTK_ARROW_RIGHT:
-          requisition->height += ARROW_WIDTH;
+
+static void     
+xfce_arrow_button_get_preferred_height (GtkWidget *widget,
+                                        gint      *minimal_height,
+                                        gint      *natural_height)
+{
+  XfceArrowButton *button = XFCE_ARROW_BUTTON (widget);
+  GtkWidget       *child;
+
+  /* use gtk for the widget size */
+  (*GTK_WIDGET_CLASS (xfce_arrow_button_parent_class)->get_preferred_height) (widget, minimal_height, natural_height);
+
+  child = gtk_bin_get_child (GTK_BIN (widget));
+  if (child != NULL 
+      && gtk_widget_get_visible (child))
+    {
+      /* reserve space for the arrow */
+      switch (button->priv->arrow_type)
+        {
+        case GTK_ARROW_UP:
+        case GTK_ARROW_DOWN:
+          *minimal_height += ARROW_WIDTH;
+          *natural_height += ARROW_WIDTH;
           break;
 
         default:
@@ -325,8 +365,8 @@ xfce_arrow_button_size_request (GtkWidget      *widget,
     }
   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;
+      *minimal_height += ARROW_WIDTH;
+      *natural_height += ARROW_WIDTH;
     }
 }
 


More information about the Xfce4-commits mailing list