ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 27日 (土) 09:36:27 JST
------------------------- REMOTE_ADDR = 74.14.158.59 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-statb ------------------------- @@ -68,9 +68,18 @@ Beside displaying the current state your application is in at any moment, another useful role of the status bar is to give the user more information about the menu item the mouse cursor is hovering over. An example of the later is shown on the figure here on the right, while the application status (the string "Pulsating") is shown below in the figure below on the left. +In our example program we keep two kinds of messages on our status bar's stack. The temporary hints, describing each individual menu option, and a bit more persistent messages reflecting the most recent user selection indicating the latest state our application is in. We created two context identifiers from the strings 'StatBarHints' and 'CurrentStatus', using the Gtk::Statusbar#get_context_id(context_description) method. The first is created from the string 'StatBarHints' in the 'statusbar_hint' method and the second from the 'CurrentStatus' string in three methods called 'pulse_activated', 'fill_activated' and 'clear_activated'. + {{image_left("statbar-state.png")}} + +The((*enter_notify_event*))signal in our example program here is handled by the 'statusbar_hint' method. The handler receives Gdk::Event object as a parameter which is used to identify whether the cursor entered the menu item (Gdk::Event::ENTER_NOTIFY) or is on its way out (see: Gdk::Event::GdkEventType). We can use this information to, for as long as the cursor is hovering above the menu item, display the description of the menu selection in the status bar, by pushing the message on the status bar stack, hence hiding for that time whatever was displayed there before, cursor entered the menu item. When the cursor leaves the menu item area, the((*enter_notify_event*))signal is emitted again, however this time carrying Gdk::Event::LEAVE_NOTIFY flag, so we pop-off the stack the message we pushed on it when the cursor appeared above our menu item, which restores whatever message was on the status bar stack before the two consecutive ((*enter_notify_event*))signal emitions. + + +:Note: + 'statusbar_hint' method handles the((*enter_notify_event*))which, if missing the((*return*))statement will interfere with the((*'activate'*))event used in the other three just mentioned '{pulse|fill|clear}_activated' methods, by disabling the highlighting menu feature when browsing the menu (see the comment before the return statement in 'statusbar_hint' method.) +Let's look at the listing: {{br}} ((*statbhints-n-state.rb*))