merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / shell / SlideSorterService.cxx
blob14e78b67e515aa135ba522d7ddd38f633a57885e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlideSorterService.cxx,v $
11 * $Revision: 1.3 $
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 {
57 namespace {
58 enum Properties
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),
106 mpSlideSorter(),
107 mxParentWindow()
109 (void)rxContext;
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)
140 ThrowIfDisposed();
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(
167 *pBase,
168 NULL,
169 *pParentWindow);
171 Resize();
173 catch (RuntimeException&)
175 throw;
178 else
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)
194 return mxViewId;
200 sal_Bool SAL_CALL SlideSorterService::isAnchorOnly (void)
201 throw (RuntimeException)
203 return sal_False;
209 //----- XWindowListener -------------------------------------------------------
211 void SAL_CALL SlideSorterService::windowResized (const awt::WindowEvent& rEvent)
212 throw (RuntimeException)
214 (void)rEvent;
215 ThrowIfDisposed();
217 Resize();
224 void SAL_CALL SlideSorterService::windowMoved (const awt::WindowEvent& rEvent)
225 throw (RuntimeException)
227 (void)rEvent;
233 void SAL_CALL SlideSorterService::windowShown (const lang::EventObject& rEvent)
234 throw (RuntimeException)
236 (void)rEvent;
237 ThrowIfDisposed();
238 Resize();
244 void SAL_CALL SlideSorterService::windowHidden (const lang::EventObject& rEvent)
245 throw (RuntimeException)
247 (void)rEvent;
248 ThrowIfDisposed();
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)
271 ThrowIfDisposed();
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)
283 ThrowIfDisposed();
284 if (mpSlideSorter.get() != NULL)
285 return mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
286 else
287 return NULL;
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)
309 ThrowIfDisposed();
310 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
311 mpSlideSorter->GetController().SetDocumentSlides(rxSlides);
317 sal_Bool SAL_CALL SlideSorterService::getIsHighlightCurrentSlide (void)
318 throw (RuntimeException)
320 ThrowIfDisposed();
321 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
322 return false;
323 else
324 return mpSlideSorter->GetController().GetProperties()->IsHighlightCurrentSlide();
330 void SAL_CALL SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue)
331 throw (RuntimeException)
333 ThrowIfDisposed();
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)
348 ThrowIfDisposed();
349 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
350 return false;
351 else
352 return mpSlideSorter->GetController().GetProperties()->IsShowSelection();
358 void SAL_CALL SlideSorterService::setIsShowSelection (sal_Bool bValue)
359 throw (RuntimeException)
361 ThrowIfDisposed();
362 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
363 mpSlideSorter->GetController().GetProperties()->SetShowSelection(bValue);
369 sal_Bool SAL_CALL SlideSorterService::getIsShowFocus (void)
370 throw (RuntimeException)
372 ThrowIfDisposed();
373 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
374 return false;
375 else
376 return mpSlideSorter->GetController().GetProperties()->IsShowFocus();
382 void SAL_CALL SlideSorterService::setIsShowFocus (sal_Bool bValue)
383 throw (RuntimeException)
385 ThrowIfDisposed();
386 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
387 mpSlideSorter->GetController().GetProperties()->SetShowFocus(bValue);
393 sal_Bool SAL_CALL SlideSorterService::getIsCenterSelection (void)
394 throw (RuntimeException)
396 ThrowIfDisposed();
397 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
398 return false;
399 else
400 return mpSlideSorter->GetController().GetProperties()->IsCenterSelection();
406 void SAL_CALL SlideSorterService::setIsCenterSelection (sal_Bool bValue)
407 throw (RuntimeException)
409 ThrowIfDisposed();
410 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
411 mpSlideSorter->GetController().GetProperties()->SetCenterSelection(bValue);
417 sal_Bool SAL_CALL SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation (void)
418 throw (RuntimeException)
420 ThrowIfDisposed();
421 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
422 return true;
423 else
424 return mpSlideSorter->GetController().GetProperties()
425 ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
431 void SAL_CALL SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
432 sal_Bool bValue)
433 throw (RuntimeException)
435 ThrowIfDisposed();
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)
447 ThrowIfDisposed();
448 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
449 return true;
450 else
451 return mpSlideSorter->GetView().GetOrientation() == SlideSorterView::VERTICAL;
457 void SAL_CALL SlideSorterService::setIsOrientationVertical (sal_Bool bValue)
458 throw (RuntimeException)
460 ThrowIfDisposed();
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)
473 ThrowIfDisposed();
474 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
475 return false;
476 else
477 return mpSlideSorter->GetController().GetProperties()->IsSmoothSelectionScrolling();
483 void SAL_CALL SlideSorterService::setIsSmoothScrolling (sal_Bool bValue)
484 throw (RuntimeException)
486 ThrowIfDisposed();
487 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
488 mpSlideSorter->GetController().GetProperties()->SetSmoothSelectionScrolling(bValue);
494 util::Color SAL_CALL SlideSorterService::getBackgroundColor (void)
495 throw (RuntimeException)
497 ThrowIfDisposed();
498 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
499 return util::Color();
500 else
501 return util::Color(
502 mpSlideSorter->GetController().GetProperties()->GetBackgroundColor().GetColor());
508 void SAL_CALL SlideSorterService::setBackgroundColor (util::Color aBackgroundColor)
509 throw (RuntimeException)
511 ThrowIfDisposed();
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)
523 ThrowIfDisposed();
524 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
525 return util::Color();
526 else
527 return util::Color(
528 mpSlideSorter->GetController().GetProperties()->GetTextColor().GetColor());
534 void SAL_CALL SlideSorterService::setTextColor (util::Color aTextColor)
535 throw (RuntimeException)
537 ThrowIfDisposed();
538 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
539 mpSlideSorter->GetController().GetProperties()->SetTextColor(
540 Color(aTextColor));
546 util::Color SAL_CALL SlideSorterService::getSelectionColor (void)
547 throw (RuntimeException)
549 ThrowIfDisposed();
550 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
551 return util::Color();
552 else
553 return util::Color(
554 mpSlideSorter->GetController().GetProperties()->GetSelectionColor().GetColor());
560 void SAL_CALL SlideSorterService::setSelectionColor (util::Color aSelectionColor)
561 throw (RuntimeException)
563 ThrowIfDisposed();
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)
575 ThrowIfDisposed();
576 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
577 return util::Color();
578 else
579 return util::Color(
580 mpSlideSorter->GetController().GetProperties()->GetHighlightColor().GetColor());
586 void SAL_CALL SlideSorterService::setHighlightColor (util::Color aHighlightColor)
587 throw (RuntimeException)
589 ThrowIfDisposed();
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)
600 ThrowIfDisposed();
601 if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
602 return true;
603 else
604 return mpSlideSorter->GetController().GetProperties()->IsUIReadOnly();
610 void SAL_CALL SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly)
611 throw (RuntimeException)
613 ThrowIfDisposed();
614 if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
615 mpSlideSorter->GetController().GetProperties()->SetUIReadOnly(
616 bIsUIReadOnly);
622 //-----------------------------------------------------------------------------
624 void SlideSorterService::Resize (void)
626 if (mxParentWindow.is())
628 awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
629 mpSlideSorter->ArrangeGUIElements(
630 Point(0,0),
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