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