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-2000. 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
39 static void gtk_arrow_class_init (GtkArrowClass *klass);
40 static void gtk_arrow_init (GtkArrow *arrow);
41 static gint gtk_arrow_expose (GtkWidget *widget,
42 GdkEventExpose *event);
43 static void gtk_arrow_set_arg (GtkObject *object,
46 static void gtk_arrow_get_arg (GtkObject *object,
52 gtk_arrow_get_type (void)
54 static GtkType arrow_type = 0;
58 static const GtkTypeInfo arrow_info =
62 sizeof (GtkArrowClass),
63 (GtkClassInitFunc) gtk_arrow_class_init,
64 (GtkObjectInitFunc) gtk_arrow_init,
65 /* reserved_1 */ NULL,
66 /* reserved_2 */ NULL,
67 (GtkClassInitFunc) NULL,
70 arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info);
77 gtk_arrow_class_init (GtkArrowClass *class)
79 GtkObjectClass *object_class;
80 GtkWidgetClass *widget_class;
82 object_class = (GtkObjectClass*) class;
83 widget_class = (GtkWidgetClass*) class;
85 gtk_object_add_arg_type ("GtkArrow::arrow_type", GTK_TYPE_ARROW_TYPE, GTK_ARG_READWRITE, ARG_ARROW_TYPE);
86 gtk_object_add_arg_type ("GtkArrow::shadow_type", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW_TYPE);
88 object_class->set_arg = gtk_arrow_set_arg;
89 object_class->get_arg = gtk_arrow_get_arg;
91 widget_class->expose_event = gtk_arrow_expose;
95 gtk_arrow_set_arg (GtkObject *object,
101 arrow = GTK_ARROW (object);
106 gtk_arrow_set (arrow,
107 GTK_VALUE_ENUM (*arg),
110 case ARG_SHADOW_TYPE:
111 gtk_arrow_set (arrow,
113 GTK_VALUE_ENUM (*arg));
121 gtk_arrow_get_arg (GtkObject *object,
127 arrow = GTK_ARROW (object);
131 GTK_VALUE_ENUM (*arg) = arrow->arrow_type;
133 case ARG_SHADOW_TYPE:
134 GTK_VALUE_ENUM (*arg) = arrow->shadow_type;
137 arg->type = GTK_TYPE_INVALID;
143 gtk_arrow_init (GtkArrow *arrow)
145 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
147 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
148 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
150 arrow->arrow_type = GTK_ARROW_RIGHT;
151 arrow->shadow_type = GTK_SHADOW_OUT;
155 gtk_arrow_new (GtkArrowType arrow_type,
156 GtkShadowType shadow_type)
160 arrow = gtk_type_new (GTK_TYPE_ARROW);
162 arrow->arrow_type = arrow_type;
163 arrow->shadow_type = shadow_type;
165 return GTK_WIDGET (arrow);
169 gtk_arrow_set (GtkArrow *arrow,
170 GtkArrowType arrow_type,
171 GtkShadowType shadow_type)
173 g_return_if_fail (arrow != NULL);
174 g_return_if_fail (GTK_IS_ARROW (arrow));
176 if (((GtkArrowType) arrow->arrow_type != arrow_type) ||
177 ((GtkShadowType) arrow->shadow_type != shadow_type))
179 arrow->arrow_type = arrow_type;
180 arrow->shadow_type = shadow_type;
182 if (GTK_WIDGET_DRAWABLE (arrow))
183 gtk_widget_queue_clear (GTK_WIDGET (arrow));
189 gtk_arrow_expose (GtkWidget *widget,
190 GdkEventExpose *event)
194 GtkShadowType shadow_type;
199 g_return_val_if_fail (widget != NULL, FALSE);
200 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
201 g_return_val_if_fail (event != NULL, FALSE);
203 if (GTK_WIDGET_DRAWABLE (widget))
205 arrow = GTK_ARROW (widget);
206 misc = GTK_MISC (widget);
208 width = widget->allocation.width - misc->xpad * 2;
209 height = widget->allocation.height - misc->ypad * 2;
210 extent = MIN (width, height);
212 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
213 (widget->allocation.x + widget->allocation.width - extent - misc->xpad) * misc->xalign);
214 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
215 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
217 shadow_type = arrow->shadow_type;
219 if (widget->state == GTK_STATE_ACTIVE)
221 if (shadow_type == GTK_SHADOW_IN)
222 shadow_type = GTK_SHADOW_OUT;
223 else if (shadow_type == GTK_SHADOW_OUT)
224 shadow_type = GTK_SHADOW_IN;
225 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
226 shadow_type = GTK_SHADOW_ETCHED_OUT;
227 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
228 shadow_type = GTK_SHADOW_ETCHED_IN;
231 gtk_paint_arrow (widget->style, widget->window,
232 widget->state, shadow_type,
233 &event->area, widget, "arrow",
234 arrow->arrow_type, TRUE,
235 x, y, extent, extent);