Chapter Contents

Previous

Next
SAS/AF Software: Class Dictionary

Using the Work Area Class

These are the basic application development steps for creating a simple work area:

  1. Subclass the widgets to be used in the work area and define their functionality. The items within the work area contain all the logic to perform tasks, not the work area itself, which functions as a space manager. Therefore, the widgets should be subclassed and provided the necessary functionality before they are added to the work area.

  2. Customize the work area pop-up menus to add functionality for the end user.

  3. Add the new widgets to the RESOURCE entry for the frame or define a new RESOURCE entry with the work area widgets.

  4. In the Build environment of a frame, create and fill a region with a work area object. Typically you don't add items to the work area in the Build environment because those items will not belong to the work area; they are simply siblings of it. Because the work area is scrollable, it can be larger than the frame.

  5. In the Attributes window, assign the RESOURCE entry containing your widget subclasses.

  6. Also specify a catalog entry in which to save the work area when the user leaves it. Typically the work area is stored as an SCL list in a catalog entry of type WORKAREA.

  7. Close the Attributes window and run TESTAF to create and test the functionality of the work area items.


Drag and Drop and the Work Area

Drag-and-drop functionality, which has been added to the Widget class as a whole, is particularly useful for the Work Area class. Drag and drop allows you to define additional functionality for objects so that you can use a mouse to pick up an object from your work area and drag it over to another object on your work area and have an action occur when you drop it. For example, your work area might contain an item called View that runs the FSVIEW command when you drag a dataset (also a work area item) and drop it on that item.

The Work Area class automatically sets each item to be a drag site of type _afWORKAREA. The _afWORKAREA representation is an SCL list that contains the result of the _getProperties method (see the Widget class) and includes all instance variables and the region definition. It provides the work area with enough information to re-create the object if it is copied or moved to a different window. As a result, you can move or copy a work area item to a different work area in either the same frame or a different frame. In this case, the object is destroyed and re-created.

You can also move or copy a work area item within the same work area. This action uses a different work area representation named _afWORKAREA plus a unique numeric suffix. This representation allows the workarea to simply move the item instead of destroying and re-creating it.

For more information on drag and drop, see SAS/AF online help.


Example: Defining Drag and Drop by Subclassing

For an example that defines drag sites and drop sites using per-instance methods (instead of subclassing) see SAS/AF online help.

A desk is defined, generally, as a place to do work. Part of your desk may include file drawers, note pads, calculators, ledgers, etc. The arrangement and contents of the things on your desk are decided by you and not by anyone else. The Work Area Class provides an area where you can place any function you can think of, from commands to applications, from calendars to datasets.

... Or, you may have placed a Graphics Object to plot how the stock market is doing. You may have several stocks that you want to plot. You could drag the stock over the Graphic object and drop it to plot that stock. Also, just like the top of your desk, if you leave the frame containing the work area object and come back to it later, it will be in the same state as when you left it.

button:
      /* Create the main list and a  */
      /* sublist */
   l = makelist();
      /* Create a sublist for class */
      /* information */
   l1 = makelist();
      /* Fill the sublist with the class  */
      /* of the item*/
   rc = setnitemc(l1, "GTEXT.GTEXT", 
                  "_classname");
      /* Add the class sublist to the main */
      /* list */
   rc = insertl(l, l1, 1);
      /* Create a sublist for position  */
      /* information */
   r = makelist();
      /* Add the region sublist to the  */
      /* main list */
   rc = setniteml(l1, r, "_region");
      /* Specify the coordinates for the */
      /* upper left corner of the item */
   rc = setnitemd(r, 1, "ULX");
   rc = setnitemd(r, 1, "ULY");
      /* Does this do anything other  */
      /* than print list contents?? */
   putlist(l);
      /* Add the button to the work area  */
      /* WORK1 */
   call notify("work1", "_newItem", l);
      /* Delete the list */
    dellist(l);
return;


Example: Adding Highlighting to a Work Area

The following example shows how to add highlighting to a work area. Two methods are overridden in this example. The first is the _selectItem method. It is used to highlight the selected item and unhighlight any previously selected items. The second method is the _select method. This method is used to unhighlight any previously selected items.

length _self_ 8;

   /* _selectItem method. Turns on  */
   /* outlines of all selected items  */
   /* Turns off outlines of previous  */
   /* selection */
selitem: method ids 8 action $ 8;
   l = makelist();

      /* Get the list of currently    */
      /* selected items and turn off their */
      /* current selection colors */
   call send(_SELF_, "_getSelections", l);
   do i=1 to listlen(l);
      l1 = getiteml(l, i);
      call send(l1, "_setSelection", "OFF", 
                "BLACK");
   end;

      /* Let the sworkarea know about the */
      /* selected items */
   call super(_SELF_, "_selectItem", ids,
              action);

      /* Get the list of currently selected */
      /* items and turn on their */
      /* current selection colors */
   call send(_SELF_, "_getSelections", l);

   do i=1 to listlen(l);
      l1 = getiteml(l, i);
      call send(l1, "_setSelection", "ON", 
                "WHITE");
   end;
   rc = dellist(l);
   if (rc ^= 0) then do;
      put "Error removing temporary list 
          during _selectItem";
      _msg="Error removing temporary list 
            during _selectItem";
   end;
endmethod;

   /* Select method to turn off outlines */
select: method;
   l = makelist();

      /* Send the select item method and */
      /* only have this item selected */
   call send(_self_, "_selectItem", l, 
             "REPLACE");
   rc = dellist(l);
   if (rc ^= 0) then do;
      put "Error removing temporary list 
          during _select";
      _msg="Error removing temporary list 
            during _select";
   end;
endmethod;


Work Area Run-time Menus

The user creates and modifies work area items at run time by selecting items from pop-up menus.

Note:    Objects placed on the work area in the Build environment are not work area items. As a result, run-time menus do not affect them, and you cannot perform actions such as growing, resizing, editing, deleting, or scrolling.  [cautionend]

Work Area Region Menu

The pop-up menu in the work area region displays these choices:

Add Item
displays the list of widgets that can be added to the work area. This list is comprised of all Widget classes contained in the current resource associated with the work area. Selecting a widget adds it to the work area. This selection runs the _addItem method.

Modify Resource
allows you to edit the current resource entry. This selection runs the _editResource method.

Turn Growing On/Off
turns resize handles on and off for all regions in the work area. When growing is on, Add Item and Copy are grayed. This selection runs the _growMode method.

Auto Arrange
arranges the work area items so the middle of the upper edges are the distance apart specified in the Adjustment dialog box. Row- and column-based objects may not show text if the arrangement places the object in an invalid location. This selection runs the _arrange method.

Adjust Arrangement
displays the dialog box for adjusting the arrangement sizes. This selection runs the _adjustDialog method.

Disallow dragging
Allow dragging
toggle between providing dragging or other functionality with a mouse button. When Disallow dragging is selected, the mouse button provides an alternate function (usually marking or pasting).

You can use the _popup method to add or delete items in this menu.

Work Area Item Menu

If you pop-up on a newly created item in the work area, the menu displays these choices:

Attributes
opens the attributes window for that item. This selection runs the _attributesDialog method.

Region Attributes
opens the Region Attributes window. This selection runs the _regionAttr method.

Remove
removes the item. This selection runs the _term method.

Copy
copies the item. This selection runs the _copyRegion method.

Move
moves the item. This selection runs the _moveRegion method.

Additional choices may be available depending on the class of the item. You can use the _childPopup method to add or delete items in this menu.


Chapter Contents

Previous

Next

Top of Page

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