LCOV - code coverage report
Current view: top level - sw/source/ui/docvw - frmsidebarwincontainer.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 41 76 53.9 %
Date: 2012-08-25 Functions: 10 15 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 60 21.7 %

           Branch data     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                 :         18 :         explicit SidebarWinKey( const xub_StrLen nIndex )
      34                 :         18 :             : mnIndex( nIndex )
      35                 :         18 :         {}
      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                 :         33 :         explicit FrmKey( const SwFrm* pFrm )
      59                 :         33 :             : mpFrm( pFrm )
      60                 :         33 :         {}
      61                 :            : 
      62                 :         30 :         bool operator < ( const FrmKey& rFrmKey ) const
      63                 :            :         {
      64                 :         30 :             return mpFrm < rFrmKey.mpFrm;
      65                 :            :         }
      66                 :            :     };
      67                 :            : 
      68                 :            :     struct FrmOrder
      69                 :            :     {
      70                 :         30 :         sal_Bool operator()( const FrmKey& rFrmKeyA,
      71                 :            :                              const FrmKey& rFrmKeyB ) const
      72                 :            :         {
      73                 :         30 :             return rFrmKeyA < rFrmKeyB;
      74                 :            :         }
      75                 :            :     };
      76                 :            : 
      77                 :            :     typedef ::std::map < FrmKey, SidebarWinContainer, FrmOrder > _FrmSidebarWinContainer;
      78                 :            : }
      79                 :            : 
      80                 :            : namespace sw { namespace sidebarwindows {
      81                 :            : 
      82                 :         33 : class FrmSidebarWinContainer : public _FrmSidebarWinContainer
      83                 :            : {
      84                 :            : };
      85                 :            : 
      86                 :         18 : SwFrmSidebarWinContainer::SwFrmSidebarWinContainer()
      87         [ +  - ]:         18 :     : mpFrmSidebarWinContainer( new FrmSidebarWinContainer() )
      88                 :         18 : {}
      89                 :            : 
      90                 :         15 : SwFrmSidebarWinContainer::~SwFrmSidebarWinContainer()
      91                 :            : {
      92                 :         15 :     mpFrmSidebarWinContainer->clear();
      93         [ +  - ]:         15 :     delete mpFrmSidebarWinContainer;
      94                 :         15 : }
      95                 :            : 
      96                 :         18 : bool SwFrmSidebarWinContainer::insert( const SwFrm& rFrm,
      97                 :            :                                        const SwFmtFld& rFmtFld,
      98                 :            :                                        SwSidebarWin& rSidebarWin )
      99                 :            : {
     100                 :         18 :     bool bInserted( false );
     101                 :            : 
     102                 :         18 :     FrmKey aFrmKey( &rFrm );
     103         [ +  - ]:         18 :     SidebarWinContainer& rSidebarWinContainer = (*mpFrmSidebarWinContainer)[ aFrmKey ];
     104                 :            : 
     105                 :         18 :     SidebarWinKey aSidebarWinKey( *(rFmtFld.GetTxtFld()->GetStart()) );
     106         [ +  - ]:         36 :     if ( rSidebarWinContainer.empty() ||
           [ -  +  #  # ]
     107 [ #  # ][ -  + ]:         18 :          rSidebarWinContainer.find( aSidebarWinKey) == rSidebarWinContainer.end() )
                 [ -  + ]
           [ #  #  #  # ]
     108                 :            :     {
     109         [ +  - ]:         18 :         rSidebarWinContainer[ aSidebarWinKey ] = &rSidebarWin;
     110                 :         18 :         bInserted = true;
     111                 :            :     }
     112                 :            : 
     113                 :         18 :     return bInserted;
     114                 :            : }
     115                 :            : 
     116                 :         15 : bool SwFrmSidebarWinContainer::remove( const SwFrm& rFrm,
     117                 :            :                                        const SwSidebarWin& rSidebarWin )
     118                 :            : {
     119                 :         15 :     bool bRemoved( false );
     120                 :            : 
     121                 :         15 :     FrmKey aFrmKey( &rFrm );
     122         [ +  - ]:         15 :     FrmSidebarWinContainer::iterator aFrmIter = mpFrmSidebarWinContainer->find( aFrmKey );
     123         [ +  - ]:         15 :     if ( aFrmIter != mpFrmSidebarWinContainer->end() )
     124                 :            :     {
     125                 :         15 :         SidebarWinContainer& rSidebarWinContainer = (*aFrmIter).second;
     126         [ +  - ]:         45 :         for ( SidebarWinContainer::iterator aIter = rSidebarWinContainer.begin();
     127                 :         15 :               aIter != rSidebarWinContainer.end();
     128                 :            :               ++aIter )
     129                 :            :         {
     130         [ +  - ]:         15 :             if ( (*aIter).second == &rSidebarWin )
     131                 :            :             {
     132         [ +  - ]:         15 :                 rSidebarWinContainer.erase( aIter );
     133                 :         15 :                 bRemoved = true;
     134                 :         15 :                 break;
     135                 :            :             }
     136                 :            :         }
     137                 :            :     }
     138                 :            : 
     139                 :         15 :     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