[14481] | 1 | /* GTK - The GIMP Toolkit |
---|
| 2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
---|
| 3 | * |
---|
| 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. |
---|
| 8 | * |
---|
| 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. |
---|
| 13 | * |
---|
| 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. |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * Modified by the GTK+ Team and others 1997-1999. 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/. |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | #include "gtkarrow.h" |
---|
| 28 | |
---|
| 29 | |
---|
| 30 | #define MIN_ARROW_SIZE 11 |
---|
| 31 | |
---|
| 32 | enum { |
---|
| 33 | ARG_0, |
---|
| 34 | ARG_ARROW_TYPE, |
---|
| 35 | ARG_SHADOW_TYPE |
---|
| 36 | }; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | static void gtk_arrow_class_init (GtkArrowClass *klass); |
---|
| 40 | static void gtk_arrow_init (GtkArrow *arrow); |
---|
| 41 | static gint gtk_arrow_expose (GtkWidget *widget, |
---|
| 42 | GdkEventExpose *event); |
---|
| 43 | static void gtk_arrow_set_arg (GtkObject *object, |
---|
| 44 | GtkArg *arg, |
---|
| 45 | guint arg_id); |
---|
| 46 | static void gtk_arrow_get_arg (GtkObject *object, |
---|
| 47 | GtkArg *arg, |
---|
| 48 | guint arg_id); |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | GtkType |
---|
| 52 | gtk_arrow_get_type (void) |
---|
| 53 | { |
---|
| 54 | static GtkType arrow_type = 0; |
---|
| 55 | |
---|
| 56 | if (!arrow_type) |
---|
| 57 | { |
---|
| 58 | static const GtkTypeInfo arrow_info = |
---|
| 59 | { |
---|
| 60 | "GtkArrow", |
---|
| 61 | sizeof (GtkArrow), |
---|
| 62 | sizeof (GtkArrowClass), |
---|
| 63 | (GtkClassInitFunc) gtk_arrow_class_init, |
---|
| 64 | (GtkObjectInitFunc) gtk_arrow_init, |
---|
| 65 | /* reserved_1 */ NULL, |
---|
| 66 | /* reserved_2 */ NULL, |
---|
| 67 | (GtkClassInitFunc) NULL, |
---|
| 68 | }; |
---|
| 69 | |
---|
| 70 | arrow_type = gtk_type_unique (GTK_TYPE_MISC, &arrow_info); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | return arrow_type; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | static void |
---|
| 77 | gtk_arrow_class_init (GtkArrowClass *class) |
---|
| 78 | { |
---|
| 79 | GtkObjectClass *object_class; |
---|
| 80 | GtkWidgetClass *widget_class; |
---|
| 81 | |
---|
| 82 | object_class = (GtkObjectClass*) class; |
---|
| 83 | widget_class = (GtkWidgetClass*) class; |
---|
| 84 | |
---|
| 85 | gtk_object_add_arg_type ("GtkArrow::arrow_type", GTK_TYPE_ARROW_TYPE, GTK_ARG_READWRITE, ARG_ARROW_TYPE); |
---|
| 86 | gtk_object_add_arg_type ("GtkArrow::shadow_type", GTK_TYPE_SHADOW_TYPE, GTK_ARG_READWRITE, ARG_SHADOW_TYPE); |
---|
| 87 | |
---|
| 88 | object_class->set_arg = gtk_arrow_set_arg; |
---|
| 89 | object_class->get_arg = gtk_arrow_get_arg; |
---|
| 90 | |
---|
| 91 | widget_class->expose_event = gtk_arrow_expose; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | static void |
---|
| 95 | gtk_arrow_set_arg (GtkObject *object, |
---|
| 96 | GtkArg *arg, |
---|
| 97 | guint arg_id) |
---|
| 98 | { |
---|
| 99 | GtkArrow *arrow; |
---|
| 100 | |
---|
| 101 | arrow = GTK_ARROW (object); |
---|
| 102 | |
---|
| 103 | switch (arg_id) |
---|
| 104 | { |
---|
| 105 | case ARG_ARROW_TYPE: |
---|
| 106 | gtk_arrow_set (arrow, |
---|
| 107 | GTK_VALUE_ENUM (*arg), |
---|
| 108 | arrow->shadow_type); |
---|
| 109 | break; |
---|
| 110 | case ARG_SHADOW_TYPE: |
---|
| 111 | gtk_arrow_set (arrow, |
---|
| 112 | arrow->arrow_type, |
---|
| 113 | GTK_VALUE_ENUM (*arg)); |
---|
| 114 | break; |
---|
| 115 | default: |
---|
| 116 | break; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | static void |
---|
| 121 | gtk_arrow_get_arg (GtkObject *object, |
---|
| 122 | GtkArg *arg, |
---|
| 123 | guint arg_id) |
---|
| 124 | { |
---|
| 125 | GtkArrow *arrow; |
---|
| 126 | |
---|
| 127 | arrow = GTK_ARROW (object); |
---|
| 128 | switch (arg_id) |
---|
| 129 | { |
---|
| 130 | case ARG_ARROW_TYPE: |
---|
| 131 | GTK_VALUE_ENUM (*arg) = arrow->arrow_type; |
---|
| 132 | break; |
---|
| 133 | case ARG_SHADOW_TYPE: |
---|
| 134 | GTK_VALUE_ENUM (*arg) = arrow->shadow_type; |
---|
| 135 | break; |
---|
| 136 | default: |
---|
| 137 | arg->type = GTK_TYPE_INVALID; |
---|
| 138 | break; |
---|
| 139 | } |
---|
| 140 | } |
---|
| 141 | |
---|
| 142 | static void |
---|
| 143 | gtk_arrow_init (GtkArrow *arrow) |
---|
| 144 | { |
---|
| 145 | GTK_WIDGET_SET_FLAGS (arrow, GTK_NO_WINDOW); |
---|
| 146 | |
---|
| 147 | GTK_WIDGET (arrow)->requisition.width = MIN_ARROW_SIZE + GTK_MISC (arrow)->xpad * 2; |
---|
| 148 | GTK_WIDGET (arrow)->requisition.height = MIN_ARROW_SIZE + GTK_MISC (arrow)->ypad * 2; |
---|
| 149 | |
---|
| 150 | arrow->arrow_type = GTK_ARROW_RIGHT; |
---|
| 151 | arrow->shadow_type = GTK_SHADOW_OUT; |
---|
| 152 | } |
---|
| 153 | |
---|
| 154 | GtkWidget* |
---|
| 155 | gtk_arrow_new (GtkArrowType arrow_type, |
---|
| 156 | GtkShadowType shadow_type) |
---|
| 157 | { |
---|
| 158 | GtkArrow *arrow; |
---|
| 159 | |
---|
| 160 | arrow = gtk_type_new (GTK_TYPE_ARROW); |
---|
| 161 | |
---|
| 162 | arrow->arrow_type = arrow_type; |
---|
| 163 | arrow->shadow_type = shadow_type; |
---|
| 164 | |
---|
| 165 | return GTK_WIDGET (arrow); |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | void |
---|
| 169 | gtk_arrow_set (GtkArrow *arrow, |
---|
| 170 | GtkArrowType arrow_type, |
---|
| 171 | GtkShadowType shadow_type) |
---|
| 172 | { |
---|
| 173 | g_return_if_fail (arrow != NULL); |
---|
| 174 | g_return_if_fail (GTK_IS_ARROW (arrow)); |
---|
| 175 | |
---|
| 176 | if (((GtkArrowType) arrow->arrow_type != arrow_type) || |
---|
| 177 | ((GtkShadowType) arrow->shadow_type != shadow_type)) |
---|
| 178 | { |
---|
| 179 | arrow->arrow_type = arrow_type; |
---|
| 180 | arrow->shadow_type = shadow_type; |
---|
| 181 | |
---|
| 182 | if (GTK_WIDGET_DRAWABLE (arrow)) |
---|
| 183 | gtk_widget_queue_clear (GTK_WIDGET (arrow)); |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | static gint |
---|
| 189 | gtk_arrow_expose (GtkWidget *widget, |
---|
| 190 | GdkEventExpose *event) |
---|
| 191 | { |
---|
| 192 | GtkArrow *arrow; |
---|
| 193 | GtkMisc *misc; |
---|
| 194 | GtkShadowType shadow_type; |
---|
| 195 | gint width, height; |
---|
| 196 | gint x, y; |
---|
| 197 | gint extent; |
---|
| 198 | |
---|
| 199 | g_return_val_if_fail (widget != NULL, FALSE); |
---|
| 200 | g_return_val_if_fail (GTK_IS_ARROW (widget), FALSE); |
---|
| 201 | g_return_val_if_fail (event != NULL, FALSE); |
---|
| 202 | |
---|
| 203 | if (GTK_WIDGET_DRAWABLE (widget)) |
---|
| 204 | { |
---|
| 205 | arrow = GTK_ARROW (widget); |
---|
| 206 | misc = GTK_MISC (widget); |
---|
| 207 | |
---|
| 208 | width = widget->allocation.width - misc->xpad * 2; |
---|
| 209 | height = widget->allocation.height - misc->ypad * 2; |
---|
| 210 | extent = MIN (width, height); |
---|
| 211 | |
---|
| 212 | x = ((widget->allocation.x + misc->xpad) * (1.0 - misc->xalign) + |
---|
| 213 | (widget->allocation.x + widget->allocation.width - extent - misc->xpad) * misc->xalign); |
---|
| 214 | y = ((widget->allocation.y + misc->ypad) * (1.0 - misc->yalign) + |
---|
| 215 | (widget->allocation.y + widget->allocation.height - extent - misc->ypad) * misc->yalign); |
---|
| 216 | |
---|
| 217 | shadow_type = arrow->shadow_type; |
---|
| 218 | |
---|
| 219 | if (widget->state == GTK_STATE_ACTIVE) |
---|
| 220 | { |
---|
| 221 | if (shadow_type == GTK_SHADOW_IN) |
---|
| 222 | shadow_type = GTK_SHADOW_OUT; |
---|
| 223 | else if (shadow_type == GTK_SHADOW_OUT) |
---|
| 224 | shadow_type = GTK_SHADOW_IN; |
---|
| 225 | else if (shadow_type == GTK_SHADOW_ETCHED_IN) |
---|
| 226 | shadow_type = GTK_SHADOW_ETCHED_OUT; |
---|
| 227 | else if (shadow_type == GTK_SHADOW_ETCHED_OUT) |
---|
| 228 | shadow_type = GTK_SHADOW_ETCHED_IN; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | gtk_paint_arrow (widget->style, widget->window, |
---|
| 232 | widget->state, shadow_type, |
---|
| 233 | &event->area, widget, "arrow", |
---|
| 234 | arrow->arrow_type, TRUE, |
---|
| 235 | x, y, extent, extent); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | return TRUE; |
---|
| 239 | } |
---|