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 const gchar *trailer);
51 static void gtk_arrow_get_property (GObject *object,
55 const gchar *trailer);
58 gtk_arrow_get_type (void)
60 static GtkType arrow_type = 0;
64 static const GtkTypeInfo arrow_info =
68 sizeof (GtkArrowClass),
69 (GtkClassInitFunc) gtk_arrow_class_init,
70 (GtkObjectInitFunc) gtk_arrow_init,
71 /* reserved_1 */ NULL,
72 /* reserved_2 */ NULL,
73 (GtkClassInitFunc) NULL,
76 arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info);
83 gtk_arrow_class_init (GtkArrowClass *class)
85 GObjectClass *gobject_class;
86 GtkObjectClass *object_class;
87 GtkWidgetClass *widget_class;
89 gobject_class = (GObjectClass*) class;
90 object_class = (GtkObjectClass*) class;
91 widget_class = (GtkWidgetClass*) class;
93 gobject_class->set_property = gtk_arrow_set_property;
94 gobject_class->get_property = gtk_arrow_get_property;
96 g_object_class_install_property (gobject_class,
98 g_param_spec_enum ("arrow_type",
100 _("The direction the arrow should point"),
103 G_PARAM_READABLE | G_PARAM_WRITABLE));
104 g_object_class_install_property (gobject_class,
106 g_param_spec_enum ("shadow_type",
108 _("Appearance of the shadow surrounding the arrow"),
109 GTK_TYPE_SHADOW_TYPE,
111 G_PARAM_READABLE | G_PARAM_WRITABLE));
113 widget_class->expose_event = gtk_arrow_expose;
116 static void gtk_arrow_set_property (GObject *object,
120 const gchar *trailer)
124 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 static void gtk_arrow_get_property (GObject *object,
149 const gchar *trailer)
153 arrow = GTK_ARROW (object);
156 case PROP_ARROW_TYPE:
157 g_value_set_enum (value, arrow->arrow_type);
159 case PROP_SHADOW_TYPE:
160 g_value_set_enum (value, arrow->shadow_type);
163 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
169 gtk_arrow_init (GtkArrow *arrow)
171 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
173 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
174 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
176 arrow->arrow_type = GTK_ARROW_RIGHT;
177 arrow->shadow_type = GTK_SHADOW_OUT;
181 gtk_arrow_new (GtkArrowType arrow_type,
182 GtkShadowType shadow_type)
186 arrow = gtk_type_new (GTK_TYPE_ARROW);
188 arrow->arrow_type = arrow_type;
189 arrow->shadow_type = shadow_type;
191 return GTK_WIDGET (arrow);
195 gtk_arrow_set (GtkArrow *arrow,
196 GtkArrowType arrow_type,
197 GtkShadowType shadow_type)
199 gboolean changed = FALSE;
201 g_return_if_fail (arrow != NULL);
202 g_return_if_fail (GTK_IS_ARROW (arrow));
204 if ((GtkArrowType) arrow->arrow_type != arrow_type)
206 arrow->arrow_type = arrow_type;
207 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");
220 if (GTK_WIDGET_DRAWABLE (arrow))
221 gtk_widget_queue_clear (GTK_WIDGET (arrow));
227 gtk_arrow_expose (GtkWidget *widget,
228 GdkEventExpose *event)
232 GtkShadowType shadow_type;
237 g_return_val_if_fail (widget != NULL, FALSE);
238 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
239 g_return_val_if_fail (event != NULL, FALSE);
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);
250 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
251 (widget->allocation.x + widget->allocation.width - extent - misc->xpad) * misc->xalign);
252 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
253 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
255 shadow_type = arrow->shadow_type;
257 if (widget->state == GTK_STATE_ACTIVE)
259 if (shadow_type == GTK_SHADOW_IN)
260 shadow_type = GTK_SHADOW_OUT;
261 else if (shadow_type == GTK_SHADOW_OUT)
262 shadow_type = GTK_SHADOW_IN;
263 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
264 shadow_type = GTK_SHADOW_ETCHED_OUT;
265 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
266 shadow_type = GTK_SHADOW_ETCHED_IN;
269 gtk_paint_arrow (widget->style, widget->window,
270 widget->state, shadow_type,
271 &event->area, widget, "arrow",
272 arrow->arrow_type, TRUE,
273 x, y, extent, extent);