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.CPP < prev    next >
C/C++ Source or Header  |  1995-12-04  |  9KB  |  247 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. /*  File:       FocusLib.cpp                                        */
  13. /*                                                                  */
  14. /*  Contains:   Library routines for focusing (setting up for       */
  15. /*              drawing into a facet)                               */
  16. /*                                                                  */
  17. /*  Change History (most recent first):                             */
  18. /*  138899 11/12/95 ced  Add fWindowClipRgn for DrgGetPS workaround */
  19. /********************************************************************/
  20.  
  21. #ifndef _EXCEPT_
  22. #include "Except.h"
  23. #endif
  24.  
  25. #ifndef _ALTPOINT_
  26. #include <AltPoint.h>
  27. #endif
  28.  
  29. #ifndef _ALTPOLY_
  30. #include <AltPoly.h>
  31. #endif
  32.  
  33. #ifndef _ODUTILS_
  34. #include <ODUtils.h>
  35. #endif
  36.  
  37. #define INCL_GPI
  38. #define INCL_WIN
  39. #define INCL_ODAPI
  40. #define INCL_ODCANVAS
  41. #define INCL_ODFACET
  42. #define INCL_ODSHAPE
  43. #define INCL_ODTRANSFORM
  44. #define INCL_ODWINDOW
  45. #include <os2.h>     // [129073] - ced
  46.  
  47. #ifndef _FOCUSLIB_
  48. #include <FocusLib.h>
  49. #endif
  50.  
  51. #include <string.h>
  52. #include <stdio.h>
  53.  
  54. HPS   APIENTRY DrgGetClipPS(HWND hwnd,               // Not yet in PMWIN.H
  55.                             HWND hwndClip,
  56.                             ULONG fl);
  57.  
  58. //------------------------------------------------------------------------------
  59. // FocusState::BeginFocus
  60. //------------------------------------------------------------------------------
  61. void
  62. FocusState::BeginFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  63.                     ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS)
  64. {
  65.     // Remember toWindow
  66.     fToWindow = toWindow;
  67.  
  68.     // Remember the facet
  69.     fFacet      = facet;
  70.     fDragPS     = dragPS;
  71.     fClipRgn    = 0;
  72.     fEv         = ev;
  73.     MATRIXLF    mtx;
  74.     HRGN        hrgnOld;
  75.  
  76.    ODCanvas* canvas = facet->GetCanvas(ev);
  77.  
  78.    if (toWindow) {
  79.        fHWND = WinWindowFromID(facet->GetWindow(ev)->GetPlatformWindow(ev), FID_CLIENT);
  80.        ULONG ulClipFlags = 0, ulStyle;
  81.        ulStyle = WinQueryWindowULong(fHWND, QWL_STYLE);
  82.        if (ulStyle & WS_CLIPCHILDREN) ulClipFlags |= PSF_CLIPCHILDREN;
  83.        if (ulStyle & WS_CLIPSIBLINGS) ulClipFlags |= PSF_CLIPSIBLINGS;
  84.        if (ulStyle & WS_PARENTCLIP)   ulClipFlags |= PSF_PARENTCLIP;
  85.        if (!fDragPS)
  86.        {
  87.           if (lockedWindowUpdate)     ulClipFlags |= PSF_LOCKWINDOWUPDATE;
  88.           fHPS = WinGetClipPS(fHWND, 0, ulClipFlags);
  89.        }
  90.        else
  91.        {
  92.            ulClipFlags |= PSF_LOCKWINDOWUPDATE;
  93.            fHPS = DrgGetClipPS(fHWND, 0, ulClipFlags);
  94.        }
  95.  
  96.        ODShape* clipShape = facet->AcquireWindowFrameAggregateClipShape(ev, canvas);
  97.        fClipRgn = clipShape->CopyRegion(ev);
  98.        ODReleaseObject(ev, clipShape);
  99.        ODTransform* xform = facet->AcquireWindowContentTransform(ev, canvas);
  100.        xform->GetMATRIXLF(ev, &mtx);
  101.        ODReleaseObject(ev, xform);
  102.    } else {
  103.        fHPS = facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODGPI)->GetPS(ev, facet);
  104.        ODShape* clipShape = facet->AcquireFrameAggregateClipShape(ev, canvas);
  105.        fClipRgn = clipShape->CopyRegion(ev);
  106.        ODReleaseObject(ev, clipShape);
  107.        ODTransform* xform = facet->AcquireContentTransform(ev, canvas);
  108.        xform->GetMATRIXLF(ev, &mtx);
  109.        ODReleaseObject(ev, xform);
  110.    }
  111.  
  112.    if (fClipRgn && invalShape) {
  113.       ODShape* tempShape = invalShape->Copy(ev);
  114.       ODTransform* xform = toWindow ? facet->AcquireWindowFrameTransform(ev, canvas) :
  115.                                       facet->AcquireFrameTransform(ev, canvas);
  116.       tempShape->Transform(ev, xform);
  117.       GpiCombineRegion(fHPS, fClipRgn, fClipRgn, tempShape->GetRegion(ev), CRGN_AND);
  118.       ODReleaseObject(ev, xform);
  119.       ODReleaseObject(ev, tempShape);
  120.    }
  121.  
  122.  
  123.    GpiSavePS(fHPS);
  124.    GpiResetPS(fHPS, GRES_ATTRS);
  125.    GpiSetDefaultViewMatrix(fHPS, 9, &mtx, TRANSFORM_REPLACE);
  126.  
  127.    if (fClipRgn && setClipRgn)
  128.       GpiSetClipRegion(fHPS, fClipRgn, &hrgnOld);
  129.  
  130.    /*
  131.     * If the facets highlight mode is full highlight, then set the mix mode
  132.     * for inverted drawing.  This type of highlighting may not be appropriate
  133.     * for some parts.
  134.     */
  135.    if (facet->GetHighlight(ev) == kODFullHighlight) {
  136.       LINEBUNDLE   lbundle;
  137.       CHARBUNDLE   cbundle;
  138.       MARKERBUNDLE mbundle;
  139.       AREABUNDLE   abundle;
  140.       IMAGEBUNDLE  ibundle;
  141.  
  142.       /*
  143.        * Set the current default mix modes of each pritive to inverted color
  144.        */
  145.       lbundle.usMixMode = FM_NOTCOPYSRC;
  146.       cbundle.usMixMode = FM_NOTCOPYSRC;
  147.       mbundle.usMixMode = FM_NOTCOPYSRC;
  148.       abundle.usMixMode = FM_NOTCOPYSRC;
  149.       ibundle.usMixMode = FM_NOTCOPYSRC;
  150.       GpiSetDefAttrs(fHPS, PRIM_LINE,   LBB_MIX_MODE, (PBUNDLE)&lbundle);
  151.       GpiSetDefAttrs(fHPS, PRIM_CHAR,   CBB_MIX_MODE, (PBUNDLE)&cbundle);
  152.       GpiSetDefAttrs(fHPS, PRIM_MARKER, MBB_MIX_MODE, (PBUNDLE)&mbundle);
  153.       GpiSetDefAttrs(fHPS, PRIM_AREA,   ABB_MIX_MODE, (PBUNDLE)&abundle);
  154.       GpiSetDefAttrs(fHPS, PRIM_IMAGE,  IBB_MIX_MODE, (PBUNDLE)&ibundle);
  155.    }
  156. }
  157.  
  158. //------------------------------------------------------------------------------
  159. // FocusState::EndFocus
  160. //------------------------------------------------------------------------------
  161.  
  162. void
  163. FocusState::EndFocus( )
  164. {
  165.    GpiRestorePS(fHPS, -1);
  166.  
  167.    // Release the PS
  168.    if (fToWindow) {
  169.        if (fDragPS) 
  170.           DrgReleasePS(fHPS);
  171.        else
  172.           WinReleasePS(fHPS);
  173.    } else {
  174.        fFacet->GetCanvas(fEv)->GetPlatformCanvas(fEv, kODGPI)->ReleasePS(fEv, fFacet);
  175.    }
  176. }
  177.  
  178. //------------------------------------------------------------------------------
  179. // CFocus
  180. //------------------------------------------------------------------------------
  181.  
  182. CFocus::CFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, HPS *theHPS )
  183. {
  184.     f.BeginFocus( ev, facet, invalShape, kODTrue, kODFalse, kODFalse, kODFalse);
  185.     *theHPS = f.fHPS;
  186. }
  187.  
  188. CFocus::CFocus( Environment* ev, ODFacet *facet, ODShape* invalShape, HPS *theHPS, HRGN *theClipRgn)
  189. {
  190.     f.BeginFocus( ev, facet, invalShape, kODFalse, kODFalse, kODFalse, kODFalse);
  191.    *theHPS = f.fHPS;
  192.    *theClipRgn = f.fClipRgn;
  193. }
  194.  
  195. CFocus::~CFocus( )
  196. {
  197.   TRY
  198.     f.EndFocus();
  199.   CATCH_ALL
  200.   ENDTRY
  201. }
  202.  
  203. CFocusWindow::CFocusWindow( Environment* ev, ODFacet *facet, ODShape* invalShape,
  204.                             HPS *theHPS, HWND *theHWND, TypePS typePS)
  205. {
  206.     f.BeginFocus( ev, facet, invalShape, kODTrue, kODTrue,
  207.                         (typePS == LockedWindowUpdatePS), (typePS == DragPS));
  208.    *theHPS = f.fHPS;
  209.    if (theHWND) *theHWND = f.fHWND;
  210. }
  211.  
  212. CFocusWindow::CFocusWindow( Environment* ev, ODFacet *facet, ODShape* invalShape,
  213.                             HPS *theHPS, HWND *theHWND, TypePS typePS, HRGN *theClipRgn)
  214. {
  215.    f.BeginFocus( ev, facet, invalShape, kODFalse, kODTrue,
  216.                         (typePS == LockedWindowUpdatePS), (typePS == DragPS));
  217.    *theHPS = f.fHPS;
  218.    if (theHWND) *theHWND = f.fHWND;
  219.    *theClipRgn = f.fClipRgn;
  220. }
  221.  
  222. CFocusWindow::~CFocusWindow( )
  223. {
  224.   TRY
  225.     f.EndFocus();
  226.   CATCH_ALL
  227.   ENDTRY
  228. }
  229.  
  230. //------------------------------------------------------------------------------
  231. // BeginFocus and EndFocus
  232. //------------------------------------------------------------------------------
  233. void
  234. BeginFocus( Environment* ev, FocusState* foc, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  235.             ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS)
  236. {
  237.    foc->BeginFocus(ev, facet, invalShape, setClipRgn,
  238.                    toWindow, lockedWindowUpdate, dragPS);
  239. }
  240.  
  241. void
  242. EndFocus( FocusState* foc)
  243. {
  244.     foc->EndFocus();
  245. }
  246.  
  247.