//====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========================================
//
//  @(#) 1.10 com/src/samples/scrbase/iodbcext.cpp, odbasescript, od96nt, odnt9712d 2/12/97 12:51:45 [3/21/97 17:38:25]
/*
 *  This file was generated by the SOM Compiler.
 *  Generated using:
 *     SOM incremental update: Development
 */


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

#ifndef SOM_Module_iodbcext_Source
#define SOM_Module_iodbcext_Source
#endif
#define ODS_BaseContainer_Class_Source

#define VARIABLE_MACROS

#include "stdio.h"
#include "iodbcext.xih"
#include "iodbcobj.xh"
#include "part.xh"
#include "frame.xh"
#include "scrcomp.xh"
#include "iodscrbc.xh"
#include "somtc.h"              // for typecode declarations
#include "oddsemgr.xh"          // for ODDSEventManager

// define the prefered name and the class name for this class as strings
#define MyName "Container"



//==========================================================================
// GetContentFrame - this local utility function will safely get a
//   ODFrame pointer or a null given a linked list item.  It is needed
//   because not all elements of the Content list will be ContentFrame's.
//   Some will be ContentObject's while other types are possible in the
//   future.
//==========================================================================

ODFrame * GetContentFrame (Environment *ev, ALink *link) {
   ODFrame *RetFrame = NULL ;                   // default return - null
   ContentFrame *aContentFrame = new ContentFrame ;
                                                // a object known to be a ContentFrame
   SOMObject *theContent = (SOMObject *)link->Content(ev) ;  // get the item from the list element
   if ( theContent->somIsA( aContentFrame->somGetClass() ) ) {
      RetFrame = ((ContentFrame *) theContent)->_get_myFrame(ev);
                                               // if it is a ContentFrame, get the
   }                                           //  associated ODFrame
   delete aContentFrame ;                      // release the temp object
   return RetFrame ;                           // return the Frame
}

//==========================================================================

SOM_Scope void  SOMLINK SBCExt_PartAdded(ODS_BaseContainer *somSelf,
                                         Environment *ev,
                                         ODPart* part)

{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_PartAdded");

    somSelf->AddContainedPart(ev, part);
    somSelf->TriggerPartAdded(ev);

}
//==========================================================================

SOM_Scope void  SOMLINK SBCExt_PartRemoved(ODS_BaseContainer *somSelf,
                                           Environment *ev,
                                           ODPart* part)

{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_PartRemoved");

    somSelf->DropContainedPart(ev, part);
    somSelf->TriggerPartRemoved(ev);
}

//==========================================================================

SOM_Scope void  SOMLINK SBCExt_InitScriptExtension(ODS_BaseContainer *somSelf,
                                                    Environment *ev,
                                                   ODPart* owner)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_InitScriptExtension");

    ODS_BaseContainer_parent_ODScriptExtension_InitScriptExtension(somSelf,
                                                                               ev,
                                                                               owner);

    _fOwner = (ScriptableBaseContainer *) somSelf->GetBase(ev) ;

    somSelf->_set_ReqFlags(ev, 0x00 );
    somSelf->_set_ReqFlagsMask(ev, 0x00 );

    // Set the preferred name for this object.
    if (somSelf->getExtName(ev) == NULL)
    {
      somSelf->setExtName(ev, MyName) ;
    }


}
//==========================================================================
SOM_Scope ODScriptExtension_ODScrRegRet  SOMLINK SBCExt_Register(ODS_BaseContainer *somSelf,
                                                                  Environment *ev,
                                                                 ODScriptExtension* RegScope,
                                                                 string Prefix)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_Register");
    ODScriptExtension_ODScrRegRet result = ODScrRegOK;
    char                          *nameAssigned ;

    try {
      ScriptableBaseContainer *object;
      object = (ScriptableBaseContainer *) somSelf->GetBase(ev);


      if (( Prefix == NULL)  || ( *Prefix == '\0'))
      {
        char * className ;
        className = somSelf->somGetClassName() ;
        result = RegScope->DoRegisterClass(ev, className) ;
        if (result != ODScrRegOK) {
          return(result);
        }
        result = RegScope->DoRegisterObject(ev, (ODScriptExtension *)somSelf, className,
                                            somSelf->getExtName(ev),
                                            Prefix, &nameAssigned, somSelf,
                                            kODTrue);
        if (result == ODScrRegOK) {            // if registration was successful
          somSelf->setExtName(ev, nameAssigned) ;   // save the name that was used
          SOMFree(nameAssigned) ;                   // then release copy we got back
        }
      }

      if (object && result == ODScrRegOK) {
        ALinkedList *lst = object->GetEmbeddedObjects(ev);

        if (lst) {
          ALink  *link;
          for (link = lst->First(ev); link && link->Content(ev); link = link->Next(ev)) {
            ODFrame *frame;
            frame = GetContentFrame(ev, link) ;
            if (frame) {
              ODPart *part = frame->AcquirePart(ev)->GetRealPart(ev);
              if (part) {
                string nameAssigned = NULL;
                result = somSelf->DoRegisterContainedPart(ev,
                                                          part,
                                                          "Part",
                                                          (RegScope != somSelf ?
                                                              Prefix :
                                                              somSelf->getExtName(ev)),
                                                          RegScope,
                                                          &nameAssigned,
                                                          kODTrue);

                if (result == ODScrRegOK && nameAssigned) {
                  SOMFree(nameAssigned);
                }
              }
              frame->AcquirePart(ev)->ReleaseRealPart(ev);
              if (result != ODScrRegOK)
                 break;
            }
          }
        }
      }
    }
    catch (ODException _exception) {
    }
    return(result);
}


//==========================================================================
SOM_Scope void  SOMLINK SBCExt_DeRegister(ODS_BaseContainer *somSelf,
                                           Environment *ev, ODScriptExtension* ExtScope,
                                          ODBoolean doContScopes)
{
     ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_DeRegister");

  try {
#if 0
    ODS_BaseContainer_parent_ODScriptExtension_DeRegister(somSelf,
                                                                      ev,
                                                                      ExtScope,
                                                                      doContScopes);

#endif
    ExtScope->DoDeRegisterObject(ev, (ODScriptExtension *) somSelf,  somSelf, doContScopes) ;
    ScriptableBaseContainer *object = (ScriptableBaseContainer *) somSelf->GetBase(ev);
    if (object) {
      ALinkedList *lst = object->GetEmbeddedObjects(ev);

      if (lst) {
        ALink  *link;
        for (link = lst->First(ev); link && link->Content(ev); link = link->Next(ev)) {
          ODFrame *frame;
          frame = GetContentFrame(ev, link) ;
          if (frame) {
            ODPart *part = frame->AcquirePart(ev)->GetRealPart(ev);
            if (part)
              somSelf->DoDeRegisterContainedPart(ev, part, ExtScope, doContScopes) ;
            frame->AcquirePart(ev)->ReleaseRealPart(ev);
          }

        }
      }
    }
  }
  catch (...) {
    SOM_InitEnvironment(ev);
  }

}
//==========================================================================
SOM_Scope ODScriptExtension_ODScrRegRet  SOMLINK SBCExt_AddContainedPart(ODS_BaseContainer *somSelf,
                                                                          Environment *ev,
                                                                         ODPart* part)
{
    // ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_AddContainedPart");

    string assignedName = NULL;

    ODScrRegRet RetVal;


    RetVal = somSelf->DoRegisterContainedPart(ev,
                                              part,
                                              "Part",                  // default name
                                              somSelf->getExtName(ev), // name prefix
                                              somSelf,
                                              &assignedName,
                                              kODTrue);
    if (RetVal == ODScrRegOK) {
      /*
      add logic to properly associate the returned name with the
      part just registered.  That association must be persistent
      so that the same name will be assigned (via Register) when we
      reconstruct the running object set in InitFromStorage.
      */
      part->Acquire(ev);
      if (assignedName)
        SOMFree(assignedName) ;
      /*
                               somewhere, the string returned needs
                               to be freed.  if it has been preserved
                               elsewhere, the SOMFree may not be needed
                               here (but will then be needed when the
                               preserved reference is released).
      */
    }
    return RetVal ;

}
//==========================================================================
SOM_Scope void  SOMLINK SBCExt_DropContainedPart(ODS_BaseContainer *somSelf,
                                                  Environment *ev,
                                                 ODPart* part)
{
    /* ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf); */
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_DropContainedPart");


    ODS_BaseContainer_parent_ODScriptExtension_DropContainedPart(somSelf,
                                                                 ev,
                                                                 part);
    if (part)
      part->Release(ev);
}


//======================================================================
//
// The following interfaces provide the scriptable interface for the
// base container.
//
//======================================================================


//======================================================================
/*
 *Method from the IDL attribute statement:
 *"attribute long BackgroundColor"
 */

SOM_Scope long  SOMLINK SBCExt__get_BackgroundColor(ODS_BaseContainer *somSelf,
                                              Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","_get_BackgroundColor");

    try {
      if (_fOwner) {
        return(_fOwner->_get_BackgroundColor(ev));
      }
    }
    catch (ODException _exception) {
    }

    return(0);
}

//======================================================================/*

/*
 *Method from the IDL attribute statement:
 *"attribute long BackgroundColor"
 */

SOM_Scope void  SOMLINK SBCExt__set_BackgroundColor(ODS_BaseContainer *somSelf,
                                              Environment *ev,
                                             long BackgroundColor)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","_set_BackgroundColor");

    try {
      if (_fOwner) {
        _fOwner->_set_BackgroundColor(ev, BackgroundColor);
      }
    }
    catch (ODException _exception) {
    }

}
//======================================================================/*
/*
 *Method from the IDL attribute statement:
 *"attribute boolean DoMenuSelection"
 */

SOM_Scope boolean  SOMLINK SBCExt__get_DoMenuSelection(ODS_BaseContainer *somSelf,
                                                 Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","_get_DoMenuSelection");

    return(TRUE);
}
//======================================================================/*

/*
 *Method from the IDL attribute statement:
 *"attribute boolean DoMenuSelection"
 */

SOM_Scope void  SOMLINK SBCExt__set_DoMenuSelection(ODS_BaseContainer *somSelf,
                                              Environment *ev,
                                             boolean DoMenuSelection)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","_set_DoMenuSelection");

    try {
      if (_fOwner && DoMenuSelection == FALSE) {
        _fOwner->AbortMenuSelection(ev);
      }
    }
    catch (ODException _exception) {

    }

}

//======================================================================
SOM_Scope void  SOMLINK SBCExt_SelectAllParts(ODS_BaseContainer *somSelf,  Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SelectAllParts");

    try {
      if (_fOwner) {
        _fOwner->SelectAllParts(ev);
      }
    }
    catch (ODException _exception) {

    }

}
//======================================================================
SOM_Scope boolean  SOMLINK SBCExt_EmbedPart(ODS_BaseContainer *somSelf,  Environment *ev,
                                     string partKind, long x,
                                     long y)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","EmbedPart");

    try {
      if (_fOwner) {
        _fOwner->EmbedPart(ev, partKind, x, y);
        return(TRUE);
      }
    }
    catch (ODException _exception) {
    }
    return(FALSE);
}
//======================================================================
SOM_Scope long  SOMLINK SBCExt_SelectMenuItem(ODS_BaseContainer *somSelf,  Environment *ev,
                                       long menuId)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SelectMenuItem");

    try {
      if (_fOwner) {
        _fOwner->SelectMenuItem(ev, menuId);
        return(menuId);
      }
    }
    catch (ODException _exception) {

    }
    return(-1);
}


//======================================================================
// The following interfaces provide the drivers for the events that are
// initiatiated by this interface
//======================================================================


//======================================================================
SOM_Scope void  SOMLINK SBCExt_TriggerMenuEvent(ODS_BaseContainer *somSelf,  Environment *ev,
                                         long menuId)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","TriggerMenuEvent");

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

    data[0]._type = TypeCodeNew(tk_long);
    data[0]._value = (void *) &menuId;
    inParms._length  = 1;
    inParms._maximum = 1;
    inParms._buffer = data;


    try {

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

    catch(ODException _exception)
    {
    }


    /* Return statement to be customized: */
    return;
}
//======================================================================
SOM_Scope void  SOMLINK SBCExt_TriggerPartAdded(ODS_BaseContainer *somSelf,  Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","TriggerPartAdded");
    _IDL_SEQUENCE_any  inParms;
    ODDSRESULT         result;
    long               sinkCount ;
    long               sinkNumber ;
    ODDSSinkEnum       *sinkEnum;

    inParms._length  = 0;
    inParms._maximum = 0;
    inParms._buffer = NULL;


    try {

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

    catch(ODException _exception)
    {
    }



}
//======================================================================
SOM_Scope void  SOMLINK SBCExt_TriggerPartRemoved(ODS_BaseContainer *somSelf,  Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","TriggerPartRemoved");
    _IDL_SEQUENCE_any  inParms;
    ODDSRESULT         result;
    long               sinkCount ;
    long               sinkNumber ;
    ODDSSinkEnum       *sinkEnum;

    inParms._length  = 0;
    inParms._maximum = 0;
    inParms._buffer = NULL;


    try {

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

    catch(ODException _exception)
    {
    }


}
//======================================================================
SOM_Scope void  SOMLINK SBCExt_TriggerPartContentsInitialized(ODS_BaseContainer *somSelf,
                                                       Environment *ev)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","TriggerMenuEvent");

    _IDL_SEQUENCE_any  inParms;
    ODDSRESULT         result;
    long               sinkCount ;
    long               sinkNumber ;
    ODDSSinkEnum       *sinkEnum;

    inParms._length  = 0;
    inParms._maximum = 0;
    inParms._buffer = NULL;


    try {

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

    catch(ODException _exception)
    {
    }

}

SOM_Scope void SOMLINK SBCExt_somDefaultInit(ODS_BaseContainer *somSelf,
                                             somInitCtrl* ctrl)
{
    ODS_BaseContainerData *somThis; /* set in BeginInitializer */
    somInitCtrl globalCtrl;
    somBooleanVector myMask;
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","somDefaultInit");
    ODS_BaseContainer_BeginInitializer_somDefaultInit;

    ODS_BaseContainer_Init_ODScriptExtension_somDefaultInit(somSelf, ctrl);
    ODS_BaseContainer_Init_ODDSConnection_somDefaultInit(somSelf, ctrl);

    /*
     * local ODS_BaseContainer initialization code
     */

    Environment *ev = SOM_CreateLocalEnvironment();
    _fOwner = (ScriptableBaseContainer *) somSelf->GetBase(ev) ;

    ODGUID odguid = { 0xf2166380, 0x285d, 0x11d0,
                      {0xa5, 0xc4, 0x00, 0x04, 0xac, 0x32, 0x80, 0xdc}};
    _fODGuid = odguid ;
    _fEventManager =  new ODDSEventMgr(ev, _fODGuid);
    somSelf->AddEventMgr(ev, _fEventManager);

    SOM_DestroyLocalEnvironment(ev);
}

#if 0
// somInit replaced by somDefaultInit above
//======================================================================
SOM_Scope void  SOMLINK SBCExt_somInit(ODS_BaseContainer *somSelf)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    Environment *ev = SOM_CreateLocalEnvironment();
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","somInit");

    ODS_BaseContainer_parent_ODDSConnection_somInit(somSelf);
    ODS_BaseContainer_parent_ODScriptExtension_somInit(somSelf);

    _fOwner = (ScriptableBaseContainer *) somSelf->GetBase(ev) ;

    ODGUID odguid = { 0xf2166380, 0x285d, 0x11d0,
                      {0xa5, 0xc4, 0x00, 0x04, 0xac, 0x32, 0x80, 0xdc}};
    _fODGuid = odguid ;
    _fEventManager =  new ODDSEventMgr(ev, _fODGuid);
    somSelf->AddEventMgr(ev, _fEventManager);

    SOM_DestroyLocalEnvironment(ev);
}
#endif


//======================================================================
//
SOM_Scope void SOMLINK SBCExt_somDestruct(ODS_BaseContainer *somSelf,
                                          octet doFree, somDestructCtrl* ctrl)
{
    ODS_BaseContainerData *somThis; /* set in BeginDestructor */
    somDestructCtrl globalCtrl;
    somBooleanVector myMask;
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","SBCExt_somDestruct");
    ODS_BaseContainer_BeginDestructor;

    /*
     * local ODS_BaseContainer deinitialization code
     */
    Environment *ev;

    ev = SOM_CreateLocalEnvironment();
    if (_fEventManager)
    {
      somSelf->DeleteEventMgr(ev,&_fODGuid) ;
      delete _fEventManager ;
    }
    SOM_DestroyLocalEnvironment(ev);

    ODS_BaseContainer_EndDestructor;
}






#if 0
// somUninit  replaced by somDestruct above
//======================================================================
SOM_Scope void  SOMLINK SBCExt_somUninit(ODS_BaseContainer *somSelf)
{
    ODS_BaseContainerData *somThis = ODS_BaseContainerGetData(somSelf);
    ODS_BaseContainerMethodDebug("ODS_BaseContainer","somUninit");
    Environment *ev;

    ev = SOM_CreateLocalEnvironment();
    if (_fEventManager)
    {
      somSelf->DeleteEventMgr(ev,&_fODGuid) ;
      delete _fEventManager ;
    }
    SOM_DestroyLocalEnvironment(ev);

    ODS_BaseContainer_parent_ODDSConnection_somUninit(somSelf);
    ODS_BaseContainer_parent_ODScriptExtension_somUninit(somSelf);
}
//======================================================================
#endif
