ruby-****@sourc*****
ruby-****@sourc*****
2012年 11月 8日 (木) 06:27:01 JST
------------------------- REMOTE_ADDR = 184.145.95.170 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-mnub ------------------------- @@ -230,7 +230,15 @@ #(9.5.2) === Keyboard Accelerators And Their Relationships With Menus And Other Widgets -Though we have already discussed keyboard accelerators in section 9.2 '((<Keyboard Accelerators|tut-gtk2-mnstbs-popup#Keyboard Accelerators>))' now that we are familiar with menus, menu bars, and sub-menus we can expose also the relationships between them and other widgets such as top windows and other nested widgets particularly menu an sub-menu items. +Though we have already discussed keyboard accelerators in section 9.2 '((<Keyboard Accelerators|tut-gtk2-mnstbs-popup#Keyboard Accelerators>))' now that we are familiar with menus, menu bars, and sub-menus we can expose also the relationships between them, the top windows and other nested widgets particularly menu an sub-menu items. Basically, you can create two kinds of accelerator key bindings. One that binds to a particular widget (menu item), and the other that binds to the top-level window. Let's look at the former first. + + +You have seen that accelerator keys are tightly related to Gtk::AccelGroup object, which in our example program above, we created before creating menu items that can in addition to mouse clicks be selected also by pressing the assigned accelerator keys. The constructor for image menu items accept the accelerator group parameter, and the stock item identifies the accelerator key combination, but for other menu items you have to explicitly add the accelerator group, and identify the accelerator key combination by calling the Gtk::Widget#add_accelerator method. In either case the desired accelerator keys are associated with the menu item object we are constructing. If you remove an item to which you assigned accelerator group for a particular accelerator key, that accelerator key will no more react if user presses it. As you can see accelerator keys here are tied to menu items. + +The second kind of accelerator key binding defined by using the Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags, closure), and Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags) {...} methods. As you see, in this case you do not identify the widget, to which the accelerator key you are defining will invoke the callback (closure or block). + +It is important to realize, that if you want to use the accelerator keys for either of the two bindings described above, you need to add the accelerator group to the top window (Gtk::Window#add_accel_group). +