1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
28 // struct PageWindow_Impl ------------------------------------------------
30 struct PageWindow_Impl
35 bool bResetBackground
;
36 sal_Bool bFrameDirection
;
37 sal_Int32 nFrameDirection
;
43 bResetBackground(false),
44 bFrameDirection(sal_False
),
47 void EnableFrameDirection(sal_Bool bEnable
){bFrameDirection
= bEnable
;}
48 void SetFrameDirection(sal_Int32 nDirection
){nFrameDirection
= nDirection
;}
52 // STATIC DATA -----------------------------------------------------------
54 #define CELL_WIDTH 1600L
55 #define CELL_HEIGHT 800L
57 // class SvxPageWindow ---------------------------------------------------
59 SvxPageWindow::SvxPageWindow( Window
* pParent
, const ResId
& rId
) :
61 Window( pParent
, rId
),
67 aColor ( COL_TRANSPARENT
),
72 aHdColor ( COL_TRANSPARENT
),
78 aFtColor ( COL_TRANSPARENT
),
80 bFooter ( sal_False
),
81 bHeader ( sal_False
),
85 eUsage ( SVX_PAGE_ALL
)
88 pImpl
= new PageWindow_Impl
;
90 // Count in Twips by default
91 SetMapMode( MapMode( MAP_TWIP
) );
92 aWinSize
= GetOutputSizePixel();
93 aWinSize
.Height() -= 4;
94 aWinSize
.Width() -= 4;
96 aWinSize
= PixelToLogic( aWinSize
);
100 SvxPageWindow::SvxPageWindow( Window
* pParent
) :
108 aColor ( COL_TRANSPARENT
),
113 aHdColor ( COL_TRANSPARENT
),
119 aFtColor ( COL_TRANSPARENT
),
121 bFooter ( sal_False
),
122 bHeader ( sal_False
),
123 bTable ( sal_False
),
126 eUsage ( SVX_PAGE_ALL
)
128 pImpl
= new PageWindow_Impl
;
130 // Count in Twips by default
131 SetMapMode( MapMode( MAP_TWIP
) );
132 aWinSize
= GetOptimalSize();
133 aWinSize
.Height() -= 4;
134 aWinSize
.Width() -= 4;
136 aWinSize
= PixelToLogic( aWinSize
);
140 // -----------------------------------------------------------------------
142 SvxPageWindow::~SvxPageWindow()
149 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvxPageWindow(Window
*pParent
)
151 return new SvxPageWindow(pParent
);
155 // -----------------------------------------------------------------------
157 void SvxPageWindow::Paint( const Rectangle
& )
159 Fraction
aXScale( aWinSize
.Width(), std::max( (long) (aSize
.Width() * 2 + aSize
.Width() / 8), 1L ) );
160 Fraction
aYScale( aWinSize
.Height(), std::max( aSize
.Height(), 1L ) );
161 MapMode
aMapMode( GetMapMode() );
163 if ( aYScale
< aXScale
)
165 aMapMode
.SetScaleX( aYScale
);
166 aMapMode
.SetScaleY( aYScale
);
170 aMapMode
.SetScaleX( aXScale
);
171 aMapMode
.SetScaleY( aXScale
);
173 SetMapMode( aMapMode
);
174 Size
aSz( PixelToLogic( GetSizePixel() ) );
175 long nYPos
= ( aSz
.Height() - aSize
.Height() ) / 2;
177 if ( eUsage
== SVX_PAGE_ALL
)
179 // all pages are equal -> draw one page
180 if ( aSize
.Width() > aSize
.Height() )
182 // Draw Landscape page of the same size
183 Fraction aX
= aMapMode
.GetScaleX();
184 Fraction aY
= aMapMode
.GetScaleY();
188 aMapMode
.SetScaleX( aX
);
189 aMapMode
.SetScaleY( aY
);
190 SetMapMode( aMapMode
);
191 aSz
= PixelToLogic( GetSizePixel() );
192 nYPos
= ( aSz
.Height() - aSize
.Height() ) / 2;
193 long nXPos
= ( aSz
.Width() - aSize
.Width() ) / 2;
194 DrawPage( Point( nXPos
, nYPos
), sal_True
, sal_True
);
198 DrawPage( Point( ( aSz
.Width() - aSize
.Width() ) / 2, nYPos
), sal_True
, sal_True
);
202 // Left and right page are different -> draw two pages if possible
203 DrawPage( Point( 0, nYPos
), sal_False
, (sal_Bool
)( eUsage
& SVX_PAGE_LEFT
) );
204 DrawPage( Point( aSize
.Width() + aSize
.Width() / 8, nYPos
), sal_True
,
205 (sal_Bool
)( eUsage
& SVX_PAGE_RIGHT
) );
209 // -----------------------------------------------------------------------
210 void SvxPageWindow::DrawPage( const Point
& rOrg
, const sal_Bool bSecond
, const sal_Bool bEnabled
)
212 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
213 const Color
& rFieldColor
= rStyleSettings
.GetFieldColor();
214 const Color
& rFieldTextColor
= rStyleSettings
.GetFieldTextColor();
215 const Color
& rDisableColor
= rStyleSettings
.GetDisableColor();
216 const Color
& rDlgColor
= rStyleSettings
.GetDialogColor();
219 if(!bSecond
|| pImpl
->bResetBackground
)
221 SetLineColor( Color(COL_TRANSPARENT
) );
222 SetFillColor( rDlgColor
);
223 Size
winSize(GetOutputSize());
224 DrawRect( Rectangle( Point(0,0), winSize
) );
226 if ( pImpl
->bResetBackground
)
227 pImpl
->bResetBackground
= false;
229 SetLineColor( rFieldTextColor
);
231 Size aTempSize
= aSize
;
235 SetFillColor( rDisableColor
);
236 DrawRect( Rectangle( rOrg
, aTempSize
) );
239 SetFillColor( rFieldColor
);
240 DrawRect( Rectangle( rOrg
, aTempSize
) );
245 if ( eUsage
== SVX_PAGE_MIRROR
&& !bSecond
)
254 aRect
.Left() = rOrg
.X() + nL
;
255 aRect
.Right() = rOrg
.X() + aTempSize
.Width() - nR
;
256 aRect
.Top() = rOrg
.Y() + nTop
;
257 aRect
.Bottom()= rOrg
.Y() + aTempSize
.Height() - nBottom
;
259 Rectangle
aHdRect( aRect
);
260 Rectangle
aFtRect( aRect
);
264 // show headers if possible
265 aHdRect
.Left() += nHdLeft
;
266 aHdRect
.Right() -= nHdRight
;
267 aHdRect
.Bottom() = aRect
.Top() + nHdHeight
;
268 aRect
.Top() += nHdHeight
+ nHdDist
;
269 SetFillColor( aHdColor
);
275 // show footer if possible
276 aFtRect
.Left() += nFtLeft
;
277 aFtRect
.Right() -= nFtRight
;
278 aFtRect
.Top() = aRect
.Bottom() - nFtHeight
;
279 aRect
.Bottom() -= nFtHeight
+ nFtDist
;
280 SetFillColor( aFtColor
);
285 SetFillColor( aColor
);
286 if ( pImpl
->bBitmap
)
289 Point aBmpPnt
= aRect
.TopLeft();
290 Size aBmpSiz
= aRect
.GetSize();
291 long nDeltaX
= aBmpSiz
.Width() / 15;
292 long nDeltaY
= aBmpSiz
.Height() / 15;
293 aBmpPnt
.X() += nDeltaX
;
294 aBmpPnt
.Y() += nDeltaY
;
295 aBmpSiz
.Width() -= nDeltaX
* 2;
296 aBmpSiz
.Height() -= nDeltaY
* 2;
297 DrawBitmap( aBmpPnt
, aBmpSiz
, pImpl
->aBitmap
);
302 if(pImpl
->bFrameDirection
&& !bTable
)
305 Font
aFont(GetFont());
306 const Size aSaveSize
= aFont
.GetSize();
307 Size
aDrawSize( 0, aRect
.GetHeight() / 6);
308 aFont
.SetSize(aDrawSize
);
310 String
sText(OUString("ABC"));
311 Point
aMove(1, GetTextHeight());
312 sal_Unicode cArrow
= 0x2193;
313 long nAWidth
= GetTextWidth(OUString(sText
.GetChar(0)));
314 switch(pImpl
->nFrameDirection
)
316 case FRMDIR_HORI_LEFT_TOP
:
317 aPos
= aRect
.TopLeft();
318 aPos
.X() += PixelToLogic(Point(1,1)).X();
322 case FRMDIR_HORI_RIGHT_TOP
:
323 aPos
= aRect
.TopRight();
329 case FRMDIR_VERT_TOP_LEFT
:
330 aPos
= aRect
.TopLeft();
331 aPos
.X() += PixelToLogic(Point(1,1)).X();
334 case FRMDIR_VERT_TOP_RIGHT
:
335 aPos
= aRect
.TopRight();
340 sText
.Append(cArrow
);
341 for(sal_uInt16 i
= 0; i
< sText
.Len(); i
++)
343 OUString
sDraw(sText
.GetChar(i
));
345 long nCharWidth
= GetTextWidth(sDraw
);
346 bool bHorizontal
= 0 == aMove
.Y();
349 nHDiff
= (nAWidth
- nCharWidth
)/2;
352 DrawText(aPos
, sDraw
);
355 aPos
.X() += aMove
.X() < 0 ? - nCharWidth
: nCharWidth
;
360 aPos
.Y() += aMove
.Y();
363 aFont
.SetSize(aSaveSize
);
369 // Paint Table, if necessary center it
370 SetLineColor( Color(COL_LIGHTGRAY
) );
372 long nW
= aRect
.GetWidth(), nH
= aRect
.GetHeight();
373 long nTW
= CELL_WIDTH
* 3, nTH
= CELL_HEIGHT
* 3;
374 long _nLeft
= bHorz
? aRect
.Left() + ((nW
- nTW
) / 2) : aRect
.Left();
375 long _nTop
= bVert
? aRect
.Top() + ((nH
- nTH
) / 2) : aRect
.Top();
376 Rectangle
aCellRect( Point( _nLeft
, _nTop
), Size( CELL_WIDTH
, CELL_HEIGHT
) );
378 for ( sal_uInt16 i
= 0; i
< 3; ++i
)
380 aCellRect
.Left() = _nLeft
;
381 aCellRect
.Right() = _nLeft
+ CELL_WIDTH
;
383 aCellRect
.Move( 0, CELL_HEIGHT
);
385 for ( sal_uInt16 j
= 0; j
< 3; ++j
)
388 aCellRect
.Move( CELL_WIDTH
, 0 );
389 DrawRect( aCellRect
);
395 // -----------------------------------------------------------------------
397 void SvxPageWindow::SetBorder( const SvxBoxItem
& rNew
)
399 delete pImpl
->pBorder
;
400 pImpl
->pBorder
= new SvxBoxItem( rNew
);
403 // -----------------------------------------------------------------------
405 void SvxPageWindow::SetBitmap( Bitmap
* pBmp
)
409 pImpl
->aBitmap
= *pBmp
;
410 pImpl
->bBitmap
= true;
413 pImpl
->bBitmap
= false;
416 // -----------------------------------------------------------------------
418 void SvxPageWindow::SetHdBorder( const SvxBoxItem
& rNew
)
421 pHdBorder
= new SvxBoxItem( rNew
);
423 // -----------------------------------------------------------------------
425 void SvxPageWindow::SetFtBorder( const SvxBoxItem
& rNew
)
428 pFtBorder
= new SvxBoxItem( rNew
);
431 void SvxPageWindow::EnableFrameDirection(sal_Bool bEnable
)
433 pImpl
->EnableFrameDirection(bEnable
);
436 void SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection
)
438 pImpl
->SetFrameDirection(nFrameDirection
);
441 void SvxPageWindow::ResetBackground()
443 pImpl
->bResetBackground
= true;
446 Size
SvxPageWindow::GetOptimalSize() const
448 return LogicToPixel(Size(75, 46), MapMode(MAP_APPFONT
));
451 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */