1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
/* -*- 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 <docvw.hrc>
#include <edtwin.hxx>
#include <fmthdft.hxx>
#include <HeaderFooterWin.hxx>
#include <pagefrm.hxx>
#include <viewopt.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/color/bcolortools.hxx>
#include <svtools/svtdata.hxx>
#include <svtools/svtools.hrc>
#include <vcl/decoview.hxx>
#include <vcl/menubtn.hxx>
#include <vcl/svapp.hxx>
#define TEXT_PADDING 7
#define BOX_DISTANCE 10
#define BUTTON_WIDTH 18
namespace
{
basegfx::BColor lcl_GetFillColor( basegfx::BColor aLineColor )
{
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 );
return basegfx::tools::hsl2rgb( aHslLine );
}
void lcl_DrawBackground( OutputDevice* pOut, const Rectangle& rRect, bool bHeader )
{
// Colors
basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor();
basegfx::BColor aFillColor = lcl_GetFillColor( aLineColor );
// Draw the background rect
pOut->SetFillColor( Color ( aFillColor ) );
pOut->SetLineColor( Color ( aFillColor ) );
pOut->DrawRect( rRect );
// Draw the lines around the rect
pOut->SetLineColor( Color( aLineColor ) );
basegfx::B2DPolygon aPolygon;
aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Top() ) );
aPolygon.append( basegfx::B2DPoint( rRect.Left(), rRect.Bottom() ) );
pOut->DrawPolyLine( aPolygon, 1.0 );
aPolygon.clear();
aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Top() ) );
aPolygon.append( basegfx::B2DPoint( rRect.Right(), rRect.Bottom() ) );
pOut->DrawPolyLine( aPolygon, 1.0 );
long nYLine = rRect.Bottom();
if ( !bHeader )
nYLine = rRect.Top();
aPolygon.clear();
aPolygon.append( basegfx::B2DPoint( rRect.Left(), nYLine ) );
aPolygon.append( basegfx::B2DPoint( rRect.Right(), nYLine ) );
pOut->DrawPolyLine( aPolygon, 1.0 );
}
}
class SwHeaderFooterButton : public MenuButton
{
SwHeaderFooterWin* m_pWindow;
public:
SwHeaderFooterButton( SwHeaderFooterWin* pWindow );
~SwHeaderFooterButton( );
virtual void Paint( const Rectangle& rRect );
};
// 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 ) :
Window( pEditWin, WB_DIALOGCONTROL ),
m_pEditWin( pEditWin ),
m_sLabel( ),
m_pPageFrm( pPageFrm ),
m_bIsHeader( bHeader ),
m_pButton( NULL )
{
// 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 text to show
m_sLabel = ResId::toString( SW_RES( STR_HEADER_TITLE ) );
if ( !m_bIsHeader )
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() );
// 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 )
nYFooterOff = aBoxSize.Height();
Point aBoxPos( aOffset.X() - aBoxSize.Width() - BOX_DISTANCE,
aOffset.Y() - nYFooterOff );
// Set the position & Size of the window
SetPosSizePixel( aBoxPos, aBoxSize );
// Add the menu button
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;
}
void SwHeaderFooterWin::Paint( const Rectangle& )
{
const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
lcl_DrawBackground( this, aRect, m_bIsHeader );
// Draw the text
Rectangle aTextRect;
GetTextBoundRect( aTextRect, String( m_sLabel ) );
Point aTextPos = aTextRect.TopLeft() + Point( TEXT_PADDING, 0 );
basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor();
SetTextColor( Color( aLineColor ) );
DrawText( aTextPos, String( m_sLabel ) );
}
bool SwHeaderFooterWin::IsEmptyHeaderFooter( )
{
bool bResult = true;
// Actually check it
const SwPageDesc* pDesc = m_pPageFrm->GetPageDesc();
const SwFrmFmt* pFmt = pDesc->GetLeftFmt();
if ( m_pPageFrm->OnRightPage() )
pFmt = pDesc->GetRightFmt();
if ( pFmt )
{
if ( m_bIsHeader )
bResult = !pFmt->GetHeader().IsActive();
else
bResult = !pFmt->GetFooter().IsActive();
}
return bResult;
}
SwHeaderFooterButton::SwHeaderFooterButton( SwHeaderFooterWin* pWindow ) :
MenuButton( pWindow ),
m_pWindow( pWindow )
{
}
SwHeaderFooterButton::~SwHeaderFooterButton( )
{
}
void SwHeaderFooterButton::Paint( const Rectangle& )
{
const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
lcl_DrawBackground( this, aRect, m_pWindow->IsHeader() );
Rectangle aSymbolRect( aRect );
// 25% distance to the left and right button border
const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth()*250)+500)/1000;
aSymbolRect.Left()+=nBorderDistanceLeftAndRight;
aSymbolRect.Right()-=nBorderDistanceLeftAndRight;
// 30% distance to the top button border
const long nBorderDistanceTop = ((aSymbolRect.GetHeight()*300)+500)/1000;
aSymbolRect.Top()+=nBorderDistanceTop;
// 25% distance to the bottom button border
const long nBorderDistanceBottom = ((aSymbolRect.GetHeight()*250)+500)/1000;
aSymbolRect.Bottom()-=nBorderDistanceBottom;
if ( m_pWindow->IsEmptyHeaderFooter( ) )
{
SvtResId id( BMP_LIST_ADD );
Image aPlusImg( id );
Size aSize = aPlusImg.GetSizePixel();
Point aPt = aRect.TopLeft();
long nXOffset = ( aRect.GetWidth() - aSize.Width() ) / 2;
long nYOffset = ( aRect.GetHeight() - aSize.Height() ) / 2;
aPt += Point( nXOffset, nYOffset );
DrawImage(aPt, aPlusImg);
}
else
{
DecorationView aDecoView( this );
aDecoView.DrawSymbol( aSymbolRect, SYMBOL_SPIN_DOWN,
( Application::GetSettings().GetStyleSettings().GetHighContrastMode()
? Color( COL_WHITE )
: Color( COL_BLACK ) ) );
}
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|