//====START_GENERATED_PROLOG======================================
//
//
//   COMPONENT_NAME: odshapepart
//
//   CLASSES: none
//
//   ORIGINS: 82,27
//
//
//   (C) COPYRIGHT International Business Machines Corp. 1995,1996
//   All Rights Reserved
//   Licensed Materials - Property of IBM
//   US Government Users Restricted Rights - Use, duplication or
//   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
//   	
//   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
//   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
//   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
//   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
//   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
//   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
//   OR PERFORMANCE OF THIS SOFTWARE.
//
//====END_GENERATED_PROLOG========================================
//
/* @(#) 1.26 com/src/samples/shape/iodshape.cpp, odshapepart, od96nt, odnt9712d 3/11/97 17:27:37 [3/21/97 17:36:37] */
/*
 *  This file was generated by the SOM Compiler and Emitter Framework.
 *  Generated using:
 *      SOM Emitter emitxtm.dll: Development
 */

#ifndef SOM_Module_shapeprt_Source
#define SOM_Module_shapeprt_Source
#endif
#define ShapePart_Class_Source
#define M_ShapePart_Class_Source

// som macro for using "_" with instance data
#define VARIABLE_MACROS

// definition for class name; use it for adding HELP menu
#define kShapeClassName "ShapePart"

#include "iodshpe.h"                    // message catalog includes.

// Include ODExcept.h before OpenDoc SOM headers
#include <ODExcept.h>

#include <ODTypesF.h>
#include <tempobj.h>
#include <PlatCanv.xh>

#ifdef _PLATFORM_OS2_
#include <OS2PCanv.xh>
#include <OS2WCanv.xh>
#include <ODos2.h>
#endif //_PLATFORM_OS2_

#ifndef SOM_ODCanvas_xh
#include <Canvas.xh>
#endif

#ifndef SOM_ODFacet_xh
#include <Facet.xh>
#endif

#ifndef SOM_ODFrame_xh
#include <Frame.xh>
#endif

#ifndef SOM_ODFrameFacetIterator_xh
#include <FrFaItr.xh>
#endif

#ifndef SOM_ODSession_xh
#include <ODSessn.xh>
#endif

#ifndef SOM_ODShape_xh
#include <Shape.xh>
#endif

#ifndef SOM_ODUndo_xh
#include <Undo.xh>
#endif

#ifndef SOM_ODStorageUnit_xh
#include <StorageU.xh>
#endif

#ifndef SOM_ODWindowState_xh
#include <WinStat.xh>
#endif

#ifndef SOM_ODMenubar_xh
#include <MenuBar.xh>
#endif

#ifndef SOM_ODDraft_xh
#include <Draft.xh>
#endif

#if defined (_PLATFORM_OS2_) || defined (_PLATFORM_WIN32_)
#include <focuslib.h>
#endif

#ifndef _ITEXT_
#include <IText.h>
#endif

#ifndef _BARRAY_
#include <BArray.h>
#endif

#ifndef _IODLINK_
#include <iodlink.xh>
#endif

#ifndef SOM_ODHelp_xh
#include <odhelp.xh>
#endif

#include <StdProps.xh>
#include <StdTypes.xh>

#ifndef _STDTYPIO_
#include <StdTypIO.h>
#endif

#include "ODResrc.h"
#include "iodshape.h"
#include "iodshape.xih"
#include <ODDebug.h>

#ifdef _PLATFORM_OS2_
#include "os2plat.cpp"
#endif

SOM_Scope void  SOMLINK ShapePartsomInit(ShapePart *somSelf)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartsomInit");

    ShapePart_parent_SimplePart_somInit(somSelf);
    somThis->fSession = kODNULL;
    somThis->fPartWrapper = kODNULL;
}

SOM_Scope void  SOMLINK ShapePartsomUninit(ShapePart *somSelf)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartsomUninit");

    ShapePart_parent_SimplePart_somUninit(somSelf);
}

SOM_Scope void  SOMLINK ShapePartCommonInit(ShapePart *somSelf,
                                            Environment *ev,
                                            ODPart* partWrapper)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartCommonInit");

    try
    {
    ShapePart_parent_SimplePart_CommonInit(somSelf, ev, partWrapper);
    somThis->fSession = somSelf->GetStorageUnit(ev)->GetSession(ev);
    somThis->fPartWrapper = partWrapper;

    ODMenuBar *menuBar = somSelf->GetMenuBar(ev);

    if (menuBar) {

       menuBar->Acquire(ev);

       // Add menu item for background color
       ODPlatformMenuItem *mi = new ODPlatformMenuItem;
       // clear the memory
       memset (mi, 0, sizeof(ODPlatformMenuItem));

       mi->id = kShapePartBGColorMenuID;
       menuBar->AddMenuItemLast(ev, IDMS_EDIT, kODNULL, mi);

#if defined(__IBMCPP__) || defined(_IBMR2)
       nl_catd msgCatalog;       // NLS message catalog handle
       char *menuText;           // pointer for NLS message

       setlocale(LC_MESSAGES, NULL);
       msgCatalog = catopen(SHAPE_MSG_CATALOG, 0);
       if(msgCatalog == CATD_ERR)
       {
         PRINT("Could not open message catalog %s\n", SHAPE_MSG_CATALOG);
       }
#else
       char menuText[256];
#endif

       // Set text of Background Color menu item
#if defined(__IBMCPP__) || defined(_IBMR2)
       menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_COLORMENU, SHAPE_DEFMSG_COLORMENU);
#else
       strcpy(menuText, SHAPE_DEFMSG_COLORMENU);
#endif
       menuBar->SetMenuItemText (ev, IDMS_EDIT, mi->id, menuText);


       //let's add help menu items ONLY if this is base container
       // and not its subclass
       if (!strcmp (somSelf->somGetClassName(), kShapeClassName))
       {
          // we add the menu items that simple part did not add since
          // this is a subclass

          // add a menu separator line to the HELP menu
          mi->id = kSimplePartMenuSeparator;
#if defined(_PLATFORM_WIN32_)
          mi->afAttribute=MF_SEPARATOR;
#elif defined(_PLATFORM_OS2_)
          mi->afAttribute=CA_TITLESEPARATOR;
#endif
          menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);

          // add shape part help menu
          mi->afAttribute=0;
          mi->id = kSimplePartHelpMenu;
          menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);

#if defined(__IBMCPP__) || defined(_IBMR2)
          menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_HELPMENU, SHAPE_DEFMSG_HELPMENU);
#else
          strcpy(menuText, SHAPE_DEFMSG_HELPMENU);
#endif
          menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartHelpMenu, menuText);


          // add shape part info menu
          mi->id = kSimplePartInfoMenu;
          menuBar->AddMenuItemLast(ev, IDMS_HELP, mi->id, mi);

#if defined(__IBMCPP__) || defined(_IBMR2)
          menuText=catgets(msgCatalog, SHAPE_MSG_SET, SHAPEMSG_INFOMENU, SHAPE_DEFMSG_INFOMENU);
#else
          strcpy(menuText, SHAPE_DEFMSG_INFOMENU);
#endif
          menuBar->SetMenuItemText(ev, IDMS_HELP, kSimplePartInfoMenu, menuText);

       } // end if the instance is of a subclass

       delete mi;
       menuBar->Release(ev);

#if defined(__IBMCPP__) || defined(_IBMR2)
       catclose(msgCatalog);             // close the message catalog
#endif
    }

    // set default background color
    _fBackgroundColor = kShapePartDefaultColor;

    // check for read only drafts
    _fDraftReadOnly = (somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly);

    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartInitPart(ShapePart *somSelf,
                                                     Environment *ev,
                                                     ODStorageUnit* storageUnit,
                                                     ODPart* partWrapper)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartInitPart");

    try
    {
       // Call parent's method (which calls our CommonInit)
       ShapePart_parent_SimplePart_InitPart(somSelf,
                                            ev,
                                            storageUnit,
                                            partWrapper);

       // Save preferred kind property
       ODSetISOStrProp(ev, storageUnit,
                      kODPropPreferredKind,
                      kODISOStr,
                      kODKindShapePart);

    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartInitPartFromStorage(ShapePart *somSelf,
                                                     Environment *ev,
                                                     ODStorageUnit* storageUnit,
                                                     ODPart* partWrapper)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartInitPartFromStorage");

    try
    {
       // Call parent's method (which calls our CommonInit)
       ShapePart_parent_SimplePart_InitPartFromStorage(somSelf,
                                                       ev,
                                                       storageUnit,
                                                       partWrapper);

       // Read background color from the contents property
       _fBackgroundColor =  ODGetULongProp(ev, storageUnit,
                                           kODPropContents,
                                           kODKindShapePart);
    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartCloneInto(ShapePart *somSelf,
                                           Environment *ev,
                                           ODDraftKey key,
                                           ODStorageUnit* storageUnit,
                                           ODFrame* scopeFrame)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartCloneInto");

    try
    {
      // Check that the part has not been cloned already
      if(!storageUnit->Exists(ev, kODPropContents, kODKindShapePart, 0))
      {
        // Call parent's method
        ShapePart_parent_SimplePart_CloneInto(somSelf, ev,
                                              key,
                                              storageUnit,
                                              scopeFrame);

        // Add this part kind's content property
        ODSetULongProp(ev, storageUnit,
                       kODPropContents,
                       kODKindShapePart,
                       _fBackgroundColor);
      }
    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartExternalize(ShapePart *somSelf,
                                             Environment *ev)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartExternalize");

    try
    {
       // Call parent method
       ShapePart_parent_SimplePart_Externalize(somSelf, ev);

       // Get the storage unit
       ODStorageUnit *su = somSelf->GetStorageUnit(ev);

       // Externalize only if draft is dirty.
       if(su->GetDraft(ev)->ChangedFromPrev(ev))
       {
          // Overwrite this part kind's content property
          ODSetULongProp(ev, su,
                         kODPropContents,
                         kODKindShapePart,
                         _fBackgroundColor);
       }

    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartRelease(ShapePart *somSelf,
                                           Environment *ev)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartRelease");

   try
   {
      // if ref ct ==1, then clear action history
      if (somSelf->GetRefCount(ev) == 1)
         _fSession->GetUndo(ev)->ClearActionHistory (ev, kODRespectMarks);

      ShapePart_parent_SimplePart_Release(somSelf, ev);
   }
   catch(...)
   {
   }
}


SOM_Scope void  SOMLINK ShapePartAdjustViewTypeShapes(ShapePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* frame)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartAdjustViewTypeShapes");

    try
    {
      // Call parent
      ShapePart_parent_SimplePart_AdjustViewTypeShapes(somSelf, ev, frame);

      ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev); // Get facets for frame
      ODFacet*    facet            = facets->First(ev);              // Assume 1 facet
      delete facets;

      ODRect rect;
      ODTypeToken viewType = frame->GetViewType(ev);

      // Override SimplePart's behavior only if this is an embedded part displaying as frame.
      if((viewType == somThis->fSession->Tokenize(ev,kODViewAsFrame)) &&
         (!frame->IsRoot(ev)))
      {

         // Set the used and active shape to a circle.
         int         width, height;
         ODRgnHandle hrgnUsedAndActive;
         ODRect      box;

         ODCanvas *canvas = facet->GetCanvas(ev);

#ifdef _PLATFORM_OS2_
         HPS       hps;
         hps = ((ODOS2WindowCanvas*) canvas->GetPlatformCanvas(ev, kODPM))->GetPS(ev); // Obtain a PS
#endif //_PLATFORM_OS2_

         TempODShape frameShape = frame->AcquireFrameShape(ev, canvas); // Get bounding box
         frameShape->GetBoundingBox(ev, &box);                          //  of frame
         width  = FixedToInt(box.right)-FixedToInt(box.left);           // circle to be
         height = abs(FixedToInt(box.top)-FixedToInt(box.bottom));      // constructed

#ifdef _PLATFORM_OS2_
         Point center;
         center.x = width/2;
         center.y = height/2;
         int rad  = (width < height) ? center.x : center.y;             // get radius
         GpiBeginPath(hps,1L);                                          // Define GPI path
         GpiSetCurrentPosition(hps , &center);                          // for circle
         GpiFullArc(hps,DRO_OUTLINE,MAKEFIXED(rad,0));
         GpiEndPath(hps);
         hrgnUsedAndActive = GpiPathToRegion(hps, 1, FPATH_ALTERNATE);  // Convert path to GPI region
         ((ODOS2WindowCanvas *)canvas->GetPlatformCanvas(ev, kODPM))->ReleasePS(ev); // Release the canvas
#elif defined(_PLATFORM_WIN32_)

         hrgnUsedAndActive = CreateEllipticRgn(0,0,width,height);       // region from Ellipse box
#endif //_PLATFORM_WIN32_

         if(hrgnUsedAndActive)
         {
            // Use TempODShape so this object won't have to be released.
            TempODShape usedAndActiveShape = frame->CreateShape(ev);       // create a shape
            usedAndActiveShape->SetRegion(ev, hrgnUsedAndActive);          // assign the region to the shape

            // Set used and active shapes to the newly defined shape
            frame->ChangeUsedShape(ev, usedAndActiveShape, kODNULL);
            if(facet)
            {
              facet->ChangeActiveShape(ev, usedAndActiveShape, kODNULL);
            }
         } // hrgnUsedAndActive
      } // viewtype is frame and frame isn't root
      else
      {
         // Reset used and active shapes to frame shape
         frame->ChangeUsedShape(ev, kODNULL, kODNULL);
         if(facet)
         {
           facet->ChangeActiveShape(ev, kODNULL, kODNULL);
         }

      }
    }
    catch(...)
    {
    }
}

SOM_Scope void  SOMLINK ShapePartCreateIcons(ShapePart *somSelf,
                                              Environment *ev)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartCreateIcons");

    somSelf->LoadIconsFromModule(ev,
                                 "iodshape",
                                 kODIcon);
}


SOM_Scope ODBoolean  SOMLINK ShapePartHandleMenuEvent( ShapePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* focusFrame,
                                                       ODEventData* event)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartHandleMenuEvent");

    ODBoolean handled = kODFalse;

#ifndef _PLATFORM_UNIX_
    try
    {

#ifdef _PLATFORM_WIN32_
       ODCommandID command = event->wParam;
#elif defined(_PLATFORM_OS2_)
       ODCommandID command = LONGFROMMP(event->mp1);
#endif


       switch (command)
       {
          case kShapePartBGColorMenuID:
             somSelf->HandleColorChange (ev, focusFrame);
             handled = kODTrue;
             break;

          case kSimplePartHelpMenu:
             {
                ODHelp *help = _fSession->GetHelp(ev);
                help->DisplayHelp(ev, SHAPE_HELP_FILE, SHAPE_HELP_PANEL);
                handled = kODTrue;
             }
             break;
          case kSimplePartInfoMenu:
             {
                somSelf->DisplayInfoDialog(ev,
                                           SHAPE_MSG_CATALOG,
                                           SHAPE_MSG_SET,
                                           SHAPEMSG_INFOTITLE,
                                           SHAPE_DEFMSG_INFOTITLE,
                                           SHAPEMSG_INFO,
                                           SHAPE_DEFMSG_INFO);
                handled = kODTrue;
             }
             break;
          default:
             handled = ShapePart_parent_SimplePart_HandleMenuEvent(somSelf, ev, focusFrame, event);
             break;
       }

    } // end try
    catch(...)
    {
    }

#endif // _PLATFORM_UNIX

    return handled;
}


SOM_Scope void  SOMLINK ShapePartHandleColorChange(ShapePart *somSelf,
                                                   Environment *ev,
                                                   ODFrame *frame)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartHandleColorChange");

    COLORREF oldColor = _fBackgroundColor;

#if defined(_PLATFORM_WIN32_)

    ODWindowState* WinStat =  _fSession->GetWindowState(ev);
    TempODWindow Window = WinStat->AcquireActiveWindow(ev);
    HWND hwnd = Window->GetPlatformWindow(ev);

    COLORREF clrCustom[16];
    int fColor;
    CHOOSECOLOR colorstruct;

    // set up structure to pass to color dialog routine
    memset(&colorstruct, 0, sizeof(colorstruct));
    colorstruct.lStructSize = sizeof(colorstruct);
    colorstruct.hwndOwner = hwnd;
    colorstruct.rgbResult = RGB(0, 0, 0);
    colorstruct.Flags = CC_RGBINIT;
    for (fColor=0; fColor<16; fColor++)
      clrCustom[fColor] = RGB(255, 255, 255);
    colorstruct.lpCustColors = clrCustom;

    if (ChooseColor(&colorstruct))
       _fBackgroundColor = colorstruct.rgbResult;

#elif defined (_PLATFORM_OS2_)

    CHAR  Error[256] = "";
    HMODULE hmod;
    int rc;
    SHORT NewColors[3] = {0, 0, 0};

    ODWindowState* WinStat =  _fSession->GetWindowState(ev);
    TempODWindow Window = WinStat->AcquireActiveWindow(ev);
    HWND hwnd = Window->GetPlatformWindow(ev);
    DosLoadModule( Error, sizeof(Error), kShapePartDLLName, &hmod );

    NewColors[RED]   = (SHORT) ((_fBackgroundColor / 65536L) & 0x000000FF);
    NewColors[GREEN]= (SHORT) ((_fBackgroundColor / 256L) & 0x000000FF);
    NewColors[BLUE]  = (SHORT) (_fBackgroundColor & 0x000000FF);

    // call procedures for bringing up rc file and user changing colors
    rc = ColorWindow(hmod, hwnd, NewColors);

    _fBackgroundColor = NewColors[BLUE] +
                    (256L   * (LONG) NewColors[GREEN]) +
                    (65536L * (LONG) NewColors[RED]);


#elif defined (_PLATFORM_UNIX_)

    // TBD

#endif

   // now that we have changed color, invalidate the frame and force redraw
   if (oldColor != _fBackgroundColor) {

      somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
      somSelf->InvalidateAllFrames(ev);

      // register with undo manager
      ODIText *undoActionName = CreateITextCString (0, 0, kShapePartUndoBGColor);
      ODIText *redoActionName = CreateITextCString (0, 0, kShapePartRedoBGColor);

      ShapePartUndoRec undoData;
      undoData.undoAction = UNDO_BGCOLOR;
      undoData.oldColor = oldColor;
      undoData.newColor = _fBackgroundColor;
      ODActionData *undoer = (ODActionData *) CreateByteArray (&undoData, sizeof (ShapePartUndoRec));

      _fSession->GetUndo(ev)->AddActionToHistory (ev, somSelf, undoer, kODSingleAction,
                    (ODName *)undoActionName, (ODName *)redoActionName);

      DisposeIText (undoActionName);
      DisposeIText (redoActionName);
      DisposeByteArray (undoer);
   }
}



SOM_Scope void  SOMLINK ShapePartDrawFrame(ShapePart *somSelf,
                                            Environment *ev,
                                            ODFacet* facet,
                                            ODShape* invalidShape)
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartDrawFrame");

    ODFrame* displayFrame = facet->GetFrame(ev);
    TempODShape shape = displayFrame->AcquireFrameShape(ev, facet->GetCanvas(ev));
    ODRect rect;
    shape->GetBoundingBox(ev, &rect);


#if defined(_PLATFORM_WIN32_)
    Rect frameRect;
    SetRect(&frameRect, FixedToInt(rect.left),
                       FixedToInt(rect.top),
                       FixedToInt(rect.right),
                       FixedToInt(rect.bottom));

    HDC hdc;
    CFocus focus(facet, invalidShape, &hdc);

    HBRUSH hbr = CreateSolidBrush (_fBackgroundColor);
    FillRect (hdc, &frameRect, hbr);
    DeleteObject (hbr);

#elif defined (_PLATFORM_OS2_)

    RECTL frameRect;
    frameRect.xLeft = FixedToInt(rect.left);
    frameRect.yTop  = FixedToInt(rect.top);
    frameRect.xRight  = FixedToInt(rect.right);
    frameRect.yBottom  = FixedToInt(rect.bottom);

    HPS hdc;
    CFocus focus(facet, invalidShape, &hdc);

    GpiCreateLogColorTable (hdc, 0L, LCOLF_RGB, 0L, 0L, 0L);
    GpiSetColor(hdc, _fBackgroundColor);
    POINTL orig = {0, 0};
    GpiMove(hdc, &orig);
    POINTL ptl = {frameRect.xRight, frameRect.yTop};
    GpiBox(hdc, DRO_FILL, &ptl, 0, 0);


#endif
}

SOM_Scope void  SOMLINK ShapePartInvalidateAllFrames(ShapePart *somSelf,       // in
                                                     Environment *ev)          // in
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartInvalidateAllFrames");

    IODLinkedList *list = somSelf->GetDisplayFrames(ev);
    IODLink *listItem;
    ODFrame *myFrame;

    for (listItem = list->First(ev);
         (listItem != kODNULL) && (myFrame = (ODFrame *)(listItem->Content(ev)));
         listItem = listItem->Next(ev))
    {

       myFrame->Invalidate (ev, kODNULL, kODNULL);
    }
}


SOM_Scope       void
SOMLINK         ShapePartAdjustMenus
                (
                ShapePart       *somSelf,       // in
                Environment     *ev,            // in
                ODFrame         *frame          // in
                )
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartAdjustMenus");

    ShapePart_parent_SimplePart_AdjustMenus (somSelf, ev, frame);
    ODMenuBar *menuBar = somSelf->GetMenuBar(ev);
    menuBar->EnableMenuItem(ev, IDMS_EDIT, kShapePartBGColorMenuID, !_fDraftReadOnly);

}

SOM_Scope       void
SOMLINK         ShapePartUndoAction
                (
                ShapePart       *somSelf,       // in
                Environment     *ev,            // in
                ODActionData    *actionState    // in
                )
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartUndoAction");

    ShapePartUndoRec *undoRec = (ShapePartUndoRec*)actionState->_buffer;
    _fBackgroundColor = undoRec->oldColor;
    somSelf->InvalidateAllFrames(ev);
}

SOM_Scope       void
SOMLINK         ShapePartRedoAction
                (
                ShapePart       *somSelf,       // in
                Environment     *ev,            // in
                ODActionData    *actionState    // in
                )
{
    ShapePartData *somThis = ShapePartGetData(somSelf);
    ShapePartMethodDebug("ShapePart","ShapePartRedoAction");

    ShapePartUndoRec *undoRec = (ShapePartUndoRec*)actionState->_buffer;
    _fBackgroundColor = undoRec->newColor;
    somSelf->InvalidateAllFrames(ev);
}

SOM_Scope ISOString  SOMLINK M_ShapePartclsGetODPartHandlerName(M_ShapePart *somSelf,
                                                                 Environment *ev)
{
    /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
    M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartHandlerName");

    string handlerName = (string)SOMMalloc(strlen(kShapePartHandlerName)+1);
    strcpy(handlerName,kShapePartHandlerName);

    return (ISOString) handlerName;
}

SOM_Scope string  SOMLINK M_ShapePartclsGetODPartHandlerDisplayName(M_ShapePart *somSelf,
                                                                     Environment *ev)
{
    /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
    M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartHandlerDisplayName");

    string displayName = (string)SOMMalloc(strlen(kShapePartHandlerDisplayName)+1);
    strcpy(displayName,kShapePartHandlerDisplayName);

    return displayName;
}

SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK M_ShapePartclsGetODPartKinds(M_ShapePart *somSelf,
                                                                            Environment *ev)
{
    /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
    M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetODPartKinds");

    _IDL_SEQUENCE_PartKindInfo ShapePartInfo;

    // Create structure PartKindInfo  and allocate memory for its fields
    PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
    info->partKindName = (ISOString) SOMMalloc(strlen(kODKindShapePart) + 1);
    info->partKindDisplayName = (string)SOMMalloc(strlen(kShapePartKindDisplayName)+1);
    info->filenameFilters =  (string)SOMMalloc(strlen("")+1);
    info->filenameTypes =  (string)SOMMalloc(strlen("")+1);
    info->categories =  (string)SOMMalloc(strlen(kShapePartCategory)+1);
    info->categoryDisplayName =  (string)SOMMalloc(strlen("")+1);
    info->objectID =  (string)SOMMalloc(strlen("")+1);

    // Copy the information into the structure
    strcpy(info->partKindName , kODKindShapePart);
    strcpy(info->partKindDisplayName, kShapePartKindDisplayName);
    strcpy(info->filenameFilters, "");
    strcpy(info->filenameTypes, "");
    strcpy(info->categories, kShapePartCategory);
    strcpy(info->categoryDisplayName, "");
    strcpy(info->objectID, "");

    ShapePartInfo._maximum = 1;
    ShapePartInfo._length = 1;
    ShapePartInfo._buffer = info;

    return ShapePartInfo;
}

SOM_Scope string  SOMLINK M_ShapePartclsGetOLE2ClassId(M_ShapePart *somSelf,
                                                        Environment *ev)
{
    /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
    M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetOLE2ClassId");

    // OLE2 Class ID is determined by running the tool UUIDGEN.EXE
    // or GUIDGEN.EXE found in the IBM VAC++ SDK\BIN directory
    // this tool is gauranteed to generate a unique ID based on your
    // network address and the time of day (DCE Standard)


    string OLE2 = "{6be34400-fba2-11cf-b25b-08005a49d940}";
    string OLE2ClassId = (string)SOMMalloc(strlen(OLE2)+1);
    strcpy(OLE2ClassId,OLE2);

    return OLE2ClassId;
}

SOM_Scope string  SOMLINK M_ShapePartclsGetWindowsIconFileName(M_ShapePart *somSelf,
                                                                Environment *ev)
{
    /* M_ShapePartData *somThis = M_ShapePartGetData(somSelf); */
    M_ShapePartMethodDebug("M_ShapePart","M_ShapePartclsGetWindowsIconFileName");

    string fileName = (string) SOMMalloc (strlen(kShapePartIconFileName)+1);
    strcpy(fileName,kShapePartIconFileName);
    return fileName;
}

