2011-09-21 17:40:40 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License or as specified alternatively below. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* Major Contributor(s):
|
|
|
|
* [ Copyright (C) 2011 SUSE <cbosdonnat@suse.com> (initial developer) ]
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* For minor contributions see the git repository.
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
|
|
|
|
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
|
|
|
|
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
|
|
|
|
* instead of those above.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <edtwin.hxx>
|
|
|
|
#include <FrameControlsManager.hxx>
|
|
|
|
#include <HeaderFooterWin.hxx>
|
2011-09-23 21:02:12 +02:00
|
|
|
#include <PageBreakWin.hxx>
|
2011-09-21 17:40:40 +02:00
|
|
|
#include <pagefrm.hxx>
|
|
|
|
#include <viewopt.hxx>
|
|
|
|
#include <view.hxx>
|
|
|
|
#include <wrtsh.hxx>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
class FramePredicate
|
|
|
|
{
|
|
|
|
const SwFrm* m_pToMatch;
|
|
|
|
|
|
|
|
public:
|
|
|
|
FramePredicate( const SwFrm* pFrm ) : m_pToMatch( pFrm ) { };
|
2011-10-18 12:59:27 +02:00
|
|
|
virtual ~FramePredicate() {};
|
2011-09-21 17:40:40 +02:00
|
|
|
|
|
|
|
virtual bool operator()( SwFrameControlPtr pToCheck )
|
|
|
|
{ return m_pToMatch == pToCheck->GetFrame(); };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
|
2011-10-18 12:59:27 +02:00
|
|
|
m_pEditWin( pEditWin ),
|
|
|
|
m_aControls( )
|
2011-09-21 17:40:40 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwFrameControlsManager::~SwFrameControlsManager()
|
|
|
|
{
|
|
|
|
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin();
|
|
|
|
|
|
|
|
while ( pIt != m_aControls.end() )
|
|
|
|
{
|
|
|
|
pIt->second.clear( );
|
|
|
|
++pIt;
|
|
|
|
}
|
|
|
|
m_aControls.clear();
|
|
|
|
}
|
|
|
|
|
2011-10-18 12:59:27 +02:00
|
|
|
SwFrameControlsManager::SwFrameControlsManager( const SwFrameControlsManager& rCopy ) :
|
|
|
|
m_pEditWin( rCopy.m_pEditWin ),
|
|
|
|
m_aControls( rCopy.m_aControls )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const SwFrameControlsManager& SwFrameControlsManager::operator=( const SwFrameControlsManager& rCopy )
|
|
|
|
{
|
|
|
|
m_pEditWin = rCopy.m_pEditWin;
|
|
|
|
m_aControls = rCopy.m_aControls;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2011-10-22 04:18:39 -07:00
|
|
|
SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrm* pFrm )
|
|
|
|
{
|
|
|
|
SwFrameControlPtr pControl;
|
|
|
|
|
|
|
|
vector< SwFrameControlPtr >& aControls = m_aControls[eType];
|
|
|
|
|
|
|
|
vector< SwFrameControlPtr >::iterator pIt = find_if(
|
|
|
|
aControls.begin(), aControls.end( ), FramePredicate( pFrm ) );
|
|
|
|
|
|
|
|
if ( pIt != aControls.end() )
|
|
|
|
pControl = *pIt;
|
|
|
|
|
|
|
|
return pControl;
|
|
|
|
}
|
|
|
|
|
2011-10-04 13:11:50 +02:00
|
|
|
std::vector< SwFrameControlPtr >& SwFrameControlsManager::GetControls( FrameControlType eType )
|
2011-09-21 17:40:40 +02:00
|
|
|
{
|
|
|
|
return m_aControls[eType];
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwFrameControlsManager::AddControl( FrameControlType eType, SwFrameControlPtr pControl )
|
|
|
|
{
|
|
|
|
m_aControls[eType].push_back( pControl );
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwFrameControlsManager::RemoveControls( const SwFrm* pFrm )
|
|
|
|
{
|
|
|
|
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin();
|
|
|
|
|
|
|
|
while ( pIt != m_aControls.end() )
|
|
|
|
{
|
2011-10-04 13:11:50 +02:00
|
|
|
vector< SwFrameControlPtr >& aVect = pIt->second;
|
2011-09-21 17:40:40 +02:00
|
|
|
aVect.erase( remove_if( aVect.begin(),
|
|
|
|
aVect.end(),
|
|
|
|
FramePredicate( pFrm ) ), aVect.end() );
|
|
|
|
++pIt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SwFrameControlsManager::HideControls( FrameControlType eType )
|
|
|
|
{
|
|
|
|
vector< SwFrameControlPtr >::iterator pIt = m_aControls[eType].begin();
|
|
|
|
while ( pIt != m_aControls[eType].end() )
|
|
|
|
{
|
|
|
|
( *pIt )->ShowAll( false );
|
2011-12-29 10:55:37 +01:00
|
|
|
++pIt;
|
2011-09-21 17:40:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
|
|
|
|
{
|
|
|
|
map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin();
|
|
|
|
|
|
|
|
while ( pIt != m_aControls.end() )
|
|
|
|
{
|
|
|
|
vector< SwFrameControlPtr >::iterator pVectIt = pIt->second.begin();
|
|
|
|
while ( pVectIt != pIt->second.end() )
|
|
|
|
{
|
|
|
|
( *pVectIt )->SetReadonly( bReadonly );
|
|
|
|
++pVectIt;
|
|
|
|
}
|
|
|
|
++pIt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset )
|
|
|
|
{
|
|
|
|
// Check if we already have the control
|
|
|
|
SwFrameControlPtr pControl;
|
2011-12-28 20:01:57 +01:00
|
|
|
FrameControlType eType = bHeader? Header: Footer;
|
2011-09-21 17:40:40 +02:00
|
|
|
|
2011-12-28 20:01:57 +01:00
|
|
|
vector< SwFrameControlPtr >& aControls = m_aControls[eType];
|
2011-09-21 17:40:40 +02:00
|
|
|
|
|
|
|
vector< SwFrameControlPtr >::iterator pIt = aControls.begin();
|
|
|
|
while ( pIt != aControls.end() && !pControl.get() )
|
|
|
|
{
|
|
|
|
SwHeaderFooterWin* pToTest = dynamic_cast< SwHeaderFooterWin* >( pIt->get() );
|
|
|
|
if ( pToTest->GetPageFrame( ) == pPageFrm &&
|
|
|
|
pToTest->IsHeader( ) == bHeader )
|
|
|
|
pControl = *pIt;
|
2011-12-29 10:55:37 +01:00
|
|
|
++pIt;
|
2011-09-21 17:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !pControl.get() )
|
|
|
|
{
|
2011-09-23 21:02:12 +02:00
|
|
|
SwFrameControlPtr pNewControl( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) );
|
2011-09-21 17:40:40 +02:00
|
|
|
const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
|
2011-09-23 21:02:12 +02:00
|
|
|
pNewControl->SetReadonly( pViewOpt->IsReadonly() );
|
2011-12-28 20:01:57 +01:00
|
|
|
AddControl( eType, pNewControl );
|
2011-09-23 21:02:12 +02:00
|
|
|
pControl.swap( pNewControl );
|
2011-09-21 17:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrm->Frm().SVRect() );
|
|
|
|
|
|
|
|
SwHeaderFooterWin* pHFWin = dynamic_cast< SwHeaderFooterWin* >( pControl.get() );
|
|
|
|
pHFWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
|
|
|
|
|
|
|
|
if ( !pHFWin->IsVisible() )
|
|
|
|
pControl->ShowAll( true );
|
|
|
|
}
|
|
|
|
|
2011-09-23 21:02:12 +02:00
|
|
|
void SwFrameControlsManager::SetPageBreakControl( const SwPageFrm* pPageFrm )
|
|
|
|
{
|
|
|
|
// Check if we already have the control
|
|
|
|
SwFrameControlPtr pControl;
|
|
|
|
|
2011-10-04 13:11:50 +02:00
|
|
|
vector< SwFrameControlPtr >& aControls = m_aControls[PageBreak];
|
2011-09-23 21:02:12 +02:00
|
|
|
|
|
|
|
vector< SwFrameControlPtr >::iterator pIt = aControls.begin();
|
|
|
|
while ( pIt != aControls.end() && !pControl.get() )
|
|
|
|
{
|
|
|
|
SwPageBreakWin* pToTest = dynamic_cast< SwPageBreakWin* >( pIt->get() );
|
|
|
|
if ( pToTest->GetPageFrame( ) == pPageFrm )
|
|
|
|
pControl = *pIt;
|
2011-12-29 10:55:37 +01:00
|
|
|
++pIt;
|
2011-09-23 21:02:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( !pControl.get() )
|
|
|
|
{
|
|
|
|
SwFrameControlPtr pNewControl( new SwPageBreakWin( m_pEditWin, pPageFrm ) );
|
|
|
|
const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
|
|
|
|
pNewControl->SetReadonly( pViewOpt->IsReadonly() );
|
|
|
|
AddControl( PageBreak, pNewControl );
|
|
|
|
pControl.swap( pNewControl );
|
|
|
|
}
|
|
|
|
|
|
|
|
SwPageBreakWin* pWin = dynamic_cast< SwPageBreakWin* >( pControl.get() );
|
|
|
|
pWin->UpdatePosition();
|
|
|
|
if ( !pWin->IsVisible() )
|
|
|
|
pControl->ShowAll( true );
|
|
|
|
}
|
|
|
|
|
2011-09-21 17:40:40 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|