summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorCédric Bosdonnat <cedric.bosdonnat.ooo@free.fr>2011-09-07 22:22:47 +0200
committerCédric Bosdonnat <cedric.bosdonnat.ooo@free.fr>2011-09-08 15:42:58 +0200
commit79f53401c6801e240800fb6e1eaae8f55974f9c6 (patch)
tree4c7a57602aec1dda55a5104be4bd5a5d97064634 /sw
parent1291efeee9ee4079e6bb38e0b06e9f73c365c7a0 (diff)
Header/Footer: just don't always drop and create SwHeaderFooterWin
This minimizes the number of creation / deletion of SwHeaderFooterWin objects and simply updates the existing ones.
Diffstat (limited to 'sw')
-rw-r--r--sw/source/core/layout/pagechg.cxx13
-rwxr-xr-xsw/source/core/layout/paintfrm.cxx16
-rw-r--r--sw/source/ui/docvw/HeaderFooterWin.cxx38
-rw-r--r--sw/source/ui/docvw/edtwin.cxx55
-rw-r--r--sw/source/ui/inc/HeaderFooterWin.hxx9
-rw-r--r--sw/source/ui/inc/edtwin.hxx5
6 files changed, 99 insertions, 37 deletions
diff --git a/sw/source/core/layout/pagechg.cxx b/sw/source/core/layout/pagechg.cxx
index 38ed77b112b0..263facb9c8c2 100644
--- a/sw/source/core/layout/pagechg.cxx
+++ b/sw/source/core/layout/pagechg.cxx
@@ -45,6 +45,9 @@
#include <tgrditem.hxx>
#include <viewopt.hxx>
#include <docsh.hxx>
+#include <wrtsh.hxx>
+#include <view.hxx>
+#include <edtwin.hxx>
#include "viewimp.hxx"
#include "viewopt.hxx"
@@ -277,6 +280,15 @@ SwPageFrm::SwPageFrm( SwFrmFmt *pFmt, SwFrm* pSib, SwPageDesc *pPgDsc ) :
SwPageFrm::~SwPageFrm()
{
+ // Cleanup the header-footer controls in the SwEditWin
+ ViewShell* pSh = getRootFrm()->GetCurrShell();
+ SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( pSh );
+ if ( pWrtSh )
+ {
+ SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
+ rEditWin.RemoveHeaderFooterControls( this );
+ }
+
//FlyContainer entleeren, delete der Flys uebernimmt der Anchor
//(Basisklasse SwFrm)
if ( pSortedObjs )
@@ -299,7 +311,6 @@ SwPageFrm::~SwPageFrm()
SwDoc *pDoc = GetFmt() ? GetFmt()->GetDoc() : NULL;
if( pDoc && !pDoc->IsInDtor() )
{
- ViewShell *pSh = getRootFrm()->GetCurrShell();
if ( pSh )
{
SwViewImp *pImp = pSh->Imp();
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index 4a67bb27508c..23c523ee9eae 100755
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -2788,7 +2788,7 @@ SwRootFrm::Paint(SwRect const& rRect, SwPrintData const*const pPrintData) const
if ( pWrtSh )
{
SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
- rEditWin.ClearHeaderFooterControls( );
+ rEditWin.HideHeaderFooterControls( );
}
@@ -3415,11 +3415,8 @@ void SwPageFrm::PaintDecorators( ) const
long nXOff = std::min( aBodyRect.Right(), rVisArea.Right() );
long nHeaderYOff = aBodyRect.Top();
- if ( rVisArea.IsInside( Point( rVisArea.Left(), nHeaderYOff ) ) )
- {
- Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nHeaderYOff + nHalfThickness ) );
- rEditWin.AddHeaderFooterControl( this, true, nOutputOff );
- }
+ Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nHeaderYOff + nHalfThickness ) );
+ rEditWin.SetHeaderFooterControl( this, true, nOutputOff );
pProcessor->process( lcl_CreateHeaderFooterSeparatorPrimitives(
this, double( nHeaderYOff ) ) );
@@ -3434,11 +3431,8 @@ void SwPageFrm::PaintDecorators( ) const
}
long nFooterYOff = aBodyRect.Bottom();
- if ( rVisArea.IsInside( Point( rVisArea.Left(), nFooterYOff ) ) )
- {
- Point nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nFooterYOff - nHalfThickness ) );
- rEditWin.AddHeaderFooterControl( this, false, nOutputOff );
- }
+ nOutputOff = rEditWin.LogicToPixel( Point( nXOff, nFooterYOff - nHalfThickness ) );
+ rEditWin.SetHeaderFooterControl( this, false, nOutputOff );
pProcessor->process( lcl_CreateHeaderFooterSeparatorPrimitives(
this, double( nFooterYOff ) ) );
diff --git a/sw/source/ui/docvw/HeaderFooterWin.cxx b/sw/source/ui/docvw/HeaderFooterWin.cxx
index 0665064b830d..d5e317f06156 100644
--- a/sw/source/ui/docvw/HeaderFooterWin.cxx
+++ b/sw/source/ui/docvw/HeaderFooterWin.cxx
@@ -104,10 +104,7 @@ class SwHeaderFooterButton : public MenuButton
};
-// the WB_MOVABLE flag is used here to avoid the window to appear on all desktops (on linux)
-// and the WB_OWNERDRAWDECORATION prevents the system to draw the window decorations.
-//
-SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader, Point aOffset ) :
+SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader ) :
Window( pEditWin, WB_DIALOGCONTROL ),
m_pEditWin( pEditWin ),
m_sLabel( ),
@@ -128,18 +125,35 @@ SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPag
m_sLabel = ResId::toString( SW_RES( STR_FOOTER_TITLE ) );
sal_Int32 nPos = m_sLabel.lastIndexOf( rtl::OUString::createFromAscii( "%1" ) );
m_sLabel = m_sLabel.replaceAt( nPos, 2, m_pPageFrm->GetPageDesc()->GetName() );
+}
+
+SwHeaderFooterWin::~SwHeaderFooterWin( )
+{
+ delete m_pButton;
+}
+MenuButton* SwHeaderFooterWin::GetMenuButton()
+{
+ if ( !m_pButton )
+ m_pButton = new SwHeaderFooterButton( this );
+
+ m_pButton->Show();
+
+ return m_pButton;
+}
+
+void SwHeaderFooterWin::SetOffset( Point aOffset )
+{
// Compute the text size and get the box position & size from it
Rectangle aTextRect;
GetTextBoundRect( aTextRect, String( m_sLabel ) );
Rectangle aTextPxRect = LogicToPixel( aTextRect );
-
Size aBoxSize ( aTextPxRect.GetWidth() + BUTTON_WIDTH + TEXT_PADDING * 2,
aTextPxRect.GetHeight() + TEXT_PADDING * 2 );
long nYFooterOff = 0;
- if ( !bHeader )
+ if ( !IsHeader() )
nYFooterOff = aBoxSize.Height();
Point aBoxPos( aOffset.X() - aBoxSize.Width() - BOX_DISTANCE,
@@ -148,18 +162,10 @@ SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPag
// Set the position & Size of the window
SetPosSizePixel( aBoxPos, aBoxSize );
- // Add the menu button
+ // Set the button position and size
Point aBtnPos( aBoxSize.getWidth() - BUTTON_WIDTH, 0 );
Size aBtnSize( BUTTON_WIDTH, aBoxSize.getHeight() );
-
- m_pButton = new SwHeaderFooterButton( this );
- m_pButton->SetPosSizePixel( aBtnPos, aBtnSize );
- m_pButton->Show();
-}
-
-SwHeaderFooterWin::~SwHeaderFooterWin( )
-{
- delete m_pButton;
+ GetMenuButton()->SetPosSizePixel( aBtnPos, aBtnSize );
}
void SwHeaderFooterWin::Paint( const Rectangle& )
diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx
index 5dbfbd3a5567..6b800f81afa1 100644
--- a/sw/source/ui/docvw/edtwin.cxx
+++ b/sw/source/ui/docvw/edtwin.cxx
@@ -141,6 +141,8 @@
#include <PostItMgr.hxx>
+#include <algorithm>
+
#include "../../core/inc/rootfrm.hxx"
using namespace sw::mark;
@@ -212,6 +214,17 @@ 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
@@ -4559,6 +4572,7 @@ SwEditWin::SwEditWin(Window *pParent, SwView &rMyView):
SwEditWin::~SwEditWin()
{
+ aHeadFootControls.clear();
aKeyInputTimer.Stop();
delete pShadCrsr;
delete pRowColumnSelectionStart;
@@ -5681,16 +5695,45 @@ Selection SwEditWin::GetSurroundingTextSelection() const
}
}
-void SwEditWin::AddHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset )
+void SwEditWin::SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset )
{
- boost::shared_ptr< SwHeaderFooterWin > pNewControl( new SwHeaderFooterWin( this, pPageFrm, bHeader, aOffset ) );
- pNewControl->Show( );
- aHeadFootControls.push_back( pNewControl );
+ // 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 ) );
+ pControl.swap( pNewControl );
+ aHeadFootControls.push_back( pControl );
+ }
+ pControl->SetOffset( aOffset );
+
+ pControl->Show( );
}
-void SwEditWin::ClearHeaderFooterControls( )
+void SwEditWin::RemoveHeaderFooterControls( const SwPageFrm* pPageFrm )
{
- aHeadFootControls.clear();
+ 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 )->Hide();
+ pIt++;
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/ui/inc/HeaderFooterWin.hxx b/sw/source/ui/inc/HeaderFooterWin.hxx
index 42b80a1c28ed..cd2991adc810 100644
--- a/sw/source/ui/inc/HeaderFooterWin.hxx
+++ b/sw/source/ui/inc/HeaderFooterWin.hxx
@@ -30,6 +30,7 @@
#include <pagedesc.hxx>
+#include <vcl/menubtn.hxx>
#include <vcl/window.hxx>
class SwHeaderFooterButton;
@@ -48,13 +49,19 @@ class SwHeaderFooterWin : public Window
SwHeaderFooterButton* m_pButton;
public:
- SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader, Point aOffset );
+ SwHeaderFooterWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm, bool bHeader );
~SwHeaderFooterWin( );
+ void SetOffset( Point aOffset );
+
virtual void Paint( const Rectangle& rRect );
bool IsHeader() { return m_bIsHeader; };
bool IsEmptyHeaderFooter( );
+ const SwPageFrm* GetPageFrame( ) { return m_pPageFrm; };
+
+private:
+ MenuButton* GetMenuButton();
};
#endif
diff --git a/sw/source/ui/inc/edtwin.hxx b/sw/source/ui/inc/edtwin.hxx
index 1c03d77c32dc..142514c655f7 100644
--- a/sw/source/ui/inc/edtwin.hxx
+++ b/sw/source/ui/inc/edtwin.hxx
@@ -312,8 +312,9 @@ public:
void SetUseInputLanguage( sal_Bool bNew );
sal_Bool IsUseInputLanguage() const { return bUseInputLanguage; }
- void AddHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset );
- void ClearHeaderFooterControls( );
+ void SetHeaderFooterControl( const SwPageFrm* pPageFrm, bool bHeader, Point aOffset );
+ void RemoveHeaderFooterControls( const SwPageFrm* pPageFrm );
+ void HideHeaderFooterControls( );
SwEditWin(Window *pParent, SwView &);
virtual ~SwEditWin();