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

Generated by: LCOV version 1.10