Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "controller/SlsSelectionFunction.hxx"
22 :
23 : #include "SlideSorter.hxx"
24 : #include "SlideSorterViewShell.hxx"
25 : #include "SlsDragAndDropContext.hxx"
26 : #include "controller/SlsTransferableData.hxx"
27 : #include "controller/SlideSorterController.hxx"
28 : #include "controller/SlsPageSelector.hxx"
29 : #include "controller/SlsFocusManager.hxx"
30 : #include "controller/SlsScrollBarManager.hxx"
31 : #include "controller/SlsClipboard.hxx"
32 : #include "controller/SlsCurrentSlideManager.hxx"
33 : #include "controller/SlsInsertionIndicatorHandler.hxx"
34 : #include "controller/SlsSelectionManager.hxx"
35 : #include "controller/SlsProperties.hxx"
36 : #include "controller/SlsSlotManager.hxx"
37 : #include "controller/SlsVisibleAreaManager.hxx"
38 : #include "model/SlideSorterModel.hxx"
39 : #include "model/SlsPageDescriptor.hxx"
40 : #include "model/SlsPageEnumerationProvider.hxx"
41 : #include "view/SlideSorterView.hxx"
42 : #include "view/SlsLayouter.hxx"
43 : #include "view/SlsPageObjectLayouter.hxx"
44 : #include "framework/FrameworkHelper.hxx"
45 : #include "ViewShellBase.hxx"
46 : #include "DrawController.hxx"
47 : #include "Window.hxx"
48 : #include "sdpage.hxx"
49 : #include "drawdoc.hxx"
50 : #include "DrawDocShell.hxx"
51 : #include "sdxfer.hxx"
52 : #include "ViewShell.hxx"
53 : #include "FrameView.hxx"
54 : #include "app.hrc"
55 : #include "sdresid.hxx"
56 : #include "strings.hrc"
57 : #include <sfx2/viewfrm.hxx>
58 : #include <sfx2/dispatch.hxx>
59 : #include <svx/svdpagv.hxx>
60 : #include <vcl/msgbox.hxx>
61 : #include <svx/svxids.hrc>
62 : #include <boost/bind.hpp>
63 : #include <boost/optional.hpp>
64 :
65 : namespace {
66 : static const sal_uInt32 SINGLE_CLICK (0x00000001);
67 : static const sal_uInt32 DOUBLE_CLICK (0x00000002);
68 : static const sal_uInt32 LEFT_BUTTON (0x00000010);
69 : static const sal_uInt32 RIGHT_BUTTON (0x00000020);
70 : static const sal_uInt32 MIDDLE_BUTTON (0x00000040);
71 : static const sal_uInt32 BUTTON_DOWN (0x00000100);
72 : static const sal_uInt32 BUTTON_UP (0x00000200);
73 : static const sal_uInt32 MOUSE_MOTION (0x00000400);
74 : static const sal_uInt32 MOUSE_DRAG (0x00000800);
75 : // The rest leaves the lower 16 bit untouched so that it can be used with
76 : // key codes.
77 : static const sal_uInt32 OVER_SELECTED_PAGE (0x00010000);
78 : static const sal_uInt32 OVER_UNSELECTED_PAGE (0x00020000);
79 : static const sal_uInt32 OVER_FADE_INDICATOR (0x00040000);
80 : static const sal_uInt32 SHIFT_MODIFIER (0x00200000);
81 : static const sal_uInt32 CONTROL_MODIFIER (0x00400000);
82 :
83 : static const sal_uInt32 KEY_EVENT (0x10000000);
84 :
85 : // Some absent events are defined so they can be expressed explicitly.
86 : static const sal_uInt32 NO_MODIFIER (0x00000000);
87 : static const sal_uInt32 NOT_OVER_PAGE (0x00000000);
88 :
89 : // Masks
90 : static const sal_uInt32 MODIFIER_MASK (SHIFT_MODIFIER | CONTROL_MODIFIER);
91 : static const sal_uInt32 BUTTON_MASK (LEFT_BUTTON | RIGHT_BUTTON | MIDDLE_BUTTON);
92 :
93 : } // end of anonymous namespace
94 :
95 :
96 :
97 : // Define some macros to make the following switch statement more readable.
98 : #define ANY_MODIFIER(code) \
99 : code|NO_MODIFIER: \
100 : case code|SHIFT_MODIFIER: \
101 : case code|CONTROL_MODIFIER
102 :
103 : namespace sd { namespace slidesorter { namespace controller {
104 :
105 : //===== SelectionFunction::EventDescriptor ====================================
106 :
107 0 : class SelectionFunction::EventDescriptor
108 : {
109 : public:
110 : Point maMousePosition;
111 : Point maMouseModelPosition;
112 : model::SharedPageDescriptor mpHitDescriptor;
113 : SdrPage* mpHitPage;
114 : sal_uInt32 mnEventCode;
115 : InsertionIndicatorHandler::Mode meDragMode;
116 : bool mbMakeSelectionVisible;
117 : bool mbIsLeaving;
118 :
119 : EventDescriptor (
120 : sal_uInt32 nEventType,
121 : const MouseEvent& rEvent,
122 : SlideSorter& rSlideSorter);
123 : EventDescriptor (
124 : sal_uInt32 nEventType,
125 : const AcceptDropEvent& rEvent,
126 : const sal_Int8 nDragAction,
127 : SlideSorter& rSlideSorter);
128 :
129 : private:
130 : /** Compute a numerical code that describes a mouse event and that can
131 : be used for fast look up of the appropriate reaction.
132 : */
133 : sal_uInt32 EncodeMouseEvent (const MouseEvent& rEvent) const;
134 :
135 : /** Compute a numerical code that describes the current state like
136 : whether the selection rectangle is visible or whether the page under
137 : the mouse or the one that has the focus is selected.
138 : */
139 : sal_uInt32 EncodeState (void) const;
140 : };
141 :
142 :
143 :
144 :
145 : //===== SelectionFunction::ModeHandler ========================================
146 :
147 : class SelectionFunction::ModeHandler
148 : {
149 : public:
150 : ModeHandler (
151 : SlideSorter& rSlideSorter,
152 : SelectionFunction& rSelectionFunction,
153 : const bool bIsMouseOverIndicatorAllowed);
154 : virtual ~ModeHandler (void);
155 :
156 : virtual Mode GetMode (void) const = 0;
157 : virtual void Abort (void) = 0;
158 : virtual void ProcessEvent (EventDescriptor& rDescriptor);
159 :
160 : /** Set the selection to exactly the specified page and also set it as
161 : the current page.
162 : */
163 : void SetCurrentPage (const model::SharedPageDescriptor& rpDescriptor);
164 :
165 : /// Deselect all pages.
166 : void DeselectAllPages (void);
167 : void SelectOnePage (const model::SharedPageDescriptor& rpDescriptor);
168 :
169 : /** When the view on which this selection function is working is the
170 : main view then the view is switched to the regular editing view.
171 : */
172 : void SwitchView (const model::SharedPageDescriptor& rpDescriptor);
173 :
174 : void StartDrag (
175 : const Point& rMousePosition,
176 : const InsertionIndicatorHandler::Mode eMode);
177 :
178 : bool IsMouseOverIndicatorAllowed (void) const;
179 :
180 : protected:
181 : SlideSorter& mrSlideSorter;
182 : SelectionFunction& mrSelectionFunction;
183 :
184 : virtual bool ProcessButtonDownEvent (EventDescriptor& rDescriptor);
185 : virtual bool ProcessButtonUpEvent (EventDescriptor& rDescriptor);
186 : virtual bool ProcessMotionEvent (EventDescriptor& rDescriptor);
187 : virtual bool ProcessDragEvent (EventDescriptor& rDescriptor);
188 : virtual bool HandleUnprocessedEvent (EventDescriptor& rDescriptor);
189 :
190 : void ReprocessEvent (EventDescriptor& rDescriptor);
191 :
192 : private:
193 : const bool mbIsMouseOverIndicatorAllowed;
194 : };
195 :
196 :
197 : /** This is the default handler for processing events. It activates the
198 : multi selection or drag-and-drop when the right conditions are met.
199 : */
200 : class NormalModeHandler : public SelectionFunction::ModeHandler
201 : {
202 : public:
203 : NormalModeHandler (
204 : SlideSorter& rSlideSorter,
205 : SelectionFunction& rSelectionFunction);
206 : virtual ~NormalModeHandler (void);
207 :
208 : virtual SelectionFunction::Mode GetMode (void) const;
209 : virtual void Abort (void);
210 :
211 : void ResetButtonDownLocation (void);
212 :
213 : protected:
214 : virtual bool ProcessButtonDownEvent (SelectionFunction::EventDescriptor& rDescriptor);
215 : virtual bool ProcessButtonUpEvent (SelectionFunction::EventDescriptor& rDescriptor);
216 : virtual bool ProcessMotionEvent (SelectionFunction::EventDescriptor& rDescriptor);
217 : virtual bool ProcessDragEvent (SelectionFunction::EventDescriptor& rDescriptor);
218 :
219 : private:
220 : ::boost::optional<Point> maButtonDownLocation;
221 :
222 : /** Select all pages between and including the selection anchor and the
223 : specified page.
224 : */
225 : void RangeSelect (const model::SharedPageDescriptor& rpDescriptor);
226 : };
227 :
228 :
229 : /** Handle events during a multi selection, which typically is started by
230 : pressing the left mouse button when not over a page.
231 : */
232 : class MultiSelectionModeHandler : public SelectionFunction::ModeHandler
233 : {
234 : public:
235 : /** Start a rectangle selection at the given position.
236 : */
237 : MultiSelectionModeHandler (
238 : SlideSorter& rSlideSorter,
239 : SelectionFunction& rSelectionFunction,
240 : #ifndef MACOSX
241 : const Point& rMouseModelPosition);
242 : #else
243 : const Point& rMouseModelPosition,
244 : const sal_uInt32 nEventCode);
245 : #endif
246 : virtual ~MultiSelectionModeHandler (void);
247 :
248 : #ifndef MACOSX
249 : void Initialize(const sal_uInt32 nEventCode);
250 : #endif
251 :
252 : virtual SelectionFunction::Mode GetMode (void) const;
253 : virtual void Abort (void);
254 : virtual void ProcessEvent (SelectionFunction::EventDescriptor& rDescriptor);
255 :
256 : enum SelectionMode { SM_Normal, SM_Add, SM_Toggle };
257 :
258 : void SetSelectionMode (const SelectionMode eSelectionMode);
259 : void SetSelectionModeFromModifier (const sal_uInt32 nEventCode);
260 :
261 : protected:
262 : virtual bool ProcessButtonUpEvent (SelectionFunction::EventDescriptor& rDescriptor);
263 : virtual bool ProcessMotionEvent (SelectionFunction::EventDescriptor& rDescriptor);
264 : virtual bool HandleUnprocessedEvent (SelectionFunction::EventDescriptor& rDescriptor);
265 :
266 : private:
267 : SelectionMode meSelectionMode;
268 : Point maSecondCorner;
269 : Pointer maSavedPointer;
270 : bool mbAutoScrollInstalled;
271 : sal_Int32 mnAnchorIndex;
272 : sal_Int32 mnSecondIndex;
273 :
274 : virtual void UpdateModelPosition (const Point& rMouseModelPosition);
275 : virtual void UpdateSelection (void);
276 :
277 : /** Update the rectangle selection so that the given position becomes
278 : the new second point of the selection rectangle.
279 : */
280 : void UpdatePosition (
281 : const Point& rMousePosition,
282 : const bool bAllowAutoScroll);
283 :
284 : void UpdateSelectionState (
285 : const model::SharedPageDescriptor& rpDescriptor,
286 : const bool bIsInSelection) const;
287 : };
288 :
289 :
290 : /** Handle events during drag-and-drop.
291 : */
292 : class DragAndDropModeHandler : public SelectionFunction::ModeHandler
293 : {
294 : public:
295 : DragAndDropModeHandler (
296 : SlideSorter& rSlideSorter,
297 : #ifndef MACOSX
298 : SelectionFunction& rSelectionFunction);
299 : #else
300 : SelectionFunction& rSelectionFunction,
301 : const Point& rMousePosition,
302 : ::Window* pWindow);
303 : #endif
304 : virtual ~DragAndDropModeHandler (void);
305 :
306 : #ifndef MACOSX
307 : void Initialize(const Point& rMousePosition, ::Window* pWindow);
308 : #endif
309 :
310 : virtual SelectionFunction::Mode GetMode (void) const;
311 : virtual void Abort (void);
312 :
313 : protected:
314 : virtual bool ProcessButtonUpEvent (SelectionFunction::EventDescriptor& rDescriptor);
315 : virtual bool ProcessDragEvent (SelectionFunction::EventDescriptor& rDescriptor);
316 :
317 : private:
318 : ::boost::scoped_ptr<DragAndDropContext> mpDragAndDropContext;
319 : };
320 :
321 :
322 : //===== SelectionFunction =====================================================
323 :
324 0 : TYPEINIT1(SelectionFunction, FuPoor);
325 :
326 :
327 0 : SelectionFunction::SelectionFunction (
328 : SlideSorter& rSlideSorter,
329 : SfxRequest& rRequest)
330 : : FuPoor (
331 : rSlideSorter.GetViewShell(),
332 : rSlideSorter.GetContentWindow().get(),
333 0 : &rSlideSorter.GetView(),
334 0 : rSlideSorter.GetModel().GetDocument(),
335 : rRequest),
336 : mrSlideSorter(rSlideSorter),
337 0 : mrController(mrSlideSorter.GetController()),
338 : mbDragSelection(false),
339 : maInsertionMarkerBox(),
340 : mbProcessingMouseButtonDown(false),
341 : mnShiftKeySelectionAnchor(-1),
342 0 : mpModeHandler(new NormalModeHandler(rSlideSorter, *this))
343 : {
344 0 : }
345 :
346 :
347 :
348 :
349 0 : SelectionFunction::~SelectionFunction (void)
350 : {
351 0 : mpModeHandler.reset();
352 0 : }
353 :
354 :
355 :
356 :
357 0 : FunctionReference SelectionFunction::Create(
358 : SlideSorter& rSlideSorter,
359 : SfxRequest& rRequest)
360 : {
361 0 : FunctionReference xFunc( new SelectionFunction( rSlideSorter, rRequest ) );
362 0 : return xFunc;
363 : }
364 :
365 :
366 :
367 :
368 0 : sal_Bool SelectionFunction::MouseButtonDown (const MouseEvent& rEvent)
369 : {
370 : // remember button state for creation of own MouseEvents
371 0 : SetMouseButtonCode (rEvent.GetButtons());
372 0 : aMDPos = rEvent.GetPosPixel();
373 0 : mbProcessingMouseButtonDown = true;
374 :
375 : // mpWindow->CaptureMouse();
376 :
377 0 : ProcessMouseEvent(BUTTON_DOWN, rEvent);
378 :
379 0 : return sal_True;
380 : }
381 :
382 :
383 :
384 :
385 0 : sal_Bool SelectionFunction::MouseMove (const MouseEvent& rEvent)
386 : {
387 0 : ProcessMouseEvent(MOUSE_MOTION, rEvent);
388 0 : return sal_True;
389 : }
390 :
391 :
392 :
393 :
394 0 : sal_Bool SelectionFunction::MouseButtonUp (const MouseEvent& rEvent)
395 : {
396 0 : mrController.GetScrollBarManager().StopAutoScroll ();
397 :
398 0 : ProcessMouseEvent(BUTTON_UP, rEvent);
399 :
400 0 : mbProcessingMouseButtonDown = false;
401 : // mpWindow->ReleaseMouse();
402 :
403 0 : return sal_True;
404 : }
405 :
406 :
407 :
408 :
409 0 : void SelectionFunction::NotifyDragFinished (void)
410 : {
411 0 : SwitchToNormalMode();
412 0 : }
413 :
414 :
415 :
416 :
417 0 : sal_Bool SelectionFunction::KeyInput (const KeyEvent& rEvent)
418 : {
419 0 : view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
420 0 : PageSelector::UpdateLock aLock (mrSlideSorter);
421 0 : FocusManager& rFocusManager (mrController.GetFocusManager());
422 0 : sal_Bool bResult = sal_False;
423 :
424 0 : const KeyCode& rCode (rEvent.GetKeyCode());
425 0 : switch (rCode.GetCode())
426 : {
427 : case KEY_RETURN:
428 : {
429 0 : model::SharedPageDescriptor pDescriptor (rFocusManager.GetFocusedPageDescriptor());
430 0 : ViewShell* pViewShell = mrSlideSorter.GetViewShell();
431 0 : if (rFocusManager.HasFocus() && pDescriptor && pViewShell!=NULL)
432 : {
433 : // The Return key triggers different functions depending on
434 : // whether the slide sorter is the main view or displayed in
435 : // the right pane.
436 0 : if (pViewShell->IsMainViewShell())
437 : {
438 0 : mpModeHandler->SetCurrentPage(pDescriptor);
439 0 : mpModeHandler->SwitchView(pDescriptor);
440 : }
441 : else
442 : {
443 : pViewShell->GetDispatcher()->Execute(
444 : SID_INSERTPAGE,
445 0 : SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD);
446 : }
447 0 : bResult = sal_True;
448 : }
449 0 : break;
450 : }
451 :
452 : case KEY_TAB:
453 0 : if ( ! rFocusManager.IsFocusShowing())
454 : {
455 0 : rFocusManager.ShowFocus();
456 0 : bResult = sal_True;
457 : }
458 0 : break;
459 :
460 : case KEY_ESCAPE:
461 : // When there is an active multiselection or drag-and-drop
462 : // operation then stop that.
463 0 : mpModeHandler->Abort();
464 0 : SwitchToNormalMode();
465 0 : bResult = sal_True;
466 0 : break;
467 :
468 : case KEY_SPACE:
469 : {
470 : // Toggle the selection state.
471 0 : model::SharedPageDescriptor pDescriptor (rFocusManager.GetFocusedPageDescriptor());
472 0 : if (pDescriptor && rCode.IsMod1())
473 : {
474 0 : if (pDescriptor->HasState(model::PageDescriptor::ST_Selected))
475 0 : mrController.GetPageSelector().DeselectPage(pDescriptor, false);
476 : else
477 0 : mrController.GetPageSelector().SelectPage(pDescriptor);
478 : }
479 0 : bResult = sal_True;
480 : }
481 0 : break;
482 :
483 :
484 : // Move the focus indicator left.
485 : case KEY_LEFT:
486 0 : MoveFocus(FocusManager::FMD_LEFT, rCode.IsShift(), rCode.IsMod1());
487 0 : bResult = sal_True;
488 0 : break;
489 :
490 : // Move the focus indicator right.
491 : case KEY_RIGHT:
492 0 : MoveFocus(FocusManager::FMD_RIGHT, rCode.IsShift(), rCode.IsMod1());
493 0 : bResult = sal_True;
494 0 : break;
495 :
496 : // Move the focus indicator up.
497 : case KEY_UP:
498 0 : MoveFocus(FocusManager::FMD_UP, rCode.IsShift(), rCode.IsMod1());
499 0 : bResult = sal_True;
500 0 : break;
501 :
502 : // Move the focus indicator down.
503 : case KEY_DOWN:
504 0 : MoveFocus(FocusManager::FMD_DOWN, rCode.IsShift(), rCode.IsMod1());
505 0 : bResult = sal_True;
506 0 : break;
507 :
508 : // Go to previous page. No wrap around.
509 : case KEY_PAGEUP:
510 0 : GotoNextPage(-1);
511 0 : bResult = sal_True;
512 0 : break;
513 :
514 : // Go to next page. No wrap around..
515 : case KEY_PAGEDOWN:
516 0 : GotoNextPage(+1);
517 0 : bResult = sal_True;
518 0 : break;
519 :
520 : case KEY_HOME:
521 0 : GotoPage(0);
522 0 : bResult = sal_True;
523 0 : break;
524 :
525 : case KEY_END:
526 0 : GotoPage(mrSlideSorter.GetModel().GetPageCount()-1);
527 0 : bResult = sal_True;
528 0 : break;
529 :
530 : case KEY_DELETE:
531 : case KEY_BACKSPACE:
532 : {
533 0 : if (mrSlideSorter.GetProperties()->IsUIReadOnly())
534 0 : break;
535 :
536 0 : mrController.GetSelectionManager()->DeleteSelectedPages(rCode.GetCode()==KEY_DELETE);
537 :
538 0 : mnShiftKeySelectionAnchor = -1;
539 0 : bResult = sal_True;
540 : }
541 0 : break;
542 :
543 : case KEY_F10:
544 0 : if (rCode.IsShift())
545 : {
546 : mpModeHandler->SelectOnePage(
547 0 : mrSlideSorter.GetController().GetFocusManager().GetFocusedPageDescriptor());
548 : }
549 0 : break;
550 :
551 : default:
552 0 : break;
553 : }
554 :
555 0 : if ( ! bResult)
556 0 : bResult = FuPoor::KeyInput(rEvent);
557 :
558 0 : return bResult;
559 : }
560 :
561 :
562 :
563 :
564 0 : void SelectionFunction::MoveFocus (
565 : const FocusManager::FocusMoveDirection eDirection,
566 : const bool bIsShiftDown,
567 : const bool bIsControlDown)
568 : {
569 : // Remember the anchor of shift key multi selection.
570 0 : if (bIsShiftDown)
571 : {
572 0 : if (mnShiftKeySelectionAnchor<0)
573 : {
574 : model::SharedPageDescriptor pFocusedDescriptor (
575 0 : mrController.GetFocusManager().GetFocusedPageDescriptor());
576 0 : mnShiftKeySelectionAnchor = pFocusedDescriptor->GetPageIndex();
577 : }
578 : }
579 0 : else if ( ! bIsControlDown)
580 0 : ResetShiftKeySelectionAnchor();
581 :
582 0 : mrController.GetFocusManager().MoveFocus(eDirection);
583 :
584 0 : PageSelector& rSelector (mrController.GetPageSelector());
585 : model::SharedPageDescriptor pFocusedDescriptor (
586 0 : mrController.GetFocusManager().GetFocusedPageDescriptor());
587 0 : if (bIsShiftDown)
588 : {
589 : // When shift is pressed then select all pages in the range between
590 : // the currently and the previously focused pages, including them.
591 0 : if (pFocusedDescriptor)
592 : {
593 0 : sal_Int32 nPageRangeEnd (pFocusedDescriptor->GetPageIndex());
594 : model::PageEnumeration aPages (
595 : model::PageEnumerationProvider::CreateAllPagesEnumeration(
596 0 : mrSlideSorter.GetModel()));
597 0 : while (aPages.HasMoreElements())
598 : {
599 0 : model::SharedPageDescriptor pDescriptor (aPages.GetNextElement());
600 0 : if (pDescriptor)
601 : {
602 0 : const sal_Int32 nPageIndex(pDescriptor->GetPageIndex());
603 0 : if ((nPageIndex>=mnShiftKeySelectionAnchor && nPageIndex<=nPageRangeEnd)
604 : || (nPageIndex<=mnShiftKeySelectionAnchor && nPageIndex>=nPageRangeEnd))
605 : {
606 0 : rSelector.SelectPage(pDescriptor);
607 : }
608 : else
609 : {
610 0 : rSelector.DeselectPage(pDescriptor);
611 : }
612 : }
613 0 : }
614 : }
615 : }
616 0 : else if (bIsControlDown)
617 : {
618 : // When control is pressed then do not alter the selection or the
619 : // current page, just move the focus.
620 : }
621 : else
622 : {
623 : // Without shift just select the focused page.
624 0 : mpModeHandler->SelectOnePage(pFocusedDescriptor);
625 0 : }
626 0 : }
627 :
628 :
629 :
630 :
631 0 : void SelectionFunction::Activate()
632 : {
633 0 : FuPoor::Activate();
634 0 : }
635 :
636 :
637 :
638 :
639 0 : void SelectionFunction::Deactivate()
640 : {
641 0 : FuPoor::Deactivate();
642 0 : }
643 :
644 :
645 :
646 0 : void SelectionFunction::DoCut (void)
647 : {
648 0 : if ( ! mrSlideSorter.GetProperties()->IsUIReadOnly())
649 : {
650 0 : mrController.GetClipboard().DoCut();
651 : }
652 0 : }
653 :
654 :
655 :
656 :
657 0 : void SelectionFunction::DoCopy (void)
658 : {
659 0 : mrController.GetClipboard().DoCopy();
660 0 : }
661 :
662 :
663 :
664 :
665 0 : void SelectionFunction::DoPaste (void)
666 : {
667 0 : if ( ! mrSlideSorter.GetProperties()->IsUIReadOnly())
668 : {
669 0 : mrController.GetClipboard().DoPaste();
670 : }
671 0 : }
672 :
673 :
674 :
675 :
676 0 : bool SelectionFunction::cancel (void)
677 : {
678 0 : mrController.GetFocusManager().ToggleFocus();
679 0 : return true;
680 : }
681 :
682 :
683 :
684 :
685 0 : void SelectionFunction::GotoNextPage (int nOffset)
686 : {
687 : model::SharedPageDescriptor pDescriptor
688 0 : = mrController.GetCurrentSlideManager()->GetCurrentSlide();
689 0 : if (pDescriptor.get() != NULL)
690 : {
691 0 : SdPage* pPage = pDescriptor->GetPage();
692 : OSL_ASSERT(pPage!=NULL);
693 0 : sal_Int32 nIndex = (pPage->GetPageNum()-1) / 2;
694 0 : GotoPage(nIndex + nOffset);
695 : }
696 0 : ResetShiftKeySelectionAnchor();
697 0 : }
698 :
699 :
700 :
701 :
702 0 : void SelectionFunction::GotoPage (int nIndex)
703 : {
704 0 : sal_uInt16 nPageCount = (sal_uInt16)mrSlideSorter.GetModel().GetPageCount();
705 :
706 0 : if (nIndex >= nPageCount)
707 0 : nIndex = nPageCount - 1;
708 0 : if (nIndex < 0)
709 0 : nIndex = 0;
710 :
711 0 : mrController.GetFocusManager().SetFocusedPage(nIndex);
712 : model::SharedPageDescriptor pNextPageDescriptor (
713 0 : mrSlideSorter.GetModel().GetPageDescriptor (nIndex));
714 0 : if (pNextPageDescriptor.get() != NULL)
715 0 : mpModeHandler->SetCurrentPage(pNextPageDescriptor);
716 : else
717 : {
718 : OSL_ASSERT(pNextPageDescriptor.get() != NULL);
719 : }
720 0 : ResetShiftKeySelectionAnchor();
721 0 : }
722 :
723 :
724 :
725 :
726 0 : void SelectionFunction::ProcessMouseEvent (sal_uInt32 nEventType, const MouseEvent& rEvent)
727 : {
728 : // #95491# remember button state for creation of own MouseEvents
729 0 : SetMouseButtonCode (rEvent.GetButtons());
730 :
731 0 : EventDescriptor aEventDescriptor (nEventType, rEvent, mrSlideSorter);
732 0 : ProcessEvent(aEventDescriptor);
733 0 : }
734 :
735 :
736 :
737 :
738 0 : void SelectionFunction::MouseDragged (
739 : const AcceptDropEvent& rEvent,
740 : const sal_Int8 nDragAction)
741 : {
742 0 : EventDescriptor aEventDescriptor (MOUSE_DRAG, rEvent, nDragAction, mrSlideSorter);
743 0 : ProcessEvent(aEventDescriptor);
744 0 : }
745 :
746 :
747 :
748 :
749 0 : void SelectionFunction::ProcessEvent (EventDescriptor& rDescriptor)
750 : {
751 : // The call to ProcessEvent may switch to another mode handler.
752 : // Prevent the untimely destruction of the called handler by aquiring a
753 : // temporary reference here.
754 0 : ::boost::shared_ptr<ModeHandler> pModeHandler (mpModeHandler);
755 0 : pModeHandler->ProcessEvent(rDescriptor);
756 0 : }
757 :
758 :
759 :
760 :
761 0 : bool Match (
762 : const sal_uInt32 nEventCode,
763 : const sal_uInt32 nPositivePattern)
764 : {
765 0 : return (nEventCode & nPositivePattern)==nPositivePattern;
766 : }
767 :
768 :
769 :
770 :
771 0 : void SelectionFunction::SwitchToNormalMode (void)
772 : {
773 0 : if (mpModeHandler->GetMode() != NormalMode)
774 : SwitchMode(::boost::shared_ptr<ModeHandler>(
775 0 : new NormalModeHandler(mrSlideSorter, *this)));
776 0 : }
777 :
778 :
779 :
780 :
781 0 : void SelectionFunction::SwitchToDragAndDropMode (const Point aMousePosition)
782 : {
783 0 : if (mpModeHandler->GetMode() != DragAndDropMode)
784 : {
785 : #ifndef MACOSX
786 : ::boost::shared_ptr<DragAndDropModeHandler> handler(
787 0 : new DragAndDropModeHandler(mrSlideSorter, *this));
788 0 : SwitchMode(handler);
789 : // Delayed initialization, only after mpModeHanler is set, otherwise DND initialization
790 : // could already trigger DND events, which would recursively trigger this code again,
791 : // and without mpModeHandler set it would again try to set a new handler.
792 0 : handler->Initialize(aMousePosition, mpWindow);
793 : #else
794 : SwitchMode(::boost::shared_ptr<ModeHandler>(
795 : new DragAndDropModeHandler(mrSlideSorter, *this, aMousePosition, mpWindow)));
796 : #endif
797 : }
798 0 : }
799 :
800 :
801 :
802 :
803 0 : void SelectionFunction::SwitchToMultiSelectionMode (
804 : const Point aMousePosition,
805 : const sal_uInt32 nEventCode)
806 : {
807 0 : if (mpModeHandler->GetMode() != MultiSelectionMode)
808 : #ifndef MACOSX
809 : {
810 : ::boost::shared_ptr<MultiSelectionModeHandler> handler(
811 0 : new MultiSelectionModeHandler(mrSlideSorter, *this, aMousePosition));
812 0 : SwitchMode(handler);
813 : // Delayed initialization, only after mpModeHanler is set, the handle ctor
814 : // is non-trivial, so it could possibly recurse just like the DND handler above.
815 0 : handler->Initialize(nEventCode);
816 : }
817 : #else
818 : SwitchMode(::boost::shared_ptr<ModeHandler>(
819 : new MultiSelectionModeHandler(mrSlideSorter, *this, aMousePosition, nEventCode)));
820 : #endif
821 0 : }
822 :
823 :
824 :
825 :
826 0 : void SelectionFunction::SwitchMode (const ::boost::shared_ptr<ModeHandler>& rpHandler)
827 : {
828 : // Not all modes allow mouse over indicator.
829 0 : if (mpModeHandler->IsMouseOverIndicatorAllowed() != rpHandler->IsMouseOverIndicatorAllowed())
830 : {
831 0 : if ( ! rpHandler->IsMouseOverIndicatorAllowed())
832 : {
833 0 : mrSlideSorter.GetView().SetPageUnderMouse(model::SharedPageDescriptor());
834 : }
835 : else
836 0 : mrSlideSorter.GetView().UpdatePageUnderMouse();
837 : }
838 :
839 0 : mpModeHandler = rpHandler;
840 0 : }
841 :
842 :
843 :
844 :
845 0 : void SelectionFunction::ResetShiftKeySelectionAnchor (void)
846 : {
847 0 : mnShiftKeySelectionAnchor = -1;
848 0 : }
849 :
850 :
851 :
852 :
853 0 : void SelectionFunction::ResetMouseAnchor (void)
854 : {
855 0 : if (mpModeHandler && mpModeHandler->GetMode() == NormalMode)
856 : {
857 : ::boost::shared_ptr<NormalModeHandler> pHandler (
858 0 : ::boost::dynamic_pointer_cast<NormalModeHandler>(mpModeHandler));
859 0 : if (pHandler)
860 0 : pHandler->ResetButtonDownLocation();
861 : }
862 0 : }
863 :
864 :
865 :
866 :
867 : //===== EventDescriptor =======================================================
868 :
869 0 : SelectionFunction::EventDescriptor::EventDescriptor (
870 : const sal_uInt32 nEventType,
871 : const MouseEvent& rEvent,
872 : SlideSorter& rSlideSorter)
873 0 : : maMousePosition(rEvent.GetPosPixel()),
874 : maMouseModelPosition(),
875 : mpHitDescriptor(),
876 : mpHitPage(),
877 : mnEventCode(nEventType),
878 : meDragMode(InsertionIndicatorHandler::MoveMode),
879 : mbMakeSelectionVisible(true),
880 0 : mbIsLeaving(false)
881 : {
882 0 : maMouseModelPosition = rSlideSorter.GetContentWindow()->PixelToLogic(maMousePosition);
883 0 : mpHitDescriptor = rSlideSorter.GetController().GetPageAt(maMousePosition);
884 0 : if (mpHitDescriptor)
885 : {
886 0 : mpHitPage = mpHitDescriptor->GetPage();
887 : }
888 :
889 0 : mnEventCode |= EncodeMouseEvent(rEvent);
890 0 : mnEventCode |= EncodeState();
891 :
892 : // Detect the mouse leaving the window. When not button is pressed then
893 : // we can call IsLeaveWindow at the event. Otherwise we have to make an
894 : // explicit test.
895 0 : mbIsLeaving = rEvent.IsLeaveWindow()
896 : || ! Rectangle(Point(0,0),
897 0 : rSlideSorter.GetContentWindow()->GetOutputSizePixel()).IsInside(maMousePosition);
898 0 : }
899 :
900 :
901 :
902 :
903 0 : SelectionFunction::EventDescriptor::EventDescriptor (
904 : const sal_uInt32 nEventType,
905 : const AcceptDropEvent& rEvent,
906 : const sal_Int8 nDragAction,
907 : SlideSorter& rSlideSorter)
908 : : maMousePosition(rEvent.maPosPixel),
909 : maMouseModelPosition(),
910 : mpHitDescriptor(),
911 : mpHitPage(),
912 : mnEventCode(nEventType),
913 0 : meDragMode(InsertionIndicatorHandler::GetModeFromDndAction(nDragAction)),
914 : mbMakeSelectionVisible(true),
915 0 : mbIsLeaving(false)
916 : {
917 0 : maMouseModelPosition = rSlideSorter.GetContentWindow()->PixelToLogic(maMousePosition);
918 0 : mpHitDescriptor = rSlideSorter.GetController().GetPageAt(maMousePosition);
919 0 : if (mpHitDescriptor)
920 : {
921 0 : mpHitPage = mpHitDescriptor->GetPage();
922 : }
923 :
924 0 : mnEventCode |= EncodeState();
925 :
926 : // Detect the mouse leaving the window. When not button is pressed then
927 : // we can call IsLeaveWindow at the event. Otherwise we have to make an
928 : // explicit test.
929 : mbIsLeaving = rEvent.mbLeaving
930 : || ! Rectangle(Point(0,0),
931 0 : rSlideSorter.GetContentWindow()->GetOutputSizePixel()).IsInside(maMousePosition);
932 0 : }
933 :
934 :
935 :
936 :
937 :
938 0 : sal_uInt32 SelectionFunction::EventDescriptor::EncodeMouseEvent (
939 : const MouseEvent& rEvent) const
940 : {
941 : // Initialize with the type of mouse event.
942 0 : sal_uInt32 nEventCode (mnEventCode & (BUTTON_DOWN | BUTTON_UP | MOUSE_MOTION));
943 :
944 : // Detect the affected button.
945 0 : switch (rEvent.GetButtons())
946 : {
947 0 : case MOUSE_LEFT: nEventCode |= LEFT_BUTTON; break;
948 0 : case MOUSE_RIGHT: nEventCode |= RIGHT_BUTTON; break;
949 0 : case MOUSE_MIDDLE: nEventCode |= MIDDLE_BUTTON; break;
950 : }
951 :
952 : // Detect the number of clicks.
953 0 : switch (rEvent.GetClicks())
954 : {
955 0 : case 1: nEventCode |= SINGLE_CLICK; break;
956 0 : case 2: nEventCode |= DOUBLE_CLICK; break;
957 : }
958 :
959 : // Detect pressed modifier keys.
960 0 : if (rEvent.IsShift())
961 0 : nEventCode |= SHIFT_MODIFIER;
962 0 : if (rEvent.IsMod1())
963 0 : nEventCode |= CONTROL_MODIFIER;
964 :
965 0 : return nEventCode;
966 : }
967 :
968 0 : sal_uInt32 SelectionFunction::EventDescriptor::EncodeState (void) const
969 : {
970 0 : sal_uInt32 nEventCode (0);
971 :
972 : // Detect whether the event has happened over a page object.
973 0 : if (mpHitPage!=NULL && mpHitDescriptor)
974 : {
975 0 : if (mpHitDescriptor->HasState(model::PageDescriptor::ST_Selected))
976 0 : nEventCode |= OVER_SELECTED_PAGE;
977 : else
978 0 : nEventCode |= OVER_UNSELECTED_PAGE;
979 : }
980 :
981 0 : return nEventCode;
982 : }
983 :
984 :
985 :
986 :
987 : //===== SelectionFunction::ModeHandler ========================================
988 :
989 0 : SelectionFunction::ModeHandler::ModeHandler (
990 : SlideSorter& rSlideSorter,
991 : SelectionFunction& rSelectionFunction,
992 : const bool bIsMouseOverIndicatorAllowed)
993 : : mrSlideSorter(rSlideSorter),
994 : mrSelectionFunction(rSelectionFunction),
995 0 : mbIsMouseOverIndicatorAllowed(bIsMouseOverIndicatorAllowed)
996 : {
997 0 : }
998 :
999 :
1000 :
1001 :
1002 0 : SelectionFunction::ModeHandler::~ModeHandler (void)
1003 : {
1004 0 : }
1005 :
1006 :
1007 :
1008 :
1009 0 : void SelectionFunction::ModeHandler::ReprocessEvent (EventDescriptor& rDescriptor)
1010 : {
1011 0 : mrSelectionFunction.ProcessEvent(rDescriptor);
1012 0 : }
1013 :
1014 :
1015 :
1016 :
1017 0 : void SelectionFunction::ModeHandler::ProcessEvent (
1018 : SelectionFunction::EventDescriptor& rDescriptor)
1019 : {
1020 0 : PageSelector::BroadcastLock aBroadcastLock (mrSlideSorter);
1021 0 : PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
1022 :
1023 0 : bool bIsProcessed (false);
1024 0 : switch (rDescriptor.mnEventCode & (BUTTON_DOWN | BUTTON_UP | MOUSE_MOTION | MOUSE_DRAG))
1025 : {
1026 : case BUTTON_DOWN:
1027 0 : bIsProcessed = ProcessButtonDownEvent(rDescriptor);
1028 0 : break;
1029 :
1030 : case BUTTON_UP:
1031 0 : bIsProcessed = ProcessButtonUpEvent(rDescriptor);
1032 0 : break;
1033 :
1034 : case MOUSE_MOTION:
1035 0 : bIsProcessed = ProcessMotionEvent(rDescriptor);
1036 0 : break;
1037 :
1038 : case MOUSE_DRAG:
1039 0 : bIsProcessed = ProcessDragEvent(rDescriptor);
1040 0 : break;
1041 : }
1042 :
1043 0 : if ( ! bIsProcessed)
1044 0 : HandleUnprocessedEvent(rDescriptor);
1045 0 : }
1046 :
1047 :
1048 :
1049 :
1050 0 : bool SelectionFunction::ModeHandler::ProcessButtonDownEvent (EventDescriptor&)
1051 : {
1052 0 : return false;
1053 : }
1054 :
1055 :
1056 :
1057 :
1058 0 : bool SelectionFunction::ModeHandler::ProcessButtonUpEvent (EventDescriptor&)
1059 : {
1060 0 : mrSelectionFunction.SwitchToNormalMode();
1061 0 : return false;
1062 : }
1063 :
1064 :
1065 :
1066 :
1067 0 : bool SelectionFunction::ModeHandler::ProcessMotionEvent (EventDescriptor& rDescriptor)
1068 : {
1069 0 : if (mbIsMouseOverIndicatorAllowed)
1070 0 : mrSlideSorter.GetView().UpdatePageUnderMouse(rDescriptor.maMousePosition);
1071 :
1072 0 : if (rDescriptor.mbIsLeaving)
1073 : {
1074 0 : mrSelectionFunction.SwitchToNormalMode();
1075 0 : mrSlideSorter.GetView().SetPageUnderMouse(model::SharedPageDescriptor());
1076 :
1077 0 : return true;
1078 : }
1079 : else
1080 0 : return false;
1081 : }
1082 :
1083 :
1084 :
1085 :
1086 0 : bool SelectionFunction::ModeHandler::ProcessDragEvent (EventDescriptor&)
1087 : {
1088 0 : return false;
1089 : }
1090 :
1091 :
1092 :
1093 :
1094 0 : bool SelectionFunction::ModeHandler::HandleUnprocessedEvent (EventDescriptor&)
1095 : {
1096 0 : return false;
1097 : }
1098 :
1099 :
1100 :
1101 :
1102 0 : void SelectionFunction::ModeHandler::SetCurrentPage (
1103 : const model::SharedPageDescriptor& rpDescriptor)
1104 : {
1105 0 : SelectOnePage(rpDescriptor);
1106 0 : mrSlideSorter.GetController().GetCurrentSlideManager()->SwitchCurrentSlide(rpDescriptor);
1107 0 : }
1108 :
1109 :
1110 :
1111 :
1112 0 : void SelectionFunction::ModeHandler::DeselectAllPages (void)
1113 : {
1114 0 : mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
1115 0 : mrSelectionFunction.ResetShiftKeySelectionAnchor();
1116 0 : }
1117 :
1118 :
1119 :
1120 :
1121 0 : void SelectionFunction::ModeHandler::SelectOnePage (
1122 : const model::SharedPageDescriptor& rpDescriptor)
1123 : {
1124 0 : DeselectAllPages();
1125 0 : mrSlideSorter.GetController().GetPageSelector().SelectPage(rpDescriptor);
1126 0 : }
1127 :
1128 :
1129 :
1130 :
1131 0 : void SelectionFunction::ModeHandler::SwitchView (const model::SharedPageDescriptor& rpDescriptor)
1132 : {
1133 : // Switch to the draw view. This is done only when the current
1134 : // view is the main view.
1135 0 : ViewShell* pViewShell = mrSlideSorter.GetViewShell();
1136 0 : if (pViewShell!=NULL && pViewShell->IsMainViewShell())
1137 : {
1138 0 : if (rpDescriptor.get()!=NULL && rpDescriptor->GetPage()!=NULL)
1139 : {
1140 0 : mrSlideSorter.GetModel().GetDocument()->SetSelected(rpDescriptor->GetPage(), sal_True);
1141 : pViewShell->GetFrameView()->SetSelectedPage(
1142 0 : (rpDescriptor->GetPage()->GetPageNum()-1)/2);
1143 : }
1144 0 : if (mrSlideSorter.GetViewShellBase() != NULL)
1145 0 : framework::FrameworkHelper::Instance(*mrSlideSorter.GetViewShellBase())->RequestView(
1146 : framework::FrameworkHelper::msImpressViewURL,
1147 0 : framework::FrameworkHelper::msCenterPaneURL);
1148 : }
1149 0 : }
1150 :
1151 :
1152 :
1153 :
1154 0 : void SelectionFunction::ModeHandler::StartDrag (
1155 : const Point& rMousePosition,
1156 : const InsertionIndicatorHandler::Mode eMode)
1157 : {
1158 : (void)eMode;
1159 : // Do not start a drag-and-drop operation when one is already active.
1160 : // (when dragging pages from one document into another, pressing a
1161 : // modifier key can trigger a MouseMotion event in the originating
1162 : // window (focus still in there). Together with the mouse button pressed
1163 : // (drag-and-drop is active) this triggers the start of drag-and-drop.)
1164 0 : if (SD_MOD()->pTransferDrag != NULL)
1165 0 : return;
1166 :
1167 0 : if ( ! mrSlideSorter.GetProperties()->IsUIReadOnly())
1168 : {
1169 0 : mrSelectionFunction.SwitchToDragAndDropMode(rMousePosition);
1170 : }
1171 : }
1172 :
1173 :
1174 :
1175 :
1176 0 : bool SelectionFunction::ModeHandler::IsMouseOverIndicatorAllowed (void) const
1177 : {
1178 0 : return mbIsMouseOverIndicatorAllowed;
1179 : }
1180 :
1181 :
1182 :
1183 :
1184 : //===== NormalModeHandler =====================================================
1185 :
1186 0 : NormalModeHandler::NormalModeHandler (
1187 : SlideSorter& rSlideSorter,
1188 : SelectionFunction& rSelectionFunction)
1189 : : ModeHandler(rSlideSorter, rSelectionFunction, true),
1190 0 : maButtonDownLocation()
1191 : {
1192 0 : }
1193 :
1194 :
1195 :
1196 :
1197 0 : NormalModeHandler::~NormalModeHandler (void)
1198 : {
1199 0 : }
1200 :
1201 :
1202 :
1203 :
1204 0 : SelectionFunction::Mode NormalModeHandler::GetMode (void) const
1205 : {
1206 0 : return SelectionFunction::NormalMode;
1207 : }
1208 :
1209 :
1210 :
1211 :
1212 0 : void NormalModeHandler::Abort (void)
1213 : {
1214 0 : }
1215 :
1216 :
1217 :
1218 :
1219 0 : bool NormalModeHandler::ProcessButtonDownEvent (
1220 : SelectionFunction::EventDescriptor& rDescriptor)
1221 : {
1222 : // Remember the location where the left button is pressed. With
1223 : // that we can filter away motion events that are caused by key
1224 : // presses. We also can tune the minimal motion distance that
1225 : // triggers a drag-and-drop operation.
1226 0 : if ((rDescriptor.mnEventCode & BUTTON_DOWN) != 0)
1227 0 : maButtonDownLocation = rDescriptor.maMousePosition;
1228 :
1229 0 : switch (rDescriptor.mnEventCode)
1230 : {
1231 : case BUTTON_DOWN | LEFT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE:
1232 0 : SetCurrentPage(rDescriptor.mpHitDescriptor);
1233 0 : break;
1234 :
1235 : case BUTTON_DOWN | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE:
1236 0 : break;
1237 :
1238 : case BUTTON_DOWN | LEFT_BUTTON | DOUBLE_CLICK | OVER_SELECTED_PAGE:
1239 : case BUTTON_DOWN | LEFT_BUTTON | DOUBLE_CLICK | OVER_UNSELECTED_PAGE:
1240 : // A double click allways shows the selected slide in the center
1241 : // pane in an edit view.
1242 0 : SetCurrentPage(rDescriptor.mpHitDescriptor);
1243 0 : SwitchView(rDescriptor.mpHitDescriptor);
1244 0 : break;
1245 :
1246 : case BUTTON_DOWN | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE | SHIFT_MODIFIER:
1247 : case BUTTON_DOWN | LEFT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE | SHIFT_MODIFIER:
1248 : // Range selection with the shift modifier.
1249 0 : RangeSelect(rDescriptor.mpHitDescriptor);
1250 0 : break;
1251 :
1252 : // Right button for context menu.
1253 : case BUTTON_DOWN | RIGHT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE:
1254 : // Single right click and shift+F10 select as preparation to
1255 : // show the context menu. Change the selection only when the
1256 : // page under the mouse is not selected. In this case the
1257 : // selection is set to this single page. Otherwise the
1258 : // selection is not modified.
1259 0 : SetCurrentPage(rDescriptor.mpHitDescriptor);
1260 0 : rDescriptor.mbMakeSelectionVisible = false;
1261 0 : break;
1262 :
1263 : case BUTTON_DOWN | RIGHT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE:
1264 : // Do not change the selection. Just adjust the insertion indicator.
1265 0 : rDescriptor.mbMakeSelectionVisible = false;
1266 0 : break;
1267 :
1268 : case BUTTON_DOWN | RIGHT_BUTTON | SINGLE_CLICK | NOT_OVER_PAGE:
1269 : // Remember the current selection so that when a multi selection
1270 : // is started, we can restore the previous selection.
1271 0 : mrSlideSorter.GetModel().SaveCurrentSelection();
1272 0 : DeselectAllPages();
1273 0 : break;
1274 :
1275 : case ANY_MODIFIER(BUTTON_DOWN | LEFT_BUTTON | SINGLE_CLICK | NOT_OVER_PAGE):
1276 : // Remember the current selection so that when a multi selection
1277 : // is started, we can restore the previous selection.
1278 0 : mrSlideSorter.GetModel().SaveCurrentSelection();
1279 0 : DeselectAllPages();
1280 0 : break;
1281 :
1282 : default:
1283 0 : return false;
1284 : }
1285 0 : return true;
1286 : }
1287 :
1288 :
1289 :
1290 :
1291 0 : bool NormalModeHandler::ProcessButtonUpEvent (
1292 : SelectionFunction::EventDescriptor& rDescriptor)
1293 : {
1294 0 : bool bIsProcessed (true);
1295 0 : switch (rDescriptor.mnEventCode)
1296 : {
1297 : case BUTTON_UP | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE:
1298 0 : SetCurrentPage(rDescriptor.mpHitDescriptor);
1299 0 : break;
1300 :
1301 : // Multi selection with the control modifier.
1302 : case BUTTON_UP | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE | CONTROL_MODIFIER:
1303 0 : mrSlideSorter.GetController().GetPageSelector().DeselectPage(
1304 0 : rDescriptor.mpHitDescriptor);
1305 0 : break;
1306 :
1307 : case BUTTON_UP | LEFT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE | CONTROL_MODIFIER:
1308 0 : mrSlideSorter.GetController().GetPageSelector().SelectPage(
1309 0 : rDescriptor.mpHitDescriptor);
1310 0 : mrSlideSorter.GetView().SetPageUnderMouse(rDescriptor.mpHitDescriptor);
1311 0 : break;
1312 : case BUTTON_UP | LEFT_BUTTON | SINGLE_CLICK | NOT_OVER_PAGE:
1313 0 : break;
1314 :
1315 : default:
1316 0 : bIsProcessed = false;
1317 0 : break;
1318 : }
1319 0 : mrSelectionFunction.SwitchToNormalMode();
1320 0 : return bIsProcessed;
1321 : }
1322 :
1323 :
1324 :
1325 :
1326 :
1327 0 : bool NormalModeHandler::ProcessMotionEvent (
1328 : SelectionFunction::EventDescriptor& rDescriptor)
1329 : {
1330 0 : if (ModeHandler::ProcessMotionEvent(rDescriptor))
1331 0 : return true;
1332 :
1333 0 : bool bIsProcessed (true);
1334 0 : switch (rDescriptor.mnEventCode)
1335 : {
1336 : case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | OVER_UNSELECTED_PAGE):
1337 : // SetCurrentPage(rDescriptor.mpHitDescriptor);
1338 : // Fallthrough
1339 :
1340 : // A mouse motion without visible substitution starts that.
1341 : case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | OVER_SELECTED_PAGE):
1342 : {
1343 0 : if (maButtonDownLocation)
1344 : {
1345 : const sal_Int32 nDistance (maButtonDownLocation
1346 : ? ::std::max (
1347 0 : abs(maButtonDownLocation->X() - rDescriptor.maMousePosition.X()),
1348 0 : abs(maButtonDownLocation->Y() - rDescriptor.maMousePosition.Y()))
1349 0 : : 0);
1350 0 : if (nDistance > 3)
1351 : StartDrag(
1352 : rDescriptor.maMousePosition,
1353 : (rDescriptor.mnEventCode & CONTROL_MODIFIER) != 0
1354 : ? InsertionIndicatorHandler::CopyMode
1355 0 : : InsertionIndicatorHandler::MoveMode);
1356 : }
1357 : }
1358 0 : break;
1359 :
1360 : // A mouse motion not over a page starts a rectangle selection.
1361 : case ANY_MODIFIER(MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK | NOT_OVER_PAGE):
1362 : mrSelectionFunction.SwitchToMultiSelectionMode(
1363 : rDescriptor.maMouseModelPosition,
1364 0 : rDescriptor.mnEventCode);
1365 0 : break;
1366 :
1367 : default:
1368 0 : bIsProcessed = false;
1369 0 : break;
1370 : }
1371 0 : return bIsProcessed;
1372 : }
1373 :
1374 :
1375 :
1376 :
1377 0 : bool NormalModeHandler::ProcessDragEvent (SelectionFunction::EventDescriptor& rDescriptor)
1378 : {
1379 0 : mrSelectionFunction.SwitchToDragAndDropMode(rDescriptor.maMousePosition);
1380 0 : ReprocessEvent(rDescriptor);
1381 0 : return true;
1382 : }
1383 :
1384 :
1385 :
1386 :
1387 0 : void NormalModeHandler::RangeSelect (const model::SharedPageDescriptor& rpDescriptor)
1388 : {
1389 0 : PageSelector::UpdateLock aLock (mrSlideSorter);
1390 0 : PageSelector& rSelector (mrSlideSorter.GetController().GetPageSelector());
1391 :
1392 0 : model::SharedPageDescriptor pAnchor (rSelector.GetSelectionAnchor());
1393 0 : DeselectAllPages();
1394 :
1395 0 : if (pAnchor.get() != NULL)
1396 : {
1397 : // Select all pages between the anchor and the given one, including
1398 : // the two.
1399 0 : const sal_uInt16 nAnchorIndex ((pAnchor->GetPage()->GetPageNum()-1) / 2);
1400 0 : const sal_uInt16 nOtherIndex ((rpDescriptor->GetPage()->GetPageNum()-1) / 2);
1401 :
1402 : // Iterate over all pages in the range. Start with the anchor
1403 : // page. This way the PageSelector will recognize it again as
1404 : // anchor (the first selected page after a DeselectAllPages()
1405 : // becomes the anchor.)
1406 0 : const sal_uInt16 nStep ((nAnchorIndex < nOtherIndex) ? +1 : -1);
1407 0 : sal_uInt16 nIndex (nAnchorIndex);
1408 0 : while (true)
1409 : {
1410 0 : rSelector.SelectPage(nIndex);
1411 0 : if (nIndex == nOtherIndex)
1412 0 : break;
1413 0 : nIndex = nIndex + nStep;
1414 : }
1415 0 : }
1416 0 : }
1417 :
1418 :
1419 :
1420 :
1421 0 : void NormalModeHandler::ResetButtonDownLocation (void)
1422 : {
1423 0 : maButtonDownLocation = ::boost::optional<Point>();
1424 0 : }
1425 :
1426 :
1427 :
1428 :
1429 : //===== MultiSelectionModeHandler =============================================
1430 :
1431 0 : MultiSelectionModeHandler::MultiSelectionModeHandler (
1432 : SlideSorter& rSlideSorter,
1433 : SelectionFunction& rSelectionFunction,
1434 : #ifndef MACOSX
1435 : const Point& rMouseModelPosition)
1436 : #else
1437 : const Point& rMouseModelPosition,
1438 : const sal_uInt32 nEventCode)
1439 : #endif
1440 : : ModeHandler(rSlideSorter, rSelectionFunction, false),
1441 : meSelectionMode(SM_Normal),
1442 : maSecondCorner(rMouseModelPosition),
1443 0 : maSavedPointer(mrSlideSorter.GetContentWindow()->GetPointer()),
1444 : mbAutoScrollInstalled(false),
1445 : mnAnchorIndex(-1),
1446 0 : mnSecondIndex(-1)
1447 : {
1448 : #ifndef MACOSX
1449 0 : }
1450 :
1451 :
1452 0 : void MultiSelectionModeHandler::Initialize(const sal_uInt32 nEventCode)
1453 : {
1454 : #endif
1455 0 : const Pointer aSelectionPointer (POINTER_TEXT);
1456 0 : mrSlideSorter.GetContentWindow()->SetPointer(aSelectionPointer);
1457 0 : SetSelectionModeFromModifier(nEventCode);
1458 0 : }
1459 :
1460 :
1461 :
1462 :
1463 :
1464 0 : MultiSelectionModeHandler::~MultiSelectionModeHandler (void)
1465 : {
1466 0 : if (mbAutoScrollInstalled)
1467 : {
1468 : //a call to this handler's MultiSelectionModeHandler::UpdatePosition
1469 : //may be still waiting to be called back
1470 0 : mrSlideSorter.GetController().GetScrollBarManager().clearAutoScrollFunctor();
1471 : }
1472 0 : mrSlideSorter.GetContentWindow()->SetPointer(maSavedPointer);
1473 0 : }
1474 :
1475 :
1476 :
1477 :
1478 0 : SelectionFunction::Mode MultiSelectionModeHandler::GetMode (void) const
1479 : {
1480 0 : return SelectionFunction::MultiSelectionMode;
1481 : }
1482 :
1483 :
1484 :
1485 :
1486 0 : void MultiSelectionModeHandler::Abort (void)
1487 : {
1488 0 : mrSlideSorter.GetView().RequestRepaint(mrSlideSorter.GetModel().RestoreSelection());
1489 0 : }
1490 :
1491 :
1492 :
1493 :
1494 0 : void MultiSelectionModeHandler::ProcessEvent (
1495 : SelectionFunction::EventDescriptor& rDescriptor)
1496 : {
1497 : // During a multi selection we do not want sudden jumps of the
1498 : // visible area caused by moving newly selected pages into view.
1499 : // Therefore disable that temporarily. The disabler object is
1500 : // released at the end of the event processing, after the focus and
1501 : // current slide have been updated.
1502 0 : VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
1503 :
1504 0 : ModeHandler::ProcessEvent(rDescriptor);
1505 0 : }
1506 :
1507 :
1508 :
1509 :
1510 0 : bool MultiSelectionModeHandler::ProcessButtonUpEvent (
1511 : SelectionFunction::EventDescriptor& rDescriptor)
1512 : {
1513 0 : if (mbAutoScrollInstalled)
1514 : {
1515 : //a call to this handler's MultiSelectionModeHandler::UpdatePosition
1516 : //may be still waiting to be called back
1517 0 : mrSlideSorter.GetController().GetScrollBarManager().clearAutoScrollFunctor();
1518 0 : mbAutoScrollInstalled = false;
1519 : }
1520 :
1521 0 : if (Match(rDescriptor.mnEventCode, BUTTON_UP | LEFT_BUTTON | SINGLE_CLICK))
1522 : {
1523 0 : mrSelectionFunction.SwitchToNormalMode();
1524 0 : return true;
1525 : }
1526 : else
1527 0 : return false;
1528 : }
1529 :
1530 :
1531 :
1532 :
1533 0 : bool MultiSelectionModeHandler::ProcessMotionEvent (
1534 : SelectionFunction::EventDescriptor& rDescriptor)
1535 : {
1536 : // The selection rectangle is visible. Handle events accordingly.
1537 0 : if (Match(rDescriptor.mnEventCode, MOUSE_MOTION | LEFT_BUTTON | SINGLE_CLICK))
1538 : {
1539 0 : SetSelectionModeFromModifier(rDescriptor.mnEventCode);
1540 0 : UpdatePosition(rDescriptor.maMousePosition, true);
1541 0 : rDescriptor.mbMakeSelectionVisible = false;
1542 0 : return true;
1543 : }
1544 : else
1545 0 : return false;
1546 : }
1547 :
1548 :
1549 :
1550 0 : bool MultiSelectionModeHandler::HandleUnprocessedEvent (
1551 : SelectionFunction::EventDescriptor& rDescriptor)
1552 : {
1553 0 : if ( ! ModeHandler::HandleUnprocessedEvent(rDescriptor))
1554 : {
1555 : // If the event has not been processed then stop multi selection.
1556 0 : mrSelectionFunction.SwitchToNormalMode();
1557 0 : ReprocessEvent(rDescriptor);
1558 : }
1559 0 : return true;
1560 : }
1561 :
1562 :
1563 :
1564 :
1565 0 : void MultiSelectionModeHandler::UpdatePosition (
1566 : const Point& rMousePosition,
1567 : const bool bAllowAutoScroll)
1568 : {
1569 0 : VisibleAreaManager::TemporaryDisabler aDisabler (mrSlideSorter);
1570 :
1571 : // Convert window coordinates into model coordinates (we need the
1572 : // window coordinates for auto-scrolling because that remains
1573 : // constant while scrolling.)
1574 0 : SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
1575 0 : const Point aMouseModelPosition (pWindow->PixelToLogic(rMousePosition));
1576 :
1577 0 : bool bDoAutoScroll = bAllowAutoScroll && mrSlideSorter.GetController().GetScrollBarManager().AutoScroll(
1578 : rMousePosition,
1579 : ::boost::bind(
1580 : &MultiSelectionModeHandler::UpdatePosition,
1581 : this,
1582 : rMousePosition,
1583 0 : false));
1584 :
1585 0 : if (!bDoAutoScroll)
1586 0 : UpdateModelPosition(aMouseModelPosition);
1587 :
1588 0 : mbAutoScrollInstalled |= bDoAutoScroll;
1589 0 : }
1590 :
1591 :
1592 :
1593 :
1594 0 : void MultiSelectionModeHandler::SetSelectionModeFromModifier (
1595 : const sal_uInt32 nEventCode)
1596 : {
1597 0 : switch (nEventCode & MODIFIER_MASK)
1598 : {
1599 : case NO_MODIFIER:
1600 0 : SetSelectionMode(SM_Normal);
1601 0 : break;
1602 :
1603 : case SHIFT_MODIFIER:
1604 0 : SetSelectionMode(SM_Add);
1605 0 : break;
1606 :
1607 : case CONTROL_MODIFIER:
1608 0 : SetSelectionMode(SM_Toggle);
1609 0 : break;
1610 : }
1611 0 : }
1612 :
1613 :
1614 :
1615 :
1616 0 : void MultiSelectionModeHandler::SetSelectionMode (const SelectionMode eSelectionMode)
1617 : {
1618 0 : if (meSelectionMode != eSelectionMode)
1619 : {
1620 0 : meSelectionMode = eSelectionMode;
1621 0 : UpdateSelection();
1622 : }
1623 0 : }
1624 :
1625 :
1626 :
1627 :
1628 0 : void MultiSelectionModeHandler::UpdateSelectionState (
1629 : const model::SharedPageDescriptor& rpDescriptor,
1630 : const bool bIsInSelection) const
1631 : {
1632 : // Determine whether the page was selected before the rectangle
1633 : // selection was started.
1634 0 : const bool bWasSelected (rpDescriptor->HasState(model::PageDescriptor::ST_WasSelected));
1635 :
1636 : // Combine the two selection states depending on the selection mode.
1637 0 : bool bSelect (false);
1638 0 : switch(meSelectionMode)
1639 : {
1640 : case SM_Normal:
1641 0 : bSelect = bIsInSelection;
1642 0 : break;
1643 :
1644 : case SM_Add:
1645 0 : bSelect = bIsInSelection || bWasSelected;
1646 0 : break;
1647 :
1648 : case SM_Toggle:
1649 0 : if (bIsInSelection)
1650 0 : bSelect = !bWasSelected;
1651 : else
1652 0 : bSelect = bWasSelected;
1653 0 : break;
1654 : }
1655 :
1656 : // Set the new selection state.
1657 0 : if (bSelect)
1658 0 : mrSlideSorter.GetController().GetPageSelector().SelectPage(rpDescriptor);
1659 : else
1660 0 : mrSlideSorter.GetController().GetPageSelector().DeselectPage(rpDescriptor);
1661 0 : }
1662 :
1663 :
1664 :
1665 :
1666 0 : void MultiSelectionModeHandler::UpdateModelPosition (const Point& rMouseModelPosition)
1667 : {
1668 0 : maSecondCorner = rMouseModelPosition;
1669 0 : UpdateSelection();
1670 0 : }
1671 :
1672 :
1673 :
1674 :
1675 0 : void MultiSelectionModeHandler::UpdateSelection (void)
1676 : {
1677 0 : view::SlideSorterView::DrawLock aLock (mrSlideSorter);
1678 :
1679 0 : model::SlideSorterModel& rModel (mrSlideSorter.GetModel());
1680 0 : const sal_Int32 nPageCount (rModel.GetPageCount());
1681 :
1682 : const sal_Int32 nIndexUnderMouse (
1683 0 : mrSlideSorter.GetView().GetLayouter().GetIndexAtPoint (
1684 : maSecondCorner,
1685 : false,
1686 0 : false));
1687 0 : if (nIndexUnderMouse>=0 && nIndexUnderMouse<nPageCount)
1688 : {
1689 0 : if (mnAnchorIndex < 0)
1690 0 : mnAnchorIndex = nIndexUnderMouse;
1691 0 : mnSecondIndex = nIndexUnderMouse;
1692 :
1693 0 : Range aRange (mnAnchorIndex, mnSecondIndex);
1694 0 : aRange.Justify();
1695 :
1696 0 : for (sal_Int32 nIndex=0; nIndex<nPageCount; ++nIndex)
1697 : {
1698 0 : UpdateSelectionState(rModel.GetPageDescriptor(nIndex), aRange.IsInside(nIndex));
1699 : }
1700 0 : }
1701 0 : }
1702 :
1703 :
1704 :
1705 :
1706 : //===== DragAndDropModeHandler ================================================
1707 :
1708 0 : DragAndDropModeHandler::DragAndDropModeHandler (
1709 : SlideSorter& rSlideSorter,
1710 : #ifndef MACOSX
1711 : SelectionFunction& rSelectionFunction)
1712 : #else
1713 : SelectionFunction& rSelectionFunction,
1714 : const Point& rMousePosition,
1715 : ::Window* pWindow)
1716 : #endif
1717 0 : : ModeHandler(rSlideSorter, rSelectionFunction, false)
1718 : {
1719 : #ifndef MACOSX
1720 0 : }
1721 :
1722 :
1723 0 : void DragAndDropModeHandler::Initialize(const Point& rMousePosition, ::Window* pWindow)
1724 : {
1725 : #endif
1726 0 : SdTransferable* pDragTransferable = SD_MOD()->pTransferDrag;
1727 0 : if (pDragTransferable==NULL && mrSlideSorter.GetViewShell() != NULL)
1728 : {
1729 : SlideSorterViewShell* pSlideSorterViewShell
1730 0 : = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
1731 0 : if (pSlideSorterViewShell != NULL)
1732 0 : pSlideSorterViewShell->StartDrag(rMousePosition, pWindow);
1733 0 : pDragTransferable = SD_MOD()->pTransferDrag;
1734 : }
1735 :
1736 0 : mpDragAndDropContext.reset(new DragAndDropContext(mrSlideSorter));
1737 0 : mrSlideSorter.GetController().GetInsertionIndicatorHandler()->Start(
1738 : pDragTransferable != NULL
1739 0 : && pDragTransferable->GetView()==&mrSlideSorter.GetView());
1740 0 : }
1741 :
1742 :
1743 :
1744 :
1745 0 : DragAndDropModeHandler::~DragAndDropModeHandler (void)
1746 : {
1747 0 : if (mpDragAndDropContext)
1748 : {
1749 : // Disconnect the substitution handler from this selection function.
1750 0 : mpDragAndDropContext->SetTargetSlideSorter();
1751 0 : mpDragAndDropContext.reset();
1752 : }
1753 0 : mrSlideSorter.GetController().GetInsertionIndicatorHandler()->End(Animator::AM_Animated);
1754 0 : }
1755 :
1756 :
1757 :
1758 :
1759 0 : SelectionFunction::Mode DragAndDropModeHandler::GetMode (void) const
1760 : {
1761 0 : return SelectionFunction::DragAndDropMode;
1762 : }
1763 :
1764 :
1765 :
1766 :
1767 0 : void DragAndDropModeHandler::Abort (void)
1768 : {
1769 0 : mrSlideSorter.GetController().GetClipboard().Abort();
1770 0 : if (mpDragAndDropContext)
1771 0 : mpDragAndDropContext->Dispose();
1772 : // mrSlideSorter.GetView().RequestRepaint(mrSlideSorter.GetModel().RestoreSelection());
1773 0 : }
1774 :
1775 :
1776 :
1777 :
1778 0 : bool DragAndDropModeHandler::ProcessButtonUpEvent (
1779 : SelectionFunction::EventDescriptor& rDescriptor)
1780 : {
1781 0 : if (Match(rDescriptor.mnEventCode, BUTTON_UP | LEFT_BUTTON))
1782 : {
1783 : // The following Process() call may lead to the desctruction
1784 : // of rDescriptor.mpHitDescriptor so release our reference to it.
1785 0 : rDescriptor.mpHitDescriptor.reset();
1786 0 : mrSelectionFunction.SwitchToNormalMode();
1787 0 : return true;
1788 : }
1789 : else
1790 0 : return false;
1791 : }
1792 :
1793 :
1794 :
1795 :
1796 0 : bool DragAndDropModeHandler::ProcessDragEvent (SelectionFunction::EventDescriptor& rDescriptor)
1797 : {
1798 : OSL_ASSERT(mpDragAndDropContext);
1799 :
1800 0 : if (rDescriptor.mbIsLeaving)
1801 : {
1802 0 : mrSelectionFunction.SwitchToNormalMode();
1803 : }
1804 0 : else if (mpDragAndDropContext)
1805 : {
1806 : mpDragAndDropContext->UpdatePosition(
1807 : rDescriptor.maMousePosition,
1808 0 : rDescriptor.meDragMode);
1809 : }
1810 :
1811 0 : return true;
1812 : }
1813 :
1814 :
1815 :
1816 :
1817 9 : } } } // end of namespace ::sd::slidesorter::controller
1818 :
1819 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|