/* @(#)Z 1.52 com/src/samples/simple/iodsimpl.cpp, odsimplepart, od96nt, odnt9714c 97/04/02 17:55:07 (97/03/20 10:15:59) */
//====START_GENERATED_PROLOG======================================
//
//
//   COMPONENT_NAME: odsamples
//
//   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========================================
//

/*
 *      File:           SimplPrt.cpp
 *
 *   Contains:  Implementation of Simple Part
 *
 *   Copyright: (c) 1993-1994 by IBM Corp., all rights reserved.
 *
 */

/*
 *  This file was generated by the SOM Compiler and Emitter Framework.
 *  Generated using:
 *      SOM Emitter emitxtm: 2.38
 */

#ifdef __IBMC__
  #pragma linkage (SOMInitModule, system)
#endif

#ifndef SOM_Module_iodsimpl_Source
#define SOM_Module_iodsimpl_Source
#endif

#ifdef _PLATFORM_UNIX_
#include <Xm/XmAll.h>
#endif

#ifdef _PLATFORM_OS2_
#include <stdio.h>
#endif //_PLATFORM_OS2_

#ifndef _ODEXCEPT_
#include "ODExcept.h"
#endif

#ifndef _FOCUSLIB_
#include <FocusLib.h>
#endif

#ifndef _ODMATH_
#include "ODMath.h"
#endif

#ifndef _WINUTILS_
#include "WinUtils.h"
#endif

#ifndef _STORUTIL_
#include "StorUtil.h"
#endif

#ifndef _IODLINK_
#include "iodlink.xh"
#endif

#ifndef _ODDEBUG_
#include "ODDebug.h"
#endif

#ifndef _TEMPOBJ_
#include <TempObj.h>
#endif

#ifndef _ODRES_
#ifdef _PLATFORM_UNIX_
#include <odres.h>
#else
#include <ODRes.h>
#endif
#endif

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

#include <string.h>

#if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_)
#include "CmdDefs.xh"
#include "ODSessn.xh"
#include "WinStat.xh"
#include "Shape.xh"
#include "MenuBar.xh"
#include "Popup.xh"
#include "Foci.xh"
#include "Info.xh"
#include "FocusSet.xh"
#include "FocusItr.xh"
#include "Arbitrat.xh"
#include "Draft.xh"
#include "FacetItr.xh"
#include "Frame.xh"
#include "Facet.xh"
#include "FrFaItr.xh"
#include "Window.xh"
#include "StdTypes.xh"
#include "StdProps.xh"
#include "StorageU.xh"
#include "ODResrc.h"
#elif defined(_PLATFORM_UNIX_)
#include <odall.h>
#endif

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

// definition for class name; use it for adding HELP menu
#define kSimpleClassName "SimplePart"

#define SimplePart_Class_Source
#define VARIABLE_MACROS
#include "iodsimpl.xih"


const ODType   kPartHandlerName           = "SimplePart";
const ODType   kSimplePartPresNormal      = "SimplePart:Presentation:Normal";
const ODType   kSimplePartPresPalette     = "SimplePart:Presentation:Palette";
const ODType   kSimplePartKind            = "SimplePart";
const ODType   kSimplePartKindDisplayName = "Simple Part Kind";
const ODType   kSimplePartCategory        = "OpenDoc:Category:Sample";

// Define InitPropVal Storage Unit utility to focus on a propName.
inline void InitPropVal (Environment *ev, ODStorageUnit *su,
                         ODPropertyName propName, ODValueType valName)
{
    if (ODSUExistsThenFocus (ev, su, propName, valName))
         su->Remove (ev);

    ODSUAddPropValue (ev, su, propName, valName);

}

/******************************************************************
The following messages are defined in ODPart and changed in SimplePart.
 ******************************************************************/

SOM_Scope void  SOMLINK SimplePartsomInit(SimplePart *somSelf)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartsomInit");

    SimplePart_parent_ODPart_somInit(somSelf);

    _fPartWrapper = kODNULL;
    _fFocusSet = kODNULL;
    _fSession = kODNULL;
    _fWindowID = kODNULL;

    _fDisplayFrames = 0;
    _fIsInitialized = kODFalse;
    _fMenuBar = kODNULL;
    _fPopup = kODNULL;

    _hSmallIcon = kODNULL;
    _hLargeIcon = kODNULL;
    _hThumbnail = kODNULL;
    _hResModule = kODNULL;
}

SOM_Scope void  SOMLINK SimplePartsomUninit(SimplePart *somSelf)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartsomUninit");


    if (_fDisplayFrames != kODNULL)
      delete _fDisplayFrames;    // make sure it's empty first

    Environment * ev = somGetGlobalEnvironment();


    try
    {
      // Release the resource module
      somSelf->FreeResModule(ev);

      SimplePart_parent_ODPart_somUninit(somSelf);

    }

    catch(ODException _exception)
    {
    }
}

SOM_Scope void  SOMLINK SimplePartDisplayFrameAdded(SimplePart *somSelf,
                                                   Environment *ev,
                                                  ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayFrameAdded");
   try
   {

      _fDisplayFrames->AddLast(ev, frame);
      frame->Acquire(ev);

 
      if (!frame->IsRoot(ev))
      {
        // Store the frame shape to be used later if we change view types.
        TempODShape frameShape = frame->AcquireFrameShape(ev, kODNULL);
        frameShape->GetBoundingBox(ev, &_lastFrameRect);
      }

     PartInfoRec* pInfo = (PartInfoRec*)frame->GetPartInfo(ev);
     if (!pInfo)
     {
        pInfo = somSelf->CreateFramePartInfo(ev);
        if (frame->IsRoot(ev))
          pInfo->fNeedsActivating = kODTrue;

        frame->SetPartInfo(ev, (ODInfoType) pInfo);
     }
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartDisplayFrameConnected(SimplePart *somSelf,
                                                        Environment *ev,
                                                        ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayFrameConnected");
   try
   {

     _fDisplayFrames->AddLast(ev, frame);
     frame->Acquire(ev);

     PartInfoRec* pInfo = (PartInfoRec*)frame->GetPartInfo(ev);
     if (!pInfo)
     {
        pInfo = somSelf->CreateFramePartInfo(ev);
        if (frame->IsRoot(ev))
           pInfo->fNeedsActivating = kODTrue;
        frame->SetPartInfo(ev, (ODInfoType) pInfo);
     }

   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope void  SOMLINK SimplePartDisplayFrameRemoved(SimplePart *somSelf,
                                                      Environment *ev,
                                                     ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayFrameRemoved");
   try
   {
     if (frame  != kODNULL)
     {
        if (_fDisplayFrames->Contains(ev, frame))
        {
           _fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, _fFocusSet,frame );

           PartInfoRec* pInfo = (PartInfoRec*) frame ->GetPartInfo(ev);
           frame ->SetPartInfo(ev, (ODInfoType) kODNULL);
           somSelf->DeleteFramePartInfo(ev, pInfo);

           _fDisplayFrames->Remove(ev, frame);

           // Release the frame acquired during DisplayFrameAdded/Connected
           frame->Release(ev);
        }
        else
           THROW(kODErrInvalidFrame);
     }
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartDisplayFrameClosed(SimplePart *somSelf,
                                                     Environment *ev,
                                                     ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayFrameClosed");
   try
   {

     if (frame  != kODNULL)
     {
        if (_fDisplayFrames->Contains(ev, frame))
        {
           _fSession->GetArbitrator(ev)->RelinquishFocusSet(ev, _fFocusSet,frame );

           PartInfoRec* pInfo = (PartInfoRec*) frame ->GetPartInfo(ev);
           somSelf->DeleteFramePartInfo(ev, pInfo);

           _fDisplayFrames->Remove(ev, frame);

           // Release the frame acquired during DisplayFrameAdded/Connected
           frame->Release(ev);
        }
        else
           THROW(kODErrInvalidFrame);
     }
   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope ODID  SOMLINK SimplePartOpen(SimplePart *somSelf,  Environment *ev,
                                       ODFrame* frame)
{
  SimplePartData *somThis = SimplePartGetData(somSelf);
  SimplePartMethodDebug("SimplePart","SimplePartOpen");

  try
  {

    TempODWindow window = kODNULL;

    ODWindowState* winState=_fSession->GetWindowState(ev);

    if (frame)
    {
        if (frame->IsRoot(ev))
        {
            // There are two situations in which this code will be executed:
            // 1) This is the root part of a stored document that is being reopened, or
            // 2) This is an embedded part of a document that was saved (by
            //    closing the document or by creating a draft) while this part was
            //    Opened-As-Window. And now the document is reopened.
            // In both cases the frame is marked as a root frame, but in the second
            // case the isRootWindow property is FALSE.

            WindowProperties props;
            BeginGetWindowProperties(ev, frame, &props);

            ODPlatformWindow platwin = winState->CreatePlatformWindow(ev, kODFalse);

#if defined(_PLATFORM_WIN32_)
            SetWindowPos(platwin,
                         HWND_TOP,
                         props.boundsRect.left,
                         props.boundsRect.top,
                         props.boundsRect.right,
                         props.boundsRect.bottom,
                         SWP_NOACTIVATE | SWP_NOREDRAW);

#elif defined(_PLATFORM_OS2_)
            WinSetWindowPos(platwin,
                         HWND_TOP,
                         props.boundsRect.xLeft,
                         props.boundsRect.yBottom,
                         props.boundsRect.xRight,
                         props.boundsRect.yTop,
                         SWP_SIZE|SWP_MOVE|SWP_NOREDRAW);

#elif defined(_PLATFORM_UNIX_)
            Display *display = winState->GetDisplay(ev);

            Widget shellWidget = XtWindowToWidget(display,
                                                  platwin);

            XtVaSetValues(shellWidget,
                          XmNx, props.boundsRect.x,
                          XmNy, props.boundsRect.y,
                          XmNwidth, props.boundsRect.width,
                          XmNheight, props.boundsRect.height,
                          NULL);
#endif
            window = winState->RegisterWindowForFrame(ev,
                                                      platwin,
                                                      frame,    //  kODFrameObject
                                                      props.isRootWindow,
                                                      props.isResizable,
                                                      props.isFloating,
                                                      kODTrue,  // shouldSave
                                                      kODTrue,  // shouldDispose
                                                      props.sourceFrame);


            EndGetWindowProperties(ev, &props);     // release source frame
            window->Open(ev);
            window->Show(ev);
        }
        else
        {
            // This is a request to Open-As-Window when this is an embedded frame
            window=winState->AcquireWindow(ev, _fWindowID);
            if (window)
            {
                // Window was created previously. Just bring it to the front.
                window->Select(ev);
            }
            else
            {
                // First time we get an Open-As-Window request for this embedded part.
                window = somSelf->MakeWindow(ev,frame);
                window->Open(ev);
                window->Show(ev);
                window->Select(ev);
            }

        } // end of frame->IsRoot
    } // end of frame
    else
    {
       // Opening document for the first time. Create initial root window.
        window = somSelf->MakeWindow(ev, frame);
        window->Open(ev);
        window->Show(ev);
        window->Select(ev);
    }
    _fWindowID = window->GetID(ev);
  }
  catch(ODException _exception)
  {
  }

  return _fWindowID;
}

SOM_Scope ODWindow* SOMLINK   SimplePartMakeWindow(SimplePart *somSelf, Environment *ev, ODFrame *sourceFrame)
{
  SimplePartData *somThis = SimplePartGetData(somSelf);
  SimplePartMethodDebug("SimplePart","SimplePartMakeWindow");
  ODPlatformWindow platwin = kODNULL;
  ODWindow* window         = kODNULL;

  try
  {

    ODWindowState* winState=_fSession->GetWindowState(ev);

    platwin = winState->CreatePlatformWindow(ev, kODFalse);

    window = winState->RegisterWindow(ev,
                                      platwin,
                                      kODFrameObject,                          // frameType
                                      sourceFrame==kODNULL,                    // isRootWindow
                                      kODTrue,                                 // isResizable
                                      kODFalse,                                // isFloating
                                      kODTrue,                                 // shouldSave
                                      kODTrue,                                 // shouldDispose
                                      _fPartWrapper,                           // rootPart
                                      _fSession->Tokenize(ev, kODViewAsFrame), // ViewType
                                      _fSession->Tokenize(ev, kODPresDefault), // presentation
                                      sourceFrame                              // sourceFrame
                                      );
  }
  catch(ODException _exception)
  {
  }

  return window;
}

SOM_Scope ODShape*  SOMLINK SimplePartAdjustBorderShape(SimplePart *somSelf,
                                                         Environment *ev,
                                                        ODFacet* embeddedFacet,
                                                        ODShape* shape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAdjustBorderShape");

   try
   {

     if ( shape == kODNULL )
       return kODNULL;
     shape->Acquire(ev);
   }
   catch(ODException _exception)
   {
   }

    return shape;
}

SOM_Scope void  SOMLINK SimplePartDraw(SimplePart *somSelf,  Environment *ev,
                                       ODFacet* facet, ODShape* invalidShape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDraw");

   try
   {

     ODTypeToken viewType = facet->GetFrame(ev)->GetViewType(ev);

     if(viewType == _fSession->Tokenize(ev,kODViewAsSmallIcon))
     {
       somSelf->DrawIcon(ev, facet, invalidShape, SmallIconView);
     }
     else if(viewType == _fSession->Tokenize(ev,kODViewAsLargeIcon))
     {
       somSelf->DrawIcon(ev, facet, invalidShape, LargeIconView);
     }
     else if(viewType == _fSession->Tokenize(ev,kODViewAsThumbnail))
     {
       somSelf->DrawThumbnail(ev, facet, invalidShape);
     }
     else
     {
       somSelf->DrawFrame(ev, facet, invalidShape);
     }
   }
   catch(...)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartHighlightChanged(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODFacet* facet)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartHighlightChanged");

   try
   {

     /*
      * cause ourselves to be redrawn.  FocusLib will take care of setting the
      * default mix mode so that we paint properly.
      */
     facet->Invalidate(ev, kODNULL, kODNULL);
   }
   catch(ODException _exception)
   {
   }
}


SOM_Scope void  SOMLINK SimplePartCommitRelinquishFocus(SimplePart *somSelf,
                                                         Environment *ev,
                                                        ODTypeToken focus,
                                                        ODFrame* ownerFrame,
                                                        ODFrame* proposedFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCommitRelinquishFocus");

   try
   {

     somSelf->FocusLost(ev, focus, ownerFrame);
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartFocusAcquired(SimplePart *somSelf,
                                                Environment *ev,
                                                ODTypeToken focus,
                                                ODFrame* ownerFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFocusAcquired");

   try
   {

     if (focus == _fSelectionFocus)
     {
       PartInfoRec* pInfo = (PartInfoRec*) ownerFrame->GetPartInfo(ev);
       pInfo->fIsActive = kODTrue;
     } else if (focus == _fMenuFocus) {
          _fMenuBar->Display(ev);
     }
   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope void  SOMLINK SimplePartFocusLost(SimplePart *somSelf,
                                             Environment *ev,
                                            ODTypeToken focus,
                                            ODFrame* ownerFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFocusLost");

   try
   {

     if (focus == _fSelectionFocus)
     {
       PartInfoRec* pInfo = (PartInfoRec*) ownerFrame->GetPartInfo(ev);
       pInfo->fIsActive = kODFalse;
     }
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartCloneInto(SimplePart *somSelf, Environment *ev,
                                            ODDraftKey key,
                                            ODStorageUnit* storageUnit,
                                            ODFrame* scopeFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCloneInto");

  try
  {
    SimplePart_parent_ODPart_CloneInto(somSelf, ev, key, storageUnit, scopeFrame);
    InitPropVal (ev, storageUnit, kODPropContents, kSimplePartKind);

#ifdef _PLATFORM_OS2_

// Customized icon support for OS2.

     ULONG cbIconSize;
     PBYTE pIconData = NULL;

     // We need to load the icons if we haven't already
     if(!_hLargeIcon) somSelf->CreateIcons(ev);

     if (!DosQueryResourceSize( _hResModule, RT_POINTER, kODIcon, &cbIconSize) &&
         !DosGetResource( _hResModule, RT_POINTER, kODIcon, (PPVOID)&pIconData)  )
     {
        InitPropVal (ev, storageUnit, kODPropIconFamily, kODIconFamily);
        StorageUnitSetValue( storageUnit, ev, cbIconSize, (ODValue)pIconData );
        DosFreeResource(pIconData);
     }
     else
        PRINT("SimplePrt DosGetResource failed!\n");

// End customized icon support
#endif // _PLATFORM_OS2_
  }
  catch(ODException _exception)
  {
  }
}


SOM_Scope void  SOMLINK SimplePartExternalizeKinds(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODTypeList* kindset)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartExternalizeKinds");

   try
   {

     somSelf->Externalize(ev);
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartExternalize(SimplePart *somSelf,
                                               Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartExternalize");

   try
   {

     ODStorageUnit* su = somSelf->GetStorageUnit(ev);

     if(su->Exists(ev, kODPropContents, kSimplePartKind, 0))
     {
         su->Focus(ev, kODPropContents, kODPosUndefined, kSimplePartKind,
                   0, kODPosUndefined);
         su->Remove(ev);
         su->AddValue(ev, kSimplePartKind);
     }
     else
     {
         su->AddProperty(ev, kODPropContents)->AddValue(ev, kSimplePartKind);
     }

     su->Focus(ev, kODPropContents, kODPosUndefined, kSimplePartKind, 0, kODPosUndefined);
     ODSetRectProp(ev, su, kODNULL, kODNULL, &_lastFrameRect);
   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartChangeKind(SimplePart *somSelf,
                                              Environment *ev,
                                             ODType kind)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartChangeKind");
    ODStorageUnit * su = somSelf->GetStorageUnit(ev);
    su->Focus(ev, kODPropContents, kODPosUndefined, kODTypeAll, 0, kODPosUndefined);
    su->Remove(ev);
    su->AddProperty(ev, kODPropContents)->AddValue(ev, kSimplePartKind);

}

SOM_Scope ODBoolean  SOMLINK SimplePartHandleEvent(SimplePart *somSelf,
                                                    Environment *ev,
                                                    ODEventData* event,
                                                    ODFrame* frame,
                                                    ODFacet* facet,
                                                    ODEventInfo* eventInfo)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartHandleEvent");

    ODBoolean handled = kODFalse;

   try
   {
      ODEventType theEventType;

#ifdef _PLATFORM_OS2_
      theEventType = event->msg;
#elif defined(_PLATFORM_WIN32_)
      theEventType = event->message;
#elif defined(_PLATFORM_UNIX_)
      theEventType = event->type;
#endif

    switch (theEventType)
    {
#ifdef _PLATFORM_WIN32_
      case WM_LBUTTONDBLCLK:
      case WM_MBUTTONDBLCLK:
      case WM_RBUTTONDBLCLK:
#elif defined(_PLATFORM_OS2_)
      case WM_BUTTON1DBLCLK:
      case WM_BUTTON2DBLCLK:
#endif
#if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_)  // Not supported on AIX
          {
           if(!frame->IsRoot(ev))
           {
              somSelf->Open(ev, frame);
              handled = kODTrue;
           }
          }
          break;
#endif

      case kODEvtMouseDown:
          {

             somSelf->Activate(ev, facet);
             handled = kODTrue;
#ifdef _PLATFORM_UNIX_
             // Display the Popup menu when the third mouse button is pressed.
             XButtonEvent *xbutton = (XButtonEvent *)event;
             if(xbutton->button == Button3)
             {
                handled = somSelf->DisplayPopupMenu(ev, event, frame, facet, eventInfo);
             }
#endif
          }
          break;

#ifdef _PLATFORM_WIN32_
      case WM_RBUTTONDOWN:
#elif defined(_PLATFORM_OS2_)
      case WM_CONTEXTMENU:
#endif
#if defined(_PLATFORM_WIN32_) || defined(_PLATFORM_OS2_)
          // Display the Popup menu when this event arrives.
          handled = somSelf->DisplayPopupMenu(ev, event, frame, facet, eventInfo);
          break;
#endif

       case kODEvtActivate:
          {
            handled = kODTrue; // actually ignored by dispatcher
#ifdef _PLATFORM_WIN32_
            if ((LOWORD(event->wParam) == WA_ACTIVE) ||
                (LOWORD(event->wParam) == WA_CLICKACTIVE))
#elif defined(_PLATFORM_OS2_)
            if (SHORT1FROMMP(event->mp1) != 0)
#elif defined(_PLATFORM_UNIX_)
            if (eventInfo->originalType == FocusIn)
#endif
               somSelf->ActivatingWindow(ev, frame);
            else
               somSelf->DeActivatingWindow(ev, frame);
          }
          break;

       case kODEvtMenu:
#ifdef _PLATFORM_WIN32_
          if ((HIWORD(event->wParam) == 1) ||        // From MENU
              (HIWORD(event->wParam) == 0))          // From ACCELERATOR  (other values are from control
#elif defined(_PLATFORM_OS2_)
          if (SHORT1FROMMP(event->mp2) & CMDSRC_MENU ||
              SHORT1FROMMP(event->mp2) & CMDSRC_ACCELERATOR)
#endif //_PLATFORM_OS2_
          {
             handled = somSelf->HandleMenuEvent(ev, frame, event);
          }
          break;

       default:
          return kODFalse;
    }
   }
   catch(ODException _exception)
   {
   }

    return handled;
}

SOM_Scope void  SOMLINK SimplePartAdjustMenus(SimplePart *somSelf,
                                               Environment *ev,
                                              ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAdjustMenus");

   try
   {
     if (frame->IsRoot(ev))
     {
        // Disable menu items which are unsupported only when root
        _fMenuBar->EnableMenuItem(ev, IDMS_DOCUMENT, DOC_SETUP, kODFalse);
        _fMenuBar->EnableMenuItem(ev, IDMS_DOCUMENT, DOC_PRINT, kODFalse);
     }else{
        // Enable menu items which are supported only when embedded
        _fMenuBar->EnableMenuItem(ev, IDMS_VIEW, VIEW_VIEWINWINDOW, kODTrue);
        _fMenuBar->EnableMenuItem(ev, IDMS_VIEW, VIEW_SHOWAS, kODTrue);
     }

     // Enable supported menu items
     _fMenuBar->EnableMenuItem(ev, IDMS_VIEW, VIEW_PROPERTIES, kODTrue);


     // Disable unsupported menu items
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_CREATE, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_CUT, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_COPY, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTE, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTEAS, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_LINK_MENU, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_DELETE, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_SELECTALL, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_DESELECTALL, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_OPENSEL, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_SELPROPERTIES, kODFalse);
     _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_INSERT, kODFalse);
   }
   catch(ODException _exception)
   {
   }

}


SOM_Scope ODActionData  SOMLINK SimplePartReadActionState(SimplePart *somSelf,
                                                          Environment *ev,
                                                          ODStorageUnitView* storageUnitView)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartReadActionState");
    ODActionData data;
    data._maximum = 0;
    data._length = 0;
    data._buffer = kODNULL;
    return data;
}

SOM_Scope void  SOMLINK SimplePartInitPart(SimplePart *somSelf,
                                            Environment *ev,
    ODStorageUnit* storageUnit, ODPart* partWrapper)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartInitPart");

   try
   {

     if (_fIsInitialized)
       return;

     _fIsInitialized = kODTrue;

     parent_InitPart(somSelf, ev, storageUnit, partWrapper);

     somSelf->CommonInit(ev, partWrapper);

   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope void  SOMLINK SimplePartInitPartFromStorage(SimplePart *somSelf,
                                                       Environment *ev,
                                                       ODStorageUnit* storageUnit, ODPart* partWrapper)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartInitPartFromStorage");

   try
   {

     if (_fIsInitialized)
       return;

     _fIsInitialized = kODTrue;

     parent_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);

     somSelf->CommonInit(ev, partWrapper);

     // Read in the value of the last frame's bounding rectangle.
     if (ODSUExistsThenFocus (ev, storageUnit, kODPropContents, kSimplePartKind)) {
       ODGetRectProp(ev, storageUnit, kODNULL, kODNULL, &_lastFrameRect);
     } else {
       _lastFrameRect.left = 0;
       _lastFrameRect.right = IntToFixed(200);
       #ifdef _PLATFORM_OS2_
       _lastFrameRect.top = IntToFixed(200);
       _lastFrameRect.bottom = 0;
       #else
       _lastFrameRect.top = 0;
       _lastFrameRect.bottom = IntToFixed(200);
       #endif
     }
   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope void  SOMLINK SimplePartRelease(SimplePart *somSelf,
                                           Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRelease");

   try
   {

     SimplePart_parent_ODPart_Release(somSelf, ev);
     if (somSelf->GetRefCount(ev) == 0)
        somSelf->GetStorageUnit(ev)->GetDraft(ev)->ReleasePart(ev, somSelf);
   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope void  SOMLINK SimplePartViewTypeChanged(SimplePart *somSelf,
                                                  Environment *ev,
                                                  ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartViewTypeChanged");

    try
    {

      if(frame->IsRoot(ev))
      {
         // When this is a root part, only support frame view.
         frame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsFrame));
         return;
      }
      else
      {
        // Set frame shape according to view type
        somSelf->AdjustViewTypeShapes(ev, frame);

        // Get the new frame shape to be invalidated.
        TempODShape newShape = frame->AcquireFrameShape(ev,kODNULL);

        // Force the display of our new view type
        frame->Invalidate(ev, newShape, kODNULL);
      }
    }
    catch(ODException _exception)
    {
    }
}

SOM_Scope void  SOMLINK SimplePartFrameShapeChanged(SimplePart *somSelf,
                                                     Environment *ev,
                                                    ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFrameShapeChanged");

    // Set frame shape according to view type
    somSelf->AdjustViewTypeShapes(ev, frame);

}

SOM_Scope void  SOMLINK SimplePartFacetAdded(SimplePart *somSelf,
                                              Environment *ev,
                                             ODFacet* facet)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFacetAdded");

    try
    {
      // Set frame shape according to view type
      somSelf->AdjustViewTypeShapes(ev, facet->GetFrame(ev));

    }
    catch(ODException _exception)
    {
    }

}

/******************************************************************
The following messages are defined in ODPart and not changed in SimplePart.
 ******************************************************************/

SOM_Scope void  SOMLINK SimplePartFulfillPromise(SimplePart *somSelf,
                                                  Environment *ev,
                                                 ODStorageUnitView* promiseSUView)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFulfillPromise");

}

SOM_Scope void  SOMLINK SimplePartDropCompleted(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODPart* destPart,
                                                ODDropResult dropResult)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDropCompleted");

}

SOM_Scope ODDropResult  SOMLINK SimplePartDrop(SimplePart *somSelf,
                                                Environment *ev,
                                               ODDragItemIterator* dropInfo,
                                               ODFacet* facet,
                                               ODPoint* where)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDrop");

    return kODDropFail;


}

SOM_Scope void  SOMLINK SimplePartContainingPartPropertiesUpdated(SimplePart *somSelf,
                                                                   Environment *ev,
                                                                  ODFrame* frame,
                                                                  ODStorageUnit* propertyUnit)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartContainingPartPropertiesUpdated");


}

SOM_Scope ODStorageUnit*  SOMLINK SimplePartAcquireContainingPartProperties(SimplePart *somSelf,
                                                                         Environment *ev,
                                                                        ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAcquireContainingPartProperties");

    return kODNULL;

}

SOM_Scope ODBoolean  SOMLINK SimplePartRevealFrame(SimplePart *somSelf,
                                               Environment *ev,
                                              ODFrame* embeddedFrame,
                                              ODShape* revealShape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRevealFrame");
    return kODFalse;
}

SOM_Scope void  SOMLINK SimplePartEmbeddedFrameSpec(SimplePart *somSelf,
                                                     Environment *ev,
                                                    ODFrame* embeddedFrame,
                                                    ODObjectSpec* spec)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartEmbeddedFrameSpec");

}

SOM_Scope ODEmbeddedFramesIterator*  SOMLINK SimplePartCreateEmbeddedFramesIterator(SimplePart *somSelf,
                                                                                     Environment *ev,
                                                                                    ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCreateEmbeddedFramesIterator");
    return (ODEmbeddedFramesIterator *) kODNULL;
}

SOM_Scope void  SOMLINK SimplePartAttachSourceFrame(SimplePart *somSelf,
                                                     Environment *ev,
                                                    ODFrame* frame,
                                                    ODFrame* sourceFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAttachSourceFrame");

}

SOM_Scope void  SOMLINK SimplePartPresentationChanged(SimplePart *somSelf,
                                                       Environment *ev,
                                                      ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartPresentationChanged");
}

SOM_Scope void  SOMLINK SimplePartSequenceChanged(SimplePart *somSelf,
                                                   Environment *ev,
                                                  ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartSequenceChanged");
}

SOM_Scope void  SOMLINK SimplePartWritePartInfo(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODInfoType partInfo,
                                                ODStorageUnitView* storageUnitView)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartWritePartInfo");

}
SOM_Scope ODInfoType  SOMLINK SimplePartReadPartInfo(SimplePart *somSelf, Environment *ev,
    ODFrame* frame,
    ODStorageUnitView* storageUnitView)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartReadPartInfo");

    return ((ODInfoType)kODNULL);

}

SOM_Scope void  SOMLINK SimplePartClonePartInfo(SimplePart *somSelf, Environment *ev,
    ODDraftKey key,
    ODInfoType partInfo,
    ODStorageUnitView* storageUnitView,
    ODFrame* scopeFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartClonePartInfo");

}
SOM_Scope ODFrame*  SOMLINK SimplePartRequestEmbeddedFrame(SimplePart *somSelf,
                                                            Environment *ev,
                                                           ODFrame* containingFrame,
                                                           ODFrame* baseFrame,
                                                           ODShape* frameShape,
                                                           ODPart* embedPart,
                                                           ODTypeToken viewType,
                                                           ODTypeToken presentation,
                                                           ODBoolean isOverlaid)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRequestEmbeddedFrame");
    return baseFrame;
}

SOM_Scope void  SOMLINK SimplePartRemoveEmbeddedFrame(SimplePart *somSelf,
                                                       Environment *ev,
                                                      ODFrame* embeddedFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRemoveEmbeddedFrame");

}

SOM_Scope ODShape*  SOMLINK SimplePartRequestFrameShape(SimplePart *somSelf,
                                                         Environment *ev,
                                                        ODFrame* embeddedFrame,
                                                        ODShape* frameShape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRequestFrameShape");

    return frameShape;
}
SOM_Scope void  SOMLINK SimplePartUsedShapeChanged(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODFrame* embeddedFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartUsedShapeChanged");

}

SOM_Scope void  SOMLINK SimplePartFacetRemoved(SimplePart *somSelf,
                                                Environment *ev,
                                               ODFacet* facet)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFacetRemoved");

}

SOM_Scope void  SOMLINK SimplePartCanvasChanged(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODFacet* facet)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCanvasChanged");

}

SOM_Scope void  SOMLINK SimplePartGeometryChanged(SimplePart *somSelf,
                                                   Environment *ev,
    ODFacet* facet, ODBoolean clipShapeChanged, ODBoolean externalTransformChanged)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartGeometryChanged");

}

SOM_Scope void  SOMLINK SimplePartCanvasUpdated(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODCanvas* canvas)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCanvasUpdated");

}

SOM_Scope ODLinkSource*  SOMLINK SimplePartCreateLink(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODByteArray* data)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCreateLink");

    return 0;

}

SOM_Scope void  SOMLINK SimplePartLinkUpdated(SimplePart *somSelf,
                                               Environment *ev,
                                              ODLink* updatedLink,
                                              ODUpdateID id)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartLinkUpdated");

}

SOM_Scope void  SOMLINK SimplePartRevealLink(SimplePart *somSelf,
                                              Environment *ev,
                                             ODLinkSource* linkSource)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRevealLink");

}

SOM_Scope void  SOMLINK SimplePartEmbeddedFrameUpdated(SimplePart *somSelf,
                                                        Environment *ev,
                                                       ODFrame* frame,
                                                       ODUpdateID change)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartEmbeddedFrameUpdated");

}

SOM_Scope void  SOMLINK SimplePartLinkStatusChanged(SimplePart *somSelf,
                                                     Environment *ev,
                                                    ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartLinkStatusChanged");

}

SOM_Scope ODBoolean  SOMLINK SimplePartBeginRelinquishFocus(SimplePart *somSelf,
                                                             Environment *ev,
                                                            ODTypeToken focus,
                                                            ODFrame* ownerFrame,
                                                            ODFrame* proposedFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartBeginRelinquishFocus");


    ODBoolean rc=kODTrue;

    try {

        ODTypeToken modalFocus  = _fSession->Tokenize(ev, kODModalFocus);
        if ( focus == modalFocus ) {
            ODPart *proposedFramePart = proposedFrame->AcquirePart(ev);

            // if proposedFramePart is not this part then
            //   Another part is trying to put up a Modal dialog
            //   while we are currently displaying ours.
            //
            //   Deny the request.

            rc= (proposedFramePart==somSelf) ? kODTrue : kODFalse;

            proposedFramePart->Release(ev);
        }

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

    return rc;

}

SOM_Scope void  SOMLINK SimplePartAbortRelinquishFocus(SimplePart *somSelf,
                                                        Environment *ev,
                                                       ODTypeToken focus,
                                                       ODFrame* ownerFrame,
                                                       ODFrame* proposedFrame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAbortRelinquishFocus");

}

SOM_Scope void  SOMLINK SimplePartUndoAction(SimplePart *somSelf,
                                              Environment *ev,
                                             ODActionData* actionState)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartUndoAction");

}

SOM_Scope void  SOMLINK SimplePartRedoAction(SimplePart *somSelf,
                                              Environment *ev,
                                             ODActionData* actionState)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartRedoAction");

    // not much to redo yet
}

SOM_Scope void  SOMLINK SimplePartDisposeActionState(SimplePart *somSelf,
                                                      Environment *ev,
                                                     ODActionData* actionState,
                                                     ODDoneState doneState)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisposeActionState");

}

SOM_Scope void  SOMLINK SimplePartWriteActionState(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODActionData* actionState,
                                                   ODStorageUnitView* storageUnitView)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartWriteActionState");

}

SOM_Scope ODBoolean  SOMLINK SimplePartHasExtension(SimplePart *somSelf,
                                                     Environment *ev,
                                                    ODType extensionName)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartHasExtension");

   try
   {

     return (SimplePart_parent_ODPart_HasExtension(somSelf, ev,
                                                   extensionName));
   }
   catch(ODException _exception)
   {
   }

    return kODFalse;
}

SOM_Scope ODExtension*  SOMLINK SimplePartAcquireExtension(SimplePart *somSelf,
                                                        Environment *ev,
                                                       ODType extensionName)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAcquireExtension");

    try
    {

       return (SimplePart_parent_ODPart_AcquireExtension(somSelf, ev,
                                                  extensionName));
    }
    catch(ODException _exception)
    {
    }

    return kODNULL;
}

SOM_Scope void  SOMLINK SimplePartReleaseExtension(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODExtension* extension)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartReleaseExtension");

    try
    {

       SimplePart_parent_ODPart_ReleaseExtension(somSelf, ev, extension);
    }
    catch(ODException _exception)
    {
    }
}

/******************************************************************
The following messages belong to DLL and Metaclass.
 ******************************************************************/

SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
                                 string className)
{
   SOM_IgnoreWarning (majorVersion);  /* This function makes   */
   SOM_IgnoreWarning (minorVersion);  /* no use of the passed  */
   SOM_IgnoreWarning (className);     /* arguments.            */

   SimplePartNewClass ( SimplePart_MajorVersion, SimplePart_MinorVersion);
}
#ifdef _PLATFORM_WIN32_
int CALLBACK LibMain(HINSTANCE inst, WORD ds, WORD Heapsize, LPSTR cmdLine)
{
  SOM_ClassLibrary("iodsimpl.dll");
  return 1;
}
#endif

SOM_Scope ISOString  SOMLINK M_SimplePartclsGetODPartHandlerName(M_SimplePart *somSelf,
                                                                  Environment *ev)
{
    /* M_SimplePartData *somThis = M_SimplePartGetData(somSelf); */
    M_SimplePartMethodDebug("M_SimplePart","M_SimplePartclsGetODPartHandlerName");

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

    return (ISOString) handlerName;
}


SOM_Scope string  SOMLINK M_SimplePartclsGetODPartHandlerDisplayName(M_SimplePart *somSelf,
                                                                      Environment *ev)
{
    /* M_SimplePartData *somThis = M_SimplePartGetData(somSelf); */
    M_SimplePartMethodDebug("M_SimplePart","M_SimplePartclsGetODPartHandlerDisplayName");

    string tempName = "Simple Part";
    string displayName =  (string) SOMMalloc(strlen(tempName) + 1);
    strcpy(displayName, tempName);
    return displayName;

}

SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK M_SimplePartclsGetODPartKinds(M_SimplePart *somSelf,
                                                                             Environment *ev)
{
    /* M_SimplePartData *somThis = M_SimplePartGetData(somSelf); */
    M_SimplePartMethodDebug("M_SimplePart","M_SimplePartclsGetODPartKinds");

    _IDL_SEQUENCE_PartKindInfo SimplePartInfo;
    // Create structure PartKindInfo  and allocate memory for variable
    PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
    info->partKindName = (ISOString) SOMMalloc(strlen(kSimplePartKind) + 1);
    info->partKindDisplayName = (string)SOMMalloc(strlen(kSimplePartKindDisplayName)+1);
    info->filenameFilters =  (string)SOMMalloc(strlen("")+1);
    info->filenameTypes =  (string)SOMMalloc(strlen("")+1);
    info->categories =  (string)SOMMalloc(strlen(kSimplePartCategory) + 1);
    info->categoryDisplayName =  (string)SOMMalloc(strlen("Sample") + 1);
    info->objectID =  (string)SOMMalloc(strlen("") + 1);
    // Copy the information into the structure
    strcpy(info->partKindName , kSimplePartKind);
    strcpy(info->partKindDisplayName, kSimplePartKindDisplayName);
    strcpy(info->filenameFilters, "");
    strcpy(info->filenameTypes, "");
    strcpy(info->categories, kSimplePartCategory);
    strcpy(info->categoryDisplayName, "Sample");
    strcpy(info->objectID, "");


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

    return SimplePartInfo;



}

SOM_Scope string  SOMLINK M_SimplePartclsGetOLE2ClassId(M_SimplePart *somSelf,
                                                         Environment *ev)
{
    /* M_SimplePartData *somThis = M_SimplePartGetData(somSelf); */
    M_SimplePartMethodDebug("M_SimplePart","M_SimplePartclsGetOLE2ClassId");

    string tempClassID = "{8ffbed80-caaa-11cf-9935-08005a88688b}";
    string classID = (string) SOMMalloc(strlen(tempClassID) + 1);
    strcpy(classID, tempClassID);
    return classID;
}

SOM_Scope string  SOMLINK M_SimplePartclsGetWindowsIconFileName(M_SimplePart *somSelf,
                                                                 Environment *ev)
{
    /* M_SimplePartData *somThis = M_SimplePartGetData(somSelf); */
    M_SimplePartMethodDebug("M_SimplePart","M_SimplePartclsGetWindowsIconFileName");

    string kWindowsIcon = "iodsimpl.ico";
    string WindowsIconFileName = (string)SOMMalloc(strlen(kWindowsIcon)+1);
    strcpy(WindowsIconFileName,kWindowsIcon);

    return WindowsIconFileName;
}


/******************************************************************
The following messages are defined in Simple Part itself and are not
inherited from ODPart.
******************************************************************/

SOM_Scope void  SOMLINK SimplePartCommonInit(SimplePart *somSelf,
                                             Environment *ev,
                                             ODPart *partWrapper)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCommonInit");

   try
   {

     ODStorageUnit* su = somSelf->GetStorageUnit(ev);
     _fPartWrapper = partWrapper;
     _fDisplayFrames = new IODLinkedList;
     _fSession = su->GetSession(ev);
     _fSelectionFocus = _fSession->Tokenize(ev, kODSelectionFocus);
     _fMenuFocus = _fSession->Tokenize(ev, kODMenuFocus);
     _fKeyFocus = _fSession->Tokenize(ev, kODKeyFocus);
     _fFocusSet = _fSession->GetArbitrator(ev)->CreateFocusSet(ev);
     _fFocusSet->Add(ev, _fSelectionFocus);
     _fFocusSet->Add(ev, _fMenuFocus);
     _fFocusSet->Add(ev, _fKeyFocus);
     _fInFrameNegotiation = kODFalse;
     _fPrevViewType = FrameView;


     _fMenuBar = _fSession->GetWindowState(ev)->CopyBaseMenuBar(ev);
     // It is required that parts instantiate their menu bars from
     // the base OpenDoc menu bar. This maintains consistency in the
     // default menu items and their placement.
     // Since the object is a copy, we can add and subtract menus and
     // items without affecting other running parts.
     if ( _fMenuBar ){
        _fPopup = _fSession->GetWindowState(ev)->CopyBasePopup(ev);
        somSelf->InstallMenus(ev);
     }

   }
   catch(ODException _exception)
   {
   }
}

SOM_Scope void  SOMLINK SimplePartActivateFrame(SimplePart *somSelf,
                                                 Environment *ev,
                                                ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartActivateFrame");

    try
    {

      if (frame != kODNULL) {

        ODBoolean succeeded = kODFalse;

        succeeded = _fSession->GetArbitrator(ev)->RequestFocusSet(ev, _fFocusSet,frame);

        if (succeeded)
        {
           somSelf->FocusAcquired(ev, _fSelectionFocus, frame);
           somSelf->FocusAcquired(ev, _fMenuFocus, frame);
           somSelf->FocusAcquired(ev, _fKeyFocus, frame);
        }
      }
    }
    catch(ODException _exception)
    {
    }
}

// Private method
SOM_Scope void  SOMLINK SimplePartActivatingWindow(SimplePart *somSelf,
                                                    Environment *ev,
                                                   ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartActivatingWindow");

    try
    {

      PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
      if (pInfo->fNeedsActivating)
      {
         somSelf->ActivateFrame(ev, frame);
         pInfo->fNeedsActivating = kODFalse;
      }
    }
    catch(ODException _exception)
    {
    }

}

// Private method
SOM_Scope void  SOMLINK SimplePartDeActivatingWindow(SimplePart *somSelf,
                                                      Environment *ev,
                                                     ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDeActivatingWindow");

    try
    {

      PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
      TempODFrame tempFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fSelectionFocus);
      if (frame == tempFrame)
      {
         if (!pInfo->fNeedsActivating)
         {
            pInfo->fNeedsActivating = kODTrue;
         }
      }
      else
      {
         if (pInfo->fNeedsActivating)
         {
            pInfo->fNeedsActivating = kODFalse;
         }
      }
    }
    catch(ODException _exception)
    {
    }

}


SOM_Scope void  SOMLINK SimplePartActivate(SimplePart *somSelf,
                                                Environment *ev,
                                                ODFacet* facet)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartActivate");

   try
   {

     if (!facet->GetWindow(ev)->IsActive(ev))
        facet->GetWindow(ev)->Select(ev);
     else {
        PartInfoRec* pInfo = (PartInfoRec*) facet->GetFrame(ev)->GetPartInfo(ev);
        if (!pInfo->fIsActive) {
           somSelf->ActivateFrame(ev, facet->GetFrame(ev));
        } /* endif */
     } /* endif */
   }
   catch(ODException _exception)
   {
   }

}

SOM_Scope ODBoolean  SOMLINK SimplePartHandleMenuEvent(SimplePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* focusFrame,
                                                       ODEventData* event)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartHandleMenuEvent");

    ODBoolean handled = kODFalse;

    try
    {

#ifdef _PLATFORM_WIN32_
    ODCommandID command = event->wParam;
#elif defined(_PLATFORM_OS2_)
    ODCommandID command = LONGFROMMP(event->mp1);
#elif defined(_PLATFORM_UNIX_)
    ODMenuItemID command = ((ODMenuEventData *)event)->item;
#endif

      switch (command)
      {
         case VIEW_PROPERTIES:
            {
              ODFrameFacetIterator* facets = focusFrame->CreateFacetIterator(ev);
              _fSession->GetInfo(ev)->ShowPartFrameInfo(ev,facets->First(ev), kODTrue);
              delete facets;
              handled = kODTrue;
            }
            break;
         case VIEW_SASMALLICON:
            focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsSmallIcon));
            somSelf->ViewTypeChanged(ev, focusFrame);
            break;
         case VIEW_SALARGEICON:
            focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsLargeIcon));
            somSelf->ViewTypeChanged(ev, focusFrame);
            break;
         case VIEW_SATHUMBNAIL:
            focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsThumbnail));
            somSelf->ViewTypeChanged(ev, focusFrame);
            break;
         case VIEW_SAFRAME:
            focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsFrame));
            somSelf->ViewTypeChanged(ev, focusFrame);
            break;
         case VIEW_OAWINDOW:
         case kODCommandViewAsWin:
            {
              somSelf->Open(ev, focusFrame);
              handled = kODTrue;
            }
            break;
         case kSimplePartHelpMenu:
            {
               ODHelp *help = _fSession->GetHelp(ev);
               help->DisplayHelp(ev, SP_HELP_FILE, SP_HELP_PANEL);
               handled = kODTrue;
            }
            break;
         case kSimplePartInfoMenu:
            {
               ODTypeToken modalFocus  = _fSession->Tokenize(ev, kODModalFocus);
               // rrk 10 jan 97 defect 27352
               // Save current modal focus owner
               ODFrame * saveModalOwner = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, modalFocus);
               PRINT("SimplePartHandleMenuEvent; kSimplePartInfoMenu entered. saveModalOwner is %x.\n", saveModalOwner);
               // Acquire modal focus
               if (_fSession->GetArbitrator(ev)->RequestFocus(ev, modalFocus, focusFrame)) {
                   somSelf->DisplayInfoDialog(ev,
                                              SP_MSG_CATALOG,
                                              SP_MSG_SET,
                                              SPMSG_INFOTITLE,
                                              SP_DEFMSG_INFOTITLE,
                                              SPMSG_INFO,
                                              SP_DEFMSG_INFO);
                    // Restore modal focus
                    _fSession->GetArbitrator(ev)->TransferFocus(ev, modalFocus, focusFrame, saveModalOwner);
                    if(saveModalOwner)
                       saveModalOwner->Release(ev);
               } /* endif */
               handled = kODTrue;
            }
            break;
         default:
            break;
      }
    }
    catch(...)
    {
    }

    return handled;

}

SOM_Scope void  SOMLINK SimplePartInstallMenus(SimplePart *somSelf,
                                                Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartInstallMenus");

    try
    {
      if(_fPopup)
      {
        _fPopup->RemoveMenuItem(ev, kODNULL, VIEW_OAICON);
        _fPopup->RemoveMenuItem(ev, kODNULL, VIEW_OATREE);
        _fPopup->RemoveMenuItem(ev, kODNULL, VIEW_OADETAILS);
      }

      //let's add help menu items ONLY if this is simple part
      // and not its subclass
      if (!strcmp (somSelf->somGetClassName(), kSimpleClassName))
      {

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

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

      _fMenuBar->Acquire(ev);

      ODPlatformMenuItem *mi = new ODPlatformMenuItem;

      // 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
      _fMenuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);


      // add SimplePart Help item to the HELP menu
      mi->id = kSimplePartHelpMenu;
#if (defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_))
      mi->afAttribute=0;           // use default attributes
#endif
      _fMenuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);
#if defined(__IBMCPP__) || defined(_IBMR2)
      menuText=catgets(spCatalog, SP_MSG_SET, SPMSG_HELPMENU, SP_DEFMSG_HELPMENU);
#else
      strcpy (menuText, SP_DEFMSG_HELPMENU);
#endif
      _fMenuBar->SetMenuItemText(ev, IDMS_HELP, mi->id, menuText);

      // add SimplePart Information item to the HELP menu
      mi->id = kSimplePartInfoMenu;
#if (defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_))
      mi->afAttribute=0;           // use default attributes
#endif
      _fMenuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);
#if defined(__IBMCPP__) || defined(_IBMR2)
      menuText=catgets(spCatalog, SP_MSG_SET, SPMSG_INFOMENU, SP_DEFMSG_INFOMENU);
#else
      strcpy (menuText, SP_DEFMSG_INFOMENU);
#endif
      _fMenuBar->SetMenuItemText(ev, IDMS_HELP, mi->id, menuText);

    // we can now release the MenuBar
    _fMenuBar->Release(ev);

    delete mi;                        // cleanup menuitem buffer

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

    } // end if this is a subclass

    }
    catch(...)
    {
    }
}

SOM_Scope ODMenuBar*  SOMLINK SimplePartGetMenuBar(SimplePart *somSelf,
                                                    Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartGetMenuBar");

    return _fMenuBar;
}

SOM_Scope ODPopup*  SOMLINK SimplePartGetPopupMenu(SimplePart *somSelf,
                                                    Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartGetPopupMenu");

    return _fPopup;
}

SOM_Scope void  SOMLINK SimplePartSetViewTypeRect(SimplePart *somSelf,
                                                  Environment *ev,
                                                  ViewTypeEnum viewType,
                                                  ODRect* rect)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartSetViewTypeRect");

    int viewSize;

    switch(viewType)
    {
       case SmallIconView:
          viewSize = kODSmallIconSize;
          break;
       case LargeIconView:
          viewSize = kODLargeIconSize;
          break;
       case ThumbnailView:
          viewSize = kODThumbnailSize;
          break;
       case FrameView:
       default:
          *rect = _lastFrameRect;
          return;
          break;
    }

    rect->right = IntToFixed((FixedToInt(rect->left)) + viewSize);
#ifdef _PLATFORM_OS2_
    rect->bottom = IntToFixed(0);
    rect->top    = IntToFixed(viewSize);
#else
    rect->bottom = IntToFixed(viewSize);
    rect->top = IntToFixed(0);
#endif
}

SOM_Scope void  SOMLINK SimplePartAdjustViewTypeShapes(SimplePart *somSelf,
                                                       Environment *ev,
                                                       ODFrame* frame)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartAdjustViewTypeShapes");

    try
    {

      // Do not change frame shape if this is a root frame
      if(frame->IsRoot(ev)) return;

      // Prevent infinite recursion of frame negotiation
      if(_fInFrameNegotiation) return;

      ViewTypeEnum newViewType;

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

      TempODShape currShape = frame->AcquireFrameShape(ev, kODNULL);
      currShape->GetBoundingBox(ev, &rect);

      // Determine the new shape we must present
      if(viewType == _fSession->Tokenize(ev,kODViewAsSmallIcon))
      {
         newViewType = SmallIconView;
      }
      else if(viewType ==  _fSession->Tokenize(ev,kODViewAsLargeIcon))
      {
         newViewType = LargeIconView;
      }
      else if(viewType == _fSession->Tokenize(ev,kODViewAsThumbnail))
      {
         newViewType = ThumbnailView;
      }
      else
      {
         frame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsFrame));
         if(_fPrevViewType == FrameView)
         {
            // This is an adjustment due to a resize or reconnect.
            // Just store the new frame shape.
            _lastFrameRect = rect;

            // Do not attempt any frame negotiation.
            return;
         }
         else
         {
            newViewType = FrameView;
         }
      }
      somSelf->SetViewTypeRect(ev, newViewType, &rect);
      newShape->SetRectangle(ev, &rect);


      // Get the facet from the frame
      ODFrameFacetIterator  *facetIter = frame->CreateFacetIterator(ev);
      ODFacet *facet = facetIter->First(ev);
      delete facetIter;

      _fInFrameNegotiation = kODTrue;

      // Change the frame shape
      TempODShape finalShape = frame->RequestFrameShape(ev, newShape, kODNULL);

      _fInFrameNegotiation = kODFalse;

      // Container has the last word on frame shape. If the returned frame
      // is not the one requested, reset the lastFrameRect.
      if(!finalShape->IsSameAs(ev, newShape) && (newViewType == FrameView))
      {
         finalShape->GetBoundingBox(ev, &_lastFrameRect);
      }

      _fPrevViewType = newViewType;
    }
    catch(ODException _exception)
    {
    }
}

SOM_Scope void  SOMLINK SimplePartDrawFrame(SimplePart *somSelf,
                                            Environment *ev,
                                            ODFacet* facet,
                                            ODShape* invalidShape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDrawFrame");

    ODRect frameODRect;
    TempODShape frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev,kODNULL);
    frameShape->GetBoundingBox(ev, &frameODRect);
    HDraw hDraw;

    CFocus f(facet, invalidShape, &hDraw);     // Set up drawing environment
#if defined(_PLATFORM_OS2_)||defined(_PLATFORM_WIN32_)

    Rect frameRect;
#endif
#ifdef _PLATFORM_OS2_
    HAB hab = WinInitialize(0);
    WinSetRect(hab,&frameRect, FixedToInt(frameODRect.left),
                               FixedToInt(frameODRect.bottom),
                               FixedToInt(frameODRect.right),
                               FixedToInt(frameODRect.top));
    Point orig = {0, 0};
    Point pt = {frameRect.xRight, frameRect.yTop};
    GpiSetColor(hDraw, CLR_RED);                  // Set the drawing color
    GpiMove(hDraw, &orig);                        // Set the origin from which to draw
    GpiBox(hDraw, DRO_FILL, &pt, 0, 0);           // Draw a color filled rectangle
    GpiSetColor(hDraw, CLR_BLACK);                // Set the drawing color

    // Draw diagonal lines
    Point pt1, pt2;

    int height = frameRect.yTop - frameRect.yBottom;
    int width  = frameRect.xRight;

    pt1.x = 0;
    pt2.x = width;
    for (int y = 0; y <= height; y += DELTA)
    {
      pt1.y = y;
      pt2.y = pt1.y + width;
      GpiMove(hDraw, &pt1);
      GpiLine(hDraw, &pt2);
    }

    pt1.y = 0;
    pt2.y =  height;
    for (int x = DELTA; x <= width; x += DELTA)
    {
      pt1.x = x;
      pt2.x = pt1.x + height;
      GpiMove(hDraw, &pt1);
      GpiLine(hDraw, &pt2);
    }

#elif defined(_PLATFORM_WIN32_)
    SetRect(&frameRect, FixedToInt(frameODRect.left),
                        FixedToInt(frameODRect.top),
                        FixedToInt(frameODRect.right),
                        FixedToInt(frameODRect.bottom));

    HBRUSH hbr = CreateSolidBrush (RGB(255,0,0)); // Create a solid brush
    FillRect (hDraw, &frameRect, hbr);             // Fill the rectangle with the brush
    DeleteObject (hbr);                           // Delete the brush

    // Draw diagonal lines
    Point pt1, pt2;

    int height = frameRect.bottom - frameRect.top;
    int width  = frameRect.right;

    pt1.x = 0;
    pt2.x = width;
    for (int y = 0; y <= height; y += DELTA)
    {
      pt1.y = y;
      pt2.y = pt1.y + width;
      MoveToEx(hDraw, pt1.x, pt1.y, NULL);
      LineTo(hDraw, pt2.x, pt2.y);
    }

    pt1.y = 0;
    pt2.y =  height;
    for (int x = DELTA; x <= width; x += DELTA)
    {
      pt1.x = x;
      pt2.x = pt1.x + height;
      MoveToEx(hDraw, pt1.x, pt1.y, NULL);
      LineTo(hDraw, pt2.x, pt2.y);
    }

#elif defined(_PLATFORM_UNIX_)

    // Get the AIX Window canvas
    ODAIXWindowCanvas *aixwincanvas = (ODAIXWindowCanvas *) (facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODAIX));

    // Get the canvas widget
    Widget widget = aixwincanvas->GetWidget(ev);

    // Get the canvas window
    Window window = aixwincanvas->GetWindow(ev);

    // Get the canvas display
    Display *display = aixwincanvas->GetDisplay(ev);

    // Get the widget's dimensions
    Position x, y;
    Dimension width, height;

    // Set the width and height according to the widget size.
    XtVaGetValues(widget,
                  XmNwidth, &width,
                  XmNheight, &height,
                  NULL);

    x = 0;
    y = 0;

    // Ensure the fill style is solid
    XSetFillStyle(display, hDraw, FillSolid);

    // Get the screen
    Screen *screen = _fSession->GetWindowState(ev)->GetScreen(ev);

    // Get the default colormap for the screen
    Colormap map = XDefaultColormapOfScreen(screen);

    XColor def, def2;

    // For loop to create filled rectangles
    for (int index = 0;
         index < 4;
         index++)
    {
        Status stat;

        // Switch on the loop pass
        switch (index)
        {
          case 0:
            width--;
            height--;

            // Background is purple
            stat = XAllocNamedColor(display, map, "purple", &def, &def2);
            break;

          case 1:
            // Set the frame rectangle for the shadow
            x += 20;
            width -= 25;
            height -= 25;
            y += 20;

            // Just use the standard black pixel
            def.pixel = BlackPixelOfScreen(screen);

            break;

          case 2:
            // Set the frame rectangle for the inner rectangle's border
            x -= 10;
            y -= 10;
            break;

          case 3:
            // Set the frame rectangle for the inner rectangle
            x++;
            width -= 2;
            height -= 2;
            y++;

            // Color is dark red
            stat = XAllocNamedColor(display, map, "red" , &def, &def2);

            break;
        }

        // Set foreground color
        XSetForeground(display, hDraw, def.pixel);

        // Fill the rectangle
        XFillRectangle(display,
                       window,
                       hDraw,
                       x, y,
                       width, height);


    }

    // Change color to standard black pixel
    def.pixel = BlackPixelOfScreen(screen);
    XSetForeground(display, hDraw, def.pixel);

    // Set the clip rectangle to prevent diagonal
    // lines to draw over shadow and background rectangle.
    XRectangle innerRect = {x, y, width, height};
    XSetClipRectangles(display, hDraw, 0, 0, &innerRect, 1, Unsorted);

    // Draw diagonal lines
    int ymax = y + height;
    int xmax = x + width;

    for (int y1=y; y1 <= ymax; y1 += DELTA)
    {
      XDrawLine(display, window, hDraw, x, y1, xmax, (y1+width));
    }

    for (int x1 = x+DELTA; x1 <= xmax; x1 += DELTA)
    {
      XDrawLine(display, window, hDraw, x1, y, (x1+height), ymax);
    }

    // Undo clipping
    XSetClipMask(display, hDraw, None);

#endif
}

SOM_Scope void  SOMLINK SimplePartDrawThumbnail(SimplePart *somSelf,
                                            Environment *ev,
                                            ODFacet* facet,
                                            ODShape* invalidShape)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDrawThumbnail");

    // Not yet implemented
    somSelf->DrawFrame(ev, facet, invalidShape);
}

SOM_Scope void  SOMLINK SimplePartLoadIconsFromModule(SimplePart *somSelf,
                                                          Environment *ev,
                                                          string moduleName,
                                                          long iconID)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimpleLoadIconsFromModule");

#ifdef _PLATFORM_OS2_
    CHAR errBuffer[CCHMAXPATH];
    if(moduleName)
    {
      DosLoadModule(errBuffer,
                    sizeof(errBuffer),
                    moduleName,
                    &_hResModule);
    }

    HPOINTER hptr = WinLoadPointer(HWND_DESKTOP,
                                   _hResModule,
                                   iconID);

    POINTERINFO pi;
    WinQueryPointerInfo( hptr, &pi );
    _hLargeIcon = pi.hbmColor;
    _hSmallIcon = pi.hbmMiniColor;

#elif defined(_PLATFORM_WIN32_)
    if(moduleName)
    {
      _hResModule = LoadLibrary(moduleName);
    }

    _hSmallIcon = LoadImage(_hResModule,
                       MAKEINTRESOURCE(iconID),
                       IMAGE_ICON,
                       kODSmallIconSize,
                       kODSmallIconSize,
                       LR_DEFAULTCOLOR);
    _hLargeIcon = LoadImage(_hResModule,
                       MAKEINTRESOURCE(iconID),
                       IMAGE_ICON,
                       kODLargeIconSize,
                       kODLargeIconSize,
                       LR_DEFAULTCOLOR);
#endif

}

SOM_Scope void  SOMLINK SimplePartCreateIcons(SimplePart *somSelf,
                                              Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCreateIcons");

#if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
    somSelf->LoadIconsFromModule(ev,
                                 "iodsimpl",
                                 kODIcon);
#endif
}

SOM_Scope void  SOMLINK SimplePartFreeResModule(SimplePart *somSelf,
                                                Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartFreeResModule");

    if(_hResModule)
    {
#ifdef _PLATFORM_OS2_
      DosFreeModule(_hResModule);
#elif defined(_PLATFORM_WIN32_)
      FreeLibrary(_hResModule);
#endif
    }
}

SOM_Scope void  SOMLINK SimplePartDrawIcon(SimplePart *somSelf,
                                           Environment *ev,
                                           ODFacet* facet,
                                           ODShape* invalidShape,
                                           ViewTypeEnum viewType)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDrawIcon");


    HIconView *hIcon;
    short iconSize;

    if(viewType == SmallIconView)
    {
      hIcon = &_hSmallIcon;
      iconSize = kODSmallIconSize;
    }
    else
    {
      hIcon = &_hLargeIcon;
      iconSize = kODLargeIconSize;
    }

    HDraw hDraw;
    CFocus f(facet, invalidShape, &hDraw);     // Set up drawing environment

#if defined(_PLATFORM_OS2_)||defined(_PLATFORM_WIN32_)

    if(*hIcon == kODNULL) somSelf->CreateIcons(ev);

    ODRect iconODRect;
    Rect iconRect;
    TempODShape frameShape = facet->GetFrame(ev)->AcquireFrameShape(ev,kODNULL);
    frameShape->GetBoundingBox(ev, &iconODRect);

#endif
#ifdef _PLATFORM_OS2_
    HAB hab = WinInitialize(0);
    WinSetRect(hab,&iconRect, FixedToInt(iconODRect.left),
                              FixedToInt(iconODRect.bottom),
                              FixedToInt(iconODRect.right),
                              FixedToInt(iconODRect.top));

    ODFixed xscale, yscale;
    Get72DPIToScreenScale( _fSession, &xscale, &yscale);

    Point aPoints[4] = {{iconRect.xLeft,iconRect.yBottom},
                        {iconRect.xRight,iconRect.yTop},
                        {0,0},
                        {FixedToInt(ODFixedMultiply(xscale, IntToFixed(iconSize))),
                         FixedToInt(ODFixedMultiply(yscale, IntToFixed(iconSize)))}};

    LONG lHits = GpiWCBitBlt(hDraw,
                             *hIcon,
                             4,
                             aPoints,
                             ROP_SRCCOPY,
                             BBO_IGNORE);

#elif defined(_PLATFORM_WIN32_)
    SetRect(&iconRect, FixedToInt(iconODRect.left),
                       FixedToInt(iconODRect.top),
                       FixedToInt(iconODRect.right),
                       FixedToInt(iconODRect.bottom));
    BOOL success = DrawIconEx(hDraw,
                              iconRect.left,
                              iconRect.top,
                              *hIcon,
                              iconSize,
                              iconSize,
                              0,
                              NULL,
                              DI_NORMAL);

#elif defined(_PLATFORM_UNIX_)

    // Get the AIX Window canvas
    ODAIXWindowCanvas *aixwincanvas =
      (ODAIXWindowCanvas *)(facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODAIX));

    // Get the canvas window
    Window window = aixwincanvas->GetWindow(ev);

    // Get the canvas display
    Display *display = aixwincanvas->GetDisplay(ev);

    // Get the screen
    Screen *screen = _fSession->GetWindowState(ev)->GetScreen(ev);

    // Get the default colormap for the screen
    Colormap map = XDefaultColormapOfScreen(screen);

    // Create red color structure
    XColor def, def2;
    Status stat = XAllocNamedColor(display, map, "red" , &def, &def2);

    // Set foreground color
    XSetForeground(display, hDraw, def.pixel);

    // Create the icon if it doesn't exist
    if(*hIcon == kODNULL)
    {
      // On AIX we may not create both icons at the same time.
      // Create the bitmaps separately because they depend
      // on the window attributes which are different
      // for each viewtype.
      if(viewType ==  SmallIconView)
      {
        _hSmallIcon = XCreateBitmapFromData(display,
                                            window,
                                            simpl16_bits,
                                            iconSize,
                                            iconSize);
      }
      else
      {
        _hLargeIcon = XCreateBitmapFromData(display,
                                            window,
                                            simpl32_bits,
                                            iconSize,
                                            iconSize);
      }
    }

    // Display the bitmap
    XCopyPlane(display, *hIcon, window, hDraw, 0, 0, iconSize, iconSize, 1, 1, 0x01);

#endif
}

SOM_Scope PartInfoRec* SOMLINK SimplePartCreateFramePartInfo(SimplePart *somSelf,
                                                          Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartCreateFramePartInfo");

    PartInfoRec* pInfo = (PartInfoRec *) SOMMalloc(sizeof(PartInfoRec));
    pInfo->fIsActive        = kODFalse;
    pInfo->fNeedsActivating = kODFalse;
    pInfo->fIsPopupMenu     = kODFalse;
    pInfo->fIsSelected      = kODFalse;
    pInfo->pOther           = kODNULL;
    return pInfo;
}

SOM_Scope void SOMLINK SimplePartDeleteFramePartInfo(SimplePart *somSelf,
                                                     Environment *ev,
                                                     PartInfoRec *pInfo)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDeleteFramePartInfo");

    SOMFree(pInfo);
}

SOM_Scope IODLinkedList* SOMLINK SimplePartGetDisplayFrames(SimplePart *somSelf,
                                                Environment *ev)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartGetDisplayFrames");

    return _fDisplayFrames;
}

SOM_Scope ODBoolean SOMLINK SimplePartDisplayPopupMenu(SimplePart *somSelf,
                                                      Environment *ev,
                                                      ODEventData* event,
                                                      ODFrame* frame,
                                                      ODFacet* facet,
                                                      ODEventInfo* eventInfo)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayPopupMenu");

    try
    {
       PartInfoRec* pInfo = (PartInfoRec*) frame->GetPartInfo(ev);
       if (!(pInfo->fIsActive))
             somSelf->ActivateFrame(ev, frame);

       if(_fPopup)
       {
          if(frame->IsRoot(ev))
          {
            _fPopup->EnableMenuItem(ev, ID_BASEPOPUP, VIEW_VIEWINWINDOW, kODFalse);
            _fPopup->EnableMenuItem(ev, ID_BASEPOPUP, VIEW_SHOWAS, kODFalse);
          }
          else
          {
            _fPopup->EnableMenuItem(ev, ID_BASEPOPUP, VIEW_VIEWINWINDOW, kODTrue);
            _fPopup->EnableMenuItem(ev, ID_BASEPOPUP, VIEW_SHOWAS, kODTrue);
          }
          _fPopup->Display(ev);
       }

       return kODTrue;
    }
    catch(...)
    {
       return kODFalse;
    }
}

#ifdef _PLATFORM_UNIX_
//------------------------------------------------------------------------------
// infoCallBack - callback for information dialog box with OK button
//------------------------------------------------------------------------------
SOMEXTERN void infoCallBack(Widget widget, XtPointer client_data, XtPointer call_data)
{
    // remove dialog
    XtUnmanageChild(widget);
    XtDestroyWidget(widget);
}

//------------------------------------------------------------------------------
// SetDispatchModal - call dispatcher to set up modality for the application
//------------------------------------------------------------------------------
SOMEXTERN void SOMLINK SetDispatchModal(ODBoolean setModality, ODSession *session)
{
    Environment  *ev = somGetGlobalEnvironment();

    try
    {
       ODDispatcher *dispatcher = kODNULL;

       if(session)
          dispatcher = session->GetDispatcher(ev);

       if (dispatcher)
          dispatcher->SetXtDispatchMode(ev, setModality);
    }
    catch (...)
    {
    }
}

//------------------------------------------------------------------------------
// DialogPopupCallBack - callback to setup modality when dialog pops up
//------------------------------------------------------------------------------
SOMEXTERN void SOMLINK DialogPopupCallBack(Widget widget,
                                     XtPointer client_data,
                                     XtPointer call_data)
{
    SetDispatchModal(kODTrue, (ODSession*)client_data);
}

//------------------------------------------------------------------------------
// DialogPopdownCallBack - callback to reset modality when dialog pops down
//------------------------------------------------------------------------------
SOMEXTERN void SOMLINK DialogPopdownCallBack(Widget widget,
                                     XtPointer client_data,
                                     XtPointer call_data)
{
    SetDispatchModal(kODFalse, (ODSession*)client_data);
}

#endif //_PLATFORM_UNIX_

SOM_Scope void SOMLINK SimplePartDisplayInfoDialog(SimplePart *somSelf,
                                                   Environment *ev,
                                                   string catalog,
                                                   long  msgSet,
                                                   long infoTitle,
                                                   string defaultInfoTitle,
                                                   long infoMsg,
                                                   string defaultInfoMsg)
{
    SimplePartData *somThis = SimplePartGetData(somSelf);
    SimplePartMethodDebug("SimplePart","SimplePartDisplayInfoDialog");

    // Create the strings to be displayed in the dialog box
#if defined(__IBMCPP__) || defined(_IBMR2)
    nl_catd msgCatalog;          // NLS message catalog handle
    char *message, *title;    // pointer for NLS message

    setlocale(LC_MESSAGES, NULL);
    msgCatalog = catopen(catalog, 0);
    if(msgCatalog == CATD_ERR)
    {
      PRINT("Could not open message catalog %s\n", catalog);
    }
    title = catgets(msgCatalog, SP_MSG_SET, SPMSG_INFOTITLE, defaultInfoTitle);
    message = catgets(msgCatalog, SP_MSG_SET, SPMSG_INFO, defaultInfoMsg);

#else
    char message[256], title[256];
    strcpy (title, defaultInfoTitle);
    strcpy (message, defaultInfoMsg);
#endif

     // Display the strings in the dialog box
#ifdef _PLATFORM_WIN32_
     MessageBox(NULL,
                message,
                title,
                MB_OK | MB_ICONINFORMATION | MB_TASKMODAL);
#elif defined(_PLATFORM_OS2_)
     ODWindowState* winState=_fSession->GetWindowState(ev);
     ODWindow *window = winState->AcquireActiveWindow(ev);
     ODPlatformWindow hwnd = window->GetPlatformWindow(ev);
     window->Release(ev);
     WinMessageBox(HWND_DESKTOP, hwnd,
                   message,
                   title,
                   0, MB_OK | MB_INFORMATION | MB_APPLMODAL);
#elif defined(_PLATFORM_UNIX_)
    Widget shellWidget;
    Display *display;
    try
    {
      ODWindowState* winState=_fSession->GetWindowState(ev);
      TempODWindow window = winState->AcquireActiveWindow(ev);
      ODPlatformWindow platwin = window->GetPlatformWindow(ev);

      display = winState->GetDisplay(ev);
      shellWidget = XtWindowToWidget(display,
                                     platwin);

    }
    catch(...)
    {
       return;
    }

    // Override default behavior for system close and set to modal
    Arg args[2];
    XtSetArg(args[0], XmNdeleteResponse, XmDO_NOTHING);
    XtSetArg(args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);

    // create dialog, it will be destroyed in the callback routine.
    Widget dialog = XmCreateInformationDialog(shellWidget,
                                              "info", args, 2);

    // set values for dialog
    XmString xTitle = XmStringCreateLocalized(title);
    XmString xMessage = XmStringCreateLocalized(message);
    XtVaSetValues(dialog,
                  XmNdialogTitle, xTitle,
                  XmNmessageString, xMessage,
                  NULL);
    XmStringFree(xMessage);
    XmStringFree(xTitle);

    // add callbacks for button
    XtAddCallback(dialog, XmNokCallback, (XtCallbackProc)infoCallBack,
                  (XtPointer)NULL);

    // add callbacks for popup and popdown
    XtAddCallback(XtParent(dialog), XmNpopupCallback,
                  (XtCallbackProc)DialogPopupCallBack,
                  (XtPointer)_fSession);
    XtAddCallback(XtParent(dialog), XmNpopdownCallback,
                  (XtCallbackProc)DialogPopdownCallBack,
                  (XtPointer)_fSession);

    // add callback for WM_DELETE_WINDOW protocol
    Atom WM_DELETE_WINDOW = XmInternAtom(display,
                                         "WM_DELETE_WINDOW",
                                         FALSE);
    XmAddWMProtocolCallback(XtParent(dialog), WM_DELETE_WINDOW,
                            (XtCallbackProc)infoCallBack,
                            (XtPointer)NULL);

    // remove cancel and help buttons from dialog.
    Widget cancel_button = XmMessageBoxGetChild(dialog,
                                                XmDIALOG_CANCEL_BUTTON);
    XtUnmanageChild(cancel_button);
    Widget help_button = XmMessageBoxGetChild(dialog,
                                              XmDIALOG_HELP_BUTTON);
    XtUnmanageChild(help_button);

    // display dialog
    XtManageChild(dialog);

#endif  // _PLATFORM_UNIX_

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

