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