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/.
29 #include "gtkalignment.h"
30 #include "gtkbutton.h"
33 #include "gtkmarshalers.h"
38 #include "gtkiconfactory.h"
39 #include "gtkprivate.h"
43 static const GtkBorder default_default_border = { 1, 1, 1, 1 };
44 static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
45 static const GtkBorder default_inner_border = { 1, 1, 1, 1 };
47 /* Time out before giving up on getting a key release when animating
50 #define ACTIVATE_TIMEOUT 250
75 #define GTK_BUTTON_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_BUTTON, GtkButtonPrivate))
76 typedef struct _GtkButtonPrivate GtkButtonPrivate;
78 struct _GtkButtonPrivate
84 guint image_is_stock : 1;
87 GtkPositionType image_position;
90 static void gtk_button_destroy (GtkObject *object);
91 static void gtk_button_set_property (GObject *object,
95 static void gtk_button_get_property (GObject *object,
99 static void gtk_button_screen_changed (GtkWidget *widget,
100 GdkScreen *previous_screen);
101 static void gtk_button_realize (GtkWidget *widget);
102 static void gtk_button_unrealize (GtkWidget *widget);
103 static void gtk_button_map (GtkWidget *widget);
104 static void gtk_button_unmap (GtkWidget *widget);
105 static void gtk_button_style_set (GtkWidget *widget,
106 GtkStyle *prev_style);
107 static void gtk_button_size_request (GtkWidget *widget,
108 GtkRequisition *requisition);
109 static void gtk_button_size_allocate (GtkWidget *widget,
110 GtkAllocation *allocation);
111 static gint gtk_button_expose (GtkWidget *widget,
112 GdkEventExpose *event);
113 static gint gtk_button_button_press (GtkWidget *widget,
114 GdkEventButton *event);
115 static gint gtk_button_button_release (GtkWidget *widget,
116 GdkEventButton *event);
117 static gint gtk_button_grab_broken (GtkWidget *widget,
118 GdkEventGrabBroken *event);
119 static gint gtk_button_key_release (GtkWidget *widget,
121 static gint gtk_button_enter_notify (GtkWidget *widget,
122 GdkEventCrossing *event);
123 static gint gtk_button_leave_notify (GtkWidget *widget,
124 GdkEventCrossing *event);
125 static void gtk_real_button_pressed (GtkButton *button);
126 static void gtk_real_button_released (GtkButton *button);
127 static void gtk_real_button_activate (GtkButton *button);
128 static void gtk_button_update_state (GtkButton *button);
129 static void gtk_button_add (GtkContainer *container,
131 static GType gtk_button_child_type (GtkContainer *container);
132 static void gtk_button_finish_activate (GtkButton *button,
135 static GObject* gtk_button_constructor (GType type,
136 guint n_construct_properties,
137 GObjectConstructParam *construct_params);
138 static void gtk_button_construct_child (GtkButton *button);
139 static void gtk_button_state_changed (GtkWidget *widget,
140 GtkStateType previous_state);
141 static void gtk_button_grab_notify (GtkWidget *widget,
142 gboolean was_grabbed);
145 static guint button_signals[LAST_SIGNAL] = { 0 };
147 G_DEFINE_TYPE (GtkButton, gtk_button, GTK_TYPE_BIN)
150 gtk_button_class_init (GtkButtonClass *klass)
152 GObjectClass *gobject_class;
153 GtkObjectClass *object_class;
154 GtkWidgetClass *widget_class;
155 GtkContainerClass *container_class;
157 gobject_class = G_OBJECT_CLASS (klass);
158 object_class = (GtkObjectClass*) klass;
159 widget_class = (GtkWidgetClass*) klass;
160 container_class = (GtkContainerClass*) klass;
162 gobject_class->constructor = gtk_button_constructor;
163 gobject_class->set_property = gtk_button_set_property;
164 gobject_class->get_property = gtk_button_get_property;
166 object_class->destroy = gtk_button_destroy;
168 widget_class->screen_changed = gtk_button_screen_changed;
169 widget_class->realize = gtk_button_realize;
170 widget_class->unrealize = gtk_button_unrealize;
171 widget_class->map = gtk_button_map;
172 widget_class->unmap = gtk_button_unmap;
173 widget_class->style_set = gtk_button_style_set;
174 widget_class->size_request = gtk_button_size_request;
175 widget_class->size_allocate = gtk_button_size_allocate;
176 widget_class->expose_event = gtk_button_expose;
177 widget_class->button_press_event = gtk_button_button_press;
178 widget_class->button_release_event = gtk_button_button_release;
179 widget_class->grab_broken_event = gtk_button_grab_broken;
180 widget_class->key_release_event = gtk_button_key_release;
181 widget_class->enter_notify_event = gtk_button_enter_notify;
182 widget_class->leave_notify_event = gtk_button_leave_notify;
183 widget_class->state_changed = gtk_button_state_changed;
184 widget_class->grab_notify = gtk_button_grab_notify;
186 container_class->child_type = gtk_button_child_type;
187 container_class->add = gtk_button_add;
189 klass->pressed = gtk_real_button_pressed;
190 klass->released = gtk_real_button_released;
191 klass->clicked = NULL;
192 klass->enter = gtk_button_update_state;
193 klass->leave = gtk_button_update_state;
194 klass->activate = gtk_real_button_activate;
196 g_object_class_install_property (gobject_class,
198 g_param_spec_string ("label",
200 P_("Text of the label widget inside the button, if the button contains a label widget"),
202 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
204 g_object_class_install_property (gobject_class,
206 g_param_spec_boolean ("use-underline",
208 P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
210 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
212 g_object_class_install_property (gobject_class,
214 g_param_spec_boolean ("use-stock",
216 P_("If set, the label is used to pick a stock item instead of being displayed"),
218 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
220 g_object_class_install_property (gobject_class,
222 g_param_spec_boolean ("focus-on-click",
223 P_("Focus on click"),
224 P_("Whether the button grabs focus when it is clicked with the mouse"),
226 GTK_PARAM_READWRITE));
228 g_object_class_install_property (gobject_class,
230 g_param_spec_enum ("relief",
232 P_("The border relief style"),
233 GTK_TYPE_RELIEF_STYLE,
235 GTK_PARAM_READWRITE));
240 * If the child of the button is a #GtkMisc or #GtkAlignment, this property
241 * can be used to control it's horizontal alignment. 0.0 is left aligned,
242 * 1.0 is right aligned.
246 g_object_class_install_property (gobject_class,
248 g_param_spec_float("xalign",
249 P_("Horizontal alignment for child"),
250 P_("Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned"),
254 GTK_PARAM_READWRITE));
259 * If the child of the button is a #GtkMisc or #GtkAlignment, this property
260 * can be used to control it's vertical alignment. 0.0 is top aligned,
261 * 1.0 is bottom aligned.
265 g_object_class_install_property (gobject_class,
267 g_param_spec_float("yalign",
268 P_("Vertical alignment for child"),
269 P_("Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned"),
273 GTK_PARAM_READWRITE));
278 * The child widget to appear next to the button text.
282 g_object_class_install_property (gobject_class,
284 g_param_spec_object ("image",
286 P_("Child widget to appear next to the button text"),
288 GTK_PARAM_READWRITE));
291 * GtkButton:image-position:
293 * The position of the image relative to the text inside the button.
297 g_object_class_install_property (gobject_class,
299 g_param_spec_enum ("image-position",
300 P_("Image position"),
301 P_("The position of the image relative to the text"),
302 GTK_TYPE_POSITION_TYPE,
304 GTK_PARAM_READWRITE));
307 * GtkButton::pressed:
308 * @button: the object that received the signal
310 * Emitted when the button is pressed.
312 * @Deprecated: Use the GtkWidget::button-press-event signal.
314 button_signals[PRESSED] =
315 g_signal_new (I_("pressed"),
316 G_OBJECT_CLASS_TYPE (object_class),
318 G_STRUCT_OFFSET (GtkButtonClass, pressed),
320 _gtk_marshal_VOID__VOID,
324 * GtkButton::released:
325 * @button: the object that received the signal
327 * Emitted when the button is released.
329 * @Deprecated: Use the GtkWidget::button-release-event signal.
331 button_signals[RELEASED] =
332 g_signal_new (I_("released"),
333 G_OBJECT_CLASS_TYPE (object_class),
335 G_STRUCT_OFFSET (GtkButtonClass, released),
337 _gtk_marshal_VOID__VOID,
341 * GtkButton::clicked:
342 * @button: the object that received the signal
344 * Emitted when the button has been activated (pressed and released).
346 button_signals[CLICKED] =
347 g_signal_new (I_("clicked"),
348 G_OBJECT_CLASS_TYPE (object_class),
349 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
350 G_STRUCT_OFFSET (GtkButtonClass, clicked),
352 _gtk_marshal_VOID__VOID,
357 * @button: the object that received the signal
359 * Emitted when the pointer enters the button.
361 * @Deprecated: Use the GtkWidget::enter-notify-event signal.
363 button_signals[ENTER] =
364 g_signal_new (I_("enter"),
365 G_OBJECT_CLASS_TYPE (object_class),
367 G_STRUCT_OFFSET (GtkButtonClass, enter),
369 _gtk_marshal_VOID__VOID,
374 * @button: the object that received the signal
376 * Emitted when the pointer leaves the button.
378 * @Deprecated: Use the GtkWidget::leave-notify-event signal.
380 button_signals[LEAVE] =
381 g_signal_new (I_("leave"),
382 G_OBJECT_CLASS_TYPE (object_class),
384 G_STRUCT_OFFSET (GtkButtonClass, leave),
386 _gtk_marshal_VOID__VOID,
390 * GtkButton::activate:
391 * @widget: the object which received the signal.
393 * The "activate" signal on GtkButton is an action signal and
394 * emitting it causes the button to animate press then release.
395 * Applications should never connect to this signal, but use the
398 button_signals[ACTIVATE] =
399 g_signal_new (I_("activate"),
400 G_OBJECT_CLASS_TYPE (object_class),
401 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
402 G_STRUCT_OFFSET (GtkButtonClass, activate),
404 _gtk_marshal_VOID__VOID,
406 widget_class->activate_signal = button_signals[ACTIVATE];
408 gtk_widget_class_install_style_property (widget_class,
409 g_param_spec_boxed ("default-border",
410 P_("Default Spacing"),
411 P_("Extra space to add for CAN_DEFAULT buttons"),
413 GTK_PARAM_READABLE));
415 gtk_widget_class_install_style_property (widget_class,
416 g_param_spec_boxed ("default-outside-border",
417 P_("Default Outside Spacing"),
418 P_("Extra space to add for CAN_DEFAULT buttons that is always drawn outside the border"),
420 GTK_PARAM_READABLE));
421 gtk_widget_class_install_style_property (widget_class,
422 g_param_spec_int ("child-displacement-x",
423 P_("Child X Displacement"),
424 P_("How far in the x direction to move the child when the button is depressed"),
428 GTK_PARAM_READABLE));
429 gtk_widget_class_install_style_property (widget_class,
430 g_param_spec_int ("child-displacement-y",
431 P_("Child Y Displacement"),
432 P_("How far in the y direction to move the child when the button is depressed"),
436 GTK_PARAM_READABLE));
439 * GtkButton:displace-focus:
441 * Whether the child_displacement_x/child_displacement_y properties should also
442 * affect the focus rectangle.
446 gtk_widget_class_install_style_property (widget_class,
447 g_param_spec_boolean ("displace-focus",
448 P_("Displace focus"),
449 P_("Whether the child_displacement_x/_y properties should also affect the focus rectangle"),
451 GTK_PARAM_READABLE));
454 * GtkButton:inner-border:
456 * Sets the border between the button edges and child.
460 gtk_widget_class_install_style_property (widget_class,
461 g_param_spec_boxed ("inner-border",
463 P_("Border between button edges and child."),
465 GTK_PARAM_READABLE));
468 * GtkButton::image-spacing:
470 * Spacing in pixels between the image and label.
474 gtk_widget_class_install_style_property (widget_class,
475 g_param_spec_int ("image-spacing",
477 P_("Spacing in pixels between the image and label"),
481 GTK_PARAM_READABLE));
484 gtk_settings_install_property (g_param_spec_boolean ("gtk-button-images",
485 P_("Show button images"),
486 P_("Whether stock icons should be shown in buttons"),
488 GTK_PARAM_READWRITE));
490 g_type_class_add_private (gobject_class, sizeof (GtkButtonPrivate));
494 gtk_button_init (GtkButton *button)
496 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
498 GTK_WIDGET_SET_FLAGS (button, GTK_CAN_FOCUS | GTK_RECEIVES_DEFAULT);
499 GTK_WIDGET_SET_FLAGS (button, GTK_NO_WINDOW);
501 button->label_text = NULL;
503 button->constructed = FALSE;
504 button->in_button = FALSE;
505 button->button_down = FALSE;
506 button->relief = GTK_RELIEF_NORMAL;
507 button->use_stock = FALSE;
508 button->use_underline = FALSE;
509 button->depressed = FALSE;
510 button->depress_on_activate = TRUE;
511 button->focus_on_click = TRUE;
516 priv->image_is_stock = TRUE;
517 priv->image_position = GTK_POS_LEFT;
521 gtk_button_destroy (GtkObject *object)
523 GtkButton *button = GTK_BUTTON (object);
525 if (button->label_text)
527 g_free (button->label_text);
528 button->label_text = NULL;
531 (* GTK_OBJECT_CLASS (gtk_button_parent_class)->destroy) (object);
535 gtk_button_constructor (GType type,
536 guint n_construct_properties,
537 GObjectConstructParam *construct_params)
542 object = (* G_OBJECT_CLASS (gtk_button_parent_class)->constructor) (type,
543 n_construct_properties,
546 button = GTK_BUTTON (object);
547 button->constructed = TRUE;
549 if (button->label_text != NULL)
550 gtk_button_construct_child (button);
557 gtk_button_child_type (GtkContainer *container)
559 if (!GTK_BIN (container)->child)
560 return GTK_TYPE_WIDGET;
566 maybe_set_alignment (GtkButton *button,
569 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
571 if (GTK_IS_MISC (widget))
573 GtkMisc *misc = GTK_MISC (widget);
576 gtk_misc_set_alignment (misc, priv->xalign, priv->yalign);
578 else if (GTK_IS_ALIGNMENT (widget))
580 GtkAlignment *alignment = GTK_ALIGNMENT (widget);
583 gtk_alignment_set (alignment, priv->xalign, priv->yalign,
584 alignment->xscale, alignment->yscale);
589 gtk_button_add (GtkContainer *container,
592 maybe_set_alignment (GTK_BUTTON (container), widget);
594 GTK_CONTAINER_CLASS (gtk_button_parent_class)->add (container, widget);
598 gtk_button_set_property (GObject *object,
603 GtkButton *button = GTK_BUTTON (object);
604 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
609 gtk_button_set_label (button, g_value_get_string (value));
612 gtk_button_set_image (button, (GtkWidget *) g_value_get_object (value));
615 gtk_button_set_relief (button, g_value_get_enum (value));
617 case PROP_USE_UNDERLINE:
618 gtk_button_set_use_underline (button, g_value_get_boolean (value));
621 gtk_button_set_use_stock (button, g_value_get_boolean (value));
623 case PROP_FOCUS_ON_CLICK:
624 gtk_button_set_focus_on_click (button, g_value_get_boolean (value));
627 gtk_button_set_alignment (button, g_value_get_float (value), priv->yalign);
630 gtk_button_set_alignment (button, priv->xalign, g_value_get_float (value));
632 case PROP_IMAGE_POSITION:
633 gtk_button_set_image_position (button, g_value_get_enum (value));
636 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
642 gtk_button_get_property (GObject *object,
647 GtkButton *button = GTK_BUTTON (object);
648 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
653 g_value_set_string (value, button->label_text);
656 g_value_set_object (value, (GObject *)priv->image);
659 g_value_set_enum (value, gtk_button_get_relief (button));
661 case PROP_USE_UNDERLINE:
662 g_value_set_boolean (value, button->use_underline);
665 g_value_set_boolean (value, button->use_stock);
667 case PROP_FOCUS_ON_CLICK:
668 g_value_set_boolean (value, button->focus_on_click);
671 g_value_set_float (value, priv->xalign);
674 g_value_set_float (value, priv->yalign);
676 case PROP_IMAGE_POSITION:
677 g_value_set_enum (value, priv->image_position);
680 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
686 gtk_button_new (void)
688 return g_object_new (GTK_TYPE_BUTTON, NULL);
692 show_image (GtkButton *button)
696 if (button->label_text)
698 GtkSettings *settings;
700 settings = gtk_widget_get_settings (GTK_WIDGET (button));
701 g_object_get (settings, "gtk-button-images", &show, NULL);
710 gtk_button_construct_child (GtkButton *button)
712 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
717 GtkWidget *image = NULL;
718 gchar *label_text = NULL;
721 if (!button->constructed)
724 if (!button->label_text && !priv->image)
727 gtk_widget_style_get (GTK_WIDGET (button),
728 "image-spacing", &image_spacing,
731 if (priv->image && !priv->image_is_stock)
733 image = g_object_ref (priv->image);
735 gtk_container_remove (GTK_CONTAINER (image->parent), image);
740 if (GTK_BIN (button)->child)
741 gtk_container_remove (GTK_CONTAINER (button),
742 GTK_BIN (button)->child);
744 if (button->use_stock &&
745 button->label_text &&
746 gtk_stock_lookup (button->label_text, &item))
749 image = g_object_ref (gtk_image_new_from_stock (button->label_text, GTK_ICON_SIZE_BUTTON));
751 label_text = item.label;
754 label_text = button->label_text;
759 g_object_set (priv->image,
760 "visible", show_image (button),
764 if (priv->image_position == GTK_POS_LEFT ||
765 priv->image_position == GTK_POS_RIGHT)
766 box = gtk_hbox_new (FALSE, image_spacing);
768 box = gtk_vbox_new (FALSE, image_spacing);
771 align = gtk_alignment_new (priv->xalign, priv->yalign, 0.0, 0.0);
773 align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
775 if (priv->image_position == GTK_POS_LEFT ||
776 priv->image_position == GTK_POS_TOP)
777 gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
779 gtk_box_pack_end (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
783 label = gtk_label_new_with_mnemonic (label_text);
784 gtk_label_set_mnemonic_widget (GTK_LABEL (label),
785 GTK_WIDGET (button));
787 if (priv->image_position == GTK_POS_RIGHT ||
788 priv->image_position == GTK_POS_BOTTOM)
789 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
791 gtk_box_pack_end (GTK_BOX (box), label, FALSE, FALSE, 0);
794 gtk_container_add (GTK_CONTAINER (button), align);
795 gtk_container_add (GTK_CONTAINER (align), box);
796 gtk_widget_show_all (align);
798 g_object_unref (image);
803 if (button->use_underline)
805 label = gtk_label_new_with_mnemonic (button->label_text);
806 gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
809 label = gtk_label_new (button->label_text);
812 gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
814 gtk_widget_show (label);
815 gtk_container_add (GTK_CONTAINER (button), label);
820 gtk_button_new_with_label (const gchar *label)
822 return g_object_new (GTK_TYPE_BUTTON, "label", label, NULL);
826 * gtk_button_new_from_stock:
827 * @stock_id: the name of the stock item
829 * Creates a new #GtkButton containing the image and text from a stock item.
830 * Some stock ids have preprocessor macros like #GTK_STOCK_OK and
833 * If @stock_id is unknown, then it will be treated as a mnemonic
834 * label (as for gtk_button_new_with_mnemonic()).
836 * Returns: a new #GtkButton
839 gtk_button_new_from_stock (const gchar *stock_id)
841 return g_object_new (GTK_TYPE_BUTTON,
844 "use-underline", TRUE,
849 * gtk_button_new_with_mnemonic:
850 * @label: The text of the button, with an underscore in front of the
852 * @returns: a new #GtkButton
854 * Creates a new #GtkButton containing a label.
855 * If characters in @label are preceded by an underscore, they are underlined.
856 * If you need a literal underscore character in a label, use '__' (two
857 * underscores). The first underlined character represents a keyboard
858 * accelerator called a mnemonic.
859 * Pressing Alt and that key activates the button.
862 gtk_button_new_with_mnemonic (const gchar *label)
864 return g_object_new (GTK_TYPE_BUTTON, "label", label, "use-underline", TRUE, NULL);
868 gtk_button_pressed (GtkButton *button)
870 g_return_if_fail (GTK_IS_BUTTON (button));
873 g_signal_emit (button, button_signals[PRESSED], 0);
877 gtk_button_released (GtkButton *button)
879 g_return_if_fail (GTK_IS_BUTTON (button));
881 g_signal_emit (button, button_signals[RELEASED], 0);
885 gtk_button_clicked (GtkButton *button)
887 g_return_if_fail (GTK_IS_BUTTON (button));
889 g_signal_emit (button, button_signals[CLICKED], 0);
893 gtk_button_enter (GtkButton *button)
895 g_return_if_fail (GTK_IS_BUTTON (button));
897 g_signal_emit (button, button_signals[ENTER], 0);
901 gtk_button_leave (GtkButton *button)
903 g_return_if_fail (GTK_IS_BUTTON (button));
905 g_signal_emit (button, button_signals[LEAVE], 0);
909 gtk_button_set_relief (GtkButton *button,
910 GtkReliefStyle newrelief)
912 g_return_if_fail (GTK_IS_BUTTON (button));
914 if (newrelief != button->relief)
916 button->relief = newrelief;
917 g_object_notify (G_OBJECT (button), "relief");
918 gtk_widget_queue_draw (GTK_WIDGET (button));
923 gtk_button_get_relief (GtkButton *button)
925 g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_RELIEF_NORMAL);
927 return button->relief;
931 gtk_button_realize (GtkWidget *widget)
934 GdkWindowAttr attributes;
935 gint attributes_mask;
938 button = GTK_BUTTON (widget);
939 GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
941 border_width = GTK_CONTAINER (widget)->border_width;
943 attributes.window_type = GDK_WINDOW_CHILD;
944 attributes.x = widget->allocation.x + border_width;
945 attributes.y = widget->allocation.y + border_width;
946 attributes.width = widget->allocation.width - border_width * 2;
947 attributes.height = widget->allocation.height - border_width * 2;
948 attributes.wclass = GDK_INPUT_ONLY;
949 attributes.event_mask = gtk_widget_get_events (widget);
950 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
951 GDK_BUTTON_RELEASE_MASK |
952 GDK_ENTER_NOTIFY_MASK |
953 GDK_LEAVE_NOTIFY_MASK);
955 attributes_mask = GDK_WA_X | GDK_WA_Y;
957 widget->window = gtk_widget_get_parent_window (widget);
958 g_object_ref (widget->window);
960 button->event_window = gdk_window_new (gtk_widget_get_parent_window (widget),
961 &attributes, attributes_mask);
962 gdk_window_set_user_data (button->event_window, button);
964 widget->style = gtk_style_attach (widget->style, widget->window);
968 gtk_button_unrealize (GtkWidget *widget)
970 GtkButton *button = GTK_BUTTON (widget);
972 if (button->activate_timeout)
973 gtk_button_finish_activate (button, FALSE);
975 if (button->event_window)
977 gdk_window_set_user_data (button->event_window, NULL);
978 gdk_window_destroy (button->event_window);
979 button->event_window = NULL;
982 GTK_WIDGET_CLASS (gtk_button_parent_class)->unrealize (widget);
986 gtk_button_map (GtkWidget *widget)
988 GtkButton *button = GTK_BUTTON (widget);
990 GTK_WIDGET_CLASS (gtk_button_parent_class)->map (widget);
992 if (button->event_window)
993 gdk_window_show (button->event_window);
997 gtk_button_unmap (GtkWidget *widget)
999 GtkButton *button = GTK_BUTTON (widget);
1001 if (button->event_window)
1002 gdk_window_hide (button->event_window);
1004 GTK_WIDGET_CLASS (gtk_button_parent_class)->unmap (widget);
1008 gtk_button_style_set (GtkWidget *widget,
1009 GtkStyle *prev_style)
1011 gtk_button_construct_child (GTK_BUTTON (widget));
1015 gtk_button_get_props (GtkButton *button,
1016 GtkBorder *default_border,
1017 GtkBorder *default_outside_border,
1018 GtkBorder *inner_border,
1019 gboolean *interior_focus)
1021 GtkWidget *widget = GTK_WIDGET (button);
1022 GtkBorder *tmp_border;
1026 gtk_widget_style_get (widget, "default-border", &tmp_border, NULL);
1030 *default_border = *tmp_border;
1031 g_free (tmp_border);
1034 *default_border = default_default_border;
1037 if (default_outside_border)
1039 gtk_widget_style_get (widget, "default-outside-border", &tmp_border, NULL);
1043 *default_outside_border = *tmp_border;
1044 g_free (tmp_border);
1047 *default_outside_border = default_default_outside_border;
1052 gtk_widget_style_get (widget, "inner-border", &tmp_border, NULL);
1056 *inner_border = *tmp_border;
1057 g_free (tmp_border);
1060 *inner_border = default_inner_border;
1064 gtk_widget_style_get (widget, "interior-focus", interior_focus, NULL);
1068 gtk_button_size_request (GtkWidget *widget,
1069 GtkRequisition *requisition)
1071 GtkButton *button = GTK_BUTTON (widget);
1072 GtkBorder default_border;
1073 GtkBorder inner_border;
1077 gtk_button_get_props (button, &default_border, NULL, &inner_border, NULL);
1078 gtk_widget_style_get (GTK_WIDGET (widget),
1079 "focus-line-width", &focus_width,
1080 "focus-padding", &focus_pad,
1083 requisition->width = ((GTK_CONTAINER (widget)->border_width +
1084 GTK_WIDGET (widget)->style->xthickness) * 2 +
1085 inner_border.left + inner_border.right);
1086 requisition->height = ((GTK_CONTAINER (widget)->border_width +
1087 GTK_WIDGET (widget)->style->ythickness) * 2 +
1088 inner_border.top + inner_border.bottom);
1090 if (GTK_WIDGET_CAN_DEFAULT (widget))
1092 requisition->width += default_border.left + default_border.right;
1093 requisition->height += default_border.top + default_border.bottom;
1096 if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
1098 GtkRequisition child_requisition;
1100 gtk_widget_size_request (GTK_BIN (button)->child, &child_requisition);
1102 requisition->width += child_requisition.width;
1103 requisition->height += child_requisition.height;
1106 requisition->width += 2 * (focus_width + focus_pad);
1107 requisition->height += 2 * (focus_width + focus_pad);
1111 gtk_button_size_allocate (GtkWidget *widget,
1112 GtkAllocation *allocation)
1114 GtkButton *button = GTK_BUTTON (widget);
1115 GtkAllocation child_allocation;
1117 gint border_width = GTK_CONTAINER (widget)->border_width;
1118 gint xthickness = GTK_WIDGET (widget)->style->xthickness;
1119 gint ythickness = GTK_WIDGET (widget)->style->ythickness;
1120 GtkBorder default_border;
1121 GtkBorder inner_border;
1125 gtk_button_get_props (button, &default_border, NULL, &inner_border, NULL);
1126 gtk_widget_style_get (GTK_WIDGET (widget),
1127 "focus-line-width", &focus_width,
1128 "focus-padding", &focus_pad,
1132 widget->allocation = *allocation;
1134 if (GTK_WIDGET_REALIZED (widget))
1135 gdk_window_move_resize (button->event_window,
1136 widget->allocation.x + border_width,
1137 widget->allocation.y + border_width,
1138 widget->allocation.width - border_width * 2,
1139 widget->allocation.height - border_width * 2);
1141 if (GTK_BIN (button)->child && GTK_WIDGET_VISIBLE (GTK_BIN (button)->child))
1143 child_allocation.x = widget->allocation.x + border_width + inner_border.left + xthickness;
1144 child_allocation.y = widget->allocation.y + border_width + inner_border.top + ythickness;
1146 child_allocation.width = MAX (1, widget->allocation.width -
1149 inner_border.right -
1151 child_allocation.height = MAX (1, widget->allocation.height -
1154 inner_border.bottom -
1157 if (GTK_WIDGET_CAN_DEFAULT (button))
1159 child_allocation.x += default_border.left;
1160 child_allocation.y += default_border.top;
1161 child_allocation.width = MAX (1, child_allocation.width - default_border.left - default_border.right);
1162 child_allocation.height = MAX (1, child_allocation.height - default_border.top - default_border.bottom);
1165 if (GTK_WIDGET_CAN_FOCUS (button))
1167 child_allocation.x += focus_width + focus_pad;
1168 child_allocation.y += focus_width + focus_pad;
1169 child_allocation.width = MAX (1, child_allocation.width - (focus_width + focus_pad) * 2);
1170 child_allocation.height = MAX (1, child_allocation.height - (focus_width + focus_pad) * 2);
1173 if (button->depressed)
1175 gint child_displacement_x;
1176 gint child_displacement_y;
1178 gtk_widget_style_get (widget,
1179 "child-displacement-x", &child_displacement_x,
1180 "child-displacement-y", &child_displacement_y,
1182 child_allocation.x += child_displacement_x;
1183 child_allocation.y += child_displacement_y;
1186 gtk_widget_size_allocate (GTK_BIN (button)->child, &child_allocation);
1191 _gtk_button_paint (GtkButton *button,
1193 GtkStateType state_type,
1194 GtkShadowType shadow_type,
1195 const gchar *main_detail,
1196 const gchar *default_detail)
1202 GtkBorder default_border;
1203 GtkBorder default_outside_border;
1204 gboolean interior_focus;
1208 if (GTK_WIDGET_DRAWABLE (button))
1210 widget = GTK_WIDGET (button);
1211 border_width = GTK_CONTAINER (widget)->border_width;
1213 gtk_button_get_props (button, &default_border, &default_outside_border, NULL, &interior_focus);
1214 gtk_widget_style_get (GTK_WIDGET (widget),
1215 "focus-line-width", &focus_width,
1216 "focus-padding", &focus_pad,
1219 x = widget->allocation.x + border_width;
1220 y = widget->allocation.y + border_width;
1221 width = widget->allocation.width - border_width * 2;
1222 height = widget->allocation.height - border_width * 2;
1224 if (GTK_WIDGET_HAS_DEFAULT (widget) &&
1225 GTK_BUTTON (widget)->relief == GTK_RELIEF_NORMAL)
1227 gtk_paint_box (widget->style, widget->window,
1228 GTK_STATE_NORMAL, GTK_SHADOW_IN,
1229 area, widget, "buttondefault",
1230 x, y, width, height);
1232 x += default_border.left;
1233 y += default_border.top;
1234 width -= default_border.left + default_border.right;
1235 height -= default_border.top + default_border.bottom;
1237 else if (GTK_WIDGET_CAN_DEFAULT (widget))
1239 x += default_outside_border.left;
1240 y += default_outside_border.top;
1241 width -= default_outside_border.left + default_outside_border.right;
1242 height -= default_outside_border.top + default_outside_border.bottom;
1245 if (!interior_focus && GTK_WIDGET_HAS_FOCUS (widget))
1247 x += focus_width + focus_pad;
1248 y += focus_width + focus_pad;
1249 width -= 2 * (focus_width + focus_pad);
1250 height -= 2 * (focus_width + focus_pad);
1253 if (button->relief != GTK_RELIEF_NONE || button->depressed ||
1254 GTK_WIDGET_STATE(widget) == GTK_STATE_PRELIGHT)
1255 gtk_paint_box (widget->style, widget->window,
1257 shadow_type, area, widget, "button",
1258 x, y, width, height);
1260 if (GTK_WIDGET_HAS_FOCUS (widget))
1262 gint child_displacement_x;
1263 gint child_displacement_y;
1264 gboolean displace_focus;
1266 gtk_widget_style_get (GTK_WIDGET (widget),
1267 "child-displacement-y", &child_displacement_y,
1268 "child-displacement-x", &child_displacement_x,
1269 "displace-focus", &displace_focus,
1274 x += widget->style->xthickness + focus_pad;
1275 y += widget->style->ythickness + focus_pad;
1276 width -= 2 * (widget->style->xthickness + focus_pad);
1277 height -= 2 * (widget->style->ythickness + focus_pad);
1281 x -= focus_width + focus_pad;
1282 y -= focus_width + focus_pad;
1283 width += 2 * (focus_width + focus_pad);
1284 height += 2 * (focus_width + focus_pad);
1287 if (button->depressed && displace_focus)
1289 x += child_displacement_x;
1290 y += child_displacement_y;
1293 gtk_paint_focus (widget->style, widget->window, GTK_WIDGET_STATE (widget),
1294 area, widget, "button",
1295 x, y, width, height);
1301 gtk_button_expose (GtkWidget *widget,
1302 GdkEventExpose *event)
1304 if (GTK_WIDGET_DRAWABLE (widget))
1306 GtkButton *button = GTK_BUTTON (widget);
1308 _gtk_button_paint (button, &event->area,
1309 GTK_WIDGET_STATE (widget),
1310 button->depressed ? GTK_SHADOW_IN : GTK_SHADOW_OUT,
1311 "button", "buttondefault");
1313 (* GTK_WIDGET_CLASS (gtk_button_parent_class)->expose_event) (widget, event);
1320 gtk_button_button_press (GtkWidget *widget,
1321 GdkEventButton *event)
1325 if (event->type == GDK_BUTTON_PRESS)
1327 button = GTK_BUTTON (widget);
1329 if (button->focus_on_click && !GTK_WIDGET_HAS_FOCUS (widget))
1330 gtk_widget_grab_focus (widget);
1332 if (event->button == 1)
1333 gtk_button_pressed (button);
1340 gtk_button_button_release (GtkWidget *widget,
1341 GdkEventButton *event)
1345 if (event->button == 1)
1347 button = GTK_BUTTON (widget);
1348 gtk_button_released (button);
1355 gtk_button_grab_broken (GtkWidget *widget,
1356 GdkEventGrabBroken *event)
1358 GtkButton *button = GTK_BUTTON (widget);
1361 /* Simulate a button release without the pointer in the button */
1362 if (button->button_down)
1364 save_in = button->in_button;
1365 button->in_button = FALSE;
1366 gtk_button_released (button);
1367 if (save_in != button->in_button)
1369 button->in_button = save_in;
1370 gtk_button_update_state (button);
1378 gtk_button_key_release (GtkWidget *widget,
1381 GtkButton *button = GTK_BUTTON (widget);
1383 if (button->activate_timeout)
1385 gtk_button_finish_activate (button, TRUE);
1388 else if (GTK_WIDGET_CLASS (gtk_button_parent_class)->key_release_event)
1389 return GTK_WIDGET_CLASS (gtk_button_parent_class)->key_release_event (widget, event);
1395 gtk_button_enter_notify (GtkWidget *widget,
1396 GdkEventCrossing *event)
1399 GtkWidget *event_widget;
1401 button = GTK_BUTTON (widget);
1402 event_widget = gtk_get_event_widget ((GdkEvent*) event);
1404 if ((event_widget == widget) &&
1405 (event->detail != GDK_NOTIFY_INFERIOR))
1407 button->in_button = TRUE;
1408 gtk_button_enter (button);
1415 gtk_button_leave_notify (GtkWidget *widget,
1416 GdkEventCrossing *event)
1419 GtkWidget *event_widget;
1421 button = GTK_BUTTON (widget);
1422 event_widget = gtk_get_event_widget ((GdkEvent*) event);
1424 if ((event_widget == widget) &&
1425 (event->detail != GDK_NOTIFY_INFERIOR))
1427 button->in_button = FALSE;
1428 gtk_button_leave (button);
1435 gtk_real_button_pressed (GtkButton *button)
1437 if (button->activate_timeout)
1440 button->button_down = TRUE;
1441 gtk_button_update_state (button);
1445 gtk_real_button_released (GtkButton *button)
1447 if (button->button_down)
1449 button->button_down = FALSE;
1451 if (button->activate_timeout)
1454 if (button->in_button)
1455 gtk_button_clicked (button);
1457 gtk_button_update_state (button);
1462 button_activate_timeout (gpointer data)
1464 GDK_THREADS_ENTER ();
1466 gtk_button_finish_activate (data, TRUE);
1468 GDK_THREADS_LEAVE ();
1474 gtk_real_button_activate (GtkButton *button)
1476 GtkWidget *widget = GTK_WIDGET (button);
1477 GtkButtonPrivate *priv;
1480 priv = GTK_BUTTON_GET_PRIVATE (button);
1482 if (GTK_WIDGET_REALIZED (button) && !button->activate_timeout)
1484 time = gtk_get_current_event_time ();
1485 if (gdk_keyboard_grab (button->event_window, TRUE, time) ==
1488 priv->has_grab = TRUE;
1489 priv->grab_time = time;
1492 gtk_grab_add (widget);
1494 button->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT,
1495 button_activate_timeout,
1497 button->button_down = TRUE;
1498 gtk_button_update_state (button);
1499 gtk_widget_queue_draw (GTK_WIDGET (button));
1504 gtk_button_finish_activate (GtkButton *button,
1507 GtkWidget *widget = GTK_WIDGET (button);
1508 GtkButtonPrivate *priv;
1510 priv = GTK_BUTTON_GET_PRIVATE (button);
1512 g_source_remove (button->activate_timeout);
1513 button->activate_timeout = 0;
1517 gdk_display_keyboard_ungrab (gtk_widget_get_display (widget),
1520 gtk_grab_remove (widget);
1522 button->button_down = FALSE;
1524 gtk_button_update_state (button);
1525 gtk_widget_queue_draw (GTK_WIDGET (button));
1528 gtk_button_clicked (button);
1532 * gtk_button_set_label:
1533 * @button: a #GtkButton
1536 * Sets the text of the label of the button to @str. This text is
1537 * also used to select the stock item if gtk_button_set_use_stock()
1540 * This will also clear any previously set labels.
1543 gtk_button_set_label (GtkButton *button,
1548 g_return_if_fail (GTK_IS_BUTTON (button));
1550 new_label = g_strdup (label);
1551 g_free (button->label_text);
1552 button->label_text = new_label;
1554 gtk_button_construct_child (button);
1556 g_object_notify (G_OBJECT (button), "label");
1560 * gtk_button_get_label:
1561 * @button: a #GtkButton
1563 * Fetches the text from the label of the button, as set by
1564 * gtk_button_set_label(). If the label text has not
1565 * been set the return value will be %NULL. This will be the
1566 * case if you create an empty button with gtk_button_new() to
1567 * use as a container.
1569 * Return value: The text of the label widget. This string is owned
1570 * by the widget and must not be modified or freed.
1572 G_CONST_RETURN gchar *
1573 gtk_button_get_label (GtkButton *button)
1575 g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
1577 return button->label_text;
1581 * gtk_button_set_use_underline:
1582 * @button: a #GtkButton
1583 * @use_underline: %TRUE if underlines in the text indicate mnemonics
1585 * If true, an underline in the text of the button label indicates
1586 * the next character should be used for the mnemonic accelerator key.
1589 gtk_button_set_use_underline (GtkButton *button,
1590 gboolean use_underline)
1592 g_return_if_fail (GTK_IS_BUTTON (button));
1594 use_underline = use_underline != FALSE;
1596 if (use_underline != button->use_underline)
1598 button->use_underline = use_underline;
1600 gtk_button_construct_child (button);
1602 g_object_notify (G_OBJECT (button), "use-underline");
1607 * gtk_button_get_use_underline:
1608 * @button: a #GtkButton
1610 * Returns whether an embedded underline in the button label indicates a
1611 * mnemonic. See gtk_button_set_use_underline ().
1613 * Return value: %TRUE if an embedded underline in the button label
1614 * indicates the mnemonic accelerator keys.
1617 gtk_button_get_use_underline (GtkButton *button)
1619 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
1621 return button->use_underline;
1625 * gtk_button_set_use_stock:
1626 * @button: a #GtkButton
1627 * @use_stock: %TRUE if the button should use a stock item
1629 * If true, the label set on the button is used as a
1630 * stock id to select the stock item for the button.
1633 gtk_button_set_use_stock (GtkButton *button,
1636 g_return_if_fail (GTK_IS_BUTTON (button));
1638 use_stock = use_stock != FALSE;
1640 if (use_stock != button->use_stock)
1642 button->use_stock = use_stock;
1644 gtk_button_construct_child (button);
1646 g_object_notify (G_OBJECT (button), "use-stock");
1651 * gtk_button_get_use_stock:
1652 * @button: a #GtkButton
1654 * Returns whether the button label is a stock item.
1656 * Return value: %TRUE if the button label is used to
1657 * select a stock item instead of being
1658 * used directly as the label text.
1661 gtk_button_get_use_stock (GtkButton *button)
1663 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
1665 return button->use_stock;
1669 * gtk_button_set_focus_on_click:
1670 * @button: a #GtkButton
1671 * @focus_on_click: whether the button grabs focus when clicked with the mouse
1673 * Sets whether the button will grab focus when it is clicked with the mouse.
1674 * Making mouse clicks not grab focus is useful in places like toolbars where
1675 * you don't want the keyboard focus removed from the main area of the
1681 gtk_button_set_focus_on_click (GtkButton *button,
1682 gboolean focus_on_click)
1684 g_return_if_fail (GTK_IS_BUTTON (button));
1686 focus_on_click = focus_on_click != FALSE;
1688 if (button->focus_on_click != focus_on_click)
1690 button->focus_on_click = focus_on_click;
1692 g_object_notify (G_OBJECT (button), "focus-on-click");
1697 * gtk_button_get_focus_on_click:
1698 * @button: a #GtkButton
1700 * Returns whether the button grabs focus when it is clicked with the mouse.
1701 * See gtk_button_set_focus_on_click().
1703 * Return value: %TRUE if the button grabs focus when it is clicked with
1709 gtk_button_get_focus_on_click (GtkButton *button)
1711 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
1713 return button->focus_on_click;
1717 * gtk_button_set_alignment:
1718 * @button: a #GtkButton
1719 * @xalign: the horizontal position of the child, 0.0 is left aligned,
1720 * 1.0 is right aligned
1721 * @yalign: the vertical position of the child, 0.0 is top aligned,
1722 * 1.0 is bottom aligned
1724 * Sets the alignment of the child. This property has no effect unless
1725 * the child is a #GtkMisc or a #GtkAligment.
1730 gtk_button_set_alignment (GtkButton *button,
1734 GtkButtonPrivate *priv;
1736 g_return_if_fail (GTK_IS_BUTTON (button));
1738 priv = GTK_BUTTON_GET_PRIVATE (button);
1740 priv->xalign = xalign;
1741 priv->yalign = yalign;
1742 priv->align_set = 1;
1744 maybe_set_alignment (button, GTK_BIN (button)->child);
1746 g_object_freeze_notify (G_OBJECT (button));
1747 g_object_notify (G_OBJECT (button), "xalign");
1748 g_object_notify (G_OBJECT (button), "yalign");
1749 g_object_thaw_notify (G_OBJECT (button));
1753 * gtk_button_get_alignment:
1754 * @button: a #GtkButton
1755 * @xalign: return location for horizontal alignment
1756 * @yalign: return location for vertical alignment
1758 * Gets the alignment of the child in the button.
1763 gtk_button_get_alignment (GtkButton *button,
1767 GtkButtonPrivate *priv;
1769 g_return_if_fail (GTK_IS_BUTTON (button));
1771 priv = GTK_BUTTON_GET_PRIVATE (button);
1774 *xalign = priv->xalign;
1777 *yalign = priv->yalign;
1781 * _gtk_button_set_depressed:
1782 * @button: a #GtkButton
1783 * @depressed: %TRUE if the button should be drawn with a recessed shadow.
1785 * Sets whether the button is currently drawn as down or not. This is
1786 * purely a visual setting, and is meant only for use by derived widgets
1787 * such as #GtkToggleButton.
1790 _gtk_button_set_depressed (GtkButton *button,
1793 GtkWidget *widget = GTK_WIDGET (button);
1795 depressed = depressed != FALSE;
1797 if (depressed != button->depressed)
1799 button->depressed = depressed;
1800 gtk_widget_queue_resize (widget);
1805 gtk_button_update_state (GtkButton *button)
1808 GtkStateType new_state;
1810 if (button->activate_timeout)
1811 depressed = button->depress_on_activate;
1813 depressed = button->in_button && button->button_down;
1815 if (button->in_button && (!button->button_down || !depressed))
1816 new_state = GTK_STATE_PRELIGHT;
1818 new_state = depressed ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL;
1820 _gtk_button_set_depressed (button, depressed);
1821 gtk_widget_set_state (GTK_WIDGET (button), new_state);
1825 show_image_change_notify (GtkButton *button)
1827 GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);
1831 if (show_image (button))
1832 gtk_widget_show (priv->image);
1834 gtk_widget_hide (priv->image);
1839 traverse_container (GtkWidget *widget,
1842 if (GTK_IS_BUTTON (widget))
1843 show_image_change_notify (GTK_BUTTON (widget));
1844 else if (GTK_IS_CONTAINER (widget))
1845 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
1849 gtk_button_setting_changed (GtkSettings *settings)
1853 list = gtk_window_list_toplevels ();
1855 for (l = list; l; l = l->next)
1856 gtk_container_forall (GTK_CONTAINER (l->data),
1857 traverse_container, NULL);
1864 gtk_button_screen_changed (GtkWidget *widget,
1865 GdkScreen *previous_screen)
1867 GtkSettings *settings;
1868 guint show_image_connection;
1870 if (!gtk_widget_has_screen (widget))
1873 settings = gtk_widget_get_settings (widget);
1875 show_image_connection =
1876 GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (settings),
1877 "gtk-button-connection"));
1879 if (show_image_connection)
1882 show_image_connection =
1883 g_signal_connect (settings, "notify::gtk-button-images",
1884 G_CALLBACK (gtk_button_setting_changed), 0);
1885 g_object_set_data (G_OBJECT (settings),
1886 I_("gtk-button-connection"),
1887 GUINT_TO_POINTER (show_image_connection));
1889 show_image_change_notify (GTK_BUTTON (widget));
1893 gtk_button_state_changed (GtkWidget *widget,
1894 GtkStateType previous_state)
1896 GtkButton *button = GTK_BUTTON (widget);
1898 if (!GTK_WIDGET_IS_SENSITIVE (widget))
1900 button->in_button = FALSE;
1901 gtk_real_button_released (button);
1906 gtk_button_grab_notify (GtkWidget *widget,
1907 gboolean was_grabbed)
1909 GtkButton *button = GTK_BUTTON (widget);
1913 button->in_button = FALSE;
1914 gtk_real_button_released (button);
1919 * gtk_button_set_image:
1920 * @button: a #GtkButton
1921 * @image: a widget to set as the image for the button
1923 * Set the image of @button to the given widget. Note that
1924 * it depends on the gtk-button-images setting whether the
1925 * image will be displayed or not, you don't have to call
1926 * gtk_widget_show() on @image yourself.
1931 gtk_button_set_image (GtkButton *button,
1934 GtkButtonPrivate *priv;
1936 g_return_if_fail (GTK_IS_BUTTON (button));
1937 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
1939 priv = GTK_BUTTON_GET_PRIVATE (button);
1941 priv->image = image;
1942 priv->image_is_stock = (image == NULL);
1944 gtk_button_construct_child (button);
1946 g_object_notify (G_OBJECT (button), "image");
1950 * gtk_button_get_image:
1951 * @button: a #GtkButton
1953 * Gets the widget that is currenty set as the image of @button.
1954 * This may have been explicitly set by gtk_button_set_image()
1955 * or constructed by gtk_button_new_from_stock().
1957 * Return value: a #GtkWidget or %NULL in case there is no image
1962 gtk_button_get_image (GtkButton *button)
1964 GtkButtonPrivate *priv;
1966 g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
1968 priv = GTK_BUTTON_GET_PRIVATE (button);
1974 * gtk_button_set_image_position:
1975 * @button: a #GtkButton
1976 * @position: the position
1978 * Sets the position of the image relative to the text
1979 * inside the button.
1984 gtk_button_set_image_position (GtkButton *button,
1985 GtkPositionType position)
1988 GtkButtonPrivate *priv;
1990 g_return_if_fail (GTK_IS_BUTTON (button));
1991 g_return_if_fail (position >= GTK_POS_LEFT && position <= GTK_POS_BOTTOM);
1993 priv = GTK_BUTTON_GET_PRIVATE (button);
1995 if (priv->image_position != position)
1997 priv->image_position = position;
1999 gtk_button_construct_child (button);
2001 g_object_notify (G_OBJECT (button), "image-position");
2006 * gtk_button_get_image_position:
2007 * @button: a #GtkButton
2009 * Gets the position of the image relative to the text
2010 * inside the button.
2012 * Return value: the position
2017 gtk_button_get_image_position (GtkButton *button)
2019 GtkButtonPrivate *priv;
2021 g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_POS_LEFT);
2023 priv = GTK_BUTTON_GET_PRIVATE (button);
2025 return priv->image_position;
2029 #define __GTK_BUTTON_C__
2030 #include "gtkaliasdef.c"