1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*5b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*5b190011SAndrew Rist  * distributed with this work for additional information
6*5b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*5b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist  * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*5b190011SAndrew Rist  *
11*5b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*5b190011SAndrew Rist  *
13*5b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist  * software distributed under the License is distributed on an
15*5b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
17*5b190011SAndrew Rist  * specific language governing permissions and limitations
18*5b190011SAndrew Rist  * under the License.
19*5b190011SAndrew Rist  *
20*5b190011SAndrew Rist  *************************************************************/
21*5b190011SAndrew Rist 
22*5b190011SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_sd.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <comphelper/serviceinfohelper.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "DrawController.hxx"
29cdf0e10cSrcweir #include "SdUnoSlideView.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "SlideSorter.hxx"
32cdf0e10cSrcweir #include "controller/SlideSorterController.hxx"
33cdf0e10cSrcweir #include "controller/SlsPageSelector.hxx"
34cdf0e10cSrcweir #include "controller/SlsCurrentSlideManager.hxx"
35cdf0e10cSrcweir #include "model/SlsPageEnumerationProvider.hxx"
36cdf0e10cSrcweir #include "model/SlideSorterModel.hxx"
37cdf0e10cSrcweir #include "model/SlsPageDescriptor.hxx"
38cdf0e10cSrcweir #include "sdpage.hxx"
39cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir using ::rtl::OUString;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace sd {
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir SdUnoSlideView::SdUnoSlideView (
50cdf0e10cSrcweir     DrawController& rController,
51cdf0e10cSrcweir     slidesorter::SlideSorter& rSlideSorter,
52cdf0e10cSrcweir     View& rView) throw()
53cdf0e10cSrcweir     : DrawSubControllerInterfaceBase(m_aMutex),
54cdf0e10cSrcweir       mrController(rController),
55cdf0e10cSrcweir       mrSlideSorter(rSlideSorter),
56cdf0e10cSrcweir       mrView(rView)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir SdUnoSlideView::~SdUnoSlideView (void) throw()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 
70cdf0e10cSrcweir //----- XSelectionSupplier ----------------------------------------------------
71cdf0e10cSrcweir 
72cdf0e10cSrcweir sal_Bool SAL_CALL SdUnoSlideView::select (const Any& aSelection)
73cdf0e10cSrcweir       throw(lang::IllegalArgumentException, RuntimeException)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     bool bOk = true;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     slidesorter::controller::SlideSorterController& rSlideSorterController
78cdf0e10cSrcweir         = mrSlideSorter.GetController();
79cdf0e10cSrcweir     slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
80cdf0e10cSrcweir     rSelector.DeselectAllPages();
81cdf0e10cSrcweir     Sequence<Reference<drawing::XDrawPage> > xPages;
82cdf0e10cSrcweir     aSelection >>= xPages;
83cdf0e10cSrcweir     const sal_uInt32 nCount = xPages.getLength();
84cdf0e10cSrcweir     for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY);
87cdf0e10cSrcweir         if (xSet.is())
88cdf0e10cSrcweir         {
89cdf0e10cSrcweir             try
90cdf0e10cSrcweir             {
91cdf0e10cSrcweir                 Any aNumber = xSet->getPropertyValue(
92cdf0e10cSrcweir                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Number")));
93cdf0e10cSrcweir                 sal_Int32 nPageNumber = 0;
94cdf0e10cSrcweir                 aNumber >>= nPageNumber;
95cdf0e10cSrcweir                 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
96cdf0e10cSrcweir                 rSelector.SelectPage(nPageNumber);
97cdf0e10cSrcweir             }
98cdf0e10cSrcweir             catch(RuntimeException e)
99cdf0e10cSrcweir             {
100cdf0e10cSrcweir             }
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir     }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir     return bOk;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir Any SAL_CALL SdUnoSlideView::getSelection (void)
111cdf0e10cSrcweir       throw(RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir     Any aResult;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir     slidesorter::model::PageEnumeration aSelectedPages (
116cdf0e10cSrcweir         slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
117cdf0e10cSrcweir             mrSlideSorter.GetModel()));
118cdf0e10cSrcweir     int nSelectedPageCount (
119cdf0e10cSrcweir         mrSlideSorter.GetController().GetPageSelector().GetSelectedPageCount());
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
122cdf0e10cSrcweir     int nIndex = 0;
123cdf0e10cSrcweir     while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
124cdf0e10cSrcweir     {
125cdf0e10cSrcweir         slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
126cdf0e10cSrcweir         aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
127cdf0e10cSrcweir     }
128cdf0e10cSrcweir     aResult <<= aPages;
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     return aResult;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir 
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 
136cdf0e10cSrcweir void SAL_CALL SdUnoSlideView::addSelectionChangeListener (
137cdf0e10cSrcweir     const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
138cdf0e10cSrcweir     throw(css::uno::RuntimeException)
139cdf0e10cSrcweir {
140cdf0e10cSrcweir     (void)rxListener;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 
146cdf0e10cSrcweir void SAL_CALL SdUnoSlideView::removeSelectionChangeListener (
147cdf0e10cSrcweir     const css::uno::Reference<css::view::XSelectionChangeListener>& rxListener)
148cdf0e10cSrcweir     throw(css::uno::RuntimeException)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     (void)rxListener;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir //----- XDrawView -------------------------------------------------------------
157cdf0e10cSrcweir 
158cdf0e10cSrcweir void SAL_CALL SdUnoSlideView::setCurrentPage (
159cdf0e10cSrcweir     const css::uno::Reference<css::drawing::XDrawPage>& rxDrawPage)
160cdf0e10cSrcweir     throw(css::uno::RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     Reference<beans::XPropertySet> xProperties (rxDrawPage, UNO_QUERY);
163cdf0e10cSrcweir     if (xProperties.is())
164cdf0e10cSrcweir     {
165cdf0e10cSrcweir         sal_uInt16 nPageNumber(0);
166cdf0e10cSrcweir         if (xProperties->getPropertyValue(::rtl::OUString::createFromAscii("Number")) >>= nPageNumber)
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             mrSlideSorter.GetController().GetCurrentSlideManager()->SwitchCurrentSlide(
169cdf0e10cSrcweir                 nPageNumber-1,
170cdf0e10cSrcweir                 true);
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 
177cdf0e10cSrcweir 
178cdf0e10cSrcweir css::uno::Reference<css::drawing::XDrawPage > SAL_CALL
179cdf0e10cSrcweir     SdUnoSlideView::getCurrentPage (void)
180cdf0e10cSrcweir     throw(css::uno::RuntimeException)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     return mrSlideSorter.GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 
188cdf0e10cSrcweir //----- XFastPropertySet ------------------------------------------------------
189cdf0e10cSrcweir 
190cdf0e10cSrcweir void SdUnoSlideView::setFastPropertyValue (
191cdf0e10cSrcweir 	sal_Int32 nHandle,
192cdf0e10cSrcweir         const Any& rValue)
193cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
194cdf0e10cSrcweir         css::beans::PropertyVetoException,
195cdf0e10cSrcweir         css::lang::IllegalArgumentException,
196cdf0e10cSrcweir         css::lang::WrappedTargetException,
197cdf0e10cSrcweir         css::uno::RuntimeException)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir     (void)nHandle;
200cdf0e10cSrcweir     (void)rValue;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	throw beans::UnknownPropertyException();
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 
208cdf0e10cSrcweir Any SAL_CALL SdUnoSlideView::getFastPropertyValue (
209cdf0e10cSrcweir     sal_Int32 nHandle)
210cdf0e10cSrcweir     throw(css::beans::UnknownPropertyException,
211cdf0e10cSrcweir         css::lang::WrappedTargetException,
212cdf0e10cSrcweir         css::uno::RuntimeException)
213cdf0e10cSrcweir {
214cdf0e10cSrcweir     (void)nHandle;
215cdf0e10cSrcweir 
216cdf0e10cSrcweir 	if( nHandle != DrawController::PROPERTY_VIEWOFFSET )
217cdf0e10cSrcweir 		throw beans::UnknownPropertyException();
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	return Any();
220cdf0e10cSrcweir }
221cdf0e10cSrcweir 
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // XServiceInfo
224cdf0e10cSrcweir OUString SAL_CALL SdUnoSlideView::getImplementationName(  ) throw (RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.sd.SdUnoSlideView") );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir 
229cdf0e10cSrcweir sal_Bool SAL_CALL SdUnoSlideView::supportsService( const OUString& ServiceName ) throw (RuntimeException)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir Sequence< OUString > SAL_CALL SdUnoSlideView::getSupportedServiceNames(  ) throw (RuntimeException)
235cdf0e10cSrcweir {
236cdf0e10cSrcweir 	OUString aSN( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.presentation.SlidesView") );
237cdf0e10cSrcweir 	uno::Sequence< OUString > aSeq( &aSN, 1 );
238cdf0e10cSrcweir 	return aSeq;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
242cdf0e10cSrcweir /*
243cdf0e10cSrcweir void SdUnoSlideView::FillPropertyTable (
244cdf0e10cSrcweir     ::std::vector< ::com::sun::star::beans::Property>& )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 
251cdf0e10cSrcweir sal_Bool SAL_CALL SdUnoSlideView::convertFastPropertyValue(
252cdf0e10cSrcweir     ::com::sun::star::uno::Any & ,
253cdf0e10cSrcweir     ::com::sun::star::uno::Any & ,
254cdf0e10cSrcweir     sal_Int32 ,
255cdf0e10cSrcweir     const ::com::sun::star::uno::Any&  )
256cdf0e10cSrcweir     throw (::com::sun::star::lang::IllegalArgumentException)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     return sal_False;
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 
264cdf0e10cSrcweir void SAL_CALL SdUnoSlideView::setFastPropertyValue_NoBroadcast(
265cdf0e10cSrcweir     sal_Int32 ,
266cdf0e10cSrcweir     const ::com::sun::star::uno::Any&  )
267cdf0e10cSrcweir     throw (::com::sun::star::uno::Exception)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 
274cdf0e10cSrcweir void SAL_CALL SdUnoSlideView::getFastPropertyValue( ::com::sun::star::uno::Any&, sal_Int32  ) const
275cdf0e10cSrcweir {
276cdf0e10cSrcweir }
277cdf0e10cSrcweir 
278cdf0e10cSrcweir */
279cdf0e10cSrcweir 
280cdf0e10cSrcweir } // end of namespace sd
281