1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sd.hxx"
25 
26 #include "SlideSorterService.hxx"
27 #include "controller/SlideSorterController.hxx"
28 #include "controller/SlsProperties.hxx"
29 #include "controller/SlsCurrentSlideManager.hxx"
30 #include "model/SlideSorterModel.hxx"
31 #include "model/SlsPageDescriptor.hxx"
32 #include "view/SlideSorterView.hxx"
33 #include "view/SlsLayouter.hxx"
34 #include "DrawController.hxx"
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <com/sun/star/lang/XUnoTunnel.hpp>
38 #include <vos/mutex.hxx>
39 #include <vcl/svapp.hxx>
40 #include <cppuhelper/proptypehlp.hxx>
41 
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::drawing::framework;
45 using ::rtl::OUString;
46 using ::sd::slidesorter::view::Layouter;
47 
48 namespace sd { namespace slidesorter {
49 
50 namespace {
51     enum Properties
52     {
53         PropertyDocumentSlides,
54         PropertyHighlightCurrentSlide,
55         PropertyShowSelection,
56         PropertyCenterSelection,
57         PropertySuspendPreviewUpdatesDuringFullScreenPresentation,
58         PropertyOrientationVertical
59     };
60 }
61 
62 
63 
64 
65 //===== Service ===============================================================
66 
SlideSorterService_createInstance(const Reference<XComponentContext> & rxContext)67 Reference<XInterface> SAL_CALL SlideSorterService_createInstance (
68     const Reference<XComponentContext>& rxContext)
69 {
70     return Reference<XInterface>(static_cast<drawing::XDrawView*>(new SlideSorterService(rxContext)));
71 }
72 
73 
74 
75 
SlideSorterService_getImplementationName(void)76 ::rtl::OUString SlideSorterService_getImplementationName (void) throw(RuntimeException)
77 {
78     return OUString::createFromAscii("com.sun.star.comp.Draw.SlideSorter");
79 }
80 
81 
82 
83 
SlideSorterService_getSupportedServiceNames(void)84 Sequence<rtl::OUString> SAL_CALL SlideSorterService_getSupportedServiceNames (void)
85     throw (RuntimeException)
86 {
87 	static const ::rtl::OUString sServiceName(
88         ::rtl::OUString::createFromAscii("com.sun.star.drawing.SlideSorter"));
89 	return Sequence<rtl::OUString>(&sServiceName, 1);
90 }
91 
92 
93 
94 
95 //===== SlideSorterService ==========================================================
96 
SlideSorterService(const Reference<XComponentContext> & rxContext)97 SlideSorterService::SlideSorterService (const Reference<XComponentContext>& rxContext)
98     : SlideSorterServiceInterfaceBase(m_aMutex),
99       mpSlideSorter(),
100       mxParentWindow()
101 {
102     (void)rxContext;
103 }
104 
105 
106 
107 
~SlideSorterService(void)108 SlideSorterService::~SlideSorterService (void)
109 {
110 }
111 
112 
113 
114 
disposing(void)115 void SAL_CALL SlideSorterService::disposing (void)
116 {
117     mpSlideSorter.reset();
118 
119     if (mxParentWindow.is())
120     {
121         mxParentWindow->removeWindowListener(this);
122     }
123 }
124 
125 
126 
127 
128 //----- XInitialization -------------------------------------------------------
129 
initialize(const Sequence<Any> & rArguments)130 void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments)
131     throw (Exception, RuntimeException)
132 {
133     ThrowIfDisposed();
134 
135     if (rArguments.getLength() == 3)
136     {
137         try
138         {
139             mxViewId = Reference<XResourceId>(rArguments[0], UNO_QUERY_THROW);
140 
141             // Get the XController.
142             Reference<frame::XController> xController (rArguments[1], UNO_QUERY_THROW);
143 
144             // Tunnel through the controller to obtain a ViewShellBase.
145             ViewShellBase* pBase = NULL;
146             Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
147             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
148                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
149             if (pController != NULL)
150                 pBase = pController->GetViewShellBase();
151 
152             // Get the parent window.
153             mxParentWindow = Reference<awt::XWindow>(rArguments[2], UNO_QUERY_THROW);
154             ::Window* pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow);
155 
156             mxParentWindow->addWindowListener(this);
157 
158             if (pBase != NULL && pParentWindow!=NULL)
159                 mpSlideSorter = SlideSorter::CreateSlideSorter(
160                     *pBase,
161                     NULL,
162                     *pParentWindow);
163 
164             Resize();
165         }
166         catch (RuntimeException&)
167         {
168             throw;
169         }
170     }
171     else
172     {
173         throw RuntimeException(
174             OUString::createFromAscii("SlideSorterService: invalid number of arguments"),
175             static_cast<drawing::XDrawView*>(this));
176     }
177 }
178 
179 
180 
181 
182 //----- XView -----------------------------------------------------------------
183 
getResourceId(void)184 Reference<XResourceId> SAL_CALL SlideSorterService::getResourceId (void)
185     throw (RuntimeException)
186 {
187     return mxViewId;
188 }
189 
190 
191 
192 
isAnchorOnly(void)193 sal_Bool SAL_CALL SlideSorterService::isAnchorOnly (void)
194     throw (RuntimeException)
195 {
196     return sal_False;
197 }
198 
199 
200 
201 
202 //----- XWindowListener -------------------------------------------------------
203 
windowResized(const awt::WindowEvent & rEvent)204 void SAL_CALL SlideSorterService::windowResized (const awt::WindowEvent& rEvent)
205     throw (RuntimeException)
206 {
207     (void)rEvent;
208     ThrowIfDisposed();
209 
210     Resize();
211 }
212 
213 
214 
215 
216 
windowMoved(const awt::WindowEvent & rEvent)217 void SAL_CALL SlideSorterService::windowMoved (const awt::WindowEvent& rEvent)
218     throw (RuntimeException)
219 {
220     (void)rEvent;
221 }
222 
223 
224 
225 
windowShown(const lang::EventObject & rEvent)226 void SAL_CALL SlideSorterService::windowShown (const lang::EventObject& rEvent)
227     throw (RuntimeException)
228 {
229     (void)rEvent;
230     ThrowIfDisposed();
231     Resize();
232 }
233 
234 
235 
236 
windowHidden(const lang::EventObject & rEvent)237 void SAL_CALL SlideSorterService::windowHidden (const lang::EventObject& rEvent)
238     throw (RuntimeException)
239 {
240     (void)rEvent;
241     ThrowIfDisposed();
242 }
243 
244 
245 
246 
247 //----- lang::XEventListener --------------------------------------------------
248 
disposing(const lang::EventObject & rEvent)249 void SAL_CALL SlideSorterService::disposing (const lang::EventObject& rEvent)
250     throw (RuntimeException)
251 {
252     if (rEvent.Source == mxParentWindow)
253         mxParentWindow = NULL;
254 }
255 
256 
257 
258 
259 //----- XDrawView -------------------------------------------------------------
260 
setCurrentPage(const Reference<drawing::XDrawPage> & rxSlide)261 void SAL_CALL SlideSorterService::setCurrentPage(const Reference<drawing::XDrawPage>& rxSlide)
262     throw (RuntimeException)
263 {
264     ThrowIfDisposed();
265     if (mpSlideSorter.get() != NULL)
266         mpSlideSorter->GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
267             mpSlideSorter->GetModel().GetIndex(rxSlide));
268 }
269 
270 
271 
272 
getCurrentPage(void)273 Reference<drawing::XDrawPage> SAL_CALL SlideSorterService::getCurrentPage (void)
274     throw (RuntimeException)
275 {
276     ThrowIfDisposed();
277     if (mpSlideSorter.get() != NULL)
278         return mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
279     else
280         return NULL;
281 }
282 
283 
284 
285 
286 //----- attributes ------------------------------------------------------------
287 
288 
getDocumentSlides(void)289 Reference<container::XIndexAccess> SAL_CALL SlideSorterService::getDocumentSlides (void)
290     throw (RuntimeException)
291 {
292     return mpSlideSorter->GetModel().GetDocumentSlides();
293 }
294 
295 
296 
297 
setDocumentSlides(const Reference<container::XIndexAccess> & rxSlides)298 void SAL_CALL SlideSorterService::setDocumentSlides (
299     const Reference<container::XIndexAccess >& rxSlides)
300     throw (RuntimeException)
301 {
302     ThrowIfDisposed();
303     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
304         mpSlideSorter->GetController().SetDocumentSlides(rxSlides);
305 }
306 
307 
308 
309 
getIsHighlightCurrentSlide(void)310 sal_Bool SAL_CALL SlideSorterService::getIsHighlightCurrentSlide (void)
311     throw (RuntimeException)
312 {
313     ThrowIfDisposed();
314     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
315         return false;
316     else
317         return mpSlideSorter->GetProperties()->IsHighlightCurrentSlide();
318 }
319 
320 
321 
322 
setIsHighlightCurrentSlide(sal_Bool bValue)323 void SAL_CALL SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue)
324     throw (RuntimeException)
325 {
326     ThrowIfDisposed();
327     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
328     {
329         mpSlideSorter->GetProperties()->SetHighlightCurrentSlide(bValue);
330         controller::SlideSorterController::ModelChangeLock aLock (mpSlideSorter->GetController());
331         mpSlideSorter->GetController().HandleModelChange();
332     }
333 }
334 
335 
336 
337 
getIsShowSelection(void)338 sal_Bool SAL_CALL SlideSorterService::getIsShowSelection (void)
339     throw (RuntimeException)
340 {
341     ThrowIfDisposed();
342     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
343         return false;
344     else
345         return mpSlideSorter->GetProperties()->IsShowSelection();
346 }
347 
348 
349 
350 
setIsShowSelection(sal_Bool bValue)351 void SAL_CALL SlideSorterService::setIsShowSelection (sal_Bool bValue)
352     throw (RuntimeException)
353 {
354     ThrowIfDisposed();
355     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
356         mpSlideSorter->GetProperties()->SetShowSelection(bValue);
357 }
358 
359 
360 
361 
getIsShowFocus(void)362 sal_Bool SAL_CALL SlideSorterService::getIsShowFocus (void)
363     throw (RuntimeException)
364 {
365     ThrowIfDisposed();
366     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
367         return false;
368     else
369         return mpSlideSorter->GetProperties()->IsShowFocus();
370 }
371 
372 
373 
374 
setIsShowFocus(sal_Bool bValue)375 void SAL_CALL SlideSorterService::setIsShowFocus (sal_Bool bValue)
376     throw (RuntimeException)
377 {
378     ThrowIfDisposed();
379     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
380         mpSlideSorter->GetProperties()->SetShowFocus(bValue);
381 }
382 
383 
384 
385 
getIsCenterSelection(void)386 sal_Bool SAL_CALL SlideSorterService::getIsCenterSelection (void)
387     throw (RuntimeException)
388 {
389     ThrowIfDisposed();
390     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
391         return false;
392     else
393         return mpSlideSorter->GetProperties()->IsCenterSelection();
394 }
395 
396 
397 
398 
setIsCenterSelection(sal_Bool bValue)399 void SAL_CALL SlideSorterService::setIsCenterSelection (sal_Bool bValue)
400     throw (RuntimeException)
401 {
402     ThrowIfDisposed();
403     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
404         mpSlideSorter->GetProperties()->SetCenterSelection(bValue);
405 }
406 
407 
408 
409 
getIsSuspendPreviewUpdatesDuringFullScreenPresentation(void)410 sal_Bool SAL_CALL SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation (void)
411     throw (RuntimeException)
412 {
413     ThrowIfDisposed();
414     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
415         return true;
416     else
417         return mpSlideSorter->GetProperties()
418             ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
419 }
420 
421 
422 
423 
setIsSuspendPreviewUpdatesDuringFullScreenPresentation(sal_Bool bValue)424 void SAL_CALL SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
425     sal_Bool bValue)
426     throw (RuntimeException)
427 {
428     ThrowIfDisposed();
429     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
430         mpSlideSorter->GetProperties()
431             ->SetSuspendPreviewUpdatesDuringFullScreenPresentation(bValue);
432 }
433 
434 
435 
436 
getIsOrientationVertical(void)437 sal_Bool SAL_CALL SlideSorterService::getIsOrientationVertical (void)
438     throw (RuntimeException)
439 {
440     ThrowIfDisposed();
441     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
442         return true;
443     else
444         return mpSlideSorter->GetView().GetOrientation() != Layouter::HORIZONTAL;
445 }
446 
447 
448 
449 
setIsOrientationVertical(sal_Bool bValue)450 void SAL_CALL SlideSorterService::setIsOrientationVertical (sal_Bool bValue)
451     throw (RuntimeException)
452 {
453     ThrowIfDisposed();
454     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
455         mpSlideSorter->GetView().SetOrientation(bValue
456             ? Layouter::GRID
457             : Layouter::HORIZONTAL);
458 }
459 
460 
461 
462 
getIsSmoothScrolling(void)463 sal_Bool SAL_CALL SlideSorterService::getIsSmoothScrolling (void)
464     throw (RuntimeException)
465 {
466     ThrowIfDisposed();
467     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
468         return false;
469     else
470         return mpSlideSorter->GetProperties()->IsSmoothSelectionScrolling();
471 }
472 
473 
474 
475 
setIsSmoothScrolling(sal_Bool bValue)476 void SAL_CALL SlideSorterService::setIsSmoothScrolling (sal_Bool bValue)
477     throw (RuntimeException)
478 {
479     ThrowIfDisposed();
480     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
481         mpSlideSorter->GetProperties()->SetSmoothSelectionScrolling(bValue);
482 }
483 
484 
485 
486 
getBackgroundColor(void)487 util::Color SAL_CALL SlideSorterService::getBackgroundColor (void)
488     throw (RuntimeException)
489 {
490     ThrowIfDisposed();
491     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
492         return util::Color();
493     else
494         return util::Color(
495             mpSlideSorter->GetProperties()->GetBackgroundColor().GetColor());
496 }
497 
498 
499 
500 
setBackgroundColor(util::Color aBackgroundColor)501 void SAL_CALL SlideSorterService::setBackgroundColor (util::Color aBackgroundColor)
502     throw (RuntimeException)
503 {
504     ThrowIfDisposed();
505     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
506         mpSlideSorter->GetProperties()->SetBackgroundColor(Color(aBackgroundColor));
507 }
508 
509 
510 
511 
getTextColor(void)512 util::Color SAL_CALL SlideSorterService::getTextColor (void)
513     throw (css::uno::RuntimeException)
514 {
515     ThrowIfDisposed();
516     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
517         return util::Color();
518     else
519         return util::Color(
520             mpSlideSorter->GetProperties()->GetTextColor().GetColor());
521 }
522 
523 
524 
525 
setTextColor(util::Color aTextColor)526 void SAL_CALL SlideSorterService::setTextColor (util::Color aTextColor)
527     throw (RuntimeException)
528 {
529     ThrowIfDisposed();
530     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
531         mpSlideSorter->GetProperties()->SetTextColor(Color(aTextColor));
532 }
533 
534 
535 
536 
getSelectionColor(void)537 util::Color SAL_CALL SlideSorterService::getSelectionColor (void)
538     throw (RuntimeException)
539 {
540     ThrowIfDisposed();
541     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
542         return util::Color();
543     else
544         return util::Color(
545             mpSlideSorter->GetProperties()->GetSelectionColor().GetColor());
546 }
547 
548 
549 
550 
setSelectionColor(util::Color aSelectionColor)551 void SAL_CALL SlideSorterService::setSelectionColor (util::Color aSelectionColor)
552     throw (RuntimeException)
553 {
554     ThrowIfDisposed();
555     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
556         mpSlideSorter->GetProperties()->SetSelectionColor(Color(aSelectionColor));
557 }
558 
559 
560 
561 
getHighlightColor(void)562 util::Color SAL_CALL SlideSorterService::getHighlightColor (void)
563     throw (RuntimeException)
564 {
565     ThrowIfDisposed();
566     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
567         return util::Color();
568     else
569         return util::Color(
570             mpSlideSorter->GetProperties()->GetHighlightColor().GetColor());
571 }
572 
573 
574 
575 
setHighlightColor(util::Color aHighlightColor)576 void SAL_CALL SlideSorterService::setHighlightColor (util::Color aHighlightColor)
577     throw (RuntimeException)
578 {
579     ThrowIfDisposed();
580     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
581         mpSlideSorter->GetProperties()->SetHighlightColor(Color(aHighlightColor));
582 }
583 
584 
585 
getIsUIReadOnly(void)586 sal_Bool SAL_CALL SlideSorterService::getIsUIReadOnly (void)
587     throw (RuntimeException)
588 {
589     ThrowIfDisposed();
590     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
591         return true;
592     else
593         return mpSlideSorter->GetProperties()->IsUIReadOnly();
594 }
595 
596 
597 
598 
setIsUIReadOnly(sal_Bool bIsUIReadOnly)599 void SAL_CALL SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly)
600     throw (RuntimeException)
601 {
602     ThrowIfDisposed();
603     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
604         mpSlideSorter->GetProperties()->SetUIReadOnly(bIsUIReadOnly);
605 }
606 
607 
608 
609 
610 //-----------------------------------------------------------------------------
611 
Resize(void)612 void SlideSorterService::Resize (void)
613 {
614     if (mxParentWindow.is())
615     {
616         awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
617         mpSlideSorter->ArrangeGUIElements(
618             Point(0,0),
619             Size(aWindowBox.Width, aWindowBox.Height));
620     }
621 }
622 
623 
624 
625 
ThrowIfDisposed(void)626 void SlideSorterService::ThrowIfDisposed (void)
627     throw (::com::sun::star::lang::DisposedException)
628 {
629 	if (SlideSorterServiceInterfaceBase::rBHelper.bDisposed || SlideSorterServiceInterfaceBase::rBHelper.bInDispose)
630 	{
631         throw lang::DisposedException (
632             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
633                 "SlideSorterService object has already been disposed")),
634             static_cast<drawing::XDrawView*>(this));
635     }
636 }
637 
638 
639 } } // end of namespace ::sd::presenter
640 
641