From 2f150822d854d8fb5df5a7f32cefd6cd623824a1 Mon Sep 17 00:00:00 2001 From: Cédric Bosdonnat Date: Mon, 5 Sep 2011 15:01:31 +0200 Subject: Header/Footer: moved the SwHeaderFooterWin to separate {h,c}xx files --- sw/Library_sw.mk | 1 + sw/source/ui/docvw/HeaderFooterWin.cxx | 122 +++++++++++++++++++++++++++++++++ sw/source/ui/docvw/edtwin.cxx | 89 +----------------------- sw/source/ui/inc/HeaderFooterWin.hxx | 52 ++++++++++++++ sw/source/ui/inc/edtwin.hxx | 25 +------ 5 files changed, 180 insertions(+), 109 deletions(-) create mode 100644 sw/source/ui/docvw/HeaderFooterWin.cxx create mode 100644 sw/source/ui/inc/HeaderFooterWin.hxx (limited to 'sw') diff --git a/sw/Library_sw.mk b/sw/Library_sw.mk index 0636bdf34b2a..35b2b032b418 100644 --- a/sw/Library_sw.mk +++ b/sw/Library_sw.mk @@ -589,6 +589,7 @@ $(eval $(call gb_Library_add_exception_objects,sw,\ sw/source/ui/docvw/SidebarTxtControlAcc \ sw/source/ui/docvw/SidebarWin \ sw/source/ui/docvw/SidebarWinAcc \ + sw/source/ui/docvw/HeaderFooterWin \ sw/source/ui/docvw/edtdd \ sw/source/ui/docvw/edtwin \ sw/source/ui/docvw/edtwin2 \ diff --git a/sw/source/ui/docvw/HeaderFooterWin.cxx b/sw/source/ui/docvw/HeaderFooterWin.cxx new file mode 100644 index 000000000000..77b15e458508 --- /dev/null +++ b/sw/source/ui/docvw/HeaderFooterWin.cxx @@ -0,0 +1,122 @@ +/* -*- 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 (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 +#include +#include + +#include +#include + +#define TEXT_PADDING 7 +#define BOX_DISTANCE 10 + +// 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 rtl::OUString& sLabel, bool bHeader, Point aOffset ) : + FloatingWindow( pEditWin, WB_SYSTEMWINDOW | WB_NOBORDER | WB_NOSHADOW | WB_MOVEABLE | WB_OWNERDRAWDECORATION ), + m_pEditWin( pEditWin ), + m_sText( sLabel ), + m_bIsHeader( bHeader ) +{ + // Get the font and configure it + Font aFont = GetSettings().GetStyleSettings().GetToolFont(); + SetZoomedPointFont( aFont ); + + // Use pixels for the rest of the drawing + SetMapMode( MapMode ( MAP_PIXEL ) ); + + // Compute the position & size of the window + Rectangle aTextRect; + GetTextBoundRect( aTextRect, String( sLabel ) ); + Rectangle aTextPxRect = LogicToPixel( aTextRect ); + + Size aBoxSize ( aTextPxRect.GetWidth() + TEXT_PADDING * 2, + aTextPxRect.GetHeight() + TEXT_PADDING * 2 ); + + long nYFooterOff = 0; + if ( !bHeader ) + nYFooterOff = aBoxSize.Height(); + + Size aPosOffset ( pEditWin->GetOutOffXPixel(), pEditWin->GetOutOffYPixel() ); + Point aBoxPos( aPosOffset.Width() + aOffset.X() - aBoxSize.Width() - BOX_DISTANCE, + aPosOffset.Height() + aOffset.Y() - nYFooterOff ); + + // Set the position & Size of the window + SetPosSizePixel( aBoxPos, aBoxSize ); + + // TODO Add the list_add.png picture +} + +void SwHeaderFooterWin::Paint( const Rectangle& rRect ) +{ + // Colors + basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor(); + basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aLineColor ); + double nLuminance = aHslLine.getZ() * 2.5; + if ( nLuminance == 0 ) + nLuminance = 0.5; + else if ( nLuminance >= 1.0 ) + nLuminance = aHslLine.getZ() * 0.4; + aHslLine.setZ( nLuminance ); + basegfx::BColor aFillColor = basegfx::tools::hsl2rgb( aHslLine ); + + // Draw the background rect + SetFillColor( Color ( aFillColor ) ); + SetLineColor( Color ( aFillColor ) ); + DrawRect( rRect ); + + // Draw the lines around the rect + SetLineColor( Color( aLineColor ) ); + basegfx::B2DPolygon aPolygon; + aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Top() ) ); + aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Bottom() ) ); + DrawPolyLine( aPolygon, 1.0 ); + + aPolygon.clear(); + aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Top() ) ); + aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Bottom() ) ); + DrawPolyLine( aPolygon, 1.0 ); + + long nYLine = rRect.Bottom(); + if ( !m_bIsHeader ) + nYLine = rRect.Top(); + aPolygon.clear(); + aPolygon.append( basegfx::B2DPoint( rRect.Left(), nYLine ) ); + aPolygon.append( basegfx::B2DPoint( rRect.Right(), nYLine ) ); + DrawPolyLine( aPolygon, 1.0 ); + + + // Draw the text + SetTextColor( Color( aLineColor ) ); + DrawText( Point( rRect.Left() + TEXT_PADDING, rRect.Top() + TEXT_PADDING ), + String( m_sText ) ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/docvw/edtwin.cxx b/sw/source/ui/docvw/edtwin.cxx index 426315048f3a..a42966a068c9 100644 --- a/sw/source/ui/docvw/edtwin.cxx +++ b/sw/source/ui/docvw/edtwin.cxx @@ -118,6 +118,7 @@ #include #include #include +#include #include #include @@ -5679,95 +5680,9 @@ Selection SwEditWin::GetSurroundingTextSelection() const } } -#define TEXT_PADDING 7 -#define BOX_DISTANCE 10 - -// 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. -// -SwHeaderFooterControl::SwHeaderFooterControl( Window* pParent, const rtl::OUString& sLabel, bool bHeader, Point aOffset, Size aPosOffset ) : - FloatingWindow( pParent, WB_SYSTEMWINDOW | WB_NOBORDER | WB_NOSHADOW | WB_MOVEABLE | WB_OWNERDRAWDECORATION ), - m_sText( sLabel ), - m_bIsHeader( bHeader ), - m_aPosOffset( aPosOffset ) -{ - // Get the font and configure it - Font aFont = GetSettings().GetStyleSettings().GetToolFont(); - SetZoomedPointFont( aFont ); - - // Use pixels for the rest of the drawing - SetMapMode( MapMode ( MAP_PIXEL ) ); - - // Compute the position & size of the window - Rectangle aTextRect; - GetTextBoundRect( aTextRect, String( sLabel ) ); - Rectangle aTextPxRect = LogicToPixel( aTextRect ); - - Size aBoxSize ( aTextPxRect.GetWidth() + TEXT_PADDING * 2, - aTextPxRect.GetHeight() + TEXT_PADDING * 2 ); - - long nYFooterOff = 0; - if ( !bHeader ) - nYFooterOff = aBoxSize.Height(); - - Point aBoxPos( m_aPosOffset.Width() + aOffset.X() - aBoxSize.Width() - BOX_DISTANCE, - m_aPosOffset.Height() + aOffset.Y() - nYFooterOff ); - - // Set the position & Size of the window - SetPosSizePixel( aBoxPos, aBoxSize ); - - // TODO Add the list_add.png picture -} - -void SwHeaderFooterControl::Paint( const Rectangle& rRect ) -{ - // Colors - basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor(); - basegfx::BColor aHslLine = basegfx::tools::rgb2hsl( aLineColor ); - double nLuminance = aHslLine.getZ() * 2.5; - if ( nLuminance == 0 ) - nLuminance = 0.5; - else if ( nLuminance >= 1.0 ) - nLuminance = aHslLine.getZ() * 0.4; - aHslLine.setZ( nLuminance ); - basegfx::BColor aFillColor = basegfx::tools::hsl2rgb( aHslLine ); - - // Draw the background rect - SetFillColor( Color ( aFillColor ) ); - SetLineColor( Color ( aFillColor ) ); - DrawRect( rRect ); - - // Draw the lines around the rect - SetLineColor( Color( aLineColor ) ); - basegfx::B2DPolygon aPolygon; - aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Top() ) ); - aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Bottom() ) ); - DrawPolyLine( aPolygon, 1.0 ); - - aPolygon.clear(); - aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Top() ) ); - aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Bottom() ) ); - DrawPolyLine( aPolygon, 1.0 ); - - long nYLine = rRect.Bottom(); - if ( !m_bIsHeader ) - nYLine = rRect.Top(); - aPolygon.clear(); - aPolygon.append( basegfx::B2DPoint( rRect.Left(), nYLine ) ); - aPolygon.append( basegfx::B2DPoint( rRect.Right(), nYLine ) ); - DrawPolyLine( aPolygon, 1.0 ); - - - // Draw the text - SetTextColor( Color( aLineColor ) ); - DrawText( Point( rRect.Left() + TEXT_PADDING, rRect.Top() + TEXT_PADDING ), - String( m_sText ) ); -} - void SwEditWin::AddHeaderFooterControl( const rtl::OUString& sLabel, bool bHeader, Point aOffset ) { - SwHeaderFooterControl::Pointer pNewControl( new SwHeaderFooterControl( this, sLabel, bHeader, aOffset, - Size( GetOutOffXPixel(), GetOutOffYPixel() ) ) ); + boost::shared_ptr< SwHeaderFooterWin > pNewControl( new SwHeaderFooterWin( this, sLabel, bHeader, aOffset ) ); pNewControl->Show( ); aHeadFootControls.push_back( pNewControl ); } diff --git a/sw/source/ui/inc/HeaderFooterWin.hxx b/sw/source/ui/inc/HeaderFooterWin.hxx new file mode 100644 index 000000000000..b41fd0974e32 --- /dev/null +++ b/sw/source/ui/inc/HeaderFooterWin.hxx @@ -0,0 +1,52 @@ +/* -*- 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 (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 _HEADERFOOTERWINDOW_HXX +#define _HEADERFOOTERWINDOW_HXX + +#include + +/** Class for the header and footer separator control window. + + This control is showing the header / footer style name and provides + a few useful actions to the user. + */ +class SwHeaderFooterWin : public FloatingWindow +{ + SwEditWin* m_pEditWin; + const rtl::OUString m_sText; + bool m_bIsHeader; + +public: + SwHeaderFooterWin( SwEditWin* pEditWin, const rtl::OUString& sLabel, bool bHeader, Point aOffset ); + + virtual void Paint( const Rectangle& rRect ); +}; + +#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 96b1f7f4e28b..5eade2a15700 100644 --- a/sw/source/ui/inc/edtwin.hxx +++ b/sw/source/ui/inc/edtwin.hxx @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -54,31 +53,13 @@ class SvxAutoCorrect; class SwPaM; struct SwApplyTemplate; struct QuickHelpData; -class SdrDropMarkerOverlay; +class SdrDropMarkerOverlay; +class SwHeaderFooterWin; /*-------------------------------------------------------------------- Description: input window --------------------------------------------------------------------*/ -/** Class for the header and footer separator control window. - - This control is showing the header / footer style name and provides - a few useful actions to the user. - */ -class SwHeaderFooterControl : public FloatingWindow -{ - const rtl::OUString m_sText; - bool m_bIsHeader; - Size m_aPosOffset; - -public: - SwHeaderFooterControl( Window* pParent, const rtl::OUString& sLabel, bool bHeader, Point aOffset, Size aOffsetPos ); - - virtual void Paint( const Rectangle& rRect ); - - typedef boost::shared_ptr< SwHeaderFooterControl > Pointer; -}; - /** Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing the final painting of the document from the buffered layout. @@ -175,7 +156,7 @@ friend void PageNumNotify( ViewShell* pVwSh, sal_uInt16 nKS_NUMDOWN_Count; // #i23725# sal_uInt16 nKS_NUMINDENTINC_Count; - std::vector< SwHeaderFooterControl::Pointer > aHeadFootControls; + std::vector< boost::shared_ptr< SwHeaderFooterWin >> aHeadFootControls; void LeaveArea(const Point &); void JustifyAreaTimer(); -- cgit