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
46 static void gtk_arrow_class_init (GtkArrowClass *klass);
47 static void gtk_arrow_init (GtkArrow *arrow);
48 static gint gtk_arrow_expose (GtkWidget *widget,
49 GdkEventExpose *event);
50 static void gtk_arrow_set_property (GObject *object,
54 static void gtk_arrow_get_property (GObject *object,
60 gtk_arrow_get_type (void)
62 static GType arrow_type = 0;
66 static const GTypeInfo arrow_info =
68 sizeof (GtkArrowClass),
70 NULL, /* base_finalize */
71 (GClassInitFunc) gtk_arrow_class_init,
72 NULL, /* class_finalize */
73 NULL, /* class_data */
76 (GInstanceInitFunc) gtk_arrow_init,
79 arrow_type = g_type_register_static (GTK_TYPE_MISC, g_intern_static_string ("GtkArrow"),
87 gtk_arrow_class_init (GtkArrowClass *class)
89 GObjectClass *gobject_class;
90 GtkWidgetClass *widget_class;
92 gobject_class = (GObjectClass*) class;
93 widget_class = (GtkWidgetClass*) class;
95 gobject_class->set_property = gtk_arrow_set_property;
96 gobject_class->get_property = gtk_arrow_get_property;
98 g_object_class_install_property (gobject_class,
100 g_param_spec_enum ("arrow-type",
101 P_("Arrow direction"),
102 P_("The direction the arrow should point"),
105 GTK_PARAM_READWRITE));
106 g_object_class_install_property (gobject_class,
108 g_param_spec_enum ("shadow-type",
110 P_("Appearance of the shadow surrounding the arrow"),
111 GTK_TYPE_SHADOW_TYPE,
113 GTK_PARAM_READWRITE));
115 widget_class->expose_event = gtk_arrow_expose;
119 gtk_arrow_set_property (GObject *object,
126 arrow = GTK_ARROW (object);
130 case PROP_ARROW_TYPE:
131 gtk_arrow_set (arrow,
132 g_value_get_enum (value),
135 case PROP_SHADOW_TYPE:
136 gtk_arrow_set (arrow,
138 g_value_get_enum (value));
141 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148 gtk_arrow_get_property (GObject *object,
155 arrow = GTK_ARROW (object);
158 case PROP_ARROW_TYPE:
159 g_value_set_enum (value, arrow->arrow_type);
161 case PROP_SHADOW_TYPE:
162 g_value_set_enum (value, arrow->shadow_type);
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 gtk_arrow_init (GtkArrow *arrow)
173 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
175 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
176 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
178 arrow->arrow_type = GTK_ARROW_RIGHT;
179 arrow->shadow_type = GTK_SHADOW_OUT;
183 gtk_arrow_new (GtkArrowType arrow_type,
184 GtkShadowType shadow_type)
188 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
190 arrow->arrow_type = arrow_type;
191 arrow->shadow_type = shadow_type;
193 return GTK_WIDGET (arrow);
197 gtk_arrow_set (GtkArrow *arrow,
198 GtkArrowType arrow_type,
199 GtkShadowType shadow_type)
201 g_return_if_fail (GTK_IS_ARROW (arrow));
203 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
204 || ((GtkShadowType) arrow->shadow_type != shadow_type))
206 g_object_freeze_notify (G_OBJECT (arrow));
208 if ((GtkArrowType) arrow->arrow_type != arrow_type)
210 arrow->arrow_type = arrow_type;
211 g_object_notify (G_OBJECT (arrow), "arrow-type");
214 if ((GtkShadowType) arrow->shadow_type != shadow_type)
216 arrow->shadow_type = shadow_type;
217 g_object_notify (G_OBJECT (arrow), "shadow-type");
220 g_object_thaw_notify (G_OBJECT (arrow));
222 if (GTK_WIDGET_DRAWABLE (arrow))
223 gtk_widget_queue_draw (GTK_WIDGET (arrow));
229 gtk_arrow_expose (GtkWidget *widget,
230 GdkEventExpose *event)
234 GtkShadowType shadow_type;
239 GtkArrowType effective_arrow_type;
241 if (GTK_WIDGET_DRAWABLE (widget))
243 arrow = GTK_ARROW (widget);
244 misc = GTK_MISC (widget);
246 width = widget->allocation.width - misc->xpad * 2;
247 height = widget->allocation.height - misc->ypad * 2;
248 extent = MIN (width, height) * 0.7;
249 effective_arrow_type = arrow->arrow_type;
251 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
252 xalign = misc->xalign;
255 xalign = 1.0 - misc->xalign;
256 if (arrow->arrow_type == GTK_ARROW_LEFT)
257 effective_arrow_type = GTK_ARROW_RIGHT;
258 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
259 effective_arrow_type = GTK_ARROW_LEFT;
262 x = floor (widget->allocation.x + misc->xpad
263 + ((widget->allocation.width - extent) * xalign));
264 y = floor (widget->allocation.y + misc->ypad
265 + ((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);
291 #define __GTK_ARROW_C__
292 #include "gtkaliasdef.c"