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_CLIPBOARD
25 #define SD_SLIDESORTER_CLIPBOARD
26 
27 #include "ViewClipboard.hxx"
28 #include "controller/SlsSelectionObserver.hxx"
29 #include "sdxfer.hxx"
30 
31 #include <sal/types.h>
32 #include <tools/solar.h>
33 #include <svx/svdpage.hxx>
34 
35 #include <set>
36 
37 class SfxRequest;
38 class Window;
39 
40 struct AcceptDropEvent;
41 class DropTargetHelper;
42 struct ExecuteDropEvent;
43 class Point;
44 class SdPage;
45 class Window;
46 
47 namespace sd {
48 class Window;
49 }
50 
51 namespace sd { namespace slidesorter {
52 class SlideSorter;
53 } }
54 
55 namespace sd { namespace slidesorter { namespace model {
56 class PageDescriptor;
57 } } }
58 
59 namespace { class NavigatorDropEvent; }
60 
61 namespace sd { namespace slidesorter { namespace controller {
62 
63 class SlideSorterController;
64 
65 class Clipboard
66     : public ViewClipboard
67 {
68 public:
69     Clipboard (SlideSorter& rSlideSorter);
70     ~Clipboard (void);
71 
72     /** Create a slide sorter transferable from the given sd
73         transferable.  The returned transferable is set up with all
74         information necessary so that it can be dropped on a slide sorter.
75     */
76     ::boost::shared_ptr<SdTransferable::UserData> CreateTransferableUserData (SdTransferable* pTransferable);
77 
78     void HandleSlotCall (SfxRequest& rRequest);
79 
80     void DoCut (::Window* pWindow = 0);
81     void DoCopy (::Window* pWindow = 0);
82     void DoPaste (::Window* pWindow = 0);
83     void DoDelete (::Window* pWindow = 0);
84 
85     void StartDrag (
86         const Point& rDragPt,
87         ::Window* pWindow );
88 
89 	void DragFinished (
90         sal_Int8 nDropAction);
91 
92     sal_Int8 AcceptDrop (
93         const AcceptDropEvent& rEvt,
94         DropTargetHelper& rTargetHelper,
95         ::sd::Window* pTargetWindow = NULL,
96         sal_uInt16 nPage = SDRPAGE_NOTFOUND,
97         sal_uInt16 nLayer = SDRPAGE_NOTFOUND );
98 
99 	sal_Int8 ExecuteDrop (
100         const ExecuteDropEvent& rEvt,
101         DropTargetHelper& rTargetHelper,
102         ::sd::Window* pTargetWindow = NULL,
103         sal_uInt16 nPage = SDRPAGE_NOTFOUND,
104         sal_uInt16 nLayer = SDRPAGE_NOTFOUND);
105 
106     void Abort (void);
107 
108 protected:
109     virtual sal_uInt16 DetermineInsertPosition (
110         const SdTransferable& rTransferable);
111 
112     virtual sal_uInt16 InsertSlides (
113         const SdTransferable& rTransferable,
114         sal_uInt16 nInsertPosition);
115 
116 private:
117     SlideSorter& mrSlideSorter;
118     SlideSorterController& mrController;
119 
120     typedef ::std::vector<SdPage*> PageList;
121     /** Remember the pages that are dragged to another document or to
122         another place in the same document so that they can be removed after
123         a move operation.
124     */
125     PageList maPagesToRemove;
126 
127     /** Remember the pages inserted from another document or another place
128         in the same document so that they can be selected after the
129         drag-and-drop operation is completed.
130     */
131     PageList maPagesToSelect;
132 
133     /** When pages are moved or copied then the selection of the slide
134         sorter has to be updated.  This flag is used to remember whether the
135         selection has to be updated or can stay as it is (sal_False).
136     */
137     bool mbUpdateSelectionPending;
138 
139     /** Used when a drop is executed to combine all undo actions into one.
140         Typically created in ExecuteDrop() and released in DragFinish().
141     */
142     class UndoContext;
143     ::boost::scoped_ptr<UndoContext> mpUndoContext;
144 
145     ::boost::scoped_ptr<SelectionObserver::Context> mpSelectionObserverContext;
146     sal_uLong mnDragFinishedUserEventId;
147 
148     void CreateSlideTransferable (
149         ::Window* pWindow,
150         bool bDrag);
151 
152     /** Select the pages stored in the maPagesToSelect member.  The list in
153         the member is cleared afterwards.
154     */
155     void SelectPages (void);
156 
157     /** Determine the position of where to insert the pages in the current
158         transferable of the sd module.
159         @param pWindow
160             This window is used as parent for dialogs that have to be shown
161             to the user.
162         @return
163             The index in the range [0,n] (both inclusive) with n the number
164             of pages is returned.
165     */
166     sal_Int32 GetInsertionPosition (::Window* pWindow);
167 
168     /** Paste the pages of the transferable of the sd module at the given
169         position.
170         @param nInsertPosition
171             The position at which to insert the pages.  The valid range is
172             [0,n] (both inclusive) with n the number of pages in the
173             document.
174         @return
175             The number of inserted pages is returned.
176     */
177     sal_Int32 PasteTransferable (sal_Int32 nInsertPosition);
178 
179     /** Select a range of pages of the model.  Typical usage is the
180         selection of newly inserted pages.
181         @param nFirstIndex
182             The index of the first page to select.
183         @param nPageCount
184             The number of pages to select.
185     */
186     void SelectPageRange (sal_Int32 nFirstIndex, sal_Int32 nPageCount);
187 
188     /** Return <TRUE/> when the current transferable in the current state of
189         the slidesorter is acceptable to be pasted.  For this the
190         transferable has to
191         a) exist,
192         b) contain one or more regular draw pages, no master pages.
193         When master pages are involved, either in the transferable or in the
194         slide sorter (by it displaying master pages) the drop of the
195         transferable is not accepted.  The reason is the missing
196         implementation of proper handling master pages copy-and-paste.
197     */
198     enum DropType { DT_PAGE, DT_PAGE_FROM_NAVIGATOR, DT_SHAPE, DT_NONE };
199     DropType IsDropAccepted (DropTargetHelper& rTargetHelper) const;
200 
201     /** This method contains the code for AcceptDrop() and ExecuteDrop() shapes.
202         There are only minor differences for the two cases at this level.
203         @param eCommand
204             This parameter specifies whether to do a AcceptDrop() or
205             ExecuteDrop().
206         @param rPosition
207             Since the event is given as void pointer we can not take the
208             mouse position from it.  The caller has to supply it in this
209             parameter.
210         @param pDropEvent
211             Event though the AcceptDropEvent and ExecuteDropEvent are very
212             similar they do not have a common base class.  Because of that
213             we have to use a void* to pass these structs.
214         @param nPage
215             When the page number is given as 0xffff then it is replaced by
216             the number of the page at the mouse position.  If the mouse is
217             not over a page then neither AcceptDrop() nor ExecuteDrop() are
218             executed.
219     */
220     enum DropCommand { DC_ACCEPT, DC_EXECUTE };
221     sal_Int8 ExecuteOrAcceptShapeDrop (
222         DropCommand eCommand,
223         const Point& rPosition,
224         const void* pDropEvent ,
225         DropTargetHelper& rTargetHelper,
226         ::sd::Window* pTargetWindow,
227         sal_uInt16 nPage,
228         sal_uInt16 nLayer);
229 
230     /** Return whether the insertion defined by the transferable is
231         trivial, i.e. would not change either source nor target document.
232     */
233     bool IsInsertionTrivial (
234         SdTransferable* pTransferable,
235         const sal_Int8 nDndAction) const;
236 
237     /** Asynchronous part of DragFinished.  The argument is the sal_Int8
238         nDropAction, disguised as void*.
239     */
240     DECL_LINK(ProcessDragFinished, void*);
241 
242     DECL_LINK(ExecuteNavigatorDrop, NavigatorDropEvent*);
243 };
244 
245 } } } // end of namespace ::sd::slidesorter::controller
246 
247 #endif
248