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/.
32 #define MIN_ARROW_SIZE 15
44 static void gtk_arrow_class_init (GtkArrowClass *klass);
45 static void gtk_arrow_init (GtkArrow *arrow);
46 static gint gtk_arrow_expose (GtkWidget *widget,
47 GdkEventExpose *event);
48 static void gtk_arrow_set_property (GObject *object,
52 static void gtk_arrow_get_property (GObject *object,
58 gtk_arrow_get_type (void)
60 static GType arrow_type = 0;
64 static const GTypeInfo arrow_info =
66 sizeof (GtkArrowClass),
68 NULL, /* base_finalize */
69 (GClassInitFunc) gtk_arrow_class_init,
70 NULL, /* class_finalize */
71 NULL, /* class_data */
74 (GInstanceInitFunc) gtk_arrow_init,
77 arrow_type = g_type_register_static (GTK_TYPE_MISC, "GtkArrow",
85 gtk_arrow_class_init (GtkArrowClass *class)
87 GObjectClass *gobject_class;
88 GtkWidgetClass *widget_class;
90 gobject_class = (GObjectClass*) class;
91 widget_class = (GtkWidgetClass*) class;
93 gobject_class->set_property = gtk_arrow_set_property;
94 gobject_class->get_property = gtk_arrow_get_property;
96 g_object_class_install_property (gobject_class,
98 g_param_spec_enum ("arrow_type",
99 P_("Arrow direction"),
100 P_("The direction the arrow should point"),
103 G_PARAM_READABLE | G_PARAM_WRITABLE));
104 g_object_class_install_property (gobject_class,
106 g_param_spec_enum ("shadow_type",
108 P_("Appearance of the shadow surrounding the arrow"),
109 GTK_TYPE_SHADOW_TYPE,
111 G_PARAM_READABLE | G_PARAM_WRITABLE));
113 widget_class->expose_event = gtk_arrow_expose;
117 gtk_arrow_set_property (GObject *object,
124 arrow = GTK_ARROW (object);
128 case PROP_ARROW_TYPE:
129 gtk_arrow_set (arrow,
130 g_value_get_enum (value),
133 case PROP_SHADOW_TYPE:
134 gtk_arrow_set (arrow,
136 g_value_get_enum (value));
139 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146 gtk_arrow_get_property (GObject *object,
153 arrow = GTK_ARROW (object);
156 case PROP_ARROW_TYPE:
157 g_value_set_enum (value, arrow->arrow_type);
159 case PROP_SHADOW_TYPE:
160 g_value_set_enum (value, arrow->shadow_type);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169 gtk_arrow_init (GtkArrow *arrow)
171 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
173 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
174 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
176 arrow->arrow_type = GTK_ARROW_RIGHT;
177 arrow->shadow_type = GTK_SHADOW_OUT;
181 gtk_arrow_new (GtkArrowType arrow_type,
182 GtkShadowType shadow_type)
186 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
188 arrow->arrow_type = arrow_type;
189 arrow->shadow_type = shadow_type;
191 return GTK_WIDGET (arrow);
195 gtk_arrow_set (GtkArrow *arrow,
196 GtkArrowType arrow_type,
197 GtkShadowType shadow_type)
199 g_return_if_fail (GTK_IS_ARROW (arrow));
201 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
202 || ((GtkShadowType) arrow->shadow_type != shadow_type))
204 g_object_freeze_notify (G_OBJECT (arrow));
206 if ((GtkArrowType) arrow->arrow_type != arrow_type)
208 arrow->arrow_type = arrow_type;
209 g_object_notify (G_OBJECT (arrow), "arrow_type");
212 if ((GtkShadowType) arrow->shadow_type != shadow_type)
214 arrow->shadow_type = shadow_type;
215 g_object_notify (G_OBJECT (arrow), "shadow_type");
218 g_object_thaw_notify (G_OBJECT (arrow));
220 if (GTK_WIDGET_DRAWABLE (arrow))
221 gtk_widget_queue_draw (GTK_WIDGET (arrow));
227 gtk_arrow_expose (GtkWidget *widget,
228 GdkEventExpose *event)
232 GtkShadowType shadow_type;
237 GtkArrowType effective_arrow_type;
239 if (GTK_WIDGET_DRAWABLE (widget))
241 arrow = GTK_ARROW (widget);
242 misc = GTK_MISC (widget);
244 width = widget->allocation.width - misc->xpad * 2;
245 height = widget->allocation.height - misc->ypad * 2;
246 extent = MIN (width, height) * 0.7;
247 effective_arrow_type = arrow->arrow_type;
249 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
250 xalign = misc->xalign;
253 xalign = 1.0 - misc->xalign;
254 if (arrow->arrow_type == GTK_ARROW_LEFT)
255 effective_arrow_type = GTK_ARROW_RIGHT;
256 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
257 effective_arrow_type = GTK_ARROW_LEFT;
260 x = floor (widget->allocation.x + misc->xpad
261 + ((widget->allocation.width - extent) * xalign)
263 y = floor (widget->allocation.y + misc->ypad
264 + ((widget->allocation.height - extent) * misc->yalign)
267 shadow_type = arrow->shadow_type;
269 if (widget->state == GTK_STATE_ACTIVE)
271 if (shadow_type == GTK_SHADOW_IN)
272 shadow_type = GTK_SHADOW_OUT;
273 else if (shadow_type == GTK_SHADOW_OUT)
274 shadow_type = GTK_SHADOW_IN;
275 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
276 shadow_type = GTK_SHADOW_ETCHED_OUT;
277 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
278 shadow_type = GTK_SHADOW_ETCHED_IN;
281 gtk_paint_arrow (widget->style, widget->window,
282 widget->state, shadow_type,
283 &event->area, widget, "arrow",
284 effective_arrow_type, TRUE,
285 x, y, extent, extent);