tdf#85428: Clip strokes
[LibreOffice.git] / sd / source / ui / slidesorter / inc / controller / SlsClipboard.hxx
blob6ced17486efef52dddbbd52473f3a04a76fca941
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <memory>
23 #include <ViewClipboard.hxx>
24 #include <controller/SlsSelectionObserver.hxx>
25 #include <sdxfer.hxx>
27 #include <sal/types.h>
28 #include <o3tl/deleter.hxx>
29 #include <svx/svdtypes.hxx>
31 #include <sddllapi.h>
33 class SfxRequest;
34 struct AcceptDropEvent;
35 class DropTargetHelper;
36 struct ExecuteDropEvent;
37 struct ImplSVEvent;
38 class Point;
39 class SdPage;
40 namespace vcl { class Window; }
42 namespace sd {
43 class Window;
46 namespace sd::slidesorter { class SlideSorter; }
48 namespace sd::slidesorter::controller {
50 class SlideSorterController;
52 class SAL_DLLPUBLIC_RTTI Clipboard final
53 : public ViewClipboard
55 public:
56 Clipboard (SlideSorter& rSlideSorter);
57 virtual ~Clipboard() override;
59 /** Create a slide sorter transferable from the given sd
60 transferable. The returned transferable is set up with all
61 information necessary so that it can be dropped on a slide sorter.
63 static std::shared_ptr<SdTransferable::UserData> CreateTransferableUserData (SdTransferable* pTransferable);
65 void HandleSlotCall (SfxRequest& rRequest);
67 void DoCut ();
68 // Exported for unit test
69 SD_DLLPUBLIC void DoCopy();
70 // Exported for unit test
71 SD_DLLPUBLIC void DoPaste();
72 void DoDelete ();
74 void StartDrag (
75 const Point& rDragPt,
76 vcl::Window* pWindow );
78 void DragFinished (
79 sal_Int8 nDropAction);
81 sal_Int8 AcceptDrop (
82 const AcceptDropEvent& rEvt,
83 DropTargetHelper& rTargetHelper,
84 ::sd::Window* pTargetWindow,
85 sal_uInt16 nPage,
86 SdrLayerID nLayer );
88 sal_Int8 ExecuteDrop (
89 const ExecuteDropEvent& rEvt,
90 DropTargetHelper& rTargetHelper,
91 ::sd::Window* pTargetWindow,
92 sal_uInt16 nPage,
93 SdrLayerID nLayer );
95 void Abort();
97 private:
98 virtual sal_uInt16 DetermineInsertPosition () override;
100 SlideSorter& mrSlideSorter;
101 SlideSorterController& mrController;
103 typedef ::std::vector<SdPage*> PageList;
104 /** Remember the pages that are dragged to another document or to
105 another place in the same document so that they can be removed after
106 a move operation.
108 PageList maPagesToRemove;
110 /** Used when a drop is executed to combine all undo actions into one.
111 Typically created in ExecuteDrop() and released in DragFinish().
113 class UndoContext;
114 std::unique_ptr<UndoContext> mxUndoContext;
116 std::unique_ptr<SelectionObserver::Context, o3tl::default_delete<SelectionObserver::Context>> mxSelectionObserverContext;
117 ImplSVEvent * mnDragFinishedUserEventId;
119 void CreateSlideTransferable (
120 vcl::Window* pWindow,
121 bool bDrag);
123 /** Determine the position of where to insert the pages in the current
124 transferable of the sd module.
125 @return
126 The index in the range [0,n] (both inclusive) with n the number
127 of pages is returned.
129 sal_Int32 GetInsertionPosition ();
131 /** Paste the pages of the transferable of the sd module at the given
132 position.
133 @param nInsertPosition
134 The position at which to insert the pages. The valid range is
135 [0,n] (both inclusive) with n the number of pages in the
136 document.
137 @return
138 The number of inserted pages is returned.
140 sal_Int32 PasteTransferable (sal_Int32 nInsertPosition);
142 /** Select a range of pages of the model. Typically usage is the
143 selection of newly inserted pages.
144 @param nFirstIndex
145 The index of the first page to select.
146 @param nPageCount
147 The number of pages to select.
149 void SelectPageRange (sal_Int32 nFirstIndex, sal_Int32 nPageCount);
151 /** Return <TRUE/> when the current transferable in the current state of
152 the slidesorter is acceptable to be pasted. For this the
153 transferable has to
154 a) exist,
155 b) contain one or more regular draw pages, no master pages.
156 When master pages are involved, either in the transferable or in the
157 slide sorter (by it displaying master pages) the drop of the
158 transferable is not accepted. The reason is the missing
159 implementation of proper handling master pages copy-and-paste.
161 enum DropType { DT_PAGE, DT_PAGE_FROM_NAVIGATOR, DT_SHAPE, DT_NONE };
162 DropType IsDropAccepted() const;
164 /** This method contains the code for AcceptDrop() and ExecuteDrop() shapes.
165 There are only minor differences for the two cases at this level.
166 @param eCommand
167 This parameter specifies whether to do an AcceptDrop() or
168 ExecuteDrop().
169 @param rPosition
170 Since the event is given as void pointer we can not take the
171 mouse position from it. The caller has to supply it in this
172 parameter.
173 @param pDropEvent
174 Event though the AcceptDropEvent and ExecuteDropEvent are very
175 similar they do not have a common base class. Because of that
176 we have to use a void* to pass these structs.
177 @param nPage
178 When the page number is given as 0xffff then it is replaced by
179 the number of the page at the mouse position. If the mouse is
180 not over a page then neither AcceptDrop() nor ExecuteDrop() are
181 executed.
183 enum DropCommand { DC_ACCEPT, DC_EXECUTE };
184 sal_Int8 ExecuteOrAcceptShapeDrop (
185 DropCommand eCommand,
186 const Point& rPosition,
187 const void* pDropEvent ,
188 DropTargetHelper& rTargetHelper,
189 ::sd::Window* pTargetWindow,
190 sal_uInt16 nPage,
191 SdrLayerID nLayer);
193 /** Return whether the insertion defined by the transferable is
194 trivial, ie would not change either source nor target document.
196 bool IsInsertionTrivial (
197 SdTransferable const * pTransferable,
198 const sal_Int8 nDndAction) const;
200 /** Asynchronous part of DragFinished. The argument is the sal_Int8
201 nDropAction, disguised as void*.
203 DECL_DLLPRIVATE_LINK(ProcessDragFinished, void*, void);
206 } // end of namespace ::sd::slidesorter::controller
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */