home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / linkcntr / iodlinkc.cpp next >
C/C++ Source or Header  |  1997-04-02  |  85KB  |  2,468 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odlinkcntr
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,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.39 com/src/samples/linkcntr/iodlinkc.cpp, odlinkpart, od96os2, odos29714c 3/25/97 11:47:22 [4/2/97 17:19:55] */
  28.  
  29. #ifndef SOM_Module_linkcntr_Source
  30. #define SOM_Module_linkcntr_Source
  31. #endif
  32. #define VARIABLE_MACROS
  33. #define METHOD_MACROS
  34.  
  35. #define LinkContainer_Class_Source
  36. #define M_LinkContainer_Class_Source
  37.  
  38. #include <BArray.h>
  39. #include <FocusLib.h>
  40. #include <ODMath.h>
  41.  
  42. #ifdef _PLATFORM_AIX_
  43. #include <odres.h>
  44. #else
  45. #include <ODRes.h>
  46. #endif
  47.  
  48. #include <ODTypes.h>
  49. #include <StorUtil.h>
  50. #include <TempObj.h>
  51. #include <WinUtils.h>
  52. #include <time.h>
  53. #include <string.h>
  54. #include <StdTypIO.h>
  55.  
  56. #ifndef SOM_ODShape_xh
  57. #include <Shape.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODFacet_xh
  61. #include <Facet.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODFrame_xh
  65. #include <Frame.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODSession_xh
  69. #include <ODSessn.xh>
  70. #endif
  71.  
  72. #ifndef SOM_Module_xh5cStdProps_OpenDoc_StdProps_defined
  73. #include <StdProps.xh>
  74. #endif
  75.  
  76. #ifndef SOM_Module_xh5cStdTypes_OpenDoc_StdTypes_defined
  77. #include <StdTypes.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODStorageUnit_xh
  81. #include <StorageU.xh>
  82. #endif
  83.  
  84. #include <iostream.h>
  85.  
  86. #include <ODRegApi.h>
  87. #include <ODDebug.h>
  88.  
  89.  
  90. #ifndef SOM_ODLinkSpec_xh
  91. #include <LinkSpec.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODLink_xh
  95. #include <Link.xh>
  96. #endif
  97.  
  98. #ifndef SOM_ODMenubar_xh
  99. #include <MenuBar.xh>
  100. #endif
  101.  
  102. #ifndef SOM_ODLinkSource_xh
  103. #include <LinkSrc.xh>
  104. #endif
  105.  
  106. #ifndef SOM_ODClipboard_xh
  107. #include <Clipbd.xh>
  108. #endif
  109.  
  110. #include "iodlinkc.xih"
  111.  
  112. #ifndef SOM_ODFrameFacetIterator_xh
  113. #include <FrFaItr.xh>
  114. #endif
  115.  
  116. #ifndef SOM_ODDragAndDrop_xh
  117. #include <DragDrp.xh>
  118. #endif
  119.  
  120. #ifndef SOM_ODDragItemIterator_xh
  121. #include <DgItmIt.xh>
  122. #endif
  123.  
  124. #ifndef SOM_ODArbitrator_xh
  125. #include <Arbitrat.xh>
  126. #endif
  127.  
  128. #ifndef SOM_ODFocus_xh
  129. #include <Foci.xh>
  130. #endif
  131.  
  132. /**********************************************************************************
  133. CONSTANTS AND TYPE DEFINITIONS
  134. **********************************************************************************/
  135.  
  136. #define kPartHandlerName                   "LinkContainer"
  137. #define kPartHandlerDisplayName            "Link Container"
  138. #define kPartKindName                      "LinkContainer"
  139. #define kPartKindDisplayName               "Link Container Kind"
  140. #define kPartCategory                      "Linking"
  141. #define kWindowsIcon                       "iodlinkc.ico"
  142. #define kLinkContainerLinkInfo             "LinkContainer:LinkInfo"
  143. #define kLinkContainerLinkSources          "LinkContainer:LinkSources"
  144. #define kLinkContainerLinkDestinations     "LinkContainer:LinkDestinations"
  145. #define kLinkContainerLinkCount            "LinkContainer:LinkCount"
  146. //********************************************************************
  147.  
  148.  
  149. #if defined (_PLATFORM_WIN32_)
  150. #pragma linkage (SOMInitModule, system)
  151. #endif
  152.  
  153. SOMEXTERN void SOMLINK SOMInitModule (long majorversion, long minorversion, string className)
  154. {
  155.     SOM_IgnoreWarning (majorversion);
  156.     SOM_IgnoreWarning (minorversion);
  157.     SOM_IgnoreWarning (className);
  158.     LinkContainerNewClass(BaseContainer_MajorVersion,BaseContainer_MinorVersion);
  159. }
  160.  
  161. #ifdef _PLATFORM_OS2_
  162. #pragma export (SOMInitModule)
  163. #endif
  164.  
  165.  
  166.  
  167. /********************************************************************
  168.   HELPER FUNCTIONS
  169. ********************************************************************/
  170. ContentFrame *GetContentObjectForFrame(ODFrame *frame, ALinkedList *l)
  171. {
  172.  
  173.    ALink *itr;
  174.    ContentFrame *cobj;
  175.    Environment *ev = somGetGlobalEnvironment();
  176.    for(itr = l->First(ev); itr->Content(ev); itr=itr->Next(ev)) {
  177.        cobj = (ContentFrame *) itr->Content(ev);
  178.        if ((cobj->_get_objType(ev) == COBJ_FRAMECLASS) && (cobj->_get_myFrame(ev) == frame))
  179.           return cobj;
  180.    }
  181.    return kODNULL;
  182. }
  183.  
  184.  
  185. ODFacet* FirstFacet (Environment *ev, ODFrame *frame)
  186. {
  187.  
  188.     ODFrameFacetIterator *ffitr  = frame->CreateFacetIterator(ev);
  189.     ODFacet *facet = (ODFacet *)ffitr->First(ev);
  190.     ODDeleteObject(ffitr);
  191.     return facet;
  192.  
  193. }
  194.  
  195. inline ODULong GetIDForContentObject (ContentObject *cObj, ContentObject **tmpArray,
  196.                                        ODULong num)
  197. {
  198.    int i;
  199.    for (i = 0; i<num; i++)
  200.       if (tmpArray[i] == cObj)
  201.          return i;
  202.    return num;
  203.  
  204. }
  205.  
  206.  
  207. void UpdateLinkStatusofEmbeds (Environment *ev, LinkContainer *somSelf)
  208. {
  209.    ALink *itr;
  210.    ALinkedList *embeds = somSelf->GetEmbeddedObjects (ev);
  211.  
  212.    for (itr = embeds->First (ev); itr->Content (ev); itr = itr->Next (ev))
  213.    {
  214.       ContentObject *cObj = (ContentObject *) itr->Content(ev);
  215.       if (cObj->_get_containingFrame (ev)->GetLinkStatus (ev) == kODInLinkSource)
  216.          cObj->_set_linkStatus (ev, kODInLinkSource);
  217.    }
  218. }
  219.  
  220.  
  221. // The following routine throws a warning if the frame in which an editing
  222. // opeartion is performed is a link destination
  223.  
  224. char warnDestMsg[] = "Editing is not allowed in this frame since it is marked \n"
  225. ;
  226. char warnDestMsg1[] = "as a link destination.  Please break the link and retry.";
  227. char warnDestMsg2[] = "Selection contains link sources or link destinations.  \n";
  228. char warnDestMsg3[] = "Please press OK to break links and proceed, or Cancel to abort.";
  229. char warnTitle[] = "Link Container Warning";
  230.  
  231. // UNIX specific code to display a modal dialog
  232.  
  233. #if defined (_PLATFORM_UNIX_)
  234.  
  235. #ifndef SOM_ODWindowState_xh
  236. #include <WinStat.xh>
  237. #endif
  238.  
  239. SOMEXTERN void SOMLINK okcancelCallBack(Widget widget, XtPointer client_data,
  240.                                     XtPointer call_data)
  241. {
  242.    int *answer = (int *)client_data;
  243.    XmAnyCallbackStruct *cbs = (XmAnyCallbackStruct *)call_data;
  244.  
  245.    switch (cbs->reason)
  246.     {
  247.         case XmCR_OK:
  248.             *answer = 1;
  249.             break;
  250.         case XmCR_CANCEL:
  251.             *answer = 2;
  252.             break;
  253.     }
  254.  
  255. }
  256.  
  257. ODBoolean ShowModalDialogOnX (ODFacet *facet, Environment *ev,
  258.                    char *warnTitle, char *msgText, ODBoolean bShowCancel)
  259. {
  260.    ODBoolean result = kODFalse;
  261.  
  262.    Widget topLevelShellWidget = facet->GetFacetWidget (ev);
  263.    if (!topLevelShellWidget)
  264.      return result;
  265.  
  266.    Arg args[2];
  267.    XtSetArg(args[0], XmNdeleteResponse, XmDO_NOTHING);
  268.    XtSetArg(args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
  269.  
  270.    Widget dialog = XmCreateInformationDialog(topLevelShellWidget,
  271.                                               "showwarningDest", args, 2);
  272.    XmString title = XmStringCreateLocalized(warnTitle);
  273.    XmString myMsg = XmStringCreateLocalized(msgText);
  274.  
  275.    XtVaSetValues(dialog,
  276.                   XmNdialogTitle, title,
  277.                   XmNmessageString, myMsg,
  278.                   NULL);
  279.    XmStringFree(myMsg);
  280.    XmStringFree(title);
  281.  
  282.    // remove cancel and help buttons from dialog.
  283.    XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON));
  284.    if (bShowCancel == kODFalse)
  285.       XtUnmanageChild (XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
  286.  
  287.    // add callbacks for buttons
  288.    int answer = 0;
  289.  
  290.    XtAddCallback(dialog, XmNokCallback,
  291.                   (XtCallbackProc)okcancelCallBack, (XtPointer)&answer);
  292.    if (bShowCancel)
  293.       XtAddCallback(dialog, XmNcancelCallback,
  294.                   (XtCallbackProc)okcancelCallBack, (XtPointer)&answer);
  295.  
  296.    // display dialog
  297.    XtManageChild(dialog);
  298.  
  299.    // get app context
  300.    XtAppContext app = facet->GetFrame(ev)->GetStorageUnit(ev)->
  301.                 GetSession(ev)->GetWindowState(ev)->GetAppContext(ev);
  302.  
  303.    while (answer == 0){
  304.       XtAppProcessEvent (app, XtIMAll);
  305.       XSync(XtDisplay(dialog), 0);
  306.    }
  307.  
  308.    if (answer == 1)
  309.       result = kODTrue;
  310.  
  311.    XtUnmanageChild (dialog);
  312.    XSync(XtDisplay(dialog), 0);
  313.    XmUpdateDisplay(dialog);
  314.  
  315.    return result;
  316. };
  317.  
  318. #endif // Aix specific modal dialog function
  319.  
  320.  
  321. // Warning dialog for non-explicit destination.. cannot break link from here
  322.  
  323. ODBoolean ShowWarningForDest (ODFacet *facet, Environment *ev)
  324. {
  325.    ODBoolean warnResult = kODFalse;
  326.    char msgText[256] = "";
  327.    strcat (msgText, warnDestMsg);
  328.    strcat (msgText, warnDestMsg1);
  329.  
  330. #if defined (_PLATFORM_WIN32_)
  331.  
  332.     MessageBox (facet->GetWindow(ev)->GetPlatformWindow(ev), msgText, warnTitle,
  333.                             MB_APPLMODAL | MB_OK);
  334.  
  335. #elif defined (_PLATFORM_OS2_)
  336.  
  337.    WinMessageBox (HWND_DESKTOP, facet->GetWindow(ev)->GetPlatformWindow(ev),
  338.                             msgText, warnTitle, 0, MB_APPLMODAL | MB_OK | MB_MOVEABLE);
  339.  
  340. #elif defined (_PLATFORM_UNIX_)
  341.  
  342.    ShowModalDialogOnX (facet, ev, warnTitle, msgText, kODFalse);
  343.  
  344. #endif
  345.    return warnResult;
  346. }
  347.  
  348.  
  349. // Warning dialog for explicit destination.. give user an option to break link or abort
  350.  
  351. ODBoolean ShowWarningForEmbed (ODFacet *facet, Environment *ev)
  352. {
  353.    ODBoolean warnResult = kODFalse;
  354.    char msgText[256] = "";
  355.    strcat (msgText, warnDestMsg2);
  356.    strcat (msgText, warnDestMsg3);
  357.  
  358. #if defined (_PLATFORM_WIN32_)
  359.  
  360.     int result = MessageBox (facet->GetWindow(ev)->GetPlatformWindow(ev), msgText, warnTitle,
  361.                             MB_APPLMODAL | MB_OKCANCEL);
  362.     if (result == IDOK)
  363.        warnResult = kODTrue;
  364.  
  365. #elif defined (_PLATFORM_OS2_)
  366.  
  367.    int result =  WinMessageBox (HWND_DESKTOP, facet->GetWindow(ev)->GetPlatformWindow(ev),
  368.                             msgText, warnTitle, 0, MB_APPLMODAL | MB_OKCANCEL | MB_MOVEABLE);
  369.     if (result == MBID_OK)
  370.        warnResult = kODTrue;
  371.  
  372. #elif defined (_PLATFORM_UNIX_)
  373.  
  374.    warnResult = ShowModalDialogOnX (facet, ev, warnTitle, msgText, kODTrue);
  375.  
  376. #endif
  377.  
  378.    return warnResult;
  379. }
  380.  
  381. // GetLinkSource does the following:
  382. //   - Receives a pointer to a list of all the link sources (l) and a pointer to a list
  383. //     of frames that we want tested.  
  384. //   - If the entire list of frames comprises exactly one of the link sources in "l,"
  385. //     then we return a pointer to the SourceOfLink structure for the link.
  386.  
  387. SourceOfLink *GetLinkSource (Environment *ev, ALinkedList *candidates,  ALinkedList *l)
  388. {
  389.     ALink *itr = kODNULL;
  390.     ODBoolean foundOne = kODFalse;
  391.     SourceOfLink *source = kODNULL;
  392.  
  393.     for(itr = l->First(ev); (itr->Content(ev) && !foundOne); itr=itr->Next(ev))
  394.     {
  395.          foundOne = kODTrue;
  396.          source = (SourceOfLink *) itr->Content(ev);
  397.          int i;
  398.      if (source->num == candidates->Count(ev)) {
  399.        for (i = 0; i < source->num; i++) {
  400.          if (!candidates->Contains(ev, source->sourceObjects[i])) {
  401.            foundOne = kODFalse;
  402.                break;
  403.          }
  404.        }
  405.      }
  406.      else
  407.        foundOne = kODFalse;
  408.     }
  409.     return (foundOne ? source : kODNULL);
  410. }
  411.  
  412. // GetLinkDestination does the following:
  413. //   - Receives a pointer to a list of all the link destinations (l) and a pointer to a list
  414. //     of frames that we want tested.  
  415. //   - If the entire list of frames comprises exactly one of the link destinations in "l,"
  416. //     then we return a pointer to the DestOfLink structure for the link.
  417.  
  418. DestOfLink *GetLinkDestination (Environment *ev, ALinkedList *candidates,  ALinkedList *l)
  419. {
  420.     ALink *itr = kODNULL;
  421.     ODBoolean foundOne = kODFalse;
  422.     DestOfLink *dest = kODNULL;
  423.  
  424.     for(itr = l->First(ev); (itr->Content(ev) && !foundOne); itr=itr->Next(ev))
  425.     {
  426.          foundOne = kODTrue;
  427.          dest = (DestOfLink *) itr->Content(ev);
  428.          int i;
  429.      if (dest->num == candidates->Count(ev)) {
  430.        for (i = 0; i < dest->num; i++) {
  431.          if (!candidates->Contains(ev, dest->destObjects[i])) {
  432.            foundOne = kODFalse;
  433.                break;
  434.          }
  435.        }
  436.      }
  437.      else
  438.        foundOne = kODFalse;
  439.     }
  440.     return (foundOne ? dest : kODNULL);
  441. }
  442.  
  443. ODBoolean IsInLinkSource (Environment *ev, ContentObject *cObj, ALinkedList *l)
  444. {
  445.     ALink *itr = kODNULL;
  446.  
  447.     for(itr = l->First(ev); itr->Content(ev); itr=itr->Next(ev))
  448.     {
  449.          SourceOfLink *source = (SourceOfLink *) itr->Content(ev);
  450.          int i;
  451.          for (i = 0; i < source->num; i++) {
  452.             if (source->sourceObjects[i] == cObj) {
  453.                return kODTrue;
  454.             }
  455.          }
  456.     }
  457.     return kODFalse;
  458. }
  459.  
  460.  
  461. ODBoolean IsInLinkDestination (Environment *ev, ContentObject *cObj, ALinkedList *l)
  462. {
  463.     ALink *itr = kODNULL;
  464.  
  465.     for(itr = l->First(ev); itr->Content(ev); itr=itr->Next(ev))
  466.     {
  467.          DestOfLink *dest = (DestOfLink *) itr->Content(ev);
  468.          int i;
  469.          for (i = 0; i < dest->num; i++) {
  470.             if (dest->destObjects[i] == cObj) {
  471.                return kODTrue;
  472.             }
  473.          }
  474.     }
  475.     return kODFalse;
  476. }
  477. //--------------------------------------------------------------------------
  478. // ODPart --> LinkStatusChanged
  479. //
  480. //      Should notify this part that the link status of one of its display
  481. //      frames has changed.
  482. //
  483. //      ->
  484. //--------------------------------------------------------------------------
  485.  
  486. SOM_Scope       void
  487. SOMLINK         LinkContainerLinkStatusChanged
  488.                 (
  489.                 LinkContainer   *somSelf,       // in
  490.                 Environment     *ev,            // in
  491.                 ODFrame         *frame          // in
  492.                 )
  493. {
  494.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  495.     LinkContainerMethodDebug("LinkContainer","LinkContainerLinkStatusChanged");
  496.  
  497.     ODLinkStatus status = frame->GetLinkStatus (ev);
  498.  
  499.     ALink *itr;
  500.     ALinkedList *list = somSelf->GetEmbeddedObjects (ev);
  501.  
  502.     for (itr = list->First(ev); itr->Content(ev); itr = itr->Next(ev))
  503.     {
  504.        ContentObject *cObj = (ContentObject *) itr->Content(ev);
  505.        if (cObj->_get_containingFrame(ev) == frame)
  506.           cObj->_set_linkStatus (ev, status);
  507.     }
  508.  
  509. }
  510.  
  511.  
  512.  
  513. //--------------------------------------------------------------------------
  514. // ODPart --> RevealLink
  515. //
  516. //      Should show the content at the source of a link.
  517. //
  518. //      ->
  519. //--------------------------------------------------------------------------
  520.  
  521. SOM_Scope       void
  522. SOMLINK         LinkContainerRevealLink
  523.                 (
  524.                 LinkContainer   *somSelf,       // in
  525.                 Environment     *ev,            // in
  526.                 ODLinkSource    *linkSource     // in
  527.                 )
  528. {
  529.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  530.     LinkContainerMethodDebug("LinkContainer","LinkContainerRevealLink");
  531.  
  532.  
  533. }
  534.  
  535.  
  536. //--------------------------------------------------------------------------
  537. // ODPart --> CreateLink
  538. //
  539. //      Should create a link-source object for this part.
  540. //
  541. //      ->
  542. //--------------------------------------------------------------------------
  543.  
  544. SOM_Scope       ODLinkSource*
  545. SOMLINK         LinkContainerCreateLink
  546.                 (
  547.                 LinkContainer   *somSelf,       // in
  548.                 Environment     *ev,            // in
  549.                 ODByteArray     *data           // in
  550.                 )
  551. {
  552.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  553.     LinkContainerMethodDebug("LinkContainer","LinkContainerCreateLink");
  554.  
  555.     SourceOfLink *source = new SourceOfLink;
  556.     memset(source, 0, sizeof(SourceOfLink));
  557.  
  558.     try {
  559.  
  560.        ODDraft* myDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  561.        ALinkedList *ObjectsToLink = kODNULL;
  562.        memcpy(&ObjectsToLink, data->_buffer, sizeof (ALinkedList*));
  563.  
  564.        source->linkSource = myDraft->CreateLinkSource(ev, somSelf);
  565.        source->num = ObjectsToLink->Count(ev);
  566.        source->sourceObjects = (ContentObject**) SOMMalloc (source->num * sizeof(ContentObject*));
  567.        ALink *itr = kODNULL;
  568.        int i = 0;
  569.  
  570.        for(itr = ObjectsToLink->First(ev); itr->Content(ev); itr=itr->Next(ev))
  571.        {
  572.            source->sourceObjects[i++] = (ContentObject*) itr->Content(ev);
  573.            if (((ContentObject*) itr->Content(ev))->_get_linkStatus(ev) != kODInLinkDestination)
  574.               ((ContentObject*) itr->Content(ev))->_set_linkStatus (ev, kODInLinkSource);
  575.        }
  576.  
  577.        _fAllLinkSources->AddLast (ev, source);
  578.  
  579.        source->change = _fSession->UniqueUpdateID(ev);
  580.        somSelf->WriteSingleLink (ev, (void*)source, source->change);
  581.  
  582.  
  583.  
  584.    }
  585.    catch (ODException _exception) {
  586.  
  587.      if (source->linkSource)
  588.         source->linkSource->Release(ev);
  589.      delete source;
  590.    }
  591.  
  592.    //According to recipes, we need to acquire link source
  593.    source->linkSource->Acquire(ev);
  594.    return source->linkSource;
  595.  
  596. }
  597.  
  598. //--------------------------------------------------------------------------
  599. //  LinkContainer->WriteLinkSpec
  600. //
  601. //      ->
  602. //--------------------------------------------------------------------------
  603.  
  604. SOM_Scope       void
  605. SOMLINK         LinkContainerWriteLinkSpec
  606.                 (
  607.                 LinkContainer   *somSelf,       // in
  608.                 Environment     *ev,            // in
  609.                 ODStorageUnit   *toSU           // in
  610.                 )
  611. {
  612.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  613.     LinkContainerMethodDebug("LinkContainer","LinkContainerWriteLinkSpec");
  614.  
  615.     try {
  616.  
  617.  
  618.     ALinkedList *ObjectsToLink = new ALinkedList;
  619.     PRINT("WriteLinkSpec:ObjectsToLink %lx\n", ObjectsToLink);
  620.     ALinkedList *fSelectedObjects = somSelf->GetSelectedObjects(ev);
  621.     ALink* itr = kODNULL;
  622.  
  623.     for(itr = fSelectedObjects->First(ev); itr->Content(ev); itr=itr->Next(ev))
  624.     {
  625.          ContentObject *lObj = (ContentObject*) itr->Content(ev);
  626.          ObjectsToLink->AddLast(ev, lObj);
  627.     }
  628.  
  629.     ODByteArray *theLinkSpecData = CreateByteArray((void*)&ObjectsToLink, sizeof(ObjectsToLink));
  630.     ODDraft* myDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  631.     toSU->AddProperty(ev, kODPropLinkSpec);
  632.     ODLinkSpec* linkSpec = myDraft->CreateLinkSpec(ev, somSelf, theLinkSpecData);
  633.     linkSpec->WriteLinkSpec(ev, toSU);
  634.  
  635.     _fLastSavedList = ObjectsToLink;
  636.  
  637.     }
  638.     catch (...) {}
  639.  
  640.  
  641. }
  642.  
  643.  
  644. //--------------------------------------------------------------------------
  645. //  LinkContainer->CompleteResizeOperation
  646. //
  647. //      ->
  648. //--------------------------------------------------------------------------
  649.  
  650. SOM_Scope       void
  651. SOMLINK         LinkContainerCompleteResizeOperation
  652.                 (
  653.                 LinkContainer   *somSelf,       // in
  654.                 Environment     *ev,             // in
  655.                 ContentObject *contentObject,
  656.                 ODULong       resizeFlags,
  657.                 ODPoint       *winPoint,
  658.                 ODFacet       *facet
  659.                 )
  660. {
  661.  
  662.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  663.     LinkContainerMethodDebug("LinkContainer","LinkContainerCompleteResizeOperation");
  664.  
  665.     try {
  666.  
  667.        ContentObject *cObj = contentObject;
  668.        if (!cObj)
  669.           cObj = (ContentObject *)somSelf->GetSelectedObjects (ev)->
  670.                                                       First(ev)->Content(ev);
  671.  
  672.        if (cObj && (cObj->_get_linkStatus(ev) == kODInLinkDestination))
  673.        {
  674.           if (IsInLinkDestination (ev, cObj, _fAllLinkDestinations))
  675.           {
  676.              if (ShowWarningForEmbed (facet, ev))
  677.              {
  678.                 // break link
  679.                 somSelf->BreakAllLinks (ev, cObj);
  680.              }
  681.              else
  682.              {
  683.                 if (somSelf->GetMouseMode (ev) == kMouseModeTrackResize)
  684.                    somSelf->AbortMouseTracking (ev, facet->GetFrame(ev));
  685.                 facet->Invalidate (ev, kODNULL, kODNULL);
  686.                 return;
  687.              }
  688.           }
  689.           else
  690.           {
  691.              ShowWarningForDest (facet, ev);
  692.              if (somSelf->GetMouseMode (ev) == kMouseModeTrackResize)
  693.                 somSelf->AbortMouseTracking (ev, facet->GetFrame(ev));
  694.              facet->Invalidate (ev, kODNULL, kODNULL);
  695.              return;
  696.           }
  697.        }
  698.  
  699.        LinkContainer_parent_BaseContainer_CompleteResizeOperation (somSelf, ev,
  700.                                       contentObject, resizeFlags, winPoint, facet);
  701.     }
  702.     catch (...) {}
  703.  
  704.  
  705. }
  706.  
  707.  
  708. //--------------------------------------------------------------------------
  709. //  LinkContainer->CompleteMoveOperation
  710. //
  711. //      ->
  712. //--------------------------------------------------------------------------
  713.  
  714. SOM_Scope       void
  715. SOMLINK         LinkContainerCompleteMoveOperation
  716.                 (
  717.                 LinkContainer   *somSelf,       // in
  718.                 Environment     *ev,             // in
  719.                 ODFrame      *containingFrame,
  720.                 ODPoint      *offset
  721.                 )
  722. {
  723.  
  724.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  725.     LinkContainerMethodDebug("LinkContainer","LinkContainerCompleteMoveOperation");
  726.  
  727.     try {
  728.  
  729.        ODBoolean embedWarn = kODFalse, destWarn = kODFalse;
  730.        ALink *itr;
  731.        ALinkedList *objects = somSelf->GetSelectedObjects (ev);
  732.  
  733.        for (itr = objects->First(ev); itr->Content(ev); itr = itr->Next(ev))
  734.        {
  735.           ContentObject *cObj = (ContentObject *)(itr->Content(ev));
  736.           ODLinkStatus ls = cObj->_get_linkStatus(ev);
  737.  
  738.           if (ls == kODInLinkDestination)
  739.           {
  740.              //chaeck if there are any explicit links here or link status is
  741.              // just inherited from parent
  742.         
  743.         if (IsInLinkDestination (ev, cObj, _fAllLinkDestinations)) {
  744.  
  745.           //  We check to see if the selection is one single entire destination.  If it is, then
  746.           //  we will allow the move.  We only disallow the move if the selection is part of a destination,
  747.           //  since such a move represents a change in that destination.  Destinations are considered to be
  748.           //  read-only, so changes are not allowed.
  749.           DestOfLink   *isEntireLinkDestination = GetLinkDestination(ev, objects, _fAllLinkDestinations);         
  750.           if (isEntireLinkDestination)
  751.         embedWarn = kODFalse;
  752.           else
  753.                 embedWarn = kODTrue;
  754.         }
  755.              else
  756.                 destWarn = kODTrue;
  757.           }
  758.  
  759.        }
  760.  
  761.        ODFacet  *facet = FirstFacet (ev, containingFrame);
  762.  
  763.        if (destWarn)
  764.        {
  765.           ShowWarningForDest (facet, ev);
  766.           if (somSelf->GetMouseMode (ev) == kMouseModeTrackMove)
  767.              somSelf->AbortMouseTracking (ev, containingFrame);
  768.           facet->Invalidate (ev, kODNULL, kODNULL);
  769.           return;
  770.        }
  771.  
  772.        else if (embedWarn)
  773.        {
  774.              if (ShowWarningForEmbed (facet, ev))
  775.              {
  776.                 // break link
  777.                 for (itr = objects->First(ev); itr->Content(ev); itr = itr->Next(ev))
  778.                 {
  779.                    ContentObject *cObj = (ContentObject *)(itr->Content(ev));
  780.                    somSelf->BreakAllLinks (ev, cObj);
  781.                 }
  782.              }
  783.              else
  784.              {
  785.                 if (somSelf->GetMouseMode (ev) == kMouseModeTrackResize)
  786.                    somSelf->AbortMouseTracking (ev, containingFrame);
  787.                 facet->Invalidate (ev, kODNULL, kODNULL);
  788.                 return;
  789.              }
  790.        }
  791.  
  792.        LinkContainer_parent_BaseContainer_CompleteMoveOperation (somSelf, ev,
  793.                                       containingFrame, offset);
  794.     }
  795.     catch (...) {}
  796.  
  797.  
  798. }
  799.  
  800. //--------------------------------------------------------------------------
  801. //  LinkContainer->DeleteSelection
  802. //
  803. //      ->
  804. //--------------------------------------------------------------------------
  805.  
  806. SOM_Scope       void
  807. SOMLINK         LinkContainerDeleteSelection
  808.                 (
  809.                 LinkContainer   *somSelf,       // in
  810.                 Environment     *ev,             // in
  811.                 ODULong         type
  812.                 )
  813. {
  814.  
  815.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  816.     LinkContainerMethodDebug("LinkContainer","LinkContainerDeleteSelection");
  817.  
  818.     try {
  819.  
  820.        ODBoolean embedWarn = kODFalse, destWarn = kODFalse;
  821.        ALink *itr;
  822.        ODFrame *cF = kODNULL;
  823.        ALinkedList *objects = somSelf->GetSelectedObjects (ev);
  824.  
  825.        for (itr = objects->First(ev); itr->Content(ev); itr = itr->Next(ev))
  826.        {
  827.           ContentObject *cObj = (ContentObject *)(itr->Content(ev));
  828.           ODLinkStatus ls = cObj->_get_linkStatus(ev);
  829.  
  830.           if (ls == kODInLinkDestination)
  831.           {
  832.              //chaeck if there are any explicit links here or link status is
  833.              // just inherited from parent
  834.  
  835.              if (IsInLinkDestination (ev, cObj, _fAllLinkDestinations))
  836.                 embedWarn = kODTrue;
  837.              else
  838.                 destWarn = kODTrue;
  839.           }
  840.  
  841.           if (ls == kODInLinkSource)
  842.              embedWarn = IsInLinkSource (ev, cObj, _fAllLinkSources);
  843.  
  844.           if (!cF)
  845.              cF = cObj->_get_containingFrame (ev);
  846.        }
  847.  
  848.        if (destWarn)
  849.        {
  850.           ShowWarningForDest (FirstFacet (ev, cF), ev);
  851.            return;
  852.        }
  853.  
  854.        if (embedWarn)
  855.        {
  856.           ODBoolean warnResult = ShowWarningForEmbed (FirstFacet (ev, cF), ev);
  857.           if (warnResult)
  858.           {
  859.              // break links
  860.              for (itr = objects->First(ev); itr->Content(ev); itr = itr->Next(ev))
  861.              {
  862.                 ContentObject *cObj = (ContentObject *)(itr->Content(ev));
  863.                 somSelf->BreakAllLinks (ev, cObj);
  864.              }
  865.           }
  866.           else
  867.              return;
  868.        }
  869.  
  870.        // Now that we have decided to delete selection, make sure
  871.        // that the link spec kept on clipboard is up-to-date
  872.  
  873.        if (type != OBJECT_DRAGGED)
  874.        {
  875.           // Looks like I was the last one to update clipboard
  876.  
  877.           ODClipboard*  clipboard = _fSession->GetClipboard(ev);
  878.           ODFrame *frame = (ODFrame *)somSelf->GetDisplayFrames(ev)->First(ev)->Content(ev);
  879.           ODBoolean gotCB = _fSession->GetArbitrator(ev)->RequestFocus(ev,
  880.                                     _fSession->Tokenize(ev,kODClipboardFocus), frame);
  881.           ODStorageUnit* clipSU = clipboard->GetContentStorageUnit(ev);
  882.  
  883.           if (gotCB && _fLastSavedList && clipSU->Exists (ev, kODPropLinkSpec, kODNULL, 0))
  884.           {
  885.              //update savedList based on what's being deleted
  886.  
  887.              for (itr = objects->First(ev); itr->Content(ev); itr = itr->Next(ev))
  888.              {
  889.                 ContentObject *cObj = (ContentObject *)(itr->Content(ev));
  890.                 if (_fLastSavedList->Contains (ev, cObj))
  891.                    _fLastSavedList->Remove (ev, cObj);
  892.  
  893.              } // end for
  894.  
  895.              if (_fLastSavedList->Count(ev) == 0)
  896.              {
  897.                 // remove the property and export clipboard and set updateID
  898.                 PRINT("Clearing link Spec\n");
  899.                 ODSURemoveProperty (ev, clipSU, kODPropLinkSpec);
  900.                 clipboard->ExportClipboard(ev);
  901.                 delete _fLastSavedList;
  902.                 _fLastSavedList = kODNULL;
  903.              }
  904.              else
  905.                 PRINT("Still keeping link spec\n");
  906.  
  907.           } // endif .. gotCB
  908.  
  909.           // relinquish focus now
  910.           if (gotCB)
  911.           {
  912.              _fSession->GetArbitrator(ev)->RelinquishFocus(ev,
  913.                             _fSession->Tokenize(ev,kODClipboardFocus), frame);
  914.           }
  915.  
  916.        } // endif .. not OBJECT_DRAGGED
  917.  
  918.        LinkContainer_parent_BaseContainer_DeleteSelection (somSelf, ev, type);
  919.  
  920.     }
  921.     catch (...) {}
  922.  
  923. }
  924.  
  925.  
  926. //--------------------------------------------------------------------------
  927. //  LinkContainer->StartDrag
  928. //
  929. //      ->
  930. //--------------------------------------------------------------------------
  931.  
  932. SOM_Scope       void
  933. SOMLINK         LinkContainerStartDrag
  934.                 (
  935.                 LinkContainer   *somSelf,       // in
  936.                 Environment     *ev,             // in
  937.                 ODEventData     *event,          // in
  938.                 ODFrame         *embeddedFrame,  // in
  939.                 ODFacet         *facet,          // in
  940.                 ODEventInfo     *eventInfo,
  941.                 ODCloneKind     cloneKind
  942.                 )
  943. {
  944.  
  945.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  946.     LinkContainerMethodDebug("LinkContainer","LinkContainerStartDrag");
  947.  
  948.     try {
  949.  
  950.        ALinkedList *list = somSelf->GetSelectedObjects (ev);
  951.        ALink *itr;
  952.        ODCloneKind cKind = kODCloneCut;
  953.  
  954.        for (itr = list->First(ev); itr->Content(ev); itr = itr->Next (ev))
  955.        {
  956.           ContentObject *cObj = (ContentObject *) itr->Content(ev);
  957.           if (cObj->_get_linkStatus (ev) != kODNotInLink)
  958.           {
  959.              cKind = kODCloneCopy;
  960.              break;
  961.           }
  962.        } // end for
  963.  
  964.        LinkContainer_parent_BaseContainer_StartDrag (somSelf, ev,
  965.                  event, embeddedFrame, facet, eventInfo, cKind);
  966.  
  967.     }
  968.     catch (...) {}
  969.  
  970. }
  971.  
  972. //--------------------------------------------------------------------------
  973. //  LinkContainer->PasteSelectionAs
  974. //
  975. //      ->
  976. //--------------------------------------------------------------------------
  977.  
  978. SOM_Scope       void
  979. SOMLINK         LinkContainerPasteSelectionAs
  980.                 (
  981.                 LinkContainer   *somSelf,       // in
  982.                 Environment     *ev,             // in
  983.                 ODFacet         *facet,          // in
  984.                 ODPoint         *toWhere
  985.                 )
  986. {
  987.  
  988.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  989.     LinkContainerMethodDebug("LinkContainer","LinkContainerPasteSelectionAs");
  990.  
  991.     try {
  992.  
  993.       ODPasteAsResult result;
  994.       ODClipboard*  clipboard = _fSession->GetClipboard(ev);
  995.       ODStorageUnit* clipSU = clipboard->GetContentStorageUnit(ev);
  996.       ODTypeToken viewType = _fSession->Tokenize(ev, kODViewAsFrame );
  997.  
  998.       // invoke the dialog; if it returns true, the user selected "OK"
  999.       if(!_fSession->GetClipboard(ev)->ShowPasteAsDialog(ev, kODTrue,
  1000.                     kODPasteAsEmbedOnly, facet, viewType, &result))
  1001.          return;
  1002.  
  1003.       if( result.pasteLinkSetting == kODFalse) {
  1004.           somSelf->PasteSelection(ev, facet, toWhere);
  1005.          return;
  1006.       }
  1007.  
  1008.       ODDraft *myDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1009.       ODLinkSpec* linkSpec = myDraft->CreateLinkSpec(ev, kODNULL, kODNULL);
  1010.  
  1011.       clipSU->Focus(ev, kODPropLinkSpec, kODPosUndefined, kODNULL, 0, kODPosUndefined);
  1012.       linkSpec->ReadLinkSpec(ev, clipSU);
  1013.  
  1014.       ODLink *link = myDraft->AcquireLink(ev, kODNULLID, linkSpec);
  1015.  
  1016.       if (link == kODNULL) {
  1017.          WARNMSG (WARN_INDEX(-1), "Link Could not be acquired. Linking failed.");
  1018.          return;
  1019.       }
  1020. #ifndef _PLATFORM_AIX_
  1021.       if (result.selectedKind == kODNULL) {
  1022.          WARNMSG (WARN_INDEX(-1), "No kind selected. Linking failed.");
  1023.          return;
  1024.       }
  1025. #endif
  1026.  
  1027.       P_DestOfLink pDest = new DestOfLink;
  1028.       memset(pDest, 0, sizeof(DestOfLink));
  1029.       _floatingDest = (void*) pDest;
  1030.  
  1031.       pDest->link = link;
  1032.       pDest->containingFrame = facet->GetFrame(ev);
  1033.       pDest->info.change = pDest->link->GetUpdateID(ev);
  1034.       time(&pDest->info.creationTime);
  1035. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  1036.       pDest->info.kind = new char[strlen(result.selectedKind)+1];
  1037.       strcpy(pDest->info.kind,result.selectedKind);
  1038. #else
  1039.       pDest->info.kind = new char[strlen("Unknown")+1];
  1040.       strcpy(pDest->info.kind,"Unknown");
  1041. #endif
  1042.       //      pDest->info.autoUpdate = kODTrue; // revisit this LATER.
  1043.       pDest->info.autoUpdate = result.autoUpdateSetting;
  1044.       pDest->destinationPoint = *toWhere;
  1045.  
  1046.       pDest->link->RegisterDependent(ev, _fPartWrapper, kODUnknownUpdate);
  1047.  
  1048.       somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  1049.  
  1050.  
  1051.     }
  1052.     catch (...) {}
  1053.  
  1054.     return;
  1055. }
  1056.  
  1057.  
  1058. //--------------------------------------------------------------------------
  1059. // ODPart --> Drop
  1060. //
  1061. //      Should move or copy the dragged data into this part.
  1062. //
  1063. //      ->
  1064. //--------------------------------------------------------------------------
  1065.  
  1066. SOM_Scope       ODDropResult
  1067. SOMLINK         LinkContainerDrop
  1068.                 (
  1069.                 LinkContainer       *somSelf,   // in
  1070.                 Environment         *ev,        // in
  1071.                 ODDragItemIterator  *dropInfo,  // in
  1072.                 ODFacet             *facet,     // in
  1073.                 ODPoint             *where      // in
  1074.                 )
  1075. {
  1076.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1077.     LinkContainerMethodDebug("LinkContainer","LinkContainerDrop");
  1078.  
  1079.     ODDropResult        dropResult = kODDropFail;
  1080.     ODBoolean readOnly = (somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetPermissions(ev) == kODDPReadOnly);
  1081.  
  1082.     if (readOnly) {
  1083.        WARNMSG(WARN_INDEX(-1), "Document is read only. Drop is not accepted.");
  1084.        return dropResult;
  1085.     }
  1086.  
  1087.     if (facet->GetFrame (ev)->GetLinkStatus (ev) == kODInLinkDestination)
  1088.     {
  1089.        ODBoolean warnResult = ShowWarningForDest (facet, ev);
  1090.        return dropResult;
  1091.     }
  1092.  
  1093.   try {
  1094.  
  1095.     // Get proper attributes
  1096.  
  1097.     ODULong             attributes;
  1098.     attributes = _fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
  1099.  
  1100.     if (!(attributes & kODDropIsLink))
  1101.         return LinkContainer_parent_BaseContainer_Drop (somSelf, ev, dropInfo, facet, where);
  1102.  
  1103.     //show drop as dialog
  1104.  
  1105.     ODPasteAsResult result;
  1106.     ODTypeToken viewType = _fSession->Tokenize(ev, kODViewAsFrame);
  1107.     ODStorageUnit *dropSU = dropInfo->First(ev);
  1108.  
  1109. #if defined(_PLATFORM_OS2_)
  1110.  
  1111.           // some OS/2 specific stuff for drag-drop from WPShell
  1112.           if ( !dropSU->Exists(ev, kODPropContents, (ODValueType)kODDragitem, 0))
  1113.           {
  1114.              // nothing to process... (bug)
  1115.              return dropResult;
  1116.           } /* end if */
  1117.  
  1118.           // get the dragitem (actual pm structure)
  1119.           dropSU->Focus(ev, kODPropContents, kODPosUndefined, (ODValueType)kODDragitem, 0, kODPosUndefined);
  1120.  
  1121.           // create a view of our focused value for the drag manager
  1122.           ODStorageUnitView *dropView = dropSU->CreateView(ev);
  1123.  
  1124.           // ask the drag manager to get it for us
  1125.           if ( ! _fSession->GetDragAndDrop(ev)-> GetDataFromDragManager(ev,  dropView,
  1126.                                           &dropSU ) )
  1127.           {
  1128.              // error in transfer
  1129.              return dropResult;
  1130.           }
  1131. #endif
  1132.  
  1133.     if(!_fSession->GetDragAndDrop(ev)->ShowPasteAsDialog(ev, kODTrue,
  1134.                     kODPasteAsEmbedOnly, facet, viewType, dropSU, &result))
  1135.          return dropResult;
  1136.  
  1137.     if( result.pasteLinkSetting == kODFalse)
  1138.         return LinkContainer_parent_BaseContainer_Drop (somSelf, ev, dropInfo, facet, where);
  1139.  
  1140.     if (result.selectedKind == kODNULL) {
  1141.        WARNMSG (WARN_INDEX(-1), "No kind selected. Linking failed.");
  1142.        return dropResult;
  1143.     }
  1144.  
  1145.     // we need to drop-link
  1146.  
  1147.     ODDraft *myDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1148.     ODLinkSpec* linkSpec = myDraft->CreateLinkSpec(ev, kODNULL, kODNULL);
  1149.  
  1150.     dropSU->Focus(ev, kODPropLinkSpec, kODPosUndefined, kODNULL, 0, kODPosUndefined);
  1151.     linkSpec->ReadLinkSpec(ev, dropSU);
  1152.  
  1153.     ODLink *link = myDraft->AcquireLink(ev, kODNULLID, linkSpec);
  1154.  
  1155.     if (link == kODNULL) {
  1156.        WARNMSG (WARN_INDEX(-1), "Link Could not be acquired. Linking failed.");
  1157.        return dropResult;
  1158.     }
  1159.  
  1160.     // Create and fill DestinationOfLink structure
  1161.  
  1162.     P_DestOfLink pDest = new DestOfLink;
  1163.     memset(pDest, 0, sizeof(DestOfLink));
  1164.     _floatingDest = (void*) pDest;
  1165.  
  1166.     pDest->link = link;
  1167.     pDest->containingFrame = facet->GetFrame(ev);
  1168.     pDest->info.change = pDest->link->GetUpdateID(ev);
  1169.     time(&pDest->info.creationTime);
  1170.     pDest->info.kind = new char[strlen(result.selectedKind)+1];
  1171.     strcpy(pDest->info.kind,result.selectedKind);
  1172.     // pDest->info.autoUpdate = kODTrue; // revisit this LATER.
  1173.     pDest->info.autoUpdate = result.autoUpdateSetting;
  1174.     pDest->destinationPoint = *where;
  1175.  
  1176.     pDest->link->RegisterDependent(ev, _fPartWrapper, kODUnknownUpdate);
  1177.  
  1178.     somSelf->GetStorageUnit(ev)->GetDraft(ev)->SetChangedFromPrev(ev);
  1179.  
  1180.  
  1181.     dropResult = kODDropCopy;
  1182.  
  1183.   }
  1184.   catch (...) {}
  1185.  
  1186.   return dropResult;
  1187.  
  1188. }
  1189.  
  1190.  
  1191. //--------------------------------------------------------------------------
  1192. //  LinkContainer->GetAllLinkSources
  1193. //
  1194. //      ->
  1195. //--------------------------------------------------------------------------
  1196.  
  1197. SOM_Scope       void
  1198. SOMLINK         LinkContainerGetAllLinkSources
  1199.                 (
  1200.                 LinkContainer   *somSelf,       // in
  1201.                 Environment     *ev,             // in
  1202.                 ContentObject   *cObj,
  1203.                 ALinkedList     *l
  1204.                 )
  1205. {
  1206.  
  1207.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1208.     LinkContainerMethodDebug("LinkContainer","LinkContainerGetAllLinkSources");
  1209.  
  1210.     try {
  1211.  
  1212.     ALink *itr = kODNULL;
  1213.  
  1214.     for(itr = _fAllLinkSources->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1215.     {
  1216.          SourceOfLink *source = (SourceOfLink *) itr->Content(ev);
  1217.          int i;
  1218.          for (i = 0; i < source->num; i++) {
  1219.             if (source->sourceObjects[i] == cObj) {
  1220.                l->AddLast(ev, source);
  1221.                break;
  1222.             }
  1223.          }
  1224.     }
  1225.  
  1226.     }
  1227.     catch (...) {}
  1228.  
  1229. }
  1230.  
  1231.  
  1232.  
  1233. //--------------------------------------------------------------------------
  1234. //  LinkContainer->GetAllLinkDestinations
  1235. //
  1236. //      ->
  1237. //--------------------------------------------------------------------------
  1238.  
  1239. SOM_Scope       void
  1240. SOMLINK         LinkContainerGetAllLinkDestinations
  1241.                 (
  1242.                 LinkContainer   *somSelf,       // in
  1243.                 Environment     *ev,             // in
  1244.                 ContentObject   *cObj,
  1245.                 ALinkedList     *l
  1246.                 )
  1247. {
  1248.  
  1249.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1250.     LinkContainerMethodDebug("LinkContainer","LinkContainerGetAllLinkDestinations");
  1251.  
  1252.     try {
  1253.  
  1254.     ALink *itr = kODNULL;
  1255.  
  1256.     for(itr = _fAllLinkDestinations->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1257.     {
  1258.          DestOfLink *dest = (DestOfLink *) itr->Content(ev);
  1259.          int i;
  1260.          for (i = 0; i < dest->num; i++) {
  1261.             if (dest->destObjects[i] == cObj) {
  1262.                l->AddLast(ev, dest);
  1263.                break;
  1264.             }
  1265.          }
  1266.     }
  1267.  
  1268.     }
  1269.     catch (...) {}
  1270.  
  1271. }
  1272.  
  1273.  
  1274. //--------------------------------------------------------------------------
  1275. //  LinkContainer->BreakAllLinks
  1276. //
  1277. //      ->
  1278. //--------------------------------------------------------------------------
  1279.  
  1280. SOM_Scope       void
  1281. SOMLINK         LinkContainerBreakAllLinks
  1282.                 (
  1283.                 LinkContainer   *somSelf,       // in
  1284.                 Environment     *ev,             // in
  1285.                 ContentObject   *cObj
  1286.                 )
  1287. {
  1288.  
  1289.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1290.     LinkContainerMethodDebug("LinkContainer","LinkContainerBreakAllLinks");
  1291.  
  1292.     try {
  1293.  
  1294.        ALinkedList *l = new ALinkedList;
  1295.        ALink *itr;
  1296.  
  1297.        // break all the link sources
  1298.        somSelf->GetAllLinkSources(ev, cObj, l);
  1299.        for (itr = l->First(ev); itr->Content(ev); itr = itr->Next(ev))
  1300.        {
  1301.           SourceOfLink *source = (SourceOfLink *)itr->Content(ev);
  1302.           _fAllLinkSources->Remove (ev, source);
  1303.  
  1304.           source->linkSource->SetSourcePart (ev, kODNULL);
  1305.           source->linkSource->Release(ev);
  1306.  
  1307.           for (int i = 0; i < source->num; i++)
  1308.              source->sourceObjects[i]->_set_linkStatus (ev, kODNotInLink);
  1309.  
  1310.           delete source;
  1311.        }
  1312.  
  1313.        l->RemoveAll(ev);
  1314.  
  1315.        // break all the link destinations
  1316.        somSelf->GetAllLinkDestinations(ev, cObj, l);
  1317.        for (itr = l->First(ev); itr->Content(ev); itr = itr->Next(ev))
  1318.        {
  1319.           DestOfLink *dest = (DestOfLink *)itr->Content(ev);
  1320.           _fAllLinkDestinations->Remove (ev, dest);
  1321.  
  1322.           dest->link->Release(ev);
  1323.           dest->link->UnregisterDependent (ev, _fPartWrapper);
  1324.  
  1325.           for (int i = 0; i < dest->num; i++)
  1326.           {
  1327.              if (IsInLinkSource (ev, cObj, _fAllLinkDestinations))
  1328.                 dest->destObjects[i]->_set_linkStatus (ev, kODInLinkSource);
  1329.              else
  1330.                 dest->destObjects[i]->_set_linkStatus (ev, kODNotInLink);
  1331.           }
  1332.  
  1333.           delete dest;
  1334.        }
  1335.  
  1336.        delete l;
  1337.     }
  1338.     catch (...) {}
  1339.  
  1340. }
  1341.  
  1342.  
  1343. //--------------------------------------------------------------------------
  1344. //  LinkContainer->PropagateChangesToLinks
  1345. //
  1346. //      ->
  1347. //--------------------------------------------------------------------------
  1348.  
  1349. SOM_Scope       void
  1350. SOMLINK         LinkContainerChangeNotification
  1351.                 (
  1352.                 LinkContainer   *somSelf,       // in
  1353.                 Environment     *ev,            // in
  1354.                 ODULong          reason,
  1355.                 ODFrame         *frame,
  1356.                 ContentObject  *content,        // in
  1357.                 ODBoolean       bPropagate,     // in
  1358.                 ODUpdateID      updateID
  1359.                 )
  1360. {
  1361.  
  1362.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1363.     LinkContainerMethodDebug("LinkContainer","LinkContainerChangeNotification");
  1364.  
  1365.     try {
  1366.  
  1367.        if ((reason == BCC_EMBED) || (reason == BCC_DROP) || (reason == BCC_PASTE))
  1368.        {
  1369.           // If my frame is a link source, then make sure that all my embeds are too
  1370.           // If my frame is a destination, this code should not be reached
  1371.           // if my frame is not in link then leave the embeds as they are
  1372.           UpdateLinkStatusofEmbeds (ev, somSelf);
  1373.        }
  1374.  
  1375.        ODUpdateID id = updateID;
  1376.  
  1377.        if (content) {
  1378.  
  1379.           ALinkedList *allSources = new ALinkedList;
  1380.           somSelf->GetAllLinkSources (ev, content, allSources);
  1381.           ALink *itr = kODNULL;
  1382.  
  1383.           if (allSources->Count(ev) && !id)
  1384.              id = _fSession->UniqueUpdateID (ev);
  1385.  
  1386.           for(itr = allSources->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1387.           {
  1388.              SourceOfLink *source = (SourceOfLink *) itr->Content(ev);
  1389.          source->change = id;
  1390.          if (source->linkSource->IsAutoUpdate(ev))
  1391.            somSelf->WriteSingleLink (ev, (void*)source, id);
  1392.  
  1393.           }
  1394.           delete allSources;
  1395.  
  1396.        } // if content
  1397.  
  1398.        LinkContainer_parent_BaseContainer_ChangeNotification (somSelf, ev, reason, frame,
  1399.                                             content, bPropagate, id);
  1400.     }
  1401.     catch (...) {}
  1402.  
  1403. }
  1404.  
  1405.  
  1406. //--------------------------------------------------------------------------
  1407. //  LinkContainer->WriteSingleLink
  1408. //
  1409. //      ->
  1410. //--------------------------------------------------------------------------
  1411.  
  1412. SOM_Scope       void
  1413. SOMLINK         LinkContainerWriteSingleLink
  1414.                 (
  1415.                 LinkContainer   *somSelf,       // in
  1416.                 Environment     *ev,            // in
  1417.                 void            *sourceoflink,  // in
  1418.                 ODUpdateID     change)
  1419. {
  1420.  
  1421.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1422.     LinkContainerMethodDebug("LinkContainer","LinkContainerWriteSingleLink");
  1423.  
  1424.     ODLinkKey linkKey;
  1425.     SourceOfLink *source = (SourceOfLink*)sourceoflink;
  1426.     ODLinkSource *linkSource = source->linkSource;
  1427.     ODUpdateID previousID = linkSource->GetUpdateID(ev);
  1428.  
  1429.     try {
  1430.  
  1431.        if (linkSource->Lock(ev, 0, &linkKey) ) {
  1432.  
  1433.           //  Get and clear the linkSU
  1434.           linkSource->Clear(ev, change, linkKey);
  1435.           ODStorageUnit* toSU = linkSource->GetContentStorageUnit(ev, linkKey);
  1436.  
  1437.           // Write data
  1438.           if ((source->num == 1) && (source->sourceObjects[0]->_get_objType(ev) == COBJ_FRAMECLASS)) {
  1439.  
  1440.              ODFrame *frame = ((ContentFrame *)source->sourceObjects[0])->_get_myFrame(ev);
  1441.              somSelf->WriteSingleFrame (ev, frame, toSU, kODCloneToLink);
  1442.           }
  1443.           else {
  1444.  
  1445.              //Multiple selection case
  1446.              somSelf->WriteKindInfo (ev, toSU);
  1447.  
  1448.              BCCloneInfo cloneInfo;
  1449.              memset (&cloneInfo, 0, sizeof(BCCloneInfo));
  1450.              cloneInfo.refPoint = new ODPoint;
  1451.  
  1452.              // refPoint computation
  1453.              int i = 0;
  1454.              ODRect bbox = source->sourceObjects[0]->_get_boundingRect(ev);
  1455.              cloneInfo.refPoint->x = bbox.left;
  1456.              cloneInfo.refPoint->y = bbox.top;
  1457.  
  1458.              for (i=1; i<source->num; i++) {
  1459.                 bbox = source->sourceObjects[i]->_get_boundingRect(ev);
  1460.                 if (bbox.left < cloneInfo.refPoint->x)
  1461.                    cloneInfo.refPoint->x = bbox.left;
  1462. #if defined (_PLATFORM_WIN32_) || defined (_PLATFORM_UNIX_)
  1463.                 if (bbox.top < cloneInfo.refPoint->y)
  1464. #elif defined(_PLATFORM_OS2_)
  1465.                 if (bbox.top > cloneInfo.refPoint->y)
  1466. #endif
  1467.                    cloneInfo.refPoint->y = bbox.top;
  1468.              }
  1469.  
  1470.              // clone stuff
  1471.              ODDraft *fromDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1472.              ODDraftKey key = 0;
  1473.              key = fromDraft->BeginClone (ev, toSU->GetDraft(ev), kODNULL, kODCloneToLink);
  1474.              cloneInfo.key = key;
  1475.  
  1476.              ODSUAddPropValue (ev, toSU, kODPropEmbeddedFrames, kODStrongStorageUnitRef);
  1477.  
  1478.              ODSetULongProp (ev, toSU, kODNULL, kODNULL, source->num);
  1479.  
  1480.  
  1481.              for (i=0; i<source->num; i++) {
  1482.  
  1483.                 // Store the object type.
  1484.                 ODULong objType = source->sourceObjects[i]->_get_objType(ev);
  1485.                 ODSetULongProp (ev, toSU, kODNULL, kODNULL, objType);
  1486.  
  1487.                 // Write out the object.
  1488.                 source->sourceObjects[i]->WriteContents (ev, toSU, CLONE_SELECTED, &cloneInfo);
  1489.              }
  1490.  
  1491.              fromDraft->EndClone (ev, key);
  1492.  
  1493.  
  1494.           }
  1495.  
  1496.           // Propagate to target
  1497.           linkSource->ContentUpdated(ev, change, linkKey);
  1498.           linkSource->Unlock(ev, linkKey);
  1499.  
  1500.        } // end if Lock
  1501.  
  1502.     }
  1503.     catch (ODException _exception) {
  1504.  
  1505.         linkSource->Clear(ev, previousID, linkKey);
  1506.     }
  1507.  
  1508.  
  1509. }
  1510.  
  1511.  
  1512. //--------------------------------------------------------------------------
  1513. // ODPart --> LinkUpdated
  1514. //
  1515. //      Should replace the content at each destination of a link
  1516. //      with new content from the updated link object.
  1517. //
  1518. //      ->
  1519. //--------------------------------------------------------------------------
  1520.  
  1521. SOM_Scope       void
  1522. SOMLINK         LinkContainerLinkUpdated
  1523.                 (
  1524.                 LinkContainer   *somSelf,       // in
  1525.                 Environment     *ev,            // in
  1526.                 ODLink          *updatedLink,   // in
  1527.                 ODUpdateID       id             // in
  1528.                 )
  1529. {
  1530.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1531.     LinkContainerMethodDebug("LinkContainer","LinkContainerLinkUpdated");
  1532.  
  1533.     try {
  1534.  
  1535.     if (_floatingDest) {
  1536.  
  1537.        // This is the first link update
  1538.        if (updatedLink != ((DestOfLink*)_floatingDest)->link) {
  1539.           WARNMSG(WARN_INDEX(-1), "Unknown link passed in. Linking failed.");
  1540.           return;
  1541.        }
  1542.  
  1543.        ODLinkKey linkKey;
  1544.        ALinkedList *fEmbeddedObjects = somSelf->GetEmbeddedObjects(ev);
  1545.        DestOfLink *pDest = new DestOfLink;
  1546.        memcpy(pDest, _floatingDest, sizeof(DestOfLink));
  1547.  
  1548.        ODStorageUnit* fromSU = kODNULL;
  1549.        if (updatedLink->Lock(ev, 0, &linkKey) ) {
  1550.  
  1551.           try {
  1552.                fromSU = updatedLink->GetContentStorageUnit(ev, linkKey);
  1553.           }
  1554.           catch (ODException _exception) {
  1555.              int Error = ErrorCode();
  1556.              if (Error == kODErrNoLinkContent) {
  1557.                 SetErrorCodeEv(ev, kODNoError);
  1558.                 updatedLink->Unlock(ev, linkKey);
  1559.                 delete pDest;
  1560.                 return;
  1561.              }
  1562.              else
  1563.                 ODSetSOMException(ev, _exception);
  1564.           }  // end catch
  1565.  
  1566.           if (fromSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  1567.           {
  1568.              ODFrame *embeddedFrame = somSelf->ReadSingleFrame (ev,
  1569.                             FirstFacet(ev, pDest->containingFrame),
  1570.                             fromSU, kODCloneFromLink, &(pDest->destinationPoint));
  1571.  
  1572.              ContentFrame *newObject = new ContentFrame();
  1573.              newObject->_set_myFrame(ev, embeddedFrame);
  1574.              fEmbeddedObjects->AddLast (ev, (ODPtr)newObject);
  1575.              pDest->num = 1;
  1576.              pDest->destObjects = (ContentObject**) SOMMalloc (sizeof(ContentObject*));
  1577.              pDest->destObjects[0] = newObject;
  1578.              newObject->_set_linkStatus (ev, kODInLinkDestination);
  1579.           }
  1580.  
  1581.           else if (somSelf->ReadKindInfo(ev, fromSU))
  1582.                {
  1583.                   BCCloneInfo cloneInfo;
  1584.                   memset (&cloneInfo, 0, sizeof(BCCloneInfo));
  1585.  
  1586.                   ODDraft *toDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1587.                   ODDraft *fromDraft = fromSU->GetDraft(ev);
  1588.                   ODDraftKey key = 0;
  1589.                   key = fromDraft->BeginClone (ev, toDraft, kODNULL, kODCloneFromLink);
  1590.                   cloneInfo.key = key;
  1591.                   cloneInfo.refPoint = &(pDest->destinationPoint);
  1592.                   cloneInfo.myFrame = pDest->containingFrame;
  1593.  
  1594.                   if ( ODSUExistsThenFocus (ev, fromSU, kODPropEmbeddedFrames, kODStrongStorageUnitRef))
  1595.                   {
  1596.                      ODULong num = 0;
  1597.                      pDest->num = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1598.                      pDest->destObjects =(ContentObject**)SOMMalloc(sizeof(ContentObject*)* (pDest->num));
  1599.  
  1600.                      for (int i = 0; i < pDest->num; i++) {
  1601.  
  1602.                         ODULong objType = 0;
  1603.                         objType = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1604.  
  1605.                         ContentObject *contObj = 0;
  1606.                         somSelf->GetContentObjectFromObjType(ev, objType, &contObj);
  1607.                         if (contObj) {
  1608.                            contObj->ReadContents(ev, fromSU, CLONE_SELECTED, &cloneInfo);
  1609.                            fEmbeddedObjects->AddLast(ev, contObj);
  1610.                            pDest->destObjects[i] = contObj;
  1611.                            contObj->_set_linkStatus (ev, kODInLinkDestination);
  1612.                         }
  1613.                      } // end for
  1614.  
  1615.                   } // end if embeddedFrames
  1616.  
  1617.                   fromDraft->EndClone(ev, key);
  1618.  
  1619.                } // end if ReadKindInfo
  1620.  
  1621.           pDest->info.change     = updatedLink->GetUpdateID(ev);
  1622.           pDest->info.changeTime = updatedLink->GetChangeTime(ev);
  1623.           _fAllLinkDestinations->AddLast (ev, pDest);
  1624.           pDest->link->Unlock(ev, linkKey);
  1625.  
  1626.           pDest->containingFrame->ContentUpdated(ev, pDest->info.change);
  1627.           pDest->containingFrame->Invalidate (ev, kODNULL, kODNULL);
  1628.  
  1629.       // If the user specified a manual update, we honor that here.  The recipe says
  1630.       // that we should ignore it at first, to let the first update flow.  Now we
  1631.       // start to honor that manual update.
  1632.       if (!pDest->info.autoUpdate)
  1633.         pDest->link->UnregisterDependent(ev, _fPartWrapper);
  1634.  
  1635.           delete _floatingDest;
  1636.           _floatingDest = kODNULL;
  1637.  
  1638.        } // if link->Lock
  1639.  
  1640.        else {
  1641.           delete pDest;
  1642.        }
  1643.  
  1644.     }  // end first time update
  1645.  
  1646.     else {
  1647.  
  1648.        // Update link from an established link
  1649.        ALink* itr = kODNULL;
  1650.        DestOfLink *pDest = kODNULL;
  1651.  
  1652.        for(itr = _fAllLinkDestinations->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1653.        {
  1654.          if (((DestOfLink*) itr->Content(ev))->link == updatedLink)
  1655.             pDest = (DestOfLink*) itr->Content(ev);
  1656.        }
  1657.        if (!pDest) {
  1658.           WARNMSG (WARN_INDEX(-1), "Unknown Link. Linking Failed.");
  1659.           return;
  1660.        }
  1661.  
  1662.        ODLinkKey linkKey;
  1663.        if (updatedLink->Lock(ev, 0, &linkKey) ) {
  1664.  
  1665.           ODStorageUnit* fromSU = updatedLink->GetContentStorageUnit(ev, linkKey);
  1666.  
  1667.           if (fromSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  1668.           {
  1669.              if ((pDest->num != 1) || (pDest->destObjects[0]->_get_objType(ev) != COBJ_FRAMECLASS)) {
  1670.                 WARNMSG (WARN_INDEX(-1), "Link does not match.");
  1671.                 updatedLink->Unlock (ev, linkKey);
  1672.                 return;
  1673.              }
  1674.              pDest->destObjects[0]->DeleteContents(ev, OBJECT_DELETED);
  1675.              ODFrame *embeddedFrame = somSelf->ReadSingleFrame (ev,
  1676.                              FirstFacet (ev, pDest->containingFrame),
  1677.                              fromSU, kODCloneFromLink, &(pDest->destinationPoint));
  1678.              ((ContentFrame*)(pDest->destObjects[0]))->_set_myFrame (ev, embeddedFrame);
  1679.              pDest->destObjects[0]->_set_linkStatus (ev, kODInLinkDestination);
  1680.  
  1681.           }  // end if SingleFrame
  1682.  
  1683.           else if (somSelf->ReadKindInfo(ev, fromSU))
  1684.                {
  1685.                   BCCloneInfo cloneInfo;
  1686.                   memset (&cloneInfo, 0, sizeof(BCCloneInfo));
  1687.  
  1688.                   ODDraft *toDraft = somSelf->GetStorageUnit(ev)->GetDraft(ev);
  1689.                   ODDraft *fromDraft = fromSU->GetDraft(ev);
  1690.                   ODDraftKey key = 0;
  1691.                   key = fromDraft->BeginClone (ev, toDraft, kODNULL, kODCloneFromLink);
  1692.                   cloneInfo.key = key;
  1693.                   cloneInfo.refPoint = &(pDest->destinationPoint);
  1694.                   cloneInfo.myFrame = pDest->containingFrame;
  1695.  
  1696.                   if ( ODSUExistsThenFocus (ev, fromSU, kODPropEmbeddedFrames, kODStrongStorageUnitRef))
  1697.                   {
  1698.                      ODULong num = 0;
  1699.                      num = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1700.                      if (num != pDest->num) {
  1701.                         WARNMSG (WARN_INDEX(-1), "Links don't match. Linking failed.");
  1702.                         fromDraft->EndClone (ev, key);
  1703.                         pDest->link->Unlock (ev, linkKey);
  1704.                         return;
  1705.                      }
  1706.  
  1707.                      for (int i = 0; i < pDest->num; i++) {
  1708.  
  1709.                         ODULong objType = 0;
  1710.                         objType = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1711.                         pDest->destObjects[i]->DeleteContents(ev, OBJECT_DELETED);
  1712.                         pDest->destObjects[i]->ReadContents(ev, fromSU, CLONE_SELECTED, &cloneInfo);
  1713.                         pDest->destObjects[i]->_set_linkStatus (ev, kODInLinkDestination);
  1714.  
  1715.                      } // end for
  1716.  
  1717.                   } // end if embeddedFrames
  1718.  
  1719.                   fromDraft->EndClone (ev, key);
  1720.  
  1721.                } // end if ReadKindInfo
  1722.  
  1723.           pDest->info.change     = updatedLink->GetUpdateID(ev);
  1724.           pDest->info.changeTime = updatedLink->GetChangeTime(ev);
  1725.           pDest->link->Unlock(ev, linkKey);
  1726.  
  1727.           // notify the change but call parent only ONCE
  1728.           for (int i=0; i < pDest->num; i++)
  1729.              somSelf->ChangeNotification (ev, BCC_EMBEDUPDATED, kODNULL,
  1730.                    pDest->destObjects[i], ((pDest->num - i) == 1), pDest->info.change);
  1731.  
  1732.           pDest->containingFrame->Invalidate (ev, kODNULL, kODNULL);
  1733.  
  1734.        } // if link->Lock
  1735.  
  1736.     } // end if of linkUpdate
  1737.  
  1738.     }
  1739.     catch (...) {}
  1740. }
  1741.  
  1742.  
  1743.  
  1744.  
  1745. // -------------------------------------------------------------------------
  1746. // LinkContainer --> WriteContents
  1747. //
  1748. //      Writes part's content to storage.
  1749. //
  1750. //      -> This method is a private method of BaseContainer
  1751. //
  1752. // -------------------------------------------------------------------------
  1753. SOM_Scope       void
  1754. SOMLINK         LinkContainerWriteContents
  1755.                 (
  1756.                 LinkContainer   *somSelf,       // in
  1757.                 Environment     *ev,            // in
  1758.                 ODStorageUnit   *toSU,          // in
  1759.                 BCCloneInfo     *cloneInfo,
  1760.                 BCTransferKind  writeKind
  1761.                 )
  1762.  
  1763. {
  1764.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1765.     LinkContainerMethodDebug("LinkContainer", "LinkContainerWriteContents");
  1766.  
  1767.     LinkContainer_parent_BaseContainer_WriteContents(somSelf, ev, toSU, cloneInfo, writeKind);
  1768.  
  1769.     try {
  1770.  
  1771.        if (writeKind == CLONE_SELECTED) // copy or drag
  1772.           somSelf->WriteLinkSpec (ev, toSU);
  1773.  
  1774.        else if (writeKind == EXTERNALIZE) {
  1775.  
  1776. #if defined(_PLATFORM_OS2_) || defined(_PLATFORM_WIN32_)
  1777.  
  1778.           // Need to store links
  1779.           if (ODSUExistsThenFocus (ev, toSU, kLinkContainerLinkInfo, kODNULL))
  1780.              toSU->Remove (ev);
  1781.  
  1782.           ODULong numSources = _fAllLinkSources->Count(ev);
  1783.           ODULong numDestinations = _fAllLinkDestinations->Count(ev);
  1784.           if (!numSources && !numDestinations)
  1785.              return;
  1786.  
  1787.  
  1788.  
  1789.           // Store the number of sources and destinations
  1790.  
  1791.           ODSUAddPropValue (ev, toSU, kLinkContainerLinkInfo, kLinkContainerLinkCount);
  1792.           ODSetULongProp (ev, toSU, kODNULL, kODNULL, numSources);
  1793.           ODSetULongProp (ev, toSU, kODNULL, kODNULL, numDestinations);
  1794.  
  1795.           // Create the temp array for easy access to IDs
  1796.           ALinkedList *embeds = somSelf->GetEmbeddedObjects(ev);
  1797.           ALink *itr;
  1798.           ODULong numEmbeds = embeds->Count(ev);
  1799.           ContentObject **tmpArray = kODNULL;
  1800.           ODULong i=0;
  1801.           tmpArray = (ContentObject**) SOMMalloc (numEmbeds * sizeof (ContentObject*));
  1802.  
  1803.           for(itr = embeds->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1804.              tmpArray[i++] = (ContentObject *)itr->Content(ev);
  1805.  
  1806.  
  1807.           // Store the source info
  1808.  
  1809.           ODSUAddPropValue (ev, toSU, kLinkContainerLinkInfo, kLinkContainerLinkSources);
  1810.           for(itr = _fAllLinkSources->First(ev); itr->Content(ev); itr=itr->Next(ev)) {
  1811.  
  1812.              SourceOfLink *source = (SourceOfLink *)itr->Content(ev);
  1813.              ODSetStrongSURefProp (ev, toSU, kODNULL, kODNULL, source->linkSource->GetID(ev));
  1814.              ODSetULongProp (ev, toSU, kODNULL, kODNULL, source->num);
  1815.  
  1816.              // Store the IDs for content objects
  1817.              for (i = 0; i< source->num; i++) {
  1818.                 ODULong storID = GetIDForContentObject(source->sourceObjects[i], tmpArray, numEmbeds);
  1819.                 ODSetULongProp (ev, toSU, kODNULL, kODNULL, storID);
  1820.  
  1821.              } // end for
  1822.  
  1823.           }  // end for
  1824.  
  1825.           // Store the destination info
  1826.  
  1827.           ODSUAddPropValue (ev, toSU, kLinkContainerLinkInfo, kLinkContainerLinkDestinations);
  1828.           for(itr = _fAllLinkDestinations->First(ev); itr->Content(ev); itr=itr->Next(ev)) {
  1829.  
  1830.              DestOfLink *dest = (DestOfLink *)itr->Content(ev);
  1831.              ODSetStrongSURefProp (ev, toSU, kODNULL, kODNULL, dest->link->GetID(ev));
  1832.              ODSetULongProp (ev, toSU, kODNULL, kODNULL, dest->num);
  1833.  
  1834.              // Store the IDs for content objects
  1835.              ODULong i;
  1836.              for (i = 0; i< dest->num; i++) {
  1837.                 ODULong storID = GetIDForContentObject(dest->destObjects[i], tmpArray, numEmbeds);
  1838.                 ODSetULongProp (ev, toSU, kODNULL, kODNULL, storID);
  1839.  
  1840.              } // end for
  1841.  
  1842.              ODSetStrongSURefProp (ev, toSU, kODNULL, kODNULL, dest->containingFrame->GetID(ev));
  1843.              ODSetPointProp (ev, toSU, kODNULL, kODNULL, &(dest->destinationPoint));
  1844.              StorageUnitSetValue(toSU, ev, sizeof(ODLinkInfo), (ODValue)&(dest->info));
  1845.  
  1846.           }  // end for
  1847.  
  1848.           SOMFree (tmpArray);
  1849.  
  1850. #endif
  1851.        } // end if EXTERNALIZE
  1852.  
  1853.     }   // end try
  1854.     catch (...) {}
  1855.  
  1856. }
  1857.  
  1858.  
  1859.  
  1860. // -------------------------------------------------------------------------
  1861. // LinkContainer --> ReadContents
  1862. //
  1863. //      Reads part's content to storage.
  1864. //
  1865. // -------------------------------------------------------------------------
  1866. SOM_Scope       void
  1867. SOMLINK         LinkContainerReadContents
  1868.                 (
  1869.                 LinkContainer   *somSelf,       // in
  1870.                 Environment     *ev,            // in
  1871.                 ODStorageUnit   *fromSU,          // in
  1872.                 BCCloneInfo     *cloneInfo,
  1873.                 BCTransferKind  readKind
  1874.                 )
  1875.  
  1876. {
  1877.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  1878.     LinkContainerMethodDebug("LinkContainer", "LinkContainerReadContents");
  1879.  
  1880.     LinkContainer_parent_BaseContainer_ReadContents(somSelf, ev, fromSU, cloneInfo, readKind);
  1881.  
  1882.     try {
  1883.  
  1884.        if (readKind == INTERNALIZE) {
  1885.  
  1886.           if (ODSUExistsThenFocus (ev, fromSU, kLinkContainerLinkInfo, kLinkContainerLinkCount)) {
  1887.  
  1888.              ODULong numSources = 0, numDestinations = 0;
  1889.              ODULong i=0;
  1890.              numSources = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1891.              numDestinations = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1892.  
  1893.              // Create the tmpArray for easy access
  1894.              ALinkedList *embeds = somSelf->GetEmbeddedObjects(ev);
  1895.              ALink *itr;
  1896.              ODULong numEmbeds = embeds->Count(ev);
  1897.              ContentObject **tmpArray = kODNULL;
  1898.              tmpArray = (ContentObject**) SOMMalloc (numEmbeds * sizeof (ContentObject*));
  1899.  
  1900.              for(itr = embeds->First(ev); itr->Content(ev); itr=itr->Next(ev))
  1901.                 tmpArray[i++] = (ContentObject *)itr->Content(ev);
  1902.  
  1903.              // Restore the link sources
  1904.  
  1905.              if (ODSUExistsThenFocus (ev, fromSU, kLinkContainerLinkInfo, kLinkContainerLinkSources)) {
  1906.  
  1907.                 for (i = 0; i< numSources; i++) {
  1908.  
  1909.                    ODID linkSourceID = ODGetStrongSURefProp (ev, fromSU, kODNULL, kODNULL);
  1910.                    SourceOfLink *source = new SourceOfLink;
  1911.  
  1912.                    if (linkSourceID != kODNULLID) {
  1913.                       source->linkSource = fromSU->GetDraft(ev)->AcquireLinkSource(ev, linkSourceID);
  1914.                       source->linkSource->SetSourcePart(ev, somSelf->GetStorageUnit(ev));
  1915.                    }
  1916.                    else
  1917.                       WARNMSG(WARN_INDEX(-1), "Invalid SU reference.");
  1918.  
  1919.                    source->num = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1920.                    int numObj = 0;
  1921.                    source->sourceObjects = (ContentObject**) SOMMalloc (source->num *
  1922.                                                          sizeof (ContentObject*) );
  1923.                    for (numObj = 0; numObj < source->num; numObj++) {
  1924.                       ODULong id = 0;
  1925.                       id = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1926.                       source->sourceObjects[numObj] = tmpArray[id];
  1927.                       tmpArray[id]->_set_linkStatus (ev, kODInLinkSource);
  1928.                    } // end for
  1929.  
  1930.                    _fAllLinkSources->AddLast (ev, source);
  1931.  
  1932.                 }// end for of link sources
  1933.              } // end if sources present
  1934.  
  1935.              // Restore the link dests
  1936.  
  1937.              if (ODSUExistsThenFocus(ev,fromSU, kLinkContainerLinkInfo, kLinkContainerLinkDestinations)) {
  1938.  
  1939.                 for (i = 0; i< numDestinations; i++) {
  1940.  
  1941.                    ODID linkID = ODGetStrongSURefProp (ev, fromSU, kODNULL, kODNULL);
  1942.                    DestOfLink *dest = new DestOfLink;
  1943.  
  1944.                    if (linkID != kODNULLID) {
  1945.                       dest->link = fromSU->GetDraft(ev)->AcquireLink(ev, linkID, kODNULL);
  1946.                    }
  1947.                    else
  1948.                       WARNMSG(WARN_INDEX(-1), "Invalid destination SU reference.");
  1949.  
  1950.                    dest->num = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1951.                    int numObj = 0;
  1952.                    dest->destObjects = (ContentObject**) SOMMalloc (dest->num *
  1953.                                                          sizeof (ContentObject*) );
  1954.                    for (numObj = 0; numObj < dest->num; numObj++) {
  1955.                       ODULong id = 0;
  1956.                       id = ODGetULongProp (ev, fromSU, kODNULL, kODNULL);
  1957.                       dest->destObjects[numObj] = tmpArray[id];
  1958.                       tmpArray[id]->_set_linkStatus (ev, kODInLinkDestination);
  1959.                    } // end for
  1960.  
  1961.                    // Read in the frame, point, info etc..
  1962.                    ODID frameID = ODGetStrongSURefProp (ev, fromSU, kODNULL, kODNULL);
  1963.                    dest->containingFrame =
  1964.                       somSelf->GetStorageUnit(ev)->GetDraft(ev)->AcquireFrame(ev, frameID);
  1965.  
  1966.                    ODGetPointProp (ev, fromSU, kODNULL, kODNULL, &(dest->destinationPoint));
  1967.                    StorageUnitGetValue(fromSU, ev, sizeof(ODLinkInfo), &(dest->info));
  1968.  
  1969.                    _fAllLinkDestinations->AddLast (ev, dest);
  1970.                    // defect 25316: Need to add dest to _fAllLinkDests before registering
  1971.                    // it as a dependent (since LinkUpdated is called)
  1972.                    dest->link->RegisterDependent (ev, _fPartWrapper, dest->info.change);
  1973.  
  1974.                 } // end for of link dests
  1975.              } // end if dests present
  1976.  
  1977.              SOMFree (tmpArray);
  1978.  
  1979.           } // end if links present
  1980.        } // end if INTERNALIZE
  1981.  
  1982.     }   // end try
  1983.     catch (...) {}
  1984.  
  1985. }
  1986.  
  1987. // -------------------------------------------------------------------------
  1988. // LinkContainer --> WriteSingleFrame
  1989. //
  1990. //      Write a single embedded frame to destination unit.
  1991. //
  1992. //      -> This method is a private method of BaseContainer
  1993. //
  1994. // -------------------------------------------------------------------------
  1995. SOM_Scope       void
  1996. SOMLINK         LinkContainerWriteSingleFrame
  1997.                 (
  1998.                 LinkContainer   *somSelf,       // in
  1999.                 Environment     *ev,            // in
  2000.                 ODFrame         *embeddedFrame, // in
  2001.                 ODStorageUnit   *toSU,          // in
  2002.                 ODCloneKind     cloneKind
  2003.                 )
  2004.  
  2005. {
  2006.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2007.     LinkContainerMethodDebug("LinkContainer", "LinkContainerWriteSingleFrame");
  2008.  
  2009.     LinkContainer_parent_BaseContainer_WriteSingleFrame(somSelf, ev, embeddedFrame, toSU, cloneKind);
  2010.  
  2011.     try {
  2012.  
  2013.        if (cloneKind != kODCloneToLink)
  2014.           somSelf->WriteLinkSpec (ev, toSU);
  2015.     }
  2016.     catch (...) {}
  2017.  
  2018. }
  2019.  
  2020.  
  2021. //--------------------------------------------------------------------------
  2022. // ODPart --> AdjustMenus
  2023. //
  2024. //      Should prepare this part's menus for display.
  2025. //
  2026. //      ->
  2027. //--------------------------------------------------------------------------
  2028.  
  2029. SOM_Scope       void
  2030. SOMLINK         LinkContainerAdjustMenus
  2031.                 (
  2032.                 LinkContainer   *somSelf,       // in
  2033.                 Environment     *ev,            // in
  2034.                 ODFrame         *frame          // in
  2035.                 )
  2036. {
  2037.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2038.     LinkContainerMethodDebug("LinkContainer","LinkContainerAdjustMenus");
  2039.  
  2040.     if (frame->GetLinkStatus(ev) != kODInLinkDestination)
  2041.     {
  2042.        LinkContainer_parent_BaseContainer_AdjustMenus (somSelf, ev, frame);
  2043.        ODMenuBar *MenuBar = somSelf->GetMenuBar (ev);
  2044.        ODBoolean bEnable =_fSession->GetClipboard(ev)->CanEmbed(ev);
  2045.        bEnable &= (somSelf->GetStorageUnit(ev)->GetDraft(ev)->GetPermissions(ev) != kODDPReadOnly);
  2046.        MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTEAS, bEnable);
  2047.  
  2048.        MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_LINK_MENU, kODTrue);
  2049.  
  2050.        ALinkedList *allSelected = somSelf->GetSelectedObjects (ev);
  2051.        SourceOfLink *isLinkSource      = GetLinkSource(ev, allSelected, _fAllLinkSources);
  2052.        DestOfLink   *isLinkDestination = GetLinkDestination(ev, allSelected, _fAllLinkDestinations);
  2053.        MenuBar->EnableMenuItem(ev, EDIT_LINK_MENU, EDIT_LINKINFO, (isLinkSource || isLinkDestination) );
  2054.  
  2055.        return;
  2056.     }
  2057.  
  2058.     ODMenuBar *MenuBar = somSelf->GetMenuBar (ev);
  2059.     ODULong numSelected = somSelf->GetSelectedObjects(ev)->Count(ev);
  2060.     ODULong numEmbedded = somSelf->GetEmbeddedObjects(ev)->Count(ev);
  2061.  
  2062.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_SELECTALL,
  2063.                                          numEmbedded && (numSelected < numEmbedded));
  2064.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_DESELECTALL,
  2065.                                          numEmbedded && (numSelected == numEmbedded));
  2066.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_OPENSEL, numSelected);
  2067.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_SELPROPERTIES, numSelected == 1);
  2068.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_COPY, numSelected);
  2069.  
  2070.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, CMD(Move), kODFalse);
  2071.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, CMD(MoveFront), kODFalse);
  2072.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, CMD(MoveBack), kODFalse);
  2073.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, CMD(Resize), kODFalse);
  2074.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_DELETE, kODFalse);
  2075.  
  2076.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_CUT, kODFalse);
  2077.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_COPYLINKTO, kODFalse);
  2078.  
  2079.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTE, kODFalse);
  2080.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTEAS, kODFalse);
  2081.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTELINK, kODFalse);
  2082.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_PASTELINKFROM, kODFalse);
  2083.  
  2084.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_INSERT, kODFalse);
  2085.     MenuBar->EnableMenuItem(ev, IDMS_EDIT, EDIT_CREATE,      kODFalse);
  2086.  
  2087.     //enable our own menu items
  2088.     MenuBar->EnableMenuItem(ev, kODOptionsMenuID, CMD(ColorCHANGE), kODFalse);
  2089.     MenuBar->EnableMenu(ev, kODEmbedMenuID, kODFalse);
  2090. }
  2091.  
  2092. // -------------------------------------------------------------------------
  2093. // LinkContainer --> Initialize
  2094. //
  2095. //      Common code needed by the InitPart* methods.
  2096. //
  2097. // -------------------------------------------------------------------------
  2098.  
  2099. SOM_Scope       void
  2100. SOMLINK         LinkContainerInitialize
  2101.                 (
  2102.                 LinkContainer   *somSelf,       // in
  2103.                 Environment     *ev,             // in
  2104.                 ODPart          *partWrapper    // in
  2105.                 )
  2106. {
  2107.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2108.     LinkContainerMethodDebug("LinkContainer", "LinkContainerInitialize");
  2109.  
  2110.     LinkContainer_parent_BaseContainer_Initialize(somSelf, ev, partWrapper);
  2111.     _fPartWrapper = partWrapper;
  2112.     _fSession = somSelf->GetStorageUnit(ev)->GetSession(ev);
  2113.  
  2114.     _fAllLinkSources = new ALinkedList;
  2115.     _fAllLinkDestinations = new ALinkedList;
  2116.     _floatingDest = kODNULL;
  2117.  
  2118.     _fLastSavedList = kODNULL;
  2119.  
  2120. }
  2121.  
  2122. //--------------------------------------------------------------------------
  2123. // ODPart --> FrameShapeChanged
  2124. //
  2125. //--------------------------------------------------------------------------
  2126.  
  2127. SOM_Scope       void
  2128. SOMLINK         LinkContainerFrameShapeChanged
  2129.                 (
  2130.                 LinkContainer   *somSelf,       // in
  2131.                 Environment     *ev,            // in
  2132.                 ODFrame         *frame          // in
  2133.                 )
  2134. {
  2135.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2136.     LinkContainerMethodDebug("LinkContainer","LinkContainerFrameShapeChanged");
  2137.  
  2138.     // On OS/2 only, we have changed code so that for end-users
  2139.     // it looks as if embeds are anchored with top-left corner of parent
  2140.     // unlike bottom-left which is actually the origin for OS/2
  2141.     // We move embeds up or down when the container is resized
  2142.     // so that distance of embeds from top-left of container is same.
  2143.     // But when embeds are linked we also need to update linking info
  2144.     // when this happens.
  2145.  
  2146. #if defined (_PLATFORM_OS2_)
  2147.     ALinkedList *embeds = somSelf->GetEmbeddedObjects(ev);
  2148.     ContentObject *cObj = (ContentObject*) embeds->First(ev)->Content(ev);
  2149.     ODRect oldRect;
  2150.     if (cObj)
  2151.        oldRect = cObj->_get_boundingRect(ev);
  2152. #endif
  2153.  
  2154.     LinkContainer_parent_BaseContainer_FrameShapeChanged (somSelf, ev, frame);
  2155.  
  2156. #if defined (_PLATFORM_OS2_)
  2157.     if (cObj) {
  2158.        ODRect newRect = cObj->_get_boundingRect(ev);
  2159.        ODPoint offset = {newRect.left - oldRect.left, newRect.top - oldRect.top};
  2160.  
  2161.        if (offset.x || offset.y) {
  2162.  
  2163.            // Looks like embeds are moved. Updated linking info
  2164.            ALink *itr;
  2165.            for (itr = _fAllLinkDestinations->First(ev); itr->Content(ev) ; itr = itr->Next(ev)) {
  2166.               DestOfLink *dest = (DestOfLink *) itr->Content(ev);
  2167.               dest->destinationPoint.x += offset.x;
  2168.               dest->destinationPoint.y += offset.y;
  2169.            } /* endfor */
  2170.  
  2171.        } /* endif */
  2172.  
  2173.     } /* endif */
  2174. #endif
  2175.  
  2176. }
  2177.  
  2178.  
  2179. SOM_Scope void  SOMLINK LinkContainersomInit(LinkContainer *somSelf)
  2180. {
  2181.     /* LinkContainerData *somThis = LinkContainerGetData(somSelf); */
  2182.     LinkContainerMethodDebug("LinkContainer","LinkContainersomInit");
  2183.  
  2184.     LinkContainer_parent_BaseContainer_somInit(somSelf);
  2185. }
  2186.  
  2187. SOM_Scope void  SOMLINK LinkContainersomUninit(LinkContainer *somSelf)
  2188. {
  2189.     /* LinkContainerData *somThis = LinkContainerGetData(somSelf); */
  2190.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2191.     LinkContainerMethodDebug("LinkContainer","LinkContainersomUninit");
  2192.  
  2193.     ALink *itr;
  2194.     Environment *ev = somGetGlobalEnvironment();
  2195.     for(itr = _fAllLinkSources->First(ev); itr->Content(ev); itr=itr->Next(ev)) {
  2196.        SourceOfLink *source = (SourceOfLink *) itr->Content(ev);
  2197.        SOMFree (source->sourceObjects);
  2198.        delete source;
  2199.     }
  2200.     for(itr = _fAllLinkDestinations->First(ev); itr->Content(ev); itr=itr->Next(ev)) {
  2201.        DestOfLink *dest = (DestOfLink *) itr->Content(ev);
  2202.        SOMFree (dest->destObjects);
  2203.        delete dest;
  2204.     }
  2205.  
  2206.     delete _fAllLinkSources;
  2207.     delete _fAllLinkDestinations;
  2208.  
  2209.     LinkContainer_parent_BaseContainer_somUninit(somSelf);
  2210. }
  2211.  
  2212. //--------------------------------------------------------------------------
  2213. // LinkContainer --> HandleMenuEvent
  2214. //
  2215. //      Handle a menubar or pulldown menu selection event.
  2216. //
  2217. //      ->
  2218. //--------------------------------------------------------------------------
  2219.  
  2220. SOM_Scope       ODBoolean
  2221. SOMLINK         LinkContainerHandleMenuEvent
  2222.                 (
  2223.                 LinkContainer   *somSelf,       // in
  2224.                 Environment     *ev,            // in
  2225.                 ODFrame         *frame,         // in
  2226.                 ODEventData     *event          // in
  2227.                 )
  2228. {
  2229.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2230.     LinkContainerMethodDebug("LinkContainer","LinkContainerHandleMenuEvent");
  2231.  
  2232.  
  2233.     try {
  2234.  
  2235. #if   defined(_PLATFORM_UNIX_)
  2236.         ODMenuEventData* menu_event = (ODMenuEventData*) event;
  2237.         switch(menu_event->item)
  2238. #elif defined(_PLATFORM_WIN32_)
  2239.         switch(LOWORD(event->wParam)) // determine which menu pulldown it was
  2240. #elif defined(_PLATFORM_OS2_)
  2241.         switch(LONGFROMMP(event->mp1))
  2242. #endif
  2243.         {
  2244.             case CMD(LinkInfo):
  2245.           return somSelf->DoLinkInfo(ev, frame);
  2246.           break;
  2247.  
  2248.             default:
  2249.           return LinkContainer_parent_BaseContainer_HandleMenuEvent (somSelf, ev, frame, event);
  2250.     }
  2251.     }
  2252.  
  2253.     catch (...) {}
  2254.     return kODFalse;
  2255. }
  2256.  
  2257.  
  2258. //--------------------------------------------------------------------------
  2259. // LinkContainer --> DoLinkInfo
  2260. //
  2261. //      Handle a menubar or pulldown menu selection event.
  2262. //
  2263. //      ->
  2264. //--------------------------------------------------------------------------
  2265.  
  2266. SOM_Scope       ODBoolean
  2267. SOMLINK         LinkContainerDoLinkInfo
  2268.                 (
  2269.                 LinkContainer   *somSelf,       // in
  2270.                 Environment     *ev,            // in
  2271.                 ODFrame         *frame          // in
  2272.                 )
  2273. {
  2274.     LinkContainerData *somThis = LinkContainerGetData(somSelf);
  2275.     LinkContainerMethodDebug("LinkContainer","LinkContainerDoLinkInfo");
  2276.  
  2277.     SourceOfLink *source = kODNULL;
  2278.     DestOfLink   *dest = kODNULL;
  2279.     ODLinkInfoResult result;
  2280.     ODUpdateID     id;
  2281.  
  2282.     //    PRINT("Entered DoLinkInfo:");
  2283.     ALinkedList *allSelected = somSelf->GetSelectedObjects (ev);
  2284.  
  2285.     ODFrameFacetIterator* facets = frame->CreateFacetIterator(ev);
  2286.  
  2287.     if (source = GetLinkSource(ev, allSelected, _fAllLinkSources)) { 
  2288.       //PRINT("Selection is a link Source.\n");
  2289.       if (source->linkSource->ShowLinkSourceInfo(ev, facets->First(ev), source->change, kODTrue, &result)) {
  2290.  
  2291.     switch (result.action) {
  2292.     case kODLinkInfoBreakLink:
  2293.       // need to call somSelf->BreakAllLinks(ev, cObj);, but need to find the right content object to pass.
  2294.       somSelf->BreakAllLinks(ev, source->sourceObjects[0]);
  2295.       break;
  2296.  
  2297.     case kODLinkInfoUpdateNow:
  2298.       id =  _fSession->UniqueUpdateID(ev);
  2299.       source->change = id;
  2300.       somSelf->WriteSingleLink (ev, (void*)source, id);
  2301.       break;
  2302.  
  2303.     case kODLinkInfoOk:
  2304.       if (result.autoUpdate != source->linkSource->IsAutoUpdate(ev)) {
  2305.         source->linkSource->SetAutoUpdate(ev, result.autoUpdate);
  2306.         if (result.autoUpdate) { 
  2307.           // update now
  2308.           id =  _fSession->UniqueUpdateID(ev);
  2309.           source->change = id;
  2310.           somSelf->WriteSingleLink (ev, (void*)source, id);
  2311.         }
  2312.       }
  2313.       break;
  2314.  
  2315.     default:
  2316.       break;
  2317.         }
  2318.  
  2319.       }
  2320.     }
  2321.  
  2322.     else if (dest = GetLinkDestination(ev, allSelected, _fAllLinkDestinations)) {
  2323.       //PRINT("Selection is a link Destination.\n");
  2324.       if (dest->link->ShowLinkDestinationInfo(ev, facets->First(ev),&dest->info, kODTrue, &result)) {
  2325.  
  2326.     switch (result.action) {
  2327.     case kODLinkInfoFindSource:
  2328.       dest->link->ShowSourceContent(ev);
  2329.       break;
  2330.     case kODLinkInfoBreakLink:
  2331.       // need to call somSelf->BreakAllLinks(ev, cObj);, but need to find the right content object to pass.
  2332.       somSelf->BreakAllLinks(ev, dest->destObjects[0]);
  2333.       break;
  2334.     case kODLinkInfoUpdateNow:
  2335.             somSelf->LinkUpdated(ev, dest->link, dest->link->GetUpdateID(ev));
  2336.         break;
  2337.     case kODLinkInfoOk:
  2338.         if (result.autoUpdate != dest->info.autoUpdate) {
  2339.           dest->info.autoUpdate = result.autoUpdate;
  2340.           if (result.autoUpdate)
  2341.         dest->link->RegisterDependent(ev, _fPartWrapper, dest->info.change);
  2342.           else
  2343.         dest->link->UnregisterDependent(ev, _fPartWrapper);
  2344.         }
  2345.     default:
  2346.       break;
  2347.     }
  2348.       }
  2349.     }
  2350.     else
  2351.       PRINT("Selection is neither link Source nor link Destination!.\n");
  2352.     return kODTrue;
  2353. }
  2354.  
  2355.  
  2356. /*****************************************************************************
  2357.  M_LinkContainer clsGetODPartHandlerName( M_T3GamePart *somSelf,
  2358.                                   Environment *ev )
  2359. ******************************************************************************/
  2360.  
  2361. SOM_Scope ISOString  SOMLINK M_LinkContainerclsGetODPartHandlerName
  2362.                  (M_LinkContainer *somSelf,  Environment *ev)
  2363. {
  2364.     /* M_LinkContainerData *somThis = M_LinkContainerGetData(somSelf); */
  2365.     M_LinkContainerMethodDebug("M_LinkContainer","M_LinkContainerclsGetODPartHandlerName");
  2366.  
  2367.     string handlerName = (string)SOMMalloc(strlen(kPartHandlerName)+1);
  2368.     strcpy(handlerName,kPartHandlerName);
  2369.  
  2370.  
  2371.     return (ISOString) handlerName;
  2372. }
  2373.  
  2374. /*****************************************************************************
  2375.  M_LinkContainer --> clsGetODPartHandlerDisplayName( M_T3GamePart *somSelf,
  2376.                                   Environment *ev )
  2377. ******************************************************************************/
  2378.  
  2379. SOM_Scope string  SOMLINK M_LinkContainerclsGetODPartHandlerDisplayName(M_LinkContainer *somSelf,
  2380.                                                                          Environment *ev)
  2381. {
  2382.     /* M_LinkContainerData *somThis = M_LinkContainerGetData(somSelf); */
  2383.     M_LinkContainerMethodDebug("M_LinkContainer","M_LinkContainerclsGetODPartHandlerDisplayName");
  2384.  
  2385.     string handlerName = (string)SOMMalloc(strlen(kPartHandlerDisplayName)+1);
  2386.     strcpy(handlerName,kPartHandlerDisplayName);
  2387.  
  2388.  
  2389.     return (ISOString) handlerName;
  2390. }
  2391.  
  2392. /*****************************************************************************
  2393.  M_LinkContainer --> clsGetODPartKinds( M_T3GamePart *somSelf,
  2394.                                   Environment *ev )
  2395. ******************************************************************************/
  2396.  
  2397. SOM_Scope _IDL_SEQUENCE_PartKindInfo  SOMLINK M_LinkContainerclsGetODPartKinds(M_LinkContainer *somSelf,
  2398.                                                                                 Environment *ev)
  2399. {
  2400.     /* M_LinkContainerData *somThis = M_LinkContainerGetData(somSelf); */
  2401.     M_LinkContainerMethodDebug("M_LinkContainer","M_LinkContainerclsGetODPartKinds");
  2402.  
  2403.     _IDL_SEQUENCE_PartKindInfo partKindInfo;
  2404.  
  2405.     // Create structure PartKindInfo  and allocate memory for its fields
  2406.     PartKindInfo * info       =  (PartKindInfo *)SOMMalloc(sizeof(PartKindInfo));
  2407.     info->partKindName        =  (ISOString) SOMMalloc(strlen(kPartKindName) + 1);
  2408.     info->partKindDisplayName =  (string)SOMMalloc(strlen(kPartKindDisplayName)+1);
  2409.     info->filenameFilters     =  (string)SOMMalloc(strlen("")+1);
  2410.     info->filenameTypes       =  (string)SOMMalloc(strlen("")+1);
  2411.     info->categories          =  (string)SOMMalloc(strlen(kPartCategory)+1);
  2412.     info->categoryDisplayName =  (string)SOMMalloc(strlen(kPartCategory)+1);
  2413.     info->objectID            =  (string)SOMMalloc(strlen("")+1);
  2414.  
  2415.     // Copy the information into the structure
  2416.     strcpy(info->partKindName , kPartKindName);
  2417.     strcpy(info->partKindDisplayName, kPartKindDisplayName);
  2418.     strcpy(info->filenameFilters, "");
  2419.     strcpy(info->filenameTypes, "");
  2420.     strcpy(info->categories, kPartCategory);
  2421.     strcpy(info->categoryDisplayName, kPartCategory);
  2422.     strcpy(info->objectID, "");
  2423.  
  2424.     partKindInfo._maximum = 1;
  2425.     partKindInfo._length = 1;
  2426.     partKindInfo._buffer = info;
  2427.  
  2428.  
  2429.  
  2430.     return partKindInfo;
  2431. }
  2432.  
  2433. /*****************************************************************************
  2434.  M_LinkContainer --> clsGetODPartGetOLE2ClassID( M_T3GamePart *somSelf,
  2435.                                   Environment *ev )
  2436. ******************************************************************************/
  2437.  
  2438. SOM_Scope string  SOMLINK M_LinkContainerclsGetOLE2ClassId(M_LinkContainer *somSelf,
  2439.                                                             Environment *ev)
  2440. {
  2441.     /* M_LinkContainerData *somThis = M_LinkContainerGetData(somSelf); */
  2442.     M_LinkContainerMethodDebug("M_LinkContainer","M_LinkContainerclsGetOLE2ClassId");
  2443.  
  2444.     char *kID = "{51f39360-faeb-11cf-ad1b-08005ac0ff26}";
  2445.  
  2446.     string OLE2ClassID = (string)SOMMalloc(strlen(kID)+1);
  2447.     strcpy(OLE2ClassID,kID);
  2448.  
  2449.     return OLE2ClassID;
  2450. }
  2451.  
  2452. /*****************************************************************************
  2453.  M_LinkContainer --> clsGetODPartGetWindowsIconFileName ( M_T3GamePart *somSelf,
  2454.                                   Environment *ev )
  2455. ******************************************************************************/
  2456.  
  2457. SOM_Scope string  SOMLINK M_LinkContainerclsGetWindowsIconFileName(M_LinkContainer *somSelf,
  2458.                                                                     Environment *ev)
  2459. {
  2460.     /* M_LinkContainerData *somThis = M_LinkContainerGetData(somSelf); */
  2461.     M_LinkContainerMethodDebug("M_LinkContainer","M_LinkContainerclsGetWindowsIconFileName");
  2462.  
  2463.     string windowsIcon = (string)SOMMalloc(strlen(kWindowsIcon)+1);
  2464.     strcpy(windowsIcon,kWindowsIcon);
  2465.  
  2466.     return windowsIcon;
  2467. }
  2468.