LCOV - code coverage report
Current view: top level - sw/source/ui/docvw - FrameControlsManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 37 78 47.4 %
Date: 2012-08-25 Functions: 6 11 54.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 36 144 25.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include <edtwin.hxx>
      30                 :            : #include <FrameControlsManager.hxx>
      31                 :            : #include <HeaderFooterWin.hxx>
      32                 :            : #include <PageBreakWin.hxx>
      33                 :            : #include <pagefrm.hxx>
      34                 :            : #include <viewopt.hxx>
      35                 :            : #include <view.hxx>
      36                 :            : #include <wrtsh.hxx>
      37                 :            : 
      38                 :            : using namespace std;
      39                 :            : 
      40                 :       1318 : SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
      41                 :            :     m_pEditWin( pEditWin ),
      42                 :       1318 :     m_aControls( )
      43                 :            : {
      44                 :       1318 : }
      45                 :            : 
      46                 :       1231 : SwFrameControlsManager::~SwFrameControlsManager()
      47                 :            : {
      48                 :       1231 : }
      49                 :            : 
      50                 :          0 : SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
      51                 :            :     m_pEditWin( rCopy.m_pEditWin ),
      52                 :          0 :     m_aControls( rCopy.m_aControls )
      53                 :            : {
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameControlsManager& rCopy )
      57                 :            : {
      58                 :          0 :     m_pEditWin = rCopy.m_pEditWin;
      59                 :          0 :     m_aControls = rCopy.m_aControls;
      60                 :          0 :     return *this;
      61                 :            : }
      62                 :            : 
      63                 :       5442 : SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
      64                 :            : {
      65         [ +  - ]:       5442 :     SwFrameControlPtrMap& rControls = m_aControls[eType];
      66                 :            : 
      67         [ +  - ]:       5442 :     SwFrameControlPtrMap::iterator aIt = rControls.find(pFrm);
      68                 :            : 
      69         [ -  + ]:       5442 :     if (aIt != rControls.end())
      70         [ #  # ]:          0 :         return aIt->second;
      71                 :            : 
      72         [ +  - ]:       5442 :     return SwFrameControlPtr();
      73                 :            : }
      74                 :            : 
      75                 :         16 : void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
      76                 :            : {
      77                 :         16 :     map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
      78                 :            : 
      79         [ +  + ]:         28 :     while ( pIt != m_aControls.end() )
      80                 :            :     {
      81                 :         12 :         SwFrameControlPtrMap& rMap = pIt->second;
      82         [ +  - ]:         12 :         rMap.erase(pFrm);
      83                 :         12 :         ++pIt;
      84                 :            :     }
      85                 :         16 : }
      86                 :            : 
      87                 :      13189 : void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm )
      88                 :            : {
      89                 :      13189 :     SwFrameControlPtrMap& rMap = m_aControls[eType];
      90                 :      13189 :     rMap.erase(pFrm);
      91                 :      13189 : }
      92                 :            : 
      93                 :          0 : void SwFrameControlsManager::HideControls( FrameControlType eType )
      94                 :            : {
      95         [ #  # ]:          0 :     SwFrameControlPtrMap::iterator pIt = m_aControls[eType].begin();
      96 [ #  # ][ #  # ]:          0 :     while ( pIt != m_aControls[eType].end() )
      97                 :            :     {
      98         [ #  # ]:          0 :         pIt->second->ShowAll( false );
      99                 :          0 :         ++pIt;
     100                 :            :     }
     101                 :          0 : }
     102                 :            : 
     103                 :          0 : void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
     104                 :            : {
     105                 :          0 :     map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
     106                 :            : 
     107         [ #  # ]:          0 :     while ( pIt != m_aControls.end() )
     108                 :            :     {
     109                 :          0 :         SwFrameControlPtrMap::iterator aCtrlIt = pIt->second.begin();
     110         [ #  # ]:          0 :         while ( aCtrlIt != pIt->second.end() )
     111                 :            :         {
     112         [ #  # ]:          0 :             aCtrlIt->second->SetReadonly( bReadonly );
     113                 :          0 :             ++aCtrlIt;
     114                 :            :         }
     115                 :          0 :         ++pIt;
     116                 :            :     }
     117                 :          0 : }
     118                 :            : 
     119                 :          0 : void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, FrameControlType eType, Point aOffset )
     120                 :            : {
     121                 :            :     OSL_ASSERT( eType == Header || eType == Footer );
     122                 :            : 
     123                 :            :     // Check if we already have the control
     124         [ #  # ]:          0 :     SwFrameControlPtr pControl;
     125                 :          0 :     const bool bHeader = ( eType == Header );
     126                 :            : 
     127         [ #  # ]:          0 :     SwFrameControlPtrMap& rControls = m_aControls[eType];
     128                 :            : 
     129         [ #  # ]:          0 :     SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
     130 [ #  # ][ #  # ]:          0 :     if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
             #  #  #  # ]
     131         [ #  # ]:          0 :         pControl = lb->second;
     132                 :            :     else
     133                 :            :     {
     134 [ #  # ][ #  # ]:          0 :         SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
                 [ #  # ]
     135                 :          0 :         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
     136         [ #  # ]:          0 :         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
     137 [ #  # ][ #  # ]:          0 :         rControls.insert(lb, make_pair(pPageFrm, pNewControl));
                 [ #  # ]
     138         [ #  # ]:          0 :         pControl.swap( pNewControl );
     139                 :            :     }
     140                 :            : 
     141 [ #  # ][ #  # ]:          0 :     Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
     142                 :            : 
     143         [ #  # ]:          0 :     SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
     144                 :            :     assert(pHFWin->IsHeader() == bHeader);
     145         [ #  # ]:          0 :     pHFWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
     146                 :            : 
     147 [ #  # ][ #  # ]:          0 :     if ( !pHFWin->IsVisible() )
     148 [ #  # ][ #  # ]:          0 :         pControl->ShowAll( true );
     149                 :          0 : }
     150                 :            : 
     151                 :         30 : void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
     152                 :            : {
     153                 :            :     // Check if we already have the control
     154         [ +  - ]:         30 :     SwFrameControlPtr pControl;
     155                 :            : 
     156         [ +  - ]:         30 :     SwFrameControlPtrMap& rControls = m_aControls[PageBreak];
     157                 :            : 
     158         [ +  - ]:         30 :     SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
     159 [ +  + ][ +  - ]:         30 :     if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
         [ +  - ][ +  + ]
         [ +  + ][ +  - ]
           [ +  +  #  #  
             #  #  #  # ]
     160         [ +  - ]:         18 :         pControl = lb->second;
     161                 :            :     else
     162                 :            :     {
     163 [ +  - ][ +  - ]:         12 :         SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
                 [ +  - ]
     164                 :         12 :         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
     165         [ +  - ]:         12 :         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
     166                 :            : 
     167 [ +  - ][ +  - ]:         12 :         rControls.insert(lb, make_pair(pPageFrm, pNewControl));
                 [ +  - ]
     168                 :            : 
     169         [ +  - ]:         12 :         pControl.swap( pNewControl );
     170                 :            :     }
     171                 :            : 
     172         [ -  + ]:         30 :     SwPageBreakWin* pWin = dynamic_cast< SwPageBreakWin* >( pControl.get() );
     173         [ +  - ]:         30 :     pWin->UpdatePosition();
     174 [ +  - ][ +  - ]:         30 :     if ( !pWin->IsVisible() )
     175 [ +  - ][ +  - ]:         30 :         pControl->ShowAll( true );
     176                 :         30 : }
     177                 :            : 
     178                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10