home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 11.6 KB | 411 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWTrackr.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWTRACKR_H
- #include "FWTrackr.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWDRGDRP_H
- #include "FWDrgDrp.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSCROLR_H
- #include "FWScrolr.h"
- #endif
-
- #ifndef FWSESION_H
- #include "FWSesion.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWEVENTU_H
- #include "FWEventU.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment framework
- #endif
-
- //========================================================================================
- // class FW_CBaseTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTracker::FW_CBaseTracker
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTracker::FW_CBaseTracker(Environment *ev, FW_CView* view, ODFacet* facet) :
- fFacet(facet),
- fView(view)
- {
- FW_UNUSED(ev);
- FW_ASSERT(view);
- FW_ASSERT(facet);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CBaseTracker::~FW_CBaseTracker
- //----------------------------------------------------------------------------------------
-
- FW_CBaseTracker::~FW_CBaseTracker()
- {
- }
-
- //========================================================================================
- // class FW_CDropTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::FW_CDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker::FW_CDropTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean autoScroll) :
- FW_CBaseTracker(ev, view, facet),
- fScroller(view->GetFrame(ev)->GetScroller(ev)),
- fAutoScroll(autoScroll)
- #ifdef FW_BUILD_MAC
- ,fMacHiliteOn(FALSE),
- fSavedHiliteState(FALSE)
- #endif
- #ifdef FW_DEBUG
- ,fHandleBeginTrackingCalled(FALSE)
- #endif
- {
- fAutoScroll = fAutoScroll && fScroller;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::~FW_CDropTracker
- //----------------------------------------------------------------------------------------
-
- FW_CDropTracker::~FW_CDropTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::HandleBeginTracking
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- void FW_CDropTracker::HandleBeginTracking(Environment *ev, const FW_CPoint& where, unsigned long dragAttributes)
- {
- #ifdef FW_DEBUG
- fHandleBeginTrackingCalled = TRUE;
- #endif
-
- fDragAttributes = dragAttributes;
-
- FW_CPoint anchorPoint(where);
- FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), anchorPoint);
- fAnchorPoint = this->BeginTracking(ev, anchorPoint);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::HandleContinueTracking
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- void FW_CDropTracker::HandleContinueTracking(Environment *ev, const FW_CPoint& where)
- {
- FW_CPoint currentPoint(where);
- FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
- fPreviousPoint = this->ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentPoint);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::HandleEndTracking
- //----------------------------------------------------------------------------------------
- // where is in frame coordinate
-
- FW_Boolean FW_CDropTracker::HandleEndTracking(Environment *ev, const FW_CPoint& where)
- {
- FW_CPoint currentPoint(where);
- FW_FrameToContent(ev, GetFacet(ev)->GetFrame(ev), currentPoint);
- return this->EndTracking(ev, fAnchorPoint, currentPoint);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CDropTracker::BeginTracking(Environment* ev, const FW_CPoint& anchorPoint)
- {
- if (!IsInSourceFrame(ev))
- PrivShowDefaultHilite(ev);
-
- if (fAutoScroll)
- fScroller->InitializeAutoScroll(ev);
-
- return anchorPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::BeginTracking
- //----------------------------------------------------------------------------------------
-
- FW_CPoint FW_CDropTracker::ContinueTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& previousPoint,
- const FW_CPoint& currentPoint)
- {
- FW_UNUSED(anchorPoint);
- FW_UNUSED(previousPoint);
- if (fAutoScroll)
- {
- FW_CPoint autoScrollOffset = fScroller->AutoScrollOffset(ev, currentPoint, 30);
- if (autoScrollOffset != FW_kZeroPoint)
- {
- if (fMacHiliteOn)
- {
- fSavedHiliteState = fMacHiliteOn;
- this->HideDragHilite(ev);
- }
- fScroller->ScrollBy(ev, autoScrollOffset);
- }
- else
- {
- if (fSavedHiliteState)
- PrivShowDefaultHilite(ev);
- }
- }
-
- return currentPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::EndTracking
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDropTracker::EndTracking(Environment* ev,
- const FW_CPoint& anchorPoint,
- const FW_CPoint& lastPoint)
- {
- this->HideDragHilite(ev);
- return anchorPoint != lastPoint;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::ShowDragHilite
- //----------------------------------------------------------------------------------------
- // hiliteShape is in frame coordinate
-
- void FW_CDropTracker::ShowDragHilite(Environment* ev, ODShape* hiliteShape, FW_Boolean showInside)
- {
- #ifdef FW_BUILD_MAC
- FW_ASSERT(fMacHiliteOn == FALSE);
- FW_ASSERT(hiliteShape);
-
- ODFacet* facet = GetFacet(ev);
- FW_CFrame* frame = GetView(ev)->GetFrame(ev);
- FW_ASSERT(facet->GetFrame(ev) == frame->GetODFrame(ev)); //just to be sure
-
- FW_CWindowContext gc(ev, facet); // focus drawing to the window
-
- FW_CAcquiredODShape aqHiliteShape = hiliteShape->Copy(ev);
-
- // ----- Intersect it with the aggregateClipShape -----
- FW_CAcquiredODShape aqClipShape = GetFacet(ev)->AcquireAggregateClipShape(ev, NULL);
- aqHiliteShape->Intersect(ev, aqClipShape);
-
- FW_FrameToWindow(ev, GetFacet(ev), aqHiliteShape);
-
- ::ShowDragHilite(FW_CSession::GetDragAndDrop(ev)->GetDragReference(ev),
- aqHiliteShape->GetQDRegion(ev),
- showInside);
-
- fMacHiliteOn = TRUE;
- fSavedHiliteState = FALSE;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::HideDragHilite
- //----------------------------------------------------------------------------------------
-
- void FW_CDropTracker::HideDragHilite(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- if (fMacHiliteOn)
- {
- FW_CWindowContext gc(ev, GetFacet(ev)); // focus drawing to the window
- ::HideDragHilite(FW_CSession::GetDragAndDrop(ev)->GetDragReference(ev));
-
- fMacHiliteOn = FALSE;
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::PrivShowDefaultHilite
- //----------------------------------------------------------------------------------------
-
- void FW_CDropTracker::PrivShowDefaultHilite(Environment* ev)
- {
- FW_CAcquiredODShape aqHiliteShape = GetView(ev)->GetFrame(ev)->GetDroppable(ev)->AcquireDragHiliteShape(ev, GetFacet(ev));
- this->ShowDragHilite(ev, aqHiliteShape, TRUE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::IsInSourceFrame
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CDropTracker::IsInSourceFrame(Environment* ev) const
- {
- FW_UNUSED(ev);
-
- #ifdef FW_DEBUG
- FW_ASSERT(fHandleBeginTrackingCalled);
- #endif
-
- return (fDragAttributes & kODDragIsInSourceFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CDropTracker::GetDragAttributes
- //----------------------------------------------------------------------------------------
-
- unsigned long FW_CDropTracker::GetDragAttributes(Environment* ev) const
- {
- FW_UNUSED(ev);
-
- #ifdef FW_DEBUG
- FW_ASSERT(fHandleBeginTrackingCalled);
- #endif
- return fDragAttributes;
- }
-
-
- //========================================================================================
- // class FW_CTracker
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CTracker::FW_CTracker
- //----------------------------------------------------------------------------------------
-
- FW_CTracker::FW_CTracker(Environment *ev, FW_CView* view, ODFacet* facet, FW_Boolean waitMouseMoved) :
- FW_CBaseTracker(ev, view, facet),
- fWaitMouseMoved(waitMouseMoved)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTracker::~FW_CTracker
- //----------------------------------------------------------------------------------------
-
- FW_CTracker::~FW_CTracker()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CTracker::Track
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CTracker::Track(Environment *ev, const FW_CMouseEvent& theMouseEvent)
- {
- FW_ASSERT(GetFacet(ev) != NULL);
- FW_ASSERT(GetView(ev) != NULL);
-
- // ----- Flush update event pending for this window
- FW_CAcquiredODWindow aqWindow = GetFacet(ev)->GetFrame(ev)->AcquireWindow(ev);
- aqWindow->Update(ev);
-
- if (fWaitMouseMoved && !theMouseEvent.WaitUntilMouseMoved(ev))
- return FALSE;
-
- FW_CPoint where = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
- GetView(ev)->FrameToViewContent(ev, where);
-
- fAnchorPoint = BeginTracking(ev, where);
-
- FW_CPoint currentLoc;
- fPreviousPoint = fAnchorPoint;
-
- do
- {
- {
- FW_CViewContext vc(ev, GetView(ev), GetFacet(ev));
- currentLoc = ::FW_GetMouseLocation(aqWindow, vc);
- }
-
- fPreviousPoint = ContinueTracking(ev, fAnchorPoint, fPreviousPoint, currentLoc);
- }
- while (FW_WaitMouseUp());
-
- return EndTracking(ev, fAnchorPoint, currentLoc);
- }
-
-