LCOV - code coverage report
Current view: top level - framework/source/classes - framecontainer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 71 0.0 %
Date: 2014-04-14 Functions: 0 14 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             : #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           0 : FrameContainer::FrameContainer()
      35             : /*DEPRECATEME
      36             :         , m_bAsyncQuit   ( sal_False                                      ) // default must be "disabled"!
      37             :         , m_aAsyncCall   ( LINK( this, FrameContainer, implts_asyncQuit ) )
      38             : */
      39             : {
      40           0 : }
      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           0 : FrameContainer::~FrameContainer()
      49             : {
      50             :     // Don't forget to free memory!
      51           0 :     m_aContainer.clear();
      52           0 :     m_xActiveFrame.clear();
      53           0 : }
      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           0 : void FrameContainer::append( const css::uno::Reference< css::frame::XFrame >& xFrame )
      66             : {
      67           0 :     if (xFrame.is() && ! exist(xFrame))
      68             :     {
      69           0 :         SolarMutexGuard g;
      70           0 :         m_aContainer.push_back( xFrame );
      71             :     }
      72           0 : }
      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           0 : void FrameContainer::remove( const css::uno::Reference< css::frame::XFrame >& xFrame )
      86             : {
      87           0 :     SolarMutexGuard g;
      88             : 
      89           0 :     TFrameIterator aSearchedItem = ::std::find( m_aContainer.begin(), m_aContainer.end(), xFrame );
      90           0 :     if (aSearchedItem!=m_aContainer.end())
      91             :     {
      92           0 :         m_aContainer.erase( aSearchedItem );
      93             : 
      94             :         // If removed frame was the current active frame - reset state variable.
      95           0 :         if (m_xActiveFrame==xFrame)
      96           0 :             m_xActiveFrame = css::uno::Reference< css::frame::XFrame >();
      97           0 :     }
      98           0 : }
      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           0 : bool FrameContainer::exist( const css::uno::Reference< css::frame::XFrame >& xFrame ) const
     111             : {
     112           0 :     SolarMutexGuard g;
     113           0 :     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           0 : void FrameContainer::clear()
     121             : {
     122           0 :     SolarMutexGuard g;
     123             :     // Clear the container ...
     124           0 :     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           0 :     m_xActiveFrame = css::uno::Reference< css::frame::XFrame >();
     129           0 : }
     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           0 : sal_uInt32 FrameContainer::getCount() const
     141             : {
     142           0 :     SolarMutexGuard g;
     143           0 :     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           0 : css::uno::Reference< css::frame::XFrame > FrameContainer::operator[]( sal_uInt32 nIndex ) const
     159             : {
     160             : 
     161           0 :     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           0 :         SolarMutexGuard g;
     167           0 :         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           0 :     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 refrences inside this container
     183             : 
     184             :     @threadsafe yes
     185             :  *****************************************************************************************************************/
     186           0 : css::uno::Sequence< css::uno::Reference< css::frame::XFrame > > FrameContainer::getAllElements() const
     187             : {
     188           0 :     SolarMutexGuard g;
     189           0 :     sal_Int32                                                       nPosition = 0;
     190           0 :     css::uno::Sequence< css::uno::Reference< css::frame::XFrame > > lElements ( (sal_uInt32)m_aContainer.size() );
     191           0 :     for (TConstFrameIterator pItem=m_aContainer.begin(); pItem!=m_aContainer.end(); ++pItem)
     192           0 :         lElements[nPosition++] = *pItem;
     193           0 :     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           0 : void FrameContainer::setActive( const css::uno::Reference< css::frame::XFrame >& xFrame )
     207             : {
     208           0 :     if ( !xFrame.is() || exist(xFrame) )
     209             :     {
     210           0 :         SolarMutexGuard g;
     211           0 :         m_xActiveFrame = xFrame;
     212             :     }
     213           0 : }
     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           0 : css::uno::Reference< css::frame::XFrame > FrameContainer::getActive() const
     226             : {
     227           0 :     SolarMutexGuard g;
     228           0 :     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           0 : css::uno::Reference< css::frame::XFrame > FrameContainer::searchOnAllChildrens( const OUString& sName ) const
     243             : {
     244           0 :     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           0 :     css::uno::Reference< css::frame::XFrame > xSearchedFrame;
     248           0 :     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           0 :     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           0 : css::uno::Reference< css::frame::XFrame > FrameContainer::searchOnDirectChildrens( const OUString& sName ) const
     277             : {
     278           0 :     SolarMutexGuard g;
     279           0 :     css::uno::Reference< css::frame::XFrame > xSearchedFrame;
     280           0 :     for( TConstFrameIterator pIterator=m_aContainer.begin(); pIterator!=m_aContainer.end(); ++pIterator )
     281             :     {
     282           0 :         if ((*pIterator)->getName()==sName)
     283             :         {
     284           0 :             xSearchedFrame = *pIterator;
     285           0 :             break;
     286             :         }
     287             :     }
     288           0 :     return xSearchedFrame;
     289             : }
     290             : 
     291             : } //  namespace framework
     292             : 
     293             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10