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.
51 typedef struct _GtkSeparatorPrivate GtkSeparatorPrivate;
53 struct _GtkSeparatorPrivate
55 GtkOrientation orientation;
58 #define GTK_SEPARATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR, GtkSeparatorPrivate))
61 static void gtk_separator_set_property (GObject *object,
65 static void gtk_separator_get_property (GObject *object,
70 static void gtk_separator_size_request (GtkWidget *widget,
71 GtkRequisition *requisition);
72 static gboolean gtk_separator_expose (GtkWidget *widget,
73 GdkEventExpose *event);
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->size_request = gtk_separator_size_request;
91 widget_class->expose_event = gtk_separator_expose;
93 g_object_class_override_property (object_class,
97 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
101 gtk_separator_init (GtkSeparator *separator)
103 GtkWidget *widget = GTK_WIDGET (separator);
104 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (separator);
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 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
124 case PROP_ORIENTATION:
125 private->orientation = g_value_get_enum (value);
126 gtk_widget_queue_resize (GTK_WIDGET (object));
129 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
135 gtk_separator_get_property (GObject *object,
140 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
144 case PROP_ORIENTATION:
145 g_value_set_enum (value, private->orientation);
148 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
154 gtk_separator_size_request (GtkWidget *widget,
155 GtkRequisition *requisition)
157 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
158 gboolean wide_separators;
159 gint separator_width;
160 gint separator_height;
162 gtk_widget_style_get (widget,
163 "wide-separators", &wide_separators,
164 "separator-width", &separator_width,
165 "separator-height", &separator_height,
168 requisition->width = 1;
169 requisition->height = 1;
171 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
174 requisition->height = separator_height;
176 requisition->height = widget->style->ythickness;
181 requisition->width = separator_width;
183 requisition->width = widget->style->xthickness;
188 gtk_separator_expose (GtkWidget *widget,
189 GdkEventExpose *event)
191 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
192 gboolean wide_separators;
193 gint separator_width;
194 gint separator_height;
196 if (!gtk_widget_is_drawable (widget))
199 gtk_widget_style_get (widget,
200 "wide-separators", &wide_separators,
201 "separator-width", &separator_width,
202 "separator-height", &separator_height,
205 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
208 gtk_paint_box (widget->style, widget->window,
209 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
210 &event->area, widget, "hseparator",
211 widget->allocation.x,
212 widget->allocation.y + (widget->allocation.height -
213 separator_height) / 2,
214 widget->allocation.width,
217 gtk_paint_hline (widget->style, widget->window,
218 gtk_widget_get_state (widget),
219 &event->area, widget, "hseparator",
220 widget->allocation.x,
221 widget->allocation.x + widget->allocation.width - 1,
222 widget->allocation.y + (widget->allocation.height -
223 widget->style->ythickness) / 2);
228 gtk_paint_box (widget->style, widget->window,
229 gtk_widget_get_state (widget), GTK_SHADOW_ETCHED_OUT,
230 &event->area, widget, "vseparator",
231 widget->allocation.x + (widget->allocation.width -
232 separator_width) / 2,
233 widget->allocation.y,
235 widget->allocation.height);
237 gtk_paint_vline (widget->style, widget->window,
238 gtk_widget_get_state (widget),
239 &event->area, widget, "vseparator",
240 widget->allocation.y,
241 widget->allocation.y + widget->allocation.height - 1,
242 widget->allocation.x + (widget->allocation.width -
243 widget->style->xthickness) / 2);
251 * @orientation: the separator's orientation.
253 * Creates a new #GtkSeparator with the given orientation.
255 * Return value: a new #GtkSeparator.
260 gtk_separator_new (GtkOrientation orientation)
262 return g_object_new (GTK_TYPE_SEPARATOR,
263 "orientation", orientation,