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

  1. /* @(#)Z 1.100 com/src/layout/Facet.cpp, odlayout, od96os2, odos29712d 97/03/21 17:18:25 (97/01/30 16:50:51) */
  2.  
  3. //====START_GENERATED_PROLOG======================================
  4. //
  5. //
  6. //   COMPONENT_NAME: odlayout
  7. //
  8. //   CLASSES: none
  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. /*  IBM Change History (most recent first):                            */
  30. /*  <1> 20537 03/25/96  SA   Apple DR4 and common Windows/OS2          */
  31. /***********************************************************************/
  32.  
  33.  
  34. #define ODFacet_Class_Source
  35.  
  36. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_)
  37. #define M_ODFacet_Class_Source
  38.  
  39. #ifndef _ALTPOINT_    // AltPoint.h must be included before ODTypes.h - SA
  40. #include "AltPoint.h"
  41. #endif
  42.  
  43. #include <stdio.h>
  44. #endif // _PLATFORM_OS2 || _PLATFORM_WIN32_
  45.  
  46. #ifdef _PLATFORM_UNIX_
  47. #include "AltPoint.h"
  48. #endif
  49.  
  50. #ifdef _PLATFORM_OS2_
  51. #define INCL_WIN
  52. #define INCL_GPI
  53. #endif  // _PLATFORM_OS2_
  54.  
  55. #ifndef SOM_ODFacet_xih
  56. #define VARIABLE_MACROS
  57. #include <Facet.xih>
  58. #endif
  59.  
  60. #ifdef _PLATFORM_MACINTOSH_    // AltPoint.h must be included before ODTypes.h - SA
  61. #ifndef _ALTPOINT_
  62. #include "AltPoint.h"
  63. #endif
  64. #endif // _PLATFORM_MACINTOSH_
  65.  
  66. #ifndef _FACETNOD_
  67. #include "FacetNod.h"
  68. #endif
  69.  
  70. #ifndef SOM_ODFacetIterator_xh
  71. #include "FacetItr.xh"
  72. #endif
  73.  
  74. #ifndef SOM_ODFrame_xh
  75. #include <Frame.xh>
  76. #endif
  77.  
  78. #ifndef SOM_ODPart_xh
  79. #include <Part.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODCanvas_xh
  83. #include <Canvas.xh>
  84. #endif
  85.  
  86. #ifndef SOM_ODShape_xh
  87. #include <Shape.xh>
  88. #endif
  89.  
  90. #ifndef SOM_ODTransform_xh
  91. #include <Trnsform.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODWindow_xh
  95. #include <Window.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODSession_xh
  99. #include <ODSessn.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODDispatcher_xh
  103. #include <Disptch.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODStorageUnit_xh
  107. #include <StorageU.xh>
  108. #endif
  109.  
  110. #ifndef _LINKLIST_
  111. #include "LinkList.h"
  112. #endif
  113.  
  114. #ifndef _NODE_
  115. #include "Node.h"
  116. #endif
  117.  
  118. #ifndef _EXCEPT_
  119. #include "Except.h"
  120. #endif
  121.  
  122. #ifndef _ODUTILS_
  123. #include <ODUtils.h>
  124. #endif
  125.  
  126. #ifndef _ODTYPES_
  127. #include <ODTypes.h>
  128. #endif
  129.  
  130. #ifndef _ODMEMORY_
  131. #include "ODMemory.h"
  132. #endif
  133.  
  134. #ifndef _ODMATH_
  135. #include "ODMath.h"
  136. #endif
  137.  
  138. #ifdef _PLATFORM_MACINTOSH_
  139. #ifndef _FOCUSLIB_
  140. #include "FocusLib.h"
  141. #endif
  142. #endif // _PLATFORM_MACINTOSH_
  143.  
  144. #ifndef _BIAS_
  145. #include "Bias.h"
  146. #endif
  147.  
  148. #ifndef _BORDER_
  149. #include "Border.h"
  150. #endif
  151.  
  152. #ifndef _ODDEBUG_
  153. #include "ODDebug.h"
  154. #endif
  155.  
  156. #ifndef som_h
  157. #include "som.h"
  158. #endif
  159.  
  160. #ifdef _PLATFORM_MACINTOSH_
  161. #ifndef __PRINTING__
  162. #include <Printing.h>
  163. #endif
  164. #endif   // _PLATFORM_MACINTOSH_
  165.  
  166. #ifndef _TEMPOBJ_
  167. #include "TempObj.h"
  168. #endif
  169.  
  170. #ifdef _PLATFORM_UNIX_
  171. #include <Xm/XmAll.h>
  172. #include <X11/extensions/shape.h>
  173. #include <X11/IntrinsicP.h>
  174. #include <X11/cursorfont.h>
  175.  
  176. #ifndef SOM_ODPlatformCanvas_xh
  177. #include "PlatCanv.xh"
  178. #endif
  179. #ifndef SOM_ODAIXWindowCanvas_xh
  180. #include "AIXWCanv.xh"
  181. #endif
  182. #ifndef SOM_ODAIXStandardCanvas_xh
  183. #include "AIXSCanv.xh"
  184. #endif
  185. #endif // _PLATFORM_UNIX_
  186.  
  187. #ifdef _PLATFORM_WIN32_
  188.  
  189. #ifndef SOM_ODPlatformCanvas_xh
  190. #include "PlatCanv.xh"
  191. #endif
  192. #ifndef SOM_ODWin32WindowCanvas_xh
  193. #include "WinWCanv.xh"
  194. #endif
  195. #ifndef SOM_ODWin32StandardCanvas_xh
  196. #include "WinSCanv.xh"
  197. #endif
  198. #include <qprintf.h>
  199. #endif // _PLATFORM_WIN32_
  200.  
  201. #ifdef  _FACET_TIMING_
  202. #include <qprintf.h>
  203. extern "C"
  204. {
  205. unsigned int RD_TSR();
  206. }
  207. #endif
  208.  
  209.  
  210. #ifdef _PLATFORM_OS2_
  211. #ifndef SOM_ODPlatformCanvas_xh
  212. #include "PlatCanv.xh"
  213. #endif
  214. #ifndef SOM_ODOS2WindowCanvas_xh
  215. #include "OS2WCanv.xh"
  216. #endif
  217. #ifndef SOM_ODOS2StandardCanvas_xh
  218. #include "OS2SCanv.xh"
  219. #endif
  220. #endif // _PLATFORM_OS2_
  221.  
  222. #ifdef _PLATFORM_MACINTOSH_ // CED
  223. #pragma segment ODFacet
  224. #endif // _PLATFORM_MACINTOSH_
  225.  
  226.  
  227. //=====================================================================================
  228. // Constants
  229. //=====================================================================================
  230.  
  231. #define kNoBias kODNULL
  232.  
  233. #ifdef _PLATFORM_UNIX_
  234. #define MOVE_WINDOW_TO_TOP ((Window)-1)
  235. #define MOVE_WINDOW_TO_BOTTOM ((Window)-2)
  236. #endif // UNIX
  237.  
  238. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_)
  239. //==============================================================================
  240. // Global variables
  241. //==============================================================================
  242. #define HWND_MOVE_THE_WINDOW ((HWND)-5)
  243. #define szFacetWinClassName "OpenDoc:FacetWindow"
  244. const char *pszFacetWinClass = szFacetWinClassName;
  245.  
  246. struct FacetWndData {
  247.   ODFacet* facet;                   // Pointer to object for this window
  248.   ODFrame* frame;                   // Pointer to this facet's frame
  249.   ODPart*  part;                    // Pointer to this facet's part
  250.   HWND     hwndClient;
  251. #ifdef _PLATFORM_OS2_
  252.   friend MRESULT EXPENTRY fnwpFacetWindow ( HWND, ULONG, MPARAM, MPARAM);
  253. #endif
  254.  
  255. #ifdef _PLATFORM_WIN32_
  256.   friend LRESULT CALLBACK fnwpFacetWindow (HWND, UINT, WPARAM, LPARAM);
  257. #endif
  258. };
  259.  
  260.  
  261. struct FacetWndCtlData {
  262.   USHORT cb;
  263.   ODFacet* self;
  264. };
  265.  
  266. //#ifdef _UNICODE_
  267. //char szMsg1[Str255];
  268. //#endif
  269.  
  270. #endif // _PLATFORM_OS2_  || _PLATFORM_WIN32_
  271.  
  272. #if (defined _PLATFORM_WIN32_  || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  273. inline static void GetFacetPosition(Environment* ev, ODTransform* trm,
  274.                         ODShape* fshape, ODPoint &offset)
  275. {
  276.     ODTransformType tptype = trm->GetType(ev);
  277.     ODPoint negScale;                   // negative scale
  278.     trm->GetScale(ev, &negScale);
  279.  
  280.     if((tptype == kODLinearTranslateXform) || (tptype == kODLinearXform) ||
  281.         (tptype == kODPerspectiveXform) || (negScale.x < 0) || (negScale.y < 0) )
  282.     {
  283.         trm->TransformShape(ev, fshape);
  284.         ODRect tbound;
  285.         fshape->GetBoundingBox(ev, &tbound);
  286.         offset.x = -tbound.left;
  287. #ifdef _PLATFORM_OS2_
  288.         offset.y = -tbound.bottom;
  289. #endif
  290. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  291.         offset.y = -tbound.top;
  292. #endif
  293.  
  294.     }
  295.     else
  296.          {
  297.             trm->GetOffset(ev, &offset);
  298.             offset.x = -offset.x;
  299.             offset.y = -offset.y;
  300.  
  301.          }
  302.  
  303. }
  304.  
  305. #endif
  306. //=====================================================================================
  307. // ODFacet
  308. //=====================================================================================
  309.  
  310. //------------------------------------------------------------------------------
  311. // ODFacet: somUninit
  312. //------------------------------------------------------------------------------
  313.  
  314. SOM_Scope void  SOMLINK ODFacetsomUninit(ODFacet *somSelf)
  315. {
  316.     ODFacetData *somThis = ODFacetGetData(somSelf);
  317.     ODFacetMethodDebug("ODFacet","somUninit");
  318.  
  319. #ifdef _FACET_DEBUG_
  320.     qprintf("Executing ODFacet::somUninit()\n");
  321. #endif
  322.    ODSafeReleaseObject(_fFrame);
  323.    ODSafeReleaseObject(_fClipShape);
  324.    ODSafeReleaseObject(_fActiveShape);
  325.    ODSafeReleaseObject(_fExternalTransform);
  326.  
  327.    if( _fNode ) {
  328. #ifdef OD_BUG
  329.       if(_fNode->GetParent())
  330. #endif
  331.          _fNode->GetParent()->RemoveChild(*_fNode);
  332.        delete _fNode;
  333.    }
  334.  
  335.    ODSafeReleaseObject(_fAggregateClipShape);
  336.    ODSafeReleaseObject(_fWindowAggregateClipShape);
  337.    ODSafeReleaseObject(_fFrameTransform);
  338.    ODSafeReleaseObject(_fContentTransform);
  339.    ODSafeReleaseObject(_fWindowFrameTransform);
  340.    ODSafeReleaseObject(_fWindowContentTransform);
  341.    ODSafeReleaseObject(_fActiveBorderShape);
  342.  
  343.    Environment* ev = somGetGlobalEnvironment();
  344.  
  345. #ifdef _PLATFORM_OS2_
  346.    if (_fFacetHWND)
  347.    {
  348.      WinDestroyWindow(_fFacetHWND);
  349.    }
  350.    if (_fCanvas)
  351.    {
  352.        ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODPM);
  353.        ODDeleteObject(platCanvas);                  //  delete ODOS2WindowCanvas
  354.        ODDeleteObject(_fCanvas);                    //  delete ODCanvas
  355.    }
  356. #endif // _PLATFORM_OS2_
  357.  
  358. #ifdef _PLATFORM_WIN32_
  359.  
  360.    if(_fUsedShapeRgn != kODNULL)
  361.       DeleteObject(_fUsedShapeRgn);
  362.  
  363.    if(somSelf->GetFacetHWND(ev)) {
  364.       DestroyWindow(somSelf->GetFacetHWND(ev));
  365.    }
  366.    if (_fCanvas)
  367.    {
  368.        ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODWin32);
  369.        ODDeleteObject(platCanvas);             //  delete ODWin32WindowCanvas
  370.        ODDeleteObject(_fCanvas);               //  delete ODCanvas
  371.    }
  372. #endif // _PLATFORM_WIN32_
  373.  
  374. #ifdef _PLATFORM_UNIX_
  375.         if(_fCanvas)
  376.         {
  377.          ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODAIX);
  378.          if (platCanvas->IsInitialized(ev))
  379.          {
  380.              GC gc = ((ODAIXWindowCanvas*)platCanvas)->GetGC(ev);
  381.              XFreeGC(XtDisplay(_fFacetWidget), gc);
  382.          }
  383.          ODDeleteObject(platCanvas);                  //  delete ODAIXWindowCanvas
  384.          ODDeleteObject(_fCanvas);                    //  delete ODCanvas
  385.         }
  386.  
  387.         if(_fActiveBorderWidget)
  388.            XtDestroyWidget(_fActiveBorderWidget);
  389.  
  390.         if(_fFacetWidget)
  391.            XtDestroyWidget(_fFacetWidget);
  392.  
  393. #endif // _PLATFORM_UNIX_
  394.  
  395. //    ODFacet_parents_somUninit(somSelf);
  396. }
  397.  
  398. //------------------------------------------------------------------------------
  399. // ODFacet: InitFacet
  400. //------------------------------------------------------------------------------
  401.  
  402. SOM_Scope void  SOMLINK ODFacetInitFacet(ODFacet *somSelf, Environment *ev,
  403.        ODFrame* frame,
  404.        ODShape* clipShape,
  405.        ODTransform* externalTransform,
  406.        ODCanvas* canvas,
  407.        ODCanvas* biasCanvas)
  408. {
  409.     ODFacetData *somThis = ODFacetGetData(somSelf);
  410.     ODFacetMethodDebug("ODFacet","InitFacet");
  411. #ifdef _FACET_DEBUG_
  412.     qprintf("Executing ODFacet::InitFacet()\n");
  413. #endif
  414.  
  415.    SOM_TRY
  416.  
  417.        if ( frame == kODNULL ) THROW(kODErrIllegalNullFrameInput);
  418.  
  419.        /* Moved from somInit. SOM itself sets fields to zero
  420.        _fFrame = kODNULL;
  421.        _fClipShape = kODNULL;
  422.        _fActiveShape = kODNULL;
  423.        _fExternalTransform = kODNULL;
  424.        _fCanvas = kODNULL;
  425.        _fPartInfo = kODNULL;
  426.        _fIsSelected = kODFalse;
  427.  
  428.        _fNode = kODNULL;
  429.        _fNeedsUpdate = kODFalse;
  430.        _fIsUpdating = kODFalse;
  431.  
  432.        _fAggregateClipShape = kODNULL;
  433.        _fWindowAggregateClipShape = kODNULL;
  434.        _fFrameTransform = kODNULL;
  435.        _fContentTransform = kODNULL;
  436.        _fWindowFrameTransform = kODNULL;
  437.        _fWindowContentTransform = kODNULL;
  438.        _fActiveBorderShape = kODNULL;
  439. #ifdef _PLATFORM_UNIX_
  440.         _fActiveBorderWidget=0;
  441.         _fFacetWidget=0;
  442. #endif // UNIX
  443.        */
  444.        _fHighlight = kODNoHighlight;
  445.  
  446.        somSelf->InitObject(ev);
  447.  
  448.        _fFrame = frame;
  449.        ODAcquireObject(ev, _fFrame);
  450.  
  451.        _fClipShape = BiasShapeSet(ev, clipShape, biasCanvas);
  452.        ODAcquireObject(ev, _fClipShape);
  453.  
  454.        _fExternalTransform = BiasTransformSet(ev, externalTransform, biasCanvas);
  455.        ODAcquireObject(ev, _fExternalTransform);
  456.  
  457. #ifdef _PLATFORM_WIN32_
  458.        _fUsedShapeRgn = kODNULL;  // Used Only in Windows 95 environment
  459. #endif
  460.  
  461.        if ( canvas )
  462.        {
  463.            _fCanvas = canvas;
  464.            _fCanvas->SetFacet(ev, somSelf);
  465.        }
  466.  
  467.        _fNode = new FacetNode(somSelf);    // must be a root facet!
  468.  
  469. #ifdef _PLATFORM_UNIX_
  470.   if(canvas) {
  471.      ODPlatformCanvas* platCanvas = canvas->GetPlatformCanvas(ev, kODAIX);
  472.      if (platCanvas && platCanvas->somIsA(_ODAIXWindowCanvas) && (!platCanvas->IsInitialized(ev))) {
  473.          ODWindow* window = somSelf->GetWindow(ev);
  474.          if(window) {
  475.                 Widget parentWidget= window->GetDrawingAreaWidget(ev);
  476.                 if(parentWidget) {
  477.                   _fFacetWidget = somSelf->CreateFacetWidget(ev, parentWidget, platCanvas);
  478.  
  479.                 }
  480.         }
  481.      }
  482.   }
  483.  
  484. #endif // _PLATFORM_UNIX_
  485.  
  486. #ifdef _PLATFORM_OS2_
  487.   if (canvas) {
  488.      ODPlatformCanvas* platCanvas = canvas->GetPlatformCanvas(ev, kODPM);
  489.      if (platCanvas && platCanvas->somIsA(_ODOS2WindowCanvas) && (!platCanvas->IsInitialized(ev))) {
  490.         ODWindow* window = somSelf->GetWindow(ev);
  491.         if (window) {
  492.            HWND hwndParent = WinWindowFromID(window->GetPlatformWindow(ev), FID_CLIENT);
  493.            if ( hwndParent ) {
  494.               // Register facet window class
  495.                   CLASSINFO clsi;
  496.                   HAB hab = WinQueryAnchorBlock(HWND_DESKTOP);
  497.                   if (!WinQueryClassInfo( hab, pszFacetWinClass, &clsi))
  498.                   {
  499.                        WinRegisterClass( hab,
  500.                                            pszFacetWinClass,
  501.                                            (PFNWP)fnwpFacetWindow,
  502.                                            CS_HITTEST,   /* | CS_PARENTCLIP,*/
  503.                                            NUM_FACETWINDOWDATAWORDS * sizeof(ULONG));
  504.                   }
  505.  
  506.                 HWND facetHWND = somSelf->CreateFacetWindow(ev, hwndParent);
  507.                 ((ODOS2WindowCanvas*)platCanvas)->InitPlatformWindowCanvas(ev, facetHWND);
  508.            }
  509.         }
  510.       }
  511.    }
  512. #endif // _PLATFORM_OS2_
  513.  
  514. #ifdef _PLATFORM_WIN32_
  515.     if (canvas) {
  516.       ODPlatformCanvas* platCanvas = canvas->GetPlatformCanvas(ev, kODWin32);
  517.       if (platCanvas && platCanvas->somIsA(_ODWin32WindowCanvas) && (!platCanvas->IsInitialized(ev))) {
  518.           ODWindow* window = somSelf->GetWindow(ev);
  519.         if (window) {
  520.            HWND hwndParent = window->GetPlatformWindow(ev);
  521.            if ( hwndParent ) {
  522.  
  523.                HINSTANCE hInst = (HINSTANCE)GetWindowLong(hwndParent, GWL_HINSTANCE);
  524.                WNDCLASS theWndCls;
  525.               // check whether this class is already registered?
  526.               if(!GetClassInfo(hInst, pszFacetWinClass, &theWndCls)) {
  527.                 WNDCLASS  wc;
  528.  
  529.                 wc.style                = 0;
  530.                 wc.lpfnWndProc          = fnwpFacetWindow;
  531.                 wc.cbClsExtra           = 0;
  532.                 wc.cbWndExtra           = NUM_FACETWINDOWDATAWORDS * sizeof(ULONG);
  533.                 wc.hInstance            = hInst;
  534.                 wc.hIcon                = NULL;
  535.                 wc.hCursor              = LoadCursor(NULL,IDC_ARROW);
  536.                 wc.hbrBackground        = (HBRUSH)kODNULL;
  537.                 wc.lpszMenuName         = NULL;
  538.                 wc.lpszClassName        = pszFacetWinClass;
  539.  
  540.                 if (!RegisterClass(&wc)) {
  541.                      THROW(kODErrUndefined);
  542.                 }
  543.                }  // GetClassInfo()
  544.  
  545.                  HWND facetHWND = somSelf->CreateFacetWindow(ev, hwndParent);
  546.                  ((ODWin32WindowCanvas*)platCanvas)->InitPlatformWindowCanvas(ev, facetHWND);
  547.            }  // hwndParent
  548.         }   // window
  549.       }   // platCanvas
  550.    }     // canvas
  551. #endif // _PLATFORM_WIN32_
  552.    SOM_CATCH_ALL
  553.    SOM_ENDTRY
  554. }
  555.  
  556. //------------------------------------------------------------------------------
  557. // ODFacet: InitChildFacet
  558. //------------------------------------------------------------------------------
  559.  
  560. SOM_Scope void  SOMLINK ODFacetInitChildFacet(ODFacet *somSelf, Environment *ev,
  561.        FacetNode* node,
  562.        ODFrame* frame,
  563.        ODShape* clipShape,
  564.        ODTransform* externalTransform,
  565.        ODCanvas* canvas,
  566.        ODCanvas* biasCanvas)
  567. {
  568.     ODFacetData *somThis = ODFacetGetData(somSelf);
  569.     ODFacetMethodDebug("ODFacet","InitChildFacet");
  570.  
  571. #ifdef _FACET_DEBUG_
  572.     qprintf("Executing ODFacet::InitChildFacet()\n");
  573. #endif
  574.    SOM_TRY
  575.  
  576.        if ( node == kODNULL ) THROW(kODErrIllegalNullFacetInput);
  577.        if ( frame == kODNULL ) THROW(kODErrIllegalNullFrameInput);
  578.  
  579.        /* Moved from somInit. SOM itself sets fields to zero
  580.        _fFrame = kODNULL;
  581.        _fClipShape = kODNULL;
  582.        _fActiveShape = kODNULL;
  583.        _fExternalTransform = kODNULL;
  584.        _fCanvas = kODNULL;
  585.        _fPartInfo = kODNULL;
  586.        _fIsSelected = kODFalse;
  587.  
  588.        _fNode = kODNULL;
  589.        _fNeedsUpdate = kODFalse;
  590.        _fIsUpdating = kODFalse;
  591.  
  592.        _fAggregateClipShape = kODNULL;
  593.        _fWindowAggregateClipShape = kODNULL;
  594.        _fFrameTransform = kODNULL;
  595.        _fContentTransform = kODNULL;
  596.        _fWindowFrameTransform = kODNULL;
  597.        _fWindowContentTransform = kODNULL;
  598.        _fActiveBorderShape = kODNULL;
  599.        */
  600.        _fNode = node;
  601.  
  602.        _fHighlight = kODNoHighlight;
  603.        somSelf->InitObject(ev);
  604.  
  605.        _fFrame = frame;
  606.        ODAcquireObject(ev, _fFrame);
  607.  
  608.        _fClipShape = BiasShapeSet(ev, clipShape, biasCanvas);
  609.        ODAcquireObject(ev, _fClipShape);
  610.  
  611.        _fExternalTransform = BiasTransformSet(ev, externalTransform, biasCanvas);
  612.        ODAcquireObject(ev, _fExternalTransform);
  613.  
  614.        if ( canvas )
  615.        {
  616.            _fCanvas = canvas;
  617.            _fCanvas->SetFacet(ev, somSelf);
  618.        }
  619. #ifdef _PLATFORM_WIN32_
  620.        _fUsedShapeRgn = kODNULL;
  621. #endif
  622.  
  623.  
  624.    SOM_CATCH_ALL
  625.    SOM_ENDTRY
  626. }
  627.  
  628.  
  629. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_)
  630. SOM_Scope ODPlatformWindow  SOMLINK ODFacetGetFacetHWND(ODFacet *somSelf,
  631.                                                                    Environment *ev)
  632. {
  633.     ODFacetData *somThis = ODFacetGetData(somSelf);
  634.     ODFacetMethodDebug("ODFacet","ODFacetGetFacetHWND");
  635.  
  636. #ifdef _FACET_DEBUG_
  637.     qprintf("Executing ODFacet::GetFacetHWND()\n");
  638. #endif
  639.  
  640. #ifdef _PLATFORM_OS2_
  641.        return _fFacetHWND;
  642. #endif  // _PLATFORM_OS2_
  643.  
  644. #ifdef _PLATFORM_WIN32_
  645.     ODPlatformWindow winHWND=kODNULL;
  646.  
  647.     if(_fCanvas && _fCanvas->GetPlatformCanvas(ev, kODWin32)->somIsA(_ODWin32WindowCanvas))
  648.     {
  649.        ODWin32WindowCanvas* winCanvas = (ODWin32WindowCanvas*) (_fCanvas->GetPlatformCanvas(ev, kODWin32));
  650.  
  651.        if(winCanvas->IsInitialized(ev))
  652.           winHWND = winCanvas->GetWindow(ev);
  653.     }
  654.  
  655.     return winHWND;
  656. #endif // _PLATFORM_WIN32_
  657.  
  658.  
  659. }
  660. #endif // _PLATFORM_OS2_ || _PLATFORM_WIN32_
  661.  
  662. #ifdef _PLATFORM_WIN32_
  663. //------------------------------------------------------------------------------
  664. // ODFacet: CreateWin32StandardCanvas
  665. //------------------------------------------------------------------------------
  666.  
  667. SOM_Scope ODWin32StandardCanvas*  SOMLINK ODFacetCreatePlatformCanvas(ODFacet *somSelf, Environment *ev,
  668.     HDC hdc)
  669. {
  670.     ODFacetData *somThis = ODFacetGetData(somSelf);
  671.     ODFacetMethodDebug("ODFacet","CreatePlatformCanvas");
  672.  
  673. #ifdef _FACET_DEBUG_
  674.     qprintf("Executing ODFacet::CreatePlatformCanvas()\n");
  675. #endif
  676.  
  677.     ODWin32StandardCanvas *c = kODNULL;  ODVolatile(c);
  678.  
  679.     SOM_TRY
  680.  
  681.     c = new ODWin32StandardCanvas;
  682.     THROW_IF_NULL(c);
  683.     c->InitPlatformCanvas(ev, hdc);
  684.  
  685.     return c;
  686.     SOM_CATCH_ALL{
  687.       ODDeleteObject(c);
  688.       return kODNULL;
  689.     }
  690.     SOM_ENDTRY
  691. }
  692. #endif // _PLATFORM_WIN32_
  693.  
  694. #ifdef _PLATFORM_UNIX_
  695. //------------------------------------------------------------------------------
  696. // ODFacet: CreateODAIXStandardCanvas
  697. //------------------------------------------------------------------------------
  698.  
  699. SOM_Scope ODAIXStandardCanvas*  SOMLINK ODFacetCreatePlatformCanvas(ODFacet *somSelf, Environment *ev,
  700.     Display *display,
  701.     Pixmap   pixmap,
  702.     GC       gc      )
  703. {
  704.     ODFacetData *somThis = ODFacetGetData(somSelf);
  705.     ODFacetMethodDebug("ODFacet","CreatePlatformCanvas");
  706.  
  707. #ifdef _FACET_DEBUG_
  708.     qprintf("Executing ODFacet::CreatePlatformCanvas()\n");
  709. #endif
  710.  
  711.     ODAIXStandardCanvas *c = kODNULL;  ODVolatile(c);
  712.  
  713.     SOM_TRY
  714.  
  715.     c = new ODAIXStandardCanvas;
  716.     THROW_IF_NULL(c);
  717.     c->InitPlatformCanvas(ev, display, pixmap, gc);
  718.  
  719.     return c;
  720.     SOM_CATCH_ALL{
  721.       ODDeleteObject(c);
  722.       return kODNULL;
  723.     }
  724.     SOM_ENDTRY
  725. }
  726.  
  727. SOM_Scope Widget  SOMLINK ODFacetGetFacetWidget(ODFacet *somSelf,
  728.                                                    Environment *ev)
  729. {
  730.  
  731.     ODFacetData *somThis = ODFacetGetData(somSelf);
  732.     ODFacetMethodDebug("ODFacet","ODFacetGetFacetWidget");
  733.  
  734.     return _fFacetWidget;
  735. }
  736.  
  737. SOM_Scope void  SOMLINK ODFacetSetFacetWidgetWinPos(ODFacet *somSelf,
  738.                                                     Environment *ev,
  739.                                                     Window childwindow,
  740.                                                     Window siblingwindow,
  741.                                                     ODBoolean MoveBeforeSibling)
  742. {
  743.     ODFacetData *somThis = ODFacetGetData(somSelf);
  744.     ODFacetMethodDebug("ODFacet","ODFacetSetFacetWidgetWinPos");
  745.  
  746.     if(siblingwindow == MOVE_WINDOW_TO_TOP)
  747.        XRaiseWindow(XtDisplay(_fFacetWidget), childwindow);
  748.  
  749.     if(siblingwindow == MOVE_WINDOW_TO_BOTTOM)
  750.        XLowerWindow(XtDisplay(_fFacetWidget), childwindow);
  751.  
  752.  
  753.     if((siblingwindow != MOVE_WINDOW_TO_TOP) &&
  754.         (siblingwindow != MOVE_WINDOW_TO_BOTTOM) && siblingwindow)
  755.     {
  756.                 ODFacet* parentFacet=somSelf->GetContainingFacet(ev);
  757.                 if(parentFacet)
  758.                 {
  759.                   Widget parentwidget = parentFacet->GetFacetWidget(ev);
  760.                   Window root, parent;
  761.                   Window *children;
  762.                   unsigned int num_children;
  763.                   Status rc;
  764.  
  765.                   rc = XQueryTree(XtDisplay(parentwidget),
  766.                                   XtWindow(parentwidget),
  767.                                   &root,
  768.                                   &parent,
  769.                                   &children,
  770.                                   &num_children);
  771.                   if(num_children > 1)
  772.                   {
  773.  
  774.                     Window *windows = new Window[num_children];
  775.                     Window *tpwindows = new Window[num_children-1];
  776.                     int index = num_children-1;
  777.                     int i=0;
  778.  
  779.                     for(; index >= 0 ; index--)
  780.                     {
  781.                         if(children[index] != childwindow)
  782.                            tpwindows[i++] = children[index];
  783.                     }
  784.  
  785.                     int j=0;
  786.                     index = num_children - 1;
  787.                     i = 0;
  788.  
  789.                     for(; index > 0 ; index--)
  790.                     {
  791.                      if(siblingwindow == tpwindows[j])
  792.                      {
  793.                         if(MoveBeforeSibling)
  794.                         {
  795.                            windows[i++] = childwindow;
  796.                            windows[i++] = tpwindows[j++];
  797.                         }
  798.                         else {  // Move behind the sibling window
  799.                               windows[i++] = tpwindows[j++];
  800.                               windows[i++] = childwindow;
  801.                         }
  802.  
  803.                      }
  804.                      else
  805.                          windows[i++] = tpwindows[j++];
  806.  
  807.                     } // for loop
  808.  
  809.                     XRestackWindows(XtDisplay(parentwidget),
  810.                                   windows,
  811.                                   num_children);
  812.                     XFree(windows);
  813.                     XFree(tpwindows);
  814.  
  815.                   }  // num_children > 1
  816.  
  817.                   XFree(children);
  818.  
  819.                 } // if parent facet exists
  820.  
  821.  
  822.     }  // if child window should be inserted in the existing windows
  823.  
  824. }
  825.  
  826.  
  827. SOM_Scope void  SOMLINK ODFacetSetFacetWidgetSize(ODFacet *somSelf, Environment *ev)
  828. {
  829.     ODFacetData *somThis = ODFacetGetData(somSelf);
  830.     ODFacetMethodDebug("ODFacet","ODFacetSetFacetWidgetSize");
  831.  
  832.     Dimension offsetx, offsety;
  833.     Dimension lWidth, lHeight;
  834.     lWidth =0; lHeight = 0;
  835.  
  836.  
  837.          TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  838.          ODRect RectBounds;
  839.  
  840.          TempODShape bShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  841.          bShape->Transform(ev, xform);
  842.          bShape->GetBoundingBox(ev, &RectBounds);
  843.  
  844.          Point childPt2 = {FixedToInt(RectBounds.left), FixedToInt(RectBounds.top)};
  845.          lWidth  = FixedToInt(RectBounds.right) - childPt2.x;
  846.          lHeight = FixedToInt(RectBounds.bottom) - childPt2.y;
  847.  
  848.          ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  849.          if(parentFacet)
  850.          {
  851.            TempODTransform x2form = parentFacet->AcquireWindowFrameTransform(ev, kODNULL);
  852.  
  853.            ODPoint ParentPt1(0,0);
  854.            TempODShape FrameShape = ODCopyAndRelease(ev,  parentFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL));
  855.            GetFacetPosition(ev, x2form, FrameShape, ParentPt1);
  856.  
  857.            Point ParentPt2 = ParentPt1.AsXPoint();
  858.  
  859.            childPt2.x += ParentPt2.x;
  860.            childPt2.y += ParentPt2.y;
  861.  
  862.            Dimension parentWidth, parentHeight;
  863.            XtVaGetValues(parentFacet->GetFacetWidget(ev),
  864.                           XmNwidth, &parentWidth,
  865.                           XmNheight, &parentHeight,
  866.                           NULL);
  867.  
  868.            if(parentWidth < (childPt2.x + lWidth))
  869.                 lWidth = parentWidth - childPt2.x;
  870.  
  871.            if(parentHeight < (childPt2.y + lHeight))
  872.                 lHeight = parentHeight - childPt2.y;
  873.          }
  874.  
  875.          // Move and position the window
  876.  
  877.            XtVaSetValues( _fFacetWidget,
  878.                           XmNwidth, lWidth,
  879.                           XmNheight, lHeight,
  880.                           XmNx, childPt2.x,
  881.                           XmNy, childPt2.y,
  882.                           XmNmarginWidth, 0,
  883.                           XmNmarginHeight, 0,
  884.                           XmNresizePolicy, XmRESIZE_NONE,
  885.                           NULL);
  886.  
  887.          if(_fClipShape)
  888.          {
  889.            // If the window has a region
  890.            if (_fIsRegionSet)
  891.            {
  892.              // Current design is once a facet window region, always a facet window region.
  893.              // A possible enhancement would be to delete the facet window
  894.              // region if the facet's clipshape and frame's usedshape become the same as the
  895.              // rectangular frameshape. An example is a toggle between a round analog
  896.              // and a rectangular digital clock.
  897.              somSelf->SetFacetWidgetRegion(ev, kODFalse);
  898.            }
  899.            else
  900.            {
  901.              // If the transformed clipshape is not rectangular or is different than the
  902.              // transform frame shape
  903.              TempODShape clipShape = _fClipShape->Copy(ev);
  904.              clipShape->Transform(ev, xform);
  905.              if( (!clipShape->IsRectangular(ev)) || (!clipShape->IsSameAs(ev, bShape)) )
  906.              {
  907.                // We've gone down the road where this facet window will now always have a
  908.                // region associated with it.
  909.                somSelf->SetFacetWidgetRegion(ev, kODFalse);
  910.              }
  911.            }
  912.          }
  913. }
  914.  
  915.  
  916. SOM_Scope void  SOMLINK ODFacetSetFacetWidgetRegion(ODFacet *somSelf,
  917.                                                     Environment *ev,
  918.                                                     ODBoolean IsUsedShape)
  919. {
  920.     ODFacetData *somThis = ODFacetGetData(somSelf);
  921.     ODFacetMethodDebug("ODFacet","ODFacetSetFacetWidgetRegion");
  922.  
  923.     TempODShape UShape = ODCopyAndRelease(ev, somSelf->GetFrame(ev)->AcquireUsedShape(ev, kNoBias));
  924.  
  925.     if(!IsUsedShape)
  926.     {
  927.        TempODShape clipShape = ODCopyAndRelease(ev, somSelf->AcquireClipShape(ev, kNoBias));
  928.        UShape->Intersect(ev, clipShape);
  929.     }
  930.  
  931.       if(UShape)
  932.       {
  933.        somSelf->Invalidate(ev, kODNULL, kODNULL);
  934.        TempODTransform xform =  somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  935.  
  936.        UShape->Transform(ev, xform);
  937.        ODPoint offset(0,0);
  938.        TempODShape FrameShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  939.        GetFacetPosition(ev, xform, FrameShape, offset);
  940.  
  941.        Point Pt2 = offset.AsXPoint();
  942.  
  943.  
  944.        //On NT & OS2 -> ODRgnHandle UShapeRgn = UShape->GetRegion(ev);
  945.        // get the shape's XRegion and modify XWindow to match with it
  946.        ODPlatformShape UsedShapeRegion =  UShape->GetPlatformShape(ev, kODAIX);
  947.  
  948.        XOffsetRegion((Region)UsedShapeRegion, Pt2.x, Pt2.y);
  949.  
  950.        XShapeCombineRegion(XtDisplay(_fFacetWidget),
  951.                            XtWindow(_fFacetWidget),
  952.                            ShapeBounding,
  953.                            0, 0,
  954.                            (Region)UsedShapeRegion,
  955.                            ShapeSet);
  956.  
  957.        _fIsRegionSet = kODTrue; // Set region flag
  958.       }
  959.  
  960. }
  961.  
  962.  
  963.  
  964. SOM_Scope Widget  SOMLINK ODFacetCreateFacetWidget(ODFacet *somSelf,
  965.                                                    Environment *ev,
  966.                                                    Widget parentWidget,
  967.                                                    ODPlatformCanvas* platformCanvas)
  968. {
  969.  
  970.     ODFacetData *somThis = ODFacetGetData(somSelf);
  971.     ODFacetMethodDebug("ODFacet","ODFacetCreateFacetWidget");
  972.  
  973. #ifdef _FACET_DEBUG_
  974.     qprintf("Executing ODFacet::CreateFacetWidget()\n");
  975. #endif
  976.  
  977.    Dimension offsetx, offsety;
  978.    Dimension lWidth, lHeight;
  979.    lWidth =0; lHeight=0;
  980.    offsetx=0; offsety=0;
  981.  
  982.           // Initialize region flag.  This can't be done in the facet's somInit.
  983.           // This has to be done every time a facet widget is created since a
  984.           // facet can have a widget, lose it (due to a ChangeCanvas) and get a widget again.
  985.           _fIsRegionSet = kODFalse;
  986.  
  987.           TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  988.           ODRect RectBounds;
  989.  
  990.           TempODShape bShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  991.           bShape->Transform(ev, xform);
  992.           bShape->GetBoundingBox(ev, &RectBounds);
  993.  
  994.           Point Pt2 = {FixedToInt(RectBounds.left), FixedToInt(RectBounds.top)};
  995.           lWidth  = FixedToInt(RectBounds.right) - Pt2.x;
  996.           lHeight = FixedToInt(RectBounds.bottom) - Pt2.y;
  997.  
  998.           offsetx = Pt2.x;
  999.           offsety = Pt2.y;
  1000.  
  1001.          ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  1002.          if(parentFacet)
  1003.          {
  1004.            TempODTransform x2form = parentFacet->AcquireWindowFrameTransform(ev, kODNULL);
  1005.  
  1006.            ODPoint ParentPt1(0,0);
  1007.            TempODShape FrameShape = ODCopyAndRelease(ev,  parentFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL));
  1008.            GetFacetPosition(ev, x2form, FrameShape, ParentPt1);
  1009.            Point ParentPt2 = ParentPt1.AsXPoint();
  1010.  
  1011.            offsetx += ParentPt2.x;
  1012.            offsety += ParentPt2.y;
  1013.           }
  1014.  
  1015.  
  1016.           Widget newWidget = XtVaCreateManagedWidget("FacetWidget",
  1017.                                 xmDrawingAreaWidgetClass,
  1018.                                 parentWidget,
  1019.                                 XmNwidth, lWidth,
  1020.                                 XmNheight, lHeight,
  1021.                                 XmNx, offsetx,
  1022.                                 XmNy, offsety,
  1023.                                 XmNmarginWidth, 0,
  1024.                                 XmNmarginHeight, 0,
  1025.                                 XmNresizePolicy, XmRESIZE_NONE,
  1026.                                 NULL);
  1027.  
  1028.           XtRealizeWidget(newWidget);
  1029.  
  1030.           Display *display = XtDisplay(newWidget);
  1031.           Window facetWindow = XtWindow(newWidget);
  1032.           GC facetGC = XCreateGC(display, facetWindow, 0, 0);
  1033.  
  1034.  
  1035.           ((ODAIXWindowCanvas*)platformCanvas)->InitPlatformWindowCanvas(ev, display, facetWindow, newWidget, facetGC);
  1036.  
  1037.           return newWidget;
  1038.  
  1039. }
  1040.  
  1041. SOM_Scope void  SOMLINK ODFacetCreateActiveBorderWidget(ODFacet *somSelf,
  1042.                                                         Environment *ev)
  1043. {
  1044.  
  1045.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1046.     ODFacetMethodDebug("ODFacet","ODFacetCreateActiveBorderWidget");
  1047.  
  1048.     Pixel fg, bg;
  1049.     XSetWindowAttributes winatt;
  1050.  
  1051.     // root facet should not draw active border
  1052.     ODFrame* frame = somSelf->GetFrame(ev);
  1053.  
  1054.     if (!frame) return;
  1055.  
  1056.     ODWindow* window = somSelf->GetWindow(ev);
  1057.     if ( !(frame->IsRoot(ev)) && (!_fActiveBorderWidget) && window)
  1058.     {
  1059.         ODRect RectBounds;
  1060.         _fActiveBorderShape->GetBoundingBox(ev, &RectBounds);
  1061.         Rect XRect;
  1062.         RectBounds.AsXRect(XRect);
  1063.  
  1064.         Widget parentWidget= window->GetDrawingAreaWidget(ev);
  1065.  
  1066.         //ODFacet* parentFacet=somSelf->GetContainingFacet(ev);
  1067.         //Widget parentWidget = parentFacet->GetFacetWidget(ev);
  1068.  
  1069.         _fActiveBorderWidget = XtVaCreateManagedWidget(
  1070.                                 "ActiveBorder",
  1071.                                 xmDrawingAreaWidgetClass,
  1072.                                 parentWidget,
  1073.                                 XmNx, XRect.x,
  1074.                                 XmNy, XRect.y,
  1075.                                 XmNwidth, XRect.width,
  1076.                                 XmNheight, XRect.height,
  1077.                                 XmNmarginWidth, 0,
  1078.                                 XmNmarginHeight, 0,
  1079.                                 XmNresizePolicy, XmRESIZE_NONE,
  1080.                                 XmNmappedWhenManaged, False,
  1081.                                 XtVaTypedArg, XmNbackground,
  1082.                                                 XmRString, "black",4,
  1083.                                 XtVaTypedArg, XmNforeground,
  1084.                                                 XmRString, "white",6,
  1085.                                 NULL);
  1086.  
  1087.         // create slanted line pixmap on active border
  1088.         XtVaGetValues(_fActiveBorderWidget,
  1089.                         XmNbackground, &bg,
  1090.                         XmNforeground, &fg,
  1091.                         NULL);
  1092.         Pixmap slantedPix = XmGetPixmap(XtScreen(parentWidget),
  1093.                                         "slant_right", fg, bg);
  1094.         XtVaSetValues(_fActiveBorderWidget,
  1095.                         XmNbackgroundPixmap, slantedPix,
  1096.                         NULL);
  1097.  
  1098.  
  1099.         // set the mouse cursor when over the active border
  1100.         winatt.cursor = XCreateFontCursor(XtDisplay(parentWidget), XC_draped_box);
  1101.         XChangeWindowAttributes(XtDisplay(parentWidget), XtWindow(_fActiveBorderWidget), CWCursor, &winatt);
  1102.     }
  1103.  
  1104. }
  1105.  
  1106.  
  1107.  
  1108. SOM_Scope ODBoolean  SOMLINK ODFacetIsEventInActiveBorder(ODFacet *somSelf,
  1109.                                                           Environment *ev,
  1110.                                                           ODEventData* event)
  1111. {
  1112.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1113.     ODFacetMethodDebug("ODFacet","ODFacetIsEventInActiveBorder");
  1114.  
  1115.         if (!event)
  1116.              return kODFalse;
  1117.  
  1118.         if ( (Window)event->window == XtWindow(_fActiveBorderWidget) )
  1119.               return kODTrue;
  1120.         else
  1121.               return kODFalse;
  1122. }
  1123.  
  1124. #endif // _PLATFORM_UNIX_
  1125.  
  1126.  
  1127. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_)
  1128. SOM_Scope HWND  SOMLINK ODFacetCreateFacetWindow(ODFacet *somSelf,
  1129.                                                  Environment *ev,
  1130.                                                  HWND parentHWND)
  1131. {
  1132.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1133.     ODFacetMethodDebug("ODFacet","ODFacetCreateFacetWindow");
  1134.  
  1135. #ifdef _FACET_DEBUG_
  1136.     qprintf("Executing ODFacet::CreateFacetWindow()\n");
  1137. #endif
  1138.       FacetWndCtlData ctlData;
  1139.       ctlData.cb = sizeof(ctlData);
  1140.       ctlData.self = somSelf;
  1141. #ifdef _EVERYTHING_IS_A_WINDOW_
  1142.        // Initialize region flag.  This can't be done in the facet's somInit.
  1143.        // This has to be done every time a facet window is created since a
  1144.        // facet can have a window, lose it (due to a ChangeCanvas) and get a window again.
  1145.        _fIsRegionSet = kODFalse;
  1146.  
  1147.        ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  1148.        if(parentFacet)
  1149.           parentHWND = parentFacet->GetFacetHWND(ev);
  1150. #endif
  1151.  
  1152. #ifdef _PLATFORM_WIN32_
  1153.       int offsetx, offsety;
  1154. #endif  // _PLATFORM_WIN32_
  1155.  
  1156. #ifdef _PLATFORM_OS2_
  1157.       LONG offsetx, offsety;
  1158. #endif  // _PLATFORM_OS2_
  1159.  
  1160.    ODULong lWidth, lHeight;
  1161.    lWidth =0; lHeight = 0;
  1162.  
  1163.           TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  1164.           ODRect RectBounds;
  1165.  
  1166.   //        TempODShape bShape = _fClipShape->Copy(ev);
  1167.           TempODShape bShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  1168.           bShape->Transform(ev, xform);
  1169.           bShape->GetBoundingBox(ev, &RectBounds);
  1170.  
  1171.  
  1172. #ifdef _PLATFORM_WIN32_
  1173.           Point Pt2;
  1174.           RECT RectShape;
  1175.           RectBounds.AsWinRect(RectShape);
  1176.           Pt2.x   = RectShape.left;
  1177.           Pt2.y   = RectShape.top;
  1178.           lWidth  = RectShape.right  - Pt2.x;
  1179.           lHeight = RectShape.bottom - Pt2.y;
  1180.  
  1181.           offsetx = Pt2.x;
  1182.           offsety = Pt2.y;
  1183. #endif // _PLATFORM_WIN32_
  1184.  
  1185. #ifdef _PLATFORM_OS2_
  1186.          POINTL Ptl ;
  1187.          RECTL RectLShape;
  1188.          RectBounds.AsRECTL(RectLShape);
  1189.          Ptl.x = RectLShape.xLeft;
  1190.          Ptl.y = RectLShape.yBottom;
  1191.          lWidth = RectLShape.xRight - Ptl.x;
  1192.          lHeight = RectLShape.yTop - Ptl.y;
  1193.  
  1194.          offsetx = Ptl.x;
  1195.          offsety = Ptl.y;
  1196.          PRINT("TESTING x =%d\t y=%d\n", offsetx, offsety);
  1197. #endif  // _PLATFORM_OS2_
  1198.  
  1199.  
  1200. #ifdef _PLATFORM_OS2_
  1201.  
  1202.     ULONG flStyle = WS_VISIBLE;
  1203.  
  1204.     HWND facetHWND = WinCreateWindow(
  1205.                                 parentHWND,
  1206.                                 pszFacetWinClass,
  1207.                                 "",
  1208.                                 flStyle,
  1209.                                 offsetx,
  1210.                                 offsety,
  1211.                                 lWidth,
  1212.                                 lHeight,
  1213.                                 0,
  1214.                                 HWND_BOTTOM,
  1215.                                 0,
  1216.                                 (PVOID)&ctlData,
  1217.                                 NULL );
  1218.     if (!facetHWND) {
  1219.         THROW(kODErrCannotCreateWindow);
  1220.     }
  1221.  
  1222.     _fFacetHWND = facetHWND;
  1223. #endif // _PLATFORM_OS2_
  1224.  
  1225. #ifdef _PLATFORM_WIN32_
  1226.  
  1227. #ifdef _EVERYTHING_IS_A_WINDOW_
  1228.       DWORD dwStyle = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  1229. #else
  1230.       DWORD dwStyle = WS_CHILDWINDOW | WS_VISIBLE;
  1231. #endif
  1232.  
  1233.       HINSTANCE hInstance = (HINSTANCE)GetWindowLong(parentHWND, GWL_HINSTANCE);
  1234.  
  1235.       HWND facetHWND = CreateWindow(pszFacetWinClass,
  1236.                                     "",
  1237.                                     dwStyle,
  1238.                                     offsetx,
  1239.                                     offsety,
  1240.                                     lWidth,
  1241.                                     lHeight,
  1242.                                     parentHWND,
  1243.                                     NULL,
  1244.                                     hInstance,
  1245.                                     (LPVOID)&ctlData);
  1246.  
  1247.  
  1248.     if (!facetHWND) {
  1249.         THROW(kODErrCannotCreateWindow);
  1250.     }
  1251.  
  1252.  
  1253. #endif // _PLATFORM_WIN32_
  1254.  
  1255.    return facetHWND;
  1256. }
  1257.  
  1258. #endif // _PLATFORM_OS2_ || _PLATFORM_WIN32_
  1259.  
  1260.  
  1261. #ifdef _PLATFORM_OS2_
  1262. //------------------------------------------------------------------------------
  1263. // ODFacet: CreateOS2Canvas
  1264. //------------------------------------------------------------------------------
  1265.  
  1266. SOM_Scope ODOS2StandardCanvas*  SOMLINK ODFacetCreatePlatformCanvas(ODFacet *somSelf, Environment *ev,
  1267.     HPS hps)
  1268. {
  1269.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1270.     ODFacetMethodDebug("ODFacet","CreatePlatformCanvas");
  1271.  
  1272. #ifdef _FACET_DEBUG_
  1273.     qprintf("Executing ODFacet::CreatePlatformCanvas()\n");
  1274. #endif
  1275.  
  1276.     ODOS2StandardCanvas *c = kODNULL;  ODVolatile(c);
  1277.  
  1278.     SOM_TRY
  1279.  
  1280.     c = new ODOS2StandardCanvas;
  1281.     THROW_IF_NULL(c);
  1282.     c->InitPlatformCanvas(ev, hps);
  1283.  
  1284.     return c;
  1285.     SOM_CATCH_ALL{
  1286.       ODDeleteObject(c);
  1287.       return kODNULL;
  1288.     }
  1289.     SOM_ENDTRY
  1290. }
  1291.  
  1292. #endif // _PLATFORM_OS2_
  1293.  
  1294. //------------------------------------------------------------------------------
  1295. // ODFacet: Purge
  1296. //------------------------------------------------------------------------------
  1297.  
  1298. SOM_Scope ODSize  SOMLINK ODFacetPurge(ODFacet *somSelf, Environment *ev,
  1299.        ODSize size)
  1300. {
  1301.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1302.     ODFacetMethodDebug("ODFacet","Purge");
  1303.  
  1304. #ifdef _FACET_DEBUG_
  1305.     qprintf("Executing ODFacet::Purge()\n");
  1306. #endif
  1307.    ODSize freed = 0;   ODVolatile(freed);
  1308.  
  1309.    SOM_TRY
  1310.        // purge non-computed objects
  1311.        if ( _fCanvas )             freed += _fCanvas->Purge(ev, size-freed);  // Canvas didn't override Purge(), so no-op
  1312.        if ( _fClipShape )          freed += _fClipShape->Purge(ev, size-freed);
  1313.        if ( _fActiveShape )        freed += _fActiveShape->Purge(ev, size-freed);
  1314.        if ( _fExternalTransform )  freed += _fExternalTransform->Purge(ev, size-freed);
  1315.        if ( _fActiveBorderShape )  freed += _fActiveBorderShape->Purge(ev, size-freed);
  1316.  
  1317.        // flush cached geometry, purging first if other owners
  1318.        if ( _fAggregateClipShape )
  1319.        {
  1320.            if ( _fAggregateClipShape->GetRefCount(ev) > 1 )
  1321.                freed += _fAggregateClipShape->Purge(ev, size-freed);
  1322.            ODReleaseObject(ev, _fAggregateClipShape);
  1323.        }
  1324.  
  1325.        if ( _fWindowAggregateClipShape )
  1326.        {
  1327.            if ( _fWindowAggregateClipShape->GetRefCount(ev) > 1 )
  1328.                freed += _fWindowAggregateClipShape->Purge(ev, size-freed);
  1329.            ODReleaseObject(ev, _fWindowAggregateClipShape);
  1330.        }
  1331.  
  1332.        if ( _fFrameTransform )
  1333.        {
  1334.            if ( _fFrameTransform->GetRefCount(ev) > 1 )
  1335.                freed += _fFrameTransform->Purge(ev, size-freed);
  1336.            ODReleaseObject(ev, _fFrameTransform);
  1337.        }
  1338.  
  1339.        if ( _fContentTransform )
  1340.        {
  1341.            if ( _fContentTransform->GetRefCount(ev) > 1 )
  1342.                freed += _fContentTransform->Purge(ev, size-freed);
  1343.            ODReleaseObject(ev, _fContentTransform);
  1344.        }
  1345.  
  1346.        if ( _fWindowFrameTransform )
  1347.        {
  1348.            if ( _fWindowFrameTransform->GetRefCount(ev) > 1 )
  1349.                freed += _fWindowFrameTransform->Purge(ev, size-freed);
  1350.            ODReleaseObject(ev, _fWindowFrameTransform);
  1351.        }
  1352.  
  1353.        if ( _fWindowContentTransform )
  1354.        {
  1355.            if ( _fWindowContentTransform->GetRefCount(ev) > 1 )
  1356.                freed += _fWindowContentTransform->Purge(ev, size-freed);
  1357.            ODReleaseObject(ev, _fWindowContentTransform);
  1358.        }
  1359.    SOM_CATCH_ALL
  1360.    SOM_ENDTRY
  1361.  
  1362.    return freed;
  1363. }
  1364.  
  1365. //------------------------------------------------------------------------------
  1366. // ODFacet: GetFrame
  1367. //------------------------------------------------------------------------------
  1368.  
  1369. SOM_Scope ODFrame*  SOMLINK ODFacetGetFrame(ODFacet *somSelf, Environment *ev)
  1370. {
  1371.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1372.     ODFacetMethodDebug("ODFacet","GetFrame");
  1373.  
  1374. #ifdef _FACET_DEBUG_
  1375.     qprintf("Executing ODFacet::GetFrame()\n");
  1376. #endif
  1377.    return _fFrame;
  1378. }
  1379.  
  1380. //------------------------------------------------------------------------------
  1381. // ODFacet: CreateEmbeddedFacet
  1382. //------------------------------------------------------------------------------
  1383.  
  1384. SOM_Scope ODFacet*  SOMLINK ODFacetCreateEmbeddedFacet(ODFacet *somSelf, Environment *ev,
  1385.        ODFrame* frame,
  1386.        ODShape* clipShape,
  1387.        ODTransform* externalTransform,
  1388.        ODCanvas* canvas,
  1389.        ODCanvas* biasCanvas,
  1390.        ODFacet* siblingFacet,
  1391.        ODFramePosition position)
  1392. {
  1393.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1394.     ODFacetMethodDebug("ODFacet","CreateEmbeddedFacet");
  1395.  
  1396. #ifdef _FACET_DEBUG_
  1397.     qprintf("Executing ODFacet::CreateEmbeddedFacet()\n");
  1398. #endif
  1399.    ODFacet* newFacet  = kODNULL;       ODVolatile(newFacet);
  1400.    FacetNode* newNode = kODNULL;       ODVolatile(newNode);
  1401.    FacetNode* childNode = kODNULL;
  1402.  
  1403. #ifdef _PLATFORM_UNIX_
  1404.         Window siblingwindow=MOVE_WINDOW_TO_TOP;
  1405. #endif
  1406.  
  1407. #ifdef _EVERYTHING_IS_A_WINDOW_
  1408.     HWND siblingWindow=HWND_TOP;
  1409. #endif
  1410.  
  1411.    SOM_TRY
  1412.  
  1413. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  1414.        if (somSelf == siblingFacet)
  1415.            THROW(kODErrInvalidFacet);
  1416.  
  1417.        if ((position != kODFrameBehind) && (position != kODFrameInFront))
  1418.             THROW(kODErrUnsupportedFramePositionCode);
  1419. #endif // WIN32 or OS2 or UNIX
  1420.  
  1421.        if ( frame == kODNULL )
  1422.            THROW(kODErrIllegalNullFrameInput);
  1423.        if ( canvas != kODNULL )
  1424.        {
  1425.            TempODPart owner = canvas->AcquireOwner(ev);
  1426.            if ( (ODPart*)owner == kODNULL )
  1427.                THROW(kODErrCanvasHasNoOwner);
  1428.        }
  1429.  
  1430.        newFacet = new ODFacet();
  1431.        THROW_IF_NULL(newFacet);
  1432.  
  1433.        newNode = new FacetNode(newFacet);
  1434.        THROW_IF_NULL(newNode);
  1435.  
  1436.        if ( siblingFacet != kODNULL )
  1437.        {
  1438. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  1439.                if(somSelf != siblingFacet->GetContainingFacet(ev) )
  1440.                    THROW(kODErrInvalidFacet);
  1441.  
  1442. #endif // WIN32 or OS2 or UNIX
  1443.            childNode = siblingFacet->GetNode(ev);
  1444.  
  1445. #ifdef _PLATFORM_UNIX_
  1446.            siblingwindow= XtWindow(siblingFacet->GetFacetWidget(ev));
  1447. #endif
  1448.  
  1449. #ifdef _EVERYTHING_IS_A_WINDOW_
  1450.             siblingWindow = siblingFacet->GetFacetHWND(ev);
  1451. #endif
  1452.        }
  1453.  
  1454.  
  1455.        if ( position == kODFrameInFront )
  1456.        {
  1457.            if ( childNode != kODNULL )
  1458.                _fNode->AddChildBefore(*childNode, newNode);
  1459.            else {
  1460.                  _fNode->AddChildFirst(newNode);
  1461.  
  1462.                 }
  1463. #ifdef _PLATFORM_UNIX_
  1464.             siblingwindow=MOVE_WINDOW_TO_TOP;
  1465. #endif
  1466.  
  1467. #ifdef _EVERYTHING_IS_A_WINDOW_
  1468.             siblingWindow = HWND_TOP;
  1469. #endif
  1470.        }
  1471.        else if ( position == kODFrameBehind )
  1472.        {
  1473.            if ( childNode != kODNULL )
  1474.                _fNode->AddChildAfter(*childNode, newNode);
  1475.            else {
  1476.                _fNode->AddChildLast(newNode);
  1477.                 }
  1478.  
  1479. #ifdef _PLATFORM_UNIX_
  1480.             siblingwindow=MOVE_WINDOW_TO_BOTTOM;
  1481. #endif
  1482.  
  1483. #ifdef _EVERYTHING_IS_A_WINDOW_
  1484.                    siblingWindow = HWND_BOTTOM;
  1485. #endif
  1486.        }
  1487.        else
  1488.            THROW(kODErrUnsupportedFramePositionCode);
  1489.  
  1490.        newFacet->InitChildFacet(ev, newNode, frame, clipShape, externalTransform,
  1491.                                    canvas, biasCanvas);
  1492.        newNode = kODNULL;                          // owned by facet now
  1493.  
  1494. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  1495. // Here GetCanvas() method is called in order to create facet size child window
  1496. // and also on-screen dynamic canvas to store HWND.
  1497.     if(canvas == kODNULL)                                                 // If no canvas passed in,
  1498.     {
  1499.       ODFacet* parent = newFacet->GetContainingFacet(ev);
  1500.       ODCanvas* parentCanvas = parent->GetCanvas(ev);
  1501.       if(parentCanvas && parentCanvas->IsDynamic(ev) && (!parentCanvas->IsOffscreen(ev)) )
  1502.       {
  1503.          ODCanvas* thisCanvas = newFacet->GetCanvas(ev);
  1504.  
  1505. #ifdef _PLATFORM_UNIX_
  1506.          Widget newfacetwidget = newFacet->GetFacetWidget(ev);
  1507.          Window newFacetwindow = XtWindow(newfacetwidget);
  1508.          if(newFacetwindow)
  1509.             newFacet->SetFacetWidgetWinPos(ev, newFacetwindow, siblingwindow, kODTrue );
  1510. #endif
  1511.  
  1512. #ifdef _EVERYTHING_IS_A_WINDOW_
  1513.       // Move and position the window
  1514.          HWND facetHWND = newFacet->GetFacetHWND(ev);
  1515.          newFacet->SetFacetWindowPos(ev, facetHWND, siblingWindow);
  1516. #endif
  1517.        }
  1518.  
  1519.     }
  1520. #endif // _PLATFORM_OS2_ || _PLATFORM_WIN32_
  1521.  
  1522.  
  1523.        frame->FacetAdded(ev, newFacet);
  1524.    SOM_CATCH_ALL
  1525.        ODDeleteObject(newFacet);
  1526.        if( newNode ) {
  1527.            newNode->GetParent()->RemoveChild(*newNode);
  1528.            delete newNode;
  1529.        }
  1530.    SOM_ENDTRY
  1531.    return newFacet;
  1532. }
  1533.  
  1534. //------------------------------------------------------------------------------
  1535. // ODFacet: RemoveFacet
  1536. //------------------------------------------------------------------------------
  1537.  
  1538. SOM_Scope void  SOMLINK ODFacetRemoveFacet(ODFacet *somSelf, Environment *ev,
  1539.        ODFacet* facet)
  1540. {
  1541.    ODFacetData *somThis = ODFacetGetData(somSelf);
  1542.    ODFacetMethodDebug("ODFacet","RemoveFacet");
  1543.  
  1544. #ifdef _FACET_DEBUG_
  1545.     qprintf("Executing ODFacet::RemoveFacet()\n");
  1546. #endif
  1547.    SOM_TRY
  1548.  
  1549. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  1550.         if( (facet == kODNULL) || (somSelf != facet->GetContainingFacet(ev)) )
  1551.           THROW(kODErrInvalidFacet);
  1552. #endif // OS2 or WIN32 or UNIX
  1553.  
  1554. #ifdef _PLATFORM_MACINTOSH_
  1555.        ASSERT( (facet->GetContainingFacet(ev) == somSelf), kODErrInvalidFacet);
  1556.        // must get StorageUnit from part as frame might be non-persistent
  1557.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  1558.        tempPart->GetStorageUnit(ev)->GetSession(ev)->
  1559.            GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
  1560. #endif  // _PLATFORM_MACINTOSH_
  1561.        _fNode->RemoveChild(*(facet->GetNode(ev)));
  1562.        facet->GetFrame(ev)->FacetRemoved(ev, facet);   // tells part to remove children
  1563.  
  1564. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  1565.         facet->SetPartInfo(ev, kODNULL);
  1566. #endif // OS2 or WIN32 or UNIX
  1567.  
  1568.    SOM_CATCH_ALL
  1569.    SOM_ENDTRY
  1570. }
  1571.  
  1572. //------------------------------------------------------------------------------
  1573. // ODFacet: MoveBefore
  1574. //------------------------------------------------------------------------------
  1575.  
  1576. SOM_Scope void  SOMLINK ODFacetMoveBefore(ODFacet *somSelf, Environment *ev,
  1577.        ODFacet* child,
  1578.        ODFacet* sibling)
  1579. {
  1580.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1581.     ODFacetMethodDebug("ODFacet","MoveBefore");
  1582. #ifdef _FACET_DEBUG_
  1583.     qprintf("Executing ODFacet::MoveBefore()\n");
  1584. #endif
  1585.  
  1586.    SOM_TRY
  1587.  
  1588.        Node* childNode;
  1589.        Node* siblingNode;
  1590.  
  1591.        if ( child )
  1592.        {
  1593.  
  1594. #ifdef _PLATFORM_UNIX_
  1595.         Window siblingwindow = MOVE_WINDOW_TO_TOP;
  1596. #endif
  1597.  
  1598. #ifdef _EVERYTHING_IS_A_WINDOW_
  1599.           HWND siblingWindow = HWND_TOP;
  1600. #endif
  1601.            childNode = child->GetNode(ev);
  1602.            _fNode->RemoveChild(*childNode);
  1603.            if ( sibling )
  1604.            {
  1605. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  1606.                if(child->GetContainingFacet(ev) != sibling->GetContainingFacet(ev) )
  1607.                    THROW(kODErrInvalidFacet);
  1608. #endif
  1609.                siblingNode = sibling->GetNode(ev);
  1610.                _fNode->AddChildBefore(*siblingNode, childNode);
  1611.  
  1612. #ifdef _PLATFORM_UNIX_
  1613.                siblingwindow = XtWindow(sibling->GetFacetWidget(ev));
  1614. #endif
  1615.  
  1616. #ifdef _EVERYTHING_IS_A_WINDOW_
  1617.                siblingWindow = sibling->GetFacetHWND(ev);
  1618. #endif
  1619.            }
  1620.            else
  1621.            {
  1622.                _fNode->AddChildFirst(childNode);
  1623.            }
  1624.  
  1625. #ifdef _PLATFORM_UNIX_
  1626.         Window childwindow = XtWindow(child->GetFacetWidget(ev));
  1627.         if(childwindow)
  1628.            child->SetFacetWidgetWinPos(ev, childwindow, siblingwindow, kODTrue );
  1629. #endif
  1630.  
  1631. #ifdef _EVERYTHING_IS_A_WINDOW_
  1632.            HWND hwnd = child->GetFacetHWND(ev);
  1633. #ifdef _PLATFORM_OS2_
  1634.          WinSetWindowPos(hwnd, siblingWindow, 0, 0, 0, 0, SWP_SHOW | SWP_ZORDER | SWP_NOREDRAW);
  1635. #endif
  1636.  
  1637. #ifdef _PLATFORM_WIN32_
  1638.                 SetWindowPos(hwnd, siblingWindow, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE);
  1639.  
  1640. #endif
  1641.  
  1642. #endif
  1643.        }
  1644.    SOM_CATCH_ALL
  1645.    SOM_ENDTRY
  1646. }
  1647.  
  1648. //------------------------------------------------------------------------------
  1649. // ODFacet: MoveBehind
  1650. //------------------------------------------------------------------------------
  1651.  
  1652. SOM_Scope void  SOMLINK ODFacetMoveBehind(ODFacet *somSelf, Environment *ev,
  1653.        ODFacet* child,
  1654.        ODFacet* sibling)
  1655. {
  1656.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1657.     ODFacetMethodDebug("ODFacet","MoveBehind");
  1658.  
  1659. #ifdef _FACET_DEBUG_
  1660.     qprintf("Executing ODFacet::MoveBehind()\n");
  1661. #endif
  1662.  
  1663.  
  1664.    SOM_TRY
  1665.        Node* childNode;
  1666.        Node* siblingNode;
  1667.  
  1668.        if ( child )
  1669.        {
  1670.  
  1671. #ifdef _PLATFORM_UNIX_
  1672.         Window siblingwindow = MOVE_WINDOW_TO_BOTTOM;
  1673. #endif
  1674.  
  1675. #ifdef _EVERYTHING_IS_A_WINDOW_
  1676.    HWND siblingWindow=HWND_BOTTOM;
  1677. #endif
  1678.            childNode = child->GetNode(ev);
  1679.            _fNode->RemoveChild(*childNode);
  1680.            if ( sibling )
  1681.            {
  1682. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  1683.                if(child->GetContainingFacet(ev) != sibling->GetContainingFacet(ev) )
  1684.                    THROW(kODErrInvalidFacet);
  1685. #endif
  1686.                siblingNode = sibling->GetNode(ev);
  1687.                _fNode->AddChildAfter(*siblingNode, childNode);
  1688.  
  1689. #ifdef _PLATFORM_UNIX_
  1690.                siblingwindow = XtWindow(sibling->GetFacetWidget(ev));
  1691. #endif
  1692.  
  1693. #ifdef _EVERYTHING_IS_A_WINDOW_
  1694.                siblingWindow = sibling->GetFacetHWND(ev);
  1695. #endif
  1696.            }
  1697.            else
  1698.            {
  1699.                _fNode->AddChildLast(childNode);
  1700.            }
  1701.  
  1702. #ifdef _PLATFORM_UNIX_
  1703.         Window childwindow = XtWindow(child->GetFacetWidget(ev));
  1704.         if(childwindow)
  1705.            child->SetFacetWidgetWinPos(ev, childwindow, siblingwindow, kODFalse );
  1706. #endif
  1707.  
  1708. #ifdef _EVERYTHING_IS_A_WINDOW_
  1709.            HWND hwnd = child->GetFacetHWND(ev);
  1710. #ifdef _PLATFORM_OS2_
  1711.          WinSetWindowPos(hwnd, siblingWindow, 0, 0, 0, 0, SWP_SHOW | SWP_ZORDER | SWP_NOREDRAW);
  1712. #endif
  1713.  
  1714. #ifdef _PLATFORM_WIN32_
  1715.                 SetWindowPos(hwnd, siblingWindow, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOMOVE | SWP_NOSIZE);
  1716.  
  1717. #endif
  1718.  
  1719. #endif
  1720.  
  1721.        }
  1722.    SOM_CATCH_ALL
  1723.    SOM_ENDTRY
  1724. }
  1725.  
  1726. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_)
  1727.  
  1728. SOM_Scope void  SOMLINK ODFacetSetFacetWindowRgn(ODFacet *somSelf, Environment *ev, ODBoolean IsUsedShape)
  1729. {
  1730.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1731.     ODFacetMethodDebug("ODFacet","ODFacetSetFacetWindowRgn");
  1732.     TempODShape UShape=kODNULL;
  1733.  
  1734. #ifdef _EVERYTHING_IS_A_WINDOW_
  1735.        UShape = ODCopyAndRelease(ev, somSelf->GetFrame(ev)->AcquireUsedShape(ev, kNoBias));
  1736.  
  1737.     if(!IsUsedShape)
  1738.     {
  1739.        TempODShape clipShape = ODCopyAndRelease(ev, somSelf->AcquireClipShape(ev, kNoBias));
  1740.        UShape->Intersect(ev, clipShape);
  1741.     }
  1742.  
  1743.     if(UShape)
  1744.     {
  1745.      somSelf->Invalidate(ev, kODNULL, kODNULL);
  1746.      TempODTransform xform =  somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  1747.      UShape->Transform(ev, xform);
  1748.  
  1749.      ODPoint offset(0,0);
  1750.      TempODShape FrameShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  1751.      GetFacetPosition(ev, xform, FrameShape, offset);
  1752.      HWND hwnd = somSelf->GetFacetHWND(ev);
  1753.  
  1754. #ifdef _PLATFORM_WIN32_
  1755.      Point winpt = offset.AsWinPoint();
  1756.      ODRgnHandle UShapeRgn = UShape->GetRegion(ev);
  1757.      OffsetRgn(UShapeRgn, winpt.x, winpt.y);
  1758.      OSVERSIONINFO osinfo;
  1759.      osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  1760.      GetVersionEx(&osinfo);
  1761.  
  1762.      if(osinfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  1763.      {
  1764.         if(_fUsedShapeRgn != kODNULL)
  1765.         {
  1766.            SetWindowRgn(hwnd, NULL, FALSE);
  1767.            DeleteObject(_fUsedShapeRgn);
  1768.         }
  1769.  
  1770.       //  if(!UShape->IsRectangular(ev))
  1771.           _fUsedShapeRgn = CreateRectRgn(0, 0, 0, 0);
  1772.       // else
  1773.       //    _fUsedShapeRgn = CreateEllipticRgn(0, 0, 0, 0);
  1774.  
  1775.         int result = CombineRgn(_fUsedShapeRgn, UShapeRgn, 0, RGN_COPY);
  1776.         SetWindowRgn(hwnd, _fUsedShapeRgn, FALSE);
  1777.      }
  1778.      else
  1779.          SetWindowRgn(hwnd, UShapeRgn, FALSE);
  1780.  
  1781. #endif //_PLATFORM_WIN32_
  1782.  
  1783. #ifdef _PLATFORM_OS2_
  1784.      ODOS2WindowCanvas *platcanv = (ODOS2WindowCanvas *) somSelf->GetCanvas(ev)->GetPlatformCanvas(ev, kODPM);
  1785.      HPS hps = platcanv->GetPS(ev);
  1786.  
  1787.      POINTL winpt = offset.AsPOINTL();
  1788.      ODRgnHandle usedShapeRgn = UShape->GetRegion(ev);
  1789.      GpiOffsetRegion(hps, usedShapeRgn, &winpt);
  1790.  
  1791.      WinSetWindowPtr(hwnd, QWL_FACETWINDOWRGN, (PVOID)1); // Set region flag, used by CopyAggregateClipRegion() method
  1792.      WinSetClipRegion(hwnd, usedShapeRgn);  // NEW PM API CALL
  1793.      platcanv->ReleasePS(ev);
  1794. #endif //_PLATFORM_OS2_
  1795.  
  1796.      _fIsRegionSet = kODTrue; // Set region flag
  1797.     }
  1798. #endif // EVERYTHING IS A WINDOW
  1799. }
  1800.  
  1801.  
  1802. SOM_Scope void  SOMLINK ODFacetSetFacetWindowPos(ODFacet *somSelf, Environment *ev, HWND facetHWND, HWND siblingHWND)
  1803. {
  1804.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1805.     ODFacetMethodDebug("ODFacet","ODFacetSetFacetWindowPos");
  1806.  
  1807. #ifdef _EVERYTHING_IS_A_WINDOW_
  1808.     ODULong lWidth, lHeight;
  1809.     lWidth =0; lHeight = 0;
  1810.  
  1811.       TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  1812.       ODRect RectBounds;
  1813.  
  1814.    // TempODShape bShape = _fClipShape->Copy(ev);
  1815.       TempODShape bShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  1816.       bShape->Transform(ev, xform);
  1817.       bShape->GetBoundingBox(ev, &RectBounds);
  1818.  
  1819.  
  1820. #ifdef _PLATFORM_WIN32_
  1821.          Point childPt2;
  1822.          RECT RectShape;
  1823.          RectBounds.AsWinRect(RectShape);
  1824.          childPt2.x = RectShape.left;
  1825.          childPt2.y = RectShape.top;
  1826.          lWidth  = RectShape.right  - childPt2.x;
  1827.          lHeight = RectShape.bottom - childPt2.y;
  1828. #endif //_PLATFORM_WIN32_
  1829.  
  1830. #ifdef _PLATFORM_OS2_
  1831.          POINTL childPt2;
  1832.          RECTL RectLShape;
  1833.          RectBounds.AsRECTL(RectLShape);
  1834.          childPt2.x = RectLShape.xLeft;
  1835.          childPt2.y = RectLShape.yBottom;
  1836.          lWidth  = RectLShape.xRight  - childPt2.x;
  1837.          lHeight = RectLShape.yTop    - childPt2.y;
  1838. #endif //_PLATFORM_OS2_
  1839.  
  1840.          ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  1841.          if(parentFacet)
  1842.          {
  1843.            TempODTransform x2form = parentFacet->AcquireWindowFrameTransform(ev, kODNULL);
  1844.            ODPoint ParentPt1(0,0);
  1845.            TempODShape tshape = ODCopyAndRelease(ev, parentFacet->GetFrame(ev)->AcquireFrameShape(ev, kODNULL));
  1846.            GetFacetPosition(ev, x2form, tshape, ParentPt1);
  1847.  
  1848. #ifdef _PLATFORM_WIN32_
  1849.            Point ParentPt2 = ParentPt1.AsWinPoint();
  1850. #endif //_PLATFORM_WIN32_
  1851.  
  1852. #ifdef _PLATFORM_OS2_
  1853.            POINTL ParentPt2 = ParentPt1.AsPOINTL();
  1854. #endif //_PLATFORM_OS2_
  1855.  
  1856.            childPt2.x += ParentPt2.x;
  1857.            childPt2.y += ParentPt2.y;
  1858.  
  1859.          }
  1860.  
  1861.  
  1862.          // Move and position the window
  1863. #ifdef _PLATFORM_WIN32_
  1864.  
  1865.          if(siblingHWND == HWND_MOVE_THE_WINDOW)
  1866.          {
  1867.           MoveWindow(facetHWND, childPt2.x, childPt2.y, lWidth, lHeight, FALSE);
  1868.          }
  1869.          else {
  1870.                 SetWindowPos(facetHWND, siblingHWND, childPt2.x, childPt2.y, lWidth, lHeight, SWP_NOACTIVATE | SWP_NOREDRAW);
  1871.         }
  1872. #endif //_PLATFORM_WIN32_
  1873.  
  1874. #ifdef _PLATFORM_OS2_
  1875.          ULONG flOptions = SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_NOREDRAW;
  1876.          if(siblingHWND)
  1877.             flOptions |= SWP_ZORDER;
  1878.          WinSetWindowPos(facetHWND, siblingHWND, childPt2.x, childPt2.y, lWidth, lHeight, flOptions);
  1879. #endif //_PLATFORM_OS2_
  1880.  
  1881.          if(_fClipShape)
  1882.          {
  1883.            // If the window has a region
  1884.            if (_fIsRegionSet)
  1885.            {
  1886.              // Current design is once a facet window region, always a facet window region.
  1887.              // A possible enhancement would be to delete the facet window
  1888.              // region if the facet's clipshape and frame's usedshape become the same as the
  1889.              // rectangular frameshape. An example is a toggle between a round analog
  1890.              // and a rectangular digital clock.
  1891.              somSelf->SetFacetWindowRgn(ev, kODFalse);
  1892.            }
  1893.            else
  1894.            {
  1895.              // If the transformed clipshape is not rectangular or is different than the
  1896.              // transform frame shape
  1897.              TempODShape clipShape = _fClipShape->Copy(ev);
  1898.              clipShape->Transform(ev, xform);
  1899.              if( (!clipShape->IsRectangular(ev)) || (!clipShape->IsSameAs(ev, bShape)) )
  1900.              {
  1901.                // We've gone down the road where this facet window will now always have a
  1902.                // region associated with it.
  1903.                somSelf->SetFacetWindowRgn(ev, kODFalse);
  1904.              }
  1905.            }
  1906.          }
  1907.  
  1908.  
  1909. #endif  // EVERYTHING IS A WINDOW
  1910.  
  1911. }
  1912.  
  1913. #endif //_PLATFORM_OS2_ || _PLATFORM_WIN32_
  1914.  
  1915. //------------------------------------------------------------------------------
  1916. // ODFacet: GetContainingFacet
  1917. //------------------------------------------------------------------------------
  1918.  
  1919. SOM_Scope ODFacet*  SOMLINK ODFacetGetContainingFacet(ODFacet *somSelf, Environment *ev)
  1920. {
  1921.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1922.     ODFacetMethodDebug("ODFacet","GetContainingFacet");
  1923.  
  1924. #ifdef _FACET_DEBUG_
  1925.     qprintf("Executing ODFacet::GetContainingFacet()\n");
  1926. #endif
  1927.    SOM_TRY
  1928.        FacetNode* parent = (FacetNode*) _fNode->GetParent();
  1929.        if (parent)
  1930.            return parent->GetFacet();
  1931.        else
  1932.            return kODNULL;
  1933.    SOM_CATCH_ALL
  1934.    SOM_ENDTRY
  1935.    return kODNULL;
  1936. }
  1937.  
  1938. //------------------------------------------------------------------------------
  1939. // ODFacet: CreateFacetIterator
  1940. //------------------------------------------------------------------------------
  1941.  
  1942. SOM_Scope ODFacetIterator*  SOMLINK ODFacetCreateFacetIterator(ODFacet *somSelf, Environment *ev,
  1943.        ODTraversalType traversalType,
  1944.        ODSiblingOrder siblingOrder)
  1945. {
  1946.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1947.     ODFacetMethodDebug("ODFacet","CreateFacetIterator");
  1948.  
  1949. #ifdef _FACET_DEBUG_
  1950.     qprintf("Executing ODFacet::CreateFacetIterator()\n");
  1951. #endif
  1952.    ODFacetIterator* iter = kODNULL; ODVolatile(iter);
  1953.    SOM_TRY
  1954.        iter = new ODFacetIterator();
  1955.        THROW_IF_NULL(iter);
  1956.        iter->InitFacetIterator(ev, somSelf, traversalType, siblingOrder);
  1957.    SOM_CATCH_ALL
  1958.        ODDeleteObject(iter);
  1959.        iter = kODNULL;
  1960.    SOM_ENDTRY
  1961.    return iter;
  1962. }
  1963.  
  1964. //------------------------------------------------------------------------------
  1965. // ODFacet: ChangeGeometry
  1966. //------------------------------------------------------------------------------
  1967.  
  1968. SOM_Scope void  SOMLINK ODFacetChangeGeometry(ODFacet *somSelf, Environment *ev,
  1969.        ODShape* clipShape,
  1970.        ODTransform* transform,
  1971.        ODCanvas* biasCanvas)
  1972.  
  1973. {
  1974.     ODFacetData *somThis = ODFacetGetData(somSelf);
  1975.     ODFacetMethodDebug("ODFacet","ChangeGeometry");
  1976.  
  1977. #ifdef _FACET_DEBUG_
  1978.     qprintf("Executing ODFacet::ChangeGeometry()\n");
  1979. #endif
  1980.     SOM_TRY
  1981.        ODBoolean clipShapeChanged = kODFalse;
  1982.        ODBoolean externalTransformChanged = kODFalse;
  1983.  
  1984. #ifdef _PLATFORM_OS2_
  1985.        somSelf->InvalidateAggregateClipShape(ev);
  1986. #endif
  1987.        if ( clipShape )
  1988.        {
  1989.            ODAcquireObject(ev, clipShape);
  1990.            ODReleaseObject(ev, _fClipShape);
  1991.            _fClipShape = BiasShapeSet(ev, clipShape, biasCanvas);
  1992.            clipShapeChanged = kODTrue;
  1993.            somSelf->InvalidateAggregateClipShape(ev);
  1994.  
  1995.        }
  1996.  
  1997.        if ( transform )
  1998.        {
  1999.            ODAcquireObject(ev, transform);
  2000.            ODReleaseObject(ev, _fExternalTransform);
  2001.            _fExternalTransform = BiasTransformSet(ev, transform, biasCanvas);
  2002.            externalTransformChanged = kODTrue;
  2003.            somSelf->InvalidateAggregateTransforms(ev);
  2004.            somSelf->InvalidateAggregateClipShape(ev);
  2005.  
  2006.        }
  2007.  
  2008. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_)
  2009.        if (( clipShape ) || ( transform ))
  2010. #endif // _PLATFORM_WIN32_
  2011.        {
  2012.            ODFacetIterator* i = new ODFacetIterator();
  2013.            THROW_IF_NULL(i);
  2014.            i->InitFacetIterator(ev, somSelf, kODTopDown, kODFrontToBack);
  2015.            for (ODFacet* facet = i->First(ev); i->IsNotComplete(ev); facet = i->Next(ev))
  2016.            {
  2017.  
  2018. #ifdef _PLATFORM_UNIX_
  2019.               facet->SetFacetWidgetSize(ev);
  2020. #endif // _PLATFORM_UNIX_
  2021.  
  2022. #ifdef _EVERYTHING_IS_A_WINDOW_
  2023.                ODPlatformWindow hwnd;
  2024.                hwnd = facet->GetFacetHWND(ev);
  2025.                if (hwnd)
  2026.                {
  2027.                    // Move and position the window
  2028. #ifdef _PLATFORM_WIN32_
  2029.                    facet->SetFacetWindowPos(ev, hwnd, HWND_MOVE_THE_WINDOW);
  2030. #endif
  2031. #ifdef _PLATFORM_OS2_
  2032.                    facet->SetFacetWindowPos(ev, hwnd, 0);
  2033. #endif
  2034.                }
  2035. #endif   // EVERYTHING IS A WINDOW
  2036.                TempODPart tempPart = facet->GetFrame(ev)->AcquirePart(ev);
  2037.                tempPart->GeometryChanged(ev, facet, clipShapeChanged, externalTransformChanged);
  2038.            }
  2039.            ODDeleteObject(i);
  2040.        }
  2041.  
  2042.    SOM_CATCH_ALL
  2043.    SOM_ENDTRY
  2044. }
  2045.  
  2046.  
  2047. //------------------------------------------------------------------------------
  2048. // ODFacet: CreateShape
  2049. //------------------------------------------------------------------------------
  2050.  
  2051. SOM_Scope ODShape*  SOMLINK ODFacetCreateShape(ODFacet *somSelf, Environment *ev)
  2052. {
  2053.    ODFacetData *somThis = ODFacetGetData(somSelf);
  2054.    ODFacetMethodDebug("ODFacet","CreateShape");
  2055.  
  2056. #ifdef _FACET_DEBUG_
  2057.     qprintf("Executing ODFacet::CreateShape()\n");
  2058. #endif
  2059.    ODShape *s = kODNULL;  ODVolatile(s);
  2060.     SOM_TRY
  2061.        s = new ODShape;
  2062.        THROW_IF_NULL(s);
  2063.        s->InitShape(ev);
  2064.     SOM_CATCH_ALL
  2065.        ODDeleteObject(s);
  2066.        s = kODNULL;
  2067.     SOM_ENDTRY
  2068.     return s;
  2069. }
  2070.  
  2071.  
  2072. //------------------------------------------------------------------------------
  2073. // ODFacet: AcquireClipShape
  2074. //------------------------------------------------------------------------------
  2075.  
  2076. SOM_Scope ODShape*  SOMLINK ODFacetAcquireClipShape(ODFacet *somSelf, Environment *ev,
  2077.        ODCanvas* biasCanvas)
  2078. {
  2079.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2080.     ODFacetMethodDebug("ODFacet","AcquireClipShape");
  2081.  
  2082. #ifdef _FACET_DEBUG_
  2083.     qprintf("Executing ODFacet::AcquireClipShape()\n");
  2084. #endif
  2085.     SOM_TRY
  2086.        if ( _fClipShape )
  2087.            return BiasShapeGet(ev, _fClipShape, biasCanvas);
  2088.        else
  2089.            return ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, biasCanvas));
  2090.     SOM_CATCH_ALL
  2091.     SOM_ENDTRY
  2092.     return kODNULL;
  2093. }
  2094.  
  2095. //------------------------------------------------------------------------------
  2096. // ODFacet: AcquireAggregateClipShape
  2097. //------------------------------------------------------------------------------
  2098.  
  2099. SOM_Scope ODShape*  SOMLINK ODFacetAcquireAggregateClipShape(ODFacet *somSelf, Environment *ev,
  2100.        ODCanvas* biasCanvas)
  2101. {
  2102.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2103.     ODFacetMethodDebug("ODFacet","AcquireAggregateClipShape");
  2104.  
  2105. #ifdef _FACET_DEBUG_
  2106.     qprintf("Executing ODFacet::AcquireAggregateClipShape()\n");
  2107. #endif
  2108.  
  2109.     SOM_TRY
  2110.        if ( !_fAggregateClipShape )
  2111.        {
  2112.            ODFacet* parent = somSelf->GetContainingFacet(ev);
  2113.  
  2114.            // Determine whether canvas is geometric or whether we can punt to regions: [jpa]
  2115. #ifdef _PLATFORM_MACINTOSH_
  2116.            ODGeometryMode mode = _fCanvas  ?GetCanvasGeometryMode(ev,_fCanvas)
  2117.                                            :kODLoseGeometry;
  2118. #endif  // _PLATFORM_MACINTOSH_
  2119.  
  2120.            if ( _fCanvas && _fCanvas->IsOffscreen(ev) )
  2121.            {
  2122.                _fAggregateClipShape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  2123. #ifdef _PLATFORM_MACINTOSH_
  2124.                _fAggregateClipShape->SetGeometryMode(ev,mode);
  2125. #endif  // _PLATFORM_MACINTOSH_
  2126.            }
  2127.            else
  2128.            {
  2129.                _fAggregateClipShape = ODCopyAndRelease(ev, somSelf->AcquireClipShape(ev, kODNULL));
  2130. #ifdef _PLATFORM_MACINTOSH_
  2131.                _fAggregateClipShape->SetGeometryMode(ev,mode);
  2132. #endif   // _PLATFORM_MACINTOSH_
  2133.                if ( parent )
  2134.                {
  2135.                    TempODShape parentClip = kODNULL;
  2136.                    TempODTransform xform = kODNULL;
  2137.                    parentClip = ODCopyAndRelease(ev, parent->AcquireAggregateClipShape(ev, kODNULL));
  2138.                    xform = ODCopyAndRelease(ev,
  2139.                        parent->GetFrame(ev)->AcquireInternalTransform(ev, kODNULL));
  2140.                    if ( _fExternalTransform != kODNULL )
  2141.                        xform->PreCompose(ev, _fExternalTransform);
  2142.                    parentClip->InverseTransform(ev, xform);
  2143.                    _fAggregateClipShape->Intersect(ev, parentClip);
  2144.                }
  2145.            }
  2146.        }
  2147.        return BiasShapeGet(ev, _fAggregateClipShape, biasCanvas);
  2148.     SOM_CATCH_ALL
  2149.     SOM_ENDTRY
  2150.     return kODNULL;
  2151. }
  2152.  
  2153. #ifdef _PLATFORM_OS2_
  2154. //------------------------------------------------------------------------------
  2155. // ODFacet: CopyAggregateClipRegion
  2156. //------------------------------------------------------------------------------
  2157.  
  2158. SOM_Scope ODRgnHandle SOMLINK ODFacetCopyAggregateClipRegion(ODFacet *somSelf, Environment *ev, HPS hps)
  2159. {
  2160.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2161.     ODFacetMethodDebug("ODFacet","CopyAggregateClipRegion");
  2162.  
  2163. #ifdef _FACET_DEBUG_
  2164.     qprintf("Executing ODFacet::CopyAggregateClipRegion()\n");
  2165. #endif
  2166.     HRGN mainRgn;
  2167.  
  2168.     SOM_TRY
  2169.       RECTL mainRect;
  2170.       HWND mainhwnd = somSelf->GetFacetHWND(ev);
  2171.       WinQueryWindowRect(mainhwnd, &mainRect) ;
  2172.       mainRgn = GpiCreateRegion(hps, 1L, &mainRect);
  2173.       HENUM henum   = WinBeginEnumWindows(mainhwnd);                                           // enum over child windows
  2174.       HWND hwndNext;
  2175.       RECTL childrectl;
  2176.       HAB hab = WinQueryAnchorBlock(HWND_DESKTOP);
  2177.       ODRgnHandle childClipRgn;
  2178.       SWP swp;
  2179.       POINTL offsetRgn;
  2180.       BOOL boolRC;
  2181.  
  2182.       // Clip children
  2183.  
  2184.       while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)   // for each child window...
  2185.       {
  2186.         // First check to see if window rects intersect
  2187.         RECTL DestRect;
  2188.         WinQueryWindowRect(hwndNext, &childrectl);                                // Get child rect
  2189.         WinMapWindowPoints(hwndNext, mainhwnd, (PPOINTL)&childrectl, 2);          // map rect to parent
  2190.         WinIntersectRect(hab, &DestRect, &childrectl, &mainRect);                 // get overlap rect
  2191.  
  2192.         if(!WinIsRectEmpty(hab, &DestRect))                                       // if overlap
  2193.         {
  2194.           BOOL WindowIsRgn = (BOOL)WinQueryWindowPtr(hwndNext, QWL_FACETWINDOWRGN);              // Is region or rect?
  2195.           LONG lComplexity;
  2196.  
  2197.           if (WindowIsRgn)  // If used shape is region, not rectangular
  2198.           {
  2199.             childClipRgn = GpiCreateRegion(hps, 0, 0);
  2200.             WinQueryClipRegion(hwndNext, childClipRgn);                                          // Get child region
  2201.             WinQueryWindowPos(hwndNext, &swp);                                                   // Get its offset from me
  2202.             POINTL offsetRgn = {swp.x, swp.y};
  2203.             boolRC           = GpiOffsetRegion(hps, childClipRgn, &offsetRgn);                   // Offset child region
  2204.             LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);  // Subtract child region
  2205.             boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2206.           }
  2207.           else              // If used shape is rectangular
  2208.           {
  2209.             childClipRgn     = GpiCreateRegion(hps, 1L, &childrectl);                            // region is rect
  2210.             LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);  // Subtract child rect
  2211.             boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2212.           }
  2213.         }
  2214.       }
  2215.       WinEndEnumWindows(henum);
  2216.  
  2217.       // Clip siblings
  2218.  
  2219.       if(!somSelf->GetFrame(ev)->IsRoot(ev))               // Don't need to do root window
  2220.       {
  2221.         HWND  parenthwnd = WinQueryWindow(mainhwnd, QW_PARENT);                         // only parent knows my siblings
  2222.         HENUM henum      = WinBeginEnumWindows(parenthwnd);                             // enum over siblings (prime)
  2223.         WinMapWindowPoints(mainhwnd, parenthwnd, (PPOINTL)&mainRect, 2);                // map rect to parent
  2224.         SWP swpmain;
  2225.         WinQueryWindowPos(mainhwnd, &swpmain);                                          // pos to parent
  2226.         POINTL offsetRgnMain = {swpmain.x, swpmain.y};
  2227.         BOOL boolRC          = GpiOffsetRegion(hps, mainRgn, &offsetRgnMain);           // map rgn to parent
  2228.  
  2229.         while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)                      // enum over siblings
  2230.         {
  2231.           if(mainhwnd == hwndNext)                                                      // don't check self and behind
  2232.             break;
  2233.  
  2234.           RECTL DestRect;
  2235.           WinQueryWindowRect(hwndNext, &childrectl);                                  // sibling rect
  2236.           WinMapWindowPoints(hwndNext, parenthwnd, (PPOINTL)&childrectl, 2);          // map rect to parent
  2237.           WinIntersectRect(hab, &DestRect, &childrectl, &mainRect);                   // get overlap rect
  2238.  
  2239.           if(!WinIsRectEmpty(hab, &DestRect))                                         // if overlap
  2240.           {
  2241.             BOOL WindowIsRgn = (BOOL)WinQueryWindowPtr(hwndNext, QWL_FACETWINDOWRGN);     // Window ptr tells if non-rect
  2242.  
  2243.             if (WindowIsRgn)  // If used shape is region, not rectangular
  2244.             {
  2245.               childClipRgn = GpiCreateRegion(hps, 0, 0);
  2246.               WinQueryClipRegion(hwndNext, childClipRgn);                                 // sibling region
  2247.               WinQueryWindowPos(hwndNext, &swp);                                          // pos to parent
  2248.               POINTL offsetRgn = {swp.x, swp.y};
  2249.               boolRC           = GpiOffsetRegion(hps, childClipRgn, &offsetRgn); // map rgn to parent
  2250.               LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);
  2251.               boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2252.             }
  2253.             else              // if used shape is rectangular
  2254.             {
  2255.               childClipRgn     = GpiCreateRegion(hps, 1L, &DestRect);                  // rect to region
  2256.               LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);
  2257.               boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2258.             }
  2259.           }
  2260.         }
  2261.         offsetRgnMain.x = -swpmain.x;                                                   // restore back to orig offset
  2262.         offsetRgnMain.y = -swpmain.y;                                                   // restore back to orig offset
  2263.         boolRC = GpiOffsetRegion(hps, mainRgn, &offsetRgnMain);                        // map rgn back
  2264.         WinEndEnumWindows(henum);
  2265.       }
  2266.     SOM_CATCH_ALL
  2267.     SOM_ENDTRY
  2268.     return mainRgn;
  2269. }
  2270.  
  2271. //------------------------------------------------------------------------------
  2272. // ODFacet: CopyFacetClipRegion
  2273. // This method is the same as CopyAggregateClipRegion but does not subtract out
  2274. // the facet's children's shape only the siblings' shape.
  2275. //------------------------------------------------------------------------------
  2276.  
  2277. SOM_Scope ODRgnHandle SOMLINK ODFacetCopyFacetClipRegion(ODFacet *somSelf, Environment *ev, HPS hps)
  2278. {
  2279.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2280.     ODFacetMethodDebug("ODFacet","CopyAggregateClipRegion");
  2281.  
  2282. #ifdef _FACET_DEBUG_
  2283.     qprintf("Executing ODFacet::CopyAggregateClipRegion()\n");
  2284. #endif
  2285.     HRGN mainRgn;
  2286.  
  2287.     SOM_TRY
  2288.       RECTL mainRect;
  2289.       HWND mainhwnd = somSelf->GetFacetHWND(ev);
  2290.       WinQueryWindowRect(mainhwnd, &mainRect) ;
  2291.       mainRgn = GpiCreateRegion(hps, 1L, &mainRect);
  2292.       HWND hwndNext;
  2293.       RECTL childrectl;
  2294.       HAB hab = WinQueryAnchorBlock(HWND_DESKTOP);
  2295.       ODRgnHandle childClipRgn;
  2296.       SWP swp;
  2297.       POINTL offsetRgn;
  2298.       BOOL boolRC;
  2299.  
  2300.       // Clip siblings
  2301.  
  2302.       if(!somSelf->GetFrame(ev)->IsRoot(ev))               // Don't need to do root window
  2303.       {
  2304.         HWND  parenthwnd = WinQueryWindow(mainhwnd, QW_PARENT);                         // only parent knows my siblings
  2305.         HENUM henum      = WinBeginEnumWindows(parenthwnd);                             // enum over siblings (prime)
  2306.         WinMapWindowPoints(mainhwnd, parenthwnd, (PPOINTL)&mainRect, 2);                // map rect to parent
  2307.         SWP swpmain;
  2308.         WinQueryWindowPos(mainhwnd, &swpmain);                                          // pos to parent
  2309.         POINTL offsetRgnMain = {swpmain.x, swpmain.y};
  2310.         BOOL boolRC          = GpiOffsetRegion(hps, mainRgn, &offsetRgnMain);           // map rgn to parent
  2311.  
  2312.         while ((hwndNext = WinGetNextWindow(henum)) != NULLHANDLE)                      // enum over siblings
  2313.         {
  2314.           if(mainhwnd == hwndNext)                                                      // don't check self and behind
  2315.             break;
  2316.  
  2317.           RECTL DestRect;
  2318.           WinQueryWindowRect(hwndNext, &childrectl);                                  // sibling rect
  2319.           WinMapWindowPoints(hwndNext, parenthwnd, (PPOINTL)&childrectl, 2);          // map rect to parent
  2320.           WinIntersectRect(hab, &DestRect, &childrectl, &mainRect);                   // get overlap rect
  2321.  
  2322.           if(!WinIsRectEmpty(hab, &DestRect))                                         // if overlap
  2323.           {
  2324.             BOOL WindowIsRgn = (BOOL)WinQueryWindowPtr(hwndNext, QWL_FACETWINDOWRGN);     // Window ptr tells if non-rect
  2325.  
  2326.             if (WindowIsRgn)  // If used shape is region, not rectangular
  2327.             {
  2328.               childClipRgn = GpiCreateRegion(hps, 0, 0);
  2329.               WinQueryClipRegion(hwndNext, childClipRgn);                                 // sibling region
  2330.               WinQueryWindowPos(hwndNext, &swp);                                          // pos to parent
  2331.               POINTL offsetRgn = {swp.x, swp.y};
  2332.               boolRC           = GpiOffsetRegion(hps, childClipRgn, &offsetRgn); // map rgn to parent
  2333.               LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);
  2334.               boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2335.             }
  2336.             else              // if used shape is rectangular
  2337.             {
  2338.               childClipRgn     = GpiCreateRegion(hps, 1L, &DestRect);                  // rect to region
  2339.               LONG lComplexity = GpiCombineRegion(hps,mainRgn, mainRgn, childClipRgn, CRGN_DIFF);
  2340.               boolRC           = GpiDestroyRegion(hps, childClipRgn);
  2341.             }
  2342.           }
  2343.         }
  2344.         offsetRgnMain.x = -swpmain.x;                                                   // restore back to orig offset
  2345.         offsetRgnMain.y = -swpmain.y;                                                   // restore back to orig offset
  2346.         boolRC = GpiOffsetRegion(hps, mainRgn, &offsetRgnMain);                        // map rgn back
  2347.         WinEndEnumWindows(henum);
  2348.       }
  2349.     SOM_CATCH_ALL
  2350.     SOM_ENDTRY
  2351.     return mainRgn;
  2352. }
  2353.  
  2354. //------------------------------------------------------------------------------                     
  2355. // ODFacet:ChildUnderPoint                                                                     
  2356. //------------------------------------------------------------------------------                     
  2357.                                                                                                      
  2358. SOM_Scope ODPlatformWindow SOMLINK ODFacetChildUnderPoint(ODFacet *somSelf, Environment *ev, ODPoint *odPt) 
  2359. {
  2360.    HWND hwndTarget = kODNULL;
  2361.    HWND hwndFacet = somSelf->GetFacetHWND(ev);                                                                                    
  2362.    if (hwndFacet)                         
  2363.    {                                                                                                                            
  2364.          POINTL ptl = odPt->AsPOINTL();                                                                                          
  2365.          WinSetWindowULong(hwndFacet, QWL_HITTESTFACET, TRUE); // Tell facet window not                                             
  2366.                                                                                                  //  to be transparent.                                                              
  2367.          hwndTarget = WinWindowFromPoint(hwndFacet, &ptl, TRUE);                                                               
  2368.          WinSetWindowULong(hwndFacet, QWL_HITTESTFACET, FALSE);                                                                     
  2369.     }
  2370.     return hwndTarget;
  2371. }
  2372.  
  2373. #endif
  2374.  
  2375. //------------------------------------------------------------------------------
  2376. // ODFacet: AcquireWindowAggregateClipShape
  2377. //------------------------------------------------------------------------------
  2378.  
  2379. SOM_Scope ODShape*  SOMLINK ODFacetAcquireWindowAggregateClipShape(ODFacet *somSelf, Environment *ev,
  2380.        ODCanvas* biasCanvas)
  2381. {
  2382.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2383.     ODFacetMethodDebug("ODFacet","AcquireWindowAggregateClipShape");
  2384. #ifdef _FACET_DEBUG_
  2385.     qprintf("Executing ODFacet::AcquireWindowAggregateClipShape()\n");
  2386. #endif
  2387.  
  2388.     SOM_TRY
  2389.        ODFacet* parent = somSelf->GetContainingFacet(ev);
  2390.  
  2391.        if ( !_fWindowAggregateClipShape )
  2392.        {
  2393.            // Determine whether canvas is geometric or whether we can punt to regions: [jpa]
  2394. #ifdef _PLATFORM_MACINTOSH_
  2395.            ODGeometryMode mode = _fCanvas  ?GetCanvasGeometryMode(ev,_fCanvas)
  2396.                                            :kODLoseGeometry;
  2397. #endif   // _PLATFORM_MACINTOSH_
  2398.            _fWindowAggregateClipShape = ODCopyAndRelease(ev, somSelf->AcquireClipShape(ev, kNoBias));
  2399. #ifdef _PLATFORM_MACINTOSH_
  2400.            _fWindowAggregateClipShape->SetGeometryMode(ev,mode);
  2401. #endif   // _PLATFORM_MACINTOSH_
  2402.  
  2403.            if ( parent )
  2404.            {
  2405.                TempODShape parentClip = kODNULL;
  2406.                TempODTransform xform = kODNULL;
  2407.                parentClip = ODCopyAndRelease(ev, parent->AcquireWindowAggregateClipShape(ev, kNoBias));
  2408.                xform = ODCopyAndRelease(ev,
  2409.                    parent->GetFrame(ev)->AcquireInternalTransform(ev, kODNULL));
  2410.                if ( _fExternalTransform != kODNULL )
  2411.                    xform->PreCompose(ev, _fExternalTransform);
  2412.                parentClip->InverseTransform(ev, xform);
  2413.                _fWindowAggregateClipShape->Intersect(ev, parentClip);
  2414.            }
  2415.        }
  2416.        return BiasShapeGet(ev, _fWindowAggregateClipShape, biasCanvas);
  2417.     SOM_CATCH_ALL
  2418.     SOM_ENDTRY
  2419.     return kODNULL;
  2420. }
  2421.  
  2422. //------------------------------------------------------------------------------
  2423. // ODFacet: InvalidateAggregateClipShape
  2424. //------------------------------------------------------------------------------
  2425.  
  2426. SOM_Scope void  SOMLINK ODFacetInvalidateAggregateClipShape(ODFacet *somSelf, Environment *ev)
  2427. {
  2428.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2429.     ODFacetMethodDebug("ODFacet","InvalidateAggregateClipShape");
  2430.  
  2431. #ifdef _FACET_DEBUG_
  2432.     qprintf("Executing ODFacet::InvalidateAggregateClipShape()\n");
  2433. #endif
  2434.     SOM_TRY
  2435.        // flush aggregate clip shapes
  2436.        ODReleaseObject(ev, _fAggregateClipShape);
  2437.        ODReleaseObject(ev, _fWindowAggregateClipShape);
  2438.  
  2439.        // must flush cached border shape, as it is based on aggClipShape
  2440.        if ( _fActiveBorderShape != kODNULL )
  2441.            somSelf->InvalidateActiveBorder(ev);
  2442.  
  2443.        LinkedListIterator iter((LinkedList*)_fNode);
  2444.        for (FacetNode* node = (FacetNode*) iter.First();
  2445.                iter.IsNotComplete();
  2446.                node = (FacetNode*) iter.Next())
  2447.        {
  2448.            node->GetFacet()->InvalidateAggregateClipShape(ev);
  2449.        }
  2450.  
  2451. #ifdef _PLATFORM_OS2_
  2452.     somSelf->InvalidateActiveBorder(ev);
  2453. //#else
  2454. //    somSelf->DrawActiveBorder(ev);
  2455. #endif
  2456.  
  2457.     SOM_CATCH_ALL
  2458.     SOM_ENDTRY
  2459. }
  2460.  
  2461. //------------------------------------------------------------------------------
  2462. // ODFacet: AcquireActiveShape
  2463. //------------------------------------------------------------------------------
  2464.  
  2465. SOM_Scope ODShape*  SOMLINK ODFacetAcquireActiveShape(ODFacet *somSelf, Environment *ev,
  2466.        ODCanvas* biasCanvas)
  2467. {
  2468.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2469.     ODFacetMethodDebug("ODFacet","AcquireActiveShape");
  2470.  
  2471. #ifdef _FACET_DEBUG_
  2472.     qprintf("Executing ODFacet::AcquireActiveShape()\n");
  2473. #endif
  2474.     SOM_TRY
  2475.        if ( _fActiveShape )
  2476.            return BiasShapeGet(ev, _fActiveShape, biasCanvas);
  2477.        else
  2478.            return ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, biasCanvas));
  2479.     SOM_CATCH_ALL
  2480.     SOM_ENDTRY
  2481.     return kODNULL;
  2482. }
  2483.  
  2484. //------------------------------------------------------------------------------
  2485. // ODFacet: ChangeActiveShape
  2486. //------------------------------------------------------------------------------
  2487.  
  2488. SOM_Scope void  SOMLINK ODFacetChangeActiveShape(ODFacet *somSelf, Environment *ev,
  2489.        ODShape* activeShape,
  2490.        ODCanvas* biasCanvas)
  2491. {
  2492.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2493.     ODFacetMethodDebug("ODFacet","ChangeActiveShape");
  2494.  
  2495. #ifdef _FACET_DEBUG_
  2496.     qprintf("Executing ODFacet::ChangeActiveShape()\n");
  2497. #endif
  2498.     SOM_TRY
  2499.        if ( _fActiveBorderShape != kODNULL )
  2500.        {
  2501.            somSelf->InvalidateActiveBorder(ev);
  2502.            ODFacet* contFacet = somSelf->GetContainingFacet(ev);
  2503.            if ( contFacet != kODNULL )
  2504.            {
  2505.                TempODPart part = contFacet->GetFrame(ev)->AcquirePart(ev);
  2506.                part->AdjustBorderShape(ev, somSelf, kODNULL);
  2507.            }
  2508.        }
  2509.  
  2510.        ODAcquireObject(ev, activeShape);
  2511.        ODReleaseObject(ev, _fActiveShape);
  2512.        _fActiveShape = BiasShapeSet(ev, activeShape, biasCanvas);
  2513.  
  2514.  
  2515. #ifdef _PLATFORM_OS2_
  2516.         somSelf->InvalidateActiveBorder(ev);
  2517. //#else
  2518. //        somSelf->DrawActiveBorder(ev);
  2519. #endif
  2520.     SOM_CATCH_ALL
  2521.     SOM_ENDTRY
  2522. }
  2523.  
  2524. //------------------------------------------------------------------------------
  2525. // ODFrame: CreateTransform
  2526. //------------------------------------------------------------------------------
  2527.  
  2528. SOM_Scope ODTransform*  SOMLINK ODFacetCreateTransform(ODFacet *somSelf, Environment *ev)
  2529. {
  2530.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2531.     ODFacetMethodDebug("ODFacet","CreateTransform");
  2532.  
  2533. #ifdef _FACET_DEBUG_
  2534.     qprintf("Executing ODFacet::CreateTransform()\n");
  2535. #endif
  2536.     ODTransform *t = kODNULL;  ODVolatile(t);
  2537.  
  2538.     SOM_TRY
  2539.        t = new ODTransform;
  2540.        THROW_IF_NULL(t);
  2541.        t->InitTransform(ev);
  2542.     SOM_CATCH_ALL
  2543.        ODDeleteObject(t);
  2544.        t = kODNULL;
  2545.     SOM_ENDTRY
  2546.     return t;
  2547. }
  2548.  
  2549. //------------------------------------------------------------------------------
  2550. // ODFacet: AcquireExternalTransform
  2551. //------------------------------------------------------------------------------
  2552.  
  2553. SOM_Scope ODTransform*  SOMLINK ODFacetAcquireExternalTransform(ODFacet *somSelf, Environment *ev,
  2554.        ODCanvas* biasCanvas)
  2555. {
  2556.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2557.     ODFacetMethodDebug("ODFacet","AcquireExternalTransform");
  2558.  
  2559. #ifdef _FACET_DEBUG_
  2560.     qprintf("Executing ODFacet::AcquireExternalTransform()\n");
  2561. #endif
  2562.    ODTransform* xform = kODNULL;
  2563.  
  2564.     SOM_TRY
  2565.        if ( _fExternalTransform != kODNULL )
  2566.            xform = _fExternalTransform;
  2567.        else
  2568.            xform = somSelf->CreateTransform(ev);
  2569.        return BiasTransformGet(ev, xform, biasCanvas);
  2570.     SOM_CATCH_ALL
  2571.     SOM_ENDTRY
  2572.     return kODNULL;
  2573. }
  2574.  
  2575. //------------------------------------------------------------------------------
  2576. // ODFacet: AcquireFrameTransform
  2577. //------------------------------------------------------------------------------
  2578.  
  2579. SOM_Scope ODTransform*  SOMLINK ODFacetAcquireFrameTransform(ODFacet *somSelf, Environment *ev,
  2580.        ODCanvas* biasCanvas)
  2581. {
  2582.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2583.     ODFacetMethodDebug("ODFacet","AcquireFrameTransform");
  2584.  
  2585. #ifdef _FACET_DEBUG_
  2586.     qprintf("Executing ODFacet::AcquireFrameTransform()\n");
  2587. #endif
  2588.     SOM_TRY
  2589.        ODFacet* parent = somSelf->GetContainingFacet(ev);
  2590.  
  2591.        if ( !_fFrameTransform )
  2592.        {
  2593. #ifdef _PLATFORM_MACINTOSH_
  2594.            if ( _fCanvas )
  2595.            {
  2596.                if ( _fFrame->IsRoot(ev) && (_fExternalTransform != kODNULL) )
  2597.                    _fFrameTransform = _fExternalTransform->Copy(ev);
  2598.                else
  2599.                    _fFrameTransform = somSelf->CreateTransform(ev);
  2600.            }
  2601. #endif // _PLATFORM_MACINTOSH_
  2602.  
  2603. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  2604.            if ( _fCanvas )
  2605.            {
  2606.              if (_fExternalTransform != kODNULL)
  2607.                    _fFrameTransform = _fExternalTransform->Copy(ev);
  2608.              else
  2609.                  _fFrameTransform = somSelf->CreateTransform(ev);
  2610.  
  2611.                 if(!_fFrame->IsRoot(ev) )
  2612.                 {
  2613.                    if ( parent )
  2614.                    {
  2615.                      TempODTransform xform = parent->AcquireContentTransform(ev, kODNULL);
  2616.                      _fFrameTransform->PostCompose(ev, xform);
  2617.                      ODPoint offset;
  2618.  
  2619.                      TempODShape tshape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  2620.                      GetFacetPosition(ev, _fFrameTransform, tshape, offset);
  2621.                      _fFrameTransform->MoveBy(ev, &offset);
  2622.                     }
  2623.  
  2624.                 }
  2625.  
  2626.            }
  2627. #endif // _PLATFORM_WIN32_ || _PLATFORM_OS2_ || _PLATFORM_UNIX_
  2628.  
  2629.            else
  2630.            {
  2631.                if ( _fExternalTransform != kODNULL )
  2632.                    _fFrameTransform = _fExternalTransform->Copy(ev);
  2633.                else
  2634.                    _fFrameTransform = somSelf->CreateTransform(ev);
  2635.                if ( parent )
  2636.                {
  2637.                    TempODTransform xform = parent->AcquireContentTransform(ev, kODNULL);
  2638.                    _fFrameTransform->PostCompose(ev, xform);
  2639.                }
  2640.            }
  2641.        }
  2642.        return BiasTransformGet(ev, _fFrameTransform, biasCanvas);
  2643.     SOM_CATCH_ALL
  2644.     SOM_ENDTRY
  2645.     return kODNULL;
  2646. }
  2647.  
  2648. //------------------------------------------------------------------------------
  2649. // ODFacet: AcquireContentTransform
  2650. //------------------------------------------------------------------------------
  2651.  
  2652. SOM_Scope ODTransform*  SOMLINK ODFacetAcquireContentTransform(ODFacet *somSelf, Environment *ev,
  2653.        ODCanvas* biasCanvas)
  2654. {
  2655.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2656.     ODFacetMethodDebug("ODFacet","AcquireContentTransform");
  2657.  
  2658. #ifdef _FACET_DEBUG_
  2659.     qprintf("Executing ODFacet::AcquireContentTransform()\n");
  2660. #endif
  2661.     SOM_TRY
  2662.        if (!_fContentTransform)
  2663.        {
  2664.            _fContentTransform = ODCopyAndRelease(ev, _fFrame->AcquireInternalTransform(ev, kODNULL));
  2665.            TempODTransform xform = somSelf->AcquireFrameTransform(ev, kODNULL);
  2666.            _fContentTransform->PostCompose(ev, xform);
  2667.        }
  2668.        return BiasTransformGet(ev, _fContentTransform, biasCanvas);
  2669.     SOM_CATCH_ALL
  2670.     SOM_ENDTRY
  2671.     return kODNULL;
  2672. }
  2673.  
  2674. //------------------------------------------------------------------------------
  2675. // ODFacet: AcquireWindowFrameTransform
  2676. //------------------------------------------------------------------------------
  2677.  
  2678. SOM_Scope ODTransform*  SOMLINK ODFacetAcquireWindowFrameTransform(ODFacet *somSelf, Environment *ev,
  2679.        ODCanvas* biasCanvas)
  2680. {
  2681.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2682.     ODFacetMethodDebug("ODFacet","AcquireWindowFrameTransform");
  2683.  
  2684. #ifdef _FACET_DEBUG_
  2685.     qprintf("Executing ODFacet::AcuireWindowFrameTransform()\n");
  2686. #endif
  2687.     SOM_TRY
  2688.        ODFacet* parent = somSelf->GetContainingFacet(ev);
  2689.  
  2690.        if (!_fWindowFrameTransform)
  2691.        {
  2692.            if ( _fExternalTransform != kODNULL )
  2693.                _fWindowFrameTransform = _fExternalTransform->Copy(ev);
  2694.            else
  2695.                _fWindowFrameTransform = somSelf->CreateTransform(ev);
  2696.            if (parent)
  2697.            {
  2698.                TempODTransform xform = parent->AcquireWindowContentTransform(ev, kODNULL);
  2699.                _fWindowFrameTransform->PostCompose(ev, xform);
  2700.            }
  2701.        }
  2702.        return BiasTransformGet(ev, _fWindowFrameTransform, biasCanvas);
  2703.     SOM_CATCH_ALL
  2704.     SOM_ENDTRY
  2705.     return kODNULL;
  2706. }
  2707.  
  2708. //------------------------------------------------------------------------------
  2709. // ODFacet: AcquireWindowContentTransform
  2710. //------------------------------------------------------------------------------
  2711.  
  2712. SOM_Scope ODTransform*  SOMLINK ODFacetAcquireWindowContentTransform(ODFacet *somSelf, Environment *ev,
  2713.        ODCanvas* biasCanvas)
  2714. {
  2715.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2716.     ODFacetMethodDebug("ODFacet","AcquireWindowContentTransform");
  2717.  
  2718. #ifdef _FACET_DEBUG_
  2719.     qprintf("Executing ODFacet::AcquireWindowContentTransform()\n");
  2720. #endif
  2721.     SOM_TRY
  2722.        if (!_fWindowContentTransform)
  2723.        {
  2724.            _fWindowContentTransform = ODCopyAndRelease(ev, _fFrame->AcquireInternalTransform(ev, kODNULL));
  2725.            TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  2726.            _fWindowContentTransform->PostCompose(ev, xform);
  2727.        }
  2728.        return BiasTransformGet(ev, _fWindowContentTransform, biasCanvas);
  2729.     SOM_CATCH_ALL
  2730.     SOM_ENDTRY
  2731.     return kODNULL;
  2732. }
  2733.  
  2734. //------------------------------------------------------------------------------
  2735. // ODFacet: InternalTransformChanged
  2736. //------------------------------------------------------------------------------
  2737.  
  2738. SOM_Scope void  SOMLINK ODFacetInternalTransformChanged(ODFacet *somSelf, Environment *ev)
  2739. {
  2740.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2741.     ODFacetMethodDebug("ODFacet","InternalTransformChanged");
  2742.  
  2743. #ifdef _FACET_DEBUG_
  2744.     qprintf("Executing ODFacet::InternalTransformChanged()\n");
  2745. #endif
  2746.    ODFacetIterator* facets = kODNULL;  ODVolatile(facets);
  2747.    ODFacet* facet = kODNULL;
  2748.  
  2749.     SOM_TRY
  2750.        ODReleaseObject(ev, _fContentTransform);
  2751.        ODReleaseObject(ev, _fWindowContentTransform);
  2752.  
  2753.        // invalidate children
  2754.        LinkedListIterator iter((LinkedList*)_fNode);
  2755.        for (FacetNode* node = (FacetNode*) iter.First();
  2756.                iter.IsNotComplete();
  2757.                node = (FacetNode*) iter.Next())
  2758.        {
  2759.            node->GetFacet()->InvalidateAggregateClipShape(ev);
  2760.            node->GetFacet()->InvalidateAggregateTransforms(ev);
  2761.        }
  2762.  
  2763.        facets = somSelf->CreateFacetIterator(ev, kODTopDown, kODFrontToBack);
  2764.        for ( facet = facets->First(ev);
  2765.                facets->IsNotComplete(ev);
  2766.                facet = facets->Next(ev) )
  2767.        {
  2768.  
  2769. #ifdef _PLATFORM_UNIX_
  2770.               facet->SetFacetWidgetSize(ev);
  2771. #endif // _PLATFORM_UNIX_
  2772.  
  2773. #ifdef _EVERYTHING_IS_A_WINDOW_
  2774.                ODPlatformWindow hwnd;
  2775.                hwnd = facet->GetFacetHWND(ev);
  2776.                if (hwnd)
  2777.                {
  2778.                    // Move and position the window
  2779. #ifdef _PLATFORM_WIN32_
  2780.                    facet->SetFacetWindowPos(ev, hwnd, HWND_MOVE_THE_WINDOW);
  2781. #endif
  2782. #ifdef _PLATFORM_OS2_
  2783.                    facet->SetFacetWindowPos(ev, hwnd, 0);
  2784. #endif
  2785.                }
  2786. #endif   // EVERYTHING IS A WINDOW
  2787.  
  2788.            TempODPart tempPart = facet->GetFrame(ev)->AcquirePart(ev);
  2789.            tempPart->GeometryChanged(ev, facet, kODFalse, kODTrue);
  2790.        }
  2791.        ODDeleteObject(facets);
  2792.  
  2793.     SOM_CATCH_ALL
  2794.        ODDeleteObject(facets);
  2795.     SOM_ENDTRY
  2796. }
  2797.  
  2798. //------------------------------------------------------------------------------
  2799. // ODFacet: InvalidateAggregateTransforms
  2800. //------------------------------------------------------------------------------
  2801.  
  2802. SOM_Scope void  SOMLINK ODFacetInvalidateAggregateTransforms(ODFacet *somSelf, Environment *ev)
  2803. {
  2804.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2805.     ODFacetMethodDebug("ODFacet","InvalidateAggregateTransforms");
  2806.  
  2807. #ifdef _FACET_DEBUG_
  2808.     qprintf("Executing ODFacet::InvalidteAggregateTransforms()\n");
  2809. #endif
  2810.    SOM_TRY
  2811.        ODReleaseObject(ev, _fFrameTransform);
  2812.        ODReleaseObject(ev, _fContentTransform);
  2813.        ODReleaseObject(ev, _fWindowFrameTransform);
  2814.        ODReleaseObject(ev, _fWindowContentTransform);
  2815.  
  2816.        // invalidate children
  2817.        LinkedListIterator iter((LinkedList*)_fNode);
  2818.        for (FacetNode* node = (FacetNode*) iter.First();
  2819.                iter.IsNotComplete();
  2820.                node = (FacetNode*) iter.Next())
  2821.        {
  2822.            node->GetFacet()->InvalidateAggregateTransforms(ev);
  2823.        }
  2824.     SOM_CATCH_ALL
  2825.     SOM_ENDTRY
  2826. }
  2827.  
  2828. //------------------------------------------------------------------------------
  2829. // ODFacet: CreateCanvas
  2830. //------------------------------------------------------------------------------
  2831.  
  2832. SOM_Scope ODCanvas*  SOMLINK ODFacetCreateCanvas(ODFacet *somSelf, Environment *ev,
  2833.        ODGraphicsSystem graphicsSystem,
  2834. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  2835.     ODPlatformCanvas* platformCanvas,
  2836. #else
  2837.        ODPlatformCanvas platformCanvas,
  2838. #endif   // _PLATFORM_OS2_
  2839.        ODBoolean isDynamic,
  2840.        ODBoolean isOffscreen)
  2841. {
  2842.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2843.     ODFacetMethodDebug("ODFacet","CreateCanvas");
  2844.  
  2845. #ifdef _FACET_DEBUG_
  2846.     qprintf("Executing ODFacet::CreateCanvas()\n");
  2847. #endif
  2848.     ODCanvas *c = kODNULL;  ODVolatile(c);
  2849.  
  2850.     SOM_TRY
  2851.        c = new ODCanvas;
  2852.        THROW_IF_NULL(c);
  2853.        c->InitCanvas(ev, graphicsSystem,platformCanvas,isDynamic,isOffscreen);
  2854.     SOM_CATCH_ALL
  2855.        ODDeleteObject(c);
  2856.        c = kODNULL;
  2857.     SOM_ENDTRY
  2858.     return c;
  2859. }
  2860.  
  2861. //------------------------------------------------------------------------------
  2862. // ODFacet: HasCanvas
  2863. //------------------------------------------------------------------------------
  2864.  
  2865. SOM_Scope ODBoolean  SOMLINK ODFacetHasCanvas(ODFacet *somSelf, Environment *ev)
  2866. {
  2867.     ODFacetData *somThis = ODFacetGetData(somSelf);
  2868.     ODFacetMethodDebug("ODFacet","HasCanvas");
  2869.  
  2870. #ifdef _FACET_DEBUG_
  2871.     qprintf("Executing ODFacet::HasCanvas()\n");
  2872. #endif
  2873.    return (_fCanvas != kODNULL);
  2874. }
  2875.  
  2876. //------------------------------------------------------------------------------
  2877. // ODFacet: GetCanvas
  2878. //------------------------------------------------------------------------------
  2879.  
  2880. SOM_Scope ODCanvas*  SOMLINK ODFacetGetCanvas(ODFacet *somSelf, Environment *ev)
  2881. {
  2882.   ODFacetData *somThis = ODFacetGetData(somSelf);
  2883.   ODFacetMethodDebug("ODFacet","GetCanvas");
  2884.  
  2885. #ifdef _FACET_DEBUG_
  2886.     qprintf("Executing ODFacet::GetCanvas()\n");
  2887. #endif
  2888.   SOM_TRY
  2889.     if (_fCanvas)
  2890.          return _fCanvas;
  2891.     else                              // don't have a canvas, so search up thru Facet heirarchy
  2892.     {
  2893.       ODFacet* parent = somSelf->GetContainingFacet(ev);
  2894.       if (parent)                                        // If there is a parent Facet
  2895. #ifdef _PLATFORM_MACINTOSH_
  2896.       {
  2897.         return parent->GetCanvas(ev);                    // return it's Canvas (or it's parent's canvas)
  2898.       }
  2899. #endif  // _PLATFORM_MACINTOSH_
  2900.  
  2901. #ifdef _PLATFORM_UNIX_
  2902.       {
  2903.         ODCanvas* parentCanvas = parent->GetCanvas(ev);
  2904.         if(parentCanvas && parentCanvas->IsDynamic(ev) && !parentCanvas->IsOffscreen(ev))
  2905.         {
  2906.            Widget parentWidget = parent->GetFacetWidget(ev);
  2907.            if(parentWidget)
  2908.            {
  2909.               ODAIXWindowCanvas* newAIXCanvas = new ODAIXWindowCanvas;
  2910.               THROW_IF_NULL(newAIXCanvas);
  2911.               _fFacetWidget = somSelf->CreateFacetWidget(ev, parentWidget, newAIXCanvas);
  2912.               ODCanvas* newCanvas = somSelf->CreateCanvas(ev,
  2913.                                                           kODAIX,
  2914.                                                           newAIXCanvas,
  2915.                                                           kODTrue,    // IsDynamic?
  2916.                                                           kODFalse);  // IsOffscreen?
  2917.  
  2918.                _fCanvas = newCanvas;
  2919.                 if ( _fCanvas )
  2920.                 {
  2921.                   _fCanvas->SetFacet(ev, somSelf);                      // point back to this facet
  2922.                   TempODPart tempPart = _fFrame->AcquirePart(ev);            // Owner is new embedded Frame's part
  2923.                   _fCanvas->SetOwner(ev, tempPart);                                 // so that he can change it.
  2924.                 }
  2925.  
  2926.             }
  2927.  
  2928.                 return _fCanvas;
  2929.  
  2930.         }
  2931.         else
  2932.           return parentCanvas;
  2933.       }
  2934. #endif // _PLATFORM_UNIX_
  2935.  
  2936.  
  2937. // Don't use parent canvas if it is Dynamic Onscreen since
  2938. // a multi-threaded part would trap on sharing an hdc.  This
  2939. // only occurs if a part has removed a Dynamic Onscreen canvas thru a call to ChangeCanvas().
  2940. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_)
  2941.       {
  2942.         ODCanvas* parentCanvas = parent->GetCanvas(ev);
  2943.         if(parentCanvas && parentCanvas->IsDynamic(ev) && !parentCanvas->IsOffscreen(ev))
  2944.         {
  2945.           ODWindow* window = somSelf->GetWindow(ev);     // Use the client hwnd as parent
  2946.           if (window)
  2947.           {
  2948.              HWND facetHWND, hwndParent;
  2949. #ifdef _PLATFORM_WIN32_
  2950.              hwndParent = window->GetPlatformWindow(ev);
  2951. #endif
  2952.  
  2953. #ifdef _PLATFORM_OS2_
  2954.              hwndParent = WinWindowFromID(window->GetPlatformWindow(ev), FID_CLIENT);
  2955. #endif
  2956.              if(hwndParent)
  2957.                 facetHWND = somSelf->CreateFacetWindow(ev, hwndParent);
  2958.  
  2959. #ifdef _PLATFORM_OS2_
  2960.              ODOS2WindowCanvas* newWindowCanvas = new ODOS2WindowCanvas;
  2961.              THROW_IF_NULL(newWindowCanvas);
  2962.              newWindowCanvas->InitPlatformWindowCanvas(ev, facetHWND);
  2963. #endif // _PLATFORM_OS2_
  2964.  
  2965. #ifdef _PLATFORM_WIN32_
  2966.              ODWin32WindowCanvas* newWindowCanvas = new ODWin32WindowCanvas;
  2967.              THROW_IF_NULL(newWindowCanvas);
  2968.              newWindowCanvas->InitPlatformWindowCanvas(ev, facetHWND);
  2969. #endif // _PLATFORM_WIN32_
  2970.              ODCanvas* newCanvas = somSelf->CreateCanvas(ev,
  2971.                                                       #ifdef _PLATFORM_WIN32_
  2972.                                                               kODWin32,
  2973.                                                       #endif
  2974.                                                       #ifdef _PLATFORM_OS2_
  2975.                                                               kODPM,
  2976.                                                       #endif
  2977.                                                               newWindowCanvas,
  2978.                                                               kODTrue,    // IsDynamic?
  2979.                                                               kODFalse);  // IsOffscreen?
  2980.  
  2981.             _fCanvas = newCanvas;
  2982.  
  2983.             if ( _fCanvas )
  2984.             {
  2985.                _fCanvas->SetFacet(ev, somSelf);                      // point back to this facet
  2986.               TempODPart tempPart = _fFrame->AcquirePart(ev);            // Owner is new embedded Frame's part
  2987.               _fCanvas->SetOwner(ev, tempPart);                                 // so that he can change it.
  2988.              }  // _fCanvas
  2989.  
  2990.             } // window is valid
  2991.             return _fCanvas;
  2992.  
  2993.         } // parent canvas is On-Screen dynamic
  2994.         else
  2995.           return parentCanvas;
  2996.       }
  2997. #endif // _PLATFORM_WIN32_
  2998.  
  2999.       else
  3000.         THROW(kODErrCanvasNotFound);
  3001.  
  3002.     }
  3003.   SOM_CATCH_ALL
  3004.   SOM_ENDTRY
  3005.   return kODNULL;
  3006. }
  3007.  
  3008. SOM_Scope void  SOMLINK ODFacetChangeCanvas(ODFacet *somSelf, Environment *ev,
  3009.        ODCanvas* canvas)
  3010. {
  3011.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3012.     ODFacetMethodDebug("ODFacet","ChangeCanvas");
  3013.  
  3014. #ifdef _FACET_DEBUG_
  3015.     qprintf("Executing ODFacet::ChangeCanvas()\n");
  3016. #endif
  3017.    // I don't manage storage for the canvas - that's up to my part!
  3018.    ODFacetIterator* i = kODNULL;   ODVolatile(i);
  3019.     SOM_TRY
  3020.  
  3021. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  3022.      if(_fCanvas && _fCanvas->IsDynamic(ev) && (!_fCanvas->IsOffscreen(ev)) )
  3023.      {
  3024. #ifdef _PLATFORM_OS2_
  3025.        HWND hwnd = somSelf->GetFacetHWND(ev);
  3026.        if(hwnd)
  3027.           WinDestroyWindow(hwnd);
  3028.           _fFacetHWND = kODNULL;
  3029.  
  3030.        ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODPM);
  3031. #endif
  3032.  
  3033. #ifdef _PLATFORM_WIN32_
  3034.        HWND hwnd = somSelf->GetFacetHWND(ev);
  3035.        if(hwnd)
  3036.           DestroyWindow(hwnd);
  3037.  
  3038.        ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODWin32);
  3039. #endif
  3040.  
  3041. #ifdef _PLATFORM_UNIX_
  3042.          ODPlatformCanvas* platCanvas = _fCanvas->GetPlatformCanvas(ev, kODAIX);
  3043.          if (platCanvas->IsInitialized(ev))
  3044.          {
  3045.              GC gc = ((ODAIXWindowCanvas*)platCanvas)->GetGC(ev);
  3046.              XFreeGC(XtDisplay(_fFacetWidget), gc);
  3047.          }
  3048.  
  3049. // When facet gets deleted, then somUninit would destroy this widget.
  3050. //        if(_fFacetWidget)
  3051. //        {
  3052. //         XtDestroyWidget(_fFacetWidget);
  3053. //         _fFacetWidget = kODNULL;
  3054. //        }
  3055.  
  3056. #endif // _PLATFORM_UNIX_
  3057.  
  3058.          ODDeleteObject(platCanvas);             //  delete WindowCanvas
  3059.          ODDeleteObject(_fCanvas);               //  delete ODCanvas
  3060.      }
  3061.  
  3062. #endif // _PLATFORM_WIN32_ || _PLATFORM_OS2_ || _PLATFORM_UNIX_
  3063.  
  3064.        if ( canvas != kODNULL )
  3065.        {
  3066.            TempODPart owner = canvas->AcquireOwner(ev);
  3067.            if ( (ODPart*)owner == kODNULL )
  3068.                THROW(kODErrCanvasHasNoOwner);
  3069.        }
  3070.  
  3071.        i = new ODFacetIterator();
  3072.        THROW_IF_NULL(i);
  3073.        i->InitFacetIterator(ev, somSelf, kODTopDown, kODBackToFront);
  3074.  
  3075.        if ( _fCanvas )
  3076.            _fCanvas->SetFacet(ev, kODNULL);
  3077.        _fCanvas = canvas;
  3078.        if ( _fCanvas )
  3079.        {
  3080.            _fCanvas->SetFacet(ev, somSelf);        // point back to this facet
  3081.            TempODShape tempShape = _fFrame->AcquireFrameShape(ev, kODNULL);
  3082.            _fCanvas->Invalidate(ev, tempShape); // contents are initially invalid
  3083.        }
  3084.  
  3085.        somSelf->InvalidateAggregateClipShape(ev);
  3086.        somSelf->InvalidateAggregateTransforms(ev);
  3087.  
  3088.        ODBoolean notFirst = kODFalse;
  3089.        for (ODFacet* facet = i->First(ev); i->IsNotComplete(ev); facet = i->Next(ev))
  3090.        {
  3091. #ifdef _PLATFORM_MACINTOSH_
  3092.            if ( notFirst && facet->HasCanvas(ev) )
  3093. #endif
  3094.  
  3095. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  3096.                if ( facet->HasCanvas(ev) && facet->GetCanvas(ev)->IsOffscreen(ev))
  3097. #endif // OS2 || WIN32 || UNIX
  3098.                i->SkipChildren(ev);
  3099.            else
  3100.            {
  3101.                TempODPart tempPart = facet->GetFrame(ev)->AcquirePart(ev);
  3102.                tempPart->CanvasChanged(ev, somSelf);
  3103.            }
  3104.            notFirst = kODTrue;
  3105.        }
  3106.        ODDeleteObject(i);
  3107.     SOM_CATCH_ALL
  3108.        ODDeleteObject(i);
  3109.     SOM_ENDTRY
  3110. }
  3111.  
  3112. //------------------------------------------------------------------------------
  3113. // ODFacet: GetWindow
  3114. //------------------------------------------------------------------------------
  3115.  
  3116. SOM_Scope ODWindow*  SOMLINK ODFacetGetWindow(ODFacet *somSelf, Environment *ev)
  3117. {
  3118.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3119.     ODFacetMethodDebug("ODFacet","GetWindow");
  3120.  
  3121. #ifdef _FACET_DEBUG_
  3122.     qprintf("Executing ODFacet::GetWindow()\n");
  3123. #endif
  3124.    // this method returns fFrame's window.  getting the window from fFrame
  3125.    // automatically increments the window's refcount, but because the window
  3126.    // in an invariant of the facet we don't want to increment the refcount.
  3127.    // so after getting the window from the frame, release it to restore its
  3128.    // original refcount.
  3129.  
  3130.    ODWindow* window = kODNULL;
  3131.  
  3132.     SOM_TRY
  3133.        window = _fFrame->AcquireWindow(ev);
  3134.        if (window)
  3135.            window->Release(ev); // undo ref bump from frame->AcquireWindow;
  3136.        return window;
  3137.     SOM_CATCH_ALL
  3138.     SOM_ENDTRY
  3139.    return kODNULL;
  3140. }
  3141.  
  3142. //------------------------------------------------------------------------------
  3143. // ODFacet: GetPartInfo
  3144. //------------------------------------------------------------------------------
  3145.  
  3146. SOM_Scope ODInfoType  SOMLINK ODFacetGetPartInfo(ODFacet *somSelf, Environment *ev)
  3147. {
  3148.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3149.     ODFacetMethodDebug("ODFacet","GetPartInfo");
  3150.  
  3151. #ifdef _FACET_DEBUG_
  3152.     qprintf("Executing ODFacet::GetPartInfo()\n");
  3153. #endif
  3154.    return _fPartInfo;
  3155. }
  3156.  
  3157. SOM_Scope void  SOMLINK ODFacetSetPartInfo(ODFacet *somSelf, Environment *ev,
  3158.        ODInfoType partInfo)
  3159. {
  3160.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3161.     ODFacetMethodDebug("ODFacet","SetPartInfo");
  3162.  
  3163. #ifdef _FACET_DEBUG_
  3164.     qprintf("Executing ODFacet::SetPartInfo()\n");
  3165. #endif
  3166.    _fPartInfo = partInfo;
  3167. }
  3168.  
  3169. //------------------------------------------------------------------------------
  3170. // ODFacet: DragEnter
  3171. //------------------------------------------------------------------------------
  3172.  
  3173. SOM_Scope ODDragResult  SOMLINK ODFacetDragEnter(ODFacet *somSelf, Environment *ev,
  3174.        ODPoint* point,
  3175.        ODDragItemIterator* dragInfo,
  3176.        ODCanvas* biasCanvas)
  3177. {
  3178.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3179.     ODFacetMethodDebug("ODFacet","DragEnter");
  3180.  
  3181. #ifdef _FACET_DEBUG_
  3182.     qprintf("Executing ODFacet::DragEnter()\n");
  3183. #endif
  3184.     SOM_TRY
  3185.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  3186.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3187.        xform->InvertPoint(ev, &bPoint);
  3188.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  3189.        return tempPart->DragEnter(ev, dragInfo, somSelf, &bPoint);
  3190.     SOM_CATCH_ALL
  3191.     SOM_ENDTRY
  3192.    return kODFalse;
  3193. }
  3194.  
  3195. //------------------------------------------------------------------------------
  3196. // ODFacet: DragWithin
  3197. //------------------------------------------------------------------------------
  3198.  
  3199. SOM_Scope ODDragResult  SOMLINK ODFacetDragWithin(ODFacet *somSelf, Environment *ev,
  3200.        ODPoint* point,
  3201.        ODDragItemIterator* dragInfo,
  3202.        ODCanvas* biasCanvas)
  3203. {
  3204.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3205.     ODFacetMethodDebug("ODFacet","DragWithin");
  3206.  
  3207. #ifdef _FACET_DEBUG_
  3208.     qprintf("Executing ODFacet::DragWithin()\n");
  3209. #endif
  3210.     SOM_TRY
  3211.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  3212.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3213.        xform->InvertPoint(ev, &bPoint);
  3214.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  3215.        return tempPart->DragWithin(ev, dragInfo, somSelf, &bPoint);
  3216.     SOM_CATCH_ALL
  3217.     SOM_ENDTRY
  3218.    return kODFalse;
  3219. }
  3220.  
  3221. //------------------------------------------------------------------------------
  3222. // ODFacet: DragLeave
  3223. //------------------------------------------------------------------------------
  3224.  
  3225. SOM_Scope void  SOMLINK ODFacetDragLeave(ODFacet *somSelf, Environment *ev,
  3226.        ODPoint* point,
  3227.        ODCanvas* biasCanvas)
  3228. {
  3229.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3230.     ODFacetMethodDebug("ODFacet","DragLeave");
  3231.  
  3232. #ifdef _FACET_DEBUG_
  3233.     qprintf("Executing ODFacet::DragLeave()\n");
  3234. #endif
  3235.     SOM_TRY
  3236.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  3237.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3238.        xform->InvertPoint(ev, &bPoint);
  3239.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  3240.        tempPart->DragLeave(ev, somSelf, &bPoint);
  3241.     SOM_CATCH_ALL
  3242.     SOM_ENDTRY
  3243. }
  3244.  
  3245. //------------------------------------------------------------------------------
  3246. // ODFacet: Drop
  3247. //------------------------------------------------------------------------------
  3248.  
  3249. SOM_Scope ODDropResult  SOMLINK ODFacetDrop(ODFacet *somSelf, Environment *ev,
  3250.        ODPoint* point,
  3251.        ODDragItemIterator* dropInfo,
  3252.        ODCanvas* biasCanvas)
  3253. {
  3254.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3255.     ODFacetMethodDebug("ODFacet","Drop");
  3256.  
  3257. #ifdef _FACET_DEBUG_
  3258.     qprintf("Executing ODFacet::Drop()\n");
  3259. #endif
  3260.     SOM_TRY
  3261.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  3262.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3263.        xform->InvertPoint(ev, &bPoint);
  3264.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  3265.        return tempPart->Drop(ev, dropInfo, somSelf, &bPoint);
  3266.     SOM_CATCH_ALL
  3267.     SOM_ENDTRY
  3268.    return kODDropFail;
  3269. }
  3270.  
  3271. #ifdef _PLATFORM_OS2_
  3272. SOM_Scope ODShape* SOMLINK ODFacetAcquireUpdateShape(ODFacet *somSelf,
  3273.                                                      Environment *ev,
  3274.                                                      ODCanvas* biasCanvas)
  3275. {
  3276.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3277.     ODFacetMethodDebug("ODFacet","AcquireUpdateShape");
  3278.  
  3279. #ifdef _FACET_DEBUG_
  3280.     qprintf("Executing ODFacet::AcquireUpdateShape()\n");
  3281. #endif
  3282.     if (_fIsUpdating && _fUpdateShape)
  3283.     {
  3284.        return BiasShapeGet(ev, _fUpdateShape, biasCanvas);
  3285.     }
  3286.     else
  3287.     {
  3288.        ODFacet* containingFacet = somSelf->GetContainingFacet(ev);
  3289.        if (containingFacet)
  3290.           return containingFacet->AcquireUpdateShape(ev, biasCanvas);
  3291.     }
  3292.     return kODNULL;
  3293. }
  3294. #endif
  3295.  
  3296. //------------------------------------------------------------------------------
  3297. // ODFacet: Update
  3298. //------------------------------------------------------------------------------
  3299.  
  3300. SOM_Scope void  SOMLINK ODFacetUpdate(ODFacet *somSelf, Environment *ev,
  3301.        ODShape* invalidShape,
  3302.        ODCanvas* biasCanvas)
  3303. {
  3304.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3305.     ODFacetMethodDebug("ODFacet","Update");
  3306.  
  3307. #ifdef _FACET_DEBUG_
  3308.     qprintf("Executing ODFacet::Update()\n");
  3309. #endif
  3310.  
  3311. #ifdef _FACET_TIMING_
  3312.     unsigned int t1,t2,t3,t4;
  3313.     t1=RD_TSR();
  3314. #endif
  3315.    ODFacet*        facet = kODNULL;
  3316.    ODBoolean       notFirst = kODFalse;
  3317.  
  3318.    SOM_TRY
  3319.        _fIsUpdating = kODTrue;
  3320.  
  3321.        TempODShape bShape = kODNULL;
  3322.        if ( invalidShape == kODNULL )
  3323.            bShape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  3324.        else
  3325.            bShape = BiasShapeSet(ev, invalidShape->Copy(ev), biasCanvas);
  3326.  
  3327.        // transform bShape into window coords for intersection with
  3328.        // shapes of embedded facets
  3329.        TempODTransform wfXform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3330.        bShape->Transform(ev, wfXform);
  3331.  
  3332.        ODFacetIterator* i = new ODFacetIterator();
  3333.        THROW_IF_NULL(i);
  3334.        i->InitFacetIterator(ev, somSelf, kODTopDown, kODBackToFront);
  3335.  
  3336.  
  3337.        for (facet = i->First(ev); i->IsNotComplete(ev); facet = i->Next(ev))
  3338.        {
  3339.            TempODShape aggClipShape = facet->AcquireAggregateClipShape(ev, kODNULL);
  3340.            TempODShape testShape = aggClipShape->Copy(ev);
  3341.            TempODTransform xform = facet->AcquireWindowFrameTransform(ev, kODNULL);
  3342.            testShape->Transform(ev, xform);
  3343.  
  3344.            // both bShape and testShape are now in window coords
  3345.            testShape->Intersect(ev, bShape);
  3346.            if ( testShape->IsEmpty(ev) )
  3347.                i->SkipChildren(ev);
  3348.            else
  3349.            {
  3350.                facet->SetNeedsUpdate(ev, kODTrue);
  3351.  
  3352.                // if facet has its own canvas, and facet is not the root facet,
  3353.                // let the facet handle updating its children
  3354. #ifdef _PLATFORM_MACINTOSH_
  3355.                if ( facet->HasCanvas(ev) && notFirst )
  3356. #endif
  3357.  
  3358. #if (defined _PLATFORM_WIN32_ || defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_)
  3359.                if ( facet->HasCanvas(ev) && facet->GetCanvas(ev)->IsOffscreen(ev))
  3360. #endif  // WIN32 || OS2 || AIX
  3361.                    i->SkipChildren(ev);
  3362.            }
  3363. #ifdef _PLATFORM_MACINTOSH_
  3364.            notFirst = kODTrue;
  3365. #endif
  3366.        }
  3367.  
  3368.        for (facet = i->First(ev); i->IsNotComplete(ev); facet = i->Next(ev))
  3369.        {
  3370.            if ( facet->NeedsUpdate(ev) )
  3371.            {
  3372.                TempODShape testShape = bShape->Copy(ev);
  3373.                TempODTransform xform = facet->AcquireWindowFrameTransform(ev, kODNULL);
  3374.                testShape->InverseTransform(ev, xform);
  3375. #ifdef _PLATFORM_OS2_
  3376.                TempODShape AggClipShape = facet->AcquireAggregateClipShape(ev, kODNULL);
  3377.                 testShape->Intersect(ev, AggClipShape);
  3378. #endif // OS2
  3379. #ifdef _FACET_TIMING_
  3380.     t2=RD_TSR();
  3381. #endif
  3382.                facet->Draw(ev, testShape, kODNULL);
  3383. #ifdef _FACET_TIMING_
  3384.     t3=RD_TSR();
  3385.     qprintf("cycles to Draw facet needing update=%i\n",t3-t2);
  3386. #endif
  3387.            }
  3388.            else
  3389.                i->SkipChildren(ev);
  3390.        }
  3391.  
  3392.        _fIsUpdating = kODFalse;
  3393.  
  3394.        delete i;
  3395.     SOM_CATCH_ALL
  3396.     SOM_ENDTRY
  3397. #ifdef _FACET_TIMING_
  3398.     t4=RD_TSR();
  3399.     qprintf("cycles to execute ODFacet::UPdate=%i\n",t4-t1);
  3400. #endif
  3401. }
  3402.  
  3403. //------------------------------------------------------------------------------
  3404. // ODFacet: Invalidate
  3405. //------------------------------------------------------------------------------
  3406.  
  3407. SOM_Scope void  SOMLINK ODFacetInvalidate(ODFacet *somSelf, Environment *ev,
  3408.        ODShape* invalidShape,
  3409.        ODCanvas* biasCanvas)
  3410. {
  3411.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3412.     ODFacetMethodDebug("ODFacet","Invalidate");
  3413.  
  3414. #ifdef _FACET_DEBUG_
  3415.     qprintf("Executing ODFacet::Invalidate()\n");
  3416. #endif
  3417.    //  Assumes invalidShape is in frame coordinates.
  3418.  
  3419.    ODCanvas* myCanvas = kODNULL;
  3420.    ODFacet* myCanvasFacet = kODNULL;
  3421.    ODFacet* myContainingFacet = kODNULL;
  3422.    ODFacet* parentCanvasFacet = kODNULL;
  3423.  
  3424.    SOM_TRY
  3425.        ODWindow* window = somSelf->GetWindow(ev);
  3426.        if( !window )
  3427.            return;
  3428.  
  3429.        TempODShape tShape = ODCopyAndRelease(ev, somSelf->AcquireAggregateClipShape(ev, kODNULL));
  3430.  
  3431.        if ( invalidShape )
  3432.        {
  3433.            TempODShape bShape = BiasShapeSet(ev, invalidShape->Copy(ev), biasCanvas);
  3434.            tShape->Intersect(ev, bShape);
  3435.        }
  3436.  
  3437.        if( !tShape->IsEmpty(ev) )
  3438.        {
  3439.            myCanvas = somSelf->GetCanvas(ev);
  3440.            TempODTransform xf1 = somSelf->AcquireFrameTransform(ev, kODNULL);
  3441.            tShape->Transform(ev, xf1);
  3442.            myCanvas->Invalidate(ev, tShape);
  3443.            tShape->InverseTransform(ev, xf1);
  3444.  
  3445.  
  3446.            if ( myCanvas->IsOffscreen(ev) )
  3447.            {
  3448.                myCanvasFacet = myCanvas->GetFacet(ev);
  3449.                myContainingFacet = myCanvasFacet->GetContainingFacet(ev);
  3450.                if ( myContainingFacet )
  3451.                    parentCanvasFacet = myContainingFacet->GetCanvas(ev)->GetFacet(ev);
  3452.                else
  3453.                    THROW(kODErrFacetNotFound);
  3454.  
  3455.                TempODTransform xf2 = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3456.                tShape->Transform(ev, xf2);
  3457.                TempODTransform xf3 = parentCanvasFacet->AcquireWindowFrameTransform(ev, kODNULL);
  3458.                tShape->InverseTransform(ev, xf3);
  3459.                parentCanvasFacet->Invalidate(ev, tShape, kODNULL);
  3460.            }
  3461. #ifdef _PLATFORM_WIN32_  // SA
  3462.            else {  // on-screen Canvas
  3463.                  TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3464.                  tShape->Transform(ev, xform);
  3465.                  HWND hwnd = window->GetPlatformWindow(ev);
  3466.                  InvalidateRgn(hwnd, tShape->GetRegion(ev), FALSE);
  3467.                  }
  3468. #endif // _PLATFORM_WIN32_
  3469.  
  3470.  
  3471. #ifdef _PLATFORM_OS2_
  3472.            else {
  3473.                  TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3474.                  tShape->Transform(ev, xform);
  3475.                  HWND hwnd = WinWindowFromID(window->GetPlatformWindow(ev), FID_CLIENT);
  3476.                  WinInvalidateRegion(hwnd, tShape->GetRegion(ev), FALSE);
  3477.                  }
  3478. #endif // _PLATFORM_OS2_
  3479.  
  3480. #ifdef _PLATFORM_UNIX_
  3481.            else {
  3482.                    TempODTransform xform = ODCopyAndRelease(ev, somSelf->AcquireWindowFrameTransform(ev, kODNULL));
  3483.  
  3484.                    // Copy over the current tShape
  3485.                    TempODShape tShape2 = tShape->Copy(ev);
  3486.  
  3487.                    // Transform the shape - it's now in window coordinates.
  3488.                    // We'll need this in logic below.              
  3489.                    tShape2->Transform(ev, xform);
  3490.  
  3491.                    if(invalidShape)
  3492.                    {
  3493.                     ODPoint offset(0,0);
  3494.                     TempODShape FrameShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  3495.                     GetFacetPosition(ev, xform, FrameShape, offset);
  3496.  
  3497.                     xform->MoveBy(ev, &offset);
  3498.                    }
  3499.  
  3500.                    tShape->Transform(ev, xform);
  3501.                    ODRect odRect;
  3502.                    tShape->GetBoundingBox(ev, &odRect);
  3503.                    Rect xRect;
  3504.                    odRect.AsXRect(xRect);
  3505.  
  3506.                    if(!invalidShape)
  3507.                    {
  3508.                       xRect.x = 0;
  3509.                       xRect.y = 0;
  3510.                    }
  3511.  
  3512.                    if ( myCanvas->IsDynamic(ev) )
  3513.                    {
  3514.                        XClearArea(XtDisplay(_fFacetWidget),
  3515.                                 XtWindow(_fFacetWidget),
  3516.                                 xRect.x,
  3517.                                 xRect.y,
  3518.                                 xRect.width,
  3519.                                 xRect.height,
  3520.                                 True);
  3521.  
  3522.                        // AIX excludes the child widget regions from the
  3523.                        // clear above, so we have to invalidate the
  3524.                        // child facets explicitly.  This logic makes
  3525.                        // AIX consistent with Mac, OS/2 and NT. 
  3526.  
  3527.                        // For all the immediate embedded child facets
  3528.                        // of this facet
  3529.                        ODFacetIterator* i;
  3530.                        i = somSelf->CreateFacetIterator(ev, kODChildrenOnly,
  3531.                                                         kODBackToFront);
  3532.  
  3533.                        for (ODFacet *facet = i->First(ev);
  3534.                             i->IsNotComplete(ev);
  3535.                             facet = i->Next(ev))
  3536.                        {
  3537.                            // Acquire window frame transform of child
  3538.                            ODTransform *xform3;
  3539.                            xform3 = facet->AcquireWindowFrameTransform(ev,
  3540.                                                                        kODNULL);
  3541.  
  3542.                            // Copy over the tShape2 above. The tShape2 is
  3543.                            // already in window coordinates.
  3544.                            TempODShape tShape3 = tShape2->Copy(ev);
  3545.  
  3546.                            // Invert the shape to be in the embedded facet's
  3547.                            // frame coordinate system
  3548.                            xform3->InvertShape(ev, tShape3);
  3549.  
  3550.                            // Call the child facet's invalidate. There is no
  3551.                            // reason to check if the embedded facet's
  3552.                            // aggregateclipshape intersects with the invalid
  3553.                            // shape being passed in as that is performed first
  3554.                            // thing in the Invalidate method.  Having it here
  3555.                            // would be redundant code.
  3556.                            facet->Invalidate(ev, tShape3, biasCanvas);
  3557.                        }
  3558.  
  3559.                        // Delete the facet iterator
  3560.                        delete i;
  3561.                    }
  3562.            }
  3563. #endif // _PLATFORM_UNIX
  3564.        }  // Shape is NOT empty
  3565.     SOM_CATCH_ALL
  3566.     SOM_ENDTRY
  3567. }
  3568.  
  3569. //------------------------------------------------------------------------------
  3570. // ODFacet: Validate
  3571. //------------------------------------------------------------------------------
  3572.  
  3573. SOM_Scope void  SOMLINK ODFacetValidate(ODFacet *somSelf, Environment *ev,
  3574.        ODShape* validShape,
  3575.        ODCanvas* biasCanvas)
  3576. {
  3577.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3578.     ODFacetMethodDebug("ODFacet","Validate");
  3579.  
  3580. #ifdef _FACET_DEBUG_
  3581.     qprintf("Executing ODFacet::Validate()\n");
  3582. #endif
  3583.    //  Assumes validShape is in frame coordinates.
  3584.  
  3585.    ODCanvas* myCanvas = kODNULL;
  3586.    ODTransform* xform = kODNULL;
  3587.  
  3588.    SOM_TRY
  3589.        ODWindow* window = somSelf->GetWindow(ev);
  3590.        if( !window )
  3591.            return;
  3592.  
  3593.        TempODShape tShape = ODCopyAndRelease(ev, somSelf->AcquireAggregateClipShape(ev, kODNULL));
  3594.        if ( validShape )
  3595.        {
  3596.            TempODShape bShape = BiasShapeSet(ev, validShape->Copy(ev), biasCanvas);
  3597.            tShape->Intersect(ev, bShape);
  3598.        }
  3599.  
  3600.        if( !tShape->IsEmpty(ev) )
  3601.        {
  3602.            myCanvas = somSelf->GetCanvas(ev);
  3603.            TempODTransform xform = somSelf->AcquireFrameTransform(ev, kODNULL);
  3604.            tShape->Transform(ev, xform);
  3605.            myCanvas->Validate(ev, tShape);
  3606.  
  3607. #if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_)
  3608.            tShape->InverseTransform(ev, xform);
  3609.            TempODTransform x2form = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3610.            tShape->Transform(ev, x2form);
  3611. #endif
  3612.  
  3613. #ifdef _PLATFORM_OS2_
  3614.            HWND hwnd = WinWindowFromID(window->GetPlatformWindow(ev), FID_CLIENT);
  3615.            WinValidateRegion(hwnd, tShape->GetRegion(ev), TRUE);
  3616. #endif // _PLATFORM_OS2_
  3617.  
  3618. #ifdef _PLATFORM_WIN32_
  3619.            HWND hwnd = window->GetPlatformWindow(ev);
  3620.            ValidateRgn(hwnd, tShape->GetRegion(ev));
  3621. #endif // _PLATFORM_WIN32_
  3622.        }
  3623.  
  3624.  
  3625.     SOM_CATCH_ALL
  3626.     SOM_ENDTRY
  3627. }
  3628.  
  3629. //------------------------------------------------------------------------------
  3630. // ODFacet: Draw
  3631. //------------------------------------------------------------------------------
  3632.  
  3633. SOM_Scope void  SOMLINK ODFacetDraw(ODFacet *somSelf, Environment *ev,
  3634.        ODShape* invalidShape,
  3635.        ODCanvas* biasCanvas)
  3636. {
  3637.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3638.     ODFacetMethodDebug("ODFacet","Draw");
  3639.  
  3640. #ifdef _FACET_DEBUG_
  3641.     qprintf("Executing ODFacet::Draw()\n");
  3642. #endif
  3643.    SOM_TRY
  3644.        TempODShape bShape = kODNULL;
  3645.        if ( invalidShape == kODNULL )
  3646.            bShape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  3647.        else
  3648.            bShape = BiasShapeSet(ev, invalidShape->Copy(ev), biasCanvas);
  3649.  
  3650.        if ( _fCanvas && !_fIsUpdating && _fCanvas->IsOffscreen(ev) )
  3651.        {
  3652.            // repair canvas if needs updating
  3653.            TempODShape testShape = bShape->Copy(ev);
  3654.            TempODShape updateShape = _fCanvas->AcquireUpdateShape(ev);
  3655.            testShape->Intersect(ev, updateShape);
  3656.  
  3657.            if ( !testShape->IsEmpty(ev) )
  3658.            {
  3659.                // fix offscreen canvas
  3660.                somSelf->Update(ev, bShape, kODNULL);
  3661.            }
  3662.  
  3663.            // tell canvas owner part to copy pixels
  3664.            TempODPart owner = _fCanvas->AcquireOwner(ev);
  3665.            owner->CanvasUpdated(ev, _fCanvas);
  3666.        }
  3667.        else
  3668.        {
  3669.            TempODPart tempPart = _fFrame->AcquirePart(ev);
  3670.            tempPart->Draw(ev, somSelf, bShape);
  3671.        }
  3672.        _fNeedsUpdate = kODFalse;
  3673.     SOM_CATCH_ALL
  3674.     SOM_ENDTRY
  3675. }
  3676.  
  3677. //------------------------------------------------------------------------------
  3678. // ODFacet: DrawChildren
  3679. //------------------------------------------------------------------------------
  3680.  
  3681. SOM_Scope void  SOMLINK ODFacetDrawChildren(ODFacet *somSelf, Environment *ev,
  3682.        ODShape* invalidShape,
  3683.        ODCanvas* biasCanvas)
  3684. {
  3685.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3686.     ODFacetMethodDebug("ODFacet","DrawChildren");
  3687.  
  3688. #ifdef _FACET_DEBUG_
  3689.     qprintf("Executing ODFacet::DrawChildren()\n");
  3690. #endif
  3691.    SOM_TRY
  3692.        TempODShape bShape = kODNULL;
  3693.        if ( invalidShape == kODNULL )
  3694.            bShape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  3695.        else
  3696.            bShape = BiasShapeSet(ev, invalidShape->Copy(ev), biasCanvas);
  3697.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3698.        bShape->Transform(ev, xform);
  3699.  
  3700.        ODFacetIterator* i = new ODFacetIterator;
  3701.        THROW_IF_NULL(i);
  3702.        i->InitFacetIterator(ev, somSelf, kODChildrenOnly, kODBackToFront);
  3703.  
  3704.        for ( ODFacet* child = i->First(ev); i->IsNotComplete(ev); child = i->Next(ev) )
  3705.        {
  3706.            if ( child->NeedsUpdate(ev) )
  3707.            {
  3708.                TempODTransform xf2 = child->AcquireWindowFrameTransform(ev, kODNULL);
  3709.                TempODShape tempShape = bShape->Copy(ev);
  3710.                tempShape->InverseTransform(ev, xf2);
  3711.                child->Draw(ev, tempShape, kODNULL);
  3712.                child->DrawChildren(ev, tempShape, kODNULL);
  3713.            }
  3714.        }
  3715.        ODDeleteObject(i);
  3716.     SOM_CATCH_ALL
  3717.     SOM_ENDTRY
  3718. }
  3719.  
  3720. //------------------------------------------------------------------------------
  3721. // ODFacet: DrawChildrenAlways
  3722. //------------------------------------------------------------------------------
  3723.  
  3724. SOM_Scope void  SOMLINK ODFacetDrawChildrenAlways(ODFacet *somSelf, Environment *ev,
  3725.        ODShape* invalidShape,
  3726.        ODCanvas* biasCanvas)
  3727. {
  3728.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3729.     ODFacetMethodDebug("ODFacet","DrawChildrenAlways");
  3730.  
  3731. #ifdef _FACET_DEBUG_
  3732.     qprintf("Executing ODFacet::DrawChildrenAlways()\n");
  3733. #endif
  3734.    SOM_TRY
  3735.        TempODShape bShape = kODNULL;
  3736.        if ( invalidShape == kODNULL )
  3737.            bShape = ODCopyAndRelease(ev, _fFrame->AcquireFrameShape(ev, kODNULL));
  3738.        else
  3739.            bShape = BiasShapeSet(ev, invalidShape->Copy(ev), biasCanvas);
  3740.        TempODTransform xf1 = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3741.        bShape->Transform(ev, xf1);
  3742.  
  3743.        ODFacetIterator* i = new ODFacetIterator;
  3744.        THROW_IF_NULL(i);
  3745.        i->InitFacetIterator(ev, somSelf, kODChildrenOnly, kODBackToFront);
  3746.  
  3747.        for ( ODFacet* child = i->First(ev); i->IsNotComplete(ev); child = i->Next(ev) )
  3748.        {
  3749.            TempODTransform xf2 = child->AcquireWindowFrameTransform(ev, kODNULL);
  3750.            TempODShape tempShape = bShape->Copy(ev);
  3751.            tempShape->InverseTransform(ev, xf2);
  3752.            child->Draw(ev, tempShape, kODNULL);
  3753.            child->DrawChildrenAlways(ev, tempShape, kODNULL);
  3754.        }
  3755.        ODDeleteObject(i);
  3756.     SOM_CATCH_ALL
  3757.     SOM_ENDTRY
  3758. }
  3759.  
  3760. //------------------------------------------------------------------------------
  3761. // ODFacet: InvalidateActiveBorder
  3762. //------------------------------------------------------------------------------
  3763. SOM_Scope void  SOMLINK ODFacetInvalidateActiveBorder(ODFacet *somSelf, Environment *ev)
  3764. {
  3765.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3766.     ODFacetMethodDebug("ODFacet","InvalidateActiveBorder");
  3767.  
  3768. #ifdef _FACET_DEBUG_
  3769.     qprintf("Executing ODFacet::InvalidateActiveBorder()\n");
  3770. #endif
  3771.    SOM_TRY
  3772.  
  3773. #ifdef _PLATFORM_UNIX_
  3774.       if(_fActiveBorderWidget)
  3775.       {
  3776.         ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  3777.         Widget parentWidget = parentFacet->GetFacetWidget(ev);
  3778.         XUnmapWindow(XtDisplay(parentWidget), XtWindow(_fActiveBorderWidget) );
  3779.         XtDestroyWidget(_fActiveBorderWidget);
  3780.         _fActiveBorderWidget = kODNULL;
  3781.  
  3782.       }
  3783. #endif
  3784.  
  3785.        if ( _fActiveBorderShape != kODNULL )
  3786.        {
  3787.            ODInvalidateBorder(ev, _fActiveBorderShape, somSelf);
  3788.            ODReleaseObject(ev, _fActiveBorderShape);
  3789.        }
  3790.     SOM_CATCH_ALL
  3791.     SOM_ENDTRY
  3792. }
  3793.  
  3794. //------------------------------------------------------------------------------
  3795. // ODFacet: DrawActiveBorder
  3796. //------------------------------------------------------------------------------
  3797. SOM_Scope void  SOMLINK ODFacetDrawActiveBorder(ODFacet *somSelf, Environment *ev)
  3798. {
  3799.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3800.     ODFacetMethodDebug("ODFacet","DrawActiveBorder");
  3801.  
  3802. #ifdef _FACET_DEBUG_
  3803.     qprintf("Executing ODFacet::DrawActiveBorder()\n");
  3804. #endif
  3805.  
  3806.    SOM_TRY
  3807.        ODFacet* contFacet = kODNULL;
  3808.        TempODPart contPart = kODNULL;
  3809.        TempODShape border = kODNULL;
  3810.        TempODShape scratch = kODNULL;
  3811.        TempODShape adjusted = kODNULL;
  3812.        TempODShape clip = kODNULL;
  3813.        TempODTransform xform = kODNULL;
  3814.        TempODTransform xform2 = kODNULL;
  3815.        TempODTransform xform3 = kODNULL;
  3816.  
  3817.        if ( _fActiveBorderShape == kODNULL )
  3818.        {
  3819.            // compute border shape
  3820.            contFacet = somSelf->GetContainingFacet(ev);
  3821.            if ( contFacet )
  3822.            {
  3823.                contPart = contFacet->GetFrame(ev)->AcquirePart(ev);
  3824.                border = ODCopyAndRelease(ev, somSelf->AcquireActiveShape(ev, kNoBias));
  3825.                xform = ODCopyAndRelease(ev, somSelf->AcquireWindowFrameTransform(ev, kNoBias));
  3826.                xform2 = contFacet->AcquireWindowFrameTransform(ev, kNoBias);
  3827.                border->Transform(ev, xform);
  3828.                border->SetGeometryMode(ev, kODLoseGeometry);
  3829.                scratch = border->Copy(ev);
  3830.  
  3831.                border->Outset(ev, ODIntToFixed(4));
  3832.                border->Subtract(ev, scratch);
  3833.                ODReleaseObject(ev, scratch);
  3834.  
  3835.                border->InverseTransform(ev, xform);
  3836.                adjusted = contPart->AdjustBorderShape(ev, somSelf, border);
  3837.                THROW_IF_NULL(adjusted);
  3838.                ODReleaseObject(ev, border);
  3839.  
  3840.                if ( adjusted->IsEmpty(ev) )
  3841.                {
  3842.                    // compute as inset
  3843.                    scratch = ODCopyAndRelease(ev, contFacet->GetFrame(ev)->AcquireUsedShape(ev, kNoBias));
  3844.                    scratch->Transform(ev, xform2);
  3845.                    border = ODCopyAndRelease(ev, somSelf->AcquireActiveShape(ev, kNoBias));
  3846.                    border->Transform(ev, xform);
  3847.                    border->Subtract(ev, scratch);
  3848.                    if ( !border->IsEmpty(ev) )
  3849.                    {
  3850.                        ODReleaseObject(ev, adjusted);
  3851.                        ODReleaseObject(ev, border);
  3852.                        border = scratch->Copy(ev);
  3853.                        scratch->Outset(ev, ODIntToFixed(-4));
  3854.                        border->Subtract(ev, scratch);
  3855.                        ODReleaseObject(ev, scratch);
  3856.  
  3857.                        border->InverseTransform(ev, xform);
  3858.                        adjusted = contPart->AdjustBorderShape(ev, somSelf, border);
  3859.                        THROW_IF_NULL(adjusted);
  3860.                        ODReleaseObject(ev, border);
  3861.                    }
  3862.                    else
  3863.                    {
  3864.                        ODReleaseObject(ev, border);
  3865.                        ODReleaseObject(ev, scratch);
  3866.                    }
  3867.                }
  3868.  
  3869.                // clip to containing facet's visible area
  3870.                clip = ODCopyAndRelease(ev,
  3871.                    contFacet->AcquireWindowAggregateClipShape(ev, kNoBias));
  3872.  
  3873.  
  3874. #ifdef _PLATFORM_MACINTOSH_
  3875.                xform3 = ODCopyAndRelease(ev,
  3876.                    contFacet->GetFrame(ev)->AcquireInternalTransform(ev, kNoBias));
  3877.                if ( _fExternalTransform != kODNULL )
  3878.                    xform3->PreCompose(ev, _fExternalTransform);
  3879.                clip->InverseTransform(ev, xform3);
  3880. #endif // _PLATFORM_MACINTOSH_
  3881.  
  3882. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_WIN32_ || defined _PLATFORM_UNIX_)
  3883.             TempODTransform xform3 = xform2->Copy(ev)->Invert(ev);
  3884.             xform3->PreCompose(ev, xform);
  3885.             clip->InverseTransform(ev, xform3);
  3886. #endif  // _PLATFORM_OS2_  || _PLATFORM_WIN32_ || _PLATFORM_UNIX_
  3887.  
  3888.  
  3889.                adjusted->Intersect(ev, clip);
  3890.  
  3891. #ifdef _PLATFORM_WIN32_
  3892.           ODPoint parentPt1(0,0);
  3893.           TempODShape FrameShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  3894.           GetFacetPosition(ev, xform2, FrameShape, parentPt1);
  3895.           xform->MoveBy(ev, &parentPt1);
  3896. #endif
  3897.                adjusted->Transform(ev, xform);
  3898.                adjusted->Acquire(ev);  // because TempODShape releases on scope exit
  3899.                _fActiveBorderShape = adjusted;
  3900.            }
  3901.        }
  3902.  
  3903.        ODWindow* window = somSelf->GetWindow(ev);
  3904.        if ( _fActiveBorderShape && window && window->IsShown(ev) )
  3905.        {
  3906. #ifdef _PLATFORM_UNIX_
  3907.           if ( !_fActiveBorderWidget )
  3908.                   somSelf->CreateActiveBorderWidget(ev);
  3909.  
  3910.           XtRealizeWidget(_fActiveBorderWidget);
  3911.  
  3912.           ODFacet* parentFacet=somSelf->GetContainingFacet(ev);
  3913.           Widget parentWidget = parentFacet->GetFacetWidget(ev);
  3914.  
  3915.           // use the border "donut" shape to surround this facet
  3916.           TempODShape tmp = _fActiveBorderShape->Copy(ev);
  3917.           Region borderRegion = tmp->GetRegion(ev);
  3918.  
  3919.           Position x, y;
  3920.           XtVaGetValues(_fActiveBorderWidget,
  3921.                         XmNx, &x,
  3922.                         XmNy, &y,
  3923.                         NULL);
  3924.  
  3925.           XOffsetRegion(borderRegion, -x, -y);
  3926.  
  3927.           XShapeCombineRegion(XtDisplay(parentWidget),
  3928.                                   XtWindow(_fActiveBorderWidget),
  3929.                                   ShapeBounding,
  3930.                                   0, 0,
  3931.                                   borderRegion,
  3932.                                   ShapeSet);
  3933.  
  3934.           // make active border visible
  3935.             XtMapWidget(_fActiveBorderWidget);
  3936.  
  3937. #else
  3938.            ODDrawBorder(ev, _fActiveBorderShape, somSelf);
  3939. #endif
  3940.        }
  3941.     SOM_CATCH_ALL
  3942.     SOM_ENDTRY
  3943. }
  3944.  
  3945. //------------------------------------------------------------------------------
  3946. // ODFacet: DrawnIn
  3947. //------------------------------------------------------------------------------
  3948.  
  3949. SOM_Scope void  SOMLINK ODFacetDrawnIn(ODFacet *somSelf, Environment *ev,
  3950.        ODShape* shape,
  3951.        ODCanvas* biasCanvas)
  3952. {
  3953.     ODFacetData *somThis = ODFacetGetData(somSelf);
  3954.     ODFacetMethodDebug("ODFacet","DrawnIn");
  3955.  
  3956. #ifdef _FACET_DEBUG_
  3957.     qprintf("Executing ODFacet::DrawnIn()\n");
  3958. #endif
  3959.    // invalidate shape on my parent canvas to ensure that changed
  3960.    // pixels get copied to it.
  3961.  
  3962.    ODCanvas* myCanvas = kODNULL;
  3963.    ODFacet* myCanvasFacet = kODNULL;
  3964.    ODFacet* containingFacet = kODNULL;
  3965.    ODFacet* parentCanvasFacet = kODNULL;
  3966.  
  3967.    SOM_TRY
  3968.        // since the shape has been drawn in, it can now be marked as valid
  3969.        somSelf->Validate(ev, shape, biasCanvas);
  3970.  
  3971.        myCanvas = somSelf->GetCanvas(ev);
  3972.  
  3973.        // don't need to worry about on-screen canvas - it's the window
  3974.        if ( !myCanvas->IsOffscreen(ev) )
  3975.            return;
  3976.  
  3977.        TempODShape tShape = ODCopyAndRelease(ev, somSelf->AcquireAggregateClipShape(ev, kODNULL));
  3978.        if ( shape )
  3979.        {
  3980.            TempODShape bShape = BiasShapeSet(ev, shape->Copy(ev), biasCanvas);
  3981.            tShape->Intersect(ev, bShape);
  3982.        }
  3983.  
  3984.        myCanvasFacet = myCanvas->GetFacet(ev);
  3985.        containingFacet = myCanvasFacet->GetContainingFacet(ev);
  3986.        if ( containingFacet )
  3987.            parentCanvasFacet = containingFacet->GetCanvas(ev)->GetFacet(ev);
  3988.        else
  3989.            THROW(kODErrFacetNotFound);
  3990.  
  3991.        TempODTransform xform = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  3992.        tShape->Transform(ev, xform);
  3993.        ODReleaseObject(ev, xform);
  3994.        xform = parentCanvasFacet->AcquireWindowFrameTransform(ev, kODNULL);
  3995.        tShape->InverseTransform(ev, xform);
  3996.  
  3997.        // since stuff was drawn on my canvas, invalidate my parent canvas
  3998.        // so that that content will get copied there.
  3999.        parentCanvasFacet->Invalidate(ev, tShape, kODNULL);
  4000.  
  4001.        // notify my canvas' owner that drawing has occurred, and pixels
  4002.        // need to be copied to the parent canvas
  4003.        TempODPart owner = myCanvas->AcquireOwner(ev);
  4004.        WASSERTMSG( owner != kODNULL, "Facet::DrawnIn - no owner for canvas",0);
  4005.        owner->CanvasUpdated(ev, myCanvas);
  4006.     SOM_CATCH_ALL
  4007.     SOM_ENDTRY
  4008. }
  4009.  
  4010. //------------------------------------------------------------------------------
  4011. // ODFacet: ContainsPoint
  4012. //------------------------------------------------------------------------------
  4013.  
  4014. SOM_Scope ODBoolean  SOMLINK ODFacetContainsPoint(ODFacet *somSelf, Environment *ev,
  4015.        ODPoint* point,
  4016.        ODCanvas* biasCanvas)
  4017. {
  4018.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4019.     ODFacetMethodDebug("ODFacet","ContainsPoint");
  4020.  
  4021. #ifdef _FACET_DEBUG_
  4022.     qprintf("Executing ODFacet::ContainsPoint()\n");
  4023. #endif
  4024.    ODBoolean result = kODFalse;    ODVolatile(result);
  4025.  
  4026.    SOM_TRY
  4027.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  4028.        if ( _fActiveShape || _fClipShape )
  4029.            result = ((!_fActiveShape || _fActiveShape->ContainsPoint(ev, &bPoint))
  4030.                     && (!_fClipShape || _fClipShape->ContainsPoint(ev, &bPoint)));
  4031.        else
  4032.        {
  4033.            TempODShape frameShape = _fFrame->AcquireFrameShape(ev, kNoBias);
  4034.            result = frameShape->ContainsPoint(ev, &bPoint);
  4035.        }
  4036.    SOM_CATCH_ALL
  4037.        result = kODFalse;
  4038.    SOM_ENDTRY
  4039.  
  4040.    return result;
  4041. }
  4042.  
  4043. //------------------------------------------------------------------------------
  4044. // ODFacet: ActiveBorderContainsPoint
  4045. //------------------------------------------------------------------------------
  4046.  
  4047. SOM_Scope ODBoolean  SOMLINK ODFacetActiveBorderContainsPoint(ODFacet *somSelf, Environment *ev,
  4048.        ODPoint* point,
  4049.        ODCanvas* biasCanvas)
  4050. {
  4051.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4052.     ODFacetMethodDebug("ODFacet","ActiveBorderContainsPoint");
  4053.  
  4054. #ifdef _FACET_DEBUG_
  4055.     qprintf("Executing ODFacet::ActiveBorderContainsPoint()\n");
  4056. #endif
  4057.    if ( _fActiveBorderShape == kODNULL )
  4058.        return kODFalse;
  4059.  
  4060.    SOM_TRY
  4061.        ODPoint bPoint = BiasPointSet(ev, point, biasCanvas);
  4062.  
  4063. #if (defined _PLATFORM_OS2_ || defined _PLATFORM_UNIX_ || defined _PLATFORM_MACINTOSH_)
  4064.        // transform point to window coordinates
  4065.        TempODTransform winToFrame = somSelf->AcquireWindowFrameTransform(ev, kODNULL);
  4066. #endif // MACINTOSH or OS2
  4067.  
  4068. #ifdef _PLATFORM_WIN32_
  4069.        TempODTransform winToFrame = ODCopyAndRelease(ev, somSelf->AcquireWindowFrameTransform(ev, kODNULL));
  4070.        ODFacet* parentFacet = somSelf->GetContainingFacet(ev);
  4071.        TempODTransform conXform= parentFacet->AcquireWindowFrameTransform(ev, kODNULL);
  4072.  
  4073.        ODPoint offset(0,0);
  4074.        TempODShape FrameShape = ODCopyAndRelease(ev,  _fFrame->AcquireFrameShape(ev, kODNULL));
  4075.        GetFacetPosition(ev, conXform, FrameShape, offset);
  4076.  
  4077.        winToFrame->MoveBy(ev, &offset);
  4078. #endif  // WIN32
  4079.  
  4080.        ODPoint framePoint = bPoint;
  4081.        winToFrame->TransformPoint(ev, &framePoint);
  4082.  
  4083.        return _fActiveBorderShape->ContainsPoint(ev, &framePoint);
  4084.    SOM_CATCH_ALL
  4085.    SOM_ENDTRY
  4086.    return kODFalse;
  4087. }
  4088.  
  4089. //------------------------------------------------------------------------------
  4090. // ODFacet: IsSelected
  4091. //------------------------------------------------------------------------------
  4092.  
  4093. SOM_Scope ODBoolean  SOMLINK ODFacetIsSelected(ODFacet *somSelf, Environment *ev)
  4094. {
  4095.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4096.     ODFacetMethodDebug("ODFacet","IsSelected");
  4097.  
  4098. #ifdef _FACET_DEBUG_
  4099.     qprintf("Executing ODFacet::IsSelected()\n");
  4100. #endif
  4101.    return _fIsSelected;
  4102. }
  4103.  
  4104. //------------------------------------------------------------------------------
  4105. // ODFacet: SetSelected
  4106. //------------------------------------------------------------------------------
  4107.  
  4108. SOM_Scope void  SOMLINK ODFacetSetSelected(ODFacet *somSelf, Environment *ev,
  4109.        ODBoolean isSelected)
  4110. {
  4111.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4112.     ODFacetMethodDebug("ODFacet","SetSelected");
  4113.  
  4114. #ifdef _FACET_DEBUG_
  4115.     qprintf("Executing ODFacet::SetSelected()\n");
  4116. #endif
  4117.    _fIsSelected = isSelected;
  4118. }
  4119.  
  4120. //------------------------------------------------------------------------------
  4121. // ODFacet: GetHighlight
  4122. //------------------------------------------------------------------------------
  4123.  
  4124. SOM_Scope ODHighlight  SOMLINK ODFacetGetHighlight(ODFacet *somSelf, Environment *ev)
  4125. {
  4126.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4127.     ODFacetMethodDebug("ODFacet","GetHighlight");
  4128.  
  4129. #ifdef _FACET_DEBUG_
  4130.     qprintf("Executing ODFacet::GetHighlight()\n");
  4131. #endif
  4132.    return _fHighlight;
  4133. }
  4134.  
  4135. //------------------------------------------------------------------------------
  4136. // ODFacet: ChangeHighlight
  4137. //------------------------------------------------------------------------------
  4138.  
  4139. SOM_Scope void  SOMLINK ODFacetChangeHighlight(ODFacet *somSelf, Environment *ev,
  4140.        ODHighlight highlight)
  4141. {
  4142.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4143.     ODFacetMethodDebug("ODFacet","ChangeHighlight");
  4144.  
  4145. #ifdef _FACET_DEBUG_
  4146.     qprintf("Executing ODFacet::ChangeHighlight()\n");
  4147. #endif
  4148.    SOM_TRY
  4149.        _fHighlight = highlight;
  4150.        TempODPart tempPart = _fFrame->AcquirePart(ev);
  4151.        tempPart->HighlightChanged(ev, somSelf);
  4152.    SOM_CATCH_ALL
  4153.    SOM_ENDTRY
  4154. }
  4155.  
  4156. //------------------------------------------------------------------------------
  4157. // ODFacet: GetNode
  4158. //------------------------------------------------------------------------------
  4159.  
  4160. SOM_Scope FacetNode*  SOMLINK ODFacetGetNode(ODFacet *somSelf, Environment *ev)
  4161. {
  4162.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4163.     ODFacetMethodDebug("ODFacet","GetNode");
  4164.  
  4165. #ifdef _FACET_DEBUG_
  4166.     qprintf("Executing ODFacet::GetNode()\n");
  4167. #endif
  4168.    return _fNode;
  4169. }
  4170.  
  4171. //------------------------------------------------------------------------------
  4172. // ODFacet: NeedsUpdate
  4173. //------------------------------------------------------------------------------
  4174.  
  4175. SOM_Scope ODBoolean  SOMLINK ODFacetNeedsUpdate(ODFacet *somSelf, Environment *ev)
  4176. {
  4177.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4178.     ODFacetMethodDebug("ODFacet","NeedsUpdate");
  4179.  
  4180. #ifdef _FACET_DEBUG_
  4181.     qprintf("Executing ODFacet::NeedsUpdate()\n");
  4182. #endif
  4183.    return _fNeedsUpdate;
  4184. }
  4185.  
  4186. //------------------------------------------------------------------------------
  4187. // ODFacet: SetNeedsUpdate
  4188. //------------------------------------------------------------------------------
  4189.  
  4190. SOM_Scope void  SOMLINK ODFacetSetNeedsUpdate(ODFacet *somSelf, Environment *ev,
  4191.        ODBoolean needsUpdate)
  4192. {
  4193.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4194.     ODFacetMethodDebug("ODFacet","SetNeedsUpdate");
  4195.  
  4196. #ifdef _FACET_DEBUG_
  4197.     qprintf("Executing ODFacet::SetNeedsUpdate()\n");
  4198. #endif
  4199.    _fNeedsUpdate = needsUpdate;
  4200. }
  4201.  
  4202. #ifdef _PLATFORM_OS2_
  4203.  
  4204. //------------------------------------------------------------------------------
  4205. // ODFacet: SetHandleMouseEvents
  4206. //------------------------------------------------------------------------------
  4207.  
  4208. SOM_Scope void  SOMLINK ODFacetSetHandleMouseEvents(ODFacet *somSelf,
  4209.                                                     Environment *ev,
  4210.                                                     ODULong flags)
  4211. {
  4212.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4213.     ODFacetMethodDebug("ODFacet","SetHandleMouseEvents");
  4214.  
  4215. #ifdef _FACET_DEBUG_
  4216.     qprintf("Executing ODFacet::SetHandleMouseEvents()\n");
  4217. #endif
  4218.     _fPartHandlesMouseEvents = flags;
  4219. }
  4220.  
  4221. //------------------------------------------------------------------------------
  4222. // ODFacet: GetHandleMouseEvents
  4223. //------------------------------------------------------------------------------
  4224.  
  4225. SOM_Scope ODULong  SOMLINK ODFacetGetHandleMouseEvents(ODFacet *somSelf,
  4226.                                                        Environment *ev)
  4227. {
  4228.     ODFacetData *somThis = ODFacetGetData(somSelf);
  4229.     ODFacetMethodDebug("ODFacet","GetHandleMouseEvents");
  4230.  
  4231. #ifdef _FACET_DEBUG_
  4232.     qprintf("Executing ODFacet::GetHandleMouseEvents()\n");
  4233. #endif
  4234.     return _fPartHandlesMouseEvents;
  4235. }
  4236.  
  4237. SOM_Scope ODFacet*  SOMLINK M_ODFacetclsGetFacetFromHWND(M_ODFacet *somSelf, Environment *ev,
  4238.     HWND hwnd)
  4239. {
  4240.     M_ODFacetMethodDebug("M_ODFacet","clsODFacetFromHWND");
  4241.  
  4242. #ifdef _FACET_DEBUG_
  4243.     qprintf("Executing M_ODFacet::clsODFacetFromHWND()\n");
  4244. #endif
  4245.     CHAR  achBuffer[sizeof(szFacetWinClassName)+1];
  4246.     ODFacet* facet;
  4247.  
  4248.     LONG lRetLen = WinQueryClassName(hwnd, sizeof(achBuffer), (PCH)achBuffer);
  4249.     if (lRetLen == strlen(pszFacetWinClass) &&
  4250.         !strcmp(achBuffer, pszFacetWinClass)) {
  4251.  
  4252.       facet = (ODFacet*)WinQueryWindowPtr(hwnd, QWL_USER);
  4253.     } else {
  4254.       facet = kODNULL;
  4255.     }
  4256.     return facet;
  4257. }
  4258.  
  4259.  
  4260.  
  4261.  
  4262. //------------------------------------------------------------------------------
  4263. // Facet window procedure
  4264. //------------------------------------------------------------------------------
  4265. MRESULT EXPENTRY fnwpFacetWindow ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  4266. {
  4267.    ODBoolean handled = kODFalse;
  4268.    ODEventData event;
  4269.    ODEventInfo eventInfo;
  4270.    Environment* ev = somGetGlobalEnvironment();
  4271.    FacetWndData* pData;
  4272.    ULONG cx, cy;
  4273.    CHAR  achBuffer[sizeof(szFacetWinClassName)+1];
  4274.    HWND hwndChild;
  4275.    LONG lRetLen;
  4276.  
  4277.    MRESULT result = 0;
  4278.  
  4279.    switch (msg) {
  4280.  
  4281.    case WM_CREATE:
  4282.       {
  4283.         handled = kODTrue;
  4284.         FacetWndCtlData* pCtlData = (FacetWndCtlData*)mp1;
  4285.  
  4286.         // Do some sanity checking
  4287.         if (!(pCtlData->self && somIsObj(pCtlData->self) &&
  4288.               pCtlData->self->somIsA(_ODFacet)))
  4289.         {
  4290.           result = (MRESULT)kODTrue;    // Creation failed
  4291.           break;
  4292.         }
  4293.         pData = new FacetWndData;
  4294.         pData->facet = pCtlData->self;
  4295.  
  4296.         TRY
  4297.           pData->frame = pData->facet->GetFrame(ev);
  4298.           pData->part = pData->frame->AcquirePart(ev);
  4299.           HWND hwndFrame = pData->facet->GetWindow(ev)->GetPlatformWindow(ev);
  4300.           pData->hwndClient = WinWindowFromID(hwndFrame, FID_CLIENT);
  4301.         CATCH_ALL
  4302.           result = (MRESULT)kODTrue;    // Creation failed
  4303.           delete pData;
  4304.           break;
  4305.         ENDTRY
  4306.         WinSetWindowPtr(hwnd, QWL_USER,                   (PVOID)pData->facet); // For ref by others
  4307.         WinSetWindowPtr(hwnd, QWP_FACETWINDOWDATA,        (PVOID)pData);
  4308.         WinSetWindowPtr(hwnd, QWL_HITTESTFACET,           0);                   // For comm with std disp mod
  4309.         WinSetWindowPtr(hwnd, QWL_PARTHANDLESMOUSEEVENTS, 0);
  4310.         WinSetWindowPtr(hwnd, QWL_FACETWINDOWRGN,         0);
  4311.         break;
  4312.       }
  4313.  
  4314.    case WM_DESTROY:
  4315.      {
  4316.       pData = (FacetWndData*)WinQueryWindowPtr(hwnd, QWP_FACETWINDOWDATA);
  4317.       ODReleaseObject( ev, pData->part );
  4318.       delete pData;
  4319.       handled = kODTrue;
  4320.       break;
  4321.      }
  4322.  
  4323.    case WM_HITTEST:
  4324.      {
  4325.       if (WinQueryWindowULong(hwnd, QWL_HITTESTFACET))
  4326.          return (MRESULT)HT_NORMAL;
  4327.       else
  4328.          return (MRESULT)HT_TRANSPARENT;
  4329.      }
  4330.      break;
  4331.  
  4332.    case WM_PAINT:
  4333.       {
  4334.        WinEndPaint(WinBeginPaint(hwnd, 0, 0));
  4335.        handled = kODTrue;
  4336.        break;
  4337.       }
  4338.  
  4339.    case WM_CHAR:
  4340.      {
  4341.       pData = (FacetWndData*)WinQueryWindowPtr(hwnd, QWP_FACETWINDOWDATA);
  4342.       return WinSendMsg(pData->hwndClient, msg, mp1, mp2);
  4343.      }
  4344.  
  4345.    case WM_ADJUSTWINDOWPOS:
  4346.    case WM_WINDOWPOSCHANGED:
  4347.    case WM_SHOW:
  4348.    case WM_CALCVALIDRECTS:
  4349.    case WM_SIZE:
  4350.    case WM_MOUSEMOVE:
  4351.       break;
  4352.  
  4353.    default:
  4354.       pData = (FacetWndData*)WinQueryWindowPtr(hwnd, QWP_FACETWINDOWDATA);
  4355.       {
  4356.          event.hwnd  = hwnd;
  4357.          event.msg   = msg;
  4358.          event.mp1   = mp1;
  4359.          event.mp2   = mp2;
  4360.  
  4361.          TRY
  4362.             handled = pData->part->HandleEvent(ev, &event, pData->frame,
  4363.                                                            pData->facet,
  4364.                                                            kODNULL);
  4365.          CATCH_ALL
  4366.             handled = kODFalse;
  4367.  
  4368. //#ifdef _UNICODE_
  4369. //            WinLoadString( WinQueryAnchorBlock(HWND_DESKTOP), NULLHANDLE,
  4370. //                           OD_OPENDOCEXCEPTION, sizeof(szMsg1), szMsg1);
  4371. //            char fmtstring[Str255];
  4372. //            strcpy(fmtstring, szMsg1);
  4373. //            int bufsize = strlen(fmtstring) + strlen(ErrorMessage()) + sizeof(__FUNCTION__) + 11;
  4374. //#else
  4375.             static const char fmtstring[] = "OpenDoc Exception %d caught in %s\n\n%s";
  4376.             int bufsize = sizeof(fmtstring) + strlen(ErrorMessage()) + sizeof(__FUNCTION__) + 11;
  4377. //#endif  // _UNICODE
  4378.             char* buffer = new char[bufsize];
  4379.             if (buffer)
  4380.                sprintf(buffer, fmtstring, ErrorCode(), __FUNCTION__, ErrorMessage());
  4381.             WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, buffer ? buffer : "Out of memory!!!", "Error",
  4382.                           0, MB_OK | MB_ERROR | MB_APPLMODAL | MB_MOVEABLE);
  4383.             delete[] buffer;
  4384.             WinPostMsg(hwnd, WM_QUIT, 0, 0);
  4385.          ENDTRY
  4386.       }
  4387.       break;
  4388.    }
  4389.    if (handled)
  4390.       return result;
  4391.    else
  4392.       return WinDefWindowProc(hwnd, msg, mp1, mp2);
  4393. }
  4394. #endif   // _PLATFORM_OS2_
  4395.  
  4396. #ifdef _PLATFORM_WIN32_
  4397. SOM_Scope ODFacet*  SOMLINK M_ODFacetclsGetFacetFromHWND(M_ODFacet *somSelf, Environment *ev,
  4398.                                                          HWND hwnd)
  4399. {
  4400.     M_ODFacetMethodDebug("M_ODFacet","clsODFacetFromHWND");
  4401.  
  4402. #ifdef _FACET_DEBUG_
  4403.     qprintf("Executing M_ODFacet::clsODFacetFromHWND()\n");
  4404. #endif
  4405.     CHAR  achBuffer[sizeof(szFacetWinClassName)+1];
  4406.     ODFacet* facet;
  4407.  
  4408.     int lRetLen = GetClassName(hwnd, (LPSTR)achBuffer, sizeof(achBuffer));
  4409.     if (lRetLen == strlen(pszFacetWinClass) &&
  4410.         !strcmp(achBuffer, pszFacetWinClass)) {
  4411.  
  4412.         facet = (ODFacet*)GetWindowLong(hwnd, QWL_FACETPTR);
  4413.     } else {
  4414.       facet = kODNULL;
  4415.     }
  4416.     return facet;
  4417. }
  4418.  
  4419. //------------------------------------------------------------------------------
  4420. // Facet window procedure
  4421. //------------------------------------------------------------------------------
  4422. LRESULT CALLBACK fnwpFacetWindow ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  4423. {
  4424.    ODBoolean handled = kODFalse;
  4425.    ODEventData event;
  4426.    ODEventInfo eventInfo;
  4427.    Environment* ev = somGetGlobalEnvironment();
  4428.    FacetWndData* pData;
  4429.    ULONG cx, cy;
  4430.    CHAR  achBuffer[sizeof(szFacetWinClassName)+1];
  4431.    HWND hwndChild;
  4432.    LONG lRetLen;
  4433.  
  4434.    LRESULT result = 0;
  4435.  
  4436.    switch (msg) {
  4437.  
  4438.    // Don't send to part's HandleEvent() method.
  4439.  
  4440.    case WM_NCCREATE:                 // Before WM_CREATE
  4441.    case WM_NCCALCSIZE:               // Before WM_CREATE
  4442.    case WM_NCDESTROY:                // After WM_DESTROY
  4443.    case WM_WINDOWPOSCHANGING:
  4444.    case WM_WINDOWPOSCHANGED:
  4445.    case WM_SHOWWINDOW:
  4446.    case WM_SIZE:
  4447.    case WM_MOUSEMOVE:
  4448.         break;
  4449.  
  4450.    case WM_CREATE:
  4451.       {
  4452.         handled = kODTrue;
  4453.         FacetWndCtlData* pCtlData = (FacetWndCtlData*)(((LPCREATESTRUCT) lParam)->lpCreateParams);
  4454.  
  4455.         // Do some sanity checking
  4456.         if (!(pCtlData->self && somIsObj(pCtlData->self) &&
  4457.               pCtlData->self->somIsA(_ODFacet)))
  4458.         {
  4459.           result = kODTrue;    // Creation failed
  4460.           break;
  4461.         }
  4462.         pData = new FacetWndData;
  4463.         pData->facet = pCtlData->self;
  4464.  
  4465.         TRY
  4466.           pData->frame = pData->facet->GetFrame(ev);
  4467.           pData->part = pData->frame->AcquirePart(ev);
  4468.         CATCH_ALL
  4469.           result = kODTrue;    // Creation failed
  4470.           delete pData;
  4471.           break;
  4472.         ENDTRY
  4473.         SetWindowLong(hwnd, QWL_FACETPTR,               (LONG) pData->facet); // For ref by others
  4474.         SetWindowLong(hwnd, QWP_FACETWINDOWDATA,        (LONG) pData);
  4475.         SetWindowLong(hwnd, QWL_HITTESTFACET,           0L);  // For comm with std disp mod
  4476.         SetWindowLong(hwnd, QWL_PARTHANDLESMOUSEEVENTS, 0L);
  4477.         SetWindowLong(hwnd, QWL_FACETWINDOWRGN,         0L);  // not used on NT
  4478.        }
  4479.        break;
  4480.    case WM_DESTROY:
  4481.       pData = (FacetWndData*)GetWindowLong(hwnd, QWP_FACETWINDOWDATA);
  4482.       ODReleaseObject( ev, pData->part );
  4483.       delete pData;
  4484.       handled = kODTrue;
  4485.       break;
  4486.  
  4487.  
  4488.    case WM_PAINT:
  4489.       {
  4490.          RECT uRect;
  4491.  
  4492.          if(GetUpdateRect(hwnd, &uRect, FALSE))
  4493.          {
  4494.            HWND parenthwnd;
  4495.            pData = (FacetWndData*)GetWindowLong(hwnd, QWP_FACETWINDOWDATA);
  4496.  
  4497.            if(pData->frame->IsRoot(ev))
  4498.            {
  4499.              parenthwnd = GetParent(hwnd);
  4500.            }
  4501.            else
  4502.            {
  4503.              ODWindow* window = pData->frame->AcquireWindow(ev);
  4504.              if(window)
  4505.              {
  4506.                window->Release(ev);
  4507.                parenthwnd = window->GetPlatformWindow(ev);
  4508.                MapWindowPoints(hwnd, parenthwnd, (LPPOINT)&uRect, 2);
  4509.              }
  4510.            }
  4511.  
  4512.            InvalidateRect(parenthwnd, &uRect, FALSE);
  4513.            PAINTSTRUCT paintStruct;
  4514.            BeginPaint(hwnd, &paintStruct);
  4515.            EndPaint(hwnd, &paintStruct);
  4516.  
  4517.            handled = kODTrue;
  4518.          }
  4519.       }
  4520.       break;
  4521.  
  4522.   case WM_ERASEBKGND:
  4523.         return (LRESULT)TRUE;
  4524.  
  4525.   case WM_NCHITTEST:
  4526.      {
  4527.   // In Windows, even though parent window is transparent
  4528.   // controls like PUSHBUTTON still receive the events.
  4529.   //    if (GetWindowLong(hwnd, QWL_HITTESTFACET))
  4530.   //        return (LRESULT)HTCLIENT;
  4531.   //    else
  4532.             return (LRESULT)HTTRANSPARENT;
  4533.       }
  4534.       break;
  4535.  
  4536.    // This is done to ensure that the message goes through the Dispatcher
  4537.    // so that the part that owns the keyboard focus gets it.
  4538.    case WM_CHAR:
  4539.       pData = (FacetWndData*)GetWindowLong(hwnd, QWP_FACETWINDOWDATA);
  4540.       return SendMessage(pData->hwndClient, msg, wParam, lParam);
  4541.  
  4542.    default:
  4543.       // send the message to part's HandleEvent() method.
  4544.       pData = (FacetWndData*)GetWindowLong(hwnd, QWP_FACETWINDOWDATA);
  4545.       {
  4546.          event.hwnd    = hwnd;
  4547.          event.message = msg;
  4548.          event.wParam  = wParam;
  4549.          event.lParam  = lParam;
  4550.          TRY
  4551.             handled = pData->part->HandleEvent(ev, &event, pData->frame,
  4552.                                                            pData->facet,
  4553.                                                            kODNULL);
  4554.          CATCH_ALL
  4555.             handled = kODFalse;
  4556.             ASSERT(handled, ErrorCode() );
  4557.  
  4558.          ENDTRY
  4559.       }
  4560.       break;
  4561.    }
  4562.    if (handled)
  4563.       return result;
  4564.    else
  4565.       return DefWindowProc(hwnd, msg, wParam, lParam);
  4566. }
  4567. #endif // _PLATFORM_WIN32_
  4568.