gtk2/gtk/gtktogglebutton.c

535 lines
15 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-2000. 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/.
*/
#include "config.h"
#include "gtktogglebutton.h"
#include "gtkaccessible.h"
#include "gtkbuttonprivate.h"
#include "gtkenums.h"
1997-11-24 22:37:52 +00:00
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
/**
* GtkToggleButton:
*
* A `GtkToggleButton` is a button which remains pressed-in when
* clicked.
*
* Clicking again will cause the toggle button to return to its normal state.
*
* A toggle button is created by calling either [ctor@Gtk.ToggleButton.new] or
* [ctor@Gtk.ToggleButton.new_with_label]. If using the former, it is advisable
* to pack a widget, (such as a `GtkLabel` and/or a `GtkImage`), into the toggle
* buttons container. (See [class@Gtk.Button] for more information).
*
* The state of a `GtkToggleButton` can be set specifically using
* [method@Gtk.ToggleButton.set_active], and retrieved using
* [method@Gtk.ToggleButton.get_active].
*
* To simply switch the state of a toggle button, use
* [method@Gtk.ToggleButton.toggled].
*
* ## Grouping
*
* Toggle buttons can be grouped together, to form mutually exclusive
* groups - only one of the buttons can be toggled at a time, and toggling
* another one will switch the currently toggled one off.
*
* To add a `GtkToggleButton` to a group, use [method@Gtk.ToggleButton.set_group].
*
* ## CSS nodes
*
* `GtkToggleButton` has a single CSS node with name button. To differentiate
* it from a plain `GtkButton`, it gets the `.toggle` style class.
*
* ## Creating two `GtkToggleButton` widgets.
*
* ```c
* static void
* output_state (GtkToggleButton *source,
* gpointer user_data)
* {
* g_print ("Toggle button "%s" is active: %s",
* gtk_button_get_label (GTK_BUTTON (source)),
* gtk_toggle_button_get_active (source) ? "Yes" : "No");
* }
*
* static void
* make_toggles (void)
* {
* GtkWidget *window, *toggle1, *toggle2;
* GtkWidget *box;
* const char *text;
*
* window = gtk_window_new ();
* box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
*
* text = "Hi, Im toggle button one";
* toggle1 = gtk_toggle_button_new_with_label (text);
*
* g_signal_connect (toggle1, "toggled",
* G_CALLBACK (output_state),
* NULL);
* gtk_box_append (GTK_BOX (box), toggle1);
*
* text = "Hi, Im toggle button two";
* toggle2 = gtk_toggle_button_new_with_label (text);
* g_signal_connect (toggle2, "toggled",
* G_CALLBACK (output_state),
* NULL);
* gtk_box_append (GTK_BOX (box), toggle2);
*
* gtk_window_set_child (GTK_WINDOW (window), box);
* gtk_window_present (GTK_WINDOW (window));
* }
* ```
*/
2018-03-29 18:20:35 +00:00
typedef struct _GtkToggleButtonPrivate GtkToggleButtonPrivate;
struct _GtkToggleButtonPrivate
{
GtkToggleButton *group_next;
GtkToggleButton *group_prev;
guint active : 1;
};
1997-11-24 22:37:52 +00:00
enum {
TOGGLED,
LAST_SIGNAL
};
new function gtk_container_child_arg_set, similar to Wed Jun 24 14:14:32 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.c: new function gtk_container_child_arg_set, similar to gtk_container_child_arg_setv, but takes a variable argument list. new function gtk_container_get_child_arg_type, which is needed by gtk_object_collect_args. * gtk/gtkobject.c: changed prototype for gtk_object_collect_args, to take a function pointer to figure the argument type. adapted callers to pass gtk_object_get_arg_type. * gtk/gtkwidget.c: adapted gtk_object_collect_args callers to pass gtk_object_get_arg_type.. * gtk/gtkpacker.h: * gtk/gtkpacker.c: (gtk_packer_reorder_child): new function to change the packing order of a child. (gtk_packer_size_request): (gtk_packer_size_allocate): take container->border_width into acount. * gtk/gtkpacker.c: implemented widget arguments: "GtkPacker::spacing", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y". implemented child arguments: "GtkPacker::side", "GtkPacker::anchor", "GtkPacker::expand", "GtkPacker::fill_x", "GtkPacker::fill_y", "GtkPacker::use_default", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y", "GtkPacker::position". * gtk/gtkmisc.c (gtk_misc_set_arg): for padding args, set the padding, not the alignment. * gtk/gtkeventbox.h: * gtk/gtkeventbox.c: GtkType and macro fixups. * gtk/testgtk.c (entry_toggle_sensitive): new function to toggle sensitivity of an entry. * gtk/gtkstyle.c (gtk_style_new): support normal grey as default color for insensitive base. * gtk/gtkentry.c (gtk_entry_realize): set the window backgrounds widget state dependent. (gtk_entry_style_set): likewise. (gtk_entry_state_changed): set background color on state changes. (gtk_entry_draw_text): for non selected text, use state dependent colors. * gtk/gtktogglebutton.c: support for widget arguments "GtkToggleButton::active" and "GtkToggleButton::draw_indicator".
1998-06-24 12:22:23 +00:00
enum {
PROP_0,
PROP_ACTIVE,
PROP_GROUP,
NUM_PROPERTIES
new function gtk_container_child_arg_set, similar to Wed Jun 24 14:14:32 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.c: new function gtk_container_child_arg_set, similar to gtk_container_child_arg_setv, but takes a variable argument list. new function gtk_container_get_child_arg_type, which is needed by gtk_object_collect_args. * gtk/gtkobject.c: changed prototype for gtk_object_collect_args, to take a function pointer to figure the argument type. adapted callers to pass gtk_object_get_arg_type. * gtk/gtkwidget.c: adapted gtk_object_collect_args callers to pass gtk_object_get_arg_type.. * gtk/gtkpacker.h: * gtk/gtkpacker.c: (gtk_packer_reorder_child): new function to change the packing order of a child. (gtk_packer_size_request): (gtk_packer_size_allocate): take container->border_width into acount. * gtk/gtkpacker.c: implemented widget arguments: "GtkPacker::spacing", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y". implemented child arguments: "GtkPacker::side", "GtkPacker::anchor", "GtkPacker::expand", "GtkPacker::fill_x", "GtkPacker::fill_y", "GtkPacker::use_default", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y", "GtkPacker::position". * gtk/gtkmisc.c (gtk_misc_set_arg): for padding args, set the padding, not the alignment. * gtk/gtkeventbox.h: * gtk/gtkeventbox.c: GtkType and macro fixups. * gtk/testgtk.c (entry_toggle_sensitive): new function to toggle sensitivity of an entry. * gtk/gtkstyle.c (gtk_style_new): support normal grey as default color for insensitive base. * gtk/gtkentry.c (gtk_entry_realize): set the window backgrounds widget state dependent. (gtk_entry_style_set): likewise. (gtk_entry_state_changed): set background color on state changes. (gtk_entry_draw_text): for non selected text, use state dependent colors. * gtk/gtktogglebutton.c: support for widget arguments "GtkToggleButton::active" and "GtkToggleButton::draw_indicator".
1998-06-24 12:22:23 +00:00
};
static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, };
1997-11-24 22:37:52 +00:00
G_DEFINE_TYPE_WITH_CODE (GtkToggleButton, gtk_toggle_button, GTK_TYPE_BUTTON,
G_ADD_PRIVATE (GtkToggleButton))
1997-11-24 22:37:52 +00:00
static void
gtk_toggle_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
1997-11-24 22:37:52 +00:00
switch (prop_id)
{
case PROP_ACTIVE:
gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
break;
case PROP_GROUP:
gtk_toggle_button_set_group (GTK_TOGGLE_BUTTON (object), g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
gtk_toggle_button_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GtkToggleButton *tb = GTK_TOGGLE_BUTTON (object);
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (tb);
switch (prop_id)
{
case PROP_ACTIVE:
g_value_set_boolean (value, priv->active);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static gboolean
gtk_toggle_button_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling)
{
/*
* We override the standard implementation in
* gtk_widget_real_mnemonic_activate() in order to focus the widget even
* if there is no mnemonic conflict.
*/
if (gtk_widget_get_focusable (widget))
gtk_widget_grab_focus (widget);
if (!group_cycling)
gtk_widget_activate (widget);
return TRUE;
}
1997-11-24 22:37:52 +00:00
static void
gtk_toggle_button_clicked (GtkButton *button)
1997-11-24 22:37:52 +00:00
{
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
1997-11-24 22:37:52 +00:00
if (priv->active && (priv->group_prev || priv->group_next))
return;
if (gtk_button_get_action_helper (button))
return;
gtk_toggle_button_set_active (toggle_button, !priv->active);
}
static void
gtk_toggle_button_dispose (GObject *object)
{
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (object);
gtk_toggle_button_set_group (toggle_button, NULL);
G_OBJECT_CLASS (gtk_toggle_button_parent_class)->dispose (object);
}
static GtkToggleButton *
get_group_next (GtkToggleButton *self)
{
return ((GtkToggleButtonPrivate *)gtk_toggle_button_get_instance_private (self))->group_next;
}
static GtkToggleButton *
get_group_prev (GtkToggleButton *self)
{
return ((GtkToggleButtonPrivate *)gtk_toggle_button_get_instance_private (self))->group_prev;
}
static GtkToggleButton *
get_group_first (GtkToggleButton *self)
{
GtkToggleButton *group_first = NULL;
GtkToggleButton *iter;
/* Find first in group */
iter = self;
while (iter)
{
group_first = iter;
iter = get_group_prev (iter);
if (!iter)
break;
}
g_assert (group_first);
return group_first;
}
static void
gtk_toggle_button_class_init (GtkToggleButtonClass *class)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (class);
1997-11-24 22:37:52 +00:00
gobject_class->dispose = gtk_toggle_button_dispose;
gobject_class->set_property = gtk_toggle_button_set_property;
gobject_class->get_property = gtk_toggle_button_get_property;
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
widget_class->mnemonic_activate = gtk_toggle_button_mnemonic_activate;
1997-11-24 22:37:52 +00:00
button_class->clicked = gtk_toggle_button_clicked;
class->toggled = NULL;
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
/**
* GtkToggleButton:active: (attributes org.gtk.Property.get=gtk_toggle_button_get_active org.gtk.Property.set=gtk_toggle_button_set_active)
*
* If the toggle button should be pressed in.
*/
toggle_button_props[PROP_ACTIVE] =
g_param_spec_boolean ("active", NULL, NULL,
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkToggleButton:group: (attributes org.gtk.Property.set=gtk_toggle_button_set_group)
*
* The toggle button whose group this widget belongs to.
*/
toggle_button_props[PROP_GROUP] =
g_param_spec_object ("group", NULL, NULL,
GTK_TYPE_TOGGLE_BUTTON,
GTK_PARAM_WRITABLE);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, toggle_button_props);
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
/**
* GtkToggleButton::toggled:
* @togglebutton: the object which received the signal.
*
* Emitted whenever the `GtkToggleButton`'s state is changed.
*/
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
toggle_button_signals[TOGGLED] =
g_signal_new (I_("toggled"),
G_OBJECT_CLASS_TYPE (gobject_class),
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (GtkToggleButtonClass, toggled),
NULL, NULL,
NULL,
G_TYPE_NONE, 0);
gtk_widget_class_set_css_name (widget_class, I_("button"));
1997-11-24 22:37:52 +00:00
}
static void
gtk_toggle_button_init (GtkToggleButton *toggle_button)
{
2018-03-29 18:20:35 +00:00
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
2018-03-29 18:20:35 +00:00
priv->active = FALSE;
gtk_widget_add_css_class (GTK_WIDGET (toggle_button), "toggle");
1997-11-24 22:37:52 +00:00
}
/**
* gtk_toggle_button_new:
*
* Creates a new toggle button.
*
* A widget should be packed into the button, as in [ctor@Gtk.Button.new].
*
* Returns: a new toggle button.
*/
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_toggle_button_new (void)
1997-11-24 22:37:52 +00:00
{
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
1997-11-24 22:37:52 +00:00
}
/**
* gtk_toggle_button_new_with_label:
* @label: a string containing the message to be placed in the toggle button.
*
* Creates a new toggle button with a text label.
*
* Returns: a new toggle button.
*/
GtkWidget *
2020-07-24 18:40:36 +00:00
gtk_toggle_button_new_with_label (const char *label)
1997-11-24 22:37:52 +00:00
{
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
1997-11-24 22:37:52 +00:00
}
/**
* gtk_toggle_button_new_with_mnemonic:
* @label: the text of the button, with an underscore in front of the
* mnemonic character
*
* Creates a new `GtkToggleButton` containing a label.
*
* The label will be created using [ctor@Gtk.Label.new_with_mnemonic],
* so underscores in @label indicate the mnemonic for the button.
*
* Returns: a new `GtkToggleButton`
*/
GtkWidget *
2020-07-24 18:40:36 +00:00
gtk_toggle_button_new_with_mnemonic (const char *label)
{
return g_object_new (GTK_TYPE_TOGGLE_BUTTON,
"label", label,
"use-underline", TRUE,
NULL);
new function gtk_container_child_arg_set, similar to Wed Jun 24 14:14:32 1998 Tim Janik <timj@gtk.org> * gtk/gtkcontainer.c: new function gtk_container_child_arg_set, similar to gtk_container_child_arg_setv, but takes a variable argument list. new function gtk_container_get_child_arg_type, which is needed by gtk_object_collect_args. * gtk/gtkobject.c: changed prototype for gtk_object_collect_args, to take a function pointer to figure the argument type. adapted callers to pass gtk_object_get_arg_type. * gtk/gtkwidget.c: adapted gtk_object_collect_args callers to pass gtk_object_get_arg_type.. * gtk/gtkpacker.h: * gtk/gtkpacker.c: (gtk_packer_reorder_child): new function to change the packing order of a child. (gtk_packer_size_request): (gtk_packer_size_allocate): take container->border_width into acount. * gtk/gtkpacker.c: implemented widget arguments: "GtkPacker::spacing", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y". implemented child arguments: "GtkPacker::side", "GtkPacker::anchor", "GtkPacker::expand", "GtkPacker::fill_x", "GtkPacker::fill_y", "GtkPacker::use_default", "GtkPacker::border_width", "GtkPacker::pad_x", "GtkPacker::pad_y", "GtkPacker::ipad_x", "GtkPacker::ipad_y", "GtkPacker::position". * gtk/gtkmisc.c (gtk_misc_set_arg): for padding args, set the padding, not the alignment. * gtk/gtkeventbox.h: * gtk/gtkeventbox.c: GtkType and macro fixups. * gtk/testgtk.c (entry_toggle_sensitive): new function to toggle sensitivity of an entry. * gtk/gtkstyle.c (gtk_style_new): support normal grey as default color for insensitive base. * gtk/gtkentry.c (gtk_entry_realize): set the window backgrounds widget state dependent. (gtk_entry_style_set): likewise. (gtk_entry_state_changed): set background color on state changes. (gtk_entry_draw_text): for non selected text, use state dependent colors. * gtk/gtktogglebutton.c: support for widget arguments "GtkToggleButton::active" and "GtkToggleButton::draw_indicator".
1998-06-24 12:22:23 +00:00
}
/**
* gtk_toggle_button_set_active: (attributes org.gtk.Method.set_property=active)
* @toggle_button: a `GtkToggleButton`.
* @is_active: %TRUE or %FALSE.
*
* Sets the status of the toggle button.
*
* Set to %TRUE if you want the `GtkToggleButton` to be pressed in,
* and %FALSE to raise it.
*
* If the status of the button changes, this action causes the
* [signal@GtkToggleButton::toggled] signal to be emitted.
*/
1997-11-24 22:37:52 +00:00
void
gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
gboolean is_active)
1997-11-24 22:37:52 +00:00
{
2018-03-29 18:20:35 +00:00
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
1997-11-24 22:37:52 +00:00
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
is_active = is_active != FALSE;
if (priv->active == is_active)
return;
2018-03-29 18:20:35 +00:00
if (is_active && (priv->group_prev || priv->group_next))
{
GtkToggleButton *group_first = NULL;
GtkToggleButton *iter;
group_first = get_group_first (toggle_button);
g_assert (group_first);
/* Set all buttons in group to !active */
for (iter = group_first; iter; iter = get_group_next (iter))
gtk_toggle_button_set_active (iter, FALSE);
/* ... and the next code block will set this one to active */
}
2018-03-29 18:20:35 +00:00
priv->active = is_active;
if (is_active)
gtk_widget_set_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_CHECKED, FALSE);
else
gtk_widget_unset_state_flags (GTK_WIDGET (toggle_button), GTK_STATE_FLAG_CHECKED);
gtk_accessible_update_state (GTK_ACCESSIBLE (toggle_button),
GTK_ACCESSIBLE_STATE_PRESSED, is_active,
-1);
g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
}
/**
* gtk_toggle_button_get_active: (attributes org.gtk.Method.get_property=active)
* @toggle_button: a `GtkToggleButton`.
*
* Queries a `GtkToggleButton` and returns its current state.
*
* Returns %TRUE if the toggle button is pressed in and %FALSE
* if it is raised.
*
* Returns: whether the button is pressed
*/
gboolean
gtk_toggle_button_get_active (GtkToggleButton *toggle_button)
{
2018-03-29 18:20:35 +00:00
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
2018-03-29 18:20:35 +00:00
return priv->active;
}
/**
* gtk_toggle_button_toggled:
* @toggle_button: a `GtkToggleButton`.
*
* Emits the ::toggled signal on the `GtkToggleButton`.
*
* Deprecated: 4.10: There is no good reason for an application ever to call this function.
*/
1997-11-24 22:37:52 +00:00
void
gtk_toggle_button_toggled (GtkToggleButton *toggle_button)
{
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
1997-11-24 22:37:52 +00:00
}
/**
* gtk_toggle_button_set_group: (attributes org.gtk.Method.set_property=group)
* @toggle_button: a `GtkToggleButton`
* @group: (nullable) (transfer none): another `GtkToggleButton` to
* form a group with
*
* Adds @self to the group of @group.
*
* In a group of multiple toggle buttons, only one button can be active
* at a time.
*
* Setting up groups in a cycle leads to undefined behavior.
*
* Note that the same effect can be achieved via the [iface@Gtk.Actionable]
* API, by using the same action with parameter type and state type 's'
* for all buttons in the group, and giving each button its own target
* value.
*/
void
gtk_toggle_button_set_group (GtkToggleButton *toggle_button,
GtkToggleButton *group)
{
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
GtkToggleButtonPrivate *group_priv = gtk_toggle_button_get_instance_private (group);
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
g_return_if_fail (toggle_button != group);
if (!group)
{
if (priv->group_prev)
{
GtkToggleButtonPrivate *p = gtk_toggle_button_get_instance_private (priv->group_prev);
p->group_next = priv->group_next;
}
if (priv->group_next)
{
GtkToggleButtonPrivate *p = gtk_toggle_button_get_instance_private (priv->group_next);
p->group_prev = priv->group_prev;
}
priv->group_next = NULL;
priv->group_prev = NULL;
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_GROUP]);
return;
}
if (priv->group_next == group)
return;
priv->group_prev = NULL;
if (group_priv->group_prev)
{
GtkToggleButtonPrivate *prev = gtk_toggle_button_get_instance_private (group_priv->group_prev);
prev->group_next = toggle_button;
priv->group_prev = group_priv->group_prev;
}
group_priv->group_prev = toggle_button;
priv->group_next = group;
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_GROUP]);
}