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 / chap23pascal_demo / chap18pascal_demoPPC / ListsPascalPPC.p < prev    next >
Text File  |  1997-01-07  |  31KB  |  1,206 lines

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