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 "gtkorientable.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,
65 static void gtk_separator_size_request (GtkWidget *widget,
66 GtkRequisition *requisition);
67 static gboolean gtk_separator_draw (GtkWidget *widget,
71 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
72 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
77 gtk_separator_class_init (GtkSeparatorClass *class)
79 GObjectClass *object_class = G_OBJECT_CLASS (class);
80 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
82 object_class->set_property = gtk_separator_set_property;
83 object_class->get_property = gtk_separator_get_property;
85 widget_class->size_request = gtk_separator_size_request;
86 widget_class->draw = gtk_separator_draw;
88 g_object_class_override_property (object_class,
92 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
96 gtk_separator_init (GtkSeparator *separator)
98 GtkSeparatorPrivate *private;
100 separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
102 GtkSeparatorPrivate);
103 private = separator->priv;
105 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
107 private->orientation = GTK_ORIENTATION_HORIZONTAL;
111 gtk_separator_set_property (GObject *object,
116 GtkSeparator *separator = GTK_SEPARATOR (object);
117 GtkSeparatorPrivate *private = separator->priv;
121 case PROP_ORIENTATION:
122 private->orientation = g_value_get_enum (value);
123 gtk_widget_queue_resize (GTK_WIDGET (object));
126 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
132 gtk_separator_get_property (GObject *object,
137 GtkSeparator *separator = GTK_SEPARATOR (object);
138 GtkSeparatorPrivate *private = separator->priv;
142 case PROP_ORIENTATION:
143 g_value_set_enum (value, private->orientation);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 gtk_separator_size_request (GtkWidget *widget,
153 GtkRequisition *requisition)
155 GtkSeparator *separator = GTK_SEPARATOR (widget);
156 GtkSeparatorPrivate *private = separator->priv;
158 gboolean wide_separators;
159 gint separator_width;
160 gint separator_height;
162 style = gtk_widget_get_style (widget);
163 gtk_widget_style_get (widget,
164 "wide-separators", &wide_separators,
165 "separator-width", &separator_width,
166 "separator-height", &separator_height,
169 requisition->width = 1;
170 requisition->height = 1;
172 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
175 requisition->height = separator_height;
177 requisition->height = style->ythickness;
182 requisition->width = separator_width;
184 requisition->width = style->xthickness;
189 gtk_separator_draw (GtkWidget *widget,
192 GtkSeparator *separator = GTK_SEPARATOR (widget);
193 GtkSeparatorPrivate *private = separator->priv;
197 gboolean wide_separators;
198 gint separator_width;
199 gint separator_height;
202 style = gtk_widget_get_style (widget);
203 gtk_widget_style_get (widget,
204 "wide-separators", &wide_separators,
205 "separator-width", &separator_width,
206 "separator-height", &separator_height,
209 window = gtk_widget_get_window (widget);
210 state = gtk_widget_get_state (widget);
211 width = gtk_widget_get_allocated_width (widget);
212 height = gtk_widget_get_allocated_height (widget);
214 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
217 gtk_paint_box (style, cr,
218 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
219 widget, "hseparator",
220 0, (height - separator_height) / 2,
221 width, separator_height);
223 gtk_paint_hline (style, cr,
224 gtk_widget_get_state (widget),
225 widget, "hseparator",
227 (height - style->ythickness) / 2);
232 gtk_paint_box (style, cr,
233 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
234 widget, "vseparator",
235 (width - separator_width) / 2, 0,
236 separator_width, height);
238 gtk_paint_vline (style, cr,
239 gtk_widget_get_state (widget),
240 widget, "vseparator",
242 (width - style->xthickness) / 2);
250 * @orientation: the separator's orientation.
252 * Creates a new #GtkSeparator with the given orientation.
254 * Return value: a new #GtkSeparator.
259 gtk_separator_new (GtkOrientation orientation)
261 return g_object_new (GTK_TYPE_SEPARATOR,
262 "orientation", orientation,