home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * MacZoop - "the framework for the rest of us"
- *
- *
- *
- * ZWindowManager.h -- desktop class; handles floaters
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
- #pragma once
-
- #ifndef __ZWINDOWMANAGER__
- #define __ZWINDOWMANAGER__
-
- #include "ZComrade.h"
-
- #ifndef __ZOBJECTARRAY__
- #include "ZObjectArray.h"
- #endif
-
- class ZWindow;
- class ZResourceFile;
-
- // container class definition for window list
-
- typedef ZObjectArray<ZWindow> ZWindowList;
-
- // structure of 'Wpos' resource:
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=mac68k
- #endif
-
- typedef struct
- {
- short globalH;
- short globalV;
- short width;
- short height;
- long userRef;
- long reserved;
- }
- WPosResource, *WPosPtr, **WPosHdl;
-
- #define kWindowPosResType 'Wpos'
-
- // note that you supply the ID for the resource, unless its 0, in which case the window template
- // (or dialog template) ID is used.
-
-
- #if PRAGMA_ALIGN_SUPPORTED
- #pragma options align=reset
- #endif
-
-
- // window manager class:
-
- class ZWindowManager : public ZComrade
- {
- friend class ZMenuBar;
-
- protected:
-
- ZWindowList* nonFloaters; // list of non-floating windows
- ZWindowList* floaters; // list of floating windows
- ZWindowList* wmWindows; // list of windows in menu
- MenuHandle wmMenu; // handle of "Windows" menu if any
- short wmItemOffset; // item count of initial number of items in menu
- Point globalPlaceLoc; // placement position
- Rect fStoredZoom; // stored zoom for DeactivateForDialog
- Rect fStoredZoomSource; // ditto but source rect
- Boolean wmActive; // tracks active state of entire window manager
-
- public:
-
- ZWindowManager();
- virtual ~ZWindowManager();
-
- virtual void AddWindow( ZWindow* aWindow );
- virtual void RemoveWindow( ZWindow* aWindow );
-
- virtual void HideWindow( ZWindow* aWindow );
- virtual void ShowWindow( ZWindow* aWindow );
-
- virtual void SelectWindow( ZWindow* aWindow );
- virtual void DragWindowOutline( ZWindow* aWindow, Point startPt, const short modifiers );
-
- virtual void Suspend();
- virtual void Resume();
- virtual void Deactivate();
- virtual void DeactivateForDialog( short dlogID, Boolean isAlert = FALSE );
- virtual void Activate();
-
- virtual ZWindow* GetTopWindow();
- virtual ZWindow* GetTopFloater();
- virtual ZWindow* GetBottomFloater();
-
- virtual Boolean CheckDialogEvent( EventRecord* theEvent );
- virtual ZWindow* LocateWindow( const Point globalMouse );
- virtual ZWindow* GetNthWindow( const long n );
- virtual ZWindow* GetNthFloater( const long n );
- virtual Boolean IsDialog( ZWindow* aWindow );
-
- virtual Boolean GetUniqueUntitledName( Str255 wName );
- virtual void FloatIdle();
-
- virtual short CountWindows();
- virtual short CountFloaters();
-
- virtual void InitiallyPlace( ZWindow* aWindow );
- virtual void ZoomWindowClosed( ZWindow* aWindow );
-
- // saving/restoring window positions- use ZWindow methods for easier use (these are lowest level)
-
- virtual short SaveWindowPosition( ZWindow* aWindow, ZResourceFile* aFile = NULL, short id = 0 );
- virtual void RestoreWindowPosition( ZWindow* aWindow, ZResourceFile* aFile = NULL, short id = 0 );
-
- private:
- void BringBehind( ZWindow* aWindow, ZWindow* behindWindow );
- void PostActivation( ZWindow* aWindow, Boolean state );
- void CalcWindowRgns( ZWindow* aWindow, RgnHandle aRgn );
- void ShowHideFloater( ZWindow* aFloater, Boolean hide );
- Boolean WindowOnDesktop( Rect* wFrame );
-
- protected: // these methods accessible to gMenuBar, but not user's code.
-
- virtual void SetWindowsMenu( MenuHandle aMenu );
- virtual void SelectWindowFromMenu( const short itemID );
- virtual void BuildWindowsMenu();
-
- virtual Boolean CommandClickInFrontDragBar( ZWindow* target, const Point startPt );
- };
-
- // This object is created by the application and installed as the global gWindowManager.
- // Windows ask this object to manage their selection, etc instead of calling the Mac's
- // window manager directly. This allows us to have floaters in our app. Windows have a
- // "isFloater" flag, which is inited automatically by detecting which WDEF is used, though this
- // can be forced as needed. The event handler also calls this to manage certain window chores
- // like dragging, to make sure the Mac Window Manager is never given the chance to screw things
- // up for us.
-
- extern ZWindowManager* gWindowManager;
-
- // WARNING: You must not call high-level mac window-manager calls from your code within MacZoop.
- // Calls such as SelectWindow() and DragWindow() in particular will cause problems. FrontWindow()
- // must be used with caution, since it does not distinguish between floating and non-floating
- // windows. Methods are provided here and in ZApplication that provide the equivalent floater-
- // savvy functionality.
-
- // New in version 1.8.3 (July 1998). ZWindowManger is now a subclass of ZComrade. Why? This allows
- // an object to get notified by activities involving other windows from a central source. This makes
- // implementing things like inspector windows much easier- become a listener of gWindowManager to
- // discover when other windows are activated, shown, hidden, created and destroyed. Doing this by
- // other means is possible, but generally more involved.
-
- // messages: In all cases, parameter passed is the window in question, except mac dialog messages
- // which pass no parameter (NULL).
-
- enum
- {
- kWMMsgWindowAdded = 'wm++',
- kWMMsgWindowRemoved = 'wm--',
- kWMMsgWindowActivated = 'wmak',
- kWMMsgWindowDeactivated = 'wmdk',
- kWMMsgWindowShown = 'wmv+',
- kWMMsgWindowHidden = 'wmv-',
- kWMMsgWindowMoved = 'wmmv',
- kWMMsgMacDialogUp = 'wmd+',
- kWMMsgMacDialogDown = 'wmd-',
- kWMMsgFloaterActivated = 'wmfa',
- kWMMsgFloaterDeactivated = 'wmfd'
- };
-
-
- #endif