bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / slidesorter / shell / SlideSorterService.cxx
blobd1e138e60a84f48910ca7335b7941a9d281bf1f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
21 #include "facreg.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 {
44 namespace {
45 enum Properties
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),
60 mpSlideSorter(),
61 mxParentWindow()
63 (void)rxContext;
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)
85 ThrowIfDisposed();
87 if (rArguments.getLength() == 3)
89 try
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(
112 *pBase,
113 NULL,
114 *pParentWindow);
116 Resize();
118 catch (RuntimeException&)
120 throw;
123 else
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)
135 return mxViewId;
138 sal_Bool SAL_CALL SlideSorterService::isAnchorOnly()
139 throw (RuntimeException, std::exception)
141 return sal_False;
144 //----- XWindowListener -------------------------------------------------------
146 void SAL_CALL SlideSorterService::windowResized (const awt::WindowEvent& rEvent)
147 throw (RuntimeException, std::exception)
149 (void)rEvent;
150 ThrowIfDisposed();
152 Resize();
155 void SAL_CALL SlideSorterService::windowMoved (const awt::WindowEvent& rEvent)
156 throw (RuntimeException, std::exception)
158 (void)rEvent;
161 void SAL_CALL SlideSorterService::windowShown (const lang::EventObject& rEvent)
162 throw (RuntimeException, std::exception)
164 (void)rEvent;
165 ThrowIfDisposed();
166 Resize();
169 void SAL_CALL SlideSorterService::windowHidden (const lang::EventObject& rEvent)
170 throw (RuntimeException, std::exception)
172 (void)rEvent;
173 ThrowIfDisposed();
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)
190 ThrowIfDisposed();
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)
199 ThrowIfDisposed();
200 if (mpSlideSorter.get() != NULL)
201 return mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
202 else
203 return NULL;
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)
218 ThrowIfDisposed();
219 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
220 mpSlideSorter->GetController().SetDocumentSlides(rxSlides);
223 sal_Bool SAL_CALL SlideSorterService::getIsHighlightCurrentSlide()
224 throw (RuntimeException, std::exception)
226 ThrowIfDisposed();
227 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
228 return false;
229 else
230 return mpSlideSorter->GetProperties()->IsHighlightCurrentSlide();
233 void SAL_CALL SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue)
234 throw (RuntimeException, std::exception)
236 ThrowIfDisposed();
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)
248 ThrowIfDisposed();
249 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
250 return false;
251 else
252 return mpSlideSorter->GetProperties()->IsShowSelection();
255 void SAL_CALL SlideSorterService::setIsShowSelection (sal_Bool bValue)
256 throw (RuntimeException, std::exception)
258 ThrowIfDisposed();
259 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
260 mpSlideSorter->GetProperties()->SetShowSelection(bValue);
263 sal_Bool SAL_CALL SlideSorterService::getIsShowFocus()
264 throw (RuntimeException, std::exception)
266 ThrowIfDisposed();
267 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
268 return false;
269 else
270 return mpSlideSorter->GetProperties()->IsShowFocus();
273 void SAL_CALL SlideSorterService::setIsShowFocus (sal_Bool bValue)
274 throw (RuntimeException, std::exception)
276 ThrowIfDisposed();
277 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
278 mpSlideSorter->GetProperties()->SetShowFocus(bValue);
281 sal_Bool SAL_CALL SlideSorterService::getIsCenterSelection()
282 throw (RuntimeException, std::exception)
284 ThrowIfDisposed();
285 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
286 return false;
287 else
288 return mpSlideSorter->GetProperties()->IsCenterSelection();
291 void SAL_CALL SlideSorterService::setIsCenterSelection (sal_Bool bValue)
292 throw (RuntimeException, std::exception)
294 ThrowIfDisposed();
295 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
296 mpSlideSorter->GetProperties()->SetCenterSelection(bValue);
299 sal_Bool SAL_CALL SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation()
300 throw (RuntimeException, std::exception)
302 ThrowIfDisposed();
303 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
304 return true;
305 else
306 return mpSlideSorter->GetProperties()
307 ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
310 void SAL_CALL SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
311 sal_Bool bValue)
312 throw (RuntimeException, std::exception)
314 ThrowIfDisposed();
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)
323 ThrowIfDisposed();
324 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
325 return true;
326 else
327 return mpSlideSorter->GetView().GetOrientation() != Layouter::HORIZONTAL;
330 void SAL_CALL SlideSorterService::setIsOrientationVertical (sal_Bool bValue)
331 throw (RuntimeException, std::exception)
333 ThrowIfDisposed();
334 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
335 mpSlideSorter->GetView().SetOrientation(bValue
336 ? Layouter::GRID
337 : Layouter::HORIZONTAL);
340 sal_Bool SAL_CALL SlideSorterService::getIsSmoothScrolling()
341 throw (RuntimeException, std::exception)
343 ThrowIfDisposed();
344 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
345 return false;
346 else
347 return mpSlideSorter->GetProperties()->IsSmoothSelectionScrolling();
350 void SAL_CALL SlideSorterService::setIsSmoothScrolling (sal_Bool bValue)
351 throw (RuntimeException, std::exception)
353 ThrowIfDisposed();
354 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
355 mpSlideSorter->GetProperties()->SetSmoothSelectionScrolling(bValue);
358 util::Color SAL_CALL SlideSorterService::getBackgroundColor()
359 throw (RuntimeException, std::exception)
361 ThrowIfDisposed();
362 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
363 return util::Color();
364 else
365 return util::Color(
366 mpSlideSorter->GetProperties()->GetBackgroundColor().GetColor());
369 void SAL_CALL SlideSorterService::setBackgroundColor (util::Color aBackgroundColor)
370 throw (RuntimeException, std::exception)
372 ThrowIfDisposed();
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)
380 ThrowIfDisposed();
381 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
382 return util::Color();
383 else
384 return util::Color(
385 mpSlideSorter->GetProperties()->GetTextColor().GetColor());
388 void SAL_CALL SlideSorterService::setTextColor (util::Color aTextColor)
389 throw (RuntimeException, std::exception)
391 ThrowIfDisposed();
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)
399 ThrowIfDisposed();
400 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
401 return util::Color();
402 else
403 return util::Color(
404 mpSlideSorter->GetProperties()->GetSelectionColor().GetColor());
407 void SAL_CALL SlideSorterService::setSelectionColor (util::Color aSelectionColor)
408 throw (RuntimeException, std::exception)
410 ThrowIfDisposed();
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)
418 ThrowIfDisposed();
419 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
420 return util::Color();
421 else
422 return util::Color(
423 mpSlideSorter->GetProperties()->GetHighlightColor().GetColor());
426 void SAL_CALL SlideSorterService::setHighlightColor (util::Color aHighlightColor)
427 throw (RuntimeException, std::exception)
429 ThrowIfDisposed();
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)
437 ThrowIfDisposed();
438 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
439 return true;
440 else
441 return mpSlideSorter->GetProperties()->IsUIReadOnly();
444 void SAL_CALL SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly)
445 throw (RuntimeException, std::exception)
447 ThrowIfDisposed();
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(
458 Point(0,0),
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: */