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"
42 typedef struct _GtkSeparatorPrivate GtkSeparatorPrivate;
44 struct _GtkSeparatorPrivate
46 GtkOrientation orientation;
49 #define GTK_SEPARATOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_SEPARATOR, GtkSeparatorPrivate))
52 static void gtk_separator_set_property (GObject *object,
56 static void gtk_separator_get_property (GObject *object,
61 static void gtk_separator_size_request (GtkWidget *widget,
62 GtkRequisition *requisition);
63 static gboolean gtk_separator_expose (GtkWidget *widget,
64 GdkEventExpose *event);
67 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GtkSeparator, gtk_separator, GTK_TYPE_WIDGET,
68 G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE,
73 gtk_separator_class_init (GtkSeparatorClass *class)
75 GObjectClass *object_class = G_OBJECT_CLASS (class);
76 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
78 object_class->set_property = gtk_separator_set_property;
79 object_class->get_property = gtk_separator_get_property;
81 widget_class->size_request = gtk_separator_size_request;
82 widget_class->expose_event = gtk_separator_expose;
84 g_object_class_override_property (object_class,
88 g_type_class_add_private (object_class, sizeof (GtkSeparatorPrivate));
92 gtk_separator_init (GtkSeparator *separator)
94 GtkWidget *widget = GTK_WIDGET (separator);
95 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (separator);
97 GTK_WIDGET_SET_FLAGS (separator, GTK_NO_WINDOW);
99 private->orientation = GTK_ORIENTATION_HORIZONTAL;
101 widget->requisition.width = 1;
102 widget->requisition.height = widget->style->ythickness;
106 gtk_separator_set_property (GObject *object,
111 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
115 case PROP_ORIENTATION:
116 private->orientation = g_value_get_enum (value);
117 gtk_widget_queue_resize (GTK_WIDGET (object));
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126 gtk_separator_get_property (GObject *object,
131 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (object);
135 case PROP_ORIENTATION:
136 g_value_set_enum (value, private->orientation);
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
145 gtk_separator_size_request (GtkWidget *widget,
146 GtkRequisition *requisition)
148 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
149 gboolean wide_separators;
150 gint separator_width;
151 gint separator_height;
153 gtk_widget_style_get (widget,
154 "wide-separators", &wide_separators,
155 "separator-width", &separator_width,
156 "separator-height", &separator_height,
159 requisition->width = 1;
160 requisition->height = 1;
162 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
165 requisition->height = separator_height;
167 requisition->height = widget->style->ythickness;
172 requisition->width = separator_width;
174 requisition->width = widget->style->xthickness;
179 gtk_separator_expose (GtkWidget *widget,
180 GdkEventExpose *event)
182 GtkSeparatorPrivate *private = GTK_SEPARATOR_GET_PRIVATE (widget);
183 gboolean wide_separators;
184 gint separator_width;
185 gint separator_height;
187 if (!GTK_WIDGET_DRAWABLE (widget))
190 gtk_widget_style_get (widget,
191 "wide-separators", &wide_separators,
192 "separator-width", &separator_width,
193 "separator-height", &separator_height,
196 if (private->orientation == GTK_ORIENTATION_HORIZONTAL)
199 gtk_paint_box (widget->style, widget->window,
200 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
201 &event->area, widget, "hseparator",
202 widget->allocation.x,
203 widget->allocation.y + (widget->allocation.height -
204 separator_height) / 2,
205 widget->allocation.width,
208 gtk_paint_hline (widget->style, widget->window,
209 GTK_WIDGET_STATE (widget),
210 &event->area, widget, "hseparator",
211 widget->allocation.x,
212 widget->allocation.x + widget->allocation.width - 1,
213 widget->allocation.y + (widget->allocation.height -
214 widget->style->ythickness) / 2);
219 gtk_paint_box (widget->style, widget->window,
220 GTK_WIDGET_STATE (widget), GTK_SHADOW_ETCHED_OUT,
221 &event->area, widget, "vseparator",
222 widget->allocation.x + (widget->allocation.width -
223 separator_width) / 2,
224 widget->allocation.y,
226 widget->allocation.height);
228 gtk_paint_vline (widget->style, widget->window,
229 GTK_WIDGET_STATE (widget),
230 &event->area, widget, "vseparator",
231 widget->allocation.y,
232 widget->allocation.y + widget->allocation.height - 1,
233 widget->allocation.x + (widget->allocation.width -
234 widget->style->xthickness) / 2);
243 * @orientation: the separator's orientation.
245 * Creates a new #GtkSeparator with the given orientation.
247 * Return value: a new #GtkSeparator.
252 gtk_separator_new (GtkOrientation orientation)
254 return g_object_new (GTK_TYPE_SEPARATOR,
255 "orientation", orientation,
261 #define __GTK_SEPARATOR_C__
262 #include "gtkaliasdef.c"