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

  1. /*
  2.     File:          $filename:toupper$.CPP
  3.  
  4.     Description:   Implementation of $partname$
  5.  
  6.     Written by:    $author$
  7.  
  8.     Copyright:     (c) $years$ by $company$
  9.                    - all rights reserved
  10.  
  11.     Generated by:  $toolname$ $toolversion$
  12. */
  13.  
  14. #ifndef SOM_Module_$filename$_Source
  15. #define SOM_Module_$filename$_Source
  16. #endif
  17. #define $partname$_Class_Source
  18.  
  19. #define VARIABLE_MACROS
  20.  
  21. #define INCL_GPI
  22. #define INCL_ODAPI
  23. #define INCL_ODARBITRATOR
  24. #define INCL_ODCANVAS
  25. #define INCL_ODDRAFT
  26. #define INCL_ODERRORS
  27. #define INCL_ODFACET
  28. #define INCL_ODFRAME
  29. #define INCL_ODMENUBAR
  30. #define INCL_ODSESSION
  31. #define INCL_ODSHAPE
  32. #define INCL_ODSTORAGEUNIT
  33. #define INCL_ODSTORAGEUNITVIEW
  34. #define INCL_ODTRANSFORM
  35. #define INCL_ODWINDOW
  36. #define INCL_ODWINDOWSTATE
  37. #include <os2.h>
  38. #include <stdio.h>
  39.  
  40. #include "$filename$.xih"
  41. #include <focuslib.h>
  42.  
  43. const ODType kPartHandlerName = "$partname$";
  44. const ODType kDisplayName = $displayname$;
  45. const ODType kKind = $kind$;
  46. const ODType kKindDisplayName = $kinddisplayname$;
  47. const ODType kCategory = $category$;
  48. const ODType kCategoryDisplayName = $categorydisplayname$;
  49.  
  50. const char  *kDebugName = "$partname$";
  51. const char  *kDebugNameM = "M_$partname$";
  52.  
  53. #define FIXED2LONG(f) (((f) + 0x8000) >> 16)
  54.  
  55. #ifdef DEBUG
  56.     #undef $partname$MethodDebug
  57.     #undef M_$partname$MethodDebug
  58.  
  59.     #define $partname$MethodDebug(x,y) LogString(somSelf,x,y)
  60.     #define M_$partname$MethodDebug(x,y) LogString(somSelf,x,y)
  61.  
  62.     #include <log.h>
  63. #endif
  64.  
  65.  
  66. /*
  67.     This is the first method called when an object of this class is created.
  68.     Initialization of all attributes and private variables.
  69.  
  70.     Implementation: Call parent initializer, initialize attributes
  71.     Return        : None
  72.     Subclassing   : Call first
  73.     Notes         : None
  74. */
  75.  
  76. SOM_Scope void SOMLINK somDefaultInit($partname$ *somSelf, somInitCtrl* ctrl)
  77. {
  78.     #ifdef DEBUG
  79.       LogOpen (somSelf, "$filename$");
  80.     #endif
  81.  
  82.     $partname$Data *somThis; /* set in BeginInitializer */
  83.     somInitCtrl globalCtrl;
  84.     somBooleanVector myMask;
  85.     $partname$MethodDebug(kPartHandlerName,"somDefaultInit");
  86.     $partname$_BeginInitializer_somDefaultInit;
  87.  
  88.     $partname$_Init_$parentname$_somDefaultInit(somSelf, ctrl);
  89.  
  90.     // initialization
  91.     _text = NULL;
  92. }
  93.  
  94. /*
  95.     This is the last method called before this instance of the class is
  96.     destroyed. Release any remaining allocated resources.
  97.  
  98.     Implementation: Clean up resources, then call parent
  99.     Return        : None
  100.     Subclassing   : Call last (or as your part requires)
  101.     Notes         : None
  102. */
  103.  
  104. SOM_Scope void SOMLINK somDestruct($partname$ *somSelf, octet doFree, somDestructCtrl* ctrl)
  105. {
  106.     $partname$Data *somThis; /* set in BeginDestructor */
  107.     somDestructCtrl globalCtrl;
  108.     somBooleanVector myMask;
  109.     $partname$MethodDebug(kPartHandlerName,"somDestruct");
  110.     $partname$_BeginDestructor;
  111.  
  112.     // clean up
  113.     if (_text != NULL)
  114.         SOMFree (_text);
  115.  
  116.     $partname$_EndDestructor;
  117. }
  118.  
  119. /*
  120.     Return part kind string
  121.  
  122.     Implementation:
  123.     Return        : None.
  124.     Subclassing   : Must be implemented by derived class
  125.     Notes         :
  126. */
  127.  
  128. SOM_Scope string  SOMLINK PartKind($partname$ *somSelf,  Environment *ev)
  129. {
  130.     $partname$Data *somThis = $partname$GetData(somSelf);
  131.     $partname$MethodDebug(kPartHandlerName,"PartKind");
  132.  
  133.     return (kKind);
  134. }
  135.  
  136. /*
  137.     Initialization common to new and restored parts.
  138.  
  139.     Implementation:
  140.     Return        : None.
  141.     Subclassing   : Call parent at any point.
  142.     Notes         :
  143. */
  144.  
  145. SOM_Scope void  SOMLINK InitializePart($partname$ *somSelf,  Environment *ev)
  146. {
  147.     $partname$Data *somThis = $partname$GetData(somSelf);
  148.     $partname$MethodDebug(kPartHandlerName,"InitializePart");
  149.  
  150.     $partname$_parent_$parentname$_InitializePart(somSelf, ev);
  151. }
  152.  
  153. SOM_Scope void  SOMLINK InitPart($partname$ *somSelf,  Environment *ev,
  154.                                  ODStorageUnit* storageUnit, ODPart *partWrapper)
  155. {
  156.     $partname$Data *somThis = $partname$GetData(somSelf);
  157.     $partname$MethodDebug(kPartHandlerName,"InitPart");
  158.  
  159.     $partname$_parent_$parentname$_InitPart(somSelf, ev, storageUnit, partWrapper);
  160.  
  161.     _text = (string) SOMMalloc (strlen ("$partname$") + 1);
  162.     strcpy (_text, "$partname$");
  163. }
  164.  
  165. SOM_Scope void  SOMLINK InitPartFromStorage($partname$ *somSelf, Environment *ev,
  166.                                             ODStorageUnit* storageUnit, ODPart *partWrapper)
  167. {
  168.     $partname$Data *somThis = $partname$GetData(somSelf);
  169.     $partname$MethodDebug(kPartHandlerName,"InitPartFromStorage");
  170.  
  171.     $partname$_parent_$parentname$_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  172. }
  173.  
  174. SOM_Scope void  SOMLINK InternalizeContent($partname$ *somSelf,  Environment *ev, ODStorageUnit *storageUnit)
  175. {
  176.     $partname$Data *somThis = $partname$GetData(somSelf);
  177.     $partname$MethodDebug(kPartHandlerName,"InternalizeContent");
  178.  
  179.     $partname$_parent_$parentname$_InternalizeContent(somSelf, ev, storageUnit);
  180.  
  181.     if (storageUnit->Exists (ev, "Text", kODISOStr, 0))
  182.      {
  183.         storageUnit->Focus (ev, "Text", kODPosUndefined, kODISOStr, 0, kODPosUndefined);
  184.         unsigned long ulSize = storageUnit->GetSize (ev);
  185.         _text = (string) SOMMalloc (ulSize);
  186.         StorageUnitGetValue (storageUnit, ev, ulSize, _text);
  187.      }
  188.     else
  189.      {
  190.         _text = (string) SOMMalloc (strlen ("$partname$") + 1);
  191.         strcpy (_text, "$partname$");
  192.      }
  193. }
  194.  
  195. SOM_Scope void  SOMLINK ExternalizeContent($partname$ *somSelf,  Environment *ev, ODStorageUnit *storageUnit)
  196. {
  197.     $partname$Data *somThis = $partname$GetData(somSelf);
  198.     $partname$MethodDebug(kPartHandlerName,"ExternalizeContent");
  199.  
  200.     $partname$_parent_$parentname$_ExternalizeContent(somSelf, ev, storageUnit);
  201.  
  202.     if (storageUnit->Exists (ev, "Text", kODISOStr, 0) == kODFalse)
  203.         storageUnit->AddProperty (ev, "Text")->AddValue (ev, kODISOStr);
  204.  
  205.     storageUnit->Focus (ev, "Text", kODPosUndefined, kODISOStr, 0, kODPosUndefined);
  206.     StorageUnitSetValue (storageUnit, ev, strlen (_text) + 1, _text);
  207. }
  208.  
  209. SOM_Scope void  SOMLINK DrawFrameView($partname$ *somSelf,  Environment *ev, ODFacet* facet, ODShape *invalidShape)
  210. {
  211.     $partname$Data *somThis = $partname$GetData(somSelf);
  212.     $partname$MethodDebug(kPartHandlerName,"DrawFrameView");
  213.  
  214.     HPS hps;
  215.     CFocus f (ev, facet, invalidShape, &hps);
  216.  
  217.     ODRect rect;
  218.     RECTL  frameRect;
  219.  
  220.     ODShape *shape = facet->GetFrame (ev)->AcquireFrameShape (ev, facet->GetCanvas (ev));
  221.     shape->GetBoundingBox (ev, &rect);
  222.     frameRect.xLeft = FIXED2LONG (rect.left);
  223.     frameRect.xRight = FIXED2LONG (rect.right);
  224.     frameRect.yTop = FIXED2LONG (rect.top);
  225.     frameRect.yBottom = FIXED2LONG (rect.bottom);
  226.  
  227.     GpiSetColor (hps, CLR_BLUE);
  228.     GpiBox (hps, DRO_FILL, (PPOINTL) &frameRect.xRight, 0, 0);
  229.  
  230.     POINTL aptl[TXTBOX_COUNT];
  231.     GpiQueryTextBox (hps, strlen (_text), _text, TXTBOX_COUNT, aptl);
  232.  
  233.     POINTL ptl;
  234.     ptl.x = (frameRect.xRight - aptl[TXTBOX_TOPRIGHT].x) / 2;
  235.     ptl.y = (frameRect.yTop - aptl[TXTBOX_TOPRIGHT].y) / 2;
  236.  
  237.     GpiSetColor (hps, CLR_WHITE);
  238.     GpiCharStringAt (hps, &ptl, strlen (_text), _text);
  239. }
  240.  
  241.  
  242. // Menu framework methods
  243.  
  244. // Return indicates whether a copy operation is currently valid
  245. SOM_Scope ODBoolean SOMLINK MenuCopyValid ($partname$ *somSelf,  Environment *ev)
  246. {
  247.     $partname$Data *somThis = $partname$GetData(somSelf);
  248.     $partname$MethodDebug("$partname$","MenuCopyValid");
  249.  
  250.     return (kODTrue);
  251. }
  252.  
  253. // Return indicates whether a paste operation is currently valid
  254. SOM_Scope ODBoolean SOMLINK MenuPasteValid ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su)
  255. {
  256.     $partname$Data *somThis = $partname$GetData(somSelf);
  257.     $partname$MethodDebug("$partname$","MenuPasteValid");
  258.  
  259.     return (kODTrue);
  260. }
  261.  
  262. // When the user executes a copy operation, the storageunit to be placed on
  263. // the clipboard must be populated, or a promise made.
  264. SOM_Scope void SOMLINK PopulateClipboardStorageUnit ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su)
  265. {
  266.     $partname$Data *somThis = $partname$GetData(somSelf);
  267.     $partname$MethodDebug("$partname$","PopulateClipboardStorageUnit");
  268.  
  269.     su->AddProperty (ev, kODPropContents)->AddValue (ev, kODKindPlainText);
  270.     StorageUnitSetValue (su, ev, strlen (_text) + 1, _text);
  271. }
  272.  
  273. // When the user executes a paste operation, this method will receive the
  274. // storageunit from the clipboard.
  275. SOM_Scope void SOMLINK ReceiveClipboardStorageUnit ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su)
  276. {
  277.     $partname$Data *somThis = $partname$GetData(somSelf);
  278.     $partname$MethodDebug("$partname$","ReceiveClipboardStorageUnit");
  279.  
  280.     // check if clipboard text type available from storage unit
  281.     if (su->Exists (ev, kODPropContents, kODKindPlainText, 0))
  282.      {
  283.         // get data from storage unit, qualify length to valid symbol length
  284.         su->Focus (ev, kODPropContents, kODPosUndefined, kODKindPlainText, 0, kODPosUndefined);
  285.         ULONG ulSize = su->GetSize (ev);
  286.         _text = (string) SOMRealloc (_text, ulSize);
  287.         StorageUnitGetValue (su, ev, ulSize, _text);
  288.  
  289.         somSelf->InvalidateAllFacets (ev);
  290.         somSelf->SetContentChanged (ev);
  291.      }
  292. }
  293.  
  294.  
  295. // Drag and Drop framework methods
  296.  
  297. // Return indicates whether a drag operation is currently valid
  298. SOM_Scope ODBoolean SOMLINK DragValid ($partname$ *somSelf, Environment *ev)
  299. {
  300.     $partname$Data *somThis = $partname$GetData(somSelf);
  301.     $partname$MethodDebug("$partname$","DragValid");
  302.  
  303.     return (kODTrue);
  304. }
  305.  
  306. // Return indicates where a drop operation is currently valid, the dragInfo
  307. // param may be used to look at the current drag object to determine whether
  308. // the drag content is suitable for dropping
  309. SOM_Scope ODBoolean SOMLINK DropValid ($partname$ *somSelf, Environment *ev, ODDragItemIterator *dragInfo)
  310. {
  311.     $partname$Data *somThis = $partname$GetData(somSelf);
  312.     $partname$MethodDebug("$partname$","DropValid");
  313.  
  314.     return (kODTrue);
  315. }
  316.  
  317. // When the user starts the drag operation, the storageunit to be dragged
  318. // must be populated, or a promise made.
  319. SOM_Scope void SOMLINK PopulateDragStorageUnit ($partname$ *somSelf, Environment *ev, ODStorageUnit *su)
  320. {
  321.     $partname$Data *somThis = $partname$GetData(somSelf);
  322.     $partname$MethodDebug("$partname$","PopulateDragStorageUnit");
  323.  
  324.     su->AddProperty (ev, kODPropContents)->AddValue (ev, kODKindPlainText);
  325.     StorageUnitSetValue (su, ev, strlen (_text) + 1, _text);
  326. }
  327.  
  328. // When the user drops the object, this method will receive the storageunit
  329. // associated with the drop object. In this case, the dropped storageunit is
  330. // managed in the same way as a Paste operation, and the equivalent clipboard
  331. // operation is used.
  332. SOM_Scope ODDropResult SOMLINK ReceiveDropStorageUnit ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su, ODFacet *facet, ODPoint *where)
  333. {
  334.     $partname$Data *somThis = $partname$GetData(somSelf);
  335.     $partname$MethodDebug("$partname$","ReceiveDropStorageUnit");
  336.  
  337.     somSelf->ReceiveClipboardStorageUnit (ev, su);
  338.     return (kODDropCopy);
  339. }
  340.  
  341.  
  342. // Link Target framework methods
  343.  
  344. // Return indicates whether a paste operation is currently valid
  345. SOM_Scope ODBoolean SOMLINK MenuPasteLinkValid ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su)
  346. {
  347.     $partname$Data *somThis = $partname$GetData(somSelf);
  348.     $partname$MethodDebug("$partname$","MenuPasteLinkValid");
  349.  
  350.     return (kODTrue);
  351. }
  352.  
  353. // When the link updates this method will receive the storageunit from the
  354. // link source. In this case, the received storageunit is managed in the same
  355. // way as a Paste operation, and the equivalent clipboard operation is used.
  356. SOM_Scope void SOMLINK ReceiveLinkStorageUnit ($partname$ *somSelf,  Environment *ev, ODStorageUnit *su)
  357. {
  358.     $partname$Data *somThis = $partname$GetData(somSelf);
  359.     $partname$MethodDebug("$partname$","ReceiveLinkStorageUnit");
  360.  
  361.     somSelf->ReceiveClipboardStorageUnit (ev, su);
  362. }
  363.  
  364. // metaclass methods
  365.  
  366. SOM_Scope ISOString  SOMLINK clsGetODPartHandlerName(M_$partname$ *somSelf,
  367.                                                      Environment *ev)
  368. {
  369.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  370.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerName");
  371.  
  372.     ISOString handlerName = (ISOString) SOMMalloc (strlen (kPartHandlerName) + 1);
  373.     strcpy (handlerName, kPartHandlerName);
  374.     return (handlerName);
  375. }
  376.  
  377. SOM_Scope string  SOMLINK clsGetODPartHandlerDisplayName(M_$partname$ *somSelf,
  378.                                                          Environment *ev)
  379. {
  380.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  381.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerDisplayName");
  382.  
  383.     string displayName = (string) SOMMalloc (strlen (kDisplayName) + 1);
  384.     strcpy (displayName, kDisplayName);
  385.     return (displayName);
  386. }
  387.  
  388. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK clsGetODPartKinds(M_$partname$ *somSelf,
  389.                                                                              Environment *ev)
  390. {
  391.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  392.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartKinds");
  393.  
  394.     _IDL_SEQUENCE_PartKindInfo kindInfo;
  395.  
  396.     // Create structure PartKindInfo  and allocate memory for variable
  397.     PartKindInfo *info = (PartKindInfo *) SOMMalloc (sizeof (PartKindInfo));
  398.     info->partKindName = (ISOString) SOMMalloc (strlen (kKind) + 1);
  399.     info->partKindDisplayName = (string) SOMMalloc (strlen (kKindDisplayName) + 1);
  400.     info->filenameFilters =  (string) SOMMalloc (strlen ("") + 1);
  401.     info->filenameTypes =  (string) SOMMalloc (strlen ("") + 1);
  402.     info->categories =  (string) SOMMalloc (strlen (kCategory) + 1);
  403.     info->categoryDisplayName =  (string) SOMMalloc (strlen (kCategoryDisplayName) + 1);
  404.     info->objectID =  (string) SOMMalloc (strlen ("") + 1);
  405.  
  406.     // Copy the information into the structure
  407.     strcpy (info->partKindName, kKind);
  408.     strcpy (info->partKindDisplayName, kKindDisplayName);
  409.     strcpy (info->filenameFilters, "");
  410.     strcpy (info->filenameTypes, "");
  411.     strcpy (info->categories, kCategory);
  412.     strcpy (info->categoryDisplayName, kCategoryDisplayName);
  413.     strcpy (info->objectID, "");
  414.  
  415.     kindInfo._maximum = 1;
  416.     kindInfo._length = 1;
  417.     kindInfo._buffer = info;
  418.  
  419.     return (kindInfo);
  420. }
  421.  
  422. SOM_Scope string  SOMLINK clsGetOLE2ClassId(M_$partname$ *somSelf,
  423.                                                          Environment *ev)
  424. {
  425.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  426.     M_$partname$MethodDebug(kDebugNameM,"clsGetOLE2ClassId");
  427.  
  428.     string classID = (string) SOMMalloc (1);
  429.     classID[0] = '\0';
  430.     return (classID);
  431. }
  432.  
  433. SOM_Scope string  SOMLINK clsGetWindowsIconFileName(M_$partname$ *somSelf,
  434.                                                                  Environment *ev)
  435. {
  436.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  437.     M_$partname$MethodDebug(kDebugNameM,"clsGetWindowsIconFileName");
  438.  
  439.     string fileName = (string) SOMMalloc (1);
  440.     fileName[0] = '\0';
  441.     return (fileName);
  442. }
  443.  
  444.  
  445. #ifdef __IBMC___
  446.   #pragma linkage (SOMInitModule, system)
  447. #endif
  448.  
  449. SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
  450.                                  string className)
  451. {
  452.    $partname$NewClass ($partname$_MajorVersion, $partname$_MinorVersion);
  453. }
  454.