home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Games / ISp Sample / Source / ShellWindow.cp < prev    next >
Encoding:
Text File  |  2000-09-28  |  5.9 KB  |  354 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ShellWindow.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                xxx put dri here xxx
  13.  
  14.         Other Contact:        xxx put other contact here xxx
  15.  
  16.         Technology:            xxx put technology here xxx
  17.  
  18.     Writers:
  19.  
  20.         (BWS)    Brent Schorsch
  21.  
  22.     Change History (most recent first):
  23.  
  24.        <SP1>      7/1/99    BWS        first checked in
  25. */
  26.  
  27. //•    ——————————————————————————————    Includes
  28.  
  29. #include <Controls.h>
  30. #include <MacWindows.h>
  31. #include <ToolUtils.h>
  32.  
  33. #include "ShellWindow.h"
  34. #include "ToolboxUtils.h"
  35.  
  36. //•    ——————————————————————————————    Private Definitions
  37. //•    ——————————————————————————————    Private Types
  38. //•    ——————————————————————————————    Private Variables
  39. //•    ——————————————————————————————    Private Functions
  40. //•    ——————————————————————————————    Public Variables
  41.  
  42. ShellWindow::ShellWindow()
  43. {
  44. }
  45.  
  46. ShellWindow::~ShellWindow()
  47. {
  48. }
  49.  
  50. //•    ————————————————————    ShellWindow::Show
  51.  
  52. void
  53. ShellWindow::Show(void)
  54. {
  55.     ::ShowWindow(window);
  56. }
  57.  
  58. //•    ————————————————————    ShellWindow::Hide
  59.  
  60. void
  61. ShellWindow::Hide(void)
  62. {
  63.     ::HideWindow(window);
  64. }
  65.  
  66. //•    ————————————————————    ShellWindow::MakeCurrentPort
  67.  
  68. void
  69. ShellWindow::MakeCurrentPort(void)
  70. {
  71.     ::SetPort(window);
  72. }
  73.  
  74. //•    ————————————————————    ShellWindow::SetTitle
  75.  
  76. void
  77. ShellWindow::SetTitle(const Str255 inTitle)
  78. {
  79.     ::SetWTitle(window, inTitle);
  80. }
  81.  
  82. //•    ————————————————————    ShellWindow::SetWidth
  83.  
  84. void
  85. ShellWindow::SetWidth(const UInt32 inWidth)
  86. {
  87. Rect    r;
  88.  
  89.     r = window->portRect;
  90.     r.right = r.left + inWidth;
  91.     
  92.     ::SizeWindow(window, r.right - r.left, r.bottom - r.top, true);
  93. }
  94.  
  95. //•    ————————————————————    ShellWindow::SetHeight
  96.  
  97. void
  98. ShellWindow::SetHeight(const UInt32 inHeight)
  99. {
  100. Rect    r;
  101.  
  102.     r = window->portRect;
  103.     r.bottom = r.top + inHeight;
  104.     
  105.     ::SizeWindow(window, r.right - r.left, r.bottom - r.top, true);
  106. }
  107.  
  108. //•    ————————————————————    ShellWindow::Width
  109.  
  110. short
  111. ShellWindow::Width(void)
  112. {
  113.     return (window->portRect.right - window->portRect.left);
  114. }
  115.  
  116. //•    ————————————————————    ShellWindow::Height
  117.  
  118. short
  119. ShellWindow::Height(void)
  120. {
  121.     return (window->portRect.bottom - window->portRect.top);
  122. }
  123.  
  124. //•    ————————————————————    ShellWindow::MoveTo
  125.  
  126. void
  127. ShellWindow::MoveTo(const SInt32 inH, const SInt32 inY)
  128. {
  129. Boolean    isFrontWindow;
  130.  
  131.     if (window == ::FrontWindow())
  132.         isFrontWindow = true;
  133.     else
  134.         isFrontWindow = false;
  135.         
  136.     ::MoveWindow(window, inH, inY, isFrontWindow);
  137. }
  138.     
  139. //•    ————————————————————    ShellWindow::MostOnWhichMonitor
  140.  
  141. GDHandle
  142. ShellWindow::MostOnWhichMonitor(void)
  143. {
  144. GDHandle    mostMonitor = nil;
  145. GDHandle    monitor;
  146. UInt32        mostArea = 0U, area;
  147. Rect        r, windowRect;
  148. GrafPtr        oldPort;
  149. GDHandle    mainMonitor;
  150.         
  151.  
  152.     ::GetPort(&oldPort);
  153.     MakeCurrentPort();
  154.     
  155.     windowRect = window->portRect;
  156.     LocalToGlobalRect(&windowRect);
  157.     
  158.     mainMonitor = ::GetMainDevice();
  159.     monitor = ::GetDeviceList();
  160.  
  161.     while (nil != monitor)
  162.     {
  163.         ::SectRect(&windowRect, & (**monitor).gdRect, &r);
  164.         ::OffsetRect(&r, -r.left, -r.top);
  165.         area = r.right * r.bottom;
  166.         
  167.         if (area > mostArea)        //•    Favor the device that has the most area
  168.         {
  169.             mostArea = area;
  170.             mostMonitor = monitor;
  171.         }
  172.         else if (area == mostArea)    //•    But if it's equal to the main monitor, favor main
  173.         {
  174.             if ((monitor == mainMonitor) || (mostMonitor == mainMonitor))
  175.                 mostMonitor = mainMonitor;
  176.         }
  177.         
  178.         monitor = ::GetNextDevice(monitor);
  179.     }
  180.     
  181.     ::SetPort(oldPort);
  182.  
  183.     return (mostMonitor);
  184. }
  185.  
  186. #pragma mark -
  187.  
  188. //•    ————————————————————    ShellWindow::Activate
  189.  
  190. void
  191. ShellWindow::Activate(const Boolean inActivate)
  192. {
  193.     ::HiliteWindow(window, inActivate);
  194.     ::DrawGrowIcon(window);
  195. }
  196.  
  197. //•    ————————————————————    ShellWindow::Update
  198.  
  199. void
  200. ShellWindow::Update(void)
  201. {
  202. GrafPtr        oldPort;
  203. WindowPtr    theWindow = window;
  204.  
  205.     ::GetPort(&oldPort);
  206.     MakeCurrentPort();
  207.  
  208.     ::BeginUpdate(theWindow);
  209.  
  210.     ::ClipRect(&theWindow->portRect);
  211.     ::EraseRect(&theWindow->portRect);
  212.     ::DrawControls(theWindow);
  213.     ::DrawGrowIcon(theWindow);
  214.  
  215.     ::EndUpdate(theWindow);
  216.     
  217.     ::SetPort(oldPort);
  218. }
  219.  
  220. //•    ————————————————————    ShellWindow::Select
  221.  
  222. void
  223. ShellWindow::Select(void)
  224. {
  225.     ::SelectWindow(window);
  226.     MakeCurrentPort();
  227. }
  228.  
  229. //•    ————————————————————    ShellWindow::Click
  230.  
  231. OSErr
  232. ShellWindow::Click(const Point inWhere, const short inModifiers)
  233. {
  234. #pragma unused (inWhere, inModifiers)
  235.  
  236.     if (FrontWindow() != window)
  237.         ::SelectWindow(window);
  238.  
  239.     return (noErr);
  240. }
  241.  
  242. //•    ————————————————————    ShellWindow::Key
  243.  
  244. OSErr
  245. ShellWindow::Key(const UInt8 inChar, const UInt8 inKey, const short inModifiers)
  246. {
  247. #pragma unused (inChar, inKey, inModifiers)
  248.  
  249.     return (noErr);
  250. }
  251.  
  252. //•    ————————————————————    ShellWindow::Grow
  253.  
  254. OSErr
  255. ShellWindow::Grow(const Point inWhere)
  256. {
  257. Rect        sizeRect;
  258. long        result;
  259. WindowPtr    theWindow = window;
  260.  
  261.     sizeRect.top = 80;
  262.     sizeRect.left = 80;
  263.     sizeRect.bottom = 440;
  264.     sizeRect.right = 640;
  265.     
  266.     result = ::GrowWindow(theWindow, inWhere, &sizeRect);
  267.  
  268.     if (0 != result)
  269.     {
  270.     GrafPtr    oldPort;
  271.     
  272.         ::SizeWindow(theWindow, LoWord(result), HiWord(result), false);
  273.         
  274.         ::GetPort(&oldPort);
  275.         MakeCurrentPort();
  276.         
  277.         ::InvalRect(&theWindow->portRect);
  278.         
  279.         ::SetPort(oldPort);
  280.     }
  281.  
  282.     return (noErr);
  283. }
  284.  
  285. //•    ————————————————————    ShellWindow::Zoom
  286.  
  287. OSErr
  288. ShellWindow::Zoom(const short inZoomDir)
  289. {
  290. #pragma unused (inZoomDir)
  291.  
  292.     return (noErr);
  293. }
  294.  
  295. //•    ————————————————————    ShellWindow::Close
  296.  
  297. OSErr
  298. ShellWindow::Close(void)
  299. {
  300.     return (noErr);
  301. }
  302.  
  303. //•    ————————————————————    ShellWindow::Idle
  304.  
  305. void
  306. ShellWindow::Idle(void)
  307. {
  308.     ::IdleControls(window);
  309. }
  310.  
  311. //•    ————————————————————    ShellWindow::Menu
  312.  
  313. Boolean
  314. ShellWindow::Menu(const UInt32 inMenuCommand, const short inModifiers)
  315. {
  316. #pragma unused (inMenuCommand, inModifiers)
  317.  
  318.     return (false);
  319. }
  320.  
  321. //•    ————————————————————    ShellWindow::Help
  322.  
  323. void
  324. ShellWindow::Help(const Point inWhere)
  325. {
  326. #pragma unused (inWhere)
  327. }
  328.  
  329. //•    ————————————————————    ShellWindow::Drag
  330.  
  331. Boolean
  332. ShellWindow::Drag(const Point inWhere, const short inModifiers)
  333. {
  334. #pragma unused (inModifiers)
  335.  
  336.     ::DragWindow(window, inWhere, &(**GetGrayRgn()).rgnBBox);
  337.  
  338.     return (false);
  339. }
  340.  
  341. //•    ————————————————————    ShellWindow::Suspend
  342.  
  343. void
  344. ShellWindow::Suspend(void)
  345. {
  346. }
  347.  
  348. //•    ————————————————————    ShellWindow::Resume
  349.  
  350. void
  351. ShellWindow::Resume(void)
  352. {
  353. }
  354.