diff options
author | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2011-09-21 17:40:40 +0200 |
---|---|---|
committer | Cédric Bosdonnat <cedric.bosdonnat.ooo@free.fr> | 2011-09-21 17:44:51 +0200 |
commit | e19f926ba247b4b84c4efa368cf19c312f5f51e7 (patch) | |
tree | 8fc0257917fedcfd91095e94ce00ee9648af7762 /sw | |
parent | Header/Footer: Extracted a few common things to a SwFrameControl class (diff) | |
download | core-e19f926ba247b4b84c4efa368cf19c312f5f51e7.tar.gz core-e19f926ba247b4b84c4efa368cf19c312f5f51e7.zip |
Header/Footer: refactored the SwEditWin to extend it to page breaks
Diffstat (limited to 'sw')
-rw-r--r-- | sw/Library_sw.mk | 1 | ||||
-rw-r--r-- | sw/source/core/layout/pagechg.cxx | 2 | ||||
-rwxr-xr-x | sw/source/core/layout/paintfrm.cxx | 4 | ||||
-rw-r--r-- | sw/source/ui/docvw/FrameControlsManager.cxx | 155 | ||||
-rw-r--r-- | sw/source/ui/docvw/edtwin.cxx | 72 | ||||
-rw-r--r-- | sw/source/ui/inc/FrameControl.hxx | 4 | ||||
-rw-r--r-- | sw/source/ui/inc/FrameControlsManager.hxx | 72 | ||||
-rw-r--r-- | sw/source/ui/inc/edtwin.hxx | 13 | ||||
-rw-r--r-- | sw/source/ui/wrtsh/wrtsh1.cxx | 4 |
9 files changed, 241 insertions, 86 deletions
diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 709b4b5929a8..f1e7d5c72425 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -584,6 +584,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/ui/docvw/AnnotationMenuButton \ sw/source/ui/docvw/AnnotationWin \ sw/source/ui/docvw/DashedLine \ + sw/source/ui/docvw/FrameControlsManager \ sw/source/ui/docvw/PostItMgr \ sw/source/ui/docvw/ShadowOverlayObject \ sw/source/ui/docvw/SidebarTxtControl \ diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx index e028d277a2b6..5f2637d70543 100644 --- a/sw/source/core/layout/pagechg.cxx +++ b/sw/source/core/layout/pagechg.cxx @@ -286,7 +286,7 @@ SwPageFrm::~SwPageFrm() if ( pWrtSh ) { SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin(); - rEditWin.RemoveHeaderFooterControls( this ); + rEditWin.GetFrameControlsManager( ).RemoveControls( this ); } //FlyContainer entleeren, delete der Flys uebernimmt der Anchor diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx index 5a1621a01931..9301167805e2 100755 --- a/sw/source/core/layout/paintfrm.cxx +++ b/sw/source/core/layout/paintfrm.cxx @@ -3512,7 +3512,7 @@ void SwPageFrm::PaintDecorators( ) const long nHeaderYOff = aBodyRect.Top(); Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nHeaderYOff ) ); - rEditWin.SetHeaderFooterControl( this, true, nOutputOff ); + rEditWin.GetFrameControlsManager().SetHeaderFooterControl( this, true, nOutputOff ); // Footer const SwFrm* pFtnContFrm = Lower(); @@ -3525,7 +3525,7 @@ void SwPageFrm::PaintDecorators( ) const long nFooterYOff = aBodyRect.Bottom(); nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nFooterYOff ) ); - rEditWin.SetHeaderFooterControl( this, false, nOutputOff ); + rEditWin.GetFrameControlsManager().SetHeaderFooterControl( this, false, nOutputOff ); } } } diff --git a/sw/source/ui/docvw/FrameControlsManager.cxx b/sw/source/ui/docvw/FrameControlsManager.cxx new file mode 100644 index 000000000000..69b9c98f6de9 --- /dev/null +++ b/sw/source/ui/docvw/FrameControlsManager.cxx @@ -0,0 +1,155 @@ +/* -*- 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> +#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 ) { }; + + virtual bool operator()( SwFrameControlPtr pToCheck ) + { return m_pToMatch == pToCheck->GetFrame(); }; + }; +} + +SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) : + m_pEditWin( pEditWin ) +{ +} + +SwFrameControlsManager::~SwFrameControlsManager() +{ + map< FrameControlType, vector< SwFrameControlPtr > >::iterator pIt = m_aControls.begin(); + + while ( pIt != m_aControls.end() ) + { + pIt->second.clear( ); + ++pIt; + } + m_aControls.clear(); +} + +std::vector< SwFrameControlPtr > SwFrameControlsManager::GetControls( FrameControlType eType ) +{ + 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() ) + { + vector< SwFrameControlPtr > aVect = pIt->second; + 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 ); + pIt++; + } +} + +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; + + vector< SwFrameControlPtr > aControls = m_aControls[HeaderFooter]; + + 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; + pIt++; + } + + if ( !pControl.get() ) + { + pControl = SwFrameControlPtr( new SwHeaderFooterWin( m_pEditWin, pPageFrm, bHeader ) ); + const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions(); + pControl->SetReadonly( pViewOpt->IsReadonly() ); + AddControl( HeaderFooter, pControl ); + } + + 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 ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx index e985981e2c88..cac527739ce7 100644 --- a/sw/source/ui/docvw/edtwin.cxx +++ b/sw/source/ui/docvw/edtwin.cxx @@ -214,17 +214,6 @@ namespace } return bRet; } - - class PageFramePredicate - { - const SwPageFrm* m_pToMatch; - - public: - PageFramePredicate( const SwPageFrm* pPageFrm ) : m_pToMatch( pPageFrm ) { }; - - virtual bool operator()( boost::shared_ptr< SwHeaderFooterWin > pToCheck ) - { return m_pToMatch == pToCheck->GetPageFrame(); }; - }; } class SwAnchorMarker @@ -4580,7 +4569,8 @@ SwEditWin::SwEditWin(Window *pParent, SwView &rMyView): bLockInput(sal_False), bObjectSelect( sal_False ), nKS_NUMDOWN_Count(0), - nKS_NUMINDENTINC_Count(0) + nKS_NUMINDENTINC_Count(0), + m_aFrameControlsManager( this ) { SetHelpId(HID_EDIT_WIN); EnableChildTransparentMode(); @@ -4623,7 +4613,6 @@ SwEditWin::SwEditWin(Window *pParent, SwView &rMyView): SwEditWin::~SwEditWin() { - aHeadFootControls.clear(); aKeyInputTimer.Stop(); delete pShadCrsr; delete pRowColumnSelectionStart; @@ -5758,61 +5747,4 @@ Selection SwEditWin::GetSurroundingTextSelection() const } } -void SwEditWin::SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset ) -{ - // Check if we already have the control - boost::shared_ptr< SwHeaderFooterWin > pControl; - std::vector< boost::shared_ptr< SwHeaderFooterWin > >::iterator pIt = aHeadFootControls.begin(); - while ( pIt != aHeadFootControls.end() && !pControl.get() ) - { - if ( ( *pIt )->GetPageFrame( ) == pPageFrm && - ( *pIt )->IsHeader( ) == bHeader ) - pControl = *pIt; - ++pIt; - } - - if ( !pControl.get() ) - { - boost::shared_ptr< SwHeaderFooterWin > pNewControl( new SwHeaderFooterWin( this, pPageFrm, bHeader ) ); - const SwViewOption* pViewOpt = GetView().GetWrtShell().GetViewOptions(); - pNewControl->SetReadonly( pViewOpt->IsReadonly() ); - pControl.swap( pNewControl ); - aHeadFootControls.push_back( pControl ); - } - - Rectangle aPageRect = LogicToPixel( pPageFrm->Frm().SVRect() ); - - pControl->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() ); - - if ( !pControl->IsVisible() ) - pControl->ShowAll( true ); -} - -void SwEditWin::RemoveHeaderFooterControls( const SwPageFrm* pPageFrm ) -{ - aHeadFootControls.erase( remove_if( aHeadFootControls.begin(), - aHeadFootControls.end(), - PageFramePredicate( pPageFrm ) ), aHeadFootControls.end() ); -} - -void SwEditWin::HideHeaderFooterControls( ) -{ - std::vector< boost::shared_ptr< SwHeaderFooterWin > >::iterator pIt = aHeadFootControls.begin(); - while ( pIt != aHeadFootControls.end() ) - { - ( *pIt )->ShowAll( false ); - ++pIt; - } -} - -void SwEditWin::SetReadonlyHeaderFooterControls( bool bReadonly ) -{ - std::vector< boost::shared_ptr< SwHeaderFooterWin > >::iterator pIt = aHeadFootControls.begin(); - while ( pIt != aHeadFootControls.end() ) - { - ( *pIt )->SetReadonly( bReadonly ); - ++pIt; - } -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/inc/FrameControl.hxx b/sw/source/ui/inc/FrameControl.hxx index 01bbb6b84510..0be643d4c1f4 100644 --- a/sw/source/ui/inc/FrameControl.hxx +++ b/sw/source/ui/inc/FrameControl.hxx @@ -28,8 +28,8 @@ #ifndef _FRAMECONTROL_HXX #define _FRAMECONTROL_HXX -#include <edtwin.hxx> -#include <frame.hxx> +class SwEditWin; +class SwFrm; /** Class representing a control linked to a SwFrm. */ diff --git a/sw/source/ui/inc/FrameControlsManager.hxx b/sw/source/ui/inc/FrameControlsManager.hxx new file mode 100644 index 000000000000..a37305bbc3eb --- /dev/null +++ b/sw/source/ui/inc/FrameControlsManager.hxx @@ -0,0 +1,72 @@ +/* -*- 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. + */ +#ifndef _FRAMECONTROLSMANAGER_HXX +#define _FRAMECONTROLSMANAGER_HXX + +#include <FrameControl.hxx> + +#include <boost/shared_ptr.hpp> +#include <tools/gen.hxx> + +#include <map> +#include <vector> + +class SwPageFrm; +class SwEditWin; + +enum FrameControlType +{ + PageBreak, + HeaderFooter +}; + +typedef boost::shared_ptr< SwFrameControl > SwFrameControlPtr; + +class SwFrameControlsManager +{ + private: + SwEditWin* m_pEditWin; + std::map< FrameControlType, std::vector< SwFrameControlPtr > > m_aControls; + + public: + SwFrameControlsManager( SwEditWin* pEditWin ); + ~SwFrameControlsManager( ); + + std::vector< SwFrameControlPtr > GetControls( FrameControlType eType ); + void AddControl( FrameControlType eType, SwFrameControlPtr pControl ); + void RemoveControls( const SwFrm* pFrm ); + void HideControls( FrameControlType eType ); + void SetReadonlyControls( bool bReadonly ); + + // Helper methods + void SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/inc/edtwin.hxx b/sw/source/ui/inc/edtwin.hxx index f85b2f11b2bc..8cdcb1b1aec3 100644 --- a/sw/source/ui/inc/edtwin.hxx +++ b/sw/source/ui/inc/edtwin.hxx @@ -28,6 +28,8 @@ #ifndef _EDTWIN_HXX #define _EDTWIN_HXX +#include <FrameControlsManager.hxx> + #include <svx/svdobj.hxx> #include <tools/link.hxx> #include <vcl/timer.hxx> @@ -38,8 +40,6 @@ #define _SVSTDARR_STRINGSISORTDTOR #include <svl/svstdarr.hxx> -#include <boost/shared_ptr.hpp> - class SwWrtShell; class SwView; class SwRect; @@ -54,8 +54,6 @@ class SwPaM; struct SwApplyTemplate; struct QuickHelpData; class SdrDropMarkerOverlay; -class SwHeaderFooterWin; -class SwPageFrm; /*-------------------------------------------------------------------- Description: input window @@ -162,7 +160,7 @@ friend void PageNumNotify( ViewShell* pVwSh, sal_uInt16 nKS_NUMDOWN_Count; // #i23725# sal_uInt16 nKS_NUMINDENTINC_Count; - std::vector< boost::shared_ptr<SwHeaderFooterWin> > aHeadFootControls; + SwFrameControlsManager m_aFrameControlsManager; void LeaveArea(const Point &); void JustifyAreaTimer(); @@ -320,10 +318,7 @@ public: void SetUseInputLanguage( sal_Bool bNew ); sal_Bool IsUseInputLanguage() const { return bUseInputLanguage; } - void SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset ); - void RemoveHeaderFooterControls( const SwPageFrm* pPageFrm ); - void HideHeaderFooterControls( ); - void SetReadonlyHeaderFooterControls( bool bReadonly ); + SwFrameControlsManager& GetFrameControlsManager() { return m_aFrameControlsManager; } SwEditWin(Window *pParent, SwView &); virtual ~SwEditWin(); diff --git a/sw/source/ui/wrtsh/wrtsh1.cxx b/sw/source/ui/wrtsh/wrtsh1.cxx index ec54dc271f0a..c5f873dc2e8c 100644 --- a/sw/source/ui/wrtsh/wrtsh1.cxx +++ b/sw/source/ui/wrtsh/wrtsh1.cxx @@ -1816,7 +1816,7 @@ void SwWrtShell::ApplyViewOptions( const SwViewOption &rOpt ) void SwWrtShell::SetReadonlyOption(sal_Bool bSet) { - GetView().GetEditWin().SetReadonlyHeaderFooterControls( bSet ); + GetView().GetEditWin().GetFrameControlsManager().SetReadonlyControls( bSet ); ViewShell::SetReadonlyOption( bSet ); } @@ -1894,7 +1894,7 @@ void SwWrtShell::SetShowHeaderFooterSeparator( sal_Bool bShow ) { ViewShell::SetShowHeaderFooterSeparator( bShow ); if ( !bShow ) - GetView().GetEditWin().HideHeaderFooterControls( ); + GetView().GetEditWin().GetFrameControlsManager().HideControls( HeaderFooter ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |