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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
29 #include "gtkorientableprivate.h"
30 #include "gtkseparator.h"
31 #include "gtkprivate.h"
35 * SECTION:gtkseparator
36 * @Short_description: A separator widget
37 * @Title: GtkSeparator
39 * GtkSeparator is a horizontal or vertical separator widget, depending on the
40 * value of the #GtkOrientable:orientation property, used to group the widgets within a
41 * window. It displays a line with a shadow to make it appear sunken into the
46 struct _GtkSeparatorPrivate
48 GtkOrientation orientation;
57 static void gtk_separator_set_property (GObject *object,
61 static void gtk_separator_get_property (GObject *object,
65 static void gtk_separator_get_preferred_width
69 static void gtk_separator_get_preferred_height
73 static gboolean gtk_separator_draw (GtkWidget *widget,
77 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
78 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
83 gtk_separator_class_init (GtkSeparatorClass *class)
85 GObjectClass *object_class = G_OBJECT_CLASS (class);
86 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
88 object_class->set_property = gtk_separator_set_property;
89 object_class->get_property = gtk_separator_get_property;
91 widget_class->get_preferred_width = gtk_separator_get_preferred_width;
92 widget_class->get_preferred_height = gtk_separator_get_preferred_height;
94 widget_class->draw = gtk_separator_draw;
96 gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_SEPARATOR);
98 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
100 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
104 gtk_separator_init (GtkSeparator *separator)
106 GtkSeparatorPrivate *private;
107 GtkStyleContext *context;
109 separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
111 GtkSeparatorPrivate);
112 private = separator->priv;
114 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
116 private->orientation = GTK_ORIENTATION_HORIZONTAL;
118 context = gtk_widget_get_style_context (GTK_WIDGET (separator));
119 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
123 gtk_separator_set_property (GObject *object,
128 GtkSeparator *separator = GTK_SEPARATOR (object);
129 GtkSeparatorPrivate *private = separator->priv;
133 case PROP_ORIENTATION:
134 private->orientation = g_value_get_enum (value);
135 _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object));
136 gtk_widget_queue_resize (GTK_WIDGET (object));
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145 gtk_separator_get_property (GObject *object,
150 GtkSeparator *separator = GTK_SEPARATOR (object);
151 GtkSeparatorPrivate *private = separator->priv;
155 case PROP_ORIENTATION:
156 g_value_set_enum (value, private->orientation);
159 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
165 gtk_separator_get_preferred_size (GtkWidget *widget,
166 GtkOrientation orientation,
170 GtkSeparator *separator = GTK_SEPARATOR (widget);
171 GtkSeparatorPrivate *private = separator->priv;
172 GtkStyleContext *context;
179 context = gtk_widget_get_style_context (widget);
180 state = gtk_widget_get_state_flags (widget);
181 gtk_style_context_get_border (context, state, &border);
183 gtk_widget_style_get (widget,
184 "wide-separators", &wide_sep,
185 "separator-width", &sep_width,
186 "separator-height", &sep_height,
189 if (orientation == private->orientation)
191 *minimum = *natural = 1;
193 else if (orientation == GTK_ORIENTATION_VERTICAL)
195 *minimum = *natural = wide_sep ? sep_height : border.top;
199 *minimum = *natural = wide_sep ? sep_width : border.left;
204 gtk_separator_get_preferred_width (GtkWidget *widget,
208 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
212 gtk_separator_get_preferred_height (GtkWidget *widget,
216 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
220 gtk_separator_draw (GtkWidget *widget,
223 GtkSeparator *separator = GTK_SEPARATOR (widget);
224 GtkSeparatorPrivate *private = separator->priv;
226 GtkStyleContext *context;
228 gboolean wide_separators;
229 gint separator_width;
230 gint separator_height;
233 context = gtk_widget_get_style_context (widget);
234 gtk_widget_style_get (widget,
235 "wide-separators", &wide_separators,
236 "separator-width", &separator_width,
237 "separator-height", &separator_height,
240 state = gtk_widget_get_state_flags (widget);
241 width = gtk_widget_get_allocated_width (widget);
242 height = gtk_widget_get_allocated_height (widget);
244 gtk_style_context_get_padding (context, state, &padding);
246 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
249 gtk_render_frame (context, cr,
250 0, (height - separator_height) / 2,
251 width, separator_height);
253 gtk_render_line (context, cr,
254 0, (height - padding.top) / 2,
255 width - 1, (height - padding.top) / 2);
260 gtk_render_frame (context, cr,
261 (width - separator_width) / 2, 0,
262 separator_width, height);
264 gtk_render_line (context, cr,
265 (width - padding.left) / 2, 0,
266 (width - padding.left) / 2, height - 1);
274 * @orientation: the separator's orientation.
276 * Creates a new #GtkSeparator with the given orientation.
278 * Return value: a new #GtkSeparator.
283 gtk_separator_new (GtkOrientation orientation)
285 return g_object_new (GTK_TYPE_SEPARATOR,
286 "orientation", orientation,