home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / text / iodtext.cpp < prev    next >
Text File  |  1997-04-02  |  46KB  |  1,337 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odtextpart
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.38 com/src/samples/text/iodtext.cpp, odtextpart, od96os2, odos29712d 3/7/97 13:03:11 [3/21/97 17:45:33]
  28. /*
  29.  *  This file was generated by the SOM Compiler and Emitter Framework.
  30.  *  Generated using:
  31.  *      SOM Emitter emitxtm.dll: Development
  32.  */
  33.  
  34. #ifndef SOM_Module_textpart_Source
  35. #define SOM_Module_textpart_Source
  36. #endif
  37.  
  38. #define TextPart_Class_Source
  39. #define M_TextPart_Class_Source
  40.  
  41. // Define VARIABLE_MACROS to use shorthand form _variablename for our
  42. // instance variables.
  43. #define VARIABLE_MACROS
  44.  
  45. #ifndef SOM_ODArbitrator_xh
  46. #include <Arbitrat.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODCanvas_xh
  50. #include <Canvas.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODDraft_xh
  54. #include <Draft.xh>
  55. #endif
  56.  
  57. #ifndef SOM_ODEmbeddedFramesIterator_xh
  58. #include <EmbFrItr.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODFacet_xh
  62. #include <Facet.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODFrameFacetIterator_xh
  66. #include <FrFaItr.xh>
  67. #endif
  68.  
  69. #ifndef SOM_Module_Foci_OpenDoc_Foci_defined
  70. #include <Foci.xh>
  71. #endif
  72.  
  73. #ifndef SOM_ODFrame_xh
  74. #include <Frame.xh>
  75. #endif
  76.  
  77. #ifndef SOM_ODMenubar_xh
  78. #include <MenuBar.xh>
  79. #endif
  80.  
  81. #ifndef SOM_ODSession_xh
  82. #include <ODSessn.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODShape_xh
  86. #include <Shape.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODStorageUnit_xh
  90. #include <StorageU.xh>
  91. #endif
  92.  
  93. #ifndef SOM_ODTransform_xh
  94. #include <Trnsform.xh>
  95. #endif
  96.  
  97. #ifndef SOM_ODWindow_xh
  98. #include <Window.xh>
  99. #endif
  100.  
  101. #ifndef SOM_ODWindowState_xh
  102. #include <WinStat.xh>
  103. #endif
  104.  
  105. #ifndef SOM_Module_xh5cStdTypes_OpenDoc_StdTypes_defined
  106. #include <StdTypes.xh>
  107. #endif
  108.  
  109. #include <StdProps.xh>
  110.  
  111. #ifndef _ODTYPESM_
  112. #include <ODTypesM.xh>
  113. #endif
  114.  
  115. #ifndef _ODMATH_
  116. #include <odmath.h>
  117. #endif
  118.  
  119. #if defined(_PLATFORM_WIN32_)
  120.  
  121. #ifndef SOM_ODWin32Canvas_xh
  122. #include <WinPCanv.xh>
  123. #endif
  124.  
  125. #endif // defined win32
  126.  
  127.  
  128. #if defined(_PLATFORM_OS2_)
  129.  
  130. #ifndef SOM_ODOS2Canvas_xh
  131. #include <OS2PCanv.xh>
  132. #endif
  133.  
  134. #endif // defined OS2
  135.  
  136. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  137. #ifndef SOM_ODScrollExtension_xh
  138. #include <IODScrol.hpp>
  139. #include <IODScrol.xh>
  140. #endif
  141. #endif
  142.  
  143. #include "iodtext.h"
  144. #include "iodtext.xih"
  145.  
  146. // HELPER FUNCTIONS
  147. inline void InitPropVal (Environment *ev, ODStorageUnit *su,
  148.                          ODPropertyName propName, ODValueType valName)
  149. {
  150.     if (ODSUExistsThenFocus (ev, su, propName, valName))
  151.          su->Remove (ev);
  152.  
  153.     ODSUAddPropValue (ev, su, propName, valName);
  154.  
  155. }
  156.  
  157.  
  158. void WinPt2FramePt (Environment *ev, ODEventData *event, ODEventInfo *eventinfo,
  159.                                ODPoint *cursorLocation, ODFacet *facet)
  160. {
  161.  
  162.       TempODTransform xform = facet->AcquireWindowContentTransform(ev, kODNULL);
  163.       cursorLocation->x = eventinfo->where.x;
  164.       cursorLocation->y = eventinfo->where.y;
  165.  
  166. #ifdef ODDebug
  167.       PRINT ("MouseClick before transform: (%d,%d).\n", cursorLocation->x, cursorLocation->y);
  168.       PRINT ("MouseClick convert to integer: (%d,%d).\n", FixedToInt(cursorLocation->x), FixedToInt(cursorLocation->y));
  169. #endif
  170.       xform->InvertPoint (ev, cursorLocation);
  171. #ifdef ODDebug
  172.       PRINT ("MouseClick inverse of WindowContentTransform: (%d,%d).\n", cursorLocation->x, cursorLocation->y);
  173.       PRINT ("MouseClick convert to integer: (%d,%d).\n", FixedToInt(cursorLocation->x), FixedToInt(cursorLocation->y));
  174. #endif
  175. }
  176.  
  177. SOM_Scope ODBoolean  SOMLINK TextPartImportFile(TextPart *somSelf,
  178.                                                   Environment *ev,
  179.                                                   ODFrame *frame)
  180. {
  181.     TextPartData *somThis = TextPartGetData(somSelf);
  182.     TextPartMethodDebug("TextPart","TextPartImportFile");
  183. #ifdef ODDebug
  184.     PRINT ("TextPart::ImportFile invoked.\n");
  185. #endif
  186.  
  187.     ODBoolean result = kODFalse;
  188.     char docName[kODMaxFileNameSize] = "";
  189.     char* buffer = kODNULL;
  190.     int dwBytesRead = 0;
  191.  
  192.   try {
  193.     ODWindowState* WinStat =  _fSession->GetWindowState(ev);
  194.  
  195.     // Get our window handle, which will own the Import File Dialog
  196.     // Use TempODWindow so this object won't have to be released.
  197. #if defined(_PLATFORM_WIN32_)
  198.     TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  199. #elif defined(_PLATFORM_OS2_)
  200.     TempODWindow Window = WinStat->AcquireFrontRootWindow(ev);
  201. #endif
  202.     ODPlatformWindow hwnd = Window->GetPlatformWindow(ev);
  203.  
  204.     // Obtain the file name to import from the Import File Dialog
  205.     if (PlatImportDlg(hwnd,docName))
  206.       if (PlatReadFile(docName,buffer,dwBytesRead))
  207.       {
  208.          if (dwBytesRead > 0) {
  209.             _fTextMgr->AddText(buffer, dwBytesRead);
  210.             somSelf->ChangeNotification(ev, TP_TEXTCHANGED, frame,
  211.                                         kODNULL, kODTrue, kODNULL);
  212.          }
  213.          result = kODTrue;
  214.       }
  215.  
  216.     } catch(...) {
  217.     }
  218.       return result;
  219. }
  220.  
  221. SOM_Scope ODBoolean  SOMLINK TextPartExportFile(TextPart *somSelf,
  222.                                                   Environment *ev)
  223. {
  224.     TextPartData *somThis = TextPartGetData(somSelf);
  225.     TextPartMethodDebug("TextPart","TextPartExportFile");
  226. #ifdef ODDebug
  227.     PRINT ("TextPart::ExportFile invoked.\n");
  228. #endif
  229.  
  230.     ODBoolean result = kODFalse;
  231.     char docName[kODMaxFileNameSize] = "";
  232.     char* buffer = kODNULL;
  233.     int bufferSize = 0;
  234.  
  235.   try {
  236.     // Get our window handle, which will own the Export File Dialog
  237.     // Use TempODWindow so this object won't have to be released.
  238.     ODWindowState* WinStat =  _fSession->GetWindowState(ev);
  239. #if defined(_PLATFORM_WIN32_)
  240.     TempODWindow Window = WinStat->AcquireActiveWindow(ev);
  241. #elif defined(_PLATFORM_OS2_)
  242.     TempODWindow Window = WinStat->AcquireFrontRootWindow(ev);
  243. #endif
  244.     ODPlatformWindow hwnd = Window->GetPlatformWindow(ev);
  245.  
  246.     // Export all of TextPart's intrinsic content.
  247.     bufferSize = _fTextMgr->GetText(&buffer);
  248.  
  249.     // Obtain the file name to save to from the Export File Dialog
  250.     if (PlatExportDlg(hwnd,docName))
  251.       if (PlatWriteFile(docName,buffer,bufferSize))
  252.          result = kODTrue;
  253.  
  254.   } catch(...) {}
  255.  
  256.     if (buffer != kODNULL) delete buffer;
  257.  
  258.     return result;
  259. }
  260.  
  261. SOM_Scope ODShape* SOMLINK TextPartAcquireEmbeddedClipShape(TextPart *somSelf,
  262.                                                   Environment *ev,
  263.                                                   ODFacet* facet)
  264. {
  265.     TextPartData *somThis = TextPartGetData(somSelf);
  266.     TextPartMethodDebug("TextPart","TextPartAcquireEmbeddedClipShape");
  267. #ifdef ODDebug
  268.     PRINT ("TextPart::AcquireEmbeddedClipShape invoked.\n");
  269. #endif
  270.  
  271.     ODShape* embedShape;
  272.     ODTransform* embedTransform;
  273.  
  274.   try {
  275.     ODShape* clipShape = facet->CreateShape(ev);
  276.  
  277.     // Iterate through the embedded objects
  278.     ALinkedList* objList = somSelf->GetEmbeddedObjects(ev);
  279.     ContentObject *theObj = kODNULL;
  280.     ALink *link;
  281.     for(link = objList->First(ev);
  282.         (theObj = (ContentObject*) link->Content(ev)) != kODNULL ;
  283.         link = link->Next(ev)) {
  284.  
  285.        // For each embedded frame, subtract its usedshape in the
  286.        // containing frame coordinates.
  287.        if (theObj->_get_objType(ev) == COBJ_FRAMECLASS) {
  288.           ODFrame* embed = ((ContentFrame*) theObj)->_get_myFrame(ev);
  289.           embedShape = ODCopyAndRelease(ev, embed->AcquireUsedShape(ev,kODNULL));
  290.  
  291.           ODFrameFacetIterator* facetIter = embed->CreateFacetIterator(ev);
  292.           embedTransform = ODCopyAndRelease(ev, facetIter->First(ev)->AcquireExternalTransform(ev,kODNULL));
  293.           embedShape->Transform(ev,embedTransform);
  294.           ODDeleteObject(facetIter);
  295.        } /* end if */
  296.        else {
  297.           embedShape = facet->CreateShape(ev);
  298.           ODRect boundingRect = theObj->_get_boundingRect(ev);
  299.           embedShape->SetRectangle(ev, &boundingRect);
  300.        } /* end else */
  301.  
  302.        clipShape->Union(ev,embedShape);
  303.        embedShape->Release(ev);
  304.     } /* endfor */
  305.  
  306.     return clipShape;
  307.  
  308.   } catch(...) {
  309.      return kODNULL;
  310.   }
  311. }
  312.  
  313. // Get the correctly transformed used shape from the given facet
  314. SOM_Scope void  SOMLINK TextPartGetFacetBoundingRect(TextPart *somSelf, Environment *ev,
  315.                                 ODFacet *facet, ODRect *clipRect)
  316. {
  317.     TextPartData *somThis = TextPartGetData(somSelf);
  318.     TextPartMethodDebug("TextPart","TextPartGetFacetBoundingRect");
  319. #ifdef ODDebug
  320. //  PRINT ("TextPart::GetFacetBoundingRect invoked.\n");
  321. #endif
  322.  
  323. try {
  324.     ODFrame* displayFrame = facet->GetFrame(ev);
  325.     TempODShape drawShape = displayFrame->AcquireUsedShape(ev, kODNULL);
  326.  
  327.     // Make sure we are drawing the portion of our content that is currently
  328.     // scrolled into view (AcquireFrameShape returns shape in frame coordinates-
  329.     // transform that into our content coordinates).
  330.     if (_fScrollExt) {
  331.        TempODTransform internalXform = displayFrame->AcquireInternalTransform(ev,kODNULL);
  332.        drawShape->InverseTransform(ev, internalXform);
  333.     } /* endif */
  334.  
  335.     // Get the bounding box of our used shape.  This is the area we will
  336.     // draw in.
  337.     drawShape->GetBoundingBox(ev, clipRect);
  338.  
  339. } catch(...) {}
  340. }
  341.  
  342. SOM_Scope void  SOMLINK TextPartsomInit(TextPart *somSelf)
  343. {
  344.     TextPartData *somThis = TextPartGetData(somSelf);
  345.     TextPartMethodDebug("TextPart","TextPartsomInit");
  346. #ifdef ODDebug
  347.     PRINT ("TextPart::somInit invoked.\n");
  348. #endif
  349.  
  350.     TextPart_parent_BaseContainer_somInit(somSelf);
  351.     _fMenuBar = kODNULL;
  352.     _fSession = kODNULL;
  353.     _fKeyFocus = kODNULL;
  354.     _fPartWrapper = kODNULL;
  355.     _fDraftReadOnly = kODFalse;
  356.     _fScrollExt = kODNULL;
  357.     _fTextMgr = kODNULL;
  358. }
  359.  
  360. SOM_Scope void  SOMLINK TextPartsomUninit(TextPart *somSelf)
  361. {
  362.     TextPartData *somThis = TextPartGetData(somSelf);
  363.     TextPartMethodDebug("TextPart","TextPartsomUninit");
  364. #ifdef ODDebug
  365.     PRINT ("TextPart::somUninit invoked.\n");
  366. #endif
  367.  
  368.     TextPart_parent_BaseContainer_somUninit(somSelf);
  369.     delete _fTextMgr;
  370.  
  371. }
  372.  
  373. //--------------------------------------------------------------------------
  374. // ReleaseAll
  375. //
  376. // This method is called prior to the object destructor being invoked.
  377. // It must release all references to other objects.  If we are the Factory
  378. // for the object we should also ensure the object is properly deleted
  379. //--------------------------------------------------------------------------
  380.  
  381. SOM_Scope       void
  382. SOMLINK         TextPartReleaseAll
  383.                 (
  384.                 TextPart        *somSelf,       // in
  385.                 Environment     *ev             // in
  386.                 )
  387. {
  388.     TextPartData *somThis = TextPartGetData(somSelf);
  389.     TextPartMethodDebug("TextPart","TextPartReleaseAll");
  390.  
  391.     //--------------------------------------------------------------------
  392.     // Release the extension we acquired in the initialize routine.
  393.     // Put it in a try/catch block in case of failure, but ignore the
  394.     // error since we're leaving.
  395.     //--------------------------------------------------------------------
  396.     if (_fScrollExt) {
  397.        try {
  398.          _fScrollExt->Release(ev);
  399.          _fScrollExt = kODNULL ;
  400.        }
  401.        catch (ODException _exception) {
  402.           PRINT("SOM exception occurred in TextPart::ReleaseAll\n");
  403.           // Clear the exception, in case we got one
  404.           SetErrorCodeEv(ev, kODNoError);
  405.        }
  406.     }
  407.  
  408.     TextPart_parent_BaseContainer_ReleaseAll(somSelf, ev);
  409.  
  410. }
  411.  
  412.  
  413. SOM_Scope void  SOMLINK TextPartInitialize(TextPart *somSelf,
  414.                                            Environment *ev,
  415.                                            ODPart *partWrapper)
  416. {
  417.     TextPartData *somThis = TextPartGetData(somSelf);
  418.     TextPartMethodDebug("TextPart","TextPartInitialize");
  419. #ifdef ODDebug
  420.     PRINT ("TextPart::Initialize invoked.\n");
  421. #endif
  422.  
  423. try {
  424.  
  425.     TextPart_parent_BaseContainer_Initialize(somSelf, ev, partWrapper);
  426.  
  427.     // Enable scrolling, so that if our text falls outside the frame shape
  428.     // scroll bars will appear.
  429.     if ( somSelf->HasExtension(ev, kODScrollExtension)) {
  430.       _fScrollExt = somSelf->AcquireExtension(ev, kODScrollExtension);
  431.       somSelf->EnableScrolling(ev, kODTrue, 0, 0);
  432.     }
  433.  
  434.     // Create our TextMgr to format the text content.
  435.     _fTextMgr = new TextMgr(somSelf);
  436.  
  437.     // Cache references to Session object and other global values
  438.     _fSession    =   somSelf->GetStorageUnit(ev)->GetSession(ev);
  439.     _fKeyFocus = _fSession->Tokenize(ev, kODKeyFocus);
  440.     _fPartWrapper = partWrapper;
  441.     _fMenuBar = somSelf->GetMenuBar(ev);
  442.     _fDraftReadOnly = (somSelf->GetStorageUnit(ev)->
  443.                        GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly);
  444.  
  445.     // Set the original background color to white.  Base Container over-
  446.     // writes the value if it is preserved in our storage unit.
  447. #if defined(_PLATFORM_WIN32_)
  448.     somSelf->SetBackgroundColor(ev,0x00FFFFFF);
  449. #elif defined(_PLATFORM_OS2_)
  450.     somSelf->SetBackgroundColor(ev,CLR_WHITE);
  451. #endif
  452.  
  453.     // No need to call InstallMenuItems since our parent calls it.
  454.  
  455. } catch (...) {}
  456.  
  457. }
  458.  
  459. SOM_Scope void  SOMLINK TextPartInitPartFromStorage(TextPart *somSelf,
  460.                                            Environment       *ev,
  461.                                            ODStorageUnit     *fromSU,
  462.                                            ODPart            *partWrapper)
  463. {
  464.     TextPartData *somThis = TextPartGetData(somSelf);
  465.     TextPartMethodDebug("TextPart","TextPartInitPartFromStorage");
  466. #ifdef ODDebug
  467.     PRINT ("TextPart::InitPartFromStorage invoked.\n");
  468. #endif
  469.  
  470.     TextPart_parent_BaseContainer_InitPartFromStorage(somSelf, ev,
  471.                                                       fromSU,
  472.                                                       partWrapper);
  473. try {
  474.     // No need to call Initialize since our parent calls it.
  475.  
  476.     // Read in the text and send it to the Text Manager to read.
  477.     // This is only done only when part comes up.  Do it before the facet
  478.     // is added so we can know whether to display the scrollbars.
  479.     char* itextBuff = kODNULL;
  480.     ODULong itextBuffSize;
  481.     ODIText* iBuffer = new ODIText;
  482.  
  483. //    if (ODGetITextProp(ev, fromSU,
  484. //                           kODPropTextContents, kODIntlText, iBuffer))
  485. //    {
  486. //       itextBuff = GetITextPtr(iBuffer);
  487. //       itextBuffSize = GetITextStringLength(iBuffer);
  488.        // _fTextMgr->AddText(itextBuff, itextBuffSize);
  489. //       delete itextBuff;
  490. //    }
  491.  
  492.     char* buffer = kODNULL;
  493.     ODULong bufferSize;
  494.  
  495.     if (ODSUExistsThenFocus (ev, fromSU, kODPropTextContents, kTypeAscii))
  496.        {
  497.          StorageUnitGetValue (fromSU, ev, sizeof (bufferSize),
  498.                               (ODValue) &bufferSize);
  499.          if (bufferSize != 0)
  500.          {
  501.              buffer = new char[bufferSize];
  502.              if (buffer != kODNULL)
  503.              {
  504.                 StorageUnitGetValue (fromSU, ev, bufferSize,
  505.                                      (ODValue) buffer );
  506.                 _fTextMgr->AddText(buffer, bufferSize);
  507.                 delete buffer;
  508.              }
  509.          }
  510.        }
  511.  
  512. } catch (...) {}
  513. }
  514.  
  515. SOM_Scope ODBoolean  SOMLINK TextPartDrawContents(TextPart *somSelf,  Environment *ev,
  516.                                      ODFacet* facet, ODShape* invalidShape)
  517. {
  518.     TextPartData *somThis = TextPartGetData(somSelf);
  519.     TextPartMethodDebug("TextPart","TextPartDrawContents");
  520.  
  521.     ODBoolean result = kODFalse;
  522.  
  523. try {
  524.     result = TextPart_parent_BaseContainer_DrawContents(somSelf, ev,
  525.                                                  facet,
  526.                                                  invalidShape);
  527.  
  528.      // Figure out if we are printing
  529.       int printing = kODFalse;
  530. #ifdef _PLATFORM_OS2_
  531.      if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODPM)) {
  532. #elif defined(_PLATFORM_WIN32_)
  533.      if (facet->GetCanvas(ev)->HasPlatformPrintJob(ev,kODWin32)) {
  534. #endif
  535.         printing = kODTrue;
  536.      } /* endif */
  537.  
  538.       // Get the rectangle within which the text should be drawn.
  539.       ODRect rect;
  540.       somSelf->GetFacetBoundingRect(ev,facet,&rect);
  541.  
  542. //    // Subtract the clipShape from our drawing shape so we don't draw over
  543. //    // embedded shapes.
  544. //    ODShape* clipShape = somSelf->AcquireEmbeddedClipShape(ev, facet);
  545. //    if (clipShape == kODNULL)
  546. //      return kODFalse;
  547. //    drawShape->Subtract(ev,clipShape);
  548. //    clipShape->Release(ev);
  549.  
  550. #ifdef _PLATFORM_OS2_
  551. //    Comment out until we figure out why the region is being cut off
  552. //    at the top and right.
  553. //    HRGN hrgnClip = drawShape->GetRegion(ev);
  554. //    GpiSetClipRegion(hdc, hrgnClip, NULL);
  555. #endif
  556.  
  557.      // Create the drawing area and apply the content transforms
  558.      HDC hdc;
  559.      CFocus focus(facet, invalidShape, &hdc);
  560.  
  561.      // Set up our font attributes and draw the text for this hdc
  562.      _fTextMgr->SetFont(hdc,printing);
  563.      _fTextMgr->DrawText(hdc,rect);
  564.  
  565.      // Display the cursor if this facet corresponds to a window
  566.      if (!printing)
  567.      {
  568.        _fTextMgr->DisplayCursor(facet,rect);
  569.      } /* endif */
  570.  
  571.      result = kODTrue;
  572. } catch (...) {}
  573.  
  574.     return result;
  575. }
  576.  
  577. SOM_Scope       void SOMLINK TextPartReadContents(TextPart *somSelf,
  578.                 Environment     *ev,            // in
  579.                 ODStorageUnit   *fromSU,        // in
  580.                 BCCloneInfo     *cloneInfo,
  581.                 BCTransferKind  readKind
  582.                 )
  583.  
  584. {
  585.     TextPartData *somThis = TextPartGetData(somSelf);
  586.     TextPartMethodDebug("TextPart","TextPartReadContents");
  587. #ifdef ODDebug
  588.     PRINT ("TextPart::ReadContents invoked.\n");
  589. #endif
  590.  
  591.     // Read in our parent's contents first
  592.     TextPart_parent_BaseContainer_ReadContents(somSelf, ev,
  593.                                                fromSU,
  594.                                                cloneInfo,
  595.                                                readKind);
  596.        // Set the scrolling dimensions so the extension can figure out when
  597.        // our text falls outside the frame shape
  598.        if (_fScrollExt) {
  599.            somSelf->SetScrollableDimensions(ev, kODNULL,
  600.                                       _fTextMgr->GetMaximumWidth(),
  601.                                       _fTextMgr->GetTotalHeight());
  602.        } /* end if _fScrollExt */
  603. }
  604.  
  605. SOM_Scope       void SOMLINK TextPartWriteContents(TextPart *somSelf,
  606.                 Environment     *ev,            // in
  607.                 ODStorageUnit   *toSU,          // in
  608.                 BCCloneInfo     *cloneInfo,
  609.                 BCTransferKind  writeKind
  610.                 )
  611.  
  612. {
  613.     TextPartData *somThis = TextPartGetData(somSelf);
  614.     TextPartMethodDebug("TextPart","TextPartWriteContents");
  615. #ifdef ODDebug
  616.     PRINT ("TextPart::WriteContents invoked.\n");
  617. #endif
  618.  
  619.     char* buffer = kODNULL;
  620.     ODULong bufferSize;
  621.  
  622. try {
  623.     // Add a default kODPropName to this part's storageUnit for the
  624.     // document properties notebook.  The notebook will maintain
  625.     // it's persistence.  Do this before we call our parent so we
  626.     // will have our own default name.
  627.     if (ODSUExistsThenFocus (ev, toSU, kODPropName, kODIntlText)) {
  628.        if (toSU->GetSize(ev) == 0) {
  629.           // create string to place in kODPropName property
  630.           ODIText* iTextPropName = CreateITextFromCharPtr(kTextPartPropertyName);
  631.  
  632.           // write the name into the kODPropName property
  633.           ODSetITextProp(ev, toSU, kODPropName, kODIntlText, iTextPropName);
  634.        }
  635.     }
  636.  
  637.     // Write out our parent's contents
  638.     TextPart_parent_BaseContainer_WriteContents(somSelf, ev,
  639.                                                toSU,
  640.                                                cloneInfo,
  641.                                                writeKind);
  642.  
  643.     // Write out the contents and the size
  644.     bufferSize = _fTextMgr->GetText(&buffer);
  645.     InitPropVal (ev, toSU, kODPropTextContents, kTypeAscii);
  646.     StorageUnitSetValue (toSU, ev, sizeof(bufferSize), (ODValue) &bufferSize);
  647.     StorageUnitSetValue (toSU, ev, bufferSize, (ODValue) buffer);
  648.  
  649.     // If we have text to store, also write the internationalized value
  650.     // to the storage unit
  651.     if (bufferSize != 0) {
  652.       // Specify 0 for the script code and language code
  653.       ODIText* iBuffer = CreateITextWLen(0, 0, (ODUByte*) buffer, bufferSize );
  654.       ODSetITextProp(ev, toSU, kODPropTextContents, kODIntlText, iBuffer);
  655.     } /* endif */
  656.  
  657. } catch(...) {}
  658.  
  659.     if (buffer != kODNULL) delete buffer;
  660. }
  661.  
  662. SOM_Scope       void SOMLINK TextPartWriteKindInfo(TextPart *somSelf,
  663.                              Environment     *ev,
  664.                              ODStorageUnit   *toSU )
  665. {
  666.  
  667.     TextPartData *somThis = TextPartGetData(somSelf);
  668.     TextPartMethodDebug("TextPart","TextPartWriteKindInfo");
  669. #ifdef ODDebug
  670.     PRINT ("TextPart::WriteKindInfo invoked.\n");
  671. #endif
  672.  
  673.     try
  674.      {
  675.         // write the part kind info attribute
  676.         ODSUAddPropValue(ev, toSU, kODPropContents, kODKindTextPart);
  677.         InitPropVal (ev, toSU, kODPropPreferredKind, kODKindTextPart);
  678.      }
  679.     catch(...) {}
  680.  
  681. }   // WriteKindInfo()
  682.  
  683. SOM_Scope       void
  684. SOMLINK         TextPartWriteIconToSU(TextPart *somSelf,
  685.                                       Environment *ev,
  686.                                       ODStorageUnit *toSU)
  687. {
  688.     TextPartData *somThis = TextPartGetData(somSelf);
  689.     TextPartMethodDebug("TextPart", "TextPartWriteIconToSU");
  690. #ifdef ODDebug
  691.     PRINT ("TextPart::WriteIconToSU invoked.\n");
  692. #endif
  693.  
  694. #ifdef _PLATFORM_OS2_
  695. // Customized icon support for OS2.
  696.  
  697.      HMODULE hmod;
  698.      ULONG cbIconSize;
  699.      PBYTE pIconData = NULL;
  700.      CHAR Error[256] = "";
  701.  
  702.      DosLoadModule(Error, sizeof(Error), "iodtext", &hmod);
  703.  
  704.      if ( !DosQueryResourceSize( hmod, RT_POINTER, 100, &cbIconSize) &&
  705.          !DosGetResource( hmod, RT_POINTER, 100, (PPVOID)&pIconData)  )
  706.      {
  707.         InitPropVal (ev, toSU,kODPropIconFamily , kODIconFamily);
  708.         StorageUnitSetValue( toSU, ev, cbIconSize, (ODValue)pIconData );
  709.         DosFreeResource(pIconData);
  710.      }
  711.      else
  712.         PRINT("DosGetResource failed!\n");
  713.  
  714. #endif // _PLATFORM_OS2_
  715.  
  716. }
  717.  
  718. SOM_Scope ODBoolean  SOMLINK TextPartHandleEvent(TextPart *somSelf,
  719.                                                   Environment *ev,
  720.                                                  ODEventData* event,
  721.                                                  ODFrame* frame,
  722.                                                  ODFacet* facet,
  723.                                                  ODEventInfo* eventInfo)
  724. {
  725.     TextPartData *somThis = TextPartGetData(somSelf);
  726.     TextPartMethodDebug("TextPart","TextPartHandleEvent");
  727. #ifdef ODDebug
  728. //    PRINT ("TextPart::HandleEvent invoked.\n");
  729. #endif
  730.  
  731.     ODBoolean eventHandled = kODFalse;
  732.     ODBoolean scrollHandled = kODFalse;  // Scroll events can be processed twice
  733.  
  734. #if defined(_PLATFORM_WIN32_)
  735.     switch (event->message) {
  736. #elif defined(_PLATFORM_OS2_)
  737.     switch (event->msg) {
  738. #endif
  739.     case WM_SETFOCUS:
  740.           #ifdef ODDebug
  741.              PRINT("TextPart: WM_SETFOCUS received.\n");
  742.           #endif
  743.           break;
  744. #if defined(_PLATFORM_WIN32_)
  745.     case WM_KILLFOCUS:
  746.           #ifdef ODDebug
  747.              PRINT("TextPart: WM_KILLFOCUS received.\n");
  748.           #endif
  749.           break;
  750. #elif defined(_PLATFORM_OS2_)
  751.     case WM_FOCUSCHANGE:
  752.           #ifdef ODDebug
  753.               PRINT("TextPart: WM_FOCUSCHANGE received.\n");
  754.           #endif
  755.           break;
  756. #endif
  757.        // Check if we are being deactivated.
  758.     case kODEvtActivate:
  759.           #if defined(_PLATFORM_WIN32_)
  760.              if (LOWORD(event->wParam) == WA_INACTIVE) {
  761.           #elif defined(_PLATFORM_OS2_)
  762.              if (SHORT1FROMMP(event->mp1) == kODFalse) {
  763.           #endif
  764.           #ifdef ODDebug
  765. //               PRINT("TextPart: Inactivate message received.\n");
  766.           #endif
  767.                TempODFrame keyOwner = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev, _fKeyFocus);
  768.                if (keyOwner == frame) {
  769.                   HWND hwnd = facet->GetFacetHWND(ev);
  770.                   _fTextMgr->DeleteCursor(hwnd);
  771.                } /* endif */
  772.              } else {
  773.           #ifdef ODDebug
  774. //               PRINT("TextPart: Activate message received.\n");
  775.           #endif
  776.              }
  777.           break;
  778.  
  779.     // After handling the scrolling event pass it on as a key event so we
  780.     // can process the cursor if necessary.
  781.     case kODEvtKeyDown:
  782.           #ifdef ODDebug
  783.           PRINT("TextPart: kODEvtKeyDown received.\n");
  784.           #endif
  785.           scrollHandled = somSelf->HandleScrollEvent(ev, frame, event);
  786.           eventHandled = somSelf->HandleKeyEvent(ev, event, frame, facet, eventInfo);
  787.           break;
  788.     // BaseContainer only calls HandleKeyEvent for kODEvtKeyUp.
  789.     case WM_CHAR:
  790.           #ifdef ODDebug
  791.           PRINT("TextPart: WM_CHAR received.\n");
  792.           #endif
  793.           eventHandled = somSelf->HandleKeyEvent(ev, event, frame, facet, eventInfo);
  794.           break;
  795.     case kODEvtKeyUp:
  796.           #ifdef ODDebug
  797.           PRINT("TextPart: kODEvtKeyUp received.\n");
  798.           #endif
  799.           eventHandled = somSelf->HandleKeyEvent(ev, event, frame, facet, eventInfo);
  800.           break;
  801.     default:
  802.           break;
  803.     } /* endswitch */
  804.  
  805.     if (!eventHandled && !scrollHandled)
  806.        eventHandled = TextPart_parent_BaseContainer_HandleEvent(somSelf, ev,
  807.                                                                 event,
  808.                                                                 frame,
  809.                                                                 facet,
  810.                                                                 eventInfo);
  811.     return eventHandled;
  812. }
  813.  
  814. SOM_Scope void  SOMLINK TextPartInstallMenuItems(TextPart *somSelf,
  815.                                                   Environment *ev,
  816.                                                  ODMenuBar* menuBar)
  817. {
  818.     TextPartData *somThis = TextPartGetData(somSelf);
  819.     TextPartMethodDebug("TextPart","TextPartInstallMenuItems");
  820. #ifdef ODDebug
  821.     PRINT ("TextPart::InstallMenuItems invoked.\n");
  822. #endif
  823.  
  824. try {
  825.     TextPart_parent_BaseContainer_InstallMenuItems(somSelf, ev,
  826.                                                    menuBar);
  827. #if defined(__IBMCPP__) || defined(_IBMR2)
  828.     nl_catd txNLSCat;       // NLS message catalog handle
  829.     char *menuText;         // pointer for NLS message
  830.     setlocale(LC_ALL,"");
  831.  
  832.     txNLSCat=catopen(TX_NLS_CATALOG, NL_CAT_LOCALE);   // Open NLS message catalog
  833. #else
  834.     char menuText[256];
  835. #endif
  836.  
  837.     menuBar->Acquire(ev);
  838.  
  839.     ODPlatformMenuItem *mi = new ODPlatformMenuItem;
  840.  
  841.     mi->afAttribute=0;           // use default attributes
  842.  
  843.     // add a menu separator line to OPTIONS menu
  844.     mi->id=CMD(Dash);
  845.     #if defined(_PLATFORM_WIN32_)
  846.         mi->afAttribute=MF_SEPARATOR;
  847.     #elif defined(_PLATFORM_OS2_)
  848.         mi->afAttribute=CA_TITLESEPARATOR;
  849.     #endif
  850.  
  851.  
  852.     // add IMPORT menu selection to OPTIONS menu
  853.     mi->id=kODCommandImport;
  854.     menuBar->AddMenuItemLast(ev, kODOptionsMenuID, kODNULL, mi);
  855. #if defined(__IBMCPP__) || defined(_IBMR2)
  856.     menuText=catgets(txNLSCat, TP_MSG_SET, TP_MSG_IMPORT_MENU, "Import");
  857. #else
  858.     strcpy (menuText, "Import");
  859. #endif
  860.     menuBar->SetMenuItemText(ev, kODOptionsMenuID, kODCommandImport, menuText);
  861.  
  862.     // add EXPORT menu selection to OPTIONS menu
  863.     mi->id=kODCommandExport;
  864.     menuBar->AddMenuItemLast(ev, kODOptionsMenuID, kODNULL, mi);
  865. #if defined(__IBMCPP__) || defined(_IBMR2)
  866.     menuText=catgets(txNLSCat, TP_MSG_SET, TP_MSG_EXPORT_MENU, "Export");
  867. #else
  868.     strcpy (menuText, "Export");
  869. #endif
  870.     menuBar->SetMenuItemText(ev, kODOptionsMenuID, kODCommandExport, menuText);
  871.  
  872.     // we can now release the MenuBar
  873.     menuBar->Release(ev);
  874.  
  875.     delete mi;                      // cleanup menuitem buffer
  876.  
  877. #if defined(__IBMCPP__) || defined(_IBMR2)
  878.     catclose(txNLSCat);             // close the message catalog
  879. #endif
  880.  
  881. } catch(...) {}
  882.  
  883. }
  884.  
  885.  
  886. SOM_Scope ODBoolean  SOMLINK TextPartHandleMenuEvent(TextPart *somSelf,
  887.                                                  Environment *ev,
  888.                                                  ODFrame* frame,
  889.                                                  ODEventData* event)
  890. {
  891.     TextPartData *somThis = TextPartGetData(somSelf);
  892.     TextPartMethodDebug("TextPart","TextPartHandleMenuEvent");
  893. #ifdef ODDebug
  894.     PRINT ("TextPart::HandleMenuEvent invoked.\n");
  895. #endif
  896.  
  897.     ODBoolean   eventHandled     = kODFalse;
  898.     long        eventMessage;
  899.  
  900. try{
  901.  
  902. #if defined(_PLATFORM_WIN32_)
  903.     switch(LOWORD(event->wParam)) // determine which menu pulldown it was
  904. #elif defined(_PLATFORM_OS2_)
  905.     switch(LONGFROMMP(event->mp1))
  906. #endif
  907.         {
  908.          case CMD(Import):
  909.               if (somSelf->ImportFile(ev,frame)) {
  910.                  frame->Invalidate (ev, kODNULL, kODNULL);
  911.                  ODUpdateID updateID = _fSession->UniqueUpdateID(ev);
  912.                  frame->ContentUpdated (ev, updateID);
  913.               }
  914.               eventHandled=kODTrue;
  915.               break;
  916.          case CMD(Export):
  917.               somSelf->ExportFile(ev);
  918.               eventHandled=kODTrue;
  919.               break;
  920.          case CMD(Delete):
  921.               // Call parent in case we have selected content objects to delete.
  922.               TextPart_parent_BaseContainer_HandleMenuEvent(somSelf, ev, frame, event);
  923.  
  924.               // Now handle the delete key.
  925.               eventMessage = ACCEL_KEY;
  926.               _fTextMgr->ProcessKeyInput(eventMessage, kODCommandDelete);
  927.  
  928.               // Set changed flags if necessary.
  929.               if (eventMessage == TEXT_CHANGED) {
  930.                  somSelf->ChangeNotification(ev, TP_TEXTCHANGED, frame,
  931.                                              kODNULL, kODTrue, kODNULL);
  932.                  frame->Invalidate(ev,kODNULL,kODNULL);
  933.               }
  934.               eventHandled = kODTrue;
  935.               break;
  936.          default:
  937.               break;
  938.         } /* endswitch*/
  939.  
  940.     if (!eventHandled)
  941.        eventHandled = TextPart_parent_BaseContainer_HandleMenuEvent(somSelf, ev,
  942.                                                     frame, event);
  943.  
  944. } catch(...) {}
  945.  
  946.     return eventHandled;
  947. }
  948.  
  949.  
  950. SOM_Scope void  SOMLINK TextPartAdjustMenus(TextPart *somSelf,
  951.                                              Environment *ev,
  952.                                             ODFrame* frame)
  953. {
  954.     TextPartData *somThis = TextPartGetData(somSelf);
  955.     TextPartMethodDebug("TextPart","TextPartAdjustMenus");
  956. #ifdef ODDebug
  957.     PRINT ("TextPart::AdjustMenus invoked.\n");
  958. #endif
  959.  
  960. try {
  961.     TextPart_parent_BaseContainer_AdjustMenus(somSelf, ev, frame);
  962.  
  963.       // Enable menu options that change our content only for writeable drafts.
  964.       _fMenuBar->EnableMenuItem(ev, kODOptionsMenuID, CMD(Import), !_fDraftReadOnly);
  965.       _fMenuBar->EnableMenuItem(ev, kODOptionsMenuID, CMD(Export), _fTextMgr->HasText());
  966.  
  967.       // Delete key must be enabled whenever text is present.  Otherwise, use our parent's
  968.       // setting of the delete key enablement.
  969.       if (_fTextMgr->HasText())
  970.          _fMenuBar->EnableMenuItem(ev, IDMS_EDIT, CMD(Delete), !_fDraftReadOnly);
  971.  
  972. } catch(...) {}
  973.  
  974. }
  975.  
  976. SOM_Scope void  SOMLINK TextPartFacetAdded(TextPart *somSelf,
  977.                                             Environment *ev,
  978.                                             ODFacet* facet)
  979. {
  980.     TextPartData *somThis = TextPartGetData(somSelf);
  981.     TextPartMethodDebug("TextPart","TextPartFacetAdded");
  982. #ifdef ODDebug
  983.     PRINT ("TextPart::FacetAdded invoked.\n");
  984. #endif
  985.  
  986. try {
  987.       TextPart_parent_BaseContainer_FacetAdded(somSelf, ev, facet);
  988.  
  989.       ODCanvas* canvas = facet->GetCanvas(ev);
  990.  
  991.       // if this is our drawing canvas, set up the default font attributes
  992.       if (canvas->IsDynamic(ev) && !canvas->IsOffscreen(ev))
  993.       {
  994.           HWND hwnd = facet->GetFacetHWND(ev);
  995. #ifdef _PLATFORM_OS2_
  996.           HPS hdc = WinGetPS(hwnd);
  997. #elif defined(_PLATFORM_WIN32_)
  998.           HDC hdc = GetDC(hwnd);
  999. #endif
  1000.           _fTextMgr->SetFont(hdc,kODFalse);  // Set font for drawing
  1001.  
  1002.           // Set the scrolling dimensions so the extension can figure out when
  1003.           // our text falls outside the frame shape
  1004.           if (_fScrollExt) {
  1005.               somSelf->SetScrollableDimensions(ev, kODNULL,
  1006.                                       _fTextMgr->GetMaximumWidth(),
  1007.                                       _fTextMgr->GetTotalHeight());
  1008.           } /* end if _fScrollExt */
  1009.  
  1010.       } /* end if drawing canvas */
  1011.  
  1012. } catch(...) {}
  1013.  
  1014. }
  1015.  
  1016. SOM_Scope void SOMLINK TextPartFocusAcquired(TextPart* somSelf,
  1017.                        Environment     *ev,
  1018.                        ODTypeToken      focus,      // string token of kOD*Focus
  1019.                        ODFrame         *ownerFrame) // display frame that owns focus
  1020. {
  1021.     TextPartData *somThis = TextPartGetData(somSelf);
  1022.     TextPartMethodDebug("TextPart","TextPartFocusAcquired");
  1023. #ifdef ODDebug
  1024. //  PRINT ("TextPart::FocusAcquired invoked.\n");
  1025. #endif
  1026.  
  1027. try {
  1028.    TextPart_parent_BaseContainer_FocusAcquired(somSelf, ev, focus, ownerFrame);
  1029.  
  1030.    // Create the cursor when we gain the keyboard focus if the draft is writeable.
  1031.    if (focus == _fKeyFocus && !_fDraftReadOnly) {
  1032.       ODFrameFacetIterator* facetItr = ownerFrame->CreateFacetIterator(ev);
  1033.       HWND hwnd = facetItr->First(ev)->GetFacetHWND(ev);
  1034.       _fTextMgr->CreateCursor(hwnd);
  1035.       delete facetItr;
  1036.    } /* endif */
  1037.  
  1038.  
  1039. } catch(...) {}
  1040.  
  1041. }
  1042.  
  1043. SOM_Scope void SOMLINK TextPartFocusLost(TextPart* somSelf,
  1044.                        Environment     *ev,
  1045.                        ODTypeToken      focus,      // string token of kOD*Focus
  1046.                        ODFrame         *ownerFrame) // display frame which lost focus
  1047. {
  1048.     TextPartData *somThis = TextPartGetData(somSelf);
  1049.     TextPartMethodDebug("TextPart","TextPartFocusLost");
  1050. #ifdef ODDebug
  1051. //  PRINT ("TextPart::FocusLost invoked.\n");
  1052. #endif
  1053.  
  1054. try {
  1055.    // Delete the cursor when we gain the keyboard focus if the draft was writeable.
  1056.    if (focus == _fKeyFocus && !_fDraftReadOnly) {
  1057.       ODFrameFacetIterator* facetItr = ownerFrame->CreateFacetIterator(ev);
  1058.       HWND hwnd = facetItr->First(ev)->GetFacetHWND(ev);
  1059.       _fTextMgr->DeleteCursor(hwnd);
  1060.       delete facetItr;
  1061.    }
  1062.    TextPart_parent_BaseContainer_FocusLost(somSelf, ev, focus, ownerFrame);
  1063. } catch(...) {}
  1064.  
  1065. }
  1066.  
  1067. SOM_Scope ODBoolean SOMLINK TextPartHandleMouseClick(TextPart* somSelf,
  1068.                                     Environment     *ev,
  1069.                                     ODEventData     *event,
  1070.                                     ODFrame         *frame,
  1071.                                     ODFacet         *facet,
  1072.                                     ODEventInfo     *eventInfo)
  1073. {
  1074.     TextPartData *somThis = TextPartGetData(somSelf);
  1075.     TextPartMethodDebug("TextPart","TextPartHandleMouseClick");
  1076. #ifdef ODDebug
  1077. //  PRINT ("TextPart::HandleMouseClick invoked.\n");
  1078. #endif
  1079.  
  1080.     ODBoolean   eventHandled     = kODFalse;
  1081.  
  1082. try {
  1083.  
  1084.    // If our parent isn't expecting a mouse click and nothing is selected and
  1085.    // the draft is writeable, then use the mouse click to position the cursor.
  1086.    if ((somSelf->GetMouseMode(ev) == kMouseModeNull) &&
  1087.        (somSelf->GetSelectedObjects(ev)->Count(ev) == 0) &&
  1088.        !_fDraftReadOnly)
  1089.    {
  1090.       // Get the window and the position of the mouse click
  1091.       HWND hwnd = facet->GetFacetHWND(ev);
  1092.       ODPoint cursorLocation;
  1093.       WinPt2FramePt (ev, event, eventInfo, &cursorLocation, facet);
  1094.  
  1095.       // Get the bounding box of our used shape.  We use this to determine
  1096.       // which paragraph and character the mouse click corresponds to.
  1097.       ODRect rect;
  1098.       somSelf->GetFacetBoundingRect(ev,facet,&rect);
  1099.  
  1100.       // Set the cursor to the location of the mouse click
  1101.       _fTextMgr->SetCursor(hwnd, cursorLocation, rect);
  1102.       _fTextMgr->DisplayCursor(facet, rect);
  1103.       eventHandled = kODTrue;
  1104.    } else {
  1105.       eventHandled = TextPart_parent_BaseContainer_HandleMouseClick (somSelf, ev,
  1106.                                event, frame, facet, eventInfo);
  1107.    } /* endif */
  1108.  
  1109. } catch(...) {}
  1110.    return eventHandled;
  1111. }
  1112.  
  1113. SOM_Scope ODBoolean SOMLINK TextPartHandleKeyEvent(TextPart* somSelf,
  1114.                                     Environment     *ev,
  1115.                                     ODEventData     *event,
  1116.                                     ODFrame         *frame,
  1117.                                     ODFacet         *facet,
  1118.                                     ODEventInfo     *eventInfo)
  1119. {
  1120.     TextPartData *somThis = TextPartGetData(somSelf);
  1121.     TextPartMethodDebug("TextPart","TextPartHandleKeyEvent");
  1122.  
  1123.     ODBoolean   eventHandled = kODFalse;
  1124.     short       keyEvent;
  1125.     long        eventMessage;
  1126.  
  1127. try {
  1128.  
  1129. // On OS/2, the WM_CHAR event is generated for both a key down and key up.
  1130. // Unlike windows, the key event code for WM_CHAR can be either an ASCII
  1131. // value OR it can be a virtual key code.  So on OS2 we must examine the
  1132. // flags in mp1 to determine if this is a character or virtual key.
  1133. #ifdef _PLATFORM_OS2_
  1134.     short fsflags = SHORT1FROMMP(event->mp1);
  1135.  
  1136.     // Don't handle key up events- only key down
  1137.     if ((fsflags & KC_KEYUP) != 0) {
  1138.        return eventHandled;
  1139.     } /* endif */
  1140.  
  1141.     // Distinguish between character input and other keys
  1142.     if ((fsflags & KC_CHAR) != 0) { // Is this a character?
  1143.       eventMessage = CHARACTER_KEY;
  1144.       keyEvent = SHORT1FROMMP(event->mp2); // Get Character key code
  1145.     } else {
  1146.       eventMessage = VIRTUAL_KEY;
  1147.       keyEvent = SHORT2FROMMP(event->mp2); // Get Virtual key code
  1148.     }
  1149.  
  1150. #elif defined(_PLATFORM_WIN32_)
  1151. // On Windows, the WM_CHAR event is a subset of a key down event.  Only
  1152. // printable characters generate the WM_CHAR event, but all keys generate
  1153. // the kODEvtKeyDown event.  The key event code for WM_CHAR is the ASCII value
  1154. // of the character, but the key event code for kODEvtKeyDown is a virtual key
  1155. // value provided by the Windows dispatcher.  The virtual key value is
  1156. // usually different from the ASCII value, so we need to process WM_CHAR
  1157. // messages separately from kODEvtKeyDown messages on Windows.
  1158.     if (event->message == WM_CHAR) {
  1159.       eventMessage = CHARACTER_KEY;
  1160.     } else {
  1161.       eventMessage = VIRTUAL_KEY;
  1162.     } /* endif */
  1163.     keyEvent = event->wParam;
  1164. #endif //_PLATFORM_WIN32_
  1165.  
  1166.     // The dispatcher generates a kODEvtKeyUp message for both OS2 and NT.
  1167.     // The only key up message we want to process is the insert key.  Since
  1168.     // multiple key downs are possible for each key up, it's best to process
  1169.     // the insert key only on key up to know what insert mode we're in.
  1170.  
  1171. #ifdef _PLATFORM_WIN32_
  1172.     if (event->message == kODEvtKeyUp)
  1173. #elif defined(_PLATFORM_OS2_)
  1174.     if (event->msg == kODEvtKeyUp)
  1175. #endif
  1176.        if (keyEvent == VK_INSERT) {
  1177.           _fTextMgr->ToggleInsertMode();
  1178.           return kODTrue;
  1179.        } else {
  1180.           return kODFalse;
  1181.        }
  1182.  
  1183.     // Don't pass on the character events if we're in a read only draft.
  1184.     if (eventMessage == CHARACTER_KEY && _fDraftReadOnly)
  1185. #ifdef _PLATFORM_WIN32_
  1186.           Beep(300,150);
  1187. #elif defined(_PLATFORM_OS2_)
  1188.           DosBeep(300,50);
  1189. #endif
  1190.     else
  1191.        eventHandled = _fTextMgr->ProcessKeyInput(eventMessage, keyEvent);
  1192.  
  1193.     if (!eventHandled)
  1194.        eventHandled = TextPart_parent_BaseContainer_HandleKeyEvent (somSelf, ev,
  1195.                                event, frame, facet, eventInfo);
  1196.     else {
  1197.        // Set changed flag if necessary.
  1198.        if (eventMessage == TEXT_CHANGED) {
  1199.           somSelf->ChangeNotification(ev, TP_TEXTCHANGED, frame,
  1200.                                       kODNULL, kODTrue, kODNULL);
  1201.        }
  1202.        frame->Invalidate(ev,kODNULL,kODNULL);
  1203.     }
  1204. } catch(...) {}
  1205.     return eventHandled;
  1206. }
  1207.  
  1208. SOM_Scope void SOMLINK TextPartChangeNotification(TextPart *somSelf,
  1209.                 Environment     *ev,
  1210.                 ODULong         reason,
  1211.                 ODFrame         *frame,
  1212.                 ContentObject  *content,
  1213.                 ODBoolean       bPropagate,
  1214.                 ODUpdateID      updateID)
  1215. {
  1216.     TextPartData *somThis = TextPartGetData(somSelf);
  1217.     TextPartMethodDebug("TextPart","TextPartChangeNotification");
  1218. try {
  1219.     TextPart_parent_BaseContainer_ChangeNotification(somSelf, ev,
  1220.                     reason, frame, content, bPropagate, updateID);
  1221.  
  1222.     if (reason == TP_TEXTCHANGED) {
  1223.        if (_fScrollExt) {
  1224.            somSelf->SetScrollableDimensions(ev, frame,
  1225.                                  _fTextMgr->GetMaximumWidth(),
  1226.                                  _fTextMgr->GetTotalHeight());
  1227.        }
  1228.        somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  1229.     } /* endif */
  1230. } catch(...) {}
  1231. }
  1232.  
  1233. SOM_Scope ISOString  SOMLINK M_TextPartclsGetODPartHandlerName(M_TextPart *somSelf,
  1234.                                                                 Environment *ev)
  1235. {
  1236.     /* M_TextPartData *somThis = M_TextPartGetData(somSelf); */
  1237.     M_TextPartMethodDebug("M_TextPart","M_TextPartclsGetODPartHandlerName");
  1238. #ifdef ODDebug
  1239.     PRINT ("TextPart::clsGetODPartHandlerName invoked.\n");
  1240. #endif
  1241.  
  1242.     string handlerName = (string)SOMMalloc(strlen(kTextPartHandlerName)+1);
  1243.     strcpy(handlerName,kTextPartHandlerName);
  1244.  
  1245.     return (ISOString) handlerName;
  1246. }
  1247.  
  1248. SOM_Scope string  SOMLINK M_TextPartclsGetODPartHandlerDisplayName(M_TextPart *somSelf,
  1249.                                                                     Environment *ev)
  1250. {
  1251.     /* M_TextPartData *somThis = M_TextPartGetData(somSelf); */
  1252.     M_TextPartMethodDebug("M_TextPart","M_TextPartclsGetODPartHandlerDisplayName");
  1253. #ifdef ODDebug
  1254.     PRINT ("TextPart::clsGetODPartHandlerDisplayName invoked.\n");
  1255. #endif
  1256.  
  1257.     string displayName = (string)SOMMalloc(strlen(kTextPartHandlerDisplayName)+1);
  1258.     strcpy(displayName,kTextPartHandlerDisplayName);
  1259.  
  1260.     return displayName;
  1261. }
  1262.  
  1263. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK M_TextPartclsGetODPartKinds(M_TextPart *somSelf,
  1264.                                                                            Environment *ev)
  1265. {
  1266.     /* M_TextPartData *somThis = M_TextPartGetData(somSelf); */
  1267.     M_TextPartMethodDebug("M_TextPart","M_TextPartclsGetODPartKinds");
  1268. #ifdef ODDebug
  1269.     PRINT ("TextPart::clsGetODPartKinds invoked.\n");
  1270. #endif
  1271.  
  1272.     _IDL_SEQUENCE_PartKindInfo TextPartInfo;
  1273.  
  1274.     // Create structure PartKindInfo  and allocate memory for its fields
  1275.     PartKindInfo * info = (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
  1276.     info->partKindName = (ISOString) SOMMalloc(strlen(kODKindTextPart) + 1);
  1277.     info->partKindDisplayName = (string)SOMMalloc(strlen(kTextPartKindDisplayName)+1);
  1278.     info->filenameFilters =  (string)SOMMalloc(strlen("")+1);
  1279.     info->filenameTypes =  (string)SOMMalloc(strlen("")+1);
  1280.     info->categories =  (string)SOMMalloc(strlen(kTextPartCategory)+1);
  1281.     info->categoryDisplayName =  (string)SOMMalloc(strlen("")+1);
  1282.     info->objectID =  (string)SOMMalloc(strlen("")+1);
  1283.  
  1284.     // Copy the information into the structure
  1285.     strcpy(info->partKindName , kODKindTextPart);
  1286.     strcpy(info->partKindDisplayName, kTextPartKindDisplayName);
  1287.     strcpy(info->filenameFilters, "");
  1288.     strcpy(info->filenameTypes, "");
  1289.     strcpy(info->categories, kTextPartCategory);
  1290.     strcpy(info->categoryDisplayName, "");
  1291.     strcpy(info->objectID, "");
  1292.  
  1293.     TextPartInfo._maximum = 1;
  1294.     TextPartInfo._length = 1;
  1295.     TextPartInfo._buffer = info;
  1296.  
  1297.     return TextPartInfo;
  1298. }
  1299.  
  1300. SOM_Scope string  SOMLINK M_TextPartclsGetOLE2ClassId(M_TextPart *somSelf,
  1301.                                                        Environment *ev)
  1302. {
  1303.     /* M_TextPartData *somThis = M_TextPartGetData(somSelf); */
  1304.     M_TextPartMethodDebug("M_TextPart","M_TextPartclsGetOLE2ClassId");
  1305. #ifdef ODDebug
  1306.     PRINT ("TextPart::clsGetOLE2ClassId invoked.\n");
  1307. #endif
  1308.  
  1309.     // OLE2 Class ID is determined by running the tool UUIDGEN.EXE
  1310.     // or GUIDGEN.EXE found in the IBM VAC++ SDK\BIN directory
  1311.     // this tool is gauranteed to generate a unique ID based on your
  1312.     // network address and the time of day (DCE Standard)
  1313.  
  1314.  
  1315.     string OLE2 = "{fa005380-e962-11cf-b257-08005a49d940}";
  1316.     string OLE2ClassId = (string)SOMMalloc(strlen(OLE2)+1);
  1317.     strcpy(OLE2ClassId,OLE2);
  1318.  
  1319.     return OLE2ClassId;
  1320. }
  1321.  
  1322. SOM_Scope string  SOMLINK M_TextPartclsGetWindowsIconFileName(M_TextPart *somSelf,
  1323.                                                                Environment *ev)
  1324. {
  1325.     /* M_TextPartData *somThis = M_TextPartGetData(somSelf); */
  1326.     M_TextPartMethodDebug("M_TextPart","M_TextPartclsGetWindowsIconFileName");
  1327. #ifdef ODDebug
  1328.     PRINT ("TextPart::clsGetWindowsIconFileName invoked.\n");
  1329. #endif
  1330.  
  1331.     string fileName = (string) SOMMalloc (strlen(kTextPartIconFileName)+1);
  1332.     strcpy(fileName,kTextPartIconFileName);
  1333.     return fileName;
  1334. }
  1335.  
  1336.  
  1337.