1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "SlsDragAndDropContext.hxx"
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "SlideSorter.hxx"
29cdf0e10cSrcweir #include "model/SlideSorterModel.hxx"
30cdf0e10cSrcweir #include "model/SlsPageEnumerationProvider.hxx"
31cdf0e10cSrcweir #include "view/SlideSorterView.hxx"
32cdf0e10cSrcweir #include "controller/SlideSorterController.hxx"
33cdf0e10cSrcweir #include "controller/SlsInsertionIndicatorHandler.hxx"
34cdf0e10cSrcweir #include "controller/SlsScrollBarManager.hxx"
35cdf0e10cSrcweir #include "controller/SlsProperties.hxx"
36cdf0e10cSrcweir #include "controller/SlsSelectionFunction.hxx"
37cdf0e10cSrcweir #include "controller/SlsSelectionManager.hxx"
38cdf0e10cSrcweir #include "controller/SlsClipboard.hxx"
39cdf0e10cSrcweir #include "controller/SlsTransferableData.hxx"
40cdf0e10cSrcweir #include "DrawDocShell.hxx"
41cdf0e10cSrcweir #include "drawdoc.hxx"
42cdf0e10cSrcweir #include "app.hrc"
43cdf0e10cSrcweir #include "sdtreelb.hxx"
44cdf0e10cSrcweir #include <sfx2/bindings.hxx>
45cdf0e10cSrcweir #include <boost/bind.hpp>
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace sd { namespace slidesorter { namespace controller {
48cdf0e10cSrcweir
DragAndDropContext(SlideSorter & rSlideSorter)49cdf0e10cSrcweir DragAndDropContext::DragAndDropContext (SlideSorter& rSlideSorter)
50cdf0e10cSrcweir : mpTargetSlideSorter(&rSlideSorter),
51cdf0e10cSrcweir mnInsertionIndex(-1)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir ::std::vector<const SdPage*> aPages;
54cdf0e10cSrcweir
55cdf0e10cSrcweir // No Drag-and-Drop for master pages.
56cdf0e10cSrcweir if (rSlideSorter.GetModel().GetEditMode() != EM_PAGE)
57cdf0e10cSrcweir return;
58cdf0e10cSrcweir
59cdf0e10cSrcweir // For poperly handling transferables created by the navigator we
60cdf0e10cSrcweir // need additional information. For this a user data object is
61cdf0e10cSrcweir // created that contains the necessary information.
62cdf0e10cSrcweir SdTransferable* pTransferable = SD_MOD()->pTransferDrag;
63cdf0e10cSrcweir SdPageObjsTLB::SdPageObjsTransferable* pTreeListBoxTransferable
64cdf0e10cSrcweir = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable*>(pTransferable);
65cdf0e10cSrcweir if (pTreeListBoxTransferable!=NULL && !TransferableData::GetFromTransferable(pTransferable))
66cdf0e10cSrcweir {
67cdf0e10cSrcweir pTransferable->AddUserData(
68cdf0e10cSrcweir rSlideSorter.GetController().GetClipboard().CreateTransferableUserData(pTransferable));
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir rSlideSorter.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable);
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir
~DragAndDropContext(void)77cdf0e10cSrcweir DragAndDropContext::~DragAndDropContext (void)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir SetTargetSlideSorter (NULL, Point(0,0), InsertionIndicatorHandler::UnknownMode, false);
80cdf0e10cSrcweir }
81cdf0e10cSrcweir
82cdf0e10cSrcweir
83cdf0e10cSrcweir
84cdf0e10cSrcweir
GetPagesFromBookmarks(::std::vector<const SdPage * > & rPages,sal_Int32 & rnSelectionCount,DrawDocShell * pDocShell,const List & rBookmarks) const85cdf0e10cSrcweir void DragAndDropContext::GetPagesFromBookmarks (
86cdf0e10cSrcweir ::std::vector<const SdPage*>& rPages,
87cdf0e10cSrcweir sal_Int32& rnSelectionCount,
88cdf0e10cSrcweir DrawDocShell* pDocShell,
89cdf0e10cSrcweir const List& rBookmarks) const
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if (pDocShell == NULL)
92cdf0e10cSrcweir return;
93cdf0e10cSrcweir
94cdf0e10cSrcweir const SdDrawDocument* pDocument = pDocShell->GetDoc();
95cdf0e10cSrcweir if (pDocument == NULL)
96cdf0e10cSrcweir return;
97cdf0e10cSrcweir
98cdf0e10cSrcweir for (sal_uLong nIndex=0,nCount=rBookmarks.Count(); nIndex<nCount; ++nIndex)
99cdf0e10cSrcweir {
100cdf0e10cSrcweir const String sPageName (*static_cast<String*>(rBookmarks.GetObject(nIndex)));
101cdf0e10cSrcweir sal_Bool bIsMasterPage (sal_False);
102cdf0e10cSrcweir const sal_uInt16 nPageIndex (pDocument->GetPageByName(sPageName, bIsMasterPage));
103cdf0e10cSrcweir if (nPageIndex == SDRPAGE_NOTFOUND)
104cdf0e10cSrcweir continue;
105cdf0e10cSrcweir
106cdf0e10cSrcweir const SdPage* pPage = dynamic_cast<const SdPage*>(pDocument->GetPage(nPageIndex));
107cdf0e10cSrcweir if (pPage != NULL)
108cdf0e10cSrcweir rPages.push_back(pPage);
109cdf0e10cSrcweir }
110cdf0e10cSrcweir rnSelectionCount = rBookmarks.Count();
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir
114cdf0e10cSrcweir
115cdf0e10cSrcweir
GetPagesFromSelection(::std::vector<const SdPage * > & rPages,sal_Int32 & rnSelectionCount,model::PageEnumeration & rSelection) const116cdf0e10cSrcweir void DragAndDropContext::GetPagesFromSelection (
117cdf0e10cSrcweir ::std::vector<const SdPage*>& rPages,
118cdf0e10cSrcweir sal_Int32& rnSelectionCount,
119cdf0e10cSrcweir model::PageEnumeration& rSelection) const
120cdf0e10cSrcweir {
121cdf0e10cSrcweir // Show a new substitution for the selected page objects.
122cdf0e10cSrcweir rnSelectionCount = 0;
123cdf0e10cSrcweir
124cdf0e10cSrcweir while (rSelection.HasMoreElements())
125cdf0e10cSrcweir {
126cdf0e10cSrcweir model::SharedPageDescriptor pDescriptor (rSelection.GetNextElement());
127cdf0e10cSrcweir if (rPages.size() < 3)
128cdf0e10cSrcweir rPages.push_back(pDescriptor->GetPage());
129cdf0e10cSrcweir ++rnSelectionCount;
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir
134cdf0e10cSrcweir
135cdf0e10cSrcweir
Dispose(void)136cdf0e10cSrcweir void DragAndDropContext::Dispose (void)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir mnInsertionIndex = -1;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir
142cdf0e10cSrcweir
143cdf0e10cSrcweir
UpdatePosition(const Point & rMousePosition,const InsertionIndicatorHandler::Mode eMode,const bool bAllowAutoScroll)144cdf0e10cSrcweir void DragAndDropContext::UpdatePosition (
145cdf0e10cSrcweir const Point& rMousePosition,
146cdf0e10cSrcweir const InsertionIndicatorHandler::Mode eMode,
147cdf0e10cSrcweir const bool bAllowAutoScroll)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir if (mpTargetSlideSorter == NULL)
150cdf0e10cSrcweir return;
151cdf0e10cSrcweir
152cdf0e10cSrcweir if (mpTargetSlideSorter->GetProperties()->IsUIReadOnly())
153cdf0e10cSrcweir return;
154cdf0e10cSrcweir
155cdf0e10cSrcweir // Convert window coordinates into model coordinates (we need the
156cdf0e10cSrcweir // window coordinates for auto-scrolling because that remains
157cdf0e10cSrcweir // constant while scrolling.)
158cdf0e10cSrcweir SharedSdWindow pWindow (mpTargetSlideSorter->GetContentWindow());
159cdf0e10cSrcweir const Point aMouseModelPosition (pWindow->PixelToLogic(rMousePosition));
160cdf0e10cSrcweir ::boost::shared_ptr<InsertionIndicatorHandler> pInsertionIndicatorHandler (
161cdf0e10cSrcweir mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler());
162cdf0e10cSrcweir
163cdf0e10cSrcweir if ( ! (bAllowAutoScroll
164cdf0e10cSrcweir && mpTargetSlideSorter->GetController().GetScrollBarManager().AutoScroll(
165cdf0e10cSrcweir rMousePosition,
166cdf0e10cSrcweir ::boost::bind(
167cdf0e10cSrcweir &DragAndDropContext::UpdatePosition, this, rMousePosition, eMode, false))))
168cdf0e10cSrcweir {
169cdf0e10cSrcweir pInsertionIndicatorHandler->UpdatePosition(aMouseModelPosition, eMode);
170cdf0e10cSrcweir
171cdf0e10cSrcweir // Remember the new insertion index.
172cdf0e10cSrcweir mnInsertionIndex = pInsertionIndicatorHandler->GetInsertionPageIndex();
173cdf0e10cSrcweir if (pInsertionIndicatorHandler->IsInsertionTrivial(mnInsertionIndex, eMode))
174cdf0e10cSrcweir mnInsertionIndex = -1;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir
179cdf0e10cSrcweir
180cdf0e10cSrcweir
SetTargetSlideSorter(SlideSorter * pSlideSorter,const Point aMousePosition,const InsertionIndicatorHandler::Mode eMode,const bool bIsOverSourceView)181cdf0e10cSrcweir void DragAndDropContext::SetTargetSlideSorter (
182cdf0e10cSrcweir SlideSorter* pSlideSorter,
183cdf0e10cSrcweir const Point aMousePosition,
184cdf0e10cSrcweir const InsertionIndicatorHandler::Mode eMode,
185cdf0e10cSrcweir const bool bIsOverSourceView)
186cdf0e10cSrcweir {
187cdf0e10cSrcweir if (mpTargetSlideSorter != NULL)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir mpTargetSlideSorter->GetController().GetScrollBarManager().StopAutoScroll();
190cdf0e10cSrcweir mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->End(
191cdf0e10cSrcweir Animator::AM_Animated);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir mpTargetSlideSorter = pSlideSorter;
195cdf0e10cSrcweir
196cdf0e10cSrcweir if (mpTargetSlideSorter != NULL)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->Start(
199cdf0e10cSrcweir bIsOverSourceView);
200cdf0e10cSrcweir mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->UpdatePosition(
201cdf0e10cSrcweir aMousePosition,
202cdf0e10cSrcweir eMode);
203cdf0e10cSrcweir
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
207cdf0e10cSrcweir
208cdf0e10cSrcweir } } } // end of namespace ::sd::slidesorter::controller
209