home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 13.5 KB | 506 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDrgDrp.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWDRGDRP_H
- #include "FWDrgDrp.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWSELECT_H
- #include "FWSelect.h"
- #endif
-
- #ifndef FWDRCMD_H
- #include "FWDrCmd.h"
- #endif
-
- #ifndef FWTRACKR_H
- #include "FWTrackr.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWPRTITE_H
- #include "FWPrtIte.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWMEMMGR_H
- #include "FWMemMgr.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWFrameworkCommands
- #endif
-
- //========================================================================================
- // class FW_MDraggableFrame
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MDraggableFrame)
-
- //----------------------------------------------------------------------------------------
- // FW_MDraggableFrame::FW_MDraggableFrame
- //----------------------------------------------------------------------------------------
-
- FW_MDraggableFrame::FW_MDraggableFrame(Environment *ev, FW_CFrame* frame) :
- fPart(frame->GetPart(ev)),
- fFrame(frame)
- {
- fFrame->PrivSetDraggable(ev, this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDraggableFrame::~FW_MDraggableFrame
- //----------------------------------------------------------------------------------------
-
- FW_MDraggableFrame::~FW_MDraggableFrame()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDraggableFrame::Drag
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MDraggableFrame::Drag(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- if (!theMouseEvent.WaitUntilMouseMoved(ev))
- return FALSE;
-
- #ifdef FW_DEBUG
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, theMouseEvent.GetFacet(ev)->GetFrame(ev));
- FW_ASSERT(frame == fFrame);
- #endif
-
- FW_CDragCommand* dragCommand = this->NewDragCommand(ev, fFrame, theMouseEvent);
- if (dragCommand)
- {
- FW_CPresentation* presentation = fFrame->GetPresentation(ev);
- presentation->PrivSetDragPending(TRUE);
-
- short level = 0;
- FW_VOLATILE(level);
-
- FW_TRY
- {
- dragCommand->BeginDrag(ev, theMouseEvent);
- level = 1;
- dragCommand->Execute(ev);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- if (level == 0) // throw in BeginDrag
- delete dragCommand;
-
- presentation->PrivSetDragPending(FALSE);
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- presentation->PrivSetDragPending(FALSE);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- //========================================================================================
- // class FW_MDroppableFrame
- //========================================================================================
-
- FW_DEFINE_CLASS_M0(FW_MDroppableFrame)
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::FW_MDroppableFrame
- //----------------------------------------------------------------------------------------
-
- FW_MDroppableFrame::FW_MDroppableFrame(Environment *ev, FW_CFrame* frame) :
- fPart(frame->GetPart(ev)),
- fFrame(frame),
- fCursorInContent(FALSE),
- fCanAcceptDrop(FALSE),
- fDropTracker(NULL)
- {
- FW_ASSERT(fFrame);
-
- fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::~FW_MDroppableFrame
- //----------------------------------------------------------------------------------------
-
- FW_MDroppableFrame::~FW_MDroppableFrame()
- {
- delete fDropTracker;
- fDropTracker = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::GetCanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MDroppableFrame::GetCanAcceptDrop(Environment* ev) const
- {
- FW_UNUSED(ev);
-
- return fCanAcceptDrop && PrivIsDroppable(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::GetDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker* FW_MDroppableFrame::GetDropTracker(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fDropTracker;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::ChangeDroppableState
- //----------------------------------------------------------------------------------------
-
- void FW_MDroppableFrame::ChangeDroppableState(Environment* ev, FW_DroppableState droppable)
- {
- fFrame->PrivSetDroppableState(droppable);
- fFrame->PrivSetDroppable(ev, this, PrivIsDroppable(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::CanAcceptDrop
- //----------------------------------------------------------------------------------------
-
- ODDragResult FW_MDroppableFrame::CanAcceptDrop(Environment *ev, ODDragItemIterator* dragInfo)
- {
- ODDragResult canAcceptDrop = TRUE;
- FW_Boolean atLeastOneSU = FALSE;
-
- for (ODStorageUnit* dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- {
- atLeastOneSU = TRUE;
- // if can't accept one of the item refuse the drop
- if (fPart->GetSupportedKind(ev, dragSU, FW_kDragAndDropStorage) == NULL)
- {
- canAcceptDrop = FALSE;
- break;
- }
- }
-
- return canAcceptDrop && atLeastOneSU;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::DragEnter
- //----------------------------------------------------------------------------------------
- // 'where' is in frame coordinate
-
- ODDragResult FW_MDroppableFrame::DragEnter(Environment *ev,
- ODFacet* facet,
- ODDragItemIterator* dragInfo,
- const FW_CPoint& where)
- {
- FW_UNUSED(where);
-
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- FW_ASSERT(frame != NULL);
-
- if (fPart->IsReadOnly(ev) || !PrivIsDroppable(ev))
- fCanAcceptDrop = FALSE;
- else
- fCanAcceptDrop = CanAcceptDrop(ev, dragInfo);
-
- FW_CSuperView* contentView = frame->GetContentView(ev);
- FW_ASSERT(contentView != NULL);
-
- fDropTracker = NewDropTracker(ev, contentView, facet);
-
- fCursorInContent = FALSE;
-
- return fCanAcceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::DragWithin
- //----------------------------------------------------------------------------------------
- // 'where' is in frame coordinate
-
- ODDragResult FW_MDroppableFrame::DragWithin(Environment* ev,
- ODFacet* facet,
- ODDragItemIterator* dragInfo,
- const FW_CPoint& where)
- {
- FW_UNUSED(dragInfo);
-
- if (!fCanAcceptDrop)
- return FALSE;
-
- // [HLX] OpenDoc Bug Begin
- // OpenDoc sometimes call DragWithin without calling DragEnter
- if (fDropTracker == NULL && !DragEnter(ev, facet, dragInfo, where))
- return FALSE;
- // [HLX] OpenDoc Bug End
-
- unsigned long attributes = FW_CSession::GetDragAndDrop(ev)->GetDragAttributes(ev);
-
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- FW_ASSERT(frame != NULL);
-
- FW_CView* contentView = frame->GetContentView(ev);
-
- FW_Boolean cursorInContent = contentView->IsMouseWithin(ev, facet, where);
-
- if (cursorInContent)
- {
- if (!fCursorInContent)
- fDropTracker->HandleBeginTracking(ev, where, attributes);
- }
- else
- {
- if (fCursorInContent)
- fDropTracker->HandleEndTracking(ev, where);
- }
-
- fCursorInContent = cursorInContent;
-
- if (fCursorInContent)
- fDropTracker->HandleContinueTracking(ev, where);
-
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::DragLeave
- //----------------------------------------------------------------------------------------
- // 'where' is in frame coordinate
-
- void FW_MDroppableFrame::DragLeave(Environment *ev, ODFacet* facet, const FW_CPoint& where)
- {
- FW_UNUSED(facet);
- if (!fCanAcceptDrop)
- return;
-
- FW_ASSERT(fDropTracker);
-
- if (fCursorInContent)
- fDropTracker->HandleEndTracking(ev, where);
-
- fCursorInContent = FALSE;
-
- // If there was a tracker delete it
- delete fDropTracker;
- fDropTracker = NULL;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::AcquireDragHiliteShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_MDroppableFrame::AcquireDragHiliteShape(Environment* ev, ODFacet* facet)
- {
- FW_UNUSED(facet);
-
- FW_ASSERT(fFrame->GetODFrame(ev) == facet->GetFrame(ev));
- FW_CAcquiredODShape contentShape = fFrame->AcquireContentShape(ev);
- return contentShape->Copy(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::Drop
- //----------------------------------------------------------------------------------------
-
- FW_DECLARE_THROW_POINT (FW_MDroppableFrame_Drop_BeforePerform);
-
- ODDropResult FW_MDroppableFrame::Drop(Environment *ev, ODDragItemIterator* dropInfo,
- ODFacet* facet, const FW_CPoint& where) // in frame coordinate
- {
-
- ODDropResult dropResult = kODDropFail;
-
- if (fCursorInContent)
- {
- FW_ASSERT(fDropTracker);
- fDropTracker->HandleEndTracking(ev, where);
- }
-
- delete fDropTracker;
- fDropTracker = NULL;
-
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- FW_ASSERT(frame != NULL);
-
- if (!fPart->IsReadOnly(ev) && fCursorInContent)
- {
- // ----- 'where' is in frame coordinate. Put it in content coordinate
- FW_CPoint dropPoint(where);
- FW_FrameToContent(ev, frame->GetODFrame(ev), dropPoint);
-
- FW_CDropCommand* dropCommand = this->NewDropCommand(ev, frame, dropInfo, facet, dropPoint);
-
- if (dropCommand)
- {
- FW_Boolean undoable = dropCommand->Execute(ev, FALSE); // do not delete if not undoable
-
- dropResult = dropCommand->GetDropResult(ev);
-
- if (!undoable)
- delete dropCommand;
- }
- }
-
- // ----- Always activate the frame at the end -----
- frame->ActivateWindow(ev, facet, TRUE);
-
- return dropResult;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::NewDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker* FW_MDroppableFrame::NewDropTracker(Environment *ev, FW_CView* view, ODFacet* facet)
- {
- return new FW_CDropTracker(ev, view, facet);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::GetDroppableState
- //----------------------------------------------------------------------------------------
-
- FW_DroppableState FW_MDroppableFrame::GetDroppableState(Environment* ev) const
- {
- FW_UNUSED(ev);
-
- return fFrame->PrivGetDroppableState();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::PrivIsDroppable
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MDroppableFrame::PrivIsDroppable(Environment *ev) const
- {
- return FW_MDroppableFrame::PrivDroppableStateToBoolean(fFrame->PrivGetDroppableState(), fFrame->GetViewType(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDroppableFrame::PrivDroppableStateToBoolean
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_MDroppableFrame::PrivDroppableStateToBoolean(FW_DroppableState droppable, ODTypeToken viewType)
- {
- if (droppable == FW_kNotDroppable)
- return FALSE;
- else if (((droppable & FW_kFrameDroppable) != 0) && (viewType == FW_CPart::fgViewAsFrameToken))
- return TRUE;
- else if (((droppable & FW_kThumbnailDroppable) != 0) && (viewType == FW_CPart::fgViewAsThumbnailToken))
- return TRUE;
- else if (((droppable & FW_kIconDroppable) != 0) && (viewType == FW_CPart::fgViewAsSmallIconToken || viewType == FW_CPart::fgViewAsLargeIconToken))
- return TRUE;
-
- return FALSE;
- }
-
-
-
-
-