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