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 Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define MIN_ARROW_SIZE 11
24 static void gtk_arrow_class_init (GtkArrowClass *klass);
25 static void gtk_arrow_init (GtkArrow *arrow);
26 static gint gtk_arrow_expose (GtkWidget *widget,
27 GdkEventExpose *event);
33 static guint arrow_type = 0;
37 GtkTypeInfo arrow_info =
41 sizeof (GtkArrowClass),
42 (GtkClassInitFunc) gtk_arrow_class_init,
43 (GtkObjectInitFunc) gtk_arrow_init,
48 arrow_type = gtk_type_unique (gtk_misc_get_type (), &arrow_info);
55 gtk_arrow_class_init (GtkArrowClass *class)
57 GtkWidgetClass *widget_class;
59 widget_class = (GtkWidgetClass*) class;
61 widget_class->expose_event = gtk_arrow_expose;
65 gtk_arrow_init (GtkArrow *arrow)
67 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
69 arrow->arrow_type = GTK_ARROW_RIGHT;
70 arrow->shadow_type = GTK_SHADOW_OUT;
74 gtk_arrow_new (GtkArrowType arrow_type,
75 GtkShadowType shadow_type)
79 arrow = gtk_type_new (gtk_arrow_get_type ());
81 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
82 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
84 arrow->arrow_type = arrow_type;
85 arrow->shadow_type = shadow_type;
87 return GTK_WIDGET (arrow);
91 gtk_arrow_set (GtkArrow *arrow,
92 GtkArrowType arrow_type,
93 GtkShadowType shadow_type)
95 g_return_if_fail (arrow != NULL);
96 g_return_if_fail (GTK_IS_ARROW (arrow));
98 if (((GtkArrowType) arrow->arrow_type != arrow_type) ||
99 ((GtkShadowType) arrow->shadow_type != shadow_type))
101 arrow->arrow_type = arrow_type;
102 arrow->shadow_type = shadow_type;
104 if (GTK_WIDGET_DRAWABLE (arrow))
106 gdk_window_clear_area (GTK_WIDGET (arrow)->window,
107 GTK_WIDGET (arrow)->allocation.x + 1,
108 GTK_WIDGET (arrow)->allocation.y + 1,
109 GTK_WIDGET (arrow)->allocation.width - 2,
110 GTK_WIDGET (arrow)->allocation.height - 2);
111 gtk_widget_queue_draw (GTK_WIDGET (arrow));
118 gtk_arrow_expose (GtkWidget *widget,
119 GdkEventExpose *event)
123 GtkShadowType shadow_type;
128 g_return_val_if_fail (widget != NULL, FALSE);
129 g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE);
130 g_return_val_if_fail (event != NULL, FALSE);
132 if (GTK_WIDGET_DRAWABLE (widget))
134 arrow = GTK_ARROW (widget);
135 misc = GTK_MISC (widget);
137 width = widget->allocation.width - misc->xpad * 2;
138 height = widget->allocation.height - misc->ypad * 2;
139 extent = MIN (width, height);
141 x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) +
142 (widget->allocation.x + widget->allocation.width - extent - misc->ypad) * misc->xalign);
143 y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) +
144 (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign);
146 shadow_type = arrow->shadow_type;
148 if (widget->state == GTK_STATE_ACTIVE)
150 if (shadow_type == GTK_SHADOW_IN)
151 shadow_type = GTK_SHADOW_OUT;
152 else if (shadow_type == GTK_SHADOW_OUT)
153 shadow_type = GTK_SHADOW_IN;
154 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
155 shadow_type = GTK_SHADOW_ETCHED_OUT;
156 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
157 shadow_type = GTK_SHADOW_ETCHED_IN;
160 gtk_draw_arrow (widget->style, widget->window,
161 widget->state, shadow_type, arrow->arrow_type, TRUE,
162 x, y, extent, extent);