1
/* vim: set expandtab ts=8 sw=4: */
3
/* $Id: xfce-arrow-button.c 23200 2006-09-24 08:57:47Z jasper $
5
* Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU Library General Public License as published
9
* by the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Library General Public License for more details.
17
* You should have received a copy of the GNU Library General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31
#include "xfce-marshal.h"
32
#include "xfce-panel-enum-types.h"
33
#include "xfce-arrow-button.h"
36
#define ARROW_PADDING 2
37
#define DEFAULT_ARROW_TYPE GTK_ARROW_UP
57
static void xfce_arrow_button_class_init (XfceArrowButtonClass * klass);
59
static void xfce_arrow_button_init (XfceArrowButton * button);
61
static void xfce_arrow_button_set_property (GObject * object,
66
static void xfce_arrow_button_get_property (GObject * object,
71
static int xfce_arrow_button_expose (GtkWidget * widget,
72
GdkEventExpose * event);
74
static void xfce_arrow_button_size_request (GtkWidget * widget,
75
GtkRequisition * requisition);
77
static void xfce_arrow_button_add (GtkContainer * container,
80
static GType xfce_arrow_button_child_type (GtkContainer * container);
85
static GtkToggleButtonClass *parent_class = NULL;
87
static guint arrow_button_signals[LAST_SIGNAL] = { 0 };
91
xfce_arrow_button_get_type (void)
93
static GtkType type = 0;
97
static const GTypeInfo type_info = {
98
sizeof (XfceArrowButtonClass),
100
(GBaseFinalizeFunc) NULL,
101
(GClassInitFunc) xfce_arrow_button_class_init,
102
(GClassFinalizeFunc) NULL,
104
sizeof (XfceArrowButton),
106
(GInstanceInitFunc) xfce_arrow_button_init,
110
type = g_type_register_static (GTK_TYPE_TOGGLE_BUTTON,
111
"XfceArrowButton", &type_info, 0);
119
xfce_arrow_button_class_init (XfceArrowButtonClass * klass)
121
GObjectClass *gobject_class;
122
GtkWidgetClass *widget_class;
123
GtkContainerClass *container_class;
125
parent_class = g_type_class_peek_parent (klass);
126
gobject_class = (GObjectClass *) klass;
127
widget_class = (GtkWidgetClass *) klass;
128
container_class = (GtkContainerClass *) klass;
130
gobject_class->get_property = xfce_arrow_button_get_property;
131
gobject_class->set_property = xfce_arrow_button_set_property;
133
widget_class->expose_event = xfce_arrow_button_expose;
134
widget_class->size_request = xfce_arrow_button_size_request;
136
container_class->add = xfce_arrow_button_add;
137
container_class->child_type = xfce_arrow_button_child_type;
142
* XfceArrowButton::arrow-type-changed
143
* @button: the object which emitted the signal
144
* @type: the new #GtkArrowType of the button
146
* Emitted when the arrow direction of the menu button changes.
147
* This value also determines the direction of the popup menu.
149
arrow_button_signals[ARROW_TYPE_CHANGED] =
150
g_signal_new ("arrow-type-changed",
151
G_OBJECT_CLASS_TYPE (klass),
153
G_STRUCT_OFFSET (XfceArrowButtonClass,
156
g_cclosure_marshal_VOID__ENUM,
157
G_TYPE_NONE, 1, GTK_TYPE_ARROW_TYPE);
162
* XfceArrowButton:arrow-type
164
* The arrow type of the button. This value also determines the direction
167
g_object_class_install_property (gobject_class,
169
g_param_spec_enum ("arrow-type",
171
"The arrow type of the menu button",
178
xfce_arrow_button_init (XfceArrowButton * arrow_button)
180
GTK_WIDGET_SET_FLAGS (GTK_WIDGET (arrow_button), GTK_NO_WINDOW);
182
arrow_button->arrow_type = DEFAULT_ARROW_TYPE;
186
xfce_arrow_button_set_property (GObject * object, guint prop_id,
187
const GValue * value, GParamSpec * pspec)
189
XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
193
case PROP_ARROW_TYPE:
194
xfce_arrow_button_set_arrow_type (button,
195
g_value_get_enum (value));
198
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
204
xfce_arrow_button_get_property (GObject * object,
205
guint prop_id, GValue * value,
208
XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
212
case PROP_ARROW_TYPE:
213
g_value_set_enum (value, button->arrow_type);
216
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
222
xfce_arrow_button_expose (GtkWidget * widget, GdkEventExpose *event)
224
if (GTK_WIDGET_DRAWABLE (widget))
228
w = MIN (widget->allocation.height - 2 * widget->style->ythickness,
229
widget->allocation.width - 2 * widget->style->xthickness);
231
w = MIN (w, ARROW_WIDTH);
233
x = widget->allocation.x + (widget->allocation.width - w) / 2;
235
y = widget->allocation.y + (widget->allocation.height - w) / 2;
237
GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
239
gtk_paint_arrow (widget->style, widget->window,
240
GTK_WIDGET_STATE (widget), GTK_SHADOW_NONE,
241
&(event->area), widget, "xfce_arrow_button",
242
XFCE_ARROW_BUTTON (widget)->arrow_type, FALSE,
250
xfce_arrow_button_size_request (GtkWidget * widget,
251
GtkRequisition * requisition)
253
int size = ARROW_WIDTH + ARROW_PADDING +
254
2 * MAX (widget->style->xthickness, widget->style->ythickness);
256
requisition->width = requisition->height = size;
259
static void xfce_arrow_button_add (GtkContainer * container, GtkWidget *child)
261
g_warning ("XfceArrowButton cannot contain any children");
264
static GType xfce_arrow_button_child_type (GtkContainer * container)
266
return GTK_TYPE_NONE;
270
/* public interface */
273
* xfce_arrow_button_new:
274
* @type : #GtkArrowType for the arrow button
276
* Returns: newly created #XfceArrowButton widget.
279
xfce_arrow_button_new (GtkArrowType type)
281
XfceArrowButton *button;
283
button = g_object_new (XFCE_TYPE_ARROW_BUTTON, "arrow_type", type, NULL);
285
return GTK_WIDGET (button);
289
* xfce_arrow_button_set_arrow_type:
290
* @button : an #XfceArrowButton
291
* @type : new #GtkArrowType to set
293
* Sets the arrow type for @button.
296
xfce_arrow_button_set_arrow_type (XfceArrowButton * button,
299
g_return_if_fail (XFCE_IS_ARROW_BUTTON (button));
301
button->arrow_type = type;
303
g_signal_emit (button, arrow_button_signals[ARROW_TYPE_CHANGED],
306
g_object_notify (G_OBJECT (button), "arrow_type");
308
gtk_widget_queue_draw (GTK_WIDGET (button));
312
* xfce_arrow_button_get_arrow_type:
313
* @button : an #XfceArrowButton
315
* Returns: the #GtkArrowType of @button.
318
xfce_arrow_button_get_arrow_type (XfceArrowButton * button)
320
g_return_val_if_fail (XFCE_IS_ARROW_BUTTON (button),
323
return button->arrow_type;