mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-10 02:40:11 +00:00
Add value parameter to allow setting the currently selected group member
2003-09-15 Matthias Clasen <maclas@gmx.de> * gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions): (gtk_action_group_add_radio_actions_full): Add value parameter to allow setting the currently selected group member before connecting signals. (GtkToggleActionEntry): Separate struct for constructing toggle actions, including a boolean to initialize the action state before connecting signals. (gtk_action_group_add_toggle_actions): (gtk_action_group_add_toggle_actions_full): New functions to construct toggle actions from an array of GtkToggleActionEntries. * demos/gtk-demo/appwindow.c: * tests/testactions.c: * tests/testmerge.c: Adjust to new action group API. * gtk/gtk-sections.txt: Add gtk_action_group_add_toggle_actions[_full].
This commit is contained in:
parent
b14b12f9d2
commit
caf380c793
16
ChangeLog
16
ChangeLog
@ -1,3 +1,19 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions):
|
||||||
|
(gtk_action_group_add_radio_actions_full): Add value parameter to allow
|
||||||
|
setting the currently selected group member before connecting signals.
|
||||||
|
(GtkToggleActionEntry): Separate struct for constructing toggle actions,
|
||||||
|
including a boolean to initialize the action state before connecting
|
||||||
|
signals.
|
||||||
|
(gtk_action_group_add_toggle_actions):
|
||||||
|
(gtk_action_group_add_toggle_actions_full): New functions to construct
|
||||||
|
toggle actions from an array of GtkToggleActionEntries.
|
||||||
|
|
||||||
|
* demos/gtk-demo/appwindow.c:
|
||||||
|
* tests/testactions.c:
|
||||||
|
* tests/testmerge.c: Adjust to new action group API.
|
||||||
|
|
||||||
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions):
|
||||||
|
(gtk_action_group_add_radio_actions_full): Add value parameter to allow
|
||||||
|
setting the currently selected group member before connecting signals.
|
||||||
|
(GtkToggleActionEntry): Separate struct for constructing toggle actions,
|
||||||
|
including a boolean to initialize the action state before connecting
|
||||||
|
signals.
|
||||||
|
(gtk_action_group_add_toggle_actions):
|
||||||
|
(gtk_action_group_add_toggle_actions_full): New functions to construct
|
||||||
|
toggle actions from an array of GtkToggleActionEntries.
|
||||||
|
|
||||||
|
* demos/gtk-demo/appwindow.c:
|
||||||
|
* tests/testactions.c:
|
||||||
|
* tests/testmerge.c: Adjust to new action group API.
|
||||||
|
|
||||||
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions):
|
||||||
|
(gtk_action_group_add_radio_actions_full): Add value parameter to allow
|
||||||
|
setting the currently selected group member before connecting signals.
|
||||||
|
(GtkToggleActionEntry): Separate struct for constructing toggle actions,
|
||||||
|
including a boolean to initialize the action state before connecting
|
||||||
|
signals.
|
||||||
|
(gtk_action_group_add_toggle_actions):
|
||||||
|
(gtk_action_group_add_toggle_actions_full): New functions to construct
|
||||||
|
toggle actions from an array of GtkToggleActionEntries.
|
||||||
|
|
||||||
|
* demos/gtk-demo/appwindow.c:
|
||||||
|
* tests/testactions.c:
|
||||||
|
* tests/testmerge.c: Adjust to new action group API.
|
||||||
|
|
||||||
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions):
|
||||||
|
(gtk_action_group_add_radio_actions_full): Add value parameter to allow
|
||||||
|
setting the currently selected group member before connecting signals.
|
||||||
|
(GtkToggleActionEntry): Separate struct for constructing toggle actions,
|
||||||
|
including a boolean to initialize the action state before connecting
|
||||||
|
signals.
|
||||||
|
(gtk_action_group_add_toggle_actions):
|
||||||
|
(gtk_action_group_add_toggle_actions_full): New functions to construct
|
||||||
|
toggle actions from an array of GtkToggleActionEntries.
|
||||||
|
|
||||||
|
* demos/gtk-demo/appwindow.c:
|
||||||
|
* tests/testactions.c:
|
||||||
|
* tests/testmerge.c: Adjust to new action group API.
|
||||||
|
|
||||||
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
||||||
|
@ -1,3 +1,19 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtkactiongroup.[hc]: (gtk_action_group_add_radio_actions):
|
||||||
|
(gtk_action_group_add_radio_actions_full): Add value parameter to allow
|
||||||
|
setting the currently selected group member before connecting signals.
|
||||||
|
(GtkToggleActionEntry): Separate struct for constructing toggle actions,
|
||||||
|
including a boolean to initialize the action state before connecting
|
||||||
|
signals.
|
||||||
|
(gtk_action_group_add_toggle_actions):
|
||||||
|
(gtk_action_group_add_toggle_actions_full): New functions to construct
|
||||||
|
toggle actions from an array of GtkToggleActionEntries.
|
||||||
|
|
||||||
|
* demos/gtk-demo/appwindow.c:
|
||||||
|
* tests/testactions.c:
|
||||||
|
* tests/testmerge.c: Adjust to new action group API.
|
||||||
|
|
||||||
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
Sun Sep 14 16:59:52 2003 Soeren Sandmann <sandmann@daimi.au.dk>
|
||||||
|
|
||||||
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
* gtk/gtktoolbar.c (gtk_toolbar_init): Name the arrow
|
||||||
|
@ -99,6 +99,16 @@ static GtkActionEntry entries[] = {
|
|||||||
};
|
};
|
||||||
static guint n_entries = G_N_ELEMENTS (entries);
|
static guint n_entries = G_N_ELEMENTS (entries);
|
||||||
|
|
||||||
|
|
||||||
|
static GtkToggleActionEntry toggle_entries[] = {
|
||||||
|
{ "Bold", GTK_STOCK_BOLD, /* name, stock id */
|
||||||
|
"_Bold", "<control>B", /* label, accelerator */
|
||||||
|
"Bold", /* tooltip */
|
||||||
|
G_CALLBACK (activate_action),
|
||||||
|
TRUE }, /* is_active */
|
||||||
|
};
|
||||||
|
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
COLOR_RED,
|
COLOR_RED,
|
||||||
COLOR_GREEN,
|
COLOR_GREEN,
|
||||||
@ -159,6 +169,7 @@ static const gchar *ui_info =
|
|||||||
" <menuitem action='Rectangle'/>"
|
" <menuitem action='Rectangle'/>"
|
||||||
" <menuitem action='Oval'/>"
|
" <menuitem action='Oval'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
|
" <menuitem action='Bold'/>"
|
||||||
" </menu>"
|
" </menu>"
|
||||||
" <menu action='HelpMenu'>"
|
" <menu action='HelpMenu'>"
|
||||||
" <menuitem action='About'/>"
|
" <menuitem action='About'/>"
|
||||||
@ -300,7 +311,6 @@ do_appwindow (void)
|
|||||||
GtkWidget *bar;
|
GtkWidget *bar;
|
||||||
GtkTextBuffer *buffer;
|
GtkTextBuffer *buffer;
|
||||||
GtkActionGroup *action_group;
|
GtkActionGroup *action_group;
|
||||||
GtkAction *action;
|
|
||||||
GtkUIManager *merge;
|
GtkUIManager *merge;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
@ -325,18 +335,25 @@ do_appwindow (void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
action_group = gtk_action_group_new ("AppWindowActions");
|
action_group = gtk_action_group_new ("AppWindowActions");
|
||||||
gtk_action_group_add_actions (action_group, entries, n_entries, NULL);
|
gtk_action_group_add_actions (action_group,
|
||||||
gtk_action_group_add_radio_actions (action_group, color_entries, n_color_entries,
|
entries, n_entries,
|
||||||
G_CALLBACK (activate_radio_action), NULL);
|
NULL);
|
||||||
gtk_action_group_add_radio_actions (action_group, shape_entries, n_shape_entries,
|
gtk_action_group_add_toggle_actions (action_group,
|
||||||
G_CALLBACK (activate_radio_action), NULL);
|
toggle_entries, n_toggle_entries,
|
||||||
|
NULL);
|
||||||
action = gtk_action_group_get_action (action_group, "Red");
|
gtk_action_group_add_radio_actions (action_group,
|
||||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
|
color_entries, n_color_entries,
|
||||||
action = gtk_action_group_get_action (action_group, "Square");
|
COLOR_RED,
|
||||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
|
G_CALLBACK (activate_radio_action),
|
||||||
|
NULL);
|
||||||
|
gtk_action_group_add_radio_actions (action_group,
|
||||||
|
shape_entries, n_shape_entries,
|
||||||
|
SHAPE_SQUARE,
|
||||||
|
G_CALLBACK (activate_radio_action),
|
||||||
|
NULL);
|
||||||
|
|
||||||
merge = gtk_ui_manager_new ();
|
merge = gtk_ui_manager_new ();
|
||||||
|
g_object_set_data_full (G_OBJECT (window), "ui-manager", merge, g_object_unref);
|
||||||
gtk_ui_manager_insert_action_group (merge, action_group, 0);
|
gtk_ui_manager_insert_action_group (merge, action_group, 0);
|
||||||
gtk_window_add_accel_group (GTK_WINDOW (window),
|
gtk_window_add_accel_group (GTK_WINDOW (window),
|
||||||
gtk_ui_manager_get_accel_group (merge));
|
gtk_ui_manager_get_accel_group (merge));
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
2003-09-15 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
|
* gtk/gtk-sections.txt: Add gtk_action_group_add_toggle_actions[_full].
|
||||||
|
|
||||||
2003-09-12 Matthias Clasen <maclas@gmx.de>
|
2003-09-12 Matthias Clasen <maclas@gmx.de>
|
||||||
|
|
||||||
* gdk/tmpl/drawing.sgml: Add deprecation note for gdk_draw_pixmap().
|
* gdk/tmpl/drawing.sgml: Add deprecation note for gdk_draw_pixmap().
|
||||||
|
@ -130,16 +130,19 @@ GtkActionPrivate
|
|||||||
<FILE>gtkactiongroup</FILE>
|
<FILE>gtkactiongroup</FILE>
|
||||||
<TITLE>GtkActionGroup</TITLE>
|
<TITLE>GtkActionGroup</TITLE>
|
||||||
GtkActionGroup
|
GtkActionGroup
|
||||||
GtkActionEntry
|
|
||||||
GtkRadioActionEntry
|
|
||||||
gtk_action_group_new
|
gtk_action_group_new
|
||||||
gtk_action_group_get_name
|
gtk_action_group_get_name
|
||||||
gtk_action_group_get_action
|
gtk_action_group_get_action
|
||||||
gtk_action_group_list_actions
|
gtk_action_group_list_actions
|
||||||
gtk_action_group_add_action
|
gtk_action_group_add_action
|
||||||
gtk_action_group_remove_action
|
gtk_action_group_remove_action
|
||||||
|
GtkActionEntry
|
||||||
gtk_action_group_add_actions
|
gtk_action_group_add_actions
|
||||||
gtk_action_group_add_actions_full
|
gtk_action_group_add_actions_full
|
||||||
|
GtkToggleActionEntry
|
||||||
|
gtk_action_group_add_toggle_actions
|
||||||
|
gtk_action_group_add_toggle_actions_full
|
||||||
|
GtkRadioActionEntry
|
||||||
gtk_action_group_add_radio_actions
|
gtk_action_group_add_radio_actions
|
||||||
gtk_action_group_add_radio_actions_full
|
gtk_action_group_add_radio_actions_full
|
||||||
gtk_action_group_set_translate_func
|
gtk_action_group_set_translate_func
|
||||||
@ -1734,6 +1737,7 @@ gtk_ui_manager_get_action
|
|||||||
gtk_ui_manager_add_ui_from_string
|
gtk_ui_manager_add_ui_from_string
|
||||||
gtk_ui_manager_add_ui_from_file
|
gtk_ui_manager_add_ui_from_file
|
||||||
gtk_ui_manager_new_merge_id
|
gtk_ui_manager_new_merge_id
|
||||||
|
GtkUIManagerItemType
|
||||||
gtk_ui_manager_add_ui
|
gtk_ui_manager_add_ui
|
||||||
gtk_ui_manager_remove_ui
|
gtk_ui_manager_remove_ui
|
||||||
gtk_ui_manager_get_ui
|
gtk_ui_manager_get_ui
|
||||||
|
@ -48,8 +48,12 @@ struct _GtkActionGroupPrivate
|
|||||||
GtkDestroyNotify translate_notify;
|
GtkDestroyNotify translate_notify;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gtk_action_group_init (GtkActionGroup *self);
|
static void gtk_action_group_init (GtkActionGroup *self);
|
||||||
static void gtk_action_group_class_init (GtkActionGroupClass *class);
|
static void gtk_action_group_class_init (GtkActionGroupClass *class);
|
||||||
|
static void gtk_action_group_finalize (GObject *object);
|
||||||
|
static GtkAction *gtk_action_group_real_get_action (GtkActionGroup *self,
|
||||||
|
const gchar *name);
|
||||||
|
|
||||||
|
|
||||||
GType
|
GType
|
||||||
gtk_action_group_get_type (void)
|
gtk_action_group_get_type (void)
|
||||||
@ -79,9 +83,6 @@ gtk_action_group_get_type (void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static GObjectClass *parent_class = NULL;
|
static GObjectClass *parent_class = NULL;
|
||||||
static void gtk_action_group_finalize (GObject *object);
|
|
||||||
static GtkAction *gtk_action_group_real_get_action (GtkActionGroup *self,
|
|
||||||
const gchar *name);
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_action_group_class_init (GtkActionGroupClass *klass)
|
gtk_action_group_class_init (GtkActionGroupClass *klass)
|
||||||
@ -284,8 +285,8 @@ gtk_action_group_list_actions (GtkActionGroup *action_group)
|
|||||||
* @n_entries: the number of entries
|
* @n_entries: the number of entries
|
||||||
* @user_data: data to pass to the action callbacks
|
* @user_data: data to pass to the action callbacks
|
||||||
*
|
*
|
||||||
* This is a convenience function to create a number of actions and add them to the
|
* This is a convenience function to create a number of actions and add them
|
||||||
* action group.
|
* to the action group.
|
||||||
*
|
*
|
||||||
* The "activate" signals of the actions are connected to the callbacks and
|
* The "activate" signals of the actions are connected to the callbacks and
|
||||||
* their accel paths are set to
|
* their accel paths are set to
|
||||||
@ -337,16 +338,10 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
|
|||||||
for (i = 0; i < n_entries; i++)
|
for (i = 0; i < n_entries; i++)
|
||||||
{
|
{
|
||||||
GtkAction *action;
|
GtkAction *action;
|
||||||
GType action_type;
|
|
||||||
gchar *accel_path;
|
gchar *accel_path;
|
||||||
gchar *label;
|
gchar *label;
|
||||||
gchar *tooltip;
|
gchar *tooltip;
|
||||||
|
|
||||||
if (entries[i].is_toggle)
|
|
||||||
action_type = GTK_TYPE_TOGGLE_ACTION;
|
|
||||||
else
|
|
||||||
action_type = GTK_TYPE_ACTION;
|
|
||||||
|
|
||||||
if (translate_func)
|
if (translate_func)
|
||||||
{
|
{
|
||||||
label = translate_func (entries[i].label, translate_data);
|
label = translate_func (entries[i].label, translate_data);
|
||||||
@ -358,7 +353,7 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
|
|||||||
tooltip = entries[i].tooltip;
|
tooltip = entries[i].tooltip;
|
||||||
}
|
}
|
||||||
|
|
||||||
action = g_object_new (action_type,
|
action = g_object_new (GTK_TYPE_ACTION,
|
||||||
"name", entries[i].name,
|
"name", entries[i].name,
|
||||||
"label", label,
|
"label", label,
|
||||||
"tooltip", tooltip,
|
"tooltip", tooltip,
|
||||||
@ -392,19 +387,133 @@ gtk_action_group_add_actions_full (GtkActionGroup *action_group,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_action_group_add_toggle_actions:
|
||||||
|
* @action_group: the action group
|
||||||
|
* @entries: an array of toggle action descriptions
|
||||||
|
* @n_entries: the number of entries
|
||||||
|
* @user_data: data to pass to the action callbacks
|
||||||
|
*
|
||||||
|
* This is a convenience function to create a number of toggle actions and add them
|
||||||
|
* to the action group.
|
||||||
|
*
|
||||||
|
* The "activate" signals of the actions are connected to the callbacks and
|
||||||
|
* their accel paths are set to
|
||||||
|
* <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
|
||||||
|
*
|
||||||
|
* Since: 2.4
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
|
||||||
|
GtkToggleActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
gtk_action_group_add_toggle_actions_full (action_group,
|
||||||
|
entries, n_entries,
|
||||||
|
user_data, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gtk_action_group_add_toggle_actions_full:
|
||||||
|
* @action_group: the action group
|
||||||
|
* @entries: an array of toggle action descriptions
|
||||||
|
* @n_entries: the number of entries
|
||||||
|
* @user_data: data to pass to the action callbacks
|
||||||
|
* @destroy: destroy notification callback for @user_data
|
||||||
|
*
|
||||||
|
* This variant of gtk_action_group_add_toggle_actions() adds a
|
||||||
|
* #GDestroyNotify callback for @user_data.
|
||||||
|
*
|
||||||
|
* Since: 2.4
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
|
||||||
|
GtkToggleActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data,
|
||||||
|
GDestroyNotify destroy)
|
||||||
|
{
|
||||||
|
guint i;
|
||||||
|
GtkTranslateFunc translate_func;
|
||||||
|
gpointer translate_data;
|
||||||
|
|
||||||
|
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
|
||||||
|
|
||||||
|
translate_func = action_group->private_data->translate_func;
|
||||||
|
translate_data = action_group->private_data->translate_data;
|
||||||
|
|
||||||
|
for (i = 0; i < n_entries; i++)
|
||||||
|
{
|
||||||
|
GtkAction *action;
|
||||||
|
gchar *accel_path;
|
||||||
|
gchar *label;
|
||||||
|
gchar *tooltip;
|
||||||
|
|
||||||
|
if (translate_func)
|
||||||
|
{
|
||||||
|
label = translate_func (entries[i].label, translate_data);
|
||||||
|
tooltip = translate_func (entries[i].tooltip, translate_data);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
label = entries[i].label;
|
||||||
|
tooltip = entries[i].tooltip;
|
||||||
|
}
|
||||||
|
|
||||||
|
action = g_object_new (GTK_TYPE_TOGGLE_ACTION,
|
||||||
|
"name", entries[i].name,
|
||||||
|
"label", label,
|
||||||
|
"tooltip", tooltip,
|
||||||
|
"stock_id", entries[i].stock_id,
|
||||||
|
NULL);
|
||||||
|
|
||||||
|
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
|
||||||
|
entries[i].is_active);
|
||||||
|
|
||||||
|
if (entries[i].callback)
|
||||||
|
g_signal_connect_data (action, "activate",
|
||||||
|
entries[i].callback,
|
||||||
|
user_data, (GClosureNotify)destroy, 0);
|
||||||
|
|
||||||
|
/* set the accel path for the menu item */
|
||||||
|
accel_path = g_strconcat ("<Actions>/", action_group->private_data->name, "/",
|
||||||
|
entries[i].name, NULL);
|
||||||
|
if (entries[i].accelerator)
|
||||||
|
{
|
||||||
|
guint accel_key = 0;
|
||||||
|
GdkModifierType accel_mods;
|
||||||
|
|
||||||
|
gtk_accelerator_parse (entries[i].accelerator, &accel_key,
|
||||||
|
&accel_mods);
|
||||||
|
if (accel_key)
|
||||||
|
gtk_accel_map_add_entry (accel_path, accel_key, accel_mods);
|
||||||
|
}
|
||||||
|
|
||||||
|
gtk_action_set_accel_path (action, accel_path);
|
||||||
|
g_free (accel_path);
|
||||||
|
|
||||||
|
gtk_action_group_add_action (action_group, action);
|
||||||
|
g_object_unref (action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_action_group_add_radio_actions:
|
* gtk_action_group_add_radio_actions:
|
||||||
* @action_group: the action group
|
* @action_group: the action group
|
||||||
* @entries: an array of radio action descriptions
|
* @entries: an array of radio action descriptions
|
||||||
* @n_entries: the number of entries
|
* @n_entries: the number of entries
|
||||||
|
* @value: the value of the action to activate initially, or -1 if
|
||||||
|
* no action should be activated
|
||||||
* @on_change: the callback to connect to the changed signal
|
* @on_change: the callback to connect to the changed signal
|
||||||
* @user_data: data to pass to the action callbacks
|
* @user_data: data to pass to the action callbacks
|
||||||
*
|
*
|
||||||
* This is a convenience routine to create a group of radio actions and
|
* This is a convenience routine to create a group of radio actions and
|
||||||
* add them to the action group.
|
* add them to the action group.
|
||||||
*
|
*
|
||||||
* The"changed" signal of the first radio action is connected to the @on_change
|
* The "changed" signal of the first radio action is connected to the
|
||||||
* callback and the accel paths of the actions are set to
|
* @on_change callback and the accel paths of the actions are set to
|
||||||
* <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
|
* <literal><Actions>/<replaceable>group-name</replaceable>/<replaceable>action-name</replaceable></literal>.
|
||||||
*
|
*
|
||||||
* Since: 2.4
|
* Since: 2.4
|
||||||
@ -413,11 +522,13 @@ void
|
|||||||
gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
|
gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
|
||||||
GtkRadioActionEntry *entries,
|
GtkRadioActionEntry *entries,
|
||||||
guint n_entries,
|
guint n_entries,
|
||||||
|
gint value,
|
||||||
GCallback on_change,
|
GCallback on_change,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
gtk_action_group_add_radio_actions_full (action_group,
|
gtk_action_group_add_radio_actions_full (action_group,
|
||||||
entries, n_entries,
|
entries, n_entries,
|
||||||
|
value,
|
||||||
on_change, user_data, NULL);
|
on_change, user_data, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,6 +537,8 @@ gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
|
|||||||
* @action_group: the action group
|
* @action_group: the action group
|
||||||
* @entries: an array of radio action descriptions
|
* @entries: an array of radio action descriptions
|
||||||
* @n_entries: the number of entries
|
* @n_entries: the number of entries
|
||||||
|
* @value: the value of the action to activate initially, or -1 if
|
||||||
|
* no action should be activated
|
||||||
* @on_change: the callback to connect to the changed signal
|
* @on_change: the callback to connect to the changed signal
|
||||||
* @user_data: data to pass to the action callbacks
|
* @user_data: data to pass to the action callbacks
|
||||||
* @destroy: destroy notification callback for @user_data
|
* @destroy: destroy notification callback for @user_data
|
||||||
@ -439,6 +552,7 @@ void
|
|||||||
gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
||||||
GtkRadioActionEntry *entries,
|
GtkRadioActionEntry *entries,
|
||||||
guint n_entries,
|
guint n_entries,
|
||||||
|
gint value,
|
||||||
GCallback on_change,
|
GCallback on_change,
|
||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
GDestroyNotify destroy)
|
GDestroyNotify destroy)
|
||||||
@ -447,6 +561,7 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
|||||||
GtkTranslateFunc translate_func;
|
GtkTranslateFunc translate_func;
|
||||||
gpointer translate_data;
|
gpointer translate_data;
|
||||||
GSList *group = NULL;
|
GSList *group = NULL;
|
||||||
|
GtkAction *first_action;
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
|
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
|
||||||
|
|
||||||
@ -478,14 +593,13 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
|||||||
"stock_id", entries[i].stock_id,
|
"stock_id", entries[i].stock_id,
|
||||||
"value", entries[i].value,
|
"value", entries[i].value,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
first_action = action;
|
||||||
if (on_change)
|
|
||||||
g_signal_connect_data (action, "changed",
|
if (value == entries[i].value)
|
||||||
on_change, user_data,
|
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
|
||||||
(GClosureNotify)destroy, 0);
|
|
||||||
}
|
|
||||||
gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
|
gtk_radio_action_set_group (GTK_RADIO_ACTION (action), group);
|
||||||
group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
|
group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
|
||||||
|
|
||||||
@ -509,6 +623,11 @@ gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
|||||||
gtk_action_group_add_action (action_group, action);
|
gtk_action_group_add_action (action_group, action);
|
||||||
g_object_unref (action);
|
g_object_unref (action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (on_change)
|
||||||
|
g_signal_connect_data (first_action, "changed",
|
||||||
|
on_change, user_data,
|
||||||
|
(GClosureNotify)destroy, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,6 +44,7 @@ typedef struct _GtkActionGroup GtkActionGroup;
|
|||||||
typedef struct _GtkActionGroupPrivate GtkActionGroupPrivate;
|
typedef struct _GtkActionGroupPrivate GtkActionGroupPrivate;
|
||||||
typedef struct _GtkActionGroupClass GtkActionGroupClass;
|
typedef struct _GtkActionGroupClass GtkActionGroupClass;
|
||||||
typedef struct _GtkActionEntry GtkActionEntry;
|
typedef struct _GtkActionEntry GtkActionEntry;
|
||||||
|
typedef struct _GtkToggleActionEntry GtkToggleActionEntry;
|
||||||
typedef struct _GtkRadioActionEntry GtkRadioActionEntry;
|
typedef struct _GtkRadioActionEntry GtkRadioActionEntry;
|
||||||
|
|
||||||
struct _GtkActionGroup
|
struct _GtkActionGroup
|
||||||
@ -71,15 +72,23 @@ struct _GtkActionGroupClass
|
|||||||
|
|
||||||
struct _GtkActionEntry
|
struct _GtkActionEntry
|
||||||
{
|
{
|
||||||
gchar *name;
|
gchar *name;
|
||||||
gchar *stock_id;
|
gchar *stock_id;
|
||||||
gchar *label;
|
gchar *label;
|
||||||
gchar *accelerator;
|
gchar *accelerator;
|
||||||
gchar *tooltip;
|
gchar *tooltip;
|
||||||
|
GCallback callback;
|
||||||
|
};
|
||||||
|
|
||||||
GCallback callback;
|
struct _GtkToggleActionEntry
|
||||||
|
{
|
||||||
gboolean is_toggle;
|
gchar *name;
|
||||||
|
gchar *stock_id;
|
||||||
|
gchar *label;
|
||||||
|
gchar *accelerator;
|
||||||
|
gchar *tooltip;
|
||||||
|
GCallback callback;
|
||||||
|
gboolean is_active;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GtkRadioActionEntry
|
struct _GtkRadioActionEntry
|
||||||
@ -89,50 +98,56 @@ struct _GtkRadioActionEntry
|
|||||||
gchar *label;
|
gchar *label;
|
||||||
gchar *accelerator;
|
gchar *accelerator;
|
||||||
gchar *tooltip;
|
gchar *tooltip;
|
||||||
|
gint value;
|
||||||
gint value;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gtk_action_group_get_type (void);
|
GType gtk_action_group_get_type (void);
|
||||||
|
GtkActionGroup *gtk_action_group_new (const gchar *name);
|
||||||
|
const gchar *gtk_action_group_get_name (GtkActionGroup *action_group);
|
||||||
|
GtkAction *gtk_action_group_get_action (GtkActionGroup *action_group,
|
||||||
|
const gchar *action_name);
|
||||||
|
GList *gtk_action_group_list_actions (GtkActionGroup *action_group);
|
||||||
|
void gtk_action_group_add_action (GtkActionGroup *action_group,
|
||||||
|
GtkAction *action);
|
||||||
|
void gtk_action_group_remove_action (GtkActionGroup *action_group,
|
||||||
|
GtkAction *action);
|
||||||
|
void gtk_action_group_add_actions (GtkActionGroup *action_group,
|
||||||
|
GtkActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data);
|
||||||
|
void gtk_action_group_add_toggle_actions (GtkActionGroup *action_group,
|
||||||
|
GtkToggleActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data);
|
||||||
|
void gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
|
||||||
|
GtkRadioActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gint value,
|
||||||
|
GCallback on_change,
|
||||||
|
gpointer user_data);
|
||||||
|
void gtk_action_group_add_actions_full (GtkActionGroup *action_group,
|
||||||
|
GtkActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data,
|
||||||
|
GDestroyNotify destroy);
|
||||||
|
void gtk_action_group_add_toggle_actions_full (GtkActionGroup *action_group,
|
||||||
|
GtkToggleActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gpointer user_data,
|
||||||
|
GDestroyNotify destroy);
|
||||||
|
void gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
||||||
|
GtkRadioActionEntry *entries,
|
||||||
|
guint n_entries,
|
||||||
|
gint value,
|
||||||
|
GCallback on_change,
|
||||||
|
gpointer user_data,
|
||||||
|
GDestroyNotify destroy);
|
||||||
|
void gtk_action_group_set_translate_func (GtkActionGroup *action_group,
|
||||||
|
GtkTranslateFunc func,
|
||||||
|
gpointer data,
|
||||||
|
GtkDestroyNotify notify);
|
||||||
|
void gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
|
||||||
|
const gchar *domain);
|
||||||
|
|
||||||
GtkActionGroup *gtk_action_group_new (const gchar *name);
|
|
||||||
|
|
||||||
const gchar *gtk_action_group_get_name (GtkActionGroup *action_group);
|
|
||||||
GtkAction *gtk_action_group_get_action (GtkActionGroup *action_group,
|
|
||||||
const gchar *action_name);
|
|
||||||
GList *gtk_action_group_list_actions (GtkActionGroup *action_group);
|
|
||||||
void gtk_action_group_add_action (GtkActionGroup *action_group,
|
|
||||||
GtkAction *action);
|
|
||||||
void gtk_action_group_remove_action (GtkActionGroup *action_group,
|
|
||||||
GtkAction *action);
|
|
||||||
|
|
||||||
void gtk_action_group_add_actions (GtkActionGroup *action_group,
|
|
||||||
GtkActionEntry *entries,
|
|
||||||
guint n_entries,
|
|
||||||
gpointer user_data);
|
|
||||||
void gtk_action_group_add_radio_actions (GtkActionGroup *action_group,
|
|
||||||
GtkRadioActionEntry *entries,
|
|
||||||
guint n_entries,
|
|
||||||
GCallback on_change,
|
|
||||||
gpointer user_data);
|
|
||||||
void gtk_action_group_add_actions_full (GtkActionGroup *action_group,
|
|
||||||
GtkActionEntry *entries,
|
|
||||||
guint n_entries,
|
|
||||||
gpointer user_data,
|
|
||||||
GDestroyNotify destroy);
|
|
||||||
void gtk_action_group_add_radio_actions_full (GtkActionGroup *action_group,
|
|
||||||
GtkRadioActionEntry *entries,
|
|
||||||
guint n_entries,
|
|
||||||
GCallback on_change,
|
|
||||||
gpointer user_data,
|
|
||||||
GDestroyNotify destroy);
|
|
||||||
|
|
||||||
void gtk_action_group_set_translate_func (GtkActionGroup *action_group,
|
|
||||||
GtkTranslateFunc func,
|
|
||||||
gpointer data,
|
|
||||||
GtkDestroyNotify notify);
|
|
||||||
|
|
||||||
void gtk_action_group_set_translation_domain (GtkActionGroup *action_group,
|
|
||||||
const gchar *domain);
|
|
||||||
|
|
||||||
#endif /* __GTK_ACTION_GROUP_H__ */
|
#endif /* __GTK_ACTION_GROUP_H__ */
|
||||||
|
@ -100,12 +100,8 @@ static GtkActionEntry entries[] = {
|
|||||||
"Copy the selected text to the clipboard", G_CALLBACK (activate_action) },
|
"Copy the selected text to the clipboard", G_CALLBACK (activate_action) },
|
||||||
{ "paste", GTK_STOCK_PASTE, "_Paste", "<control>V",
|
{ "paste", GTK_STOCK_PASTE, "_Paste", "<control>V",
|
||||||
"Paste the text from the clipboard", G_CALLBACK (activate_action) },
|
"Paste the text from the clipboard", G_CALLBACK (activate_action) },
|
||||||
{ "bold", GTK_STOCK_BOLD, "_Bold", "<control>B",
|
|
||||||
"Change to bold face", G_CALLBACK (toggle_action), TRUE },
|
|
||||||
{ "quit", GTK_STOCK_QUIT, NULL, "<control>Q",
|
{ "quit", GTK_STOCK_QUIT, NULL, "<control>Q",
|
||||||
"Quit the application", G_CALLBACK (gtk_main_quit) },
|
"Quit the application", G_CALLBACK (gtk_main_quit) },
|
||||||
{ "toggle-cnp", NULL, "Enable Cut/Copy/Paste", NULL,
|
|
||||||
"Change the sensitivity of the cut, copy and paste actions", G_CALLBACK (toggle_cnp_actions), TRUE },
|
|
||||||
{ "customise-accels", NULL, "Customise _Accels", NULL,
|
{ "customise-accels", NULL, "Customise _Accels", NULL,
|
||||||
"Customise keyboard shortcuts", G_CALLBACK (show_accel_dialog) },
|
"Customise keyboard shortcuts", G_CALLBACK (show_accel_dialog) },
|
||||||
{ "toolbar-small-icons", NULL, "Small Icons", NULL,
|
{ "toolbar-small-icons", NULL, "Small Icons", NULL,
|
||||||
@ -115,6 +111,16 @@ static GtkActionEntry entries[] = {
|
|||||||
};
|
};
|
||||||
static guint n_entries = G_N_ELEMENTS (entries);
|
static guint n_entries = G_N_ELEMENTS (entries);
|
||||||
|
|
||||||
|
static GtkToggleActionEntry toggle_entries[] = {
|
||||||
|
{ "bold", GTK_STOCK_BOLD, "_Bold", "<control>B",
|
||||||
|
"Change to bold face",
|
||||||
|
G_CALLBACK (toggle_action), FALSE },
|
||||||
|
{ "toggle-cnp", NULL, "Enable Cut/Copy/Paste", NULL,
|
||||||
|
"Change the sensitivity of the cut, copy and paste actions",
|
||||||
|
G_CALLBACK (toggle_cnp_actions), TRUE },
|
||||||
|
};
|
||||||
|
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
JUSTIFY_LEFT,
|
JUSTIFY_LEFT,
|
||||||
JUSTIFY_CENTER,
|
JUSTIFY_CENTER,
|
||||||
@ -254,15 +260,21 @@ main (int argc, char **argv)
|
|||||||
gtk_accel_map_load ("accels");
|
gtk_accel_map_load ("accels");
|
||||||
|
|
||||||
action_group = gtk_action_group_new ("TestActions");
|
action_group = gtk_action_group_new ("TestActions");
|
||||||
gtk_action_group_add_actions (action_group, entries, n_entries, NULL);
|
gtk_action_group_add_actions (action_group,
|
||||||
gtk_action_group_add_radio_actions (action_group, justify_entries, n_justify_entries,
|
entries, n_entries,
|
||||||
|
NULL);
|
||||||
|
gtk_action_group_add_toggle_actions (action_group,
|
||||||
|
toggle_entries, n_toggle_entries,
|
||||||
|
NULL);
|
||||||
|
gtk_action_group_add_radio_actions (action_group,
|
||||||
|
justify_entries, n_justify_entries,
|
||||||
|
JUSTIFY_LEFT,
|
||||||
G_CALLBACK (radio_action), NULL);
|
G_CALLBACK (radio_action), NULL);
|
||||||
gtk_action_group_add_radio_actions (action_group, toolbar_entries, n_toolbar_entries,
|
gtk_action_group_add_radio_actions (action_group,
|
||||||
|
toolbar_entries, n_toolbar_entries,
|
||||||
|
GTK_TOOLBAR_BOTH,
|
||||||
G_CALLBACK (radio_action), NULL);
|
G_CALLBACK (radio_action), NULL);
|
||||||
|
|
||||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (gtk_action_group_get_action (action_group, "toggle-cnp")),
|
|
||||||
FALSE);
|
|
||||||
|
|
||||||
create_window (action_group);
|
create_window (action_group);
|
||||||
|
|
||||||
gtk_main ();
|
gtk_main ();
|
||||||
|
@ -126,10 +126,15 @@ static GtkActionEntry entries[] = {
|
|||||||
{ "CopyAction", GTK_STOCK_COPY, NULL, "<control>c", NULL, G_CALLBACK (activate_action) },
|
{ "CopyAction", GTK_STOCK_COPY, NULL, "<control>c", NULL, G_CALLBACK (activate_action) },
|
||||||
{ "PasteAction", GTK_STOCK_PASTE, NULL, "<control>v", NULL, G_CALLBACK (activate_action) },
|
{ "PasteAction", GTK_STOCK_PASTE, NULL, "<control>v", NULL, G_CALLBACK (activate_action) },
|
||||||
{ "AboutAction", NULL, "_About", NULL, NULL, G_CALLBACK (activate_action) },
|
{ "AboutAction", NULL, "_About", NULL, NULL, G_CALLBACK (activate_action) },
|
||||||
{ "BoldAction", GTK_STOCK_BOLD, "_Bold", "<control>b", NULL, G_CALLBACK (toggle_action), TRUE },
|
|
||||||
};
|
};
|
||||||
static guint n_entries = G_N_ELEMENTS (entries);
|
static guint n_entries = G_N_ELEMENTS (entries);
|
||||||
|
|
||||||
|
static GtkToggleActionEntry toggle_entries[] = {
|
||||||
|
{ "BoldAction", GTK_STOCK_BOLD, "_Bold", "<control>b", NULL, G_CALLBACK (toggle_action),
|
||||||
|
TRUE },
|
||||||
|
};
|
||||||
|
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
JUSTIFY_LEFT,
|
JUSTIFY_LEFT,
|
||||||
JUSTIFY_CENTER,
|
JUSTIFY_CENTER,
|
||||||
@ -442,9 +447,15 @@ main (int argc, char **argv)
|
|||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
action_group = gtk_action_group_new ("TestActions");
|
action_group = gtk_action_group_new ("TestActions");
|
||||||
gtk_action_group_add_actions (action_group, entries, n_entries, NULL);
|
gtk_action_group_add_actions (action_group,
|
||||||
|
entries, n_entries,
|
||||||
|
NULL);
|
||||||
|
gtk_action_group_add_toggle_actions (action_group,
|
||||||
|
toggle_entries, n_toggle_entries,
|
||||||
|
NULL);
|
||||||
gtk_action_group_add_radio_actions (action_group,
|
gtk_action_group_add_radio_actions (action_group,
|
||||||
radio_entries, n_radio_entries,
|
radio_entries, n_radio_entries,
|
||||||
|
JUSTIFY_LEFT,
|
||||||
G_CALLBACK (radio_action_changed), NULL);
|
G_CALLBACK (radio_action_changed), NULL);
|
||||||
|
|
||||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||||
|
Loading…
Reference in New Issue
Block a user