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