// @(#) 1.1 com/src/samples/scrsimp2/iodsppr2.cpp, odsimplescript, od96nt, odnt9712d 2/20/97 17:47:25 [3/21/97 17:46:52]
//====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========================================
//

#include <iodspcl2.h>

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


#ifndef SOM_Module_iodsppr2_Source
#define SOM_Module_iodsppr2_Source
#endif
#define ODS_Simple2_Class_Source

#define  VARIABLE_MACROS
#include "iodsppr2.xih"
#include "somtc.h"              // for TypeCodeNew declarations
#include "iodscrs2.xh"          // for ScriptableSimplepart2
#include "iodspex2.xh"          // for ScriptableSimplePart2ScrExt
#include "oddsemgr.xh"          // for ODDSEventManager

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


SOM_Scope long  SOMLINK ODS_Simple2TriggerMouseDown(ODS_Simple2 *somSelf,
                                                              Environment *ev,
                                                             long x,
                                                             long y)
{
    ODS_Simple2Data  *somThis = ODS_Simple2GetData (somSelf);
    ODS_Simple2MethodDebug ( "ODS_Simple2", "ODS_Simple2TriggerMouseDown" );

    _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
//=======================================================================

SOM_Scope void  SOMLINK ODS_Simple2SetColor(ODS_Simple2 *somSelf,
                                                      Environment *ev,
                                                     long newColor)
{

    ODS_Simple2Data  *somThis = ODS_Simple2GetData (somSelf);
    ODS_Simple2MethodDebug ( "ODS_Simple2" , "ODS_Simple2SetColor" );

    (( _CLp_ *)(_fScriptExtension->GetBase(ev)))->SetColor(ev,newColor);

}

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

SOM_Scope long  SOMLINK ODS_Simple2GetColor(ODS_Simple2 *somSelf,
                                            Environment *ev)
{
    ODS_Simple2Data  *somThis = ODS_Simple2GetData (somSelf);
    ODS_Simple2MethodDebug ( "ODS_Simple2", "ODS_Simple2GetColor" );

    return (( _CLp_ *)(_fScriptExtension->GetBase(ev)))->GetColor(ev);
}

//=======================================================================
// Override somDefaultInit to add initialization for connection support
//=======================================================================
SOM_Scope void SOMLINK ODS_Simple2somDefaultInit(ODS_Simple2  *somSelf,
                                             somInitCtrl* ctrl)
{
    ODS_Simple2Data *somThis; /* set in BeginInitializer */
    somInitCtrl globalCtrl;
    somBooleanVector myMask;
    ODS_Simple2MethodDebug( "ODS_Simple2" ,"somDefaultInit");
    ODS_Simple2_BeginInitializer_somDefaultInit;

    ODS_Simple2_Init_ODDSConnection_somDefaultInit(somSelf, ctrl);

    /*
     * local initialization code
     */


    ODGUID odguid = { 0xfb252a30,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 ODS_Simple2somDestruct(ODS_Simple2 *somSelf,
                                          octet doFree, somDestructCtrl* ctrl)
{
    ODS_Simple2Data *somThis; /* set in BeginDestructor */
    somDestructCtrl globalCtrl;
    somBooleanVector myMask;
    ODS_Simple2MethodDebug( "ODS_Simple2" , "ODS_Simple2somDestruct");
    ODS_Simple2_BeginDestructor;

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

    ODS_Simple2_EndDestructor ;
}


