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

  1. /* @(#)Z 1.22 com/src/layout/Border.cpp, odlayout, od96os2, odos29712d 97/03/21 17:18:25 (96/09/13 17:02:21) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odlayout
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27,94
  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. /*  IBM Change History (most recent first):                         */
  29. /*   20470 03/19/96 tmw/SA Apple DR4 and common Windows/OS2         */
  30. /********************************************************************/
  31. /*
  32.    File:       Border.cpp
  33.  
  34.    Contains:   Implementation of active border display routines
  35.  
  36.    Owned by:   Joshua Susser
  37.  
  38.    Copyright:  ⌐ 1995 by Apple Computer, Inc., all rights reserved.
  39.  
  40.    Change History (most recent first):
  41.  
  42.         <4>     6/20/95    JBS     1257315 change Facet::AcquireWindow to
  43.                                    GetWindow
  44.         <3>     5/26/95    RR      #1251403: Multithreading naming support
  45.         <2>     5/17/95    JBS     1242496 remove SOM_CATCH
  46.         <1>     2/28/95    JBS     first checked in
  47.         <0>     2/28/95    JBS     1198509 created
  48. */
  49.  
  50. #ifdef _PLATFORM_OS2_
  51. #define INCL_WIN
  52. #define INCL_GPI
  53. #include <ODos2.h>
  54. #endif //_PLATFORM_OS2_
  55.  
  56. /*
  57. These functions are private utilities for use by ODFacet to display and
  58. invalidate the active border.  The functions are platform-dependent, in
  59. that they make direct calls to the platform graphics system.
  60. */
  61.  
  62. #ifndef _ALTPOINT_
  63. #include "AltPoint.h"
  64. #endif
  65.  
  66. #ifndef _TEMPOBJ_
  67. #include <TempObj.h>
  68. #endif
  69.  
  70. #ifndef _BORDER_
  71. #include "Border.h"
  72. #endif
  73.  
  74. #ifndef SOM_ODFacet_xh
  75. #include <Facet.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODCanvas_xh
  79. #include <Canvas.xh>
  80. #endif
  81.  
  82. #ifdef _PLATFORM_WIN32_
  83. #ifndef SOM_ODWin32WindowCanvas_xh
  84. #include "WinWCanv.xh"
  85. #endif
  86. #endif //_PLATFORM_WIN32_
  87.  
  88. #ifdef _PLATFORM_OS2_
  89. #ifndef SOM_ODOS2WindowCanvas_xh
  90. #include "OS2WCanv.xh"
  91. #endif
  92.  
  93. #ifndef SOM_ODTransform_xh
  94. #include <Trnsform.xh>
  95. #endif
  96.  
  97. #ifndef _ODDEBUG_
  98. #include "ODDebug.h"
  99. #endif
  100. #endif //_PLATFORM_OS2_
  101.  
  102.  
  103. #ifndef SOM_ODShape_xh
  104. #include <Shape.xh>
  105. #endif
  106.  
  107. #ifndef SOM_ODWindow_xh
  108. #include <Window.xh>
  109. #endif
  110.  
  111. #ifdef _PLATFORM_MACINTOSH_
  112. #ifndef __QUICKDRAW__
  113. #include <QuickDraw.h>
  114. #endif
  115.  
  116. #pragma segment ODFacet
  117. #endif //_PLATFORM_MACINTOSH_
  118.  
  119. //==============================================================================
  120. // Global variables
  121. //==============================================================================
  122.  
  123. #ifdef _PLATFORM_MACINTOSH_
  124. extern Pattern borderPattern;
  125. #endif //_PLATFORM_MACINTOSH_
  126.  
  127. #ifdef _FACET_DEBUG_
  128. #include <qprintf.h>
  129. #endif
  130.  
  131. #ifdef _PLATFORM_WIN32_
  132.  
  133. #ifndef _TEMPOBJ_
  134. #include "TempObj.h"
  135. #endif
  136.  
  137. #ifndef SOM_ODTransform_xh
  138. #include <Trnsform.xh>
  139. #endif
  140.  
  141. #endif // PLATFORM_WIN32_
  142. //==============================================================================
  143. // Functions
  144. //==============================================================================
  145.  
  146. //------------------------------------------------------------------------------
  147. // ODDrawBorder
  148. //------------------------------------------------------------------------------
  149.  
  150. void
  151. ODDrawBorder(Environment *ev, ODShape* borderShape, ODFacet* facet)
  152. {
  153. #ifdef _FACET_DEBUG_
  154.   qprintf("Executing ODDrawBorder()\n");
  155. #endif //_FACET_DEBUG_
  156.  
  157. #ifdef _PLATFORM_WIN32_
  158.   HDC hDC;
  159.   ODWin32WindowCanvas *platcanv;
  160.   LONG winStyles=0;
  161.   LONG rStyles=0;
  162.   HWND hwnd;
  163.  
  164.  
  165.   ODWindow* window = facet->GetWindow(ev);
  166.  
  167.   if ( window != kODNULL )
  168.   {
  169.     ODRgnHandle borderRgn  = borderShape->GetRegion(ev);
  170.  
  171. #ifdef _FACET_DEBUG_
  172.     ODRect boundingBox;
  173.     borderShape->GetBoundingBox(ev, &boundingBox);
  174.     RECT RectShape;
  175.     boundingBox.AsWinRect(RectShape);
  176.     qprintf("??In DrawBorder()->border shape left=%d\ttop=%d\tright=%d\tbottom=%d\n", RectShape.left, RectShape.top, RectShape.right, RectShape.bottom);
  177.     GetRgnBox(borderRgn, &RectShape);
  178.     qprintf("??In DrawBorder()->border region left=%d\ttop=%d\tright=%d\tbottom=%d\n", RectShape.left, RectShape.top, RectShape.right, RectShape.bottom);
  179. #endif //_FACET_DEBUG_
  180.  
  181.     ODFacet* parentFacet = facet->GetContainingFacet(ev);
  182.  
  183.     if(parentFacet)
  184.     {
  185.       hwnd= parentFacet->GetFacetHWND(ev);
  186.       HWND facethwnd = facet->GetFacetHWND(ev);
  187.       LONG fwStyles = GetWindowLong(facethwnd, GWL_STYLE);
  188.  
  189.       if(fwStyles & WS_VISIBLE)  // OLE parts hide the window
  190.       {
  191.        winStyles = GetWindowLong(hwnd, GWL_STYLE);
  192.        rStyles = (WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
  193.        winStyles &= ~(rStyles);
  194.        SetWindowLong(hwnd, GWL_STYLE, winStyles);
  195.       }
  196.  
  197.       platcanv = (ODWin32WindowCanvas *) parentFacet->GetCanvas(ev)->GetPlatformCanvas(ev, kODWin32);
  198.       hDC = platcanv->GetDC(ev);
  199.  
  200.     //Hairy Hatch Border
  201.     WORD    wHatchBmp[] = {0x11, 0x22, 0x44, 0x88, 0x11, 0x22, 0x44, 0x88};
  202.  
  203.     HBITMAP hbm = CreateBitmap(8, 8, 1, 1, wHatchBmp);
  204.     HBRUSH  hairBrush = CreatePatternBrush(hbm);
  205.     HBRUSH  hbrOld = SelectObject(hDC, hairBrush);
  206.  
  207.     COLORREF cvText = SetTextColor(hDC, RGB(255, 255, 255));
  208.     COLORREF cvBk = SetBkColor(hDC, RGB(0, 0, 0));
  209.     FillRgn(hDC, borderRgn, hairBrush);
  210.     SetTextColor(hDC, cvText);
  211.     SetBkColor(hDC, cvBk);
  212.     SelectObject(hDC, hbrOld);
  213.     DeleteObject(hairBrush);
  214.     DeleteObject(hbm);
  215.  
  216.       platcanv->ReleaseDC(ev);
  217.       winStyles = GetWindowLong(hwnd, GWL_STYLE);
  218.       winStyles |= rStyles;
  219.       SetWindowLong(hwnd, GWL_STYLE, winStyles);
  220.     }
  221.   }
  222. #endif //_PLATFORM_WIN32_
  223.  
  224. #ifdef _PLATFORM_OS2_
  225.   ODOS2WindowCanvas *platcanv;
  226.   HWND hwndClient = NULLHANDLE;
  227.   ODWindow* window = facet->GetWindow(ev);
  228.   HPS hps;
  229.   ODFacet* parentFacet = facet->GetContainingFacet(ev);
  230.  
  231.  
  232.   if ( window != kODNULL )
  233.   {
  234.        HWND hwndFrame = window->GetPlatformWindow(ev);  //TMW don't use GetClientWindow()
  235.        hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
  236.        hps = WinGetPS(hwndClient);
  237.  
  238.     //Setup PS to draw border
  239.     LONG lSet = GpiQueryPatternSet(hps);
  240.     GpiResetPS(hps, GRES_ATTRS);
  241.     GpiSetPatternSet(hps,LCID_DEFAULT);
  242.     GpiSetPattern(hps, PATSYM_DIAG2);
  243.     GpiPaintRegion(hps, borderShape->GetRegion(ev));
  244.     GpiSetPatternSet(hps, lSet);
  245.  
  246. /*
  247.      ODRect fxRect;
  248.      RECTL upRect;
  249.      borderShape->GetBoundingBox(ev, &fxRect);
  250.      fxRect.AsRECTL(upRect);
  251.      WinValidateRect(hwndClient, &upRect, TRUE);
  252. */
  253.  
  254.      WinReleasePS(hps);
  255.      WinValidateRegion(hwndClient,
  256.                        borderShape->GetRegion(ev),
  257.                        TRUE);
  258.  
  259.   }
  260. #endif //_PLATFORM_OS2_
  261.  
  262.  
  263. #ifdef _PLATFORM_MACINTOSH_
  264.   GrafPtr savePort;
  265.  
  266.   ODWindow* window = facet->GetWindow(ev);
  267.   if ( window != kODNULL )
  268.   {
  269.     GetPort(&savePort);
  270.  
  271.     SetPort((GrafPtr)(window->GetRootFacet(ev)->
  272.             GetCanvas(ev)->GetPlatformCanvas(ev, kODQuickDraw)));
  273.     SetOrigin(0,0);
  274.     ClipRect(&(ODQDGlobals.thePort->portRect));
  275.  
  276.     RgnHandle borderRgn = borderShape->GetQDRegion(ev);
  277.     FillRgn(borderRgn, &borderPattern);
  278.  
  279.     SetPort(savePort);
  280.   }
  281. #endif // _PLATFORM_MACINTOSH_
  282. }
  283.  
  284. //------------------------------------------------------------------------------
  285. // ODInvalidateBorder
  286. //------------------------------------------------------------------------------
  287.  
  288. void
  289. ODInvalidateBorder(Environment *ev, ODShape* borderShape, ODFacet* facet)
  290. {
  291. #ifdef _FACET_DEBUG_
  292.     qprintf("Executing ODInvalidateBorder()\n");
  293. #endif
  294. #ifdef _PLATFORM_WIN32_
  295.   ODWindow* window = facet->GetWindow(ev);
  296.   if ( window != kODNULL )
  297.   {
  298.     ODFacet* parentFacet = facet->GetContainingFacet(ev);
  299.     HWND hwnd;
  300.  
  301.     if(parentFacet)
  302.     {
  303.  
  304.       TempODShape newshape = borderShape->Copy(ev);
  305.       TempODTransform xform = parentFacet->AcquireWindowFrameTransform(ev, kODNULL);
  306.       ODPoint pt(0, 0);
  307.       xform->TransformPoint(ev, &pt);
  308.       TempODTransform xform2 = parentFacet->CreateTransform(ev);
  309.       xform2->SetOffset(ev, &pt);
  310.       newshape->Transform(ev, xform2);
  311.       ODRgnHandle borderRgn  = newshape->GetRegion(ev);
  312.  
  313.       hwnd = window->GetPlatformWindow(ev);
  314.       InvalidateRgn(hwnd,
  315.                     borderRgn,
  316.                     FALSE);
  317.     }
  318.   }
  319. #endif //_PLATFORM_WIN32_
  320.  
  321. #ifdef _PLATFORM_OS2_
  322.  
  323.   ODWindow* window = facet->GetWindow(ev);
  324.   if ( window != kODNULL )
  325.   {
  326.     HWND   hwndFrame = window->GetPlatformWindow(ev);  //TMW don't use GetClientWindow()
  327.     HWND hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
  328.  
  329.     WinInvalidateRegion(hwndClient, borderShape->GetRegion(ev), TRUE);
  330.  
  331. /*
  332.      ODRect fxRect;
  333.      RECTL upRect;
  334.      borderShape->GetBoundingBox(ev, &fxRect);
  335.      fxRect.AsRECTL(upRect);
  336.        // sometimes 1 or 2 pixel width border is NOT getting erased
  337.        upRect.xLeft -= 2;
  338.        upRect.yBottom -= 2;
  339.        upRect.xRight += 2;
  340.        upRect.yTop += 2;
  341.  
  342.        WinInvalidateRect(hwndClient, &upRect, TRUE);
  343. */
  344.  
  345.  
  346.   }
  347.  
  348. #endif //_PLATFORM_OS2_
  349.  
  350. #ifdef _PLATFORM_MACINTOSH_
  351.   GrafPtr savePort;
  352.  
  353.   ODWindow* window = facet->GetWindow(ev);
  354.   if ( window != kODNULL )
  355.   {
  356.     GetPort(&savePort);
  357.  
  358.     SetPort((GrafPtr)(window->GetRootFacet(ev)->
  359.             GetCanvas(ev)->GetPlatformCanvas(ev, kODQuickDraw)));
  360.     SetOrigin(0,0);
  361.     ClipRect(&(ODQDGlobals.thePort->portRect));
  362.  
  363.     RgnHandle borderRgn = borderShape->GetQDRegion(ev);
  364.     InvalRgn(borderRgn);
  365.  
  366.     SetPort(savePort);
  367.   }
  368. #endif //_PLATFORM_MACINTOSH_
  369. }
  370.  
  371.