1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <cppuhelper/supportsservice.hxx>
22 #include <DrawController.hxx>
23 #include <SdUnoSlideView.hxx>
25 #include <SlideSorter.hxx>
26 #include <controller/SlideSorterController.hxx>
27 #include <controller/SlsPageSelector.hxx>
28 #include <controller/SlsCurrentSlideManager.hxx>
29 #include <model/SlsPageEnumerationProvider.hxx>
30 #include <model/SlsPageDescriptor.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::uno
;
39 SdUnoSlideView::SdUnoSlideView (
40 slidesorter::SlideSorter
& rSlideSorter
) noexcept
41 : mrSlideSorter(rSlideSorter
)
45 SdUnoSlideView::~SdUnoSlideView() noexcept
49 //----- XSelectionSupplier ----------------------------------------------------
51 sal_Bool SAL_CALL
SdUnoSlideView::select (const Any
& aSelection
)
53 slidesorter::controller::SlideSorterController
& rSlideSorterController
54 = mrSlideSorter
.GetController();
55 slidesorter::controller::PageSelector
& rSelector (rSlideSorterController
.GetPageSelector());
56 rSelector
.DeselectAllPages();
57 Sequence
<Reference
<drawing::XDrawPage
> > xPages
;
58 aSelection
>>= xPages
;
59 for (const auto& rPage
: xPages
)
61 Reference
<beans::XPropertySet
> xSet (rPage
, UNO_QUERY
);
66 Any aNumber
= xSet
->getPropertyValue(u
"Number"_ustr
);
67 sal_Int32 nPageNumber
= 0;
68 aNumber
>>= nPageNumber
;
69 nPageNumber
-=1; // Transform 1-based page numbers to 0-based ones.
70 rSelector
.SelectPage(nPageNumber
);
72 catch (const RuntimeException
&)
81 Any SAL_CALL
SdUnoSlideView::getSelection()
85 slidesorter::model::PageEnumeration
aSelectedPages (
86 slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
87 mrSlideSorter
.GetModel()));
88 int nSelectedPageCount (
89 mrSlideSorter
.GetController().GetPageSelector().GetSelectedPageCount());
91 Sequence
<Reference
<XInterface
> > aPages(nSelectedPageCount
);
92 auto aPagesRange
= asNonConstRange(aPages
);
94 while (aSelectedPages
.HasMoreElements() && nIndex
<nSelectedPageCount
)
96 slidesorter::model::SharedPageDescriptor
pDescriptor (aSelectedPages
.GetNextElement());
97 aPagesRange
[nIndex
++] = pDescriptor
->GetPage()->getUnoPage();
104 void SAL_CALL
SdUnoSlideView::addSelectionChangeListener (
105 const css::uno::Reference
<css::view::XSelectionChangeListener
>&)
108 void SAL_CALL
SdUnoSlideView::removeSelectionChangeListener (
109 const css::uno::Reference
<css::view::XSelectionChangeListener
>&)
112 //----- XDrawView -------------------------------------------------------------
114 void SAL_CALL
SdUnoSlideView::setCurrentPage (
115 const css::uno::Reference
<css::drawing::XDrawPage
>& rxDrawPage
)
117 Reference
<beans::XPropertySet
> xProperties (rxDrawPage
, UNO_QUERY
);
118 if (xProperties
.is())
120 sal_uInt16
nPageNumber(0);
121 if (xProperties
->getPropertyValue(u
"Number"_ustr
) >>= nPageNumber
)
123 mrSlideSorter
.GetController().GetCurrentSlideManager()->SwitchCurrentSlide(
129 css::uno::Reference
<css::drawing::XDrawPage
> SAL_CALL
130 SdUnoSlideView::getCurrentPage()
132 return mrSlideSorter
.GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
135 //----- XFastPropertySet ------------------------------------------------------
137 void SdUnoSlideView::setFastPropertyValue (
141 throw beans::UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
144 Any SAL_CALL
SdUnoSlideView::getFastPropertyValue (
147 if( nHandle
!= DrawController::PROPERTY_VIEWOFFSET
)
148 throw beans::UnknownPropertyException( OUString::number(nHandle
), static_cast<cppu::OWeakObject
*>(this));
154 OUString SAL_CALL
SdUnoSlideView::getImplementationName( )
156 return u
"com.sun.star.comp.sd.SdUnoSlideView"_ustr
;
159 sal_Bool SAL_CALL
SdUnoSlideView::supportsService( const OUString
& ServiceName
)
161 return cppu::supportsService( this, ServiceName
);
164 Sequence
< OUString
> SAL_CALL
SdUnoSlideView::getSupportedServiceNames( )
166 return { u
"com.sun.star.presentation.SlidesView"_ustr
};
169 } // end of namespace sd
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */