]> Pileus Git - ~andy/gtk/blob - gtk/gtkorientable.c
7a5038b491a88677fd4835d05a22b8205798332d
[~andy/gtk] / gtk / gtkorientable.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * gtkorientable.c
5  * Copyright (C) 2008 Imendio AB
6  * Contact: Michael Natterer <mitch@imendio.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the
20  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  * Boston, MA 02111-1307, USA.
22  */
23
24 #include "config.h"
25
26 #include "gtkorientableprivate.h"
27 #include "gtkprivate.h"
28 #include "gtktypebuiltins.h"
29 #include "gtkintl.h"
30
31
32 /**
33  * SECTION:gtkorientable
34  * @Short_description: An interface for flippable widgets
35  * @Title: GtkOrientable
36  *
37  * The #GtkOrientable interface is implemented by all widgets that can be
38  * oriented horizontally or vertically. Historically, such widgets have been
39  * realized as subclasses of a common base class (e.g #GtkBox/#GtkHBox/#GtkVBox
40  * or #GtkScale/#GtkHScale/#GtkVScale). #GtkOrientable is more flexible in that
41  * it allows the orientation to be changed at runtime, allowing the widgets
42  * to 'flip'.
43  *
44  * #GtkOrientable was introduced in GTK+ 2.16.
45  */
46
47
48 typedef GtkOrientableIface GtkOrientableInterface;
49 G_DEFINE_INTERFACE (GtkOrientable, gtk_orientable, G_TYPE_OBJECT)
50
51 static void
52 gtk_orientable_default_init (GtkOrientableInterface *iface)
53 {
54   /**
55    * GtkOrientable:orientation:
56    *
57    * The orientation of the orientable.
58    *
59    * Since: 2.16
60    **/
61   g_object_interface_install_property (iface,
62                                        g_param_spec_enum ("orientation",
63                                                           P_("Orientation"),
64                                                           P_("The orientation of the orientable"),
65                                                           GTK_TYPE_ORIENTATION,
66                                                           GTK_ORIENTATION_HORIZONTAL,
67                                                           GTK_PARAM_READWRITE));
68 }
69
70 /**
71  * gtk_orientable_set_orientation:
72  * @orientable: a #GtkOrientable
73  * @orientation: the orientable's new orientation.
74  *
75  * Sets the orientation of the @orientable.
76  *
77  * Since: 2.16
78  **/
79 void
80 gtk_orientable_set_orientation (GtkOrientable  *orientable,
81                                 GtkOrientation  orientation)
82 {
83   g_return_if_fail (GTK_IS_ORIENTABLE (orientable));
84
85   g_object_set (orientable,
86                 "orientation", orientation,
87                 NULL);
88
89   if (GTK_IS_WIDGET (orientable))
90     _gtk_orientable_set_style_classes (orientable);
91 }
92
93 /**
94  * gtk_orientable_get_orientation:
95  * @orientable: a #GtkOrientable
96  *
97  * Retrieves the orientation of the @orientable.
98  *
99  * Return value: the orientation of the @orientable.
100  *
101  * Since: 2.16
102  **/
103 GtkOrientation
104 gtk_orientable_get_orientation (GtkOrientable *orientable)
105 {
106   GtkOrientation orientation;
107
108   g_return_val_if_fail (GTK_IS_ORIENTABLE (orientable),
109                         GTK_ORIENTATION_HORIZONTAL);
110
111   g_object_get (orientable,
112                 "orientation", &orientation,
113                 NULL);
114
115   return orientation;
116 }
117
118 void
119 _gtk_orientable_set_style_classes (GtkOrientable *orientable)
120 {
121   GtkStyleContext *context;
122   GtkOrientation orientation;
123
124   g_return_if_fail (GTK_IS_ORIENTABLE (orientable));
125   g_return_if_fail (GTK_IS_WIDGET (orientable));
126
127   context = gtk_widget_get_style_context (GTK_WIDGET (orientable));
128   orientation = gtk_orientable_get_orientation (orientable);
129
130   if (orientation == GTK_ORIENTATION_HORIZONTAL)
131     {
132       gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
133       gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VERTICAL);
134     }
135   else
136     {
137       gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
138       gtk_style_context_remove_class (context, GTK_STYLE_CLASS_HORIZONTAL);
139     }
140 }