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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "config.h"
23
24 #include "gtkorientableprivate.h"
25 #include "gtkprivate.h"
26 #include "gtktypebuiltins.h"
27 #include "gtkintl.h"
28
29
30 /**
31 * SECTION:gtkorientable
32 * @Short_description: An interface for flippable widgets
33 * @Title: GtkOrientable
34 *
35 * The #GtkOrientable interface is implemented by all widgets that can be
36 * oriented horizontally or vertically. Historically, such widgets have been
37 * realized as subclasses of a common base class (e.g #GtkBox/#GtkHBox/#GtkVBox
38 * or #GtkScale/#GtkHScale/#GtkVScale). #GtkOrientable is more flexible in that
39 * it allows the orientation to be changed at runtime, allowing the widgets
40 * to “flip”.
41 *
42 * #GtkOrientable was introduced in GTK+ 2.16.
43 */
44
45
46 typedef GtkOrientableIface GtkOrientableInterface;
G_DEFINE_INTERFACE(GtkOrientable,gtk_orientable,G_TYPE_OBJECT)47 G_DEFINE_INTERFACE (GtkOrientable, gtk_orientable, G_TYPE_OBJECT)
48
49 static void
50 gtk_orientable_default_init (GtkOrientableInterface *iface)
51 {
52 /**
53 * GtkOrientable:orientation:
54 *
55 * The orientation of the orientable.
56 *
57 * Since: 2.16
58 **/
59 g_object_interface_install_property (iface,
60 g_param_spec_enum ("orientation",
61 P_("Orientation"),
62 P_("The orientation of the orientable"),
63 GTK_TYPE_ORIENTATION,
64 GTK_ORIENTATION_HORIZONTAL,
65 GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
66 }
67
68 /**
69 * gtk_orientable_set_orientation:
70 * @orientable: a #GtkOrientable
71 * @orientation: the orientable’s new orientation.
72 *
73 * Sets the orientation of the @orientable.
74 *
75 * Since: 2.16
76 **/
77 void
gtk_orientable_set_orientation(GtkOrientable * orientable,GtkOrientation orientation)78 gtk_orientable_set_orientation (GtkOrientable *orientable,
79 GtkOrientation orientation)
80 {
81 g_return_if_fail (GTK_IS_ORIENTABLE (orientable));
82
83 g_object_set (orientable,
84 "orientation", orientation,
85 NULL);
86
87 if (GTK_IS_WIDGET (orientable))
88 _gtk_orientable_set_style_classes (orientable);
89 }
90
91 /**
92 * gtk_orientable_get_orientation:
93 * @orientable: a #GtkOrientable
94 *
95 * Retrieves the orientation of the @orientable.
96 *
97 * Returns: the orientation of the @orientable.
98 *
99 * Since: 2.16
100 **/
101 GtkOrientation
gtk_orientable_get_orientation(GtkOrientable * orientable)102 gtk_orientable_get_orientation (GtkOrientable *orientable)
103 {
104 GtkOrientation orientation;
105
106 g_return_val_if_fail (GTK_IS_ORIENTABLE (orientable),
107 GTK_ORIENTATION_HORIZONTAL);
108
109 g_object_get (orientable,
110 "orientation", &orientation,
111 NULL);
112
113 return orientation;
114 }
115
116 void
_gtk_orientable_set_style_classes(GtkOrientable * orientable)117 _gtk_orientable_set_style_classes (GtkOrientable *orientable)
118 {
119 GtkStyleContext *context;
120 GtkOrientation orientation;
121
122 g_return_if_fail (GTK_IS_ORIENTABLE (orientable));
123 g_return_if_fail (GTK_IS_WIDGET (orientable));
124
125 context = gtk_widget_get_style_context (GTK_WIDGET (orientable));
126 orientation = gtk_orientable_get_orientation (orientable);
127
128 if (orientation == GTK_ORIENTATION_HORIZONTAL)
129 {
130 gtk_style_context_add_class (context, GTK_STYLE_CLASS_HORIZONTAL);
131 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_VERTICAL);
132 }
133 else
134 {
135 gtk_style_context_add_class (context, GTK_STYLE_CLASS_VERTICAL);
136 gtk_style_context_remove_class (context, GTK_STYLE_CLASS_HORIZONTAL);
137 }
138 }
139