1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideSorterService.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "SlideSorterService.hxx"
35 #include "controller/SlideSorterController.hxx"
36 #include "controller/SlsProperties.hxx"
37 #include "controller/SlsCurrentSlideManager.hxx"
38 #include "model/SlideSorterModel.hxx"
39 #include "model/SlsPageDescriptor.hxx"
40 #include "view/SlideSorterView.hxx"
41 #include "DrawController.hxx"
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/lang/XUnoTunnel.hpp>
45 #include <vos/mutex.hxx>
46 #include <vcl/svapp.hxx>
47 #include <cppuhelper/proptypehlp.hxx>
49 using namespace ::com::sun::star
;
50 using namespace ::com::sun::star::uno
;
51 using namespace ::com::sun::star::drawing::framework
;
52 using ::rtl::OUString
;
53 using ::sd::slidesorter::view::SlideSorterView
;
55 namespace sd
{ namespace slidesorter
{
60 PropertyDocumentSlides
,
61 PropertyHighlightCurrentSlide
,
62 PropertyShowSelection
,
63 PropertyCenterSelection
,
64 PropertySuspendPreviewUpdatesDuringFullScreenPresentation
,
65 PropertyOrientationVertical
72 //===== Service ===============================================================
74 Reference
<XInterface
> SAL_CALL
SlideSorterService_createInstance (
75 const Reference
<XComponentContext
>& rxContext
)
77 return Reference
<XInterface
>(static_cast<drawing::XDrawView
*>(new SlideSorterService(rxContext
)));
83 ::rtl::OUString
SlideSorterService_getImplementationName (void) throw(RuntimeException
)
85 return OUString::createFromAscii("com.sun.star.comp.Draw.SlideSorter");
91 Sequence
<rtl::OUString
> SAL_CALL
SlideSorterService_getSupportedServiceNames (void)
92 throw (RuntimeException
)
94 static const ::rtl::OUString
sServiceName(
95 ::rtl::OUString::createFromAscii("com.sun.star.drawing.SlideSorter"));
96 return Sequence
<rtl::OUString
>(&sServiceName
, 1);
102 //===== SlideSorterService ==========================================================
104 SlideSorterService::SlideSorterService (const Reference
<XComponentContext
>& rxContext
)
105 : SlideSorterServiceInterfaceBase(m_aMutex
),
115 SlideSorterService::~SlideSorterService (void)
122 void SAL_CALL
SlideSorterService::disposing (void)
124 mpSlideSorter
.reset();
126 if (mxParentWindow
.is())
128 mxParentWindow
->removeWindowListener(this);
135 //----- XInitialization -------------------------------------------------------
137 void SAL_CALL
SlideSorterService::initialize (const Sequence
<Any
>& rArguments
)
138 throw (Exception
, RuntimeException
)
142 if (rArguments
.getLength() == 3)
146 mxViewId
= Reference
<XResourceId
>(rArguments
[0], UNO_QUERY_THROW
);
148 // Get the XController.
149 Reference
<frame::XController
> xController (rArguments
[1], UNO_QUERY_THROW
);
151 // Tunnel through the controller to obtain a ViewShellBase.
152 ViewShellBase
* pBase
= NULL
;
153 Reference
<lang::XUnoTunnel
> xTunnel (xController
, UNO_QUERY_THROW
);
154 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
155 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
156 if (pController
!= NULL
)
157 pBase
= pController
->GetViewShellBase();
159 // Get the parent window.
160 mxParentWindow
= Reference
<awt::XWindow
>(rArguments
[2], UNO_QUERY_THROW
);
161 ::Window
* pParentWindow
= VCLUnoHelper::GetWindow(mxParentWindow
);
163 mxParentWindow
->addWindowListener(this);
165 if (pBase
!= NULL
&& pParentWindow
!=NULL
)
166 mpSlideSorter
= SlideSorter::CreateSlideSorter(
173 catch (RuntimeException
&)
180 throw RuntimeException(
181 OUString::createFromAscii("SlideSorterService: invalid number of arguments"),
182 static_cast<drawing::XDrawView
*>(this));
189 //----- XView -----------------------------------------------------------------
191 Reference
<XResourceId
> SAL_CALL
SlideSorterService::getResourceId (void)
192 throw (RuntimeException
)
200 sal_Bool SAL_CALL
SlideSorterService::isAnchorOnly (void)
201 throw (RuntimeException
)
209 //----- XWindowListener -------------------------------------------------------
211 void SAL_CALL
SlideSorterService::windowResized (const awt::WindowEvent
& rEvent
)
212 throw (RuntimeException
)
224 void SAL_CALL
SlideSorterService::windowMoved (const awt::WindowEvent
& rEvent
)
225 throw (RuntimeException
)
233 void SAL_CALL
SlideSorterService::windowShown (const lang::EventObject
& rEvent
)
234 throw (RuntimeException
)
244 void SAL_CALL
SlideSorterService::windowHidden (const lang::EventObject
& rEvent
)
245 throw (RuntimeException
)
254 //----- lang::XEventListener --------------------------------------------------
256 void SAL_CALL
SlideSorterService::disposing (const lang::EventObject
& rEvent
)
257 throw (RuntimeException
)
259 if (rEvent
.Source
== mxParentWindow
)
260 mxParentWindow
= NULL
;
266 //----- XDrawView -------------------------------------------------------------
268 void SAL_CALL
SlideSorterService::setCurrentPage(const Reference
<drawing::XDrawPage
>& rxSlide
)
269 throw (RuntimeException
)
272 if (mpSlideSorter
.get() != NULL
)
273 mpSlideSorter
->GetController().GetCurrentSlideManager()->CurrentSlideHasChanged(
274 mpSlideSorter
->GetModel().GetIndex(rxSlide
));
280 Reference
<drawing::XDrawPage
> SAL_CALL
SlideSorterService::getCurrentPage (void)
281 throw (RuntimeException
)
284 if (mpSlideSorter
.get() != NULL
)
285 return mpSlideSorter
->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
293 //----- attributes ------------------------------------------------------------
296 Reference
<container::XIndexAccess
> SAL_CALL
SlideSorterService::getDocumentSlides (void)
297 throw (RuntimeException
)
299 return mpSlideSorter
->GetModel().GetDocumentSlides();
305 void SAL_CALL
SlideSorterService::setDocumentSlides (
306 const Reference
<container::XIndexAccess
>& rxSlides
)
307 throw (RuntimeException
)
310 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
311 mpSlideSorter
->GetController().SetDocumentSlides(rxSlides
);
317 sal_Bool SAL_CALL
SlideSorterService::getIsHighlightCurrentSlide (void)
318 throw (RuntimeException
)
321 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
324 return mpSlideSorter
->GetController().GetProperties()->IsHighlightCurrentSlide();
330 void SAL_CALL
SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue
)
331 throw (RuntimeException
)
334 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
336 mpSlideSorter
->GetController().GetProperties()->SetHighlightCurrentSlide(bValue
);
337 controller::SlideSorterController::ModelChangeLock
aLock (mpSlideSorter
->GetController());
338 mpSlideSorter
->GetController().HandleModelChange();
345 sal_Bool SAL_CALL
SlideSorterService::getIsShowSelection (void)
346 throw (RuntimeException
)
349 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
352 return mpSlideSorter
->GetController().GetProperties()->IsShowSelection();
358 void SAL_CALL
SlideSorterService::setIsShowSelection (sal_Bool bValue
)
359 throw (RuntimeException
)
362 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
363 mpSlideSorter
->GetController().GetProperties()->SetShowSelection(bValue
);
369 sal_Bool SAL_CALL
SlideSorterService::getIsShowFocus (void)
370 throw (RuntimeException
)
373 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
376 return mpSlideSorter
->GetController().GetProperties()->IsShowFocus();
382 void SAL_CALL
SlideSorterService::setIsShowFocus (sal_Bool bValue
)
383 throw (RuntimeException
)
386 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
387 mpSlideSorter
->GetController().GetProperties()->SetShowFocus(bValue
);
393 sal_Bool SAL_CALL
SlideSorterService::getIsCenterSelection (void)
394 throw (RuntimeException
)
397 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
400 return mpSlideSorter
->GetController().GetProperties()->IsCenterSelection();
406 void SAL_CALL
SlideSorterService::setIsCenterSelection (sal_Bool bValue
)
407 throw (RuntimeException
)
410 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
411 mpSlideSorter
->GetController().GetProperties()->SetCenterSelection(bValue
);
417 sal_Bool SAL_CALL
SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation (void)
418 throw (RuntimeException
)
421 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
424 return mpSlideSorter
->GetController().GetProperties()
425 ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
431 void SAL_CALL
SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
433 throw (RuntimeException
)
436 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
437 mpSlideSorter
->GetController().GetProperties()
438 ->SetSuspendPreviewUpdatesDuringFullScreenPresentation(bValue
);
444 sal_Bool SAL_CALL
SlideSorterService::getIsOrientationVertical (void)
445 throw (RuntimeException
)
448 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
451 return mpSlideSorter
->GetView().GetOrientation() == SlideSorterView::VERTICAL
;
457 void SAL_CALL
SlideSorterService::setIsOrientationVertical (sal_Bool bValue
)
458 throw (RuntimeException
)
461 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
462 mpSlideSorter
->GetView().SetOrientation(bValue
463 ? SlideSorterView::VERTICAL
464 : SlideSorterView::HORIZONTAL
);
470 sal_Bool SAL_CALL
SlideSorterService::getIsSmoothScrolling (void)
471 throw (RuntimeException
)
474 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
477 return mpSlideSorter
->GetController().GetProperties()->IsSmoothSelectionScrolling();
483 void SAL_CALL
SlideSorterService::setIsSmoothScrolling (sal_Bool bValue
)
484 throw (RuntimeException
)
487 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
488 mpSlideSorter
->GetController().GetProperties()->SetSmoothSelectionScrolling(bValue
);
494 util::Color SAL_CALL
SlideSorterService::getBackgroundColor (void)
495 throw (RuntimeException
)
498 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
499 return util::Color();
502 mpSlideSorter
->GetController().GetProperties()->GetBackgroundColor().GetColor());
508 void SAL_CALL
SlideSorterService::setBackgroundColor (util::Color aBackgroundColor
)
509 throw (RuntimeException
)
512 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
513 mpSlideSorter
->GetController().GetProperties()->SetBackgroundColor(
514 Color(aBackgroundColor
));
520 util::Color SAL_CALL
SlideSorterService::getTextColor (void)
521 throw (css::uno::RuntimeException
)
524 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
525 return util::Color();
528 mpSlideSorter
->GetController().GetProperties()->GetTextColor().GetColor());
534 void SAL_CALL
SlideSorterService::setTextColor (util::Color aTextColor
)
535 throw (RuntimeException
)
538 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
539 mpSlideSorter
->GetController().GetProperties()->SetTextColor(
546 util::Color SAL_CALL
SlideSorterService::getSelectionColor (void)
547 throw (RuntimeException
)
550 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
551 return util::Color();
554 mpSlideSorter
->GetController().GetProperties()->GetSelectionColor().GetColor());
560 void SAL_CALL
SlideSorterService::setSelectionColor (util::Color aSelectionColor
)
561 throw (RuntimeException
)
564 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
565 mpSlideSorter
->GetController().GetProperties()->SetSelectionColor(
566 Color(aSelectionColor
));
572 util::Color SAL_CALL
SlideSorterService::getHighlightColor (void)
573 throw (RuntimeException
)
576 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
577 return util::Color();
580 mpSlideSorter
->GetController().GetProperties()->GetHighlightColor().GetColor());
586 void SAL_CALL
SlideSorterService::setHighlightColor (util::Color aHighlightColor
)
587 throw (RuntimeException
)
590 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
591 mpSlideSorter
->GetController().GetProperties()->SetHighlightColor(
592 Color(aHighlightColor
));
597 sal_Bool SAL_CALL
SlideSorterService::getIsUIReadOnly (void)
598 throw (RuntimeException
)
601 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
604 return mpSlideSorter
->GetController().GetProperties()->IsUIReadOnly();
610 void SAL_CALL
SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly
)
611 throw (RuntimeException
)
614 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
615 mpSlideSorter
->GetController().GetProperties()->SetUIReadOnly(
622 //-----------------------------------------------------------------------------
624 void SlideSorterService::Resize (void)
626 if (mxParentWindow
.is())
628 awt::Rectangle aWindowBox
= mxParentWindow
->getPosSize();
629 mpSlideSorter
->ArrangeGUIElements(
631 Size(aWindowBox
.Width
, aWindowBox
.Height
));
638 void SlideSorterService::Rearrange (void)
640 if (mxParentWindow
.is())
642 awt::Rectangle aWindowBox
= mxParentWindow
->getPosSize();
643 mpSlideSorter
->GetController().Rearrange();
650 void SlideSorterService::ThrowIfDisposed (void)
651 throw (::com::sun::star::lang::DisposedException
)
653 if (SlideSorterServiceInterfaceBase::rBHelper
.bDisposed
|| SlideSorterServiceInterfaceBase::rBHelper
.bInDispose
)
655 throw lang::DisposedException (
656 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
657 "SlideSorterService object has already been disposed")),
658 static_cast<drawing::XDrawView
*>(this));
663 } } // end of namespace ::sd::presenter