1  /**************************************************************
2   *
3   * Licensed to the Apache Software Foundation (ASF) under one
4   * or more contributor license agreements.  See the NOTICE file
5   * distributed with this work for additional information
6   * regarding copyright ownership.  The ASF licenses this file
7   * to you under the Apache License, Version 2.0 (the
8   * "License"); you may not use this file except in compliance
9   * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   *
20   *************************************************************/
21  
22  
23  
24  #ifndef SD_SLIDESORTER_SELECTION_FUNCTION_HXX
25  #define SD_SLIDESORTER_SELECTION_FUNCTION_HXX
26  
27  #include "model/SlsSharedPageDescriptor.hxx"
28  #include "controller/SlsFocusManager.hxx"
29  #include "controller/SlsInsertionIndicatorHandler.hxx"
30  #include "fupoor.hxx"
31  #include <svtools/transfer.hxx>
32  #include <boost/noncopyable.hpp>
33  #include <boost/scoped_ptr.hpp>
34  
35  class SdSlideViewShell;
36  class SdWindow;
37  class SdSlideView;
38  class SdDrawDocument;
39  class Sound;
40  
41  namespace sd { namespace slidesorter {
42  class SlideSorter;
43  } }
44  
45  namespace sd { namespace slidesorter { namespace controller {
46  
47  class SlideSorterController;
48  class DragAndDropContext;
49  
50  
51  class SelectionFunction
52      : public FuPoor,
53        private ::boost::noncopyable
54  {
55  public:
56      TYPEINFO();
57  
58  	static FunctionReference Create( SlideSorter& rSlideSorter, SfxRequest& rRequest );
59  
60      // Mouse- & Key-Events
61  	virtual sal_Bool KeyInput(const KeyEvent& rKEvt);
62  	virtual sal_Bool MouseMove(const MouseEvent& rMEvt);
63  	virtual sal_Bool MouseButtonUp(const MouseEvent& rMEvt);
64  	virtual sal_Bool MouseButtonDown(const MouseEvent& rMEvt);
65  
66  	virtual void Activate();
67  	virtual void Deactivate();
68  
69  	virtual void ScrollStart();
70  	virtual void ScrollEnd();
71  
72      // Forward to the clipboard manager.
73  	virtual void DoCut (void);
74  
75      // Forward to the clipboard manager.
76  	virtual void DoCopy (void);
77  
78      // Forward to the clipboard manager.
79  	virtual void DoPaste (void);
80  
81  	/** is called when the current function should be aborted. <p>
82  		This is used when a function gets a KEY_ESCAPE but can also
83  		be called directly.
84  
85  		@returns
86              true if a active function was aborted
87  	*/
88  	virtual bool cancel();
89  
90      void MouseDragged (
91          const AcceptDropEvent& rEvent,
92          const sal_Int8 nDragAction);
93  
94      /** Turn of substitution display and insertion indicator.
95      */
96      void NotifyDragFinished (void);
97  
98      /** Call when drag-and-drop or multi selection is started or stopped in
99          order to update permission of mouse over indication.
100      */
101      void UpdateMouseOverIndicationPermission (void);
102  
103      class EventDescriptor;
104      class ModeHandler;
105      friend class ModeHandler;
106      enum Mode
107      {
108          NormalMode,
109          MultiSelectionMode,
110          DragAndDropMode,
111          ButtonMode
112      };
113      void SwitchToNormalMode (void);
114      void SwitchToDragAndDropMode(const Point aMousePosition);
115      void SwitchToMultiSelectionMode (const Point aMousePosition, const sal_uInt32 nEventCode);
116      bool SwitchToButtonMode (void);
117  
118      void ResetShiftKeySelectionAnchor (void);
119      /** Special case handling for when the context menu is hidden.  This
120          method will reinitialize the current mouse position to prevent the
121          mouse motion during the time the context menu is displayed from
122          being interpreted as drag-and-drop start.
123      */
124      void ResetMouseAnchor (void);
125  
126  protected:
127      SlideSorter& mrSlideSorter;
128      SlideSorterController& mrController;
129  
130      SelectionFunction (
131          SlideSorter& rSlideSorter,
132          SfxRequest& rRequest);
133  
134  	virtual ~SelectionFunction();
135  
136  private:
137  
138      // The rectangle of the mouse drag selection.
139  	Rectangle maDragSelectionRectangle;
140  	bool mbDragSelection;
141  
142      // Box of the insert marker in model coordinates.
143      Rectangle maInsertionMarkerBox;
144  
145      /** We use this flag to filter out the cases where MouseMotion() is called
146          with a pressed mouse button but without a prior MouseButtonDown()
147          call.  This is an indication that the mouse button was pressed over
148          another control, e.g. the view tab bar, and that a re-layout of the
149          controls moved the slide sorter under the mouse.
150      */
151      bool mbProcessingMouseButtonDown;
152  
153      bool mbIsDeselectionPending;
154  
155      /** Remember the slide where the shift key was pressed and started a
156          multiselection via keyboard.
157      */
158      sal_Int32 mnShiftKeySelectionAnchor;
159  
160      /** The selection function can be in one of several mutually
161          exclusive modes.
162      */
163      ::boost::shared_ptr<ModeHandler> mpModeHandler;
164  
165      /** Make the slide nOffset slides away of the current one the new
166          current slide.  When the new index is outside the range of valid
167          page numbers it is clipped to that range.
168          @param nOffset
169              When nOffset is negative then go back.  When nOffset if positive go
170              forward.  When it is zero then ignore the call.
171      */
172      void GotoNextPage (int nOffset);
173  
174      /** Make the slide with the given index the new current slide.
175          @param nIndex
176              Index of the new current slide.  When the new index is outside
177              the range of valid page numbers it is clipped to that range.
178      */
179      void GotoPage (int nIndex);
180  
181      void ProcessMouseEvent (sal_uInt32 nEventType, const MouseEvent& rEvent);
182      void ProcessKeyEvent (const KeyEvent& rEvent);
183  
184      // What follows are a couple of helper methods that are used by
185      // ProcessMouseEvent().
186  
187      void ProcessEvent (EventDescriptor& rEvent);
188  
189      void MoveFocus (
190          const FocusManager::FocusMoveDirection eDirection,
191          const bool bIsShiftDown,
192          const bool bIsControlDown);
193  
194      void StopDragAndDrop (void);
195  
196      void SwitchMode (const ::boost::shared_ptr<ModeHandler>& rpHandler);
197  };
198  
199  } } } // end of namespace ::sd::slidesorter::controller
200  
201  #endif
202