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 / chap20pascal_demo / UFloatRoutines.p < prev    next >
Text File  |  1997-01-23  |  21KB  |  750 lines

  1. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
  2. // UFloatRoutines.p                                   Routines to support floating windows
  3. // ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  4.  
  5. unit UFloatRoutines;
  6.  
  7.  
  8.  
  9. interface
  10.  
  11. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  12.  
  13. uses
  14.  
  15.     Types, Events, Quickdraw,
  16.     
  17. { ……………………………………………………………………………………………………………………… include the following user-defined units }
  18.  
  19.     UFloaters;
  20.  
  21. { ………………………………………………………………………………………………………………………………………… exported functions and procedures }
  22.  
  23.     function  NewGetNewWindow(windResourceID : integer; behind : WindowPtr;
  24.                 activateHandler : ActivateProcPtr; windowType : integer) : WindowPtr;
  25.     procedure NewHideWindow(windowToHidePtr : WindowPtr);
  26.     procedure NewShowWindow(windowToShowPtr : WindowPtr);
  27.     procedure NewSelectWindow(windowToSelectPtr : WindowPtr);
  28.     procedure NewDragWindow(theWindowPtr : WindowPtr; startPoint : Point; 
  29.                 {$CONST} var dragBounds : Rect);
  30.     procedure NewDisposeWindow(theWindowPtr : WindowPtr);
  31.     procedure HandleSuspendEvent;
  32.     procedure HandleResumeEvent;
  33.     procedure DeactivateFloatsAndFirstDocWin;
  34.     procedure ActivateFloatsAndFirstDocWin;
  35.     function  FindFrontNonFloatingWindow : WindowPtr;
  36.     function  IsWindowModal(theWindowPtr : WindowPtr) : boolean;
  37.     function  GetWindowVisible(theWindowPtr : WindowPtr) : boolean;
  38.  
  39.  
  40.  
  41. implementation
  42.  
  43. { ………………………………………………………………………………………………………………… include the following Universal Interfaces }
  44.  
  45. uses
  46.  
  47.     Windows, Fonts, Menus, TextEdit, Dialogs, QuickdrawText, Processes, LowMem, 
  48.     Memory, TextUtils, ToolUtils, OSUtils, Devices, SegLoad, GestaltEqu, 
  49.     
  50. { ……………………………………………………………………………………………………………………… include the following user-defined units }
  51.  
  52.     UFloaters;
  53.  
  54. { ……………………………………………………………………………………………………………………………………… procedure and function definitions }
  55.  
  56.     procedure DeactivateWindow(theWindowPtr : WindowPtr); forward;
  57.     procedure ActivateWindow(theWindowPtr : WindowPtr); forward;
  58.     procedure HighlightAndActivateWindow(theWindowPtr : WindowPtr;
  59.                 activate : boolean); forward;
  60.     function  FindLastFloatingWindow : WindowPtr; forward;
  61.     function  GetWindowList : WindowPtr; forward;
  62.     procedure SetWindowList(theWindowPtr : WindowPtr); forward;
  63.     function  GetNextWindow(theWindowPtr : WindowPtr) : WindowPtr; forward;
  64.     procedure SetNextWindow(theWindowPtr, nextWindowPtr : WindowPtr); forward;
  65.     function  GetWasVisible(theWindowPtr : WindowPtr) : boolean; forward;
  66.     procedure SetWasVisible(theWindowPtr : WindowPtr;  wasVisible : boolean); forward;
  67.     function  GetWindowKind(theWindowPtr : WindowPtr) : integer; forward;
  68.     procedure SetWindowKind(theWindowPtr : WindowPtr; windowKind : integer); forward;
  69.     function  GetStructureRegion(theWindowPtr : WindowPtr) : RgnHandle; forward;
  70.     function  GetContentRegion(theWindowPtr : WindowPtr) : RgnHandle; forward;
  71.     procedure SetWindowHilite(theWindowPtr : WindowPtr; windowHilite : boolean); forward;
  72.  
  73. { …………………………………………………………………………………………………………………………… procedure and function implementations }
  74.  
  75. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewGetNewWindow }
  76.  
  77. function  NewGetNewWindow(windResourceID : integer; behind : WindowPtr;
  78.                 activateHandler : ActivateProcPtr; windowType : integer) : WindowPtr;
  79.  
  80.     var
  81.     docRecordHdl : DocRecordHandle;
  82.     theErr : OSErr;
  83.     response : longint;
  84.     newWindowPtr : WindowPtr;
  85.     lastFloatingWindowPtr : WindowPtr;
  86.  
  87.     begin
  88.     docRecordHdl := DocRecordHandle(NewHandle(sizeof(DocRecord)));
  89.  
  90.     theErr := Gestalt(gestaltQuickdrawVersion, response);
  91.     if (response < gestalt32BitQD) then
  92.         newWindowPtr := GetNewWindow(windResourceID, nil, WindowPtr(behind))
  93.     else
  94.         newWindowPtr := GetNewCWindow(windResourceID, nil, WindowPtr(behind));
  95.  
  96.     if (newWindowPtr <> nil) then
  97.         begin
  98.         SetWRefCon(newWindowPtr, longint(docRecordHdl));
  99.         docRecordHdl := DocRecordHandle(GetWRefCon(newWindowPtr));
  100.         docRecordHdl^^.activateHandler := activateHandler;
  101.  
  102.         if (windowType = kFloatingKind) then
  103.             begin
  104.             SetWindowKind(newWindowPtr, kFloatingKind);
  105.             HiliteWindow(newWindowPtr, true);
  106.             end
  107.         else begin
  108.             SetWindowKind(newWindowPtr, kDocumentKind);
  109.             if (behind = WindowPtr(-1)) then
  110.                 begin
  111.                 lastFloatingWindowPtr := FindLastFloatingWindow;
  112.                     
  113.                 if (lastFloatingWindowPtr <> nil) then
  114.                     SendBehind(newWindowPtr, lastFloatingWindowPtr)
  115.                 else
  116.                     BringToFront(newWindowPtr);
  117.                 end;
  118.             end;
  119.         end
  120.     else
  121.         DisposeHandle(Handle(docRecordHdl));
  122.  
  123.     NewGetNewWindow := newWindowPtr;
  124.     end;
  125.         {of function NewGetNewWindow}
  126.         
  127. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewDisposeWindow }
  128.  
  129. procedure NewDisposeWindow(theWindowPtr : WindowPtr);
  130.  
  131.     begin
  132.     if (GetWindowVisible(theWindowPtr)) then
  133.         NewHideWindow(theWindowPtr);
  134.     CloseWindow(theWindowPtr);
  135.     DisposeHandle(Handle(GetWRefCon(theWindowPtr)));
  136.     DisposePtr(Ptr(theWindowPtr));
  137.     end;
  138.         {of function NewGetNewWindow}
  139.  
  140. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewSelectWindow }
  141.  
  142. procedure NewSelectWindow(windowToSelectPtr : WindowPtr);
  143.  
  144.     var
  145.     isFloatingWindow : boolean;
  146.     currentFrontWindowPtr : WindowPtr;
  147.     lastFloatingWindowPtr : WindowPtr;
  148.     
  149.     begin
  150.     if (GetWindowKind(windowToSelectPtr) = kFloatingKind) then
  151.         begin
  152.         isFloatingWindow := true;
  153.         currentFrontWindowPtr := FrontWindow;
  154.         end
  155.     else begin
  156.         isFloatingWindow := false;
  157.         currentFrontWindowPtr := FindFrontNonFloatingWindow;
  158.         lastFloatingWindowPtr := FindLastFloatingWindow;
  159.         end;
  160.  
  161.     if (currentFrontWindowPtr <> windowToSelectPtr) then
  162.         begin
  163.         if (isFloatingWindow) then
  164.             BringToFront(windowToSelectPtr)
  165.         else begin
  166.             if (lastFloatingWindowPtr = nil) then
  167.                 SelectWindow(windowToSelectPtr)
  168.             else begin
  169.                 DeactivateWindow(currentFrontWindowPtr);
  170.                 SendBehind(windowToSelectPtr, lastFloatingWindowPtr);
  171.                 ActivateWindow(windowToSelectPtr);
  172.                 end;
  173.             end;
  174.         end;
  175.     end;
  176.         {of procedure NewSelectWindow}
  177.  
  178. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewHideWindow }
  179.  
  180. procedure NewHideWindow(windowToHidePtr : WindowPtr);
  181.  
  182.     var
  183.     frontFloaterPtr : WindowPtr;
  184.     frontNonFloaterPtr : WindowPtr;
  185.     windowBehindPtr : WindowPtr;
  186.     lastFloaterPtr : WindowPtr;
  187.  
  188.     begin
  189.     if (GetWindowVisible(windowToHidePtr) = false) then
  190.         Exit(NewHideWindow);
  191.  
  192.     frontFloaterPtr := FrontWindow;
  193.     if (GetWindowKind(frontFloaterPtr) <> kFloatingKind) then
  194.         frontFloaterPtr := nil;
  195.  
  196.     frontNonFloaterPtr := FindFrontNonFloatingWindow;
  197.  
  198.     ShowHide(windowToHidePtr, false);
  199.  
  200.     if (windowToHidePtr = frontFloaterPtr) then
  201.         begin
  202.         windowBehindPtr := GetNextWindow(windowToHidePtr);
  203.  
  204.         if ((windowBehindPtr <> nil) and (GetWindowKind(windowBehindPtr) = kFloatingKind)) then
  205.             begin
  206.             SetNextWindow(windowToHidePtr, GetNextWindow(windowBehindPtr));
  207.             SetNextWindow(windowBehindPtr, windowToHidePtr);
  208.             SetWindowList(windowBehindPtr);
  209.             end;
  210.         end
  211.     else begin
  212.         if (windowToHidePtr = frontNonFloaterPtr) then
  213.             begin
  214.             windowBehindPtr := GetNextWindow(windowToHidePtr);
  215.  
  216.             if (windowBehindPtr <> nil) then
  217.                 begin
  218.                 SetNextWindow(windowToHidePtr, GetNextWindow(windowBehindPtr));
  219.                 SetNextWindow(windowBehindPtr, windowToHidePtr);
  220.  
  221.                 lastFloaterPtr := FindLastFloatingWindow;
  222.                 if (lastFloaterPtr <> nil) then
  223.                     SetNextWindow(lastFloaterPtr, windowBehindPtr)
  224.                 else
  225.                     SetWindowList(windowBehindPtr);
  226.  
  227.                 ActivateWindow(windowBehindPtr);
  228.                 end;
  229.             end;
  230.         end;
  231.     end;
  232.         {of procedure NewHideWindow}
  233.         
  234. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewShowWindow }
  235.  
  236. procedure NewShowWindow(windowToShowPtr : WindowPtr);
  237.  
  238.     var
  239.     windowType : integer;
  240.     windowBehindPtr : WindowPtr;
  241.     frontNonFloatingWindowPtr : WindowPtr;
  242.     windowIsInFront : boolean;
  243.     activateHandler : ActivateProcPtr;
  244.     docRecordHdl : DocRecordHandle;
  245.  
  246.     begin
  247.     windowIsInFront := false;
  248.     
  249.     if (GetWindowVisible(windowToShowPtr) <> false) then
  250.         Exit(NewShowWindow);
  251.  
  252.     windowType := GetWindowKind(windowToShowPtr);
  253.     
  254.     if (windowType <> kFloatingKind) then
  255.         begin
  256.         windowBehindPtr := GetNextWindow(windowToShowPtr);
  257.         if (windowBehindPtr = FindFrontNonFloatingWindow) then
  258.             begin
  259.             if (windowBehindPtr <> nil) then
  260.                 DeactivateWindow(windowBehindPtr);
  261.  
  262.             SetWindowHilite(windowToShowPtr, true);
  263.             windowIsInFront := true;
  264.             end;
  265.         end
  266.     else begin
  267.         frontNonFloatingWindowPtr := FindFrontNonFloatingWindow;
  268.  
  269.         if ((frontNonFloatingWindowPtr <> nil) and 
  270.              (frontNonFloatingWindowPtr = FrontWindow) and
  271.              (IsWindowModal(frontNonFloatingWindowPtr))) then
  272.             begin
  273.             SetWindowHilite(windowToShowPtr, false);
  274.             end
  275.         else begin
  276.             SetWindowHilite(windowToShowPtr, true);
  277.             windowIsInFront := true;
  278.             end;
  279.         end;
  280.  
  281.     ShowHide(windowToShowPtr, true);
  282.  
  283.     if (windowIsInFront) then
  284.         begin
  285.         docRecordHdl := DocRecordHandle(GetWRefCon(windowToShowPtr));
  286.         activateHandler := docRecordHdl^^.activateHandler;
  287.         activateHandler(windowToShowPtr, true);
  288.         end;
  289.     end;
  290.         {of procedure NewShowWindow}
  291.  
  292. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ NewDragWindow }
  293.  
  294. procedure NewDragWindow(theWindowPtr : WindowPtr; startPoint : Point; 
  295.             {$CONST} var dragBounds : Rect);
  296.  
  297.     var
  298.     topLimit : integer;
  299.     slopRect : Rect;
  300.     oldPort : GrafPtr;
  301.     windowManagerPort : GrafPtr;
  302.     theKeyMap : KeyMap;
  303.     commandKeyDown : boolean;
  304.     dragRegion : RgnHandle;
  305.     dragResult : longint;
  306.     horizOffset : integer;
  307.     vertOffset : integer;
  308.     windowContentRegion : RgnHandle;
  309.     newHorizWindowPosition : integer;
  310.     newVertWindowPosition : integer;
  311.  
  312.     begin
  313.     commandKeyDown := false;
  314.     
  315.     if (WaitMouseUp) then
  316.         begin
  317.         topLimit := GetMBarHeight + 4;
  318.         slopRect := dragBounds;
  319.  
  320.         if (slopRect.top < topLimit) then
  321.             slopRect.top := topLimit;
  322.  
  323.         GetPort(oldPort);
  324.         GetWMgrPort(windowManagerPort);
  325.         SetPort(windowManagerPort);
  326.  
  327.         SetClip(GetGrayRgn);
  328.  
  329.         GetKeys(theKeyMap);
  330.         if (BAnd(theKeyMap[1], $8000) <> 0) then
  331.             commandKeyDown := true;
  332.  
  333.         if ((commandKeyDown = true) or 
  334.             (GetWindowKind(theWindowPtr) <> kFloatingKind)) then
  335.             begin
  336.             if (commandKeyDown = false) then
  337.                 ClipAbove(WindowRef(WindowPeek(FindFrontNonFloatingWindow)))
  338.             else
  339.                 ClipAbove(WindowRef(WindowPeek(theWindowPtr)));
  340.             end;
  341.  
  342.         dragRegion := NewRgn;
  343.         CopyRgn(GetStructureRegion(theWindowPtr), dragRegion);
  344.  
  345.         dragResult := DragGrayRgn(dragRegion, startPoint, slopRect, slopRect, 
  346.                     noConstraint, nil);
  347.  
  348.         SetPort(oldPort);
  349.  
  350.         if (dragResult <> 0) then
  351.             begin
  352.             horizOffset := BAnd(dragResult, $FFFF);
  353.             vertOffset := BSR(dragResult, 16);
  354.  
  355.             if (vertOffset <> -32768) then
  356.                 begin
  357.                 windowContentRegion := GetContentRegion(theWindowPtr);
  358.     
  359.                 newHorizWindowPosition := windowContentRegion^^.rgnBBox.left 
  360.                                                                         + horizOffset;
  361.                 newVertWindowPosition := windowContentRegion^^.rgnBBox.top + vertOffset;
  362.                 
  363.                 MoveWindow(theWindowPtr, newHorizWindowPosition, newVertWindowPosition, 
  364.                                 false);
  365.                 end;
  366.             end;
  367.  
  368.         if (commandKeyDown = false) then
  369.             NewSelectWindow(theWindowPtr);
  370.     
  371.         DisposeRgn(dragRegion);
  372.         end;
  373.     end;
  374.         {of procedure NewDragWindow}
  375.  
  376. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ HandleSuspendEvent }
  377.  
  378. procedure HandleSuspendEvent;
  379.  
  380.     var
  381.     currentWindowPtr : WindowPtr;
  382.     windowIsVisible : boolean;
  383.     
  384.     begin
  385.     currentWindowPtr := GetWindowList;
  386.  
  387.     if (GetWindowKind(currentWindowPtr) <> kFloatingKind) then
  388.         Exit(HandleSuspendEvent);
  389.  
  390.     while ((currentWindowPtr <> nil) &
  391.                     (GetWindowKind(currentWindowPtr) = kFloatingKind)) do
  392.         begin
  393.         windowIsVisible := GetWindowVisible(currentWindowPtr);
  394.         SetWasVisible(currentWindowPtr, windowIsVisible);
  395.         if (windowIsVisible) then
  396.             ShowHide(currentWindowPtr, false);
  397.         currentWindowPtr := GetNextWindow(currentWindowPtr);
  398.         end;
  399.  
  400.     currentWindowPtr := FindFrontNonFloatingWindow;
  401.     if (currentWindowPtr <> nil) then
  402.         begin
  403.         DrawGrowIcon(currentWindowPtr);
  404.         DeactivateWindow(currentWindowPtr);
  405.         end;
  406.     end;
  407.         {of procedure HandleSuspendEvent}
  408.  
  409. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ HandleResumeEvent }
  410.  
  411. procedure HandleResumeEvent;
  412.  
  413.     var
  414.     currentWindowPtr : WindowPtr;
  415.     windowWasVisible : boolean;
  416.  
  417.     begin
  418.     currentWindowPtr := GetWindowList;
  419.  
  420.     if (GetWindowKind(currentWindowPtr) <> kFloatingKind) then
  421.         Exit(HandleResumeEvent);
  422.  
  423.     while((currentWindowPtr <> nil) &
  424.                     (GetWindowKind(currentWindowPtr) = kFloatingKind)) do
  425.         begin
  426.         windowWasVisible := GetWasVisible(currentWindowPtr);
  427.         if (windowWasVisible) then
  428.             begin
  429.             ShowHide(currentWindowPtr, true);
  430.             ActivateWindow(currentWindowPtr);
  431.             end;
  432.         currentWindowPtr := GetNextWindow(currentWindowPtr);
  433.         end;
  434.  
  435.     currentWindowPtr := FindFrontNonFloatingWindow;
  436.     if (currentWindowPtr <> nil) then
  437.         begin
  438.         DrawGrowIcon(currentWindowPtr);
  439.         ActivateWindow(currentWindowPtr);
  440.         end;
  441.     end;
  442.         {of procedure HandleResumeEvent}
  443.  
  444. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DeactivateFloatsAndFirstDocWin }
  445.  
  446. procedure DeactivateFloatsAndFirstDocWin;
  447.  
  448.     var
  449.     firstWindowPtr : WindowPtr;
  450.     secondDocumentWindowPtr : WindowPtr;
  451.     currentWindowPtr : WindowPtr;
  452.  
  453.     begin
  454.     firstWindowPtr := FrontWindow;
  455.     secondDocumentWindowPtr := FindFrontNonFloatingWindow;
  456.     if (secondDocumentWindowPtr <> nil) then
  457.         secondDocumentWindowPtr := GetNextWindow(secondDocumentWindowPtr);
  458.  
  459.     currentWindowPtr := firstWindowPtr;
  460.     while (currentWindowPtr <> secondDocumentWindowPtr) do
  461.         begin
  462.         if (GetWindowVisible(currentWindowPtr)) then
  463.             DeactivateWindow(currentWindowPtr);
  464.         currentWindowPtr := GetNextWindow(currentWindowPtr);
  465.         end;
  466.     end;
  467.         {of procedure DeactivateFloatsAndFirstDocWin}
  468.  
  469. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ ActivateFloatsAndFirstDocWin }
  470.  
  471. procedure ActivateFloatsAndFirstDocWin;
  472.  
  473.     var
  474.     getFrontProcessResult : OSErr;
  475.     getCurrentProcessResult : OSErr;
  476.     frontPSN : ProcessSerialNumber;
  477.     currentPSN : ProcessSerialNumber;
  478.     sameProcessResult : OSErr;
  479.     isSameProcess : boolean;
  480.     firstWindowPtr : WindowPtr;
  481.     secondDocumentWindowPtr : WindowPtr;
  482.     currentWindowPtr : WindowPtr;
  483.  
  484.     begin
  485.     getFrontProcessResult := GetFrontProcess(frontPSN);
  486.     getCurrentProcessResult := GetCurrentProcess(currentPSN);
  487.  
  488.     if ((getFrontProcessResult = noErr) and (getCurrentProcessResult = noErr)) then
  489.         sameProcessResult := SameProcess(frontPSN, currentPSN, isSameProcess);
  490.  
  491.     if ((sameProcessResult = noErr) and (isSameProcess = false)) then
  492.         HandleSuspendEvent
  493.     else begin
  494.         firstWindowPtr := FrontWindow;
  495.         secondDocumentWindowPtr := FindFrontNonFloatingWindow;
  496.         if (secondDocumentWindowPtr <> nil) then
  497.             secondDocumentWindowPtr := GetNextWindow(secondDocumentWindowPtr);
  498.         currentWindowPtr := firstWindowPtr;
  499.  
  500.         while(currentWindowPtr <> secondDocumentWindowPtr) do
  501.             begin
  502.             if (GetWindowVisible(currentWindowPtr)) then
  503.                 ActivateWindow(currentWindowPtr);
  504.             currentWindowPtr := GetNextWindow(currentWindowPtr);
  505.             end;
  506.         end;
  507.     end;
  508.         {of procedure ActivateFloatsAndFirstDocWin}
  509.  
  510. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ DeactivateWindow }
  511.  
  512. procedure DeactivateWindow(theWindowPtr : WindowPtr);
  513.  
  514.     begin
  515.     HighlightAndActivateWindow(theWindowPtr, false);    
  516.     end;
  517.         {of procedure DeactivateWindow}
  518.  
  519. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ ActivateWindow }
  520.  
  521. procedure ActivateWindow(theWindowPtr : WindowPtr);
  522.  
  523.     begin
  524.     HighlightAndActivateWindow(theWindowPtr, true);
  525.     end;
  526.         {of procedure ActivateWindow}
  527.         
  528. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ HighlightAndActivateWindow }
  529.  
  530. procedure HighlightAndActivateWindow(theWindowPtr : WindowPtr;  activate : boolean);
  531.  
  532.     var
  533.     activateHandler : ActivateProcPtr;
  534.     docRecordHdl : DocRecordHandle;
  535.  
  536.     begin
  537.     HiliteWindow(theWindowPtr, activate);
  538.     docRecordHdl := DocRecordHandle(GetWRefCon(theWindowPtr));
  539.     activateHandler := docRecordHdl^^.activateHandler;
  540.     if (activateHandler <> nil) then
  541.         activateHandler(theWindowPtr, activate);
  542.     end;
  543.         {of procedure HighlightAndActivateWindow}
  544.         
  545. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ FindFrontNonFloatingWindow }
  546.  
  547. function  FindFrontNonFloatingWindow : WindowPtr;
  548.  
  549.     var
  550.     frontWindowPtr : WindowPtr;
  551.  
  552.     begin
  553.     frontWindowPtr := FrontWindow;
  554.  
  555.     while (frontWindowPtr <> nil) & ((GetWindowKind(frontWindowPtr) = kFloatingKind) or 
  556.             not GetWindowVisible(frontWindowPtr)) do
  557.         frontWindowPtr := GetNextWindow(frontWindowPtr);
  558.  
  559.     FindFrontNonFloatingWindow := frontWindowPtr;
  560.     end;
  561.         {of function FindFrontNonFloatingWindow}
  562.  
  563. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ FindLastFloatingWindow }
  564.  
  565. function  FindLastFloatingWindow : WindowPtr;
  566.  
  567.     var
  568.     theWindowPtr : WindowPtr;
  569.     lastFloatingWindowPtr : WindowPtr;
  570.  
  571.     begin
  572.     theWindowPtr := GetWindowList;
  573.     lastFloatingWindowPtr := nil;
  574.  
  575.     while (theWindowPtr <> nil) do
  576.         begin
  577.         if (GetWindowKind(theWindowPtr) = kFloatingKind) then
  578.             lastFloatingWindowPtr := theWindowPtr;
  579.         theWindowPtr := GetNextWindow(theWindowPtr);
  580.         end;
  581.  
  582.     FindLastFloatingWindow := lastFloatingWindowPtr;
  583.     end;
  584.         {of function FindLastFloatingWindow}
  585.  
  586. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ IsWindowModal }
  587.  
  588. function  IsWindowModal(theWindowPtr : WindowPtr) : boolean;
  589.  
  590.     var
  591.     variant : integer;
  592.  
  593.     begin
  594.     variant := GetWVariant(theWindowPtr);
  595.     
  596.     if (theWindowPtr = nil) then
  597.         IsWindowModal := false
  598.     else if ((WindowPeek(theWindowPtr)^.windowKind = dialogKind) and
  599.          ((variant = dBoxProc) or (variant = movableDBoxProc))) then
  600.         IsWindowModal := true
  601.     else
  602.         IsWindowModal := false;
  603.     end;
  604.         {of function IsWindowModal}
  605.  
  606. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetWindowList }
  607.  
  608. function  GetWindowList : WindowPtr;
  609.  
  610.     begin
  611.     GetWindowList := LMGetWindowList;
  612.     end;
  613.         {of function GetWindowList}
  614.  
  615. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SetWindowList }
  616.  
  617. procedure SetWindowList(theWindowPtr : WindowPtr);
  618.  
  619.     begin
  620.     LMSetWindowList(theWindowPtr);
  621.     end;
  622.         {of procedure SetWindowList}
  623.  
  624.  
  625. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetNextWindow }
  626.  
  627. function  GetNextWindow(theWindowPtr : WindowPtr) : WindowPtr;
  628.  
  629.     begin
  630.     GetNextWindow := WindowPtr(WindowPeek(theWindowPtr)^.nextWindow);
  631.     end;
  632.         {of function GetNextWindow}
  633.  
  634.  
  635. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SetNextWindow }
  636.  
  637. procedure SetNextWindow(theWindowPtr, nextWindowPtr : WindowPtr);
  638.  
  639.     begin
  640.     WindowPeek(theWindowPtr)^.nextWindow := WindowPeek(nextWindowPtr);
  641.     end;
  642.         {of procedure SetNextWindow}
  643.  
  644.  
  645. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetWasVisible }
  646.  
  647. function  GetWasVisible(theWindowPtr : WindowPtr) : boolean;
  648.  
  649.     var
  650.     docRecordHdl : DocRecordHandle;
  651.  
  652.     begin
  653.     docRecordHdl := DocRecordHandle(GetWRefCon(theWindowPtr));
  654.     GetWasVisible := docRecordHdl^^.wasVisible;
  655.     end;
  656.         {of function GetWasVisible}
  657.  
  658.  
  659. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SetWasVisible }
  660.  
  661. procedure SetWasVisible(theWindowPtr : WindowPtr;  wasVisible : boolean);
  662.  
  663.     var
  664.     docRecordHdl : DocRecordHandle;
  665.  
  666.     begin
  667.     docRecordHdl := DocRecordHandle(GetWRefCon(theWindowPtr));
  668.     docRecordHdl^^.wasVisible := wasVisible;
  669.     end;
  670.         {of procedure SetWasVisible}
  671.  
  672.  
  673. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetWindowKind }
  674.  
  675. function  GetWindowKind(theWindowPtr : WindowPtr) : integer;
  676.  
  677.     var
  678.     docRecordHdl : DocRecordHandle;
  679.  
  680.     begin
  681.     if (WindowPeek(theWindowPtr)^.windowKind <> dialogKind) then
  682.         begin
  683.         docRecordHdl := DocRecordHandle(GetWRefCon(theWindowPtr));
  684.         if (docRecordHdl <> nil) then
  685.             GetWindowKind := docRecordHdl^^.windowType;
  686.         end
  687.     else
  688.         GetWindowKind := 0;
  689.     end;
  690.         {of function GetWindowKind}
  691.  
  692.  
  693. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SetWindowKind }
  694.  
  695. procedure SetWindowKind(theWindowPtr : WindowPtr; windowKind : integer);
  696.  
  697.     var
  698.     docRecordHdl : DocRecordHandle;
  699.  
  700.     begin
  701.     docRecordHdl := DocRecordHandle(GetWRefCon(theWindowPtr));
  702.     docRecordHdl^^.windowType := windowKind;
  703.     end;
  704.         {of procedure SetWindowKind}
  705.  
  706. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetWindowVisible }
  707.  
  708. function  GetWindowVisible(theWindowPtr : WindowPtr) : boolean;
  709.  
  710.     begin
  711.     GetWindowVisible := WindowPeek(theWindowPtr)^.visible;
  712.     end;
  713.         {of function GetWindowVisible}
  714.  
  715.  
  716. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetStructureRegion }
  717.  
  718. function  GetStructureRegion(theWindowPtr : WindowPtr) : RgnHandle;
  719.  
  720.     begin
  721.     GetStructureRegion := WindowPeek(theWindowPtr)^.strucRgn;
  722.     end;
  723.         {of function GetStructureRegion}
  724.  
  725.  
  726. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ GetContentRegion }
  727.  
  728. function  GetContentRegion(theWindowPtr : WindowPtr) : RgnHandle;
  729.  
  730.     begin
  731.     GetContentRegion := WindowPeek(theWindowPtr)^.contRgn;
  732.     end;
  733.         {of function GetContentRegion}
  734.  
  735.  
  736. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ SetWindowHilite }
  737.  
  738. procedure SetWindowHilite(theWindowPtr : WindowPtr; windowHilite : boolean);
  739.  
  740.     begin
  741.     WindowPeek(theWindowPtr)^.hilited := windowHilite;
  742.     end;
  743.         {of procedure SetWindowHilite}
  744.  
  745. end.
  746.     {of unit UFloatRoutines.p}
  747.  
  748. { ◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊ }
  749.  
  750.