home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / odtlktv4.zip / ODTLKT / TOOLKIT / BETA / SAMPLES / OPENDOC / PUBUTILS / FOCUSLIB.H < prev    next >
C/C++ Source or Header  |  1995-12-04  |  6KB  |  178 lines

  1. /********************************************************************/
  2. /*  Licensed Materials - Property of IBM                            */
  3. /*                                                                  */
  4. /*                                                                  */
  5. /* Copyright (C) International Business Machines Corp., 1994.       */
  6. /* Copyright (C) Apple Computer, Inc., 1994                         */
  7. /*                                                                  */
  8. /*  US Government Users Restricted Rights -                         */
  9. /*  Use, duplication, or disclosure restricted                      */
  10. /*  by GSA ADP Schedule Contract with IBM Corp.                     */
  11. /*                                                                  */
  12. /*  IBM Change History (most recent first):                         */
  13. /*  138899 11/12/95 ced  Add fWindowClipRgn for DrgGetPS workaround */
  14. /*  124371  6/02/95 ced  Added support for drag PS in CFocusWindow  */
  15. /*  120604  4/28/95 ced  Merge with B1C16 Apple code.               */
  16. /*                                                                  */
  17. /********************************************************************/
  18. /*
  19.   File:    FocusLib.h
  20.  
  21.   THEORY OF OPERATION:
  22.  
  23.     FocusLib sets up the drawing environment for a part so that
  24.     it can start drawing into a facet. It provides both a one-time change of
  25.     focus (via the Focus call) and a way to set the focus but restore it later
  26.     when the current scope exits (via the CFocus object.)
  27.  
  28.     Focus() and FocusWindow() are slightly different for offscreen facets. If the
  29.     facet is in an offscreen canvas, Focus will set up to draw into that canvas;
  30.     this is what one usually wants to do. On the other hand, FocusWindow will
  31.     always focus onto an on-screen canvas, even for an off-screen facet. Use
  32.     FocusWindow for things like rubber-banding where your drawing needs to show
  33.     up immediately, even if the facet is offscreen.
  34.  
  35.     The CFocus object deserves an example:
  36.  
  37.     void DrawSomething( ODFacet *facet )
  38.     {
  39.       CFocus f(facet);    // Creates a CFocus object on the stack, which
  40.                           // changes the focus but stores the old state
  41.       ....drawing code...
  42.     }
  43.  
  44.     Declaring the CFocus object calls its constructor, which sets the focus and
  45.     stores the old state in the CFocus object itself (on the stack.) When its
  46.     scope exists, the CFocus object's destructor is called, which restores the
  47.     old focus.
  48.  
  49. */
  50.  
  51.  
  52. #ifndef _FOCUSLIB_
  53. #define _FOCUSLIB_
  54.  
  55. #ifndef __OS2DEF__
  56. #include <os2def.h>
  57. #endif
  58.  
  59. #ifndef INCL_ODDTS // include non-DTS C++ headers
  60.  
  61. #ifndef SOM_Module_OpenDoc_Global_TypesB_defined
  62. #include "ODTypesB.xh"    
  63. #endif
  64.  
  65. #else // include DTS C++ headers
  66.  
  67. #ifndef SOM_HH_DTS_Included
  68. #include <som.hh>
  69. #endif
  70. #ifndef _DTS_HH_INCLUDED_ODTypesB
  71. #include <ODTypesB.hh>
  72. #endif
  73.  
  74. #endif // ! INCL_ODDTS
  75.  
  76. #ifdef __cplusplus
  77.  
  78. class ODCanvas;
  79. class ODShape;
  80. class ODFacet;
  81. struct Environment;
  82. #else
  83.   #ifndef som_h
  84.   #include <som.h>
  85.   #endif
  86.   #ifndef SOM_ODCanvas_h
  87.   #include <Canvas.h>
  88.   #endif
  89.   #ifndef SOM_ODShape_h
  90.   #include <Shape.h>
  91.   #endif
  92.   #ifndef SOM_ODFacet_h
  93.   #include <Facet.h>
  94.   #endif
  95. #endif
  96.  
  97. /*  FocusState stores the state data for QD focusing.
  98.   C users should allocate one on the stack and call BeginFocus and
  99.   EndFocus (q.v.) to do the focusing.
  100.   C++ users should ignore FocusState and simply allocate a CFocus object
  101.   (see below).
  102. */
  103.  
  104. struct FocusState
  105. {
  106.   HPS          fHPS;
  107.   HWND         fHWND;
  108.   HWND         fToWindow;
  109.   HRGN         fClipRgn;
  110.   ODFacet*     fFacet;
  111.   ODBoolean    fDragPS;
  112.   Environment* fEv;
  113.  
  114. #ifdef __cplusplus
  115.   void    BeginFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  116.                     ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS);
  117.   void    EndFocus( );
  118. #endif
  119. };
  120. typedef struct FocusState FocusState;
  121.  
  122.  
  123. /*  CFocus is a class for C++ users. Just allocate one as a local variable:
  124.   the constructor will focus, and the destructor (called when it goes out
  125.   of scope or an exception is thrown) will unfocus.
  126.   CFocusWindow is just like CFocus, but focuses to the window instead of
  127.   the facet's canvas (if they're different.)
  128. */
  129.  
  130. #ifdef __cplusplus
  131.  
  132. class CFocus {
  133.   public:
  134.   CFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, HPS *theHPS );
  135.   CFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, HPS *theHPS, HRGN* theClipRgn );
  136.   virtual ~CFocus();
  137.  
  138. protected:
  139.   FocusState f;
  140. };
  141.  
  142. class CFocusWindow {
  143.   public:
  144.   enum TypePS {
  145.     NormalPS,
  146.     DragPS,
  147.     LockedWindowUpdatePS
  148.   };
  149.     
  150.   CFocusWindow( Environment* ev, ODFacet *facet, ODShape* invalShape,
  151.                             HPS *theHPS, HWND *theHWND = kODNULL, TypePS typePS = NormalPS);
  152.  
  153.   CFocusWindow( Environment* ev, ODFacet *facet, ODShape* invalShape,
  154.                 HPS *theHPS, HWND *theHWND, TypePS typePS, HRGN *theClipRgn);
  155.   virtual ~CFocusWindow();
  156.   
  157.   protected:
  158.   FocusState f;
  159. };
  160. #endif
  161.  
  162.  
  163. #ifdef __cplusplus
  164. extern "C" {
  165. #endif
  166.  
  167. // For C only:
  168. void BeginFocus( Environment* ev, FocusState* foc, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  169.          ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS);
  170.  
  171. void EndFocus( FocusState* );
  172.  
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176.  
  177. #endif //_FOCUSLIB_
  178.