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 #define MIN_ARROW_SIZE 11
42 static void gtk_arrow_class_init (GtkArrowClass *klass);
43 static void gtk_arrow_init (GtkArrow *arrow);
44 static gint gtk_arrow_expose (GtkWidget *widget,
45 GdkEventExpose *event);
46 static void gtk_arrow_set_property (GObject *object,
50 static void gtk_arrow_get_property (GObject *object,
56 gtk_arrow_get_type (void)
58 static GtkType arrow_type = 0;
62 static const GtkTypeInfo arrow_info =
66 sizeof (GtkArrowClass),
67 (GtkClassInitFunc) gtk_arrow_class_init,
68 (GtkObjectInitFunc) gtk_arrow_init,
69 /* reserved_1 */ NULL,
70 /* reserved_2 */ NULL,
71 (GtkClassInitFunc) NULL,
74 arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info);
81 gtk_arrow_class_init (GtkArrowClass *class)
83 GObjectClass *gobject_class;
84 GtkObjectClass *object_class;
85 GtkWidgetClass *widget_class;
87 gobject_class = (GObjectClass*) class;
88 object_class = (GtkObjectClass*) class;
89 widget_class = (GtkWidgetClass*) class;
91 gobject_class->set_property = gtk_arrow_set_property;
92 gobject_class->get_property = gtk_arrow_get_property;
94 g_object_class_install_property (gobject_class,
96 g_param_spec_enum ("arrow_type",
98 _("The direction the arrow should point"),
101 G_PARAM_READABLE | G_PARAM_WRITABLE));
102 g_object_class_install_property (gobject_class,
104 g_param_spec_enum ("shadow_type",
106 _("Appearance of the shadow surrounding the arrow"),
107 GTK_TYPE_SHADOW_TYPE,
109 G_PARAM_READABLE | G_PARAM_WRITABLE));
111 widget_class->expose_event = gtk_arrow_expose;
115 gtk_arrow_set_property (GObject *object,
122 arrow = GTK_ARROW (object);
126 case PROP_ARROW_TYPE:
127 gtk_arrow_set (arrow,
128 g_value_get_enum (value),
131 case PROP_SHADOW_TYPE:
132 gtk_arrow_set (arrow,
134 g_value_get_enum (value));
137 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
144 gtk_arrow_get_property (GObject *object,
151 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_FLAGS (arrow, GTK_NO_WINDOW);
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;
179 gtk_arrow_new (GtkArrowType arrow_type,
180 GtkShadowType shadow_type)
184 arrow = gtk_type_new (GTK_TYPE_ARROW);
186 arrow->arrow_type = arrow_type;
187 arrow->shadow_type = shadow_type;
189 return GTK_WIDGET (arrow);
193 gtk_arrow_set (GtkArrow *arrow,
194 GtkArrowType arrow_type,
195 GtkShadowType shadow_type)
197 gboolean changed = FALSE;
199 g_return_if_fail (GTK_IS_ARROW (arrow));
201 if ((GtkArrowType) arrow->arrow_type != arrow_type)
203 arrow->arrow_type = arrow_type;
204 g_object_notify (G_OBJECT (arrow), "arrow_type");
208 if ((GtkShadowType) arrow->shadow_type != shadow_type)
210 arrow->shadow_type = shadow_type;
211 g_object_notify (G_OBJECT (arrow), "shadow_type");
217 if (GTK_WIDGET_DRAWABLE (arrow))
218 gtk_widget_queue_clear (GTK_WIDGET (arrow));
224 gtk_arrow_expose (GtkWidget *widget,
225 GdkEventExpose *event)
229 GtkShadowType shadow_type;
234 g_return_val_if_fail (widget != NULL, FALSE);
235 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
236 g_return_val_if_fail (event != NULL, FALSE);
238 if (GTK_WIDGET_DRAWABLE (widget))
240 arrow = GTK_ARROW (widget);
241 misc = GTK_MISC (widget);
243 width = widget->allocation.width - misc->xpad * 2;
244 height = widget->allocation.height - misc->ypad * 2;
245 extent = MIN (width, height);
247 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
248 (widget->allocation.x + widget->allocation.width - extent - misc->xpad) * misc->xalign);
249 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
250 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
252 shadow_type = arrow->shadow_type;
254 if (widget->state == GTK_STATE_ACTIVE)
256 if (shadow_type == GTK_SHADOW_IN)
257 shadow_type = GTK_SHADOW_OUT;
258 else if (shadow_type == GTK_SHADOW_OUT)
259 shadow_type = GTK_SHADOW_IN;
260 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
261 shadow_type = GTK_SHADOW_ETCHED_OUT;
262 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
263 shadow_type = GTK_SHADOW_ETCHED_IN;
266 gtk_paint_arrow (widget->style, widget->window,
267 widget->state, shadow_type,
268 &event->area, widget, "arrow",
269 arrow->arrow_type, TRUE,
270 x, y, extent, extent);