LCOV - code coverage report
Current view: top level - sd/source/ui/slidesorter/shell - SlideSorterService.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 205 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 45 4.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      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>
      36             : 
      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;
      41             : 
      42             : namespace sd { namespace slidesorter {
      43             : 
      44             : namespace {
      45             :     enum Properties
      46             :     {
      47             :         PropertyDocumentSlides,
      48             :         PropertyHighlightCurrentSlide,
      49             :         PropertyShowSelection,
      50             :         PropertyCenterSelection,
      51             :         PropertySuspendPreviewUpdatesDuringFullScreenPresentation,
      52             :         PropertyOrientationVertical
      53             :     };
      54             : }
      55             : 
      56             : //===== SlideSorterService ==========================================================
      57             : 
      58           0 : SlideSorterService::SlideSorterService (const Reference<XComponentContext>& rxContext)
      59             :     : SlideSorterServiceInterfaceBase(m_aMutex),
      60             :       mpSlideSorter(),
      61           0 :       mxParentWindow()
      62             : {
      63             :     (void)rxContext;
      64           0 : }
      65             : 
      66           0 : SlideSorterService::~SlideSorterService()
      67             : {
      68           0 : }
      69             : 
      70           0 : void SAL_CALL SlideSorterService::disposing()
      71             : {
      72           0 :     mpSlideSorter.reset();
      73             : 
      74           0 :     if (mxParentWindow.is())
      75             :     {
      76           0 :         mxParentWindow->removeWindowListener(this);
      77             :     }
      78           0 : }
      79             : 
      80             : //----- XInitialization -------------------------------------------------------
      81             : 
      82           0 : void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments)
      83             :     throw (Exception, RuntimeException, std::exception)
      84             : {
      85           0 :     ThrowIfDisposed();
      86             : 
      87           0 :     if (rArguments.getLength() == 3)
      88             :     {
      89             :         try
      90             :         {
      91           0 :             mxViewId = Reference<XResourceId>(rArguments[0], UNO_QUERY_THROW);
      92             : 
      93             :             // Get the XController.
      94           0 :             Reference<frame::XController> xController (rArguments[1], UNO_QUERY_THROW);
      95             : 
      96             :             // Tunnel through the controller to obtain a ViewShellBase.
      97           0 :             ViewShellBase* pBase = NULL;
      98           0 :             Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
      99             :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     100           0 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
     101           0 :             if (pController != NULL)
     102           0 :                 pBase = pController->GetViewShellBase();
     103             : 
     104             :             // Get the parent window.
     105           0 :             mxParentWindow = Reference<awt::XWindow>(rArguments[2], UNO_QUERY_THROW);
     106           0 :             vcl::Window* pParentWindow = VCLUnoHelper::GetWindow(mxParentWindow);
     107             : 
     108           0 :             mxParentWindow->addWindowListener(this);
     109             : 
     110           0 :             if (pBase != NULL && pParentWindow!=NULL)
     111           0 :                 mpSlideSorter = SlideSorter::CreateSlideSorter(
     112             :                     *pBase,
     113             :                     NULL,
     114           0 :                     *pParentWindow);
     115             : 
     116           0 :             Resize();
     117             :         }
     118           0 :         catch (RuntimeException&)
     119             :         {
     120           0 :             throw;
     121             :         }
     122             :     }
     123             :     else
     124             :     {
     125             :         throw RuntimeException("SlideSorterService: invalid number of arguments",
     126           0 :             static_cast<drawing::XDrawView*>(this));
     127             :     }
     128           0 : }
     129             : 
     130             : //----- XView -----------------------------------------------------------------
     131             : 
     132           0 : Reference<XResourceId> SAL_CALL SlideSorterService::getResourceId()
     133             :     throw (RuntimeException, std::exception)
     134             : {
     135           0 :     return mxViewId;
     136             : }
     137             : 
     138           0 : sal_Bool SAL_CALL SlideSorterService::isAnchorOnly()
     139             :     throw (RuntimeException, std::exception)
     140             : {
     141           0 :     return sal_False;
     142             : }
     143             : 
     144             : //----- XWindowListener -------------------------------------------------------
     145             : 
     146           0 : void SAL_CALL SlideSorterService::windowResized (const awt::WindowEvent& rEvent)
     147             :     throw (RuntimeException, std::exception)
     148             : {
     149             :     (void)rEvent;
     150           0 :     ThrowIfDisposed();
     151             : 
     152           0 :     Resize();
     153           0 : }
     154             : 
     155           0 : void SAL_CALL SlideSorterService::windowMoved (const awt::WindowEvent& rEvent)
     156             :     throw (RuntimeException, std::exception)
     157             : {
     158             :     (void)rEvent;
     159           0 : }
     160             : 
     161           0 : void SAL_CALL SlideSorterService::windowShown (const lang::EventObject& rEvent)
     162             :     throw (RuntimeException, std::exception)
     163             : {
     164             :     (void)rEvent;
     165           0 :     ThrowIfDisposed();
     166           0 :     Resize();
     167           0 : }
     168             : 
     169           0 : void SAL_CALL SlideSorterService::windowHidden (const lang::EventObject& rEvent)
     170             :     throw (RuntimeException, std::exception)
     171             : {
     172             :     (void)rEvent;
     173           0 :     ThrowIfDisposed();
     174           0 : }
     175             : 
     176             : //----- lang::XEventListener --------------------------------------------------
     177             : 
     178           0 : void SAL_CALL SlideSorterService::disposing (const lang::EventObject& rEvent)
     179             :     throw (RuntimeException, std::exception)
     180             : {
     181           0 :     if (rEvent.Source == mxParentWindow)
     182           0 :         mxParentWindow = NULL;
     183           0 : }
     184             : 
     185             : //----- XDrawView -------------------------------------------------------------
     186             : 
     187           0 : void SAL_CALL SlideSorterService::setCurrentPage(const Reference<drawing::XDrawPage>& rxSlide)
     188             :     throw (RuntimeException, std::exception)
     189             : {
     190           0 :     ThrowIfDisposed();
     191           0 :     if (mpSlideSorter.get() != NULL)
     192           0 :         mpSlideSorter->GetController().GetCurrentSlideManager()->NotifyCurrentSlideChange(
     193           0 :             mpSlideSorter->GetModel().GetIndex(rxSlide));
     194           0 : }
     195             : 
     196           0 : Reference<drawing::XDrawPage> SAL_CALL SlideSorterService::getCurrentPage()
     197             :     throw (RuntimeException, std::exception)
     198             : {
     199           0 :     ThrowIfDisposed();
     200           0 :     if (mpSlideSorter.get() != NULL)
     201           0 :         return mpSlideSorter->GetController().GetCurrentSlideManager()->GetCurrentSlide()->GetXDrawPage();
     202             :     else
     203           0 :         return NULL;
     204             : }
     205             : 
     206             : //----- attributes ------------------------------------------------------------
     207             : 
     208           0 : Reference<container::XIndexAccess> SAL_CALL SlideSorterService::getDocumentSlides()
     209             :     throw (RuntimeException, std::exception)
     210             : {
     211           0 :     return mpSlideSorter->GetModel().GetDocumentSlides();
     212             : }
     213             : 
     214           0 : void SAL_CALL SlideSorterService::setDocumentSlides (
     215             :     const Reference<container::XIndexAccess >& rxSlides)
     216             :     throw (RuntimeException, std::exception)
     217             : {
     218           0 :     ThrowIfDisposed();
     219           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     220           0 :         mpSlideSorter->GetController().SetDocumentSlides(rxSlides);
     221           0 : }
     222             : 
     223           0 : sal_Bool SAL_CALL SlideSorterService::getIsHighlightCurrentSlide()
     224             :     throw (RuntimeException, std::exception)
     225             : {
     226           0 :     ThrowIfDisposed();
     227           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     228           0 :         return false;
     229             :     else
     230           0 :         return mpSlideSorter->GetProperties()->IsHighlightCurrentSlide();
     231             : }
     232             : 
     233           0 : void SAL_CALL SlideSorterService::setIsHighlightCurrentSlide (sal_Bool bValue)
     234             :     throw (RuntimeException, std::exception)
     235             : {
     236           0 :     ThrowIfDisposed();
     237           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     238             :     {
     239           0 :         mpSlideSorter->GetProperties()->SetHighlightCurrentSlide(bValue);
     240           0 :         controller::SlideSorterController::ModelChangeLock aLock (mpSlideSorter->GetController());
     241           0 :         mpSlideSorter->GetController().HandleModelChange();
     242             :     }
     243           0 : }
     244             : 
     245           0 : sal_Bool SAL_CALL SlideSorterService::getIsShowSelection()
     246             :     throw (RuntimeException, std::exception)
     247             : {
     248           0 :     ThrowIfDisposed();
     249           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     250           0 :         return false;
     251             :     else
     252           0 :         return mpSlideSorter->GetProperties()->IsShowSelection();
     253             : }
     254             : 
     255           0 : void SAL_CALL SlideSorterService::setIsShowSelection (sal_Bool bValue)
     256             :     throw (RuntimeException, std::exception)
     257             : {
     258           0 :     ThrowIfDisposed();
     259           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     260           0 :         mpSlideSorter->GetProperties()->SetShowSelection(bValue);
     261           0 : }
     262             : 
     263           0 : sal_Bool SAL_CALL SlideSorterService::getIsShowFocus()
     264             :     throw (RuntimeException, std::exception)
     265             : {
     266           0 :     ThrowIfDisposed();
     267           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     268           0 :         return false;
     269             :     else
     270           0 :         return mpSlideSorter->GetProperties()->IsShowFocus();
     271             : }
     272             : 
     273           0 : void SAL_CALL SlideSorterService::setIsShowFocus (sal_Bool bValue)
     274             :     throw (RuntimeException, std::exception)
     275             : {
     276           0 :     ThrowIfDisposed();
     277           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     278           0 :         mpSlideSorter->GetProperties()->SetShowFocus(bValue);
     279           0 : }
     280             : 
     281           0 : sal_Bool SAL_CALL SlideSorterService::getIsCenterSelection()
     282             :     throw (RuntimeException, std::exception)
     283             : {
     284           0 :     ThrowIfDisposed();
     285           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     286           0 :         return false;
     287             :     else
     288           0 :         return mpSlideSorter->GetProperties()->IsCenterSelection();
     289             : }
     290             : 
     291           0 : void SAL_CALL SlideSorterService::setIsCenterSelection (sal_Bool bValue)
     292             :     throw (RuntimeException, std::exception)
     293             : {
     294           0 :     ThrowIfDisposed();
     295           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     296           0 :         mpSlideSorter->GetProperties()->SetCenterSelection(bValue);
     297           0 : }
     298             : 
     299           0 : sal_Bool SAL_CALL SlideSorterService::getIsSuspendPreviewUpdatesDuringFullScreenPresentation()
     300             :     throw (RuntimeException, std::exception)
     301             : {
     302           0 :     ThrowIfDisposed();
     303           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     304           0 :         return true;
     305             :     else
     306             :         return mpSlideSorter->GetProperties()
     307           0 :             ->IsSuspendPreviewUpdatesDuringFullScreenPresentation();
     308             : }
     309             : 
     310           0 : void SAL_CALL SlideSorterService::setIsSuspendPreviewUpdatesDuringFullScreenPresentation (
     311             :     sal_Bool bValue)
     312             :     throw (RuntimeException, std::exception)
     313             : {
     314           0 :     ThrowIfDisposed();
     315           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     316             :         mpSlideSorter->GetProperties()
     317           0 :             ->SetSuspendPreviewUpdatesDuringFullScreenPresentation(bValue);
     318           0 : }
     319             : 
     320           0 : sal_Bool SAL_CALL SlideSorterService::getIsOrientationVertical()
     321             :     throw (RuntimeException, std::exception)
     322             : {
     323           0 :     ThrowIfDisposed();
     324           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     325           0 :         return true;
     326             :     else
     327           0 :         return mpSlideSorter->GetView().GetOrientation() != Layouter::HORIZONTAL;
     328             : }
     329             : 
     330           0 : void SAL_CALL SlideSorterService::setIsOrientationVertical (sal_Bool bValue)
     331             :     throw (RuntimeException, std::exception)
     332             : {
     333           0 :     ThrowIfDisposed();
     334           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     335           0 :         mpSlideSorter->GetView().SetOrientation(bValue
     336             :             ? Layouter::GRID
     337           0 :             : Layouter::HORIZONTAL);
     338           0 : }
     339             : 
     340           0 : sal_Bool SAL_CALL SlideSorterService::getIsSmoothScrolling()
     341             :     throw (RuntimeException, std::exception)
     342             : {
     343           0 :     ThrowIfDisposed();
     344           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     345           0 :         return false;
     346             :     else
     347           0 :         return mpSlideSorter->GetProperties()->IsSmoothSelectionScrolling();
     348             : }
     349             : 
     350           0 : void SAL_CALL SlideSorterService::setIsSmoothScrolling (sal_Bool bValue)
     351             :     throw (RuntimeException, std::exception)
     352             : {
     353           0 :     ThrowIfDisposed();
     354           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     355           0 :         mpSlideSorter->GetProperties()->SetSmoothSelectionScrolling(bValue);
     356           0 : }
     357             : 
     358           0 : util::Color SAL_CALL SlideSorterService::getBackgroundColor()
     359             :     throw (RuntimeException, std::exception)
     360             : {
     361           0 :     ThrowIfDisposed();
     362           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     363           0 :         return util::Color();
     364             :     else
     365             :         return util::Color(
     366           0 :             mpSlideSorter->GetProperties()->GetBackgroundColor().GetColor());
     367             : }
     368             : 
     369           0 : void SAL_CALL SlideSorterService::setBackgroundColor (util::Color aBackgroundColor)
     370             :     throw (RuntimeException, std::exception)
     371             : {
     372           0 :     ThrowIfDisposed();
     373           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     374           0 :         mpSlideSorter->GetProperties()->SetBackgroundColor(Color(aBackgroundColor));
     375           0 : }
     376             : 
     377           0 : util::Color SAL_CALL SlideSorterService::getTextColor()
     378             :     throw (css::uno::RuntimeException, std::exception)
     379             : {
     380           0 :     ThrowIfDisposed();
     381           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     382           0 :         return util::Color();
     383             :     else
     384             :         return util::Color(
     385           0 :             mpSlideSorter->GetProperties()->GetTextColor().GetColor());
     386             : }
     387             : 
     388           0 : void SAL_CALL SlideSorterService::setTextColor (util::Color aTextColor)
     389             :     throw (RuntimeException, std::exception)
     390             : {
     391           0 :     ThrowIfDisposed();
     392           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     393           0 :         mpSlideSorter->GetProperties()->SetTextColor(Color(aTextColor));
     394           0 : }
     395             : 
     396           0 : util::Color SAL_CALL SlideSorterService::getSelectionColor()
     397             :     throw (RuntimeException, std::exception)
     398             : {
     399           0 :     ThrowIfDisposed();
     400           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     401           0 :         return util::Color();
     402             :     else
     403             :         return util::Color(
     404           0 :             mpSlideSorter->GetProperties()->GetSelectionColor().GetColor());
     405             : }
     406             : 
     407           0 : void SAL_CALL SlideSorterService::setSelectionColor (util::Color aSelectionColor)
     408             :     throw (RuntimeException, std::exception)
     409             : {
     410           0 :     ThrowIfDisposed();
     411           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     412           0 :         mpSlideSorter->GetProperties()->SetSelectionColor(Color(aSelectionColor));
     413           0 : }
     414             : 
     415           0 : util::Color SAL_CALL SlideSorterService::getHighlightColor()
     416             :     throw (RuntimeException, std::exception)
     417             : {
     418           0 :     ThrowIfDisposed();
     419           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     420           0 :         return util::Color();
     421             :     else
     422             :         return util::Color(
     423           0 :             mpSlideSorter->GetProperties()->GetHighlightColor().GetColor());
     424             : }
     425             : 
     426           0 : void SAL_CALL SlideSorterService::setHighlightColor (util::Color aHighlightColor)
     427             :     throw (RuntimeException, std::exception)
     428             : {
     429           0 :     ThrowIfDisposed();
     430           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     431           0 :         mpSlideSorter->GetProperties()->SetHighlightColor(Color(aHighlightColor));
     432           0 : }
     433             : 
     434           0 : sal_Bool SAL_CALL SlideSorterService::getIsUIReadOnly()
     435             :     throw (RuntimeException, std::exception)
     436             : {
     437           0 :     ThrowIfDisposed();
     438           0 :     if (mpSlideSorter.get() == NULL || ! mpSlideSorter->IsValid())
     439           0 :         return true;
     440             :     else
     441           0 :         return mpSlideSorter->GetProperties()->IsUIReadOnly();
     442             : }
     443             : 
     444           0 : void SAL_CALL SlideSorterService::setIsUIReadOnly (sal_Bool bIsUIReadOnly)
     445             :     throw (RuntimeException, std::exception)
     446             : {
     447           0 :     ThrowIfDisposed();
     448           0 :     if (mpSlideSorter.get() != NULL && mpSlideSorter->IsValid())
     449           0 :         mpSlideSorter->GetProperties()->SetUIReadOnly(bIsUIReadOnly);
     450           0 : }
     451             : 
     452           0 : void SlideSorterService::Resize()
     453             : {
     454           0 :     if (mxParentWindow.is())
     455             :     {
     456           0 :         awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
     457             :         mpSlideSorter->ArrangeGUIElements(
     458             :             Point(0,0),
     459           0 :             Size(aWindowBox.Width, aWindowBox.Height));
     460             :     }
     461           0 : }
     462             : 
     463           0 : void SlideSorterService::ThrowIfDisposed()
     464             :     throw (::com::sun::star::lang::DisposedException)
     465             : {
     466           0 :     if (SlideSorterServiceInterfaceBase::rBHelper.bDisposed || SlideSorterServiceInterfaceBase::rBHelper.bInDispose)
     467             :     {
     468             :         throw lang::DisposedException ("SlideSorterService object has already been disposed",
     469           0 :             static_cast<drawing::XDrawView*>(this));
     470             :     }
     471           0 : }
     472             : 
     473             : } } // end of namespace ::sd::slidesorter
     474             : 
     475             : 
     476             : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
     477           0 : com_sun_star_comp_Draw_SlideSorter_get_implementation(::com::sun::star::uno::XComponentContext* context,
     478             :                                                       ::com::sun::star::uno::Sequence<css::uno::Any> const &)
     479             : {
     480           0 :     return cppu::acquire(new sd::slidesorter::SlideSorterService(context));
     481          66 : }
     482             : 
     483             : 
     484             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11