LCOV - code coverage report
Current view: top level - framework/source/classes - framecontainer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 64 71 90.1 %
Date: 2015-06-13 12:38:46 Functions: 13 14 92.9 %
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 <classes/framecontainer.hxx>
      21             : 
      22             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      23             : 
      24             : #include <vcl/svapp.hxx>
      25             : 
      26             : namespace framework{
      27             : 
      28             : /**-***************************************************************************************************************
      29             :     @short      initialize an empty container
      30             :     @descr      The container will be empty then - special features (e.g. the async quit mechanism) are disabled.
      31             : 
      32             :     @threadsafe not necessary - its not a singleton
      33             :  *****************************************************************************************************************/
      34        3494 : FrameContainer::FrameContainer()
      35             : /*DEPRECATEME
      36             :         , m_bAsyncQuit   ( sal_False                                      ) // default must be "disabled"!
      37             :         , m_aAsyncCall   ( LINK( this, FrameContainer, implts_asyncQuit ) )
      38             : */
      39             : {
      40        3494 : }
      41             : 
      42             : /**-***************************************************************************************************************
      43             :     @short      deinitialize may a filled container
      44             :     @descr      Special features (if the currently are running) will be dsiabled and we free all used other resources.
      45             : 
      46             :     @threadsafe not necessary - its not a singleton
      47             :  *****************************************************************************************************************/
      48        5798 : FrameContainer::~FrameContainer()
      49             : {
      50             :     // Don't forget to free memory!
      51        2899 :     m_aContainer.clear();
      52        2899 :     m_xActiveFrame.clear();
      53        2899 : }
      54             : 
      55             : /**-***************************************************************************************************************
      56             :     @short      append a new frame to the container
      57             :     @descr      We accept the incoming frame only, if it is a valid reference and dosnt exist already.
      58             : 
      59             :     @param      xFrame
      60             :                     frame, which should be added to this container
      61             :                     Must be a valid reference.
      62             : 
      63             :     @threadsafe yes
      64             :  *****************************************************************************************************************/
      65        3282 : void FrameContainer::append( const css::uno::Reference< css::frame::XFrame >& xFrame )
      66             : {
      67        3282 :     if (xFrame.is() && ! exist(xFrame))
      68             :     {
      69        3282 :         SolarMutexGuard g;
      70        3282 :         m_aContainer.push_back( xFrame );
      71             :     }
      72        3282 : }
      73             : 
      74             : /**-***************************************************************************************************************
      75             :     @short      remove a frame from the container
      76             :     @descr      In case we remove the last frame and our internal special feature (the async quit mechanism)
      77             :                 was enabled by the desktop instance, we start it.
      78             : 
      79             :     @param      xFrame
      80             :                     frame, which should be deleted from this container
      81             :                     Must be a valid reference.
      82             : 
      83             :     @threadsafe yes
      84             :  *****************************************************************************************************************/
      85        3273 : void FrameContainer::remove( const css::uno::Reference< css::frame::XFrame >& xFrame )
      86             : {
      87        3273 :     SolarMutexGuard g;
      88             : 
      89        3273 :     TFrameIterator aSearchedItem = ::std::find( m_aContainer.begin(), m_aContainer.end(), xFrame );
      90        3273 :     if (aSearchedItem!=m_aContainer.end())
      91             :     {
      92        3273 :         m_aContainer.erase( aSearchedItem );
      93             : 
      94             :         // If removed frame was the current active frame - reset state variable.
      95        3273 :         if (m_xActiveFrame==xFrame)
      96        2858 :             m_xActiveFrame = css::uno::Reference< css::frame::XFrame >();
      97        3273 :     }
      98        3273 : }
      99             : 
     100             : /**-***************************************************************************************************************
     101             :     @short      check if the given frame currently exist inside the container
     102             :     @param      xFrame
     103             :                     reference to the queried frame
     104             : 
     105             :     @return     <TRUE/> if frame is oart of this container
     106             :                 <FALSE/> otherwise
     107             : 
     108             :     @threadsafe yes
     109             :  *****************************************************************************************************************/
     110        6166 : bool FrameContainer::exist( const css::uno::Reference< css::frame::XFrame >& xFrame ) const
     111             : {
     112        6166 :     SolarMutexGuard g;
     113        6166 :     return( ::std::find( m_aContainer.begin(), m_aContainer.end(), xFrame ) != m_aContainer.end() );
     114             : }
     115             : 
     116             : /**-***************************************************************************************************************
     117             :     @short      delete all existing items of the container
     118             :     @threadsafe yes
     119             :  *****************************************************************************************************************/
     120        3483 : void FrameContainer::clear()
     121             : {
     122        3483 :     SolarMutexGuard g;
     123             :     // Clear the container ...
     124        3483 :     m_aContainer.clear();
     125             :     // ... and don't forget to reset the active frame.
     126             :     // Its an reference to a valid container-item.
     127             :     // But no container item => no active frame!
     128        3483 :     m_xActiveFrame = css::uno::Reference< css::frame::XFrame >();
     129        3483 : }
     130             : 
     131             : /**-***************************************************************************************************************
     132             :     @short      returns count of all current existing frames
     133             :     @deprecated This value can't be guaranteed for multithreading environments.
     134             :                 So it will be marked as deprecated and should be replaced by "getAllElements()".
     135             : 
     136             :     @return     the count of existing container items
     137             : 
     138             :     @threadsafe yes
     139             :  *****************************************************************************************************************/
     140       43923 : sal_uInt32 FrameContainer::getCount() const
     141             : {
     142       43923 :     SolarMutexGuard g;
     143       43923 :     return( (sal_uInt32)m_aContainer.size() );
     144             : }
     145             : 
     146             : /**-***************************************************************************************************************
     147             :     @short      returns one item of this container
     148             :     @deprecated This value can't be guaranteed for multithreading environments.
     149             :                 So it will be marked as deprecatedf and should be replaced by "getAllElements()".
     150             : 
     151             :     @param      nIndex
     152             :                     a valud between 0 and (getCount()-1) to address one container item
     153             : 
     154             :     @return     a reference to a frame inside the container, which match with given index
     155             : 
     156             :     @threadsafe yes
     157             :  *****************************************************************************************************************/
     158       19429 : css::uno::Reference< css::frame::XFrame > FrameContainer::operator[]( sal_uInt32 nIndex ) const
     159             : {
     160             : 
     161       19429 :     css::uno::Reference< css::frame::XFrame > xFrame;
     162             :     try
     163             :     {
     164             :         // Get element form container WITH automatic test of ranges!
     165             :         // If index not valid, a out_of_range exception is thrown.
     166       19429 :         SolarMutexGuard g;
     167       19429 :         xFrame = m_aContainer.at( nIndex );
     168             :     }
     169           0 :     catch( const std::out_of_range& )
     170             :     {
     171             :         // The index is not valid for current container-content - we must handle this case!
     172             :         // We can return the default value ...
     173             :         SAL_INFO( "fwk", "FrameContainer::operator[]: Exception caught: std::out_of_range" );
     174             :     }
     175       19429 :     return xFrame;
     176             : }
     177             : 
     178             : /**-***************************************************************************************************************
     179             :     @short      returns a snapshot of all currently existing frames inside this container
     180             :     @descr      Should be used to replace the deprecated functions getCount()/operator[]!
     181             : 
     182             :     @return     a list of all frame references inside this container
     183             : 
     184             :     @threadsafe yes
     185             :  *****************************************************************************************************************/
     186         119 : css::uno::Sequence< css::uno::Reference< css::frame::XFrame > > FrameContainer::getAllElements() const
     187             : {
     188         119 :     SolarMutexGuard g;
     189         119 :     sal_Int32                                                       nPosition = 0;
     190         119 :     css::uno::Sequence< css::uno::Reference< css::frame::XFrame > > lElements ( (sal_uInt32)m_aContainer.size() );
     191         123 :     for (TConstFrameIterator pItem=m_aContainer.begin(); pItem!=m_aContainer.end(); ++pItem)
     192           4 :         lElements[nPosition++] = *pItem;
     193         119 :     return lElements;
     194             : }
     195             : 
     196             : /**-***************************************************************************************************************
     197             :     @short      set the given frame as  the new active one inside this container
     198             :     @descr      We accept this frame only, if it's already a part of this container.
     199             : 
     200             :     @param      xFrame
     201             :                     reference to the new active frame
     202             :                     Must be a valid reference and already part of this container.
     203             : 
     204             :     @threadsafe yes
     205             :  *****************************************************************************************************************/
     206        2885 : void FrameContainer::setActive( const css::uno::Reference< css::frame::XFrame >& xFrame )
     207             : {
     208        2885 :     if ( !xFrame.is() || exist(xFrame) )
     209             :     {
     210        2885 :         SolarMutexGuard g;
     211        2885 :         m_xActiveFrame = xFrame;
     212             :     }
     213        2885 : }
     214             : 
     215             : /**-***************************************************************************************************************
     216             :     @short      return sthe current active frame of this container
     217             :     @descr      Value can be null in case the frame was removed from the container and nobody
     218             :                 from outside decide which of all others should be the new one ...
     219             : 
     220             :     @return     a reference to the current active frame
     221             :                 Value can be NULL!
     222             : 
     223             :     @threadsafe yes
     224             :  *****************************************************************************************************************/
     225       22088 : css::uno::Reference< css::frame::XFrame > FrameContainer::getActive() const
     226             : {
     227       22088 :     SolarMutexGuard g;
     228       22088 :     return m_xActiveFrame;
     229             : }
     230             : 
     231             : /**-***************************************************************************************************************
     232             :     @short      implements a simple search based on current container items
     233             :     @descr      It can be used for findFrame() and implements a deep down search.
     234             : 
     235             :     @param      sName
     236             :                     target name, which is searched
     237             : 
     238             :     @return     reference to the found frame or NULL if not.
     239             : 
     240             :     @threadsafe yes
     241             :  *****************************************************************************************************************/
     242           4 : css::uno::Reference< css::frame::XFrame > FrameContainer::searchOnAllChildrens( const OUString& sName ) const
     243             : {
     244           4 :     SolarMutexGuard g;
     245             :     // Step over all child frames. But if direct child isn't the right one search on his children first - before
     246             :     // you go to next direct child of this container!
     247           4 :     css::uno::Reference< css::frame::XFrame > xSearchedFrame;
     248           4 :     for( TConstFrameIterator pIterator=m_aContainer.begin(); pIterator!=m_aContainer.end(); ++pIterator )
     249             :     {
     250           0 :         if ((*pIterator)->getName()==sName)
     251             :         {
     252           0 :             xSearchedFrame = *pIterator;
     253           0 :             break;
     254             :         }
     255             :         else
     256             :         {
     257           0 :             xSearchedFrame = (*pIterator)->findFrame( sName, css::frame::FrameSearchFlag::CHILDREN );
     258           0 :             if (xSearchedFrame.is())
     259           0 :                 break;
     260             :         }
     261             :     }
     262           4 :     return xSearchedFrame;
     263             : }
     264             : 
     265             : /**-***************************************************************************************************************
     266             :     @short      implements a simple search based on current container items
     267             :     @descr      It can be used for findFrame() and search on members of this container only!
     268             : 
     269             :     @param      sName
     270             :                     target name, which is searched
     271             : 
     272             :     @return     reference to the found frame or NULL if not.
     273             : 
     274             :     @threadsafe yes
     275             :  *****************************************************************************************************************/
     276        2772 : css::uno::Reference< css::frame::XFrame > FrameContainer::searchOnDirectChildrens( const OUString& sName ) const
     277             : {
     278        2772 :     SolarMutexGuard g;
     279        2772 :     css::uno::Reference< css::frame::XFrame > xSearchedFrame;
     280        2772 :     for( TConstFrameIterator pIterator=m_aContainer.begin(); pIterator!=m_aContainer.end(); ++pIterator )
     281             :     {
     282           5 :         if ((*pIterator)->getName()==sName)
     283             :         {
     284           5 :             xSearchedFrame = *pIterator;
     285           5 :             break;
     286             :         }
     287             :     }
     288        2772 :     return xSearchedFrame;
     289             : }
     290             : 
     291             : } //  namespace framework
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11