Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include "controller/SlsInsertionIndicatorHandler.hxx"
22 : #include "controller/SlsProperties.hxx"
23 : #include "view/SlideSorterView.hxx"
24 : #include "view/SlsLayouter.hxx"
25 : #include "view/SlsInsertionIndicatorOverlay.hxx"
26 : #include "model/SlideSorterModel.hxx"
27 : #include "model/SlsPageEnumerationProvider.hxx"
28 : #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
29 :
30 : #include "SlideSorter.hxx"
31 :
32 : using namespace ::com::sun::star::datatransfer::dnd::DNDConstants;
33 :
34 : namespace sd { namespace slidesorter { namespace controller {
35 :
36 :
37 0 : InsertionIndicatorHandler::InsertionIndicatorHandler (SlideSorter& rSlideSorter)
38 : : mrSlideSorter(rSlideSorter),
39 : mpInsertAnimator(),
40 0 : mpInsertionIndicatorOverlay(new view::InsertionIndicatorOverlay(rSlideSorter)),
41 : maInsertPosition(),
42 : meMode(MoveMode),
43 : mbIsInsertionTrivial(false),
44 : mbIsActive(false),
45 0 : mbIsReadOnly(mrSlideSorter.GetModel().IsReadOnly()),
46 : mbIsOverSourceView(true),
47 : maIconSize(0,0),
48 0 : mbIsForcedShow(false)
49 : {
50 0 : }
51 :
52 :
53 :
54 :
55 0 : InsertionIndicatorHandler::~InsertionIndicatorHandler (void)
56 : {
57 0 : }
58 :
59 :
60 :
61 :
62 0 : void InsertionIndicatorHandler::Start (const bool bIsOverSourceView)
63 : {
64 0 : if (mbIsActive)
65 : {
66 : OSL_ASSERT(!mbIsActive);
67 : }
68 :
69 0 : mbIsReadOnly = mrSlideSorter.GetModel().IsReadOnly();
70 0 : if (mbIsReadOnly)
71 0 : return;
72 :
73 0 : mbIsActive = true;
74 0 : mbIsOverSourceView = bIsOverSourceView;
75 : }
76 :
77 :
78 :
79 :
80 0 : void InsertionIndicatorHandler::End (const controller::Animator::AnimationMode eMode)
81 : {
82 0 : if (mbIsForcedShow || ! mbIsActive || mbIsReadOnly)
83 0 : return;
84 :
85 0 : GetInsertAnimator()->Reset(eMode);
86 :
87 0 : mbIsActive = false;
88 : // maInsertPosition = view::InsertPosition();
89 0 : meMode = UnknownMode;
90 :
91 0 : mpInsertionIndicatorOverlay->Hide();
92 0 : mpInsertionIndicatorOverlay.reset(new view::InsertionIndicatorOverlay(mrSlideSorter));
93 : }
94 :
95 :
96 :
97 :
98 0 : void InsertionIndicatorHandler::ForceShow (void)
99 : {
100 0 : mbIsForcedShow = true;
101 0 : }
102 :
103 :
104 :
105 :
106 0 : void InsertionIndicatorHandler::ForceEnd (void)
107 : {
108 0 : mbIsForcedShow = false;
109 0 : End(Animator::AM_Immediate);
110 0 : }
111 :
112 :
113 :
114 :
115 0 : void InsertionIndicatorHandler::UpdateIndicatorIcon (const SdTransferable* pTransferable)
116 : {
117 0 : mpInsertionIndicatorOverlay->Create(pTransferable);
118 0 : maIconSize = mpInsertionIndicatorOverlay->GetSize();
119 0 : }
120 :
121 :
122 :
123 :
124 0 : InsertionIndicatorHandler::Mode InsertionIndicatorHandler::GetModeFromDndAction (
125 : const sal_Int8 nDndAction)
126 : {
127 0 : if ((nDndAction & ACTION_MOVE) != 0)
128 0 : return MoveMode;
129 0 : else if ((nDndAction & ACTION_COPY) != 0)
130 0 : return CopyMode;
131 : else
132 0 : return UnknownMode;
133 : }
134 :
135 :
136 :
137 :
138 0 : void InsertionIndicatorHandler::UpdatePosition (
139 : const Point& rMouseModelPosition,
140 : const Mode eMode)
141 : {
142 0 : if ( ! mbIsActive)
143 0 : return;
144 :
145 0 : if (mbIsReadOnly)
146 0 : return;
147 :
148 0 : SetPosition(rMouseModelPosition, eMode);
149 : }
150 :
151 :
152 :
153 :
154 0 : void InsertionIndicatorHandler::UpdatePosition (
155 : const Point& rMouseModelPosition,
156 : const sal_Int8 nDndAction)
157 : {
158 0 : UpdatePosition(rMouseModelPosition, GetModeFromDndAction(nDndAction));
159 0 : }
160 :
161 :
162 :
163 :
164 0 : bool InsertionIndicatorHandler::IsActive (void) const
165 : {
166 0 : return mbIsActive;
167 : }
168 :
169 :
170 :
171 :
172 0 : sal_Int32 InsertionIndicatorHandler::GetInsertionPageIndex (void) const
173 : {
174 0 : if (mbIsReadOnly)
175 0 : return -1;
176 : else
177 0 : return maInsertPosition.GetIndex();
178 : }
179 :
180 :
181 :
182 :
183 0 : void InsertionIndicatorHandler::SetPosition (
184 : const Point& rPoint,
185 : const Mode eMode)
186 : {
187 0 : view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter());
188 :
189 : const view::InsertPosition aInsertPosition (rLayouter.GetInsertPosition(
190 : rPoint,
191 : maIconSize,
192 0 : mrSlideSorter.GetModel()));
193 :
194 0 : if (maInsertPosition != aInsertPosition
195 0 : || meMode != eMode
196 : // || ! mpInsertionIndicatorOverlay->IsVisible()
197 : )
198 : {
199 0 : maInsertPosition = aInsertPosition;
200 0 : meMode = eMode;
201 0 : mbIsInsertionTrivial = IsInsertionTrivial(maInsertPosition.GetIndex(), eMode);
202 0 : if (maInsertPosition.GetIndex()>=0 && ! mbIsInsertionTrivial)
203 : {
204 0 : mpInsertionIndicatorOverlay->SetLocation(maInsertPosition.GetLocation());
205 :
206 0 : GetInsertAnimator()->SetInsertPosition(maInsertPosition);
207 0 : mpInsertionIndicatorOverlay->Show();
208 : }
209 : else
210 : {
211 0 : GetInsertAnimator()->Reset(Animator::AM_Animated);
212 0 : mpInsertionIndicatorOverlay->Hide();
213 : }
214 : }
215 0 : }
216 :
217 :
218 :
219 :
220 0 : ::boost::shared_ptr<view::InsertAnimator> InsertionIndicatorHandler::GetInsertAnimator (void)
221 : {
222 0 : if ( ! mpInsertAnimator)
223 0 : mpInsertAnimator.reset(new view::InsertAnimator(mrSlideSorter));
224 0 : return mpInsertAnimator;
225 : }
226 :
227 :
228 :
229 :
230 0 : bool InsertionIndicatorHandler::IsInsertionTrivial (
231 : const sal_Int32 nInsertionIndex,
232 : const Mode eMode) const
233 : {
234 0 : if (eMode == CopyMode)
235 0 : return false;
236 0 : else if (eMode == UnknownMode)
237 0 : return true;
238 :
239 0 : if ( ! mbIsOverSourceView)
240 0 : return false;
241 :
242 : // Iterate over all selected pages and check whether there are
243 : // holes. While we do this we remember the indices of the first and
244 : // last selected page as preparation for the next step.
245 0 : sal_Int32 nCurrentIndex = -1;
246 0 : sal_Int32 nFirstIndex = -1;
247 0 : sal_Int32 nLastIndex = -1;
248 : model::PageEnumeration aSelectedPages (
249 : model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
250 0 : mrSlideSorter.GetModel()));
251 0 : while (aSelectedPages.HasMoreElements())
252 : {
253 0 : model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
254 :
255 : // Get the page number and compare it to the last one.
256 0 : const sal_Int32 nPageNumber (pDescriptor->GetPageIndex());
257 0 : if (nCurrentIndex>=0 && nPageNumber>(nCurrentIndex+1))
258 0 : return false;
259 : else
260 0 : nCurrentIndex = nPageNumber;
261 :
262 : // Remember indices of the first and last page of the selection.
263 0 : if (nFirstIndex == -1)
264 0 : nFirstIndex = nPageNumber;
265 0 : nLastIndex = nPageNumber;
266 0 : }
267 :
268 : // When we come here then the selection has no holes. We still have
269 : // to check that the insertion position is not directly in front or
270 : // directly behind the selection and thus moving the selection there
271 : // would not change the model.
272 0 : if (nInsertionIndex<nFirstIndex || nInsertionIndex>(nLastIndex+1))
273 0 : return false;
274 :
275 0 : return true;
276 : }
277 :
278 :
279 :
280 :
281 0 : bool InsertionIndicatorHandler::IsInsertionTrivial (const sal_Int8 nDndAction)
282 : {
283 0 : return IsInsertionTrivial(GetInsertionPageIndex(), GetModeFromDndAction(nDndAction));
284 : }
285 :
286 :
287 :
288 :
289 : //===== InsertionIndicatorHandler::ForceShowContext ===========================
290 :
291 0 : InsertionIndicatorHandler::ForceShowContext::ForceShowContext (
292 : const ::boost::shared_ptr<InsertionIndicatorHandler>& rpHandler)
293 0 : : mpHandler(rpHandler)
294 : {
295 0 : mpHandler->ForceShow();
296 0 : }
297 :
298 :
299 :
300 :
301 0 : InsertionIndicatorHandler::ForceShowContext::~ForceShowContext (void)
302 : {
303 0 : mpHandler->ForceEnd();
304 0 : }
305 :
306 : } } } // end of namespace ::sd::slidesorter::controller
307 :
308 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|