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 <cppuhelper/supportsservice.hxx>
21 
22 #include <DrawController.hxx>
23 #include <SdUnoSlideView.hxx>
24 
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>
31 #include <sdpage.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 
37 namespace sd {
38 
SdUnoSlideView(slidesorter::SlideSorter & rSlideSorter)39 SdUnoSlideView::SdUnoSlideView (
40     slidesorter::SlideSorter& rSlideSorter) throw()
41     : DrawSubControllerInterfaceBase(m_aMutex),
42       mrSlideSorter(rSlideSorter)
43 {
44 }
45 
~SdUnoSlideView()46 SdUnoSlideView::~SdUnoSlideView() throw()
47 {
48 }
49 
50 //----- XSelectionSupplier ----------------------------------------------------
51 
select(const Any & aSelection)52 sal_Bool SAL_CALL SdUnoSlideView::select (const Any& aSelection)
53 {
54     slidesorter::controller::SlideSorterController& rSlideSorterController
55         = mrSlideSorter.GetController();
56     slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
57     rSelector.DeselectAllPages();
58     Sequence<Reference<drawing::XDrawPage> > xPages;
59     aSelection >>= xPages;
60     for (const auto& rPage : std::as_const(xPages))
61     {
62         Reference<beans::XPropertySet> xSet (rPage, UNO_QUERY);
63         if (xSet.is())
64         {
65             try
66             {
67                 Any aNumber = xSet->getPropertyValue("Number");
68                 sal_Int32 nPageNumber = 0;
69                 aNumber >>= nPageNumber;
70                 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
71                 rSelector.SelectPage(nPageNumber);
72             }
73             catch (const RuntimeException&)
74             {
75             }
76         }
77     }
78 
79     return true;
80 }
81 
getSelection()82 Any SAL_CALL SdUnoSlideView::getSelection()
83 {
84     Any aResult;
85 
86     slidesorter::model::PageEnumeration aSelectedPages (
87         slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
88             mrSlideSorter.GetModel()));
89     int nSelectedPageCount (
90         mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount());
91 
92     Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
93     int nIndex = 0;
94     while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
95     {
96         slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
97         aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
98     }
99     aResult <<= aPages;
100 
101     return aResult;
102 }
103 
addSelectionChangeListener(const css::uno::Reference<css::view::XSelectionChangeListener> &)104 void SAL_CALL SdUnoSlideView::addSelectionChangeListener (
105     const css::uno::Reference<css::view::XSelectionChangeListener>&)
106 {}
107 
removeSelectionChangeListener(const css::uno::Reference<css::view::XSelectionChangeListener> &)108 void SAL_CALL SdUnoSlideView::removeSelectionChangeListener (
109     const css::uno::Reference<css::view::XSelectionChangeListener>&)
110 {}
111 
112 //----- XDrawView -------------------------------------------------------------
113 
setCurrentPage(const css::uno::Reference<css::drawing::XDrawPage> & rxDrawPage)114 void SAL_CALL SdUnoSlideView::setCurrentPage (
115     const css::uno::Reference<css::drawing::XDrawPage>& rxDrawPage)
116 {
117     Reference<beans::XPropertySet> xProperties (rxDrawPage, UNO_QUERY);
118     if (xProperties.is())
119     {
120         sal_uInt16 nPageNumber(0);
121         if (xProperties->getPropertyValue("Number") >>= nPageNumber)
122         {
123             mrSlideSorter.GetController().GetCurrentSlideManager()->SwitchCurrentSlide(
124                 nPageNumber-1);
125         }
126     }
127 }
128 
129 css::uno::Reference<css::drawing::XDrawPage > SAL_CALL
getCurrentPage()130     SdUnoSlideView::getCurrentPage()
131 {
132     return mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
133 }
134 
135 //----- XFastPropertySet ------------------------------------------------------
136 
setFastPropertyValue(sal_Int32 nHandle,const Any &)137 void SdUnoSlideView::setFastPropertyValue (
138     sal_Int32 nHandle,
139         const Any&)
140 {
141     throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
142 }
143 
getFastPropertyValue(sal_Int32 nHandle)144 Any SAL_CALL SdUnoSlideView::getFastPropertyValue (
145     sal_Int32 nHandle)
146 {
147     if( nHandle != DrawController::PROPERTY_VIEWOFFSET )
148         throw beans::UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
149 
150     return Any();
151 }
152 
153 // XServiceInfo
getImplementationName()154 OUString SAL_CALL SdUnoSlideView::getImplementationName(  )
155 {
156     return "com.sun.star.comp.sd.SdUnoSlideView";
157 }
158 
supportsService(const OUString & ServiceName)159 sal_Bool SAL_CALL SdUnoSlideView::supportsService( const OUString& ServiceName )
160 {
161     return cppu::supportsService( this, ServiceName );
162 }
163 
getSupportedServiceNames()164 Sequence< OUString > SAL_CALL SdUnoSlideView::getSupportedServiceNames(  )
165 {
166     return { "com.sun.star.presentation.SlidesView" };
167 }
168 
169 } // end of namespace sd
170 
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
172