home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWPasta.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.3 KB  |  224 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPasta.cpp
  4. //    Release Version:    $ ODF 2 $
  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. #ifndef FWSESION_H
  44. #include "FWSesion.h"
  45. #endif
  46.  
  47. #ifndef FWMEMMGR_H
  48. #include "FWMemMgr.h"
  49. #endif
  50.  
  51. // ----- OpenDoc Includes -----
  52.  
  53. #ifndef SOM_ODClipboard_xh
  54. #include <Clipbd.xh>
  55. #endif
  56.  
  57. #ifndef SOM_ODDragAndDrop_xh
  58. #include <DragDrp.xh>
  59. #endif
  60.  
  61. //========================================================================================
  62. //    RunTime Info
  63. //========================================================================================
  64.  
  65. #ifdef FW_BUILD_MAC
  66. #pragma segment odflinking
  67. #endif
  68.  
  69. //========================================================================================
  70. //    class FW_MPasteAsHandler
  71. //========================================================================
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_MPasteAsHandler constructor
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_MPasteAsHandler::FW_MPasteAsHandler(Environment *ev, FW_CFrame* frame)
  78. :    fNewLink(NULL),
  79.     fPrivFrame(frame)
  80. {
  81. FW_UNUSED(ev);
  82.     fEmbedInfo.mergeSetting = kODTrue;    // default setting
  83.     fEmbedInfo.selectedKind = NULL;
  84.     fEmbedInfo.translateKind = NULL;
  85.     fEmbedInfo.editor = NULL;
  86. }
  87.  
  88. //----------------------------------------------------------------------------------------
  89. //    FW_MPasteAsHandler destructor
  90. //----------------------------------------------------------------------------------------
  91.  
  92. FW_MPasteAsHandler::~FW_MPasteAsHandler()
  93. {
  94.     //--- Dispose of fEmbedInfo pointer fields
  95.     PrivDisposeEmbedInfoFields(&fEmbedInfo);
  96. }
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    FW_MPasteAsHandler::PrivDisposeEmbedInfoFields
  100. //----------------------------------------------------------------------------------------
  101.  
  102. void FW_MPasteAsHandler::PrivDisposeEmbedInfoFields(ODPasteAsResult* embedInfo)
  103. {
  104.     FW_ASSERT(embedInfo != NULL);
  105.     
  106.     if (embedInfo->selectedKind != kODNULL)
  107.         FW_CMemoryManager::FreeBlock(embedInfo->selectedKind);
  108.  
  109.     if (embedInfo->translateKind != kODNULL)
  110.         FW_CMemoryManager::FreeBlock(embedInfo->translateKind);
  111.  
  112.     if (embedInfo->editor != kODNULL)
  113.         FW_CMemoryManager::FreeBlock(embedInfo->editor);
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_MPasteAsHandler::HandlePasteAsDialog - clipboard version
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_Boolean FW_MPasteAsHandler::HandlePasteAsDialog(Environment* ev, ODCloneKind cloneKind,
  121.                                                    FW_Boolean& handledIt)
  122. {
  123.     FW_Boolean result = FALSE;
  124.     ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
  125.     ODBoolean canPasteLink = FALSE;
  126.  
  127.     ODClipboard* clipboard = FW_CSession::GetClipboard(ev);
  128.     ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
  129.  
  130.     // ---- Check whether the selection supports linking ----
  131.     canPasteLink = fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, clipboardSU);
  132.  
  133.     // ---- Display the Paste As... dialog ----
  134.     result = clipboard->ShowPasteAsDialog(ev, canPasteLink, mergeSetting, 
  135.                                           fPrivFrame->GetActiveFacet(ev),    // facet from which dialog is triggered
  136.                                           fPrivFrame->GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev),        // viewType of data
  137.                                           GetEmbedInfoPtr(ev));
  138.  
  139.     if (result == kODFalse)
  140.         handledIt = TRUE;                // we tried, but the user cancelled
  141.     else
  142.         result = this->PostPasteAsDialog(ev, clipboardSU, FW_kClipboardStorage, cloneKind, handledIt);
  143.  
  144.     return result;
  145. }
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    FW_MPasteAsHandler::HandleDropPasteAsDialog - drag&drop version
  149. //----------------------------------------------------------------------------------------
  150.  
  151. FW_Boolean FW_MPasteAsHandler::HandleDropPasteAsDialog(Environment* ev, ODStorageUnit* dropSU,
  152.                                                        FW_Boolean& handledDrop)
  153. {
  154.     FW_Boolean result = FALSE;
  155.     ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
  156.     ODBoolean canPasteLink = FALSE;
  157.  
  158.     // ---- Check whether the selection supports linking ----
  159.     canPasteLink = fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, dropSU);
  160.  
  161.     // ---- Display the Paste As... dialog ----
  162.     ODDragAndDrop* drag = FW_CSession::GetDragAndDrop(ev);
  163.     result = drag->ShowPasteAsDialog(ev, canPasteLink, mergeSetting, 
  164.                                      fPrivFrame->GetActiveFacet(ev),    // facet from which dialog is triggered
  165.                                      fPrivFrame->GetViewType(ev),        // viewType of data
  166.                                      dropSU, GetEmbedInfoPtr(ev));
  167.  
  168.     if (result == kODFalse)
  169.         handledDrop = TRUE;            // we tried, but the user cancelled
  170.     else
  171.         result = this->PostPasteAsDialog(ev, dropSU, FW_kDragAndDropStorage, kODCloneDropCopy, handledDrop);
  172.  
  173.     return result;
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_MPasteAsHandler::PostPasteAsDialog
  178. //----------------------------------------------------------------------------------------
  179. FW_Boolean FW_MPasteAsHandler::PostPasteAsDialog(Environment* ev, 
  180.                                                  ODStorageUnit* storageUnit, 
  181.                                                  FW_StorageKinds storageKind,
  182.                                                  ODCloneKind cloneKind, 
  183.                                                  FW_Boolean& handledIt)
  184. {
  185.     FW_Boolean result = TRUE;
  186.  
  187.     // --- Figure out what to do depending on settings from the Paste As dialog
  188.     if (fEmbedInfo.pasteLinkSetting == kODTrue)        // user wants to create a Link
  189.     {
  190.         FW_CLinkManager* linkMgr = fPrivFrame->GetPart(ev)->GetLinkManager(ev);
  191.         fNewLink = linkMgr->PasteWithLink(ev, storageUnit, fEmbedInfo, fPrivFrame, storageKind);
  192.         result = (fNewLink != NULL);
  193.         handledIt = TRUE;
  194.     }
  195.     else if (fEmbedInfo.mergeSetting == kODFalse)    // user wants to embed w/o Linking
  196.     {
  197.         result = this->PasteAsEmbed(ev, storageUnit, storageKind, cloneKind);
  198.         handledIt = TRUE;
  199.     }
  200.     else     // Merge with Contents - let Drag&Drop or clipboard command handle this
  201.         handledIt = FALSE;
  202.  
  203.     return result;
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. //    FW_MPasteAsHandler::PasteAsEmbed
  208. //----------------------------------------------------------------------------------------
  209. FW_Boolean FW_MPasteAsHandler::PasteAsEmbed(Environment* ev, 
  210.                                             ODStorageUnit* storageUnit, 
  211.                                             FW_StorageKinds storageKind,
  212.                                             ODCloneKind cloneKind)
  213. {
  214.     // User wants to Embed the data, with or without translation
  215.     FW_Boolean result = false;
  216.  
  217.     FW_CPart* part = fPrivFrame->GetPart(ev);    
  218.     FW_CSelection* selection = fPrivFrame->GetPresentation(ev)->GetSelection(ev);
  219.     result = (part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), fPrivFrame, storageUnit, storageKind, cloneKind, GetEmbedInfoPtr(ev)) != FW_kInternalizeFailed);
  220.  
  221.     return result;
  222. }
  223.  
  224.