2003-06-29 23:34:20 +00:00
|
|
|
/* gtkradiotoolbutton.c
|
|
|
|
*
|
2003-12-29 10:55:53 +00:00
|
|
|
* Copyright (C) 2002 Anders Carlsson <andersca@gnome.og>
|
2003-06-29 23:34:20 +00:00
|
|
|
* Copyright (C) 2002 James Henstridge <james@daa.com.au>
|
|
|
|
* Copyright (C) 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
|
|
|
*
|
|
|
|
* 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 "gtkradiotoolbutton.h"
|
|
|
|
#include "gtkradiobutton.h"
|
|
|
|
#include "gtkintl.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-15 16:26:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkradiotoolbutton
|
|
|
|
* @Short_description: A toolbar item that contains a radio button
|
|
|
|
* @Title: GtkRadioToolButton
|
|
|
|
* @See_also: #GtkToolbar, #GtkToolButton
|
|
|
|
*
|
|
|
|
* A #GtkRadioToolButton is a #GtkToolItem that contains a radio button,
|
|
|
|
* that is, a button that is part of a group of toggle buttons where only
|
|
|
|
* one button can be active at a time.
|
|
|
|
*
|
2015-11-05 20:41:37 +00:00
|
|
|
* Use gtk_radio_tool_button_new() to create a new GtkRadioToolButton. Use
|
|
|
|
* gtk_radio_tool_button_new_from_widget() to create a new GtkRadioToolButton
|
|
|
|
* that is part of the same group as an existing GtkRadioToolButton.
|
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* GtkRadioToolButton has a single CSS node with name toolbutton.
|
2011-04-15 16:26:46 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2004-01-24 16:49:31 +00:00
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
PROP_GROUP
|
|
|
|
};
|
|
|
|
|
|
|
|
static void gtk_radio_tool_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2006-05-14 04:25:34 +00:00
|
|
|
G_DEFINE_TYPE (GtkRadioToolButton, gtk_radio_tool_button, GTK_TYPE_TOGGLE_TOOL_BUTTON)
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_radio_tool_button_class_init (GtkRadioToolButtonClass *klass)
|
|
|
|
{
|
2004-01-24 16:49:31 +00:00
|
|
|
GObjectClass *object_class;
|
2003-06-29 23:34:20 +00:00
|
|
|
GtkToolButtonClass *toolbutton_class;
|
|
|
|
|
2004-01-24 16:49:31 +00:00
|
|
|
object_class = (GObjectClass *)klass;
|
2003-06-29 23:34:20 +00:00
|
|
|
toolbutton_class = (GtkToolButtonClass *)klass;
|
2004-01-24 16:49:31 +00:00
|
|
|
|
|
|
|
object_class->set_property = gtk_radio_tool_button_set_property;
|
2003-06-29 23:34:20 +00:00
|
|
|
|
|
|
|
toolbutton_class->button_type = GTK_TYPE_RADIO_BUTTON;
|
2004-01-24 16:49:31 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkRadioToolButton:group:
|
|
|
|
*
|
|
|
|
* Sets a new group for a radio tool button.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_GROUP,
|
|
|
|
g_param_spec_object ("group",
|
2008-08-12 11:32:35 +00:00
|
|
|
P_("Group"),
|
|
|
|
P_("The radio tool button whose group this button belongs to."),
|
2004-01-24 16:49:31 +00:00
|
|
|
GTK_TYPE_RADIO_TOOL_BUTTON,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_WRITABLE));
|
2004-01-24 16:49:31 +00:00
|
|
|
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_radio_tool_button_init (GtkRadioToolButton *button)
|
|
|
|
{
|
2003-07-08 18:20:45 +00:00
|
|
|
GtkToolButton *tool_button = GTK_TOOL_BUTTON (button);
|
2017-01-27 11:02:47 +00:00
|
|
|
gtk_check_button_set_draw_indicator (GTK_CHECK_BUTTON (_gtk_tool_button_get_button (tool_button)), FALSE);
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
2004-01-24 16:49:31 +00:00
|
|
|
static void
|
|
|
|
gtk_radio_tool_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkRadioToolButton *button;
|
|
|
|
|
|
|
|
button = GTK_RADIO_TOOL_BUTTON (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_GROUP:
|
|
|
|
{
|
|
|
|
GtkRadioToolButton *arg;
|
|
|
|
GSList *slist = NULL;
|
|
|
|
if (G_VALUE_HOLDS_OBJECT (value))
|
|
|
|
{
|
|
|
|
arg = GTK_RADIO_TOOL_BUTTON (g_value_get_object (value));
|
|
|
|
if (arg)
|
|
|
|
slist = gtk_radio_tool_button_get_group (arg);
|
|
|
|
gtk_radio_tool_button_set_group (button, slist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
/**
|
|
|
|
* gtk_radio_tool_button_new:
|
2013-12-06 22:53:41 +00:00
|
|
|
* @group: (allow-none) (element-type GtkRadioButton): An
|
2011-10-27 18:03:11 +00:00
|
|
|
* existing radio button group, or %NULL if you are creating a new group
|
2003-08-04 21:13:55 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GtkRadioToolButton, adding it to @group.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: The new #GtkRadioToolButton
|
2003-08-04 21:13:55 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
GtkToolItem *
|
|
|
|
gtk_radio_tool_button_new (GSList *group)
|
|
|
|
{
|
|
|
|
GtkRadioToolButton *button;
|
|
|
|
|
|
|
|
button = g_object_new (GTK_TYPE_RADIO_TOOL_BUTTON,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_radio_tool_button_set_group (button, group);
|
|
|
|
|
|
|
|
return GTK_TOOL_ITEM (button);
|
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
/**
|
2011-10-15 17:18:52 +00:00
|
|
|
* gtk_radio_tool_button_new_from_widget: (constructor)
|
2011-10-27 18:03:11 +00:00
|
|
|
* @group: (allow-none): An existing #GtkRadioToolButton, or %NULL
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2003-08-04 21:13:55 +00:00
|
|
|
* Creates a new #GtkRadioToolButton adding it to the same group as @gruup
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: (transfer none): The new #GtkRadioToolButton
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2003-08-04 21:13:55 +00:00
|
|
|
* Since: 2.4
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
GtkToolItem *
|
2003-11-24 03:09:32 +00:00
|
|
|
gtk_radio_tool_button_new_from_widget (GtkRadioToolButton *group)
|
2003-06-29 23:34:20 +00:00
|
|
|
{
|
|
|
|
GSList *list = NULL;
|
|
|
|
|
2011-10-27 18:03:11 +00:00
|
|
|
g_return_val_if_fail (group == NULL || GTK_IS_RADIO_TOOL_BUTTON (group), NULL);
|
2003-06-29 23:34:20 +00:00
|
|
|
|
2011-10-27 18:03:11 +00:00
|
|
|
if (group != NULL)
|
2003-06-29 23:34:20 +00:00
|
|
|
list = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (group));
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
return gtk_radio_tool_button_new (list);
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
static GtkRadioButton *
|
|
|
|
get_radio_button (GtkRadioToolButton *button)
|
|
|
|
{
|
|
|
|
return GTK_RADIO_BUTTON (_gtk_tool_button_get_button (GTK_TOOL_BUTTON (button)));
|
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
/**
|
|
|
|
* gtk_radio_tool_button_get_group:
|
|
|
|
* @button: a #GtkRadioToolButton
|
|
|
|
*
|
|
|
|
* Returns the radio button group @button belongs to.
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: (transfer none) (element-type GtkRadioButton): The group @button belongs to.
|
2010-09-21 04:18:11 +00:00
|
|
|
*
|
2003-08-04 21:13:55 +00:00
|
|
|
* Since: 2.4
|
2010-09-21 04:18:11 +00:00
|
|
|
*/
|
2003-06-29 23:34:20 +00:00
|
|
|
GSList *
|
|
|
|
gtk_radio_tool_button_get_group (GtkRadioToolButton *button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button), NULL);
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
return gtk_radio_button_get_group (get_radio_button (button));
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|
|
|
|
|
2003-08-04 21:13:55 +00:00
|
|
|
/**
|
|
|
|
* gtk_radio_tool_button_set_group:
|
|
|
|
* @button: a #GtkRadioToolButton
|
2013-12-06 22:53:41 +00:00
|
|
|
* @group: (element-type GtkRadioButton) (allow-none): an existing radio button group, or %NULL
|
2003-08-04 21:13:55 +00:00
|
|
|
*
|
|
|
|
* Adds @button to @group, removing it from the group it belonged to before.
|
|
|
|
*
|
|
|
|
* Since: 2.4
|
|
|
|
**/
|
2003-06-29 23:34:20 +00:00
|
|
|
void
|
|
|
|
gtk_radio_tool_button_set_group (GtkRadioToolButton *button,
|
|
|
|
GSList *group)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_RADIO_TOOL_BUTTON (button));
|
|
|
|
|
2003-07-08 18:20:45 +00:00
|
|
|
gtk_radio_button_set_group (get_radio_button (button), group);
|
2003-06-29 23:34:20 +00:00
|
|
|
}
|