home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
odtlktv4.zip
/
ODTLKT
/
TOOLKIT
/
BETA
/
BIN
/
PMEISTER
/
CNTNR.TC
next >
Wrap
Text File
|
1995-12-15
|
13KB
|
410 lines
/*
* This file was generated by IBM %%toolname%% version %%toolversion%%
*/
#ifndef SOM_Module_%%filename%%_Source
#define SOM_Module_%%filename%%_Source
#endif
#define %%partname%%_Class_Source
#define VARIABLE_MACROS
#include "%%filename%%.xih"
/*
Defines are used to control which sections of the os2.h and od.h files
are included in the compile.
*/
#define INCL_GPI
#define INCL_ODARBITRATOR
#define INCL_ODCANVAS
#define INCL_ODDRAFT
#define INCL_ODERRORS
#define INCL_ODFACET
#define INCL_ODFRAME
#define INCL_ODMENUBAR
#define INCL_ODSHAPE
#define INCL_ODSESSION
#define INCL_ODSTORAGEUNIT
#define INCL_ODSTORAGEUNITVIEW
#define INCL_ODTRANSFORM
#define INCL_ODWINDOW
#define INCL_ODWINDOWSTATE
#include <os2.h>
#include <od.h>
#include <stdio.h>
/*
common.hpp contains helper functions and classes for drawing.
focuslib.h contains the CFocus helper class.
*/
#include <common.hpp>
#include <focuslib.h>
/*
The following text constants are used in the registration and binding
operations to identify your part.
*/
const ODType kKind = "%%kind%%";
const ODType kKindDisplayName = "%%kind%%";
const ODType kDisplayName = "%%kind%%";
const ODType kPartHandlerName = "%%partname%%";
const ODType kCategory = "%%category%%";
/*
This debug section will produce a trace file named %%filename%%.DBG
if DEBUG is defined (uncomment the line). The output will show the
'class name : method name' as each method is called.
*/
//#define DEBUG
#ifdef DEBUG
#undef %%partname%%MethodDebug
#undef M_%%partname%%MethodDebug
#define %%partname%%MethodDebug(x,y) Log(x,y)
#define M_%%partname%%MethodDebug(x,y) Log(x,y)
#include <stdio.h>
#include <string.h>
void Log (char *x, char *y)
{
static FILE *fp = fopen ("%%filename%%.dbg", "w");
if (fp != NULL)
{
fprintf (fp, "%s:%s\n", x, y);
fflush (fp);
if (strcmp (y, "somUninit") == 0)
{
fclose (fp);
fp = NULL;
}
}
}
#endif
/*
somInit is executed when the SOM object is created. It is used to set
initial values for the SOM object attributes and private variables.
*/
SOM_Scope void SOMLINK somInit(%%partname%% *somSelf)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","somInit");
%%partname%%_parent_%%parentname%%_somInit(somSelf);
}
/*
somUnit is called on the destruction of the SOM object instance and is
used to release memory assigned to attributes and private variables.
*/
SOM_Scope void SOMLINK somUninit(%%partname%% *somSelf)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","somUninit");
%%partname%%_parent_%%parentname%%_somInit(somSelf);
}
/*
For code that is common to InitPart and InitPartFromStorage, this function
is provided. Common operations include focus and menu setup where the
requirements for the part differ from the parent implementation
*/
void CommonInitPart(%%partname%% *somSelf, Environment *ev)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","CommonInitPart");
return;
}
/*
InitPart is called when a part instance is being created from scratch (not
from a storage unit. This may occur during initial part registration or
if this part is created dynamically by another part.
*/
SOM_Scope void SOMLINK InitPart(%%partname%% *somSelf, Environment *ev,
ODStorageUnit* storageUnit, ODPart *partWrapper)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","InitPart");
// call parent method
%%partname%%_parent_%%parentname%%_InitPart(somSelf, ev, storageUnit, partWrapper);
// common part initialization
CommonInitPart (somSelf, ev);
// if the contents property does not exist, create the property, add part
if (! storageUnit->Exists (ev, kODPropContents, kKind, 0))
storageUnit->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
// add part specific part information to storage unit
_cdata.ulVar1 = 1;
_cdata.ulVar2 = 2;
StorageUnitSetValue (storageUnit, ev, sizeof (_cdata), &_cdata);
// set preferred editor property to this part
storageUnit->AddProperty (ev, kODPropPreferredKind)->AddValue (ev, kODISOStr);
StorageUnitSetValue (storageUnit, ev, strlen (kKind) + 1, kKind);
}
/*
InitPartFromStorage is called on the creation of a part instance that is
associated with an existing storage unit (usually from the template
created at registration or from a document being loaded).
*/
SOM_Scope void SOMLINK InitPartFromStorage(%%partname%% *somSelf, Environment *ev,
ODStorageUnit* storageUnit, ODPart *partWrapper)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","InitPartFromStorage");
// call parent method
%%partname%%_parent_%%parentname%%_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
// common part initialization
CommonInitPart (somSelf, ev);
// retrieve part specific data
storageUnit->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
StorageUnitGetValue (storageUnit, ev, sizeof (_cdata), &_cdata);
}
/*
Externalize stores the part information and contents into a storage unit.
*/
SOM_Scope void SOMLINK Externalize(%%partname%% *somSelf, Environment *ev)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","Externalize");
// get the storage unit to save to
ODStorageUnit* su = somSelf->GetStorageUnit (ev);
// if the contents propery exists, remove its content and replace with
// this part kind
if (su->Exists (ev, kODPropContents, kKind, 0))
{
su->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
su->Remove (ev);
su->AddValue (ev, kKind);
}
else
{
// add the contents property with this part kind
su->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
}
// store part specific data
StorageUnitSetValue (su, ev, sizeof (componentdata), &_cdata);
// call parent method
%%partname%%_parent_%%parentname%%_Externalize(somSelf, ev);
return;
}
/*
CloneInto creates a new storage unit (toSU). During registration this
method creates the storage unit for the template.
*/
SOM_Scope void SOMLINK CloneInto(%%partname%% *somSelf, Environment *ev, ODDraftKey key,
ODStorageUnit *toSU, ODFrame *scope)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","CloneInto");
// set the contents property to this part kind (create if necessary)
if (! toSU->Exists (ev, kODPropContents, kKind, 0))
toSU->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
else
{
toSU->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
toSU->Remove (ev);
toSU->AddValue (ev, kKind);
}
_cdata.ulVar1 = 1;
_cdata.ulVar2 = 2;
StorageUnitSetValue (toSU, ev, sizeof (_cdata), &_cdata);
// call parent method
%%partname%%_parent_%%parentname%%_CloneInto (somSelf, ev, key, toSU, scope);
return;
}
/*
Draw is called when the display of the part requires updating, either
the whole part (invalidShape == kODNULL) or a specified region (the
invalidShape specifies the region to redraw).
*/
SOM_Scope void SOMLINK Draw(%%partname%% *somSelf, Environment *ev, ODFacet* facet, ODShape *invalidShape)
{
%%partname%%Data *somThis = %%partname%%GetData(somSelf);
%%partname%%MethodDebug("%%partname%%","DynamicCanvasRender");
// call parent method
%%partname%%_parent_%%parentname%%_Draw (somSelf, ev, facet, invalidShape);
// set up default hps, transforms and clipping with CFocus call
HPS hps;
CFocus f (ev, facet, invalidShape, &hps);
// get part rectangle
ODRect rect;
facet->GetFrame (ev)->AcquireFrameShape (ev, kODNULL)->GetBoundingBox (ev, &rect);
ODRECTL frameRect (rect);
// calculate size of text string, and centering coordinates
POINTL aptl[TXTBOX_COUNT];
GpiQueryTextBox (hps, strlen ("%%partname%%"), "%%partname%%", TXTBOX_COUNT, aptl);
POINTL ptl;
ptl.x = (frameRect.xRight - aptl[TXTBOX_TOPRIGHT].x) / 2;
ptl.y = (frameRect.yTop - aptl[TXTBOX_TOPRIGHT].y) / 2;
// draw text
GpiSetColor (hps, CLR_BLACK);
GpiCharStringAt (hps, &ptl, strlen ("%%partname%%"), "%%partname%%");
}
/*
Return part handler name (%%partname%%)
*/
SOM_Scope ISOString SOMLINK clsGetODPartHandlerName(M_%%partname%% *somSelf,
Environment *ev)
{
/* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartHandlerName");
string handlerName = kPartHandlerName;
return ((ISOString) handlerName);
}
/*
Return part handler display name (%%kind%% Kind).
*/
SOM_Scope string SOMLINK clsGetODPartHandlerDisplayName(M_%%partname%% *somSelf,
Environment *ev)
{
/* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartHandlerDisplayName");
string displayName = kDisplayName;
return (displayName);
}
/*
Set the part kinds that this part handles.
*/
SOM_Scope _IDL_SEQUENCE_PartKindInfo SOMLINK clsGetODPartKinds(M_%%partname%% *somSelf,
Environment *ev)
{
/* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartKinds");
_IDL_SEQUENCE_PartKindInfo kindInfo;
// Create structure PartKindInfo and allocate memory for variable
PartKindInfo *info = (PartKindInfo *) SOMMalloc (sizeof (PartKindInfo));
info->partKindName = (ISOString) SOMMalloc (strlen (kKind) + 1);
info->partKindDisplayName = (string) SOMMalloc (strlen (kKindDisplayName) + 1);
info->filenameFilters = (string) SOMMalloc (strlen ("") + 1);
info->filenameTypes = (string) SOMMalloc (strlen ("") + 1);
info->categories = (string) SOMMalloc (strlen (kCategory) + 1);
info->objectID = (string) SOMMalloc (strlen ("") + 1);
// Copy the information into the structure
strcpy (info->partKindName , kKind);
strcpy (info->partKindDisplayName, kKindDisplayName);
strcpy (info->filenameFilters, "");
strcpy (info->filenameTypes, "");
strcpy (info->categories, kCategory);
strcpy (info->objectID, "");
kindInfo._maximum = 1;
kindInfo._length = 1;
kindInfo._buffer = info;
return (kindInfo);
}
/*
Return an OLE 2 class id (a part must have an OLE id in order to be
embedded within an OLE document).
*/
SOM_Scope string SOMLINK clsGetOLE2ClassId(M_%%partname%% *somSelf,
Environment *ev)
{
/* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
M_%%partname%%MethodDebug("M_%%partname%%","clsGetOLE2ClassId");
string classID = "";
return (classID);
}
/*
For OLE, sets the name of the file that will be used by an OLE document
as the icon for the part.
*/
SOM_Scope string SOMLINK clsGetWindowsIconFileName(M_%%partname%% *somSelf,
Environment *ev)
{
/* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
M_%%partname%%MethodDebug("M_%%partname%%","clsGetWindowsIconFileName");
string fileName = "";
return (fileName);
}
/*
SOMInitModule
*/
#ifdef __IBMC___
#pragma linkage (SOMInitModule, system)
#endif
SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
string className)
{
%%partname%%NewClass (%%partname%%_MajorVersion, %%partname%%_MinorVersion);
}