MoreWindows/MoreWindows.cp

/*
    File:       MoreWindows.cp
 
    Contains:   
 
    Written by: Pete Gontier
 
    Copyright:  Copyright (c) 1998 Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
 
         <5>     20/3/00    Quinn   Added GetWindowList for non-Carbon clients.
         <4>      2/9/99    PCG     more TARGET_CARBON
         <3>     1/25/99    PCG     TARGET_CARBON
         <2>    11/11/98    PCG     fix header
         <1>    11/10/98    PCG     first big re-org at behest of Quinn
 
    Old Change History (most recent first):
 
         <2>     7/24/98    PCG     eliminate dependency on 'qd'
         <1>     6/16/98    PCG     initial checkin
*/
 
#include "MoreQuickDraw.h"
#include "MoreWindows.h"
#include "MoreAppearance.h"
 
#include <Controls.h>
#include <Menus.h>
#include <LowMem.h>
 
pascal OSStatus MoveWindowToAlertPosition (WindowRef window)
{
    OSStatus err = noErr;
 
    if (!MoreAssert (HaveAppearance ( ) || IsWindowVisible (window)))
        err = paramErr;
    else
    {
        Rect screenRect = (**GetMainDevice ( )).gdRect;
        screenRect.top += GetMBarHeight ( );
        InsetRect (&screenRect,4,4);
 
        Rect contRect;
 
#if !TARGET_CARBON
 
        if (!HaveAppearance ( ) || IsWindowVisible (window))
            contRect = (**(((WindowPeek)window)->contRgn)).rgnBBox;
        else
 
#endif
 
        {
            RgnHandle contRgn = NewRgn ( );
 
            if (!contRgn)
                err = QDError ( );
            else
            {
                err = GetWindowRegion (window,kWindowContentRgn,contRgn);
                GetRegionBounds (contRgn,&contRect);
                DisposeRgn (contRgn);
                (void) MoreAssert (noErr == QDError ( ));
            }
        }
 
        if (!err)
        {
            Point windLoc;
 
            windLoc.v   = screenRect.top + ((screenRect.bottom - screenRect.top) / 3);
            windLoc.h   = screenRect.left + ((screenRect.right - screenRect.top) / 2);
 
            windLoc.v   -= (contRect.bottom - contRect.top) / 2;
            windLoc.h   -= (contRect.right - contRect.left) / 2;
 
            MoveWindow (window, windLoc.h, windLoc.v, true);
        }
    }
 
    return err;
}
 
pascal OSErr MoreNewWindow (    const Rect *            boundsRect,
                                ConstStr255Param        title,
                                short                   theProc,
                                Boolean                 goAwayFlag,
                                long                    refCon,
                                WindowRef               *window         )
{
    OSErr err = noErr;
 
    if (!title)
        title = "\p";
 
    if (HaveColorQuickDraw ( ))
        *window = NewCWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
    else
        *window = NewWindow (nil,boundsRect,title,false,theProc,(WindowRef)kFirstWindowOfClass,goAwayFlag,refCon);
 
    if (!*window)
        err = nilHandleErr;
    else if (HaveAppearance ( ))
    {
        ControlRef dontCare;
        err = CreateRootControl (*window,&dontCare);
        if (err) DisposeWindow (*window);
    }
 
    return err;
}
 
#if !TARGET_API_MAC_CARBON
 
    extern pascal WindowRef GetWindowList(void)
    {
        return LMGetWindowList();
    }
 
#endif