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"
37 * SECTION:gtkseparator
38 * @Short_description: Base class for GtkHSeparator and GtkVSeparator
39 * @Title: GtkSeparator
41 * The GtkSeparator widget is the base class for #GtkHSeparator and
42 * #GtkVSeparator. It can be used in the same way as these, by setting
43 * the "orientation" property suitably.
53 typedef struct _GtkSeparatorPrivate GtkSeparatorPrivate;
55 struct _GtkSeparatorPrivate
57 GtkOrientation orientation;
60 #define GTK_SEPARATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR, GtkSeparatorPrivate))
63 static void gtk_separator_set_property (GObject *object,
67 static void gtk_separator_get_property (GObject *object,
72 static void gtk_separator_size_request (GtkWidget *widget,
73 GtkRequisition *requisition);
74 static gboolean gtk_separator_expose (GtkWidget *widget,
75 GdkEventExpose *event);
78 G_DEFINE_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
79 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
84 gtk_separator_class_init (GtkSeparatorClass *class)
86 GObjectClass *object_class = G_OBJECT_CLASS (class);
87 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
89 object_class->set_property = gtk_separator_set_property;
90 object_class->get_property = gtk_separator_get_property;
92 widget_class->size_request = gtk_separator_size_request;
93 widget_class->expose_event = gtk_separator_expose;
95 g_object_class_override_property (object_class,
99 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
103 gtk_separator_init (GtkSeparator *separator)
105 GtkWidget *widget = GTK_WIDGET (separator);
106 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (separator);
108 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
110 private->orientation = GTK_ORIENTATION_HORIZONTAL;
112 widget->requisition.width = 1;
113 widget->requisition.height = widget->style->ythickness;
117 gtk_separator_set_property (GObject *object,
122 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
126 case PROP_ORIENTATION:
127 private->orientation = g_value_get_enum (value);
128 gtk_widget_queue_resize (GTK_WIDGET (object));
131 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
137 gtk_separator_get_property (GObject *object,
142 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
146 case PROP_ORIENTATION:
147 g_value_set_enum (value, private->orientation);
150 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
156 gtk_separator_size_request (GtkWidget *widget,
157 GtkRequisition *requisition)
159 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
160 gboolean wide_separators;
161 gint separator_width;
162 gint separator_height;
164 gtk_widget_style_get (widget,
165 "wide-separators", &wide_separators,
166 "separator-width", &separator_width,
167 "separator-height", &separator_height,
170 requisition->width = 1;
171 requisition->height = 1;
173 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
176 requisition->height = separator_height;
178 requisition->height = widget->style->ythickness;
183 requisition->width = separator_width;
185 requisition->width = widget->style->xthickness;
190 gtk_separator_expose (GtkWidget *widget,
191 GdkEventExpose *event)
193 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
194 gboolean wide_separators;
195 gint separator_width;
196 gint separator_height;
198 if (!gtk_widget_is_drawable (widget))
201 gtk_widget_style_get (widget,
202 "wide-separators", &wide_separators,
203 "separator-width", &separator_width,
204 "separator-height", &separator_height,
207 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
210 gtk_paint_box (widget->style, widget->window,
211 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
212 &event->area, widget, "hseparator",
213 widget->allocation.x,
214 widget->allocation.y + (widget->allocation.height -
215 separator_height) / 2,
216 widget->allocation.width,
219 gtk_paint_hline (widget->style, widget->window,
220 gtk_widget_get_state (widget),
221 &event->area, widget, "hseparator",
222 widget->allocation.x,
223 widget->allocation.x + widget->allocation.width - 1,
224 widget->allocation.y + (widget->allocation.height -
225 widget->style->ythickness) / 2);
230 gtk_paint_box (widget->style, widget->window,
231 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
232 &event->area, widget, "vseparator",
233 widget->allocation.x + (widget->allocation.width -
234 separator_width) / 2,
235 widget->allocation.y,
237 widget->allocation.height);
239 gtk_paint_vline (widget->style, widget->window,
240 gtk_widget_get_state (widget),
241 &event->area, widget, "vseparator",
242 widget->allocation.y,
243 widget->allocation.y + widget->allocation.height - 1,
244 widget->allocation.x + (widget->allocation.width -
245 widget->style->xthickness) / 2);
253 * @orientation: the separator's orientation.
255 * Creates a new #GtkSeparator with the given orientation.
257 * Return value: a new #GtkSeparator.
262 gtk_separator_new (GtkOrientation orientation)
264 return g_object_new (GTK_TYPE_SEPARATOR,
265 "orientation", orientation,
270 #define __GTK_SEPARATOR_C__
271 #include "gtkaliasdef.c"