LibreOffice Module sd (master) 1
SlsInsertionIndicatorHandler.cxx
Go to the documentation of this file.
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
21#include <utility>
23#include <view/SlsLayouter.hxx>
28#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
29#include <osl/diagnose.h>
30
31#include <SlideSorter.hxx>
32
33using namespace ::com::sun::star::datatransfer::dnd::DNDConstants;
34
36
38 : mrSlideSorter(rSlideSorter),
39 mpInsertionIndicatorOverlay(std::make_shared<view::InsertionIndicatorOverlay>(rSlideSorter)),
40 meMode(MoveMode),
41 mbIsInsertionTrivial(false),
42 mbIsActive(false),
43 mbIsReadOnly(mrSlideSorter.GetModel().IsReadOnly()),
44 mbIsOverSourceView(true),
45 maIconSize(0,0),
46 mbIsForcedShow(false)
47{
48}
49
51{
52}
53
54void InsertionIndicatorHandler::Start (const bool bIsOverSourceView)
55{
56 if (mbIsActive)
57 {
58 OSL_ASSERT(!mbIsActive);
59 }
60
62 if (mbIsReadOnly)
63 return;
64
65 mbIsActive = true;
66 mbIsOverSourceView = bIsOverSourceView;
67}
68
70{
72 return;
73
74 GetInsertAnimator()->Reset(eMode);
75
76 mbIsActive = false;
77 // maInsertPosition = view::InsertPosition();
79
81 mpInsertionIndicatorOverlay = std::make_shared<view::InsertionIndicatorOverlay>(mrSlideSorter);
82}
83
85{
86 mbIsForcedShow = true;
87}
88
90{
91 mbIsForcedShow = false;
93}
94
96{
97 mpInsertionIndicatorOverlay->Create(pTransferable);
99}
100
102 const sal_Int8 nDndAction)
103{
104 if ((nDndAction & ACTION_MOVE) != 0)
105 return MoveMode;
106 else if ((nDndAction & ACTION_COPY) != 0)
107 return CopyMode;
108 else
109 return UnknownMode;
110}
111
113 const Point& rMouseModelPosition,
114 const Mode eMode)
115{
116 if ( ! mbIsActive)
117 return;
118
119 if (mbIsReadOnly)
120 return;
121
122 SetPosition(rMouseModelPosition, eMode);
123}
124
126 const Point& rMouseModelPosition,
127 const sal_Int8 nDndAction)
128{
129 UpdatePosition(rMouseModelPosition, GetModeFromDndAction(nDndAction));
130}
131
133{
134 if (mbIsReadOnly)
135 return -1;
136 else
137 return maInsertPosition.GetIndex();
138}
139
141 const Point& rPoint,
142 const Mode eMode)
143{
145
146 const view::InsertPosition aInsertPosition (rLayouter.GetInsertPosition(
147 rPoint,
150
151 if (maInsertPosition == aInsertPosition && meMode == eMode)
152 return;
153
154 maInsertPosition = aInsertPosition;
155 meMode = eMode;
158 {
160
161 GetInsertAnimator()->SetInsertPosition(maInsertPosition);
163 }
164 else
165 {
168 }
169}
170
171std::shared_ptr<view::InsertAnimator> const & InsertionIndicatorHandler::GetInsertAnimator()
172{
173 if ( ! mpInsertAnimator)
174 mpInsertAnimator = std::make_shared<view::InsertAnimator>(mrSlideSorter);
175 return mpInsertAnimator;
176}
177
179 const sal_Int32 nInsertionIndex,
180 const Mode eMode) const
181{
182 if (eMode == CopyMode)
183 return false;
184 else if (eMode == UnknownMode)
185 return true;
186
187 if ( ! mbIsOverSourceView)
188 return false;
189
190 // Iterate over all selected pages and check whether there are
191 // holes. While we do this we remember the indices of the first and
192 // last selected page as preparation for the next step.
193 sal_Int32 nCurrentIndex = -1;
194 sal_Int32 nFirstIndex = -1;
195 sal_Int32 nLastIndex = -1;
196 model::PageEnumeration aSelectedPages (
199 while (aSelectedPages.HasMoreElements())
200 {
201 model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
202
203 // Get the page number and compare it to the last one.
204 const sal_Int32 nPageNumber (pDescriptor->GetPageIndex());
205 if (nCurrentIndex>=0 && nPageNumber>(nCurrentIndex+1))
206 return false;
207 else
208 nCurrentIndex = nPageNumber;
209
210 // Remember indices of the first and last page of the selection.
211 if (nFirstIndex == -1)
212 nFirstIndex = nPageNumber;
213 nLastIndex = nPageNumber;
214 }
215
216 // When we come here then the selection has no holes. We still have
217 // to check that the insertion position is not directly in front or
218 // directly behind the selection and thus moving the selection there
219 // would not change the model.
220 return nInsertionIndex >= nFirstIndex && nInsertionIndex <= (nLastIndex+1);
221}
222
224{
226}
227
228//===== InsertionIndicatorHandler::ForceShowContext ===========================
229
231 std::shared_ptr<InsertionIndicatorHandler> pHandler)
232 : mpHandler(std::move(pHandler))
233{
234 mpHandler->ForceShow();
235}
236
238{
239 mpHandler->ForceEnd();
240}
241
242} // end of namespace ::sd::slidesorter::controller
243
244/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorter & mrSlideSorter
Show previews for all the slides in a document and allow the user to insert or delete slides and modi...
Definition: SlideSorter.hxx:62
model::SlideSorterModel & GetModel() const
view::SlideSorterView & GetView() const
AnimationMode
In some circumstances we have to avoid animation and jump to the final animation state immediately.
Definition: SlsAnimator.hxx:45
sal_Int32 GetInsertionPageIndex() const
Return the insertion index that corresponds with the current graphical location of the insertion indi...
std::shared_ptr< view::InsertAnimator > const & GetInsertAnimator()
void UpdatePosition(const Point &rMouseModelPosition, const Mode eMode)
Set the position of the insertion marker to the given coordinates.
void ForceShow()
Make the insertion indicator visible (that is the show part) and keep it visible, even when the mouse...
std::shared_ptr< view::InsertionIndicatorOverlay > mpInsertionIndicatorOverlay
void End(const controller::Animator::AnimationMode eMode)
Deactivate the insertion marker.
bool IsInsertionTrivial(const sal_Int32 nInsertionIndex, const Mode eMode) const
Determine whether moving the current selection to the current position of the insertion marker would ...
void UpdateIndicatorIcon(const SdTransferable *pTransferable)
Update the indicator icon from the current transferable (from the clipboard or an active drag and dro...
void Start(const bool bIsOverSourceView)
Activate the insertion marker at the given coordinates.
static PageEnumeration CreateSelectedPagesEnumeration(const SlideSorterModel &rModel)
The returned enumeration of slides iterates over the currently selected slides of the given model.
Public class of page enumerations that delegates its calls to an implementation object that can filte...
virtual SharedPageDescriptor GetNextElement() override
Return the next element of the enumeration.
virtual bool HasMoreElements() const override
Return <TRUE> when the enumeration has more elements, i.e.
Collect all values concerning the logical and visual properties of the insertion position that is use...
Calculate the size and position of page objects displayed by a slide sorter.
Definition: SlsLayouter.hxx:60
InsertPosition GetInsertPosition(const Point &rModelPosition, const Size &rIndicatorSize, model::SlideSorterModel const &rModel) const
Return an object that describes the logical and visual properties of where to do an insert operation ...
ColorMode meMode
HandlerSharedPtrT mpHandler
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
bool mbIsActive
Mode eMode
std::shared_ptr< T > make_shared(Args &&... args)
std::shared_ptr< PageDescriptor > SharedPageDescriptor
signed char sal_Int8