home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / shape / iodshape.cpp next >
Text File  |  1997-04-02  |  29KB  |  865 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odshapepart
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. /* @(#) 1.26 com/src/samples/shape/iodshape.cpp, odshapepart, od96os2, odos29712d 3/11/97 17:27:37 [3/21/97 17:45:38] */
  28. /*
  29.  *  This file was generated by the SOM Compiler and Emitter Framework.
  30.  *  Generated using:
  31.  *      SOM Emitter emitxtm.dll: Development
  32.  */
  33.  
  34. #ifndef SOM_Module_shapeprt_Source
  35. #define SOM_Module_shapeprt_Source
  36. #endif
  37. #define ShapePart_Class_Source
  38. #define M_ShapePart_Class_Source
  39.  
  40. // som macro for using "_" with instance data
  41. #define VARIABLE_MACROS
  42.  
  43. // definition for class name; use it for adding HELP menu
  44. #define kShapeClassName "ShapePart"
  45.  
  46. #include "iodshpe.h"                    // message catalog includes.
  47.  
  48. // Include ODExcept.h before OpenDoc SOM headers
  49. #include <ODExcept.h>
  50.  
  51. #include <ODTypesF.h>
  52. #include <tempobj.h>
  53. #include <PlatCanv.xh>
  54.  
  55. #ifdef _PLATFORM_OS2_
  56. #include <OS2PCanv.xh>
  57. #include <OS2WCanv.xh>
  58. #include <ODos2.h>
  59. #endif //_PLATFORM_OS2_
  60.  
  61. #ifndef SOM_ODCanvas_xh
  62. #include <Canvas.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODFacet_xh
  66. #include <Facet.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODFrame_xh
  70. #include <Frame.xh>
  71. #endif
  72.  
  73. #ifndef SOM_ODFrameFacetIterator_xh
  74. #include <FrFaItr.xh>
  75. #endif
  76.  
  77. #ifndef SOM_ODSession_xh
  78. #include <ODSessn.xh>
  79. #endif
  80.  
  81. #ifndef SOM_ODShape_xh
  82. #include <Shape.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODUndo_xh
  86. #include <Undo.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODStorageUnit_xh
  90. #include <StorageU.xh>
  91. #endif
  92.  
  93. #ifndef SOM_ODWindowState_xh
  94. #include <WinStat.xh>
  95. #endif
  96.  
  97. #ifndef SOM_ODMenubar_xh
  98. #include <MenuBar.xh>
  99. #endif
  100.  
  101. #ifndef SOM_ODDraft_xh
  102. #include <Draft.xh>
  103. #endif
  104.  
  105. #if defined (_PLATFORM_OS2_) || defined (_PLATFORM_WIN32_)
  106. #include <focuslib.h>
  107. #endif
  108.  
  109. #ifndef _ITEXT_
  110. #include <IText.h>
  111. #endif
  112.  
  113. #ifndef _BARRAY_
  114. #include <BArray.h>
  115. #endif
  116.  
  117. #ifndef _IODLINK_
  118. #include <iodlink.xh>
  119. #endif
  120.  
  121. #ifndef SOM_ODHelp_xh
  122. #include <odhelp.xh>
  123. #endif
  124.  
  125. #include <StdProps.xh>
  126. #include <StdTypes.xh>
  127.  
  128. #ifndef _STDTYPIO_
  129. #include <StdTypIO.h>
  130. #endif
  131.  
  132. #include "ODResrc.h"
  133. #include "iodshape.h"
  134. #include "iodshape.xih"
  135. #include <ODDebug.h>
  136.  
  137. #ifdef _PLATFORM_OS2_
  138. #include "os2plat.cpp"
  139. #endif
  140.  
  141. SOM_Scope void  SOMLINK ShapePartsomInit(ShapePart *somSelf)
  142. {
  143.     ShapePartData *somThis = ShapePartGetData(somSelf);
  144.     ShapePartMethodDebug("ShapePart","ShapePartsomInit");
  145.  
  146.     ShapePart_parent_SimplePart_somInit(somSelf);
  147.     somThis->fSession = kODNULL;
  148.     somThis->fPartWrapper = kODNULL;
  149. }
  150.  
  151. SOM_Scope void  SOMLINK ShapePartsomUninit(ShapePart *somSelf)
  152. {
  153.     ShapePartData *somThis = ShapePartGetData(somSelf);
  154.     ShapePartMethodDebug("ShapePart","ShapePartsomUninit");
  155.  
  156.     ShapePart_parent_SimplePart_somUninit(somSelf);
  157. }
  158.  
  159. SOM_Scope void  SOMLINK ShapePartCommonInit(ShapePart *somSelf,
  160.                                             Environment *ev,
  161.                                             ODPart* partWrapper)
  162. {
  163.     ShapePartData *somThis = ShapePartGetData(somSelf);
  164.     ShapePartMethodDebug("ShapePart","ShapePartCommonInit");
  165.  
  166.     try
  167.     {
  168.     ShapePart_parent_SimplePart_CommonInit(somSelf, ev, partWrapper);
  169.     somThis->fSession = somSelf->GetStorageUnit(ev)->GetSession(ev);
  170.     somThis->fPartWrapper = partWrapper;
  171.  
  172.     ODMenuBar *menuBar = somSelf->GetMenuBar(ev);
  173.  
  174.     if (menuBar) {
  175.  
  176.        menuBar->Acquire(ev);
  177.  
  178.        // Add menu item for background color
  179.        ODPlatformMenuItem *mi = new ODPlatformMenuItem;
  180.        // clear the memory
  181.        memset (mi, 0, sizeof(ODPlatformMenuItem));
  182.  
  183.        mi->id = kShapePartBGColorMenuID;
  184.        menuBar->AddMenuItemLast(ev, IDMS_EDIT, kODNULL, mi);
  185.  
  186. #if defined(__IBMCPP__) || defined(_IBMR2)
  187.        nl_catd msgCatalog;       // NLS message catalog handle
  188.        char *menuText;           // pointer for NLS message
  189.  
  190.        setlocale(LC_MESSAGES, NULL);
  191.        msgCatalog = catopen(SHAPE_MSG_CATALOG, 0);
  192.        if(msgCatalog == CATD_ERR)
  193.        {
  194.          PRINT("Could not open message catalog %s\n", SHAPE_MSG_CATALOG);
  195.        }
  196. #else
  197.        char menuText[256];
  198. #endif
  199.  
  200.        // Set text of Background Color menu item
  201. #if defined(__IBMCPP__) || defined(_IBMR2)
  202.        menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_COLORMENU, SHAPE_DEFMSG_COLORMENU);
  203. #else
  204.        strcpy(menuText, SHAPE_DEFMSG_COLORMENU);
  205. #endif
  206.        menuBar->SetMenuItemText (ev, IDMS_EDIT, mi->id, menuText);
  207.  
  208.  
  209.        //let's add help menu items ONLY if this is base container
  210.        // and not its subclass
  211.        if (!strcmp (somSelf->somGetClassName(), kShapeClassName))
  212.        {
  213.           // we add the menu items that simple part did not add since
  214.           // this is a subclass
  215.  
  216.           // add a menu separator line to the HELP menu
  217.           mi->id = kSimplePartMenuSeparator;
  218. #if defined(_PLATFORM_WIN32_)
  219.           mi->afAttribute=MF_SEPARATOR;
  220. #elif defined(_PLATFORM_OS2_)
  221.           mi->afAttribute=CA_TITLESEPARATOR;
  222. #endif
  223.           menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);
  224.  
  225.           // add shape part help menu
  226.           mi->afAttribute=0;
  227.           mi->id = kSimplePartHelpMenu;
  228.           menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);
  229.  
  230. #if defined(__IBMCPP__) || defined(_IBMR2)
  231.           menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_HELPMENU, SHAPE_DEFMSG_HELPMENU);
  232. #else
  233.           strcpy(menuText, SHAPE_DEFMSG_HELPMENU);
  234. #endif
  235.           menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartHelpMenu, menuText);
  236.  
  237.  
  238.           // add shape part info menu
  239.           mi->id = kSimplePartInfoMenu;
  240.           menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);
  241.  
  242. #if defined(__IBMCPP__) || defined(_IBMR2)
  243.           menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_INFOMENU, SHAPE_DEFMSG_INFOMENU);
  244. #else
  245.           strcpy(menuText, SHAPE_DEFMSG_INFOMENU);
  246. #endif
  247.           menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartInfoMenu, menuText);
  248.  
  249.        } // end if the instance is of a subclass
  250.  
  251.        delete mi;
  252.        menuBar->Release(ev);
  253.  
  254. #if defined(__IBMCPP__) || defined(_IBMR2)
  255.        catclose(msgCatalog);             // close the message catalog
  256. #endif
  257.     }
  258.  
  259.     // set default background color
  260.     _fBackgroundColor = kShapePartDefaultColor;
  261.  
  262.     // check for read only drafts
  263.     _fDraftReadOnly = (somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly);
  264.  
  265.     }
  266.     catch(...)
  267.     {
  268.     }
  269. }
  270.  
  271. SOM_Scope void  SOMLINK ShapePartInitPart(ShapePart *somSelf,
  272.                                                      Environment *ev,
  273.                                                      ODStorageUnit* storageUnit,
  274.                                                      ODPart* partWrapper)
  275. {
  276.     ShapePartData *somThis = ShapePartGetData(somSelf);
  277.     ShapePartMethodDebug("ShapePart","ShapePartInitPart");
  278.  
  279.     try
  280.     {
  281.        // Call parent's method (which calls our CommonInit)
  282.        ShapePart_parent_SimplePart_InitPart(somSelf,
  283.                                             ev,
  284.                                             storageUnit,
  285.                                             partWrapper);
  286.  
  287.        // Save preferred kind property
  288.        ODSetISOStrProp(ev, storageUnit,
  289.                       kODPropPreferredKind,
  290.                       kODISOStr,
  291.                       kODKindShapePart);
  292.  
  293.     }
  294.     catch(...)
  295.     {
  296.     }
  297. }
  298.  
  299. SOM_Scope void  SOMLINK ShapePartInitPartFromStorage(ShapePart *somSelf,
  300.                                                      Environment *ev,
  301.                                                      ODStorageUnit* storageUnit,
  302.                                                      ODPart* partWrapper)
  303. {
  304.     ShapePartData *somThis = ShapePartGetData(somSelf);
  305.     ShapePartMethodDebug("ShapePart","ShapePartInitPartFromStorage");
  306.  
  307.     try
  308.     {
  309.        // Call parent's method (which calls our CommonInit)
  310.        ShapePart_parent_SimplePart_InitPartFromStorage(somSelf,
  311.                                                        ev,
  312.                                                        storageUnit,
  313.                                                        partWrapper);
  314.  
  315.        // Read background color from the contents property
  316.        _fBackgroundColor =  ODGetULongProp(ev, storageUnit,
  317.                                            kODPropContents,
  318.                                            kODKindShapePart);
  319.     }
  320.     catch(...)
  321.     {
  322.     }
  323. }
  324.  
  325. SOM_Scope void  SOMLINK ShapePartCloneInto(ShapePart *somSelf,
  326.                                            Environment *ev,
  327.                                            ODDraftKey key,
  328.                                            ODStorageUnit* storageUnit,
  329.                                            ODFrame* scopeFrame)
  330. {
  331.     ShapePartData *somThis = ShapePartGetData(somSelf);
  332.     ShapePartMethodDebug("ShapePart","ShapePartCloneInto");
  333.  
  334.     try
  335.     {
  336.       // Check that the part has not been cloned already
  337.       if(!storageUnit->Exists(ev, kODPropContents, kODKindShapePart, 0))
  338.       {
  339.         // Call parent's method
  340.         ShapePart_parent_SimplePart_CloneInto(somSelf, ev,
  341.                                               key,
  342.                                               storageUnit,
  343.                                               scopeFrame);
  344.  
  345.         // Add this part kind's content property
  346.         ODSetULongProp(ev, storageUnit,
  347.                        kODPropContents,
  348.                        kODKindShapePart,
  349.                        _fBackgroundColor);
  350.       }
  351.     }
  352.     catch(...)
  353.     {
  354.     }
  355. }
  356.  
  357. SOM_Scope void  SOMLINK ShapePartExternalize(ShapePart *somSelf,
  358.                                              Environment *ev)
  359. {
  360.     ShapePartData *somThis = ShapePartGetData(somSelf);
  361.     ShapePartMethodDebug("ShapePart","ShapePartExternalize");
  362.  
  363.     try
  364.     {
  365.        // Call parent method
  366.        ShapePart_parent_SimplePart_Externalize(somSelf, ev);
  367.  
  368.        // Get the storage unit
  369.        ODStorageUnit *su = somSelf->GetStorageUnit(ev);
  370.  
  371.        // Externalize only if draft is dirty.
  372.        if(su->GetDraft(ev)->ChangedFromPrev(ev))
  373.        {
  374.           // Overwrite this part kind's content property
  375.           ODSetULongProp(ev, su,
  376.                          kODPropContents,
  377.                          kODKindShapePart,
  378.                          _fBackgroundColor);
  379.        }
  380.  
  381.     }
  382.     catch(...)
  383.     {
  384.     }
  385. }
  386.  
  387. SOM_Scope void  SOMLINK ShapePartRelease(ShapePart *somSelf,
  388.                                            Environment *ev)
  389. {
  390.     ShapePartData *somThis = ShapePartGetData(somSelf);
  391.     ShapePartMethodDebug("ShapePart","ShapePartRelease");
  392.  
  393.    try
  394.    {
  395.       // if ref ct ==1, then clear action history
  396.       if (somSelf->GetRefCount(ev) == 1)
  397.          _fSession->GetUndo(ev)->ClearActionHistory (ev, kODRespectMarks);
  398.  
  399.       ShapePart_parent_SimplePart_Release(somSelf, ev);
  400.    }
  401.    catch(...)
  402.    {
  403.    }
  404. }
  405.  
  406.  
  407. SOM_Scope void  SOMLINK ShapePartAdjustViewTypeShapes(ShapePart *somSelf,
  408.                                                        Environment *ev,
  409.                                                        ODFrame* frame)
  410. {
  411.     ShapePartData *somThis = ShapePartGetData(somSelf);
  412.     ShapePartMethodDebug("ShapePart","ShapePartAdjustViewTypeShapes");
  413.  
  414.     try
  415.     {
  416.       // Call parent
  417.       ShapePart_parent_SimplePart_AdjustViewTypeShapes(somSelf, ev, frame);
  418.  
  419.       ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); // Get facets for frame
  420.       ODFacet*    facet            = facets->First(ev);              // Assume 1 facet
  421.       delete facets;
  422.  
  423.       ODRect rect;
  424.       ODTypeToken viewType = frame->GetViewType(ev);
  425.  
  426.       // Override SimplePart's behavior only if this is an embedded part displaying as frame.
  427.       if((viewType == somThis->fSession->Tokenize(ev,kODViewAsFrame)) &&
  428.          (!frame->IsRoot(ev)))
  429.       {
  430.  
  431.          // Set the used and active shape to a circle.
  432.          int         width, height;
  433.          ODRgnHandle hrgnUsedAndActive;
  434.          ODRect      box;
  435.  
  436.          ODCanvas *canvas = facet->GetCanvas(ev);
  437.  
  438. #ifdef _PLATFORM_OS2_
  439.          HPS       hps;
  440.          hps = ((ODOS2WindowCanvas*) canvas->GetPlatformCanvas(ev, kODPM))->GetPS(ev); // Obtain a PS
  441. #endif //_PLATFORM_OS2_
  442.  
  443.          TempODShape frameShape = frame->AcquireFrameShape(ev, canvas); // Get bounding box
  444.          frameShape->GetBoundingBox(ev, &box);                          //  of frame
  445.          width  = FixedToInt(box.right)-FixedToInt(box.left);           // circle to be
  446.          height = abs(FixedToInt(box.top)-FixedToInt(box.bottom));      // constructed
  447.  
  448. #ifdef _PLATFORM_OS2_
  449.          Point center;
  450.          center.x = width/2;
  451.          center.y = height/2;
  452.          int rad  = (width < height) ? center.x : center.y;             // get radius
  453.          GpiBeginPath(hps,1L);                                          // Define GPI path
  454.          GpiSetCurrentPosition(hps , ¢er);                          // for circle
  455.          GpiFullArc(hps,DRO_OUTLINE,MAKEFIXED(rad,0));
  456.          GpiEndPath(hps);
  457.          hrgnUsedAndActive = GpiPathToRegion(hps, 1, FPATH_ALTERNATE);  // Convert path to GPI region
  458.          ((ODOS2WindowCanvas *)canvas->GetPlatformCanvas(ev, kODPM))->ReleasePS(ev); // Release the canvas
  459. #elif defined(_PLATFORM_WIN32_)
  460.  
  461.          hrgnUsedAndActive = CreateEllipticRgn(0,0,width,height);       // region from Ellipse box
  462. #endif //_PLATFORM_WIN32_
  463.  
  464.          if(hrgnUsedAndActive)
  465.          {
  466.             // Use TempODShape so this object won't have to be released.
  467.             TempODShape usedAndActiveShape = frame->CreateShape(ev);       // create a shape
  468.             usedAndActiveShape->SetRegion(ev, hrgnUsedAndActive);          // assign the region to the shape
  469.  
  470.             // Set used and active shapes to the newly defined shape
  471.             frame->ChangeUsedShape(ev, usedAndActiveShape, kODNULL);
  472.             if(facet)
  473.             {
  474.               facet->ChangeActiveShape(ev, usedAndActiveShape, kODNULL);
  475.             }
  476.          } // hrgnUsedAndActive
  477.       } // viewtype is frame and frame isn't root
  478.       else
  479.       {
  480.          // Reset used and active shapes to frame shape
  481.          frame->ChangeUsedShape(ev, kODNULL, kODNULL);
  482.          if(facet)
  483.          {
  484.            facet->ChangeActiveShape(ev, kODNULL, kODNULL);
  485.          }
  486.  
  487.       }
  488.     }
  489.     catch(...)
  490.     {
  491.     }
  492. }
  493.  
  494. SOM_Scope void  SOMLINK ShapePartCreateIcons(ShapePart *somSelf,
  495.                                               Environment *ev)
  496. {
  497.     ShapePartData *somThis = ShapePartGetData(somSelf);
  498.     ShapePartMethodDebug("ShapePart","ShapePartCreateIcons");
  499.  
  500.     somSelf->LoadIconsFromModule(ev,
  501.                                  "iodshape",
  502.                                  kODIcon);
  503. }
  504.  
  505.  
  506. SOM_Scope ODBoolean  SOMLINK ShapePartHandleMenuEvent( ShapePart *somSelf,
  507.                                                        Environment *ev,
  508.                                                        ODFrame* focusFrame,
  509.                                                        ODEventData* event)
  510. {
  511.     ShapePartData *somThis = ShapePartGetData(somSelf);
  512.     ShapePartMethodDebug("ShapePart","ShapePartHandleMenuEvent");
  513.  
  514.     ODBoolean handled = kODFalse;
  515.  
  516. #ifndef _PLATFORM_UNIX_
  517.     try
  518.     {
  519.  
  520. #ifdef _PLATFORM_WIN32_
  521.        ODCommandID command = event->wParam;
  522. #elif defined(_PLATFORM_OS2_)
  523.        ODCommandID command = LONGFROMMP(event->mp1);
  524. #endif
  525.  
  526.  
  527.        switch (command)
  528.        {
  529.           case kShapePartBGColorMenuID:
  530.              somSelf->HandleColorChange (ev, focusFrame);
  531.              handled = kODTrue;
  532.              break;
  533.  
  534.           case kSimplePartHelpMenu:
  535.              {
  536.                 ODHelp *help = _fSession->GetHelp(ev);
  537.                 help->DisplayHelp(ev, SHAPE_HELP_FILE, SHAPE_HELP_PANEL);
  538.                 handled = kODTrue;
  539.              }
  540.              break;
  541.           case kSimplePartInfoMenu:
  542.              {
  543.                 somSelf->DisplayInfoDialog(ev,
  544.                                            SHAPE_MSG_CATALOG,
  545.                                            SHAPE_MSG_SET,
  546.                                            SHAPEMSG_INFOTITLE,
  547.                                            SHAPE_DEFMSG_INFOTITLE,
  548.                                            SHAPEMSG_INFO,
  549.                                            SHAPE_DEFMSG_INFO);
  550.                 handled = kODTrue;
  551.              }
  552.              break;
  553.           default:
  554.              handled = ShapePart_parent_SimplePart_HandleMenuEvent(somSelf, ev, focusFrame, event);
  555.              break;
  556.        }
  557.  
  558.     } // end try
  559.     catch(...)
  560.     {
  561.     }
  562.  
  563. #endif // _PLATFORM_UNIX
  564.  
  565.     return handled;
  566. }
  567.  
  568.  
  569. SOM_Scope void  SOMLINK ShapePartHandleColorChange(ShapePart *somSelf,
  570.                                                    Environment *ev,
  571.                                                    ODFrame *frame)
  572. {
  573.     ShapePartData *somThis = ShapePartGetData(somSelf);
  574.     ShapePartMethodDebug("ShapePart","ShapePartHandleColorChange");
  575.  
  576.     COLORREF oldColor = _fBackgroundColor;
  577.  
  578. #if defined(_PLATFORM_WIN32_)
  579.  
  580.     ODWindowState* WinStat =  _fSession->GetWindowState(ev);
  581.     TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  582.     HWND hwnd = Window->GetPlatformWindow(ev);
  583.  
  584.     COLORREF clrCustom[16];
  585.     int fColor;
  586.     CHOOSECOLOR colorstruct;
  587.  
  588.     // set up structure to pass to color dialog routine
  589.     memset(&colorstruct, 0, sizeof(colorstruct));
  590.     colorstruct.lStructSize = sizeof(colorstruct);
  591.     colorstruct.hwndOwner = hwnd;
  592.     colorstruct.rgbResult = RGB(0, 0, 0);
  593.     colorstruct.Flags = CC_RGBINIT;
  594.     for (fColor=0; fColor<16; fColor++)
  595.       clrCustom[fColor] = RGB(255, 255, 255);
  596.     colorstruct.lpCustColors = clrCustom;
  597.  
  598.     if (ChooseColor(&colorstruct))
  599.        _fBackgroundColor = colorstruct.rgbResult;
  600.  
  601. #elif defined (_PLATFORM_OS2_)
  602.  
  603.     CHAR  Error[256] = "";
  604.     HMODULE hmod;
  605.     int rc;
  606.     SHORT NewColors[3] = {0, 0, 0};
  607.  
  608.     ODWindowState* WinStat =  _fSession->GetWindowState(ev);
  609.     TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  610.     HWND hwnd = Window->GetPlatformWindow(ev);
  611.     DosLoadModule( Error, sizeof(Error), kShapePartDLLName, &hmod );
  612.  
  613.     NewColors[RED]   = (SHORT) ((_fBackgroundColor / 65536L) & 0x000000FF);
  614.     NewColors[GREEN]= (SHORT) ((_fBackgroundColor / 256L) & 0x000000FF);
  615.     NewColors[BLUE]  = (SHORT) (_fBackgroundColor & 0x000000FF);
  616.  
  617.     // call procedures for bringing up rc file and user changing colors
  618.     rc = ColorWindow(hmod, hwnd, NewColors);
  619.  
  620.     _fBackgroundColor = NewColors[BLUE] +
  621.                     (256L   * (LONG) NewColors[GREEN]) +
  622.                     (65536L * (LONG) NewColors[RED]);
  623.  
  624.  
  625. #elif defined (_PLATFORM_UNIX_)
  626.  
  627.     // TBD
  628.  
  629. #endif
  630.  
  631.    // now that we have changed color, invalidate the frame and force redraw
  632.    if (oldColor != _fBackgroundColor) {
  633.  
  634.       somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  635.       somSelf->InvalidateAllFrames(ev);
  636.  
  637.       // register with undo manager
  638.       ODIText *undoActionName = CreateITextCString (0, 0, kShapePartUndoBGColor);
  639.       ODIText *redoActionName = CreateITextCString (0, 0, kShapePartRedoBGColor);
  640.  
  641.       ShapePartUndoRec undoData;
  642.       undoData.undoAction = UNDO_BGCOLOR;
  643.       undoData.oldColor = oldColor;
  644.       undoData.newColor = _fBackgroundColor;
  645.       ODActionData *undoer = (ODActionData *) CreateByteArray (&undoData, sizeof (ShapePartUndoRec));
  646.  
  647.       _fSession->GetUndo(ev)->AddActionToHistory (ev, somSelf, undoer, kODSingleAction,
  648.                     (ODName *)undoActionName, (ODName *)redoActionName);
  649.  
  650.       DisposeIText (undoActionName);
  651.       DisposeIText (redoActionName);
  652.       DisposeByteArray (undoer);
  653.    }
  654. }
  655.  
  656.  
  657.  
  658. SOM_Scope void  SOMLINK ShapePartDrawFrame(ShapePart *somSelf,
  659.                                             Environment *ev,
  660.                                             ODFacet* facet,
  661.                                             ODShape* invalidShape)
  662. {
  663.     ShapePartData *somThis = ShapePartGetData(somSelf);
  664.     ShapePartMethodDebug("ShapePart","ShapePartDrawFrame");
  665.  
  666.     ODFrame* displayFrame = facet->GetFrame(ev);
  667.     TempODShape shape = displayFrame->AcquireFrameShape(ev, facet->GetCanvas(ev));
  668.     ODRect rect;
  669.     shape->GetBoundingBox(ev, &rect);
  670.  
  671.  
  672. #if defined(_PLATFORM_WIN32_)
  673.     Rect frameRect;
  674.     SetRect(&frameRect, FixedToInt(rect.left),
  675.                        FixedToInt(rect.top),
  676.                        FixedToInt(rect.right),
  677.                        FixedToInt(rect.bottom));
  678.  
  679.     HDC hdc;
  680.     CFocus focus(facet, invalidShape, &hdc);
  681.  
  682.     HBRUSH hbr = CreateSolidBrush (_fBackgroundColor);
  683.     FillRect (hdc, &frameRect, hbr);
  684.     DeleteObject (hbr);
  685.  
  686. #elif defined (_PLATFORM_OS2_)
  687.  
  688.     RECTL frameRect;
  689.     frameRect.xLeft = FixedToInt(rect.left);
  690.     frameRect.yTop  = FixedToInt(rect.top);
  691.     frameRect.xRight  = FixedToInt(rect.right);
  692.     frameRect.yBottom  = FixedToInt(rect.bottom);
  693.  
  694.     HPS hdc;
  695.     CFocus focus(facet, invalidShape, &hdc);
  696.  
  697.     GpiCreateLogColorTable (hdc, 0L, LCOLF_RGB, 0L, 0L, 0L);
  698.     GpiSetColor(hdc, _fBackgroundColor);
  699.     POINTL orig = {0, 0};
  700.     GpiMove(hdc, &orig);
  701.     POINTL ptl = {frameRect.xRight, frameRect.yTop};
  702.     GpiBox(hdc, DRO_FILL, &ptl, 0, 0);
  703.  
  704.  
  705. #endif
  706. }
  707.  
  708. SOM_Scope void  SOMLINK ShapePartInvalidateAllFrames(ShapePart *somSelf,       // in
  709.                                                      Environment *ev)          // in
  710. {
  711.     ShapePartData *somThis = ShapePartGetData(somSelf);
  712.     ShapePartMethodDebug("ShapePart","ShapePartInvalidateAllFrames");
  713.  
  714.     IODLinkedList *list = somSelf->GetDisplayFrames(ev);
  715.     IODLink *listItem;
  716.     ODFrame *myFrame;
  717.  
  718.     for (listItem = list->First(ev);
  719.          (listItem != kODNULL) && (myFrame = (ODFrame *)(listItem->Content(ev)));
  720.          listItem = listItem->Next(ev))
  721.     {
  722.  
  723.        myFrame->Invalidate (ev, kODNULL, kODNULL);
  724.     }
  725. }
  726.  
  727.  
  728. SOM_Scope       void
  729. SOMLINK         ShapePartAdjustMenus
  730.                 (
  731.                 ShapePart       *somSelf,       // in
  732.                 Environment     *ev,            // in
  733.                 ODFrame         *frame          // in
  734.                 )
  735. {
  736.     ShapePartData *somThis = ShapePartGetData(somSelf);
  737.     ShapePartMethodDebug("ShapePart","ShapePartAdjustMenus");
  738.  
  739.     ShapePart_parent_SimplePart_AdjustMenus (somSelf, ev, frame);
  740.     ODMenuBar *menuBar = somSelf->GetMenuBar(ev);
  741.     menuBar->EnableMenuItem(ev, IDMS_EDIT, kShapePartBGColorMenuID, !_fDraftReadOnly);
  742.  
  743. }
  744.  
  745. SOM_Scope       void
  746. SOMLINK         ShapePartUndoAction
  747.                 (
  748.                 ShapePart       *somSelf,       // in
  749.                 Environment     *ev,            // in
  750.                 ODActionData    *actionState    // in
  751.                 )
  752. {
  753.     ShapePartData *somThis = ShapePartGetData(somSelf);
  754.     ShapePartMethodDebug("ShapePart","ShapePartUndoAction");
  755.  
  756.     ShapePartUndoRec *undoRec = (ShapePartUndoRec*)actionState->_buffer;
  757.     _fBackgroundColor = undoRec->oldColor;
  758.     somSelf->InvalidateAllFrames(ev);
  759. }
  760.  
  761. SOM_Scope       void
  762. SOMLINK         ShapePartRedoAction
  763.                 (
  764.                 ShapePart       *somSelf,       // in
  765.                 Environment     *ev,            // in
  766.                 ODActionData    *actionState    // in
  767.                 )
  768. {
  769.     ShapePartData *somThis = ShapePartGetData(somSelf);
  770.     ShapePartMethodDebug("ShapePart","ShapePartRedoAction");
  771.  
  772.     ShapePartUndoRec *undoRec = (ShapePartUndoRec*)actionState->_buffer;
  773.     _fBackgroundColor = undoRec->newColor;
  774.     somSelf->InvalidateAllFrames(ev);
  775. }
  776.  
  777. SOM_Scope ISOString  SOMLINK M_ShapePartclsGetODPartHandlerName(M_ShapePart *somSelf,
  778.                                                                  Environment *ev)
  779. {
  780.     /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
  781.     M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartHandlerName");
  782.  
  783.     string handlerName = (string)SOMMalloc(strlen(kShapePartHandlerName)+1);
  784.     strcpy(handlerName,kShapePartHandlerName);
  785.  
  786.     return (ISOString) handlerName;
  787. }
  788.  
  789. SOM_Scope string  SOMLINK M_ShapePartclsGetODPartHandlerDisplayName(M_ShapePart *somSelf,
  790.                                                                      Environment *ev)
  791. {
  792.     /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
  793.     M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartHandlerDisplayName");
  794.  
  795.     string displayName = (string)SOMMalloc(strlen(kShapePartHandlerDisplayName)+1);
  796.     strcpy(displayName,kShapePartHandlerDisplayName);
  797.  
  798.     return displayName;
  799. }
  800.  
  801. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK M_ShapePartclsGetODPartKinds(M_ShapePart *somSelf,
  802.                                                                             Environment *ev)
  803. {
  804.     /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
  805.     M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartKinds");
  806.  
  807.     _IDL_SEQUENCE_PartKindInfo ShapePartInfo;
  808.  
  809.     // Create structure PartKindInfo  and allocate memory for its fields
  810.     PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
  811.     info->partKindName = (ISOString) SOMMalloc(strlen(kODKindShapePart) + 1);
  812.     info->partKindDisplayName = (string)SOMMalloc(strlen(kShapePartKindDisplayName)+1);
  813.     info->filenameFilters =  (string)SOMMalloc(strlen("")+1);
  814.     info->filenameTypes =  (string)SOMMalloc(strlen("")+1);
  815.     info->categories =  (string)SOMMalloc(strlen(kShapePartCategory)+1);
  816.     info->categoryDisplayName =  (string)SOMMalloc(strlen("")+1);
  817.     info->objectID =  (string)SOMMalloc(strlen("")+1);
  818.  
  819.     // Copy the information into the structure
  820.     strcpy(info->partKindName , kODKindShapePart);
  821.     strcpy(info->partKindDisplayName, kShapePartKindDisplayName);
  822.     strcpy(info->filenameFilters, "");
  823.     strcpy(info->filenameTypes, "");
  824.     strcpy(info->categories, kShapePartCategory);
  825.     strcpy(info->categoryDisplayName, "");
  826.     strcpy(info->objectID, "");
  827.  
  828.     ShapePartInfo._maximum = 1;
  829.     ShapePartInfo._length = 1;
  830.     ShapePartInfo._buffer = info;
  831.  
  832.     return ShapePartInfo;
  833. }
  834.  
  835. SOM_Scope string  SOMLINK M_ShapePartclsGetOLE2ClassId(M_ShapePart *somSelf,
  836.                                                         Environment *ev)
  837. {
  838.     /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
  839.     M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetOLE2ClassId");
  840.  
  841.     // OLE2 Class ID is determined by running the tool UUIDGEN.EXE
  842.     // or GUIDGEN.EXE found in the IBM VAC++ SDK\BIN directory
  843.     // this tool is gauranteed to generate a unique ID based on your
  844.     // network address and the time of day (DCE Standard)
  845.  
  846.  
  847.     string OLE2 = "{6be34400-fba2-11cf-b25b-08005a49d940}";
  848.     string OLE2ClassId = (string)SOMMalloc(strlen(OLE2)+1);
  849.     strcpy(OLE2ClassId,OLE2);
  850.  
  851.     return OLE2ClassId;
  852. }
  853.  
  854. SOM_Scope string  SOMLINK M_ShapePartclsGetWindowsIconFileName(M_ShapePart *somSelf,
  855.                                                                 Environment *ev)
  856. {
  857.     /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
  858.     M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetWindowsIconFileName");
  859.  
  860.     string fileName = (string) SOMMalloc (strlen(kShapePartIconFileName)+1);
  861.     strcpy(fileName,kShapePartIconFileName);
  862.     return fileName;
  863. }
  864.  
  865.