Re: [gtk-list] Mouseless GTK+
- From: Olaf Klischat <olaf klischat tu-clausthal de>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Mouseless GTK+
- Date: Thu, 02 Sep 1999 15:13:41 +0000
"Jon K. Hellan" wrote:
>
> --
> I am slightly frustrated about trying to interact with GTK+
> applications without a mouse. Before blaming anybody, I would like to
> know how responsibility is divided between the widget set and
> applications.
>
> To illustrate what I am talking about, you can run testgtk in gtk+
> 1.2.4 and select "entry". Now try to type into the dialog.
> Intuitively, I would expect to be able to type into the text entry
> field at the top. But the only keys which have effect are <Tab>, which
> navigates to the entry field, and Shift+<Tab>, which navigates to the
> close button.
>
> I also like having <Esc> to make the dialog go away, like in Motif and
> Windows. It could just as well be Ctl+C, of course, but there should
> be a way and it should be standardized.
>
Another thing are those Alt+letter shortcuts that focuse the dialog's
widgets (the label belonging to a particular widget usually has that
widget's shortcut letter underlined).
I recently used the following to achieve this behaviour:
/* extract accelerator key from label_text
* (must contain a '_' before the desired letter),
* set label text accordingly,
* connect Alt+Key with the specified signal
* on the specified target widget
*/
void connect_accelerator
(const char* label_text,
GtkLabel* label_widget,
GtkWidget* target,
const char* signal,
GtkAccelGroup* accel_group)
{
guint accel_key;
accel_key = gtk_label_parse_uline (label_widget,label_text);
gtk_widget_add_accelerator
(target, signal,
accel_group,
accel_key,
GDK_MOD1_MASK,
GTK_ACCEL_LOCKED);
}
/* extract accelerator key from label_text
* inscribe the button accordingly,
* connect button's "clicked" event with Alt+key
*/
void connect_button_accelerator
(GtkButton* button,
const char* label_text,
GtkAccelGroup* accel_group)
{
guint accel_key;
GtkWidget* btn_label = gtk_label_new ("");
accel_key = gtk_label_parse_uline
(GTK_LABEL(btn_label),label_text);
gtk_container_add (GTK_CONTAINER(button), btn_label);
gtk_widget_show (btn_label);
gtk_widget_add_accelerator
(GTK_WIDGET(button), "clicked",
accel_group,
accel_key,
GDK_MOD1_MASK,
GTK_ACCEL_LOCKED);
}
usage:
/* create dialog */
GtkWidget* dialog = gtk_dialog_new ();
/* create new accel group and connect it to the dialog */
GtkAccelGroup* accel_group = gtk_accel_group_new ();
gtk_accel_group_attach (accel_group, GTK_OBJECT (m_dialog));
/* create a text entry */
GtkWidget* text_entry = gtk_entry_new ();
gtk_widget_show (text_entry);
/* and its label */
GtkWidget* label = gtk_label_new ("");
/* text entry will be activatable via Alt+t */
connect_accelerator
("Enter _Text:",
GTK_LABEL(label),
text_entry,
"grab_focus",
accel_group);
gtk_widget_show (label);
/* a button labelled "Click me", clickable via Alt+c*/
GtkWidget* button = gtk_button_new ();
connect_button_accelerator
(GTK_BUTTON(button), "_Click me", accel_group);
gtk_widget_show (button);
...arrange everything inside the dialog here...
Olaf
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]