gtk2/docs/reference/gtk/tmpl/gtkaccellabel.sgml

158 lines
4.4 KiB
Plaintext
Raw Normal View History

1999-08-16 18:51:52 +00:00
<!-- ##### SECTION Title ##### -->
GtkAccelLabel
<!-- ##### SECTION Short_Description ##### -->
A label which displays an accelerator key on the right of the text
1999-08-16 18:51:52 +00:00
<!-- ##### SECTION Long_Description ##### -->
<para>
The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
accelerator key on the right of the label text, e.g. 'Ctl+S'.
It is commonly used in menus to show the keyboard short-cuts for commands.
</para>
<para>
The accelerator key to display is not set explicitly.
Instead, the #GtkAccelLabel displays the accelerators which have been added to
a particular widget. This widget is set by calling
gtk_accel_label_set_accel_widget().
</para>
<para>
For example, a #GtkMenuItem widget may have an accelerator added to emit the
"activate" signal when the 'Ctl+S' key combination is pressed.
A #GtkAccelLabel is created and added to the #GtkMenuItem, and
gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
1999-08-16 18:51:52 +00:00
</para>
<para>
Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
gtk_accel_label_set_accel_widget() to set it up for you.
</para>
<para>
A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
set (see #GtkAccelFlags).
A #GtkAccelLabel can display multiple accelerators and even signal names,
though it is almost always used to display just one accelerator key.
</para>
<example>
<title>Creating a simple menu item with an accelerator key.</title>
<programlisting>
GtkWidget *save_item;
GtkAccelGroup *accel_group;
/* Create a GtkAccelGroup and add it to the window. */
accel_group = gtk_accel_group_new (<!-- -->);
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
/* Create the menu item using the convenience function. */
save_item = gtk_menu_item_new_with_label ("Save");
gtk_widget_show (save_item);
gtk_container_add (GTK_CONTAINER (menu), save_item);
/* Now add the accelerator to the GtkMenuItem. Note that since we called
gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
GtkAccelLabel is automatically set up to display the GtkMenuItem
accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. */
gtk_widget_add_accelerator (save_item, "activate", accel_group,
GDK_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
</programlisting>
</example>
1999-08-16 18:51:52 +00:00
<!-- ##### SECTION See_Also ##### -->
<para>
<variablelist>
1999-08-16 18:51:52 +00:00
<varlistentry>
<term><link linkend="gtk-keyboard-accelerators">Keyboard Accelerators</link>
</term>
<listitem><para>installing and using keyboard short-cuts.</para></listitem>
</varlistentry>
<varlistentry>
<term>#GtkItemFactory</term>
<listitem><para>an easier way to create menus.</para></listitem>
</varlistentry>
</variablelist>
1999-08-16 18:51:52 +00:00
</para>
<!-- ##### STRUCT GtkAccelLabel ##### -->
<para>
The #GtkAccelLabel-struct struct contains private data only, and
should be accessed using the functions below.
1999-08-16 18:51:52 +00:00
</para>
<!-- ##### ARG GtkAccelLabel:accel-closure ##### -->
<para>
</para>
<!-- ##### ARG GtkAccelLabel:accel-widget ##### -->
<para>
</para>
1999-08-16 18:51:52 +00:00
<!-- ##### FUNCTION gtk_accel_label_new ##### -->
<para>
Creates a new #GtkAccelLabel.
1999-08-16 18:51:52 +00:00
</para>
@string: the label string. Must be non-%NULL.
@Returns: a new #GtkAccelLabel.
1999-08-16 18:51:52 +00:00
applied patch from owen to get rid of accel map notifiers. changed things Tue Nov 20 21:25:08 2001 Tim Janik <timj@gtk.org> * applied patch from owen to get rid of accel map notifiers. changed things to fix reentrancy and API as discussed on gtk-devel. * gtk/gtkaccelgroup.[hc]: (gtk_accel_group_finalize): unregister this accel group from all accel map paths. (accel_closure_invalidate): handle invalidation of closures by disconnecting their accelerators. (quick_accel_add): move closure connection and changed notification into this function to reduce code duplication. don't emit change notification on closurers without accelerators. (quick_accel_remove): rewrite, do the exact opposite of quick_accel_add for a GtkAccelGroupEntry. (gtk_accel_group_connect): get rid of the accel_path_quark argument. (gtk_accel_group_connect_by_path): new function to add accelerators with an accel path. (gtk_accel_group_disconnect_closure): new function, disconnect a closure from of an accel group. (gtk_accel_group_disconnect): loop over all closure for a accel_ley, accel_mods pair and remove them. (_gtk_accel_group_reconnect): new function that basically does gtk_accel_group_disconnect_closure() and gtk_accel_group_connect_by_path() once an accel path changed. (gtk_accel_groups_disconnect_closure): remove this, there's gtk_accel_group_disconnect_closure(). * gtk/gtkaccelmap.[hc]: keep list of accel groups per entry now, nuke notifiers. (_gtk_accel_path_is_valid): make this non-static for gtkwidget.c and gtkaccelgroup.c assertions. (gtk_accel_map_add_notifer): removed this function. (gtk_accel_map_remove_notifer): same. (_gtk_accel_map_add_group): (_gtk_accel_map_remove_group): (un-)register accel groups, with accel paths for correct propagation. (gtk_accel_map_add_entry): return void. (gtk_accel_map_lookup): return gboolean instead of GQuark. * gtk/gtkitemfactory.c (gtk_item_factory_add_foreign): always set accel_path on widgets. * gtk/gtkwidget.[hc]: (accel_path_changed): got rid of this, changes are handled by accel maps internally now. (_gtk_widget_set_accel_path): get things to work without notifiers. (gtk_widget_list_accel_closures): list accel closures of a widget. * gtk/gtkwindow.[hc]: rename ::accels_changed, to ::keys_changed.
2001-11-20 23:43:03 +00:00
<!-- ##### FUNCTION gtk_accel_label_set_accel_closure ##### -->
<para>
</para>
@accel_label:
@accel_closure:
<!-- # Unused Parameters # -->
applied patch from owen to get rid of accel map notifiers. changed things Tue Nov 20 21:25:08 2001 Tim Janik <timj@gtk.org> * applied patch from owen to get rid of accel map notifiers. changed things to fix reentrancy and API as discussed on gtk-devel. * gtk/gtkaccelgroup.[hc]: (gtk_accel_group_finalize): unregister this accel group from all accel map paths. (accel_closure_invalidate): handle invalidation of closures by disconnecting their accelerators. (quick_accel_add): move closure connection and changed notification into this function to reduce code duplication. don't emit change notification on closurers without accelerators. (quick_accel_remove): rewrite, do the exact opposite of quick_accel_add for a GtkAccelGroupEntry. (gtk_accel_group_connect): get rid of the accel_path_quark argument. (gtk_accel_group_connect_by_path): new function to add accelerators with an accel path. (gtk_accel_group_disconnect_closure): new function, disconnect a closure from of an accel group. (gtk_accel_group_disconnect): loop over all closure for a accel_ley, accel_mods pair and remove them. (_gtk_accel_group_reconnect): new function that basically does gtk_accel_group_disconnect_closure() and gtk_accel_group_connect_by_path() once an accel path changed. (gtk_accel_groups_disconnect_closure): remove this, there's gtk_accel_group_disconnect_closure(). * gtk/gtkaccelmap.[hc]: keep list of accel groups per entry now, nuke notifiers. (_gtk_accel_path_is_valid): make this non-static for gtkwidget.c and gtkaccelgroup.c assertions. (gtk_accel_map_add_notifer): removed this function. (gtk_accel_map_remove_notifer): same. (_gtk_accel_map_add_group): (_gtk_accel_map_remove_group): (un-)register accel groups, with accel paths for correct propagation. (gtk_accel_map_add_entry): return void. (gtk_accel_map_lookup): return gboolean instead of GQuark. * gtk/gtkitemfactory.c (gtk_item_factory_add_foreign): always set accel_path on widgets. * gtk/gtkwidget.[hc]: (accel_path_changed): got rid of this, changes are handled by accel maps internally now. (_gtk_widget_set_accel_path): get things to work without notifiers. (gtk_widget_list_accel_closures): list accel closures of a widget. * gtk/gtkwindow.[hc]: rename ::accels_changed, to ::keys_changed.
2001-11-20 23:43:03 +00:00
@closure:
added gtkaccelmap.sgml. other updates. Mon Nov 12 23:06:38 2001 Tim Janik <timj@gtk.org> * added gtkaccelmap.sgml. other updates. Mon Nov 12 23:08:37 2001 Tim Janik <timj@gtk.org> * gtk/maketypes.awk: fix type utils generation on unix. * gtk/gtkaccelmap.[hc]: new files, implementing a global accelerator registry. * gtk/gtkaccelgroup.[hc]: major API/implementation revamp: removed GTK_ACCEL_SIGNAL_VISIBLE, gtk_accel_group_get_default, gtk_accel_group_get_entry, gtk_accel_group_(un)lock_entry, gtk_accel_group_add/remove, gtk_accel_group_handle_add/remove, gtk_accel_group_create_add/remove, gtk_accel_group_entries_from_object. introduced ::accel_changed signal for change notification, and gtk_accel_group_connect/disconnect to connect closures to accel groups. made gtk_accel_group_attach/detach and gtk_accel_group_activate private functions. deprecated gtk_accel_group_ref/unref. * gtk/gtkaccellabel.[hc]: changes to make accellabels pay attention to accel group changed notification and basically operate on closures. removed gtk_accel_label_get_accel_object and gtk_accel_label_set_accel_object. introduced gtk_accel_label_set_accel_closure, and for convenience, gtk_accel_label_set_accel_widget. * gtk/gtkitemfactory.[hc]: removed accelerator propagation code which mostly moved into gtkaccelmap.[hc]. removed gtk_item_factory_parse_rc*, gtk_item_factory_dump_* and gtk_item_factory_print_func. * gtk/gtkmain.c: call _gtk_accel_map_init(). * gtk/gtkmenuitem.[hc]: introduced gtk_menu_item_set_accel_path(), that associates an accelerator path with menu items, through which persistent accelerator settings on menu items are enabled. * gtk/gtkmenu.[hc]: added gtk_menu_set_accel_path() so accelerator paths of menu item can be default constructed to allow installation of accelerators on menu items that don't come with an accelerator binding by default. * gtk/gtksettings.c: fix STRING type rc settings by special casing them appropriately in the parser. * gtk/gtksignal.[hc]: allow a class function offset of 0 for gtk_signal_newv(). * gtk/gtkwidget.[hc]: accelerator API revamp. removed ::accelerator_add/remove signals, gtk_widget_accelerator_signal, gtk_widget_accelerators_locked, gtk_widget_remove_accelerators and gtk_widget_(un)lock_accelerators. accelerators maintained through gtk_widget_add/remove_accelerator() are not runtime changable now, the correct sequence to setup a widget for runtime changable accelerators is now: gtk_accel_map_add_entry(accel_path, key, mods); _gtk_widget_set_accel_path(widget, accel_path, accel_group); * gtk/gtkwindow.[hc]: accelerator changes, proxy and coalesce accel group changes (as well as mnemonic changes) through the new signal ::accels_changed. Sat Nov 10 12:08:56 2001 Tim Janik <timj@gtk.org> * gtk/gtksettings.c (_gtk_settings_parse_convert): properly handle GString->string conversions.
2001-11-13 00:53:47 +00:00
<!-- ##### FUNCTION gtk_accel_label_get_accel_widget ##### -->
<para>
</para>
@accel_label:
@Returns:
added gtkaccelmap.sgml. other updates. Mon Nov 12 23:06:38 2001 Tim Janik <timj@gtk.org> * added gtkaccelmap.sgml. other updates. Mon Nov 12 23:08:37 2001 Tim Janik <timj@gtk.org> * gtk/maketypes.awk: fix type utils generation on unix. * gtk/gtkaccelmap.[hc]: new files, implementing a global accelerator registry. * gtk/gtkaccelgroup.[hc]: major API/implementation revamp: removed GTK_ACCEL_SIGNAL_VISIBLE, gtk_accel_group_get_default, gtk_accel_group_get_entry, gtk_accel_group_(un)lock_entry, gtk_accel_group_add/remove, gtk_accel_group_handle_add/remove, gtk_accel_group_create_add/remove, gtk_accel_group_entries_from_object. introduced ::accel_changed signal for change notification, and gtk_accel_group_connect/disconnect to connect closures to accel groups. made gtk_accel_group_attach/detach and gtk_accel_group_activate private functions. deprecated gtk_accel_group_ref/unref. * gtk/gtkaccellabel.[hc]: changes to make accellabels pay attention to accel group changed notification and basically operate on closures. removed gtk_accel_label_get_accel_object and gtk_accel_label_set_accel_object. introduced gtk_accel_label_set_accel_closure, and for convenience, gtk_accel_label_set_accel_widget. * gtk/gtkitemfactory.[hc]: removed accelerator propagation code which mostly moved into gtkaccelmap.[hc]. removed gtk_item_factory_parse_rc*, gtk_item_factory_dump_* and gtk_item_factory_print_func. * gtk/gtkmain.c: call _gtk_accel_map_init(). * gtk/gtkmenuitem.[hc]: introduced gtk_menu_item_set_accel_path(), that associates an accelerator path with menu items, through which persistent accelerator settings on menu items are enabled. * gtk/gtkmenu.[hc]: added gtk_menu_set_accel_path() so accelerator paths of menu item can be default constructed to allow installation of accelerators on menu items that don't come with an accelerator binding by default. * gtk/gtksettings.c: fix STRING type rc settings by special casing them appropriately in the parser. * gtk/gtksignal.[hc]: allow a class function offset of 0 for gtk_signal_newv(). * gtk/gtkwidget.[hc]: accelerator API revamp. removed ::accelerator_add/remove signals, gtk_widget_accelerator_signal, gtk_widget_accelerators_locked, gtk_widget_remove_accelerators and gtk_widget_(un)lock_accelerators. accelerators maintained through gtk_widget_add/remove_accelerator() are not runtime changable now, the correct sequence to setup a widget for runtime changable accelerators is now: gtk_accel_map_add_entry(accel_path, key, mods); _gtk_widget_set_accel_path(widget, accel_path, accel_group); * gtk/gtkwindow.[hc]: accelerator changes, proxy and coalesce accel group changes (as well as mnemonic changes) through the new signal ::accels_changed. Sat Nov 10 12:08:56 2001 Tim Janik <timj@gtk.org> * gtk/gtksettings.c (_gtk_settings_parse_convert): properly handle GString->string conversions.
2001-11-13 00:53:47 +00:00
<!-- ##### FUNCTION gtk_accel_label_set_accel_widget ##### -->
1999-08-16 18:51:52 +00:00
<para>
1999-08-16 18:51:52 +00:00
</para>
@accel_label:
@accel_widget:
1999-08-16 18:51:52 +00:00
<!-- ##### FUNCTION gtk_accel_label_get_accel_width ##### -->
<para>
Returns the width needed to display the accelerator key(s).
This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
be needed by applications.
1999-08-16 18:51:52 +00:00
</para>
@accel_label: a #GtkAccelLabel.
@Returns: the width needed to display the accelerator key(s).
1999-08-16 18:51:52 +00:00
<!-- ##### FUNCTION gtk_accel_label_refetch ##### -->
<para>
Recreates the string representing the accelerator keys.
This should not be needed since the string is automatically updated whenever
accelerators are added or removed from the associated widget.
1999-08-16 18:51:52 +00:00
</para>
@accel_label: a #GtkAccelLabel.
@Returns: always returns %FALSE.
1999-08-16 18:51:52 +00:00