LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - FrameControlsManager.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 38 78 48.7 %
Date: 2014-04-11 Functions: 6 11 54.5 %
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             : 
      10             : #include <edtwin.hxx>
      11             : #include <FrameControlsManager.hxx>
      12             : #include <HeaderFooterWin.hxx>
      13             : #include <PageBreakWin.hxx>
      14             : #include <pagefrm.hxx>
      15             : #include <viewopt.hxx>
      16             : #include <view.hxx>
      17             : #include <wrtsh.hxx>
      18             : 
      19             : using namespace std;
      20             : 
      21        1732 : SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
      22             :     m_pEditWin( pEditWin ),
      23        1732 :     m_aControls( )
      24             : {
      25        1732 : }
      26             : 
      27        1731 : SwFrameControlsManager::~SwFrameControlsManager()
      28             : {
      29        1731 : }
      30             : 
      31           0 : SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
      32             :     m_pEditWin( rCopy.m_pEditWin ),
      33           0 :     m_aControls( rCopy.m_aControls )
      34             : {
      35           0 : }
      36             : 
      37           0 : const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameControlsManager& rCopy )
      38             : {
      39           0 :     m_pEditWin = rCopy.m_pEditWin;
      40           0 :     m_aControls = rCopy.m_aControls;
      41           0 :     return *this;
      42             : }
      43             : 
      44        2471 : SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
      45             : {
      46        2471 :     SwFrameControlPtrMap& rControls = m_aControls[eType];
      47             : 
      48        2471 :     SwFrameControlPtrMap::iterator aIt = rControls.find(pFrm);
      49             : 
      50        2471 :     if (aIt != rControls.end())
      51           4 :         return aIt->second;
      52             : 
      53        2467 :     return SwFrameControlPtr();
      54             : }
      55             : 
      56         141 : void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
      57             : {
      58         141 :     map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
      59             : 
      60         340 :     while ( pIt != m_aControls.end() )
      61             :     {
      62          58 :         SwFrameControlPtrMap& rMap = pIt->second;
      63          58 :         rMap.erase(pFrm);
      64          58 :         ++pIt;
      65             :     }
      66         141 : }
      67             : 
      68        7299 : void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrm* pFrm )
      69             : {
      70        7299 :     SwFrameControlPtrMap& rMap = m_aControls[eType];
      71        7299 :     rMap.erase(pFrm);
      72        7299 : }
      73             : 
      74           0 : void SwFrameControlsManager::HideControls( FrameControlType eType )
      75             : {
      76           0 :     SwFrameControlPtrMap::iterator pIt = m_aControls[eType].begin();
      77           0 :     while ( pIt != m_aControls[eType].end() )
      78             :     {
      79           0 :         pIt->second->ShowAll( false );
      80           0 :         ++pIt;
      81             :     }
      82           0 : }
      83             : 
      84           0 : void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
      85             : {
      86           0 :     map< FrameControlType, SwFrameControlPtrMap >::iterator pIt = m_aControls.begin();
      87             : 
      88           0 :     while ( pIt != m_aControls.end() )
      89             :     {
      90           0 :         SwFrameControlPtrMap::iterator aCtrlIt = pIt->second.begin();
      91           0 :         while ( aCtrlIt != pIt->second.end() )
      92             :         {
      93           0 :             aCtrlIt->second->SetReadonly( bReadonly );
      94           0 :             ++aCtrlIt;
      95             :         }
      96           0 :         ++pIt;
      97             :     }
      98           0 : }
      99             : 
     100           0 : void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, FrameControlType eType, Point aOffset )
     101             : {
     102             :     OSL_ASSERT( eType == Header || eType == Footer );
     103             : 
     104             :     // Check if we already have the control
     105           0 :     SwFrameControlPtr pControl;
     106           0 :     const bool bHeader = ( eType == Header );
     107             : 
     108           0 :     SwFrameControlPtrMap& rControls = m_aControls[eType];
     109             : 
     110           0 :     SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
     111           0 :     if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
     112           0 :         pControl = lb->second;
     113             :     else
     114             :     {
     115           0 :         SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
     116           0 :         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
     117           0 :         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
     118           0 :         rControls.insert(lb, make_pair(pPageFrm, pNewControl));
     119           0 :         pControl.swap( pNewControl );
     120             :     }
     121             : 
     122           0 :     Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
     123             : 
     124           0 :     SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
     125             :     assert(pHFWin->IsHeader() == bHeader);
     126           0 :     pHFWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
     127             : 
     128           0 :     if ( !pHFWin->IsVisible() )
     129           0 :         pControl->ShowAll( true );
     130           0 : }
     131             : 
     132         148 : void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
     133             : {
     134             :     // Check if we already have the control
     135         148 :     SwFrameControlPtr pControl;
     136             : 
     137         148 :     SwFrameControlPtrMap& rControls = m_aControls[PageBreak];
     138             : 
     139         148 :     SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrm);
     140         148 :     if (lb != rControls.end() && !(rControls.key_comp()(pPageFrm, lb->first)))
     141          39 :         pControl = lb->second;
     142             :     else
     143             :     {
     144         109 :         SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
     145         109 :         const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
     146         109 :         pNewControl->SetReadonly( pViewOpt->IsReadonly() );
     147             : 
     148         109 :         rControls.insert(lb, make_pair(pPageFrm, pNewControl));
     149             : 
     150         109 :         pControl.swap( pNewControl );
     151             :     }
     152             : 
     153         148 :     SwPageBreakWin* pWin = dynamic_cast< SwPageBreakWin* >( pControl.get() );
     154         148 :     pWin->UpdatePosition();
     155         148 :     if ( !pWin->IsVisible() )
     156         148 :         pControl->ShowAll( true );
     157         148 : }
     158             : 
     159             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10