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