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 <vcl/builder.hxx>
22 #include <vcl/settings.hxx>
23 #include <editeng/frmdiritem.hxx>
24 #include <svx/pageitem.hxx>
25 #include <svx/pagectrl.hxx>
26 #include <editeng/boxitem.hxx>
30 // struct PageWindow_Impl ------------------------------------------------
32 struct PageWindow_Impl
37 bool bResetBackground
;
39 sal_Int32 nFrameDirection
;
45 bResetBackground(false),
46 bFrameDirection(false),
49 void EnableFrameDirection(bool bEnable
){bFrameDirection
= bEnable
;}
50 void SetFrameDirection(sal_Int32 nDirection
){nFrameDirection
= nDirection
;}
54 // STATIC DATA -----------------------------------------------------------
56 #define CELL_WIDTH 1600L
57 #define CELL_HEIGHT 800L
59 // class SvxPageWindow ---------------------------------------------------
61 SvxPageWindow::SvxPageWindow( Window
* pParent
) :
69 aColor ( COL_TRANSPARENT
),
74 aHdColor ( COL_TRANSPARENT
),
80 aFtColor ( COL_TRANSPARENT
),
87 eUsage ( SVX_PAGE_ALL
)
89 pImpl
= new PageWindow_Impl
;
91 // Count in Twips by default
92 SetMapMode( MapMode( MAP_TWIP
) );
93 aWinSize
= GetOptimalSize();
94 aWinSize
.Height() -= 4;
95 aWinSize
.Width() -= 4;
97 aWinSize
= PixelToLogic( aWinSize
);
103 SvxPageWindow::~SvxPageWindow()
110 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeSvxPageWindow(Window
*pParent
, VclBuilder::stringmap
&)
112 return new SvxPageWindow(pParent
);
118 void SvxPageWindow::Paint( const Rectangle
& )
120 Fraction
aXScale( aWinSize
.Width(), std::max( (long) (aSize
.Width() * 2 + aSize
.Width() / 8), 1L ) );
121 Fraction
aYScale( aWinSize
.Height(), std::max( aSize
.Height(), 1L ) );
122 MapMode
aMapMode( GetMapMode() );
124 if ( aYScale
< aXScale
)
126 aMapMode
.SetScaleX( aYScale
);
127 aMapMode
.SetScaleY( aYScale
);
131 aMapMode
.SetScaleX( aXScale
);
132 aMapMode
.SetScaleY( aXScale
);
134 SetMapMode( aMapMode
);
135 Size
aSz( PixelToLogic( GetSizePixel() ) );
136 long nYPos
= ( aSz
.Height() - aSize
.Height() ) / 2;
138 if ( eUsage
== SVX_PAGE_ALL
)
140 // all pages are equal -> draw one page
141 if ( aSize
.Width() > aSize
.Height() )
143 // Draw Landscape page of the same size
144 Fraction aX
= aMapMode
.GetScaleX();
145 Fraction aY
= aMapMode
.GetScaleY();
149 aMapMode
.SetScaleX( aX
);
150 aMapMode
.SetScaleY( aY
);
151 SetMapMode( aMapMode
);
152 aSz
= PixelToLogic( GetSizePixel() );
153 nYPos
= ( aSz
.Height() - aSize
.Height() ) / 2;
154 long nXPos
= ( aSz
.Width() - aSize
.Width() ) / 2;
155 DrawPage( Point( nXPos
, nYPos
), true, true );
159 DrawPage( Point( ( aSz
.Width() - aSize
.Width() ) / 2, nYPos
), true, true );
163 // Left and right page are different -> draw two pages if possible
164 DrawPage( Point( 0, nYPos
), false, eUsage
& SVX_PAGE_LEFT
);
165 DrawPage( Point( aSize
.Width() + aSize
.Width() / 8, nYPos
), true,
166 eUsage
& SVX_PAGE_RIGHT
);
171 void SvxPageWindow::DrawPage( const Point
& rOrg
, const bool bSecond
, const bool bEnabled
)
173 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
174 const Color
& rFieldColor
= rStyleSettings
.GetFieldColor();
175 const Color
& rFieldTextColor
= rStyleSettings
.GetFieldTextColor();
176 const Color
& rDisableColor
= rStyleSettings
.GetDisableColor();
177 const Color
& rDlgColor
= rStyleSettings
.GetDialogColor();
180 if(!bSecond
|| pImpl
->bResetBackground
)
182 SetLineColor( Color(COL_TRANSPARENT
) );
183 SetFillColor( rDlgColor
);
184 Size
winSize(GetOutputSize());
185 DrawRect( Rectangle( Point(0,0), winSize
) );
187 if ( pImpl
->bResetBackground
)
188 pImpl
->bResetBackground
= false;
190 SetLineColor( rFieldTextColor
);
192 Size aTempSize
= aSize
;
196 SetFillColor( rDisableColor
);
197 DrawRect( Rectangle( rOrg
, aTempSize
) );
200 SetFillColor( rFieldColor
);
201 DrawRect( Rectangle( rOrg
, aTempSize
) );
206 if ( eUsage
== SVX_PAGE_MIRROR
&& !bSecond
)
215 aRect
.Left() = rOrg
.X() + nL
;
216 aRect
.Right() = rOrg
.X() + aTempSize
.Width() - nR
;
217 aRect
.Top() = rOrg
.Y() + nTop
;
218 aRect
.Bottom()= rOrg
.Y() + aTempSize
.Height() - nBottom
;
220 Rectangle
aHdRect( aRect
);
221 Rectangle
aFtRect( aRect
);
225 // show headers if possible
226 aHdRect
.Left() += nHdLeft
;
227 aHdRect
.Right() -= nHdRight
;
228 aHdRect
.Bottom() = aRect
.Top() + nHdHeight
;
229 aRect
.Top() += nHdHeight
+ nHdDist
;
230 SetFillColor( aHdColor
);
236 // show footer if possible
237 aFtRect
.Left() += nFtLeft
;
238 aFtRect
.Right() -= nFtRight
;
239 aFtRect
.Top() = aRect
.Bottom() - nFtHeight
;
240 aRect
.Bottom() -= nFtHeight
+ nFtDist
;
241 SetFillColor( aFtColor
);
246 SetFillColor( aColor
);
247 if ( pImpl
->bBitmap
)
250 Point aBmpPnt
= aRect
.TopLeft();
251 Size aBmpSiz
= aRect
.GetSize();
252 long nDeltaX
= aBmpSiz
.Width() / 15;
253 long nDeltaY
= aBmpSiz
.Height() / 15;
254 aBmpPnt
.X() += nDeltaX
;
255 aBmpPnt
.Y() += nDeltaY
;
256 aBmpSiz
.Width() -= nDeltaX
* 2;
257 aBmpSiz
.Height() -= nDeltaY
* 2;
258 DrawBitmap( aBmpPnt
, aBmpSiz
, pImpl
->aBitmap
);
263 if(pImpl
->bFrameDirection
&& !bTable
)
266 Font
aFont(GetFont());
267 const Size aSaveSize
= aFont
.GetSize();
268 Size
aDrawSize( 0, aRect
.GetHeight() / 6);
269 aFont
.SetSize(aDrawSize
);
271 OUString
sText("ABC");
272 Point
aMove(1, GetTextHeight());
273 sal_Unicode cArrow
= 0x2193;
274 long nAWidth
= GetTextWidth(sText
.copy(0,1));
275 switch(pImpl
->nFrameDirection
)
277 case FRMDIR_HORI_LEFT_TOP
:
278 aPos
= aRect
.TopLeft();
279 aPos
.X() += PixelToLogic(Point(1,1)).X();
283 case FRMDIR_HORI_RIGHT_TOP
:
284 aPos
= aRect
.TopRight();
290 case FRMDIR_VERT_TOP_LEFT
:
291 aPos
= aRect
.TopLeft();
292 aPos
.X() += PixelToLogic(Point(1,1)).X();
295 case FRMDIR_VERT_TOP_RIGHT
:
296 aPos
= aRect
.TopRight();
301 sText
+= OUString(cArrow
);
302 for(sal_uInt16 i
= 0; i
< sText
.getLength(); i
++)
304 OUString
sDraw(sText
.copy(i
,1));
306 long nCharWidth
= GetTextWidth(sDraw
);
307 bool bHorizontal
= 0 == aMove
.Y();
310 nHDiff
= (nAWidth
- nCharWidth
)/2;
313 DrawText(aPos
, sDraw
);
316 aPos
.X() += aMove
.X() < 0 ? - nCharWidth
: nCharWidth
;
321 aPos
.Y() += aMove
.Y();
324 aFont
.SetSize(aSaveSize
);
330 // Paint Table, if necessary center it
331 SetLineColor( Color(COL_LIGHTGRAY
) );
333 long nW
= aRect
.GetWidth(), nH
= aRect
.GetHeight();
334 long nTW
= CELL_WIDTH
* 3, nTH
= CELL_HEIGHT
* 3;
335 long _nLeft
= bHorz
? aRect
.Left() + ((nW
- nTW
) / 2) : aRect
.Left();
336 long _nTop
= bVert
? aRect
.Top() + ((nH
- nTH
) / 2) : aRect
.Top();
337 Rectangle
aCellRect( Point( _nLeft
, _nTop
), Size( CELL_WIDTH
, CELL_HEIGHT
) );
339 for ( sal_uInt16 i
= 0; i
< 3; ++i
)
341 aCellRect
.Left() = _nLeft
;
342 aCellRect
.Right() = _nLeft
+ CELL_WIDTH
;
344 aCellRect
.Move( 0, CELL_HEIGHT
);
346 for ( sal_uInt16 j
= 0; j
< 3; ++j
)
349 aCellRect
.Move( CELL_WIDTH
, 0 );
350 DrawRect( aCellRect
);
358 void SvxPageWindow::SetBorder( const SvxBoxItem
& rNew
)
360 delete pImpl
->pBorder
;
361 pImpl
->pBorder
= new SvxBoxItem( rNew
);
366 void SvxPageWindow::SetBitmap( Bitmap
* pBmp
)
370 pImpl
->aBitmap
= *pBmp
;
371 pImpl
->bBitmap
= true;
374 pImpl
->bBitmap
= false;
379 void SvxPageWindow::SetHdBorder( const SvxBoxItem
& rNew
)
382 pHdBorder
= new SvxBoxItem( rNew
);
386 void SvxPageWindow::SetFtBorder( const SvxBoxItem
& rNew
)
389 pFtBorder
= new SvxBoxItem( rNew
);
392 void SvxPageWindow::EnableFrameDirection(bool bEnable
)
394 pImpl
->EnableFrameDirection(bEnable
);
397 void SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection
)
399 pImpl
->SetFrameDirection(nFrameDirection
);
402 void SvxPageWindow::ResetBackground()
404 pImpl
->bResetBackground
= true;
407 Size
SvxPageWindow::GetOptimalSize() const
409 return LogicToPixel(Size(75, 46), MapMode(MAP_APPFONT
));
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */