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: Base class for GtkHSeparator and GtkVSeparator
37 * @Title: GtkSeparator
39 * The GtkSeparator widget is the base class for #GtkHSeparator and
40 * #GtkVSeparator. It can be used in the same way as these, by setting
41 * the "orientation" property suitably.
45 struct _GtkSeparatorPrivate
47 GtkOrientation orientation;
56 static void gtk_separator_set_property (GObject *object,
60 static void gtk_separator_get_property (GObject *object,
64 static void gtk_separator_get_preferred_width
68 static void gtk_separator_get_preferred_height
72 static gboolean gtk_separator_draw (GtkWidget *widget,
76 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
77 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
82 gtk_separator_class_init (GtkSeparatorClass *class)
84 GObjectClass *object_class = G_OBJECT_CLASS (class);
85 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
87 object_class->set_property = gtk_separator_set_property;
88 object_class->get_property = gtk_separator_get_property;
90 widget_class->get_preferred_width = gtk_separator_get_preferred_width;
91 widget_class->get_preferred_height = gtk_separator_get_preferred_height;
93 widget_class->draw = gtk_separator_draw;
95 g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation");
97 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
101 gtk_separator_init (GtkSeparator *separator)
103 GtkSeparatorPrivate *private;
104 GtkStyleContext *context;
106 separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
108 GtkSeparatorPrivate);
109 private = separator->priv;
111 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
113 private->orientation = GTK_ORIENTATION_HORIZONTAL;
115 context = gtk_widget_get_style_context (GTK_WIDGET (separator));
116 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SEPARATOR);
120 gtk_separator_set_property (GObject *object,
125 GtkSeparator *separator = GTK_SEPARATOR (object);
126 GtkSeparatorPrivate *private = separator->priv;
130 case PROP_ORIENTATION:
131 private->orientation = g_value_get_enum (value);
132 _gtk_orientable_set_style_classes (GTK_ORIENTABLE (object));
133 gtk_widget_queue_resize (GTK_WIDGET (object));
136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
142 gtk_separator_get_property (GObject *object,
147 GtkSeparator *separator = GTK_SEPARATOR (object);
148 GtkSeparatorPrivate *private = separator->priv;
152 case PROP_ORIENTATION:
153 g_value_set_enum (value, private->orientation);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
162 gtk_separator_get_preferred_size (GtkWidget *widget,
163 GtkOrientation orientation,
167 GtkSeparator *separator = GTK_SEPARATOR (widget);
168 GtkSeparatorPrivate *private = separator->priv;
169 GtkStyleContext *context;
176 context = gtk_widget_get_style_context (widget);
177 state = gtk_widget_get_state_flags (widget);
178 gtk_style_context_get_border (context, state, &border);
180 gtk_widget_style_get (widget,
181 "wide-separators", &wide_sep,
182 "separator-width", &sep_width,
183 "separator-height", &sep_height,
186 if (orientation == private->orientation)
188 *minimum = *natural = 1;
190 else if (orientation == GTK_ORIENTATION_VERTICAL)
192 *minimum = *natural = wide_sep ? sep_height : border.top;
196 *minimum = *natural = wide_sep ? sep_width : border.left;
201 gtk_separator_get_preferred_width (GtkWidget *widget,
205 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum, natural);
209 gtk_separator_get_preferred_height (GtkWidget *widget,
213 gtk_separator_get_preferred_size (widget, GTK_ORIENTATION_VERTICAL, minimum, natural);
217 gtk_separator_draw (GtkWidget *widget,
220 GtkSeparator *separator = GTK_SEPARATOR (widget);
221 GtkSeparatorPrivate *private = separator->priv;
223 GtkStyleContext *context;
225 gboolean wide_separators;
226 gint separator_width;
227 gint separator_height;
230 context = gtk_widget_get_style_context (widget);
231 gtk_widget_style_get (widget,
232 "wide-separators", &wide_separators,
233 "separator-width", &separator_width,
234 "separator-height", &separator_height,
237 state = gtk_widget_get_state_flags (widget);
238 width = gtk_widget_get_allocated_width (widget);
239 height = gtk_widget_get_allocated_height (widget);
241 gtk_style_context_get_padding (context, state, &padding);
243 gtk_style_context_save (context);
244 gtk_style_context_set_state (context, state);
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);
269 gtk_style_context_restore (context);
276 * @orientation: the separator's orientation.
278 * Creates a new #GtkSeparator with the given orientation.
280 * Return value: a new #GtkSeparator.
285 gtk_separator_new (GtkOrientation orientation)
287 return g_object_new (GTK_TYPE_SEPARATOR,
288 "orientation", orientation,