gtk2/gtk/gtkbutton.c

1076 lines
34 KiB
C
Raw Normal View History

/* GTK - The GIMP Toolkit
1997-11-24 22:37:52 +00:00
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
1997-11-24 22:37:52 +00:00
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
1997-11-24 22:37:52 +00:00
*
* You should have received a copy of the GNU Lesser General Public
2012-02-27 13:01:10 +00:00
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
1997-11-24 22:37:52 +00:00
*/
/*
* Modified by the GTK+ Team and others 1997-2001. See the AUTHORS
* file for a list of people on the GTK+ Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
/**
* GtkButton:
*
* The `GtkButton` widget is generally used to trigger a callback function that is
* called when the button is pressed.
*
* ![An example GtkButton](button.png)
*
2021-02-28 00:44:03 +00:00
* The `GtkButton` widget can hold any valid child widget. That is, it can hold
* almost any other standard `GtkWidget`. The most commonly used child is the
* `GtkLabel`.
*
* # CSS nodes
*
* `GtkButton` has a single CSS node with name button. The node will get the
* style classes .image-button or .text-button, if the content is just an
* image or label, respectively. It may also receive the .flat style class.
* When activating a button via the keyboard, the button will temporarily
* gain the .keyboard-activating style class.
*
* Other style classes that are commonly used with `GtkButton` include
2016-03-03 00:10:59 +00:00
* .suggested-action and .destructive-action. In special cases, buttons
* can be made round by adding the .circular style class.
*
* Button-like widgets like [class@Gtk.ToggleButton], [class@Gtk.MenuButton],
* [class@Gtk.VolumeButton], [class@Gtk.LockButton], [class@Gtk.ColorButton]
* or [class@Gtk.FontButton] use style classes such as .toggle, .popup, .scale,
* .lock, .color on the button node to differentiate themselves from a plain
* `GtkButton`.
*
* # Accessibility
*
2021-02-28 00:44:03 +00:00
* `GtkButton` uses the %GTK_ACCESSIBLE_ROLE_BUTTON role.
*/
#include "config.h"
#include "gtkbuttonprivate.h"
#include "gtkactionhelperprivate.h"
#include "gtkbuildable.h"
#include "gtkcheckbutton.h"
#include "gtkgestureclick.h"
#include "gtkeventcontrollerkey.h"
#include "gtkbinlayout.h"
#include "gtkimage.h"
#include "gtkintl.h"
1997-11-24 22:37:52 +00:00
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtktypebuiltins.h"
#include "gtkwidgetprivate.h"
#include "gtkshortcuttrigger.h"
#include <string.h>
1997-11-24 22:37:52 +00:00
/* Time out before giving up on getting a key release when animating
* the close button.
*/
#define ACTIVATE_TIMEOUT 250
1997-11-24 22:37:52 +00:00
struct _GtkButtonPrivate
{
GtkWidget *child;
GtkActionHelper *action_helper;
GtkGesture *gesture;
guint activate_timeout;
guint button_down : 1;
guint use_underline : 1;
guint child_type : 2;
};
1997-11-24 22:37:52 +00:00
enum {
CLICKED,
ACTIVATE,
1997-11-24 22:37:52 +00:00
LAST_SIGNAL
};
Move more text widget headers into the private header list 2000-09-26 Havoc Pennington <hp@redhat.com> * gtk/Makefile.am (gtk_private_h_sources): Move more text widget headers into the private header list * Makefile.am (pkgconfig_DATA): install pkg-config files * configure.in: add pkg-config files * gdk-2.0.pc.in, gdk-pixbuf.pc.in, gtk+-2.0.pc.in: pkg-config files * gtk/gtkwindow.c (gtk_window_read_rcfiles): Invalidate outstanding icon caches on theme change. * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: New icon system. Three important types: (GtkIconSource): Specification for creating a pixbuf appropriate for a direction/state/size triplet from a source pixbuf or filename (GtkIconSet): List of GtkIconSource objects that are used to create the "same" icon (e.g. an OK button icon), and cache for rendered icons (GtkIconFactory): Hash from stock ID to GtkIconSet; used to look up the icon set for a given stock ID. GTK maintains a stack of GtkIconFactory to search, and applications or libraries can add additional icon factories on top of the stack * gtk/gtkrc.h, gtk/gtkrc.c: When loading an RcStyle, parse the set of GtkIconSource specified for a given stock ID into a GtkIconSet, and put the GtkIconSet into a GtkIconFactory for the RcStyle, under the specified stock ID. * gtk/gtkstyle.h, gtk/gtkstyle.c: Add a virtual function render_icon used to derive a GdkPixbuf from a GtkIconSource. This allows people to theme how prelight, insensitive, etc. are done. (gtk_style_lookup_icon_set): Look up a stock ID in the list of icon factories for a style, and return the resulting icon set if any. (gtk_style_render_icon): Render an icon using the render_icon method in the GtkStyleClass. * gtk/gtkwidget.h, gtk/gtkwidget.c (gtk_widget_render_icon): Use the style for a given widget to look up a stock ID, get the icon set, and render an icon using the render_icon method of the style * gtk/gtkstock.h, gtk/gtkstock.c: Header with the GtkStockItem type (contains information about a stock item), the built-in stock item IDs, and functions to add/lookup stock items. * gtk/stock-icons/*: Stock icons that come with GTK * gtk/gtkbutton.h, gtk/gtkbutton.c (gtk_button_new_stock): Returns a button based on a GtkStockItem (gtk_button_new_accel): Takes a uline string and accel group, and installs the accelerator. * gtk/gtkimage.h, gtk/gtkimage.c: Make this into a generic image-display widget.
2000-09-26 20:22:17 +00:00
enum {
PROP_0,
PROP_LABEL,
PROP_HAS_FRAME,
PROP_USE_UNDERLINE,
PROP_ICON_NAME,
2020-05-02 06:45:09 +00:00
PROP_CHILD,
/* actionable properties */
PROP_ACTION_NAME,
PROP_ACTION_TARGET,
LAST_PROP = PROP_ACTION_NAME
};
2016-10-20 15:58:03 +00:00
enum {
LABEL_CHILD,
ICON_CHILD,
WIDGET_CHILD
};
configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on Sun May 3 13:38:22 1998 Owen Taylor <otaylor@gtk.org> * configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on the client and server side. (And, more importantly, check for the shape extension so we may include -lXext even when compiling with --disable-xshm) Don't set override_redirect on all shaped windows. It isn't necessary. * gdk/gdkwindow.c: Set ->colormap to NULL for root and foreign windows. Use this to check if we need to get the colormap from X. Fri May 1 22:32:47 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkbutton.c (gtk_button_paint): Draw the areas between the default and the button always in GTK_STATE_NORMAL. * gtk/gtkrange.c (gtk_range_style_set): Added a style_set callback. Fri May 1 16:40:57 1998 Owen Taylor <otaylor@gtk.org> * gdk/gdkpixmap.c (gdk_pixmap_colormap_create_from_xpmp[_d]): Fix a buffer overflow on pixmaps that claim to have more than 31 characters per pixel. (gdk_pixmap_read_string): Don't wrap around strings longer than half of address space ;-) * gtk/gtk[vh]ruler.c gtk/gtkinputdialog.c: Expand some buffers that were used for printing integers. * */* (almost): Style: All int foo () { ... } changed to int foo (void) { ... } ^^^^^^^ This is why some many files changed Even where there were proper prototypes elsewhere. * gdk/gxid.c (handle_claim_device): Some extra checks. It isn't safe against being fed bad X id's, but at least it should be safe against deleting all your files.
1998-05-03 22:41:32 +00:00
static void gtk_button_dispose (GObject *object);
static void gtk_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void gtk_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
static void gtk_button_unrealize (GtkWidget * widget);
static void gtk_real_button_clicked (GtkButton * button);
static void gtk_real_button_activate (GtkButton *button);
static void gtk_button_finish_activate (GtkButton *button,
2020-08-15 09:54:38 +00:00
gboolean do_it);
1997-11-24 22:37:52 +00:00
2016-11-01 19:28:28 +00:00
static void gtk_button_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state);
static void gtk_button_do_release (GtkButton *button,
gboolean emit_clicked);
static void gtk_button_set_child_type (GtkButton *button, guint child_type);
static void gtk_button_buildable_iface_init (GtkBuildableIface *iface);
static void gtk_button_actionable_iface_init (GtkActionableInterface *iface);
static GParamSpec *props[LAST_PROP] = { NULL, };
made the <widget>_signals[] arrays of type guint rather than gint. made Mon Mar 9 15:48:10 1998 Tim Janik <timj@gimp.org> * Signal signedness and naming corrections, plus GtkType fixes: * gtk/gtkadjustment.c: * gtk/gtkbutton.c: * gtk/gtkcheckmenuitem.c: * gtk/gtkclist.c: * gtk/gtkcolorsel.c: * gtk/gtkcontainer.c: * gtk/gtkcurve.c: * gtk/gtkdata.c: * gtk/gtkeditable.c: * gtk/gtkentry.c: * gtk/gtkhandlebox.c: * gtk/gtkinputdialog.c: * gtk/gtkitem.c: * gtk/gtklist.c: * gtk/gtkmenuitem.c: * gtk/gtkmenushell.c: * gtk/gtknotebook.c: * gtk/gtkstatusbar.c: * gtk/gtktoolbar.c: * gtk/gtktree.c: * gtk/gtktreeitem.c: * gtk/gtkwidget.c: * gtk/gtktogglebutton.c: * gtk/gtkwindow.c: made the <widget>_signals[] arrays of type guint rather than gint. * gtk/gtkwidget.c (gtk_widget_get_ancestor): made widget_type a GtkType. * gtk/gtkcombo.h: handler ids need to be of type guint (entry_change_id, list_change_id). * gtk/gtkaccelerator.c: changed signal_num to signal_id and typed it guint. * gtk/gtkmain.c: made gtk_ndebug_keys a guint. * gtk/gtkmenu.h: * gtk/gtkmenu.c: (gtk_menu_popup): made button a guint. (gtk_menu_set_active): made index a guint. * gtk/gtkmenuitem.h: * gtk/gtkmenuitem.c: made accelerator_signal a guint. * gtk/gtkoptionmenu.h: * gtk/gtkoptionmenu.c: (gtk_option_menu_set_history): made index a guint. * gtk/gtksignal.h: * gtk/gtksignal.c: * gtk/gtkobject.h: * gtk/gtkobject.c: changed a bunch of prototypes to take guints rather than gints. also made some conversions from guint to GtkType, left over from when the fundamental-types system was introduced. * gtk/gtkobject.h: * gtk/gtkobject.c: made object_data_id_index and obj_count guints. made *signals and nsignals guints in GtkObjectClass.
1998-03-09 15:16:28 +00:00
static guint button_signals[LAST_SIGNAL] = { 0 };
1997-11-24 22:37:52 +00:00
G_DEFINE_TYPE_WITH_CODE (GtkButton, gtk_button, GTK_TYPE_WIDGET,
G_ADD_PRIVATE (GtkButton)
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, gtk_button_buildable_iface_init)
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_button_actionable_iface_init))
1997-11-24 22:37:52 +00:00
2016-10-20 15:58:03 +00:00
static void
gtk_button_compute_expand (GtkWidget *widget,
gboolean *hexpand,
gboolean *vexpand)
2016-10-20 15:58:03 +00:00
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (GTK_BUTTON (widget));
2016-10-20 15:58:03 +00:00
if (priv->child)
{
*hexpand = gtk_widget_compute_expand (priv->child, GTK_ORIENTATION_HORIZONTAL);
*vexpand = gtk_widget_compute_expand (priv->child, GTK_ORIENTATION_VERTICAL);
}
else
{
*hexpand = FALSE;
*vexpand = FALSE;
}
2016-10-20 15:58:03 +00:00
}
static GtkSizeRequestMode
gtk_button_get_request_mode (GtkWidget *widget)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (GTK_BUTTON (widget));
if (priv->child)
return gtk_widget_get_request_mode (priv->child);
else
return GTK_SIZE_REQUEST_CONSTANT_SIZE;
}
1997-11-24 22:37:52 +00:00
static void
gtk_button_class_init (GtkButtonClass *klass)
{
const guint activate_keyvals[] = { GDK_KEY_space, GDK_KEY_KP_Space, GDK_KEY_Return,
GDK_KEY_ISO_Enter, GDK_KEY_KP_Enter };
GObjectClass *gobject_class;
1997-11-24 22:37:52 +00:00
GtkWidgetClass *widget_class;
GtkShortcutAction *activate_action;
1997-11-24 22:37:52 +00:00
gobject_class = G_OBJECT_CLASS (klass);
1997-11-24 22:37:52 +00:00
widget_class = (GtkWidgetClass*) klass;
2016-10-20 15:58:03 +00:00
gobject_class->dispose = gtk_button_dispose;
gobject_class->set_property = gtk_button_set_property;
gobject_class->get_property = gtk_button_get_property;
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
widget_class->unrealize = gtk_button_unrealize;
2016-11-01 19:28:28 +00:00
widget_class->state_flags_changed = gtk_button_state_flags_changed;
widget_class->compute_expand = gtk_button_compute_expand;
widget_class->get_request_mode = gtk_button_get_request_mode;
2016-10-20 15:58:03 +00:00
klass->clicked = NULL;
klass->activate = gtk_real_button_activate;
doh, this was broken beyond believe. Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org> * gtk/stock-icons/Makefile.am: doh, this was broken beyond believe. * gtk/gtkbox.c: change property types from (u)long to (u)int for ::position and ::padding. * gtk/gtkcontainer.c: make ::border_width an INT property. * gtk/gtkpacker.c: make ::position an INT property. * gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed): guard against NULL h/v scrollbars, since this is used at construction time. * gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented internal gtk_clist_constructor(). * gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented gtk_ctree_constructor(). * gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property ::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION. * docs/reference/Makefile.am: fun stuff, disabled docs generation again, gtk-scan.c needs to introspec paramspecs, not GtkAgs. * gtk/gtkwidget.[hc]: removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv() and gtk_widget_get(). (gtk_widget_new): use g_object_new_valist(). (gtk_widget_set): use g_object_set_valist(). * gtk/gtkobject.[hc]: removed gtk_object_arg_get_info(), gtk_object_getv(), gtk_object_query_args(), gtk_object_newv(), gtk_object_class_add_signals(), gtk_object_class_user_signal_new(), gtk_object_class_user_signal_newv(), gtk_object_arg_set(), gtk_object_arg_get(), gtk_object_args_collect(), gtk_object_default_construct(), gtk_object_constructed(), GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED(). removed nsignals, signals and n_args members from GtkObjectClass. (gtk_object_new): use g_object_new_valist(). (gtk_object_set): use g_object_set_valist(). (gtk_object_get): use g_object_get_valist(). * gtk/gtkcompat.h: define gtk_object_default_construct(). * gtk/gtktypeutils.c (gtk_type_new): create constructed objects via g_object_new(). * gtk/*.c: removed gtk_object_class_add_signals() from class_init() fucntions, cleaned up method assignments (make sure your structures are setup properly before calling out). removed all GTK_CONSTRUCTED hacks ;)
2000-12-13 01:34:41 +00:00
/**
* GtkButton:label: (attributes org.gtk.Property.get=gtk_button_get_label org.gtk.Property.set=gtk_button_set_label)
*
* Text of the label inside the button, if the button contains a label widget.
*/
props[PROP_LABEL] =
g_param_spec_string ("label",
P_("Label"),
P_("Text of the label widget inside the button, if the button contains a label widget"),
NULL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
2016-10-02 17:03:29 +00:00
/**
* GtkButton:use-underline: (attributes org.gtk.Property.get=gtk_button_get_use_underline org.gtk.Property.set=gtk_button_set_use_underline)
*
* If set, an underline in the text indicates that the following character is
* to be used as mnemonic.
*/
props[PROP_USE_UNDERLINE] =
g_param_spec_boolean ("use-underline",
P_("Use underline"),
P_("If set, an underline in the text indicates the next character should be used for the mnemonic accelerator key"),
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
2016-10-02 17:03:29 +00:00
/**
* GtkButton:has-frame: (attributes org.gtk.Property.get=gtk_button_get_has_frame org.gtk.Property.set=gtk_button_set_has_frame)
*
* Whether the button has a frame.
*/
props[PROP_HAS_FRAME] =
g_param_spec_boolean ("has-frame",
P_("Has Frame"),
P_("Whether the button has a frame"),
TRUE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
1997-11-24 22:37:52 +00:00
/**
* GtkButton:icon-name: (attributes org.gtk.Property.get=gtk_button_get_icon_name org.gtk.Property.set=gtk_button_set_icon_name)
*
* The name of the icon used to automatically populate the button.
*/
props[PROP_ICON_NAME] =
g_param_spec_string ("icon-name",
P_("Icon Name"),
P_("The name of the icon used to automatically populate the button"),
NULL,
2014-06-07 14:48:49 +00:00
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
2004-11-15 20:56:28 +00:00
/**
* GtkButton:child: (attributes org.gtk.Property.get=gtk_button_get_child org.gtk.Property.set=gtk_button_set_child)
*
* The child widget.
*/
2020-05-02 06:45:09 +00:00
props[PROP_CHILD] =
g_param_spec_object ("child",
P_("Child"),
P_("The child widget"),
GTK_TYPE_WIDGET,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (gobject_class, LAST_PROP, props);
g_object_class_override_property (gobject_class, PROP_ACTION_NAME, "action-name");
g_object_class_override_property (gobject_class, PROP_ACTION_TARGET, "action-target");
/**
* GtkButton::clicked:
* @button: the object that received the signal
*
* Emitted when the button has been activated (pressed and released).
*/
1997-11-24 22:37:52 +00:00
button_signals[CLICKED] =
g_signal_new (I_("clicked"),
2020-08-15 09:54:38 +00:00
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkButtonClass, clicked),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
/**
* GtkButton::activate:
* @widget: the object which received the signal.
*
* Emitted to animate press then release.
*
* This is an action signal. Applications should never connect
* to this signal, but use the [signal@Gtk.Button::clicked] signal.
*/
button_signals[ACTIVATE] =
g_signal_new (I_("activate"),
2020-08-15 09:54:38 +00:00
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET (GtkButtonClass, activate),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
gtk_widget_class_set_activate_signal (widget_class, button_signals[ACTIVATE]);
activate_action = gtk_signal_action_new ("activate");
for (guint i = 0; i < G_N_ELEMENTS (activate_keyvals); i++)
{
GtkShortcut *activate_shortcut = gtk_shortcut_new (gtk_keyval_trigger_new (activate_keyvals[i], 0),
g_object_ref (activate_action));
gtk_widget_class_add_shortcut (widget_class, activate_shortcut);
g_object_unref (activate_shortcut);
}
g_object_unref (activate_action);
2020-07-13 15:03:27 +00:00
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("button"));
1997-11-24 22:37:52 +00:00
}
static void
click_pressed_cb (GtkGestureClick *gesture,
guint n_press,
2020-07-24 20:32:16 +00:00
double x,
double y,
GtkWidget *widget)
{
GtkButton *button = GTK_BUTTON (widget);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (gtk_widget_get_focus_on_click (widget) && !gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
if (!priv->activate_timeout)
priv->button_down = TRUE;
}
static void
click_released_cb (GtkGestureClick *gesture,
guint n_press,
2020-07-24 20:32:16 +00:00
double x,
double y,
GtkWidget *widget)
{
GtkButton *button = GTK_BUTTON (widget);
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
gtk_button_do_release (button,
gtk_widget_is_sensitive (GTK_WIDGET (button)) &&
gtk_widget_contains (widget, x, y));
}
static void
click_gesture_cancel_cb (GtkGesture *gesture,
GdkEventSequence *sequence,
GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (priv->activate_timeout)
gtk_button_finish_activate (button, FALSE);
gtk_button_do_release (button, FALSE);
}
static gboolean
key_controller_key_pressed_cb (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
guint modifiers,
GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return priv->activate_timeout != 0;
}
static void
key_controller_key_released_cb (GtkEventControllerKey *controller,
guint keyval,
guint keycode,
guint modifiers,
GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (priv->activate_timeout)
gtk_button_finish_activate (button, TRUE);
}
2016-10-20 15:58:03 +00:00
static void
gtk_button_set_child_type (GtkButton *button, guint child_type)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (priv->child_type == child_type)
return;
if (child_type == LABEL_CHILD)
gtk_widget_add_css_class (GTK_WIDGET (button), "text-button");
else
gtk_widget_remove_css_class (GTK_WIDGET (button), "text-button");
if (child_type == ICON_CHILD)
gtk_widget_add_css_class (GTK_WIDGET (button), "image-button");
else
gtk_widget_remove_css_class (GTK_WIDGET (button), "image-button");
2016-10-20 15:58:03 +00:00
if (child_type != LABEL_CHILD)
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_LABEL]);
else if (child_type != ICON_CHILD)
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_ICON_NAME]);
priv->child_type = child_type;
}
1997-11-24 22:37:52 +00:00
static void
gtk_button_init (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
GtkEventController *key_controller;
gtk_widget_set_focusable (GTK_WIDGET (button), TRUE);
gtk_widget_set_receives_default (GTK_WIDGET (button), TRUE);
1997-11-24 22:37:52 +00:00
priv->button_down = FALSE;
priv->use_underline = FALSE;
2016-10-20 15:58:03 +00:00
priv->child_type = WIDGET_CHILD;
priv->gesture = gtk_gesture_click_new ();
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->gesture), FALSE);
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->gesture), GDK_BUTTON_PRIMARY);
g_signal_connect (priv->gesture, "pressed", G_CALLBACK (click_pressed_cb), button);
g_signal_connect (priv->gesture, "released", G_CALLBACK (click_released_cb), button);
g_signal_connect (priv->gesture, "cancel", G_CALLBACK (click_gesture_cancel_cb), button);
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (priv->gesture), GTK_PHASE_CAPTURE);
gtk_widget_add_controller (GTK_WIDGET (button), GTK_EVENT_CONTROLLER (priv->gesture));
key_controller = gtk_event_controller_key_new ();
g_signal_connect (key_controller, "key-pressed", G_CALLBACK (key_controller_key_pressed_cb), button);
g_signal_connect (key_controller, "key-released", G_CALLBACK (key_controller_key_released_cb), button);
gtk_widget_add_controller (GTK_WIDGET (button), key_controller);
}
2015-12-04 02:56:25 +00:00
static void
gtk_button_dispose (GObject *object)
{
GtkButton *button = GTK_BUTTON (object);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_clear_pointer (&priv->child, gtk_widget_unparent);
2012-08-17 22:27:21 +00:00
g_clear_object (&priv->action_helper);
G_OBJECT_CLASS (gtk_button_parent_class)->dispose (object);
}
static void
gtk_button_set_action_name (GtkActionable *actionable,
2020-07-24 18:40:36 +00:00
const char *action_name)
{
GtkButton *button = GTK_BUTTON (actionable);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (!priv->action_helper)
priv->action_helper = gtk_action_helper_new (actionable);
2012-08-17 22:27:21 +00:00
g_signal_handlers_disconnect_by_func (button, gtk_real_button_clicked, NULL);
if (action_name)
g_signal_connect_after (button, "clicked", G_CALLBACK (gtk_real_button_clicked), NULL);
gtk_action_helper_set_action_name (priv->action_helper, action_name);
}
static void
gtk_button_set_action_target_value (GtkActionable *actionable,
GVariant *action_target)
{
GtkButton *button = GTK_BUTTON (actionable);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (!priv->action_helper)
priv->action_helper = gtk_action_helper_new (actionable);
gtk_action_helper_set_action_target_value (priv->action_helper, action_target);
}
1997-11-24 22:37:52 +00:00
static void
gtk_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
1997-11-24 22:37:52 +00:00
{
GtkButton *button = GTK_BUTTON (object);
1997-11-24 22:37:52 +00:00
switch (prop_id)
{
case PROP_LABEL:
gtk_button_set_label (button, g_value_get_string (value));
break;
case PROP_HAS_FRAME:
gtk_button_set_has_frame (button, g_value_get_boolean (value));
break;
case PROP_USE_UNDERLINE:
gtk_button_set_use_underline (button, g_value_get_boolean (value));
break;
case PROP_ICON_NAME:
gtk_button_set_icon_name (button, g_value_get_string (value));
break;
2020-05-02 06:45:09 +00:00
case PROP_CHILD:
gtk_button_set_child (button, g_value_get_object (value));
break;
case PROP_ACTION_NAME:
gtk_button_set_action_name (GTK_ACTIONABLE (button), g_value_get_string (value));
break;
case PROP_ACTION_TARGET:
gtk_button_set_action_target_value (GTK_ACTIONABLE (button), g_value_get_variant (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkButton *button = GTK_BUTTON (object);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
call the base class init fucntions from all parent types upon class Sun Jun 28 04:29:10 1998 Tim Janik <timj@gtk.org> * gtk/gtktypeutils.c (gtk_type_class_init): call the base class init fucntions from all parent types upon class initialization. * gtk/gtkcontainer.c: (gtk_container_get_type): announce gtk_container_base_class_init to the type system. (gtk_container_base_class_init): new function to feature base class initialization. (gtk_container_get_child_arg): (gtk_container_set_child_arg): call the GtkContainerClass get_child_arg and set_child_arg methods of the class indicated through the argument name. * gtk/gtkobject.c: (gtk_object_base_class_init): new function to feature base class initialization. (gtk_object_init_type): announce gtk_object_base_class_init to the type system. (gtk_object_class_init): setup the get_arg and set_arg pointers for GtkObjectClass. (gtk_object_setv): (gtk_object_getv): call the GtkObjectClass get_arg and set_arg methods, instead of bothering the type system with this. * gtk/gtkaccellabel.c: * gtk/gtkbutton.c: * gtk/gtkradiobutton.c: * gtk/gtktable.c: * gtk/gtktogglebutton.c: * gtk/gtktipsquery.c: * gtk/gtkbox.c: * gtk/gtkpacker.c: * gtk/gtkwidget.c: * gtk/gtkwindow.c: * gtk/gtkframe.c: * gtk/gtkmisc.c: * gtk/gtklabel.c: set the object_class->{g|s}et_arg pointers to the corresponding gtk_*_{g|s]et_arg functions and updated the gtk_*_get_type functions wrt GtkTypeInfo initialization. changed a lot of the set/get arg functions to take a GtkObject argument. gtk/gtkadjustment.c: gtk/gtkalignment.c: gtk/gtkarrow.c: gtk/gtkaspectframe.c: gtk/gtkbbox.c: gtk/gtkbin.c: gtk/gtkcheckbutton.c: gtk/gtkcheckmenuitem.c: gtk/gtkclist.c: gtk/gtkcolorsel.c: gtk/gtkcombo.c: gtk/gtkctree.c: gtk/gtkcurve.c: gtk/gtkdata.c: gtk/gtkdialog.c: gtk/gtkdrawingarea.c: gtk/gtkeditable.c: gtk/gtkentry.c: gtk/gtkeventbox.c: gtk/gtkfilesel.c: gtk/gtkfixed.c: gtk/gtkfontsel.c: gtk/gtkgamma.c: gtk/gtkhandlebox.c: gtk/gtkhbbox.c: gtk/gtkhbox.c: gtk/gtkhpaned.c: gtk/gtkhruler.c: gtk/gtkhscale.c: gtk/gtkhscrollbar.c: gtk/gtkhseparator.c: gtk/gtkimage.c: gtk/gtkinputdialog.c: gtk/gtkitem.c: gtk/gtkitemfactory.c: gtk/gtklist.c: gtk/gtklistitem.c: gtk/gtkmenu.c: gtk/gtkmenubar.c: gtk/gtkmenuitem.c: gtk/gtkmenushell.c: gtk/gtknotebook.c: gtk/gtkoptionmenu.c: gtk/gtkpaned.c: gtk/gtkpixmap.c: gtk/gtkpreview.c: gtk/gtkprogressbar.c: gtk/gtkradiomenuitem.c: gtk/gtkrange.c: gtk/gtkruler.c: gtk/gtkscale.c: gtk/gtkscrollbar.c: gtk/gtkscrolledwindow.c: gtk/gtkseparator.c: gtk/gtkspinbutton.c: gtk/gtkstatusbar.c: gtk/gtktext.c: gtk/gtktoolbar.c: gtk/gtktooltips.c: gtk/gtktree.c: gtk/gtktreeitem.c: gtk/gtkvbbox.c: gtk/gtkvbox.c: gtk/gtkviewport.c: gtk/gtkvpaned.c: gtk/gtkvruler.c: gtk/gtkvscale.c: gtk/gtkvscrollbar.c: gtk/gtkvseparator.c: updated the GtkTypeInfo initialization code to match the modified GtkTypeInfo structure.
1998-06-28 07:46:10 +00:00
switch (prop_id)
{
case PROP_LABEL:
2016-10-20 15:58:03 +00:00
g_value_set_string (value, gtk_button_get_label (button));
break;
case PROP_HAS_FRAME:
g_value_set_boolean (value, gtk_button_get_has_frame (button));
break;
case PROP_USE_UNDERLINE:
g_value_set_boolean (value, priv->use_underline);
break;
case PROP_ICON_NAME:
g_value_set_string (value, gtk_button_get_icon_name (button));
break;
2020-05-02 06:45:09 +00:00
case PROP_CHILD:
g_value_set_object (value, priv->child);
2020-05-02 06:45:09 +00:00
break;
case PROP_ACTION_NAME:
2012-08-17 22:27:21 +00:00
g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
break;
case PROP_ACTION_TARGET:
2012-08-17 22:27:21 +00:00
g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
break;
1998-01-21 23:03:11 +00:00
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1998-01-21 23:03:11 +00:00
break;
1997-11-24 22:37:52 +00:00
}
}
2020-07-24 18:40:36 +00:00
static const char *
gtk_button_get_action_name (GtkActionable *actionable)
{
GtkButton *button = GTK_BUTTON (actionable);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return gtk_action_helper_get_action_name (priv->action_helper);
}
static GVariant *
gtk_button_get_action_target_value (GtkActionable *actionable)
{
GtkButton *button = GTK_BUTTON (actionable);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return gtk_action_helper_get_action_target_value (priv->action_helper);
}
static void
gtk_button_actionable_iface_init (GtkActionableInterface *iface)
{
iface->get_action_name = gtk_button_get_action_name;
iface->set_action_name = gtk_button_set_action_name;
iface->get_action_target_value = gtk_button_get_action_target_value;
iface->set_action_target_value = gtk_button_set_action_target_value;
}
static GtkBuildableIface *parent_buildable_iface;
static void
gtk_button_buildable_add_child (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
2020-07-24 18:40:36 +00:00
const char *type)
{
if (GTK_IS_WIDGET (child))
gtk_button_set_child (GTK_BUTTON (buildable), GTK_WIDGET (child));
else
parent_buildable_iface->add_child (buildable, builder, child, type);
}
static void
gtk_button_buildable_iface_init (GtkBuildableIface *iface)
{
parent_buildable_iface = g_type_interface_peek_parent (iface);
iface->add_child = gtk_button_buildable_add_child;
}
/**
* gtk_button_new:
*
* Creates a new `GtkButton` widget.
*
* To add a child widget to the button, use [method@Gtk.Button.set_child].
*
* Returns: The newly created `GtkButton` widget.
*/
1997-11-24 22:37:52 +00:00
GtkWidget*
configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on Sun May 3 13:38:22 1998 Owen Taylor <otaylor@gtk.org> * configure.in acheader.h gdk/gdkwindow.c Check for Shape extension both on the client and server side. (And, more importantly, check for the shape extension so we may include -lXext even when compiling with --disable-xshm) Don't set override_redirect on all shaped windows. It isn't necessary. * gdk/gdkwindow.c: Set ->colormap to NULL for root and foreign windows. Use this to check if we need to get the colormap from X. Fri May 1 22:32:47 1998 Owen Taylor <otaylor@gtk.org> * gtk/gtkbutton.c (gtk_button_paint): Draw the areas between the default and the button always in GTK_STATE_NORMAL. * gtk/gtkrange.c (gtk_range_style_set): Added a style_set callback. Fri May 1 16:40:57 1998 Owen Taylor <otaylor@gtk.org> * gdk/gdkpixmap.c (gdk_pixmap_colormap_create_from_xpmp[_d]): Fix a buffer overflow on pixmaps that claim to have more than 31 characters per pixel. (gdk_pixmap_read_string): Don't wrap around strings longer than half of address space ;-) * gtk/gtk[vh]ruler.c gtk/gtkinputdialog.c: Expand some buffers that were used for printing integers. * */* (almost): Style: All int foo () { ... } changed to int foo (void) { ... } ^^^^^^^ This is why some many files changed Even where there were proper prototypes elsewhere. * gdk/gxid.c (handle_claim_device): Some extra checks. It isn't safe against being fed bad X id's, but at least it should be safe against deleting all your files.
1998-05-03 22:41:32 +00:00
gtk_button_new (void)
1997-11-24 22:37:52 +00:00
{
return g_object_new (GTK_TYPE_BUTTON, NULL);
1997-11-24 22:37:52 +00:00
}
/**
* gtk_button_new_with_label:
* @label: The text you want the `GtkLabel` to hold
*
* Creates a `GtkButton` widget with a `GtkLabel` child.
*
* Returns: The newly created `GtkButton` widget
*/
GtkWidget*
2020-07-24 18:40:36 +00:00
gtk_button_new_with_label (const char *label)
{
return g_object_new (GTK_TYPE_BUTTON, "label", label, NULL);
}
/**
* gtk_button_new_from_icon_name:
* @icon_name: (nullable): an icon name
*
* Creates a new button containing an icon from the current icon theme.
*
2014-02-07 18:32:47 +00:00
* If the icon name isnt known, a broken image icon will be
* displayed instead. If the current icon theme is changed, the icon
* will be updated appropriately.
*
* Returns: a new `GtkButton` displaying the themed icon
*/
GtkWidget*
2020-07-24 18:40:36 +00:00
gtk_button_new_from_icon_name (const char *icon_name)
{
GtkWidget *button;
button = g_object_new (GTK_TYPE_BUTTON,
"icon-name", icon_name,
NULL);
return button;
}
Renamed gtk_button_new_stock() to gtk_button_new_from_stock() and removed 2001-03-21 Alexander Larsson <alexl@redhat.com> * gtk/gtkbutton.[ch]: * gtk/gtkdialog.c: Renamed gtk_button_new_stock() to gtk_button_new_from_stock() and removed accel_group argument. Renamed gtk_button_new_accel() to gtk_button_new_with_mnemonic() and removed accel_group argument. * gtk/gtkcheckbutton.[ch]: New function gtk_check_button_new_with_mnemonic(). * gtk/gtkentry.c: Override activate_mnemonic and just grab focus. * gtk/gtkitemfactory.c: Don't add menu uline accel group, instead use mnemonics support. * gtk/gtklabel.[ch]: New support for mnemonics. * gtk/gtkmarshal.list: Needed BOOLEAN:BOOLEAN for activate_mnemonic. * gtk/gtkmenu.[c]: * gtkmenushell.c: Use mnemonics instead of accel groups for uline support in menu items. Removed gtk_menu_get_uline_accel_group() and gtk_menu_ensure_uline_accel_group(). * gtk/gtkmenuitem.c: Override activate_mnemonic to handle switching between menu items if there are collisions. * gtk/gtknotebook.c: Connect to activate_mnemonic on the tab_label, so that activating it switches to that notebook page. * gtk/gtkwidget.[ch]: Add activate_mnemonic signal. New function gtk_widget_activate_mnemonic() to emit it. Default implementation does activate/grab_focus. * gtk/gtkwindow.[ch]: Add support for mnemonics in windows. New functions: gtk_window_add_mnemonic, gtk_window_remove_mnemonic, gtk_window_activate_mnemonic, gtk_window_set_mnemonic_modifier * gtk/testgtk.c: Update to function name changes.
2001-03-21 18:58:28 +00:00
/**
* gtk_button_new_with_mnemonic:
* @label: The text of the button, with an underscore in front of the
* mnemonic character
Renamed gtk_button_new_stock() to gtk_button_new_from_stock() and removed 2001-03-21 Alexander Larsson <alexl@redhat.com> * gtk/gtkbutton.[ch]: * gtk/gtkdialog.c: Renamed gtk_button_new_stock() to gtk_button_new_from_stock() and removed accel_group argument. Renamed gtk_button_new_accel() to gtk_button_new_with_mnemonic() and removed accel_group argument. * gtk/gtkcheckbutton.[ch]: New function gtk_check_button_new_with_mnemonic(). * gtk/gtkentry.c: Override activate_mnemonic and just grab focus. * gtk/gtkitemfactory.c: Don't add menu uline accel group, instead use mnemonics support. * gtk/gtklabel.[ch]: New support for mnemonics. * gtk/gtkmarshal.list: Needed BOOLEAN:BOOLEAN for activate_mnemonic. * gtk/gtkmenu.[c]: * gtkmenushell.c: Use mnemonics instead of accel groups for uline support in menu items. Removed gtk_menu_get_uline_accel_group() and gtk_menu_ensure_uline_accel_group(). * gtk/gtkmenuitem.c: Override activate_mnemonic to handle switching between menu items if there are collisions. * gtk/gtknotebook.c: Connect to activate_mnemonic on the tab_label, so that activating it switches to that notebook page. * gtk/gtkwidget.[ch]: Add activate_mnemonic signal. New function gtk_widget_activate_mnemonic() to emit it. Default implementation does activate/grab_focus. * gtk/gtkwindow.[ch]: Add support for mnemonics in windows. New functions: gtk_window_add_mnemonic, gtk_window_remove_mnemonic, gtk_window_activate_mnemonic, gtk_window_set_mnemonic_modifier * gtk/testgtk.c: Update to function name changes.
2001-03-21 18:58:28 +00:00
*
* Creates a new `GtkButton` containing a label.
*
* If characters in @label are preceded by an underscore, they are underlined.
* If you need a literal underscore character in a label, use __ (two
* underscores). The first underlined character represents a keyboard
* accelerator called a mnemonic. Pressing Alt and that key activates the button.
*
* Returns: a new `GtkButton`
*/
Move more text widget headers into the private header list 2000-09-26 Havoc Pennington <hp@redhat.com> * gtk/Makefile.am (gtk_private_h_sources): Move more text widget headers into the private header list * Makefile.am (pkgconfig_DATA): install pkg-config files * configure.in: add pkg-config files * gdk-2.0.pc.in, gdk-pixbuf.pc.in, gtk+-2.0.pc.in: pkg-config files * gtk/gtkwindow.c (gtk_window_read_rcfiles): Invalidate outstanding icon caches on theme change. * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: New icon system. Three important types: (GtkIconSource): Specification for creating a pixbuf appropriate for a direction/state/size triplet from a source pixbuf or filename (GtkIconSet): List of GtkIconSource objects that are used to create the "same" icon (e.g. an OK button icon), and cache for rendered icons (GtkIconFactory): Hash from stock ID to GtkIconSet; used to look up the icon set for a given stock ID. GTK maintains a stack of GtkIconFactory to search, and applications or libraries can add additional icon factories on top of the stack * gtk/gtkrc.h, gtk/gtkrc.c: When loading an RcStyle, parse the set of GtkIconSource specified for a given stock ID into a GtkIconSet, and put the GtkIconSet into a GtkIconFactory for the RcStyle, under the specified stock ID. * gtk/gtkstyle.h, gtk/gtkstyle.c: Add a virtual function render_icon used to derive a GdkPixbuf from a GtkIconSource. This allows people to theme how prelight, insensitive, etc. are done. (gtk_style_lookup_icon_set): Look up a stock ID in the list of icon factories for a style, and return the resulting icon set if any. (gtk_style_render_icon): Render an icon using the render_icon method in the GtkStyleClass. * gtk/gtkwidget.h, gtk/gtkwidget.c (gtk_widget_render_icon): Use the style for a given widget to look up a stock ID, get the icon set, and render an icon using the render_icon method of the style * gtk/gtkstock.h, gtk/gtkstock.c: Header with the GtkStockItem type (contains information about a stock item), the built-in stock item IDs, and functions to add/lookup stock items. * gtk/stock-icons/*: Stock icons that come with GTK * gtk/gtkbutton.h, gtk/gtkbutton.c (gtk_button_new_stock): Returns a button based on a GtkStockItem (gtk_button_new_accel): Takes a uline string and accel group, and installs the accelerator. * gtk/gtkimage.h, gtk/gtkimage.c: Make this into a generic image-display widget.
2000-09-26 20:22:17 +00:00
GtkWidget*
2020-07-24 18:40:36 +00:00
gtk_button_new_with_mnemonic (const char *label)
Move more text widget headers into the private header list 2000-09-26 Havoc Pennington <hp@redhat.com> * gtk/Makefile.am (gtk_private_h_sources): Move more text widget headers into the private header list * Makefile.am (pkgconfig_DATA): install pkg-config files * configure.in: add pkg-config files * gdk-2.0.pc.in, gdk-pixbuf.pc.in, gtk+-2.0.pc.in: pkg-config files * gtk/gtkwindow.c (gtk_window_read_rcfiles): Invalidate outstanding icon caches on theme change. * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: New icon system. Three important types: (GtkIconSource): Specification for creating a pixbuf appropriate for a direction/state/size triplet from a source pixbuf or filename (GtkIconSet): List of GtkIconSource objects that are used to create the "same" icon (e.g. an OK button icon), and cache for rendered icons (GtkIconFactory): Hash from stock ID to GtkIconSet; used to look up the icon set for a given stock ID. GTK maintains a stack of GtkIconFactory to search, and applications or libraries can add additional icon factories on top of the stack * gtk/gtkrc.h, gtk/gtkrc.c: When loading an RcStyle, parse the set of GtkIconSource specified for a given stock ID into a GtkIconSet, and put the GtkIconSet into a GtkIconFactory for the RcStyle, under the specified stock ID. * gtk/gtkstyle.h, gtk/gtkstyle.c: Add a virtual function render_icon used to derive a GdkPixbuf from a GtkIconSource. This allows people to theme how prelight, insensitive, etc. are done. (gtk_style_lookup_icon_set): Look up a stock ID in the list of icon factories for a style, and return the resulting icon set if any. (gtk_style_render_icon): Render an icon using the render_icon method in the GtkStyleClass. * gtk/gtkwidget.h, gtk/gtkwidget.c (gtk_widget_render_icon): Use the style for a given widget to look up a stock ID, get the icon set, and render an icon using the render_icon method of the style * gtk/gtkstock.h, gtk/gtkstock.c: Header with the GtkStockItem type (contains information about a stock item), the built-in stock item IDs, and functions to add/lookup stock items. * gtk/stock-icons/*: Stock icons that come with GTK * gtk/gtkbutton.h, gtk/gtkbutton.c (gtk_button_new_stock): Returns a button based on a GtkStockItem (gtk_button_new_accel): Takes a uline string and accel group, and installs the accelerator. * gtk/gtkimage.h, gtk/gtkimage.c: Make this into a generic image-display widget.
2000-09-26 20:22:17 +00:00
{
return g_object_new (GTK_TYPE_BUTTON, "label", label, "use-underline", TRUE, NULL);
Move more text widget headers into the private header list 2000-09-26 Havoc Pennington <hp@redhat.com> * gtk/Makefile.am (gtk_private_h_sources): Move more text widget headers into the private header list * Makefile.am (pkgconfig_DATA): install pkg-config files * configure.in: add pkg-config files * gdk-2.0.pc.in, gdk-pixbuf.pc.in, gtk+-2.0.pc.in: pkg-config files * gtk/gtkwindow.c (gtk_window_read_rcfiles): Invalidate outstanding icon caches on theme change. * gtk/gtkiconfactory.h, gtk/gtkiconfactory.c: New icon system. Three important types: (GtkIconSource): Specification for creating a pixbuf appropriate for a direction/state/size triplet from a source pixbuf or filename (GtkIconSet): List of GtkIconSource objects that are used to create the "same" icon (e.g. an OK button icon), and cache for rendered icons (GtkIconFactory): Hash from stock ID to GtkIconSet; used to look up the icon set for a given stock ID. GTK maintains a stack of GtkIconFactory to search, and applications or libraries can add additional icon factories on top of the stack * gtk/gtkrc.h, gtk/gtkrc.c: When loading an RcStyle, parse the set of GtkIconSource specified for a given stock ID into a GtkIconSet, and put the GtkIconSet into a GtkIconFactory for the RcStyle, under the specified stock ID. * gtk/gtkstyle.h, gtk/gtkstyle.c: Add a virtual function render_icon used to derive a GdkPixbuf from a GtkIconSource. This allows people to theme how prelight, insensitive, etc. are done. (gtk_style_lookup_icon_set): Look up a stock ID in the list of icon factories for a style, and return the resulting icon set if any. (gtk_style_render_icon): Render an icon using the render_icon method in the GtkStyleClass. * gtk/gtkwidget.h, gtk/gtkwidget.c (gtk_widget_render_icon): Use the style for a given widget to look up a stock ID, get the icon set, and render an icon using the render_icon method of the style * gtk/gtkstock.h, gtk/gtkstock.c: Header with the GtkStockItem type (contains information about a stock item), the built-in stock item IDs, and functions to add/lookup stock items. * gtk/stock-icons/*: Stock icons that come with GTK * gtk/gtkbutton.h, gtk/gtkbutton.c (gtk_button_new_stock): Returns a button based on a GtkStockItem (gtk_button_new_accel): Takes a uline string and accel group, and installs the accelerator. * gtk/gtkimage.h, gtk/gtkimage.c: Make this into a generic image-display widget.
2000-09-26 20:22:17 +00:00
}
/**
* gtk_button_set_has_frame: (attributes org.gtk.Method.set_property=has-frame)
* @button: a `GtkButton`
* @has_frame: whether the button should have a visible frame
*
* Sets the style of the button.
*
* Buttons can has a flat appearance or have a frame drawn around them.
*/
void
gtk_button_set_has_frame (GtkButton *button,
gboolean has_frame)
{
g_return_if_fail (GTK_IS_BUTTON (button));
if (gtk_button_get_has_frame (button) == has_frame)
return;
if (has_frame)
gtk_widget_remove_css_class (GTK_WIDGET (button), "flat");
else
gtk_widget_add_css_class (GTK_WIDGET (button), "flat");
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_HAS_FRAME]);
}
/**
* gtk_button_get_has_frame: (attributes org.gtk.Method.get_property=has-frame)
* @button: a `GtkButton`
*
* Returns whether the button has a frame.
*
* Returns: %TRUE if the button has a frame
*/
gboolean
gtk_button_get_has_frame (GtkButton *button)
{
g_return_val_if_fail (GTK_IS_BUTTON (button), TRUE);
return !gtk_widget_has_css_class (GTK_WIDGET (button), "flat");
}
static void
gtk_button_unrealize (GtkWidget *widget)
{
GtkButton *button = GTK_BUTTON (widget);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (priv->activate_timeout)
gtk_button_finish_activate (button, FALSE);
2006-05-02 23:56:43 +00:00
GTK_WIDGET_CLASS (gtk_button_parent_class)->unrealize (widget);
}
static void
gtk_button_do_release (GtkButton *button,
gboolean emit_clicked)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (priv->button_down)
{
priv->button_down = FALSE;
if (priv->activate_timeout)
2020-08-15 09:54:38 +00:00
return;
if (emit_clicked)
g_signal_emit (button, button_signals[CLICKED], 0);
}
}
1997-11-24 22:37:52 +00:00
static void
gtk_real_button_clicked (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
2012-08-17 22:27:21 +00:00
if (priv->action_helper)
gtk_action_helper_activate (priv->action_helper);
}
static gboolean
button_activate_timeout (gpointer data)
{
gtk_button_finish_activate (data, TRUE);
return FALSE;
}
static void
gtk_real_button_activate (GtkButton *button)
{
GtkWidget *widget = GTK_WIDGET (button);
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
if (gtk_widget_get_realized (widget) && !priv->activate_timeout)
{
priv->activate_timeout = g_timeout_add (ACTIVATE_TIMEOUT, button_activate_timeout, button);
g_source_set_name_by_id (priv->activate_timeout, "[gtk] button_activate_timeout");
gtk_widget_add_css_class (GTK_WIDGET (button), "keyboard-activating");
priv->button_down = TRUE;
}
}
static void
gtk_button_finish_activate (GtkButton *button,
2020-08-15 09:54:38 +00:00
gboolean do_it)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
gtk_widget_remove_css_class (GTK_WIDGET (button), "keyboard-activating");
g_source_remove (priv->activate_timeout);
priv->activate_timeout = 0;
priv->button_down = FALSE;
if (do_it)
g_signal_emit (button, button_signals[CLICKED], 0);
}
/**
* gtk_button_set_label: (attributes org.gtk.Method.set_property=label)
* @button: a `GtkButton`
* @label: a string
*
* Sets the text of the label of the button to @label.
*
* This will also clear any previously set labels.
*/
void
gtk_button_set_label (GtkButton *button,
2020-07-24 18:40:36 +00:00
const char *label)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
GtkWidget *child;
g_return_if_fail (GTK_IS_BUTTON (button));
if (priv->child_type != LABEL_CHILD || priv->child == NULL)
{
2016-10-20 15:58:03 +00:00
child = gtk_label_new (NULL);
if (priv->use_underline)
{
2016-10-20 15:58:03 +00:00
gtk_label_set_use_underline (GTK_LABEL (child), priv->use_underline);
gtk_label_set_mnemonic_widget (GTK_LABEL (child), GTK_WIDGET (button));
}
if (GTK_IS_CHECK_BUTTON (button))
gtk_label_set_xalign (GTK_LABEL (child), 0.0);
gtk_button_set_child (button, child);
}
gtk_label_set_label (GTK_LABEL (priv->child), label);
2016-10-20 15:58:03 +00:00
gtk_button_set_child_type (button, LABEL_CHILD);
gtk_accessible_update_property (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_PROPERTY_LABEL, label,
-1);
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_LABEL]);
}
/**
* gtk_button_get_label: (attributes org.gtk.Method.get_property=label)
* @button: a `GtkButton`
*
* Fetches the text from the label of the button.
*
* If the label text has not been set with [method@Gtk.Button.set_label]
* the return value will be %NULL. This will be the case if you create
* an empty button with [ctor@Gtk.Button.new] to use as a container.
*
* Returns: (nullable): The text of the label widget. This string is owned
Minor documentation fixes 2002-08-10 Soren Sandmann <sandmann@daimi.au.dk> * docs/reference/gtk/tree_widget.sgml, docs/reference/gtk/tmpl/gtkdialog.sgml, docs/reference/gtk/tmpl/gtkentry.sgml, docs/reference/gtk/tmpl/gtkfilesel.sgml, docs/reference/gtk/tmpl/gtkfontsel.sgml, docs/reference/gtk/tmpl/gtkfontseldlg.sgml, docs/reference/gtk/tmpl/gtktreemodel.sgml, docs/reference/gtk/tmpl/gtkwidget.sgml, gdk/x11/gdkdisplay-x11.c, gtk/gtkbbox.c, gtk/gtkbox.c, gtk/gtkbutton.c, gtk/gtkcellrenderer.c, gtk/gtkcellrendererpixbuf.c, gtk/gtkcellrenderertext.c, gtk/gtkcheckmenuitem.c, gtk/gtkcontainer.c, gtk/gtkcurve.c, gtk/gtkdialog.h, gtk/gtkentry.c, gtk/gtkfilesel.c, gtk/gtkfontsel.c, gtk/gtkframe.c, gtk/gtkhandlebox.c, gtk/gtkiconfactory.c, gtk/gtkimage.c, gtk/gtkinvisible.c, gtk/gtkitemfactory.c, gtk/gtklabel.c, gtk/gtklayout.c, gtk/gtkmenu.c, gtk/gtkprogress.c, gtk/gtkprogressbar.c, gtk/gtkscrolledwindow.c, gtk/gtksizegroup.c, gtk/gtktable.c, gtk/gtktextiter.c, gtk/gtktexttag.c, gtk/gtktexttag.h, gtk/gtktextview.c, gtk/gtktogglebutton.c, gtk/gtktoolbar.c, gtk/gtktreemodel.c, gtk/gtktreeselection.c, gtk/gtktreestore.c, gtk/gtktreeview.c, gtk/gtktreeviewcolumn.c, gtk/gtkviewport.c, gtk/gtkwidget.c, gtk/gtkwidget.h, gtk/gtkwindow.c: Minor documentation fixes (#89254, patch from Brett Nash; #85809, patch from daten@dnetc.org; #76391, patch from Ross Burton; #74559, Manuel Clos; #73569, #72005, Alexey A. Malyshev; #70061, patch from Dennis Bj"orklund; #64566, #63388, #58328, #57499, #81007, #77349, Vitaly Tishkov; #78932, Vitaly Tishkov, patch from Ross Burton; #73306)
2002-08-10 09:55:41 +00:00
* by the widget and must not be modified or freed.
*/
2020-07-24 18:40:36 +00:00
const char *
gtk_button_get_label (GtkButton *button)
{
2016-10-20 15:58:03 +00:00
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
2016-10-20 15:58:03 +00:00
if (priv->child_type == LABEL_CHILD)
return gtk_label_get_label (GTK_LABEL (priv->child));
2016-10-20 15:58:03 +00:00
return NULL;
}
/**
* gtk_button_set_use_underline: (attributes org.gtk.Method.set_property=use-underline)
* @button: a `GtkButton`
* @use_underline: %TRUE if underlines in the text indicate mnemonics
*
* Sets whether to use underlines as mnemonics.
*
* If true, an underline in the text of the button label indicates
* the next character should be used for the mnemonic accelerator key.
*/
void
gtk_button_set_use_underline (GtkButton *button,
gboolean use_underline)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_return_if_fail (GTK_IS_BUTTON (button));
use_underline = use_underline != FALSE;
if (use_underline != priv->use_underline)
{
2016-10-20 15:58:03 +00:00
if (priv->child_type == LABEL_CHILD)
{
gtk_label_set_use_underline (GTK_LABEL (priv->child), use_underline);
gtk_label_set_mnemonic_widget (GTK_LABEL (priv->child), GTK_WIDGET (button));
}
2016-10-20 15:58:03 +00:00
priv->use_underline = use_underline;
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_USE_UNDERLINE]);
}
}
/**
* gtk_button_get_use_underline: (attributes org.gtk.Method.get_property=use-underline)
* @button: a `GtkButton`
*
* gets whether underlines are interpreted as mnemonics.
*
* See [method@Gtk.Button.set_use_underline].
*
* Returns: %TRUE if an embedded underline in the button label
* indicates the mnemonic accelerator keys.
*/
gboolean
gtk_button_get_use_underline (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_return_val_if_fail (GTK_IS_BUTTON (button), FALSE);
return priv->use_underline;
}
static void
2016-11-01 19:28:28 +00:00
gtk_button_state_flags_changed (GtkWidget *widget,
GtkStateFlags previous_state)
{
GtkButton *button = GTK_BUTTON (widget);
if (!gtk_widget_is_sensitive (widget))
gtk_button_do_release (button, FALSE);
}
/**
* gtk_button_set_icon_name: (attributes org.gtk.Method.set_property=icon-name)
* @button: A `GtkButton`
* @icon_name: An icon name
*
* Adds a `GtkImage` with the given icon name as a child.
*
* If @button already contains a child widget, that child widget will
* be removed and replaced with the image.
*/
void
gtk_button_set_icon_name (GtkButton *button,
const char *icon_name)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (icon_name != NULL);
if (priv->child_type != ICON_CHILD || priv->child == NULL)
{
GtkWidget *child = g_object_new (GTK_TYPE_IMAGE,
"accessible-role", GTK_ACCESSIBLE_ROLE_PRESENTATION,
"icon-name", icon_name,
NULL);
2020-05-02 06:45:09 +00:00
gtk_button_set_child (GTK_BUTTON (button), child);
gtk_widget_set_valign (child, GTK_ALIGN_CENTER);
2016-10-20 15:58:03 +00:00
}
else
{
gtk_image_set_from_icon_name (GTK_IMAGE (priv->child), icon_name);
2016-10-20 15:58:03 +00:00
}
gtk_accessible_update_relation (GTK_ACCESSIBLE (button),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, priv->child, NULL,
-1);
2016-10-20 15:58:03 +00:00
gtk_button_set_child_type (button, ICON_CHILD);
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_ICON_NAME]);
}
/**
* gtk_button_get_icon_name: (attributes org.gtk.Method.get_property=icon-name)
* @button: A `GtkButton`
*
* Returns the icon name of the button.
*
* If the icon name has not been set with [method@Gtk.Button.set_icon_name]
* the return value will be %NULL. This will be the case if you create
* an empty button with [ctor@Gtk.Button.new] to use as a container.
*
* Returns: (nullable): The icon name set via [method@Gtk.Button.set_icon_name]
*/
const char *
gtk_button_get_icon_name (GtkButton *button)
{
2016-10-20 15:58:03 +00:00
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
2016-10-20 15:58:03 +00:00
if (priv->child_type == ICON_CHILD)
return gtk_image_get_icon_name (GTK_IMAGE (priv->child));
2016-10-20 15:58:03 +00:00
return NULL;
}
GtkGesture *
gtk_button_get_gesture (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return priv->gesture;
}
2020-05-02 06:45:09 +00:00
GtkActionHelper *
gtk_button_get_action_helper (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
return priv->action_helper;
}
2020-05-02 06:45:09 +00:00
/**
* gtk_button_set_child: (attributes org.gtk.Method.set_property=child)
* @button: a `GtkButton`
* @child: (nullable): the child widget
2020-05-02 06:45:09 +00:00
*
* Sets the child widget of @button.
*/
void
gtk_button_set_child (GtkButton *button,
GtkWidget *child)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
2020-05-02 06:45:09 +00:00
g_return_if_fail (GTK_IS_BUTTON (button));
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
g_clear_pointer (&priv->child, gtk_widget_unparent);
priv->child = child;
if (priv->child)
gtk_widget_set_parent (priv->child, GTK_WIDGET (button));
gtk_button_set_child_type (button, WIDGET_CHILD);
2020-08-01 13:34:07 +00:00
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_CHILD]);
2020-05-02 06:45:09 +00:00
}
/**
* gtk_button_get_child: (attributes org.gtk.Method.get_property=child)
* @button: a `GtkButton`
2020-05-02 06:45:09 +00:00
*
* Gets the child widget of @button.
*
* Returns: (nullable) (transfer none): the child widget of @button
*/
GtkWidget *
gtk_button_get_child (GtkButton *button)
{
GtkButtonPrivate *priv = gtk_button_get_instance_private (button);
2020-05-02 06:45:09 +00:00
g_return_val_if_fail (GTK_IS_BUTTON (button), NULL);
return priv->child;
2020-05-02 06:45:09 +00:00
}