home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / FocusLib.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  10KB  |  364 lines

  1. /* @(#)Z 1.15 os2/src/pubutils/src/FocusLib.cpp, odpubutils, od96os2, odos29712d 97/03/21 17:37:54 (96/10/22 13:56:05) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odpubutils
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. //
  30. //
  31.  
  32. #ifdef _PLATFORM_OS2_
  33. // We have a platform specific version here.
  34.  
  35. #pragma import ( DrgGetClipPS,"DrgGetClipPS","PMCtls",108)
  36.  
  37. //#ifndef _ODUTILS_
  38. //#include <ODUtils.h>
  39. //#endif
  40.  
  41. #ifndef _ALTPOINT_
  42. #include "AltPoint.h"
  43. #endif
  44.  
  45. #ifndef _FOCUSLIB_
  46. #include <FocusLib.h>
  47. #endif
  48.  
  49. #ifndef SOM_ODShape_xh
  50. #include "Shape.xh"
  51. #endif
  52.  
  53. #ifndef SOM_ODPlatformCanvas_xh
  54. #include "PlatCanv.xh"
  55. #endif
  56.  
  57. #ifndef SOM_ODTransform_xh
  58. #include "Trnsform.xh"
  59. #endif
  60.  
  61. #ifndef SOM_ODFacet_xh
  62. #include "Facet.xh"
  63. #endif
  64.  
  65. #ifndef SOM_ODFrame_xh
  66. #include "Frame.xh"
  67. #endif
  68.  
  69. #ifndef SOM_ODWindow_xh
  70. #include "Window.xh"
  71. #endif
  72.  
  73. #ifndef SOM_OS2PCanv_xh
  74. #include "OS2PCanv.xh"
  75. #endif
  76.  
  77. #ifndef SOM_OS2WCanv_xh
  78. #include "OS2WCanv.xh"
  79. #endif
  80.  
  81. #ifndef SOM_ODCanvas_xh
  82. #include "Canvas.xh"
  83. #endif
  84.  
  85. HPS APIENTRY DrgGetClipPS(HWND hwnd,HWND hwndClip,ULONG fl);  // Not yet in PMWIN.H
  86.  
  87.  
  88. //------------------------------------------------------------------------------
  89. // FocusState::BeginFocus
  90. //------------------------------------------------------------------------------
  91. void
  92. FocusState::BeginFocus(ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  93.                     ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS)
  94. {
  95.  
  96.   // Remember toWindow
  97.   fToWindow = toWindow;
  98.   MATRIXLF mtx;
  99.  
  100.   // Remember the facet
  101.   fFacet          = facet;
  102.   fclipShape      = NULL;
  103.   Environment *ev = somGetGlobalEnvironment();
  104.   fEv         = ev;
  105.   ODCanvas* canvas = facet->GetCanvas(ev);
  106.  
  107.   // Get the HDC
  108.   if (toWindow)
  109.   {
  110.     fHWND = WinWindowFromID((HWND)( facet->GetWindow(ev)->GetPlatformWindow(ev) ), FID_CLIENT);
  111.     ULONG ulClipFlags = 0, ulStyle;
  112.     ulStyle = WinQueryWindowULong(fHWND, QWL_STYLE);
  113.     if (ulStyle & WS_CLIPCHILDREN) ulClipFlags |= PSF_CLIPCHILDREN;
  114.     if (ulStyle & WS_CLIPSIBLINGS) ulClipFlags |= PSF_CLIPSIBLINGS;
  115.     if (ulStyle & WS_PARENTCLIP)   ulClipFlags |= PSF_PARENTCLIP;
  116.     if (!fDragPS)
  117.     {
  118.       if (lockedWindowUpdate)     ulClipFlags |= PSF_LOCKWINDOWUPDATE;
  119.       fHPS = WinGetClipPS(fHWND, 0, ulClipFlags);
  120.     }
  121.     else
  122.     {
  123.       ulClipFlags |= PSF_LOCKWINDOWUPDATE;
  124.       fHPS = DrgGetClipPS(fHWND, 0, ulClipFlags);
  125.     }
  126.   }
  127.   else
  128.   {
  129.     ODPlatformCanvas *tmpCanvas = facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODPM);
  130.     fHPS = ( (ODOS2Canvas*)tmpCanvas )->GetPS(ev);
  131.   }
  132.  
  133.  
  134.   // Find out if we're a Metafile DC
  135.   ODBoolean isMetafileDC = 0;
  136.  
  137.   // Are we Printing?
  138.   ODBoolean isPrinting = !(facet->GetCanvas(ev)->IsDynamic(ev));
  139.  
  140.   // Clip to it (don't clip if to a Window)
  141.   // Don't clip to Metafiles because it's basically useless
  142.   if (!toWindow && !isMetafileDC)
  143.   {
  144.     fclipShape = facet->CreateShape(ev);
  145.     if (fclipShape)
  146.     {
  147.       // When drawing to a window, the clip shape is the invalid shape
  148.       // which was passed in. 
  149.       if (!isPrinting) 
  150.       {
  151.         if (invalShape)
  152.         {
  153.           fclipShape->CopyFrom(ev, invalShape);
  154.         }
  155.         else
  156.         {
  157.           ODShape *cShape = facet->AcquireClipShape(ev, kODNULL);
  158.           fclipShape->CopyFrom( ev, cShape);
  159.           cShape->Release( ev );
  160.         }
  161.       }
  162.       else 
  163.       {
  164.         // In the printing case, the shape we clip to is the determined by
  165.         // the aggregate clip shape intersected with the frame's used
  166.         // shape, then intersected with the invalid shape which was passed
  167.         // in.
  168.         ODShape *aggshape = facet->AcquireAggregateClipShape(ev, kODNULL);
  169.         ODShape *usedshape = facet->GetFrame(ev)->AcquireUsedShape(ev, kODNULL);
  170.         fclipShape->CopyFrom( ev, aggshape );
  171.         fclipShape->Intersect( ev, usedshape );
  172.     if (invalShape)
  173.             fclipShape->Intersect(ev, invalShape);
  174.  
  175.         aggshape->Release( ev );
  176.         usedshape->Release( ev );
  177.       }
  178.  
  179.       // When drawing to a window, transform using the facet's window 
  180.       // frame transform.  This should convert the shape to window 
  181.       // coordinates for the docshell window.
  182.       ODTransform *frameTransform;
  183.       if( !isPrinting ) 
  184.       {
  185.         frameTransform = facet->AcquireWindowFrameTransform(ev, kODNULL);
  186.         fclipShape->Transform(ev, frameTransform);
  187.       }
  188.       else 
  189.       {
  190.         // For printing, transform using the facet's frame transform. The
  191.         // facet's window frame transform wouldn't work in this case. 
  192.         frameTransform = facet->AcquireFrameTransform(ev, kODNULL);
  193.         fclipShape->Transform(ev, frameTransform);
  194.       }
  195.     
  196.       HRGN clip;
  197.       
  198.       // The following lines were added so parts are clipped properly when 
  199.       // rotated. The GpiOffsetRegion() call below was also added and some 
  200.       // lines were deleted.  If you use GetOffset(), as was previously used, 
  201.       // it takes into account post-scale but pre-rotation.
  202.       // GetBoundingBox() is taking into account post-scale & post-rotation.
  203.       if( !isPrinting ) 
  204.       {
  205.         ODShape *frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL);
  206.         ODShape *frameShape2 = frameShape->Copy(ev);
  207.         frameShape->Release(ev);
  208.         frameShape2->Transform(ev, frameTransform);
  209.         ODRect RectBounds;
  210.         frameShape2->GetBoundingBox(ev, &RectBounds);
  211.         frameShape2->Release(ev);
  212.         RECTL rl;
  213.         RectBounds.AsRECTL(rl);
  214.         POINTL pt;
  215.         pt.x = -rl.xLeft;
  216.         pt.y = -rl.yBottom;
  217.  
  218.         // Get the region from the clipshape
  219.         clip = fclipShape->GetRegion(ev);
  220.         GpiOffsetRegion(fHPS, clip, &pt);
  221.       }
  222.       else 
  223.       {
  224.         clip = fclipShape->GetRegion(ev);
  225.       }
  226.  
  227.       ODTransform* xform1 = facet->AcquireContentTransform(ev, canvas);
  228.       xform1->GetMATRIXLF(ev, &mtx);
  229.       xform1->Release(ev);
  230.  
  231.       GpiSavePS(fHPS);
  232.       GpiResetPS(fHPS, GRES_ATTRS);
  233.       GpiSetDefaultViewMatrix(fHPS, 9, &mtx, TRANSFORM_REPLACE);
  234.  
  235.       // If a region was retrieved
  236.       if (clip)
  237.       {
  238.         if (!isPrinting) 
  239.         { 
  240.           HRGN mainRgn = facet->CopyAggregateClipRegion(ev, fHPS);  // Fast PM Clipping
  241.           GpiCombineRegion(fHPS, clip, clip, mainRgn, CRGN_AND );
  242.           GpiDestroyRegion(fHPS, mainRgn);
  243.         }
  244.  
  245.         HRGN hrgnOld;
  246.         GpiSetClipRegion(fHPS, clip, &hrgnOld);
  247.         GpiDestroyRegion(fHPS, hrgnOld);
  248.       }
  249.  
  250.       frameTransform->Release(ev);
  251.     }
  252.   }
  253. }
  254.  
  255. //------------------------------------------------------------------------------
  256. // FocusState::EndFocus
  257. //------------------------------------------------------------------------------
  258.  
  259. void
  260. FocusState::EndFocus( )
  261. {
  262.   // Only got fclipShape if (!toWindow && !isMetafileDC && !isPrinting)
  263.   if (fclipShape)
  264.   {
  265.     fclipShape->Release(fEv);
  266.   }
  267.  
  268.   GpiRestorePS(fHPS, -1);
  269.  
  270.   // Release the PS
  271.   if (fToWindow)
  272.   {
  273.     if (fDragPS)
  274.       DrgReleasePS(fHPS);
  275.     else
  276.       WinReleasePS(fHPS);
  277.   } 
  278.   else
  279.   {
  280.     ODPlatformCanvas *theCanv = fFacet->GetCanvas(fEv)->GetPlatformCanvas(fEv, kODPM);
  281.     ( (ODOS2Canvas*)theCanv )->ReleasePS(fEv);
  282.   }
  283. }
  284.  
  285. //------------------------------------------------------------------------------
  286. // CFocus
  287. //------------------------------------------------------------------------------
  288.  
  289. CFocus::CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS )
  290. {
  291.   f.BeginFocus(facet, invalShape, kODTrue, kODFalse, kODFalse, kODFalse);
  292.   *theHPS = f.fHPS;
  293. }
  294.  
  295. CFocus::CFocus(ODFacet *facet, ODShape* invalShape, HPS *theHPS, HRGN *theClipRgn)
  296. {
  297.   f.BeginFocus(facet, invalShape, kODFalse, kODFalse, kODFalse, kODFalse);
  298.   *theHPS = f.fHPS;
  299.   *theClipRgn = f.fClipRgn;
  300. }
  301.  
  302. CFocus::~CFocus( )
  303. {
  304.   try
  305.   {
  306.     f.EndFocus();
  307.   }
  308.   catch (ODException _exception)
  309.   {
  310.   }
  311. }
  312.  
  313. CFocusWindow::CFocusWindow(ODFacet *facet, ODShape* invalShape,
  314.                             HPS *theHPS, HWND *theHWND, TypePS typePS)
  315. {
  316.   f.BeginFocus(facet, invalShape, kODTrue, kODTrue,
  317.                         (typePS == LockedWindowUpdatePS), (typePS == DragPS));
  318.   *theHPS = f.fHPS;
  319.   if (theHWND)
  320.     *theHWND = f.fHWND;
  321. }
  322.  
  323. CFocusWindow::CFocusWindow(ODFacet *facet, ODShape* invalShape,
  324.                             HPS *theHPS, HWND *theHWND, TypePS typePS, HRGN *theClipRgn)
  325. {
  326.   f.BeginFocus(facet, invalShape, kODFalse, kODTrue,
  327.                         (typePS == LockedWindowUpdatePS), (typePS == DragPS));
  328.   *theHPS = f.fHPS;
  329.   if (theHWND)
  330.     *theHWND = f.fHWND;
  331.   *theClipRgn = f.fClipRgn;
  332. }
  333.  
  334. CFocusWindow::~CFocusWindow( )
  335. {
  336.   try
  337.   {
  338.     f.EndFocus();
  339.   }
  340.   catch (ODException _exception)
  341.   {
  342.   }
  343. }
  344.  
  345. //------------------------------------------------------------------------------
  346. // BeginFocus and EndFocus
  347. //------------------------------------------------------------------------------
  348. void
  349. BeginFocus(FocusState* foc, ODFacet *facet, ODShape* invalShape, ODBoolean setClipRgn,
  350.             ODBoolean toWindow, ODBoolean lockedWindowUpdate, ODBoolean dragPS)
  351. {
  352.   foc->BeginFocus(facet, invalShape, setClipRgn,
  353.                    toWindow, lockedWindowUpdate, dragPS);
  354. }
  355.  
  356. void
  357. EndFocus( FocusState* foc)
  358. {
  359.   foc->EndFocus();
  360. }
  361.  
  362.  
  363. #endif // _PLATFORM_OS2_
  364.