home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / macintosh-pascal / macintoshp-1.2-demos.sit.hqx / chap18pascal_demo / ListsPascal.p next >
Text File  |  1999-04-05  |  31KB  |  1,198 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // ListsPascal.p
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  4. // 
  5. // This program allows the user to open a dialog box by choosing the Dialog With Lists
  6. // item in the Demonstration menu.
  7. //
  8. // The dialog box contains two lists.  The cells of one list contain text.  The cells of
  9. // the other list contain icon-like pictures and their titles.
  10. //
  11. // The text list uses the default list definition procedure.
  12. // 
  13. // The picture list uses a custom list definition procedure.  The source code for the
  14. // custom list definition procedure is at the file LDEFPascal.p in the LDEFPascal folder.
  15. //
  16. // The currently active list is outlined by a two-pixel-wide border.  The currently
  17. // active list can be changed by clicking in the non-active list or by pressing the tab
  18. // key.
  19. //
  20. // The text list uses the default cell-selection algorithm; accordingly, multiple cells, 
  21. // including discontiguous multiple cells, may be selected.  The picture list also
  22. // supports arrow key selection (of single or multiple cells) and type selection.
  23. //
  24. // The constant lOnlyOne is assigned to the selFlags field of the picture list's list
  25. // record.  Accordingly, the selection of multiple items is not possible in this list.
  26. // Arrow key selection (of single cells) is, however, supported.
  27. //
  28. // When the dialog is dismissed by clicking on the OK button, or by double-clicking on a
  29. // cell in the active list, the user's selections are displayed in a window opened by the
  30. // program at program launch.  (Note that the use of the Return, Enter, Esc and
  31. // Command-period keys as alternatives to clicking the OK and Cancel buttons in the
  32. // dialog box is not supported in this program.)
  33. //
  34. // The program utilizes the following resources:
  35. //
  36. // •    An 'MBAR' resource, and 'MENU' resources for Apple, File, Edit and Demonstration
  37. //        menus (preload, non-purgeable).
  38. //
  39. // •    A 'WIND' resource (purgeable) (initially visible) for the window in which the
  40. //        user's selections are displayed.  
  41. //
  42. // •    A'DLOG' resource (purgeable) and associated 'DITL' resource (purgeable) for the
  43. //        dialog box.
  44. //
  45. // •    'STR#' resources (purgeable) containing the text strings for the text list.
  46. //
  47. // •    'PICT' resources (non-purgeable) containing the images for the picture list.
  48. //
  49. // •    An 'LDEF' resource (non-purgeable) containing the custom list definition procedure
  50. //        used by the picture list.
  51. //
  52. // •    A 'SIZE' resource with the acceptSuspendResumeEvents and doesActivateOnFGSwitch
  53. //        flags set.
  54. //
  55. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  56.  
  57. program ListsPascal(input, output);
  58.  
  59. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  60.  
  61. uses
  62.  
  63.     Windows, Fonts, Menus, TextEdit, Quickdraw, Dialogs, QuickdrawText, Processes, Types, 
  64.     Memory, Events, TextUtils, ToolUtils, OSUtils, Devices, Lists, LowMem, SegLoad, Sound;
  65.  
  66. { ………………………………………………………………………………………………………………………………………………… define the following constants }
  67.  
  68. const
  69.  
  70. mApple = 128;
  71.  iAbout = 1;
  72. mFile = 129;
  73.  iQuit = 11;
  74. mDemonstration = 131;
  75.  iDialog = 1;
  76.  
  77. rMenubar = 128;
  78. rWindow = 128;
  79. rDialog = 129;
  80.  iOK = 1;
  81.  iCancel = 2;
  82.  iUserItemText = 3;
  83.  iUserItemPict = 4;
  84. rListCellStrings = 128;
  85. rListCellPicts = 128;
  86. rListCellPictTitles = 129;
  87.  
  88. kUpArrow = $1e;
  89. kDownArrow = $1f;
  90. kTab = $09;
  91. kScrollBarWidth = 15;
  92. kMaxKeyThresh = 120;
  93.  
  94. kSystemLDEF = 0;
  95. kCustomLDEF = 128;
  96.  
  97. kMaxLong = $7FFFFFFF;
  98.  
  99. { ………………………………………………………………………………………………………………………………………………………………………………… user-defined types }
  100.  
  101. type
  102.  
  103. ListsRec = record
  104.     textListHdl : ListRef;
  105.     pictListHdl : ListRef;
  106.     end;
  107.     
  108. ListsRecPtr = ^ListsRec;
  109. ListsRecHandle = ^ListsRecPtr;
  110.  
  111. { ……………………………………………………………………………………………………………………………………………………………………………………… global variables }
  112.  
  113. var
  114.  
  115. gDone : boolean;
  116. gInBackground : boolean;
  117. gWindowPtr : WindowPtr;
  118. gCurrentListHdl : ListRef;
  119. gTSString : string;    
  120. gTSResetThreshold : integer;    
  121. gTSLastKeyTime : longint;
  122. gTSLastListHit : ListRef;    
  123.  
  124. menubarHdl : Handle;
  125. menuHdl : MenuHandle;
  126. eventRec : EventRecord;
  127.  
  128. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInitManagers }
  129.  
  130. procedure DoInitManagers;
  131.  
  132.     begin
  133.     MaxApplZone;
  134.     MoreMasters;
  135.  
  136.     InitGraf(@qd.thePort);
  137.     InitFonts;
  138.     InitWindows;
  139.     InitMenus;
  140.     TEInit;
  141.     InitDialogs(nil);
  142.  
  143.     InitCursor;    
  144.     FlushEvents(everyEvent, 0);
  145.     end;
  146.         {of procedure DoInitManagers}
  147.         
  148. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDrawDialogDefaultButton }
  149.  
  150. procedure DoDrawDialogDefaultButton(theDialogPtr : DialogPtr);
  151.  
  152.     var
  153.     oldPort : WindowPtr;
  154.     oldPenState : PenState;
  155.     itemType : integer;
  156.     itemHandle : Handle;
  157.     itemRect : Rect;
  158.     buttonOval : integer;
  159.  
  160.     begin
  161.     GetPort(oldPort);
  162.     GetPenState(oldPenState);
  163.  
  164.     GetDialogItem(theDialogPtr, iOK, itemType, itemHandle, itemRect);
  165.     SetPort(ControlHandle(itemHandle)^^.contrlOwner);
  166.     InsetRect(itemRect, -4, -4);
  167.     buttonOval := (itemRect.bottom - itemRect.top) div 2 + 2;
  168.  
  169.     if (ControlHandle(itemHandle)^^.contrlHilite = 255) then
  170.         PenPat(qd.gray)
  171.     else
  172.         PenPat(qd.black);
  173.  
  174.     PenSize(3, 3);
  175.     FrameRoundRect(itemRect, buttonOval, buttonOval);
  176.  
  177.     SetPenState(oldPenState);
  178.     SetPort(oldPort);
  179.     end;
  180.         {of procedure DoDrawDialogDefaultButton}
  181.  
  182. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAddRowsAndDataToPictList }
  183.  
  184. procedure DoAddRowsAndDataToPictList(pictListHdl : ListRef; pictListID : integer);
  185.  
  186.     var
  187.     rowNumber, pictIndex : integer;
  188.     pictureHdl : PicHandle;
  189.     theCell : Cell;
  190.  
  191.     begin
  192.     rowNumber := pictListHdl^^.dataBounds.bottom;
  193.  
  194.     for pictIndex := pictListID to (pictListID + 5) do
  195.         begin    
  196.         pictureHdl := GetPicture(pictIndex);
  197.  
  198.         rowNumber := LAddRow(1, rowNumber, pictListHdl);
  199.         SetPt(theCell, 0, rowNumber);
  200.         LSetCell(@pictureHdl, sizeof(PicHandle), theCell, pictListHdl);
  201.     
  202.         rowNumber := rowNumber + 1;
  203.         end;
  204.     end;
  205.         {of procedure DoAddRowsAndDataToPictList}
  206.  
  207. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCreatePictList }
  208.  
  209. function DoCreatePictList(theDialogPtr : DialogPtr; listRect : Rect; 
  210.                                                 numCols, lDef : integer) : ListRef;
  211.  
  212.     var
  213.     dataBounds : Rect;
  214.     cellSize : Point;
  215.     pictListHdl : ListRef;
  216.     theCell : Cell;
  217.         
  218.     begin
  219.     SetRect(dataBounds, 0, 0, numCols, 0);
  220.     SetPt(cellSize, 48, 48);
  221.  
  222.     listRect.right := listRect.right - kScrollBarWidth;
  223.  
  224.     pictListHdl := LNew(listRect, dataBounds, cellSize, lDef, theDialogPtr, true,
  225.                                                                 false, false, true);
  226.  
  227.     pictListHdl^^.selFlags := lOnlyOne;
  228.  
  229.     DoAddRowsAndDataToPictList(pictListHdl, rListCellPicts);
  230.  
  231.     SetPt(theCell, 0, 0);
  232.     LSetSelect(true, theCell, pictListHdl);
  233.  
  234.     DoCreatePictList := pictListHdl;
  235.     end;
  236.         {of function DoCreatePictList}
  237.  
  238. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAddTextItemAlphabetically }
  239.  
  240. procedure DoAddTextItemAlphabetically(listHdl : ListRef; theString : string);
  241.  
  242.     var
  243.     found : boolean;
  244.     totalRows, currentRow, cellDataOffset, cellDataLength : integer;
  245.     aCell : Cell;
  246.  
  247.     begin
  248.     found := false;
  249.  
  250.     totalRows := listHdl^^.dataBounds.bottom - listHdl^^.dataBounds.top;
  251.     currentRow := -1;
  252.  
  253.     while not (found) do
  254.         begin
  255.         currentRow := currentRow + 1;
  256.         if (currentRow = totalRows) then
  257.             found := true
  258.         else begin
  259.             SetPt(aCell, 0, currentRow);
  260.             LGetCellDataLocation(cellDataOffset, cellDataLength, aCell, listHdl);
  261.  
  262.             MoveHHi(Handle(listHdl^^.cells));
  263.             HLock(Handle(listHdl^^.cells));
  264.  
  265.             if (IUMagPString(Ptr(longint(@theString) + 1), 
  266.                         (Ptr(longint(@listHdl^^.cells) + cellDataOffset)), 
  267.                                 integer(theString[0]), cellDataLength, nil) = -1) then
  268.                 begin
  269.                 found := true;
  270.                 end;
  271.  
  272.             HUnlock(Handle(listHdl^^.cells));
  273.             end;
  274.         end;
  275.  
  276.     currentRow := LAddRow(1, currentRow, listHdl);
  277.     SetPt(aCell, 0, currentRow);
  278.  
  279.     LSetCell((Ptr(longint(@theString) + 1)), integer(theString[0]), aCell, listHdl);
  280.     end;
  281.         {of procedure DoAddTextAlphabetically}
  282.  
  283. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAddRowsAndDataToTextList }
  284.  
  285. procedure DoAddRowsAndDataToTextList(textListHdl : ListRef; stringListID : integer);
  286.  
  287.     var
  288.     stringIndex : integer;
  289.     theString : string;
  290.  
  291.     begin
  292.     for stringIndex := 1 to 15 do 
  293.         begin
  294.         GetIndString(theString, stringListID, stringIndex);
  295.         DoAddTextItemAlphabetically(textListHdl, theString);    
  296.         end;
  297.     end;
  298.         {of procedure DoAddRowsAndDataToTextList}
  299.         
  300. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoResetTypeSelection }
  301.  
  302. procedure DoResetTypeSelection;
  303.  
  304.     begin    
  305.     gTSString[0] := char(0);
  306.     gTSLastListHit := nil;
  307.     gTSLastKeyTime := 0;
  308.     gTSResetThreshold := 2 * LMGetKeyThresh;    
  309.     if (gTSResetThreshold > kMaxKeyThresh) then
  310.         gTSResetThreshold := kMaxKeyThresh;    
  311.     end;
  312.         {of procedure DoResetTypeSelection}
  313.         
  314. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCreateTextList }
  315.  
  316. function DoCreateTextList(theDialogPtr : DialogPtr; listRect : Rect; 
  317.                                     numCols, lDef : integer) : ListRef;
  318.  
  319.     var
  320.     dataBounds : Rect;
  321.     cellSize : Point;
  322.     textListHdl : ListRef;
  323.     theCell : Cell;
  324.  
  325.     begin
  326.     SetRect(dataBounds, 0, 0, numCols, 0);
  327.     SetPt(cellSize, 0, 0);
  328.  
  329.     listRect.right := listRect.right - kScrollBarWidth;
  330.  
  331.     textListHdl := LNew(listRect, dataBounds, cellSize, lDef, theDialogPtr, 
  332.                                                         true, false, false, true);
  333.  
  334.     DoAddRowsAndDataToTextList(textListHdl, rListCellStrings);
  335.  
  336.     SetPt(theCell, 0, 0);
  337.     LSetSelect(true, theCell, textListHdl);
  338.  
  339.     DoResetTypeSelection;
  340.  
  341.     DoCreateTextList := textListHdl;
  342.     end;
  343.         {of function DoCreateTextList}
  344.  
  345. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoAdjustMenus }
  346.  
  347. procedure DoAdjustMenus;
  348.  
  349.     var
  350.     fileMenuHdl, demoMenuHdl : MenuHandle;
  351.  
  352.     begin
  353.     fileMenuHdl := GetMenuHandle(mFile);
  354.     demoMenuHdl := GetMenuHandle(mDemonstration);
  355.  
  356.     if (WindowPeek(FrontWindow)^.windowKind = dialogKind) then
  357.         begin
  358.         DisableItem(fileMenuHdl, 0);
  359.         DisableItem(demoMenuHdl, 0);
  360.         end
  361.     else begin
  362.         EnableItem(fileMenuHdl, 0);
  363.         EnableItem(demoMenuHdl, 0);
  364.         end;
  365.  
  366.     DrawMenuBar;
  367.     end;
  368.         {of procedure DoAdjustMenus}
  369.  
  370. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoCreateDialogWithLists }
  371.  
  372. procedure DoCreateDialogWithLists;
  373.  
  374.     var    
  375.     modalDlgPtr : DialogPtr;
  376.     listsRecHdl : ListsRecHandle;
  377.     fontNum, itemType : integer;
  378.     itemHdl : Handle;
  379.     itemRect : Rect;
  380.     textListHdl, pictListHdl : ListRef;
  381.  
  382.     begin
  383.     modalDlgPtr := GetNewDialog(rDialog, nil, WindowPtr(-1));
  384.     if (modalDlgPtr = nil) then
  385.         ExitToShell;
  386.  
  387.     listsRecHdl := ListsRecHandle(NewHandle(sizeof(ListsRec)));
  388.     if (listsRecHdl = nil) then
  389.         ExitToShell;
  390.     SetWRefCon(modalDlgPtr, longint(listsRecHdl));
  391.  
  392.     SetPort(modalDlgPtr);
  393.  
  394.     GetFNum('Chicago', fontNum);
  395.     TextFont(fontNum);
  396.     TextSize(12);
  397.  
  398.     GetDialogItem(modalDlgPtr, iUserItemText, itemType, itemHdl, itemRect);
  399.     textListHdl := DoCreateTextList(modalDlgPtr, itemRect, 1, kSystemLDEF);
  400.  
  401.     GetDialogItem(modalDlgPtr, iUserItemPict, itemType, itemHdl, itemRect);
  402.     pictListHdl := DoCreatePictList(modalDlgPtr, itemRect, 1, kCustomLDEF);
  403.  
  404.     listsRecHdl^^.textListHdl := textListHdl;
  405.     listsRecHdl^^.pictListHdl := pictListHdl;
  406.  
  407.     textListHdl^^.refCon := longint(pictListHdl);
  408.     pictListHdl^^.refCon := longint(textListHdl);
  409.  
  410.     gCurrentListHdl := textListHdl;
  411.  
  412.     ShowWindow(modalDlgPtr);
  413.     DoAdjustMenus;
  414.  
  415.     end;
  416.         {of procedure DoCreateDialogWithLists}
  417.  
  418. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMenuChoice }
  419.  
  420. procedure DoMenuChoice(menuChoice : longint);
  421.  
  422.     var
  423.     menuID, menuItem : integer;
  424.     itemName : string;
  425.     daDriverRefNum : integer;
  426.  
  427.     begin
  428.     menuID := HiWord(menuChoice);
  429.     menuItem := LoWord(menuChoice);
  430.  
  431.     if (menuID = 0) then
  432.         Exit(DoMenuChoice);
  433.  
  434.     case (menuID) of
  435.  
  436.         mApple: begin
  437.             if (menuItem = iAbout) then
  438.                 SysBeep(10)
  439.             else begin
  440.                 GetMenuItemText(GetMenuHandle(mApple), menuItem, itemName);
  441.                 daDriverRefNum := OpenDeskAcc(itemName);
  442.                 end;
  443.             end;
  444.             
  445.         mFile: begin
  446.             if (menuItem = iQuit) then
  447.                 gDone := true;
  448.             end;
  449.             
  450.         mDemonstration: begin
  451.             if (menuItem = iDialog) then
  452.                 begin
  453.                 SetPort(gWindowPtr);
  454.                 EraseRect(gWindowPtr^.portRect);
  455.                 DoCreateDialogWithLists;
  456.                 end;
  457.             end;
  458.         end;
  459.             {of case statement}
  460.  
  461.     HiliteMenu(0);
  462.     end;
  463.         {of procedure DoMenuChoice}
  464.  
  465. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDisplaySelections }
  466.  
  467. procedure DoDisplaySelections;
  468.  
  469.     var
  470.     listsRecHdl : ListsRecHandle;
  471.     textListHdl, pictListHdl : ListRef;
  472.     nextLine, cellIndex : integer;
  473.     theCell : Cell;
  474.     theString : string;
  475.     offset, dataLen : integer;
  476.     ignored : boolean;
  477.  
  478.     begin
  479.     nextLine := 15;
  480.     listsRecHdl := ListsRecHandle(GetWRefCon(FrontWindow));
  481.     textListHdl := listsRecHdl^^.textListHdl;
  482.     pictListHdl := listsRecHdl^^.pictListHdl;
  483.  
  484.     HideWindow(FrontWindow);    
  485.     SetPort(gWindowPtr);
  486.  
  487.     MoveTo(10, nextLine);
  488.     DrawString('TIMBER:');
  489.     MoveTo(120, nextLine);
  490.     DrawString('TOOL:');
  491.  
  492.     for cellIndex := 0 to (textListHdl^^.dataBounds.bottom - 1) do
  493.         begin
  494.         SetPt(theCell, 0, cellIndex);
  495.         if (LGetSelect(false, theCell, textListHdl)) then
  496.             begin
  497.             LGetCellDataLocation(offset, dataLen, theCell, textListHdl);
  498.             LGetCell(Ptr(longint(@theString) + 1), dataLen, theCell, textListHdl);
  499.             theString[0] := char(dataLen);
  500.  
  501.             nextLine := nextLine + 15;
  502.             MoveTo(10, nextLine);
  503.             DrawString(theString);
  504.             end;
  505.         end;
  506.  
  507.     SetPt(theCell, 0, 0);
  508.     ignored := LGetSelect(true, theCell, pictListHdl);
  509.     GetIndString(theString, rListCellPictTitles, theCell.v + 1);
  510.     MoveTo(120, 30);
  511.     DrawString(theString);
  512.     end;
  513.         {of procedure DoDisplaySelections}
  514.  
  515. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDrawActiveListBorder }
  516.  
  517. procedure DoDrawActiveListBorder(listHdl : ListRef);
  518.  
  519.     var
  520.     oldPenState : PenState;
  521.     borderRect : Rect;
  522.  
  523.     begin
  524.     GetPenState(oldPenState);
  525.     PenSize(2, 2);
  526.  
  527.     borderRect := listHdl^^.rView;
  528.     borderRect.right := borderRect.right + kScrollBarWidth;
  529.     InsetRect(borderRect, -4, -4);
  530.     
  531.     if ((listHdl = gCurrentListHdl) and listHdl^^.lActive) then
  532.         PenPat(qd.black)
  533.     else
  534.         PenPat(qd.white);
  535.  
  536.     FrameRect(borderRect);        
  537.  
  538.     SetPenState(oldPenState);
  539.     end;
  540.         {of procedure DoDrawActiveListBorder}
  541.         
  542. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoDrawListsBorders }
  543.  
  544. procedure DoDrawListsBorders(textListHdl, pictListHdl : ListRef);
  545.  
  546.     var
  547.     oldPenState : PenState;
  548.     borderRect : Rect;
  549.  
  550.     begin
  551.     GetPenState(oldPenState);
  552.     PenSize(1, 1);
  553.  
  554.     borderRect := textListHdl^^.rView;
  555.     InsetRect(borderRect, -1, -1);
  556.     FrameRect(borderRect);
  557.  
  558.     borderRect := pictListHdl^^.rView;
  559.     InsetRect(borderRect, -1, -1);
  560.     FrameRect(borderRect);
  561.  
  562.     SetPenState(oldPenState);
  563.     end;
  564.         {of procedure DoDrawListsBorders}
  565.  
  566. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoRotateCurrentList }
  567.  
  568. procedure DoRotateCurrentList;
  569.  
  570.     var
  571.     myWindowPtr : WindowPtr;
  572.     oldListHdl, newListHdl : ListRef;
  573.  
  574.     begin
  575.     myWindowPtr := FrontWindow;
  576.     if (WindowPeek(myWindowPtr)^.windowKind <> dialogKind) then
  577.         Exit(DoRotateCurrentList);    
  578.  
  579.     oldListHdl := gCurrentListHdl;
  580.     newListHdl := ListRef(gCurrentListHdl^^.refCon);
  581.     gCurrentListHdl := newListHdl;
  582.  
  583.     DoDrawActiveListBorder(oldListHdl);
  584.     DoDrawActiveListBorder(newListHdl);
  585.     end;
  586.         {of procedure DoRotateCurrentList}
  587.         
  588. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoFindNewCellLoc }
  589.  
  590. procedure DoFindNewCellLoc(listHdl : ListRef; oldCellLoc : Cell; var newCellLoc : Cell;
  591.                             charCode : UInt8; moveToTopBottom : boolean);
  592.  
  593.     var
  594.     listRows : integer;
  595.  
  596.     begin
  597.     listRows := listHdl^^.dataBounds.bottom - listHdl^^.dataBounds.top;
  598.     newCellLoc := oldCellLoc;
  599.  
  600.     if (moveToTopBottom) then
  601.          begin
  602.         if (charCode = kUpArrow) then
  603.             newCellLoc.v := 0
  604.         else if (charCode = kDownArrow) then
  605.             newCellLoc.v := listRows - 1;
  606.         end
  607.     else begin
  608.         if (charCode =  kUpArrow) then
  609.             begin
  610.             if (oldCellLoc.v <> 0) then
  611.                 newCellLoc.v := oldCellLoc.v - 1;
  612.             end    
  613.         else if (charCode = kDownArrow) then
  614.             begin
  615.             if (oldCellLoc.v <> listRows - 1) then
  616.                 newCellLoc.v := oldCellLoc.v + 1;
  617.             end;
  618.         end;
  619.     end;
  620.         {of procedure DoFindNewCellLoc}
  621.  
  622. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoFindFirstSelectedCell }
  623.  
  624. function DoFindFirstSelectedCell(listHdl : ListRef; var theCell : Cell) : boolean;
  625.  
  626.     var
  627.     result : boolean;
  628.  
  629.     begin
  630.     SetPt(theCell, 0, 0);
  631.     result := LGetSelect(true, theCell, listHdl);
  632.  
  633.     DoFindFirstSelectedCell := result;
  634.     end;
  635.         {of function DoFindFirstSelectedCell}
  636.  
  637. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoFindLastSelectedCell }
  638.  
  639. procedure DoFindLastSelectedCell(listHdl : ListRef; var theCell : Cell);
  640.  
  641.     var
  642.     aCell : Cell;
  643.     moreCellsInList : boolean;
  644.  
  645.     begin
  646.     if (DoFindFirstSelectedCell(listHdl, aCell)) then
  647.         begin
  648.         while (LGetSelect(true, aCell, listHdl)) do
  649.             begin
  650.             theCell := aCell;
  651.             moreCellsInList := LNextCell(true, true, aCell, listHdl);
  652.             end; 
  653.         end;
  654.     end;
  655.         {of procedure DoFindLastSelectedCell}
  656.  
  657. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMakeCellVisible }
  658.  
  659. procedure DoMakeCellVisible(listHdl : ListRef; newSelection : Cell);
  660.  
  661.     var
  662.     visibleRect : Rect;
  663.     dRows : integer;
  664.  
  665.     begin
  666.     visibleRect := listHdl^^.visible;
  667.  
  668.     if not(PtInRect(newSelection, visibleRect)) then
  669.         begin
  670.         if (newSelection.v > visibleRect.bottom - 1) then
  671.             dRows := newSelection.v - visibleRect.bottom + 1
  672.         else if (newSelection.v < visibleRect.top) then
  673.             dRows := newSelection.v - visibleRect.top;
  674.  
  675.         LScroll(0, dRows, listHdl);
  676.         end;
  677.     end;
  678.         {of procedure DoMakeCellVisible}
  679.         
  680. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoSelectOneCell }
  681.  
  682. procedure DoSelectOneCell(listHdl : ListRef; theCell : Cell) ;
  683.  
  684.     var
  685.     nextSelectedCell : Cell;
  686.     moreCellsInList : boolean;
  687.  
  688.     begin
  689.     if (DoFindFirstSelectedCell(listHdl, nextSelectedCell)) then
  690.         begin
  691.         while(LGetSelect(true, nextSelectedCell, listHdl)) do
  692.             begin
  693.             if (nextSelectedCell.v <> theCell.v) then
  694.                 LSetSelect(false, nextSelectedCell, listHdl)
  695.             else
  696.                 moreCellsInList := LNextCell(true, true, nextSelectedCell, listHdl);
  697.             end; 
  698.  
  699.         LSetSelect(true, theCell, listHdl);
  700.         end;
  701.     end;
  702.         {of procedure DoSelectOneCell}
  703.         
  704. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoSearchPartialMatch }
  705.  
  706. function DoSearchPartialMatch(searchDataPtr, cellDataPtr : Ptr;
  707.                                      cellDataLen, searchDataLen : integer ) : integer;
  708.  
  709.     var
  710.     result : integer;
  711.  
  712.     begin
  713.     if ((cellDataLen > 0) and (cellDataLen >= searchDataLen)) then
  714.         result := IUMagIDString(cellDataPtr, searchDataPtr, searchDataLen, searchDataLen)
  715.     else
  716.         result := 1;
  717.  
  718.     DoSearchPartialMatch := result;
  719.     end;
  720.         {of function DoSearchPartialMatch}    
  721.  
  722. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoTypeSelectSearch }
  723.  
  724. procedure DoTypeSelectSearch( listHdl : ListRef; var theEvent : EventRecord);
  725.  
  726.     var
  727.     newChar : char;
  728.     theCell : Cell;
  729.  
  730.     begin
  731.     newChar := chr(BAnd(theEvent.message, charCodeMask));
  732.  
  733.     if ((gTSLastListHit <> listHdl) or ((theEvent.when - gTSLastKeyTime) >= 
  734.          gTSResetThreshold) or (integer(gTSString[0]) = 255)) then
  735.         DoResetTypeSelection;
  736.  
  737.     gTSLastListHit := listHdl;
  738.     gTSLastKeyTime := theEvent.when;
  739.  
  740.     gTSString[0] := char(integer(gTSString[0]) + 1);
  741.     gTSString[integer(gTSString[0])] := newChar;
  742.  
  743.     SetPt(theCell, 0, 0);
  744.  
  745.     if (LSearch(Ptr(longint(@gTSString) + 1), integer(gTSString[0]), @DoSearchPartialMatch, 
  746.                                     theCell, listHdl)) then
  747.         begin
  748.         LSetSelect(true, theCell, listHdl);
  749.         DoSelectOneCell(listHdl, theCell);
  750.         DoMakeCellVisible(listHdl, theCell);
  751.         end;
  752.     end;
  753.         {of procedure DoTypeSelectSearch}
  754.  
  755. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoArrowKeyExtendSelection }
  756.  
  757. procedure DoArrowKeyExtendSelection(listHdl : ListRef; charCode : UInt8;
  758.                                             moveToTopBottom : boolean);
  759.  
  760.     var
  761.     currentSelection, newSelection : Cell;
  762.  
  763.     begin
  764.     if (DoFindFirstSelectedCell(listHdl, currentSelection)) then
  765.         begin
  766.         if (charCode = kDownArrow) then
  767.             DoFindLastSelectedCell(listHdl, currentSelection);
  768.  
  769.         DoFindNewCellLoc(listHdl, currentSelection, newSelection, charCode,
  770.                                                                 moveToTopBottom);
  771.  
  772.         if not (LGetSelect(false, newSelection, listHdl)) then
  773.             LSetSelect(true, newSelection, listHdl);
  774.  
  775.         DoMakeCellVisible(listHdl, newSelection);
  776.         end;
  777.     end;
  778.         {of procedure DoArrowKeyExtendSelection}
  779.  
  780. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoArrowKeyMoveSelection }
  781.  
  782. procedure DoArrowKeyMoveSelection(listHdl : ListRef; charCode : UInt8;
  783.                                             moveToTopBottom : boolean);
  784.  
  785.     var
  786.     currentSelection, newSelection : Cell;
  787.  
  788.     begin
  789.     if (DoFindFirstSelectedCell(listHdl, currentSelection)) then
  790.         begin
  791.         if (charCode = kDownArrow) then
  792.             DoFindLastSelectedCell(listHdl, currentSelection);
  793.  
  794.         DoFindNewCellLoc(listHdl, currentSelection, newSelection, charCode,
  795.                                                                 moveToTopBottom);
  796.  
  797.         DoSelectOneCell(listHdl, newSelection);
  798.         DoMakeCellVisible(listHdl, newSelection);
  799.         end;
  800.     end;
  801.         {of procedure DoArrowKeyMoveSelection}
  802.  
  803. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoHandleArrowKey }
  804.  
  805. procedure DoHandleArrowKey(charCode : UInt8; var theEvent : EventRecord;
  806.                                             allowExtendSelect : boolean);
  807.  
  808.     var
  809.     moveToTopBottom : boolean;
  810.  
  811.     begin
  812.     moveToTopBottom := false;
  813.  
  814.     if (BAnd(theEvent.modifiers, cmdKey) <> 0) then
  815.         moveToTopBottom := true;
  816.  
  817.     if (allowExtendSelect and (BAnd(theEvent.modifiers, shiftKey) <> 0)) then
  818.         DoArrowKeyExtendSelection(gCurrentListHdl, charCode, moveToTopBottom)
  819.     else
  820.         DoArrowKeyMoveSelection(gCurrentListHdl, charCode, moveToTopBottom);
  821.     end;
  822.         {of procedure DoHandleArrowKey}
  823.  
  824. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoItemHitInDialog }
  825.  
  826. procedure DoItemHitInDialog(myDialogPtr : DialogPtr; itemHit : integer);
  827.  
  828.     var
  829.     listsRecHdl : ListsRecHandle;
  830.  
  831.     begin
  832.     if ((itemHit = iOK) or (itemHit = iCancel)) then
  833.         begin
  834.         if (itemHit = iOK) then
  835.             DoDisplaySelections;
  836.  
  837.         listsRecHdl := ListsRecHandle(GetWRefCon(myDialogPtr));
  838.  
  839.         LDispose(listsRecHdl^^.textListHdl);
  840.         LDispose(listsRecHdl^^.pictListHdl);
  841.         DisposeHandle(Handle(listsRecHdl));
  842.         DisposeDialog(myDialogPtr);        
  843.  
  844.         DoAdjustMenus;
  845.         end;
  846.     end;
  847.         {of procedure DoItemHitInDialog}
  848.  
  849. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoInContent }
  850.  
  851. procedure DoInContent(var theEvent : EventRecord);
  852.  
  853.     var
  854.     oldPort : GrafPtr;
  855.     listsRecHdl : ListsRecHandle;
  856.     textListHdl, pictListHdl : ListRef;
  857.     textListRect, pictListRect, gCurrentListRect : Rect;
  858.     mouseXY : Point;
  859.     isDoubleClick : boolean;
  860.     theDialogPtr : DialogPtr;
  861.     itemHit : integer;
  862.  
  863.     begin
  864.     GetPort(oldPort);
  865.  
  866.     listsRecHdl := ListsRecHandle(GetWRefCon(FrontWindow));
  867.     textListHdl := listsRecHdl^^.textListHdl;
  868.     pictListHdl := listsRecHdl^^.pictListHdl;
  869.  
  870.     textListRect := listsRecHdl^^.textListHdl^^.rView;
  871.     pictListRect := listsRecHdl^^.pictListHdl^^.rView;
  872.     gCurrentListRect := gCurrentListHdl^^.rView;
  873.     textListRect.right := textListRect.right + kScrollBarWidth;    
  874.     pictListRect.right := pictListRect.right + kScrollBarWidth;    
  875.     gCurrentListRect.right := gCurrentListRect.right + kScrollBarWidth;
  876.  
  877.     mouseXY := theEvent.where;
  878.     GlobalToLocal(mouseXY);
  879.  
  880.     if ((PtInRect(mouseXY, textListRect) and (gCurrentListHdl <> textListHdl)) or
  881.          (PtInRect(mouseXY, pictListRect) and (gCurrentListHdl <> pictListHdl))) then
  882.         begin
  883.         DoRotateCurrentList;
  884.         end
  885.     else if (PtInRect(mouseXY, gCurrentListRect)) then
  886.         begin
  887.         SetPort(gCurrentListHdl^^.port);
  888.         isDoubleClick := LClick(mouseXY, theEvent.modifiers, gCurrentListHdl);
  889.         if (isDoubleClick) then
  890.             DoItemHitInDialog(FrontWindow, iOK);
  891.         end
  892.     else begin
  893.         if (DialogSelect(theEvent, theDialogPtr, itemHit)) then
  894.             DoItemHitInDialog(theDialogPtr, itemHit);
  895.         end;
  896.  
  897.     SetPort(oldPort);
  898.  
  899.     end;
  900.         {of procedure DoInContent}
  901.  
  902. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivateDialog }
  903.  
  904. procedure DoActivateDialog(myWindowPtr : WindowPtr; becomingActive : Boolean);
  905.  
  906.     var
  907.     listRecsHdl : ListsRecHandle;
  908.     textListHdl, pictListHdl : ListRef;
  909.     itemType : integer;
  910.     itemHdl : Handle;
  911.     itemRect : Rect;
  912.     
  913.     begin        
  914.     listRecsHdl := ListsRecHandle(GetWRefCon(myWindowPtr));
  915.     textListHdl := listRecsHdl^^.textListHdl;
  916.     pictListHdl := listRecsHdl^^.pictListHdl;
  917.     
  918.     if (becomingActive) then
  919.         begin
  920.         GetDialogItem(DialogPtr(myWindowPtr), iOK, itemType, itemHdl, itemRect);
  921.         HiliteControl(ControlHandle(itemHdl), 0);
  922.         GetDialogItem(DialogPtr(myWindowPtr), iCancel, itemType, itemHdl, itemRect);
  923.         HiliteControl(ControlHandle(itemHdl), 0);
  924.         DoDrawDialogDefaultButton(myWindowPtr);
  925.  
  926.         LActivate(true, textListHdl);
  927.         LActivate(true, pictListHdl);
  928.  
  929.         DoDrawActiveListBorder(gCurrentListHdl);
  930.         DoResetTypeSelection;
  931.         end
  932.     else begin
  933.         GetDialogItem(DialogPtr(myWindowPtr), iOK, itemType, itemHdl, itemRect);
  934.         HiliteControl(ControlHandle(itemHdl), 255);
  935.         GetDialogItem(DialogPtr(myWindowPtr), iCancel, itemType, itemHdl, itemRect);
  936.         HiliteControl(ControlHandle(itemHdl), 255);
  937.         DoDrawDialogDefaultButton(myWindowPtr);
  938.  
  939.         LActivate(false, textListHdl);
  940.         LActivate(false, pictListHdl);
  941.  
  942.         DoDrawActiveListBorder(gCurrentListHdl);
  943.         end;
  944.     end;
  945.         {of procedure DoActivateDialog}
  946.  
  947. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoOSEvent }
  948.  
  949. procedure DoOSEvent(var theEvent : EventRecord);
  950.  
  951.     begin
  952.     case BAnd(BSR(theEvent.message, 24), $000000FF) of
  953.  
  954.         suspendResumeMessage:
  955.             begin
  956.             gInBackground := BAnd(theEvent.message, resumeFlag) = 0;
  957.             if (WindowPeek(FrontWindow)^.windowKind = dialogKind) then
  958.                 DoActivateDialog(FrontWindow, not (gInBackground));
  959.             end;
  960.  
  961.         mouseMovedMessage:
  962.             begin
  963.             end;
  964.         end;
  965.             {of case statement}
  966.     end;
  967.         {of procedure DoOSEvent}
  968.  
  969. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoActivate }
  970.  
  971. procedure DoActivate(var theEvent : EventRecord);
  972.  
  973.     var
  974.     myWindowPtr : WindowPtr;
  975.     becomingActive : boolean;
  976.  
  977.     begin
  978.     myWindowPtr := WindowPtr(theEvent.message);
  979.     becomingActive := (BAnd(theEvent.modifiers, activeFlag) = activeFlag);
  980.  
  981.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  982.         DoActivateDialog(myWindowPtr, becomingActive);
  983.     end;
  984.         {of procedure DoActivate}
  985.         
  986. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdateLists }
  987.  
  988. procedure DoUpdateLists(myWindowPtr : WindowPtr);
  989.  
  990.     var
  991.     listsRecHdl : ListsRecHandle;
  992.     textListHdl, pictListHdl : ListRef;
  993.  
  994.     begin
  995.     listsRecHdl := ListsRecHandle(GetWRefCon(myWindowPtr));
  996.     
  997.     textListHdl := listsRecHdl^^.textListHdl;
  998.     pictListHdl := listsRecHdl^^.pictListHdl;
  999.  
  1000.     SetPort(textListHdl^^.port);
  1001.  
  1002.     LUpdate(textListHdl^^.port^.visRgn, textListHdl);
  1003.     LUpdate(pictListHdl^^.port^.visRgn, pictListHdl);
  1004.  
  1005.     DoDrawListsBorders(textListHdl, pictListHdl);
  1006.     DoDrawActiveListBorder(textListHdl);
  1007.     DoDrawActiveListBorder(pictListHdl);
  1008.     end;
  1009.         {of procedure DoUpdateLists}
  1010.         
  1011. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoUpdate }
  1012.  
  1013. procedure DoUpdate(var theEvent : EventRecord);
  1014.  
  1015.     var
  1016.     myWindowPtr : WindowPtr;
  1017.     
  1018.     begin
  1019.     myWindowPtr := WindowPtr(theEvent.message);
  1020.  
  1021.     BeginUpdate(myWindowPtr);
  1022.  
  1023.     if (WindowPeek(myWindowPtr)^.windowKind = dialogKind) then
  1024.         begin
  1025.         UpdateDialog(myWindowPtr, myWindowPtr^.visRgn);
  1026.         DoDrawDialogDefaultButton(myWindowPtr);    
  1027.         DoUpdateLists(myWindowPtr);
  1028.         end;
  1029.  
  1030.     EndUpdate(myWindowPtr);
  1031.  
  1032.     end;
  1033.         {of procedure DoUpdate}
  1034.         
  1035. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoKeyDown }
  1036.  
  1037. procedure DoKeyDown(charCode : UInt8; var theEvent : EventRecord);
  1038.  
  1039.     var
  1040.     listsRecHdl : ListsRecHandle;
  1041.     allowExtendSelect : boolean;
  1042.  
  1043.     begin
  1044.     if (WindowPeek(FrontWindow)^.windowKind = dialogKind) then
  1045.         begin
  1046.         listsRecHdl := ListsRecHandle(GetWRefCon(FrontWindow));
  1047.  
  1048.         if (charCode = kTab) then
  1049.             DoRotateCurrentList 
  1050.         else if ((charCode = kUpArrow) or (charCode = kDownArrow)) then
  1051.             begin
  1052.             if (gCurrentListHdl = listsRecHdl^^.textListHdl) then
  1053.                 allowExtendSelect := true
  1054.             else
  1055.                 allowExtendSelect := false;
  1056.             DoHandleArrowKey(charCode, theEvent, allowExtendSelect);
  1057.             end
  1058.         else begin
  1059.             if (gCurrentListHdl = listsRecHdl^^.textListHdl) then
  1060.                 DoTypeSelectSearch(listsRecHdl^^.textListHdl, theEvent);
  1061.             end;
  1062.         end;
  1063.     end;
  1064.         {of procedure DoKeyDown}
  1065. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoMouseDown }
  1066.  
  1067. procedure DoMouseDown(var theEvent : EventRecord);
  1068.  
  1069.     var
  1070.     partCode : integer;
  1071.     myWindowPtr : WindowPtr;
  1072.  
  1073.     begin
  1074.     partCode := FindWindow(theEvent.where, myWindowPtr);
  1075.  
  1076.     case (partCode) of
  1077.  
  1078.         inMenuBar: begin
  1079.             DoAdjustMenus;
  1080.             DoMenuChoice(MenuSelect(theEvent.where));
  1081.             end;
  1082.  
  1083.         inSysWindow: begin
  1084.             SystemClick(theEvent, myWindowPtr);
  1085.             end;
  1086.  
  1087.         inContent: begin
  1088.             if (myWindowPtr <> FrontWindow) then
  1089.                 begin
  1090.                 if (WindowPeek(FrontWindow)^.windowKind = dialogKind) then
  1091.                      SysBeep(10)
  1092.                 else SelectWindow(myWindowPtr);
  1093.                 end
  1094.             else begin
  1095.                 if (WindowPeek(FrontWindow)^.windowKind = dialogKind) then
  1096.                     DoInContent(theEvent);
  1097.                 end;
  1098.             end;
  1099.             
  1100.         inDrag: begin
  1101.             if ((WindowPeek(FrontWindow)^.windowKind = dialogKind) and 
  1102.                  (WindowPeek(myWindowPtr)^.windowKind <> dialogKind)) then
  1103.                 begin
  1104.                 SysBeep(10);
  1105.                 Exit(DoMouseDown);
  1106.                 end;
  1107.             DragWindow(myWindowPtr, theEvent.where, qd.screenBits.bounds);
  1108.             end;
  1109.         end;
  1110.             {of statement}
  1111.     end;
  1112.         {of procedure DoMouseDown}
  1113.         
  1114. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DoEvents }
  1115.  
  1116. procedure DoEvents(var theEvent : EventRecord);
  1117.  
  1118.     var
  1119.     charCode : UInt8;
  1120.  
  1121.     begin
  1122.     case (theEvent.what) of
  1123.  
  1124.         mouseDown: begin
  1125.             DoMouseDown(theEvent);
  1126.             end;
  1127.  
  1128.         keyDown, autoKey: begin
  1129.             charCode := UInt8(BAnd(theEvent.message, charCodeMask));
  1130.             if (BAnd(theEvent.modifiers, cmdKey) <> 0) then
  1131.                 begin
  1132.                 DoAdjustMenus;
  1133.                 DoMenuChoice(MenuKey(char(charCode)));
  1134.                 end;
  1135.             DoKeyDown(charCode, theEvent);
  1136.             end;
  1137.  
  1138.         updateEvt: begin
  1139.             DoUpdate(theEvent);
  1140.             end;
  1141.  
  1142.         activateEvt: begin
  1143.             DoActivate(theEvent);
  1144.             end;
  1145.  
  1146.         osEvt: begin
  1147.             DoOSEvent(theEvent);
  1148.             HiliteMenu(0);
  1149.             end;
  1150.         end;
  1151.             {of case statement}
  1152.     end;
  1153.         {of procedure DoEvents}
  1154.  
  1155. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ start of main program }
  1156.  
  1157. begin
  1158.  
  1159.     { …………………………………………………………………………………………………………………………………………………………………… initialize managers }
  1160.  
  1161.     DoInitManagers;
  1162.     
  1163.     { …………………………………………………………………………………………………………………………………………………… set up menu bar and menus }
  1164.     
  1165.     menubarHdl := GetNewMBar(rMenubar);
  1166.     if (menubarHdl = nil) then
  1167.         ExitToShell;
  1168.     SetMenuBar(menubarHdl);
  1169.     DrawMenuBar;
  1170.  
  1171.     menuHdl := GetMenuHandle(mApple);
  1172.     if (menuHdl = nil) then
  1173.         ExitToShell
  1174.     else
  1175.         AppendResMenu(menuHdl, 'DRVR');
  1176.     
  1177.     { ………………………………………………………………………………………………………………………………………………………………………………………… open window }
  1178.  
  1179.     gWindowPtr := GetNewWindow(rWindow, nil, WindowPtr(-1));
  1180.     if (gWindowPtr = nil) then
  1181.             ExitToShell;
  1182.  
  1183.     SetPort(gWindowPtr);
  1184.     TextSize(10);
  1185.  
  1186.     { ……………………………………………………………………………………………………………………………………………………………………………… enter eventLoop }
  1187.     
  1188.     gDone := false;
  1189.     
  1190.     while not (gDone) do
  1191.         begin
  1192.         if (WaitNextEvent(everyEvent, eventRec, kMaxLong, nil)) then
  1193.             DoEvents(eventRec);
  1194.         end;
  1195.  
  1196. end.
  1197.     
  1198. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }