home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pm6tool.zip / CNTNR.TC < prev    next >
Text File  |  1996-08-02  |  13KB  |  405 lines

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