home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / technical documentation / develop / develop issue 26 / develop issue 26 code / truffles - display mgr. / sprocket / interfaces / window.h < prev   
Encoding:
C/C++ Source or Header  |  1996-06-05  |  5.1 KB  |  189 lines

  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. #ifndef        _WINDOW_
  30. #define        _WINDOW_
  31.  
  32. #ifndef        __TYPES__
  33. #include    <Types.h>
  34. #endif
  35.  
  36. #ifndef        __WINDOWS__
  37. #include    <Windows.h>
  38. #endif
  39.  
  40. #ifndef        __EVENTS__
  41. #include    <Events.h>
  42. #endif
  43.  
  44. #ifndef        __DRAG__
  45. #include    <Drag.h>
  46. #endif
  47.  
  48. #ifndef        _MENUBAR_
  49. #include    "MenuBar.h"
  50. #endif
  51.  
  52.  
  53. typedef    short    WindowTemplateID;
  54.  
  55.  
  56. class    TWindow
  57.     {
  58. protected:
  59.     //    protect the constructor because it isn’t legal to create a TWindow directly
  60.                             TWindow();
  61.  
  62. public:
  63.  
  64.     virtual                    ~TWindow();
  65.  
  66.     //    Event routing methods
  67.  
  68.     virtual    Boolean            EventFilter(EventRecord * theEvent);    
  69.  
  70.     //    Methods you shouldn’t need to override, but might need to
  71.  
  72.     enum WindowType
  73.         {
  74.         kModalWindow    = 1000,
  75.         kFloatingWindow,
  76.         kNormalWindow
  77.         };
  78.  
  79.     virtual void            CreateWindow(WindowType typeOfWindowToCreate = kNormalWindow);
  80.     virtual    void            Select(void);
  81.     virtual    void            Drag(Point startPoint);
  82.     virtual void            Nudge(short horizontalDistance, short verticalDistance);
  83.     virtual void            Grow(Point startPoint);
  84.     virtual void            Zoom(short zoomState);
  85.  
  86.     virtual    void            ShowHide(Boolean showFlag);
  87.  
  88.  
  89.     //    Methods which MUST be overridden:
  90.  
  91.     virtual WindowRef        MakeNewWindow(WindowRef behindWindow)    = 0;
  92.     
  93.  
  94.     //    Methods which probably should be overridden
  95.  
  96.     virtual    void            AdjustCursor(EventRecord * anEvent);
  97.     virtual void            Idle(EventRecord * anEvent);
  98.     virtual void            Activate(Boolean activating);
  99.     virtual void            Draw();
  100.     virtual void            Click(EventRecord * anEvent);
  101.     virtual    void            KeyDown(EventRecord * anEvent);
  102.  
  103.     virtual    Boolean            Close();
  104.  
  105.     virtual void            GetPerfectWindowSize(Rect * perfectSize);
  106.     virtual    void            GetWindowSizeLimits(Rect * limits);
  107.     virtual void            AdjustForNewWindowSize(Rect * oldRect,Rect * newRect);
  108.  
  109.  
  110.     //    Window property accessor methods…
  111.     //        …watch for new ones when we add scripting support    
  112.     
  113.     virtual    Boolean            IsVisible();
  114.     virtual Rect            GetContentsBounds();
  115.     virtual    Boolean            CanClose();        
  116.  
  117.     
  118.     //    Methods for handling menus & menu commands
  119.     
  120.     virtual    void            AdjustMenusBeforeMenuSelection();
  121.     virtual    void            AdjustMenusAfterMenuSelection();
  122.     virtual Boolean            DoMenuSelection(short menu, short item);
  123.     virtual Boolean            DoMenuCommand(MenuCommandID menuCommand);
  124.  
  125.     //    Methods for use with the Drag Manager
  126.     
  127.     virtual    OSErr            HandleDrag(DragTrackingMessage dragMessage,DragReference theDrag);
  128.     virtual    OSErr            HandleDrop(DragReference theDragRef);
  129.  
  130.     virtual    OSErr            DragEnterWindow(DragReference theDrag);
  131.     virtual    OSErr            DragInWindow(DragReference theDrag);
  132.     virtual    OSErr            DragLeaveWindow(DragReference theDrag);
  133.  
  134.     static pascal OSErr        CallDragTrackingHandler(DragTrackingMessage message,WindowRef theWindow,void *handlerRefCon,DragReference theDragRef);
  135.     static pascal OSErr        CallDragReceiveHandler(WindowRef theWindow, void *handlerRefCon,DragReference theDragRef);
  136.  
  137.     virtual Boolean            IsPointInContentRgn(Point pt);
  138.     virtual Boolean            IsDragInContentRgn(DragReference dragRef);
  139.  
  140.     void                    FindScreenRectWithLargestPartOfWindow(WindowRef aWindow,Rect *theBestScreenRect, GDHandle * theBestDevice);
  141.  
  142. protected:
  143.     WindowRef                fWindow;
  144.     WindowType                fWindowType;
  145.  
  146.     Boolean                    fIsDialogWindow;
  147.     Boolean                    fIsVisible;
  148.  
  149.  
  150. //    "globals"
  151.  
  152.     static UInt32            fgModalState;
  153.  
  154. public:    
  155.  
  156. //    Utility functions:
  157.  
  158.     static WindowRef        FrontNonFloatingWindow();
  159.     static WindowRef        FrontModalWindow();
  160.     static WindowRef        LastModalWindow();
  161.     static WindowRef        FrontFloatingWindow();
  162.     static WindowRef        LastFloatingWindow();
  163.     static WindowRef        FrontNormalWindow();
  164.  
  165.  
  166. //    Cool functions that replace Toolbox equivalents and/or add functionality
  167.  
  168.     static WindowRef        GetNewWindow(short windowID, void *wStorage, WindowRef behind);
  169.     static WindowRef        NewWindow(void *wStorage, const Rect *boundsRect, ConstStr255Param title, Boolean visible, short theProc, WindowRef behind, Boolean goAwayFlag, long refCon);
  170.     static void                DrawGrowIcon(WindowRef theWindow);
  171.  
  172.     static void                EnterModalState();
  173.     static void                ExitModalState();
  174.  
  175.     static void                SuspendResumeWindows(Boolean resuming);
  176.  
  177.     static void                HiliteAndActivateWindow(WindowRef aWindow, Boolean active);
  178.     };
  179.  
  180.  
  181. //    Utility Functions:
  182.  
  183.  
  184. TWindow *            GetWindowObject(WindowRef aWindow);
  185.  
  186.  
  187.  
  188. #endif
  189.