home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C ++ / Code Resources / Windows 95 MDEF 2.0.1 / Sourcery / GetDominantDevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  2.4 KB  |  79 lines  |  [TEXT/CWIE]

  1. #include <Types.h>
  2. #include <Memory.h>
  3. #include <Quickdraw.h>
  4. #include <Fonts.h>
  5. #include <ToolUtils.h>
  6. #include <Icons.h>
  7. #include <Controls.h>
  8. #include <Gestalt.h>
  9. #include <Resources.h>
  10.  
  11. #include "GetDominantDevice.h"
  12.  
  13. static Boolean IsActiveScreenDevice(GDHandle theDevice);
  14. static long GetRectArea(Rect r);
  15.  
  16. // ---------------------------------------------------------------------------
  17.  
  18. /*
  19.     The following routines were written by Norman Basham.
  20.     They were taken from "Monitors.cpp"
  21.     
  22.     Thanks a mil, Norman!
  23. */
  24. #pragma mark === Norman Basham ===
  25.  
  26. //    ------------------------------------------------------------------------
  27. //    Given rect r, which device does it overlap most.  An example of its use
  28. //    would be passing in (**wp->visRgn).rgnBBox to find out which device a
  29. //    window is overlapping the most, as in the case of zooming a window.
  30. //    ------------------------------------------------------------------------
  31. GDHandle GetDominantDevice (Rect *r)
  32. {
  33.     GDHandle            aGDevice;
  34.     GDHandle            bigGDevice;
  35.     Rect                screenRect;
  36.     Rect                sectRect;
  37.     long                area;
  38.     long                biggestArea = 0L;
  39.  
  40.     aGDevice = GetDeviceList ();                        //    start at begining of device list
  41.     while (aGDevice != nil)                                //    loop if device exists
  42.         {
  43.         if (IsActiveScreenDevice (aGDevice))            //    if device is a monitor and active
  44.             {
  45.             screenRect = (**aGDevice).gdRect;            //    get the devices global rect
  46.             SectRect (&screenRect, r, §Rect);        //    get overlapping rect of device and r
  47.             
  48.             area = GetRectArea (sectRect);                //    changed 3/21/94
  49.             if (area > biggestArea)                        //    if overlapping rect has the biggest area
  50.                 {
  51.                 bigGDevice = aGDevice;                    //    set big device to current device
  52.                 biggestArea = area;                        //    set big area to current area
  53.                 }
  54.     
  55.             aGDevice = GetNextDevice (aGDevice);        //    check next device in list
  56.             }
  57.         }
  58.         
  59.     return bigGDevice;                                    //    return device containing biggest portion of r
  60. }
  61.  
  62. //    ------------------------------------------------------------------------
  63. //    Given a device, return wether it is a monitor and wether it's active
  64. //    ------------------------------------------------------------------------
  65. Boolean IsActiveScreenDevice(GDHandle theDevice)
  66. {
  67.     return (
  68.             (TestDeviceAttribute (theDevice, screenDevice)) &&
  69.             (TestDeviceAttribute (theDevice, screenActive))
  70.             );
  71. }
  72.  
  73. long GetRectArea(Rect r)
  74. {
  75.     Rect        temp = r;
  76.  
  77.     OffsetRect (&temp, -temp.left, -temp.top);        //    rids us of neg values
  78.     return (long) temp.right * temp.bottom;            //    return width x heigth
  79. }