Re: [gtk-list] Re: accelerators



On Wed, 29 Apr 1998, robert havoc pennington wrote:

> 
> Hmm, I have progress. New angles on the questions...
> 
> On Wed, 29 Apr 1998, robert havoc pennington wrote:
> > 
> > I want to bind the escape key to delete_event for Gnome dialogs; but the
> > accelerator functions seem to take characters, not keysyms. Is there a
> > character for escape? 
> > 
> 
> So I've tried '\x1b' and 27, and then tried using the letter a ('a'), but
> the accelerator doesn't do anything AFAICT. I push the key, nothing
> happens.


x doesn't report ESC as '\x1b' but as GDK_Escape (0xFF1B). since accelerators
currently only support gchar characters, you can not use GDK_Escape as an
accelerator binding.

> I have:
> 
>  dialog->accelerators = gtk_accelerator_table_new();
>   gtk_widget_install_accelerator(GTK_WIDGET(dialog),
> 				 dialog->accelerators,
> 				 "delete_event",
> 				 'a', 0);

gtk_window_add_accelerator_table (GTK_WINDOW (dialog),
				  dialog->accelerators);

> I also tried adding:
> gtk_widget_set_events(GTK_WIDGET(dialog), GDK_KEY_PRESS_MASK);

you don't need to, that's automatically set for all toplevels.

> theorizing that the dialog wasn't getting the key press; no dice.

that's not the case, it just doesn't interpret it in the way you want it to ;)

> What else is supposed to happen here? 
> 
> I have the same problem in 'gw,' none of the accelerators work; gw uses
> GnomeApp, so it ought to be automatic, right? But they do work in 'gtt',
> for example, and I can't see a difference in what's being done.  It's even
> the same key, control-Q; I even tried changing gw to use 'Q' instead of
> 'q' to match gtt. Clearly I'm missing something.
> 
> > Separate question: is there a way to find out which widget is the default? 
> > Specifically, I want to bind return to the current default button in the
> > button box.
> > 
> 
> After perusing some source, I have the following plan: attach a callback
> to key_press_event, test the key for return, if it is GDK_Return then see
> if GTK_WINDOW(dialog)->default_widget is a button and emit "clicked" on
> the button if so.

you don't need to do that, the default widget will automatically be activated
if you press return, as will the focus widget if you press SPACE.

the only case where this won't happen is if you are currently editing some
text in a GtkEntry, RETURN here will activate the entry. if you still want
to have the default widget activated i nthis case make the following signal
connection:

gtk_signal_connect_object (GTK_OBJECT (the_entry_widget),
			   "activate",
			   GTK_SIGNAL_FUNC (gtk_window_activate_default),
			   GTK_OBJECT (dialog_or_window_any_toplevel));
			   
> I think this will work, but I'd love suggestions on a better way. Can
> GtkAccelerator do anything other than emit signals, like callbacks? 

i don't really understand this question... GtkAccelerators will invoke
the signal you pass to it, though you should only use signals that have
the signature:

void (*signal) (GtkObject *object, gpointer user_data);

since there are no else parameters available when the signal is emitted
from the accelerator code, and your function arguments will be just
rubbish (and likely cause segmentation faults).

> 
> Thanks,
> 
> Havoc Pennington
> http://pobox.com/~hp
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]