home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / C++ Exceptions / µShell / UI Classes / Windows / Window.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-09  |  6.0 KB  |  185 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Window.h
  3.  
  4.     Contains:    Definition of TWindow, a base class which provides a
  5.                 framework for building way-cool windows which even John
  6.                 Sullivan would be happy with. Floating windows and “smart
  7.                 zooming” algorithms are based on code samples provided by
  8.                 Dean Yu.
  9.                 
  10.     Written by: Dave Falkenburg, Dean Yu
  11.  
  12.     Copyright:    © 1993-1995 by Dave Falkenburg, all rights reserved.
  13.  
  14.     Change History (most recent first):
  15.      
  16.          <8>     1/24/95    DRF        Make DoMenuSelection return a Boolean, just like DoMenuCommand.
  17.          <7>     1/20/95    DRF        Add a field to track whether a TWindow needs to be disposed via
  18.                                     DisposeDialog. Thanks to Gary W. Powell @ Adobe for reporting
  19.                                     the bug.
  20.          <6>      1/3/95    DRF        Add Nitin’s changes for Drag handling: a ClickAndDrag method.
  21.          <5>      1/3/95    DRF        Protected TWindow::Window because it is not legal to create a
  22.                                     TWindow without subclassing. Also revised DoMenuSelection to use
  23.                                     a typedef-ed parameter.
  24.          <4>    11/12/94    DRF        Added AdjustMenusBeforeMenuSelection.
  25.          <3>     11/8/94    DRF        Add some better menu handling methods.
  26.          <2>      9/4/94    DRF        Added DrawJustTheGrowIcon.
  27.  
  28.  */
  29.  
  30. #ifndef        _WINDOW_
  31. #define        _WINDOW_
  32. #pragma once
  33.  
  34. #include <Types.h>
  35. #include <Windows.h>
  36. #include <Events.h>
  37. #include <Drag.h>
  38.  
  39. #include "EventDispatcher.h"
  40. #include "AECoreSuite.h"
  41. #include "WindowManager.h"
  42.  
  43.  
  44. typedef    short    WindowTemplateID;
  45.  
  46.  
  47. //--------------------------------------------------------------------------------
  48. class TWindow :
  49.     public TWindowEventDispatcher,
  50.     public virtual MAEWindow
  51. {
  52. public:
  53.     static WindowRef    GetNewWindow(short windowID, WindowRef behind, WindowLayer layer = kNormalWindowLayer);
  54.     static WindowRef    NewWindow(const Rect &boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowRef behind, Boolean goAwayFlag, long refCon, WindowLayer layer = kNormalWindowLayer);
  55.  
  56.     static void            SuspendApplication(void);
  57.     static void            ResumeApplication(void);
  58.     static void            BeginModalDialog(void);
  59.     static void            EndModalDialog(void);
  60.  
  61. protected:
  62.     WindowRef            fWindow;
  63.     
  64. public:
  65.     TWindow(WindowRef aWindowRef);
  66.     void IWindow();
  67.     virtual void Dispose();
  68.     virtual    ~TWindow() = 0;
  69.  
  70.     //    Event routing methods
  71.  
  72.     virtual    Boolean        EventFilter(EventRecord * theEvent);    
  73.  
  74.     //    Methods you shouldn’t need to override, but might need to
  75.  
  76.     virtual    void        Select(void);
  77.     virtual    void        ShowHide(Boolean showFlag);
  78.  
  79.     //    Methods which probably should be overridden
  80.  
  81.     virtual    void        AdjustCursor(Point where);
  82.     virtual void        Activate(void);
  83.     virtual void        Deactivate(void);
  84.  
  85.     virtual void        Draw(void);
  86.     virtual void        DrawGrowIcon(void);
  87.     virtual void        Click(EventRecord * anEvent);
  88.     virtual    void        KeyDown(EventRecord * anEvent);
  89.  
  90.     virtual Rect        GetGrowSizeRect(void);
  91.     virtual void        AdjustForNewWindowSize(Rect * oldRect,Rect * newRect);
  92.  
  93.     //    Window property accessor methods…
  94.  
  95.     virtual Rect        GetBounds() const;
  96.     virtual Boolean        HasCloseBox() const;
  97.     virtual Boolean        HasTitleBar() const;
  98.     virtual long        GetIndex() const;
  99.     virtual Boolean     IsFloating() const;
  100.     virtual Boolean     IsModal() const;
  101.     virtual Boolean     IsResizable() const;
  102.     virtual Boolean     IsZoomable() const;
  103.     virtual Boolean     IsZoomed() const;
  104.     virtual Boolean     IsVisible() const;
  105.  
  106.     virtual Rect        SetBounds(Rect r);
  107.     virtual long        SetIndex(long index);
  108.     virtual Boolean     SetZoomed(Boolean zoomed);
  109.     virtual Boolean     SetVisible(Boolean show);
  110.     
  111.     virtual    Boolean        CanClose(void);        
  112.     virtual Boolean        Close(DescType saveOptions = kAEAsk);
  113.     virtual    Boolean        DeleteAfterClose(void);
  114.     
  115.     //    Methods for handling menus & menu commands
  116.     
  117.     virtual void        AdjustMenus(void);
  118. //    virtual Boolean        DispatchMenuCommand(MenuCommand command);
  119. //    virtual Boolean     DispatchMenuSelection(MenuSelection& selection);
  120.  
  121.     //    Methods for use with the Drag Manager
  122.     
  123.     virtual    void        ClickAndDrag(EventRecord * anEvent);
  124.                         //    NOTE:    This method takes GLOBAL coordinates
  125.                         //            because that’s what TrackDrag expects.
  126.     
  127.     virtual    OSErr        HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag);
  128.  
  129.     virtual    OSErr        DragEnterWindow(DragReference theDrag);
  130.     virtual    OSErr        DragInWindow(DragReference theDrag);
  131.     virtual    OSErr        DragLeaveWindow(DragReference theDrag);
  132.  
  133.     virtual    OSErr        HandleDrop(DragReference theDragRef);
  134.  
  135.     virtual Boolean        IsPointInContentRgn( Point pt );
  136.     virtual Boolean        IsMouseInContentRgn( DragReference dragRef );
  137.     virtual Rect        GetContentsBounds(void);
  138.  
  139.     //    TWindowEventDispatcher overrides
  140.  
  141.     virtual Boolean        DispatchContentClick(EventRecord& event, WindowRef window);
  142.     virtual Boolean        DispatchUpdate(EventRecord& event);
  143.     virtual Boolean        DispatchActivateOrResume(EventRecord& event);
  144.     virtual Boolean        DispatchDeactivateOrSuspend(EventRecord& event);
  145.  
  146.     virtual Boolean     TrackDrag(EventRecord& event, WindowRef window);
  147.     virtual Point        TrackGrow(EventRecord& event, WindowRef window);
  148.     virtual Boolean     TrackGoAway(EventRecord& event, WindowRef window);
  149.     virtual Boolean     TrackZoomIn(EventRecord& event, WindowRef window);
  150.     virtual Boolean     TrackZoomOut(EventRecord& event, WindowRef window);
  151.  
  152.     //    AEOM Support
  153.     virtual void        AEGetNameDesc(CAEDesc& value, const CAETypeList& requestedTypes = fgWildcardTypeList) const;
  154.     virtual void        AESetNameDesc(const CAEDesc& name);
  155.     virtual void        HandleAEClose(AEServerEvent& event);
  156.  
  157.     //  Class methods
  158.     static TWindow*        GetWindowObject(WindowRef aWindow);
  159.     static TWindow*        GetNthWindow(long index, WindowLayer = kNormalWindowLayer);
  160.     static TWindow*        GetNamedWindow(ConstStr255Param name, WindowLayer = kNormalWindowLayer);
  161.  
  162. private:
  163.     static DragTrackingHandler    fgDragTrackingHandler;
  164.     static DragReceiveHandler    fgDragReceiveHandler;
  165.     
  166.     // Toolbox callbacks
  167.     static pascal OSErr    CallWindowDragTrackingHandler(DragTrackingMessage message,WindowRef theWindow,void *handlerRefCon,DragReference theDragRef);
  168.     static pascal OSErr    CallWindowDragReceiveHandler(WindowRef theWindow, void *handlerRefCon,DragReference theDragRef);
  169. };
  170.  
  171. class WithModalDialogHilite
  172. {
  173. private:
  174.     static int    fgNestLevel;
  175.     
  176. public:
  177.     WithModalDialogHilite();
  178.     ~WithModalDialogHilite();
  179. };
  180.  
  181. inline Rect GetWindowBounds(WindowRef w)     { return GetWindowPort(w)->portRect; }
  182.  
  183.  
  184. #endif
  185.