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

Generated by: LCOV version 1.10