home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / DTS.Lib / =Using ListControl.c < prev    next >
Encoding:
Text File  |  1993-06-18  |  9.8 KB  |  203 lines  |  [TEXT/MPS ]

  1. ***** ListControl.c usage documentation *****/
  2.  
  3. Purpose:  To simplify List handling within a window.
  4.  
  5. Implementing a List control does the following:
  6.  
  7. 1) Makes using lists in a non-dialog window easier.
  8. 2) The List is automatically associated with the window, since
  9.    it is in the window's control list.
  10. 4) Updating of the List is much simpler, since all that is
  11.    necessary is to draw the control (or all the window's controls with
  12.    a DrawControls call).
  13. 5) What isn't handled automatically by tracking the control can be handled
  14.    with a direct call.  There are simple calls to handle List events.
  15. 6) When you close the window, the ListRecord is disposed of.
  16.    (This automatic disposal can easily be defeated.)
  17.  
  18.  
  19.  
  20. To create a List control, you only need a single call.  For example:
  21.  
  22.     list = CLNew(rViewCtl,            /* Resource ID of view control for List control. */
  23.                  true,                /* Initially visible.                             */
  24.                  &viewRect,            /* View rect of list.                             */
  25.                  numRows,            /* Number of rows to create List with.             */
  26.                  numCols,            /* Number of columns to create List with.         */
  27.                  cellHeight,
  28.                  cellWidth,
  29.                  theLProc,            /* Custom List procedure resource ID.             */
  30.                  window,            /* Window to hold List control.                     */
  31.                  clHScroll | blBrdr | clActive);    /* Horizontal scrollbar, active List. */
  32.  
  33. The various choices for the List control are defined as follows:
  34.  
  35. #define clHScroll        0x0002
  36. #define clVScroll        0x0008
  37. #define clActive        0x0020
  38. #define clShowActive    0x0040
  39. #define clKeyPos        0x0080
  40. #define clTwoStep        0x0100
  41. #define clHasGrow        0x0200
  42. #define clDrawIt        0x8000
  43.  
  44. clHScroll:            Create a list that includes a horizontal scrollbar.
  45. clVScroll:            Create a list that includes a vertical scrollbar.
  46. clActive:            Make this the initially active control for the window.
  47. clShowActive:        When the control is active, show that it is by drawing a selection
  48.                     border around the control.  This is the new 7.0 human-interface
  49.                     method of showing which control is active.
  50. clKeyPos:            Allow list positioning, based on user keypresses.  This assumes that
  51.                     the list is alphabetized so that key presses for location make sense.
  52.                     If typing by the user is fast enough, multiple characters will be
  53.                     used for the positioning.
  54. clTwoStep:            When using IsCtlEvent(), you may want the initial click on a List
  55.                     control to just select the control, or you may wish the click to start
  56.                     tracking in addition to selecting the control.  The tracking is
  57.                     considered the second step.  By setting this bit, you indicate that you
  58.                     want control selection and item selection to be a 2-step process.
  59.                     Setting this bit means that it will take 2 separate clicks by the
  60.                     user to select an item in the list if the list is inactive.
  61. clHasGrow:            This makes sure that there is space for the growIcon if the list
  62.                     has a scrollbar.  If the list occupies an entire window, then if there
  63.                     is only one scrollbar, the scrollbar has to be shrunk to make room
  64.                     for the growIcon.  The List Manager supposedly has this ability, but
  65.                     it doesn't work.  The List control manages it correctly.
  66. clDrawIt:            This is a List manager flag that is needed for the LNew() call.
  67.  
  68.  
  69. If the CLNew call succeeds, you then have a List control in your
  70. window.  It will be automatically disposed of when you close the window.
  71. If you don't want this to happen, then you can detach it from the
  72. view control which owns it.  To do this, you would to the following:
  73.  
  74.     viewCtl = CLViewFromList(theListHndl);
  75.     if (viewCtl) SetCRefCon(viewCtl, nil);
  76.  
  77. The view control keeps a reference to the List record in the refCon.
  78. If the refCon is cleared, then the view control does nothing.  So, all that
  79. is needed to detach a List record from a view control is to set the
  80. view control's refCon nil.  Now if you close the window, you will still
  81. have the List record.
  82.  
  83.  
  84. To remove a List control completely from a window, just dispose of the view
  85. control that holds the List record.  To do this, just do something like the below:
  86.  
  87.     DisposeControl(CLViewFromList(theListHndl));
  88.  
  89. This completely disposes of the List control.
  90.  
  91.  
  92. Events for the List record are handled nearly automatically.  Just make the
  93. following call:
  94.  
  95.     CLEvent(window, eventPtr, &action);
  96.  
  97. If the event was handled, true is returned.  If the event is false, then the
  98. event doesn't belong to a List control, and further processing of the event
  99. should be done.
  100.  
  101.  
  102.  
  103. Here is a list of the functions and a description as to their purpose:
  104.  
  105. void            CLActivate(Boolean active, ListHandle listHndl);
  106.     /* Activate this List record.  Activation is not done by calling LActivate().
  107.     ** The active control is indicated by the 2-pixel thick border around the
  108.     ** List control.  This allows all List controls in a window to display which
  109.     ** cells are selected.  This behavior can be overridden by calling LActivate()
  110.     ** on the List record for List controls.
  111.     ** Human interface dictates that only at most a single List control has this
  112.     ** active border.  For this reason, this function scans for other List
  113.     ** controls in the window and removes the border from any other that it finds. */
  114.  
  115. Boolean            CLClick(WindowPtr window, EventRecord *event, short *action);
  116.     /* This is called when a mouseDown occurs in the content of a window.  It
  117.     ** returns true if the mouseDown caused a List action to occur.  Events
  118.     ** that are handled include if the user clicks on a scrollbar that is
  119.     ** associated with a List control. */
  120.  
  121. ControlHandle    CLCtlHit(void);
  122.     /* The List control that was hit by calling FindControl is saved in a
  123.     ** global variable, since the CDEF has no way of returning what kind it was.
  124.     ** To determine that it was a List control that was hit, first call this
  125.     ** function.  The first call returns the old value in the global variable,
  126.     ** plus it resets the global to nil.  Then call FindControl(), and then
  127.     ** call this function again.  If it returns nil, then a List control
  128.     ** wasn't hit.  If it returns non-nil, then it was a List control that
  129.     ** was hit, and specifically the one returned. */
  130.  
  131. Boolean            CLEvent(WindowPtr window, EventRecord *event, short *action);
  132.     /* Handle the event if it applies to the active List control.  If some
  133.     ** action occured due to the event, return true. */
  134.  
  135. ListHandle        CLFindActive(WindowPtr window);
  136.     /* Returns the active List control, if any.  If nil is passed in, then
  137.     ** the return value represents whatever List control is active, independent
  138.     ** of what window it is in.  If a window is passed in, then it returns a
  139.     ** List control only if the active control is in the specified window.
  140.     ** If the active List control is in some other window, then nil is returned. */
  141.  
  142. Boolean            CLFindCtl(WindowPtr window, EventRecord *event, ListHandle *listHndl, ControlHandle *ctlHit);
  143.     /* This determines if a List control was clicked on directly.  This does
  144.     ** not determine if a related scrollbar was clicked on.  If a List
  145.     ** control was clicked on, then true is returned, as well as the List
  146.     ** handle and the handle to the view control. */
  147.  
  148. ListHandle        CLFromScroll(ControlHandle scrollCtl, ControlHandle *retCtl);
  149.     /* Find the List record that is related to the indicated scrollbar. */
  150.  
  151. short            CLInsert(ListHandle listHndl, char *data, short dataLen, short row, short col);
  152.     /* Insert a cell alphabetically into the list.  Whichever parameter is passed in
  153.     ** as -1, either row or column, that is the dimension that is determined. */
  154.  
  155. Boolean            CLKey(WindowPtr window, EventRecord *event);
  156.     /* See if the keypress event applies to the List control, and if it does,
  157.     ** handle it and return true. */
  158.  
  159. ListHandle        CLNew(short viewID, Boolean vis, Rect *vRect, short numRows, short numCols, short cellHeight, short cellWidth, short theLProc, WindowPtr window, short mode);
  160.     /* Create a new List control.  See the comments at the beginning of this
  161.     ** file for more information. */
  162.  
  163. ControlHandle    CLNext(WindowPtr window, ListHandle *listHndl, ControlHandle ctl, short dir, Boolean justActive);
  164.     /* Get the next List control in the window.  You pass it a control handle
  165.     ** for the view control, or nil to start at the beginning of the window.
  166.     ** It returns both a List handle and the view control handle for that
  167.     ** List record.  If none is found, nil is returned.  This allows you to
  168.     ** repeatedly call this function and walk through all the List controls
  169.     ** in a window. */
  170.  
  171. void            CLPrint(RgnHandle clipRgn, ListHandle listHndl, short *row, short *col, short leftEdge, Rect *drawRct);
  172.     /* From the starting for or column, print as many cells as will fit into the
  173.     ** designated rect.  Pass in a starting row and column, and they will be
  174.     ** adjusted to indicate the first cell that didn't fit into the rect.  If all
  175.     ** remaining cells were printed, the row is returned as -1.  The bottom of the
  176.     ** rect to print in is also adjusted to indicate where the actual cut-off
  177.     ** point was. */
  178.  
  179. short            CLRowOrColSearch(ListHandle listHndl, char *data, short dataLen, short row, short col);
  180.     /* Find the location in the list where the data would belong if inserted.  The row
  181.     ** and column are passed in.  If either is -1, that is the dimension that will be
  182.     ** determined and returned. */
  183.  
  184. void            CLUpdate(RgnHandle clipRgn, ListHandle list);
  185.     /* Draw the List control in the correct form. */
  186.  
  187. ControlHandle    CLViewFromList(ListHandle listHndl);
  188.     /* Return the control handle for the view control that owns the List
  189.     ** record.  Use this to find the view to do customizations such as changing
  190.     ** the update procedure for this List control. */
  191.  
  192. void            CLWindActivate(WindowPtr window);
  193.     /* This window is becoming active or inactive.  The borders of the List
  194.     ** controls need to be redrawn due to this.  For each List control in the
  195.     ** window, redraw the active border. */
  196.  
  197. void            CLSize(ListHandle list, short newH, short newV);
  198.     /* This resizes the list and it's viewCtl. */
  199.  
  200. void            CLMove(ListHandle list, short newH, short newV);
  201.     /* This moves the list and it's viewCtl. */
  202.  
  203.