1 | /* GTK - The GIMP Toolkit |
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
3 | * |
4 | * This library is free software; you can redistribute it and/or |
5 | * modify it under the terms of the GNU Lesser General Public |
6 | * License as published by the Free Software Foundation; either |
7 | * version 2 of the License, or (at your option) any later version. |
8 | * |
9 | * This library is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | * Lesser General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU Lesser General Public |
15 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
16 | */ |
17 | |
18 | /* |
19 | * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS |
20 | * file for a list of people on the GTK+ Team. See the ChangeLog |
21 | * files for a list of changes. These files are distributed with |
22 | * GTK+ at ftp://ftp.gtk.org/pub/gtk/. |
23 | */ |
24 | |
25 | #include "config.h" |
26 | |
27 | #include "gtkseparator.h" |
28 | |
29 | #include "gtkaccessible.h" |
30 | #include "gtkintl.h" |
31 | #include "gtkorientable.h" |
32 | #include "gtkprivate.h" |
33 | #include "gtkwidgetprivate.h" |
34 | |
35 | /** |
36 | * GtkSeparator: |
37 | * |
38 | * `GtkSeparator` is a horizontal or vertical separator widget. |
39 | * |
40 | * ![An example GtkSeparator](separators.png) |
41 | * |
42 | * A `GtkSeparator` can be used to group the widgets within a window. |
43 | * It displays a line with a shadow to make it appear sunken into the |
44 | * interface. |
45 | * |
46 | * # CSS nodes |
47 | * |
48 | * `GtkSeparator` has a single CSS node with name separator. The node |
49 | * gets one of the .horizontal or .vertical style classes. |
50 | * |
51 | * # Accessibility |
52 | * |
53 | * `GtkSeparator` uses the %GTK_ACCESSIBLE_ROLE_SEPARATOR role. |
54 | */ |
55 | |
56 | typedef struct _GtkSeparatorClass GtkSeparatorClass; |
57 | |
58 | struct _GtkSeparator |
59 | { |
60 | GtkWidget parent_instance; |
61 | |
62 | GtkOrientation orientation; |
63 | }; |
64 | |
65 | struct _GtkSeparatorClass |
66 | { |
67 | GtkWidgetClass parent_class; |
68 | }; |
69 | |
70 | enum { |
71 | PROP_0, |
72 | PROP_ORIENTATION |
73 | }; |
74 | |
75 | |
76 | G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET, |
77 | G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)) |
78 | |
79 | static void |
80 | gtk_separator_set_orientation (GtkSeparator *self, |
81 | GtkOrientation orientation) |
82 | { |
83 | if (self->orientation != orientation) |
84 | { |
85 | self->orientation = orientation; |
86 | |
87 | gtk_widget_update_orientation (GTK_WIDGET (self), orientation); |
88 | gtk_widget_queue_resize (GTK_WIDGET (self)); |
89 | |
90 | gtk_accessible_update_property (self: GTK_ACCESSIBLE (ptr: self), |
91 | first_property: GTK_ACCESSIBLE_PROPERTY_ORIENTATION, orientation, |
92 | -1); |
93 | |
94 | g_object_notify (G_OBJECT (self), property_name: "orientation" ); |
95 | } |
96 | } |
97 | |
98 | static void |
99 | gtk_separator_set_property (GObject *object, |
100 | guint prop_id, |
101 | const GValue *value, |
102 | GParamSpec *pspec) |
103 | { |
104 | GtkSeparator *separator = GTK_SEPARATOR (object); |
105 | |
106 | switch (prop_id) |
107 | { |
108 | case PROP_ORIENTATION: |
109 | gtk_separator_set_orientation (self: separator, orientation: g_value_get_enum (value)); |
110 | break; |
111 | default: |
112 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
113 | break; |
114 | } |
115 | } |
116 | |
117 | static void |
118 | gtk_separator_get_property (GObject *object, |
119 | guint prop_id, |
120 | GValue *value, |
121 | GParamSpec *pspec) |
122 | { |
123 | GtkSeparator *separator = GTK_SEPARATOR (object); |
124 | |
125 | switch (prop_id) |
126 | { |
127 | case PROP_ORIENTATION: |
128 | g_value_set_enum (value, v_enum: separator->orientation); |
129 | break; |
130 | default: |
131 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
132 | break; |
133 | } |
134 | } |
135 | |
136 | static void |
137 | gtk_separator_init (GtkSeparator *separator) |
138 | { |
139 | separator->orientation = GTK_ORIENTATION_HORIZONTAL; |
140 | |
141 | gtk_widget_update_orientation (GTK_WIDGET (separator), |
142 | orientation: separator->orientation); |
143 | } |
144 | |
145 | static void |
146 | gtk_separator_class_init (GtkSeparatorClass *class) |
147 | { |
148 | GObjectClass *object_class = G_OBJECT_CLASS (class); |
149 | GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); |
150 | |
151 | object_class->set_property = gtk_separator_set_property; |
152 | object_class->get_property = gtk_separator_get_property; |
153 | |
154 | g_object_class_override_property (oclass: object_class, property_id: PROP_ORIENTATION, name: "orientation" ); |
155 | |
156 | gtk_widget_class_set_css_name (widget_class, I_("separator" )); |
157 | gtk_widget_class_set_accessible_role (widget_class, accessible_role: GTK_ACCESSIBLE_ROLE_SEPARATOR); |
158 | } |
159 | |
160 | /** |
161 | * gtk_separator_new: |
162 | * @orientation: the separator’s orientation. |
163 | * |
164 | * Creates a new `GtkSeparator` with the given orientation. |
165 | * |
166 | * Returns: a new `GtkSeparator`. |
167 | */ |
168 | GtkWidget * |
169 | gtk_separator_new (GtkOrientation orientation) |
170 | { |
171 | return g_object_new (GTK_TYPE_SEPARATOR, |
172 | first_property_name: "orientation" , orientation, |
173 | NULL); |
174 | } |
175 | |