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_expose (GtkWidget *widget,
68 GdkEventExpose *event);
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->expose_event = gtk_separator_expose;
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 GtkWidget *widget = GTK_WIDGET (separator);
99 GtkSeparatorPrivate *private;
101 separator->priv = G_TYPE_INSTANCE_GET_PRIVATE (separator,
103 GtkSeparatorPrivate);
104 private = separator->priv;
106 gtk_widget_set_has_window (GTK_WIDGET (separator), FALSE);
108 private->orientation = GTK_ORIENTATION_HORIZONTAL;
110 widget->requisition.width = 1;
111 widget->requisition.height = widget->style->ythickness;
115 gtk_separator_set_property (GObject *object,
120 GtkSeparator *separator = GTK_SEPARATOR (object);
121 GtkSeparatorPrivate *private = separator->priv;
125 case PROP_ORIENTATION:
126 private->orientation = g_value_get_enum (value);
127 gtk_widget_queue_resize (GTK_WIDGET (object));
130 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
136 gtk_separator_get_property (GObject *object,
141 GtkSeparator *separator = GTK_SEPARATOR (object);
142 GtkSeparatorPrivate *private = separator->priv;
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 GtkSeparator *separator = GTK_SEPARATOR (widget);
160 GtkSeparatorPrivate *private = separator->priv;
161 gboolean wide_separators;
162 gint separator_width;
163 gint separator_height;
165 gtk_widget_style_get (widget,
166 "wide-separators", &wide_separators,
167 "separator-width", &separator_width,
168 "separator-height", &separator_height,
171 requisition->width = 1;
172 requisition->height = 1;
174 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
177 requisition->height = separator_height;
179 requisition->height = widget->style->ythickness;
184 requisition->width = separator_width;
186 requisition->width = widget->style->xthickness;
191 gtk_separator_expose (GtkWidget *widget,
192 GdkEventExpose *event)
194 GtkSeparator *separator = GTK_SEPARATOR (widget);
195 GtkSeparatorPrivate *private = separator->priv;
196 gboolean wide_separators;
197 gint separator_width;
198 gint separator_height;
200 if (!gtk_widget_is_drawable (widget))
203 gtk_widget_style_get (widget,
204 "wide-separators", &wide_separators,
205 "separator-width", &separator_width,
206 "separator-height", &separator_height,
209 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
212 gtk_paint_box (widget->style, widget->window,
213 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
214 &event->area, widget, "hseparator",
215 widget->allocation.x,
216 widget->allocation.y + (widget->allocation.height -
217 separator_height) / 2,
218 widget->allocation.width,
221 gtk_paint_hline (widget->style, widget->window,
222 gtk_widget_get_state (widget),
223 &event->area, widget, "hseparator",
224 widget->allocation.x,
225 widget->allocation.x + widget->allocation.width - 1,
226 widget->allocation.y + (widget->allocation.height -
227 widget->style->ythickness) / 2);
232 gtk_paint_box (widget->style, widget->window,
233 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
234 &event->area, widget, "vseparator",
235 widget->allocation.x + (widget->allocation.width -
236 separator_width) / 2,
237 widget->allocation.y,
239 widget->allocation.height);
241 gtk_paint_vline (widget->style, widget->window,
242 gtk_widget_get_state (widget),
243 &event->area, widget, "vseparator",
244 widget->allocation.y,
245 widget->allocation.y + widget->allocation.height - 1,
246 widget->allocation.x + (widget->allocation.width -
247 widget->style->xthickness) / 2);
255 * @orientation: the separator's orientation.
257 * Creates a new #GtkSeparator with the given orientation.
259 * Return value: a new #GtkSeparator.
264 gtk_separator_new (GtkOrientation orientation)
266 return g_object_new (GTK_TYPE_SEPARATOR,
267 "orientation", orientation,