LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - ViewShellWrapper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 63 109 57.8 %
Date: 2014-11-03 Functions: 16 21 76.2 %
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         338 : 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         338 :       mxWindow(rxWindow)
      67             : {
      68         338 : }
      69             : 
      70         676 : ViewShellWrapper::~ViewShellWrapper (void)
      71             : {
      72         676 : }
      73             : 
      74         338 : void SAL_CALL ViewShellWrapper::disposing (void)
      75             : {
      76         338 :     ::osl::MutexGuard aGuard( maMutex );
      77             : 
      78             :     OSL_TRACE("disposing ViewShellWrapper %x", this);
      79         676 :     Reference<awt::XWindow> xWindow (mxWindow);
      80         338 :     if (xWindow.is())
      81             :     {
      82             :         OSL_TRACE("removing ViewShellWrapper %x from window listener at %x", this, mxWindow.get());
      83         212 :         xWindow->removeWindowListener(this);
      84             :     }
      85             : 
      86         338 :     mpSlideSorterViewShell.reset();
      87         676 :     mpViewShell.reset();
      88         338 : }
      89             : 
      90       12548 : uno::Any SAL_CALL ViewShellWrapper::queryInterface( const uno::Type & rType ) throw(uno::RuntimeException, std::exception)
      91             : {
      92       14060 :     if( mpSlideSorterViewShell &&
      93       14060 :         rType == cppu::UnoType<view::XSelectionSupplier>::get() )
      94             :     {
      95           0 :         uno::Any aAny;
      96           0 :         uno::Reference<view::XSelectionSupplier> xSupplier( this );
      97           0 :         aAny <<= xSupplier;
      98             : 
      99           0 :         return aAny;
     100             :     }
     101             :     else
     102       12548 :         return ViewShellWrapperInterfaceBase::queryInterface( rType );
     103             : }
     104             : 
     105             : //----- XResource -------------------------------------------------------------
     106             : 
     107         772 : Reference<XResourceId> SAL_CALL ViewShellWrapper::getResourceId (void)
     108             :     throw (RuntimeException, std::exception)
     109             : {
     110         772 :     return mxViewId;
     111             : }
     112             : 
     113         974 : sal_Bool SAL_CALL ViewShellWrapper::isAnchorOnly (void)
     114             :     throw (RuntimeException, std::exception)
     115             : {
     116         974 :     return false;
     117             : }
     118             : 
     119             : //----- XSelectionSupplier --------------------------------------------------
     120             : 
     121           0 : sal_Bool SAL_CALL ViewShellWrapper::select( const ::com::sun::star::uno::Any& aSelection ) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
     122             : {
     123           0 :     if (!mpSlideSorterViewShell)
     124           0 :         return false;
     125             : 
     126           0 :     bool bOk = true;
     127             : 
     128             :     ::sd::slidesorter::controller::SlideSorterController& rSlideSorterController
     129           0 :         = mpSlideSorterViewShell->GetSlideSorter().GetController();
     130           0 :     ::sd::slidesorter::controller::PageSelector& rSelector (rSlideSorterController.GetPageSelector());
     131           0 :     rSelector.DeselectAllPages();
     132           0 :     Sequence<Reference<drawing::XDrawPage> > xPages;
     133           0 :     aSelection >>= xPages;
     134           0 :     const sal_uInt32 nCount = xPages.getLength();
     135           0 :     for (sal_uInt32 nIndex=0; nIndex<nCount; ++nIndex)
     136             :     {
     137           0 :         Reference<beans::XPropertySet> xSet (xPages[nIndex], UNO_QUERY);
     138           0 :         if (xSet.is())
     139             :         {
     140             :             try
     141             :             {
     142           0 :                 Any aNumber = xSet->getPropertyValue("Number");
     143           0 :                 sal_Int32 nPageNumber = 0;
     144           0 :                 aNumber >>= nPageNumber;
     145           0 :                 nPageNumber -=1; // Transform 1-based page numbers to 0-based ones.
     146           0 :                 rSelector.SelectPage(nPageNumber);
     147             :             }
     148           0 :             catch (const RuntimeException&)
     149             :             {
     150             :             }
     151             :         }
     152           0 :     }
     153             : 
     154           0 :     return bOk;
     155             : }
     156             : 
     157           0 : uno::Any SAL_CALL ViewShellWrapper::getSelection()
     158             :     throw (uno::RuntimeException, std::exception)
     159             : {
     160           0 :     Any aResult;
     161             : 
     162           0 :     if (!mpSlideSorterViewShell)
     163           0 :         return aResult;
     164             : 
     165             :     slidesorter::model::PageEnumeration aSelectedPages (
     166             :         slidesorter::model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
     167           0 :             mpSlideSorterViewShell->GetSlideSorter().GetModel()));
     168             :     int nSelectedPageCount (
     169           0 :         mpSlideSorterViewShell->GetSlideSorter().GetController().GetPageSelector().GetSelectedPageCount());
     170             : 
     171           0 :     Sequence<Reference<XInterface> > aPages(nSelectedPageCount);
     172           0 :     int nIndex = 0;
     173           0 :     while (aSelectedPages.HasMoreElements() && nIndex<nSelectedPageCount)
     174             :     {
     175           0 :         slidesorter::model::SharedPageDescriptor pDescriptor (aSelectedPages.GetNextElement());
     176           0 :         aPages[nIndex++] = pDescriptor->GetPage()->getUnoPage();
     177           0 :     }
     178           0 :     aResult <<= aPages;
     179             : 
     180           0 :     return aResult;
     181             : }
     182             : 
     183           0 : void SAL_CALL ViewShellWrapper::addSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
     184             : {
     185           0 : }
     186             : 
     187           0 : void SAL_CALL ViewShellWrapper::removeSelectionChangeListener( const uno::Reference< view::XSelectionChangeListener >& ) throw(uno::RuntimeException, std::exception)
     188             : {
     189           0 : }
     190             : 
     191             : //----- XRelocatableResource --------------------------------------------------
     192             : 
     193         126 : sal_Bool SAL_CALL ViewShellWrapper::relocateToAnchor (
     194             :     const Reference<XResource>& xResource)
     195             :     throw (RuntimeException, std::exception)
     196             : {
     197         126 :     bool bResult (false);
     198             : 
     199         126 :     Reference<XPane> xPane (xResource, UNO_QUERY);
     200         126 :     if (xPane.is())
     201             :     {
     202             :         // Detach from the window of the old pane.
     203         126 :         Reference<awt::XWindow> xWindow (mxWindow);
     204         126 :         if (xWindow.is())
     205         126 :             xWindow->removeWindowListener(this);
     206         126 :         mxWindow = NULL;
     207             : 
     208         126 :         if (mpViewShell.get() != NULL)
     209             :         {
     210         126 :             ::vcl::Window* pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
     211         126 :             if (pWindow != NULL && mpViewShell->RelocateToParentWindow(pWindow))
     212             :             {
     213         126 :                 bResult = true;
     214             : 
     215             :                 // Attach to the window of the new pane.
     216         126 :                 xWindow = Reference<awt::XWindow>(xPane->getWindow(), UNO_QUERY);
     217         126 :                 if (xWindow.is())
     218             :                 {
     219         126 :                     xWindow->addWindowListener(this);
     220         126 :                     mpViewShell->Resize();
     221             :                 }
     222             :             }
     223         126 :         }
     224             :     }
     225             : 
     226         126 :     return bResult;
     227             : }
     228             : 
     229             : //----- XUnoTunnel ------------------------------------------------------------
     230             : 
     231             : namespace
     232             : {
     233             :     class theViewShellWrapperUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theViewShellWrapperUnoTunnelId> {};
     234             : }
     235             : 
     236       18236 : const Sequence<sal_Int8>& ViewShellWrapper::getUnoTunnelId (void)
     237             : {
     238       18236 :     return theViewShellWrapperUnoTunnelId::get().getSeq();
     239             : }
     240             : 
     241        9118 : sal_Int64 SAL_CALL ViewShellWrapper::getSomething (const Sequence<sal_Int8>& rId)
     242             :     throw (RuntimeException, std::exception)
     243             : {
     244        9118 :     sal_Int64 nResult = 0;
     245             : 
     246       18236 :     if (rId.getLength() == 16
     247        9118 :         && memcmp(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0)
     248             :     {
     249        9118 :         nResult = reinterpret_cast<sal_Int64>(this);
     250             :     }
     251             : 
     252        9118 :     return nResult;
     253             : }
     254             : 
     255             : //===== awt::XWindowListener ==================================================
     256             : 
     257         644 : void SAL_CALL ViewShellWrapper::windowResized (const awt::WindowEvent& rEvent)
     258             :     throw (RuntimeException, std::exception)
     259             : {
     260             :     (void)rEvent;
     261         644 :     ViewShell* pViewShell (mpViewShell.get());
     262         644 :     if (pViewShell != NULL)
     263         644 :         pViewShell->Resize();
     264         644 : }
     265             : 
     266         724 : void SAL_CALL ViewShellWrapper::windowMoved (const awt::WindowEvent& rEvent)
     267             :     throw (RuntimeException, std::exception)
     268             : {
     269             :     (void)rEvent;
     270         724 : }
     271             : 
     272         253 : void SAL_CALL ViewShellWrapper::windowShown (const lang::EventObject& rEvent)
     273             :     throw (RuntimeException, std::exception)
     274             : {
     275             :     (void)rEvent;
     276         253 :     ViewShell* pViewShell (mpViewShell.get());
     277         253 :     if (pViewShell != NULL)
     278         253 :         pViewShell->Resize();
     279         253 : }
     280             : 
     281           0 : void SAL_CALL ViewShellWrapper::windowHidden (const lang::EventObject& rEvent)
     282             :     throw (RuntimeException, std::exception)
     283             : {
     284             :     (void)rEvent;
     285           0 : }
     286             : 
     287             : //===== XEventListener ========================================================
     288             : 
     289         126 : void SAL_CALL ViewShellWrapper::disposing (const lang::EventObject& rEvent)
     290             :     throw (RuntimeException, std::exception)
     291             : {
     292         126 :     if (rEvent.Source == mxWindow)
     293           0 :         mxWindow = NULL;
     294         126 : }
     295             : 
     296         114 : } } // end of namespace sd::framework
     297             : 
     298             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10