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 >
Text File  |  1995-12-15  |  13KB  |  410 lines

  1. /*
  2.  *  This file was generated by IBM %%toolname%% version %%toolversion%%
  3.  */
  4.  
  5. #ifndef SOM_Module_%%filename%%_Source
  6. #define SOM_Module_%%filename%%_Source
  7. #endif
  8. #define %%partname%%_Class_Source
  9.  
  10. #define VARIABLE_MACROS
  11. #include "%%filename%%.xih"
  12.  
  13. /*
  14.     Defines are used to control which sections of the os2.h and od.h files
  15.     are included in the compile.
  16. */
  17.  
  18. #define INCL_GPI
  19. #define INCL_ODARBITRATOR
  20. #define INCL_ODCANVAS
  21. #define INCL_ODDRAFT
  22. #define INCL_ODERRORS
  23. #define INCL_ODFACET
  24. #define INCL_ODFRAME
  25. #define INCL_ODMENUBAR
  26. #define INCL_ODSHAPE
  27. #define INCL_ODSESSION
  28. #define INCL_ODSTORAGEUNIT
  29. #define INCL_ODSTORAGEUNITVIEW
  30. #define INCL_ODTRANSFORM
  31. #define INCL_ODWINDOW
  32. #define INCL_ODWINDOWSTATE
  33. #include <os2.h>
  34. #include <od.h>
  35. #include <stdio.h>
  36.  
  37. /*
  38.     common.hpp contains helper functions and classes for drawing.
  39.     focuslib.h contains the CFocus helper class.
  40. */
  41.  
  42. #include <common.hpp>
  43. #include <focuslib.h>
  44.  
  45.  
  46. /*
  47.     The following text constants are used in the registration and binding
  48.     operations to identify your part.
  49. */
  50.  
  51. const ODType kKind = "%%kind%%";
  52. const ODType kKindDisplayName = "%%kind%%";
  53. const ODType kDisplayName = "%%kind%%";
  54. const ODType kPartHandlerName = "%%partname%%";
  55. const ODType kCategory = "%%category%%";
  56.  
  57.  
  58. /*
  59.     This debug section will produce a trace file named %%filename%%.DBG
  60.     if DEBUG is defined (uncomment the line).  The output will show the
  61.     'class name : method name' as each method is called.
  62. */
  63.  
  64. //#define DEBUG
  65. #ifdef DEBUG
  66.     #undef %%partname%%MethodDebug
  67.     #undef M_%%partname%%MethodDebug
  68.  
  69.     #define %%partname%%MethodDebug(x,y) Log(x,y)
  70.     #define M_%%partname%%MethodDebug(x,y) Log(x,y)
  71.  
  72.     #include <stdio.h>
  73.     #include <string.h>
  74.  
  75.     void Log (char *x, char *y)
  76.      {
  77.         static FILE *fp = fopen ("%%filename%%.dbg", "w");
  78.         if (fp != NULL)
  79.          {
  80.             fprintf (fp, "%s:%s\n", x, y);
  81.             fflush (fp);
  82.  
  83.             if (strcmp (y, "somUninit") == 0)
  84.              {
  85.                 fclose (fp);
  86.                 fp = NULL;
  87.              }
  88.          }
  89.      }
  90. #endif
  91.  
  92.  
  93. /*
  94.     somInit is executed when the SOM object is created.  It is used to set
  95.     initial values for the SOM object attributes and private variables.
  96. */
  97.  
  98. SOM_Scope void  SOMLINK somInit(%%partname%% *somSelf)
  99. {
  100.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  101.     %%partname%%MethodDebug("%%partname%%","somInit");
  102.  
  103.     %%partname%%_parent_%%parentname%%_somInit(somSelf);
  104. }
  105.  
  106.  
  107. /*
  108.     somUnit is called on the destruction of the SOM object instance and is
  109.     used to release memory assigned to attributes and private variables.
  110. */
  111.  
  112. SOM_Scope void  SOMLINK somUninit(%%partname%% *somSelf)
  113. {
  114.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  115.     %%partname%%MethodDebug("%%partname%%","somUninit");
  116.  
  117.     %%partname%%_parent_%%parentname%%_somInit(somSelf);
  118. }
  119.  
  120.  
  121. /*
  122.     For code that is common to InitPart and InitPartFromStorage, this function
  123.     is provided.  Common operations include focus and menu setup where the
  124.     requirements for the part differ from the parent implementation
  125. */
  126.  
  127. void CommonInitPart(%%partname%% *somSelf, Environment *ev)
  128. {
  129.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  130.     %%partname%%MethodDebug("%%partname%%","CommonInitPart");
  131.  
  132.     return;
  133. }
  134.  
  135.  
  136. /*
  137.     InitPart is called when a part instance is being created from scratch (not
  138.     from a storage unit.  This may occur during initial part registration or
  139.     if this part is created dynamically by another part.
  140. */
  141.  
  142. SOM_Scope void  SOMLINK InitPart(%%partname%% *somSelf,  Environment *ev,
  143.                                  ODStorageUnit* storageUnit, ODPart *partWrapper)
  144. {
  145.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  146.     %%partname%%MethodDebug("%%partname%%","InitPart");
  147.  
  148.     // call parent method
  149.     %%partname%%_parent_%%parentname%%_InitPart(somSelf, ev, storageUnit, partWrapper);
  150.  
  151.     // common part initialization
  152.     CommonInitPart (somSelf, ev);
  153.  
  154.     // if the contents property does not exist, create the property, add part
  155.     if (! storageUnit->Exists (ev, kODPropContents, kKind, 0))
  156.         storageUnit->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
  157.  
  158.     // add part specific part information to storage unit
  159.     _cdata.ulVar1 = 1;
  160.     _cdata.ulVar2 = 2;
  161.     StorageUnitSetValue (storageUnit, ev, sizeof (_cdata), &_cdata);
  162.  
  163.     // set preferred editor property to this part
  164.     storageUnit->AddProperty (ev, kODPropPreferredKind)->AddValue (ev, kODISOStr);
  165.     StorageUnitSetValue (storageUnit, ev, strlen (kKind) + 1, kKind);
  166. }
  167.  
  168.  
  169. /*
  170.     InitPartFromStorage is called on the creation of a part instance that is
  171.     associated with an existing storage unit (usually from the template
  172.     created at registration or from a document being loaded).
  173. */
  174.  
  175. SOM_Scope void  SOMLINK InitPartFromStorage(%%partname%% *somSelf, Environment *ev,
  176.                                             ODStorageUnit* storageUnit, ODPart *partWrapper)
  177. {
  178.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  179.     %%partname%%MethodDebug("%%partname%%","InitPartFromStorage");
  180.  
  181.     // call parent method
  182.     %%partname%%_parent_%%parentname%%_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  183.  
  184.     // common part initialization
  185.     CommonInitPart (somSelf, ev);
  186.  
  187.     // retrieve part specific data
  188.     storageUnit->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
  189.     StorageUnitGetValue (storageUnit, ev, sizeof (_cdata), &_cdata);
  190. }
  191.  
  192.  
  193. /*
  194.     Externalize stores the part information and contents into a storage unit.
  195. */
  196.  
  197. SOM_Scope void  SOMLINK Externalize(%%partname%% *somSelf,  Environment *ev)
  198. {
  199.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  200.     %%partname%%MethodDebug("%%partname%%","Externalize");
  201.  
  202.     // get the storage unit to save to
  203.     ODStorageUnit* su = somSelf->GetStorageUnit (ev);
  204.  
  205.     // if the contents propery exists, remove its content and replace with
  206.     // this part kind
  207.     if (su->Exists (ev, kODPropContents, kKind, 0))
  208.      {
  209.         su->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
  210.         su->Remove (ev);
  211.         su->AddValue (ev, kKind);
  212.      }
  213.     else
  214.      {
  215.         // add the contents property with this part kind
  216.         su->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
  217.      }
  218.  
  219.     // store part specific data
  220.     StorageUnitSetValue (su, ev, sizeof (componentdata), &_cdata);
  221.  
  222.     // call parent method
  223.     %%partname%%_parent_%%parentname%%_Externalize(somSelf, ev);
  224.  
  225.     return;
  226. }
  227.  
  228.  
  229. /*
  230.     CloneInto creates a new storage unit (toSU).  During registration this
  231.     method creates the storage unit for the template.
  232. */
  233.  
  234. SOM_Scope void  SOMLINK CloneInto(%%partname%% *somSelf,  Environment *ev, ODDraftKey key,
  235.                                   ODStorageUnit *toSU, ODFrame *scope)
  236. {
  237.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  238.     %%partname%%MethodDebug("%%partname%%","CloneInto");
  239.  
  240.     // set the contents property to this part kind (create if necessary)
  241.     if (! toSU->Exists (ev, kODPropContents, kKind, 0))
  242.         toSU->AddProperty (ev, kODPropContents)->AddValue (ev, kKind);
  243.     else
  244.      {
  245.         toSU->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
  246.         toSU->Remove (ev);
  247.         toSU->AddValue (ev, kKind);
  248.      }
  249.  
  250.     _cdata.ulVar1 = 1;
  251.     _cdata.ulVar2 = 2;
  252.     StorageUnitSetValue (toSU, ev, sizeof (_cdata), &_cdata);
  253.  
  254.     // call parent method
  255.     %%partname%%_parent_%%parentname%%_CloneInto (somSelf, ev, key, toSU, scope);
  256.  
  257.     return;
  258. }
  259.  
  260.  
  261. /*
  262.     Draw is called when the display of the part requires updating, either
  263.     the whole part (invalidShape == kODNULL) or a specified region (the
  264.     invalidShape specifies the region to redraw).
  265. */
  266.  
  267. SOM_Scope void  SOMLINK Draw(%%partname%% *somSelf,  Environment *ev, ODFacet* facet, ODShape *invalidShape)
  268. {
  269.     %%partname%%Data *somThis = %%partname%%GetData(somSelf);
  270.     %%partname%%MethodDebug("%%partname%%","DynamicCanvasRender");
  271.  
  272.     // call parent method
  273.     %%partname%%_parent_%%parentname%%_Draw (somSelf, ev, facet, invalidShape);
  274.  
  275.     // set up default hps, transforms and clipping with CFocus call
  276.     HPS hps;
  277.     CFocus f (ev, facet, invalidShape, &hps);
  278.  
  279.     // get part rectangle
  280.     ODRect rect;
  281.     facet->GetFrame (ev)->AcquireFrameShape (ev, kODNULL)->GetBoundingBox (ev, &rect);
  282.     ODRECTL frameRect (rect);
  283.  
  284.     // calculate size of text string, and centering coordinates
  285.     POINTL aptl[TXTBOX_COUNT];
  286.     GpiQueryTextBox (hps, strlen ("%%partname%%"), "%%partname%%", TXTBOX_COUNT, aptl);
  287.  
  288.     POINTL ptl;
  289.     ptl.x = (frameRect.xRight - aptl[TXTBOX_TOPRIGHT].x) / 2;
  290.     ptl.y = (frameRect.yTop - aptl[TXTBOX_TOPRIGHT].y) / 2;
  291.  
  292.     // draw text
  293.     GpiSetColor (hps, CLR_BLACK);
  294.     GpiCharStringAt (hps, &ptl, strlen ("%%partname%%"), "%%partname%%");
  295. }
  296.  
  297.  
  298. /*
  299.     Return part handler name (%%partname%%)
  300. */
  301.  
  302. SOM_Scope ISOString  SOMLINK clsGetODPartHandlerName(M_%%partname%% *somSelf,
  303.                                                      Environment *ev)
  304. {
  305.     /* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
  306.     M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartHandlerName");
  307.  
  308.     string handlerName = kPartHandlerName;
  309.     return ((ISOString) handlerName);
  310. }
  311.  
  312.  
  313. /*
  314.     Return part handler display name (%%kind%% Kind).
  315. */
  316.  
  317. SOM_Scope string  SOMLINK clsGetODPartHandlerDisplayName(M_%%partname%% *somSelf,
  318.                                                          Environment *ev)
  319. {
  320.     /* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
  321.     M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartHandlerDisplayName");
  322.  
  323.     string displayName = kDisplayName;
  324.     return (displayName);
  325. }
  326.  
  327.  
  328. /*
  329.     Set the part kinds that this part handles.
  330. */
  331.  
  332. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK clsGetODPartKinds(M_%%partname%% *somSelf,
  333.                                                                              Environment *ev)
  334. {
  335.     /* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
  336.     M_%%partname%%MethodDebug("M_%%partname%%","clsGetODPartKinds");
  337.  
  338.     _IDL_SEQUENCE_PartKindInfo kindInfo;
  339.  
  340.     // Create structure PartKindInfo  and allocate memory for variable
  341.     PartKindInfo *info = (PartKindInfo *) SOMMalloc (sizeof (PartKindInfo));
  342.     info->partKindName = (ISOString) SOMMalloc (strlen (kKind) + 1);
  343.     info->partKindDisplayName = (string) SOMMalloc (strlen (kKindDisplayName) + 1);
  344.     info->filenameFilters =  (string) SOMMalloc (strlen ("") + 1);
  345.     info->filenameTypes =  (string) SOMMalloc (strlen ("") + 1);
  346.     info->categories =  (string) SOMMalloc (strlen (kCategory) + 1);
  347.     info->objectID =  (string) SOMMalloc (strlen ("") + 1);
  348.  
  349.     // Copy the information into the structure
  350.     strcpy (info->partKindName , kKind);
  351.     strcpy (info->partKindDisplayName, kKindDisplayName);
  352.     strcpy (info->filenameFilters, "");
  353.     strcpy (info->filenameTypes, "");
  354.     strcpy (info->categories, kCategory);
  355.     strcpy (info->objectID, "");
  356.  
  357.     kindInfo._maximum = 1;
  358.     kindInfo._length = 1;
  359.     kindInfo._buffer = info;
  360.  
  361.     return (kindInfo);
  362. }
  363.  
  364.  
  365. /*
  366.     Return an OLE 2 class id (a part must have an OLE id in order to be
  367.     embedded within an OLE document).
  368. */
  369.  
  370. SOM_Scope string  SOMLINK clsGetOLE2ClassId(M_%%partname%% *somSelf,
  371.                                                          Environment *ev)
  372. {
  373.     /* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
  374.     M_%%partname%%MethodDebug("M_%%partname%%","clsGetOLE2ClassId");
  375.  
  376.     string classID = "";
  377.     return (classID);
  378. }
  379.  
  380.  
  381. /*
  382.     For OLE, sets the name of the file that will be used by an OLE document
  383.     as the icon for the part.
  384. */
  385.  
  386. SOM_Scope string  SOMLINK clsGetWindowsIconFileName(M_%%partname%% *somSelf,
  387.                                                                  Environment *ev)
  388. {
  389.     /* M_%%partname%%Data *somThis = M_%%partname%%GetData(somSelf); */
  390.     M_%%partname%%MethodDebug("M_%%partname%%","clsGetWindowsIconFileName");
  391.  
  392.     string fileName = "";
  393.     return (fileName);
  394. }
  395.  
  396.  
  397. /*
  398.     SOMInitModule
  399. */
  400.  
  401. #ifdef __IBMC___
  402.   #pragma linkage (SOMInitModule, system)
  403. #endif
  404.  
  405. SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
  406.                                  string className)
  407. {
  408.    %%partname%%NewClass (%%partname%%_MajorVersion, %%partname%%_MinorVersion);
  409. }
  410.