1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pagectrl.cxx,v $
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>
45 // struct PageWindow_Impl ------------------------------------------------
47 struct PageWindow_Impl
52 sal_Bool bResetBackground
;
53 sal_Bool bFrameDirection
;
54 sal_Int32 nFrameDirection
;
60 bResetBackground(sal_False
),
61 bFrameDirection(sal_False
),
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
),
84 aColor ( COL_TRANSPARENT
),
89 aHdColor ( COL_TRANSPARENT
),
95 aFtColor ( COL_TRANSPARENT
),
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
);
117 // -----------------------------------------------------------------------
119 SvxPageWindow::~SvxPageWindow()
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
);
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();
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
);
169 DrawPage( Point( ( aSz
.Width() - aSize
.Width() ) / 2, nYPos
), TRUE
, TRUE
);
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();
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
);
202 Size aTempSize
= aSize
;
206 SetFillColor( rDisableColor
);
207 DrawRect( Rectangle( rOrg
, aTempSize
) );
210 SetFillColor( rFieldColor
);
211 DrawRect( Rectangle( rOrg
, aTempSize
) );
213 // Border Top Bottom Left Right
214 Point
aBegin( rOrg
);
220 if ( eUsage
== SVX_PAGE_MIRROR
&& !bSecond
)
222 // f"ur gespiegelt drehen
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
);
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
);
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
);
260 SetFillColor( aColor
);
261 if ( pImpl
->bBitmap
)
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
);
277 if(pImpl
->bFrameDirection
&& !bTable
)
279 //pImpl->nFrameDirection
281 Font
aFont(GetFont());
282 const Size aSaveSize
= aFont
.GetSize();
283 Size
aDrawSize( 0, aRect
.GetHeight() / 6);
284 aFont
.SetSize(aDrawSize
);
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();
298 case FRMDIR_HORI_RIGHT_TOP
:
299 aPos
= aRect
.TopRight();
305 case FRMDIR_VERT_TOP_LEFT
:
306 aPos
= aRect
.TopLeft();
307 aPos
.X() += PixelToLogic(Point(1,1)).X();
310 case FRMDIR_VERT_TOP_RIGHT
:
311 aPos
= aRect
.TopRight();
316 sText
.Append(cArrow
);
317 for(USHORT i
= 0; i
< sText
.Len(); i
++)
319 String
sDraw(sText
.GetChar(i
));
321 long nCharWidth
= GetTextWidth(sDraw
);
322 BOOL bHorizontal
= 0 == aMove
.Y();
325 nHDiff
= (nAWidth
- nCharWidth
)/2;
328 DrawText(aPos
, sDraw
);
331 aPos
.X() += aMove
.X() < 0 ? - nCharWidth
: nCharWidth
;
336 aPos
.Y() += aMove
.Y();
339 aFont
.SetSize(aSaveSize
);
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
;
359 aCellRect
.Move( 0, CELL_HEIGHT
);
361 for ( USHORT j
= 0; j
< 3; ++j
)
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
)
385 pImpl
->aBitmap
= *pBmp
;
386 pImpl
->bBitmap
= TRUE
;
389 pImpl
->bBitmap
= FALSE
;
392 // -----------------------------------------------------------------------
394 void SvxPageWindow::SetHdBorder( const SvxBoxItem
& rNew
)
397 pHdBorder
= new SvxBoxItem( rNew
);
399 // -----------------------------------------------------------------------
401 void SvxPageWindow::SetFtBorder( const SvxBoxItem
& rNew
)
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
;