home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWPasta.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.1 KB  |  214 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPasta.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9. #include "FWFrameW.hpp"
  10.  
  11. #ifndef FWPASTA_H
  12. #include "FWPasta.h"
  13. #endif
  14.  
  15. #ifndef FWFRAME_H
  16. #include "FWFrame.h"
  17. #endif
  18.  
  19. #ifndef FWINTER_H
  20. #include "FWInter.h"
  21. #endif
  22.  
  23. #ifndef FWPART_H
  24. #include "FWPart.h"
  25. #endif
  26.  
  27. #ifndef FWPRESEN_H
  28. #include "FWPresen.h"
  29. #endif
  30.  
  31. #ifndef FWSELECT_H
  32. #include "FWSelect.h"
  33. #endif
  34.  
  35. #ifndef FWLNKMGR_H
  36. #include "FWLnkMgr.h"
  37. #endif
  38.  
  39. #ifndef FWLNKCMD_H
  40. #include "FWLnkCmd.h"
  41. #endif
  42.  
  43. // ----- OpenDoc Includes -----
  44.  
  45. #ifndef SOM_ODClipboard_xh
  46. #include <Clipbd.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODDragAndDrop_xh
  50. #include <DragDrp.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODSession_xh
  54. #include <ODSessn.xh>
  55. #endif
  56.  
  57. //========================================================================================
  58. //    RunTime Info
  59. //========================================================================================
  60.  
  61. #ifdef FW_BUILD_MAC
  62. #pragma segment odflinking
  63. #endif
  64.  
  65. //========================================================================================
  66. //    class FW_MPasteAsHandler
  67. //========================================================================================
  68.  
  69. //----------------------------------------------------------------------------------------
  70. //    FW_MPasteAsHandler constructor
  71. //----------------------------------------------------------------------------------------
  72.  
  73. FW_MPasteAsHandler::FW_MPasteAsHandler(Environment *ev, FW_CFrame* frame)
  74. :    fNewLink(NULL),
  75.     fPrivFrame(frame)
  76. {
  77. FW_UNUSED(ev);
  78.     fEmbedInfo.mergeSetting = kODTrue;    // default setting
  79.     fEmbedInfo.selectedKind = NULL;
  80.     fEmbedInfo.translateKind = NULL;
  81.     fEmbedInfo.editor = NULL;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. //    FW_MPasteAsHandler destructor
  86. //----------------------------------------------------------------------------------------
  87.  
  88. FW_MPasteAsHandler::~FW_MPasteAsHandler()
  89. {
  90.     //--- Dispose of fEmbedInfo pointer fields
  91.  
  92.     if (fEmbedInfo.selectedKind != kODNULL)
  93.         ODDisposePtr(fEmbedInfo.selectedKind);
  94.     
  95.     if (fEmbedInfo.translateKind != kODNULL)
  96.         ODDisposePtr(fEmbedInfo.translateKind);
  97.     
  98.     if (fEmbedInfo.editor != kODNULL)
  99.         ODDisposePtr(fEmbedInfo.editor);
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    FW_MPasteAsHandler::HandlePasteAsDialog - clipboard version
  104. //----------------------------------------------------------------------------------------
  105.  
  106. FW_Boolean FW_MPasteAsHandler::HandlePasteAsDialog(Environment* ev, ODCloneKind cloneKind,
  107.                                                    FW_Boolean& handledIt)
  108. {
  109.     FW_Boolean result = FALSE;
  110.     ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
  111.     ODBoolean canPasteLink = FALSE;
  112.     FW_CLinkManager* linkMgr = fPrivFrame->GetPart(ev)->GetLinkManager(ev);
  113.  
  114.     ODClipboard* clipboard = fPrivFrame->GetPart(ev)->GetSession(ev)->GetClipboard(ev);
  115.     ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
  116.  
  117.     // ---- Check whether the selection supports linking ----
  118.     if (linkMgr && fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, clipboardSU))
  119.         canPasteLink = TRUE;
  120.  
  121.     // ---- Display the Paste As... dialog ----
  122.     result = clipboard->ShowPasteAsDialog(ev, canPasteLink, mergeSetting, 
  123.                                           fPrivFrame->GetActiveFacet(ev),    // facet from which dialog is triggered
  124.                                           fPrivFrame->GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev),        // viewType of data
  125.                                           GetEmbedInfoPtr(ev));
  126.  
  127.     if (result == kODFalse)
  128.         handledIt = TRUE;                // we tried, but the user cancelled
  129.     else
  130.         result = this->PostPasteAsDialog(ev, clipboardSU, FW_kClipboardStorage, cloneKind, handledIt);
  131.  
  132.     return result;
  133. }
  134.  
  135. //----------------------------------------------------------------------------------------
  136. //    FW_MPasteAsHandler::HandleDropPasteAsDialog - drag&drop version
  137. //----------------------------------------------------------------------------------------
  138.  
  139. FW_Boolean FW_MPasteAsHandler::HandleDropPasteAsDialog(Environment* ev, ODStorageUnit* dropSU,
  140.                                                        FW_Boolean& handledDrop)
  141. {
  142.     FW_Boolean result = FALSE;
  143.     ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
  144.     ODBoolean canPasteLink = FALSE;
  145.     FW_CLinkManager* linkMgr = fPrivFrame->GetPart(ev)->GetLinkManager(ev);
  146.  
  147.     // ---- Check whether the selection supports linking ----
  148.     if (linkMgr && fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, dropSU))
  149.         canPasteLink = TRUE;
  150.  
  151.     // ---- Display the Paste As... dialog ----
  152.     ODDragAndDrop* drag = fPrivFrame->GetPart(ev)->GetSession(ev)->GetDragAndDrop(ev);
  153.     result = drag->ShowPasteAsDialog(ev, canPasteLink, mergeSetting, 
  154.                                      fPrivFrame->GetActiveFacet(ev),    // facet from which dialog is triggered
  155.                                      fPrivFrame->GetViewType(ev),        // viewType of data
  156.                                      dropSU, GetEmbedInfoPtr(ev));
  157.  
  158.     if (result == kODFalse)
  159.         handledDrop = TRUE;            // we tried, but the user cancelled
  160.     else
  161.         result = this->PostPasteAsDialog(ev, dropSU, FW_kDragAndDropStorage, kODCloneDropCopy, handledDrop);
  162.  
  163.     return result;
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_MPasteAsHandler::PostPasteAsDialog
  168. //----------------------------------------------------------------------------------------
  169. FW_Boolean FW_MPasteAsHandler::PostPasteAsDialog(Environment* ev, 
  170.                                                  ODStorageUnit* storageUnit, 
  171.                                                  FW_EStorageKinds storageKind,
  172.                                                  ODCloneKind cloneKind, 
  173.                                                  FW_Boolean& handledIt)
  174. {
  175.     FW_Boolean result = TRUE;
  176.  
  177.     // --- Figure out what to do depending on settings from the Paste As dialog
  178.     if (fEmbedInfo.pasteLinkSetting == kODTrue)        // user wants to create a Link
  179.     {
  180.         FW_CLinkManager* linkMgr = fPrivFrame->GetPart(ev)->GetLinkManager(ev);
  181.         fNewLink = linkMgr->PasteWithLink(ev, storageUnit, fEmbedInfo, fPrivFrame, storageKind);
  182.         result = (fNewLink != NULL);
  183.         handledIt = TRUE;
  184.     }
  185.     else if (fEmbedInfo.mergeSetting == kODFalse)    // user wants to embed w/o Linking
  186.     {
  187.         result = this->PasteAsEmbed(ev, storageUnit, storageKind, cloneKind);
  188.         handledIt = TRUE;
  189.     }
  190.     else     // Merge with Contents - let Drag&Drop or clipboard command handle this
  191.         handledIt = FALSE;
  192.  
  193.     return result;
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    FW_MPasteAsHandler::PasteAsEmbed
  198. //----------------------------------------------------------------------------------------
  199. FW_Boolean FW_MPasteAsHandler::PasteAsEmbed(Environment* ev, 
  200.                                             ODStorageUnit* storageUnit, 
  201.                                             FW_EStorageKinds storageKind,
  202.                                             ODCloneKind cloneKind)
  203. {
  204.     // User wants to Embed the data, with or without translation
  205.     FW_Boolean result = false;
  206.  
  207.     FW_CPart* part = fPrivFrame->GetPart(ev);    
  208.     FW_CSelection* selection = fPrivFrame->GetPresentation(ev)->GetSelection(ev);
  209.     result = (part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), fPrivFrame, storageUnit, storageKind, cloneKind, GetEmbedInfoPtr(ev)) != FW_kInternalizeFailed);
  210.  
  211.     return result;
  212. }
  213.  
  214.