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-2001. 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/.
33 #define MIN_ARROW_SIZE 15
45 static void gtk_arrow_class_init (GtkArrowClass *klass);
46 static void gtk_arrow_init (GtkArrow *arrow);
47 static gint gtk_arrow_expose (GtkWidget *widget,
48 GdkEventExpose *event);
49 static void gtk_arrow_set_property (GObject *object,
53 static void gtk_arrow_get_property (GObject *object,
59 gtk_arrow_get_type (void)
61 static GType arrow_type = 0;
65 static const GTypeInfo arrow_info =
67 sizeof (GtkArrowClass),
69 NULL, /* base_finalize */
70 (GClassInitFunc) gtk_arrow_class_init,
71 NULL, /* class_finalize */
72 NULL, /* class_data */
75 (GInstanceInitFunc) gtk_arrow_init,
78 arrow_type = g_type_register_static (GTK_TYPE_MISC, "GtkArrow",
86 gtk_arrow_class_init (GtkArrowClass *class)
88 GObjectClass *gobject_class;
89 GtkWidgetClass *widget_class;
91 gobject_class = (GObjectClass*) class;
92 widget_class = (GtkWidgetClass*) class;
94 gobject_class->set_property = gtk_arrow_set_property;
95 gobject_class->get_property = gtk_arrow_get_property;
97 g_object_class_install_property (gobject_class,
99 g_param_spec_enum ("arrow-type",
100 P_("Arrow direction"),
101 P_("The direction the arrow should point"),
104 G_PARAM_READABLE | G_PARAM_WRITABLE));
105 g_object_class_install_property (gobject_class,
107 g_param_spec_enum ("shadow-type",
109 P_("Appearance of the shadow surrounding the arrow"),
110 GTK_TYPE_SHADOW_TYPE,
112 G_PARAM_READABLE | G_PARAM_WRITABLE));
114 widget_class->expose_event = gtk_arrow_expose;
118 gtk_arrow_set_property (GObject *object,
125 arrow = GTK_ARROW (object);
129 case PROP_ARROW_TYPE:
130 gtk_arrow_set (arrow,
131 g_value_get_enum (value),
134 case PROP_SHADOW_TYPE:
135 gtk_arrow_set (arrow,
137 g_value_get_enum (value));
140 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147 gtk_arrow_get_property (GObject *object,
154 arrow = GTK_ARROW (object);
157 case PROP_ARROW_TYPE:
158 g_value_set_enum (value, arrow->arrow_type);
160 case PROP_SHADOW_TYPE:
161 g_value_set_enum (value, arrow->shadow_type);
164 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
170 gtk_arrow_init (GtkArrow *arrow)
172 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
174 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
175 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
177 arrow->arrow_type = GTK_ARROW_RIGHT;
178 arrow->shadow_type = GTK_SHADOW_OUT;
182 gtk_arrow_new (GtkArrowType arrow_type,
183 GtkShadowType shadow_type)
187 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
189 arrow->arrow_type = arrow_type;
190 arrow->shadow_type = shadow_type;
192 return GTK_WIDGET (arrow);
196 gtk_arrow_set (GtkArrow *arrow,
197 GtkArrowType arrow_type,
198 GtkShadowType shadow_type)
200 g_return_if_fail (GTK_IS_ARROW (arrow));
202 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
203 || ((GtkShadowType) arrow->shadow_type != shadow_type))
205 g_object_freeze_notify (G_OBJECT (arrow));
207 if ((GtkArrowType) arrow->arrow_type != arrow_type)
209 arrow->arrow_type = arrow_type;
210 g_object_notify (G_OBJECT (arrow), "arrow_type");
213 if ((GtkShadowType) arrow->shadow_type != shadow_type)
215 arrow->shadow_type = shadow_type;
216 g_object_notify (G_OBJECT (arrow), "shadow_type");
219 g_object_thaw_notify (G_OBJECT (arrow));
221 if (GTK_WIDGET_DRAWABLE (arrow))
222 gtk_widget_queue_draw (GTK_WIDGET (arrow));
228 gtk_arrow_expose (GtkWidget *widget,
229 GdkEventExpose *event)
233 GtkShadowType shadow_type;
238 GtkArrowType effective_arrow_type;
240 if (GTK_WIDGET_DRAWABLE (widget))
242 arrow = GTK_ARROW (widget);
243 misc = GTK_MISC (widget);
245 width = widget->allocation.width - misc->xpad * 2;
246 height = widget->allocation.height - misc->ypad * 2;
247 extent = MIN (width, height) * 0.7;
248 effective_arrow_type = arrow->arrow_type;
250 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
251 xalign = misc->xalign;
254 xalign = 1.0 - misc->xalign;
255 if (arrow->arrow_type == GTK_ARROW_LEFT)
256 effective_arrow_type = GTK_ARROW_RIGHT;
257 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
258 effective_arrow_type = GTK_ARROW_LEFT;
261 x = floor (widget->allocation.x + misc->xpad
262 + ((widget->allocation.width - extent) * xalign)
264 y = floor (widget->allocation.y + misc->ypad
265 + ((widget->allocation.height - extent) * misc->yalign)
268 shadow_type = arrow->shadow_type;
270 if (widget->state == GTK_STATE_ACTIVE)
272 if (shadow_type == GTK_SHADOW_IN)
273 shadow_type = GTK_SHADOW_OUT;
274 else if (shadow_type == GTK_SHADOW_OUT)
275 shadow_type = GTK_SHADOW_IN;
276 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
277 shadow_type = GTK_SHADOW_ETCHED_OUT;
278 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
279 shadow_type = GTK_SHADOW_ETCHED_IN;
282 gtk_paint_arrow (widget->style, widget->window,
283 widget->state, shadow_type,
284 &event->area, widget, "arrow",
285 effective_arrow_type, TRUE,
286 x, y, extent, extent);