1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
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.
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.
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/>.
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/.
27 #include "gtkorientableprivate.h"
28 #include "gtkseparator.h"
29 #include "gtkprivate.h"
33 * SECTION:gtkseparator
34 * @Short_description: A separator widget
35 * @Title: GtkSeparator
37 * GtkSeparator is a horizontal or vertical separator widget, depending on the
38 * value of the #GtkOrientable:orientation property, used to group the widgets within a
39 * window. It displays a line with a shadow to make it appear sunken into the
44 struct _GtkSeparatorPrivate
46 GtkOrientation orientation;
55 static void gtk_separator_set_property (GObject *object,
59 static void gtk_separator_get_property (GObject *object,
63 static void gtk_separator_get_preferred_width
67 static void gtk_separator_get_preferred_height
71 static gboolean gtk_separator_draw (GtkWidget *widget,
75 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
76 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
81 gtk_separator_class_init (GtkSeparatorClass *class)
83 GObjectClass *object_class = G_OBJECT_CLASS (class);
84 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
86 object_class->set_property = gtk_separator_set_property;
87 object_class->get_property = gtk_separator_get_property;
89 widget_class->get_preferred_width = gtk_separator_get_preferred_width;
90 widget_class->get_preferred_height = gtk_separator_get_preferred_height;
92 widget_class->draw = gtk_separator_draw;
94 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_SEPARATOR);
96 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
98 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
102 gtk_separator_init (GtkSeparator *separator)
104 GtkSeparatorPrivate *private;
105 GtkStyleContext *context;
107 separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
109 GtkSeparatorPrivate);
110 private = separator->priv;
112 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
114 private->orientation = GTK_ORIENTATION_HORIZONTAL;
116 context = gtk_widget_get_style_context (GTK_WIDGET (separator));
117 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
121 gtk_separator_set_property (GObject *object,
126 GtkSeparator *separator = GTK_SEPARATOR (object);
127 GtkSeparatorPrivate *private = separator->priv;
131 case PROP_ORIENTATION:
132 private->orientation = g_value_get_enum (value);
133 _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object));
134 gtk_widget_queue_resize (GTK_WIDGET (object));
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
143 gtk_separator_get_property (GObject *object,
148 GtkSeparator *separator = GTK_SEPARATOR (object);
149 GtkSeparatorPrivate *private = separator->priv;
153 case PROP_ORIENTATION:
154 g_value_set_enum (value, private->orientation);
157 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
163 gtk_separator_get_preferred_size (GtkWidget *widget,
164 GtkOrientation orientation,
168 GtkSeparator *separator = GTK_SEPARATOR (widget);
169 GtkSeparatorPrivate *private = separator->priv;
170 GtkStyleContext *context;
177 context = gtk_widget_get_style_context (widget);
178 state = gtk_widget_get_state_flags (widget);
179 gtk_style_context_get_border (context, state, &border);
181 gtk_widget_style_get (widget,
182 "wide-separators", &wide_sep,
183 "separator-width", &sep_width,
184 "separator-height", &sep_height,
187 if (orientation == private->orientation)
189 *minimum = *natural = 1;
191 else if (orientation == GTK_ORIENTATION_VERTICAL)
193 *minimum = *natural = wide_sep ? sep_height : border.top;
197 *minimum = *natural = wide_sep ? sep_width : border.left;
202 gtk_separator_get_preferred_width (GtkWidget *widget,
206 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
210 gtk_separator_get_preferred_height (GtkWidget *widget,
214 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
218 gtk_separator_draw (GtkWidget *widget,
221 GtkSeparator *separator = GTK_SEPARATOR (widget);
222 GtkSeparatorPrivate *private = separator->priv;
224 GtkStyleContext *context;
226 gboolean wide_separators;
227 gint separator_width;
228 gint separator_height;
231 context = gtk_widget_get_style_context (widget);
232 gtk_widget_style_get (widget,
233 "wide-separators", &wide_separators,
234 "separator-width", &separator_width,
235 "separator-height", &separator_height,
238 state = gtk_widget_get_state_flags (widget);
239 width = gtk_widget_get_allocated_width (widget);
240 height = gtk_widget_get_allocated_height (widget);
242 gtk_style_context_get_padding (context, state, &padding);
244 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
247 gtk_render_frame (context, cr,
248 0, (height - separator_height) / 2,
249 width, separator_height);
251 gtk_render_line (context, cr,
252 0, (height - padding.top) / 2,
253 width - 1, (height - padding.top) / 2);
258 gtk_render_frame (context, cr,
259 (width - separator_width) / 2, 0,
260 separator_width, height);
262 gtk_render_line (context, cr,
263 (width - padding.left) / 2, 0,
264 (width - padding.left) / 2, height - 1);
272 * @orientation: the separator's orientation.
274 * Creates a new #GtkSeparator with the given orientation.
276 * Return value: a new #GtkSeparator.
281 gtk_separator_new (GtkOrientation orientation)
283 return g_object_new (GTK_TYPE_SEPARATOR,
284 "orientation", orientation,