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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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.
22 #define MIN_ARROW_SIZE 11
31 static void gtk_arrow_class_init (GtkArrowClass *klass);
32 static void gtk_arrow_init (GtkArrow *arrow);
33 static gint gtk_arrow_expose (GtkWidget *widget,
34 GdkEventExpose *event);
35 static void gtk_arrow_set_arg (GtkObject *object,
38 static void gtk_arrow_get_arg (GtkObject *object,
44 gtk_arrow_get_type (void)
46 static GtkType arrow_type = 0;
50 GtkTypeInfo arrow_info =
54 sizeof (GtkArrowClass),
55 (GtkClassInitFunc) gtk_arrow_class_init,
56 (GtkObjectInitFunc) gtk_arrow_init,
57 /* reserved_1 */ NULL,
58 /* reserved_2 */ NULL,
59 (GtkClassInitFunc) NULL,
62 arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info);
69 gtk_arrow_class_init (GtkArrowClass *class)
71 GtkObjectClass *object_class;
72 GtkWidgetClass *widget_class;
74 object_class = (GtkObjectClass*) class;
75 widget_class = (GtkWidgetClass*) class;
77 gtk_object_add_arg_type ("GtkArrow::arrow_type", GTK_TYPE_ARROW_TYPE, GTK_ARG_READWRITE, ARG_ARROW_TYPE);
78 gtk_object_add_arg_type ("GtkArrow::shadow_type", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW_TYPE);
80 object_class->set_arg = gtk_arrow_set_arg;
81 object_class->get_arg = gtk_arrow_get_arg;
83 widget_class->expose_event = gtk_arrow_expose;
87 gtk_arrow_set_arg (GtkObject *object,
93 arrow = GTK_ARROW (object);
99 GTK_VALUE_ENUM (*arg),
102 case ARG_SHADOW_TYPE:
103 gtk_arrow_set (arrow,
105 GTK_VALUE_ENUM (*arg));
113 gtk_arrow_get_arg (GtkObject *object,
119 arrow = GTK_ARROW (object);
123 GTK_VALUE_ENUM (*arg) = arrow->arrow_type;
125 case ARG_SHADOW_TYPE:
126 GTK_VALUE_ENUM (*arg) = arrow->shadow_type;
129 arg->type = GTK_TYPE_INVALID;
135 gtk_arrow_init (GtkArrow *arrow)
137 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
139 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
140 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
142 arrow->arrow_type = GTK_ARROW_RIGHT;
143 arrow->shadow_type = GTK_SHADOW_OUT;
147 gtk_arrow_new (GtkArrowType arrow_type,
148 GtkShadowType shadow_type)
152 arrow = gtk_type_new (GTK_TYPE_ARROW);
154 arrow->arrow_type = arrow_type;
155 arrow->shadow_type = shadow_type;
157 return GTK_WIDGET (arrow);
161 gtk_arrow_set (GtkArrow *arrow,
162 GtkArrowType arrow_type,
163 GtkShadowType shadow_type)
165 g_return_if_fail (arrow != NULL);
166 g_return_if_fail (GTK_IS_ARROW (arrow));
168 if (((GtkArrowType) arrow->arrow_type != arrow_type) ||
169 ((GtkShadowType) arrow->shadow_type != shadow_type))
171 arrow->arrow_type = arrow_type;
172 arrow->shadow_type = shadow_type;
174 if (GTK_WIDGET_DRAWABLE (arrow))
175 gtk_widget_queue_clear (GTK_WIDGET (arrow));
181 gtk_arrow_expose (GtkWidget *widget,
182 GdkEventExpose *event)
186 GtkShadowType shadow_type;
191 g_return_val_if_fail (widget != NULL, FALSE);
192 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
193 g_return_val_if_fail (event != NULL, FALSE);
195 if (GTK_WIDGET_DRAWABLE (widget))
197 arrow = GTK_ARROW (widget);
198 misc = GTK_MISC (widget);
200 width = widget->allocation.width - misc->xpad * 2;
201 height = widget->allocation.height - misc->ypad * 2;
202 extent = MIN (width, height);
204 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
205 (widget->allocation.x + widget->allocation.width - extent - misc->xpad) * misc->xalign);
206 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
207 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
209 shadow_type = arrow->shadow_type;
211 if (widget->state == GTK_STATE_ACTIVE)
213 if (shadow_type == GTK_SHADOW_IN)
214 shadow_type = GTK_SHADOW_OUT;
215 else if (shadow_type == GTK_SHADOW_OUT)
216 shadow_type = GTK_SHADOW_IN;
217 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
218 shadow_type = GTK_SHADOW_ETCHED_OUT;
219 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
220 shadow_type = GTK_SHADOW_ETCHED_IN;
223 gtk_paint_arrow (widget->style, widget->window,
224 widget->state, shadow_type,
225 &event->area, widget, "arrow",
226 arrow->arrow_type, TRUE,
227 x, y, extent, extent);