[gtk+/wip/baedert/drawing: 42/49] checkbutton: Inherit from GtkBin
- From: Timm Bäder <baedert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/baedert/drawing: 42/49] checkbutton: Inherit from GtkBin
- Date: Fri, 19 May 2017 13:47:30 +0000 (UTC)
commit 7cef44f22355e6b7509a4b9cf786803f8635cc17
Author: Timm Bäder <mail baedert org>
Date: Mon May 15 22:39:20 2017 +0200
checkbutton: Inherit from GtkBin
Make the checkbutton a GtkBin, containing a GtkToggleButton with a box
and a GtkIcon as indicator. It adds/removed the child to/from the
internal box. It has label, icon-name, active and use-underline
properties as well as a ::toggled signal.
gtk/gtkcheckbutton.c | 413 +++++++++++++++++++++++++++++++------------
gtk/gtkcheckbutton.h | 35 ++++-
gtk/gtkcheckbuttonprivate.h | 5 +-
gtk/gtkfilechooserwidget.c | 1 +
gtk/gtkicon.c | 8 +
gtk/gtkiconprivate.h | 3 +
gtk/gtkmountoperation.c | 1 +
gtk/gtkradiobutton.c | 109 +++++-------
gtk/gtkstackswitcher.c | 12 +-
gtk/gtktoolbar.c | 1 +
10 files changed, 401 insertions(+), 187 deletions(-)
---
diff --git a/gtk/gtkcheckbutton.c b/gtk/gtkcheckbutton.c
index 612ca42..f6220f9 100644
--- a/gtk/gtkcheckbutton.c
+++ b/gtk/gtkcheckbutton.c
@@ -35,25 +35,25 @@
#include "gtkwidgetprivate.h"
#include "gtkbuiltiniconprivate.h"
#include "gtkcssnodeprivate.h"
-#include "gtkboxgadgetprivate.h"
#include "gtkcontainerprivate.h"
#include "gtkstylecontextprivate.h"
#include "gtkcssnumbervalueprivate.h"
#include "gtkradiobutton.h"
+#include "gtkbutton.h"
+#include "gtkbox.h"
+#include "gtkiconprivate.h"
+#include "gtktogglebutton.h"
+#include "gtktogglebuttonprivate.h"
/**
* SECTION:gtkcheckbutton
* @Short_description: Create widgets with a discrete toggle button
* @Title: GtkCheckButton
- * @See_also: #GtkCheckMenuItem, #GtkButton, #GtkToggleButton, #GtkRadioButton
+ * @See_also: #GtkCheckMenuItem, #GtkButton, #GtkRadioButton
*
- * A #GtkCheckButton places a discrete #GtkToggleButton next to a widget,
- * (usually a #GtkLabel). See the section on #GtkToggleButton widgets for
- * more information about toggle/check buttons.
- *
- * The important signal ( #GtkToggleButton::toggled ) is also inherited from
- * #GtkToggleButton.
+ * A #GtkCheckButton places a discrete indicator next to a widget,
+ * (usually a #GtkLabel).
*
* # CSS nodes
*
@@ -84,8 +84,9 @@ static void gtk_check_button_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot);
typedef struct {
- GtkCssGadget *gadget;
- GtkCssGadget *indicator_gadget;
+ GtkWidget *button;
+ GtkWidget *box;
+ GtkWidget *indicator;
guint draw_indicator : 1;
guint inconsistent : 1;
@@ -95,12 +96,22 @@ enum {
PROP_0,
PROP_DRAW_INDICATOR,
PROP_INCONSISTENT,
+ PROP_ACTIVE,
+ PROP_LABEL,
+ PROP_ICON_NAME,
+ PROP_USE_UNDERLINE,
NUM_PROPERTIES
};
+enum {
+ TOGGLED,
+ LAST_SIGNAL
+};
+
static GParamSpec *props[NUM_PROPERTIES] = { NULL, };
+static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE_WITH_PRIVATE (GtkCheckButton, gtk_check_button, GTK_TYPE_TOGGLE_BUTTON)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkCheckButton, gtk_check_button, GTK_TYPE_BIN)
static void
@@ -110,26 +121,23 @@ gtk_check_button_update_node_state (GtkWidget *widget)
GtkCssImageBuiltinType image_type;
GtkStateFlags state;
- state = gtk_widget_get_state_flags (widget);
+ state = gtk_widget_get_state_flags (priv->button);
- /* XXX: This is somewhat awkward here, but there's no better
- * way to update the icon
- */
if (state & GTK_STATE_FLAG_CHECKED)
image_type = GTK_IS_RADIO_BUTTON (widget) ? GTK_CSS_IMAGE_BUILTIN_OPTION : GTK_CSS_IMAGE_BUILTIN_CHECK;
else if (state & GTK_STATE_FLAG_INCONSISTENT)
image_type = GTK_IS_RADIO_BUTTON (widget) ? GTK_CSS_IMAGE_BUILTIN_OPTION_INCONSISTENT :
GTK_CSS_IMAGE_BUILTIN_CHECK_INCONSISTENT;
else
image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
- gtk_builtin_icon_set_image (GTK_BUILTIN_ICON (priv->indicator_gadget), image_type);
- gtk_css_gadget_set_state (priv->indicator_gadget, state);
+ gtk_icon_set_image (GTK_ICON (priv->indicator), image_type);
+ gtk_widget_set_state_flags (priv->indicator, state, TRUE);
}
static void
gtk_check_button_state_flags_changed (GtkWidget *widget,
- GtkStateFlags previous_state_flags)
+ GtkStateFlags previous_state_flags)
{
gtk_check_button_update_node_state (widget);
@@ -137,27 +145,11 @@ gtk_check_button_state_flags_changed (GtkWidget *widget,
}
static void
-gtk_check_button_direction_changed (GtkWidget *widget,
- GtkTextDirection previous_direction)
-{
- GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
-
- gtk_box_gadget_reverse_children (GTK_BOX_GADGET (priv->gadget));
- gtk_box_gadget_set_allocate_reverse (GTK_BOX_GADGET (priv->gadget),
- gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
- gtk_box_gadget_set_align_reverse (GTK_BOX_GADGET (priv->gadget),
- gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
-
- GTK_WIDGET_CLASS (gtk_check_button_parent_class)->direction_changed (widget, previous_direction);
-}
-
-static void
gtk_check_button_finalize (GObject *object)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (object));
- g_clear_object (&priv->gadget);
- g_clear_object (&priv->indicator_gadget);
+ gtk_widget_unparent (priv->button);
G_OBJECT_CLASS (gtk_check_button_parent_class)->finalize (object);
}
@@ -167,13 +159,9 @@ gtk_check_button_add (GtkContainer *container,
GtkWidget *widget)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (container));
- int pos;
-
- GTK_CONTAINER_CLASS (gtk_check_button_parent_class)->add (container, widget);
- pos = gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL ? 0 : 1;
- gtk_box_gadget_insert_widget (GTK_BOX_GADGET (priv->gadget), pos, widget);
- gtk_box_gadget_set_gadget_expand (GTK_BOX_GADGET (priv->gadget), G_OBJECT (widget), TRUE);
+ _gtk_bin_set_child (GTK_BIN (container), widget);
+ gtk_container_add (GTK_CONTAINER (priv->box), widget);
}
static void
@@ -182,9 +170,8 @@ gtk_check_button_remove (GtkContainer *container,
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (container));
- gtk_box_gadget_remove_widget (GTK_BOX_GADGET (priv->gadget), widget);
-
- GTK_CONTAINER_CLASS (gtk_check_button_parent_class)->remove (container, widget);
+ gtk_container_remove (GTK_CONTAINER (priv->box), widget);
+ _gtk_bin_set_child (GTK_BIN (container), NULL);
}
static void
@@ -198,20 +185,8 @@ gtk_check_button_measure (GtkWidget *widget,
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
- if (priv->draw_indicator)
- {
- gtk_css_gadget_get_preferred_size (priv->gadget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
- }
- else
- {
- GTK_WIDGET_CLASS (gtk_check_button_parent_class)->measure (widget, orientation, for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
- }
+ gtk_widget_measure (priv->button, orientation, for_size,
+ minimum, natural, minimum_baseline, natural_baseline);
}
static void
@@ -231,6 +206,22 @@ gtk_check_button_set_property (GObject *object,
gtk_check_button_set_inconsistent (GTK_CHECK_BUTTON (object),
g_value_get_boolean (value));
break;
+ case PROP_ACTIVE:
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (object),
+ g_value_get_boolean (value));
+ break;
+ case PROP_LABEL:
+ gtk_check_button_set_label (GTK_CHECK_BUTTON (object),
+ g_value_get_string (value));
+ break;
+ case PROP_ICON_NAME:
+ gtk_check_button_set_icon_name (GTK_CHECK_BUTTON (object),
+ g_value_get_string (value));
+ break;
+ case PROP_USE_UNDERLINE:
+ gtk_check_button_set_use_underline (GTK_CHECK_BUTTON (object),
+ g_value_get_boolean (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -251,6 +242,18 @@ gtk_check_button_get_property (GObject *object,
case PROP_INCONSISTENT:
g_value_set_boolean (value, gtk_check_button_get_inconsistent (GTK_CHECK_BUTTON (object)));
break;
+ 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_ICON_NAME:
+ g_value_set_string (value, gtk_check_button_get_icon_name (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;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -258,21 +261,33 @@ gtk_check_button_get_property (GObject *object,
}
static void
+gtk_check_button_dispose (GObject *object)
+{
+ GtkCheckButton *check_button = GTK_CHECK_BUTTON (object);
+ GtkWidget *child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (check_button), child);
+
+ G_OBJECT_CLASS (gtk_check_button_parent_class)->dispose (object);
+}
+
+static void
gtk_check_button_class_init (GtkCheckButtonClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
- object_class->finalize = gtk_check_button_finalize;
object_class->set_property = gtk_check_button_set_property;
object_class->get_property = gtk_check_button_get_property;
+ object_class->finalize = gtk_check_button_finalize;
+ object_class->dispose = gtk_check_button_dispose;
widget_class->measure = gtk_check_button_measure;
widget_class->size_allocate = gtk_check_button_size_allocate;
widget_class->snapshot = gtk_check_button_snapshot;
widget_class->state_flags_changed = gtk_check_button_state_flags_changed;
- widget_class->direction_changed = gtk_check_button_direction_changed;
container_class->add = gtk_check_button_add;
container_class->remove = gtk_check_button_remove;
@@ -291,6 +306,41 @@ gtk_check_button_class_init (GtkCheckButtonClass *class)
FALSE,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ props[PROP_ACTIVE] =
+ g_param_spec_boolean ("active",
+ P_("Active"),
+ P_("if the indicator should be checked"),
+ FALSE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
+ props[PROP_LABEL] =
+ g_param_spec_string ("label",
+ P_("Label"),
+ P_("Text of the label widget next to the indicator"),
+ NULL,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ props[PROP_ICON_NAME] =
+ g_param_spec_string ("icon-name",
+ P_("Icon Name"),
+ P_("The name of the icon used to automatically populate the button"),
+ NULL,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+
+ props[PROP_USE_UNDERLINE] =
+ g_param_spec_boolean ("use-underline",
+ P_("Use underline"),
+ P_("If set, an underline in the label indicates the next character should be
used for the mnemonic accelerator key"),
+ FALSE,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
+ 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);
+
g_object_class_install_properties (object_class, NUM_PROPERTIES, props);
gtk_widget_class_set_accessible_role (widget_class, ATK_ROLE_CHECK_BOX);
@@ -302,64 +352,67 @@ draw_indicator_changed (GtkCheckButton *check_button)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
GtkCssNode *widget_node;
- GtkCssNode *indicator_node;
+
+ gtk_widget_set_visible (priv->indicator, priv->draw_indicator);
widget_node = gtk_widget_get_css_node (GTK_WIDGET (check_button));
- indicator_node = gtk_css_gadget_get_node (priv->indicator_gadget);
if (priv->draw_indicator)
{
- gtk_css_node_set_visible (indicator_node, TRUE);
if (GTK_IS_RADIO_BUTTON (check_button))
{
gtk_css_node_remove_class (widget_node, g_quark_from_static_string ("radio"));
- gtk_css_node_set_name (widget_node, I_("radiobutton"));
}
else if (GTK_IS_CHECK_BUTTON (check_button))
{
gtk_css_node_remove_class (widget_node, g_quark_from_static_string ("check"));
- gtk_css_node_set_name (widget_node, I_("checkbutton"));
}
}
else
{
- gtk_css_node_set_visible (indicator_node, FALSE);
if (GTK_IS_RADIO_BUTTON (check_button))
{
gtk_css_node_add_class (widget_node, g_quark_from_static_string ("radio"));
- gtk_css_node_set_name (widget_node, I_("button"));
}
else if (GTK_IS_CHECK_BUTTON (check_button))
{
gtk_css_node_add_class (widget_node, g_quark_from_static_string ("check"));
- gtk_css_node_set_name (widget_node, I_("button"));
}
}
}
static void
+toggle_button_clicked_cb (GtkToggleButton *toggle_button,
+ gpointer user_data)
+{
+ GtkCheckButton *check_button = user_data;
+
+ g_signal_emit (check_button, signals[TOGGLED], 0);
+}
+
+static void
gtk_check_button_init (GtkCheckButton *check_button)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
- GtkCssNode *widget_node;
priv->draw_indicator = TRUE;
gtk_widget_set_receives_default (GTK_WIDGET (check_button), FALSE);
- gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (check_button)), "toggle");
+ priv->button = gtk_toggle_button_new ();
+ priv->box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
+ priv->indicator = gtk_icon_new ("check");
+ gtk_widget_set_valign (priv->indicator, GTK_ALIGN_CENTER);
- widget_node = gtk_widget_get_css_node (GTK_WIDGET (check_button));
- priv->gadget = gtk_box_gadget_new_for_node (widget_node, GTK_WIDGET (check_button));
- gtk_box_gadget_set_orientation (GTK_BOX_GADGET (priv->gadget), GTK_ORIENTATION_HORIZONTAL);
- gtk_box_gadget_set_draw_focus (GTK_BOX_GADGET (priv->gadget), FALSE);
- priv->indicator_gadget = gtk_builtin_icon_new ("check",
- GTK_WIDGET (check_button),
- priv->gadget,
- NULL);
- gtk_box_gadget_insert_gadget (GTK_BOX_GADGET (priv->gadget), 0, priv->indicator_gadget, FALSE,
GTK_ALIGN_BASELINE);
+ gtk_container_add (GTK_CONTAINER (priv->button), priv->box);
+ gtk_container_add (GTK_CONTAINER (priv->box), priv->indicator);
+ gtk_widget_set_parent (priv->button, GTK_WIDGET (check_button));
- gtk_check_button_update_node_state (GTK_WIDGET (check_button));
+ g_object_bind_property (check_button, "active",
+ priv->button, "active",
+ G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
+
+ g_signal_connect (priv->button, "toggled", G_CALLBACK (toggle_button_clicked_cb), check_button);
}
/**
@@ -415,31 +468,12 @@ gtk_check_button_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
- GdkRectangle clip = *allocation;
+ GdkRectangle clip;
- if (priv->draw_indicator)
- {
- gtk_css_gadget_allocate (priv->gadget,
- allocation,
- gtk_widget_get_allocated_baseline (widget),
- &clip);
- gtk_widget_set_clip (widget, &clip);
- }
- else
- {
- GTK_WIDGET_CLASS (gtk_check_button_parent_class)->size_allocate (widget, allocation);
- }
+ gtk_widget_size_allocate (priv->button, allocation);
+ gtk_widget_get_clip (priv->button, &clip);
- if (gtk_widget_get_realized (widget))
- {
- GtkAllocation widget_allocation;
- gtk_widget_get_allocation (widget, &widget_allocation);
- gdk_window_move_resize (GTK_BUTTON (widget)->priv->event_window,
- widget_allocation.x,
- widget_allocation.y,
- widget_allocation.width,
- widget_allocation.height);
- }
+ gtk_widget_set_clip (widget, &clip);
}
static void
@@ -448,18 +482,25 @@ gtk_check_button_snapshot (GtkWidget *widget,
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (GTK_CHECK_BUTTON (widget));
- if (!priv->draw_indicator)
- GTK_WIDGET_CLASS (gtk_check_button_parent_class)->snapshot (widget, snapshot);
- else
- gtk_css_gadget_snapshot (priv->gadget, snapshot);
+ gtk_widget_snapshot_child (widget, priv->button, snapshot);
+}
+
+GtkIcon *
+gtk_check_button_get_indicator (GtkCheckButton *check_button)
+{
+ GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
+
+ return GTK_ICON (priv->indicator);
}
-GtkCssNode *
-gtk_check_button_get_indicator_node (GtkCheckButton *check_button)
+void
+_gtk_check_button_set_active (GtkCheckButton *check_button,
+ gboolean active)
{
GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
- return gtk_css_gadget_get_node (priv->indicator_gadget);
+ _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), active);
+ gtk_check_button_update_node_state (GTK_WIDGET (check_button));
}
/**
@@ -558,3 +599,155 @@ gtk_check_button_get_inconsistent (GtkCheckButton *check_button)
return priv->inconsistent;
}
+
+void
+gtk_check_button_set_active (GtkCheckButton *check_button,
+ gboolean active)
+{
+ GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
+
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->button), active);
+ gtk_check_button_update_node_state (GTK_WIDGET (check_button));
+
+ g_object_notify_by_pspec (G_OBJECT (check_button), props[PROP_ACTIVE]);
+}
+
+gboolean
+gtk_check_button_get_active (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 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->button));
+}
+
+void
+gtk_check_button_set_label (GtkCheckButton *check_button,
+ const char *label)
+{
+ GtkWidget *child;
+
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_LABEL (child))
+ {
+ gtk_label_set_label (GTK_LABEL (child), label);
+ }
+ else
+ {
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (check_button), child);
+
+ child = gtk_label_new (label);
+ gtk_container_add (GTK_CONTAINER (check_button), child);
+ }
+}
+
+const char *
+gtk_check_button_get_label (GtkCheckButton *check_button)
+{
+ GtkWidget *child;
+
+ g_return_val_if_fail (GTK_IS_CHECK_BUTTON (check_button), NULL);
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_LABEL (child))
+ return gtk_label_get_label (GTK_LABEL (child));
+
+ return NULL;
+}
+
+void
+gtk_check_button_set_icon_name (GtkCheckButton *check_button,
+ const char *icon_name)
+{
+ GtkWidget *child;
+
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_IMAGE (child))
+ {
+ gtk_image_set_from_icon_name (GTK_IMAGE (child), icon_name, GTK_ICON_SIZE_BUTTON);
+ }
+ else
+ {
+ if (child)
+ gtk_container_remove (GTK_CONTAINER (check_button), child);
+
+ child = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_BUTTON);
+ gtk_container_add (GTK_CONTAINER (check_button), child);
+ }
+}
+
+const char *
+gtk_check_button_get_icon_name (GtkCheckButton *check_button)
+{
+ GtkWidget *child;
+
+ g_return_val_if_fail (GTK_IS_CHECK_BUTTON (check_button), NULL);
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_IMAGE (child))
+ {
+ const char *icon_name;
+
+ gtk_image_get_icon_name (GTK_IMAGE (child), &icon_name, NULL);
+ return icon_name;
+ }
+
+ return NULL;
+}
+
+void
+gtk_check_button_set_use_underline (GtkCheckButton *check_button,
+ gboolean use_underline)
+{
+ GtkWidget *child;
+
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_LABEL (child))
+ {
+ gtk_label_set_use_underline (GTK_LABEL (child), use_underline);
+ gtk_label_set_mnemonic_widget (GTK_LABEL (child), GTK_WIDGET (check_button));
+ }
+}
+
+gboolean
+gtk_check_button_get_use_underline (GtkCheckButton *check_button)
+{
+ GtkWidget *child;
+
+ g_return_val_if_fail (GTK_IS_CHECK_BUTTON (check_button), FALSE);
+
+ child = gtk_bin_get_child (GTK_BIN (check_button));
+
+ if (GTK_IS_LABEL (child))
+ return gtk_label_get_use_underline (GTK_LABEL (child));
+
+ return FALSE;
+}
+
+void
+gtk_check_button_toggled (GtkCheckButton *check_button)
+{
+ GtkCheckButtonPrivate *priv = gtk_check_button_get_instance_private (check_button);
+
+ g_return_if_fail (GTK_IS_CHECK_BUTTON (check_button));
+
+ g_signal_handlers_block_by_func (priv->button, toggle_button_clicked_cb, check_button);
+ gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (priv->button));
+ g_signal_emit (check_button, signals[TOGGLED], 0);
+ g_signal_handlers_unblock_by_func (priv->button, toggle_button_clicked_cb, check_button);
+}
diff --git a/gtk/gtkcheckbutton.h b/gtk/gtkcheckbutton.h
index 2c3f54b..f74d189 100644
--- a/gtk/gtkcheckbutton.h
+++ b/gtk/gtkcheckbutton.h
@@ -30,7 +30,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
-#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkbin.h>
G_BEGIN_DECLS
@@ -48,12 +48,14 @@ typedef struct _GtkCheckButtonClass GtkCheckButtonClass;
struct _GtkCheckButton
{
- GtkToggleButton toggle_button;
+ GtkBin parent_instance;
};
struct _GtkCheckButtonClass
{
- GtkToggleButtonClass parent_class;
+ GtkBinClass parent_class;
+
+ void (* toggled) (GtkCheckButton *checkbutton);
/* Padding for future expansion */
void (*_gtk_reserved1) (void);
@@ -82,6 +84,33 @@ void gtk_check_button_set_inconsistent (GtkCheckButton *check_button,
GDK_AVAILABLE_IN_3_90
gboolean gtk_check_button_get_inconsistent (GtkCheckButton *check_button);
+GDK_AVAILABLE_IN_3_92
+void gtk_check_button_set_active (GtkCheckButton *check_button,
+ gboolean active);
+GDK_AVAILABLE_IN_3_92
+gboolean gtk_check_button_get_active (GtkCheckButton *check_button);
+GDK_AVAILABLE_IN_3_92
+void gtk_check_button_set_label (GtkCheckButton *check_button,
+ const char *label);
+GDK_AVAILABLE_IN_3_92
+const char *gtk_check_button_get_label (GtkCheckButton *check_button);
+GDK_AVAILABLE_IN_3_92
+void gtk_check_button_set_icon_name (GtkCheckButton *check_button,
+ const char *icon_name);
+GDK_AVAILABLE_IN_3_92
+const char *gtk_check_button_get_icon_name (GtkCheckButton *check_button);
+GDK_AVAILABLE_IN_3_92
+void gtk_check_button_set_use_underline (GtkCheckButton *check_button,
+ gboolean use_underline);
+GDK_AVAILABLE_IN_3_92
+gboolean gtk_check_button_get_use_underline (GtkCheckButton *check_button);
+
+
+
+GDK_AVAILABLE_IN_3_92
+void gtk_check_button_toggled (GtkCheckButton *check_button);
+
+
G_END_DECLS
#endif /* __GTK_CHECK_BUTTON_H__ */
diff --git a/gtk/gtkcheckbuttonprivate.h b/gtk/gtkcheckbuttonprivate.h
index c7ccf5b..226ebff 100644
--- a/gtk/gtkcheckbuttonprivate.h
+++ b/gtk/gtkcheckbuttonprivate.h
@@ -27,12 +27,13 @@
#include "gtkcheckbutton.h"
-#include "gtkcssnodeprivate.h"
+#include "gtkiconprivate.h"
G_BEGIN_DECLS
-GtkCssNode *gtk_check_button_get_indicator_node (GtkCheckButton *check_button);
+GtkIcon *gtk_check_button_get_indicator (GtkCheckButton *check_button);
+void _gtk_check_button_set_active (GtkCheckButton *check_button, gboolean active);
G_END_DECLS
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index ec51668..0b0646d 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -80,6 +80,7 @@
#include "gtkseparator.h"
#include "gtkmodelbutton.h"
#include "gtkgesturelongpress.h"
+#include "gtktogglebutton.h"
#include "gtkdebug.h"
#include <cairo-gobject.h>
diff --git a/gtk/gtkicon.c b/gtk/gtkicon.c
index 7b5327a..307bb06 100644
--- a/gtk/gtkicon.c
+++ b/gtk/gtkicon.c
@@ -86,3 +86,11 @@ gtk_icon_set_image (GtkIcon *self,
{
self->image = image;
}
+
+void
+gtk_icon_set_css_name (GtkIcon *self,
+ const char *css_name)
+{
+ gtk_css_node_set_name (gtk_widget_get_css_node (GTK_WIDGET (self)),
+ g_intern_string (css_name));
+}
diff --git a/gtk/gtkiconprivate.h b/gtk/gtkiconprivate.h
index dcbb6d7..b979e50 100644
--- a/gtk/gtkiconprivate.h
+++ b/gtk/gtkiconprivate.h
@@ -53,6 +53,9 @@ GtkWidget * gtk_icon_new (const char *css_name);
void gtk_icon_set_image (GtkIcon *self,
GtkCssImageBuiltinType image);
+void gtk_icon_set_css_name (GtkIcon *self,
+ const char *css_name);
+
G_END_DECLS
#endif /* __GTK_ICON_PRIVATE_H__ */
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index 2f5189d..c11038c 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -52,6 +52,7 @@
#include "gtksettings.h"
#include "gtkstylecontextprivate.h"
#include "gtkdialogprivate.h"
+#include "gtktogglebutton.h"
#include <glib/gprintf.h>
diff --git a/gtk/gtkradiobutton.c b/gtk/gtkradiobutton.c
index a86cd37..ef22e84 100644
--- a/gtk/gtkradiobutton.c
+++ b/gtk/gtkradiobutton.c
@@ -28,7 +28,7 @@
#include "gtkcontainerprivate.h"
#include "gtkbuttonprivate.h"
-#include "gtktogglebuttonprivate.h"
+#include "gtkcheckbuttonprivate.h"
#include "gtkcheckbuttonprivate.h"
#include "gtklabel.h"
#include "gtkmarshalers.h"
@@ -122,10 +122,10 @@
* }
* ]|
*
- * When an unselected button in the group is clicked the clicked button
- * receives the #GtkToggleButton::toggled signal, as does the previously
+ * When an unselected button in the group is toggled the toggled button
+ * receives the #GtkCheckButton::toggled signal, as does the previously
* selected button.
- * Inside the #GtkToggleButton::toggled handler, gtk_toggle_button_get_active()
+ * Inside the #GtkCheckButton::toggled handler, gtk_check_button_get_active()
* can be used to determine if the button has been selected or deselected.
*/
@@ -146,7 +146,7 @@ static GParamSpec *radio_button_props[LAST_PROP] = { NULL, };
static void gtk_radio_button_destroy (GtkWidget *widget);
static gboolean gtk_radio_button_focus (GtkWidget *widget,
GtkDirectionType direction);
-static void gtk_radio_button_clicked (GtkButton *button);
+static void gtk_radio_button_toggled (GtkCheckButton *check_button);
static void gtk_radio_button_set_property (GObject *object,
guint prop_id,
const GValue *value,
@@ -164,12 +164,12 @@ static void
gtk_radio_button_class_init (GtkRadioButtonClass *class)
{
GObjectClass *gobject_class;
- GtkButtonClass *button_class;
+ GtkCheckButtonClass *check_button_class;
GtkWidgetClass *widget_class;
gobject_class = G_OBJECT_CLASS (class);
widget_class = (GtkWidgetClass*) class;
- button_class = (GtkButtonClass*) class;
+ check_button_class = (GtkCheckButtonClass*) class;
gobject_class->set_property = gtk_radio_button_set_property;
gobject_class->get_property = gtk_radio_button_get_property;
@@ -191,7 +191,7 @@ gtk_radio_button_class_init (GtkRadioButtonClass *class)
widget_class->destroy = gtk_radio_button_destroy;
widget_class->focus = gtk_radio_button_focus;
- button_class->clicked = gtk_radio_button_clicked;
+ check_button_class->toggled = gtk_radio_button_toggled;
class->group_changed = NULL;
@@ -224,19 +224,19 @@ static void
gtk_radio_button_init (GtkRadioButton *radio_button)
{
GtkRadioButtonPrivate *priv;
- GtkCssNode *css_node;
+ GtkIcon *indicator;
radio_button->priv = gtk_radio_button_get_instance_private (radio_button);
priv = radio_button->priv;
gtk_widget_set_receives_default (GTK_WIDGET (radio_button), FALSE);
- _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
+ _gtk_check_button_set_active (GTK_CHECK_BUTTON (radio_button), TRUE);
priv->group = g_slist_prepend (NULL, radio_button);
- css_node = gtk_check_button_get_indicator_node (GTK_CHECK_BUTTON (radio_button));
- gtk_css_node_set_name (css_node, I_("radio"));
+ indicator = gtk_check_button_get_indicator (GTK_CHECK_BUTTON (radio_button));
+ gtk_icon_set_css_name (indicator, "radio");
}
static void
@@ -362,7 +362,7 @@ gtk_radio_button_set_group (GtkRadioButton *radio_button,
g_object_unref (new_group_singleton);
}
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (radio_button), group == NULL);
g_object_unref (radio_button);
}
@@ -696,7 +696,7 @@ gtk_radio_button_focus (GtkWidget *widget,
{
gtk_widget_grab_focus (new_focus);
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (new_focus), TRUE);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (new_focus), TRUE);
}
return TRUE;
@@ -712,9 +712,9 @@ gtk_radio_button_focus (GtkWidget *widget,
tmp_slist = priv->group;
while (tmp_slist)
{
- if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)) &&
- gtk_widget_get_visible (tmp_slist->data))
- selected_button = tmp_slist->data;
+ if (gtk_check_button_get_active (GTK_CHECK_BUTTON (tmp_slist->data)) &&
+ gtk_widget_get_visible (tmp_slist->data))
+ selected_button = tmp_slist->data;
tmp_slist = tmp_slist->next;
}
@@ -727,71 +727,46 @@ gtk_radio_button_focus (GtkWidget *widget,
}
static void
-gtk_radio_button_clicked (GtkButton *button)
+gtk_radio_button_toggled (GtkCheckButton *check_button)
{
- GtkRadioButton *radio_button = GTK_RADIO_BUTTON (button);
+ GtkRadioButton *radio_button = GTK_RADIO_BUTTON (check_button);
GtkRadioButtonPrivate *priv = radio_button->priv;
- GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
- GtkToggleButton *tmp_button;
+ GtkCheckButton *tmp_button;
GSList *tmp_list;
- gint toggled;
- toggled = FALSE;
+ tmp_list = priv->group;
- g_object_ref (GTK_WIDGET (button));
+ g_object_ref (check_button);
- if (gtk_toggle_button_get_active (toggle_button))
+ if (gtk_check_button_get_active (check_button))
{
- tmp_button = NULL;
- tmp_list = priv->group;
-
while (tmp_list)
- {
- tmp_button = tmp_list->data;
- tmp_list = tmp_list->next;
-
- if (tmp_button != toggle_button &&
- gtk_toggle_button_get_active (tmp_button))
- break;
-
- tmp_button = NULL;
- }
+ {
+ tmp_button = tmp_list->data;
+ tmp_list = tmp_list->next;
- if (tmp_button)
- {
- toggled = TRUE;
- _gtk_toggle_button_set_active (toggle_button,
- !gtk_toggle_button_get_active (toggle_button));
- }
+ if (tmp_button != check_button &&
+ gtk_check_button_get_active (tmp_button))
+ gtk_check_button_set_active (tmp_button, FALSE);
+ }
}
- else
+ else/* Now inactive */
{
- toggled = TRUE;
- _gtk_toggle_button_set_active (toggle_button,
- !gtk_toggle_button_get_active (toggle_button));
-
- tmp_list = priv->group;
while (tmp_list)
- {
- tmp_button = tmp_list->data;
- tmp_list = tmp_list->next;
+ {
+ tmp_button = tmp_list->data;
+ tmp_list = tmp_list->next;
- if (gtk_toggle_button_get_active (tmp_button) && (tmp_button != toggle_button))
- {
- gtk_button_clicked (GTK_BUTTON (tmp_button));
- break;
- }
- }
- }
+ if (tmp_button != check_button &&
+ gtk_check_button_get_active (tmp_button))
+ break;
- if (toggled)
- {
- gtk_toggle_button_toggled (toggle_button);
+ tmp_button = NULL;
+ }
- g_object_notify (G_OBJECT (toggle_button), "active");
+ if (!tmp_button)
+ _gtk_check_button_set_active (check_button, TRUE);
}
- gtk_widget_queue_draw (GTK_WIDGET (button));
-
- g_object_unref (button);
+ g_object_unref (check_button);
}
diff --git a/gtk/gtkstackswitcher.c b/gtk/gtkstackswitcher.c
index 37678fd..e20395c 100644
--- a/gtk/gtkstackswitcher.c
+++ b/gtk/gtkstackswitcher.c
@@ -21,6 +21,8 @@
#include "gtkstackswitcher.h"
#include "gtkradiobutton.h"
#include "gtklabel.h"
+#include "gtkimage.h"
+#include "gtktogglebutton.h"
#include "gtkdnd.h"
#include "gtkdragdest.h"
#include "gtkorientable.h"
@@ -101,7 +103,7 @@ gtk_stack_switcher_init (GtkStackSwitcher *switcher)
}
static void
-on_button_clicked (GtkWidget *widget,
+on_button_toggled (GtkWidget *widget,
GtkStackSwitcher *self)
{
GtkWidget *child;
@@ -280,7 +282,7 @@ gtk_stack_switcher_switch_timeout (gpointer data)
priv->switch_button = NULL;
if (button)
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE);
return G_SOURCE_REMOVE;
}
@@ -374,7 +376,7 @@ add_child (GtkWidget *widget,
gtk_container_add (GTK_CONTAINER (self), button);
g_object_set_data (G_OBJECT (button), "stack-child", widget);
- g_signal_connect (button, "clicked", G_CALLBACK (on_button_clicked), self);
+ g_signal_connect (button, "toggled", G_CALLBACK (on_button_toggled), self);
g_signal_connect (widget, "notify::visible", G_CALLBACK (on_title_icon_visible_updated), self);
g_signal_connect (widget, "child-notify::title", G_CALLBACK (on_title_icon_visible_updated), self);
g_signal_connect (widget, "child-notify::icon-name", G_CALLBACK (on_title_icon_visible_updated), self);
@@ -416,7 +418,7 @@ populate_switcher (GtkStackSwitcher *self)
{
button = g_hash_table_lookup (priv->buttons, widget);
priv->in_child_changed = TRUE;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE);
priv->in_child_changed = FALSE;
}
}
@@ -446,7 +448,7 @@ on_child_changed (GtkWidget *widget,
if (button != NULL)
{
priv->in_child_changed = TRUE;
- gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+ gtk_check_button_set_active (GTK_CHECK_BUTTON (button), TRUE);
priv->in_child_changed = FALSE;
}
}
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 6a1e32e..fc5e5ba 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -60,6 +60,7 @@
#include "gtkwidgetprivate.h"
#include "gtkwindowprivate.h"
#include "gtkgesturemultipress.h"
+#include "gtktogglebutton.h"
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]