Update ooo320-m1
[ooovba.git] / svx / source / dialog / pagectrl.cxx
bloba7cb2f0c694604c6949dba5fb80813818473a9cf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pagectrl.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 // include ---------------------------------------------------------------
37 #include <vcl/bitmap.hxx>
38 #include <svx/frmdiritem.hxx>
39 #include <svx/pageitem.hxx>
40 #include <svx/pagectrl.hxx>
41 #include <svx/boxitem.hxx>
43 #include <algorithm>
45 // struct PageWindow_Impl ------------------------------------------------
47 struct PageWindow_Impl
49 SvxBoxItem* pBorder;
50 Bitmap aBitmap;
51 FASTBOOL bBitmap;
52 sal_Bool bResetBackground;
53 sal_Bool bFrameDirection;
54 sal_Int32 nFrameDirection;
57 PageWindow_Impl() :
58 pBorder(0),
59 bBitmap(FALSE),
60 bResetBackground(sal_False),
61 bFrameDirection(sal_False),
62 nFrameDirection(0) {}
64 void EnableFrameDirection(sal_Bool bEnable){bFrameDirection = bEnable;}
65 void SetFrameDirection(sal_Int32 nDirection){nFrameDirection = nDirection;}
69 // STATIC DATA -----------------------------------------------------------
71 #define CELL_WIDTH 1600L
72 #define CELL_HEIGHT 800L
74 // class SvxPageWindow ---------------------------------------------------
76 SvxPageWindow::SvxPageWindow( Window* pParent, const ResId& rId ) :
78 Window( pParent, rId ),
80 nTop ( 0 ),
81 nBottom ( 0 ),
82 nLeft ( 0 ),
83 nRight ( 0 ),
84 aColor ( COL_TRANSPARENT ),
85 nHdLeft ( 0 ),
86 nHdRight ( 0 ),
87 nHdDist ( 0 ),
88 nHdHeight ( 0 ),
89 aHdColor ( COL_TRANSPARENT ),
90 pHdBorder ( 0 ),
91 nFtLeft ( 0 ),
92 nFtRight ( 0 ),
93 nFtDist ( 0 ),
94 nFtHeight ( 0 ),
95 aFtColor ( COL_TRANSPARENT ),
96 pFtBorder ( 0 ),
97 bFooter ( FALSE ),
98 bHeader ( FALSE ),
99 bTable ( FALSE ),
100 bHorz ( FALSE ),
101 bVert ( FALSE ),
102 eUsage ( SVX_PAGE_ALL )
105 pImpl = new PageWindow_Impl;
107 // defaultmaessing in Twips rechnen
108 SetMapMode( MapMode( MAP_TWIP ) );
109 aWinSize = GetOutputSizePixel();
110 aWinSize.Height() -= 4;
111 aWinSize.Width() -= 4;
113 aWinSize = PixelToLogic( aWinSize );
114 SetBackground();
117 // -----------------------------------------------------------------------
119 SvxPageWindow::~SvxPageWindow()
121 delete pImpl;
122 delete pHdBorder;
123 delete pFtBorder;
126 // -----------------------------------------------------------------------
128 void __EXPORT SvxPageWindow::Paint( const Rectangle& )
130 Fraction aXScale( aWinSize.Width(), std::max( (long) (aSize.Width() * 2 + aSize.Width() / 8), 1L ) );
131 Fraction aYScale( aWinSize.Height(), std::max( aSize.Height(), 1L ) );
132 MapMode aMapMode( GetMapMode() );
134 if ( aYScale < aXScale )
136 aMapMode.SetScaleX( aYScale );
137 aMapMode.SetScaleY( aYScale );
139 else
141 aMapMode.SetScaleX( aXScale );
142 aMapMode.SetScaleY( aXScale );
144 SetMapMode( aMapMode );
145 Size aSz( PixelToLogic( GetSizePixel() ) );
146 long nYPos = ( aSz.Height() - aSize.Height() ) / 2;
148 if ( eUsage == SVX_PAGE_ALL )
150 // alle Seiten gleich -> eine Seite malen
151 if ( aSize.Width() > aSize.Height() )
153 // Querformat in gleicher Gr"osse zeichnen
154 Fraction aX = aMapMode.GetScaleX();
155 Fraction aY = aMapMode.GetScaleY();
156 Fraction a2( 1.5 );
157 aX *= a2;
158 aY *= a2;
159 aMapMode.SetScaleX( aX );
160 aMapMode.SetScaleY( aY );
161 SetMapMode( aMapMode );
162 aSz = PixelToLogic( GetSizePixel() );
163 nYPos = ( aSz.Height() - aSize.Height() ) / 2;
164 long nXPos = ( aSz.Width() - aSize.Width() ) / 2;
165 DrawPage( Point( nXPos, nYPos ), TRUE, TRUE );
167 else
168 // Hochformat
169 DrawPage( Point( ( aSz.Width() - aSize.Width() ) / 2, nYPos ), TRUE, TRUE );
171 else
173 // Linke und rechte Seite unterschiedlich -> ggf. zwei Seiten malen
174 DrawPage( Point( 0, nYPos ), FALSE, (BOOL)( eUsage & SVX_PAGE_LEFT ) );
175 DrawPage( Point( aSize.Width() + aSize.Width() / 8, nYPos ), TRUE,
176 (BOOL)( eUsage & SVX_PAGE_RIGHT ) );
180 // -----------------------------------------------------------------------
181 void SvxPageWindow::DrawPage( const Point& rOrg, const BOOL bSecond, const BOOL bEnabled )
183 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
184 const Color& rFieldColor = rStyleSettings.GetFieldColor();
185 const Color& rFieldTextColor = rStyleSettings.GetFieldTextColor();
186 const Color& rDisableColor = rStyleSettings.GetDisableColor();
187 const Color& rDlgColor = rStyleSettings.GetDialogColor();
189 // background
190 if(!bSecond || pImpl->bResetBackground)
192 SetLineColor( Color(COL_TRANSPARENT) );
193 SetFillColor( rDlgColor );
194 Size winSize(GetOutputSize());
195 DrawRect( Rectangle( Point(0,0), winSize ) );
197 if ( pImpl->bResetBackground )
198 pImpl->bResetBackground = sal_False;
200 SetLineColor( rFieldTextColor );
201 // Schatten
202 Size aTempSize = aSize;
203 // Seite
204 if ( !bEnabled )
206 SetFillColor( rDisableColor );
207 DrawRect( Rectangle( rOrg, aTempSize ) );
208 return;
210 SetFillColor( rFieldColor );
211 DrawRect( Rectangle( rOrg, aTempSize ) );
213 // Border Top Bottom Left Right
214 Point aBegin( rOrg );
215 Point aEnd( rOrg );
217 long nL = nLeft;
218 long nR = nRight;
220 if ( eUsage == SVX_PAGE_MIRROR && !bSecond )
222 // f"ur gespiegelt drehen
223 nL = nRight;
224 nR = nLeft;
227 Rectangle aRect;
229 aRect.Left() = rOrg.X() + nL;
230 aRect.Right() = rOrg.X() + aTempSize.Width() - nR;
231 aRect.Top() = rOrg.Y() + nTop;
232 aRect.Bottom()= rOrg.Y() + aTempSize.Height() - nBottom;
234 Rectangle aHdRect( aRect );
235 Rectangle aFtRect( aRect );
237 if ( bHeader )
239 // ggf. Header anzeigen
240 aHdRect.Left() += nHdLeft;
241 aHdRect.Right() -= nHdRight;
242 aHdRect.Bottom() = aRect.Top() + nHdHeight;
243 aRect.Top() += nHdHeight + nHdDist;
244 SetFillColor( aHdColor );
245 DrawRect( aHdRect );
248 if ( bFooter )
250 // ggf. Footer anzeigen
251 aFtRect.Left() += nFtLeft;
252 aFtRect.Right() -= nFtRight;
253 aFtRect.Top() = aRect.Bottom() - nFtHeight;
254 aRect.Bottom() -= nFtHeight + nFtDist;
255 SetFillColor( aFtColor );
256 DrawRect( aFtRect );
259 // Body malen
260 SetFillColor( aColor );
261 if ( pImpl->bBitmap )
263 DrawRect( aRect );
264 Point aBmpPnt = aRect.TopLeft();
265 Size aBmpSiz = aRect.GetSize();
266 long nDeltaX = aBmpSiz.Width() / 15;
267 long nDeltaY = aBmpSiz.Height() / 15;
268 aBmpPnt.X() += nDeltaX;
269 aBmpPnt.Y() += nDeltaY;
270 aBmpSiz.Width() -= nDeltaX * 2;
271 aBmpSiz.Height() -= nDeltaY * 2;
272 DrawBitmap( aBmpPnt, aBmpSiz, pImpl->aBitmap );
274 else
275 DrawRect( aRect );
277 if(pImpl->bFrameDirection && !bTable)
279 //pImpl->nFrameDirection
280 Point aPos;
281 Font aFont(GetFont());
282 const Size aSaveSize = aFont.GetSize();
283 Size aDrawSize( 0, aRect.GetHeight() / 6);
284 aFont.SetSize(aDrawSize);
285 SetFont(aFont);
286 String sText(String::CreateFromAscii("ABC"));
287 Point aMove(1, GetTextHeight());
288 sal_Unicode cArrow = 0x2193;
289 long nAWidth = GetTextWidth(String(sText.GetChar(0)));
290 switch(pImpl->nFrameDirection)
292 case FRMDIR_HORI_LEFT_TOP:
293 aPos = aRect.TopLeft();
294 aPos.X() += PixelToLogic(Point(1,1)).X();
295 aMove.Y() = 0;
296 cArrow = 0x2192;
297 break;
298 case FRMDIR_HORI_RIGHT_TOP:
299 aPos = aRect.TopRight();
300 aPos.X() -= nAWidth;
301 aMove.Y() = 0;
302 aMove.X() *= -1;
303 cArrow = 0x2190;
304 break;
305 case FRMDIR_VERT_TOP_LEFT:
306 aPos = aRect.TopLeft();
307 aPos.X() += PixelToLogic(Point(1,1)).X();
308 aMove.X() = 0;
309 break;
310 case FRMDIR_VERT_TOP_RIGHT:
311 aPos = aRect.TopRight();
312 aPos.X() -= nAWidth;
313 aMove.X() = 0;
314 break;
316 sText.Append(cArrow);
317 for(USHORT i = 0; i < sText.Len(); i++)
319 String sDraw(sText.GetChar(i));
320 long nHDiff = 0;
321 long nCharWidth = GetTextWidth(sDraw);
322 BOOL bHorizontal = 0 == aMove.Y();
323 if(!bHorizontal)
325 nHDiff = (nAWidth - nCharWidth)/2;
326 aPos.X() += nHDiff;
328 DrawText(aPos, sDraw);
329 if(bHorizontal)
331 aPos.X() += aMove.X() < 0 ? - nCharWidth : nCharWidth;
333 else
335 aPos.X() -= nHDiff;
336 aPos.Y() += aMove.Y();
339 aFont.SetSize(aSaveSize);
340 SetFont(aFont);
343 if ( bTable )
345 // Tabelle malen, ggf. zentrieren
346 SetLineColor( Color(COL_LIGHTGRAY) );
348 long nW = aRect.GetWidth(), nH = aRect.GetHeight();
349 long nTW = CELL_WIDTH * 3, nTH = CELL_HEIGHT * 3;
350 long _nLeft = bHorz ? aRect.Left() + ((nW - nTW) / 2) : aRect.Left();
351 long _nTop = bVert ? aRect.Top() + ((nH - nTH) / 2) : aRect.Top();
352 Rectangle aCellRect( Point( _nLeft, _nTop ), Size( CELL_WIDTH, CELL_HEIGHT ) );
354 for ( USHORT i = 0; i < 3; ++i )
356 aCellRect.Left() = _nLeft;
357 aCellRect.Right() = _nLeft + CELL_WIDTH;
358 if ( i > 0 )
359 aCellRect.Move( 0, CELL_HEIGHT );
361 for ( USHORT j = 0; j < 3; ++j )
363 if ( j > 0 )
364 aCellRect.Move( CELL_WIDTH, 0 );
365 DrawRect( aCellRect );
371 // -----------------------------------------------------------------------
373 void SvxPageWindow::SetBorder( const SvxBoxItem& rNew )
375 delete pImpl->pBorder;
376 pImpl->pBorder = new SvxBoxItem( rNew );
379 // -----------------------------------------------------------------------
381 void SvxPageWindow::SetBitmap( Bitmap* pBmp )
383 if ( pBmp )
385 pImpl->aBitmap = *pBmp;
386 pImpl->bBitmap = TRUE;
388 else
389 pImpl->bBitmap = FALSE;
392 // -----------------------------------------------------------------------
394 void SvxPageWindow::SetHdBorder( const SvxBoxItem& rNew )
396 delete pHdBorder;
397 pHdBorder = new SvxBoxItem( rNew );
399 // -----------------------------------------------------------------------
401 void SvxPageWindow::SetFtBorder( const SvxBoxItem& rNew )
403 delete pFtBorder;
404 pFtBorder = new SvxBoxItem( rNew );
406 /* -----------------------------13.06.2002 16:16------------------------------
408 ---------------------------------------------------------------------------*/
409 void SvxPageWindow::EnableFrameDirection(sal_Bool bEnable)
411 pImpl->EnableFrameDirection(bEnable);
413 /* -----------------------------13.06.2002 16:16------------------------------
415 ---------------------------------------------------------------------------*/
416 void SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection)
418 pImpl->SetFrameDirection(nFrameDirection);
421 void SvxPageWindow::ResetBackground()
423 pImpl->bResetBackground = sal_True;