LibreOffice Module sd (master) 1
SlsCurrentSlideManager.cxx
Go to the documentation of this file.
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#include <SlideSorter.hxx>
28#include <ViewShellBase.hxx>
29#include <ViewShell.hxx>
30#include <DrawViewShell.hxx>
31#include <sdpage.hxx>
32#include <FrameView.hxx>
33#include <com/sun/star/beans/XPropertySet.hpp>
34#include <com/sun/star/frame/XController.hpp>
35#include <osl/diagnose.h>
36
37using namespace ::com::sun::star;
38using namespace ::com::sun::star::uno;
39
40using namespace ::sd::slidesorter::model;
41
43
45 : mrSlideSorter(rSlideSorter),
46 mnCurrentSlideIndex(-1),
47 maSwitchPageDelayTimer("sd CurrentSlideManager maSwitchPageDelayTimer")
48{
51}
52
54{
55}
56
58{
59 if (pPage != nullptr)
62 Reference<drawing::XDrawPage>(
63 const_cast<SdPage*>(pPage)->getUnoPage(),
64 UNO_QUERY)));
65 else
67}
68
69void CurrentSlideManager::NotifyCurrentSlideChange (const sal_Int32 nSlideIndex)
70{
71 if (mnCurrentSlideIndex == nSlideIndex)
72 return;
73
75
77
79 AcquireCurrentSlide(nSlideIndex);
80
81 // Update the selection.
83 {
86 }
87}
88
90{
92 mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, false);
93
94 mpCurrentSlide.reset();
96}
97
98void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
99{
100 mnCurrentSlideIndex = nSlideIndex;
101
102 // if current slide valid
104 {
105 // Get a descriptor for the XDrawPage reference. Note that the
106 // given XDrawPage may or may not be member of the slide sorter
107 // document.
109 if (mpCurrentSlide)
110 mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
111 }
112}
113
115 const sal_Int32 nSlideIndex)
116{
117 SwitchCurrentSlide(mrSlideSorter.GetModel().GetPageDescriptor(nSlideIndex), true/*bUpdateSelection*/);
118}
119
121 const SharedPageDescriptor& rpDescriptor,
122 const bool bUpdateSelection)
123{
124 if (!rpDescriptor || mpCurrentSlide==rpDescriptor)
125 return;
126
128 AcquireCurrentSlide((rpDescriptor->GetPage()->GetPageNum()-1)/2);
129
130 ViewShell* pViewShell = mrSlideSorter.GetViewShell();
131 if (pViewShell != nullptr && pViewShell->IsMainViewShell())
132 {
133 // The slide sorter is the main view.
134 FrameView* pFrameView = pViewShell->GetFrameView();
135 if (pFrameView != nullptr)
136 pFrameView->SetSelectedPage(sal::static_int_cast<sal_uInt16>(mnCurrentSlideIndex));
138 }
139
140 // We do not tell the XController/ViewShellBase about the new
141 // slide right away. This is done asynchronously after a short
142 // delay to allow for more slide switches in the slide sorter.
143 // This goes under the assumption that slide switching inside
144 // the slide sorter is fast (no expensive redraw of the new page
145 // (unless the preview of the new slide is not yet preset)) and
146 // that slide switching in the edit view is slow (all shapes of
147 // the new slide have to be repainted.)
149
150 // We have to store the (index of the) new current slide at
151 // the tab control because there are other asynchronous
152 // notifications of the slide switching that otherwise
153 // overwrite the correct value.
155
156 if (bUpdateSelection)
157 {
160 }
162}
163
165{
166 OSL_ASSERT(rpDescriptor);
167
169 if (pBase != nullptr)
170 {
171 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(
172 pBase->GetMainViewShell().get());
173 if (pDrawViewShell != nullptr)
174 {
175 sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
176 pDrawViewShell->SwitchPage(nPageNumber);
177 TabControl& rPageTabControl = pDrawViewShell->GetPageTabControl();
178 rPageTabControl.SetCurPageId(rPageTabControl.GetPageId(nPageNumber));
179 }
180 }
181}
182
184{
185 OSL_ASSERT(rpDescriptor);
186
188 if (pBase != nullptr)
189 {
190 std::shared_ptr<DrawViewShell> pDrawViewShell (
191 std::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
192 if (pDrawViewShell)
193 {
194 sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
195 TabControl& rPageTabControl = pDrawViewShell->GetPageTabControl();
196 rPageTabControl.SetCurPageId(rPageTabControl.GetPageId(nPageNumber));
197 }
198 }
199}
200
202{
203 OSL_ASSERT(rpDescriptor);
204
205 try
206 {
207 Reference<beans::XPropertySet> xSet (mrSlideSorter.GetXController(), UNO_QUERY);
208 if (xSet.is())
209 {
210 Any aPage;
211 aPage <<= rpDescriptor->GetPage()->getUnoPage();
212 xSet->setPropertyValue( "CurrentPage", aPage );
213 }
214 }
215 catch (const Exception&)
216 {
217 // We have not been able to set the current page at the main view.
218 // This is sad but still leaves us in a valid state. Therefore,
219 // this exception is silently ignored.
220 }
221}
222
224{
225 mpCurrentSlide.reset();
226}
227
229{
230 if (mnCurrentSlideIndex >= 0)
231 {
233 if (mpCurrentSlide)
234 mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
235 }
236}
237
238IMPL_LINK_NOARG(CurrentSlideManager, SwitchPageCallback, Timer *, void)
239{
240 if (mpCurrentSlide)
241 {
242 // Set current page. At the moment we have to do this in two
243 // different ways. The UNO way is the preferable one but, alas,
244 // it does not work always correctly (after some kinds of model
245 // changes). Therefore, we call DrawViewShell::SwitchPage(),
246 // too.
247 ViewShell* pViewShell = mrSlideSorter.GetViewShell();
248 if (pViewShell==nullptr || ! pViewShell->IsMainViewShell())
249 SetCurrentSlideAtViewShellBase(mpCurrentSlide);
250 SetCurrentSlideAtXController(mpCurrentSlide);
251 }
252}
253
254} // end of namespace ::sd::slidesorter::controller
255
256/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorter & mrSlideSorter
css::uno::Reference< css::uno::XInterface > const & getUnoPage()
void SetCurPageId(sal_uInt16 nPageId)
sal_uInt16 GetPageId(sal_uInt16 nPos) const
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
virtual void Start(bool bStartTimer=true) override
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
TabControl & GetPageTabControl()
Return a pointer to the tab control for pages.
bool SwitchPage(sal_uInt16 nPage, bool bAllowChangeFocus=true)
Switch to desired page.
Definition: drviews1.cxx:831
View for MDIFrame.
Definition: FrameView.hxx:36
void SetSelectedPage(sal_uInt16 nPage)
Definition: frmview.cxx:907
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
bool IsMainViewShell() const
Return <TRUE> when the called view shell is the main sub shell of its ViewShellBase object,...
Definition: viewshel.cxx:1493
FrameView * GetFrameView()
Definition: ViewShell.hxx:221
Show previews for all the slides in a document and allow the user to insert or delete slides and modi...
Definition: SlideSorter.hxx:62
css::uno::Reference< css::frame::XController > GetXController() const
Return the XController object of the main view.
SD_DLLPUBLIC controller::SlideSorterController & GetController() const
ViewShell * GetViewShell() const
Return the view shell that was given at construction.
ViewShellBase * GetViewShellBase() const
Return the ViewShellBase object.
model::SlideSorterModel & GetModel() const
view::SlideSorterView & GetView() const
void ReleaseCurrentSlide()
When switching from one slide to a new current slide then this method releases all ties to the old sl...
void AcquireCurrentSlide(const sal_Int32 nSlideIndex)
When switching from one slide to a new current slide then this method connects to the new current sli...
void NotifyCurrentSlideChange(const sal_Int32 nSlideIndex)
Call this when the current page of the main view shell has been switched.
void HandleModelChange()
Modify inner state in reaction to a change of the SlideSorterModel.
void SetCurrentSlideAtXController(const model::SharedPageDescriptor &rpSlide)
void SetCurrentSlideAtTabControl(const model::SharedPageDescriptor &rpSlide)
void SetCurrentSlideAtViewShellBase(const model::SharedPageDescriptor &rpSlide)
Timer maSwitchPageDelayTimer
Timer to control the delay after which to ask XController/ViewShellBase to switch to another slide.
CurrentSlideManager(SlideSorter &rSlideSorter)
Create a new CurrentSlideManager object that manages the current slide for the given SlideSorter.
void PrepareModelChange()
Release all references to model data.
void SwitchCurrentSlide(const sal_Int32 nSlideIndex)
Call this method to switch the current page of the main view shell to the given slide.
bool SetFocusedPage(const model::SharedPageDescriptor &rDescriptor)
Set the focused page to the one described by the given page descriptor.
void SetCoreSelection()
Update the selection state of the SdPage objects to be the same as that of the corresponding page des...
void SelectPage(int nPageIndex)
Select the specified descriptor.
sal_Int32 GetPageCount() const
Return the number of slides in the document regardless of whether they are visible or not or whether ...
SharedPageDescriptor GetPageDescriptor(const sal_Int32 nPageIndex, const bool bCreate=true) const
Return a page descriptor for the page with the specified index.
sal_Int32 GetIndex(const css::uno::Reference< css::drawing::XDrawPage > &rxSlide) const
Return a page descriptor for the given XDrawPage.
bool SetState(const model::SharedPageDescriptor &rpDescriptor, const model::PageDescriptor::State eState, const bool bStateValue)
@ Exception
IMPL_LINK_NOARG(Animator, TimeoutHandler, Timer *, void)
std::shared_ptr< PageDescriptor > SharedPageDescriptor