renaissance1: #i107215# Fixed drag-and-drop.

This commit is contained in:
Andre Fischer
2010-03-08 18:29:19 +01:00
parent 33a5458e44
commit 9c1e4f81d7
9 changed files with 92 additions and 76 deletions

View File

@@ -230,8 +230,24 @@ model::SharedPageDescriptor SlideSorterController::GetPageAt (
sal_Int32 nHitPageIndex (mrView.GetPageIndexAtPoint(aPixelPosition)); sal_Int32 nHitPageIndex (mrView.GetPageIndexAtPoint(aPixelPosition));
model::SharedPageDescriptor pDescriptorAtPoint; model::SharedPageDescriptor pDescriptorAtPoint;
if (nHitPageIndex >= 0) if (nHitPageIndex >= 0)
{
pDescriptorAtPoint = mrModel.GetPageDescriptor(nHitPageIndex); pDescriptorAtPoint = mrModel.GetPageDescriptor(nHitPageIndex);
if (pDescriptorAtPoint
&& mrSlideSorter.GetProperties()->IsOnlyPreviewTriggersMouseOver()
&& ! pDescriptorAtPoint->HasState(PageDescriptor::ST_Selected))
{
// Make sure that the mouse is over the preview area.
if ( ! mrView.GetLayouter().GetPageObjectLayouter()->GetBoundingBox(
pDescriptorAtPoint,
view::PageObjectLayouter::Preview,
view::PageObjectLayouter::WindowCoordinateSystem).IsInside(aPixelPosition))
{
pDescriptorAtPoint.reset();
}
}
}
return pDescriptorAtPoint; return pDescriptorAtPoint;
} }

View File

@@ -528,13 +528,6 @@ sal_Int8 Clipboard::AcceptDrop (
sal_Int8 nResult = DND_ACTION_NONE; sal_Int8 nResult = DND_ACTION_NONE;
const Clipboard::DropType eDropType (IsDropAccepted()); const Clipboard::DropType eDropType (IsDropAccepted());
if (eDropType != DT_NONE)
{
FunctionReference rFunction (mrSlideSorter.GetViewShell()->GetCurrentFunction());
SelectionFunction* pSelectionFunction = dynamic_cast<SelectionFunction*>(rFunction.get());
if (pSelectionFunction != NULL)
pSelectionFunction->MouseDragged(rEvent);
}
switch (eDropType) switch (eDropType)
{ {
@@ -559,9 +552,10 @@ sal_Int8 Clipboard::AcceptDrop (
// Show the insertion marker and the substitution for a drop. // Show the insertion marker and the substitution for a drop.
Point aPosition = pTargetWindow->PixelToLogic (rEvent.maPosPixel); Point aPosition = pTargetWindow->PixelToLogic (rEvent.maPosPixel);
mrController.GetInsertionIndicatorHandler()->UpdatePosition( SelectionFunction* pSelectionFunction = dynamic_cast<SelectionFunction*>(
aPosition, mrSlideSorter.GetViewShell()->GetCurrentFunction().get());
rEvent.maDragEvent.DropAction); if (pSelectionFunction != NULL)
pSelectionFunction->MouseDragged(rEvent, nResult);
// Scroll the window when the mouse reaches the window border. // Scroll the window when the mouse reaches the window border.
// mrController.GetScrollBarManager().AutoScroll (rEvent.maPosPixel); // mrController.GetScrollBarManager().AutoScroll (rEvent.maPosPixel);
@@ -617,7 +611,6 @@ sal_Int8 Clipboard::ExecuteDrop (
aEventModelPosition, aEventModelPosition,
rEvent.mnAction); rEvent.mnAction);
USHORT nIndex = DetermineInsertPosition(*pDragTransferable); USHORT nIndex = DetermineInsertPosition(*pDragTransferable);
mrController.GetInsertionIndicatorHandler()->End();
if (bContinue) if (bContinue)
{ {
@@ -650,6 +643,7 @@ sal_Int8 Clipboard::ExecuteDrop (
nResult = rEvent.mnAction; nResult = rEvent.mnAction;
} }
} }
mrController.GetInsertionIndicatorHandler()->End();
// Notify the receiving selection function that drag-and-drop is // Notify the receiving selection function that drag-and-drop is
// finished and the substitution handler can be released. // finished and the substitution handler can be released.

View File

@@ -241,5 +241,4 @@ void DragAndDropContext::SetTargetSlideSorter (
} }
} } } // end of namespace ::sd::slidesorter::controller } } } // end of namespace ::sd::slidesorter::controller

View File

@@ -98,6 +98,9 @@ void InsertionIndicatorHandler::End (void)
GetInsertAnimator()->Reset(); GetInsertAnimator()->Reset();
mbIsActive = false; mbIsActive = false;
maInsertPosition = view::InsertPosition();
meMode = UnknownMode;
mpInsertionIndicatorOverlay->Hide(); mpInsertionIndicatorOverlay->Hide();
} }
@@ -116,12 +119,12 @@ void InsertionIndicatorHandler::UpdateIndicatorIcon (const Transferable* pTransf
InsertionIndicatorHandler::Mode InsertionIndicatorHandler::GetModeFromDndAction ( InsertionIndicatorHandler::Mode InsertionIndicatorHandler::GetModeFromDndAction (
const sal_Int8 nDndAction) const sal_Int8 nDndAction)
{ {
switch (nDndAction & (ACTION_COPY | ACTION_MOVE | ACTION_LINK)) if ((nDndAction & ACTION_MOVE) != 0)
{ return MoveMode;
case ACTION_COPY: return CopyMode; else if ((nDndAction & ACTION_COPY) != 0)
case ACTION_MOVE: return MoveMode; return CopyMode;
default: return UnknownMode; else
} return UnknownMode;
} }
@@ -184,7 +187,8 @@ void InsertionIndicatorHandler::SetPosition (
if (maInsertPosition != aInsertPosition if (maInsertPosition != aInsertPosition
|| meMode != eMode || meMode != eMode
|| ! mpInsertionIndicatorOverlay->IsVisible()) // || ! mpInsertionIndicatorOverlay->IsVisible()
)
{ {
maInsertPosition = aInsertPosition; maInsertPosition = aInsertPosition;
meMode = eMode; meMode = eMode;

View File

@@ -47,7 +47,8 @@ Properties::Properties (void)
maTextColor(Application::GetSettings().GetStyleSettings().GetActiveTextColor()), maTextColor(Application::GetSettings().GetStyleSettings().GetActiveTextColor()),
maSelectionColor(Application::GetSettings().GetStyleSettings().GetHighlightColor()), maSelectionColor(Application::GetSettings().GetStyleSettings().GetHighlightColor()),
maHighlightColor(Application::GetSettings().GetStyleSettings().GetMenuHighlightColor()), maHighlightColor(Application::GetSettings().GetStyleSettings().GetMenuHighlightColor()),
mbIsUIReadOnly(false) mbIsUIReadOnly(false),
mbIsOnlyPreviewTriggersMouseOver(true)
{ {
} }
@@ -245,4 +246,20 @@ void Properties::SetUIReadOnly (const bool bIsUIReadOnly)
} }
bool Properties::IsOnlyPreviewTriggersMouseOver (void) const
{
return mbIsOnlyPreviewTriggersMouseOver;
}
void Properties::SetOnlyPreviewTriggersMouseOver (const bool bFlag)
{
mbIsOnlyPreviewTriggersMouseOver = bFlag;
}
} } } // end of namespace ::sd::slidesorter::controller } } } // end of namespace ::sd::slidesorter::controller

View File

@@ -194,14 +194,11 @@ public:
EventDescriptor ( EventDescriptor (
sal_uInt32 nEventType, sal_uInt32 nEventType,
const MouseEvent& rEvent, const Point& rMousePosition,
SlideSorter& rSlideSorter); SlideSorter& rSlideSorter);
EventDescriptor ( EventDescriptor (
const KeyEvent& rEvent, const KeyEvent& rEvent,
SlideSorter& rSlideSorter); SlideSorter& rSlideSorter);
EventDescriptor (
const AcceptDropEvent& rEvent,
SlideSorter& rSlideSorter);
EventDescriptor (const EventDescriptor& rDescriptor); EventDescriptor (const EventDescriptor& rDescriptor);
void SetDragMode (const InsertionIndicatorHandler::Mode eMode); void SetDragMode (const InsertionIndicatorHandler::Mode eMode);
@@ -262,7 +259,7 @@ BOOL SelectionFunction::MouseButtonDown (const MouseEvent& rEvent)
aMDPos = rEvent.GetPosPixel(); aMDPos = rEvent.GetPosPixel();
mbProcessingMouseButtonDown = true; mbProcessingMouseButtonDown = true;
mpWindow->CaptureMouse(); // mpWindow->CaptureMouse();
ProcessMouseEvent(BUTTON_DOWN, rEvent); ProcessMouseEvent(BUTTON_DOWN, rEvent);
@@ -312,9 +309,6 @@ BOOL SelectionFunction::MouseButtonUp (const MouseEvent& rEvent)
{ {
mrController.GetScrollBarManager().StopAutoScroll (); mrController.GetScrollBarManager().StopAutoScroll ();
// #95491# remember button state for creation of own MouseEvents
SetMouseButtonCode (rEvent.GetButtons());
ProcessMouseEvent(BUTTON_UP, rEvent); ProcessMouseEvent(BUTTON_UP, rEvent);
mbProcessingMouseButtonDown = false; mbProcessingMouseButtonDown = false;
@@ -326,8 +320,12 @@ BOOL SelectionFunction::MouseButtonUp (const MouseEvent& rEvent)
void SelectionFunction::MouseDragged (const AcceptDropEvent& rEvent) void SelectionFunction::MouseDragged (
const AcceptDropEvent& rEvent,
const sal_Int8 nDragAction)
{ {
const InsertionIndicatorHandler::Mode eMode (
InsertionIndicatorHandler::GetModeFromDndAction(nDragAction));//rEvent.mnAction));
if (rEvent.mbLeaving) if (rEvent.mbLeaving)
{ {
if (mpDragAndDropContext) if (mpDragAndDropContext)
@@ -346,14 +344,12 @@ void SelectionFunction::MouseDragged (const AcceptDropEvent& rEvent)
mrController.GetInsertionIndicatorHandler()->Start( mrController.GetInsertionIndicatorHandler()->Start(
pDragTransferable != NULL pDragTransferable != NULL
&& pDragTransferable->GetView()==&mrSlideSorter.GetView()); && pDragTransferable->GetView()==&mrSlideSorter.GetView());
mpDragAndDropContext->UpdatePosition( mpDragAndDropContext->UpdatePosition(rEvent.maPosPixel, eMode);
rEvent.maPosPixel,
InsertionIndicatorHandler::GetModeFromDndAction(rEvent.mnAction));
} }
// 1. Compute some frequently used values relating to the event. // 1. Compute some frequently used values relating to the event.
::std::auto_ptr<EventDescriptor> pEventDescriptor ( ::std::auto_ptr<EventDescriptor> pEventDescriptor (
new EventDescriptor(rEvent, mrSlideSorter)); new EventDescriptor(MOUSE_DRAG, rEvent.maPosPixel, mrSlideSorter));
// 2. Detect whether we are dragging pages or dragging a selection rectangle. // 2. Detect whether we are dragging pages or dragging a selection rectangle.
if (mpDragAndDropContext) if (mpDragAndDropContext)
@@ -362,8 +358,7 @@ void SelectionFunction::MouseDragged (const AcceptDropEvent& rEvent)
pEventDescriptor->mnEventCode |= MULTI_SELECTOR; pEventDescriptor->mnEventCode |= MULTI_SELECTOR;
// 3. Set the drag mode. // 3. Set the drag mode.
pEventDescriptor->SetDragMode( pEventDescriptor->SetDragMode(eMode);
InsertionIndicatorHandler::GetModeFromDndAction(rEvent.mnAction));
// 4. Process the event. // 4. Process the event.
if ( ! ProcessEvent(*pEventDescriptor)) if ( ! ProcessEvent(*pEventDescriptor))
@@ -687,6 +682,14 @@ void SelectionFunction::StartDrag (
const Point& rMousePosition, const Point& rMousePosition,
const InsertionIndicatorHandler::Mode eMode) const InsertionIndicatorHandler::Mode eMode)
{ {
// Do not start a drag-and-drop operation when one is already active.
// (when dragging pages from one document into another, pressing a
// modifier key can trigger a MouseMotion event in the originating
// window (focus still in there). Together with the mouse button pressed
// (drag-and-drop is active) this triggers the start of drag-and-drop.)
if (SD_MOD()->pTransferDrag != NULL)
return;
if ( ! mrSlideSorter.GetProperties()->IsUIReadOnly()) if ( ! mrSlideSorter.GetProperties()->IsUIReadOnly())
{ {
if (mrSlideSorter.GetViewShell() != NULL) if (mrSlideSorter.GetViewShell() != NULL)
@@ -817,7 +820,7 @@ void SelectionFunction::ProcessMouseEvent (sal_uInt32 nEventType, const MouseEve
// 1. Compute some frequently used values relating to the event. // 1. Compute some frequently used values relating to the event.
::std::auto_ptr<EventDescriptor> pEventDescriptor ( ::std::auto_ptr<EventDescriptor> pEventDescriptor (
new EventDescriptor(nEventType, rEvent, mrSlideSorter)); new EventDescriptor(nEventType, rEvent.GetPosPixel(), mrSlideSorter));
// 2. Compute a numerical code that describes the event and that is used // 2. Compute a numerical code that describes the event and that is used
// for fast look-up of the associated reaction. // for fast look-up of the associated reaction.
@@ -1016,11 +1019,9 @@ void SelectionFunction::ProcessEventWhileDragActive (EventDescriptor& rDescripto
// The substitution is visible. Handle events accordingly. // The substitution is visible. Handle events accordingly.
if (Match(rDescriptor.mnEventCode, MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK)) if (Match(rDescriptor.mnEventCode, MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK))
{ {
if ((rDescriptor.mnEventCode & CONTROL_MODIFIER) != 0) // mpDragAndDropContext->UpdatePosition(
StartDrag(rDescriptor.maMousePosition, InsertionIndicatorHandler::CopyMode); // rDescriptor.maMousePosition,
mpDragAndDropContext->UpdatePosition( // rDescriptor.meDragMode);
rDescriptor.maMousePosition,
rDescriptor.meDragMode);
} }
else if (Match(rDescriptor.mnEventCode, MOUSE_DRAG)) else if (Match(rDescriptor.mnEventCode, MOUSE_DRAG))
{ {
@@ -1176,6 +1177,10 @@ void SelectionFunction::ProcessMouseMotionEvent (const EventDescriptor& rDescrip
{ {
switch (rDescriptor.mnEventCode) switch (rDescriptor.mnEventCode)
{ {
case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE):
SetCurrentPage(rDescriptor.mpHitDescriptor);
// Fallthrough
// A mouse motion without visible substitution starts that. // A mouse motion without visible substitution starts that.
case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE): case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE):
StartDrag( StartDrag(
@@ -1305,19 +1310,16 @@ void SelectionFunction::ProcessButtonClick (
SelectionFunction::EventDescriptor::EventDescriptor ( SelectionFunction::EventDescriptor::EventDescriptor (
sal_uInt32 nEventType, sal_uInt32 nEventType,
const MouseEvent& rEvent, const Point& rMousePosition,
SlideSorter& rSlideSorter) SlideSorter& rSlideSorter)
: maMousePosition(), : maMousePosition(rMousePosition),
maMouseModelPosition(), maMouseModelPosition(),
mpHitDescriptor(), mpHitDescriptor(),
mpHitPage(), mpHitPage(),
mnEventCode(nEventType), mnEventCode(nEventType),
mnButtonIndex(-1) mnButtonIndex(-1)
{ {
SharedSdWindow pWindow (rSlideSorter.GetContentWindow()); maMouseModelPosition = rSlideSorter.GetContentWindow()->PixelToLogic(maMousePosition);
maMousePosition = rEvent.GetPosPixel();
maMouseModelPosition = pWindow->PixelToLogic(maMousePosition);
mpHitDescriptor = rSlideSorter.GetController().GetPageAt(maMousePosition); mpHitDescriptor = rSlideSorter.GetController().GetPageAt(maMousePosition);
if (mpHitDescriptor) if (mpHitDescriptor)
{ {
@@ -1359,33 +1361,6 @@ SelectionFunction::EventDescriptor::EventDescriptor (
SelectionFunction::EventDescriptor::EventDescriptor (
const AcceptDropEvent& rEvent,
SlideSorter& rSlideSorter)
: maMousePosition(rEvent.maPosPixel),
maMouseModelPosition(),
mpHitDescriptor(),
mpHitPage(),
mnEventCode(MOUSE_DRAG),
mnButtonIndex(-1),
meDragMode(InsertionIndicatorHandler::MoveMode),
mbMakeSelectionVisible(true)
{
SharedSdWindow pWindow (rSlideSorter.GetContentWindow());
maMouseModelPosition = pWindow->PixelToLogic(maMousePosition);
model::SharedPageDescriptor pHitDescriptor (
rSlideSorter.GetController().GetPageAt(maMousePosition));
if (pHitDescriptor.get() != NULL)
{
mpHitDescriptor = pHitDescriptor;
mpHitPage = pHitDescriptor->GetPage();
}
}
SelectionFunction::EventDescriptor::EventDescriptor (const EventDescriptor& rDescriptor) SelectionFunction::EventDescriptor::EventDescriptor (const EventDescriptor& rDescriptor)
: maMousePosition(rDescriptor.maMousePosition), : maMousePosition(rDescriptor.maMousePosition),
maMouseModelPosition(rDescriptor.maMouseModelPosition), maMouseModelPosition(rDescriptor.maMouseModelPosition),

View File

@@ -114,7 +114,8 @@ public:
SlideSorter& GetSlideSorter (void) const; SlideSorter& GetSlideSorter (void) const;
/** Return the descriptor of the page that is rendered under the /** Return the descriptor of the page that is rendered under the
given position. given position. This takes the IsOnlyPreviewTriggersMouseOver
property into account.
@return @return
Returns a pointer to a page descriptor instead of a Returns a pointer to a page descriptor instead of a
reference because when no page is found at the position reference because when no page is found at the position

View File

@@ -117,6 +117,13 @@ public:
bool IsUIReadOnly (void) const; bool IsUIReadOnly (void) const;
void SetUIReadOnly (const bool bIsUIReadOnly); void SetUIReadOnly (const bool bIsUIReadOnly);
/** The mouse over effect (and whether a mouse motion starts a multi
selection or a drag-and-drop) can be triggered by just the preview
area or the whole page object area.
*/
bool IsOnlyPreviewTriggersMouseOver (void) const;
void SetOnlyPreviewTriggersMouseOver (const bool bFlag);
private: private:
bool mbIsHighlightCurrentSlide; bool mbIsHighlightCurrentSlide;
bool mbIsShowSelection; bool mbIsShowSelection;
@@ -129,6 +136,7 @@ private:
Color maSelectionColor; Color maSelectionColor;
Color maHighlightColor; Color maHighlightColor;
bool mbIsUIReadOnly; bool mbIsUIReadOnly;
bool mbIsOnlyPreviewTriggersMouseOver;
}; };
} } } // end of namespace ::sd::slidesorter::controller } } } // end of namespace ::sd::slidesorter::controller

View File

@@ -94,7 +94,9 @@ public:
*/ */
virtual bool cancel(); virtual bool cancel();
void MouseDragged (const AcceptDropEvent& rEvent); void MouseDragged (
const AcceptDropEvent& rEvent,
const sal_Int8 nDragAction);
/** Turn of substitution display and insertion indicator. /** Turn of substitution display and insertion indicator.
*/ */