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 #include "precompiled_sd.hxx"
25
26 #include "SlsDragAndDropContext.hxx"
27
28 #include "SlideSorter.hxx"
29 #include "model/SlideSorterModel.hxx"
30 #include "model/SlsPageEnumerationProvider.hxx"
31 #include "view/SlideSorterView.hxx"
32 #include "controller/SlideSorterController.hxx"
33 #include "controller/SlsInsertionIndicatorHandler.hxx"
34 #include "controller/SlsScrollBarManager.hxx"
35 #include "controller/SlsProperties.hxx"
36 #include "controller/SlsSelectionFunction.hxx"
37 #include "controller/SlsSelectionManager.hxx"
38 #include "controller/SlsClipboard.hxx"
39 #include "controller/SlsTransferableData.hxx"
40 #include "DrawDocShell.hxx"
41 #include "drawdoc.hxx"
42 #include "app.hrc"
43 #include "sdtreelb.hxx"
44 #include <sfx2/bindings.hxx>
45 #include <boost/bind.hpp>
46
47 namespace sd { namespace slidesorter { namespace controller {
48
DragAndDropContext(SlideSorter & rSlideSorter)49 DragAndDropContext::DragAndDropContext (SlideSorter& rSlideSorter)
50 : mpTargetSlideSorter(&rSlideSorter),
51 mnInsertionIndex(-1)
52 {
53 ::std::vector<const SdPage*> aPages;
54
55 // No Drag-and-Drop for master pages.
56 if (rSlideSorter.GetModel().GetEditMode() != EM_PAGE)
57 return;
58
59 // For poperly handling transferables created by the navigator we
60 // need additional information. For this a user data object is
61 // created that contains the necessary information.
62 SdTransferable* pTransferable = SD_MOD()->pTransferDrag;
63 SdPageObjsTLB::SdPageObjsTransferable* pTreeListBoxTransferable
64 = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable*>(pTransferable);
65 if (pTreeListBoxTransferable!=NULL && !TransferableData::GetFromTransferable(pTransferable))
66 {
67 pTransferable->AddUserData(
68 rSlideSorter.GetController().GetClipboard().CreateTransferableUserData(pTransferable));
69 }
70
71 rSlideSorter.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable);
72 }
73
74
75
76
~DragAndDropContext(void)77 DragAndDropContext::~DragAndDropContext (void)
78 {
79 SetTargetSlideSorter (NULL, Point(0,0), InsertionIndicatorHandler::UnknownMode, false);
80 }
81
82
83
84
GetPagesFromBookmarks(::std::vector<const SdPage * > & rPages,sal_Int32 & rnSelectionCount,DrawDocShell * pDocShell,const List & rBookmarks) const85 void DragAndDropContext::GetPagesFromBookmarks (
86 ::std::vector<const SdPage*>& rPages,
87 sal_Int32& rnSelectionCount,
88 DrawDocShell* pDocShell,
89 const List& rBookmarks) const
90 {
91 if (pDocShell == NULL)
92 return;
93
94 const SdDrawDocument* pDocument = pDocShell->GetDoc();
95 if (pDocument == NULL)
96 return;
97
98 for (sal_uLong nIndex=0,nCount=rBookmarks.Count(); nIndex<nCount; ++nIndex)
99 {
100 const String sPageName (*static_cast<String*>(rBookmarks.GetObject(nIndex)));
101 sal_Bool bIsMasterPage (sal_False);
102 const sal_uInt16 nPageIndex (pDocument->GetPageByName(sPageName, bIsMasterPage));
103 if (nPageIndex == SDRPAGE_NOTFOUND)
104 continue;
105
106 const SdPage* pPage = dynamic_cast<const SdPage*>(pDocument->GetPage(nPageIndex));
107 if (pPage != NULL)
108 rPages.push_back(pPage);
109 }
110 rnSelectionCount = rBookmarks.Count();
111 }
112
113
114
115
GetPagesFromSelection(::std::vector<const SdPage * > & rPages,sal_Int32 & rnSelectionCount,model::PageEnumeration & rSelection) const116 void DragAndDropContext::GetPagesFromSelection (
117 ::std::vector<const SdPage*>& rPages,
118 sal_Int32& rnSelectionCount,
119 model::PageEnumeration& rSelection) const
120 {
121 // Show a new substitution for the selected page objects.
122 rnSelectionCount = 0;
123
124 while (rSelection.HasMoreElements())
125 {
126 model::SharedPageDescriptor pDescriptor (rSelection.GetNextElement());
127 if (rPages.size() < 3)
128 rPages.push_back(pDescriptor->GetPage());
129 ++rnSelectionCount;
130 }
131 }
132
133
134
135
Dispose(void)136 void DragAndDropContext::Dispose (void)
137 {
138 mnInsertionIndex = -1;
139 }
140
141
142
143
UpdatePosition(const Point & rMousePosition,const InsertionIndicatorHandler::Mode eMode,const bool bAllowAutoScroll)144 void DragAndDropContext::UpdatePosition (
145 const Point& rMousePosition,
146 const InsertionIndicatorHandler::Mode eMode,
147 const bool bAllowAutoScroll)
148 {
149 if (mpTargetSlideSorter == NULL)
150 return;
151
152 if (mpTargetSlideSorter->GetProperties()->IsUIReadOnly())
153 return;
154
155 // Convert window coordinates into model coordinates (we need the
156 // window coordinates for auto-scrolling because that remains
157 // constant while scrolling.)
158 SharedSdWindow pWindow (mpTargetSlideSorter->GetContentWindow());
159 const Point aMouseModelPosition (pWindow->PixelToLogic(rMousePosition));
160 ::boost::shared_ptr<InsertionIndicatorHandler> pInsertionIndicatorHandler (
161 mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler());
162
163 if ( ! (bAllowAutoScroll
164 && mpTargetSlideSorter->GetController().GetScrollBarManager().AutoScroll(
165 rMousePosition,
166 ::boost::bind(
167 &DragAndDropContext::UpdatePosition, this, rMousePosition, eMode, false))))
168 {
169 pInsertionIndicatorHandler->UpdatePosition(aMouseModelPosition, eMode);
170
171 // Remember the new insertion index.
172 mnInsertionIndex = pInsertionIndicatorHandler->GetInsertionPageIndex();
173 if (pInsertionIndicatorHandler->IsInsertionTrivial(mnInsertionIndex, eMode))
174 mnInsertionIndex = -1;
175 }
176 }
177
178
179
180
SetTargetSlideSorter(SlideSorter * pSlideSorter,const Point aMousePosition,const InsertionIndicatorHandler::Mode eMode,const bool bIsOverSourceView)181 void DragAndDropContext::SetTargetSlideSorter (
182 SlideSorter* pSlideSorter,
183 const Point aMousePosition,
184 const InsertionIndicatorHandler::Mode eMode,
185 const bool bIsOverSourceView)
186 {
187 if (mpTargetSlideSorter != NULL)
188 {
189 mpTargetSlideSorter->GetController().GetScrollBarManager().StopAutoScroll();
190 mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->End(
191 Animator::AM_Animated);
192 }
193
194 mpTargetSlideSorter = pSlideSorter;
195
196 if (mpTargetSlideSorter != NULL)
197 {
198 mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->Start(
199 bIsOverSourceView);
200 mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->UpdatePosition(
201 aMousePosition,
202 eMode);
203
204 }
205 }
206
207
208 } } } // end of namespace ::sd::slidesorter::controller
209