2003-08-24 19:58:30 +00:00
|
|
|
/*
|
2008-07-01 22:57:50 +00:00
|
|
|
* GTK - The GIMP Toolkit
|
2003-08-24 19:58:30 +00:00
|
|
|
* Copyright (C) 1998, 1999 Red Hat, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This Library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2003-08-24 19:58:30 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Author: James Henstridge <james@daa.com.au>
|
|
|
|
*
|
|
|
|
* Modified by the GTK+ Team and others 2003. See the AUTHORS
|
|
|
|
* file for a list of people on the GTK+ Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2013-06-28 15:27:19 +00:00
|
|
|
#define GDK_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
#include "gtkintl.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
#include "gtktoggleaction.h"
|
|
|
|
#include "gtktoggletoolbutton.h"
|
2003-09-04 21:34:15 +00:00
|
|
|
#include "gtktogglebutton.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
#include "gtkcheckmenuitem.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2010-05-13 01:23:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* SECTION:gtktoggleaction
|
|
|
|
* @Short_description: An action which can be toggled between two states
|
|
|
|
* @Title: GtkToggleAction
|
|
|
|
*
|
|
|
|
* A #GtkToggleAction corresponds roughly to a #GtkCheckMenuItem. It has an
|
2014-02-05 18:07:34 +00:00
|
|
|
* “active” state specifying whether the action has been checked or not.
|
2010-05-13 01:23:30 +00:00
|
|
|
*/
|
|
|
|
|
2010-07-13 18:27:16 +00:00
|
|
|
struct _GtkToggleActionPrivate
|
|
|
|
{
|
|
|
|
guint active : 1;
|
|
|
|
guint draw_as_radio : 1;
|
|
|
|
};
|
2010-05-13 01:23:30 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TOGGLED,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
2005-11-30 04:25:34 +00:00
|
|
|
PROP_DRAW_AS_RADIO,
|
|
|
|
PROP_ACTIVE
|
2003-09-21 22:04:48 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkToggleAction, gtk_toggle_action, GTK_TYPE_ACTION)
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
static void gtk_toggle_action_activate (GtkAction *action);
|
|
|
|
static void set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static GtkWidget *create_menu_item (GtkAction *action);
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
static guint action_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_toggle_action_class_init (GtkToggleActionClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GtkActionClass *action_class;
|
|
|
|
|
|
|
|
parent_class = g_type_class_peek_parent (klass);
|
|
|
|
gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
action_class = GTK_ACTION_CLASS (klass);
|
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
gobject_class->set_property = set_property;
|
|
|
|
gobject_class->get_property = get_property;
|
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
action_class->activate = gtk_toggle_action_activate;
|
|
|
|
|
|
|
|
action_class->menu_item_type = GTK_TYPE_CHECK_MENU_ITEM;
|
|
|
|
action_class->toolbar_item_type = GTK_TYPE_TOGGLE_TOOL_BUTTON;
|
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
action_class->create_menu_item = create_menu_item;
|
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
klass->toggled = NULL;
|
2003-08-24 19:58:30 +00:00
|
|
|
|
2009-01-23 15:15:28 +00:00
|
|
|
/**
|
|
|
|
* GtkToggleAction:draw-as-radio:
|
|
|
|
*
|
|
|
|
* Whether the proxies for this action look like radio action proxies.
|
|
|
|
*
|
|
|
|
* This is an appearance property and thus only applies if
|
|
|
|
* #GtkActivatable:use-action-appearance is %TRUE.
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2009-01-23 15:15:28 +00:00
|
|
|
*/
|
2003-09-21 22:04:48 +00:00
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_DRAW_AS_RADIO,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_boolean ("draw-as-radio",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("Create the same proxies as a radio action"),
|
|
|
|
P_("Whether the proxies for this action look like radio action proxies"),
|
2003-09-21 22:04:48 +00:00
|
|
|
FALSE,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE));
|
2003-09-21 22:04:48 +00:00
|
|
|
|
2005-11-30 04:25:34 +00:00
|
|
|
/**
|
|
|
|
* GtkToggleAction:active:
|
|
|
|
*
|
2010-08-10 08:23:49 +00:00
|
|
|
* Whether the toggle action should be active.
|
2005-11-30 04:25:34 +00:00
|
|
|
*
|
|
|
|
* Since: 2.10
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2005-11-30 04:25:34 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
|
|
|
PROP_ACTIVE,
|
|
|
|
g_param_spec_boolean ("active",
|
|
|
|
P_("Active"),
|
2010-08-10 08:23:49 +00:00
|
|
|
P_("Whether the toggle action should be active"),
|
2005-11-30 04:25:34 +00:00
|
|
|
FALSE,
|
|
|
|
GTK_PARAM_READWRITE));
|
2010-05-13 01:23:30 +00:00
|
|
|
/**
|
|
|
|
* GtkToggleAction::toggled:
|
|
|
|
* @toggleaction: the object which received the signal.
|
|
|
|
*
|
|
|
|
* Should be connected if you wish to perform an action
|
|
|
|
* whenever the #GtkToggleAction state is changed.
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2010-05-13 01:23:30 +00:00
|
|
|
*/
|
2003-08-24 19:58:30 +00:00
|
|
|
action_signals[TOGGLED] =
|
2005-09-01 05:11:46 +00:00
|
|
|
g_signal_new (I_("toggled"),
|
2003-08-24 19:58:30 +00:00
|
|
|
G_OBJECT_CLASS_TYPE (klass),
|
|
|
|
G_SIGNAL_RUN_FIRST,
|
|
|
|
G_STRUCT_OFFSET (GtkToggleActionClass, toggled),
|
|
|
|
NULL, NULL,
|
|
|
|
g_cclosure_marshal_VOID__VOID,
|
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_toggle_action_init (GtkToggleAction *action)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
action->private_data = gtk_toggle_action_get_instance_private (action);
|
2003-08-24 19:58:30 +00:00
|
|
|
action->private_data->active = FALSE;
|
2003-09-21 22:04:48 +00:00
|
|
|
action->private_data->draw_as_radio = FALSE;
|
|
|
|
}
|
|
|
|
|
2004-01-07 21:54:33 +00:00
|
|
|
/**
|
|
|
|
* gtk_toggle_action_new:
|
|
|
|
* @name: A unique name for the action
|
2011-01-18 09:12:38 +00:00
|
|
|
* @label: (allow-none): The label displayed in menu items and on buttons,
|
|
|
|
* or %NULL
|
2010-02-19 16:53:17 +00:00
|
|
|
* @tooltip: (allow-none): A tooltip for the action, or %NULL
|
2011-01-18 08:25:47 +00:00
|
|
|
* @stock_id: (allow-none): The stock icon to display in widgets representing
|
|
|
|
* the action, or %NULL
|
2004-01-07 21:54:33 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GtkToggleAction object. To add the action to
|
|
|
|
* a #GtkActionGroup and set the accelerator for the action,
|
|
|
|
* call gtk_action_group_add_action_with_accel().
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: a new #GtkToggleAction
|
2004-01-07 21:54:33 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2004-01-07 21:54:33 +00:00
|
|
|
*/
|
|
|
|
GtkToggleAction *
|
|
|
|
gtk_toggle_action_new (const gchar *name,
|
|
|
|
const gchar *label,
|
|
|
|
const gchar *tooltip,
|
|
|
|
const gchar *stock_id)
|
|
|
|
{
|
2007-09-09 20:18:24 +00:00
|
|
|
g_return_val_if_fail (name != NULL, NULL);
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_TOGGLE_ACTION,
|
|
|
|
"name", name,
|
|
|
|
"label", label,
|
|
|
|
"tooltip", tooltip,
|
|
|
|
"stock-id", stock_id,
|
|
|
|
NULL);
|
2004-01-07 21:54:33 +00:00
|
|
|
}
|
|
|
|
|
2003-09-21 22:04:48 +00:00
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToggleAction *action = GTK_TOGGLE_ACTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAW_AS_RADIO:
|
|
|
|
g_value_set_boolean (value, gtk_toggle_action_get_draw_as_radio (action));
|
|
|
|
break;
|
2005-11-30 04:25:34 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
g_value_set_boolean (value, gtk_toggle_action_get_active (action));
|
|
|
|
break;
|
2003-09-21 22:04:48 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkToggleAction *action = GTK_TOGGLE_ACTION (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_DRAW_AS_RADIO:
|
|
|
|
gtk_toggle_action_set_draw_as_radio (action, g_value_get_boolean (value));
|
|
|
|
break;
|
2005-11-30 04:25:34 +00:00
|
|
|
case PROP_ACTIVE:
|
|
|
|
gtk_toggle_action_set_active (action, g_value_get_boolean (value));
|
|
|
|
break;
|
2003-09-21 22:04:48 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_toggle_action_activate (GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkToggleAction *toggle_action;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
|
|
|
|
|
|
|
|
toggle_action = GTK_TOGGLE_ACTION (action);
|
|
|
|
|
|
|
|
toggle_action->private_data->active = !toggle_action->private_data->active;
|
|
|
|
|
2006-10-08 05:07:55 +00:00
|
|
|
g_object_notify (G_OBJECT (action), "active");
|
2005-11-30 04:25:34 +00:00
|
|
|
|
2003-08-24 19:58:30 +00:00
|
|
|
gtk_toggle_action_toggled (toggle_action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_toggle_action_toggled:
|
|
|
|
* @action: the action object
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
* Emits the “toggled” signal on the toggle action.
|
2003-08-24 19:58:30 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2003-08-24 19:58:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_toggle_action_toggled (GtkToggleAction *action)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
|
|
|
|
|
|
|
|
g_signal_emit (action, action_signals[TOGGLED], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_toggle_action_set_active:
|
|
|
|
* @action: the action object
|
|
|
|
* @is_active: whether the action should be checked or not
|
|
|
|
*
|
|
|
|
* Sets the checked state on the toggle action.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2003-08-24 19:58:30 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_toggle_action_set_active (GtkToggleAction *action,
|
|
|
|
gboolean is_active)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
|
|
|
|
|
|
|
|
is_active = is_active != FALSE;
|
|
|
|
|
|
|
|
if (action->private_data->active != is_active)
|
2009-01-27 00:25:21 +00:00
|
|
|
_gtk_action_emit_activate (GTK_ACTION (action));
|
2003-08-24 19:58:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_toggle_action_get_active:
|
|
|
|
* @action: the action object
|
|
|
|
*
|
2003-10-01 22:53:57 +00:00
|
|
|
* Returns the checked state of the toggle action.
|
2010-05-13 01:23:30 +00:00
|
|
|
*
|
2003-08-24 19:58:30 +00:00
|
|
|
* Returns: the checked state of the toggle action
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2003-08-24 19:58:30 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_toggle_action_get_active (GtkToggleAction *action)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOGGLE_ACTION (action), FALSE);
|
|
|
|
|
|
|
|
return action->private_data->active;
|
|
|
|
}
|
2003-09-21 22:04:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_toggle_action_set_draw_as_radio:
|
|
|
|
* @action: the action object
|
|
|
|
* @draw_as_radio: whether the action should have proxies like a radio
|
|
|
|
* action
|
|
|
|
*
|
|
|
|
* Sets whether the action should have proxies like a radio action.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2003-09-21 22:04:48 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_toggle_action_set_draw_as_radio (GtkToggleAction *action,
|
|
|
|
gboolean draw_as_radio)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TOGGLE_ACTION (action));
|
|
|
|
|
|
|
|
draw_as_radio = draw_as_radio != FALSE;
|
|
|
|
|
|
|
|
if (action->private_data->draw_as_radio != draw_as_radio)
|
|
|
|
{
|
|
|
|
action->private_data->draw_as_radio = draw_as_radio;
|
|
|
|
|
2005-03-26 05:49:15 +00:00
|
|
|
g_object_notify (G_OBJECT (action), "draw-as-radio");
|
2003-09-21 22:04:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_toggle_action_get_draw_as_radio:
|
|
|
|
* @action: the action object
|
|
|
|
*
|
2003-10-01 22:53:57 +00:00
|
|
|
* Returns whether the action should have proxies like a radio action.
|
|
|
|
*
|
2003-09-21 22:04:48 +00:00
|
|
|
* Returns: whether the action should have proxies like a radio action.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2003-09-21 22:04:48 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_toggle_action_get_draw_as_radio (GtkToggleAction *action)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TOGGLE_ACTION (action), FALSE);
|
|
|
|
|
|
|
|
return action->private_data->draw_as_radio;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *
|
|
|
|
create_menu_item (GtkAction *action)
|
|
|
|
{
|
|
|
|
GtkToggleAction *toggle_action = GTK_TOGGLE_ACTION (action);
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_CHECK_MENU_ITEM,
|
2005-03-26 05:49:15 +00:00
|
|
|
"draw-as-radio", toggle_action->private_data->draw_as_radio,
|
2003-09-21 22:04:48 +00:00
|
|
|
NULL);
|
|
|
|
}
|
2010-07-16 16:34:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Private */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* _gtk_toggle_action_set_active:
|
|
|
|
* @toggle_action: a #GtkToggleAction
|
|
|
|
* @is_active: whether the action is active or not
|
|
|
|
*
|
|
|
|
* Sets the #GtkToggleAction:active property directly. This function does
|
|
|
|
* not emit signals or notifications: it is left to the caller to do so.
|
2013-06-28 15:27:19 +00:00
|
|
|
*
|
|
|
|
* Deprecated: 3.10
|
2010-07-16 16:34:46 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
_gtk_toggle_action_set_active (GtkToggleAction *toggle_action,
|
|
|
|
gboolean is_active)
|
|
|
|
{
|
|
|
|
GtkToggleActionPrivate *priv = toggle_action->private_data;
|
|
|
|
|
|
|
|
priv->active = is_active;
|
|
|
|
}
|