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/.
31 #define MIN_ARROW_SIZE 11
43 static void gtk_arrow_class_init (GtkArrowClass *klass);
44 static void gtk_arrow_init (GtkArrow *arrow);
45 static gint gtk_arrow_expose (GtkWidget *widget,
46 GdkEventExpose *event);
47 static void gtk_arrow_set_property (GObject *object,
51 static void gtk_arrow_get_property (GObject *object,
57 gtk_arrow_get_type (void)
59 static GtkType arrow_type = 0;
63 static const GtkTypeInfo arrow_info =
67 sizeof (GtkArrowClass),
68 (GtkClassInitFunc) gtk_arrow_class_init,
69 (GtkObjectInitFunc) gtk_arrow_init,
70 /* reserved_1 */ NULL,
71 /* reserved_2 */ NULL,
72 (GtkClassInitFunc) NULL,
75 arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info);
82 gtk_arrow_class_init (GtkArrowClass *class)
84 GObjectClass *gobject_class;
85 GtkObjectClass *object_class;
86 GtkWidgetClass *widget_class;
88 gobject_class = (GObjectClass*) class;
89 object_class = (GtkObjectClass*) class;
90 widget_class = (GtkWidgetClass*) class;
92 gobject_class->set_property = gtk_arrow_set_property;
93 gobject_class->get_property = gtk_arrow_get_property;
95 g_object_class_install_property (gobject_class,
97 g_param_spec_enum ("arrow_type",
99 _("The direction the arrow should point"),
102 G_PARAM_READABLE | G_PARAM_WRITABLE));
103 g_object_class_install_property (gobject_class,
105 g_param_spec_enum ("shadow_type",
107 _("Appearance of the shadow surrounding the arrow"),
108 GTK_TYPE_SHADOW_TYPE,
110 G_PARAM_READABLE | G_PARAM_WRITABLE));
112 widget_class->expose_event = gtk_arrow_expose;
116 gtk_arrow_set_property (GObject *object,
123 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);
145 gtk_arrow_get_property (GObject *object,
152 arrow = GTK_ARROW (object);
155 case PROP_ARROW_TYPE:
156 g_value_set_enum (value, arrow->arrow_type);
158 case PROP_SHADOW_TYPE:
159 g_value_set_enum (value, arrow->shadow_type);
162 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
168 gtk_arrow_init (GtkArrow *arrow)
170 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
172 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
173 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
175 arrow->arrow_type = GTK_ARROW_RIGHT;
176 arrow->shadow_type = GTK_SHADOW_OUT;
180 gtk_arrow_new (GtkArrowType arrow_type,
181 GtkShadowType shadow_type)
185 arrow = gtk_type_new (GTK_TYPE_ARROW);
187 arrow->arrow_type = arrow_type;
188 arrow->shadow_type = shadow_type;
190 return GTK_WIDGET (arrow);
194 gtk_arrow_set (GtkArrow *arrow,
195 GtkArrowType arrow_type,
196 GtkShadowType shadow_type)
198 g_return_if_fail (GTK_IS_ARROW (arrow));
200 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
201 || ((GtkShadowType) arrow->shadow_type != shadow_type))
203 g_object_freeze_notify (G_OBJECT (arrow));
205 if ((GtkArrowType) arrow->arrow_type != arrow_type)
207 arrow->arrow_type = arrow_type;
208 g_object_notify (G_OBJECT (arrow), "arrow_type");
211 if ((GtkShadowType) arrow->shadow_type != shadow_type)
213 arrow->shadow_type = shadow_type;
214 g_object_notify (G_OBJECT (arrow), "shadow_type");
217 g_object_thaw_notify (G_OBJECT (arrow));
219 if (GTK_WIDGET_DRAWABLE (arrow))
220 gtk_widget_queue_clear (GTK_WIDGET (arrow));
226 gtk_arrow_expose (GtkWidget *widget,
227 GdkEventExpose *event)
231 GtkShadowType shadow_type;
237 if (GTK_WIDGET_DRAWABLE (widget))
239 arrow = GTK_ARROW (widget);
240 misc = GTK_MISC (widget);
242 width = widget->allocation.width - misc->xpad * 2;
243 height = widget->allocation.height - misc->ypad * 2;
244 extent = MIN (width, height);
246 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
247 xalign = misc->xalign;
249 xalign = 1.0 - misc->xalign;
251 x = floor (widget->allocation.x + misc->xpad
252 + ((widget->allocation.width - extent) * xalign)
254 y = floor (widget->allocation.y + misc->ypad
255 + ((widget->allocation.height - extent) * misc->yalign)
258 shadow_type = arrow->shadow_type;
260 if (widget->state == GTK_STATE_ACTIVE)
262 if (shadow_type == GTK_SHADOW_IN)
263 shadow_type = GTK_SHADOW_OUT;
264 else if (shadow_type == GTK_SHADOW_OUT)
265 shadow_type = GTK_SHADOW_IN;
266 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
267 shadow_type = GTK_SHADOW_ETCHED_OUT;
268 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
269 shadow_type = GTK_SHADOW_ETCHED_IN;
272 gtk_paint_arrow (widget->style, widget->window,
273 widget->state, shadow_type,
274 &event->area, widget, "arrow",
275 arrow->arrow_type, TRUE,
276 x, y, extent, extent);