GRAphical Programming for Eiffel index contents

Chapter VIII. Adding Speedbar

WINDOW
   SPEEDBAR

BUTTON
   PICTURE_BUTTON
      SPEEDBAR_BUTTON

SPEEDBAR_RESPONDER

If you want to achieve the professional quality for your applications you should add a speedbar window. Speedbar contains buttons with pictures that act as hotkeys. Instead of navigating in menus User simply clicks on a button. The picture buttons sometimes look more natural and more intuitive than hotkey accelerators or menu commands.

This chapter describes how to add a Speedbar to your applications. In the picture below you can see all Speedbar classes.


Figure 8.1 Speedbar classes.


SPEEDBAR_BUTTON

This class inherits from PICTURE_BUTTON and adds some more functionality for Speedbar.

There are three states for a Speedbar button:

Pressed Button is pressed down.
Released Button is in the normal state (released).
Disabled Button cannot be pressed or released.


There are four types of the speedbar buttons.

Push button This is a stand alone button that can be pressed. It's released automatically. Usually performs some command actions.
Check button This is a stand alone button - "switch". After it has been pressed it's not released automatically. User has to click for the second time to release - to "turn it off". Usually it controls the state of some objects.
Radio button This is a member of the group of check buttons. When you press any button in the group - previously pressed button of this group is released automatically. To form a group of this kind you should add a radio buttons one after another sequentially.
Separator A special dummy button object used to represent the delimiter between different buttons groups.


Figure 8.2 Speedbar buttons.


SPEEDBAR

Class SPEEDBAR inherits from class WINDOW and acts as a manager for buttons. You can add/remove buttons on it, hide/show or disable/enable them. Class SPEEDBAR has special attribute responder.


SPEEDBAR_RESPONDER

On any events a speedbar calls this object (if it is assigned under the creation procedure). You can inherit from this class to take control under such events as mouse movement over the speedbar button and so on.


How to add speedbar

To add a speedbar object you must redefine APPLICATION's make_speedbar feature. You will see how to do it in the example below. First we create a group of push buttons, then a group of check buttons and finally a radio buttons group.

make_speedbar : SPEEDBAR is
   local
     p : PICTURE;
     b : SPEEDBAR_BUTTON;
     rsp: SBAR_RESPONDER
   do
     !!rsp.make();
     !!Result.make_with_responder( rsp, True );
     -- 
     !!p.make_predefined ( p.SHEET_PICTURE );
     !!b.make ( "New", p, IDM_NEW );
     Result.add_button ( b );
     !!p.make_predefined ( p.LOAD_PICTURE );
     !!b.make ( "Open", p, IDM_OPEN );
     Result.add_button ( b );
     !!p.make_predefined ( p.SAVE_PICTURE );
     !!b.make ( "Save", p, IDM_SAVE );
     Result.add_button ( b );
     --
     !!b.make_separator ( 0 )
     Result.add_button ( b )
     --
     !!p.make_predefined ( p.BOLD_FONT_PICTURE );
     !!b.make_check ( p, IDM_BOLD, CTX_BOLD );
     Result.add_button ( b );
     !!p.make_predefined ( p.ITALIC_FONT_PICTURE );
     !!b.make_check ( p, IDM_ITALIC, CTX_ITALIC );
     Result.add_button ( b );
     !!p.make_predefined ( p.UNDERLINE_PICTURE );
     !!b.make_check ( p, IDM_UNDERLINE, CTX_UNDERLINE );
     Result.add_button ( b );
     -- 
     !!b.make_separator ( 0 )
     Result.add_button ( b )
     --
     !!p.make_predefined ( p.ARC_PICTURE );
     !!b.make_radio ( p, IDM_ARC, CTX_ARC );
     Result.add_button ( b );
     !!p.make_predefined ( p.ELLIPSE_PICTURE );
     !!b.make_radio ( p, IDM_ELLIPSE, CTX_ELLIPSE );
     Result.add_button ( b );
     !!p.make_predefined ( p.RECTANGLE_PICTURE );
     !!b.make_radio ( p, IDM_RECT, CTX_RECT );
     Result.add_button ( b );

   end;

Next we can control the state of buttons dependently from the application state. This feature we can invoke any time when the desktop includes or removes a child window.

check_sbar_buttons is
   do
     if desktop.number_of_childs > 0 then
       speedbar.enable_commands( << IDM_SAVE >> );
       speedbar.show_commands( << IDM_BOLD, IDM_ITALIC, IDM_UNDERLINE, IDM_ARC, IDM_ELLIPSE, IDM_RECT >> );
     else
       speedbar.disable_commands( << IDM_SAVE >> );
       speedbar.hide_commands( << IDM_BOLD, IDM_ITALIC, IDM_UNDERLINE, IDM_ARC, IDM_ELLIPSE, IDM_RECT >> );
     end
   end

Finally we can display hint windows any time User moves the mouse pointer over particular speedbar button.

class SBAR_RESPONDER 
   inherit 
     SPEEDBAR_RESPONDER 
       redefine
         on_hint_string_request
       select
         on_hint_string_request
       end;
     SYSTEM_COMMAND

   feature 

     on_hint_string_request( t: TILE ): STRING is
       local
         but: SPEEDBAR_BUTTON
       do 
         but ?= t;
         if but /= Void then
         inspect but.command_code
         ------------------------
           when IDM_NEW then
             !!Result.adapt( "Create new document" );
           when IDM_OPEN then
             !!Result.adapt( "Open document" );
           ...

           else
             !!Result.adapt( "" );
         end; -- inspect
       end; -- if
     end; -- on_hint_string_request 
  
   end -- class SBAR_RESPONDER


See example in the \EXAMPLES\SPEEDBAR directory and our On-Line Help Reference for more information.


© Object Tools -- info@object-tools.com -- December 1999