home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 14.1 KB | 514 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWDrgDrp.cpp
- // Release Version: $ ODF 1 $
- //
- // 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 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
-
- // ----- 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);
-
- FW_TRY
- {
- dragCommand->BeginDrag(ev, theMouseEvent);
- dragCommand->Execute(ev);
- }
- FW_CATCH_BEGIN
- FW_CATCH_EVERYTHING()
- {
- presentation->PrivSetDragPending(FALSE);
-
- FW_THROW_SAME();
- }
- FW_CATCH_END
-
- presentation->PrivSetDragPending(FALSE);
-
- return TRUE;
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_MDraggableFrame::SetDragging
- //----------------------------------------------------------------------------------------
-
- void FW_MDraggableFrame::SetDragging(Environment* ev, FW_Boolean dragging)
- {
- fFrame->GetODFrame(ev)->SetDragging(ev, dragging);
- }
-
- //========================================================================================
- // 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 = FALSE;
-
- if (PrivIsDroppable(ev))
- {
- ODStorageUnit *dragSU;
- ODTranslation *translate = fPart->GetSession(ev)->GetTranslation(ev);
- ODType applehfs = translate->GetISOTypeFromPlatformType(ev, 0x68667320UL, kODPlatformDataType); // 'hfs '
-
- for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- if (dragSU->Exists(ev, kODPropContents, fPart->GetPartKind(ev), 0))
- {
- canAcceptDrop = TRUE;
- break;
- }
- else if (dragSU->Exists(ev, kODPropContents, applehfs, 0))
- {
- #ifdef FW_BUILD_MAC
- HFSFlavor *valueData;
- long valueSize;
-
- dragSU->Focus(ev, kODPropContents, kODPosUndefined, applehfs, 0, kODPosUndefined);
- valueSize = dragSU->GetSize(ev);
- valueData = (HFSFlavor*)FW_CMemoryManager::AllocateBlock(valueSize);
- if (valueData)
- {
- FW_CByteArray byteArray;
- dragSU->GetValue(ev, valueSize, byteArray);
- byteArray.CopyBuffer(valueData, valueSize);
-
- if (valueData->fileType == 'bnto')
- {
- canAcceptDrop = TRUE;
- break;
- }
- }
- FW_CMemoryManager::FreeBlock(valueData);
- #endif
- }
- }
-
- return canAcceptDrop;
- }
-
- //----------------------------------------------------------------------------------------
- // 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);
-
- FW_CView* contentView = frame->GetContentView(ev);
- FW_ASSERT(contentView != NULL);
-
- fCanAcceptDrop = fPart->IsReadOnly(ev) ? FALSE : CanAcceptDrop(ev, dragInfo);
-
- 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);
- // [HLX] OpenDoc Bug End
-
- ODSession* session = fPart->GetSession(ev);
- unsigned long attributes = session->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));
- return fFrame->AcquireContentShape(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;
-
- if (fPart->IsReadOnly(ev))
- return dropResult;
-
- FW_CFrame *frame = FW_CFrame::ODtoFWFrame(ev, facet->GetFrame(ev));
- FW_ASSERT(frame != NULL);
-
- // ----- '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;
- }
-
- 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::gViewAsFrameToken))
- return TRUE;
- else if (((droppable & FW_kThumbnailDroppable) != 0) && (viewType == FW_CPart::gViewAsThumbnailToken))
- return TRUE;
- else if (((droppable & FW_kIconDroppable) != 0) && (viewType == FW_CPart::gViewAsSmallIconToken || viewType == FW_CPart::gViewAsLargeIconToken))
- return TRUE;
-
- return FALSE;
- }
-
-
-
-
-