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
25 static void gtk_arrow_class_init (GtkArrowClass *klass);
26 static void gtk_arrow_init (GtkArrow *arrow);
27 static gint gtk_arrow_expose (GtkWidget *widget,
28 GdkEventExpose *event);
34 static guint arrow_type = 0;
38 GtkTypeInfo arrow_info =
42 sizeof (GtkArrowClass),
43 (GtkClassInitFunc) gtk_arrow_class_init,
44 (GtkObjectInitFunc) gtk_arrow_init,
49 arrow_type = gtk_type_unique (gtk_misc_get_type (), &arrow_info);
56 gtk_arrow_class_init (GtkArrowClass *class)
58 GtkWidgetClass *widget_class;
60 widget_class = (GtkWidgetClass*) class;
62 widget_class->expose_event = gtk_arrow_expose;
66 gtk_arrow_init (GtkArrow *arrow)
68 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
70 arrow->arrow_type = GTK_ARROW_RIGHT;
71 arrow->shadow_type = GTK_SHADOW_OUT;
75 gtk_arrow_new (GtkArrowType arrow_type,
76 GtkShadowType shadow_type)
80 arrow = gtk_type_new (gtk_arrow_get_type ());
82 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
83 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
85 arrow->arrow_type = arrow_type;
86 arrow->shadow_type = shadow_type;
88 return GTK_WIDGET (arrow);
92 gtk_arrow_set (GtkArrow *arrow,
93 GtkArrowType arrow_type,
94 GtkShadowType shadow_type)
96 g_return_if_fail (arrow != NULL);
97 g_return_if_fail (GTK_IS_ARROW (arrow));
99 if (((GtkArrowType) arrow->arrow_type != arrow_type) ||
100 ((GtkShadowType) arrow->shadow_type != shadow_type))
102 arrow->arrow_type = arrow_type;
103 arrow->shadow_type = shadow_type;
105 if (GTK_WIDGET_DRAWABLE (arrow))
107 gdk_window_clear_area (GTK_WIDGET (arrow)->window,
108 GTK_WIDGET (arrow)->allocation.x + 1,
109 GTK_WIDGET (arrow)->allocation.y + 1,
110 GTK_WIDGET (arrow)->allocation.width - 2,
111 GTK_WIDGET (arrow)->allocation.height - 2);
112 gtk_widget_queue_draw (GTK_WIDGET (arrow));
119 gtk_arrow_expose (GtkWidget *widget,
120 GdkEventExpose *event)
124 GtkShadowType shadow_type;
129 g_return_val_if_fail (widget != NULL, FALSE);
130 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
131 g_return_val_if_fail (event != NULL, FALSE);
133 if (GTK_WIDGET_DRAWABLE (widget))
135 arrow = GTK_ARROW (widget);
136 misc = GTK_MISC (widget);
138 width = widget->allocation.width - misc->xpad * 2;
139 height = widget->allocation.height - misc->ypad * 2;
140 extent = MIN (width, height);
142 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
143 (widget->allocation.x + widget->allocation.width - extent - misc->ypad) * misc->xalign);
144 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
145 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
147 shadow_type = arrow->shadow_type;
149 if (widget->state == GTK_STATE_ACTIVE)
151 if (shadow_type == GTK_SHADOW_IN)
152 shadow_type = GTK_SHADOW_OUT;
153 else if (shadow_type == GTK_SHADOW_OUT)
154 shadow_type = GTK_SHADOW_IN;
155 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
156 shadow_type = GTK_SHADOW_ETCHED_OUT;
157 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
158 shadow_type = GTK_SHADOW_ETCHED_IN;
161 gtk_draw_arrow (widget->style, widget->window,
162 widget->state, shadow_type, arrow->arrow_type, TRUE,
163 x, y, extent, extent);