Re: New accelerator API



"Padraig O'Briain" <Padraig Obriain Sun COM> writes:

> > To: "Padraig O'Briain" <Padraig Obriain Sun COM>
> > Cc: gtk-devel-list gnome org, timj gtk org
> > Subject: Re: New accelerator API
> > User-Agent: Gnus/5.0807 (Gnus v5.8.7) Emacs/20.7
> > MIME-Version: 1.0
> > 
> > 
> > "Padraig O'Briain" <Padraig Obriain Sun COM> writes:
> > 
> > > Is it possible to determine the accelerator associated with a menu item 
> using 
> > > the new API?
> > 
> > Not quite - GtkAccelLabel uses a GtkWidget private function:
> > 
> >  _gtk_widget_get_accel_closures (accel_label->accel_widget);
> > 
> > To do this. This lack most likely needs to be fixed.
> > 
> > Regards,
> >                                         Owen
> 
> I have used the code snippet below to find the accelerator, if any, for a menu 
> item. It seems to produde the correct results for the menu items in testgtk.

Well, it should work, but this depends on two implementation details:

 - The priv_accels field of GtkAccelGroup
 - The fact that closure->data points to the widget

The first can gotten around by using gtk_accel_group_find(); the
second is not possible to get around with our existing API. But
all we have to do is make gtk_widget_get_accel_closures() exported
to solve this.

Now, if nothing else can be done, hacking around limitations using
implementation details can be possible as long as you aren't going
to complain if it breaks, but I think we should fix things here instead.

Regards,
                                        Owen

> ------------- Begin Included Message -------------
> 
>       parent = gtk_widget_get_parent (item);
>       if (GTK_IS_MENU (parent))
>         {
>           GtkAccelGroup *group;
>           gint i;
> 
>           group = gtk_menu_get_accel_group (GTK_MENU (parent));
>           for (i = 0; i < group->n_accels; i++)
>             {
>               GtkAccelGroupEntry *entry;
>               GClosure *closure;
> 
>               entry = &group->priv_accels[i];
>               closure = entry->closure;
>               if (closure->data == item)
>                 {
>                    GtkAccelKey key;
>                    key = entry->key;
> 
>                    accelerator = gtk_accelerator_name (key.accel_key,
>                                                        key.accel_mods);
>                    break;
>                 }
>             }
>         }



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