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 /* reversed_1 */ NULL,
58 /* reversed_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 arrow->arrow_type = GTK_ARROW_RIGHT;
140 arrow->shadow_type = GTK_SHADOW_OUT;
144 gtk_arrow_new (GtkArrowType arrow_type,
145 GtkShadowType shadow_type)
149 arrow = gtk_type_new (gtk_arrow_get_type ());
151 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
152 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
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))
176 gdk_window_clear_area (GTK_WIDGET (arrow)->window,
177 GTK_WIDGET (arrow)->allocation.x + 1,
178 GTK_WIDGET (arrow)->allocation.y + 1,
179 GTK_WIDGET (arrow)->allocation.width - 2,
180 GTK_WIDGET (arrow)->allocation.height - 2);
181 gtk_widget_queue_draw (GTK_WIDGET (arrow));
188 gtk_arrow_expose (GtkWidget *widget,
189 GdkEventExpose *event)
193 GtkShadowType shadow_type;
198 g_return_val_if_fail (widget != NULL, FALSE);
199 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
200 g_return_val_if_fail (event != NULL, FALSE);
202 if (GTK_WIDGET_DRAWABLE (widget))
204 arrow = GTK_ARROW (widget);
205 misc = GTK_MISC (widget);
207 width = widget->allocation.width - misc->xpad * 2;
208 height = widget->allocation.height - misc->ypad * 2;
209 extent = MIN (width, height);
211 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
212 (widget->allocation.x + widget->allocation.width - extent - misc->ypad) * misc->xalign);
213 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
214 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
216 shadow_type = arrow->shadow_type;
218 if (widget->state == GTK_STATE_ACTIVE)
220 if (shadow_type == GTK_SHADOW_IN)
221 shadow_type = GTK_SHADOW_OUT;
222 else if (shadow_type == GTK_SHADOW_OUT)
223 shadow_type = GTK_SHADOW_IN;
224 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
225 shadow_type = GTK_SHADOW_ETCHED_OUT;
226 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
227 shadow_type = GTK_SHADOW_ETCHED_IN;
230 gtk_draw_arrow (widget->style, widget->window,
231 widget->state, shadow_type, arrow->arrow_type, TRUE,
232 x, y, extent, extent);