Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the Toolbar Class


How the Toolbar Works

There are two ways to make toolbar buttons perform actions:

  1. Clicking on a toolbar button runs the command specified in the Commands section of the Enter Values window, or assigned with the _setCmd method, or specified in the Command Processing window (see the Widget class).

  2. Clicking on a toolbar button runs a labeled section of the SCL program. Include these steps in your program:

    For example, this program determines which of two buttons has been selected in the toolbar named TBAR1 and runs the appropriate labeled section:

    length name $24;
    TBAR1:
    call notify ('tbar1', '_get_last_sel_', 
                 index, status, name);
       if name='PRINT' then link PRINT;
       else if name='DATASET' then link OPEN;
    return;
    
    PRINT:
       /* code for printing here */
    return;
    
    OPEN:
       /* code for opening a data set here */
    return;


Scroll Buttons

If a toolbar has more buttons than can be displayed in the space available, scroll buttons are automatically added to each end of the toolbar. Two scroll buttons (left and right or up and down) allow you to step through all the buttons in a toolbar.

Each scroll button occupies one button space in the toolbar. For example, if you specify a toolbar with six button spaces and eight buttons, the toolbar displays the left and right scroll buttons and four of the eight action buttons. Therefore, a toolbar that uses scroll buttons must have a minimum of three button places.

Toolbars with scroll buttons do not have any space between the buttons, even if space is specified in the Attributes window.


Drag and Drop

The Toolbar object supports drag and drop. By default drag and drop is enabled at Build time and disabled at run time. The toolbar uses drag and drop in three ways:

  1. In the Build environment, you can move or copy a button by dragging it to the desired location, either within the same toolbar or within a different toolbar. To delete a button, use the Attributes window.

  2. The same functionality is available in the run-time environment if you explicitly enable it for the toolbar. For example, to enable drag and drop for the toolbar called TBAR1, include the _enableDragDropSite method of the Widget class in the SCL program:
    INIT:
    call notify ('tbar1',
                 '_enable_drag_drop_site_');
    return;

    This allows the user of the toolbar to copy and move toolbar buttons at run time.

    To turn off drag and drop at run time, call the _disableDragDropSite method of the Widget class.

  3. In the run-time environment, you can drag onto a toolbar any widget that has been set up as a drag site and assigned one of the Toolbar drag representations that define the kind of data a toolbar button can accept. By default, the Toolbar class supports three drag representations:
    _dndPaletteBUTTON
    is an SCL list that contains complete information about the button.

    _dndPaletteIMAGE
    is an image stored in SASHELP.I0x0x that can be used by the button as its image.

    _dndPaletteLABEL
    is text that can be used as the label for the button.

    These representations allow you to edit a toolbar by changing the text, image, or functionality of a button by entering the data in another widget and dragging that widget onto the button.

For more information on drag and drop concepts, refer to SAS/AF online help.

If you want to know if something has been dragged out of your toolbar, or if something has been dropped on your toolbar, then you need to subclass the toolbar and override one or more of the three toolbar drag-and-drop methods and possibly one or more of the Widget drag-and-drop methods.


Example: Changing Button Labels and Images with Drag and Drop

This example creates a toolbar in which the user can dynamically change a toolbar button label or image at run time. The frame contains a toolbar and two text entry fields in which the user enters new text or the name of a new image. The contents of each field can be dragged to a toolbar button where it replaces the current label or image.

  1. In the SASUSER library create a catalog called FRAMECAT in which to store the FRAME entry and the associated SCL programs.

  2. Create a FRAME entry containing a toolbar, TBAR1, and two text entry fields named LABEL and IMAGE. The toolbar should have one or more buttons and the Button Display attribute should be Image and label.

  3. Provide the SCL program for the frame:
    INIT:
       /* Make the toolbar a drag/drop site. */
       call notify('tbar1',
                   '_enable_drag_drop_site_');
    
       /* Make both text entry fields drag  */
       /* sites and assign the appropriate  */
       /* data representation.              */
       call notify('image', '_add_drag_rep_',
                   '_dndPaletteIMAGE');
       call notify('label', '_add_drag_rep_',
                   '_dndPaletteLABEL');
    
       /* Make the text entry fields   */
       /* drag/drop sites.            */
       call notify('image',
                   '_enable_drag_drop_site_');
       call notify('label', 
                   '_enable_drag_drop_site_');
    
       /* Override the _getDragData  */
       /* methods for both fields. Point to */
       /* the SCL program that implements */
       /* the methods. */
       call notify('image', 
                   '_set_instance_method_',
                   '_getDragData',
                   'sasuser.framecat.tbarmeth.scl',
                   'getimage');
       call notify('label',
                   '_set_instance_method_',
                   '_getDragData',
                   'sasuser.framecat.tbarmeth.scl',
                   'getlabel');
    return;

    Compile the code and close the SCL entry.

  4. Provide the SCL program that defines the methods (SASUSER.FRAMECAT.TBARMETH.SCL):
    length value $200;
    
       /* Store the image data in a list. */
    GETIMAGE:  method rep $200 op $200 data 8 x
               8 y 8 / RESIDENT;
       call send(_self_, '_get_text_', value);
       setnitemc(data, value, 'IMAGE');
    endmethod;
    /*newpage*/
    
       /* Store the label data in a list. */
    GETLABEL:  method rep $200 op $200 data 8 x
               8 y 8 / RESIDENT;
       call send(_self_, '_get_text_', value);
       setnitemc(data, value, 'LABEL');
    endmethod;

    Compile the code and save or close the SCL entry.

  5. Run TESTAF. In the TESTAF window,


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.