~ubuntu-branches/debian/experimental/xfce4-panel/experimental

« back to all changes in this revision

Viewing changes to libxfce4panel/xfce-arrow-button.c

  • Committer: Bazaar Package Importer
  • Author(s): Yves-Alexis Perez
  • Date: 2008-05-19 08:08:22 UTC
  • mfrom: (1.1.16 upstream)
  • Revision ID: james.westby@ubuntu.com-20080519080822-c8ptdv1s8o9r4ou0
Tags: 4.4.2-6
* switch to triggers:
  - debian/postinst: remove xfce-mcs-manager refresh.
  - debian/prerm dropped.
  - debian/control: conflicts against non-triggers-enable xfce4-mcs-manager.
* debian/control: remove useless Conflicts/Replaces against Sarge stuff.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* vim: set expandtab ts=8 sw=4: */
 
2
 
 
3
/*  $Id: xfce-arrow-button.c 23200 2006-09-24 08:57:47Z jasper $
 
4
 *
 
5
 *  Copyright © 2004-2005 Jasper Huijsmans <jasper@xfce.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include <config.h>
 
24
#endif
 
25
 
 
26
#include <stdio.h>
 
27
#include <string.h>
 
28
 
 
29
#include <gtk/gtk.h>
 
30
 
 
31
#include "xfce-marshal.h"
 
32
#include "xfce-panel-enum-types.h"
 
33
#include "xfce-arrow-button.h"
 
34
 
 
35
#define ARROW_WIDTH          8
 
36
#define ARROW_PADDING        2
 
37
#define DEFAULT_ARROW_TYPE   GTK_ARROW_UP
 
38
 
 
39
 
 
40
#ifndef _
 
41
#define _(x) (x)
 
42
#endif
 
43
 
 
44
enum
 
45
{
 
46
    ARROW_TYPE_CHANGED,
 
47
    LAST_SIGNAL
 
48
};
 
49
 
 
50
enum
 
51
{
 
52
    PROP_0,
 
53
    PROP_ARROW_TYPE
 
54
};
 
55
 
 
56
 
 
57
static void xfce_arrow_button_class_init   (XfceArrowButtonClass * klass);
 
58
 
 
59
static void xfce_arrow_button_init         (XfceArrowButton * button);
 
60
 
 
61
static void xfce_arrow_button_set_property (GObject * object,
 
62
                                            guint prop_id,
 
63
                                            const GValue * value,
 
64
                                            GParamSpec * pspec);
 
65
 
 
66
static void xfce_arrow_button_get_property (GObject * object,
 
67
                                            guint prop_id,
 
68
                                            GValue * value, 
 
69
                                            GParamSpec * pspec);
 
70
 
 
71
static int xfce_arrow_button_expose        (GtkWidget * widget,
 
72
                                            GdkEventExpose * event);
 
73
 
 
74
static void xfce_arrow_button_size_request (GtkWidget * widget,
 
75
                                            GtkRequisition * requisition);
 
76
 
 
77
static void xfce_arrow_button_add          (GtkContainer * container, 
 
78
                                            GtkWidget *child);
 
79
 
 
80
static GType xfce_arrow_button_child_type  (GtkContainer * container);
 
81
 
 
82
 
 
83
    
 
84
/* global vars */
 
85
static GtkToggleButtonClass *parent_class = NULL;
 
86
 
 
87
static guint arrow_button_signals[LAST_SIGNAL] = { 0 };
 
88
 
 
89
 
 
90
GType
 
91
xfce_arrow_button_get_type (void)
 
92
{
 
93
    static GtkType type = 0;
 
94
 
 
95
    if (!type)
 
96
    {
 
97
        static const GTypeInfo type_info = {
 
98
            sizeof (XfceArrowButtonClass),
 
99
            (GBaseInitFunc) NULL,
 
100
            (GBaseFinalizeFunc) NULL,
 
101
            (GClassInitFunc) xfce_arrow_button_class_init,
 
102
            (GClassFinalizeFunc) NULL,
 
103
            NULL,
 
104
            sizeof (XfceArrowButton),
 
105
            0,                  /* n_preallocs */
 
106
            (GInstanceInitFunc) xfce_arrow_button_init,
 
107
            NULL
 
108
        };
 
109
 
 
110
        type = g_type_register_static (GTK_TYPE_TOGGLE_BUTTON,
 
111
                                       "XfceArrowButton", &type_info, 0);
 
112
    }
 
113
 
 
114
    return type;
 
115
}
 
116
 
 
117
 
 
118
static void
 
119
xfce_arrow_button_class_init (XfceArrowButtonClass * klass)
 
120
{
 
121
    GObjectClass *gobject_class;
 
122
    GtkWidgetClass *widget_class;
 
123
    GtkContainerClass *container_class;
 
124
 
 
125
    parent_class    = g_type_class_peek_parent (klass);
 
126
    gobject_class   = (GObjectClass *) klass;
 
127
    widget_class    = (GtkWidgetClass *) klass;
 
128
    container_class = (GtkContainerClass *) klass;
 
129
 
 
130
    gobject_class->get_property = xfce_arrow_button_get_property;
 
131
    gobject_class->set_property = xfce_arrow_button_set_property;
 
132
 
 
133
    widget_class->expose_event  = xfce_arrow_button_expose;    
 
134
    widget_class->size_request  = xfce_arrow_button_size_request;    
 
135
    
 
136
    container_class->add        = xfce_arrow_button_add;
 
137
    container_class->child_type = xfce_arrow_button_child_type;
 
138
 
 
139
    /* signals */
 
140
 
 
141
    /**
 
142
    * XfceArrowButton::arrow-type-changed
 
143
    * @button: the object which emitted the signal
 
144
    * @type: the new #GtkArrowType of the button
 
145
    *
 
146
    * Emitted when the arrow direction of the menu button changes.
 
147
    * This value also determines the direction of the popup menu.
 
148
    **/
 
149
    arrow_button_signals[ARROW_TYPE_CHANGED] =
 
150
        g_signal_new ("arrow-type-changed",
 
151
                      G_OBJECT_CLASS_TYPE (klass),
 
152
                      G_SIGNAL_RUN_FIRST,
 
153
                      G_STRUCT_OFFSET (XfceArrowButtonClass, 
 
154
                                       arrow_type_changed),
 
155
                      NULL, NULL,
 
156
                      g_cclosure_marshal_VOID__ENUM,
 
157
                      G_TYPE_NONE, 1, GTK_TYPE_ARROW_TYPE);
 
158
 
 
159
    /* properties */
 
160
 
 
161
    /**
 
162
     * XfceArrowButton:arrow-type
 
163
     *
 
164
     * The arrow type of the button. This value also determines the direction
 
165
     * of the popup menu.
 
166
     **/
 
167
    g_object_class_install_property (gobject_class, 
 
168
            PROP_ARROW_TYPE, 
 
169
            g_param_spec_enum ("arrow-type",
 
170
                               "Arrow type",
 
171
                               "The arrow type of the menu button",
 
172
                               GTK_TYPE_ARROW_TYPE,
 
173
                               GTK_ARROW_UP, 
 
174
                               G_PARAM_READWRITE));
 
175
}
 
176
 
 
177
static void
 
178
xfce_arrow_button_init (XfceArrowButton * arrow_button)
 
179
{
 
180
    GTK_WIDGET_SET_FLAGS (GTK_WIDGET (arrow_button), GTK_NO_WINDOW);
 
181
 
 
182
    arrow_button->arrow_type = DEFAULT_ARROW_TYPE;
 
183
}
 
184
 
 
185
static void
 
186
xfce_arrow_button_set_property (GObject * object, guint prop_id,
 
187
                                const GValue * value, GParamSpec * pspec)
 
188
{
 
189
    XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
 
190
 
 
191
    switch (prop_id)
 
192
    {
 
193
        case PROP_ARROW_TYPE:
 
194
            xfce_arrow_button_set_arrow_type (button, 
 
195
                                              g_value_get_enum (value));
 
196
            break;
 
197
        default:
 
198
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
199
            break;
 
200
    }
 
201
}
 
202
 
 
203
static void
 
204
xfce_arrow_button_get_property (GObject * object,
 
205
                                guint prop_id, GValue * value, 
 
206
                                GParamSpec * pspec)
 
207
{
 
208
    XfceArrowButton *button = XFCE_ARROW_BUTTON (object);
 
209
 
 
210
    switch (prop_id)
 
211
    {
 
212
        case PROP_ARROW_TYPE:
 
213
            g_value_set_enum (value, button->arrow_type);
 
214
            break;
 
215
        default:
 
216
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
217
            break;
 
218
    }
 
219
}
 
220
 
 
221
static int
 
222
xfce_arrow_button_expose (GtkWidget * widget, GdkEventExpose *event)
 
223
{
 
224
    if (GTK_WIDGET_DRAWABLE (widget))
 
225
    {
 
226
        int x, y, w;
 
227
 
 
228
        w = MIN (widget->allocation.height - 2 * widget->style->ythickness, 
 
229
                 widget->allocation.width  - 2 * widget->style->xthickness);
 
230
 
 
231
        w = MIN (w, ARROW_WIDTH);
 
232
        
 
233
        x = widget->allocation.x + (widget->allocation.width - w) / 2;
 
234
        
 
235
        y = widget->allocation.y + (widget->allocation.height - w) / 2;
 
236
        
 
237
        GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
 
238
 
 
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,
 
243
                         x, y, w, w);
 
244
    }
 
245
 
 
246
    return TRUE;
 
247
}
 
248
 
 
249
static void
 
250
xfce_arrow_button_size_request (GtkWidget * widget,
 
251
                               GtkRequisition * requisition)
 
252
{
 
253
    int size = ARROW_WIDTH + ARROW_PADDING + 
 
254
               2 * MAX (widget->style->xthickness, widget->style->ythickness);
 
255
    
 
256
    requisition->width = requisition->height = size;
 
257
}
 
258
 
 
259
static void xfce_arrow_button_add (GtkContainer * container, GtkWidget *child)
 
260
{
 
261
    g_warning ("XfceArrowButton cannot contain any children");
 
262
}
 
263
 
 
264
static GType xfce_arrow_button_child_type (GtkContainer * container)
 
265
{
 
266
    return GTK_TYPE_NONE;
 
267
}
 
268
 
 
269
 
 
270
/* public interface */
 
271
 
 
272
/**
 
273
 * xfce_arrow_button_new:
 
274
 * @type : #GtkArrowType for the arrow button
 
275
 *
 
276
 * Returns: newly created #XfceArrowButton widget.
 
277
 **/
 
278
GtkWidget *
 
279
xfce_arrow_button_new (GtkArrowType type)
 
280
{
 
281
    XfceArrowButton *button;
 
282
 
 
283
    button = g_object_new (XFCE_TYPE_ARROW_BUTTON, "arrow_type", type, NULL);
 
284
 
 
285
    return GTK_WIDGET (button);
 
286
}
 
287
 
 
288
/**
 
289
 * xfce_arrow_button_set_arrow_type:
 
290
 * @button : an #XfceArrowButton
 
291
 * @type   : new #GtkArrowType to set
 
292
 *
 
293
 * Sets the arrow type for @button.
 
294
 **/
 
295
void
 
296
xfce_arrow_button_set_arrow_type (XfceArrowButton * button,
 
297
                                  GtkArrowType type)
 
298
{
 
299
    g_return_if_fail (XFCE_IS_ARROW_BUTTON (button));
 
300
    
 
301
    button->arrow_type = type;
 
302
 
 
303
    g_signal_emit (button, arrow_button_signals[ARROW_TYPE_CHANGED],
 
304
                   0, type);
 
305
 
 
306
    g_object_notify (G_OBJECT (button), "arrow_type");
 
307
 
 
308
    gtk_widget_queue_draw (GTK_WIDGET (button));
 
309
}
 
310
 
 
311
/**
 
312
 * xfce_arrow_button_get_arrow_type:
 
313
 * @button : an #XfceArrowButton
 
314
 *
 
315
 * Returns: the #GtkArrowType of @button.
 
316
 **/
 
317
GtkArrowType
 
318
xfce_arrow_button_get_arrow_type (XfceArrowButton * button)
 
319
{
 
320
    g_return_val_if_fail (XFCE_IS_ARROW_BUTTON (button),
 
321
                          DEFAULT_ARROW_TYPE);
 
322
 
 
323
    return button->arrow_type;
 
324
}