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"
54 #define MIN_ARROW_SIZE 15
63 static void gtk_arrow_set_property (GObject *object,
67 static void gtk_arrow_get_property (GObject *object,
71 static gboolean gtk_arrow_expose (GtkWidget *widget,
72 GdkEventExpose *event);
75 G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
79 gtk_arrow_class_init (GtkArrowClass *class)
81 GObjectClass *gobject_class;
82 GtkWidgetClass *widget_class;
84 gobject_class = (GObjectClass*) class;
85 widget_class = (GtkWidgetClass*) class;
87 gobject_class->set_property = gtk_arrow_set_property;
88 gobject_class->get_property = gtk_arrow_get_property;
90 widget_class->expose_event = gtk_arrow_expose;
92 g_object_class_install_property (gobject_class,
94 g_param_spec_enum ("arrow-type",
95 P_("Arrow direction"),
96 P_("The direction the arrow should point"),
99 GTK_PARAM_READWRITE));
101 g_object_class_install_property (gobject_class,
103 g_param_spec_enum ("shadow-type",
105 P_("Appearance of the shadow surrounding the arrow"),
106 GTK_TYPE_SHADOW_TYPE,
108 GTK_PARAM_READWRITE));
110 gtk_widget_class_install_style_property (widget_class,
111 g_param_spec_float ("arrow-scaling",
113 P_("Amount of space used up by arrow"),
115 GTK_PARAM_READABLE));
119 gtk_arrow_set_property (GObject *object,
124 GtkArrow *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);
145 gtk_arrow_get_property (GObject *object,
150 GtkArrow *arrow = GTK_ARROW (object);
154 case PROP_ARROW_TYPE:
155 g_value_set_enum (value, arrow->arrow_type);
157 case PROP_SHADOW_TYPE:
158 g_value_set_enum (value, arrow->shadow_type);
161 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
167 gtk_arrow_init (GtkArrow *arrow)
169 gtk_widget_set_has_window (GTK_WIDGET (arrow), FALSE);
171 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
172 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
174 arrow->arrow_type = GTK_ARROW_RIGHT;
175 arrow->shadow_type = GTK_SHADOW_OUT;
180 * @arrow_type: a valid #GtkArrowType.
181 * @shadow_type: a valid #GtkShadowType.
183 * Creates a new #GtkArrow widget.
185 * Returns: the new #GtkArrow widget.
188 gtk_arrow_new (GtkArrowType arrow_type,
189 GtkShadowType shadow_type)
193 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
195 arrow->arrow_type = arrow_type;
196 arrow->shadow_type = shadow_type;
198 return GTK_WIDGET (arrow);
203 * @arrow: a widget of type #GtkArrow.
204 * @arrow_type: a valid #GtkArrowType.
205 * @shadow_type: a valid #GtkShadowType.
207 * Sets the direction and style of the #GtkArrow, @arrow.
210 gtk_arrow_set (GtkArrow *arrow,
211 GtkArrowType arrow_type,
212 GtkShadowType shadow_type)
216 g_return_if_fail (GTK_IS_ARROW (arrow));
218 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
219 || ((GtkShadowType) arrow->shadow_type != shadow_type))
221 g_object_freeze_notify (G_OBJECT (arrow));
223 if ((GtkArrowType) arrow->arrow_type != arrow_type)
225 arrow->arrow_type = arrow_type;
226 g_object_notify (G_OBJECT (arrow), "arrow-type");
229 if ((GtkShadowType) arrow->shadow_type != shadow_type)
231 arrow->shadow_type = shadow_type;
232 g_object_notify (G_OBJECT (arrow), "shadow-type");
235 g_object_thaw_notify (G_OBJECT (arrow));
237 widget = GTK_WIDGET (arrow);
238 if (gtk_widget_is_drawable (widget))
239 gtk_widget_queue_draw (widget);
245 gtk_arrow_expose (GtkWidget *widget,
246 GdkEventExpose *event)
248 if (gtk_widget_is_drawable (widget))
250 GtkArrow *arrow = GTK_ARROW (widget);
251 GtkMisc *misc = GTK_MISC (widget);
252 GtkShadowType shadow_type;
257 GtkArrowType effective_arrow_type;
258 gfloat arrow_scaling;
260 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
262 width = widget->allocation.width - misc->xpad * 2;
263 height = widget->allocation.height - misc->ypad * 2;
264 extent = MIN (width, height) * arrow_scaling;
265 effective_arrow_type = arrow->arrow_type;
267 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
268 xalign = misc->xalign;
271 xalign = 1.0 - misc->xalign;
272 if (arrow->arrow_type == GTK_ARROW_LEFT)
273 effective_arrow_type = GTK_ARROW_RIGHT;
274 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
275 effective_arrow_type = GTK_ARROW_LEFT;
278 x = floor (widget->allocation.x + misc->xpad
279 + ((widget->allocation.width - extent) * xalign));
280 y = floor (widget->allocation.y + misc->ypad
281 + ((widget->allocation.height - extent) * misc->yalign));
283 shadow_type = arrow->shadow_type;
285 if (widget->state == GTK_STATE_ACTIVE)
287 if (shadow_type == GTK_SHADOW_IN)
288 shadow_type = GTK_SHADOW_OUT;
289 else if (shadow_type == GTK_SHADOW_OUT)
290 shadow_type = GTK_SHADOW_IN;
291 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
292 shadow_type = GTK_SHADOW_ETCHED_OUT;
293 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
294 shadow_type = GTK_SHADOW_ETCHED_IN;
297 gtk_paint_arrow (widget->style, widget->window,
298 widget->state, shadow_type,
299 &event->area, widget, "arrow",
300 effective_arrow_type, TRUE,
301 x, y, extent, extent);
307 #define __GTK_ARROW_C__
308 #include "gtkaliasdef.c"