Chapter Contents |
Previous |
Next |
SAS/AF Software: Class Dictionary |
How the Toolbar Works |
There are two ways to make toolbar buttons perform actions:
Commands
section of the Enter Values window, or assigned with the _setCmd method, or specified in the Command Processing window (see the Widget class).
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:
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.
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.
Button Display
attribute should be
Image and label
.
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.
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.
Label
field, press ENTER, and drag the text onto the button.
Image
field, such as FILENAME, press ENTER, and drag the image name onto the button.
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.