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
|
2020-08-07 03:45:30 +00:00
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
1999-02-24 07:37:18 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2010-09-09 13:35:58 +00:00
|
|
|
|
2020-08-30 21:55:13 +00:00
|
|
|
#include "gtkcheckbutton.h"
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
#include "gtkactionhelperprivate.h"
|
|
|
|
#include "gtkboxlayout.h"
|
|
|
|
#include "gtkbuiltiniconprivate.h"
|
2015-12-16 18:11:24 +00:00
|
|
|
#include "gtkcssnumbervalueprivate.h"
|
2020-08-07 03:45:30 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2022-09-24 13:07:56 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2020-08-07 03:45:30 +00:00
|
|
|
#include "gtklabel.h"
|
|
|
|
#include "gtkprivate.h"
|
2020-12-29 13:54:25 +00:00
|
|
|
#include "gtkshortcuttrigger.h"
|
2021-01-28 04:07:55 +00:00
|
|
|
#include "gtkcssnodeprivate.h"
|
2020-08-07 03:45:30 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2020-09-01 19:25:26 +00:00
|
|
|
#include "gtkmodelbuttonprivate.h"
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
2021-02-21 18:15:39 +00:00
|
|
|
* GtkCheckButton:
|
2011-04-13 11:25:06 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* A `GtkCheckButton` places a label next to an indicator.
|
|
|
|
*
|
|
|
|
* ![Example GtkCheckButtons](check-button.png)
|
|
|
|
*
|
2021-02-28 00:44:51 +00:00
|
|
|
* A `GtkCheckButton` is created by calling either [ctor@Gtk.CheckButton.new]
|
|
|
|
* or [ctor@Gtk.CheckButton.new_with_label].
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
|
|
|
* The state of a `GtkCheckButton` can be set specifically using
|
|
|
|
* [method@Gtk.CheckButton.set_active], and retrieved using
|
|
|
|
* [method@Gtk.CheckButton.get_active].
|
|
|
|
*
|
|
|
|
* # Inconsistent state
|
|
|
|
*
|
|
|
|
* In addition to "on" and "off", check buttons can be an
|
|
|
|
* "in between" state that is neither on nor off. This can be used
|
|
|
|
* e.g. when the user has selected a range of elements (such as some
|
|
|
|
* text or spreadsheet cells) that are affected by a check button,
|
|
|
|
* and the current values in that range are inconsistent.
|
|
|
|
*
|
|
|
|
* To set a `GtkCheckButton` to inconsistent state, use
|
|
|
|
* [method@Gtk.CheckButton.set_inconsistent].
|
|
|
|
*
|
|
|
|
* # Grouping
|
|
|
|
*
|
|
|
|
* Check 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.
|
|
|
|
*
|
|
|
|
* Grouped check buttons use a different indicator, and are commonly referred
|
|
|
|
* to as *radio buttons*.
|
|
|
|
*
|
|
|
|
* ![Example GtkCheckButtons](radio-button.png)
|
|
|
|
*
|
|
|
|
* To add a `GtkCheckButton` to a group, use [method@Gtk.CheckButton.set_group].
|
2015-10-30 04:27:13 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
2021-02-28 00:44:51 +00:00
|
|
|
* ```
|
2020-08-07 03:45:30 +00:00
|
|
|
* checkbutton[.text-button]
|
2015-12-16 15:55:52 +00:00
|
|
|
* ├── check
|
2020-08-07 03:45:30 +00:00
|
|
|
* ╰── [label]
|
2021-02-28 00:44:51 +00:00
|
|
|
* ```
|
2015-11-03 15:17:41 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* A `GtkCheckButton` has a main node with name checkbutton. If the
|
2022-03-25 13:34:04 +00:00
|
|
|
* [property@Gtk.CheckButton:label] or [property@Gtk.CheckButton:child]
|
|
|
|
* properties are set, it contains a child widget. The indicator node
|
|
|
|
* is named check when no group is set, and radio if the checkbutton
|
|
|
|
* is grouped together with other checkbuttons.
|
2020-07-27 14:46:52 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2021-02-28 00:44:51 +00:00
|
|
|
* `GtkCheckButton` uses the %GTK_ACCESSIBLE_ROLE_CHECKBOX role.
|
2011-04-13 11:25:06 +00:00
|
|
|
*/
|
|
|
|
|
2015-10-30 04:27:13 +00:00
|
|
|
typedef struct {
|
2017-06-15 18:54:14 +00:00
|
|
|
GtkWidget *indicator_widget;
|
2022-03-25 13:34:04 +00:00
|
|
|
GtkWidget *child;
|
2020-08-07 03:45:30 +00:00
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
guint inconsistent: 1;
|
|
|
|
guint active: 1;
|
2020-08-07 03:45:30 +00:00
|
|
|
guint use_underline: 1;
|
2022-03-25 13:34:04 +00:00
|
|
|
guint child_type: 1;
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
GtkCheckButton *group_next;
|
|
|
|
GtkCheckButton *group_prev;
|
2017-01-27 11:02:47 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkActionHelper *action_helper;
|
2015-10-30 04:27:13 +00:00
|
|
|
} GtkCheckButtonPrivate;
|
|
|
|
|
2017-01-27 11:02:47 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2020-08-07 03:45:30 +00:00
|
|
|
PROP_ACTIVE,
|
|
|
|
PROP_GROUP,
|
|
|
|
PROP_LABEL,
|
2017-01-28 07:11:14 +00:00
|
|
|
PROP_INCONSISTENT,
|
2020-08-07 03:45:30 +00:00
|
|
|
PROP_USE_UNDERLINE,
|
2022-03-25 13:34:04 +00:00
|
|
|
PROP_CHILD,
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
/* actionable properties */
|
|
|
|
PROP_ACTION_NAME,
|
|
|
|
PROP_ACTION_TARGET,
|
|
|
|
LAST_PROP = PROP_ACTION_NAME
|
2017-01-27 11:02:47 +00:00
|
|
|
};
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
enum {
|
|
|
|
TOGGLED,
|
2020-12-29 13:54:25 +00:00
|
|
|
ACTIVATE,
|
2020-08-07 03:45:30 +00:00
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2017-01-27 11:02:47 +00:00
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
enum {
|
|
|
|
LABEL_CHILD,
|
|
|
|
WIDGET_CHILD
|
|
|
|
};
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static void gtk_check_button_actionable_iface_init (GtkActionableInterface *iface);
|
1997-11-24 22:37:52 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static guint signals[LAST_SIGNAL] = { 0 };
|
|
|
|
static GParamSpec *props[LAST_PROP] = { NULL, };
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkCheckButton, gtk_check_button, GTK_TYPE_WIDGET,
|
|
|
|
G_ADD_PRIVATE (GtkCheckButton)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_check_button_actionable_iface_init))
|
2017-01-27 11:02:47 +00:00
|
|
|
|
2014-08-17 04:24:41 +00:00
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_dispose (GObject *object)
|
2014-08-17 04:24:41 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (object));
|
2015-10-30 04:27:13 +00:00
|
|
|
|
2020-09-01 19:24:34 +00:00
|
|
|
g_clear_object (&priv->action_helper);
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
g_clear_pointer (&priv->indicator_widget, gtk_widget_unparent);
|
2022-03-25 13:34:04 +00:00
|
|
|
g_clear_pointer (&priv->child, gtk_widget_unparent);
|
2017-10-28 17:23:06 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (object), NULL);
|
2015-12-16 17:44:58 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
G_OBJECT_CLASS (gtk_check_button_parent_class)->dispose (object);
|
2015-12-28 15:24:02 +00:00
|
|
|
}
|
|
|
|
|
2020-09-01 19:25:26 +00:00
|
|
|
static void
|
|
|
|
button_role_changed (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
if (gtk_action_helper_get_role (priv->action_helper) == GTK_BUTTON_ROLE_RADIO)
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget),
|
|
|
|
g_quark_from_static_string("radio"));
|
|
|
|
else
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget),
|
|
|
|
g_quark_from_static_string("check"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ensure_action_helper (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
if (priv->action_helper)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->action_helper = gtk_action_helper_new (GTK_ACTIONABLE (self));
|
|
|
|
g_signal_connect_swapped (priv->action_helper, "notify::role",
|
|
|
|
G_CALLBACK (button_role_changed), self);
|
|
|
|
}
|
|
|
|
|
2015-12-28 15:24:02 +00:00
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_set_action_name (GtkActionable *actionable,
|
|
|
|
const char *action_name)
|
2015-12-28 15:24:02 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (actionable);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
2014-08-17 04:24:41 +00:00
|
|
|
|
2020-09-01 19:25:26 +00:00
|
|
|
ensure_action_helper (self);
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
gtk_action_helper_set_action_name (priv->action_helper, action_name);
|
2014-08-17 04:24:41 +00:00
|
|
|
}
|
|
|
|
|
2015-12-04 05:34:52 +00:00
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_set_action_target_value (GtkActionable *actionable,
|
|
|
|
GVariant *action_target)
|
2015-12-04 05:34:52 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (actionable);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
2015-12-04 05:34:52 +00:00
|
|
|
|
2020-09-01 19:25:26 +00:00
|
|
|
ensure_action_helper (self);
|
2015-12-04 05:34:52 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_action_helper_set_action_target_value (priv->action_helper, action_target);
|
2015-12-04 05:34:52 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 11:02:47 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
gtk_check_button_set_active (GTK_CHECK_BUTTON (object), g_value_get_boolean (value));
|
|
|
|
break;
|
|
|
|
case PROP_GROUP:
|
|
|
|
gtk_check_button_set_group (GTK_CHECK_BUTTON (object), g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
|
|
|
gtk_check_button_set_label (GTK_CHECK_BUTTON (object), g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_INCONSISTENT:
|
|
|
|
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (object), g_value_get_boolean (value));
|
2017-01-27 11:02:47 +00:00
|
|
|
break;
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_USE_UNDERLINE:
|
|
|
|
gtk_check_button_set_use_underline (GTK_CHECK_BUTTON (object), g_value_get_boolean (value));
|
2017-01-28 07:11:14 +00:00
|
|
|
break;
|
2022-03-25 13:34:04 +00:00
|
|
|
case PROP_CHILD:
|
|
|
|
gtk_check_button_set_child (GTK_CHECK_BUTTON (object), g_value_get_object (value));
|
|
|
|
break;
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_ACTION_NAME:
|
|
|
|
gtk_check_button_set_action_name (GTK_ACTIONABLE (object), g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
case PROP_ACTION_TARGET:
|
|
|
|
gtk_check_button_set_action_target_value (GTK_ACTIONABLE (object), g_value_get_variant (value));
|
|
|
|
break;
|
|
|
|
default:
|
2017-01-27 11:02:47 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2017-01-27 11:02:47 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (object));
|
|
|
|
|
2017-01-27 11:02:47 +00:00
|
|
|
switch (prop_id)
|
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_boolean (value, gtk_check_button_get_active (GTK_CHECK_BUTTON (object)));
|
|
|
|
break;
|
|
|
|
case PROP_LABEL:
|
|
|
|
g_value_set_string (value, gtk_check_button_get_label (GTK_CHECK_BUTTON (object)));
|
|
|
|
break;
|
|
|
|
case PROP_INCONSISTENT:
|
|
|
|
g_value_set_boolean (value, gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (object)));
|
|
|
|
break;
|
|
|
|
case PROP_USE_UNDERLINE:
|
|
|
|
g_value_set_boolean (value, gtk_check_button_get_use_underline (GTK_CHECK_BUTTON (object)));
|
|
|
|
break;
|
2022-03-25 13:34:04 +00:00
|
|
|
case PROP_CHILD:
|
|
|
|
g_value_set_object (value, gtk_check_button_get_child (GTK_CHECK_BUTTON (object)));
|
|
|
|
break;
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_ACTION_NAME:
|
|
|
|
g_value_set_string (value, gtk_action_helper_get_action_name (priv->action_helper));
|
2017-01-27 11:02:47 +00:00
|
|
|
break;
|
2020-08-07 03:45:30 +00:00
|
|
|
case PROP_ACTION_TARGET:
|
|
|
|
g_value_set_variant (value, gtk_action_helper_get_action_target_value (priv->action_helper));
|
2017-01-28 07:11:14 +00:00
|
|
|
break;
|
2020-08-07 03:45:30 +00:00
|
|
|
default:
|
2017-01-27 11:02:47 +00:00
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static const char *
|
|
|
|
gtk_check_button_get_action_name (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (actionable);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
return gtk_action_helper_get_action_name (priv->action_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GVariant *
|
|
|
|
gtk_check_button_get_action_target_value (GtkActionable *actionable)
|
|
|
|
{
|
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (actionable);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
return gtk_action_helper_get_action_target_value (priv->action_helper);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_check_button_actionable_iface_init (GtkActionableInterface *iface)
|
|
|
|
{
|
|
|
|
iface->get_action_name = gtk_check_button_get_action_name;
|
|
|
|
iface->set_action_name = gtk_check_button_set_action_name;
|
|
|
|
iface->get_action_target_value = gtk_check_button_get_action_target_value;
|
|
|
|
iface->set_action_target_value = gtk_check_button_set_action_target_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
click_pressed_cb (GtkGestureClick *gesture,
|
|
|
|
guint n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
if (gtk_widget_get_focus_on_click (widget) && !gtk_widget_has_focus (widget))
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
click_released_cb (GtkGestureClick *gesture,
|
|
|
|
guint n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (widget);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
2020-08-30 22:19:05 +00:00
|
|
|
if (priv->active && (priv->group_prev || priv->group_next))
|
2020-08-07 03:45:30 +00:00
|
|
|
return;
|
|
|
|
|
2020-12-25 10:59:38 +00:00
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
2021-06-19 20:27:55 +00:00
|
|
|
if (gtk_widget_is_sensitive (widget) &&
|
|
|
|
gtk_widget_contains (widget, x, y))
|
|
|
|
{
|
|
|
|
if (priv->action_helper)
|
|
|
|
gtk_action_helper_activate (priv->action_helper);
|
|
|
|
else
|
|
|
|
gtk_check_button_set_active (self, !priv->active);
|
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 19:51:28 +00:00
|
|
|
static void
|
|
|
|
update_accessible_state (GtkCheckButton *check_button)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
|
|
|
|
|
|
|
|
GtkAccessibleTristate checked_state;
|
|
|
|
|
|
|
|
if (priv->inconsistent)
|
|
|
|
checked_state = GTK_ACCESSIBLE_TRISTATE_MIXED;
|
2020-08-07 03:45:30 +00:00
|
|
|
else if (priv->active)
|
2020-07-17 19:51:28 +00:00
|
|
|
checked_state = GTK_ACCESSIBLE_TRISTATE_TRUE;
|
|
|
|
else
|
|
|
|
checked_state = GTK_ACCESSIBLE_TRISTATE_FALSE;
|
|
|
|
|
|
|
|
gtk_accessible_update_state (GTK_ACCESSIBLE (check_button),
|
|
|
|
GTK_ACCESSIBLE_STATE_CHECKED, checked_state,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
static GtkCheckButton *
|
|
|
|
get_group_next (GtkCheckButton *self)
|
2020-07-17 19:51:28 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
return ((GtkCheckButtonPrivate *)gtk_check_button_get_instance_private (self))->group_next;
|
|
|
|
}
|
2020-07-17 19:51:28 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static GtkCheckButton *
|
|
|
|
get_group_prev (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
return ((GtkCheckButtonPrivate *)gtk_check_button_get_instance_private (self))->group_prev;
|
2020-07-17 19:51:28 +00:00
|
|
|
}
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static GtkCheckButton *
|
|
|
|
get_group_first (GtkCheckButton *self)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *group_first = NULL;
|
|
|
|
GtkCheckButton *iter;
|
2010-10-27 01:29:58 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
/* Find first in group */
|
|
|
|
iter = self;
|
|
|
|
while (iter)
|
|
|
|
{
|
|
|
|
group_first = iter;
|
2010-10-27 01:29:58 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
iter = get_group_prev (iter);
|
|
|
|
if (!iter)
|
|
|
|
break;
|
|
|
|
}
|
2016-01-18 02:16:33 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
g_assert (group_first);
|
2017-01-27 11:02:47 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
return group_first;
|
|
|
|
}
|
2017-01-28 07:11:14 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static GtkCheckButton *
|
|
|
|
get_group_active_button (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButton *iter;
|
2017-01-27 11:02:47 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
for (iter = get_group_first (self); iter; iter = get_group_next (iter))
|
|
|
|
{
|
|
|
|
if (gtk_check_button_get_active (iter))
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-20 07:16:32 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_state_flags_changed (GtkWidget *widget,
|
|
|
|
GtkStateFlags previous_flags)
|
|
|
|
{
|
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (widget);
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
GtkStateFlags state = gtk_widget_get_state_flags (GTK_WIDGET (self));
|
|
|
|
|
|
|
|
gtk_widget_set_state_flags (priv->indicator_widget, state, TRUE);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_check_button_parent_class)->state_flags_changed (widget, previous_flags);
|
|
|
|
}
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_check_button_focus (GtkWidget *widget,
|
|
|
|
GtkDirectionType direction)
|
2012-08-10 17:41:48 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *self = GTK_CHECK_BUTTON (widget);
|
2012-08-10 17:41:48 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
if (gtk_widget_is_focus (widget))
|
2015-10-30 04:27:13 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkCheckButton *iter;
|
|
|
|
GPtrArray *child_array;
|
|
|
|
GtkWidget *new_focus = NULL;
|
|
|
|
guint index;
|
|
|
|
gboolean found;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
if (direction == GTK_DIR_TAB_FORWARD ||
|
|
|
|
direction == GTK_DIR_TAB_BACKWARD)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
child_array = g_ptr_array_new ();
|
|
|
|
for (iter = get_group_first (self); iter; iter = get_group_next (iter))
|
|
|
|
g_ptr_array_add (child_array, iter);
|
|
|
|
|
|
|
|
gtk_widget_focus_sort (widget, direction, child_array);
|
|
|
|
found = g_ptr_array_find (child_array, widget, &index);
|
|
|
|
|
|
|
|
if (found)
|
2015-11-03 04:06:57 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
/* Start at the *next* widget in the list */
|
|
|
|
if (index < child_array->len - 1)
|
|
|
|
index ++;
|
2015-11-03 04:06:57 +00:00
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
else
|
2015-11-03 04:06:57 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
/* Search from the start of the list */
|
|
|
|
index = 0;
|
2015-11-03 04:06:57 +00:00
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
for (i = index; i < child_array->len; i ++)
|
2015-11-03 04:06:57 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkWidget *child = g_ptr_array_index (child_array, i);
|
|
|
|
|
|
|
|
if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
|
|
|
|
{
|
|
|
|
new_focus = child;
|
|
|
|
break;
|
|
|
|
}
|
2015-11-03 04:06:57 +00:00
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (new_focus)
|
2015-11-03 04:06:57 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_widget_grab_focus (new_focus);
|
2021-07-30 18:18:36 +00:00
|
|
|
gtk_widget_activate (new_focus);
|
2015-11-03 04:06:57 +00:00
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
g_ptr_array_free (child_array, TRUE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-07-30 18:18:36 +00:00
|
|
|
GtkCheckButton *active_button;
|
|
|
|
|
|
|
|
active_button = get_group_active_button (self);
|
2020-08-07 03:45:30 +00:00
|
|
|
if (active_button && active_button != self)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
return TRUE;
|
2015-10-30 04:27:13 +00:00
|
|
|
}
|
2012-08-10 17:41:48 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
static void
|
|
|
|
gtk_check_button_real_set_child (GtkCheckButton *self,
|
|
|
|
GtkWidget *child,
|
|
|
|
guint child_type)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
|
|
|
|
|
|
|
|
g_clear_pointer (&priv->child, gtk_widget_unparent);
|
|
|
|
|
|
|
|
priv->child = child;
|
|
|
|
|
|
|
|
if (priv->child)
|
|
|
|
{
|
|
|
|
gtk_widget_set_parent (priv->child, GTK_WIDGET (self));
|
|
|
|
gtk_widget_insert_after (priv->child, GTK_WIDGET (self), priv->indicator_widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (child_type == priv->child_type)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->child_type = child_type;
|
|
|
|
if (child_type != LABEL_CHILD)
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_LABEL]);
|
|
|
|
else
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_CHILD]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-12-29 13:54:25 +00:00
|
|
|
static void
|
2021-05-20 09:38:33 +00:00
|
|
|
gtk_check_button_real_activate (GtkCheckButton *self)
|
2020-12-29 13:54:25 +00:00
|
|
|
{
|
2021-05-20 09:38:33 +00:00
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
if (priv->active && (priv->group_prev || priv->group_next))
|
|
|
|
return;
|
|
|
|
|
2021-07-30 05:40:48 +00:00
|
|
|
if (priv->action_helper)
|
|
|
|
gtk_action_helper_activate (priv->action_helper);
|
|
|
|
else
|
|
|
|
gtk_check_button_set_active (self, !gtk_check_button_get_active (self));
|
2020-12-29 13:54:25 +00:00
|
|
|
}
|
|
|
|
|
1997-11-24 22:37:52 +00:00
|
|
|
static void
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_check_button_class_init (GtkCheckButtonClass *class)
|
1997-11-24 22:37:52 +00:00
|
|
|
{
|
2020-12-29 13:54:25 +00:00
|
|
|
const guint activate_keyvals[] = {
|
|
|
|
GDK_KEY_space,
|
|
|
|
GDK_KEY_KP_Space,
|
|
|
|
GDK_KEY_Return,
|
|
|
|
GDK_KEY_ISO_Enter,
|
|
|
|
GDK_KEY_KP_Enter
|
|
|
|
};
|
2020-08-07 03:45:30 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
2020-12-29 13:54:25 +00:00
|
|
|
GtkShortcutAction *activate_action;
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
object_class->dispose = gtk_check_button_dispose;
|
|
|
|
object_class->set_property = gtk_check_button_set_property;
|
|
|
|
object_class->get_property = gtk_check_button_get_property;
|
2015-10-30 04:27:13 +00:00
|
|
|
|
2021-05-20 07:16:32 +00:00
|
|
|
widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
|
2020-08-07 03:45:30 +00:00
|
|
|
widget_class->focus = gtk_check_button_focus;
|
2015-10-30 04:27:13 +00:00
|
|
|
|
2020-12-29 13:54:25 +00:00
|
|
|
class->activate = gtk_check_button_real_activate;
|
|
|
|
|
2021-02-21 18:15:39 +00:00
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* GtkCheckButton:active: (attributes org.gtk.Property.get=gtk_check_button_get_active org.gtk.Property.set=gtk_check_button_set_active)
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
|
|
|
* If the check button is active.
|
2021-02-25 16:02:10 +00:00
|
|
|
*
|
|
|
|
* Setting `active` to %TRUE will add the `:checked:` state to both
|
|
|
|
* the check button and the indicator CSS node.
|
2021-02-21 18:15:39 +00:00
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
props[PROP_ACTIVE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("active", NULL, NULL,
|
2020-08-07 03:45:30 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2021-02-21 18:15:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* GtkCheckButton:group: (attributes org.gtk.Property.set=gtk_check_button_set_group)
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
|
|
|
* The check button whose group this widget belongs to.
|
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
props[PROP_GROUP] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("group", NULL, NULL,
|
2020-08-07 03:45:30 +00:00
|
|
|
GTK_TYPE_CHECK_BUTTON,
|
|
|
|
GTK_PARAM_WRITABLE);
|
2021-02-21 18:15:39 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* GtkCheckButton:label: (attributes org.gtk.Property.get=gtk_check_button_get_label org.gtk.Property.set=gtk_check_button_set_label)
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
|
|
|
* Text of the label inside the check button, if it contains a label widget.
|
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
props[PROP_LABEL] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_string ("label", NULL, NULL,
|
2020-08-07 03:45:30 +00:00
|
|
|
NULL,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2021-02-21 18:15:39 +00:00
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* GtkCheckButton:inconsistent: (attributes org.gtk.Property.get=gtk_check_button_get_inconsistent org.gtk.Property.set=gtk_check_button_set_inconsistent)
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
|
|
|
* If the check button is in an “in between” state.
|
2021-02-25 16:02:10 +00:00
|
|
|
*
|
|
|
|
* The inconsistent state only affects visual appearance,
|
|
|
|
* not the semantics of the button.
|
2021-02-21 18:15:39 +00:00
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
props[PROP_INCONSISTENT] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("inconsistent", NULL, NULL,
|
2020-08-07 03:45:30 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
2015-10-30 04:27:13 +00:00
|
|
|
|
2021-02-21 18:15:39 +00:00
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* GtkCheckButton:use-underline: (attributes org.gtk.Property.get=gtk_check_button_get_use_underline org.gtk.Property.set=gtk_check_button_set_use_underline)
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
2021-02-25 16:02:10 +00:00
|
|
|
* If set, an underline in the text indicates that the following
|
|
|
|
* character is to be used as mnemonic.
|
2021-02-21 18:15:39 +00:00
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
props[PROP_USE_UNDERLINE] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_boolean ("use-underline", NULL, NULL,
|
2020-08-07 03:45:30 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
/**
|
|
|
|
* GtkCheckButton:child: (attributes org.gtk.Property.get=gtk_check_button_get_child org.gtk.Property.set=gtk_check_button_set_child)
|
|
|
|
*
|
|
|
|
* The child widget.
|
|
|
|
*
|
|
|
|
* Since: 4.8
|
|
|
|
*/
|
|
|
|
props[PROP_CHILD] =
|
2022-05-11 12:19:39 +00:00
|
|
|
g_param_spec_object ("child", NULL, NULL,
|
2022-03-25 13:34:04 +00:00
|
|
|
GTK_TYPE_WIDGET,
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
g_object_class_install_properties (object_class, LAST_PROP, props);
|
|
|
|
|
|
|
|
g_object_class_override_property (object_class, PROP_ACTION_NAME, "action-name");
|
|
|
|
g_object_class_override_property (object_class, PROP_ACTION_TARGET, "action-target");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkCheckButton::toggled:
|
|
|
|
*
|
2021-02-25 16:02:10 +00:00
|
|
|
* Emitted when the buttons's [property@Gtk.CheckButton:active]
|
|
|
|
* property changes.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
signals[TOGGLED] =
|
|
|
|
g_signal_new (I_("toggled"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkCheckButtonClass, toggled),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
2020-12-29 13:54:25 +00:00
|
|
|
/**
|
|
|
|
* GtkCheckButton::activate:
|
|
|
|
* @widget: the object which received the signal.
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Emitted to when the check button is activated.
|
|
|
|
*
|
|
|
|
* The `::activate` signal on `GtkCheckButton` is an action signal and
|
2020-12-29 13:54:25 +00:00
|
|
|
* emitting it causes the button to animate press then release.
|
2021-02-21 18:15:39 +00:00
|
|
|
*
|
2020-12-29 13:54:25 +00:00
|
|
|
* Applications should never connect to this signal, but use the
|
2021-02-21 18:15:39 +00:00
|
|
|
* [signal@Gtk.CheckButton::toggled] signal.
|
2021-03-07 15:51:38 +00:00
|
|
|
*
|
|
|
|
* Since: 4.2
|
2020-12-29 13:54:25 +00:00
|
|
|
*/
|
|
|
|
signals[ACTIVATE] =
|
|
|
|
g_signal_new (I_ ("activate"),
|
|
|
|
G_OBJECT_CLASS_TYPE (object_class),
|
|
|
|
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GtkCheckButtonClass, activate),
|
|
|
|
NULL, NULL,
|
|
|
|
NULL,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
gtk_widget_class_set_activate_signal (widget_class, 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-08-07 03:45:30 +00:00
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
|
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("checkbutton"));
|
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_CHECKBOX);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_check_button_init (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
GtkGesture *gesture;
|
|
|
|
|
|
|
|
gtk_widget_set_receives_default (GTK_WIDGET (self), FALSE);
|
|
|
|
priv->indicator_widget = gtk_builtin_icon_new ("check");
|
|
|
|
gtk_widget_set_halign (priv->indicator_widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_valign (priv->indicator_widget, GTK_ALIGN_CENTER);
|
|
|
|
gtk_widget_set_parent (priv->indicator_widget, GTK_WIDGET (self));
|
|
|
|
|
|
|
|
update_accessible_state (self);
|
|
|
|
|
|
|
|
gesture = gtk_gesture_click_new ();
|
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
|
|
|
|
gtk_gesture_single_set_exclusive (GTK_GESTURE_SINGLE (gesture), TRUE);
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), GDK_BUTTON_PRIMARY);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (click_pressed_cb), self);
|
|
|
|
g_signal_connect (gesture, "released", G_CALLBACK (click_released_cb), self);
|
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE);
|
|
|
|
gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture));
|
|
|
|
|
|
|
|
gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new:
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Creates a new `GtkCheckButton`.
|
2011-04-13 11:25:06 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: a new `GtkCheckButton`
|
2011-04-13 11:25:06 +00:00
|
|
|
*/
|
2020-08-07 03:45:30 +00:00
|
|
|
GtkWidget *
|
1998-05-03 22:41:32 +00:00
|
|
|
gtk_check_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_CHECK_BUTTON, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2011-04-13 11:25:06 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new_with_label:
|
2020-08-07 03:45:30 +00:00
|
|
|
* @label: (nullable): the text for the check button.
|
2011-04-13 11:25:06 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Creates a new `GtkCheckButton` with the given text.
|
2011-04-13 11:25:06 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: a new `GtkCheckButton`
|
2011-04-13 11:25:06 +00:00
|
|
|
*/
|
1997-11-24 22:37:52 +00:00
|
|
|
GtkWidget*
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_check_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_CHECK_BUTTON, "label", label, NULL);
|
1997-11-24 22:37:52 +00:00
|
|
|
}
|
|
|
|
|
2001-03-21 18:58:28 +00:00
|
|
|
/**
|
|
|
|
* gtk_check_button_new_with_mnemonic:
|
2021-02-21 18:15:39 +00:00
|
|
|
* @label: (nullable): The text of the button, with an underscore
|
|
|
|
* in front of the mnemonic character
|
2001-03-21 18:58:28 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Creates a new `GtkCheckButton` with the given text and a mnemonic.
|
2011-09-26 00:58:59 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: a new `GtkCheckButton`
|
2011-09-26 00:58:59 +00:00
|
|
|
*/
|
2001-03-21 18:58:28 +00:00
|
|
|
GtkWidget*
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_check_button_new_with_mnemonic (const char *label)
|
2001-03-21 18:58:28 +00:00
|
|
|
{
|
2020-08-07 03:45:30 +00:00
|
|
|
return g_object_new (GTK_TYPE_CHECK_BUTTON,
|
|
|
|
"label", label,
|
|
|
|
"use-underline", TRUE,
|
2006-07-06 05:14:03 +00:00
|
|
|
NULL);
|
2001-03-21 18:58:28 +00:00
|
|
|
}
|
|
|
|
|
2017-01-28 07:11:14 +00:00
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_set_inconsistent: (attributes org.gtk.Method.set_property=inconsistent)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @check_button: a `GtkCheckButton`
|
2017-01-28 07:11:14 +00:00
|
|
|
* @inconsistent: %TRUE if state is inconsistent
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Sets the `GtkCheckButton` to inconsistent state.
|
|
|
|
*
|
|
|
|
* You shoud turn off the inconsistent state again if the user checks
|
|
|
|
* the check button. This has to be done manually.
|
2017-01-28 07:11:14 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_inconsistent (GtkCheckButton *check_button,
|
|
|
|
gboolean inconsistent)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
|
|
|
|
|
|
|
|
inconsistent = !!inconsistent;
|
2017-12-25 16:27:16 +00:00
|
|
|
if (priv->inconsistent != inconsistent)
|
2017-01-28 07:11:14 +00:00
|
|
|
{
|
2017-12-25 16:27:16 +00:00
|
|
|
priv->inconsistent = inconsistent;
|
|
|
|
|
2017-01-28 07:11:14 +00:00
|
|
|
if (inconsistent)
|
2020-08-07 03:45:30 +00:00
|
|
|
{
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (check_button), GTK_STATE_FLAG_INCONSISTENT, FALSE);
|
|
|
|
gtk_widget_set_state_flags (priv->indicator_widget, GTK_STATE_FLAG_INCONSISTENT, FALSE);
|
|
|
|
}
|
2017-01-28 07:11:14 +00:00
|
|
|
else
|
2020-08-07 03:45:30 +00:00
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (check_button), GTK_STATE_FLAG_INCONSISTENT);
|
|
|
|
gtk_widget_unset_state_flags (priv->indicator_widget, GTK_STATE_FLAG_INCONSISTENT);
|
|
|
|
}
|
2017-01-28 07:11:14 +00:00
|
|
|
|
2020-07-17 19:51:28 +00:00
|
|
|
update_accessible_state (check_button);
|
|
|
|
|
2017-01-28 07:11:14 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (check_button), props[PROP_INCONSISTENT]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_get_inconsistent: (attributes org.gtk.Method.get_property=inconsistent)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @check_button: a `GtkCheckButton`
|
2017-01-28 07:11:14 +00:00
|
|
|
*
|
2019-02-24 20:29:08 +00:00
|
|
|
* Returns whether the check button is in an inconsistent state.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: %TRUE if @check_button is currently in an inconsistent state
|
2017-01-28 07:11:14 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_check_button_get_inconsistent (GtkCheckButton *check_button)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (check_button), FALSE);
|
|
|
|
|
|
|
|
return priv->inconsistent;
|
|
|
|
}
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_get_active: (attributes org.gtk.Method.get_property=active)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns whether the check button is active.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-25 16:02:10 +00:00
|
|
|
* Returns: whether the check button is active
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_check_button_get_active (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (self), FALSE);
|
|
|
|
|
|
|
|
return priv->active;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_set_active: (attributes org.gtk.Method.set_property=active)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
* @setting: the new value to set
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Changes the check buttons active state.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_active (GtkCheckButton *self,
|
|
|
|
gboolean setting)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
|
|
|
|
|
|
|
|
setting = !!setting;
|
|
|
|
|
|
|
|
if (setting == priv->active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (setting)
|
|
|
|
{
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_CHECKED, FALSE);
|
|
|
|
gtk_widget_set_state_flags (priv->indicator_widget, GTK_STATE_FLAG_CHECKED, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_CHECKED);
|
|
|
|
gtk_widget_unset_state_flags (priv->indicator_widget, GTK_STATE_FLAG_CHECKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting && (priv->group_prev || priv->group_next))
|
|
|
|
{
|
|
|
|
GtkCheckButton *group_first = NULL;
|
|
|
|
GtkCheckButton *iter;
|
|
|
|
|
2020-08-30 22:21:22 +00:00
|
|
|
group_first = get_group_first (self);
|
2020-08-07 03:45:30 +00:00
|
|
|
g_assert (group_first);
|
|
|
|
|
|
|
|
/* Set all buttons in group to !active */
|
|
|
|
for (iter = group_first; iter; iter = get_group_next (iter))
|
|
|
|
gtk_check_button_set_active (iter, FALSE);
|
|
|
|
|
|
|
|
/* ... and the next code block will set this one to active */
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->active = setting;
|
|
|
|
update_accessible_state (self);
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_ACTIVE]);
|
|
|
|
g_signal_emit (self, signals[TOGGLED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_get_label: (attributes org.gtk.Method.get_property=label)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2022-03-25 13:34:04 +00:00
|
|
|
* Returns the label of the check button or `NULL` if [property@CheckButton:child] is set.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: (nullable) (transfer none): The label @self shows next
|
|
|
|
* to the indicator. If no label is shown, %NULL will be returned.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
gtk_check_button_get_label (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (self), "");
|
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
if (priv->child_type == LABEL_CHILD && priv->child != NULL)
|
|
|
|
return gtk_label_get_label (GTK_LABEL (priv->child));
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_set_label: (attributes org.gtk.Method.set_property=label)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
* @label: (nullable): The text shown next to the indicator, or %NULL
|
|
|
|
* to show no text
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Sets the text of @self.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* If [property@Gtk.CheckButton:use-underline] is %TRUE, an underscore
|
|
|
|
* in @label is interpreted as mnemonic indicator, see
|
|
|
|
* [method@Gtk.CheckButton.set_use_underline] for details on this behavior.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_label (GtkCheckButton *self,
|
|
|
|
const char *label)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
2022-03-25 13:34:04 +00:00
|
|
|
GtkWidget *child;
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
|
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
g_object_freeze_notify (G_OBJECT (self));
|
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
if (label == NULL || label[0] == '\0')
|
|
|
|
{
|
2022-03-25 13:34:04 +00:00
|
|
|
gtk_check_button_real_set_child (self, NULL, LABEL_CHILD);
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (self), "text-button");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-03-25 13:34:04 +00:00
|
|
|
if (priv->child_type != LABEL_CHILD || priv->child == NULL)
|
2020-08-07 03:45:30 +00:00
|
|
|
{
|
2022-03-25 13:34:04 +00:00
|
|
|
child = gtk_label_new (NULL);
|
|
|
|
gtk_widget_set_hexpand (child, TRUE);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (child), 0.0f);
|
2022-03-25 13:31:36 +00:00
|
|
|
if (priv->use_underline)
|
2022-03-25 13:34:04 +00:00
|
|
|
gtk_label_set_use_underline (GTK_LABEL (child), priv->use_underline);
|
|
|
|
gtk_check_button_real_set_child (self, GTK_WIDGET (child), LABEL_CHILD);
|
2020-08-07 03:45:30 +00:00
|
|
|
}
|
2022-05-17 19:28:25 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (self), "text-button");
|
2022-03-25 13:34:04 +00:00
|
|
|
gtk_label_set_label (GTK_LABEL (priv->child), label);
|
2020-08-07 03:45:30 +00:00
|
|
|
}
|
|
|
|
|
2022-03-25 13:34:04 +00:00
|
|
|
|
2020-08-07 03:45:30 +00:00
|
|
|
gtk_accessible_update_property (GTK_ACCESSIBLE (self),
|
|
|
|
GTK_ACCESSIBLE_PROPERTY_LABEL, label,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_LABEL]);
|
2022-03-25 13:34:04 +00:00
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (self));
|
2020-08-07 03:45:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_set_group: (attributes org.gtk.Method.set_property=group)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
|
|
|
* @group: (nullable) (transfer none): another `GtkCheckButton` to
|
2020-08-07 03:45:30 +00:00
|
|
|
* form a group with
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Adds @self to the group of @group.
|
|
|
|
*
|
|
|
|
* In a group of multiple check buttons, only one button can be active
|
|
|
|
* at a time. The behavior of a checkbutton in a group is also commonly
|
|
|
|
* known as a *radio button*.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
|
|
|
* Setting the group of a check button also changes the css name of the
|
|
|
|
* indicator widget's CSS node to 'radio'.
|
|
|
|
*
|
2021-03-17 11:37:33 +00:00
|
|
|
* Setting up groups in a cycle leads to undefined behavior.
|
|
|
|
*
|
2021-05-23 01:21:10 +00:00
|
|
|
* Note that the same effect can be achieved via the [iface@Gtk.Actionable]
|
2021-02-21 18:15:39 +00:00
|
|
|
* API, by using the same action with parameter type and state type 's'
|
2020-09-01 19:31:24 +00:00
|
|
|
* for all buttons in the group, and giving each button its own target
|
|
|
|
* value.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_group (GtkCheckButton *self,
|
|
|
|
GtkCheckButton *group)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
GtkCheckButtonPrivate *group_priv = gtk_check_button_get_instance_private (group);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
|
2021-03-17 11:37:33 +00:00
|
|
|
g_return_if_fail (self != group);
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
if (!group)
|
|
|
|
{
|
|
|
|
if (priv->group_prev)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *p = gtk_check_button_get_instance_private (priv->group_prev);
|
|
|
|
p->group_next = priv->group_next;
|
|
|
|
}
|
|
|
|
if (priv->group_next)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *p = gtk_check_button_get_instance_private (priv->group_next);
|
|
|
|
p->group_prev = priv->group_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->group_next = NULL;
|
|
|
|
priv->group_prev = NULL;
|
|
|
|
|
|
|
|
if (priv->indicator_widget)
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget),
|
|
|
|
g_quark_from_static_string("check"));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->group_next == group)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->group_prev = NULL;
|
|
|
|
if (group_priv->group_prev)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *prev = gtk_check_button_get_instance_private (group_priv->group_prev);
|
|
|
|
|
|
|
|
prev->group_next = self;
|
|
|
|
priv->group_prev = group_priv->group_prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
group_priv->group_prev = self;
|
|
|
|
priv->group_next = group;
|
|
|
|
|
|
|
|
if (priv->indicator_widget)
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (priv->indicator_widget),
|
|
|
|
g_quark_from_static_string("radio"));
|
|
|
|
|
|
|
|
gtk_css_node_set_name (gtk_widget_get_css_node (group_priv->indicator_widget),
|
|
|
|
g_quark_from_static_string("radio"));
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_GROUP]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_get_use_underline: (attributes org.gtk.Method.get_property=use-underline)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns whether underlines in the label indicate mnemonics.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Returns: The value of the [property@Gtk.CheckButton:use-underline] property.
|
|
|
|
* See [method@Gtk.CheckButton.set_use_underline] for details on how to set
|
|
|
|
* a new value.
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_check_button_get_use_underline (GtkCheckButton *self)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (self), FALSE);
|
|
|
|
|
|
|
|
return priv->use_underline;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-25 16:02:10 +00:00
|
|
|
* gtk_check_button_set_use_underline: (attributes org.gtk.Method.set_property=use-underline)
|
2021-02-21 18:15:39 +00:00
|
|
|
* @self: a `GtkCheckButton`
|
2020-08-07 03:45:30 +00:00
|
|
|
* @setting: the new value to set
|
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* Sets whether underlines in the label indicate mnemonics.
|
2020-08-07 03:45:30 +00:00
|
|
|
*
|
2021-02-21 18:15:39 +00:00
|
|
|
* If @setting is %TRUE, an underscore character in @self's label
|
|
|
|
* indicates a mnemonic accelerator key. This behavior is similar
|
|
|
|
* to [property@Gtk.Label:use-underline].
|
2020-08-07 03:45:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_use_underline (GtkCheckButton *self,
|
|
|
|
gboolean setting)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (self);
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (self));
|
|
|
|
|
|
|
|
setting = !!setting;
|
|
|
|
|
|
|
|
if (setting == priv->use_underline)
|
|
|
|
return;
|
|
|
|
|
|
|
|
priv->use_underline = setting;
|
2022-05-17 19:28:25 +00:00
|
|
|
if (priv->child_type == LABEL_CHILD && priv->child != NULL)
|
2022-03-25 13:34:04 +00:00
|
|
|
gtk_label_set_use_underline (GTK_LABEL (priv->child), priv->use_underline);
|
2020-08-07 03:45:30 +00:00
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_USE_UNDERLINE]);
|
|
|
|
}
|
2022-03-25 13:34:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_check_button_set_child: (attributes org.gtk.Method.set_property=child)
|
|
|
|
* @button: a `GtkCheckButton`
|
|
|
|
* @child: (nullable): the child widget
|
|
|
|
*
|
|
|
|
* Sets the child widget of @button.
|
|
|
|
*
|
|
|
|
* Note that by using this API, you take full responsibility for setting
|
|
|
|
* up the proper accessibility label and description information for @button.
|
|
|
|
* Most likely, you'll either set the accessibility label or description
|
|
|
|
* for @button explicitly, or you'll set a labelled-by or described-by
|
|
|
|
* relations from @child to @button.
|
|
|
|
*
|
|
|
|
* Since: 4.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_check_button_set_child (GtkCheckButton *button,
|
|
|
|
GtkWidget *child)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_CHECK_BUTTON (button));
|
|
|
|
g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
|
|
|
|
|
|
|
|
g_object_freeze_notify (G_OBJECT (button));
|
|
|
|
|
|
|
|
gtk_widget_remove_css_class (GTK_WIDGET (button), "text-button");
|
|
|
|
|
|
|
|
gtk_check_button_real_set_child (button, child, WIDGET_CHILD);
|
|
|
|
|
|
|
|
g_object_notify_by_pspec (G_OBJECT (button), props[PROP_CHILD]);
|
|
|
|
|
|
|
|
g_object_thaw_notify (G_OBJECT (button));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_check_button_get_child: (attributes org.gtk.Method.get_property=child)
|
|
|
|
* @button: a `GtkCheckButton`
|
|
|
|
*
|
|
|
|
* Gets the child widget of @button or `NULL` if [property@CheckButton:label] is set.
|
|
|
|
*
|
|
|
|
* Returns: (nullable) (transfer none): the child widget of @button
|
|
|
|
*
|
|
|
|
* Since: 4.8
|
|
|
|
*/
|
|
|
|
GtkWidget *
|
|
|
|
gtk_check_button_get_child (GtkCheckButton *button)
|
|
|
|
{
|
|
|
|
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (button);
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_CHECK_BUTTON (button), NULL);
|
|
|
|
|
|
|
|
if (priv->child_type == WIDGET_CHILD)
|
|
|
|
return priv->child;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|