merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / controller / SlsCurrentSlideManager.cxx
bloba0b1e627c908bc73067916adf0cb3c527ceeb5a3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsCurrentSlideManager.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "SlideSorter.hxx"
35 #include "model/SlideSorterModel.hxx"
36 #include "model/SlsPageDescriptor.hxx"
37 #include "controller/SlsPageSelector.hxx"
38 #include "controller/SlideSorterController.hxx"
39 #include "controller/SlsCurrentSlideManager.hxx"
40 #include "view/SlideSorterView.hxx"
41 #include "view/SlsPageObjectViewObjectContact.hxx"
42 #include "ViewShellBase.hxx"
43 #include "ViewShell.hxx"
44 #include "DrawViewShell.hxx"
45 #include "sdpage.hxx"
46 #include "FrameView.hxx"
47 #include <com/sun/star/beans/XPropertySet.hpp>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
52 using namespace ::sd::slidesorter::model;
54 namespace sd { namespace slidesorter { namespace controller {
56 CurrentSlideManager::CurrentSlideManager (SlideSorter& rSlideSorter)
57 : mrSlideSorter(rSlideSorter),
58 mnCurrentSlideIndex(-1),
59 mpCurrentSlide()
66 CurrentSlideManager::~CurrentSlideManager (void)
73 void CurrentSlideManager::CurrentSlideHasChanged (const sal_Int32 nSlideIndex)
75 if (mnCurrentSlideIndex != nSlideIndex)
77 ReleaseCurrentSlide();
78 AcquireCurrentSlide(nSlideIndex);
80 // Update the selection.
81 mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
82 if (mpCurrentSlide.get() != NULL)
83 mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);
90 void CurrentSlideManager::ReleaseCurrentSlide (void)
92 if (mpCurrentSlide.get() != NULL)
94 mpCurrentSlide->SetIsCurrentPage(false);
95 mrSlideSorter.GetView().RequestRepaint(mpCurrentSlide);
98 mpCurrentSlide.reset();
99 mnCurrentSlideIndex = -1;
105 bool CurrentSlideManager::IsCurrentSlideIsValid (void)
107 return mnCurrentSlideIndex >= 0 && mnCurrentSlideIndex<mrSlideSorter.GetModel().GetPageCount();
113 void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
115 mnCurrentSlideIndex = nSlideIndex;
117 if (IsCurrentSlideIsValid())
119 // Get a descriptor for the XDrawPage reference. Note that the
120 // given XDrawPage may or may not be member of the slide sorter
121 // document.
122 mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
123 if (mpCurrentSlide.get() != NULL)
125 mpCurrentSlide->SetIsCurrentPage(true);
126 mrSlideSorter.GetView().RequestRepaint(mpCurrentSlide);
134 void CurrentSlideManager::SwitchCurrentSlide (const sal_Int32 nSlideIndex)
136 SwitchCurrentSlide(mrSlideSorter.GetModel().GetPageDescriptor(nSlideIndex));
142 void CurrentSlideManager::SwitchCurrentSlide (const SharedPageDescriptor& rpDescriptor)
144 if (rpDescriptor.get() != NULL)
146 mpCurrentSlide = rpDescriptor;
147 mnCurrentSlideIndex = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
149 ViewShell* pViewShell = mrSlideSorter.GetViewShell();
150 if (pViewShell != NULL && pViewShell->IsMainViewShell())
152 FrameView* pFrameView = pViewShell->GetFrameView();
153 if (pFrameView != NULL)
154 pFrameView->SetSelectedPage(sal::static_int_cast<USHORT>(mnCurrentSlideIndex));
156 else
158 // Set current page. At the moment we have to do this in two
159 // different ways. The UNO way is the preferable one but, alas,
160 // it does not work always correctly (after some kinds of model
161 // changes). Therefore, we call DrawViewShell::SwitchPage(),
162 // too.
163 SetCurrentSlideAtViewShellBase(rpDescriptor);
164 SetCurrentSlideAtXController(rpDescriptor);
172 void CurrentSlideManager::SetCurrentSlideAtViewShellBase (const SharedPageDescriptor& rpDescriptor)
174 OSL_ASSERT(rpDescriptor.get() != NULL);
176 ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
177 if (pBase != NULL)
179 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(
180 pBase->GetMainViewShell().get());
181 if (pDrawViewShell != NULL)
183 USHORT nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
184 pDrawViewShell->SwitchPage(nPageNumber);
185 pDrawViewShell->GetPageTabControl()->SetCurPageId(nPageNumber+1);
188 else
190 presenter::PresenterViewShell* pPresenterViewShell
191 = dynamic_cast<presenter::PresenterViewShell*>(pBase->GetMainViewShell());
192 if (pPresenterViewShell != NULL)
194 pPresenterViewShell->SetCurrentSlide(
195 Reference<drawing::XDrawPage>(
196 rpDescriptor->GetPage()->getUnoPage(), UNO_QUERY));
206 void CurrentSlideManager::SetCurrentSlideAtXController (const SharedPageDescriptor& rpDescriptor)
208 OSL_ASSERT(rpDescriptor.get() != NULL);
212 Reference<beans::XPropertySet> xSet (mrSlideSorter.GetXController(), UNO_QUERY);
213 if (xSet.is())
215 Any aPage;
216 aPage <<= rpDescriptor->GetPage()->getUnoPage();
217 xSet->setPropertyValue (
218 String::CreateFromAscii("CurrentPage"),
219 aPage);
222 catch (beans::UnknownPropertyException aException)
224 // We have not been able to set the current page at the main view.
225 // This is sad but still leaves us in a valid state. Therefore,
226 // this exception is silently ignored.
233 SharedPageDescriptor CurrentSlideManager::GetCurrentSlide (void)
235 return mpCurrentSlide;
241 void CurrentSlideManager::PrepareModelChange (void)
243 mpCurrentSlide.reset();
249 void CurrentSlideManager::HandleModelChange (void)
251 if (mnCurrentSlideIndex >= 0)
253 mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(
254 mnCurrentSlideIndex);
255 if (mpCurrentSlide.get() != NULL)
256 mpCurrentSlide->SetIsCurrentPage(true);
263 SdPage* GetCurrentSdPage (SlideSorter& rSlideSorter)
265 SharedPageDescriptor pDescriptor (
266 rSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide());
267 if (pDescriptor.get() == NULL)
268 return NULL;
269 else
270 return pDescriptor->GetPage();
275 } } } // end of namespace ::sd::slidesorter::controller