Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/bitmap.hxx>
30 : : #include <editeng/frmdiritem.hxx>
31 : : #include <svx/pageitem.hxx>
32 : : #include <svx/pagectrl.hxx>
33 : : #include <editeng/boxitem.hxx>
34 : :
35 : : #include <algorithm>
36 : :
37 : : // struct PageWindow_Impl ------------------------------------------------
38 : :
39 : 0 : struct PageWindow_Impl
40 : : {
41 : : SvxBoxItem* pBorder;
42 : : Bitmap aBitmap;
43 : : bool bBitmap;
44 : : sal_Bool bResetBackground;
45 : : sal_Bool bFrameDirection;
46 : : sal_Int32 nFrameDirection;
47 : :
48 : :
49 : 0 : PageWindow_Impl() :
50 : : pBorder(0),
51 : : bBitmap(sal_False),
52 : : bResetBackground(sal_False),
53 : : bFrameDirection(sal_False),
54 : 0 : nFrameDirection(0) {}
55 : :
56 : 0 : void EnableFrameDirection(sal_Bool bEnable){bFrameDirection = bEnable;}
57 : 0 : void SetFrameDirection(sal_Int32 nDirection){nFrameDirection = nDirection;}
58 : :
59 : : };
60 : :
61 : : // STATIC DATA -----------------------------------------------------------
62 : :
63 : : #define CELL_WIDTH 1600L
64 : : #define CELL_HEIGHT 800L
65 : :
66 : : // class SvxPageWindow ---------------------------------------------------
67 : :
68 : 0 : SvxPageWindow::SvxPageWindow( Window* pParent, const ResId& rId ) :
69 : :
70 : : Window( pParent, rId ),
71 : :
72 : : nTop ( 0 ),
73 : : nBottom ( 0 ),
74 : : nLeft ( 0 ),
75 : : nRight ( 0 ),
76 : : aColor ( COL_TRANSPARENT ),
77 : : nHdLeft ( 0 ),
78 : : nHdRight ( 0 ),
79 : : nHdDist ( 0 ),
80 : : nHdHeight ( 0 ),
81 : : aHdColor ( COL_TRANSPARENT ),
82 : : pHdBorder ( 0 ),
83 : : nFtLeft ( 0 ),
84 : : nFtRight ( 0 ),
85 : : nFtDist ( 0 ),
86 : : nFtHeight ( 0 ),
87 : : aFtColor ( COL_TRANSPARENT ),
88 : : pFtBorder ( 0 ),
89 : : bFooter ( sal_False ),
90 : : bHeader ( sal_False ),
91 : : bTable ( sal_False ),
92 : : bHorz ( sal_False ),
93 : : bVert ( sal_False ),
94 [ # # ][ # # ]: 0 : eUsage ( SVX_PAGE_ALL )
95 : :
96 : : {
97 [ # # ][ # # ]: 0 : pImpl = new PageWindow_Impl;
98 : :
99 : : // Count in Twips by default
100 [ # # ][ # # ]: 0 : SetMapMode( MapMode( MAP_TWIP ) );
[ # # ]
101 : 0 : aWinSize = GetOutputSizePixel();
102 : 0 : aWinSize.Height() -= 4;
103 : 0 : aWinSize.Width() -= 4;
104 : :
105 [ # # ]: 0 : aWinSize = PixelToLogic( aWinSize );
106 [ # # ]: 0 : SetBackground();
107 : 0 : }
108 : :
109 : : // -----------------------------------------------------------------------
110 : :
111 [ # # ][ # # ]: 0 : SvxPageWindow::~SvxPageWindow()
112 : : {
113 [ # # ][ # # ]: 0 : delete pImpl;
114 [ # # ][ # # ]: 0 : delete pHdBorder;
115 [ # # ][ # # ]: 0 : delete pFtBorder;
116 [ # # ]: 0 : }
117 : :
118 : : // -----------------------------------------------------------------------
119 : :
120 : 0 : void SvxPageWindow::Paint( const Rectangle& )
121 : : {
122 [ # # ][ # # ]: 0 : Fraction aXScale( aWinSize.Width(), std::max( (long) (aSize.Width() * 2 + aSize.Width() / 8), 1L ) );
123 [ # # ][ # # ]: 0 : Fraction aYScale( aWinSize.Height(), std::max( aSize.Height(), 1L ) );
124 [ # # ]: 0 : MapMode aMapMode( GetMapMode() );
125 : :
126 [ # # ][ # # ]: 0 : if ( aYScale < aXScale )
127 : : {
128 [ # # ]: 0 : aMapMode.SetScaleX( aYScale );
129 [ # # ]: 0 : aMapMode.SetScaleY( aYScale );
130 : : }
131 : : else
132 : : {
133 [ # # ]: 0 : aMapMode.SetScaleX( aXScale );
134 [ # # ]: 0 : aMapMode.SetScaleY( aXScale );
135 : : }
136 [ # # ]: 0 : SetMapMode( aMapMode );
137 [ # # ][ # # ]: 0 : Size aSz( PixelToLogic( GetSizePixel() ) );
138 : 0 : long nYPos = ( aSz.Height() - aSize.Height() ) / 2;
139 : :
140 [ # # ]: 0 : if ( eUsage == SVX_PAGE_ALL )
141 : : {
142 : : // all pages are equal -> draw one page
143 [ # # ]: 0 : if ( aSize.Width() > aSize.Height() )
144 : : {
145 : : // Draw Landscape page of the same size
146 [ # # ]: 0 : Fraction aX = aMapMode.GetScaleX();
147 [ # # ]: 0 : Fraction aY = aMapMode.GetScaleY();
148 [ # # ]: 0 : Fraction a2( 1.5 );
149 [ # # ]: 0 : aX *= a2;
150 [ # # ]: 0 : aY *= a2;
151 [ # # ]: 0 : aMapMode.SetScaleX( aX );
152 [ # # ]: 0 : aMapMode.SetScaleY( aY );
153 [ # # ]: 0 : SetMapMode( aMapMode );
154 [ # # ][ # # ]: 0 : aSz = PixelToLogic( GetSizePixel() );
155 : 0 : nYPos = ( aSz.Height() - aSize.Height() ) / 2;
156 : 0 : long nXPos = ( aSz.Width() - aSize.Width() ) / 2;
157 [ # # ]: 0 : DrawPage( Point( nXPos, nYPos ), sal_True, sal_True );
158 : : }
159 : : else
160 : : // Portrait
161 [ # # ]: 0 : DrawPage( Point( ( aSz.Width() - aSize.Width() ) / 2, nYPos ), sal_True, sal_True );
162 : : }
163 : : else
164 : : {
165 : : // Left and right page are different -> draw two pages if possible
166 [ # # ]: 0 : DrawPage( Point( 0, nYPos ), sal_False, (sal_Bool)( eUsage & SVX_PAGE_LEFT ) );
167 : 0 : DrawPage( Point( aSize.Width() + aSize.Width() / 8, nYPos ), sal_True,
168 [ # # ]: 0 : (sal_Bool)( eUsage & SVX_PAGE_RIGHT ) );
169 [ # # ]: 0 : }
170 : 0 : }
171 : :
172 : : // -----------------------------------------------------------------------
173 : 0 : void SvxPageWindow::DrawPage( const Point& rOrg, const sal_Bool bSecond, const sal_Bool bEnabled )
174 : : {
175 : 0 : const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
176 : 0 : const Color& rFieldColor = rStyleSettings.GetFieldColor();
177 : 0 : const Color& rFieldTextColor = rStyleSettings.GetFieldTextColor();
178 : 0 : const Color& rDisableColor = rStyleSettings.GetDisableColor();
179 : 0 : const Color& rDlgColor = rStyleSettings.GetDialogColor();
180 : :
181 : : // background
182 [ # # ][ # # ]: 0 : if(!bSecond || pImpl->bResetBackground)
183 : : {
184 [ # # ]: 0 : SetLineColor( Color(COL_TRANSPARENT) );
185 [ # # ]: 0 : SetFillColor( rDlgColor );
186 [ # # ]: 0 : Size winSize(GetOutputSize());
187 [ # # ][ # # ]: 0 : DrawRect( Rectangle( Point(0,0), winSize ) );
188 : :
189 [ # # ]: 0 : if ( pImpl->bResetBackground )
190 : 0 : pImpl->bResetBackground = sal_False;
191 : : }
192 [ # # ]: 0 : SetLineColor( rFieldTextColor );
193 : : // Shadow
194 : 0 : Size aTempSize = aSize;
195 : : // Page
196 [ # # ]: 0 : if ( !bEnabled )
197 : : {
198 [ # # ]: 0 : SetFillColor( rDisableColor );
199 [ # # ][ # # ]: 0 : DrawRect( Rectangle( rOrg, aTempSize ) );
200 : 0 : return;
201 : : }
202 [ # # ]: 0 : SetFillColor( rFieldColor );
203 [ # # ][ # # ]: 0 : DrawRect( Rectangle( rOrg, aTempSize ) );
204 : :
205 : 0 : long nL = nLeft;
206 : 0 : long nR = nRight;
207 : :
208 [ # # ][ # # ]: 0 : if ( eUsage == SVX_PAGE_MIRROR && !bSecond )
209 : : {
210 : : // turn for mirrored
211 : 0 : nL = nRight;
212 : 0 : nR = nLeft;
213 : : }
214 : :
215 [ # # ]: 0 : Rectangle aRect;
216 : :
217 : 0 : aRect.Left() = rOrg.X() + nL;
218 : 0 : aRect.Right() = rOrg.X() + aTempSize.Width() - nR;
219 : 0 : aRect.Top() = rOrg.Y() + nTop;
220 : 0 : aRect.Bottom()= rOrg.Y() + aTempSize.Height() - nBottom;
221 : :
222 : 0 : Rectangle aHdRect( aRect );
223 : 0 : Rectangle aFtRect( aRect );
224 : :
225 [ # # ]: 0 : if ( bHeader )
226 : : {
227 : : // show headers if possible
228 : 0 : aHdRect.Left() += nHdLeft;
229 : 0 : aHdRect.Right() -= nHdRight;
230 : 0 : aHdRect.Bottom() = aRect.Top() + nHdHeight;
231 : 0 : aRect.Top() += nHdHeight + nHdDist;
232 [ # # ]: 0 : SetFillColor( aHdColor );
233 [ # # ]: 0 : DrawRect( aHdRect );
234 : : }
235 : :
236 [ # # ]: 0 : if ( bFooter )
237 : : {
238 : : // show footer if possible
239 : 0 : aFtRect.Left() += nFtLeft;
240 : 0 : aFtRect.Right() -= nFtRight;
241 : 0 : aFtRect.Top() = aRect.Bottom() - nFtHeight;
242 : 0 : aRect.Bottom() -= nFtHeight + nFtDist;
243 [ # # ]: 0 : SetFillColor( aFtColor );
244 [ # # ]: 0 : DrawRect( aFtRect );
245 : : }
246 : :
247 : : // Paint Body
248 [ # # ]: 0 : SetFillColor( aColor );
249 [ # # ]: 0 : if ( pImpl->bBitmap )
250 : : {
251 [ # # ]: 0 : DrawRect( aRect );
252 : 0 : Point aBmpPnt = aRect.TopLeft();
253 [ # # ]: 0 : Size aBmpSiz = aRect.GetSize();
254 : 0 : long nDeltaX = aBmpSiz.Width() / 15;
255 : 0 : long nDeltaY = aBmpSiz.Height() / 15;
256 : 0 : aBmpPnt.X() += nDeltaX;
257 : 0 : aBmpPnt.Y() += nDeltaY;
258 : 0 : aBmpSiz.Width() -= nDeltaX * 2;
259 : 0 : aBmpSiz.Height() -= nDeltaY * 2;
260 [ # # ]: 0 : DrawBitmap( aBmpPnt, aBmpSiz, pImpl->aBitmap );
261 : : }
262 : : else
263 [ # # ]: 0 : DrawRect( aRect );
264 : :
265 [ # # ][ # # ]: 0 : if(pImpl->bFrameDirection && !bTable)
266 : : {
267 : 0 : Point aPos;
268 [ # # ]: 0 : Font aFont(GetFont());
269 [ # # ]: 0 : const Size aSaveSize = aFont.GetSize();
270 [ # # ]: 0 : Size aDrawSize( 0, aRect.GetHeight() / 6);
271 [ # # ]: 0 : aFont.SetSize(aDrawSize);
272 [ # # ]: 0 : SetFont(aFont);
273 [ # # ]: 0 : String sText(rtl::OUString("ABC"));
274 [ # # ]: 0 : Point aMove(1, GetTextHeight());
275 : 0 : sal_Unicode cArrow = 0x2193;
276 [ # # ][ # # ]: 0 : long nAWidth = GetTextWidth(rtl::OUString(sText.GetChar(0)));
[ # # ]
277 [ # # # # : 0 : switch(pImpl->nFrameDirection)
# ]
278 : : {
279 : : case FRMDIR_HORI_LEFT_TOP:
280 : 0 : aPos = aRect.TopLeft();
281 [ # # ]: 0 : aPos.X() += PixelToLogic(Point(1,1)).X();
282 : 0 : aMove.Y() = 0;
283 : 0 : cArrow = 0x2192;
284 : 0 : break;
285 : : case FRMDIR_HORI_RIGHT_TOP:
286 [ # # ]: 0 : aPos = aRect.TopRight();
287 : 0 : aPos.X() -= nAWidth;
288 : 0 : aMove.Y() = 0;
289 : 0 : aMove.X() *= -1;
290 : 0 : cArrow = 0x2190;
291 : 0 : break;
292 : : case FRMDIR_VERT_TOP_LEFT:
293 : 0 : aPos = aRect.TopLeft();
294 [ # # ]: 0 : aPos.X() += PixelToLogic(Point(1,1)).X();
295 : 0 : aMove.X() = 0;
296 : 0 : break;
297 : : case FRMDIR_VERT_TOP_RIGHT:
298 [ # # ]: 0 : aPos = aRect.TopRight();
299 : 0 : aPos.X() -= nAWidth;
300 : 0 : aMove.X() = 0;
301 : 0 : break;
302 : : }
303 [ # # ]: 0 : sText.Append(cArrow);
304 [ # # ]: 0 : for(sal_uInt16 i = 0; i < sText.Len(); i++)
305 : : {
306 : 0 : rtl::OUString sDraw(sText.GetChar(i));
307 : 0 : long nHDiff = 0;
308 [ # # ][ # # ]: 0 : long nCharWidth = GetTextWidth(sDraw);
[ # # ]
309 : 0 : sal_Bool bHorizontal = 0 == aMove.Y();
310 [ # # ]: 0 : if(!bHorizontal)
311 : : {
312 : 0 : nHDiff = (nAWidth - nCharWidth)/2;
313 : 0 : aPos.X() += nHDiff;
314 : : }
315 [ # # ][ # # ]: 0 : DrawText(aPos, sDraw);
[ # # ]
316 [ # # ]: 0 : if(bHorizontal)
317 : : {
318 [ # # ]: 0 : aPos.X() += aMove.X() < 0 ? - nCharWidth : nCharWidth;
319 : : }
320 : : else
321 : : {
322 : 0 : aPos.X() -= nHDiff;
323 : 0 : aPos.Y() += aMove.Y();
324 : : }
325 : 0 : }
326 [ # # ]: 0 : aFont.SetSize(aSaveSize);
327 [ # # ][ # # ]: 0 : SetFont(aFont);
[ # # ]
328 : :
329 : : }
330 [ # # ]: 0 : if ( bTable )
331 : : {
332 : : // Paint Table, if necessary center it
333 [ # # ]: 0 : SetLineColor( Color(COL_LIGHTGRAY) );
334 : :
335 [ # # ][ # # ]: 0 : long nW = aRect.GetWidth(), nH = aRect.GetHeight();
336 : 0 : long nTW = CELL_WIDTH * 3, nTH = CELL_HEIGHT * 3;
337 [ # # ]: 0 : long _nLeft = bHorz ? aRect.Left() + ((nW - nTW) / 2) : aRect.Left();
338 [ # # ]: 0 : long _nTop = bVert ? aRect.Top() + ((nH - nTH) / 2) : aRect.Top();
339 [ # # ]: 0 : Rectangle aCellRect( Point( _nLeft, _nTop ), Size( CELL_WIDTH, CELL_HEIGHT ) );
340 : :
341 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < 3; ++i )
342 : : {
343 : 0 : aCellRect.Left() = _nLeft;
344 : 0 : aCellRect.Right() = _nLeft + CELL_WIDTH;
345 [ # # ]: 0 : if ( i > 0 )
346 [ # # ]: 0 : aCellRect.Move( 0, CELL_HEIGHT );
347 : :
348 [ # # ]: 0 : for ( sal_uInt16 j = 0; j < 3; ++j )
349 : : {
350 [ # # ]: 0 : if ( j > 0 )
351 [ # # ]: 0 : aCellRect.Move( CELL_WIDTH, 0 );
352 [ # # ]: 0 : DrawRect( aCellRect );
353 : : }
354 : : }
355 : : }
356 : : }
357 : :
358 : : // -----------------------------------------------------------------------
359 : :
360 : 0 : void SvxPageWindow::SetBorder( const SvxBoxItem& rNew )
361 : : {
362 [ # # ]: 0 : delete pImpl->pBorder;
363 [ # # ]: 0 : pImpl->pBorder = new SvxBoxItem( rNew );
364 : 0 : }
365 : :
366 : : // -----------------------------------------------------------------------
367 : :
368 : 0 : void SvxPageWindow::SetBitmap( Bitmap* pBmp )
369 : : {
370 [ # # ]: 0 : if ( pBmp )
371 : : {
372 : 0 : pImpl->aBitmap = *pBmp;
373 : 0 : pImpl->bBitmap = sal_True;
374 : : }
375 : : else
376 : 0 : pImpl->bBitmap = sal_False;
377 : 0 : }
378 : :
379 : : // -----------------------------------------------------------------------
380 : :
381 : 0 : void SvxPageWindow::SetHdBorder( const SvxBoxItem& rNew )
382 : : {
383 [ # # ]: 0 : delete pHdBorder;
384 [ # # ]: 0 : pHdBorder = new SvxBoxItem( rNew );
385 : 0 : }
386 : : // -----------------------------------------------------------------------
387 : :
388 : 0 : void SvxPageWindow::SetFtBorder( const SvxBoxItem& rNew )
389 : : {
390 [ # # ]: 0 : delete pFtBorder;
391 [ # # ]: 0 : pFtBorder = new SvxBoxItem( rNew );
392 : 0 : }
393 : :
394 : 0 : void SvxPageWindow::EnableFrameDirection(sal_Bool bEnable)
395 : : {
396 : 0 : pImpl->EnableFrameDirection(bEnable);
397 : 0 : }
398 : :
399 : 0 : void SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection)
400 : : {
401 : 0 : pImpl->SetFrameDirection(nFrameDirection);
402 : 0 : }
403 : :
404 : 0 : void SvxPageWindow::ResetBackground()
405 : : {
406 : 0 : pImpl->bResetBackground = sal_True;
407 : 0 : }
408 : :
409 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|