xref: /AOO41X/main/sd/source/ui/slidesorter/controller/SlsDragAndDropContext.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_sd.hxx"
29 
30 #include "SlsDragAndDropContext.hxx"
31 
32 #include "SlideSorter.hxx"
33 #include "model/SlideSorterModel.hxx"
34 #include "model/SlsPageEnumerationProvider.hxx"
35 #include "view/SlideSorterView.hxx"
36 #include "controller/SlideSorterController.hxx"
37 #include "controller/SlsInsertionIndicatorHandler.hxx"
38 #include "controller/SlsScrollBarManager.hxx"
39 #include "controller/SlsProperties.hxx"
40 #include "controller/SlsSelectionFunction.hxx"
41 #include "controller/SlsSelectionManager.hxx"
42 #include "controller/SlsClipboard.hxx"
43 #include "controller/SlsTransferableData.hxx"
44 #include "DrawDocShell.hxx"
45 #include "drawdoc.hxx"
46 #include "app.hrc"
47 #include "sdtreelb.hxx"
48 #include <sfx2/bindings.hxx>
49 #include <boost/bind.hpp>
50 
51 namespace sd { namespace slidesorter { namespace controller {
52 
53 DragAndDropContext::DragAndDropContext (SlideSorter& rSlideSorter)
54     : mpTargetSlideSorter(&rSlideSorter),
55       mnInsertionIndex(-1)
56 {
57     ::std::vector<const SdPage*> aPages;
58 
59     // No Drag-and-Drop for master pages.
60     if (rSlideSorter.GetModel().GetEditMode() != EM_PAGE)
61         return;
62 
63     // For poperly handling transferables created by the navigator we
64     // need additional information.  For this a user data object is
65     // created that contains the necessary information.
66     SdTransferable* pTransferable = SD_MOD()->pTransferDrag;
67     SdPageObjsTLB::SdPageObjsTransferable* pTreeListBoxTransferable
68         = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable*>(pTransferable);
69     if (pTreeListBoxTransferable!=NULL && !TransferableData::GetFromTransferable(pTransferable))
70     {
71         pTransferable->AddUserData(
72             rSlideSorter.GetController().GetClipboard().CreateTransferableUserData(pTransferable));
73     }
74 
75     rSlideSorter.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable);
76 }
77 
78 
79 
80 
81 DragAndDropContext::~DragAndDropContext (void)
82 {
83     SetTargetSlideSorter (NULL, Point(0,0), InsertionIndicatorHandler::UnknownMode, false);
84 }
85 
86 
87 
88 
89 void DragAndDropContext::GetPagesFromBookmarks (
90     ::std::vector<const SdPage*>& rPages,
91     sal_Int32& rnSelectionCount,
92     DrawDocShell* pDocShell,
93     const List& rBookmarks) const
94 {
95     if (pDocShell == NULL)
96         return;
97 
98     const SdDrawDocument* pDocument = pDocShell->GetDoc();
99     if (pDocument == NULL)
100         return;
101 
102     for (sal_uLong nIndex=0,nCount=rBookmarks.Count(); nIndex<nCount; ++nIndex)
103     {
104         const String sPageName (*static_cast<String*>(rBookmarks.GetObject(nIndex)));
105         sal_Bool bIsMasterPage (sal_False);
106         const sal_uInt16 nPageIndex (pDocument->GetPageByName(sPageName, bIsMasterPage));
107         if (nPageIndex == SDRPAGE_NOTFOUND)
108             continue;
109 
110         const SdPage* pPage = dynamic_cast<const SdPage*>(pDocument->GetPage(nPageIndex));
111         if (pPage != NULL)
112             rPages.push_back(pPage);
113     }
114     rnSelectionCount = rBookmarks.Count();
115 }
116 
117 
118 
119 
120 void DragAndDropContext::GetPagesFromSelection (
121     ::std::vector<const SdPage*>& rPages,
122     sal_Int32& rnSelectionCount,
123     model::PageEnumeration& rSelection) const
124 {
125     // Show a new substitution for the selected page objects.
126     rnSelectionCount = 0;
127 
128     while (rSelection.HasMoreElements())
129 	{
130         model::SharedPageDescriptor pDescriptor (rSelection.GetNextElement());
131         if (rPages.size() < 3)
132             rPages.push_back(pDescriptor->GetPage());
133         ++rnSelectionCount;
134     }
135 }
136 
137 
138 
139 
140 void DragAndDropContext::Dispose (void)
141 {
142     mnInsertionIndex = -1;
143 }
144 
145 
146 
147 
148 void DragAndDropContext::UpdatePosition (
149     const Point& rMousePosition,
150     const InsertionIndicatorHandler::Mode eMode,
151     const bool bAllowAutoScroll)
152 {
153     if (mpTargetSlideSorter == NULL)
154         return;
155 
156     if (mpTargetSlideSorter->GetProperties()->IsUIReadOnly())
157         return;
158 
159     // Convert window coordinates into model coordinates (we need the
160     // window coordinates for auto-scrolling because that remains
161     // constant while scrolling.)
162     SharedSdWindow pWindow (mpTargetSlideSorter->GetContentWindow());
163     const Point aMouseModelPosition (pWindow->PixelToLogic(rMousePosition));
164     ::boost::shared_ptr<InsertionIndicatorHandler> pInsertionIndicatorHandler (
165         mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler());
166 
167     if ( ! (bAllowAutoScroll
168             && mpTargetSlideSorter->GetController().GetScrollBarManager().AutoScroll(
169                 rMousePosition,
170                 ::boost::bind(
171                     &DragAndDropContext::UpdatePosition, this, rMousePosition, eMode, false))))
172     {
173         pInsertionIndicatorHandler->UpdatePosition(aMouseModelPosition, eMode);
174 
175         // Remember the new insertion index.
176         mnInsertionIndex = pInsertionIndicatorHandler->GetInsertionPageIndex();
177         if (pInsertionIndicatorHandler->IsInsertionTrivial(mnInsertionIndex, eMode))
178             mnInsertionIndex = -1;
179     }
180 }
181 
182 
183 
184 
185 void DragAndDropContext::SetTargetSlideSorter (
186     SlideSorter* pSlideSorter,
187     const Point aMousePosition,
188     const InsertionIndicatorHandler::Mode eMode,
189     const bool bIsOverSourceView)
190 {
191     if (mpTargetSlideSorter != NULL)
192     {
193         mpTargetSlideSorter->GetController().GetScrollBarManager().StopAutoScroll();
194         mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->End(
195             Animator::AM_Animated);
196     }
197 
198     mpTargetSlideSorter = pSlideSorter;
199 
200     if (mpTargetSlideSorter != NULL)
201     {
202         mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->Start(
203             bIsOverSourceView);
204         mpTargetSlideSorter->GetController().GetInsertionIndicatorHandler()->UpdatePosition(
205             aMousePosition,
206             eMode);
207 
208     }
209 }
210 
211 
212 } } } // end of namespace ::sd::slidesorter::controller
213