home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / pm6tool.zip / basenc1.tc next >
Text File  |  1996-08-02  |  12KB  |  394 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. #if defined (_PLATFORM_OS2_)
  22.   #define INCL_GPI
  23. #endif
  24.  
  25. #define INCL_ODAPI
  26. #define INCL_ODARBITRATOR
  27. #define INCL_ODCANVAS
  28. #define INCL_ODDRAFT
  29. #define INCL_ODERRORS
  30. #define INCL_ODFACET
  31. #define INCL_ODFRAME
  32. #define INCL_ODMENUBAR
  33. #define INCL_ODSESSION
  34. #define INCL_ODSHAPE
  35. #define INCL_ODSTORAGEUNIT
  36. #define INCL_ODSTORAGEUNITVIEW
  37. #define INCL_ODTRANSFORM
  38. #define INCL_ODWINDOW
  39. #define INCL_ODWINDOWSTATE
  40.  
  41. #if defined (_PLATFORM_OS2_)
  42.   #include <os2.h>
  43. #elif defined (_PLATFORM_WIN32_)
  44.   #include <od.h>
  45.  
  46.   // Prototyps for utility functions
  47.   static ODULong StorageUnitGetValue (ODStorageUnit *, Environment *, ODULong, const void *);
  48.   static ODULong StorageUnitSetValue (ODStorageUnit *, Environment *, ODULong, const void *);
  49. #endif
  50.  
  51. #include <stdio.h>
  52.  
  53. #include "$filename$.xih"
  54.  
  55. #if defined (_PLATFORM_OS2_)
  56.   #include <focuslib.h>
  57. #endif
  58.  
  59. const ODType kPartHandlerName = "$partname$";
  60. const ODType kDisplayName = $displayname$;
  61. const ODType kKind = $kind$;
  62. const ODType kKindDisplayName = $kinddisplayname$;
  63. const ODType kCategory = $category$;
  64. const ODType kCategoryDisplayName = $categorydisplayname$;
  65.  
  66. const char  *kDebugName = "$partname$";
  67. const char  *kDebugNameM = "M_$partname$";
  68.  
  69. #define FIXED2LONG(f) (((f) + 0x8000) >> 16)
  70.  
  71. #ifdef DEBUG
  72.     #undef $partname$MethodDebug
  73.     #undef M_$partname$MethodDebug
  74.  
  75.     #define $partname$MethodDebug(x,y) LogString(somSelf,x,y)
  76.     #define M_$partname$MethodDebug(x,y) LogString(somSelf,x,y)
  77.  
  78.     #include <log.h>
  79. #endif
  80.  
  81.  
  82. /*
  83.     This is the first method called when an object of this class is created.
  84.     Initialization of all attributes and private variables.
  85.  
  86.     Implementation: Call parent initializer, initialize attributes
  87.     Return        : None
  88.     Subclassing   : Call first
  89.     Notes         : None
  90. */
  91.  
  92. SOM_Scope void SOMLINK somDefaultInit($partname$ *somSelf, somInitCtrl* ctrl)
  93. {
  94.     #ifdef DEBUG
  95.       LogOpen (somSelf, "$filename$");
  96.     #endif
  97.  
  98.     $partname$Data *somThis; /* set in BeginInitializer */
  99.     somInitCtrl globalCtrl;
  100.     somBooleanVector myMask;
  101.     $partname$MethodDebug(kPartHandlerName,"somDefaultInit");
  102.     $partname$_BeginInitializer_somDefaultInit;
  103.  
  104.     $partname$_Init_$parentname$_somDefaultInit(somSelf, ctrl);
  105.  
  106.     // initialization
  107.     _text = NULL;
  108. }
  109.  
  110. /*
  111.     This is the last method called before this instance of the class is
  112.     destroyed. Release any remaining allocated resources.
  113.  
  114.     Implementation: Clean up resources, then call parent
  115.     Return        : None
  116.     Subclassing   : Call last (or as your part requires)
  117.     Notes         : None
  118. */
  119.  
  120. SOM_Scope void SOMLINK somDestruct($partname$ *somSelf, octet doFree,
  121.                                    somDestructCtrl* ctrl)
  122. {
  123.     $partname$Data *somThis; /* set in BeginDestructor */
  124.     somDestructCtrl globalCtrl;
  125.     somBooleanVector myMask;
  126.     $partname$MethodDebug(kPartHandlerName,"somDestruct");
  127.     $partname$_BeginDestructor;
  128.  
  129.     // clean up
  130.     if (_text != NULL)
  131.         SOMFree (_text);
  132.  
  133.     $partname$_EndDestructor;
  134. }
  135.  
  136. /*
  137.     Return part kind string
  138.  
  139.     Implementation:
  140.     Return        : None.
  141.     Subclassing   : Must be implemented by derived class
  142.     Notes         :
  143. */
  144.  
  145. SOM_Scope string  SOMLINK PartKind($partname$ *somSelf,  Environment *ev)
  146. {
  147.     $partname$Data *somThis = $partname$GetData(somSelf);
  148.     $partname$MethodDebug(kPartHandlerName,"PartKind");
  149.  
  150.     return (kKind);
  151. }
  152.  
  153. /*
  154.     Initialization common to new and restored parts.
  155.  
  156.     Implementation:
  157.     Return        : None.
  158.     Subclassing   : Call parent at any point.
  159.     Notes         :
  160. */
  161.  
  162. SOM_Scope void  SOMLINK InitializePart($partname$ *somSelf,  Environment *ev)
  163. {
  164.     $partname$Data *somThis = $partname$GetData(somSelf);
  165.     $partname$MethodDebug(kPartHandlerName,"InitializePart");
  166.  
  167.     $partname$_parent_$parentname$_InitializePart(somSelf, ev);
  168. }
  169.  
  170. SOM_Scope void  SOMLINK InitPart($partname$ *somSelf,  Environment *ev,
  171.                                  ODStorageUnit* storageUnit, ODPart *partWrapper)
  172. {
  173.     $partname$Data *somThis = $partname$GetData(somSelf);
  174.     $partname$MethodDebug(kPartHandlerName,"InitPart");
  175.  
  176.     $partname$_parent_$parentname$_InitPart(somSelf, ev, storageUnit, partWrapper);
  177.  
  178.     _text = (string) SOMMalloc (strlen ("$partname$") + 1);
  179.     strcpy (_text, "$partname$");
  180. }
  181.  
  182. SOM_Scope void  SOMLINK InitPartFromStorage($partname$ *somSelf, Environment *ev,
  183.                                             ODStorageUnit* storageUnit, ODPart *partWrapper)
  184. {
  185.     $partname$Data *somThis = $partname$GetData(somSelf);
  186.     $partname$MethodDebug(kPartHandlerName,"InitPartFromStorage");
  187.  
  188.     $partname$_parent_$parentname$_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  189. }
  190.  
  191. SOM_Scope void  SOMLINK InternalizeContent($partname$ *somSelf,  Environment *ev, ODStorageUnit *storageUnit)
  192. {
  193.     $partname$Data *somThis = $partname$GetData(somSelf);
  194.     $partname$MethodDebug(kPartHandlerName,"InternalizeContent");
  195.  
  196.     $partname$_parent_$parentname$_InternalizeContent(somSelf, ev, storageUnit);
  197.  
  198.     if (storageUnit->Exists (ev, kODPropContents, kKind, 0))
  199.      {
  200.         storageUnit->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
  201.         unsigned long ulSize = storageUnit->GetSize (ev);
  202.         _text = (string) SOMMalloc (ulSize);
  203.         StorageUnitGetValue (storageUnit, ev, ulSize, _text);
  204.      }
  205.     else
  206.      {
  207.         _text = (string) SOMMalloc (strlen ("$partname$") + 1);
  208.         strcpy (_text, "$partname$");
  209.      }
  210. }
  211.  
  212. SOM_Scope void  SOMLINK ExternalizeContent($partname$ *somSelf,  Environment *ev, ODStorageUnit *storageUnit)
  213. {
  214.     $partname$Data *somThis = $partname$GetData(somSelf);
  215.     $partname$MethodDebug(kPartHandlerName,"ExternalizeContent");
  216.  
  217.     $partname$_parent_$parentname$_ExternalizeContent(somSelf, ev, storageUnit);
  218.  
  219.     storageUnit->Focus (ev, kODPropContents, kODPosUndefined, kKind, 0, kODPosUndefined);
  220.     StorageUnitSetValue (storageUnit, ev, strlen (_text) + 1, _text);
  221. }
  222.  
  223. SOM_Scope void  SOMLINK DrawFrameView ($partname$ *somSelf,  Environment *ev, ODFacet* facet, ODShape *invalidShape)
  224. {
  225.     $partname$Data *somThis = $partname$GetData(somSelf);
  226.     $partname$MethodDebug(kPartHandlerName,"DrawFrameView");
  227.  
  228.     #if defined (_PLATFORM_OS2_)
  229.       HPS   gc;
  230.       RECTL frameRect;
  231.  
  232.       CFocus f (ev, facet, invalidShape, &gc);
  233.     #elif defined (_PLATFORM_WIN32_)
  234.       HDC  gc;
  235.       Rect frameRect;
  236.  
  237.       CFocus f (facet, invalidShape, &gc);
  238.     #endif
  239.  
  240.     ODRect rect;
  241.     ODShape *shape = facet->GetFrame (ev)->AcquireFrameShape (ev, facet->GetCanvas (ev));
  242.  
  243.     shape->GetBoundingBox (ev, &rect);
  244.     frameRect.xLeft = FIXED2LONG (rect.left);
  245.     frameRect.xRight = FIXED2LONG (rect.right);
  246.     frameRect.yTop = FIXED2LONG (rect.top);
  247.     frameRect.yBottom = FIXED2LONG (rect.bottom);
  248.  
  249.     #if defined (_PLATFORM_OS2_)
  250.  
  251.       GpiSetColor (gc, CLR_BLUE);
  252.       GpiBox (gc, DRO_FILL, (PPOINTL) &frameRect.xRight, 0, 0);
  253.  
  254.       POINTL aptl[TXTBOX_COUNT];
  255.       GpiQueryTextBox (gc, strlen (_text), _text, TXTBOX_COUNT, aptl);
  256.  
  257.       POINTL ptl;
  258.       ptl.x = (frameRect.xRight - aptl[TXTBOX_TOPRIGHT].x) / 2;
  259.       ptl.y = (frameRect.yTop - aptl[TXTBOX_TOPRIGHT].y) / 2;
  260.  
  261.       GpiSetColor (gc, CLR_WHITE);
  262.       GpiCharStringAt (gc, &ptl, strlen (_text), _text);
  263.     #elif defined (_PLATFORM_WIN32_)
  264.       HBRUSH hbr = CreateSolidBrush (BLUE);
  265.       FillRect (gc, &frameRect, hbr);
  266.       DeleteObject (hbr);
  267.  
  268.       SetBkMode (gc, TRANSPARENT);
  269.       SetTextColor (0x00FFFFFF);
  270.       DrawText (gc, _text, strlen (_text), &frameRect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  271.     #endif
  272. }
  273.  
  274. // metaclass methods
  275.  
  276. SOM_Scope ISOString  SOMLINK clsGetODPartHandlerName(M_$partname$ *somSelf,
  277.                                                      Environment *ev)
  278. {
  279.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  280.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerName");
  281.  
  282.     ISOString handlerName = (ISOString) SOMMalloc (strlen (kPartHandlerName) + 1);
  283.     strcpy (handlerName, kPartHandlerName);
  284.     return (handlerName);
  285. }
  286.  
  287. SOM_Scope string  SOMLINK clsGetODPartHandlerDisplayName(M_$partname$ *somSelf,
  288.                                                          Environment *ev)
  289. {
  290.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  291.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerDisplayName");
  292.  
  293.     string displayName = (string) SOMMalloc (strlen (kDisplayName) + 1);
  294.     strcpy (displayName, kDisplayName);
  295.     return (displayName);
  296. }
  297.  
  298. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK clsGetODPartKinds(M_$partname$ *somSelf,
  299.                                                                              Environment *ev)
  300. {
  301.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  302.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartKinds");
  303.  
  304.     _IDL_SEQUENCE_PartKindInfo kindInfo;
  305.  
  306.     // Create structure PartKindInfo  and allocate memory for variable
  307.     PartKindInfo *info = (PartKindInfo *) SOMMalloc (sizeof (PartKindInfo));
  308.     info->partKindName = (ISOString) SOMMalloc (strlen (kKind) + 1);
  309.     info->partKindDisplayName = (string) SOMMalloc (strlen (kKindDisplayName) + 1);
  310.     info->filenameFilters =  (string) SOMMalloc (strlen ("") + 1);
  311.     info->filenameTypes =  (string) SOMMalloc (strlen ("") + 1);
  312.     info->categories =  (string) SOMMalloc (strlen (kCategory) + 1);
  313.     info->categoryDisplayName =  (string) SOMMalloc (strlen (kCategoryDisplayName) + 1);
  314.     info->objectID =  (string) SOMMalloc (strlen ("") + 1);
  315.  
  316.     // Copy the information into the structure
  317.     strcpy (info->partKindName, kKind);
  318.     strcpy (info->partKindDisplayName, kKindDisplayName);
  319.     strcpy (info->filenameFilters, "");
  320.     strcpy (info->filenameTypes, "");
  321.     strcpy (info->categories, kCategory);
  322.     strcpy (info->categoryDisplayName, kCategoryDisplayName);
  323.     strcpy (info->objectID, "");
  324.  
  325.     kindInfo._maximum = 1;
  326.     kindInfo._length = 1;
  327.     kindInfo._buffer = info;
  328.  
  329.     return (kindInfo);
  330. }
  331.  
  332. SOM_Scope string  SOMLINK clsGetOLE2ClassId(M_$partname$ *somSelf,
  333.                                                          Environment *ev)
  334. {
  335.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  336.     M_$partname$MethodDebug(kDebugNameM,"clsGetOLE2ClassId");
  337.  
  338.     string classID = (string) SOMMalloc (1);
  339.     classID[0] = '\0';
  340.     return (classID);
  341. }
  342.  
  343. SOM_Scope string  SOMLINK clsGetWindowsIconFileName(M_$partname$ *somSelf,
  344.                                                                  Environment *ev)
  345. {
  346.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  347.     M_$partname$MethodDebug(kDebugNameM,"clsGetWindowsIconFileName");
  348.  
  349.     string fileName = (string) SOMMalloc (1);
  350.     fileName[0] = '\0';
  351.     return (fileName);
  352. }
  353.  
  354.  
  355. #ifdef __IBMC___
  356.   #pragma linkage (SOMInitModule, system)
  357. #endif
  358.  
  359. SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
  360.                                  string className)
  361. {
  362.    $partname$NewClass ($partname$_MajorVersion, $partname$_MinorVersion);
  363. }
  364.  
  365.  
  366. #if defined (_PLATFORM_WIN32_)
  367.  
  368. // Define storage utility functions for Windows
  369.  
  370. static ODULong StorageUnitGetValue (ODStorageUnit* su, Environment* ev, ODULong size, ODPtr buffer)
  371.  {
  372.     ODByteArray ba;
  373.     ODULong bytesRead = su->GetValue (ev, size, &ba);
  374.  
  375.     if (bytesRead > 0)
  376.      {
  377.         memcpy (ba._buffer, buffer, bytesRead);
  378.         delete[] (ba._buffer);
  379.      }
  380.  
  381.     return (bytesRead);
  382.  }
  383.  
  384. void StorageUnitSetValue (ODStorageUnit* su, Environment* ev, ODULong size, const void *buffer)
  385.  {
  386.     ODByteArray ba;
  387.  
  388.     ba._length = size;
  389.     ba._maximum = size;
  390.     ba._buffer = (octet *) buffer;
  391.     su->SetValue (ev, &ba);
  392.  }
  393. #endif
  394.