home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 15.7 KB | 499 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: DrwDDCmd.cpp
- // Release Version: $ ODF 1 $
- //
- // Author: Mary Boetcher
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "ODFDraw.hpp"
-
- #ifndef DRWDDCMD_H
- #include "DrwDDCmd.h"
- #endif
-
- #ifndef DRAWCONT_H
- #include "DrawCont.h"
- #endif
-
- #ifndef DRAWSEL_H
- #include "DrawSel.h"
- #endif
-
- #ifndef BASESHP_H
- #include "BaseShp.h"
- #endif
-
- #ifndef DRAWPART_H
- #include "DrawPart.h"
- #endif
-
- #ifndef DRAWCLIP_H
- #include "DrawClip.h"
- #endif
-
- #ifndef DRAWLINK_H
- #include "DrawLink.h"
- #endif
-
- // ----- FrameWork Includes -----
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfdrawcommand
- #endif
-
- FW_DEFINE_AUTO(CDrawDragCommand)
- FW_DEFINE_AUTO(CDrawDropCommand)
-
- //========================================================================================
- // class CDrawDragCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand constructor
- //----------------------------------------------------------------------------------------
- CDrawDragCommand::CDrawDragCommand(Environment* ev,
- CDrawPart* part,
- FW_CFrame* frame,
- CDrawSelection* selection,
- FW_Boolean canUndo)
- : FW_CDragCommand(ev, frame, canUndo),
- fDrawPart(part),
- fDrawSelection(selection),
- fDraggedContent(NULL),
- fLinkSources(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand destructor
- //----------------------------------------------------------------------------------------
-
- CDrawDragCommand::~CDrawDragCommand()
- {
- FW_START_DESTRUCTOR
- delete fDraggedContent; // Will call remove all if necessary
- fDraggedContent = NULL;
-
- delete fLinkSources;
- fLinkSources = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::SaveUndoState(Environment* ev) // Override
- {
- FW_ASSERT(fDraggedContent == NULL);
- fDraggedContent = FW_NEW(CDrawUndoContent, (ev, fDrawPart, fDrawSelection));
-
- fLinkSources = fDrawSelection->GetSelectedLinkSources();
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::UndoIt(Environment* ev) // Override
- {
- // ----- Add the dragged shapes back into the part
- CDrawContentShapeIterator ite(fDraggedContent);
- for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->RestoreShape(ev);
- }
-
- fDraggedContent->RestoreLinks(ev);
-
- // ----- Add the saved shapes to the selection
- fDrawSelection->SelectContent(ev, fDraggedContent);
-
- // ----- Invalidate
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::RedoIt(Environment* ev) // Override
- {
- // Select saved shapes
- fDrawSelection->SelectContent(ev, fDraggedContent);
-
- fDrawSelection->ClearSelection(ev); // clear them, again
-
- fDraggedContent->RemoveFromLinks(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::FreeUndoState
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::FreeUndoState(Environment *ev) // Override
- {
- // Delete link sources left empty because all their shapes were removed
- fDraggedContent->DeleteEmptyLinkSources(ev);
-
- // Delete undo data
- fDraggedContent->DeleteSavedShapesAndLinks(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::PropagateChanges(Environment* ev, ODUpdateID id )
- {
- // Propagate changes should only be called when content was removed from the part.
- FW_ASSERT(IsDragMoveToAnotherPart);
-
- if (fLinkSources)
- {
- //--- Update affected links ---
- id = FW_CSession::UniqueUpdateID(ev);
- CDrawPublishLinkCollectionIterator iter(fLinkSources);
- for (CDrawPublishLink* link = iter.First(); iter.IsNotComplete(); link = iter.Next())
- {
- link->ContentUpdated(ev, id);
- }
- }
-
- FW_CDragCommand::PropagateChanges(ev, id);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDragCommand::DoIt
- //----------------------------------------------------------------------------------------
-
- void CDrawDragCommand::DoIt(Environment* ev)
- {
- FW_CDragCommand::DoIt(ev);
-
- if (fDraggedContent)
- fDraggedContent->RemoveFromLinks(ev);
- }
-
- //========================================================================================
- // class CDrawDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand constructor
- //----------------------------------------------------------------------------------------
- CDrawDropCommand::CDrawDropCommand(Environment* ev,
- CDrawPart* part,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* facet,
- const FW_CPoint& windowPoint,
- FW_Boolean canUndo)
- : FW_CDropCommand(ev, frame, dropInfo, facet, windowPoint, canUndo),
- fDrawPart(part),
- fSavedLink(NULL),
- fDropDelta(FW_kZeroPoint),
- fDroppedContent(NULL),
- fDrawSelection((CDrawSelection*)GetPresentation(ev)->GetSelection(ev))
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CDrawDropCommand::~CDrawDropCommand()
- {
- FW_START_DESTRUCTOR
- delete fDroppedContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::DoDrop
- //----------------------------------------------------------------------------------------
- FW_Boolean CDrawDropCommand::DoDrop(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& mouseDownOffset,
- const FW_CPoint& dropPoint,
- FW_Boolean isDropMove,
- short itemNumber)
- {
- if (itemNumber == 1)
- fDrawSelection->CloseSelection(ev);
-
- FW_Boolean result = FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
-
- if (result)
- {
- fDrawPart->SetTool(ev, kSelectTool);
-
- fDrawSelection->CalcCache(ev);
-
- FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
-
- FW_CRect box = fDrawSelection->GetDragRect();
-
- fDrawSelection->OffsetSelection(ev, newPosition.x - box.left, newPosition.y - box.top);
-
- ODShape* updateShape = fDrawSelection->GetUpdateShape();
-
- // ----- Calculate clip -----
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, fDrawSelection->GetPresentation(ev), updateShape);
-
- // ----- Invalidate -----
- GetPresentation(ev)->Invalidate(ev, updateShape);
-
- // ----- If I am not the active part I should not have a selection -----
- if (!fDrawPart->HasSelectionFocus(ev))
- fDrawSelection->CloseSelection(ev);
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::DoDroppedInSameFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CDrawDropCommand::DoDroppedInSameFrame(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& mouseDownOffset,
- const FW_CPoint& dropPoint)
- {
- FW_UNUSED(dropSU);
-
- FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
-
- FW_CRect box = fDrawSelection->GetDragRect();
-
- fDropDelta.Set(newPosition.x - box.left, newPosition.y - box.top);
-
- this->OffsetSelection(ev, fDropDelta);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
-
- void CDrawDropCommand::SaveRedoState(Environment* ev) // Override
- {
- if (fSavedLink == NULL) // if a link was created, don't need to save anything
- {
- // Save shapes that were just dropped
- FW_ASSERT(fDroppedContent == NULL);
- fDroppedContent = FW_NEW(CDrawContent, (ev, fDrawPart, fDrawSelection->GetDrawContent(ev)));
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::UndoIt
- //----------------------------------------------------------------------------------------
- void CDrawDropCommand::UndoIt(Environment* ev) // Override
- {
- if (fSavedLink)
- {
- fSavedLink->SelectShapes(ev); // set the selection's update shape
- GetDrawLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
- else if (this->IsDragMoveInSameFrame(ev)) // it's a drag-move
- {
- // select dropped shapes and move them back to the original position
- fDrawSelection->SelectContent(ev, fDroppedContent);
- this->OffsetSelection(ev, -fDropDelta);
- }
- else
- {
- // select dropped shapes and remove them from the document
- fDrawSelection->SelectContent(ev, fDroppedContent);
- fDrawSelection->ClearSelection(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::RedoIt
- //----------------------------------------------------------------------------------------
- void CDrawDropCommand::RedoIt(Environment* ev) // Override
- {
- if (fSavedLink)
- {
- GetDrawLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
- fSavedLink->SelectShapes(ev);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
- else if (this->IsDragMoveInSameFrame(ev)) // it's a drag-move
- {
- // select dropped shapes and move them to new position
- fDrawSelection->SelectContent(ev, fDroppedContent);
- this->OffsetSelection(ev, fDropDelta);
- }
- else // dropped shapes are copies
- {
- // add dropped shapes back into document
- this->RestoreDroppedShapes(ev);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::RestoreDroppedShapes
- //----------------------------------------------------------------------------------------
- void CDrawDropCommand::RestoreDroppedShapes(Environment* ev)
- {
- // Add the dropped shapes back into the part
- CDrawContentShapeIterator ite(fDroppedContent);
- for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
- {
- shape->RestoreShape(ev);
- }
-
- // Add the saved shapes to the selection
- fDrawSelection->SelectContent(ev, fDroppedContent);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::OffsetSelection
- //----------------------------------------------------------------------------------------
-
- void CDrawDropCommand::OffsetSelection(Environment* ev, const FW_CPoint& delta)
- {
- if (delta != FW_kZeroPoint)
- {
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- fDrawSelection->OffsetSelection(ev, delta.x, delta.y);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
-
- // Adjust offsets of linked shapes
- CDrawContentShapeIterator it(fDrawSelection->GetDrawContent(ev));
- for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
- {
- if (shape->GetSubscribeLink() != NULL)
- {
- shape->GetSubscribeLink()->AdjustUpdateOffset(ev, delta);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::FreeRedoState
- //----------------------------------------------------------------------------------------
-
- void CDrawDropCommand::FreeRedoState(Environment* ev) // Override
- {
- if (!fSavedLink) // created link deletes it's own shapes when it's deleted in FW_CPrivCreateLinkCommand::CommitUndone
- {
- //-- Delete the the dropped shapes
- CBaseShape* shape;
- while ((shape = fDroppedContent->GetFirstShape()) != NULL)
- {
- fDroppedContent->RemoveShape(ev, shape);
- delete shape;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::GetDrawLinkManager
- //----------------------------------------------------------------------------------------
-
- CDrawLinkManager* CDrawDropCommand::GetDrawLinkManager(Environment* ev) const
- {
- return (CDrawLinkManager*) fDrawPart->GetLinkManager(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::DoDroppedPasteAs
- //----------------------------------------------------------------------------------------
-
- void CDrawDropCommand::DoDroppedPasteAs(Environment* ev,
- const FW_CPoint& mouseDownOffset,
- const FW_CPoint& dropPoint)
- {
- FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
- fDrawSelection->CalcCache(ev);
- FW_CRect box = fDrawSelection->GetDragRect();
- fDropDelta.Set(newPosition.x - box.left, newPosition.y - box.top);
-
- fSavedLink = (CDrawSubscribeLink*) this->GetNewLink(ev);
-
- if (fSavedLink)
- {
- if (!fSavedLink->IsEstablished(ev)) // cross-doc link not yet established
- fDropDelta = FW_kZeroPoint; // puts linked shapes in same position as original
-
- // ----- Save information about newly-created link
- fSavedLink->SetUpdateOffset(ev, fDropDelta);
-
- if (fDropDelta != FW_kZeroPoint)
- {
- // invalidate and clear the current selection
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- fDrawSelection->CloseSelection(ev); // empty the selection
-
- // Select the newly-subscribed shapes
- fSavedLink->SelectShapes(ev);
-
- // offset the dropped shapes
- fDrawSelection->OffsetSelection(ev, fDropDelta.x, fDropDelta.y);
- GetPresentation(ev)->Invalidate(ev, fDrawSelection->GetUpdateShape());
- }
- }
- else // no link created - must be Embed As
- {
- fDrawPart->SetTool(ev, kSelectTool);
-
- fDrawSelection->OffsetSelection(ev, fDropDelta.x, fDropDelta.y);
- ODShape* updateShape = fDrawSelection->GetUpdateShape();
-
- // ----- Calculate clip -----
- CDrawFacetClipper facetClipper(fDrawPart);
- facetClipper.Clip(ev, fDrawSelection->GetPresentation(ev), updateShape);
-
- // ----- Invalidate -----
- GetPresentation(ev)->Invalidate(ev, updateShape);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CDrawDropCommand::PropagateChanges
- //----------------------------------------------------------------------------------------
-
- void CDrawDropCommand::PropagateChanges(Environment* ev, ODUpdateID id )
- {
-
- if (this->IsDragMoveInSameFrame(ev))
- {
- if (id == kODUnknownUpdate)
- id = FW_CSession::UniqueUpdateID(ev);
-
- fDrawSelection->SelectionChanged(ev, id);
- }
-
- FW_CDropCommand::PropagateChanges(ev, id);
- }
-