home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Snippets / TruchetTiles / WindowStuff.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1994-08-09  |  3.6 KB  |  127 lines  |  [TEXT/PJMM]

  1. unit WindowStuff;
  2. interface
  3.     uses
  4.         PrintTraps, Quickdraw, Picker, Toolutils, Palettes, DlogStuff, globs;
  5.  
  6.     procedure FakeGrowIcon (WPtr: WindowPtr);
  7.     procedure PutUpWind (title: str255);
  8.     procedure CloseUpWind;
  9.     procedure DoDrag (theWindow: WindowPtr);
  10.     procedure DoGrow (theWindow: WindowPtr);
  11.  
  12. implementation
  13.  
  14. {===========================================================================}
  15.     procedure FakeGrowIcon; {(WPtr : WindowPtr)}
  16.         var
  17.             bot, rght: integer;
  18.             R: rect;
  19.             pState: PenState;
  20.     begin
  21.         bot := WPtr^.portRect.bottom;
  22.         rght := WPtr^.PortRect.right;
  23.         SetRect(gdh^^.GrowIconRect, rght - 15, bot - 15, rght + 1, bot + 1);
  24.         if gdh^^.showGroBox then
  25.             begin
  26.                 GetPenState(pState);
  27.                 EraseRect(gdh^^.GrowIconRect);
  28.                 FrameRect(gdh^^.GrowIconRect);
  29.                 SetRect(R, rght - 10, bot - 10, rght - 1, bot - 1);
  30.                 FrameRect(R);
  31.                 SetRect(R, rght - 12, bot - 12, rght - 5, bot - 5);
  32.                 EraseRect(R);
  33.                 FrameRect(R);
  34.                 SetPenState(pState);
  35.             end;{if if ghd^^.showGroBox}
  36.     end;{FakeGrowIcon}
  37.  
  38. {===========================================================================}
  39.     procedure PutUpWind;{title:str255}
  40.         const
  41.             xtra = 18;        {for structure region of window}
  42.         var
  43.             offSet: point;
  44.     begin
  45. {•  if gdh^^.hasColorQD then•}
  46. {•   begin•}
  47. {•    MainWindPtr := GetNewCWindow(1000, @mainWindowStorage, pointer(-1));•}
  48. {•    SetPalette(MainWindPtr, mainWindPalette, TRUE);•}
  49. {•    ActivatePalette(MainWindPtr);•}
  50. {•   end•}
  51. {•  else•}
  52.  
  53.         MainWindPtr := GetNewWindow(1000, @mainWindowStorage, WindowPtr(-1));
  54.  
  55.  
  56.         if MainWindPtr = nil then
  57.             begin
  58.                 DoMessage('**WIND resource not found. Oops!', 'Can''t run. Gotta quit…', '', '');
  59.                 ExittoShell;
  60.             end;
  61.  
  62.         SetPort(MainWindPtr);
  63.  
  64.         offSet.h := (ScreenBits.bounds.right - MainWindPtr^.portRect.right) div 2;
  65.         offSet.v := gdh^^.MenuHeight + (ScreenBits.bounds.bottom - MainWindPtr^.portRect.bottom + xtra) div 3;
  66.         MoveWindow(MainWindPtr, offSet.h, offSet.v, TRUE);
  67.  
  68.         SetWTitle(MainWindPtr, title);
  69.         ShowWindow(MainWindPtr);
  70.         FakeGrowIcon(MainWindPtr);
  71.     end;{PutUpWind}
  72.  
  73.  
  74. {===========================================================================}
  75.     procedure CloseUpWind;
  76.     begin
  77.         CloseWindow(MainWindPtr);        {handle last-minute 'WannaSave' dlogs here…}
  78.     end;
  79.  
  80. {===========================================================================}
  81.     procedure DoDrag;{(theWindow : WindowPtr);}
  82.         var
  83.             screen: rect;
  84.     begin
  85. {this allows the user to drag a window around in the rectangle defined by}
  86. {our dragRect.}
  87.         screen := gdh^^.dragRect;
  88.         DragWindow(theWindow, MainEvent.where, screen);
  89.     end;
  90.  
  91. {===========================================================================}
  92.     procedure DoGrow;{(theWindow : WindowPtr);}
  93.         var
  94.             Wptr: Windowptr;
  95.             sizeRect: rect;
  96.             newSize: longint;
  97.             newWidth, newHeight: integer;
  98.             r: rect;
  99.             bot, rght: integer;
  100.  
  101.     begin
  102.         if theWindow <> FrontWindow then
  103.             SelectWindow(theWindow)
  104.         else
  105.             begin
  106. {the minimum size that this particular window can be resized is}
  107. {100 pixels wide,  100 pixels tall.  The maximum size is}
  108. {screenBits.right,screenBits.bottom - 37 tall.}
  109.                 SetRect(sizeRect, 100, 100, screenBits.bounds.right, screenBits.bounds.bottom - 37);
  110.                 newSize := GrowWindow(theWindow, MainEvent.where, sizeRect);
  111.                 if newSize <> 0 then
  112.                     begin
  113.                         bot := WPtr^.portRect.bottom;
  114.                         rght := WPtr^.PortRect.right;
  115.                         EraseRect(theWindow^.portRect);
  116.                         newWidth := LoWord(newSize);
  117.                         newHeight := HiWord(newSize);
  118.                         SizeWindow(theWindow, newWidth, newHeight, TRUE);
  119.                         ClipRect(theWindow^.portRect);
  120.                         InvalRect(theWindow^.portRect);
  121.                         FakeGrowIcon(theWindow);
  122.                     end;
  123.             end;
  124.  
  125.     end;{DoGrow}
  126.  
  127. end.            {WindowStuff Unit}