[Goodies-commits] r4783 - xfmpc/trunk/src
Mike Massonnet
mmassonnet at xfce.org
Sun May 11 20:08:39 CEST 2008
Author: mmassonnet
Date: 2008-05-11 18:08:39 +0000 (Sun, 11 May 2008)
New Revision: 4783
Added:
xfmpc/trunk/src/xfce-arrow-button.c
xfmpc/trunk/src/xfce-arrow-button.h
Modified:
xfmpc/trunk/src/Makefile.am
xfmpc/trunk/src/extended-interface.c
Log:
Replace the context button image against an arrow
* src/Makefile.am,
src/xfce-arrow-button.c,
src/xfce-arrow-button.h:
- Import XfceArrowButton from xfce4-panel with quick modifications
* src/extended-interface.c(xfmpc_extended_interface_init):
- Replace gtk_toggle_button_new against xfce_arrow_button_new
Modified: xfmpc/trunk/src/Makefile.am
===================================================================
--- xfmpc/trunk/src/Makefile.am 2008-05-11 18:08:32 UTC (rev 4782)
+++ xfmpc/trunk/src/Makefile.am 2008-05-11 18:08:39 UTC (rev 4783)
@@ -15,7 +15,9 @@
preferences.c \
preferences.h \
mpdclient.c \
- mpdclient.h
+ mpdclient.h \
+ xfce-arrow-button.c \
+ xfce-arrow-button.h
xfmpc_CFLAGS = \
@GTK_CFLAGS@ \
Modified: xfmpc/trunk/src/extended-interface.c
===================================================================
--- xfmpc/trunk/src/extended-interface.c 2008-05-11 18:08:32 UTC (rev 4782)
+++ xfmpc/trunk/src/extended-interface.c 2008-05-11 18:08:39 UTC (rev 4783)
@@ -169,15 +169,12 @@
gtk_button_set_image (GTK_BUTTON (widget), image);
/* Context menu */
- priv->context_button = gtk_toggle_button_new ();
+ priv->context_button = GTK_WIDGET (xfce_arrow_button_new (GTK_ARROW_DOWN));
gtk_widget_set_tooltip_text (priv->context_button, _("Context Menu"));
gtk_box_pack_start (GTK_BOX (hbox), priv->context_button, FALSE, FALSE, 0);
g_signal_connect (priv->context_button, "toggled",
G_CALLBACK (cb_context_menu), extended_interface);
- image = gtk_image_new_from_stock (GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
- gtk_button_set_image (GTK_BUTTON (priv->context_button), image);
-
/* Combo box */
priv->list_store = gtk_list_store_new (N_COLUMNS,
G_TYPE_STRING,
Added: xfmpc/trunk/src/xfce-arrow-button.c
===================================================================
--- xfmpc/trunk/src/xfce-arrow-button.c (rev 0)
+++ xfmpc/trunk/src/xfce-arrow-button.c 2008-05-11 18:08:39 UTC (rev 4783)
@@ -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: xfmpc/trunk/src/xfce-arrow-button.h
===================================================================
--- xfmpc/trunk/src/xfce-arrow-button.h (rev 0)
+++ xfmpc/trunk/src/xfce-arrow-button.h 2008-05-11 18:08:39 UTC (rev 4783)
@@ -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