1
/* $Id: xfce-hvbox.c 27412 2008-08-01 20:19:47Z nick $
2
* This file is partly based on OBox
3
* Copyright (C) 2002 Red Hat Inc. based on GtkHBox
3
* OBox Copyright (c) 2002 Red Hat Inc. based on GtkHBox
4
* Copyright (c) 2006 Jani Monoses <jani@ubuntu.com>
5
* Copyright (c) 2006-2007 Jasper Huijsmans <jasper@xfce.org>
5
* Copyright (C) 2006-2007 Jasper Huijsmans <jasper@xfce.org>
6
* Copyright (C) 2006 Jani Monoses <jani@ubuntu.com>
7
* Copyright (C) 2007-2010 Nick Schermer <nick@xfce.org>
7
9
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Library General Public
10
* modify it under the terms of the GNU Lesser General Public
9
11
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* version 2.1 of the License, or (at your option) any later version.
12
14
* This library is distributed in the hope that it will be useful,
13
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Library General Public License for more details.
17
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Library General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with this library; if not, write to the Free Software
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
24
#ifdef HAVE_CONFIG_H
24
25
#include <config.h>
28
#include <gtk/gtkhbox.h>
29
#include <gtk/gtkvbox.h>
31
30
#include <libxfce4panel/xfce-panel-macros.h>
32
31
#include <libxfce4panel/xfce-hvbox.h>
38
static void xfce_hvbox_class_init (XfceHVBoxClass *klass);
39
static void xfce_hvbox_size_request (GtkWidget *widget,
40
GtkRequisition *requisition);
41
static void xfce_hvbox_size_allocate (GtkWidget *widget,
42
GtkAllocation *allocation);
47
xfce_hvbox_get_type (void)
39
* @short_description: Container widget with configurable orienation
40
* @include: libxfce4panel/libxfce4panel.h
42
* #XfceHVBox is a #GtkBox widget that allows the user to change
43
* its orientation. It is in fact a combination of #GtkHBox and #GtkVBox.
45
* If your code depends on Gtk+ 2.16 or later, if it better to use
46
* the normal #GtkBox widgets in combination with
47
* gtk_orientable_set_orientation().
49
* See also: #GtkOrientable and #GtkBox.
54
#if !GTK_CHECK_VERSION (2, 16, 0)
49
static GtkType type = G_TYPE_INVALID;
51
if (G_UNLIKELY (type == G_TYPE_INVALID))
53
type = _panel_g_type_register_simple (GTK_TYPE_BOX,
55
sizeof (XfceHVBoxClass),
56
xfce_hvbox_class_init,
61
static void xfce_hvbox_get_property (GObject *object,
65
static void xfce_hvbox_set_property (GObject *object,
69
static gpointer xfce_hvbox_get_class (XfceHVBox *hvbox);
70
static void xfce_hvbox_size_request (GtkWidget *widget,
71
GtkRequisition *requisition);
72
static void xfce_hvbox_size_allocate (GtkWidget *widget,
73
GtkAllocation *allocation);
78
G_DEFINE_TYPE (XfceHVBox, xfce_hvbox, GTK_TYPE_BOX)
67
83
xfce_hvbox_class_init (XfceHVBoxClass *klass)
69
GtkWidgetClass *widget_class;
71
widget_class = (GtkWidgetClass *) klass;
73
widget_class->size_request = xfce_hvbox_size_request;
74
widget_class->size_allocate = xfce_hvbox_size_allocate;
85
#if !GTK_CHECK_VERSION (2, 16, 0)
86
GObjectClass *gobject_class;
87
GtkWidgetClass *gtkwidget_class;
89
gobject_class = G_OBJECT_CLASS (klass);
90
gobject_class->get_property = xfce_hvbox_get_property;
91
gobject_class->set_property = xfce_hvbox_set_property;
93
gtkwidget_class = GTK_WIDGET_CLASS (klass);
94
gtkwidget_class->size_request = xfce_hvbox_size_request;
95
gtkwidget_class->size_allocate = xfce_hvbox_size_allocate;
98
* XfceHVBox:orientation:
100
* The orientation of the #XfceHVBox. When compiled with Gtk+ 2.16,
101
* this is the orientation property of the #GtkOrientable.
103
g_object_class_install_property (gobject_class,
105
g_param_spec_enum ("orientation",
107
"Orientation of the box",
108
GTK_TYPE_ORIENTATION,
109
GTK_ORIENTATION_HORIZONTAL,
111
| G_PARAM_STATIC_STRINGS));
118
xfce_hvbox_init (XfceHVBox *hvbox)
120
/* initialize variables */
121
hvbox->orientation = GTK_ORIENTATION_HORIZONTAL;
126
#if !GTK_CHECK_VERSION (2, 16, 0)
128
xfce_hvbox_get_property (GObject *object,
133
XfceHVBox *hvbox = XFCE_HVBOX (object);
137
case PROP_ORIENTATION:
138
g_value_set_enum (value, hvbox->orientation);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
150
xfce_hvbox_set_property (GObject *object,
155
XfceHVBox *hvbox = XFCE_HVBOX (object);
159
case PROP_ORIENTATION:
160
xfce_hvbox_set_orientation (hvbox, g_value_get_enum (value));
164
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
80
172
xfce_hvbox_get_class (XfceHVBox *hvbox)
85
if (hvbox->orientation == GTK_ORIENTATION_HORIZONTAL)
90
/* peek the class, this only works if the class already exists */
91
klass = g_type_class_peek (type);
93
/* return the type or create the class */
94
return klass ? klass : g_type_class_ref (type);
177
if (hvbox->orientation == GTK_ORIENTATION_HORIZONTAL)
178
type = GTK_TYPE_HBOX;
180
type = GTK_TYPE_VBOX;
182
/* peek the class, this only works if the class already exists */
183
klass = g_type_class_peek (type);
185
/* return the type or create the class */
186
return klass ? klass : g_type_class_ref (type);
135
228
* Creates a new #XfceHVBox container widget.
137
* Return value: the newly allocated #XfceHVBox container widget.
230
* Returns: the newly allocated #XfceHVBox container widget.
140
233
xfce_hvbox_new (GtkOrientation orientation,
141
234
gboolean homogeneous,
146
box = g_object_new (XFCE_TYPE_HVBOX,
147
"homogeneous", homogeneous,
151
XFCE_HVBOX (box)->orientation = orientation;
239
/* create new object */
240
box = g_object_new (XFCE_TYPE_HVBOX,
241
#if GTK_CHECK_VERSION (2, 16, 0)
242
"orientation", orientation,
244
"homogeneous", homogeneous,
245
"spacing", spacing, NULL);
247
/* store the orientation */
248
box->orientation = orientation;
250
return GTK_WIDGET (box);
166
263
xfce_hvbox_set_orientation (XfceHVBox *hvbox,
167
264
GtkOrientation orientation)
169
_panel_return_if_fail (XFCE_IS_HVBOX (hvbox));
171
if (G_UNLIKELY (hvbox->orientation == orientation))
174
hvbox->orientation = orientation;
176
gtk_widget_queue_resize (GTK_WIDGET (hvbox));
266
g_return_if_fail (XFCE_IS_HVBOX (hvbox));
268
if (G_LIKELY (hvbox->orientation != orientation))
270
/* store new orientation */
271
hvbox->orientation = orientation;
273
#if GTK_CHECK_VERSION (2, 16, 0)
274
gtk_orientable_set_orientation (GTK_ORIENTABLE (hvbox), orientation);
276
gtk_widget_queue_resize (GTK_WIDGET (hvbox));
284
* xfce_hvbox_get_orientation:
285
* @hvbox : #XfceHVBox
287
* Get the current orientation of the @hvbox.
289
* Returns: the current orientation of the #XfceHVBox.
292
xfce_hvbox_get_orientation (XfceHVBox *hvbox)
294
g_return_val_if_fail (XFCE_IS_HVBOX (hvbox), GTK_ORIENTATION_HORIZONTAL);
296
#if GTK_CHECK_VERSION (2, 16, 0)
297
return gtk_orientable_get_orientation (GTK_ORIENTABLE (hvbox));
299
return hvbox->orientation;
181
305
#define __XFCE_HVBOX_C__
182
306
#include <libxfce4panel/libxfce4panel-aliasdef.c>