// @(#) 1.2 com/src/samples/scrgraph/iodscrgp.cpp, odgrafscript, od96nt, odnt9712d 1/22/97 15:29:13 [3/21/97 17:42:56]
//#====START_GENERATED_PROLOG======================================
//#
//#
//#   COMPONENT_NAME: odgrafscript
//#
//#   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 'GraphPart'.


#ifndef SOM_Module_iodscrgp_Source
#define SOM_Module_iodscrgp_Source
#endif
#define ScriptableGraphPart_Class_Source

#define  VARIABLE_MACROS
#include "iodscrgp.xih"

//nclude "iodscrsp.h"           // for DELTA and AIX icon defintion

#include "iodgpext.xh"          // for ODS_Graph
#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 "StdProps.xh"          // for kODAttachedScriptType

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

const ODType   kHandlerName     = "ScriptableGraphPart";
const ODType   kPresNormal      = "ScriptableGraphPart:Presentation:Normal";
const ODType   kPresPalette     = "ScriptableGraphPart:Presentation:Palette";
const ODType   kKind            = "ScriptableGraphPart";
const ODType   kKindDisplayName = "Scriptable Graph Part Kind";
const ODType   kCategory        = "OpenDoc:Category:Sample";
const ODType   kDisplayCatagory = "Sample" ;
const ODType   kWindowsIcon     = "iodscgra.ico";
const ODType   kClassGUID       = "{aae66200-3357-11d0-800a-08005a88887e}";


// Note that for a base scriptable class, ovrride code is normall needed  for:
//    somInit or somDefaultInit - for local variables including commonly the
//             reference to the new script extension object.
//    somUninit or somDestruct  - to release the extension object
//    HasExtension - to support the script Extension
//    AcquireExtension - to create and save the reference to the extension object
//    ReleaseExtension - to release and destroy the extension object
//    InitPartFromStorage - to recover the persistent information for the class
//             for the extension object.
//    Externalize and CloneInto - ensure the extension object can save its
//             persistent information
//
// Most of these are appropriately supported by the base class, Scriptable
// Base Container. Only Acquire Extension needs to be specialized since it
// needs to create an instance of the ODS_Graph ScriptExtension object.


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

    /*ScriptableGraphPartData *somThis = ScriptableGraphPartGetData(somSelf);*/
    ScriptableGraphPartMethodDebug("ScriptableGraphPart","ScriptableGraphPartAcquireExtension");

    try
    {
      if (strcmp(extensionName, kODScriptExtension)== 0)
      {
         ODS_Graph *Ext = (ODS_Graph *) somSelf->_get_fScriptExtension(ev) ;
         if (Ext == kODNULL)
         {
            Ext = new ODS_Graph ;
            if (Ext)
            {
              Ext->InitScriptExtension(ev, somSelf) ;
            }
         }
         if (Ext != NULL)
         { Ext->Acquire(ev) ; }
         somSelf->_set_fScriptExtension(ev, Ext) ;
         RetVal = (ODExtension *) Ext ;
      }
      else
      {
        RetVal = parent_AcquireExtension(somSelf,  ev,  extensionName);
      }
    }
    catch(ODException _exception)
    {
    }

    return (RetVal) ;

}
//=======================================================================
// Override HandleEvent to inovke the MouseDown Event logic
//=======================================================================
SOM_Scope ODBoolean  SOMLINK ScriptableGraphPartHandleEvent(ScriptableGraphPart *somSelf,
                                                    Environment *ev,
                                                    ODEventData* event,
                                                    ODFrame* frame,
                                                    ODFacet* facet,
                                                    ODEventInfo* eventInfo)
{
    /*ScriptableGraphPartData *somThis = ScriptableGraphPartGetData(somSelf);*/
    ScriptableGraphPartMethodDebug("ScriptableGraphPart","ScriptableGraphPartHandleEvent");

    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:
         {
             ODS_Graph * Ext = (ODS_Graph *) somSelf->_get_fScriptExtension(ev) ;
             if (Ext != NULL)
             {
               handled =
                 Ext->TriggerMouseDown(ev, LOWORD(event->lParam),
                                             HIWORD(event->lParam));
             }
          }

       default:
         break ;
    }   // end switch

    if (!handled)                       // if not handled above pass to parent
    {
          handled = parent_HandleEvent(somSelf, ev, event, frame, facet, eventInfo) ;
    }
   }
   catch(ODException _exception)
   {
   }

    return handled;
}


//=======================================================================
// Bring in the base implementation of the graph part.  Note we do this
// to avoid having a 'graphPart' that, because it inherits from scriptable
// Base Container, has some but not a full set of scripting interfaces.
//=======================================================================

// define the symbol _Scriptable_GP_ which will cause the code to
// be generated using the class name ScriptableGraphPart.
// Note that currently there are no methods implemented in the
// GraphPart code which are customized for the ScriptableGraphPart
// and thus there is no collision of method names.  If such a collision
// occurs, one solution is to simply wrap the GraphPart version in appropriate
// #ifdef/#endif and put the full implementation in the Scriptable version.
//

#define _Scriptable_GP_

#include "graph_cm.cpp"







//=======================================================================
// modify Meta class with part specific name strings. PartHandlerName
//=======================================================================
SOM_Scope ISOString  SOMLINK M_ScriptableGraphPartclsGetODPartHandlerName(M_ScriptableGraphPart *somSelf,
                                                                            Environment *ev)
{
    /* M_ScriptableGraphPartData *somThis = M_ScriptableGraphPartGetData(somSelf); */
    M_ScriptableGraphPartMethodDebug("M_ScriptableGraphPart","M_ScriptableGraphPartclsGetODPartHandlerName");

    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 M_ScriptableGraphPartclsGetODPartHandlerDisplayName(M_ScriptableGraphPart *somSelf,
                                                                                Environment *ev)
{
    /* M_ScriptableGraphPartData *somThis = M_ScriptableGraphPartGetData(somSelf); */
    M_ScriptableGraphPartMethodDebug("M_ScriptableGraphPart","M_ScriptableGraphPartclsGetODPartHandlerDisplayName");

    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 M_ScriptableGraphPartclsGetODPartKinds(M_ScriptableGraphPart *somSelf,
                                                                                       Environment *ev)
{
    /* M_ScriptableGraphPartData *somThis = M_ScriptableGraphPartGetData(somSelf); */
    M_ScriptableGraphPartMethodDebug("M_ScriptableGraphPart","M_ScriptableGraphPartclsGetODPartKinds");


    _IDL_SEQUENCE_PartKindInfo ScriptableGraphPartInfo;

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


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

    return ScriptableGraphPartInfo;

}

//=======================================================================
// modify Meta class with part specific name strings. OLE2ClassId
//=======================================================================
SOM_Scope string  SOMLINK M_ScriptableGraphPartclsGetOLE2ClassId(M_ScriptableGraphPart *somSelf,
                                                                   Environment *ev)
{
    /* M_ScriptableGraphPartData *somThis = M_ScriptableGraphPartGetData(somSelf); */
    M_ScriptableGraphPartMethodDebug("M_ScriptableGraphPart","M_ScriptableGraphPartclsGetOLE2ClassId");

    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 M_ScriptableGraphPartclsGetWindowsIconFileName(M_ScriptableGraphPart *somSelf,
                                                                           Environment *ev)
{
    /* M_ScriptableGraphPartData *somThis = M_ScriptableGraphPartGetData(somSelf); */
    M_ScriptableGraphPartMethodDebug("M_ScriptableGraphPart","M_ScriptableGraphPartclsGetWindowsIconFileName");

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

    return WindowsIconFileName;
}

