Line data Source code
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 :
20 :
21 : #include "SlideSorter.hxx"
22 : #include "model/SlideSorterModel.hxx"
23 : #include "model/SlsPageDescriptor.hxx"
24 : #include "controller/SlsPageSelector.hxx"
25 : #include "controller/SlideSorterController.hxx"
26 : #include "controller/SlsCurrentSlideManager.hxx"
27 : #include "controller/SlsFocusManager.hxx"
28 : #include "view/SlideSorterView.hxx"
29 : #include "ViewShellBase.hxx"
30 : #include "ViewShell.hxx"
31 : #include "DrawViewShell.hxx"
32 : #include "sdpage.hxx"
33 : #include "FrameView.hxx"
34 : #include <com/sun/star/beans/XPropertySet.hpp>
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::uno;
38 :
39 : using namespace ::sd::slidesorter::model;
40 :
41 :
42 : namespace sd { namespace slidesorter { namespace controller {
43 :
44 :
45 0 : CurrentSlideManager::CurrentSlideManager (SlideSorter& rSlideSorter)
46 : : mrSlideSorter(rSlideSorter),
47 : mnCurrentSlideIndex(-1),
48 : mpCurrentSlide(),
49 0 : maSwitchPageDelayTimer()
50 : {
51 0 : maSwitchPageDelayTimer.SetTimeout(100);
52 0 : maSwitchPageDelayTimer.SetTimeoutHdl(LINK(this,CurrentSlideManager,SwitchPageCallback));
53 0 : }
54 :
55 :
56 :
57 :
58 0 : CurrentSlideManager::~CurrentSlideManager (void)
59 : {
60 0 : }
61 :
62 :
63 :
64 :
65 0 : void CurrentSlideManager::NotifyCurrentSlideChange (const SdPage* pPage)
66 : {
67 0 : if (pPage != NULL)
68 : NotifyCurrentSlideChange(
69 0 : mrSlideSorter.GetModel().GetIndex(
70 : Reference<drawing::XDrawPage>(
71 : const_cast<SdPage*>(pPage)->getUnoPage(),
72 0 : UNO_QUERY)));
73 : else
74 0 : NotifyCurrentSlideChange(-1);
75 0 : }
76 :
77 :
78 :
79 :
80 0 : void CurrentSlideManager::NotifyCurrentSlideChange (const sal_Int32 nSlideIndex)
81 : {
82 0 : if (mnCurrentSlideIndex != nSlideIndex)
83 : {
84 0 : ReleaseCurrentSlide();
85 0 : AcquireCurrentSlide(nSlideIndex);
86 :
87 : // Update the selection.
88 0 : mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
89 0 : if (mpCurrentSlide)
90 : {
91 0 : mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);
92 0 : mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(mpCurrentSlide);
93 : }
94 : }
95 0 : }
96 :
97 :
98 :
99 :
100 0 : void CurrentSlideManager::ReleaseCurrentSlide (void)
101 : {
102 0 : if (mpCurrentSlide.get() != NULL)
103 0 : mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, false);
104 :
105 0 : mpCurrentSlide.reset();
106 0 : mnCurrentSlideIndex = -1;
107 0 : }
108 :
109 :
110 :
111 :
112 0 : bool CurrentSlideManager::IsCurrentSlideIsValid (void)
113 : {
114 0 : return mnCurrentSlideIndex >= 0 && mnCurrentSlideIndex<mrSlideSorter.GetModel().GetPageCount();
115 : }
116 :
117 :
118 :
119 :
120 0 : void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
121 : {
122 0 : mnCurrentSlideIndex = nSlideIndex;
123 :
124 0 : if (IsCurrentSlideIsValid())
125 : {
126 : // Get a descriptor for the XDrawPage reference. Note that the
127 : // given XDrawPage may or may not be member of the slide sorter
128 : // document.
129 0 : mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
130 0 : if (mpCurrentSlide.get() != NULL)
131 0 : mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
132 : }
133 0 : }
134 :
135 :
136 :
137 :
138 0 : void CurrentSlideManager::SwitchCurrentSlide (
139 : const sal_Int32 nSlideIndex,
140 : const bool bUpdateSelection)
141 : {
142 0 : SwitchCurrentSlide(mrSlideSorter.GetModel().GetPageDescriptor(nSlideIndex), bUpdateSelection);
143 0 : }
144 :
145 :
146 :
147 :
148 0 : void CurrentSlideManager::SwitchCurrentSlide (
149 : const SharedPageDescriptor& rpDescriptor,
150 : const bool bUpdateSelection)
151 : {
152 0 : if (rpDescriptor.get() != NULL && mpCurrentSlide!=rpDescriptor)
153 : {
154 0 : ReleaseCurrentSlide();
155 0 : AcquireCurrentSlide((rpDescriptor->GetPage()->GetPageNum()-1)/2);
156 :
157 0 : ViewShell* pViewShell = mrSlideSorter.GetViewShell();
158 0 : if (pViewShell != NULL && pViewShell->IsMainViewShell())
159 : {
160 : // The slide sorter is the main view.
161 0 : FrameView* pFrameView = pViewShell->GetFrameView();
162 0 : if (pFrameView != NULL)
163 0 : pFrameView->SetSelectedPage(sal::static_int_cast<sal_uInt16>(mnCurrentSlideIndex));
164 0 : mrSlideSorter.GetController().GetPageSelector().SetCoreSelection();
165 : }
166 :
167 : // We do not tell the XController/ViewShellBase about the new
168 : // slide right away. This is done asynchronously after a short
169 : // delay to allow for more slide switches in the slide sorter.
170 : // This goes under the assumption that slide switching inside
171 : // the slide sorter is fast (no expensive redraw of the new page
172 : // (unless the preview of the new slide is not yet preset)) and
173 : // that slide switching in the edit view is slow (all shapes of
174 : // the new slide have to be repainted.)
175 0 : maSwitchPageDelayTimer.Start();
176 :
177 : // We have to store the (index of the) new current slide at
178 : // the tab control because there are other asynchronous
179 : // notifications of the slide switching that otherwise
180 : // overwrite the correct value.
181 0 : SetCurrentSlideAtTabControl(mpCurrentSlide);
182 :
183 0 : if (bUpdateSelection)
184 : {
185 0 : mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
186 0 : mrSlideSorter.GetController().GetPageSelector().SelectPage(rpDescriptor);
187 : }
188 0 : mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(rpDescriptor);
189 : }
190 0 : }
191 :
192 :
193 :
194 :
195 0 : void CurrentSlideManager::SetCurrentSlideAtViewShellBase (const SharedPageDescriptor& rpDescriptor)
196 : {
197 : OSL_ASSERT(rpDescriptor.get() != NULL);
198 :
199 0 : ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
200 0 : if (pBase != NULL)
201 : {
202 : DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(
203 0 : pBase->GetMainViewShell().get());
204 0 : if (pDrawViewShell != NULL)
205 : {
206 0 : sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
207 0 : pDrawViewShell->SwitchPage(nPageNumber);
208 0 : pDrawViewShell->GetPageTabControl()->SetCurPageId(nPageNumber+1);
209 : }
210 : }
211 0 : }
212 :
213 :
214 :
215 :
216 0 : void CurrentSlideManager::SetCurrentSlideAtTabControl (const SharedPageDescriptor& rpDescriptor)
217 : {
218 : OSL_ASSERT(rpDescriptor.get() != NULL);
219 :
220 0 : ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
221 0 : if (pBase != NULL)
222 : {
223 : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
224 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
225 0 : if (pDrawViewShell)
226 : {
227 0 : sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
228 0 : pDrawViewShell->GetPageTabControl()->SetCurPageId(nPageNumber+1);
229 0 : }
230 : }
231 0 : }
232 :
233 :
234 :
235 :
236 0 : void CurrentSlideManager::SetCurrentSlideAtXController (const SharedPageDescriptor& rpDescriptor)
237 : {
238 : OSL_ASSERT(rpDescriptor.get() != NULL);
239 :
240 : try
241 : {
242 0 : Reference<beans::XPropertySet> xSet (mrSlideSorter.GetXController(), UNO_QUERY);
243 0 : if (xSet.is())
244 : {
245 0 : Any aPage;
246 0 : aPage <<= rpDescriptor->GetPage()->getUnoPage();
247 0 : xSet->setPropertyValue (
248 : rtl::OUString("CurrentPage"),
249 0 : aPage);
250 0 : }
251 : }
252 0 : catch (const Exception&)
253 : {
254 : // We have not been able to set the current page at the main view.
255 : // This is sad but still leaves us in a valid state. Therefore,
256 : // this exception is silently ignored.
257 : }
258 0 : }
259 :
260 :
261 :
262 :
263 0 : SharedPageDescriptor CurrentSlideManager::GetCurrentSlide (void)
264 : {
265 0 : return mpCurrentSlide;
266 : }
267 :
268 :
269 :
270 :
271 0 : void CurrentSlideManager::PrepareModelChange (void)
272 : {
273 0 : mpCurrentSlide.reset();
274 0 : }
275 :
276 :
277 :
278 :
279 0 : void CurrentSlideManager::HandleModelChange (void)
280 : {
281 0 : if (mnCurrentSlideIndex >= 0)
282 : {
283 0 : mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
284 0 : if (mpCurrentSlide.get() != NULL)
285 0 : mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
286 : }
287 0 : }
288 :
289 :
290 :
291 :
292 0 : IMPL_LINK_NOARG(CurrentSlideManager, SwitchPageCallback)
293 : {
294 0 : if (mpCurrentSlide)
295 : {
296 : // Set current page. At the moment we have to do this in two
297 : // different ways. The UNO way is the preferable one but, alas,
298 : // it does not work always correctly (after some kinds of model
299 : // changes). Therefore, we call DrawViewShell::SwitchPage(),
300 : // too.
301 0 : ViewShell* pViewShell = mrSlideSorter.GetViewShell();
302 0 : if (pViewShell==NULL || ! pViewShell->IsMainViewShell())
303 0 : SetCurrentSlideAtViewShellBase(mpCurrentSlide);
304 0 : SetCurrentSlideAtXController(mpCurrentSlide);
305 : }
306 :
307 0 : return 1;
308 : }
309 :
310 : } } } // end of namespace ::sd::slidesorter::controller
311 :
312 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|