LCOV - code coverage report
Current view: top level - framework/source/helper - ocomponentaccess.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 38 51 74.5 %
Date: 2015-06-13 12:38:46 Functions: 6 9 66.7 %
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 <helper/ocomponentaccess.hxx>
      21             : #include <helper/ocomponentenumeration.hxx>
      22             : 
      23             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      24             : 
      25             : #include <vcl/svapp.hxx>
      26             : 
      27             : namespace framework{
      28             : 
      29             : using namespace ::com::sun::star::container;
      30             : using namespace ::com::sun::star::frame;
      31             : using namespace ::com::sun::star::lang;
      32             : using namespace ::com::sun::star::uno;
      33             : using namespace ::cppu;
      34             : using namespace ::osl;
      35             : 
      36             : //  constructor
      37             : 
      38          89 : OComponentAccess::OComponentAccess( const css::uno::Reference< XDesktop >& xOwner )
      39          89 :         :   m_xOwner        ( xOwner                        )
      40             : {
      41             :     // Safe impossible cases
      42             :     SAL_WARN_IF( !impldbg_checkParameter_OComponentAccessCtor( xOwner ), "fwk", "OComponentAccess::OComponentAccess(): Invalid parameter detected!" );
      43          89 : }
      44             : 
      45             : //  destructor
      46             : 
      47         178 : OComponentAccess::~OComponentAccess()
      48             : {
      49         178 : }
      50             : 
      51             : //  XEnumerationAccess
      52          89 : css::uno::Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() throw( RuntimeException, std::exception )
      53             : {
      54          89 :     SolarMutexGuard g;
      55             : 
      56             :     // Set default return value, if method failed.
      57             :     // If no desktop exist and there is no task container - return an empty enumeration!
      58          89 :     css::uno::Reference< XEnumeration > xReturn = css::uno::Reference< XEnumeration >();
      59             : 
      60             :     // Try to "lock" the desktop for access to task container.
      61         178 :     css::uno::Reference< XInterface > xLock = m_xOwner.get();
      62          89 :     if ( xLock.is() )
      63             :     {
      64             :         // Desktop exist => pointer to task container must be valid.
      65             :         // Initialize a new enumeration ... if some tasks and his components exist!
      66             :         // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!)
      67             : 
      68          89 :         Sequence< css::uno::Reference< XComponent > > seqComponents;
      69          89 :         impl_collectAllChildComponents( css::uno::Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents );
      70          89 :         OComponentEnumeration* pEnumeration = new OComponentEnumeration( seqComponents );
      71          89 :         xReturn = css::uno::Reference< XEnumeration >( static_cast<OWeakObject*>(pEnumeration), UNO_QUERY );
      72             :     }
      73             : 
      74             :     // Return result of this operation.
      75         178 :     return xReturn;
      76             : }
      77             : 
      78             : //  XElementAccess
      79           0 : Type SAL_CALL OComponentAccess::getElementType() throw( RuntimeException, std::exception )
      80             : {
      81             :     // Elements in list an enumeration are components!
      82             :     // Return the uno-type of XComponent.
      83           0 :     return cppu::UnoType<XComponent>::get();
      84             : }
      85             : 
      86             : //  XElementAccess
      87           0 : sal_Bool SAL_CALL OComponentAccess::hasElements() throw( RuntimeException, std::exception )
      88             : {
      89           0 :     SolarMutexGuard g;
      90             : 
      91             :     // Set default return value, if method failed.
      92           0 :     bool bReturn = false;
      93             : 
      94             :     // Try to "lock" the desktop for access to task container.
      95           0 :     css::uno::Reference< XFramesSupplier > xLock( m_xOwner.get(), UNO_QUERY );
      96           0 :     if ( xLock.is() )
      97             :     {
      98             :         // Ask container of owner for existing elements.
      99           0 :         bReturn = xLock->getFrames()->hasElements();
     100             :     }
     101             : 
     102             :     // Return result of this operation.
     103           0 :     return bReturn;
     104             : }
     105             : 
     106             : 
     107          89 : void OComponentAccess::impl_collectAllChildComponents(  const   css::uno::Reference< XFramesSupplier >&         xNode           ,
     108             :                                                                  Sequence< css::uno::Reference< XComponent > >& seqComponents   )
     109             : {
     110             :     // If valid node was given ...
     111          89 :     if( xNode.is() )
     112             :     {
     113             :         // ... continue collection at these.
     114             : 
     115             :         // Get the container of current node, collect the components of existing child frames
     116             :         // and go down to next level in tree (recursive!).
     117             : 
     118          89 :         sal_Int32 nComponentCount = seqComponents.getLength();
     119             : 
     120          89 :         const css::uno::Reference< XFrames >                xContainer  = xNode->getFrames();
     121         178 :         const Sequence< css::uno::Reference< XFrame > > seqFrames   = xContainer->queryFrames( FrameSearchFlag::CHILDREN );
     122             : 
     123          89 :         const sal_Int32 nFrameCount = seqFrames.getLength();
     124         182 :         for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame )
     125             :         {
     126          93 :             css::uno::Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] );
     127          93 :             if( xComponent.is() )
     128             :             {
     129          93 :                 nComponentCount++;
     130          93 :                 seqComponents.realloc( nComponentCount );
     131          93 :                 seqComponents[nComponentCount-1] = xComponent;
     132             :             }
     133         182 :         }
     134             :     }
     135             :     // ... otherwise break a recursive path and go back at current stack!
     136          89 : }
     137             : 
     138          93 : css::uno::Reference< XComponent > OComponentAccess::impl_getFrameComponent( const css::uno::Reference< XFrame >& xFrame ) const
     139             : {
     140             :     // Set default return value, if method failed.
     141          93 :     css::uno::Reference< XComponent > xComponent = css::uno::Reference< XComponent >();
     142             :     // Does no controller exists?
     143         186 :     css::uno::Reference< XController > xController = xFrame->getController();
     144          93 :     if ( !xController.is() )
     145             :     {
     146             :         // Controller not exist - use the VCL-component.
     147           0 :         xComponent = css::uno::Reference< XComponent >( xFrame->getComponentWindow(), UNO_QUERY );
     148             :     }
     149             :     else
     150             :     {
     151             :         // Does no model exists?
     152          93 :         css::uno::Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
     153          93 :         if ( xModel.is() )
     154             :         {
     155             :             // Model exist - use the model as component.
     156          93 :             xComponent = css::uno::Reference< XComponent >( xModel, UNO_QUERY );
     157             :         }
     158             :         else
     159             :         {
     160             :             // Model not exist - use the controller as component.
     161           0 :             xComponent = css::uno::Reference< XComponent >( xController, UNO_QUERY );
     162          93 :         }
     163             :     }
     164             : 
     165         186 :     return xComponent;
     166             : }
     167             : 
     168             : //  debug methods
     169             : 
     170             : /*-----------------------------------------------------------------------------------------------------------------
     171             :     The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
     172             :     we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!
     173             : 
     174             :     ATTENTION
     175             : 
     176             :         If you miss a test for one of this parameters, contact the author or add it himself !(?)
     177             :         But ... look for right testing! See using of this methods!
     178             : -----------------------------------------------------------------------------------------------------------------*/
     179             : 
     180           0 : bool OComponentAccess::impldbg_checkParameter_OComponentAccessCtor( const   css::uno::Reference< XDesktop >&      xOwner  )
     181             : {
     182           0 :     return xOwner.is();
     183             : }
     184             : 
     185             : }       //  namespace framework
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11