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