summaryrefslogtreecommitdiff
path: root/sw/source/ui
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/source/ui
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/source/ui')
-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
4 files changed, 82 insertions, 25 deletions
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();