home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 21.0 KB | 678 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: TblCmds.cpp
- // Release Version: $ 1.0d11 $
- //
- // Author: Mary Boetcher
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef TBLCMDS_H
- #include "TblCmds.h"
- #endif
-
- #ifndef TBLFRAME_H
- #include "TblFrame.h"
- #endif
-
- #ifndef TBLPART_H
- #include "TblPart.h"
- #endif
-
- #ifndef TBLSEL_H
- #include "TblSel.h"
- #endif
-
- #ifndef TBLPROXY_H
- #include "TblProxy.h"
- #endif
-
- #ifndef TBLLINK_H
- #include "TblLink.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWFRMING_H
- #include "FWFrming.h"
- #endif
-
- #ifndef FWLNKMGR_H
- #include "FWLnkMgr.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef SOM_ODLinkSource_xh
- #include <LinkSrc.xh>
- #endif
-
- #ifndef SOM_ODLinkSpec_xh
- #include <LinkSpec.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfTable
- #endif
-
- //========================================================================================
- // class CCellDragCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CCellDragCommand constructor
- //----------------------------------------------------------------------------------------
-
- CCellDragCommand::CCellDragCommand( Environment* ev,
- CTablePart* itsPart,
- FW_CFrame* frame,
- CTableSelection* selection) :
- FW_CDragCommand(ev, frame, FW_kCanUndo),
- fTablePart(itsPart),
- fTableSelection(selection),
- fSavedProxy(NULL)
- {
- fDragCell = selection->GetCell();
- }
-
- //----------------------------------------------------------------------------------------
- // CCellDragCommand destructor
- //----------------------------------------------------------------------------------------
-
- CCellDragCommand::~CCellDragCommand()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDragCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CCellDragCommand::UndoIt(Environment* ev)
- {
- FW_ASSERT(fSavedProxy);
-
- // Restore saved proxy to the table
- fSavedProxy->AttachEmbeddedFrames(ev);
- fTablePart->AddProxy(fSavedProxy);
- fTableSelection->SelectProxy(ev, fSavedProxy);
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDragCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CCellDragCommand::RedoIt(Environment* ev)
- {
- // Remove saved proxy, again
- fTableSelection->SelectProxy(ev, fSavedProxy);
- fTableSelection->ClearSelection(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDragCommand::SaveUndoState
- //---------------------------------------------------------------------------------------
- void CCellDragCommand::SaveUndoState(Environment *ev)
- {
- // Save the proxy for the part that was dragged
- fSavedProxy = fTablePart->CellToProxy(ev, fDragCell);
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDragCommand::FreeUndoState
- //---------------------------------------------------------------------------------------
- void CCellDragCommand::FreeUndoState(Environment *ev)
- {
- fSavedProxy = NULL;
- }
-
- //========================================================================================
- // class CCellDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CCellDropCommand constructor
- //----------------------------------------------------------------------------------------
-
- CCellDropCommand::CCellDropCommand( Environment* ev,
- CTablePart* itsPart,
- CTableFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint,
- const CCell& dropCell,
- const CCell& draggedCell) :
- FW_CDropCommand(ev, (FW_CPart*)itsPart, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
- fTablePart(itsPart),
- fTableFrame(frame),
- fDropCell(dropCell),
- fDraggedCell(draggedCell),
- fSavedProxy(NULL)
- {
- this->SetMenuStrings(ev, "Undo Drop", "Redo Drop");
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CCellDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CCellDropCommand::~CCellDropCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CCellDropCommand::DoDrop
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CCellDropCommand::DoDrop(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& mouseOffset,
- const FW_CPoint& dropPoint,
- FW_Boolean isDropMove)
- {
- fTableFrame->SelectCell(ev, fDropCell, FALSE);
-
- return FW_CDropCommand::DoDrop(ev, dropSU, mouseOffset, dropPoint, isDropMove);
- }
-
- //----------------------------------------------------------------------------------------
- // CCellDropCommand::DoDroppedInSameFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CCellDropCommand::DoDroppedInSameFrame(Environment* ev,
- ODStorageUnit* dropSU,
- const FW_CPoint& originPoint,
- const FW_CPoint& dropPoint)
- {
- FW_UNUSED(dropSU);
-
- FW_ASSERT(fDropCell != fDraggedCell);
-
- // Move the frame's cell
-
- CTableProxy* proxy = fTablePart->CellToProxy(ev, fDraggedCell);
- FW_ASSERT(proxy);
-
- fTableFrame->MoveProxy(ev, proxy, fDropCell);
- fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
-
- return TRUE;
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDropCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CCellDropCommand::UndoIt(Environment* ev)
- {
- FW_ASSERT(fSavedProxy);
-
- if (this->IsDragMoveInSameFrame(ev)) // simple move from one cell to another
- {
- // move the dropped part back to the cell it came from
- fTableFrame->MoveProxy(ev, fSavedProxy, fDraggedCell);
- }
- else // part was dropped here from outside
- {
- // remove the dropped cell from the table
- CTableSelection* selection = fTableFrame->GetSelection(ev);
- selection->SelectProxy(ev, fSavedProxy);
- selection->ClearSelection(ev);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDropCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CCellDropCommand::RedoIt(Environment* ev)
- {
- if (this->IsDragMoveInSameFrame(ev)) // simple move from one cell to another
- {
- // move the dropped part to the cell it was dropped in
- fTableFrame->MoveProxy(ev, fSavedProxy, fDropCell);
- }
- else // part was dropped here from outside
- {
- // re-drop the cell
- fSavedProxy->AttachEmbeddedFrames(ev);
- fTablePart->AddProxy(fSavedProxy);
- fTableFrame->SelectCell(ev, fDropCell, TRUE);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDropCommand::SaveRedoState
- //---------------------------------------------------------------------------------------
- void CCellDropCommand::SaveRedoState(Environment *ev)
- {
- // Save the proxy for the part that was just dropped
- fSavedProxy = fTablePart->CellToProxy(ev, fDropCell);
- }
-
- //---------------------------------------------------------------------------------------
- // CCellDropCommand::FreeRedoState
- //---------------------------------------------------------------------------------------
- void CCellDropCommand::FreeRedoState(Environment *ev)
- {
- // Delete the saved proxy
- delete fSavedProxy;
- }
-
- //====================================================================
- // CTableEditCommand class
- //====================================================================
-
- FW_DEFINE_CLASS_M1(CTableEditCommand, FW_CEditCommand)
-
- //--------------------------------------------------------------------
- // CTableEditCommand constructor
- //--------------------------------------------------------------------
- CTableEditCommand::CTableEditCommand(Environment* ev,
- ODCommandID id,
- CTablePart* itsPart,
- FW_CFrame* frame,
- CTableSelection* selection) :
- FW_CEditCommand(ev, id, frame, FW_kCanUndo),
- fTablePart(itsPart),
- fTableSelection(selection),
- fSavedProxy(NULL),
- fSavedLink(NULL)
- {
- }
-
- //--------------------------------------------------------------------
- // CTableEditCommand destructor
- //--------------------------------------------------------------------
- CTableEditCommand::~CTableEditCommand()
- {
- }
-
- //--------------------------------------------------------------------
- // CTableEditCommand::DoClear, DoCut, DoPaste
- // --- Override to call ContentUpdated
- //--------------------------------------------------------------------
- void CTableEditCommand::DoClear(Environment* ev)
- {
- fTablePart->ContentUpdated(ev, fFrame, kODUnknownUpdate);
- }
-
- //--------------------------------------------------------------------
- void CTableEditCommand::DoCut(Environment* ev)
- {
- fTablePart->ContentUpdated(ev, fFrame, kODUnknownUpdate);
- }
-
- //--------------------------------------------------------------------
- void CTableEditCommand::DoPaste(Environment* ev)
- {
- if (fCommandID == kODCommandPasteAs) // called from DoPasteAs
- fCommandID = kODCommandPaste; // for Undo
- fTablePart->ContentUpdated(ev, fFrame, kODUnknownUpdate);
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::UndoIt
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::UndoIt(Environment* ev)
- {
- FW_CEditCommand::UndoIt(ev); // call inherited
-
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestoreSelection(ev);
- break;
-
- case kODCommandPaste:
- this->RemoveSelection(ev);
- break;
-
- case kODCommandPasteAs:
- this->UndoPasteAs(ev);
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::RedoIt
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::RedoIt(Environment *ev) // Override
- {
- FW_CEditCommand::RedoIt(ev); // call inherited
-
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemoveSelection(ev);
- break;
-
- case kODCommandPaste:
- this->RestoreSelection(ev);
- break;
-
- case kODCommandPasteAs:
- this->RedoPasteAs(ev);
- }
- }
-
- /*----------------------------------------------------------------------------------------
- // CTableEditCommand::Commit
- //----------------------------------------------------------------------------------------
- void CTableEditCommand::Commit(Environment *ev, ODDoneState doneState) // Override
- {
- // Called by FW_CPart::DisposeActionState before deleting the command
- switch (fCommandID)
- {
- case kODCommandCut:
- case kODCommandClear:
- if (doneState == kODDone)
- this->DeleteSavedProxy(ev);
- break;
-
- case kODCommandPaste:
- if (doneState == kODUndone)
- this->DeleteSavedProxy(ev);
- break;
-
- case kODCommandPasteAs:
- this->CommitPasteAs(ev, doneState);
- }
- }
- */
- //----------------------------------------------------------------------------------------
- // CTableEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
- void CTableEditCommand::SaveUndoState(Environment *ev) // Override
- {
- if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
- this->SaveSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableEditCommand::FreeUndoState (doneState == kODDone)
- //----------------------------------------------------------------------------------------
- void CTableEditCommand::FreeUndoState(Environment *ev) // Override
- {
- if ((fCommandID == kODCommandCut) || (fCommandID == kODCommandClear))
- this->DeleteSavedProxy(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CTableEditCommand::SaveRedoState
- //----------------------------------------------------------------------------------------
- void CTableEditCommand::SaveRedoState(Environment *ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- {
- this->SaveSelection(ev);
- }
- else if (fCommandID == kODCommandPasteAs)
- {
- fPasteAsCell = fTableSelection->GetCell();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CTableEditCommand::FreeUndoState (doneState == kODUndone)
- //----------------------------------------------------------------------------------------
- void CTableEditCommand::FreeRedoState(Environment *ev) // Override
- {
- if (fCommandID == kODCommandPaste)
- {
- this->DeleteSavedProxy(ev);
- }
- else if (fCommandID == kODCommandPasteAs)
- {
- delete fSavedLink;
- }
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::SaveSelection
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::SaveSelection(Environment* ev)
- {
- //--- The selection is a single embedded frame ---
- CCell cell = fTableSelection->GetCell(); // selected cell
- fSavedProxy = fTablePart->CellToProxy(ev, cell);
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::RestoreSelection
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::RestoreSelection(Environment* ev)
- {
- // Re-attach the proxy's frames
- fSavedProxy->AttachEmbeddedFrames(ev);
-
- // Add the saved proxy back into the table part
- fTablePart->AddProxy(fSavedProxy);
-
- // Select it
- fTableSelection->CloseSelection(ev);
- fTableSelection->SelectProxy(ev, fSavedProxy);
- fTableSelection->InvalidateSelection(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::RemoveSelection
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::RemoveSelection(Environment* ev)
- {
- // Make sure the saved proxy is selected
- fTableSelection->CloseSelection(ev);
- fTableSelection->SelectProxy(ev, fSavedProxy);
-
- // Save the selected proxy
- this->SaveSelection(ev);
-
- // Clear the selection, which includes detaching the proxy frames.
- fTableSelection->ClearSelection(ev);
- }
-
- //---------------------------------------------------------------------------------------
- // CTableEditCommand::DeleteSavedProxy
- //---------------------------------------------------------------------------------------
- void CTableEditCommand::DeleteSavedProxy(Environment* ev)
- {
- FW_ASSERT(fSavedProxy);
-
- delete fSavedProxy;
- fSavedProxy = NULL;
- }
-
- //--------------------------------------------------------------------
- // CTableEditCommand::UndoPasteAs
- //--------------------------------------------------------------------
- void CTableEditCommand::UndoPasteAs(Environment* ev)
- {
- //--- Break the link ---
- CTableLinkManager* linkMgr = (CTableLinkManager*)fPart->GetLinkManager(ev);
- fSavedLink = linkMgr->CellToSubscribeLink(ev, fPasteAsCell);
- linkMgr->BreakSubscribeLink(ev, fSavedLink);
-
- //--- Remove the proxy frame ---
- CTableProxy* proxy = fTablePart->CellToProxy(ev, fPasteAsCell);
- proxy->RemoveEmbeddedFrames(ev);
- fTablePart->RemoveProxy(proxy);
- delete proxy;
-
- //--- Force redraw ---
- fFrame->GetPresentation(ev)->Invalidate(ev);
- }
-
- //--------------------------------------------------------------------
- // CTableEditCommand::RedoPasteAs
- //--------------------------------------------------------------------
- void CTableEditCommand::RedoPasteAs(Environment *ev)
- {
- //-- Restore the broken link --
- fPart->GetLinkManager(ev)->RestoreSubscribeLink(ev, fSavedLink);
- }
-
- //--------------------------------------------------------------------
- // CTableEditCommand::CommitPasteAs
- /*--------------------------------------------------------------------
- void CTableEditCommand::CommitPasteAs(Environment* ev, ODDoneState doneState)
- {
- if (doneState == kODUndone)
- {
- delete fSavedLink;
- fSavedLink = NULL;
- }
- }
- */
- //====================================================================
- // Constants for CBreakLinkSourceCommand and CBreakLinkCommand
- //====================================================================
-
- const ODCommandID kBreakLinkSourceID = 12345;
- const ODCommandID kBreakLinkID = 56789;
-
- //====================================================================
- // CBreakLinkSourceCommand class
- //====================================================================
-
- FW_DEFINE_CLASS_M1(CBreakLinkSourceCommand, FW_CCommand)
-
- //--------------------------------------------------------------------
- // CBreakLinkSourceCommand constructor
- //--------------------------------------------------------------------
- CBreakLinkSourceCommand::CBreakLinkSourceCommand(Environment* ev,
- FW_CFrame* frame,
- CTablePublishLink* linkSource) :
- FW_CCommand(ev, kBreakLinkSourceID, frame, FW_kCanUndo),
- fLinkSource(linkSource)
- {
- this->SetMenuStrings(ev, "Restore Link", "Break Link");
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkSourceCommand destructor
- //--------------------------------------------------------------------
- CBreakLinkSourceCommand::~CBreakLinkSourceCommand()
- {
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkSourceCommand::DoIt
- //--------------------------------------------------------------------
- void CBreakLinkSourceCommand::DoIt(Environment* ev)
- {
- //-- Break the link --
- fPart->GetLinkManager(ev)->BreakPublishLink(ev, fLinkSource);
- fPart->Changed(ev);
- }
-
- //--------------------------------------------------------------------
- void CBreakLinkSourceCommand::UndoIt(Environment* ev)
- {
- //-- Restore the broken link --
- fPart->GetLinkManager(ev)->RestorePublishLink(ev, fLinkSource);
- fPart->Changed(ev);
- }
-
- //--------------------------------------------------------------------
- void CBreakLinkSourceCommand::RedoIt(Environment* ev)
- {
- this->DoIt(ev); // just DoIt
- }
-
- //--------------------------------------------------------------------
- void CBreakLinkSourceCommand::CommitDone(Environment* ev)
- {
- // Delete the saved link source only if the command was not undone
- fLinkSource->GetODLinkSource(ev)->Release(ev);
- fLinkSource->SetODLinkSource(ev, NULL);
- delete fLinkSource;
- }
-
- //====================================================================
- // CBreakLinkCommand class
- //====================================================================
-
- FW_DEFINE_CLASS_M1(CBreakLinkCommand, FW_CCommand)
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand constructor
- //--------------------------------------------------------------------
- CBreakLinkCommand::CBreakLinkCommand(Environment* ev,
- FW_CFrame* frame,
- CTableSubscribeLink* linkDestination) :
- FW_CCommand(ev, kBreakLinkID, frame, FW_kCanUndo),
- fLink(linkDestination)
- {
- this->SetMenuStrings(ev, "Restore Link", "Break Link");
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand destructor
- //--------------------------------------------------------------------
- CBreakLinkCommand::~CBreakLinkCommand()
- {
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand::DoIt
- //--------------------------------------------------------------------
- void CBreakLinkCommand::DoIt(Environment* ev)
- {
- //-- Break the link --
- fPart->GetLinkManager(ev)->BreakSubscribeLink(ev, fLink);
- fPart->Changed(ev);
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand::UndoIt
- //--------------------------------------------------------------------
- void CBreakLinkCommand::UndoIt(Environment* ev)
- {
- //-- Restore the broken link --
- fPart->GetLinkManager(ev)->RestoreSubscribeLink(ev, fLink);
- fPart->Changed(ev);
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand::RedoIt
- //--------------------------------------------------------------------
- void CBreakLinkCommand::RedoIt(Environment* ev)
- {
- this->DoIt(ev); // just DoIt
- }
-
- //--------------------------------------------------------------------
- // CBreakLinkCommand::CommitDone
- //--------------------------------------------------------------------
- void CBreakLinkCommand::CommitDone(Environment* ev)
- {
- // Delete the saved link destination only if the command was not undone
- delete fLink;
- }
-
-
-