home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 7.9 KB | 245 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWLnkCmd.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWLNKCMD_H
- #include "FWLnkCmd.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- #ifndef FWLNKDST_H
- #include "FWLnkDst.h"
- #endif
-
- #ifndef FWLNKSRC_H
- #include "FWLnkSrc.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef SLODFSTR_K
- #include "SLODFStr.k"
- #endif
-
- #ifndef SLODFSTR_H
- #include "SLODFStr.h"
- #endif
-
- #ifndef FWMENU_K
- #include "FWMenu.k"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odflinking
- #endif
-
- FW_DEFINE_AUTO(FW_CPrivCreateLinkSourceCommand)
- FW_DEFINE_AUTO(FW_CPrivCreateLinkCommand)
-
- //========================================================================================
- // FW_CPrivCreateLinkSourceCommand class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkSourceCommand::FW_CPrivCreateLinkSourceCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkManager* linkMgr,
- FW_CLinkSource* pendingLink)
- : FW_CCommand(ev, FW_kCreateLinkSourceCommand, frame, FW_kCanUndo),
- fLinkMgr(linkMgr),
- fLinkSource(pendingLink)
- {
- // This command's Undo strings don't matter, because this transaction is always
- // bracketted by kODBegin/EndAction transactions.
- // this->SetMenuStrings(ev, "", "");
-
- // [MEB] temporary fix for empty Edit menu problem
- SetMenuStrings(ev, "Undo Link Creation", "Redo Link Creation");
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkSourceCommand::~FW_CPrivCreateLinkSourceCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::CommitUndone
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::CommitUndone(Environment*)
- {
- delete fLinkSource;
- fLinkSource = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::DoIt(Environment* ev)
- {
- FW_CPart* part = GetPart(ev);
- ODLinkSource* odLinkSource = part->GetDraft(ev)->CreateLinkSource(ev, part->GetODPart(ev));
- fLinkSource->SetODLinkSource(ev, odLinkSource);
-
- //--- Establish the link ---
- fLinkMgr->AddToSourceLinkList(ev, fLinkSource);
- fLinkSource->PrivLinkEstablished(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::GetODLinkSource
- //----------------------------------------------------------------------------------------
- ODLinkSource* FW_CPrivCreateLinkSourceCommand::GetODLinkSource(Environment* ev)
- {
- if (fLinkSource)
- return fLinkSource->GetODLinkSource(ev);
- return NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::UndoIt(Environment* ev)
- {
- fLinkMgr->BreakSourceLink(ev, fLinkSource); // calls RemoveFromSourceLinkList
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkSourceCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkSourceCommand::RedoIt(Environment* ev)
- {
- //--- Re-establish the link ---
- fLinkMgr->RestoreSourceLink(ev, fLinkSource); // calls AddToSourceLinkList
- }
-
- //========================================================================================
- // FW_CPrivCreateLinkCommand class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand constructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkCommand::FW_CPrivCreateLinkCommand(Environment* ev,
- FW_CFrame* frame,
- FW_CLinkManager* linkMgr,
- FW_Boolean fromClipboard)
- : FW_CCommand(ev, FW_kCreateLinkCommand, frame, FW_kCanUndo),
- fLinkMgr(linkMgr),
- fLink(NULL)
- {
- if (fromClipboard)
- {
- SetActionType(ev, kODBeginAction);
- // ODPG says to use kODEndAction, but my PasteAs command adds its Undo action
- // _after_ the link has been created, so I have to reverse the order of transactions
-
- // Set Undo strings to the ones used for the Paste As command
- FW_CString undoString;
- FW_CString redoString;
- ::FW_PrivLoadUndoStrings(ev, FW_kUndoPasteAsMsg, undoString, redoString);
- SetMenuStrings(ev, undoString, redoString);
- }
- else
- {
- // For Drag&Drop use the default action type, kODSingleAction.
- // The Undo strings don't matter, because this transaction will be
- // bracketted by kODBegin/EndAction transactions.
- this->SetMenuStrings(ev, "", "");
- }
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand destructor
- //----------------------------------------------------------------------------------------
- FW_CPrivCreateLinkCommand::~FW_CPrivCreateLinkCommand()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::CommitUndone
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::CommitUndone(Environment*)
- {
- // The link creation was Undone
- delete fLink;
- fLink = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::DoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::DoIt(Environment* ev)
- {
- FW_UNUSED(ev);
- // The main purpose of this command is to add a transaction to the Undo history
- FW_ASSERT(GetCanUndo(ev));
- // Nothing else to do
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::UndoIt(Environment* ev)
- {
- //--- Remove the link ---
- FW_ASSERT(fLink);
- fLinkMgr->BreakDestinationLink(ev, fLink);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPrivCreateLinkCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void FW_CPrivCreateLinkCommand::RedoIt(Environment* ev)
- {
- //--- Restore the link ---
- FW_ASSERT(fLink);
- fLinkMgr->RestoreDestinationLink(ev, fLink);
- }
-
-