2009-01-23 15:15:28 +00:00
|
|
|
|
/* gtktoggletoolbutton.c
|
2003-06-29 23:34:20 +00:00
|
|
|
|
*
|
2003-12-29 10:55:53 +00:00
|
|
|
|
* Copyright (C) 2002 Anders Carlsson <andersca@gnome.org>
|
2003-06-29 23:34:20 +00:00
|
|
|
|
* Copyright (C) 2002 James Henstridge <james@daa.com.au>
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* 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/>.
|
2003-06-29 23:34:20 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2003-06-29 23:34:20 +00:00
|
|
|
|
#include "gtktoggletoolbutton.h"
|
|
|
|
|
#include "gtkcheckmenuitem.h"
|
|
|
|
|
#include "gtklabel.h"
|
|
|
|
|
#include "gtktogglebutton.h"
|
2013-07-20 00:29:11 +00:00
|
|
|
|
#include "deprecated/gtkstock.h"
|
2003-06-29 23:34:20 +00:00
|
|
|
|
#include "gtkintl.h"
|
2003-08-29 18:28:23 +00:00
|
|
|
|
#include "gtkradiotoolbutton.h"
|
2013-07-20 00:29:11 +00:00
|
|
|
|
#include "deprecated/gtktoggleaction.h"
|
|
|
|
|
#include "deprecated/gtkactivatable.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2011-04-13 19:37:21 +00:00
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtktoggletoolbutton
|
|
|
|
|
* @Short_description: A GtkToolItem containing a toggle button
|
|
|
|
|
* @Title: GtkToggleToolButton
|
|
|
|
|
* @See_also: #GtkToolbar, #GtkToolButton, #GtkSeparatorToolItem
|
|
|
|
|
*
|
|
|
|
|
* A #GtkToggleToolButton is a #GtkToolItem that contains a toggle
|
|
|
|
|
* button.
|
|
|
|
|
*
|
2015-11-05 20:41:37 +00:00
|
|
|
|
* Use gtk_toggle_tool_button_new() to create a new GtkToggleToolButton.
|
|
|
|
|
*
|
|
|
|
|
* # CSS nodes
|
|
|
|
|
*
|
|
|
|
|
* GtkToggleToolButton has a single CSS node with name togglebutton.
|
2011-04-13 19:37:21 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
#define MENU_ID "gtk-toggle-tool-button-menu-id"
|
|
|
|
|
|
|
|
|
|
enum {
|
|
|
|
|
TOGGLED,
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
|
};
|
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
enum {
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_ACTIVE
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
struct _GtkToggleToolButtonPrivate
|
|
|
|
|
{
|
|
|
|
|
guint active : 1;
|
|
|
|
|
};
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
static void gtk_toggle_tool_button_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gtk_toggle_tool_button_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
static gboolean gtk_toggle_tool_button_create_menu_proxy (GtkToolItem *button);
|
|
|
|
|
|
|
|
|
|
static void button_toggled (GtkWidget *widget,
|
|
|
|
|
GtkToggleToolButton *button);
|
|
|
|
|
static void menu_item_activated (GtkWidget *widget,
|
|
|
|
|
GtkToggleToolButton *button);
|
|
|
|
|
|
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
|
static void gtk_toggle_tool_button_activatable_interface_init (GtkActivatableIface *iface);
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void gtk_toggle_tool_button_update (GtkActivatable *activatable,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
GtkAction *action,
|
|
|
|
|
const gchar *property_name);
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void gtk_toggle_tool_button_sync_action_properties (GtkActivatable *activatable,
|
2009-01-23 15:15:28 +00:00
|
|
|
|
GtkAction *action);
|
|
|
|
|
|
|
|
|
|
static GtkActivatableIface *parent_activatable_iface;
|
|
|
|
|
static guint toggle_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkToggleToolButton, gtk_toggle_tool_button, GTK_TYPE_TOOL_BUTTON,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkToggleToolButton)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
|
|
|
|
|
gtk_toggle_tool_button_activatable_interface_init))
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_toggle_tool_button_class_init (GtkToggleToolButtonClass *klass)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
GtkToolItemClass *toolitem_class;
|
|
|
|
|
GtkToolButtonClass *toolbutton_class;
|
|
|
|
|
|
|
|
|
|
object_class = (GObjectClass *)klass;
|
|
|
|
|
toolitem_class = (GtkToolItemClass *)klass;
|
|
|
|
|
toolbutton_class = (GtkToolButtonClass *)klass;
|
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
object_class->set_property = gtk_toggle_tool_button_set_property;
|
|
|
|
|
object_class->get_property = gtk_toggle_tool_button_get_property;
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
toolitem_class->create_menu_proxy = gtk_toggle_tool_button_create_menu_proxy;
|
|
|
|
|
toolbutton_class->button_type = GTK_TYPE_TOGGLE_BUTTON;
|
2005-04-04 06:28:07 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GtkToggleToolButton:active:
|
|
|
|
|
*
|
2010-08-10 08:23:49 +00:00
|
|
|
|
* If the toggle tool button should be pressed in.
|
2005-04-04 06:28:07 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.8
|
|
|
|
|
*/
|
2005-04-04 20:37:42 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
2005-04-04 06:28:07 +00:00
|
|
|
|
PROP_ACTIVE,
|
|
|
|
|
g_param_spec_boolean ("active",
|
2014-06-09 13:43:49 +00:00
|
|
|
|
P_("Active"),
|
|
|
|
|
P_("If the toggle button should be pressed in"),
|
|
|
|
|
FALSE,
|
|
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2005-04-04 06:28:07 +00:00
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* GtkToggleToolButton::toggled:
|
|
|
|
|
* @toggle_tool_button: the object that emitted the signal
|
|
|
|
|
*
|
|
|
|
|
* Emitted whenever the toggle tool button changes state.
|
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
|
toggle_signals[TOGGLED] =
|
2005-09-01 05:11:46 +00:00
|
|
|
|
g_signal_new (I_("toggled"),
|
2003-06-29 23:34:20 +00:00
|
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
|
G_STRUCT_OFFSET (GtkToggleToolButtonClass, toggled),
|
|
|
|
|
NULL, NULL,
|
2019-05-29 20:27:53 +00:00
|
|
|
|
NULL,
|
2003-06-29 23:34:20 +00:00
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_toggle_tool_button_init (GtkToggleToolButton *button)
|
|
|
|
|
{
|
2003-08-29 18:28:23 +00:00
|
|
|
|
GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
|
|
|
|
|
GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button));
|
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
button->priv = gtk_toggle_tool_button_get_instance_private (button);
|
2003-08-29 18:28:23 +00:00
|
|
|
|
|
|
|
|
|
/* If the real button is a radio button, it may have been
|
|
|
|
|
* active at the time it was created.
|
|
|
|
|
*/
|
|
|
|
|
button->priv->active = gtk_toggle_button_get_active (toggle_button);
|
|
|
|
|
|
|
|
|
|
g_signal_connect_object (toggle_button,
|
2003-07-08 18:20:45 +00:00
|
|
|
|
"toggled", G_CALLBACK (button_toggled), button, 0);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_toggle_tool_button_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkToggleToolButton *button = GTK_TOGGLE_TOOL_BUTTON (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_ACTIVE:
|
2006-01-30 15:30:25 +00:00
|
|
|
|
gtk_toggle_tool_button_set_active (button,
|
|
|
|
|
g_value_get_boolean (value));
|
2005-04-04 06:28:07 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_toggle_tool_button_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkToggleToolButton *button = GTK_TOGGLE_TOOL_BUTTON (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_ACTIVE:
|
|
|
|
|
g_value_set_boolean (value, gtk_toggle_tool_button_get_active (button));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_toggle_tool_button_create_menu_proxy (GtkToolItem *item)
|
|
|
|
|
{
|
|
|
|
|
GtkToolButton *tool_button = GTK_TOOL_BUTTON (item);
|
|
|
|
|
GtkToggleToolButton *toggle_tool_button = GTK_TOGGLE_TOOL_BUTTON (item);
|
|
|
|
|
GtkWidget *menu_item = NULL;
|
|
|
|
|
GtkStockItem stock_item;
|
|
|
|
|
gboolean use_mnemonic = TRUE;
|
2003-08-29 18:28:23 +00:00
|
|
|
|
const char *label;
|
2009-01-26 03:01:01 +00:00
|
|
|
|
GtkWidget *label_widget;
|
|
|
|
|
const gchar *label_text;
|
|
|
|
|
const gchar *stock_id;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2009-01-26 03:01:01 +00:00
|
|
|
|
if (_gtk_tool_item_create_menu_proxy (item))
|
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
label_widget = gtk_tool_button_get_label_widget (tool_button);
|
|
|
|
|
label_text = gtk_tool_button_get_label (tool_button);
|
2013-06-25 03:47:52 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2009-01-26 03:01:01 +00:00
|
|
|
|
stock_id = gtk_tool_button_get_stock_id (tool_button);
|
2003-07-08 18:20:45 +00:00
|
|
|
|
|
2008-02-06 09:53:34 +00:00
|
|
|
|
if (GTK_IS_LABEL (label_widget))
|
2003-07-08 18:20:45 +00:00
|
|
|
|
{
|
|
|
|
|
label = gtk_label_get_label (GTK_LABEL (label_widget));
|
2003-08-29 18:28:23 +00:00
|
|
|
|
use_mnemonic = gtk_label_get_use_underline (GTK_LABEL (label_widget));
|
2003-07-08 18:20:45 +00:00
|
|
|
|
}
|
|
|
|
|
else if (label_text)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
{
|
2003-07-08 18:20:45 +00:00
|
|
|
|
label = label_text;
|
2003-08-29 18:28:23 +00:00
|
|
|
|
use_mnemonic = gtk_tool_button_get_use_underline (tool_button);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
2003-07-08 18:20:45 +00:00
|
|
|
|
else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
|
2003-08-29 18:28:23 +00:00
|
|
|
|
{
|
|
|
|
|
label = stock_item.label;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
label = "";
|
|
|
|
|
}
|
2013-06-27 21:51:38 +00:00
|
|
|
|
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
if (use_mnemonic)
|
|
|
|
|
menu_item = gtk_check_menu_item_new_with_mnemonic (label);
|
|
|
|
|
else
|
|
|
|
|
menu_item = gtk_check_menu_item_new_with_label (label);
|
|
|
|
|
|
|
|
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
|
2003-07-08 18:20:45 +00:00
|
|
|
|
toggle_tool_button->priv->active);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2003-08-29 18:28:23 +00:00
|
|
|
|
if (GTK_IS_RADIO_TOOL_BUTTON (toggle_tool_button))
|
|
|
|
|
{
|
|
|
|
|
gtk_check_menu_item_set_draw_as_radio (GTK_CHECK_MENU_ITEM (menu_item),
|
|
|
|
|
TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
|
g_signal_connect_closure_by_id (menu_item,
|
|
|
|
|
g_signal_lookup ("activate", G_OBJECT_TYPE (menu_item)), 0,
|
|
|
|
|
g_cclosure_new_object (G_CALLBACK (menu_item_activated),
|
|
|
|
|
G_OBJECT (toggle_tool_button)),
|
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
|
|
gtk_tool_item_set_proxy_menu_item (item, MENU_ID, menu_item);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* There are two activatable widgets, a toggle button and a menu item.
|
|
|
|
|
*
|
|
|
|
|
* If a widget is activated and the state of the tool button is the same as
|
|
|
|
|
* the new state of the activated widget, then the other widget was the one
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* that was activated by the user and updated the tool button’s state.
|
2003-06-29 23:34:20 +00:00
|
|
|
|
*
|
|
|
|
|
* If the state of the tool button is not the same as the new state of the
|
|
|
|
|
* activated widget, then the activation was activated by the user, and the
|
|
|
|
|
* widget needs to make sure the tool button is updated before the other
|
|
|
|
|
* widget is activated. This will make sure the other widget a tool button
|
|
|
|
|
* in a state that matches its own new state.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
menu_item_activated (GtkWidget *menu_item,
|
|
|
|
|
GtkToggleToolButton *toggle_tool_button)
|
|
|
|
|
{
|
|
|
|
|
GtkToolButton *tool_button = GTK_TOOL_BUTTON (toggle_tool_button);
|
|
|
|
|
gboolean menu_active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menu_item));
|
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
if (toggle_tool_button->priv->active != menu_active)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
{
|
2003-07-08 18:20:45 +00:00
|
|
|
|
toggle_tool_button->priv->active = menu_active;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (_gtk_tool_button_get_button (tool_button)),
|
|
|
|
|
toggle_tool_button->priv->active);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
g_object_notify (G_OBJECT (toggle_tool_button), "active");
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_emit (toggle_tool_button, toggle_signals[TOGGLED], 0);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
button_toggled (GtkWidget *widget,
|
|
|
|
|
GtkToggleToolButton *toggle_tool_button)
|
|
|
|
|
{
|
2010-10-19 16:45:11 +00:00
|
|
|
|
gboolean toggle_active;
|
|
|
|
|
|
|
|
|
|
toggle_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
if (toggle_tool_button->priv->active != toggle_active)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
{
|
|
|
|
|
GtkWidget *menu_item;
|
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
toggle_tool_button->priv->active = toggle_active;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
|
|
|
|
if ((menu_item =
|
|
|
|
|
gtk_tool_item_get_proxy_menu_item (GTK_TOOL_ITEM (toggle_tool_button), MENU_ID)))
|
|
|
|
|
{
|
|
|
|
|
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item),
|
2003-07-08 18:20:45 +00:00
|
|
|
|
toggle_tool_button->priv->active);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-04-04 06:28:07 +00:00
|
|
|
|
g_object_notify (G_OBJECT (toggle_tool_button), "active");
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_emit (toggle_tool_button, toggle_signals[TOGGLED], 0);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_toggle_tool_button_activatable_interface_init (GtkActivatableIface *iface)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
{
|
|
|
|
|
parent_activatable_iface = g_type_interface_peek_parent (iface);
|
2009-02-22 05:20:14 +00:00
|
|
|
|
iface->update = gtk_toggle_tool_button_update;
|
|
|
|
|
iface->sync_action_properties = gtk_toggle_tool_button_sync_action_properties;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2009-02-22 05:20:14 +00:00
|
|
|
|
gtk_toggle_tool_button_update (GtkActivatable *activatable,
|
|
|
|
|
GtkAction *action,
|
|
|
|
|
const gchar *property_name)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
{
|
|
|
|
|
GtkToggleToolButton *button;
|
|
|
|
|
|
|
|
|
|
parent_activatable_iface->update (activatable, action, property_name);
|
|
|
|
|
|
|
|
|
|
button = GTK_TOGGLE_TOOL_BUTTON (activatable);
|
|
|
|
|
|
|
|
|
|
if (strcmp (property_name, "active") == 0)
|
|
|
|
|
{
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
gtk_action_block_activate (action);
|
|
|
|
|
gtk_toggle_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
|
|
|
|
gtk_action_unblock_activate (action);
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2009-02-22 05:20:14 +00:00
|
|
|
|
gtk_toggle_tool_button_sync_action_properties (GtkActivatable *activatable,
|
|
|
|
|
GtkAction *action)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
{
|
|
|
|
|
GtkToggleToolButton *button;
|
2013-06-28 15:27:19 +00:00
|
|
|
|
gboolean is_toggle_action;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2009-02-22 05:20:14 +00:00
|
|
|
|
parent_activatable_iface->sync_action_properties (activatable, action);
|
2009-01-23 15:15:28 +00:00
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
is_toggle_action = GTK_IS_TOGGLE_ACTION (action);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
|
|
|
|
|
if (!is_toggle_action)
|
2009-01-23 15:15:28 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
button = GTK_TOGGLE_TOOL_BUTTON (activatable);
|
|
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
gtk_action_block_activate (action);
|
|
|
|
|
gtk_toggle_tool_button_set_active (button, gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
|
|
|
|
|
gtk_action_unblock_activate (action);
|
2013-06-28 15:27:19 +00:00
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
2009-01-23 15:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_tool_button_new:
|
|
|
|
|
*
|
|
|
|
|
* Returns a new #GtkToggleToolButton
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: a newly created #GtkToggleToolButton
|
2003-08-04 21:13:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
|
GtkToolItem *
|
|
|
|
|
gtk_toggle_tool_button_new (void)
|
|
|
|
|
{
|
|
|
|
|
GtkToolButton *button;
|
|
|
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_TOGGLE_TOOL_BUTTON,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return GTK_TOOL_ITEM (button);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_tool_button_new_from_stock:
|
|
|
|
|
* @stock_id: the name of the stock item
|
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkToggleToolButton containing the image and text from a
|
|
|
|
|
* stock item. Some stock ids have preprocessor macros like #GTK_STOCK_OK
|
|
|
|
|
* and #GTK_STOCK_APPLY.
|
|
|
|
|
*
|
|
|
|
|
* It is an error if @stock_id is not a name of a stock item.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: A new #GtkToggleToolButton
|
2003-08-04 21:13:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
2013-06-25 03:47:52 +00:00
|
|
|
|
*
|
|
|
|
|
* Deprecated: 3.10: Use gtk_toggle_tool_button_new() instead.
|
2003-08-04 21:13:55 +00:00
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
|
GtkToolItem *
|
|
|
|
|
gtk_toggle_tool_button_new_from_stock (const gchar *stock_id)
|
|
|
|
|
{
|
|
|
|
|
GtkToolButton *button;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (stock_id != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_TOGGLE_TOOL_BUTTON,
|
2005-03-26 05:49:15 +00:00
|
|
|
|
"stock-id", stock_id,
|
2003-06-29 23:34:20 +00:00
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return GTK_TOOL_ITEM (button);
|
|
|
|
|
}
|
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_tool_button_set_active:
|
|
|
|
|
* @button: a #GtkToggleToolButton
|
|
|
|
|
* @is_active: whether @button should be active
|
|
|
|
|
*
|
|
|
|
|
* Sets the status of the toggle tool button. Set to %TRUE if you
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* want the GtkToggleButton to be “pressed in”, and %FALSE to raise it.
|
2003-08-04 21:13:55 +00:00
|
|
|
|
* This action causes the toggled signal to be emitted.
|
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
|
void
|
|
|
|
|
gtk_toggle_tool_button_set_active (GtkToggleToolButton *button,
|
2014-06-09 13:43:49 +00:00
|
|
|
|
gboolean is_active)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button));
|
|
|
|
|
|
|
|
|
|
is_active = is_active != FALSE;
|
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
if (button->priv->active != is_active)
|
2014-06-09 13:43:49 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_button_clicked (GTK_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button))));
|
|
|
|
|
g_object_notify (G_OBJECT (button), "active");
|
|
|
|
|
}
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
|
/**
|
|
|
|
|
* gtk_toggle_tool_button_get_active:
|
|
|
|
|
* @button: a #GtkToggleToolButton
|
|
|
|
|
*
|
|
|
|
|
* Queries a #GtkToggleToolButton and returns its current state.
|
|
|
|
|
* Returns %TRUE if the toggle button is pressed in and %FALSE if it is raised.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the toggle tool button is pressed in, %FALSE if not
|
2003-08-04 21:13:55 +00:00
|
|
|
|
*
|
|
|
|
|
* Since: 2.4
|
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
|
gboolean
|
|
|
|
|
gtk_toggle_tool_button_get_active (GtkToggleToolButton *button)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TOGGLE_TOOL_BUTTON (button), FALSE);
|
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
|
return button->priv->active;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
}
|