[Goodies-commits] r6793 - in xfce4-notes-plugin/trunk: . panel-plugin

Mike Massonnet mmassonnet at xfce.org
Wed Feb 25 11:49:39 CET 2009


Author: mmassonnet
Date: 2009-02-25 10:49:39 +0000 (Wed, 25 Feb 2009)
New Revision: 6793

Added:
   xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.c
   xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.h
Modified:
   xfce4-notes-plugin/trunk/ChangeLog
   xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
   xfce4-notes-plugin/trunk/panel-plugin/color.c
   xfce4-notes-plugin/trunk/panel-plugin/notes.c
Log:
Replace the custom packed arrow button against XfceArrowButton

Modified: xfce4-notes-plugin/trunk/ChangeLog
===================================================================
--- xfce4-notes-plugin/trunk/ChangeLog	2009-02-25 10:28:24 UTC (rev 6792)
+++ xfce4-notes-plugin/trunk/ChangeLog	2009-02-25 10:49:39 UTC (rev 6793)
@@ -1,5 +1,21 @@
 2009-02-25  Mike Massonnet <mmassonnet at xfce.org>
 
+Replace the custom packed arrow button against XfceArrowButton
+	* panel-plugin/xfce-arrow-button.c, panel-plugin/xfce-arrow-button.h,
+	  panel-plugin/Makefile.am:
+	  - Import XfceArrowButton from Xfmpc (it was imported from Xfce4 Panel
+	  and contains a few modifications to be usable without apparent
+	  functions/callbacks for the panel)
+	* panel-plugin/notes.c(notes_window_new_with_label):
+	  - Use XfceArrowButton, the packed GtkArrow drawed poorly on some
+	  theme engines where the arrow had the color of the text which is
+	  basically the same as the background of the window thus invisible
+	  to the user
+	* panel-plugin/color.c:
+	  - Set default thickness to 1
+
+2009-02-25  Mike Massonnet <mmassonnet at xfce.org>
+
 Support for GTK+ < 2.14
 	* panel-plugin/color.c, panel-plugin/color.h:
 	  - Copy GTK function gtk_color_selection_dialog_get_color_selection

Modified: xfce4-notes-plugin/trunk/panel-plugin/Makefile.am
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2009-02-25 10:28:24 UTC (rev 6792)
+++ xfce4-notes-plugin/trunk/panel-plugin/Makefile.am	2009-02-25 10:49:39 UTC (rev 6793)
@@ -18,8 +18,10 @@
 
 xfce4_notes_plugin_SOURCES =						\
 	defines.h							\
+	xfce-arrow-button.c						\
+	xfce-arrow-button.h						\
+	color.c								\
 	color.h								\
-	color.c								\
 	panel-plugin.c							\
 	settings-dialog.c						\
 	settings-dialog.h						\

Modified: xfce4-notes-plugin/trunk/panel-plugin/color.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/color.c	2009-02-25 10:28:24 UTC (rev 6792)
+++ xfce4-notes-plugin/trunk/panel-plugin/color.c	2009-02-25 10:49:39 UTC (rev 6793)
@@ -38,8 +38,8 @@
 #define RC_STYLE \
   "gtk_color_scheme = \"notes_fg_color:#xxxxxxxxxxxx\\nnotes_bg_color:#xxxxxxxxxxxx\\nnotes_base_color:#xxxxxxxxxxxx\\nnotes_text_color:#xxxxxxxxxxxx\\nnotes_selected_bg_color:#xxxxxxxxxxxx\\nnotes_selected_fg_color:#xxxxxxxxxxxx\"\n" \
   "style \"notes-default\" {\n" \
-  "xthickness = 2\n" \
-  "ythickness = 2\n" \
+  "xthickness = 1\n" \
+  "ythickness = 1\n" \
   "fg[NORMAL] = @notes_fg_color\n" \
   "fg[ACTIVE] = @notes_fg_color\n" \
   "fg[PRELIGHT] = @notes_fg_color\n" \

Modified: xfce4-notes-plugin/trunk/panel-plugin/notes.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/notes.c	2009-02-25 10:28:24 UTC (rev 6792)
+++ xfce4-notes-plugin/trunk/panel-plugin/notes.c	2009-02-25 10:49:39 UTC (rev 6793)
@@ -35,6 +35,7 @@
 
 #include "defines.h"
 #include "notes.h"
+#include "xfce-arrow-button.h"
 
 #define PLUGIN_NAME "xfce4-notes-plugin"
 #define OPAQUE 0xffffffff
@@ -282,11 +283,10 @@
   gtk_widget_show (notes_window->title);
 
   /* Menu button */
-  notes_window->btn_menu = xfce_create_panel_toggle_button ();
+  notes_window->btn_menu = xfce_arrow_button_new (GTK_ARROW_DOWN);
+  gtk_button_set_relief (GTK_BUTTON (notes_window->btn_menu), GTK_RELIEF_NONE);
   gtk_widget_set_size_request (notes_window->btn_menu, 22, 22);
-  arrow_menu = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
-  gtk_container_add (GTK_CONTAINER (notes_window->btn_menu),
-                     arrow_menu);
+  g_object_set (notes_window->btn_menu, "can-focus", FALSE, NULL);
   gtk_box_pack_start (GTK_BOX (notes_window->hbox),
                       notes_window->btn_menu,
                       FALSE,

Added: xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.c
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.c	                        (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.c	2009-02-25 10:49:39 UTC (rev 6793)
@@ -0,0 +1,340 @@
+/*
+ * Copyright (c) 2004-2007 Jasper Huijsmans <jasper at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDIO_H
+#include <stdio.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <gtk/gtk.h>
+#include "xfce-arrow-button.h"
+
+#define ARROW_WIDTH          8
+#define ARROW_PADDING        2
+#define DEFAULT_ARROW_TYPE   GTK_ARROW_UP
+
+
+#ifndef _
+#define _(x) (x)
+#endif
+
+enum
+{
+    ARROW_TYPE_CHANGED,
+    LAST_SIGNAL
+};
+
+enum
+{
+    PROP_0,
+    PROP_ARROW_TYPE
+};
+
+static void   xfce_arrow_button_class_init    (XfceArrowButtonClass  *klass);
+static void   xfce_arrow_button_init          (XfceArrowButton       *button);
+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 gint   xfce_arrow_button_expose        (GtkWidget             *widget,
+                                               GdkEventExpose        *event);
+static void   xfce_arrow_button_size_request  (GtkWidget             *widget,
+                                               GtkRequisition        *requisition);
+static void   xfce_arrow_button_add           (GtkContainer          *container,
+                                               GtkWidget             *child);
+static GType  xfce_arrow_button_child_type    (GtkContainer          *container);
+
+
+
+/* global vars */
+static GtkToggleButtonClass *parent_class = NULL;
+static guint                 arrow_button_signals[LAST_SIGNAL] = { 0 };
+
+
+
+GType
+xfce_arrow_button_get_type (void)
+{
+    static GtkType type = G_TYPE_INVALID;
+
+    if (G_UNLIKELY (type == G_TYPE_INVALID))
+    {
+        static const GTypeInfo info =
+        {
+            sizeof (XfceArrowButtonClass),
+            (GBaseInitFunc) NULL,
+            (GBaseFinalizeFunc) NULL,
+            (GClassInitFunc) xfce_arrow_button_class_init,
+            (GClassFinalizeFunc) NULL,
+            NULL,
+            sizeof (XfceArrowButton),
+            0,
+            (GInstanceInitFunc) xfce_arrow_button_init,
+            NULL
+        };
+        type = g_type_register_static (GTK_TYPE_TOGGLE_BUTTON, "XfceArrowButton", &info, 0);
+    }
+
+    return type;
+}
+
+
+
+static void
+xfce_arrow_button_class_init (XfceArrowButtonClass * klass)
+{
+    GObjectClass      *gobject_class;
+    GtkWidgetClass    *widget_class;
+    GtkContainerClass *container_class;
+
+    parent_class = g_type_class_peek_parent (klass);
+
+    gobject_class = G_OBJECT_CLASS (klass);
+    gobject_class->get_property = xfce_arrow_button_get_property;
+    gobject_class->set_property = xfce_arrow_button_set_property;
+
+    widget_class = GTK_WIDGET_CLASS (klass);
+    widget_class->expose_event  = xfce_arrow_button_expose;
+    widget_class->size_request  = xfce_arrow_button_size_request;
+
+    container_class = GTK_CONTAINER_CLASS (klass);
+    container_class->add        = xfce_arrow_button_add;
+    container_class->child_type = xfce_arrow_button_child_type;
+
+    /* signals */
+
+    /**
+    * XfceArrowButton::arrow-type-changed
+    * @button: the object which emitted the signal
+    * @type: the new #GtkArrowType of the button
+    *
+    * Emitted when the arrow direction of the menu button changes.
+    * This value also determines the direction of the popup menu.
+    **/
+    arrow_button_signals[ARROW_TYPE_CHANGED] =
+        g_signal_new ("arrow-type-changed",
+                      G_OBJECT_CLASS_TYPE (klass),
+                      G_SIGNAL_RUN_FIRST,
+                      G_STRUCT_OFFSET (XfceArrowButtonClass, arrow_type_changed),
+                      NULL, NULL,
+                      g_cclosure_marshal_VOID__ENUM,
+                      G_TYPE_NONE, 1, GTK_TYPE_ARROW_TYPE);
+
+    /* properties */
+
+    /**
+     * XfceArrowButton:arrow-type
+     *
+     * The arrow type of the button. This value also determines the direction
+     * of the popup menu.
+     **/
+    g_object_class_install_property (gobject_class,
+                                     PROP_ARROW_TYPE,
+                                     g_param_spec_enum ("arrow-type",
+                                                        "Arrow type",
+                                                        "The arrow type of the menu button",
+                                                        GTK_TYPE_ARROW_TYPE,
+                                                        GTK_ARROW_UP,
+                                                        G_PARAM_READWRITE));
+}
+
+
+
+static void
+xfce_arrow_button_init (XfceArrowButton * arrow_button)
+{
+    GTK_WIDGET_SET_FLAGS (GTK_WIDGET (arrow_button), GTK_NO_WINDOW);
+
+    arrow_button->arrow_type = DEFAULT_ARROW_TYPE;
+}
+
+
+
+static void
+xfce_arrow_button_set_property (GObject      *object,
+                                guint         prop_id,
+                                const GValue *value,
+                                GParamSpec   *pspec)
+{
+    XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
+
+    switch (prop_id)
+    {
+        case PROP_ARROW_TYPE:
+            xfce_arrow_button_set_arrow_type (button, g_value_get_enum (value));
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+            break;
+    }
+}
+
+
+
+static void
+xfce_arrow_button_get_property (GObject    *object,
+                                guint       prop_id,
+                                GValue     *value,
+                                GParamSpec *pspec)
+{
+    XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
+
+    switch (prop_id)
+    {
+        case PROP_ARROW_TYPE:
+            g_value_set_enum (value, button->arrow_type);
+            break;
+        default:
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+            break;
+    }
+}
+
+
+
+static gint
+xfce_arrow_button_expose (GtkWidget      *widget,
+                          GdkEventExpose *event)
+{
+    gint x, y, w;
+
+    if (G_LIKELY (GTK_WIDGET_DRAWABLE (widget)))
+    {
+        w = MIN (widget->allocation.height - 2 * widget->style->ythickness,
+                 widget->allocation.width  - 2 * widget->style->xthickness);
+        w = MIN (w, ARROW_WIDTH);
+
+        x = widget->allocation.x + (widget->allocation.width - w) / 2;
+        y = widget->allocation.y + (widget->allocation.height - w) / 2;
+
+        GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
+
+        gtk_paint_arrow (widget->style, widget->window,
+                         GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
+                         &(event->area), widget, "xfce_arrow_button",
+                         XFCE_ARROW_BUTTON (widget)->arrow_type, FALSE,
+                         x, y, w, w);
+    }
+
+    return TRUE;
+}
+
+
+
+static void
+xfce_arrow_button_size_request (GtkWidget      *widget,
+                                GtkRequisition *requisition)
+{
+    gint size = ARROW_WIDTH + ARROW_PADDING +
+                2 * MAX (widget->style->xthickness, widget->style->ythickness);
+
+    requisition->width = requisition->height = size;
+}
+
+
+
+static void
+xfce_arrow_button_add (GtkContainer *container,
+                       GtkWidget    *child)
+{
+    g_warning ("XfceArrowButton cannot contain any children");
+}
+
+
+
+static GType
+xfce_arrow_button_child_type (GtkContainer *container)
+{
+    return GTK_TYPE_NONE;
+}
+
+
+
+/* public interface */
+
+/**
+ * xfce_arrow_button_new:
+ * @type : #GtkArrowType for the arrow button
+ *
+ * Creates a new #XfceArrowButton widget.
+ *
+ * Returns: The newly created #XfceArrowButton widget.
+ **/
+GtkWidget *
+xfce_arrow_button_new (GtkArrowType type)
+{
+    return g_object_new (XFCE_TYPE_ARROW_BUTTON, "arrow-type", type, NULL);
+}
+
+
+
+/**
+ * xfce_arrow_button_set_arrow_type:
+ * @button : a #XfceArrowButton
+ * @type   : a valid  #GtkArrowType
+ *
+ * Sets the arrow type for @button.
+ **/
+void
+xfce_arrow_button_set_arrow_type (XfceArrowButton *button,
+                                  GtkArrowType     type)
+{
+    g_return_if_fail (XFCE_IS_ARROW_BUTTON (button));
+
+    button->arrow_type = type;
+
+    g_signal_emit (button, arrow_button_signals[ARROW_TYPE_CHANGED], 0, type);
+
+    g_object_notify (G_OBJECT (button), "arrow_type");
+
+    gtk_widget_queue_draw (GTK_WIDGET (button));
+}
+
+
+
+/**
+ * xfce_arrow_button_get_arrow_type:
+ * @button : a #XfceArrowButton
+ *
+ * Returns the value of the ::arrow-type property.
+ *
+ * Returns: the #GtkArrowType of @button.
+ **/
+GtkArrowType
+xfce_arrow_button_get_arrow_type (XfceArrowButton *button)
+{
+    g_return_val_if_fail (XFCE_IS_ARROW_BUTTON (button), DEFAULT_ARROW_TYPE);
+
+    return button->arrow_type;
+}
+
+
+
+#define __XFCE_ARROW_BUTTON_C__
+

Added: xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.h
===================================================================
--- xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.h	                        (rev 0)
+++ xfce4-notes-plugin/trunk/panel-plugin/xfce-arrow-button.h	2009-02-25 10:49:39 UTC (rev 6793)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2004-2007 Jasper Huijsmans <jasper at xfce.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __XFCE_ARROW_BUTTON_H__
+#define __XFCE_ARROW_BUTTON_H__
+
+#include <gtk/gtkenums.h>
+#include <gtk/gtktogglebutton.h>
+
+G_BEGIN_DECLS
+
+typedef struct _XfceArrowButton      XfceArrowButton;
+typedef struct _XfceArrowButtonClass XfceArrowButtonClass;
+
+#define XFCE_TYPE_ARROW_BUTTON            (xfce_arrow_button_get_type ())
+#define XFCE_ARROW_BUTTON(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), XFCE_TYPE_ARROW_BUTTON, XfceArrowButton))
+#define XFCE_ARROW_BUTTON_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), XFCE_TYPE_ARROW_BUTTON, XfceArrowButtonClass))
+#define XFCE_IS_ARROW_BUTTON(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), XFCE_TYPE_ARROW_BUTTON))
+#define XFCE_IS_ARROW_BUTTON_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XFCE_TYPE_ARROW_BUTTON))
+#define XFCE_ARROW_BUTTON_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), XFCE_TYPE_ARROW_BUTTON, XfceArrowButtonClass))
+
+struct _XfceArrowButton
+{
+    GtkToggleButton parent;
+    GtkArrowType    arrow_type;
+};
+
+struct _XfceArrowButtonClass
+{
+    GtkToggleButtonClass parent_class;
+
+    /* signals */
+    void (*arrow_type_changed) (GtkWidget    *widget,
+                                GtkArrowType  type);
+};
+
+GType          xfce_arrow_button_get_type        (void) G_GNUC_CONST;
+
+GtkWidget     *xfce_arrow_button_new             (GtkArrowType      type) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+void           xfce_arrow_button_set_arrow_type  (XfceArrowButton  *button,
+                                                  GtkArrowType      type);
+
+GtkArrowType   xfce_arrow_button_get_arrow_type  (XfceArrowButton  *button);
+
+G_END_DECLS
+
+#endif /* !__XFCE_ARROW_BUTTON_H__ */




More information about the Goodies-commits mailing list