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 "SlideSorterService.hxx"
22 #include "controller/SlideSorterController.hxx"
23 #include "controller/SlsProperties.hxx"
24 #include "controller/SlsCurrentSlideManager.hxx"
25 #include "model/SlideSorterModel.hxx"
26 #include "model/SlsPageDescriptor.hxx"
27 #include "view/SlideSorterView.hxx"
28 #include "view/SlsLayouter.hxx"
29 #include "DrawController.hxx"
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <com/sun/star/lang/XUnoTunnel.hpp>
33 #include <osl/mutex.hxx>
34 #include <vcl/svapp.hxx>
35 #include <cppuhelper/proptypehlp.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::drawing::framework
;
40 using ::sd::slidesorter::view::Layouter
;
42 namespace sd
{ namespace slidesorter
{
47 PropertyDocumentSlides
,
48 PropertyHighlightCurrentSlide
,
49 PropertyShowSelection
,
50 PropertyCenterSelection
,
51 PropertySuspendPreviewUpdatesDuringFullScreenPresentation
,
52 PropertyOrientationVertical
56 //===== SlideSorterService ==========================================================
58 SlideSorterService::SlideSorterService (const Reference
<XComponentContext
>& rxContext
)
59 : SlideSorterServiceInterfaceBase(m_aMutex
),
66 SlideSorterService::~SlideSorterService()
70 void SAL_CALL
SlideSorterService::disposing()
72 mpSlideSorter
.reset();
74 if (mxParentWindow
.is())
76 mxParentWindow
->removeWindowListener(this);
80 //----- XInitialization -------------------------------------------------------
82 void SAL_CALL
SlideSorterService::initialize (const Sequence
<Any
>& rArguments
)
83 throw (Exception
, RuntimeException
, std::exception
)
87 if (rArguments
.getLength() == 3)
91 mxViewId
= Reference
<XResourceId
>(rArguments
[0], UNO_QUERY_THROW
);
93 // Get the XController.
94 Reference
<frame::XController
> xController (rArguments
[1], UNO_QUERY_THROW
);
96 // Tunnel through the controller to obtain a ViewShellBase.
97 ViewShellBase
* pBase
= NULL
;
98 Reference
<lang::XUnoTunnel
> xTunnel (xController
, UNO_QUERY_THROW
);
99 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
100 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
101 if (pController
!= NULL
)
102 pBase
= pController
->GetViewShellBase();
104 // Get the parent window.
105 mxParentWindow
= Reference
<awt::XWindow
>(rArguments
[2], UNO_QUERY_THROW
);
106 vcl::Window
* pParentWindow
= VCLUnoHelper::GetWindow(mxParentWindow
);
108 mxParentWindow
->addWindowListener(this);
110 if (pBase
!= NULL
&& pParentWindow
!=NULL
)
111 mpSlideSorter
= SlideSorter::CreateSlideSorter(
118 catch (RuntimeException
&)
125 throw RuntimeException("SlideSorterService: invalid number of arguments",
126 static_cast<drawing::XDrawView
*>(this));
130 //----- XView -----------------------------------------------------------------
132 Reference
<XResourceId
> SAL_CALL
SlideSorterService::getResourceId()
133 throw (RuntimeException
, std::exception
)
138 sal_Bool SAL_CALL
SlideSorterService::isAnchorOnly()
139 throw (RuntimeException
, std::exception
)
144 //----- XWindowListener -------------------------------------------------------
146 void SAL_CALL
SlideSorterService::windowResized (const awt::WindowEvent
& rEvent
)
147 throw (RuntimeException
, std::exception
)
155 void SAL_CALL
SlideSorterService::windowMoved (const awt::WindowEvent
& rEvent
)
156 throw (RuntimeException
, std::exception
)
161 void SAL_CALL
SlideSorterService::windowShown (const lang::EventObject
& rEvent
)
162 throw (RuntimeException
, std::exception
)
169 void SAL_CALL
SlideSorterService::windowHidden (const lang::EventObject
& rEvent
)
170 throw (RuntimeException
, std::exception
)
176 //----- lang::XEventListener --------------------------------------------------
178 void SAL_CALL
SlideSorterService::disposing (const lang::EventObject
& rEvent
)
179 throw (RuntimeException
, std::exception
)
181 if (rEvent
.Source
== mxParentWindow
)
182 mxParentWindow
= NULL
;
185 //----- XDrawView -------------------------------------------------------------
187 void SAL_CALL
SlideSorterService::setCurrentPage(const Reference
<drawing::XDrawPage
>& rxSlide
)
188 throw (RuntimeException
, std::exception
)
191 if (mpSlideSorter
.get() != NULL
)
192 mpSlideSorter
->GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
193 mpSlideSorter
->GetModel().GetIndex(rxSlide
));
196 Reference
<drawing::XDrawPage
> SAL_CALL
SlideSorterService::getCurrentPage()
197 throw (RuntimeException
, std::exception
)
200 if (mpSlideSorter
.get() != NULL
)
201 return mpSlideSorter
->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
206 //----- attributes ------------------------------------------------------------
208 Reference
<container::XIndexAccess
> SAL_CALL
SlideSorterService::getDocumentSlides()
209 throw (RuntimeException
, std::exception
)
211 return mpSlideSorter
->GetModel().GetDocumentSlides();
214 void SAL_CALL
SlideSorterService::setDocumentSlides (
215 const Reference
<container::XIndexAccess
>& rxSlides
)
216 throw (RuntimeException
, std::exception
)
219 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
220 mpSlideSorter
->GetController().SetDocumentSlides(rxSlides
);
223 sal_Bool SAL_CALL
SlideSorterService::getIsHighlightCurrentSlide()
224 throw (RuntimeException
, std::exception
)
227 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
230 return mpSlideSorter
->GetProperties()->IsHighlightCurrentSlide();
233 void SAL_CALL
SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue
)
234 throw (RuntimeException
, std::exception
)
237 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
239 mpSlideSorter
->GetProperties()->SetHighlightCurrentSlide(bValue
);
240 controller::SlideSorterController::ModelChangeLock
aLock (mpSlideSorter
->GetController());
241 mpSlideSorter
->GetController().HandleModelChange();
245 sal_Bool SAL_CALL
SlideSorterService::getIsShowSelection()
246 throw (RuntimeException
, std::exception
)
249 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
252 return mpSlideSorter
->GetProperties()->IsShowSelection();
255 void SAL_CALL
SlideSorterService::setIsShowSelection (sal_Bool bValue
)
256 throw (RuntimeException
, std::exception
)
259 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
260 mpSlideSorter
->GetProperties()->SetShowSelection(bValue
);
263 sal_Bool SAL_CALL
SlideSorterService::getIsShowFocus()
264 throw (RuntimeException
, std::exception
)
267 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
270 return mpSlideSorter
->GetProperties()->IsShowFocus();
273 void SAL_CALL
SlideSorterService::setIsShowFocus (sal_Bool bValue
)
274 throw (RuntimeException
, std::exception
)
277 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
278 mpSlideSorter
->GetProperties()->SetShowFocus(bValue
);
281 sal_Bool SAL_CALL
SlideSorterService::getIsCenterSelection()
282 throw (RuntimeException
, std::exception
)
285 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
288 return mpSlideSorter
->GetProperties()->IsCenterSelection();
291 void SAL_CALL
SlideSorterService::setIsCenterSelection (sal_Bool bValue
)
292 throw (RuntimeException
, std::exception
)
295 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
296 mpSlideSorter
->GetProperties()->SetCenterSelection(bValue
);
299 sal_Bool SAL_CALL
SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation()
300 throw (RuntimeException
, std::exception
)
303 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
306 return mpSlideSorter
->GetProperties()
307 ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
310 void SAL_CALL
SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
312 throw (RuntimeException
, std::exception
)
315 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
316 mpSlideSorter
->GetProperties()
317 ->SetSuspendPreviewUpdatesDuringFullScreenPresentation(bValue
);
320 sal_Bool SAL_CALL
SlideSorterService::getIsOrientationVertical()
321 throw (RuntimeException
, std::exception
)
324 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
327 return mpSlideSorter
->GetView().GetOrientation() != Layouter::HORIZONTAL
;
330 void SAL_CALL
SlideSorterService::setIsOrientationVertical (sal_Bool bValue
)
331 throw (RuntimeException
, std::exception
)
334 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
335 mpSlideSorter
->GetView().SetOrientation(bValue
337 : Layouter::HORIZONTAL
);
340 sal_Bool SAL_CALL
SlideSorterService::getIsSmoothScrolling()
341 throw (RuntimeException
, std::exception
)
344 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
347 return mpSlideSorter
->GetProperties()->IsSmoothSelectionScrolling();
350 void SAL_CALL
SlideSorterService::setIsSmoothScrolling (sal_Bool bValue
)
351 throw (RuntimeException
, std::exception
)
354 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
355 mpSlideSorter
->GetProperties()->SetSmoothSelectionScrolling(bValue
);
358 util::Color SAL_CALL
SlideSorterService::getBackgroundColor()
359 throw (RuntimeException
, std::exception
)
362 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
363 return util::Color();
366 mpSlideSorter
->GetProperties()->GetBackgroundColor().GetColor());
369 void SAL_CALL
SlideSorterService::setBackgroundColor (util::Color aBackgroundColor
)
370 throw (RuntimeException
, std::exception
)
373 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
374 mpSlideSorter
->GetProperties()->SetBackgroundColor(Color(aBackgroundColor
));
377 util::Color SAL_CALL
SlideSorterService::getTextColor()
378 throw (css::uno::RuntimeException
, std::exception
)
381 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
382 return util::Color();
385 mpSlideSorter
->GetProperties()->GetTextColor().GetColor());
388 void SAL_CALL
SlideSorterService::setTextColor (util::Color aTextColor
)
389 throw (RuntimeException
, std::exception
)
392 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
393 mpSlideSorter
->GetProperties()->SetTextColor(Color(aTextColor
));
396 util::Color SAL_CALL
SlideSorterService::getSelectionColor()
397 throw (RuntimeException
, std::exception
)
400 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
401 return util::Color();
404 mpSlideSorter
->GetProperties()->GetSelectionColor().GetColor());
407 void SAL_CALL
SlideSorterService::setSelectionColor (util::Color aSelectionColor
)
408 throw (RuntimeException
, std::exception
)
411 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
412 mpSlideSorter
->GetProperties()->SetSelectionColor(Color(aSelectionColor
));
415 util::Color SAL_CALL
SlideSorterService::getHighlightColor()
416 throw (RuntimeException
, std::exception
)
419 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
420 return util::Color();
423 mpSlideSorter
->GetProperties()->GetHighlightColor().GetColor());
426 void SAL_CALL
SlideSorterService::setHighlightColor (util::Color aHighlightColor
)
427 throw (RuntimeException
, std::exception
)
430 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
431 mpSlideSorter
->GetProperties()->SetHighlightColor(Color(aHighlightColor
));
434 sal_Bool SAL_CALL
SlideSorterService::getIsUIReadOnly()
435 throw (RuntimeException
, std::exception
)
438 if (mpSlideSorter
.get() == NULL
|| ! mpSlideSorter
->IsValid())
441 return mpSlideSorter
->GetProperties()->IsUIReadOnly();
444 void SAL_CALL
SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly
)
445 throw (RuntimeException
, std::exception
)
448 if (mpSlideSorter
.get() != NULL
&& mpSlideSorter
->IsValid())
449 mpSlideSorter
->GetProperties()->SetUIReadOnly(bIsUIReadOnly
);
452 void SlideSorterService::Resize()
454 if (mxParentWindow
.is())
456 awt::Rectangle aWindowBox
= mxParentWindow
->getPosSize();
457 mpSlideSorter
->ArrangeGUIElements(
459 Size(aWindowBox
.Width
, aWindowBox
.Height
));
463 void SlideSorterService::ThrowIfDisposed()
464 throw (::com::sun::star::lang::DisposedException
)
466 if (SlideSorterServiceInterfaceBase::rBHelper
.bDisposed
|| SlideSorterServiceInterfaceBase::rBHelper
.bInDispose
)
468 throw lang::DisposedException ("SlideSorterService object has already been disposed",
469 static_cast<drawing::XDrawView
*>(this));
473 } } // end of namespace ::sd::slidesorter
476 extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface
* SAL_CALL
477 com_sun_star_comp_Draw_SlideSorter_get_implementation(::com::sun::star::uno::XComponentContext
* context
,
478 ::com::sun::star::uno::Sequence
<css::uno::Any
> const &)
480 return cppu::acquire(new sd::slidesorter::SlideSorterService(context
));
484 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */