home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 7.3 KB | 224 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWPasta.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
- #include "FWFrameW.hpp"
-
- #ifndef FWPASTA_H
- #include "FWPasta.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWINTER_H
- #include "FWInter.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWLNKCMD_H
- #include "FWLnkCmd.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODClipboard_xh
- #include <Clipbd.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odflinking
- #endif
-
- //========================================================================================
- // class FW_MPasteAsHandler
- //=============================== ==== ==== ==== =============================
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler constructor
- //----------------------------------------------------------------------------------------
-
- FW_MPasteAsHandler::FW_MPasteAsHandler(Environment *ev, FW_CFrame* frame)
- : fNewLink(NULL),
- fPrivFrame(frame)
- {
- FW_UNUSED(ev);
- fEmbedInfo.mergeSetting = kODTrue; // default setting
- fEmbedInfo.selectedKind = NULL;
- fEmbedInfo.translateKind = NULL;
- fEmbedInfo.editor = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler destructor
- //----------------------------------------------------------------------------------------
-
- FW_MPasteAsHandler::~FW_MPasteAsHandler()
- {
- //--- Dispose of fEmbedInfo pointer fields
- PrivDisposeEmbedInfoFields(&fEmbedInfo);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler::PrivDisposeEmbedInfoFields
- //----------------------------------------------------------------------------------------
-
- void FW_MPasteAsHandler::PrivDisposeEmbedInfoFields(ODPasteAsResult* embedInfo)
- {
- FW_ASSERT(embedInfo != NULL);
-
- if (embedInfo->selectedKind != kODNULL)
- FW_CMemoryManager::FreeBlock(embedInfo->selectedKind);
-
- if (embedInfo->translateKind != kODNULL)
- FW_CMemoryManager::FreeBlock(embedInfo->translateKind);
-
- if (embedInfo->editor != kODNULL)
- FW_CMemoryManager::FreeBlock(embedInfo->editor);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler::HandlePasteAsDialog - clipboard version
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MPasteAsHandler::HandlePasteAsDialog(Environment* ev, ODCloneKind cloneKind,
- FW_Boolean& handledIt)
- {
- FW_Boolean result = FALSE;
- ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
- ODBoolean canPasteLink = FALSE;
-
- ODClipboard* clipboard = FW_CSession::GetClipboard(ev);
- ODStorageUnit* clipboardSU = clipboard->GetContentStorageUnit(ev);
-
- // ---- Check whether the selection supports linking ----
- canPasteLink = fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, clipboardSU);
-
- // ---- Display the Paste As... dialog ----
- result = clipboard->ShowPasteAsDialog(ev, canPasteLink, mergeSetting,
- fPrivFrame->GetActiveFacet(ev), // facet from which dialog is triggered
- fPrivFrame->GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev), // viewType of data
- GetEmbedInfoPtr(ev));
-
- if (result == kODFalse)
- handledIt = TRUE; // we tried, but the user cancelled
- else
- result = this->PostPasteAsDialog(ev, clipboardSU, FW_kClipboardStorage, cloneKind, handledIt);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler::HandleDropPasteAsDialog - drag&drop version
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MPasteAsHandler::HandleDropPasteAsDialog(Environment* ev, ODStorageUnit* dropSU,
- FW_Boolean& handledDrop)
- {
- FW_Boolean result = FALSE;
- ODPasteAsMergeSetting mergeSetting = kODPasteAsMergeOnly;
- ODBoolean canPasteLink = FALSE;
-
- // ---- Check whether the selection supports linking ----
- canPasteLink = fPrivFrame->GetPresentation(ev)->GetSelection(ev)->CanPasteAsLink(ev, mergeSetting, dropSU);
-
- // ---- Display the Paste As... dialog ----
- ODDragAndDrop* drag = FW_CSession::GetDragAndDrop(ev);
- result = drag->ShowPasteAsDialog(ev, canPasteLink, mergeSetting,
- fPrivFrame->GetActiveFacet(ev), // facet from which dialog is triggered
- fPrivFrame->GetViewType(ev), // viewType of data
- dropSU, GetEmbedInfoPtr(ev));
-
- if (result == kODFalse)
- handledDrop = TRUE; // we tried, but the user cancelled
- else
- result = this->PostPasteAsDialog(ev, dropSU, FW_kDragAndDropStorage, kODCloneDropCopy, handledDrop);
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler::PostPasteAsDialog
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_MPasteAsHandler::PostPasteAsDialog(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_StorageKinds storageKind,
- ODCloneKind cloneKind,
- FW_Boolean& handledIt)
- {
- FW_Boolean result = TRUE;
-
- // --- Figure out what to do depending on settings from the Paste As dialog
- if (fEmbedInfo.pasteLinkSetting == kODTrue) // user wants to create a Link
- {
- FW_CLinkManager* linkMgr = fPrivFrame->GetPart(ev)->GetLinkManager(ev);
- fNewLink = linkMgr->PasteWithLink(ev, storageUnit, fEmbedInfo, fPrivFrame, storageKind);
- result = (fNewLink != NULL);
- handledIt = TRUE;
- }
- else if (fEmbedInfo.mergeSetting == kODFalse) // user wants to embed w/o Linking
- {
- result = this->PasteAsEmbed(ev, storageUnit, storageKind, cloneKind);
- handledIt = TRUE;
- }
- else // Merge with Contents - let Drag&Drop or clipboard command handle this
- handledIt = FALSE;
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MPasteAsHandler::PasteAsEmbed
- //----------------------------------------------------------------------------------------
- FW_Boolean FW_MPasteAsHandler::PasteAsEmbed(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_StorageKinds storageKind,
- ODCloneKind cloneKind)
- {
- // User wants to Embed the data, with or without translation
- FW_Boolean result = false;
-
- FW_CPart* part = fPrivFrame->GetPart(ev);
- FW_CSelection* selection = fPrivFrame->GetPresentation(ev)->GetSelection(ev);
- result = (part->GetDataInterchange(ev)->InternalizeData(ev, selection->GetSelectedContent(ev), fPrivFrame, storageUnit, storageKind, cloneKind, GetEmbedInfoPtr(ev)) != FW_kInternalizeFailed);
-
- return result;
- }
-
-