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/.
29 * @Short_description: Displays an arrow
31 * @See_also: gtk_paint_arrow()
33 * GtkArrow should be used to draw simple arrows that need to point in
34 * one of the four cardinal directions (up, down, left, or right). The
35 * style of the arrow can be one of shadow in, shadow out, etched in, or
36 * etched out. Note that these directions and style types may be
37 * ammended in versions of GTK+ to come.
39 * GtkArrow will fill any space alloted to it, but since it is inherited
40 * from #GtkMisc, it can be padded and/or aligned, to fill exactly the
41 * space the programmer desires.
43 * Arrows are created with a call to gtk_arrow_new(). The direction or
44 * style of an arrow can be changed after creation by using gtk_arrow_set().
50 #include "gtkprivate.h"
53 #define MIN_ARROW_SIZE 15
62 static void gtk_arrow_set_property (GObject *object,
66 static void gtk_arrow_get_property (GObject *object,
70 static gboolean gtk_arrow_expose (GtkWidget *widget,
71 GdkEventExpose *event);
74 G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
78 gtk_arrow_class_init (GtkArrowClass *class)
80 GObjectClass *gobject_class;
81 GtkWidgetClass *widget_class;
83 gobject_class = (GObjectClass*) class;
84 widget_class = (GtkWidgetClass*) class;
86 gobject_class->set_property = gtk_arrow_set_property;
87 gobject_class->get_property = gtk_arrow_get_property;
89 widget_class->expose_event = gtk_arrow_expose;
91 g_object_class_install_property (gobject_class,
93 g_param_spec_enum ("arrow-type",
94 P_("Arrow direction"),
95 P_("The direction the arrow should point"),
98 GTK_PARAM_READWRITE));
100 g_object_class_install_property (gobject_class,
102 g_param_spec_enum ("shadow-type",
104 P_("Appearance of the shadow surrounding the arrow"),
105 GTK_TYPE_SHADOW_TYPE,
107 GTK_PARAM_READWRITE));
109 gtk_widget_class_install_style_property (widget_class,
110 g_param_spec_float ("arrow-scaling",
112 P_("Amount of space used up by arrow"),
114 GTK_PARAM_READABLE));
118 gtk_arrow_set_property (GObject *object,
123 GtkArrow *arrow = GTK_ARROW (object);
127 case PROP_ARROW_TYPE:
128 gtk_arrow_set (arrow,
129 g_value_get_enum (value),
132 case PROP_SHADOW_TYPE:
133 gtk_arrow_set (arrow,
135 g_value_get_enum (value));
138 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 gtk_arrow_get_property (GObject *object,
149 GtkArrow *arrow = GTK_ARROW (object);
153 case PROP_ARROW_TYPE:
154 g_value_set_enum (value, arrow->arrow_type);
156 case PROP_SHADOW_TYPE:
157 g_value_set_enum (value, arrow->shadow_type);
160 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
166 gtk_arrow_init (GtkArrow *arrow)
168 gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
170 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
171 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
173 arrow->arrow_type = GTK_ARROW_RIGHT;
174 arrow->shadow_type = GTK_SHADOW_OUT;
179 * @arrow_type: a valid #GtkArrowType.
180 * @shadow_type: a valid #GtkShadowType.
182 * Creates a new #GtkArrow widget.
184 * Returns: the new #GtkArrow widget.
187 gtk_arrow_new (GtkArrowType arrow_type,
188 GtkShadowType shadow_type)
192 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
194 arrow->arrow_type = arrow_type;
195 arrow->shadow_type = shadow_type;
197 return GTK_WIDGET (arrow);
202 * @arrow: a widget of type #GtkArrow.
203 * @arrow_type: a valid #GtkArrowType.
204 * @shadow_type: a valid #GtkShadowType.
206 * Sets the direction and style of the #GtkArrow, @arrow.
209 gtk_arrow_set (GtkArrow *arrow,
210 GtkArrowType arrow_type,
211 GtkShadowType shadow_type)
215 g_return_if_fail (GTK_IS_ARROW (arrow));
217 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
218 || ((GtkShadowType) arrow->shadow_type != shadow_type))
220 g_object_freeze_notify (G_OBJECT (arrow));
222 if ((GtkArrowType) arrow->arrow_type != arrow_type)
224 arrow->arrow_type = arrow_type;
225 g_object_notify (G_OBJECT (arrow), "arrow-type");
228 if ((GtkShadowType) arrow->shadow_type != shadow_type)
230 arrow->shadow_type = shadow_type;
231 g_object_notify (G_OBJECT (arrow), "shadow-type");
234 g_object_thaw_notify (G_OBJECT (arrow));
236 widget = GTK_WIDGET (arrow);
237 if (gtk_widget_is_drawable (widget))
238 gtk_widget_queue_draw (widget);
244 gtk_arrow_expose (GtkWidget *widget,
245 GdkEventExpose *event)
247 if (gtk_widget_is_drawable (widget))
249 GtkArrow *arrow = GTK_ARROW (widget);
250 GtkMisc *misc = GTK_MISC (widget);
251 GtkShadowType shadow_type;
256 GtkArrowType effective_arrow_type;
257 gfloat arrow_scaling;
259 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
261 width = widget->allocation.width - misc->xpad * 2;
262 height = widget->allocation.height - misc->ypad * 2;
263 extent = MIN (width, height) * arrow_scaling;
264 effective_arrow_type = arrow->arrow_type;
266 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
267 xalign = misc->xalign;
270 xalign = 1.0 - misc->xalign;
271 if (arrow->arrow_type == GTK_ARROW_LEFT)
272 effective_arrow_type = GTK_ARROW_RIGHT;
273 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
274 effective_arrow_type = GTK_ARROW_LEFT;
277 x = floor (widget->allocation.x + misc->xpad
278 + ((widget->allocation.width - extent) * xalign));
279 y = floor (widget->allocation.y + misc->ypad
280 + ((widget->allocation.height - extent) * misc->yalign));
282 shadow_type = arrow->shadow_type;
284 if (widget->state == GTK_STATE_ACTIVE)
286 if (shadow_type == GTK_SHADOW_IN)
287 shadow_type = GTK_SHADOW_OUT;
288 else if (shadow_type == GTK_SHADOW_OUT)
289 shadow_type = GTK_SHADOW_IN;
290 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
291 shadow_type = GTK_SHADOW_ETCHED_OUT;
292 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
293 shadow_type = GTK_SHADOW_ETCHED_IN;
296 gtk_paint_arrow (widget->style, widget->window,
297 widget->state, shadow_type,
298 &event->area, widget, "arrow",
299 effective_arrow_type, TRUE,
300 x, y, extent, extent);