2008-07-01 22:57:50 +00:00
|
|
|
|
/* 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
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* 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
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Lesser General Public License for more details.
|
1997-11-24 22:37:52 +00:00
|
|
|
|
*
|
2000-07-26 11:33:08 +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
|
|
|
|
*/
|
1999-02-24 07:37:18 +00:00
|
|
|
|
|
|
|
|
|
/*
|
2000-07-26 11:33:08 +00:00
|
|
|
|
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
1999-02-24 07:37:18 +00:00
|
|
|
|
* 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/.
|
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2010-10-19 00:01:31 +00:00
|
|
|
|
|
2019-10-26 05:00:24 +00:00
|
|
|
|
#include "gtktogglebutton.h"
|
2010-10-19 00:01:31 +00:00
|
|
|
|
|
2020-07-13 15:10:36 +00:00
|
|
|
|
#include "gtkaccessible.h"
|
2010-10-19 00:01:31 +00:00
|
|
|
|
#include "gtkbuttonprivate.h"
|
2020-07-13 15:10:36 +00:00
|
|
|
|
#include "gtkenums.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
#include "gtkintl.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtkmain.h"
|
2001-11-17 23:28:51 +00:00
|
|
|
|
#include "gtkmarshalers.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2019-03-16 03:48:26 +00:00
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtktogglebutton
|
|
|
|
|
* @Short_description: Create buttons which retain their state
|
|
|
|
|
* @Title: GtkToggleButton
|
2020-08-05 01:17:49 +00:00
|
|
|
|
* @See_also: #GtkButton, #GtkCheckButton
|
2011-04-17 23:24:56 +00:00
|
|
|
|
*
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* A #GtkToggleButton is a #GtkButton which will remain “pressed-in” when
|
2011-04-17 23:24:56 +00:00
|
|
|
|
* clicked. Clicking again will cause the toggle button to return to its
|
|
|
|
|
* normal state.
|
|
|
|
|
*
|
|
|
|
|
* A toggle button is created by calling either gtk_toggle_button_new() or
|
|
|
|
|
* gtk_toggle_button_new_with_label(). If using the former, it is advisable to
|
2012-07-02 06:19:06 +00:00
|
|
|
|
* pack a widget, (such as a #GtkLabel and/or a #GtkImage), into the toggle
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* button’s container. (See #GtkButton for more information).
|
2011-04-17 23:24:56 +00:00
|
|
|
|
*
|
|
|
|
|
* The state of a #GtkToggleButton can be set specifically using
|
|
|
|
|
* gtk_toggle_button_set_active(), and retrieved using
|
|
|
|
|
* gtk_toggle_button_get_active().
|
|
|
|
|
*
|
|
|
|
|
* To simply switch the state of a toggle button, use gtk_toggle_button_toggled().
|
|
|
|
|
*
|
2015-10-30 04:27:13 +00:00
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* GtkToggleButton has a single CSS node with name button. To differentiate
|
|
|
|
|
* it from a plain #GtkButton, it gets the .toggle style class.
|
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
|
* ## Creating two #GtkToggleButton widgets.
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2017-10-11 10:35:55 +00:00
|
|
|
|
* static void output_state (GtkToggleButton *source, gpointer user_data) {
|
|
|
|
|
* printf ("Active: %d\n", gtk_toggle_button_get_active (source));
|
|
|
|
|
* }
|
|
|
|
|
*
|
2011-04-17 23:24:56 +00:00
|
|
|
|
* void make_toggles (void) {
|
2017-10-11 20:12:33 +00:00
|
|
|
|
* GtkWidget *window, *toggle1, *toggle2;
|
|
|
|
|
* GtkWidget *box;
|
|
|
|
|
* const char *text;
|
|
|
|
|
*
|
2020-02-14 19:55:36 +00:00
|
|
|
|
* window = gtk_window_new ();
|
2017-10-11 20:12:33 +00:00
|
|
|
|
* box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
|
|
|
|
|
*
|
|
|
|
|
* text = "Hi, I’m a toggle button.";
|
|
|
|
|
* toggle1 = gtk_toggle_button_new_with_label (text);
|
|
|
|
|
*
|
|
|
|
|
* g_signal_connect (toggle1, "toggled",
|
|
|
|
|
* G_CALLBACK (output_state),
|
|
|
|
|
* NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
* gtk_box_append (GTK_BOX (box), toggle1);
|
2017-10-11 20:12:33 +00:00
|
|
|
|
*
|
|
|
|
|
* text = "Hi, I’m a toggle button.";
|
|
|
|
|
* toggle2 = gtk_toggle_button_new_with_label (text);
|
|
|
|
|
* g_signal_connect (toggle2, "toggled",
|
|
|
|
|
* G_CALLBACK (output_state),
|
|
|
|
|
* NULL);
|
2020-05-09 12:26:52 +00:00
|
|
|
|
* gtk_box_append (GTK_BOX (box), toggle2);
|
2017-10-11 20:12:33 +00:00
|
|
|
|
*
|
2020-05-02 21:26:54 +00:00
|
|
|
|
* gtk_window_set_child (GTK_WINDOW (window), box);
|
2017-10-11 20:12:33 +00:00
|
|
|
|
* gtk_widget_show (window);
|
2011-04-17 23:24:56 +00:00
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2018-03-29 18:20:35 +00:00
|
|
|
|
typedef struct _GtkToggleButtonPrivate GtkToggleButtonPrivate;
|
2010-10-19 16:18:02 +00:00
|
|
|
|
struct _GtkToggleButtonPrivate
|
|
|
|
|
{
|
2020-08-31 01:48:00 +00:00
|
|
|
|
GtkToggleButton *group_next;
|
|
|
|
|
GtkToggleButton *group_prev;
|
|
|
|
|
|
2010-10-19 16:18:02 +00:00
|
|
|
|
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 {
|
2001-05-13 22:41:30 +00:00
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_ACTIVE,
|
2020-08-31 01:48:00 +00:00
|
|
|
|
PROP_GROUP,
|
2015-09-06 14:45:33 +00:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
2020-08-01 17:24:54 +00:00
|
|
|
|
static guint toggle_button_signals[LAST_SIGNAL] = { 0 };
|
2015-09-06 14:45:33 +00:00
|
|
|
|
static GParamSpec *toggle_button_props[NUM_PROPERTIES] = { NULL, };
|
1997-11-24 22:37:52 +00:00
|
|
|
|
|
2020-08-01 17:24:54 +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
|
|
|
|
|
2020-08-01 17:24:54 +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
|
|
|
|
|
2020-08-01 17:24:54 +00:00
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_ACTIVE:
|
|
|
|
|
gtk_toggle_button_set_active (tb, g_value_get_boolean (value));
|
|
|
|
|
break;
|
2020-08-31 01:48:00 +00:00
|
|
|
|
case PROP_GROUP:
|
|
|
|
|
gtk_toggle_button_set_group (GTK_TOGGLE_BUTTON (object), g_value_get_object (value));
|
|
|
|
|
break;
|
2020-08-01 17:24:54 +00:00
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2020-08-01 17:24:54 +00:00
|
|
|
|
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_can_focus (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
|
2020-08-01 17:24:54 +00:00
|
|
|
|
gtk_toggle_button_clicked (GtkButton *button)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2020-08-01 17:24:54 +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
|
|
|
|
|
2020-08-01 17:24:54 +00:00
|
|
|
|
gtk_toggle_button_set_active (toggle_button, !priv->active);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 01:48:00 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-01 17:24:54 +00:00
|
|
|
|
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
|
|
|
|
|
2020-08-31 01:48:00 +00:00
|
|
|
|
gobject_class->dispose = gtk_toggle_button_dispose;
|
2001-05-13 22:41:30 +00:00
|
|
|
|
gobject_class->set_property = gtk_toggle_button_set_property;
|
|
|
|
|
gobject_class->get_property = gtk_toggle_button_get_property;
|
1998-06-28 07:46:10 +00:00
|
|
|
|
|
2002-07-25 16:12:46 +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
|
|
|
|
|
2015-09-06 14:45:33 +00:00
|
|
|
|
toggle_button_props[PROP_ACTIVE] =
|
|
|
|
|
g_param_spec_boolean ("active",
|
|
|
|
|
P_("Active"),
|
|
|
|
|
P_("If the toggle button should be pressed in"),
|
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
|
2020-08-31 01:48:00 +00:00
|
|
|
|
toggle_button_props[PROP_GROUP] =
|
|
|
|
|
g_param_spec_object ("group",
|
|
|
|
|
P_("Group"),
|
|
|
|
|
P_("The toggle button whose group this widget belongs to."),
|
|
|
|
|
GTK_TYPE_TOGGLE_BUTTON,
|
|
|
|
|
GTK_PARAM_WRITABLE);
|
|
|
|
|
|
2015-09-06 14:45:33 +00:00
|
|
|
|
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
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkToggleButton::toggled:
|
|
|
|
|
* @togglebutton: the object which received the signal.
|
|
|
|
|
*
|
|
|
|
|
* Should be connected if you wish to perform an action 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] =
|
2005-09-01 05:11:46 +00:00
|
|
|
|
g_signal_new (I_("toggled"),
|
2020-08-01 17:24:54 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (gobject_class),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkToggleButtonClass, toggled),
|
|
|
|
|
NULL, NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
G_TYPE_NONE, 0);
|
2010-10-19 16:18:02 +00:00
|
|
|
|
|
2017-11-18 03:49:57 +00:00
|
|
|
|
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);
|
2015-10-30 03:04:47 +00:00
|
|
|
|
|
2018-03-29 18:20:35 +00:00
|
|
|
|
priv->active = FALSE;
|
2015-10-30 03:04:47 +00:00
|
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (toggle_button), "toggle");
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_button_new:
|
|
|
|
|
*
|
|
|
|
|
* Creates a new toggle button. A widget should be packed into the button, as in gtk_button_new().
|
|
|
|
|
*
|
|
|
|
|
* Returns: a new toggle button.
|
|
|
|
|
*/
|
2020-08-01 17:24:54 +00:00
|
|
|
|
GtkWidget *
|
1998-05-03 22:41:32 +00:00
|
|
|
|
gtk_toggle_button_new (void)
|
1997-11-24 22:37:52 +00:00
|
|
|
|
{
|
2002-10-11 22:57:11 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 23:24:56 +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.
|
|
|
|
|
*/
|
2020-08-01 17:24:54 +00:00
|
|
|
|
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
|
|
|
|
{
|
2001-08-27 01:05:07 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_TOGGLE_BUTTON, "label", label, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2001-06-05 18:22:30 +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 gtk_label_new_with_mnemonic(), so underscores
|
|
|
|
|
* in @label indicate the mnemonic for the button.
|
2011-09-26 00:58:59 +00:00
|
|
|
|
*
|
|
|
|
|
* Returns: a new #GtkToggleButton
|
|
|
|
|
*/
|
2020-08-01 17:24:54 +00:00
|
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
|
gtk_toggle_button_new_with_mnemonic (const char *label)
|
2001-06-05 18:22:30 +00:00
|
|
|
|
{
|
2020-08-01 17:24:54 +00:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_button_set_active:
|
|
|
|
|
* @toggle_button: a #GtkToggleButton.
|
|
|
|
|
* @is_active: %TRUE or %FALSE.
|
|
|
|
|
*
|
|
|
|
|
* Sets the status of the toggle button. Set to %TRUE if you want the
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* GtkToggleButton to be “pressed in”, and %FALSE to raise it.
|
2019-10-26 05:00:24 +00:00
|
|
|
|
*
|
|
|
|
|
* If the status of the button changes, this action causes the
|
|
|
|
|
* #GtkToggleButton::toggled signal to be emitted.
|
2011-04-17 23:24:56 +00:00
|
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
|
void
|
1999-01-11 18:49:54 +00:00
|
|
|
|
gtk_toggle_button_set_active (GtkToggleButton *toggle_button,
|
2020-08-01 17:24:54 +00:00
|
|
|
|
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);
|
2010-10-19 16:18:02 +00:00
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
|
|
|
|
|
|
2001-05-13 22:41:30 +00:00
|
|
|
|
is_active = is_active != FALSE;
|
1999-01-11 18:49:54 +00:00
|
|
|
|
|
2019-10-26 05:00:24 +00:00
|
|
|
|
if (priv->active == is_active)
|
|
|
|
|
return;
|
2018-03-29 18:20:35 +00:00
|
|
|
|
|
2020-08-31 01:48:00 +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;
|
2014-08-15 14:58:39 +00:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
2020-07-13 15:10:36 +00:00
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (toggle_button),
|
|
|
|
|
GTK_ACCESSIBLE_STATE_PRESSED, is_active,
|
|
|
|
|
-1);
|
|
|
|
|
|
2019-10-26 05:00:24 +00:00
|
|
|
|
gtk_toggle_button_toggled (toggle_button);
|
|
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_ACTIVE]);
|
2010-10-19 16:21:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_button_get_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: a #gboolean value.
|
|
|
|
|
*/
|
1999-01-21 00:37:48 +00:00
|
|
|
|
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);
|
|
|
|
|
|
1999-01-21 00:37:48 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE);
|
|
|
|
|
|
2018-03-29 18:20:35 +00:00
|
|
|
|
return priv->active;
|
1999-01-21 00:37:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-17 23:24:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_button_toggled:
|
|
|
|
|
* @toggle_button: a #GtkToggleButton.
|
|
|
|
|
*
|
|
|
|
|
* Emits the #GtkToggleButton::toggled signal on the
|
|
|
|
|
* #GtkToggleButton. 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)
|
|
|
|
|
{
|
1999-01-11 18:49:54 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
|
|
|
|
|
|
2002-10-11 22:57:11 +00:00
|
|
|
|
g_signal_emit (toggle_button, toggle_button_signals[TOGGLED], 0);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
}
|
2020-08-31 01:48:00 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_button_set_group:
|
2020-09-04 11:05:01 +00:00
|
|
|
|
* @toggle_button: a #GtkToggleButton
|
2020-08-31 01:48:00 +00:00
|
|
|
|
* @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.
|
2020-09-01 19:31:24 +00:00
|
|
|
|
*
|
|
|
|
|
* Note that the same effect can be achieved via the #GtkActionable
|
|
|
|
|
* 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.
|
|
|
|
|
|
2020-08-31 01:48:00 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
2020-09-04 11:05:01 +00:00
|
|
|
|
gtk_toggle_button_set_group (GtkToggleButton *toggle_button,
|
2020-08-31 01:48:00 +00:00
|
|
|
|
GtkToggleButton *group)
|
|
|
|
|
{
|
2020-09-04 11:05:01 +00:00
|
|
|
|
GtkToggleButtonPrivate *priv = gtk_toggle_button_get_instance_private (toggle_button);
|
2020-08-31 01:48:00 +00:00
|
|
|
|
GtkToggleButtonPrivate *group_priv = gtk_toggle_button_get_instance_private (group);
|
|
|
|
|
|
2020-09-04 11:05:01 +00:00
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button));
|
2020-08-31 01:48:00 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2020-09-04 11:05:01 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_GROUP]);
|
2020-08-31 01:48:00 +00:00
|
|
|
|
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);
|
|
|
|
|
|
2020-09-04 11:05:01 +00:00
|
|
|
|
prev->group_next = toggle_button;
|
2020-08-31 01:48:00 +00:00
|
|
|
|
priv->group_prev = group_priv->group_prev;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-04 11:05:01 +00:00
|
|
|
|
group_priv->group_prev = toggle_button;
|
2020-08-31 01:48:00 +00:00
|
|
|
|
priv->group_next = group;
|
|
|
|
|
|
2020-09-04 11:05:01 +00:00
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (toggle_button), toggle_button_props[PROP_GROUP]);
|
2020-08-31 01:48:00 +00:00
|
|
|
|
}
|