home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12otk1.exe / pmeister / IODSIMPL.TC next >
Text File  |  1997-04-02  |  18KB  |  540 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. #include <odall.h>
  22.  
  23. #ifndef _ODDEBUG_
  24. #include <ODDebug.h>
  25. #endif
  26.  
  27. #ifndef _TEMPOBJ_
  28. #include <TempObj.h>
  29. #endif
  30.  
  31. #ifndef _ODMATH_
  32. #include <ODMath.h>
  33. #endif
  34.  
  35. #ifndef _WINUTILS_
  36. #include <WinUtils.h>
  37. #endif
  38.  
  39. #ifndef _STDTYPIO_
  40. #include <StdTypIO.h>
  41. #endif
  42.  
  43. #if defined (_PLATFORM_OS2_)
  44. #include <odos2.h>
  45. #endif
  46.  
  47. #if defined (_PLATFORM_WIN32_)
  48. #include <storutil.h>
  49. #endif
  50.  
  51. #if defined (_PLATFORM_AIX_)
  52. #include <Xm/XmAll.h>
  53. #endif
  54.  
  55.  
  56. #include <stdio.h>
  57.  
  58. #include "$filename$.xih"
  59.  
  60. #include <FocusLib.h>
  61.  
  62. #include "$filename$.h"
  63.  
  64. #if (defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_))
  65. #include "$lang_subdir$\$filename$.h"       // The generated message catalog header
  66. #endif
  67.  
  68. #ifdef _PLATFORM_AIX_
  69. #include "$lang_subdir$/$filename$_msg.h"   // The generated message catalog header
  70. #endif
  71.  
  72. const ODType kPartHandlerName     = "$partname$";
  73. const ODType kDisplayName         = $displayname$;
  74. const ODType kKind                = $kind$;
  75. const ODType kKindDisplayName     = $kinddisplayname$;
  76. const ODType kCategory            = $category$;
  77. const ODType kCategoryDisplayName = $categorydisplayname$;
  78.  
  79. const char  *kDebugName           = "$partname$";
  80. const char  *kDebugNameM          = "M_$partname$";
  81.  
  82. #define FIXED2LONG(f) (((f) + 0x8000) >> 16)
  83.  
  84. /*
  85.     This is the first method called when an object of this class is created.
  86.     Initialization of all attributes and private variables.
  87.  
  88.     Implementation: Call parent initializer, initialize attributes
  89.     Return        : None
  90.     Subclassing   : Call first
  91.     Notes         : None
  92. */
  93.  
  94. SOM_Scope void SOMLINK somDefaultInit($partname$ *somSelf, somInitCtrl* ctrl)
  95. {
  96.     $partname$Data *somThis; /* set in BeginInitializer */
  97.     somInitCtrl globalCtrl;
  98.     somBooleanVector myMask;
  99.     $partname$MethodDebug(kPartHandlerName,"somDefaultInit");
  100.     $partname$_BeginInitializer_somDefaultInit;
  101.  
  102.     $partname$_Init_$parentname$_somDefaultInit(somSelf, ctrl);
  103.  
  104.     // initialization
  105.     _text = NULL;
  106. }
  107.  
  108. /*
  109.     This is the last method called before this instance of the class is
  110.     destroyed. Release any remaining allocated resources.
  111.  
  112.     Implementation: Clean up resources, then call parent
  113.     Return        : None
  114.     Subclassing   : Call last (or as your part requires)
  115.     Notes         : None
  116. */
  117.  
  118. SOM_Scope void SOMLINK somDestruct($partname$ *somSelf, octet doFree,
  119.                                    somDestructCtrl* ctrl)
  120. {
  121.     $partname$Data *somThis; /* set in BeginDestructor */
  122.     somDestructCtrl globalCtrl;
  123.     somBooleanVector myMask;
  124.     $partname$MethodDebug(kPartHandlerName,"somDestruct");
  125.     $partname$_BeginDestructor;
  126.  
  127.     // clean up
  128.     if (_text != NULL)
  129.         SOMFree (_text);
  130.  
  131.     $partname$_EndDestructor;
  132. }
  133.  
  134.  
  135.  
  136. SOM_Scope void  SOMLINK InitPart($partname$ *somSelf,  Environment *ev,
  137.                                  ODStorageUnit* storageUnit, ODPart *partWrapper)
  138. {
  139.     $partname$Data *somThis = $partname$GetData(somSelf);
  140.     $partname$MethodDebug(kPartHandlerName,"InitPart");
  141.  
  142.     try
  143.     {
  144.        // Call parent's method (which calls our CommonInit)
  145.        $partname$_parent_SimplePart_InitPart(somSelf, ev, storageUnit, partWrapper);
  146.  
  147.        // Save preferred kind property
  148.        ODSetISOStrProp(ev, storageUnit,
  149.                       kODPropPreferredKind,
  150.                       kODISOStr,
  151.                       kKind);
  152.  
  153.        _text = (string) SOMMalloc (strlen ("$partname$") + 1);
  154.        strcpy (_text, "$partname$");
  155.     }
  156.     catch(...)
  157.     {
  158.     }
  159. }
  160.  
  161.  
  162. SOM_Scope void  SOMLINK CommonInit($partname$ *somSelf,
  163.                                    Environment *ev,
  164.                                    ODPart* partWrapper)
  165. {
  166.     $partname$Data *somThis = $partname$GetData(somSelf);
  167.     $partname$MethodDebug(kPartHandlerName,"CommonInit");
  168.  
  169.     try
  170.     {
  171.     $partname$_parent_SimplePart_CommonInit(somSelf, ev, partWrapper);
  172.     somThis->fSession = somSelf->GetStorageUnit(ev)->GetSession(ev);
  173.  
  174.     ODMenuBar *menuBar = somSelf->GetMenuBar(ev);
  175.  
  176.     if (menuBar) {
  177.  
  178.        menuBar->Acquire(ev);
  179.  
  180. #if defined(__IBMCPP__) || defined(_IBMR2)
  181.        nl_catd msgCatalog;       // NLS message catalog handle
  182.        char *menuText;           // pointer for NLS message
  183.  
  184.        setlocale(LC_MESSAGES, NULL);
  185.        msgCatalog = catopen($filename:toupper$_MSG_CATALOG, 0);
  186.        if(msgCatalog == CATD_ERR)
  187.        {
  188.          PRINT("Could not open message catalog %s\n", $filename:toupper$_MSG_CATALOG);
  189.        }
  190. #else
  191.        char menuText[256];
  192. #endif
  193.  
  194.        ODPlatformMenuItem *mi = new ODPlatformMenuItem;
  195.  
  196.        // add a menu separator line to the HELP menu
  197.        mi->id = k$partname$MenuSeparator;
  198.        #if defined(_PLATFORM_WIN32_)
  199.        mi->afAttribute=MF_SEPARATOR;
  200.        #elif defined(_PLATFORM_OS2_)
  201.        mi->afAttribute=CA_TITLESEPARATOR;
  202.        #endif
  203.  
  204.        menuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);
  205.  
  206.        // add $partname$ Help item to the HELP menu
  207.        mi->id = k$partname$HelpMenu;
  208.        #if (defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_))
  209.        mi->afAttribute=0;           // use default attributes
  210.        #endif
  211.        menuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);
  212.        #if defined(__IBMCPP__) || defined(_IBMR2)
  213.        menuText=catgets(msgCatalog, FIRST_MSG_SET, $filename:toupper$_MSG_HELPMENU, $filename:toupper$_DEFMSG_HELPMENU);
  214.        #else
  215.        strcpy (menuText, $filename:toupper$_DEFMSG_HELPMENU);
  216.        #endif
  217.        menuBar->SetMenuItemText(ev, IDMS_HELP, mi->id, menuText);
  218.  
  219.        // add $partname$ Information item to the HELP menu
  220.        mi->id = k$partname$InfoMenu;
  221.        #if (defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_))
  222.        mi->afAttribute=0;           // use default attributes
  223.        #endif
  224.        menuBar->AddMenuItemLast(ev, IDMS_HELP, kODNULL, mi);
  225.        #if defined(__IBMCPP__) || defined(_IBMR2)
  226.        menuText=catgets(msgCatalog, FIRST_MSG_SET, $filename:toupper$_MSG_INFOMENU, $filename:toupper$_DEFMSG_INFOMENU);
  227.        #else
  228.        strcpy (menuText, $filename:toupper$_DEFMSG_INFOMENU);
  229.        #endif
  230.        menuBar->SetMenuItemText(ev, IDMS_HELP, mi->id, menuText);
  231.  
  232.        // we can now release the MenuBar
  233.        menuBar->Release(ev);
  234.  
  235.        delete mi;                        // cleanup menuitem buffer
  236.  
  237.        #if defined(__IBMCPP__) || defined(_IBMR2)
  238.        catclose(msgCatalog);             // close the message catalog
  239.        #endif
  240.     }  // if menubar
  241.  
  242.     }
  243.     catch(...)
  244.     {
  245.     }
  246. }
  247.  
  248.  
  249. SOM_Scope void  SOMLINK InitPartFromStorage($partname$ *somSelf, Environment *ev,
  250.                                             ODStorageUnit* storageUnit, ODPart *partWrapper)
  251. {
  252.     $partname$Data *somThis = $partname$GetData(somSelf);
  253.     $partname$MethodDebug(kPartHandlerName,"InitPartFromStorage");
  254.  
  255.     $partname$_parent_$parentname$_InitPartFromStorage(somSelf, ev, storageUnit, partWrapper);
  256. }
  257.  
  258. SOM_Scope void  SOMLINK DrawFrame($partname$ *somSelf,
  259.                                             Environment *ev,
  260.                                             ODFacet* facet,
  261.                                             ODShape* invalidShape)
  262. {
  263.     $partname$Data *somThis = $partname$GetData(somSelf);
  264.     $partname$MethodDebug(kPartHandlerName,"DrawFrame");
  265.  
  266.     ODRect frameODRect;
  267.     TempODShape usedShape = facet->GetFrame(ev)->AcquireUsedShape(ev,kODNULL);
  268.     usedShape->GetBoundingBox(ev, &frameODRect);
  269.     HDraw hDraw;
  270.  
  271.     CFocus f(facet, invalidShape, &hDraw);     // Set up drawing environment
  272. #if defined(_PLATFORM_OS2_)||defined(_PLATFORM_WIN32_)
  273.  
  274.     Rect frameRect;
  275. #endif
  276. #ifdef _PLATFORM_OS2_
  277.     HAB hab = WinInitialize(0);
  278.     WinSetRect(hab,&frameRect, FixedToInt(frameODRect.left),
  279.                                FixedToInt(frameODRect.bottom),
  280.                                FixedToInt(frameODRect.right),
  281.                                FixedToInt(frameODRect.top));
  282.     Point orig = {0, 0};
  283.     Point pt = {frameRect.xRight, frameRect.yTop};
  284.     GpiSetColor(hDraw, CLR_BLUE);                 // Set the drawing color
  285.     GpiMove(hDraw, &orig);                        // Set the origin from which to draw
  286.     GpiBox(hDraw, DRO_FILL, &pt, 0, 0);           // Draw a color filled rectangle
  287.  
  288. #elif defined(_PLATFORM_WIN32_)
  289.     SetRect(&frameRect, FixedToInt(frameODRect.left),
  290.                         FixedToInt(frameODRect.top),
  291.                         FixedToInt(frameODRect.right),
  292.                         FixedToInt(frameODRect.bottom));
  293.  
  294.     HBRUSH hbr = CreateSolidBrush (RGB(0,0,255)); // Create a solid brush
  295.     FillRect (hDraw, &frameRect, hbr);            // Fill the rectangle with the brush
  296.     DeleteObject (hbr);                           // Delete the brush
  297.  
  298. #elif defined(_PLATFORM_UNIX_)
  299.  
  300.     // Get the AIX Window canvas
  301.     ODAIXWindowCanvas *aixwincanvas = (ODAIXWindowCanvas *) (facet->GetCanvas(ev)->GetPlatformCanvas(ev, kODAIX));
  302.  
  303.     // Get the canvas widget
  304.     Widget widget = aixwincanvas->GetWidget(ev);
  305.  
  306.     // Get the canvas window
  307.     Window window = aixwincanvas->GetWindow(ev);
  308.  
  309.     // Get the canvas display
  310.     Display *display = aixwincanvas->GetDisplay(ev);
  311.  
  312.     // Get the widget's dimensions
  313.     Position x, y;
  314.     Dimension width, height;
  315.  
  316.     // Use the following code when DrawThumbnail is implemented.
  317.     // Set the width and height according to the widget size.
  318.     // XtVaGetValues(widget,
  319.     //              XmNwidth, &width,
  320.     //              XmNheight, &height,
  321.     //              NULL);
  322.  
  323.     // Use the following code if DrawThumbnail calls DrawFrame.
  324.     // Set the width and height according to the used shape.
  325.     ODFixed xscale, yscale;
  326.     Get72DPIToScreenScale( _fSession, &xscale, &yscale);
  327.     width = FixedToInt((ODFixedMultiply(xscale,
  328.                                       (frameODRect.right - frameODRect.left))));
  329.     height = FixedToInt((ODFixedMultiply(yscale,
  330.                                       (frameODRect.bottom - frameODRect.top))));
  331.  
  332.     x = 0;
  333.     y = 0;
  334.  
  335.     // Ensure the fill style is solid
  336.     XSetFillStyle(display, hDraw, FillSolid);
  337.  
  338.     // Get the screen
  339.     Screen *screen = _fSession->GetWindowState(ev)->GetScreen(ev);
  340.  
  341.     // Get the default colormap for the screen
  342.     Colormap map = XDefaultColormapOfScreen(screen);
  343.  
  344.     XColor def, def2;
  345.  
  346.     Status stat;
  347.  
  348.     // Color is dark purple
  349.     stat = XAllocNamedColor(display, map, "purple" , &def, &def2);
  350.  
  351.     // Set foreground color
  352.     XSetForeground(display, hDraw, def.pixel);
  353.  
  354.     // Fill the rectangle
  355.     XFillRectangle(display,
  356.                    window,
  357.                    hDraw,
  358.                    x, y,
  359.                    width, height);
  360. #endif
  361. }
  362.  
  363. SOM_Scope ODBoolean  SOMLINK HandleMenuEvent($partname$ *somSelf,
  364.                                               Environment *ev,
  365.                                               ODFrame* focusFrame,
  366.                                               ODEventData* event)
  367. {
  368.     $partname$Data *somThis = $partname$GetData(somSelf);
  369.     $partname$MethodDebug(kDebugName,"HandleMenuEvent");
  370.  
  371.     ODBoolean handled = kODFalse;
  372.  
  373.     try
  374.     {
  375.  
  376. #ifdef _PLATFORM_WIN32_
  377.     ODCommandID command = event->wParam;
  378. #elif defined(_PLATFORM_OS2_)
  379.     ODCommandID command = LONGFROMMP(event->mp1);
  380. #elif defined(_PLATFORM_UNIX_)
  381.     ODMenuItemID command = ((ODMenuEventData *)event)->item;
  382. #endif
  383.  
  384.       switch (command)
  385.       {
  386.          case VIEW_PROPERTIES:
  387.             {
  388.               ODFrameFacetIterator* facets = focusFrame->CreateFacetIterator(ev);
  389.               _fSession->GetInfo(ev)->ShowPartFrameInfo(ev,facets->First(ev), kODFalse);
  390.               delete facets;
  391.               handled = kODTrue;
  392.             }
  393.             break;
  394.          case VIEW_SASMALLICON:
  395.             focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsSmallIcon));
  396.             somSelf->ViewTypeChanged(ev, focusFrame);
  397.             break;
  398.          case VIEW_SALARGEICON:
  399.             focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsLargeIcon));
  400.             somSelf->ViewTypeChanged(ev, focusFrame);
  401.             break;
  402.          case VIEW_SATHUMBNAIL:
  403.             focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsThumbnail));
  404.             somSelf->ViewTypeChanged(ev, focusFrame);
  405.             break;
  406.          case VIEW_SAFRAME:
  407.             focusFrame->SetViewType(ev, _fSession->Tokenize(ev,kODViewAsFrame));
  408.             somSelf->ViewTypeChanged(ev, focusFrame);
  409.             break;
  410.          case VIEW_OAWINDOW:
  411.          case kODCommandViewAsWin:
  412.             {
  413.               somSelf->Open(ev, focusFrame);
  414.               handled = kODTrue;
  415.             }
  416.             break;
  417.          case kSimplePartHelpMenu:         // Using parent class $parentname$ menu constants
  418.             {
  419.                ODHelp *help = _fSession->GetHelp(ev);
  420.                help->DisplayHelp(ev, $filename:toupper$_HELP_FILE, $filename:toupper$_HELP_PANEL);
  421.                handled = kODTrue;
  422.             }
  423.             break;
  424.          case kSimplePartInfoMenu:         // Using parent class $parentname$ menu constants
  425.             {
  426.  
  427.                somSelf->DisplayInfoDialog(ev,
  428.                                           $filename:toupper$_MSG_CATALOG,
  429.                                           FIRST_MSG_SET,
  430.                                           $filename:toupper$_MSG_INFOTITLE,
  431.                                           $filename:toupper$_DEFMSG_INFOTITLE,
  432.                                           $filename:toupper$_MSG_INFO,
  433.                                           $filename:toupper$_DEFMSG_INFO);
  434.                handled = kODTrue;
  435.             }
  436.             break;
  437.          default:
  438.             break;
  439.       }
  440.     }
  441.     catch(...)
  442.     {
  443.     }
  444.  
  445.     return handled;
  446.  
  447. }
  448.  
  449.  
  450. // metaclass methods
  451.  
  452. SOM_Scope ISOString  SOMLINK clsGetODPartHandlerName(M_$partname$ *somSelf,
  453.                                                      Environment *ev)
  454. {
  455.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  456.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerName");
  457.  
  458.     ISOString handlerName = (ISOString) SOMMalloc (strlen (kPartHandlerName) + 1);
  459.     strcpy (handlerName, kPartHandlerName);
  460.     return (handlerName);
  461. }
  462.  
  463. SOM_Scope string  SOMLINK clsGetODPartHandlerDisplayName(M_$partname$ *somSelf,
  464.                                                          Environment *ev)
  465. {
  466.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  467.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartHandlerDisplayName");
  468.  
  469.     string displayName = (string) SOMMalloc (strlen (kDisplayName) + 1);
  470.     strcpy (displayName, kDisplayName);
  471.     return (displayName);
  472. }
  473.  
  474. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK clsGetODPartKinds(M_$partname$ *somSelf,
  475.                                                                              Environment *ev)
  476. {
  477.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  478.     M_$partname$MethodDebug(kDebugNameM,"clsGetODPartKinds");
  479.  
  480.     _IDL_SEQUENCE_PartKindInfo kindInfo;
  481.  
  482.     // Create structure PartKindInfo  and allocate memory for variable
  483.     PartKindInfo *info        = (PartKindInfo *) SOMMalloc (sizeof (PartKindInfo));
  484.     info->partKindName        = (ISOString)      SOMMalloc (strlen (kKind)                + 1);
  485.     info->partKindDisplayName = (string)         SOMMalloc (strlen (kKindDisplayName)     + 1);
  486.     info->filenameFilters     = (string)         SOMMalloc (strlen ("")                   + 1);
  487.     info->filenameTypes       = (string)         SOMMalloc (strlen ("")                   + 1);
  488.     info->categories          = (string)         SOMMalloc (strlen (kCategory)            + 1);
  489.     info->categoryDisplayName = (string)         SOMMalloc (strlen (kCategoryDisplayName) + 1);
  490.     info->objectID            = (string)         SOMMalloc (strlen ("")                   + 1);
  491.  
  492.     // Copy the information into the structure
  493.     strcpy (info->partKindName,        kKind);
  494.     strcpy (info->partKindDisplayName, kKindDisplayName);
  495.     strcpy (info->filenameFilters,     "");
  496.     strcpy (info->filenameTypes,       "");
  497.     strcpy (info->categories,          kCategory);
  498.     strcpy (info->categoryDisplayName, kCategoryDisplayName);
  499.     strcpy (info->objectID,            "");
  500.  
  501.     kindInfo._maximum = 1;
  502.     kindInfo._length  = 1;
  503.     kindInfo._buffer  = info;
  504.  
  505.     return (kindInfo);
  506. }
  507.  
  508. SOM_Scope string  SOMLINK clsGetOLE2ClassId(M_$partname$ *somSelf,
  509.                                                          Environment *ev)
  510. {
  511.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  512.     M_$partname$MethodDebug(kDebugNameM,"clsGetOLE2ClassId");
  513.  
  514.     string classID = (string) SOMMalloc (1);
  515.     classID[0]     = '\0';
  516.     return (classID);
  517. }
  518.  
  519. SOM_Scope string  SOMLINK clsGetWindowsIconFileName(M_$partname$ *somSelf,
  520.                                                                  Environment *ev)
  521. {
  522.     /* M_$partname$Data *somThis = M_$partname$GetData(somSelf); */
  523.     M_$partname$MethodDebug(kDebugNameM,"clsGetWindowsIconFileName");
  524.  
  525.     string fileName = (string) SOMMalloc (1);
  526.     fileName[0]     = '\0';
  527.     return (fileName);
  528. }
  529.  
  530.  
  531. #ifdef __IBMC___
  532.   #pragma linkage (SOMInitModule, system)
  533. #endif
  534.  
  535. SOMEXTERN void SOMLINK SOMInitModule (long majorVersion, long minorVersion,
  536.                                  string className)
  537. {
  538.    $partname$NewClass ($partname$_MajorVersion, $partname$_MinorVersion);
  539. }
  540.