LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - ViewShellWrapper.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 65 109 59.6 %
Date: 2015-06-13 12:38:46 Functions: 17 21 81.0 %
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 "framework/ViewShellWrapper.hxx"
      21             : #include "framework/Pane.hxx"
      22             : #include "sdpage.hxx"
      23             : #include "ViewShell.hxx"
      24             : #include "Window.hxx"
      25             : 
      26             : #include "SlideSorter.hxx"
      27             : #include "SlideSorterViewShell.hxx"
      28             : #include "controller/SlsPageSelector.hxx"
      29             : #include "controller/SlsCurrentSlideManager.hxx"
      30             : #include "controller/SlideSorterController.hxx"
      31             : #include "model/SlsPageEnumerationProvider.hxx"
      32             : #include "model/SlideSorterModel.hxx"
      33             : #include "model/SlsPageDescriptor.hxx"
      34             : 
      35             : #include <com/sun/star/drawing/framework/XPane.hpp>
      36             : #include <com/sun/star/lang/DisposedException.hpp>
      37             : #include <com/sun/star/beans/XPropertySet.hpp>
      38             : 
      39             : #include <toolkit/helper/vclunohelper.hxx>
      40             : #include <comphelper/sequence.hxx>
      41             : #include <comphelper/servicehelper.hxx>
      42             : #include <cppuhelper/typeprovider.hxx>
      43             : #include <vcl/svapp.hxx>
      44             : #include <osl/mutex.hxx>
      45             : #include <tools/diagnose_ex.h>
      46             : 
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::uno;
      49             : using namespace ::com::sun::star::drawing::framework;
      50             : 
      51             : using ::com::sun::star::awt::XWindow;
      52             : using ::com::sun::star::rendering::XCanvas;
      53             : using ::com::sun::star::lang::DisposedException;
      54             : 
      55             : namespace sd { namespace framework {
      56             : 
      57         197 : ViewShellWrapper::ViewShellWrapper (
      58             :     ::boost::shared_ptr<ViewShell> pViewShell,
      59             :     const Reference<XResourceId>& rxViewId,
      60             :     const Reference<awt::XWindow>& rxWindow)
      61             :     : ViewShellWrapperInterfaceBase(MutexOwner::maMutex),
      62             :       mpViewShell(pViewShell),
      63             :       mpSlideSorterViewShell(
      64             :           ::boost::dynamic_pointer_cast< ::sd::slidesorter::SlideSorterViewShell >( pViewShell )),
      65             :       mxViewId(rxViewId),
      66         197 :       mxWindow(rxWindow)
      67             : {
      68         197 : }
      69             : 
      70         394 : ViewShellWrapper::~ViewShellWrapper()
      71             : {
      72         394 : }
      73             : 
      74         197 : void SAL_CALL ViewShellWrapper::disposing()
      75             : {
      76         197 :     ::osl::MutexGuard aGuard( maMutex );
      77             : 
      78             :     SAL_INFO("sd.ui", "disposing ViewShellWrapper " << this);
      79         394 :     Reference<awt::XWindow> xWindow (mxWindow);
      80         197 :     if (xWindow.is())
      81             :     {
      82             :         SAL_INFO(
      83             :             "sd.ui",
      84             :             "removing ViewShellWrapper " << this << " from window listener at "
      85             :                 << mxWindow.get());
      86         133 :         xWindow->removeWindowListener(this);
      87             :     }
      88             : 
      89         197 :     mpSlideSorterViewShell.reset();
      90         394 :     mpViewShell.reset();
      91         197 : }
      92             : 
      93        7950 : uno::Any SAL_CALL ViewShellWrapper::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
      94             : {
      95        8738 :     if( mpSlideSorterViewShell &&
      96        8738 :         rType == cppu::UnoType<view::XSelectionSupplier>::get() )
      97             :     {
      98           0 :         uno::Any aAny;
      99           0 :         uno::Reference<view::XSelectionSupplier> xSupplier( this );
     100           0 :         aAny <<= xSupplier;
     101             : 
     102           0 :         return aAny;
     103             :     }
     104             :     else
     105        7950 :         return ViewShellWrapperInterfaceBase::queryInterface( rType );
     106             : }
     107             : 
     108             : //----- XResource -------------------------------------------------------------
     109             : 
     110         502 : Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId()
     111             :     throw (RuntimeException, std::exception)
     112             : {
     113         502 :     return mxViewId;
     114             : }
     115             : 
     116         599 : sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly()
     117             :     throw (RuntimeException, std::exception)
     118             : {
     119         599 :     return false;
     120             : }
     121             : 
     122             : //----- XSelectionSupplier --------------------------------------------------
     123             : 
     124           0 : sal_Bool SAL_CALL ViewShellWrapper::select( const ::com::sun::star::uno::Any& aSelection ) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     125             : {
     126           0 :     if (!mpSlideSorterViewShell)
     127           0 :         return false;
     128             : 
     129           0 :     bool bOk = true;
     130             : 
     131             :     ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController
     132           0 :         = mpSlideSorterViewShell->GetSlideSorter().GetController();
     133           0 :     ::sd::slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
     134           0 :     rSelector.DeselectAllPages();
     135           0 :     Sequence<Reference<drawing::XDrawPage> > xPages;
     136           0 :     aSelection >>= xPages;
     137           0 :     const sal_uInt32 nCount = xPages.getLength();
     138           0 :     for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
     139             :     {
     140           0 :         Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY);
     141           0 :         if (xSet.is())
     142             :         {
     143             :             try
     144             :             {
     145           0 :                 Any aNumber = xSet->getPropertyValue("Number");
     146           0 :                 sal_Int32 nPageNumber = 0;
     147           0 :                 aNumber >>= nPageNumber;
     148           0 :                 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
     149           0 :                 rSelector.SelectPage(nPageNumber);
     150             :             }
     151           0 :             catch (const RuntimeException&)
     152             :             {
     153             :             }
     154             :         }
     155           0 :     }
     156             : 
     157           0 :     return bOk;
     158             : }
     159             : 
     160           0 : uno::Any SAL_CALL ViewShellWrapper::getSelection()
     161             :     throw (uno::RuntimeException, std::exception)
     162             : {
     163           0 :     Any aResult;
     164             : 
     165           0 :     if (!mpSlideSorterViewShell)
     166           0 :         return aResult;
     167             : 
     168             :     slidesorter::model::PageEnumeration aSelectedPages (
     169             :         slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
     170           0 :             mpSlideSorterViewShell->GetSlideSorter().GetModel()));
     171             :     int nSelectedPageCount (
     172           0 :         mpSlideSorterViewShell->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
     173             : 
     174           0 :     Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
     175           0 :     int nIndex = 0;
     176           0 :     while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
     177             :     {
     178           0 :         slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
     179           0 :         aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
     180           0 :     }
     181           0 :     aResult <<= aPages;
     182             : 
     183           0 :     return aResult;
     184             : }
     185             : 
     186           0 : void SAL_CALL ViewShellWrapper::addSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
     187             : {
     188           0 : }
     189             : 
     190           0 : void SAL_CALL ViewShellWrapper::removeSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
     191             : {
     192           0 : }
     193             : 
     194             : //----- XRelocatableResource --------------------------------------------------
     195             : 
     196          68 : sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
     197             :     const Reference<XResource>& xResource)
     198             :     throw (RuntimeException, std::exception)
     199             : {
     200          68 :     bool bResult (false);
     201             : 
     202          68 :     Reference<XPane> xPane (xResource, UNO_QUERY);
     203          68 :     if (xPane.is())
     204             :     {
     205             :         // Detach from the window of the old pane.
     206          68 :         Reference<awt::XWindow> xWindow (mxWindow);
     207          68 :         if (xWindow.is())
     208          64 :             xWindow->removeWindowListener(this);
     209          68 :         mxWindow = NULL;
     210             : 
     211          68 :         if (mpViewShell.get() != NULL)
     212             :         {
     213          68 :             vcl::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
     214          68 :             if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
     215             :             {
     216          68 :                 bResult = true;
     217             : 
     218             :                 // Attach to the window of the new pane.
     219          68 :                 xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
     220          68 :                 if (xWindow.is())
     221             :                 {
     222          68 :                     xWindow->addWindowListener(this);
     223          68 :                     mpViewShell->Resize();
     224             :                 }
     225             :             }
     226          68 :         }
     227             :     }
     228             : 
     229          68 :     return bResult;
     230             : }
     231             : 
     232             : //----- XUnoTunnel ------------------------------------------------------------
     233             : 
     234             : namespace
     235             : {
     236             :     class theViewShellWrapperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewShellWrapperUnoTunnelId> {};
     237             : }
     238             : 
     239       11862 : const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId()
     240             : {
     241       11862 :     return theViewShellWrapperUnoTunnelId::get().getSeq();
     242             : }
     243             : 
     244        5931 : sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
     245             :     throw (RuntimeException, std::exception)
     246             : {
     247        5931 :     sal_Int64 nResult = 0;
     248             : 
     249       11862 :     if (rId.getLength() == 16
     250        5931 :         && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
     251             :     {
     252        5931 :         nResult = reinterpret_cast<sal_Int64>(this);
     253             :     }
     254             : 
     255        5931 :     return nResult;
     256             : }
     257             : 
     258             : //===== awt::XWindowListener ==================================================
     259             : 
     260         357 : void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
     261             :     throw (RuntimeException, std::exception)
     262             : {
     263             :     (void)rEvent;
     264         357 :     ViewShell* pViewShell (mpViewShell.get());
     265         357 :     if (pViewShell != NULL)
     266         357 :         pViewShell->Resize();
     267         357 : }
     268             : 
     269         389 : void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
     270             :     throw (RuntimeException, std::exception)
     271             : {
     272             :     (void)rEvent;
     273         389 : }
     274             : 
     275         168 : void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
     276             :     throw (RuntimeException, std::exception)
     277             : {
     278             :     (void)rEvent;
     279         168 :     ViewShell* pViewShell (mpViewShell.get());
     280         168 :     if (pViewShell != NULL)
     281         168 :         pViewShell->Resize();
     282         168 : }
     283             : 
     284           9 : void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
     285             :     throw (RuntimeException, std::exception)
     286             : {
     287             :     (void)rEvent;
     288           9 : }
     289             : 
     290             : //===== XEventListener ========================================================
     291             : 
     292          68 : void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
     293             :     throw (RuntimeException, std::exception)
     294             : {
     295          68 :     if (rEvent.Source == mxWindow)
     296           0 :         mxWindow = NULL;
     297          68 : }
     298             : 
     299          66 : } } // end of namespace sd::framework
     300             : 
     301             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11