• MacTech Network:
  • Tech Support
  • |
  • MacForge.net
  • |
  • Apple News
  • |
  • Register Domains
  • |
  • SSL Certificates
  • |
  • iPod Deals
  • |
  • Mac Deals
  • |
  • Mac Book Shelf

MAC TECH

  • Home
  • Magazine
    • About MacTech in Print
    • Issue Table of Contents
    • Subscribe
    • Risk Free Sample
    • Back Issues
    • MacTech DVD
  • Archives
    • MacTech Print Archives
    • MacMod
    • MacTutor
    • FrameWorks
    • develop
  • Forums
  • News
    • MacTech News
    • MacTech Blog
    • MacTech Reviews and KoolTools
    • Whitepapers, Screencasts, Videos and Books
    • News Scanner
    • Rumors Scanner
    • Documentation Scanner
    • Submit News or PR
    • MacTech News List
  • Store
  • Apple Expo
    • by Category
    • by Company
    • by Product
  • Job Board
  • Editorial
    • Submit News or PR
    • Writer's Kit
    • Editorial Staff
    • Editorial Calendar
  • Advertising
    • Benefits of MacTech
    • Mechanicals and Submission
    • Dates and Deadlines
    • Submit Apple Expo Entry
  • User
    • Register for Ongoing Raffles
    • Register new user
    • Edit User Settings
    • Logout
  • Contact
    • Customer Service
    • Webmaster Feedback
    • Submit News or PR
    • Suggest an article
  • Connect Tools
    • MacTech Live Podcast
    • RSS Feeds
    • Twitter

ADVERTISEMENT

Volume Number: 14 (1998)
Issue Number: 9
Column Tag: Tips & Tidbits

Sep 1998 Tips & Tidbits

by Steve Sisak

Smarter ZoomWindows

Here's a painless substitute for ZoomWindow. I originally wrote the SmartZoomWindow wrapper to add multiple monitor support to ZoomWindow. Recently I tweaked the code to compensate for Mac OS 8 "fat borders" (actually it should work correctly with any WDEF geometry.)

I inset the zoom out by 3 pixels. I do this because some displays still have rounded corners that will crop the window's corners. Additionally I like to leave a small gap around the edge of a window so I can click into the Finder. If you desired to adjoin the window with the Menubar and display edges set kInsetZoomOut to zero.

Remember to compensate for "fat borders" in your window position and window staggering routines.

Public Interface
   enum {
      kInsetZoomOut = 3
   };

   void SmartZoomWindow(
         WindowPtr targetWindow,
         short partCode,
         Boolean bringFront);

Implementation
static void 
_LocalToGlobalRect(
   Rect *targetRect)
{
   LocalToGlobal((Point*)(&targetRect->top));
   LocalToGlobal((Point*)(&targetRect->bottom));
}

void SmartZoomWindow(
   WindowPtr targetWindow,
   short partCode,
   Boolean front)
{
   GrafPtr savePort;
   GDHandle dstGDevice;
   GDHandle testGDevice;
   Rect srcRect;
   Rect dstRect;
   Rect testRect;
   long dstArea;
   long testArea;
   short titleHeight;
   short borderWidth;

   if(targetWindow)
   {
      GetPort(&savePort);
      SetPort(targetWindow);

      if(partCode == inZoomOut)
      {
         srcRect = targetWindow->portRect;
         _LocalToGlobalRect(&srcRect);
         titleHeight = srcRect.top - 1 -
            (*((WindowPeek)targetWindow)->strucRgn)->rgnBBox.top;
         borderWidth = srcRect.left - 1 -
            (*((WindowPeek)targetWindow)->strucRgn)->rgnBBox.left;
         srcRect.top -= titleHeight;
         dstArea = 0;
         testGDevice = GetDeviceList();

         while(testGDevice)
         {
            if(TestDeviceAttribute(testGDevice, screenDevice))
            {
               if(TestDeviceAttribute(testGDevice, screenActive))
               {
                  SectRect(&srcRect, & (*testGDevice)->gdRect,
                                               &testRect);
                  testArea = (long)(testRect.right - testRect.left) *
                              (long)(testRect.bottom - testRect.top);
                  if(testArea > dstArea)
                  {
                     dstGDevice = testGDevice;
                     dstArea = testArea;
                  }
               }
            }

            testGDevice = GetNextDevice(testGDevice);
         }

         if(dstGDevice == GetMainDevice())
         {
            titleHeight += GetMBarHeight();
         }

         dstRect = (*dstGDevice)->gdRect;
         dstRect.top += titleHeight + kInsetZoomOut;
         dstRect.left += borderWidth + kInsetZoomOut;
         dstRect.right -= borderWidth + kInsetZoomOut;
         dstRect.bottom -= borderWidth + kInsetZoomOut;
         (*(WStateDataHandle)((WindowPeek)targetWindow)-
                            >dataHandle)->stdState = dstRect;
      }

      ZoomWindow(targetWindow, partCode, front);

      SetPort(savePort);
   }
}

Craig Marciniak
craig@marciniac.com

 
MacTech Only Search:
Community Search:

 
 
 

 
 
 
 
 
  • SPREAD THE WORD:
  • Slashdot
  • Digg
  • Del.icio.us
  • Reddit
  • Newsvine
  • Generate a short URL for this page:



MacTech Magazine. www.mactech.com
Toll Free 877-MACTECH, Outside US/Canada: 805-494-9797
MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders.
All contents are Copyright 1984-2010 by Xplain Corporation. All rights reserved. Theme designed by Icreon.
 
Nov. 20: Take Control of Syncing Data in Sow Leopard' released
Nov. 19: Cocktail 4.5 (Leopard Edition) released
Nov. 19: macProVideo offers new Cubase tutorials
Nov. 18: S Stardom anounces Safe Capsule, a companion piece for Apple's
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live
Nov. 17: Ableton releases Max for Live