1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include "controller/SlsInsertionIndicatorHandler.hxx"
21 #include "controller/SlsProperties.hxx"
22 #include "view/SlideSorterView.hxx"
23 #include "view/SlsLayouter.hxx"
24 #include "view/SlsInsertionIndicatorOverlay.hxx"
25 #include "model/SlideSorterModel.hxx"
26 #include "model/SlsPageEnumerationProvider.hxx"
27 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
29 #include "SlideSorter.hxx"
31 using namespace ::com::sun::star::datatransfer::dnd::DNDConstants
;
33 namespace sd
{ namespace slidesorter
{ namespace controller
{
35 InsertionIndicatorHandler::InsertionIndicatorHandler (SlideSorter
& rSlideSorter
)
36 : mrSlideSorter(rSlideSorter
),
38 mpInsertionIndicatorOverlay(new view::InsertionIndicatorOverlay(rSlideSorter
)),
41 mbIsInsertionTrivial(false),
43 mbIsReadOnly(mrSlideSorter
.GetModel().IsReadOnly()),
44 mbIsOverSourceView(true),
50 InsertionIndicatorHandler::~InsertionIndicatorHandler()
54 void InsertionIndicatorHandler::Start (const bool bIsOverSourceView
)
58 OSL_ASSERT(!mbIsActive
);
61 mbIsReadOnly
= mrSlideSorter
.GetModel().IsReadOnly();
66 mbIsOverSourceView
= bIsOverSourceView
;
69 void InsertionIndicatorHandler::End (const controller::Animator::AnimationMode eMode
)
71 if (mbIsForcedShow
|| ! mbIsActive
|| mbIsReadOnly
)
74 GetInsertAnimator()->Reset(eMode
);
77 // maInsertPosition = view::InsertPosition();
80 mpInsertionIndicatorOverlay
->Hide();
81 mpInsertionIndicatorOverlay
.reset(new view::InsertionIndicatorOverlay(mrSlideSorter
));
84 void InsertionIndicatorHandler::ForceShow()
86 mbIsForcedShow
= true;
89 void InsertionIndicatorHandler::ForceEnd()
91 mbIsForcedShow
= false;
92 End(Animator::AM_Immediate
);
95 void InsertionIndicatorHandler::UpdateIndicatorIcon (const SdTransferable
* pTransferable
)
97 mpInsertionIndicatorOverlay
->Create(pTransferable
);
98 maIconSize
= mpInsertionIndicatorOverlay
->GetSize();
101 InsertionIndicatorHandler::Mode
InsertionIndicatorHandler::GetModeFromDndAction (
102 const sal_Int8 nDndAction
)
104 if ((nDndAction
& ACTION_MOVE
) != 0)
106 else if ((nDndAction
& ACTION_COPY
) != 0)
112 void InsertionIndicatorHandler::UpdatePosition (
113 const Point
& rMouseModelPosition
,
122 SetPosition(rMouseModelPosition
, eMode
);
125 void InsertionIndicatorHandler::UpdatePosition (
126 const Point
& rMouseModelPosition
,
127 const sal_Int8 nDndAction
)
129 UpdatePosition(rMouseModelPosition
, GetModeFromDndAction(nDndAction
));
132 sal_Int32
InsertionIndicatorHandler::GetInsertionPageIndex() const
137 return maInsertPosition
.GetIndex();
140 void InsertionIndicatorHandler::SetPosition (
144 view::Layouter
& rLayouter (mrSlideSorter
.GetView().GetLayouter());
146 const view::InsertPosition
aInsertPosition (rLayouter
.GetInsertPosition(
149 mrSlideSorter
.GetModel()));
151 if (maInsertPosition
!= aInsertPosition
153 // || ! mpInsertionIndicatorOverlay->IsVisible()
156 maInsertPosition
= aInsertPosition
;
158 mbIsInsertionTrivial
= IsInsertionTrivial(maInsertPosition
.GetIndex(), eMode
);
159 if (maInsertPosition
.GetIndex()>=0 && ! mbIsInsertionTrivial
)
161 mpInsertionIndicatorOverlay
->SetLocation(maInsertPosition
.GetLocation());
163 GetInsertAnimator()->SetInsertPosition(maInsertPosition
);
164 mpInsertionIndicatorOverlay
->Show();
168 GetInsertAnimator()->Reset(Animator::AM_Animated
);
169 mpInsertionIndicatorOverlay
->Hide();
174 ::boost::shared_ptr
<view::InsertAnimator
> InsertionIndicatorHandler::GetInsertAnimator()
176 if ( ! mpInsertAnimator
)
177 mpInsertAnimator
.reset(new view::InsertAnimator(mrSlideSorter
));
178 return mpInsertAnimator
;
181 bool InsertionIndicatorHandler::IsInsertionTrivial (
182 const sal_Int32 nInsertionIndex
,
183 const Mode eMode
) const
185 if (eMode
== CopyMode
)
187 else if (eMode
== UnknownMode
)
190 if ( ! mbIsOverSourceView
)
193 // Iterate over all selected pages and check whether there are
194 // holes. While we do this we remember the indices of the first and
195 // last selected page as preparation for the next step.
196 sal_Int32 nCurrentIndex
= -1;
197 sal_Int32 nFirstIndex
= -1;
198 sal_Int32 nLastIndex
= -1;
199 model::PageEnumeration
aSelectedPages (
200 model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
201 mrSlideSorter
.GetModel()));
202 while (aSelectedPages
.HasMoreElements())
204 model::SharedPageDescriptor
pDescriptor (aSelectedPages
.GetNextElement());
206 // Get the page number and compare it to the last one.
207 const sal_Int32
nPageNumber (pDescriptor
->GetPageIndex());
208 if (nCurrentIndex
>=0 && nPageNumber
>(nCurrentIndex
+1))
211 nCurrentIndex
= nPageNumber
;
213 // Remember indices of the first and last page of the selection.
214 if (nFirstIndex
== -1)
215 nFirstIndex
= nPageNumber
;
216 nLastIndex
= nPageNumber
;
219 // When we come here then the selection has no holes. We still have
220 // to check that the insertion position is not directly in front or
221 // directly behind the selection and thus moving the selection there
222 // would not change the model.
223 if (nInsertionIndex
<nFirstIndex
|| nInsertionIndex
>(nLastIndex
+1))
229 bool InsertionIndicatorHandler::IsInsertionTrivial (const sal_Int8 nDndAction
)
231 return IsInsertionTrivial(GetInsertionPageIndex(), GetModeFromDndAction(nDndAction
));
234 //===== InsertionIndicatorHandler::ForceShowContext ===========================
236 InsertionIndicatorHandler::ForceShowContext::ForceShowContext (
237 const ::boost::shared_ptr
<InsertionIndicatorHandler
>& rpHandler
)
238 : mpHandler(rpHandler
)
240 mpHandler
->ForceShow();
243 InsertionIndicatorHandler::ForceShowContext::~ForceShowContext()
245 mpHandler
->ForceEnd();
248 } } } // end of namespace ::sd::slidesorter::controller
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */