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, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 * @Short_description: A widget that emits a signal when clicked on
30 * The #GtkButton widget is generally used to trigger a callback function that is
31 * called when the button is pressed. The various signals and how to use them
34 * The #GtkButton widget can hold any valid child widget. That is, it can hold
35 * almost any other standard #GtkWidget. The most commonly used child is the
41 #include "gtkbutton.h"
42 #include "gtkbuttonprivate.h"
45 #include "gtkalignment.h"
48 #include "gtkmarshalers.h"
52 #include "gtkiconfactory.h"
53 #include "gtkactivatable.h"
54 #include "gtksizerequest.h"
55 #include "gtktypebuiltins.h"
56 #include "gtkprivate.h"
58 #include "a11y/gtkbuttonaccessible.h"
59 #include "gtkapplicationprivate.h"
60 #include "gtkactionable.h"
62 static const GtkBorder default_default_border = { 1, 1, 1, 1 };
63 static const GtkBorder default_default_outside_border = { 0, 0, 0, 0 };
65 /* Time out before giving up on getting a key release when animating
68 #define ACTIVATE_TIMEOUT 250
94 PROP_ALWAYS_SHOW_IMAGE,
96 /* activatable properties */
97 PROP_ACTIVATABLE_RELATED_ACTION,
98 PROP_ACTIVATABLE_USE_ACTION_APPEARANCE
102 static void gtk_button_destroy (GtkWidget *widget);
103 static void gtk_button_dispose (GObject *object);
104 static void gtk_button_set_property (GObject *object,
108 static void gtk_button_get_property (GObject *object,
112 static void gtk_button_screen_changed (GtkWidget *widget,
113 GdkScreen *previous_screen);
114 static void gtk_button_realize (GtkWidget * widget);
115 static void gtk_button_unrealize (GtkWidget * widget);
116 static void gtk_button_map (GtkWidget * widget);
117 static void gtk_button_unmap (GtkWidget * widget);
118 static void gtk_button_style_updated (GtkWidget * widget);
119 static void gtk_button_size_allocate (GtkWidget * widget,
120 GtkAllocation * allocation);
121 static gint gtk_button_draw (GtkWidget * widget, cairo_t *cr);
122 static gint gtk_button_button_press (GtkWidget * widget,
123 GdkEventButton * event);
124 static gint gtk_button_button_release (GtkWidget * widget,
125 GdkEventButton * event);
126 static gboolean gtk_button_touch (GtkWidget *widget,
127 GdkEventTouch *event);
128 static gint gtk_button_grab_broken (GtkWidget * widget,
129 GdkEventGrabBroken * event);
130 static gint gtk_button_key_release (GtkWidget * widget, GdkEventKey * event);
131 static gint gtk_button_enter_notify (GtkWidget * widget,
132 GdkEventCrossing * event);
133 static gint gtk_button_leave_notify (GtkWidget * widget,
134 GdkEventCrossing * event);
135 static void gtk_real_button_pressed (GtkButton * button);
136 static void gtk_real_button_released (GtkButton * button);
137 static void gtk_real_button_clicked (GtkButton * button);
138 static void gtk_real_button_activate (GtkButton *button);
139 static void gtk_button_update_state (GtkButton *button);
140 static void gtk_button_add (GtkContainer *container,
142 static GType gtk_button_child_type (GtkContainer *container);
143 static void gtk_button_finish_activate (GtkButton *button,
146 static GObject* gtk_button_constructor (GType type,
147 guint n_construct_properties,
148 GObjectConstructParam *construct_params);
149 static void gtk_button_construct_child (GtkButton *button);
150 static void gtk_button_state_changed (GtkWidget *widget,
151 GtkStateType previous_state);
152 static void gtk_button_grab_notify (GtkWidget *widget,
153 gboolean was_grabbed);
154 static void gtk_button_hierarchy_changed (GtkWidget *widget,
155 GtkWidget *previous_toplevel);
158 static void gtk_button_actionable_iface_init (GtkActionableInterface *iface);
159 static void gtk_button_activatable_interface_init(GtkActivatableIface *iface);
160 static void gtk_button_update (GtkActivatable *activatable,
162 const gchar *property_name);
163 static void gtk_button_sync_action_properties (GtkActivatable *activatable,
165 static void gtk_button_set_related_action (GtkButton *button,
167 static void gtk_button_set_use_action_appearance (GtkButton *button,
168 gboolean use_appearance);
170 static void gtk_button_get_preferred_width (GtkWidget *widget,
173 static void gtk_button_get_preferred_height (GtkWidget *widget,
177 static guint button_signals[LAST_SIGNAL] = { 0 };
179 G_DEFINE_TYPE_WITH_CODE (GtkButton, gtk_button, GTK_TYPE_BIN,
180 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_button_actionable_iface_init)
181 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
182 gtk_button_activatable_interface_init))
185 gtk_button_class_init (GtkButtonClass *klass)
187 GObjectClass *gobject_class;
188 GtkWidgetClass *widget_class;
189 GtkContainerClass *container_class;
191 gobject_class = G_OBJECT_CLASS (klass);
192 widget_class = (GtkWidgetClass*) klass;
193 container_class = (GtkContainerClass*) klass;
195 gobject_class->constructor = gtk_button_constructor;
196 gobject_class->dispose = gtk_button_dispose;
197 gobject_class->set_property = gtk_button_set_property;
198 gobject_class->get_property = gtk_button_get_property;
200 widget_class->get_preferred_width = gtk_button_get_preferred_width;
201 widget_class->get_preferred_height = gtk_button_get_preferred_height;
202 widget_class->destroy = gtk_button_destroy;
203 widget_class->screen_changed = gtk_button_screen_changed;
204 widget_class->realize = gtk_button_realize;
205 widget_class->unrealize = gtk_button_unrealize;
206 widget_class->map = gtk_button_map;
207 widget_class->unmap = gtk_button_unmap;
208 widget_class->style_updated = gtk_button_style_updated;
209 widget_class->size_allocate = gtk_button_size_allocate;
210 widget_class->draw = gtk_button_draw;
211 widget_class->button_press_event = gtk_button_button_press;
212 widget_class->button_release_event = gtk_button_button_release;
213 widget_class->touch_event = gtk_button_touch;
214 widget_class->grab_broken_event = gtk_button_grab_broken;
215 widget_class->key_release_event = gtk_button_key_release;
216 widget_class->enter_notify_event = gtk_button_enter_notify;
217 widget_class->leave_notify_event = gtk_button_leave_notify;
218 widget_class->state_changed = gtk_button_state_changed;
219 widget_class->grab_notify = gtk_button_grab_notify;
220 widget_class->hierarchy_changed = gtk_button_hierarchy_changed;
222 container_class->child_type = gtk_button_child_type;
223 container_class->add = gtk_button_add;
224 gtk_container_class_handle_border_width (container_class);
226 klass->pressed = gtk_real_button_pressed;
227 klass->released = gtk_real_button_released;
228 klass->clicked = NULL;
229 klass->enter = gtk_button_update_state;
230 klass->leave = gtk_button_update_state;
231 klass->activate = gtk_real_button_activate;
233 g_object_class_install_property (gobject_class,
235 g_param_spec_string ("label",
237 P_("Text of the label widget inside the button, if the button contains a label widget"),
239 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
241 g_object_class_install_property (gobject_class,
243 g_param_spec_boolean ("use-underline",
245 P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
247 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
249 g_object_class_install_property (gobject_class,
251 g_param_spec_boolean ("use-stock",
253 P_("If set, the label is used to pick a stock item instead of being displayed"),
255 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
257 g_object_class_install_property (gobject_class,
259 g_param_spec_boolean ("focus-on-click",
260 P_("Focus on click"),
261 P_("Whether the button grabs focus when it is clicked with the mouse"),
263 GTK_PARAM_READWRITE));
265 g_object_class_install_property (gobject_class,
267 g_param_spec_enum ("relief",
269 P_("The border relief style"),
270 GTK_TYPE_RELIEF_STYLE,
272 GTK_PARAM_READWRITE));
277 * If the child of the button is a #GtkMisc or #GtkAlignment, this property
278 * can be used to control its horizontal alignment. 0.0 is left aligned,
279 * 1.0 is right aligned.
283 g_object_class_install_property (gobject_class,
285 g_param_spec_float("xalign",
286 P_("Horizontal alignment for child"),
287 P_("Horizontal position of child in available space. 0.0 is left aligned, 1.0 is right aligned"),
291 GTK_PARAM_READWRITE));
296 * If the child of the button is a #GtkMisc or #GtkAlignment, this property
297 * can be used to control its vertical alignment. 0.0 is top aligned,
298 * 1.0 is bottom aligned.
302 g_object_class_install_property (gobject_class,
304 g_param_spec_float("yalign",
305 P_("Vertical alignment for child"),
306 P_("Vertical position of child in available space. 0.0 is top aligned, 1.0 is bottom aligned"),
310 GTK_PARAM_READWRITE));
315 * The child widget to appear next to the button text.
319 g_object_class_install_property (gobject_class,
321 g_param_spec_object ("image",
323 P_("Child widget to appear next to the button text"),
325 GTK_PARAM_READWRITE));
328 * GtkButton:image-position:
330 * The position of the image relative to the text inside the button.
334 g_object_class_install_property (gobject_class,
336 g_param_spec_enum ("image-position",
337 P_("Image position"),
338 P_("The position of the image relative to the text"),
339 GTK_TYPE_POSITION_TYPE,
341 GTK_PARAM_READWRITE));
344 * GtkButton:always-show-image:
346 * If %TRUE, the button will ignore the #GtkSettings:gtk-button-images
347 * setting and always show the image, if available.
349 * Use this property if the button would be useless or hard to use
354 g_object_class_install_property (gobject_class,
355 PROP_ALWAYS_SHOW_IMAGE,
356 g_param_spec_boolean ("always-show-image",
357 P_("Always show image"),
358 P_("Whether the image will always be shown"),
360 GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT));
362 g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
363 g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
365 g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_RELATED_ACTION, "related-action");
366 g_object_class_override_property (gobject_class, PROP_ACTIVATABLE_USE_ACTION_APPEARANCE, "use-action-appearance");
369 * GtkButton::pressed:
370 * @button: the object that received the signal
372 * Emitted when the button is pressed.
374 * Deprecated: 2.8: Use the #GtkWidget::button-press-event signal.
376 button_signals[PRESSED] =
377 g_signal_new (I_("pressed"),
378 G_OBJECT_CLASS_TYPE (gobject_class),
380 G_STRUCT_OFFSET (GtkButtonClass, pressed),
382 _gtk_marshal_VOID__VOID,
386 * GtkButton::released:
387 * @button: the object that received the signal
389 * Emitted when the button is released.
391 * Deprecated: 2.8: Use the #GtkWidget::button-release-event signal.
393 button_signals[RELEASED] =
394 g_signal_new (I_("released"),
395 G_OBJECT_CLASS_TYPE (gobject_class),
397 G_STRUCT_OFFSET (GtkButtonClass, released),
399 _gtk_marshal_VOID__VOID,
403 * GtkButton::clicked:
404 * @button: the object that received the signal
406 * Emitted when the button has been activated (pressed and released).
408 button_signals[CLICKED] =
409 g_signal_new (I_("clicked"),
410 G_OBJECT_CLASS_TYPE (gobject_class),
411 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
412 G_STRUCT_OFFSET (GtkButtonClass, clicked),
414 _gtk_marshal_VOID__VOID,
419 * @button: the object that received the signal
421 * Emitted when the pointer enters the button.
423 * Deprecated: 2.8: Use the #GtkWidget::enter-notify-event signal.
425 button_signals[ENTER] =
426 g_signal_new (I_("enter"),
427 G_OBJECT_CLASS_TYPE (gobject_class),
429 G_STRUCT_OFFSET (GtkButtonClass, enter),
431 _gtk_marshal_VOID__VOID,
436 * @button: the object that received the signal
438 * Emitted when the pointer leaves the button.
440 * Deprecated: 2.8: Use the #GtkWidget::leave-notify-event signal.
442 button_signals[LEAVE] =
443 g_signal_new (I_("leave"),
444 G_OBJECT_CLASS_TYPE (gobject_class),
446 G_STRUCT_OFFSET (GtkButtonClass, leave),
448 _gtk_marshal_VOID__VOID,
452 * GtkButton::activate:
453 * @widget: the object which received the signal.
455 * The ::activate signal on GtkButton is an action signal and
456 * emitting it causes the button to animate press then release.
457 * Applications should never connect to this signal, but use the
458 * #GtkButton::clicked signal.
460 button_signals[ACTIVATE] =
461 g_signal_new (I_("activate"),
462 G_OBJECT_CLASS_TYPE (gobject_class),
463 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
464 G_STRUCT_OFFSET (GtkButtonClass, activate),
466 _gtk_marshal_VOID__VOID,
468 widget_class->activate_signal = button_signals[ACTIVATE];
471 * GtkButton:default-border:
473 * The "default-border" style property defines the extra space to add
474 * around a button that can become the default widget of its window.
475 * For more information about default widgets, see gtk_widget_grab_default().
478 gtk_widget_class_install_style_property (widget_class,
479 g_param_spec_boxed ("default-border",
480 P_("Default Spacing"),
481 P_("Extra space to add for GTK_CAN_DEFAULT buttons"),
483 GTK_PARAM_READABLE));
486 * GtkButton:default-outside-border:
488 * The "default-outside-border" style property defines the extra outside
489 * space to add around a button that can become the default widget of its
490 * window. Extra outside space is always drawn outside the button border.
491 * For more information about default widgets, see gtk_widget_grab_default().
493 gtk_widget_class_install_style_property (widget_class,
494 g_param_spec_boxed ("default-outside-border",
495 P_("Default Outside Spacing"),
496 P_("Extra space to add for GTK_CAN_DEFAULT buttons that is always drawn outside the border"),
498 GTK_PARAM_READABLE));
499 gtk_widget_class_install_style_property (widget_class,
500 g_param_spec_int ("child-displacement-x",
501 P_("Child X Displacement"),
502 P_("How far in the x direction to move the child when the button is depressed"),
506 GTK_PARAM_READABLE));
507 gtk_widget_class_install_style_property (widget_class,
508 g_param_spec_int ("child-displacement-y",
509 P_("Child Y Displacement"),
510 P_("How far in the y direction to move the child when the button is depressed"),
514 GTK_PARAM_READABLE));
517 * GtkButton:displace-focus:
519 * Whether the child_displacement_x/child_displacement_y properties
520 * should also affect the focus rectangle.
524 gtk_widget_class_install_style_property (widget_class,
525 g_param_spec_boolean ("displace-focus",
526 P_("Displace focus"),
527 P_("Whether the child_displacement_x/_y properties should also affect the focus rectangle"),
529 GTK_PARAM_READABLE));
532 * GtkButton:inner-border:
534 * Sets the border between the button edges and child.
538 * Deprecated: 3.4: Use the standard border and padding CSS properties;
539 * the value of this style property is ignored.
541 gtk_widget_class_install_style_property (widget_class,
542 g_param_spec_boxed ("inner-border",
544 P_("Border between button edges and child."),
546 GTK_PARAM_READABLE));
549 * GtkButton::image-spacing:
551 * Spacing in pixels between the image and label.
555 gtk_widget_class_install_style_property (widget_class,
556 g_param_spec_int ("image-spacing",
558 P_("Spacing in pixels between the image and label"),
562 GTK_PARAM_READABLE));
564 g_type_class_add_private (gobject_class, sizeof (GtkButtonPrivate));
566 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_BUTTON_ACCESSIBLE);
570 gtk_button_init (GtkButton *button)
572 GtkButtonPrivate *priv;
573 GtkStyleContext *context;
575 button->priv = G_TYPE_INSTANCE_GET_PRIVATE (button,
580 gtk_widget_set_can_focus (GTK_WIDGET (button), TRUE);
581 gtk_widget_set_receives_default (GTK_WIDGET (button), TRUE);
582 gtk_widget_set_has_window (GTK_WIDGET (button), FALSE);
584 priv->label_text = NULL;
586 priv->constructed = FALSE;
587 priv->in_button = FALSE;
588 priv->button_down = FALSE;
589 priv->relief = GTK_RELIEF_NORMAL;
590 priv->use_stock = FALSE;
591 priv->use_underline = FALSE;
592 priv->depressed = FALSE;
593 priv->depress_on_activate = TRUE;
594 priv->focus_on_click = TRUE;
599 priv->image_is_stock = TRUE;
600 priv->image_position = GTK_POS_LEFT;
601 priv->use_action_appearance = TRUE;
603 context = gtk_widget_get_style_context (GTK_WIDGET (button));
604 gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
608 gtk_button_destroy (GtkWidget *widget)
610 GtkButton *button = GTK_BUTTON (widget);
611 GtkButtonPrivate *priv = button->priv;
613 if (priv->label_text)
615 g_free (priv->label_text);
616 priv->label_text = NULL;
619 if (priv->action_name)
621 g_free (priv->action_name);
622 priv->action_name = NULL;
625 GTK_WIDGET_CLASS (gtk_button_parent_class)->destroy (widget);
629 gtk_button_constructor (GType type,
630 guint n_construct_properties,
631 GObjectConstructParam *construct_params)
635 GtkButtonPrivate *priv;
637 object = G_OBJECT_CLASS (gtk_button_parent_class)->constructor (type,
638 n_construct_properties,
641 button = GTK_BUTTON (object);
644 priv->constructed = TRUE;
646 if (priv->label_text != NULL)
647 gtk_button_construct_child (button);
654 gtk_button_child_type (GtkContainer *container)
656 if (!gtk_bin_get_child (GTK_BIN (container)))
657 return GTK_TYPE_WIDGET;
663 maybe_set_alignment (GtkButton *button,
666 GtkButtonPrivate *priv = button->priv;
668 if (GTK_IS_MISC (widget))
670 GtkMisc *misc = GTK_MISC (widget);
673 gtk_misc_set_alignment (misc, priv->xalign, priv->yalign);
675 else if (GTK_IS_ALIGNMENT (widget))
677 GtkAlignment *alignment = GTK_ALIGNMENT (widget);
678 gfloat xscale, yscale;
680 g_object_get (alignment,
686 gtk_alignment_set (alignment,
687 priv->xalign, priv->yalign,
693 gtk_button_add (GtkContainer *container,
696 maybe_set_alignment (GTK_BUTTON (container), widget);
698 GTK_CONTAINER_CLASS (gtk_button_parent_class)->add (container, widget);
702 gtk_button_dispose (GObject *object)
704 GtkButton *button = GTK_BUTTON (object);
705 GtkButtonPrivate *priv = button->priv;
707 g_clear_object (&priv->action_observer);
711 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (button), NULL);
714 G_OBJECT_CLASS (gtk_button_parent_class)->dispose (object);
718 gtk_button_update_action_observer (GtkButton *button)
722 g_signal_handlers_disconnect_by_func (button, gtk_real_button_clicked, NULL);
724 /* we are the only owner so this will clear all the signals */
725 g_clear_object (&button->priv->action_observer);
727 window = gtk_widget_get_toplevel (GTK_WIDGET (button));
729 if (GTK_IS_APPLICATION_WINDOW (window) && button->priv->action_name)
731 GSimpleActionObserver *observer;
733 observer = gtk_application_window_create_observer (GTK_APPLICATION_WINDOW (window),
734 button->priv->action_name,
735 button->priv->action_target);
737 _gtk_button_set_depressed (button, g_simple_action_observer_get_active (observer));
739 if (g_object_class_find_property (G_OBJECT_GET_CLASS (button), "active"))
740 g_object_bind_property (observer, "active", button, "active", G_BINDING_SYNC_CREATE);
741 g_object_bind_property (observer, "enabled", button, "sensitive", G_BINDING_SYNC_CREATE);
743 button->priv->action_observer = observer;
745 g_signal_connect_after (button, "clicked", G_CALLBACK (gtk_real_button_clicked), NULL);
750 gtk_button_set_action_name (GtkActionable *actionable,
751 const gchar *action_name)
753 GtkButton *button = GTK_BUTTON (actionable);
755 g_return_if_fail (GTK_IS_BUTTON (button));
756 g_return_if_fail (button->priv->action == NULL);
758 g_free (button->priv->action_name);
759 button->priv->action_name = g_strdup (action_name);
761 gtk_button_update_action_observer (button);
763 g_object_notify (G_OBJECT (button), "action-name");
767 gtk_button_set_action_target_value (GtkActionable *actionable,
768 GVariant *action_target)
770 GtkButton *button = GTK_BUTTON (actionable);
772 g_return_if_fail (GTK_IS_BUTTON (button));
774 if (action_target != button->priv->action_target &&
775 (!action_target || !button->priv->action_target ||
776 !g_variant_equal (action_target, button->priv->action_target)))
778 if (button->priv->action_target)
779 g_variant_unref (button->priv->action_target);
781 button->priv->action_target = NULL;
784 button->priv->action_target = g_variant_ref_sink (action_target);
786 gtk_button_update_action_observer (button);
788 g_object_notify (G_OBJECT (button), "action-target");
793 gtk_button_set_property (GObject *object,
798 GtkButton *button = GTK_BUTTON (object);
799 GtkButtonPrivate *priv = button->priv;
804 gtk_button_set_label (button, g_value_get_string (value));
807 gtk_button_set_image (button, (GtkWidget *) g_value_get_object (value));
809 case PROP_ALWAYS_SHOW_IMAGE:
810 gtk_button_set_always_show_image (button, g_value_get_boolean (value));
813 gtk_button_set_relief (button, g_value_get_enum (value));
815 case PROP_USE_UNDERLINE:
816 gtk_button_set_use_underline (button, g_value_get_boolean (value));
819 gtk_button_set_use_stock (button, g_value_get_boolean (value));
821 case PROP_FOCUS_ON_CLICK:
822 gtk_button_set_focus_on_click (button, g_value_get_boolean (value));
825 gtk_button_set_alignment (button, g_value_get_float (value), priv->yalign);
828 gtk_button_set_alignment (button, priv->xalign, g_value_get_float (value));
830 case PROP_IMAGE_POSITION:
831 gtk_button_set_image_position (button, g_value_get_enum (value));
833 case PROP_ACTIVATABLE_RELATED_ACTION:
834 gtk_button_set_related_action (button, g_value_get_object (value));
836 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
837 gtk_button_set_use_action_appearance (button, g_value_get_boolean (value));
839 case PROP_ACTION_NAME:
840 gtk_button_set_action_name (GTK_ACTIONABLE (button), g_value_get_string (value));
842 case PROP_ACTION_TARGET:
843 gtk_button_set_action_target_value (GTK_ACTIONABLE (button), g_value_get_variant (value));
846 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
852 gtk_button_get_property (GObject *object,
857 GtkButton *button = GTK_BUTTON (object);
858 GtkButtonPrivate *priv = button->priv;
863 g_value_set_string (value, priv->label_text);
866 g_value_set_object (value, (GObject *)priv->image);
868 case PROP_ALWAYS_SHOW_IMAGE:
869 g_value_set_boolean (value, gtk_button_get_always_show_image (button));
872 g_value_set_enum (value, priv->relief);
874 case PROP_USE_UNDERLINE:
875 g_value_set_boolean (value, priv->use_underline);
878 g_value_set_boolean (value, priv->use_stock);
880 case PROP_FOCUS_ON_CLICK:
881 g_value_set_boolean (value, priv->focus_on_click);
884 g_value_set_float (value, priv->xalign);
887 g_value_set_float (value, priv->yalign);
889 case PROP_IMAGE_POSITION:
890 g_value_set_enum (value, priv->image_position);
892 case PROP_ACTIVATABLE_RELATED_ACTION:
893 g_value_set_object (value, priv->action);
895 case PROP_ACTIVATABLE_USE_ACTION_APPEARANCE:
896 g_value_set_boolean (value, priv->use_action_appearance);
898 case PROP_ACTION_NAME:
899 g_value_set_string (value, priv->action_name);
901 case PROP_ACTION_TARGET:
902 g_value_set_variant (value, priv->action_target);
905 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
911 gtk_button_get_action_name (GtkActionable *actionable)
913 GtkButton *button = GTK_BUTTON (actionable);
915 return button->priv->action_name;
919 gtk_button_get_action_target_value (GtkActionable *actionable)
921 GtkButton *button = GTK_BUTTON (actionable);
923 return button->priv->action_target;
927 gtk_button_actionable_iface_init (GtkActionableInterface *iface)
929 iface->get_action_name = gtk_button_get_action_name;
930 iface->set_action_name = gtk_button_set_action_name;
931 iface->get_action_target_value = gtk_button_get_action_target_value;
932 iface->set_action_target_value = gtk_button_set_action_target_value;
936 gtk_button_activatable_interface_init (GtkActivatableIface *iface)
938 iface->update = gtk_button_update;
939 iface->sync_action_properties = gtk_button_sync_action_properties;
943 activatable_update_stock_id (GtkButton *button,
946 if (!gtk_button_get_use_stock (button))
949 gtk_button_set_label (button, gtk_action_get_stock_id (action));
953 activatable_update_short_label (GtkButton *button,
959 if (gtk_button_get_use_stock (button))
962 image = gtk_button_get_image (button);
964 /* Dont touch custom child... */
965 child = gtk_bin_get_child (GTK_BIN (button));
966 if (GTK_IS_IMAGE (image) ||
968 GTK_IS_LABEL (child))
970 gtk_button_set_label (button, gtk_action_get_short_label (action));
971 gtk_button_set_use_underline (button, TRUE);
976 activatable_update_icon_name (GtkButton *button,
981 if (gtk_button_get_use_stock (button))
984 image = gtk_button_get_image (button);
986 if (GTK_IS_IMAGE (image) &&
987 (gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
988 gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_ICON_NAME))
989 gtk_image_set_from_icon_name (GTK_IMAGE (image),
990 gtk_action_get_icon_name (action), GTK_ICON_SIZE_MENU);
994 activatable_update_gicon (GtkButton *button,
997 GtkWidget *image = gtk_button_get_image (button);
998 GIcon *icon = gtk_action_get_gicon (action);
1000 if (GTK_IS_IMAGE (image) &&
1001 (gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_EMPTY ||
1002 gtk_image_get_storage_type (GTK_IMAGE (image)) == GTK_IMAGE_GICON))
1003 gtk_image_set_from_gicon (GTK_IMAGE (image), icon, GTK_ICON_SIZE_BUTTON);
1007 gtk_button_update (GtkActivatable *activatable,
1009 const gchar *property_name)
1011 GtkButton *button = GTK_BUTTON (activatable);
1012 GtkButtonPrivate *priv = button->priv;
1014 if (strcmp (property_name, "visible") == 0)
1016 if (gtk_action_is_visible (action))
1017 gtk_widget_show (GTK_WIDGET (activatable));
1019 gtk_widget_hide (GTK_WIDGET (activatable));
1021 else if (strcmp (property_name, "sensitive") == 0)
1022 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
1024 if (!priv->use_action_appearance)
1027 if (strcmp (property_name, "stock-id") == 0)
1028 activatable_update_stock_id (GTK_BUTTON (activatable), action);
1029 else if (strcmp (property_name, "gicon") == 0)
1030 activatable_update_gicon (GTK_BUTTON (activatable), action);
1031 else if (strcmp (property_name, "short-label") == 0)
1032 activatable_update_short_label (GTK_BUTTON (activatable), action);
1033 else if (strcmp (property_name, "icon-name") == 0)
1034 activatable_update_icon_name (GTK_BUTTON (activatable), action);
1038 gtk_button_sync_action_properties (GtkActivatable *activatable,
1041 GtkButton *button = GTK_BUTTON (activatable);
1042 GtkButtonPrivate *priv = button->priv;
1047 if (gtk_action_is_visible (action))
1048 gtk_widget_show (GTK_WIDGET (activatable));
1050 gtk_widget_hide (GTK_WIDGET (activatable));
1052 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
1054 if (priv->use_action_appearance)
1056 activatable_update_stock_id (GTK_BUTTON (activatable), action);
1057 activatable_update_short_label (GTK_BUTTON (activatable), action);
1058 activatable_update_gicon (GTK_BUTTON (activatable), action);
1059 activatable_update_icon_name (GTK_BUTTON (activatable), action);
1062 gtk_button_set_always_show_image (button,
1063 gtk_action_get_always_show_image (action));
1067 gtk_button_set_related_action (GtkButton *button,
1070 GtkButtonPrivate *priv = button->priv;
1072 g_return_if_fail (button->priv->action_name == NULL);
1074 if (priv->action == action)
1077 /* This should be a default handler, but for compatibility reasons
1078 * we need to support derived classes that don't chain up their
1081 g_signal_handlers_disconnect_by_func (button, gtk_real_button_clicked, NULL);
1083 g_signal_connect_after (button, "clicked",
1084 G_CALLBACK (gtk_real_button_clicked), NULL);
1086 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (button), action);
1088 priv->action = action;
1092 gtk_button_set_use_action_appearance (GtkButton *button,
1093 gboolean use_appearance)
1095 GtkButtonPrivate *priv = button->priv;
1097 if (priv->use_action_appearance != use_appearance)
1099 priv->use_action_appearance = use_appearance;
1101 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (button), priv->action);
1108 * Creates a new #GtkButton widget. To add a child widget to the button,
1109 * use gtk_container_add().
1111 * Returns: The newly created #GtkButton widget.
1114 gtk_button_new (void)
1116 return g_object_new (GTK_TYPE_BUTTON, NULL);
1120 show_image (GtkButton *button)
1122 GtkButtonPrivate *priv = button->priv;
1125 if (priv->label_text && !priv->always_show_image)
1127 GtkSettings *settings;
1129 settings = gtk_widget_get_settings (GTK_WIDGET (button));
1130 g_object_get (settings, "gtk-button-images", &show, NULL);
1140 gtk_button_construct_child (GtkButton *button)
1142 GtkButtonPrivate *priv = button->priv;
1143 GtkStyleContext *context;
1149 GtkWidget *image = NULL;
1150 gchar *label_text = NULL;
1153 if (!priv->constructed)
1156 if (!priv->label_text && !priv->image)
1159 context = gtk_widget_get_style_context (GTK_WIDGET (button));
1161 gtk_style_context_get_style (context,
1162 "image-spacing", &image_spacing,
1165 if (priv->image && !priv->image_is_stock)
1169 image = g_object_ref (priv->image);
1171 parent = gtk_widget_get_parent (image);
1173 gtk_container_remove (GTK_CONTAINER (parent), image);
1178 child = gtk_bin_get_child (GTK_BIN (button));
1180 gtk_container_remove (GTK_CONTAINER (button), child);
1182 if (priv->use_stock &&
1184 gtk_stock_lookup (priv->label_text, &item))
1187 image = g_object_ref (gtk_image_new_from_stock (priv->label_text, GTK_ICON_SIZE_BUTTON));
1189 label_text = item.label;
1192 label_text = priv->label_text;
1196 priv->image = image;
1197 g_object_set (priv->image,
1198 "visible", show_image (button),
1199 "no-show-all", TRUE,
1202 if (priv->image_position == GTK_POS_LEFT ||
1203 priv->image_position == GTK_POS_RIGHT)
1204 box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, image_spacing);
1206 box = gtk_box_new (GTK_ORIENTATION_VERTICAL, image_spacing);
1208 if (priv->align_set)
1209 align = gtk_alignment_new (priv->xalign, priv->yalign, 0.0, 0.0);
1211 align = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
1213 if (priv->image_position == GTK_POS_LEFT ||
1214 priv->image_position == GTK_POS_TOP)
1215 gtk_box_pack_start (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
1217 gtk_box_pack_end (GTK_BOX (box), priv->image, FALSE, FALSE, 0);
1221 if (priv->use_underline || priv->use_stock)
1223 label = gtk_label_new_with_mnemonic (label_text);
1224 gtk_label_set_mnemonic_widget (GTK_LABEL (label),
1225 GTK_WIDGET (button));
1228 label = gtk_label_new (label_text);
1230 if (priv->image_position == GTK_POS_RIGHT ||
1231 priv->image_position == GTK_POS_BOTTOM)
1232 gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
1234 gtk_box_pack_end (GTK_BOX (box), label, FALSE, FALSE, 0);
1237 gtk_container_add (GTK_CONTAINER (button), align);
1238 gtk_container_add (GTK_CONTAINER (align), box);
1239 gtk_widget_show_all (align);
1241 g_object_unref (image);
1246 if (priv->use_underline || priv->use_stock)
1248 label = gtk_label_new_with_mnemonic (priv->label_text);
1249 gtk_label_set_mnemonic_widget (GTK_LABEL (label), GTK_WIDGET (button));
1252 label = gtk_label_new (priv->label_text);
1254 if (priv->align_set)
1255 gtk_misc_set_alignment (GTK_MISC (label), priv->xalign, priv->yalign);
1257 gtk_widget_show (label);
1258 gtk_container_add (GTK_CONTAINER (button), label);
1263 * gtk_button_new_with_label:
1264 * @label: The text you want the #GtkLabel to hold.
1266 * Creates a #GtkButton widget with a #GtkLabel child containing the given
1269 * Returns: The newly created #GtkButton widget.
1272 gtk_button_new_with_label (const gchar *label)
1274 return g_object_new (GTK_TYPE_BUTTON, "label", label, NULL);
1278 * gtk_button_new_from_stock:
1279 * @stock_id: the name of the stock item
1281 * Creates a new #GtkButton containing the image and text from a stock item.
1282 * Some stock ids have preprocessor macros like #GTK_STOCK_OK and
1285 * If @stock_id is unknown, then it will be treated as a mnemonic
1286 * label (as for gtk_button_new_with_mnemonic()).
1288 * Returns: a new #GtkButton
1291 gtk_button_new_from_stock (const gchar *stock_id)
1293 return g_object_new (GTK_TYPE_BUTTON,
1296 "use-underline", TRUE,
1301 * gtk_button_new_with_mnemonic:
1302 * @label: The text of the button, with an underscore in front of the
1303 * mnemonic character
1305 * Creates a new #GtkButton containing a label.
1306 * If characters in @label are preceded by an underscore, they are underlined.
1307 * If you need a literal underscore character in a label, use '__' (two
1308 * underscores). The first underlined character represents a keyboard
1309 * accelerator called a mnemonic.
1310 * Pressing Alt and that key activates the button.
1312 * Returns: a new #GtkButton
1315 gtk_button_new_with_mnemonic (const gchar *label)
1317 return g_object_new (GTK_TYPE_BUTTON, "label", label, "use-underline", TRUE, NULL);
1321 * gtk_button_pressed:
1322 * @button: The #GtkButton you want to send the signal to.
1324 * Emits a #GtkButton::pressed signal to the given #GtkButton.
1326 * Deprecated: 2.20: Use the #GtkWidget::button-press-event signal.
1329 gtk_button_pressed (GtkButton *button)
1331 g_return_if_fail (GTK_IS_BUTTON (button));
1333 g_signal_emit (button, button_signals[PRESSED], 0);
1337 * gtk_button_released:
1338 * @button: The #GtkButton you want to send the signal to.
1340 * Emits a #GtkButton::released signal to the given #GtkButton.
1342 * Deprecated: 2.20: Use the #GtkWidget::button-release-event signal.
1345 gtk_button_released (GtkButton *button)
1347 g_return_if_fail (GTK_IS_BUTTON (button));
1349 g_signal_emit (button, button_signals[RELEASED], 0);
1353 * gtk_button_clicked:
1354 * @button: The #GtkButton you want to send the signal to.
1356 * Emits a #GtkButton::clicked signal to the given #GtkButton.
1359 gtk_button_clicked (GtkButton *button)
1361 g_return_if_fail (GTK_IS_BUTTON (button));
1363 g_signal_emit (button, button_signals[CLICKED], 0);
1368 * @button: The #GtkButton you want to send the signal to.
1370 * Emits a #GtkButton::enter signal to the given #GtkButton.
1372 * Deprecated: 2.20: Use the #GtkWidget::enter-notify-event signal.
1375 gtk_button_enter (GtkButton *button)
1377 g_return_if_fail (GTK_IS_BUTTON (button));
1379 g_signal_emit (button, button_signals[ENTER], 0);
1384 * @button: The #GtkButton you want to send the signal to.
1386 * Emits a #GtkButton::leave signal to the given #GtkButton.
1388 * Deprecated: 2.20: Use the #GtkWidget::leave-notify-event signal.
1391 gtk_button_leave (GtkButton *button)
1393 g_return_if_fail (GTK_IS_BUTTON (button));
1395 g_signal_emit (button, button_signals[LEAVE], 0);
1399 * gtk_button_set_relief:
1400 * @button: The #GtkButton you want to set relief styles of.
1401 * @newstyle: The GtkReliefStyle as described above.
1403 * Sets the relief style of the edges of the given #GtkButton widget.
1404 * Three styles exist, GTK_RELIEF_NORMAL, GTK_RELIEF_HALF, GTK_RELIEF_NONE.
1405 * The default style is, as one can guess, GTK_RELIEF_NORMAL.
1407 * <!-- FIXME: put pictures of each style -->
1410 gtk_button_set_relief (GtkButton *button,
1411 GtkReliefStyle newrelief)
1413 GtkButtonPrivate *priv;
1415 g_return_if_fail (GTK_IS_BUTTON (button));
1417 priv = button->priv;
1419 if (newrelief != priv->relief)
1421 priv->relief = newrelief;
1422 g_object_notify (G_OBJECT (button), "relief");
1423 gtk_widget_queue_draw (GTK_WIDGET (button));
1428 * gtk_button_get_relief:
1429 * @button: The #GtkButton you want the #GtkReliefStyle from.
1431 * Returns the current relief style of the given #GtkButton.
1433 * Returns: The current #GtkReliefStyle
1436 gtk_button_get_relief (GtkButton *button)
1438 g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_RELIEF_NORMAL);
1440 return button->priv->relief;
1444 gtk_button_realize (GtkWidget *widget)
1446 GtkButton *button = GTK_BUTTON (widget);
1447 GtkButtonPrivate *priv = button->priv;
1448 GtkAllocation allocation;
1450 GdkWindowAttr attributes;
1451 gint attributes_mask;
1453 gtk_widget_get_allocation (widget, &allocation);
1455 gtk_widget_set_realized (widget, TRUE);
1457 attributes.window_type = GDK_WINDOW_CHILD;
1458 attributes.x = allocation.x;
1459 attributes.y = allocation.y;
1460 attributes.width = allocation.width;
1461 attributes.height = allocation.height;
1462 attributes.wclass = GDK_INPUT_ONLY;
1463 attributes.event_mask = gtk_widget_get_events (widget);
1464 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
1465 GDK_BUTTON_RELEASE_MASK |
1467 GDK_ENTER_NOTIFY_MASK |
1468 GDK_LEAVE_NOTIFY_MASK);
1470 attributes_mask = GDK_WA_X | GDK_WA_Y;
1472 window = gtk_widget_get_parent_window (widget);
1473 gtk_widget_set_window (widget, window);
1474 g_object_ref (window);
1476 priv->event_window = gdk_window_new (window,
1477 &attributes, attributes_mask);
1478 gdk_window_set_user_data (priv->event_window, button);
1482 gtk_button_unrealize (GtkWidget *widget)
1484 GtkButton *button = GTK_BUTTON (widget);
1485 GtkButtonPrivate *priv = button->priv;
1487 if (priv->activate_timeout)
1488 gtk_button_finish_activate (button, FALSE);
1490 if (priv->event_window)
1492 gdk_window_set_user_data (priv->event_window, NULL);
1493 gdk_window_destroy (priv->event_window);
1494 priv->event_window = NULL;
1497 GTK_WIDGET_CLASS (gtk_button_parent_class)->unrealize (widget);
1501 gtk_button_map (GtkWidget *widget)
1503 GtkButton *button = GTK_BUTTON (widget);
1504 GtkButtonPrivate *priv = button->priv;
1506 GTK_WIDGET_CLASS (gtk_button_parent_class)->map (widget);
1508 if (priv->event_window)
1509 gdk_window_show (priv->event_window);
1513 gtk_button_unmap (GtkWidget *widget)
1515 GtkButton *button = GTK_BUTTON (widget);
1516 GtkButtonPrivate *priv = button->priv;
1518 if (priv->event_window)
1519 gdk_window_hide (priv->event_window);
1521 GTK_WIDGET_CLASS (gtk_button_parent_class)->unmap (widget);
1525 gtk_button_update_image_spacing (GtkButton *button,
1526 GtkStyleContext *context)
1528 GtkButtonPrivate *priv = button->priv;
1532 /* Keep in sync with gtk_button_construct_child,
1533 * we only want to update the spacing if the box
1534 * was constructed there.
1536 if (!priv->constructed || !priv->image)
1539 child = gtk_bin_get_child (GTK_BIN (button));
1540 if (GTK_IS_ALIGNMENT (child))
1542 child = gtk_bin_get_child (GTK_BIN (child));
1543 if (GTK_IS_BOX (child))
1545 gtk_style_context_get_style (context,
1546 "image-spacing", &spacing,
1549 gtk_box_set_spacing (GTK_BOX (child), spacing);
1555 gtk_button_style_updated (GtkWidget *widget)
1557 GtkStyleContext *context;
1559 GTK_WIDGET_CLASS (gtk_button_parent_class)->style_updated (widget);
1561 context = gtk_widget_get_style_context (widget);
1563 gtk_button_update_image_spacing (GTK_BUTTON (widget), context);
1567 gtk_button_get_props (GtkButton *button,
1568 GtkBorder *default_border,
1569 GtkBorder *default_outside_border,
1572 gboolean *interior_focus)
1574 GtkStyleContext *context;
1575 GtkStateFlags state;
1576 GtkBorder *tmp_border;
1578 context = gtk_widget_get_style_context (GTK_WIDGET (button));
1579 state = gtk_style_context_get_state (context);
1583 gtk_style_context_get_style (context,
1584 "default-border", &tmp_border,
1589 *default_border = *tmp_border;
1590 gtk_border_free (tmp_border);
1593 *default_border = default_default_border;
1596 if (default_outside_border)
1598 gtk_style_context_get_style (context,
1599 "default-outside-border", &tmp_border,
1604 *default_outside_border = *tmp_border;
1605 gtk_border_free (tmp_border);
1608 *default_outside_border = default_default_outside_border;
1613 gtk_style_context_get_style (context,
1614 "interior-focus", interior_focus,
1619 gtk_style_context_get_padding (context, state, padding);
1622 gtk_style_context_get_border (context, state, border);
1626 gtk_button_size_allocate (GtkWidget *widget,
1627 GtkAllocation *allocation)
1629 GtkButton *button = GTK_BUTTON (widget);
1630 GtkButtonPrivate *priv = button->priv;
1631 GtkAllocation child_allocation;
1632 GtkStyleContext *context;
1634 GtkBorder default_border;
1640 context = gtk_widget_get_style_context (widget);
1642 gtk_button_get_props (button, &default_border, NULL,
1643 &padding, &border, NULL);
1644 gtk_style_context_get_style (context,
1645 "focus-line-width", &focus_width,
1646 "focus-padding", &focus_pad,
1649 gtk_widget_set_allocation (widget, allocation);
1651 if (gtk_widget_get_realized (widget))
1652 gdk_window_move_resize (priv->event_window,
1656 allocation->height);
1658 child = gtk_bin_get_child (GTK_BIN (button));
1659 if (child && gtk_widget_get_visible (child))
1661 child_allocation.x = allocation->x + padding.left + border.left;
1662 child_allocation.y = allocation->y + padding.top + border.top;
1664 child_allocation.width =
1666 (padding.left + padding.right) -
1667 (border.left + border.right);
1669 child_allocation.height =
1670 allocation->height -
1671 (padding.top + padding.bottom) -
1672 (border.top + border.bottom);
1674 if (gtk_widget_get_can_default (GTK_WIDGET (button)))
1676 child_allocation.x += default_border.left;
1677 child_allocation.y += default_border.top;
1678 child_allocation.width = child_allocation.width - default_border.left - default_border.right;
1679 child_allocation.height = child_allocation.height - default_border.top - default_border.bottom;
1682 if (gtk_widget_get_can_focus (GTK_WIDGET (button)))
1684 child_allocation.x += focus_width + focus_pad;
1685 child_allocation.y += focus_width + focus_pad;
1686 child_allocation.width = child_allocation.width - (focus_width + focus_pad) * 2;
1687 child_allocation.height = child_allocation.height - (focus_width + focus_pad) * 2;
1690 if (priv->depressed)
1692 gint child_displacement_x;
1693 gint child_displacement_y;
1695 gtk_style_context_get_style (context,
1696 "child-displacement-x", &child_displacement_x,
1697 "child-displacement-y", &child_displacement_y,
1699 child_allocation.x += child_displacement_x;
1700 child_allocation.y += child_displacement_y;
1703 child_allocation.width = MAX (1, child_allocation.width);
1704 child_allocation.height = MAX (1, child_allocation.height);
1706 gtk_widget_size_allocate (child, &child_allocation);
1711 gtk_button_draw (GtkWidget *widget,
1714 GtkButton *button = GTK_BUTTON (widget);
1715 GtkButtonPrivate *priv = button->priv;
1717 GtkBorder default_border;
1718 GtkBorder default_outside_border;
1719 gboolean interior_focus;
1722 GtkAllocation allocation;
1723 GtkStyleContext *context;
1724 GtkStateFlags state;
1725 gboolean draw_focus;
1728 context = gtk_widget_get_style_context (widget);
1729 state = gtk_style_context_get_state (context);
1731 gtk_button_get_props (button, &default_border, &default_outside_border, NULL, NULL, &interior_focus);
1732 gtk_style_context_get_style (context,
1733 "focus-line-width", &focus_width,
1734 "focus-padding", &focus_pad,
1737 gtk_widget_get_allocation (widget, &allocation);
1741 width = allocation.width;
1742 height = allocation.height;
1744 if (gtk_widget_has_default (widget) &&
1745 priv->relief == GTK_RELIEF_NORMAL)
1747 x += default_border.left;
1748 y += default_border.top;
1749 width -= default_border.left + default_border.right;
1750 height -= default_border.top + default_border.bottom;
1752 else if (gtk_widget_get_can_default (widget))
1754 x += default_outside_border.left;
1755 y += default_outside_border.top;
1756 width -= default_outside_border.left + default_outside_border.right;
1757 height -= default_outside_border.top + default_outside_border.bottom;
1760 draw_focus = gtk_widget_has_visible_focus (widget);
1763 if (!interior_focus && draw_focus)
1765 x += focus_width + focus_pad;
1766 y += focus_width + focus_pad;
1767 width -= 2 * (focus_width + focus_pad);
1768 height -= 2 * (focus_width + focus_pad);
1771 if (priv->relief != GTK_RELIEF_NONE || priv->depressed ||
1772 state & GTK_STATE_FLAG_PRELIGHT)
1774 gtk_render_background (context, cr,
1775 x, y, width, height);
1776 gtk_render_frame (context, cr,
1777 x, y, width, height);
1782 gint child_displacement_x;
1783 gint child_displacement_y;
1784 gboolean displace_focus;
1787 gtk_style_context_get_style (context,
1788 "child-displacement-y", &child_displacement_y,
1789 "child-displacement-x", &child_displacement_x,
1790 "displace-focus", &displace_focus,
1792 gtk_style_context_get_border (context, state, &border);
1796 x += border.left + focus_pad;
1797 y += border.top + focus_pad;
1798 width -= (2 * focus_pad) + border.left + border.right;
1799 height -= (2 * focus_pad) + border.top + border.bottom;
1803 x -= focus_width + focus_pad;
1804 y -= focus_width + focus_pad;
1805 width += 2 * (focus_width + focus_pad);
1806 height += 2 * (focus_width + focus_pad);
1809 if (priv->depressed && displace_focus)
1811 x += child_displacement_x;
1812 y += child_displacement_y;
1815 gtk_render_focus (context, cr, x, y, width, height);
1818 GTK_WIDGET_CLASS (gtk_button_parent_class)->draw (widget, cr);
1824 gtk_button_button_press (GtkWidget *widget,
1825 GdkEventButton *event)
1828 GtkButtonPrivate *priv;
1830 if (event->type == GDK_BUTTON_PRESS)
1832 button = GTK_BUTTON (widget);
1833 priv = button->priv;
1835 if (priv->focus_on_click && !gtk_widget_has_focus (widget))
1836 gtk_widget_grab_focus (widget);
1838 if (event->button == GDK_BUTTON_PRIMARY)
1839 g_signal_emit (button, button_signals[PRESSED], 0);
1846 gtk_button_button_release (GtkWidget *widget,
1847 GdkEventButton *event)
1851 if (event->button == GDK_BUTTON_PRIMARY)
1853 button = GTK_BUTTON (widget);
1854 g_signal_emit (button, button_signals[RELEASED], 0);
1861 gtk_button_touch (GtkWidget *widget,
1862 GdkEventTouch *event)
1864 GtkButton *button = GTK_BUTTON (widget);
1865 GtkButtonPrivate *priv = button->priv;
1867 if (event->type == GDK_TOUCH_BEGIN)
1869 if (priv->focus_on_click && !gtk_widget_has_focus (widget))
1870 gtk_widget_grab_focus (widget);
1872 g_signal_emit (button, button_signals[PRESSED], 0);
1874 else if (event->type == GDK_TOUCH_END)
1876 g_signal_emit (button, button_signals[RELEASED], 0);
1883 gtk_button_grab_broken (GtkWidget *widget,
1884 GdkEventGrabBroken *event)
1886 GtkButton *button = GTK_BUTTON (widget);
1887 GtkButtonPrivate *priv = button->priv;
1890 /* Simulate a button release without the pointer in the button */
1891 if (priv->button_down)
1893 save_in = priv->in_button;
1894 priv->in_button = FALSE;
1895 g_signal_emit (button, button_signals[RELEASED], 0);
1896 if (save_in != priv->in_button)
1898 priv->in_button = save_in;
1899 gtk_button_update_state (button);
1907 gtk_button_key_release (GtkWidget *widget,
1910 GtkButton *button = GTK_BUTTON (widget);
1911 GtkButtonPrivate *priv = button->priv;
1913 if (priv->activate_timeout)
1915 gtk_button_finish_activate (button, TRUE);
1918 else if (GTK_WIDGET_CLASS (gtk_button_parent_class)->key_release_event)
1919 return GTK_WIDGET_CLASS (gtk_button_parent_class)->key_release_event (widget, event);
1925 gtk_button_enter_notify (GtkWidget *widget,
1926 GdkEventCrossing *event)
1928 GtkButton *button = GTK_BUTTON (widget);
1929 GtkButtonPrivate *priv = button->priv;
1931 if ((event->window == button->priv->event_window) &&
1932 (event->detail != GDK_NOTIFY_INFERIOR))
1934 priv->in_button = TRUE;
1935 g_signal_emit (button, button_signals[ENTER], 0);
1942 gtk_button_leave_notify (GtkWidget *widget,
1943 GdkEventCrossing *event)
1945 GtkButton *button = GTK_BUTTON (widget);
1946 GtkButtonPrivate *priv = button->priv;
1948 if ((event->window == button->priv->event_window) &&
1949 (event->detail != GDK_NOTIFY_INFERIOR) &&
1950 (gtk_widget_get_sensitive (widget)))
1952 priv->in_button = FALSE;
1953 g_signal_emit (button, button_signals[LEAVE], 0);
1960 gtk_real_button_pressed (GtkButton *button)
1962 GtkButtonPrivate *priv = button->priv;
1964 if (priv->activate_timeout)
1967 priv->button_down = TRUE;
1968 gtk_button_update_state (button);
1972 touch_release_in_button (GtkButton *button)
1974 GtkButtonPrivate *priv;
1979 priv = button->priv;
1980 event = gtk_get_current_event ();
1985 if (event->type != GDK_TOUCH_END ||
1986 event->touch.window != priv->event_window)
1988 gdk_event_free (event);
1992 gdk_event_get_coords (event, &x, &y);
1993 width = gdk_window_get_width (priv->event_window);
1994 height = gdk_window_get_height (priv->event_window);
1996 gdk_event_free (event);
1998 if (x >= 0 && x <= width &&
1999 y >= 0 && y <= height)
2006 gtk_real_button_released (GtkButton *button)
2008 GtkButtonPrivate *priv = button->priv;
2010 if (priv->button_down)
2012 priv->button_down = FALSE;
2014 if (priv->activate_timeout)
2017 if (priv->in_button ||
2018 touch_release_in_button (button))
2019 gtk_button_clicked (button);
2021 gtk_button_update_state (button);
2026 gtk_real_button_clicked (GtkButton *button)
2028 GtkButtonPrivate *priv = button->priv;
2030 if (priv->action_observer)
2031 g_simple_action_observer_activate (priv->action_observer);
2034 gtk_action_activate (priv->action);
2038 button_activate_timeout (gpointer data)
2040 gtk_button_finish_activate (data, TRUE);
2046 gtk_real_button_activate (GtkButton *button)
2048 GtkWidget *widget = GTK_WIDGET (button);
2049 GtkButtonPrivate *priv = button->priv;
2053 device = gtk_get_current_event_device ();
2055 if (device && gdk_device_get_source (device) != GDK_SOURCE_KEYBOARD)
2056 device = gdk_device_get_associated_device (device);
2058 if (gtk_widget_get_realized (widget) && !priv->activate_timeout)
2060 time = gtk_get_current_event_time ();
2062 /* bgo#626336 - Only grab if we have a device (from an event), not if we
2063 * were activated programmatically when no event is available.
2065 if (device && gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD)
2067 if (gdk_device_grab (device, priv->event_window,
2068 GDK_OWNERSHIP_WINDOW, TRUE,
2069 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK,
2070 NULL, time) == GDK_GRAB_SUCCESS)
2072 gtk_device_grab_add (widget, device, TRUE);
2073 priv->grab_keyboard = device;
2074 priv->grab_time = time;
2078 priv->activate_timeout = gdk_threads_add_timeout (ACTIVATE_TIMEOUT,
2079 button_activate_timeout,
2081 priv->button_down = TRUE;
2082 gtk_button_update_state (button);
2083 gtk_widget_queue_draw (GTK_WIDGET (button));
2088 gtk_button_finish_activate (GtkButton *button,
2091 GtkWidget *widget = GTK_WIDGET (button);
2092 GtkButtonPrivate *priv = button->priv;
2094 g_source_remove (priv->activate_timeout);
2095 priv->activate_timeout = 0;
2097 if (priv->grab_keyboard)
2099 gdk_device_ungrab (priv->grab_keyboard, priv->grab_time);
2100 gtk_device_grab_remove (widget, priv->grab_keyboard);
2101 priv->grab_keyboard = NULL;
2104 priv->button_down = FALSE;
2106 gtk_button_update_state (button);
2107 gtk_widget_queue_draw (GTK_WIDGET (button));
2110 gtk_button_clicked (button);
2115 gtk_button_get_size (GtkWidget *widget,
2116 GtkOrientation orientation,
2120 GtkButton *button = GTK_BUTTON (widget);
2121 GtkStyleContext *context;
2123 GtkBorder default_border;
2128 gint minimum, natural;
2130 context = gtk_widget_get_style_context (widget);
2132 gtk_button_get_props (button, &default_border, NULL,
2133 &padding, &border, NULL);
2134 gtk_style_context_get_style (context,
2135 "focus-line-width", &focus_width,
2136 "focus-padding", &focus_pad,
2139 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2141 minimum = padding.left + padding.right +
2142 border.left + border.right;
2144 if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
2145 minimum += default_border.left + default_border.right;
2149 minimum = padding.top + padding.bottom +
2150 border.top + border.bottom;
2152 if (gtk_widget_get_can_default (GTK_WIDGET (widget)))
2153 minimum += default_border.top + default_border.bottom;
2156 minimum += 2 * (focus_width + focus_pad);
2159 if ((child = gtk_bin_get_child (GTK_BIN (button))) &&
2160 gtk_widget_get_visible (child))
2162 gint child_min, child_nat;
2164 if (orientation == GTK_ORIENTATION_HORIZONTAL)
2165 gtk_widget_get_preferred_width (child, &child_min, &child_nat);
2167 gtk_widget_get_preferred_height (child, &child_min, &child_nat);
2169 minimum += child_min;
2170 natural += child_nat;
2174 *minimum_size = minimum;
2177 *natural_size = natural;
2181 gtk_button_get_preferred_width (GtkWidget *widget,
2185 gtk_button_get_size (widget, GTK_ORIENTATION_HORIZONTAL, minimum_size, natural_size);
2189 gtk_button_get_preferred_height (GtkWidget *widget,
2193 gtk_button_get_size (widget, GTK_ORIENTATION_VERTICAL, minimum_size, natural_size);
2197 * gtk_button_set_label:
2198 * @button: a #GtkButton
2201 * Sets the text of the label of the button to @str. This text is
2202 * also used to select the stock item if gtk_button_set_use_stock()
2205 * This will also clear any previously set labels.
2208 gtk_button_set_label (GtkButton *button,
2211 GtkButtonPrivate *priv;
2214 g_return_if_fail (GTK_IS_BUTTON (button));
2216 priv = button->priv;
2218 new_label = g_strdup (label);
2219 g_free (priv->label_text);
2220 priv->label_text = new_label;
2222 gtk_button_construct_child (button);
2224 g_object_notify (G_OBJECT (button), "label");
2228 * gtk_button_get_label:
2229 * @button: a #GtkButton
2231 * Fetches the text from the label of the button, as set by
2232 * gtk_button_set_label(). If the label text has not
2233 * been set the return value will be %NULL. This will be the
2234 * case if you create an empty button with gtk_button_new() to
2235 * use as a container.
2237 * Return value: The text of the label widget. This string is owned
2238 * by the widget and must not be modified or freed.
2241 gtk_button_get_label (GtkButton *button)
2243 g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
2245 return button->priv->label_text;
2249 * gtk_button_set_use_underline:
2250 * @button: a #GtkButton
2251 * @use_underline: %TRUE if underlines in the text indicate mnemonics
2253 * If true, an underline in the text of the button label indicates
2254 * the next character should be used for the mnemonic accelerator key.
2257 gtk_button_set_use_underline (GtkButton *button,
2258 gboolean use_underline)
2260 GtkButtonPrivate *priv;
2262 g_return_if_fail (GTK_IS_BUTTON (button));
2264 priv = button->priv;
2266 use_underline = use_underline != FALSE;
2268 if (use_underline != priv->use_underline)
2270 priv->use_underline = use_underline;
2272 gtk_button_construct_child (button);
2274 g_object_notify (G_OBJECT (button), "use-underline");
2279 * gtk_button_get_use_underline:
2280 * @button: a #GtkButton
2282 * Returns whether an embedded underline in the button label indicates a
2283 * mnemonic. See gtk_button_set_use_underline ().
2285 * Return value: %TRUE if an embedded underline in the button label
2286 * indicates the mnemonic accelerator keys.
2289 gtk_button_get_use_underline (GtkButton *button)
2291 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
2293 return button->priv->use_underline;
2297 * gtk_button_set_use_stock:
2298 * @button: a #GtkButton
2299 * @use_stock: %TRUE if the button should use a stock item
2301 * If %TRUE, the label set on the button is used as a
2302 * stock id to select the stock item for the button.
2305 gtk_button_set_use_stock (GtkButton *button,
2308 GtkButtonPrivate *priv;
2310 g_return_if_fail (GTK_IS_BUTTON (button));
2312 priv = button->priv;
2314 use_stock = use_stock != FALSE;
2316 if (use_stock != priv->use_stock)
2318 priv->use_stock = use_stock;
2320 gtk_button_construct_child (button);
2322 g_object_notify (G_OBJECT (button), "use-stock");
2327 * gtk_button_get_use_stock:
2328 * @button: a #GtkButton
2330 * Returns whether the button label is a stock item.
2332 * Return value: %TRUE if the button label is used to
2333 * select a stock item instead of being
2334 * used directly as the label text.
2337 gtk_button_get_use_stock (GtkButton *button)
2339 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
2341 return button->priv->use_stock;
2345 * gtk_button_set_focus_on_click:
2346 * @button: a #GtkButton
2347 * @focus_on_click: whether the button grabs focus when clicked with the mouse
2349 * Sets whether the button will grab focus when it is clicked with the mouse.
2350 * Making mouse clicks not grab focus is useful in places like toolbars where
2351 * you don't want the keyboard focus removed from the main area of the
2357 gtk_button_set_focus_on_click (GtkButton *button,
2358 gboolean focus_on_click)
2360 GtkButtonPrivate *priv;
2362 g_return_if_fail (GTK_IS_BUTTON (button));
2364 priv = button->priv;
2366 focus_on_click = focus_on_click != FALSE;
2368 if (priv->focus_on_click != focus_on_click)
2370 priv->focus_on_click = focus_on_click;
2372 g_object_notify (G_OBJECT (button), "focus-on-click");
2377 * gtk_button_get_focus_on_click:
2378 * @button: a #GtkButton
2380 * Returns whether the button grabs focus when it is clicked with the mouse.
2381 * See gtk_button_set_focus_on_click().
2383 * Return value: %TRUE if the button grabs focus when it is clicked with
2389 gtk_button_get_focus_on_click (GtkButton *button)
2391 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
2393 return button->priv->focus_on_click;
2397 * gtk_button_set_alignment:
2398 * @button: a #GtkButton
2399 * @xalign: the horizontal position of the child, 0.0 is left aligned,
2400 * 1.0 is right aligned
2401 * @yalign: the vertical position of the child, 0.0 is top aligned,
2402 * 1.0 is bottom aligned
2404 * Sets the alignment of the child. This property has no effect unless
2405 * the child is a #GtkMisc or a #GtkAlignment.
2410 gtk_button_set_alignment (GtkButton *button,
2414 GtkButtonPrivate *priv;
2416 g_return_if_fail (GTK_IS_BUTTON (button));
2418 priv = button->priv;
2420 priv->xalign = xalign;
2421 priv->yalign = yalign;
2422 priv->align_set = 1;
2424 maybe_set_alignment (button, gtk_bin_get_child (GTK_BIN (button)));
2426 g_object_freeze_notify (G_OBJECT (button));
2427 g_object_notify (G_OBJECT (button), "xalign");
2428 g_object_notify (G_OBJECT (button), "yalign");
2429 g_object_thaw_notify (G_OBJECT (button));
2433 * gtk_button_get_alignment:
2434 * @button: a #GtkButton
2435 * @xalign: (out): return location for horizontal alignment
2436 * @yalign: (out): return location for vertical alignment
2438 * Gets the alignment of the child in the button.
2443 gtk_button_get_alignment (GtkButton *button,
2447 GtkButtonPrivate *priv;
2449 g_return_if_fail (GTK_IS_BUTTON (button));
2451 priv = button->priv;
2454 *xalign = priv->xalign;
2457 *yalign = priv->yalign;
2461 * _gtk_button_set_depressed:
2462 * @button: a #GtkButton
2463 * @depressed: %TRUE if the button should be drawn with a recessed shadow.
2465 * Sets whether the button is currently drawn as down or not. This is
2466 * purely a visual setting, and is meant only for use by derived widgets
2467 * such as #GtkToggleButton.
2470 _gtk_button_set_depressed (GtkButton *button,
2473 GtkWidget *widget = GTK_WIDGET (button);
2474 GtkButtonPrivate *priv = button->priv;
2476 depressed = depressed != FALSE;
2478 if (depressed != priv->depressed)
2480 priv->depressed = depressed;
2481 gtk_widget_queue_resize (widget);
2486 gtk_button_update_state (GtkButton *button)
2488 GtkButtonPrivate *priv = button->priv;
2489 GtkStateFlags new_state;
2492 if (priv->activate_timeout)
2493 depressed = priv->depress_on_activate;
2495 depressed = priv->in_button && priv->button_down;
2497 new_state = gtk_widget_get_state_flags (GTK_WIDGET (button)) &
2498 ~(GTK_STATE_FLAG_PRELIGHT | GTK_STATE_FLAG_ACTIVE);
2500 if (priv->in_button)
2501 new_state |= GTK_STATE_FLAG_PRELIGHT;
2504 new_state |= GTK_STATE_FLAG_ACTIVE;
2506 _gtk_button_set_depressed (button, depressed);
2507 gtk_widget_set_state_flags (GTK_WIDGET (button), new_state, TRUE);
2511 show_image_change_notify (GtkButton *button)
2513 GtkButtonPrivate *priv = button->priv;
2517 if (show_image (button))
2518 gtk_widget_show (priv->image);
2520 gtk_widget_hide (priv->image);
2525 traverse_container (GtkWidget *widget,
2528 if (GTK_IS_BUTTON (widget))
2529 show_image_change_notify (GTK_BUTTON (widget));
2530 else if (GTK_IS_CONTAINER (widget))
2531 gtk_container_forall (GTK_CONTAINER (widget), traverse_container, NULL);
2535 gtk_button_setting_changed (GtkSettings *settings)
2539 list = gtk_window_list_toplevels ();
2541 for (l = list; l; l = l->next)
2542 gtk_container_forall (GTK_CONTAINER (l->data),
2543 traverse_container, NULL);
2550 gtk_button_screen_changed (GtkWidget *widget,
2551 GdkScreen *previous_screen)
2554 GtkButtonPrivate *priv;
2555 GtkSettings *settings;
2556 gulong show_image_connection;
2558 if (!gtk_widget_has_screen (widget))
2561 button = GTK_BUTTON (widget);
2562 priv = button->priv;
2564 /* If the button is being pressed while the screen changes the
2565 release might never occur, so we reset the state. */
2566 if (priv->button_down)
2568 priv->button_down = FALSE;
2569 gtk_button_update_state (button);
2572 settings = gtk_widget_get_settings (widget);
2574 show_image_connection =
2575 g_signal_handler_find (settings, G_SIGNAL_MATCH_FUNC, 0, 0,
2576 NULL, gtk_button_setting_changed, NULL);
2578 if (show_image_connection)
2581 g_signal_connect (settings, "notify::gtk-button-images",
2582 G_CALLBACK (gtk_button_setting_changed), NULL);
2584 show_image_change_notify (button);
2588 gtk_button_state_changed (GtkWidget *widget,
2589 GtkStateType previous_state)
2591 GtkButton *button = GTK_BUTTON (widget);
2592 GtkButtonPrivate *priv = button->priv;
2594 if (!gtk_widget_is_sensitive (widget))
2596 priv->in_button = FALSE;
2597 gtk_real_button_released (button);
2602 gtk_button_grab_notify (GtkWidget *widget,
2603 gboolean was_grabbed)
2605 GtkButton *button = GTK_BUTTON (widget);
2606 GtkButtonPrivate *priv = button->priv;
2609 if (priv->activate_timeout &&
2610 priv->grab_keyboard &&
2611 gtk_widget_device_is_shadowed (widget, priv->grab_keyboard))
2612 gtk_button_finish_activate (button, FALSE);
2616 save_in = priv->in_button;
2617 priv->in_button = FALSE;
2618 gtk_real_button_released (button);
2619 if (save_in != priv->in_button)
2621 priv->in_button = save_in;
2622 gtk_button_update_state (button);
2628 gtk_button_hierarchy_changed (GtkWidget *widget,
2629 GtkWidget *previous_toplevel)
2631 GtkButton *button = GTK_BUTTON (widget);
2632 GtkWidgetClass *parent_class;
2634 parent_class = GTK_WIDGET_CLASS (gtk_button_parent_class);
2635 if (parent_class->hierarchy_changed)
2636 parent_class->hierarchy_changed (widget, previous_toplevel);
2638 if (button->priv->action_name)
2640 GtkWidget *toplevel;
2642 toplevel = gtk_widget_get_toplevel (widget);
2644 if (toplevel != previous_toplevel)
2645 gtk_button_update_action_observer (button);
2650 * gtk_button_set_image:
2651 * @button: a #GtkButton
2652 * @image: a widget to set as the image for the button
2654 * Set the image of @button to the given widget. Note that
2655 * it depends on the #GtkSettings:gtk-button-images setting whether the
2656 * image will be displayed or not, you don't have to call
2657 * gtk_widget_show() on @image yourself.
2662 gtk_button_set_image (GtkButton *button,
2665 GtkButtonPrivate *priv;
2668 g_return_if_fail (GTK_IS_BUTTON (button));
2669 g_return_if_fail (image == NULL || GTK_IS_WIDGET (image));
2671 priv = button->priv;
2675 parent = gtk_widget_get_parent (priv->image);
2677 gtk_container_remove (GTK_CONTAINER (parent), priv->image);
2680 priv->image = image;
2681 priv->image_is_stock = (image == NULL);
2683 gtk_button_construct_child (button);
2685 g_object_notify (G_OBJECT (button), "image");
2689 * gtk_button_get_image:
2690 * @button: a #GtkButton
2692 * Gets the widget that is currenty set as the image of @button.
2693 * This may have been explicitly set by gtk_button_set_image()
2694 * or constructed by gtk_button_new_from_stock().
2696 * Return value: (transfer none): a #GtkWidget or %NULL in case there is no image
2701 gtk_button_get_image (GtkButton *button)
2703 g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
2705 return button->priv->image;
2709 * gtk_button_set_image_position:
2710 * @button: a #GtkButton
2711 * @position: the position
2713 * Sets the position of the image relative to the text
2714 * inside the button.
2719 gtk_button_set_image_position (GtkButton *button,
2720 GtkPositionType position)
2722 GtkButtonPrivate *priv;
2724 g_return_if_fail (GTK_IS_BUTTON (button));
2725 g_return_if_fail (position >= GTK_POS_LEFT && position <= GTK_POS_BOTTOM);
2727 priv = button->priv;
2729 if (priv->image_position != position)
2731 priv->image_position = position;
2733 gtk_button_construct_child (button);
2735 g_object_notify (G_OBJECT (button), "image-position");
2740 * gtk_button_get_image_position:
2741 * @button: a #GtkButton
2743 * Gets the position of the image relative to the text
2744 * inside the button.
2746 * Return value: the position
2751 gtk_button_get_image_position (GtkButton *button)
2753 g_return_val_if_fail (GTK_IS_BUTTON (button), GTK_POS_LEFT);
2755 return button->priv->image_position;
2759 * gtk_button_set_always_show_image:
2760 * @button: a #GtkButton
2761 * @always_show: %TRUE if the menuitem should always show the image
2763 * If %TRUE, the button will ignore the #GtkSettings:gtk-button-images
2764 * setting and always show the image, if available.
2766 * Use this property if the button would be useless or hard to use
2767 * without the image.
2772 gtk_button_set_always_show_image (GtkButton *button,
2773 gboolean always_show)
2775 GtkButtonPrivate *priv;
2777 g_return_if_fail (GTK_IS_BUTTON (button));
2779 priv = button->priv;
2781 if (priv->always_show_image != always_show)
2783 priv->always_show_image = always_show;
2787 if (show_image (button))
2788 gtk_widget_show (priv->image);
2790 gtk_widget_hide (priv->image);
2793 g_object_notify (G_OBJECT (button), "always-show-image");
2798 * gtk_button_get_always_show_image:
2799 * @button: a #GtkButton
2801 * Returns whether the button will ignore the #GtkSettings:gtk-button-images
2802 * setting and always show the image, if available.
2804 * Returns: %TRUE if the button will always show the image
2809 gtk_button_get_always_show_image (GtkButton *button)
2811 g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
2813 return button->priv->always_show_image;
2817 * gtk_button_get_event_window:
2818 * @button: a #GtkButton
2820 * Returns the button's event window if it is realized, %NULL otherwise.
2821 * This function should be rarely needed.
2823 * Return value: (transfer none): @button's event window.
2828 gtk_button_get_event_window (GtkButton *button)
2830 g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
2832 return button->priv->event_window;