// @(#) 1.1 com/src/samples/scrsimp1/iodscrs1.cpp, odsimplescript, od96nt, odnt9712d 2/20/97 17:46:31 [3/21/97 17:46:47]
//====START_GENERATED_PROLOG======================================
//
//
//   COMPONENT_NAME: odscriptableparts
//
//   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========================================
//


// This file implements the part code for a scriptable part which
// inherits from 'SimplePart'.

#include <iodspcl1.h>

#ifndef SOM_Module_iodscrsp1_Source
#define SOM_Module_iodscrsp1_Source
#endif
#define ScriptableSimplePart1_Class_Source

#define  VARIABLE_MACROS
#include "iodscrs1.xih"
#include "iodscrs1.h"           // for DELTA and AIX icon defintion
#include "somtc.h"              // for TypeCodeNew declarations
#include "iodspex1.xh"          // for ScriptableSimplePartScrExt
#include "scrcomp.xh"           // for ODScriptComponent
#include "oddsemgr.xh"          // for ODDSEventManager
#include "iodlink.xh"           // for IODLink and IODLinkedList
#include "StorageU.xh"          // for ODStorageUnit
#include "Frame.xh"             // for ODFrame
#include "Facet.xh"             // for ODFacet
#include "Shape.xh"             // for ODShape
#include "FocusLib.h"           // for CFocus
#include "MenuBar.xh"           // for ODMenuBar
#include "StdExts.xh"           // for kODScriptExtension
#include "StdTypes.xh"          // for ODCommandID
#include "StdProps.xh"          // for kODAttachedScriptType
#include "TempObj.h"            // for TempODShape

// ----------------------------------------------------------
// constants to define meta information for the class
// ----------------------------------------------------------

const ODType   kHandlerName     = _CLp_q;
const ODType   kPresNormal      = _CLp_Pq(:Presentation:Normal);
const ODType   kPresPalette     = _CLp_Pq(:Presentation:Palette);
const ODType   kKind            = _CLp_q;
const ODType   kKindDisplayName = "Scriptable Simple Part1 Kind";
const ODType   kCategory        = "OpenDoc:Category:Sample";
const ODType   kDisplayCatagory = "Sample" ;
const ODType   kWindowsIcon     = "iodscspl.ico";
const ODType   kClassGUID       = "{8993fcd0-8aa2-11d0-8052-08005a88887e}";

// ----------------------------------------------------------
//
//  Command constants used in Scriptable Simple Part
//
//   -> CMD_Offset_Subclass is set in iodsimpl.h to MENUID_ACTIVEPART_USER
//      (from CMDDEFS.XH) + some offset, so that menuids of subclassing parts
//      don't conflict with the menuids of SimplePart and of the docshell.
//      This is an area reserved for USER defined menuitems.
// ----------------------------------------------------------
//  command values
#define kODCommandSimplePartScriptStart  (CMD_Offset_Subclass+1)
#define kODCommandSimplePartScriptEnd    (CMD_Offset_Subclass+2)

//=======================================================================
// Method to invoke any event sinks attached to the MouseDown event
//=======================================================================


SOM_Scope long  SOMLINK _CLp_P(TriggerMouseDown)(_CLp_ *somSelf,
                                                              Environment *ev,
                                                             long x,
                                                             long y)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(TriggerMouseDown) );

    _IDL_SEQUENCE_any  inParms;
    ODDSRESULT         result;
    long               sinkCount ;
    long               sinkNumber ;
    any                data[2];
    ODDSSinkEnum       *sinkEnum;

    data[0]._type = TypeCodeNew(tk_long);
    data[0]._value = (void *) &x;
    data[1]._type = TypeCodeNew(tk_long);
    data[1]._value = (void *) &y;

    inParms._length  = 2;
    inParms._maximum = 2;
    inParms._buffer = data;


    _fEventManager->PrepareEventFiring(ev, &sinkCount, &sinkEnum);
    for (sinkNumber = 0 ; sinkNumber < sinkCount ; sinkNumber++ )
    {
      _fEventManager->FireEvent(ev, sinkEnum, "MouseDown",&inParms,&result);
      // ignore any return value, we don't use it in this case
    }
    _fEventManager->StopEventFiring(ev, sinkEnum);

    return(0);

}


//=======================================================================
// Method to set the color of the part and force update
//=======================================================================

SOM_Scope void  SOMLINK _CLp_P(SetColor)(_CLp_ *somSelf,
                                                      Environment *ev,
                                                     long newColor)
{
    ODFrame *frame ;
    IODLink *frameNode ;

    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(SetColor) );

    _fColor = newColor;

    for (frameNode = somSelf->GetDisplayFrames(ev)->First(ev) ;
         (frameNode != kODNULL) && ((frame=(ODFrame *) frameNode->Content(ev)) != kODNULL)  ;
         frameNode =  frameNode->Next(ev)  )
    {
      frame->Invalidate(ev, kODNULL, kODNULL ) ;
    }
}

//=======================================================================
// Method to return the color for the part
//=======================================================================

SOM_Scope long  SOMLINK _CLp_P(GetColor)(_CLp_ *somSelf,
                                                      Environment *ev)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(GetColor) );

    return (_fColor) ;
}

//=======================================================================
// Override somDefaultInit to add initialization for color and connection support
//=======================================================================
SOM_Scope void SOMLINK _CLp_P(somDefaultInit)(_CLp_  *somSelf,
                                             somInitCtrl* ctrl)
{
    _CLp_P(Data) *somThis; /* set in BeginInitializer */
    somInitCtrl globalCtrl;
    somBooleanVector myMask;
    _CLp_P(MethodDebug)( _CLp_q ,"somDefaultInit");
    _CLp_P(_BeginInitializer_somDefaultInit);

    _CLp_P(_Init_SimplePart_somDefaultInit)(somSelf, ctrl);
    _CLp_P(_Init_ODDSConnection_somDefaultInit)(somSelf, ctrl);

    /*
     * local initialization code
     */

    _fColor = (long) RGB(0, 128, 128) ;

    ODGUID odguid = { 0xc52dd400,0x8aa2, 0x11d0,
                      { 0x08, 0x00, 0x5a, 0x88, 0x88, 0x88, 0x88, 0x7e}};
    _fODGuid = odguid ;
    Environment *ev = SOM_CreateLocalEnvironment();
    _fEventManager =  new ODDSEventMgr(ev, _fODGuid);
    somSelf->AddEventMgr(ev, _fEventManager);
    SOM_DestroyLocalEnvironment(ev);

}

//=======================================================================
// Override somDestruct to properly dispose of connection data
//=======================================================================

SOM_Scope void SOMLINK _CLp_P(somDestruct)(_CLp_ *somSelf,
                                          octet doFree, somDestructCtrl* ctrl)
{
    _CLp_P(Data) *somThis; /* set in BeginDestructor */
    somDestructCtrl globalCtrl;
    somBooleanVector myMask;
    _CLp_P(MethodDebug)( _CLp_q , _CLp_Pq(somDestruct));
    _CLp_P(_BeginDestructor);

    /*
     * local deinitialization code
     */
    Environment *ev = SOM_CreateLocalEnvironment();
    if (_fEventManager)
    {
      somSelf->DeleteEventMgr(ev,&_fODGuid) ;
      _fEventManager = NULL ;
    }
    if (_fScriptExtension )
    {
      _fScriptExtension->EndScripting(ev) ;
      _fScriptExtension->Release(ev) ;
      _fScriptExtension = NULL ;
    }
    SOM_DestroyLocalEnvironment(ev);

    _CLp_P(_EndDestructor) ;
}




//=======================================================================
// Override HasExtension to recognize kODScriptExtension
//=======================================================================
SOM_Scope ODBoolean  SOMLINK _CLp_P(HasExtension)(_CLp_ *somSelf,
                                                               Environment *ev,
                                                              ODType extensionName)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(HasExtension) );

   ODBoolean RetVal ;

   try
   {
     if (strcmp(extensionName, kODScriptExtension)== 0)
     {
       RetVal = kODTrue ;
     }
     else
     {
       RetVal = _CLp_P(_parent_SimplePart_HasExtension)(somSelf,
                                                                  ev,
                                                                  extensionName);
     }
   }
   catch(ODException _exception)
   {
   }

   return RetVal ;

}

//=======================================================================
// Override AcquireExtension to recognize kODScriptExtension
//=======================================================================
SOM_Scope ODExtension*  SOMLINK _CLp_P(AcquireExtension)(_CLp_ *somSelf,
                                                                      Environment *ev,
                                                                     ODType extensionName)
{
    ODExtension *RetVal ;

    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(AcquireExtension) );

    try
    {
      if (strcmp(extensionName, kODScriptExtension)== 0)
      {
         if (_fScriptExtension == kODNULL)
         {
            _fScriptExtension = new _CLx_ ;
            if (_fScriptExtension)
            {
              _fScriptExtension->InitScriptExtension(ev, somSelf) ;
            }
         }
         if (_fScriptExtension != NULL)
         { _fScriptExtension->Acquire(ev) ; }

         RetVal = (ODExtension *) _fScriptExtension ;
      }
      else
      {
        RetVal = _CLp_P(_parent_SimplePart_AcquireExtension)(somSelf,
                                                                    ev,
                                                                    extensionName);
      }
    }
    catch(ODException _exception)
    {
    }

    return (RetVal) ;

}

//=======================================================================
// Override ReleaseExtension to properly dispose of the extension object
//=======================================================================
SOM_Scope void  SOMLINK _CLp_P(ReleaseExtension)(_CLp_ *somSelf,
                                                              Environment *ev,
                                                             ODExtension* extension)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(ReleaseExtension) );

    try
    {
      if (extension == (ODExtension *) _fScriptExtension)
      {
        delete _fScriptExtension ;
        _fScriptExtension = NULL ;
      }
      else
      {
        _CLp_P(_parent_SimplePart_ReleaseExtension)(somSelf,
                                                              ev,
                                                              extension);
      }
    }
    catch(ODException _exception)
    {
    }
}

//=======================================================================
// Override AdjustMenus to set the script edit menu items properly
//=======================================================================
SOM_Scope void  SOMLINK _CLp_P(AdjustMenus)(_CLp_ *somSelf,
                                                         Environment *ev,
                                                        ODFrame* frame)
{
    ODMenuBar *tMenuBar ;

    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(AdjustMenus) );

    try
    {
       _CLp_P(_parent_SimplePart_AdjustMenus)(somSelf,
                                                         ev, frame);

       // enable scripting menu items
       tMenuBar = somSelf->GetMenuBar(ev) ;

       tMenuBar->EnableMenuItem(ev, IDMS_EDIT, kODCommandSimplePartScriptStart, kODTrue);

       tMenuBar->EnableMenuItem(ev, IDMS_EDIT, kODCommandSimplePartScriptEnd,
                                 (((_fScriptExtension != NULL) &&
                                   (_fScriptExtension->getScrComp(ev) != NULL))
                                  ? kODTrue: kODFalse));
    }
    catch(ODException _exception)
    {
    }
}

//=======================================================================
// Override HandleMenuEvent to process script menu items
//=======================================================================
SOM_Scope ODBoolean  SOMLINK _CLp_P(HandleMenuEvent)(_CLp_ *somSelf,
                                                                  Environment *ev,
                                                                 ODFrame* focusFrame,
                                                                 ODEventData* event)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(HandleMenuEvent) );

    ODBoolean handled = kODFalse;

#ifndef _PLATFORM_UNIX_
    try
    {

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

      switch (command)
      {
         case kODCommandSimplePartScriptStart :
                _CLx_ * theScrExt ;
                if ( theScrExt = (_CLx_ *) somSelf->AcquireExtension(ev,kODScriptExtension) )
                {
                  theScrExt->InitScriptEditor(ev) ;
                  theScrExt->Release(ev) ;
                }
                handled = kODTrue ;
                break ;
         case kODCommandSimplePartScriptEnd :
                if (_fScriptExtension)
                {
                  _fScriptExtension->EndScripting(ev) ;
                }
                handled = kODTrue ;
                break ;
         default:
                handled = _CLp_P(_parent_SimplePart_HandleMenuEvent)(somSelf,
                                                                   ev,
                                                                   focusFrame,
                                                                   event);
                break;
      }
    }
    catch(ODException _exception)
    {
    }
#endif // !UNIX

    return handled;
}

//=======================================================================
// Override InstallMenus to add script menu items to the edit menu
//=======================================================================
SOM_Scope void  SOMLINK _CLp_P(InstallMenus)(_CLp_ *somSelf,
                                                          Environment *ev)
{
    ODMenuBar *tMenuBar ;

    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(InstallMenus) );

    try
    {
      _CLp_P(_parent_SimplePart_InstallMenus)(somSelf,
                                                          ev);
      // create new menu items for scripting support
      tMenuBar = somSelf->GetMenuBar(ev) ;

      ODPlatformMenuItem *mi = new ODPlatformMenuItem;

      mi->afAttribute = 0;              // set to default attributes
      mi->afStyle     = 0;
      mi->id          = 0;
      mi->hwndSubMenu = 0;
      mi->hItem       = 0;

      //   Add - Enable Scripting - item to Edit menu.
      mi->id = kODCommandSimplePartScriptStart ;
      tMenuBar->AddMenuItemLast(ev, IDMS_EDIT, kODNULL, mi);
      tMenuBar->SetMenuItemText(ev, IDMS_EDIT,
                                 kODCommandSimplePartScriptStart,
                                 "Edit Scripts") ;

      //   Add - Enable Scripting - item to Edit menu.
      mi->id = kODCommandSimplePartScriptEnd ;
      tMenuBar->AddMenuItemLast(ev, IDMS_EDIT, kODNULL, mi);
      tMenuBar->SetMenuItemText(ev, IDMS_EDIT,
                                 kODCommandSimplePartScriptEnd,
                                 "Remove Scripts") ;
    }
    catch(ODException _exception)
    {
    }
}


//=======================================================================
// Override HandleEvent to inovke the MouseDown Event logic
//=======================================================================
SOM_Scope ODBoolean  SOMLINK _CLp_P(HandleEvent)(_CLp_ *somSelf,
                                                    Environment *ev,
                                                    ODEventData* event,
                                                    ODFrame* frame,
                                                    ODFacet* facet,
                                                    ODEventInfo* eventInfo)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(HandleEvent) );

    ODBoolean handled = kODFalse;

   try
   {
#ifdef _PLATFORM_OS2_
    switch (event->msg)
#elif defined(_PLATFORM_WIN32_)
    switch (event->message)
#elif defined(_PLATFORM_UNIX_)
    XButtonEvent* button_struct  = (XButtonEvent*) event;
    switch (event->type)
#endif
    {
      case kODEvtMouseDown:
          {

             somSelf->TriggerMouseDown(ev, LOWORD(event->lParam),
                                           HIWORD(event->lParam));
          }
          // break; Note: we let it fall thru so the parent can handle
          //              the semantics it has associated with the mouse.

       default:
          handled = _CLp_P(_parent_SimplePart_HandleEvent)(somSelf,
                                                   ev,
                                                   event,
                                                   frame,
                                                   facet,
                                                   eventInfo) ;
    }
   }
   catch(ODException _exception)
   {
   }

    return handled;
}

//=======================================================================
// Override InitPartFromStorage to let extension access its data from the SU
//=======================================================================

SOM_Scope void  SOMLINK _CLp_P(InitPartFromStorage)(_CLp_ *somSelf,
                                                                 Environment *ev,
                                                                ODStorageUnit* storageUnit,
                                                                ODPart* partWrapper)
{
    ODBoolean RetV ;
    OSErr     ErrCode ;

    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(InitPartFromStorage) );

   try
   {
      _CLp_P(_parent_SimplePart_InitPartFromStorage)(somSelf,
                                                                 ev,
                                                                 storageUnit,
                                                                 partWrapper);

     if (storageUnit->Exists(ev, kODPropAttachedScriptType, kODNULL, (ODValueIndex)0))
     {
       _CLx_ * theScrExt ;
       if ( theScrExt = (_CLx_ *) somSelf->AcquireExtension(ev,kODScriptExtension) )
       {
         theScrExt->InitScriptFromStorage(ev, somSelf, storageUnit) ;
         theScrExt->Release(ev) ;
       }
     }

   }
   catch(ODException _exception)
   {
   }
}

//=======================================================================
// Override Externalize to allow script extension to save its data
//=======================================================================
SOM_Scope void  SOMLINK _CLp_P(Externalize)(_CLp_ *somSelf,
                                                         Environment *ev)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(Externalize) );

   try
   {

     _CLp_P(_parent_SimplePart_Externalize)(somSelf,
                                                        ev);

     if (_fScriptExtension != NULL)
     {
       ODStorageUnit* su = somSelf->GetStorageUnit(ev);
       _fScriptExtension->ScriptExternalize(ev, su) ;
     }

   }
   catch(ODException _exception)
   {
   }
}

//=======================================================================
// Override CloneInto to allow script extension to save its data
//=======================================================================
SOM_Scope void  SOMLINK _CLp_P(CloneInto)(_CLp_ *somSelf, Environment *ev,
                                            ODDraftKey key,
                                            ODStorageUnit* storageUnit,
                                            ODFrame* scopeFrame)
{
  _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
  _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(CloneInto) );


  try
  {
    _CLp_P(_parent_SimplePart_CloneInto)(somSelf, ev, key, storageUnit, scopeFrame);

    if (_fScriptExtension != NULL)
    {
      _fScriptExtension->ScriptExternalize(ev, storageUnit) ;
    }

   }
   catch(ODException _exception)
   {
   }
}


//=======================================================================
// modify Meta class with part specific name strings. PartHandlerName
//=======================================================================
SOM_Scope ISOString  SOMLINK _CLm_P(clsGetODPartHandlerName)(_CLm_ *somSelf,
                                                             Environment *ev)
{
    /* _CLm_P(Data) *somThis = _CLm_P(GetData)(somSelf); */
    _CLm_P(MethodDebug)(_CLm_q,_CLm_Pq(clsGetODPartHandlerName));

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

    return (ISOString) handlerName;
}

//=======================================================================
// modify Meta class with part specific name strings. PartHandlerDisplayName
//=======================================================================
SOM_Scope string  SOMLINK _CLm_P(clsGetODPartHandlerDisplayName)(_CLm_ *somSelf,
                                                                                Environment *ev)
{
    /* _CLm_P(Data) *somThis = _CLm_P(GetData)(somSelf); */
    _CLm_P(MethodDebug)(_CLm_q,_CLm_Pq(clsGetODPartHandlerDisplayName));

    string tempName = kKind  ;
    string displayName =  (string) SOMMalloc(strlen(tempName) + 1);
    strcpy(displayName, tempName);
    return displayName;
}

//=======================================================================
// modify Meta class with part specific name strings. PartKindInfo
//=======================================================================
SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK _CLm_P(clsGetODPartKinds)(_CLm_ *somSelf,
                                                                                       Environment *ev)
{
    /* _CLm_P(Data) *somThis = _CLm_P(GetData)(somSelf); */
    _CLm_P(MethodDebug)(_CLm_q,_CLm_Pq(clsGetODPartKinds) );


    _IDL_SEQUENCE_PartKindInfo ScriptableSimplePartInfo;

    // Create structure PartKindInfo  and allocate memory for variable

    PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));

    info->partKindName =     (ISOString)SOMMalloc(strlen(kKind) + 1);
    strcpy(info->partKindName , kKind);

    info->partKindDisplayName = (string)SOMMalloc(strlen(kKindDisplayName)+1);
    strcpy(info->partKindDisplayName, kKindDisplayName);

    info->filenameFilters =     (string)SOMMalloc(strlen("")+1);
    strcpy(info->filenameFilters, "");

    info->filenameTypes =       (string)SOMMalloc(strlen("")+1);
    strcpy(info->filenameTypes, "");

    info->categories =          (string)SOMMalloc(strlen(kCategory) + 1);
    strcpy(info->categories, kCategory);

    info->categoryDisplayName = (string)SOMMalloc(strlen(kDisplayCatagory)+1);
    strcpy(info->categoryDisplayName, kDisplayCatagory);

    info->objectID =            (string)SOMMalloc(strlen("") + 1);
    strcpy(info->objectID, "");

    // Copy the information into the structure


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

    return ScriptableSimplePartInfo;

}

//=======================================================================
// modify Meta class with part specific name strings. OLE2ClassId
//=======================================================================
SOM_Scope string  SOMLINK _CLm_P(clsGetOLE2ClassId)(_CLm_ *somSelf,
                                                                   Environment *ev)
{
    /* _CLm_P(Data) *somThis = _CLm_P(GetData)(somSelf); */
    _CLm_P(MethodDebug)(_CLm_q,_CLm_Pq(clsGetOLE2ClassId) );

    string tempClassID = kClassGUID ;
    string classID = (string) SOMMalloc(strlen(tempClassID) + 1);
    strcpy(classID, tempClassID);
    return classID;
}

//=======================================================================
// modify Meta class with part specific name strings. WindowsIconFileName
//=======================================================================
SOM_Scope string  SOMLINK _CLm_P(clsGetWindowsIconFileName)(_CLm_ *somSelf,
                                                                           Environment *ev)
{
    /* _CLm_P(Data) *somThis = _CLm_P(GetData)(somSelf); */
    _CLm_P(MethodDebug)(_CLm_q,_CLm_Pq(clsGetWindowsIconFileName) );

    string tempName = kWindowsIcon ;
    string WindowsIconFileName = (string)SOMMalloc(strlen(tempName)+1);
    strcpy(WindowsIconFileName,tempName);

    return WindowsIconFileName;
}

//=======================================================================
// Copy DrawFrame and modify to use color setting.
//=======================================================================

SOM_Scope void  SOMLINK _CLp_P(DrawFrame)(_CLp_ *somSelf,
                                            Environment *ev,
                                            ODFacet* facet,
                                            ODShape* invalidShape)
{
    _CLp_P(Data)  *somThis = _CLp_P(GetData) (somSelf);
    _CLp_P(MethodDebug) (_CLp_q,_CLp_Pq(DrawFrame) );

#if defined(_PLATFORM_OS2_)||defined(_PLATFORM_WIN32_)
    ODRect frameODRect;
    TempODShape usedShape = facet->GetFrame(ev)->AcquireUsedShape(ev,kODNULL);
    usedShape->GetBoundingBox(ev, &frameODRect);
    HDraw hDraw;
    CFocus f(facet, invalidShape, &hDraw);     // Set up drawing environment

    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, _fColor);                  // 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 (_fColor);      // 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_)
    GC gc;

    // Use the focuslib code to set up clipping - On AIX, transforms
    // are not setup
    CFocus Focus(facet, invalidShape, &gc);

    // 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;
    XtVaGetValues(widget,
                  XmNwidth, &width,
                  XmNheight, &height,
                  NULL);

    x = 0;
    y = 0;

    // Ensure the fill style is solid
    XSetFillStyle(display, gc, 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 red
            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 turquoise
            stat = XAllocNamedColor(display, map, "red" , &def, &def2);

            break;
        }

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

        // Fill the rectangle
        XFillRectangle(display,
                       window,
                       gc,
                       x, y,
                       width, height);
    }
#endif
}

