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-2001. 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 #include "gtkprivate.h"
34 #define MIN_ARROW_SIZE 15
46 static gint gtk_arrow_expose (GtkWidget *widget,
47 GdkEventExpose *event);
48 static void gtk_arrow_set_property (GObject *object,
52 static void gtk_arrow_get_property (GObject *object,
58 G_DEFINE_TYPE (GtkArrow, gtk_arrow, GTK_TYPE_MISC)
62 gtk_arrow_class_init (GtkArrowClass *class)
64 GObjectClass *gobject_class;
65 GtkWidgetClass *widget_class;
67 gobject_class = (GObjectClass*) class;
68 widget_class = (GtkWidgetClass*) class;
70 gobject_class->set_property = gtk_arrow_set_property;
71 gobject_class->get_property = gtk_arrow_get_property;
73 g_object_class_install_property (gobject_class,
75 g_param_spec_enum ("arrow-type",
76 P_("Arrow direction"),
77 P_("The direction the arrow should point"),
80 GTK_PARAM_READWRITE));
81 g_object_class_install_property (gobject_class,
83 g_param_spec_enum ("shadow-type",
85 P_("Appearance of the shadow surrounding the arrow"),
88 GTK_PARAM_READWRITE));
89 gtk_widget_class_install_style_property (widget_class,
90 g_param_spec_float ("arrow-scaling",
92 P_("Amount of space sed up by arrow"),
96 widget_class->expose_event = gtk_arrow_expose;
100 gtk_arrow_set_property (GObject *object,
107 arrow = GTK_ARROW (object);
111 case PROP_ARROW_TYPE:
112 gtk_arrow_set (arrow,
113 g_value_get_enum (value),
116 case PROP_SHADOW_TYPE:
117 gtk_arrow_set (arrow,
119 g_value_get_enum (value));
122 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
129 gtk_arrow_get_property (GObject *object,
136 arrow = GTK_ARROW (object);
139 case PROP_ARROW_TYPE:
140 g_value_set_enum (value, arrow->arrow_type);
142 case PROP_SHADOW_TYPE:
143 g_value_set_enum (value, arrow->shadow_type);
146 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
152 gtk_arrow_init (GtkArrow *arrow)
154 GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW);
156 GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2;
157 GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2;
159 arrow->arrow_type = GTK_ARROW_RIGHT;
160 arrow->shadow_type = GTK_SHADOW_OUT;
164 gtk_arrow_new (GtkArrowType arrow_type,
165 GtkShadowType shadow_type)
169 arrow = g_object_new (GTK_TYPE_ARROW, NULL);
171 arrow->arrow_type = arrow_type;
172 arrow->shadow_type = shadow_type;
174 return GTK_WIDGET (arrow);
178 gtk_arrow_set (GtkArrow *arrow,
179 GtkArrowType arrow_type,
180 GtkShadowType shadow_type)
182 g_return_if_fail (GTK_IS_ARROW (arrow));
184 if ( ((GtkArrowType) arrow->arrow_type != arrow_type)
185 || ((GtkShadowType) arrow->shadow_type != shadow_type))
187 g_object_freeze_notify (G_OBJECT (arrow));
189 if ((GtkArrowType) arrow->arrow_type != arrow_type)
191 arrow->arrow_type = arrow_type;
192 g_object_notify (G_OBJECT (arrow), "arrow-type");
195 if ((GtkShadowType) arrow->shadow_type != shadow_type)
197 arrow->shadow_type = shadow_type;
198 g_object_notify (G_OBJECT (arrow), "shadow-type");
201 g_object_thaw_notify (G_OBJECT (arrow));
203 if (GTK_WIDGET_DRAWABLE (arrow))
204 gtk_widget_queue_draw (GTK_WIDGET (arrow));
210 gtk_arrow_expose (GtkWidget *widget,
211 GdkEventExpose *event)
213 GtkShadowType shadow_type;
218 GtkArrowType effective_arrow_type;
220 if (GTK_WIDGET_DRAWABLE (widget))
222 GtkArrow *arrow = GTK_ARROW (widget);
223 GtkMisc *misc = GTK_MISC (widget);
224 gfloat arrow_scaling;
225 gtk_widget_style_get (widget, "arrow-scaling", &arrow_scaling, NULL);
227 width = widget->allocation.width - misc->xpad * 2;
228 height = widget->allocation.height - misc->ypad * 2;
229 extent = MIN (width, height) * arrow_scaling;
230 effective_arrow_type = arrow->arrow_type;
232 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR)
233 xalign = misc->xalign;
236 xalign = 1.0 - misc->xalign;
237 if (arrow->arrow_type == GTK_ARROW_LEFT)
238 effective_arrow_type = GTK_ARROW_RIGHT;
239 else if (arrow->arrow_type == GTK_ARROW_RIGHT)
240 effective_arrow_type = GTK_ARROW_LEFT;
243 x = floor (widget->allocation.x + misc->xpad
244 + ((widget->allocation.width - extent) * xalign));
245 y = floor (widget->allocation.y + misc->ypad
246 + ((widget->allocation.height - extent) * misc->yalign));
248 shadow_type = arrow->shadow_type;
250 if (widget->state == GTK_STATE_ACTIVE)
252 if (shadow_type == GTK_SHADOW_IN)
253 shadow_type = GTK_SHADOW_OUT;
254 else if (shadow_type == GTK_SHADOW_OUT)
255 shadow_type = GTK_SHADOW_IN;
256 else if (shadow_type == GTK_SHADOW_ETCHED_IN)
257 shadow_type = GTK_SHADOW_ETCHED_OUT;
258 else if (shadow_type == GTK_SHADOW_ETCHED_OUT)
259 shadow_type = GTK_SHADOW_ETCHED_IN;
262 gtk_paint_arrow (widget->style, widget->window,
263 widget->state, shadow_type,
264 &event->area, widget, "arrow",
265 effective_arrow_type, TRUE,
266 x, y, extent, extent);
272 #define __GTK_ARROW_C__
273 #include "gtkaliasdef.c"