home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / warphead.zip / H / FOCUSLIB.H < prev    next >
C/C++ Source or Header  |  1997-02-28  |  6KB  |  190 lines

  1. /* @(#)Z 1.4 os2/src/pubutils/include/FocusLib.h, odpubutils, od96os2, odos29646d 96/11/15 15:50:43 (96/08/23 01:42:34) */
  2. /*====START_GENERATED_PROLOG======================================
  3.  */
  4. /*
  5.  *   COMPONENT_NAME: odpubutils
  6.  *
  7.  *   CLASSES:   CFocus
  8.  *        CFocusWindow
  9.  *
  10.  *   ORIGINS: 82,27
  11.  *
  12.  *
  13.  *   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  14.  *   All Rights Reserved
  15.  *   Licensed Materials - Property of IBM
  16.  *   US Government Users Restricted Rights - Use, duplication or
  17.  *   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  18.  *       
  19.  *   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  20.  *   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21.  *   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  22.  *   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  23.  *   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  24.  *   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25.  *   OR PERFORMANCE OF THIS SOFTWARE.
  26.  */
  27. /*====END_GENERATED_PROLOG========================================
  28.  */
  29.  
  30. #ifdef _PLATFORM_OS2_
  31. // We have an OS/2 platform specific version here.
  32.  
  33. /*
  34.     File:        FocusLib.h
  35.  
  36.     Contains:    Library routines for focusing (setting up for drawing into a facet)
  37.  
  38.     Owned by:    Jens Alfke
  39.  
  40.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  41.          
  42.          
  43.     THEORY OF OPERATION:
  44.     
  45.         FocusLib sets up the drawing environment for a QuickDraw-based part so that
  46.         it can start drawing into a facet. It provides both a one-time change of
  47.         focus (via the Focus call) and a way to set the focus but restore it later
  48.         when the current scope exits (via the CFocus object.)
  49.         
  50.         Focus() and FocusWindow() are slightly different for offscreen facets. If the
  51.         facet is in an offscreen canvas, Focus will set up to draw into that canvas;
  52.         this is what one usually wants to do. On the other hand, FocusWindow will
  53.         always focus onto an on-screen canvas, even for an off-screen facet. Use
  54.         FocusWindow for things like rubber-banding where your drawing needs to show
  55.         up immediately, even if the facet is offscreen.
  56.  
  57.         The CFocus object deserves an example:
  58.         
  59.         void DrawSomething( ODFacet *facet )
  60.         {
  61.             CFocus f(facet);        // Creates a CFocus object on the stack, which
  62.                                     // changes the focus but stores the old state
  63.             ....drawing code...
  64.         }
  65.         
  66.         Declaring the CFocus object calls its constructor, which sets the focus and
  67.         stores the old state in the CFocus object itself (on the stack.) When its
  68.         scope exists, the CFocus object's destructor is called, which restores the
  69.         old focus.
  70.         
  71.         CFocus inherits from Destructo (see Except.h) so it will now be destructed
  72.         properly if an exception is thrown while it's active. You no longer need to
  73.         catch the exception and manually destruct the CFocus.
  74. */
  75.  
  76.  
  77. #ifndef _FOCUSLIB_
  78. #define _FOCUSLIB_
  79.  
  80. #ifndef _ODOS2_
  81. #include <odos2.h>
  82. #endif 
  83.  
  84. #ifndef _ODTYPES_
  85. #include <ODTypes.h>
  86. #endif
  87.  
  88. #ifdef __cplusplus
  89.     class ODCanvas;
  90.     class ODShape;
  91.     class ODFacet;
  92.     struct Environment;
  93. #else
  94.     #ifndef som_h
  95.     #include <som.h>
  96.     #endif
  97.     #ifndef SOM_ODCanvas_h
  98.     #include <Canvas.h>
  99.     #endif
  100.     #ifndef SOM_ODShape_h
  101.     #include <Shape.h>
  102.     #endif
  103.     #ifndef SOM_ODFacet_h
  104.     #include <Facet.h>
  105.     #endif
  106. #endif
  107.  
  108.  
  109. /*    FocusState stores the state data for QD focusing.
  110.     C users should allocate one on the stack and call BeginFocus and
  111.     EndFocus (q.v.) to do the focusing.
  112.     C++ users should ignore FocusState and simply allocate a CFocus object
  113.     (see below).
  114. */
  115. struct FocusState
  116. {
  117.   HPS          fHPS;
  118.   HWND         fHWND;
  119.   HWND         fToWindow;
  120.   HRGN         fClipRgn;
  121.   ODFacet*     fFacet;
  122.   ODBoolean    fDragPS;
  123.   ODShape        *fclipShape;
  124.   Environment* fEv;
  125.  
  126. #ifdef __cplusplus
  127.   void    BeginFocus(ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  128.                     ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS);
  129.   void    EndFocus( );
  130. #endif
  131. };
  132. typedef struct FocusState FocusState;
  133.  
  134. #ifdef __cplusplus
  135.  
  136. /*    CFocus is a class for C++ users. Just allocate one as a local variable:
  137.     the constructor will focus, and the destructor (called when it goes out
  138.     of scope or an exception is thrown) will unfocus.
  139.     CFocusWindow is just like CFocus, but focuses to the window instead of
  140.     the facet's canvas (if they're different.)
  141. */
  142. class CFocus {
  143.   public:
  144.   CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS );
  145.   CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS, HRGN* theClipRgn );
  146.   virtual ~CFocus();
  147.  
  148. protected:
  149.   FocusState f;
  150. };
  151.  
  152. class CFocusWindow {
  153.   public:
  154.   enum TypePS {
  155.     NormalPS,
  156.     DragPS,
  157.     LockedWindowUpdatePS
  158.   };
  159.     
  160.   CFocusWindow(ODFacet *facet, ODShape* invalShape,
  161.                             HPS *theHPS, HWND *theHWND = kODNULL, TypePS typePS = NormalPS);
  162.  
  163.   CFocusWindow(ODFacet *facet, ODShape* invalShape,
  164.                 HPS *theHPS, HWND *theHWND, TypePS typePS, HRGN *theClipRgn);
  165.   virtual ~CFocusWindow();
  166.   
  167.   protected:
  168.   FocusState f;
  169. };
  170. #endif
  171.  
  172.  
  173. #ifdef __cplusplus
  174. extern "C" {
  175. #endif
  176.  
  177. // For C only:
  178. void BeginFocus(FocusState* foc, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  179.          ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS);
  180.  
  181. void EndFocus( FocusState* );
  182.  
  183. #ifdef __cplusplus
  184. }
  185. #endif
  186.  
  187.  
  188. #endif //_FOCUSLIB_
  189. #endif // _PLATFORM_OS2_
  190.