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/.
30 #include "gtkprivate.h"
34 #define MIN_ARROW_SIZE 15
43 static gint gtk_arrow_expose (GtkWidget *widget,
44 GdkEventExpose *event);
45 static void gtk_arrow_set_property (GObject *object,
49 static void gtk_arrow_get_property (GObject *object,
55 G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
59 gtk_arrow_class_init (GtkArrowClass *class)
61 GObjectClass *gobject_class;
62 GtkWidgetClass *widget_class;
64 gobject_class = (GObjectClass*) class;
65 widget_class = (GtkWidgetClass*) class;
67 gobject_class->set_property = gtk_arrow_set_property;
68 gobject_class->get_property = gtk_arrow_get_property;
70 g_object_class_install_property (gobject_class,
72 g_param_spec_enum ("arrow-type",
73 P_("Arrow direction"),
74 P_("The direction the arrow should point"),
77 GTK_PARAM_READWRITE));
78 g_object_class_install_property (gobject_class,
80 g_param_spec_enum ("shadow-type",
82 P_("Appearance of the shadow surrounding the arrow"),
85 GTK_PARAM_READWRITE));
86 gtk_widget_class_install_style_property (widget_class,
87 g_param_spec_float ("arrow-scaling",
89 P_("Amount of space used up by arrow"),
93 widget_class->expose_event = gtk_arrow_expose;
97 gtk_arrow_set_property (GObject *object,
104 arrow = GTK_ARROW (object);
108 case PROP_ARROW_TYPE:
109 gtk_arrow_set (arrow,
110 g_value_get_enum (value),
113 case PROP_SHADOW_TYPE:
114 gtk_arrow_set (arrow,
116 g_value_get_enum (value));
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126 gtk_arrow_get_property (GObject *object,
133 arrow = GTK_ARROW (object);
136 case PROP_ARROW_TYPE:
137 g_value_set_enum (value, arrow->arrow_type);
139 case PROP_SHADOW_TYPE:
140 g_value_set_enum (value, arrow->shadow_type);
143 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
149 gtk_arrow_init (GtkArrow *arrow)
151 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
153 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
154 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
156 arrow->arrow_type = GTK_ARROW_RIGHT;
157 arrow->shadow_type = GTK_SHADOW_OUT;
161 gtk_arrow_new (GtkArrowType arrow_type,
162 GtkShadowType shadow_type)
166 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
168 arrow->arrow_type = arrow_type;
169 arrow->shadow_type = shadow_type;
171 return GTK_WIDGET (arrow);
175 gtk_arrow_set (GtkArrow *arrow,
176 GtkArrowType arrow_type,
177 GtkShadowType shadow_type)
179 g_return_if_fail (GTK_IS_ARROW (arrow));
181 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
182 || ((GtkShadowType) arrow->shadow_type != shadow_type))
184 g_object_freeze_notify (G_OBJECT (arrow));
186 if ((GtkArrowType) arrow->arrow_type != arrow_type)
188 arrow->arrow_type = arrow_type;
189 g_object_notify (G_OBJECT (arrow), "arrow-type");
192 if ((GtkShadowType) arrow->shadow_type != shadow_type)
194 arrow->shadow_type = shadow_type;
195 g_object_notify (G_OBJECT (arrow), "shadow-type");
198 g_object_thaw_notify (G_OBJECT (arrow));
200 if (GTK_WIDGET_DRAWABLE (arrow))
201 gtk_widget_queue_draw (GTK_WIDGET (arrow));
207 gtk_arrow_expose (GtkWidget *widget,
208 GdkEventExpose *event)
210 GtkShadowType shadow_type;
215 GtkArrowType effective_arrow_type;
217 if (GTK_WIDGET_DRAWABLE (widget))
219 GtkArrow *arrow = GTK_ARROW (widget);
220 GtkMisc *misc = GTK_MISC (widget);
221 gfloat arrow_scaling;
222 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
224 width = widget->allocation.width - misc->xpad * 2;
225 height = widget->allocation.height - misc->ypad * 2;
226 extent = MIN (width, height) * arrow_scaling;
227 effective_arrow_type = arrow->arrow_type;
229 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
230 xalign = misc->xalign;
233 xalign = 1.0 - misc->xalign;
234 if (arrow->arrow_type == GTK_ARROW_LEFT)
235 effective_arrow_type = GTK_ARROW_RIGHT;
236 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
237 effective_arrow_type = GTK_ARROW_LEFT;
240 x = floor (widget->allocation.x + misc->xpad
241 + ((widget->allocation.width - extent) * xalign));
242 y = floor (widget->allocation.y + misc->ypad
243 + ((widget->allocation.height - extent) * misc->yalign));
245 shadow_type = arrow->shadow_type;
247 if (widget->state == GTK_STATE_ACTIVE)
249 if (shadow_type == GTK_SHADOW_IN)
250 shadow_type = GTK_SHADOW_OUT;
251 else if (shadow_type == GTK_SHADOW_OUT)
252 shadow_type = GTK_SHADOW_IN;
253 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
254 shadow_type = GTK_SHADOW_ETCHED_OUT;
255 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
256 shadow_type = GTK_SHADOW_ETCHED_IN;
259 gtk_paint_arrow (widget->style, widget->window,
260 widget->state, shadow_type,
261 &event->area, widget, "arrow",
262 effective_arrow_type, TRUE,
263 x, y, extent, extent);
269 #define __GTK_ARROW_C__
270 #include "gtkaliasdef.c"