LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/docvw - frmsidebarwincontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 76 53.9 %
Date: 2012-12-17 Functions: 10 15 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             : 
      21             : #include <frmsidebarwincontainer.hxx>
      22             : 
      23             : #include <map>
      24             : #include <fmtfld.hxx>
      25             : #include <txtfld.hxx>
      26             : #include <SidebarWin.hxx>
      27             : 
      28             : namespace {
      29             :     struct SidebarWinKey
      30             :     {
      31             :         const xub_StrLen mnIndex;
      32             : 
      33          12 :         explicit SidebarWinKey( const xub_StrLen nIndex )
      34          12 :             : mnIndex( nIndex )
      35          12 :         {}
      36             : 
      37           0 :         bool operator < ( const SidebarWinKey& rSidebarWinKey ) const
      38             :         {
      39           0 :             return mnIndex < rSidebarWinKey.mnIndex;
      40             :         }
      41             :     };
      42             : 
      43             :     struct SidebarWinOrder
      44             :     {
      45           0 :         sal_Bool operator()( const SidebarWinKey& rSidebarWinKeyA,
      46             :                              const SidebarWinKey& rSidebarWinKeyB ) const
      47             :         {
      48           0 :             return rSidebarWinKeyA < rSidebarWinKeyB;
      49             :         }
      50             :     };
      51             : 
      52             :     typedef ::std::map < SidebarWinKey, sw::sidebarwindows::SwSidebarWin*, SidebarWinOrder > SidebarWinContainer;
      53             : 
      54             :     struct FrmKey
      55             :     {
      56             :         const SwFrm* mpFrm;
      57             : 
      58          16 :         explicit FrmKey( const SwFrm* pFrm )
      59          16 :             : mpFrm( pFrm )
      60          16 :         {}
      61             : 
      62           8 :         bool operator < ( const FrmKey& rFrmKey ) const
      63             :         {
      64           8 :             return mpFrm < rFrmKey.mpFrm;
      65             :         }
      66             :     };
      67             : 
      68             :     struct FrmOrder
      69             :     {
      70           8 :         sal_Bool operator()( const FrmKey& rFrmKeyA,
      71             :                              const FrmKey& rFrmKeyB ) const
      72             :         {
      73           8 :             return rFrmKeyA < rFrmKeyB;
      74             :         }
      75             :     };
      76             : 
      77             :     typedef ::std::map < FrmKey, SidebarWinContainer, FrmOrder > _FrmSidebarWinContainer;
      78             : }
      79             : 
      80             : namespace sw { namespace sidebarwindows {
      81             : 
      82          16 : class FrmSidebarWinContainer : public _FrmSidebarWinContainer
      83             : {
      84             : };
      85             : 
      86          12 : SwFrmSidebarWinContainer::SwFrmSidebarWinContainer()
      87          12 :     : mpFrmSidebarWinContainer( new FrmSidebarWinContainer() )
      88          12 : {}
      89             : 
      90           4 : SwFrmSidebarWinContainer::~SwFrmSidebarWinContainer()
      91             : {
      92           4 :     mpFrmSidebarWinContainer->clear();
      93           4 :     delete mpFrmSidebarWinContainer;
      94           4 : }
      95             : 
      96          12 : bool SwFrmSidebarWinContainer::insert( const SwFrm& rFrm,
      97             :                                        const SwFmtFld& rFmtFld,
      98             :                                        SwSidebarWin& rSidebarWin )
      99             : {
     100          12 :     bool bInserted( false );
     101             : 
     102          12 :     FrmKey aFrmKey( &rFrm );
     103          12 :     SidebarWinContainer& rSidebarWinContainer = (*mpFrmSidebarWinContainer)[ aFrmKey ];
     104             : 
     105          12 :     SidebarWinKey aSidebarWinKey( *(rFmtFld.GetTxtFld()->GetStart()) );
     106          24 :     if ( rSidebarWinContainer.empty() ||
     107          12 :          rSidebarWinContainer.find( aSidebarWinKey) == rSidebarWinContainer.end() )
     108             :     {
     109          12 :         rSidebarWinContainer[ aSidebarWinKey ] = &rSidebarWin;
     110          12 :         bInserted = true;
     111             :     }
     112             : 
     113          12 :     return bInserted;
     114             : }
     115             : 
     116           4 : bool SwFrmSidebarWinContainer::remove( const SwFrm& rFrm,
     117             :                                        const SwSidebarWin& rSidebarWin )
     118             : {
     119           4 :     bool bRemoved( false );
     120             : 
     121           4 :     FrmKey aFrmKey( &rFrm );
     122           4 :     FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
     123           4 :     if ( aFrmIter != mpFrmSidebarWinContainer->end() )
     124             :     {
     125           4 :         SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
     126          12 :         for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
     127           8 :               aIter != rSidebarWinContainer.end();
     128             :               ++aIter )
     129             :         {
     130           4 :             if ( (*aIter).second == &rSidebarWin )
     131             :             {
     132           4 :                 rSidebarWinContainer.erase( aIter );
     133           4 :                 bRemoved = true;
     134           4 :                 break;
     135             :             }
     136             :         }
     137             :     }
     138             : 
     139           4 :     return bRemoved;
     140             : }
     141             : 
     142           0 : bool SwFrmSidebarWinContainer::empty( const SwFrm& rFrm )
     143             : {
     144           0 :     bool bEmpty( true );
     145             : 
     146           0 :     FrmKey aFrmKey( &rFrm );
     147           0 :     FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
     148           0 :     if ( aFrmIter != mpFrmSidebarWinContainer->end() )
     149             :     {
     150           0 :         bEmpty = (*aFrmIter).second.empty();
     151             :     }
     152             : 
     153           0 :     return bEmpty;
     154             : }
     155             : 
     156           0 : SwSidebarWin* SwFrmSidebarWinContainer::get( const SwFrm& rFrm,
     157             :                                              const sal_Int32 nIndex )
     158             : {
     159           0 :     SwSidebarWin* pRet( 0 );
     160             : 
     161           0 :     FrmKey aFrmKey( &rFrm );
     162           0 :     FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
     163           0 :     if ( aFrmIter != mpFrmSidebarWinContainer->end() )
     164             :     {
     165           0 :         SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
     166           0 :         sal_Int32 nCounter( nIndex );
     167           0 :         for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
     168           0 :               nCounter >= 0 && aIter != rSidebarWinContainer.end();
     169             :               ++aIter )
     170             :         {
     171           0 :             if ( nCounter == 0 )
     172             :             {
     173           0 :                 pRet = (*aIter).second;
     174           0 :                 break;
     175             :             }
     176             : 
     177           0 :             --nCounter;
     178             :         }
     179             :     }
     180             : 
     181           0 :     return pRet;
     182             : }
     183             : 
     184           0 : void SwFrmSidebarWinContainer::getAll( const SwFrm& rFrm,
     185             :                                        std::vector< Window* >* pSidebarWins )
     186             : {
     187           0 :     pSidebarWins->clear();
     188             : 
     189           0 :     FrmKey aFrmKey( &rFrm );
     190           0 :     FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
     191           0 :     if ( aFrmIter != mpFrmSidebarWinContainer->end() )
     192             :     {
     193           0 :         SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
     194           0 :         for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
     195           0 :               aIter != rSidebarWinContainer.end();
     196             :               ++aIter )
     197             :         {
     198           0 :             pSidebarWins->push_back( (*aIter).second );
     199             :         }
     200             :     }
     201           0 : }
     202             : 
     203             : } } // eof of namespace sw::sidebarwindows::
     204             : 
     205             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10