home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-25 | 9.0 KB | 320 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: ClipCmds.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Henri Lamiraux
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef CLIPCMDS_H
- #include "ClipCmds.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef BOUNDSHP_H
- #include "BoundShp.h"
- #endif
-
- #ifndef LINESHP_H
- #include "LineShp.h"
- #endif
-
- #ifndef OVALSHP_H
- #include "OvalShp.h"
- #endif
-
- #ifndef RECTSHP_H
- #include "RectShp.h"
- #endif
-
- #ifndef RRECTSHP_H
- #include "RRectShp.h"
- #endif
-
- #ifndef TEXTSHP_H
- #include "TextShp.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWFRM_H
- #include "DrawFrm.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- // ----- FrameWork Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWORDCOL_H
- #include "FWOrdCol.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawcommand
- #endif
-
- FW_DEFINE_AUTO(CDrawClipboardCommand)
-
- //========================================================================================
- // CDrawClipboardCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand constructor
- //----------------------------------------------------------------------------------------
-
- CDrawClipboardCommand::CDrawClipboardCommand(Environment* ev,
- ODCommandID commandID,
- CDrawPart* part,
- CDrawFrame* frame,
- CDrawSelection* selection,
- FW_Boolean canUndo) :
- FW_CClipboardCommand(ev, commandID, frame, canUndo),
- fDrawPart(part),
- fDrawSelection(selection),
- fUndoContent(NULL),
- fSavedLink(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand destructor
- //----------------------------------------------------------------------------------------
-
- CDrawClipboardCommand::~CDrawClipboardCommand()
- {
- delete fUndoContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::SaveUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- FW_ASSERT(fUndoContent == NULL);
- fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawSelection));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::SaveRedoState(Environment* ev) // Override
- {
- if (this->IsPasteWithoutLink(ev))
- {
- FW_ASSERT(fUndoContent == NULL);
- fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawSelection));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::FreeUndoState(Environment* ev) // Override
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandCut || commandID == kODCommandClear)
- fUndoContent->DeleteSavedShapesAndLinks(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::FreeRedoState(Environment* ev) // Override
- {
- if (this->IsPasteWithoutLink(ev))
- fUndoContent->DeleteSavedShapes(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::UndoIt(Environment* ev) // Override
- {
- FW_CClipboardCommand::UndoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- fUndoContent->RestoreShapeSelection(ev);
- fUndoContent->RestoreLinks(ev);
- break;
-
- case kODCommandPasteAs:
- if (fSavedLink)
- {
- GetDrawLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
- GetPresentation(ev)->Invalidate(ev);
- break;
- }
- // else fall through to kODCommandPaste
-
- case kODCommandPaste:
- fUndoContent->RemoveShapeSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::RedoIt(Environment* ev) // Override
- {
- FW_CClipboardCommand::RedoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- fUndoContent->RemoveShapeSelection(ev);
- fUndoContent->RemoveFromLinks(ev);
- break;
-
- case kODCommandPasteAs:
- if (fSavedLink)
- {
- GetDrawLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
- GetPresentation(ev)->Invalidate(ev);
- break;
- }
- // else fall through to kODCommandPaste
-
- case kODCommandPaste:
- fUndoContent->RestoreShapeSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::PreCommand
- //----------------------------------------------------------------------------------------
-
- void CDrawClipboardCommand::PreCommand(Environment* ev)
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandPaste || commandID == kODCommandPasteAs)
- fDrawSelection->CloseSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommandDone
- //----------------------------------------------------------------------------------------
-
- void CDrawClipboardCommand::CommandDone(Environment* ev)
- {
- ODCommandID commandID = GetCommandID(ev);
-
- if (commandID == kODCommandPaste)
- fDrawSelection->CenterSelection(ev, GetFrame(ev));
- else if (commandID == kODCommandPasteAs)
- {
- fSavedLink = (CDrawSubscribeLink*)GetNewLink(ev);
- if (fSavedLink)
- {
- // Select the newly-subscribed shapes
- fSavedLink->SelectShapes(ev);
-
- // Offset the selection, saving the offset for later updates
- FW_CPoint offset = fDrawSelection->CenterSelection(ev, GetFrame(ev));
-
- // Save information about newly-created link
- fSavedLink->SetUpdateOffset(ev, offset);
- }
- }
- else if (commandID == kODCommandCut || commandID == kODCommandClear)
- {
- fUndoContent->RemoveFromLinks(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::IsPasteWithoutLink
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawClipboardCommand::IsPasteWithoutLink(Environment* ev) const
- {
- if (GetCommandID(ev) == kODCommandPaste)
- return TRUE;
- if (GetCommandID(ev) == kODCommandPasteAs)
- return (fSavedLink == NULL);
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::GetDrawLinkManager
- //----------------------------------------------------------------------------------------
-
- CDrawLinkManager* CDrawClipboardCommand::GetDrawLinkManager(Environment* ev) const
- {
- return (CDrawLinkManager*)GetPart(ev)->GetLinkManager(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommitUndone
- //----------------------------------------------------------------------------------------
-
- void CDrawClipboardCommand::CommitUndone(Environment* ev) // Override
- {
- if (fSavedLink == NULL)
- FW_CClipboardCommand::CommitUndone(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawClipboardCommand::CommitDone
- //----------------------------------------------------------------------------------------
- void CDrawClipboardCommand::CommitDone(Environment* ev) // Override
- {
- if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
- {
- // Delete link sources left empty because all their shapes were removed
- fUndoContent->DeleteEmptyLinkSources(ev);
- }
-
- FW_CClipboardCommand::CommitDone(ev); // calls FreeUndoState
- }
-