xref: /aoo4110/main/svx/source/dialog/pagectrl.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 // include ---------------------------------------------------------------
28 
29 
30 #include <vcl/bitmap.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <svx/pageitem.hxx>
33 #include <svx/pagectrl.hxx>
34 #include <editeng/boxitem.hxx>
35 
36 #include <algorithm>
37 
38 // struct PageWindow_Impl ------------------------------------------------
39 
40 struct PageWindow_Impl
41 {
42 	SvxBoxItem*		pBorder;
43 	Bitmap			aBitmap;
44 	FASTBOOL		bBitmap;
45     sal_Bool        bResetBackground;
46     sal_Bool        bFrameDirection;
47     sal_Int32       nFrameDirection;
48 
49 
PageWindow_ImplPageWindow_Impl50     PageWindow_Impl() :
51         pBorder(0),
52         bBitmap(sal_False),
53         bResetBackground(sal_False),
54         bFrameDirection(sal_False),
55         nFrameDirection(0) {}
56 
EnableFrameDirectionPageWindow_Impl57     void        EnableFrameDirection(sal_Bool bEnable){bFrameDirection = bEnable;}
SetFrameDirectionPageWindow_Impl58     void        SetFrameDirection(sal_Int32 nDirection){nFrameDirection = nDirection;}
59 
60 };
61 
62 // STATIC DATA -----------------------------------------------------------
63 
64 #define CELL_WIDTH		1600L
65 #define CELL_HEIGHT		 800L
66 
67 // class SvxPageWindow ---------------------------------------------------
68 
SvxPageWindow(Window * pParent,const ResId & rId)69 SvxPageWindow::SvxPageWindow( Window* pParent, const ResId& rId ) :
70 
71 	Window( pParent, rId ),
72 
73 	nTop		( 0 ),
74 	nBottom		( 0 ),
75 	nLeft		( 0 ),
76 	nRight		( 0 ),
77     aColor      ( COL_TRANSPARENT ),
78 	nHdLeft		( 0 ),
79 	nHdRight	( 0 ),
80 	nHdDist		( 0 ),
81 	nHdHeight	( 0 ),
82     aHdColor    ( COL_TRANSPARENT ),
83 	pHdBorder	( 0 ),
84 	nFtLeft		( 0 ),
85 	nFtRight	( 0 ),
86 	nFtDist		( 0 ),
87 	nFtHeight	( 0 ),
88     aFtColor    ( COL_TRANSPARENT ),
89 	pFtBorder 	( 0 ),
90 	bFooter		( sal_False ),
91 	bHeader		( sal_False ),
92 	bTable		( sal_False ),
93 	bHorz		( sal_False ),
94 	bVert		( sal_False ),
95 	eUsage		( SVX_PAGE_ALL )
96 
97 {
98 	pImpl = new PageWindow_Impl;
99 
100 	// defaultmaessing in Twips rechnen
101 	SetMapMode( MapMode( MAP_TWIP ) );
102 	aWinSize = GetOutputSizePixel();
103 	aWinSize.Height() -= 4;
104 	aWinSize.Width() -= 4;
105 
106 	aWinSize = PixelToLogic( aWinSize );
107     SetBackground();
108 }
109 
110 // -----------------------------------------------------------------------
111 
~SvxPageWindow()112 SvxPageWindow::~SvxPageWindow()
113 {
114 	delete pImpl;
115 	delete pHdBorder;
116 	delete pFtBorder;
117 }
118 
119 // -----------------------------------------------------------------------
120 
Paint(const Rectangle &)121 void __EXPORT SvxPageWindow::Paint( const Rectangle& )
122 {
123 	Fraction aXScale( aWinSize.Width(), std::max( (long) (aSize.Width() * 2 + aSize.Width() / 8), 1L ) );
124 	Fraction aYScale( aWinSize.Height(), std::max( aSize.Height(), 1L ) );
125 	MapMode aMapMode( GetMapMode() );
126 
127 	if ( aYScale < aXScale )
128 	{
129 		aMapMode.SetScaleX( aYScale );
130 		aMapMode.SetScaleY( aYScale );
131 	}
132 	else
133 	{
134 		aMapMode.SetScaleX( aXScale );
135 		aMapMode.SetScaleY( aXScale );
136 	}
137 	SetMapMode( aMapMode );
138 	Size aSz( PixelToLogic( GetSizePixel() ) );
139 	long nYPos = ( aSz.Height() - aSize.Height() ) / 2;
140 
141 	if ( eUsage == SVX_PAGE_ALL )
142 	{
143 		// alle Seiten gleich -> eine Seite malen
144 		if ( aSize.Width() > aSize.Height() )
145 		{
146 			// Querformat in gleicher Gr"osse zeichnen
147 			Fraction aX = aMapMode.GetScaleX();
148 			Fraction aY = aMapMode.GetScaleY();
149 			Fraction a2( 1.5 );
150 			aX *= a2;
151 			aY *= a2;
152 			aMapMode.SetScaleX( aX );
153 			aMapMode.SetScaleY( aY );
154 			SetMapMode( aMapMode );
155 			aSz = PixelToLogic( GetSizePixel() );
156 			nYPos = ( aSz.Height() - aSize.Height() ) / 2;
157 			long nXPos = ( aSz.Width() - aSize.Width() ) / 2;
158 			DrawPage( Point( nXPos, nYPos ), sal_True, sal_True );
159 		}
160 		else
161 			// Hochformat
162 			DrawPage( Point( ( aSz.Width() - aSize.Width() ) / 2, nYPos ), sal_True, sal_True );
163 	}
164 	else
165 	{
166 		// Linke und rechte Seite unterschiedlich -> ggf. zwei Seiten malen
167 		DrawPage( Point( 0, nYPos ), sal_False, (sal_Bool)( eUsage & SVX_PAGE_LEFT ) );
168 		DrawPage( Point( aSize.Width() + aSize.Width() / 8, nYPos ), sal_True,
169 				  (sal_Bool)( eUsage & SVX_PAGE_RIGHT ) );
170 	}
171 }
172 
173 // -----------------------------------------------------------------------
DrawPage(const Point & rOrg,const sal_Bool bSecond,const sal_Bool bEnabled)174 void SvxPageWindow::DrawPage( const Point& rOrg, const sal_Bool bSecond, const sal_Bool bEnabled )
175 {
176     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
177     const Color& rFieldColor = rStyleSettings.GetFieldColor();
178     const Color& rFieldTextColor = rStyleSettings.GetFieldTextColor();
179     const Color& rDisableColor = rStyleSettings.GetDisableColor();
180     const Color& rDlgColor = rStyleSettings.GetDialogColor();
181 
182     // background
183     if(!bSecond || pImpl->bResetBackground)
184     {
185         SetLineColor( Color(COL_TRANSPARENT) );
186         SetFillColor( rDlgColor );
187         Size winSize(GetOutputSize());
188         DrawRect( Rectangle( Point(0,0), winSize ) );
189 
190         if ( pImpl->bResetBackground )
191             pImpl->bResetBackground = sal_False;
192     }
193     SetLineColor( rFieldTextColor );
194     // Schatten
195     Size aTempSize = aSize;
196     // Seite
197 	if ( !bEnabled )
198 	{
199         SetFillColor( rDisableColor );
200 		DrawRect( Rectangle( rOrg, aTempSize ) );
201 		return;
202 	}
203     SetFillColor( rFieldColor );
204 	DrawRect( Rectangle( rOrg, aTempSize ) );
205 
206 	// Border Top Bottom Left Right
207 	Point aBegin( rOrg );
208 	Point aEnd( rOrg );
209 
210 	long nL = nLeft;
211 	long nR = nRight;
212 
213 	if ( eUsage == SVX_PAGE_MIRROR && !bSecond )
214 	{
215 		// f"ur gespiegelt drehen
216 		nL = nRight;
217 		nR = nLeft;
218 	}
219 
220 	Rectangle aRect;
221 
222 	aRect.Left()  = rOrg.X() + nL;
223 	aRect.Right() = rOrg.X() + aTempSize.Width() - nR;
224 	aRect.Top()	  = rOrg.Y() + nTop;
225 	aRect.Bottom()= rOrg.Y() + aTempSize.Height() - nBottom;
226 
227 	Rectangle aHdRect( aRect );
228 	Rectangle aFtRect( aRect );
229 
230 	if ( bHeader )
231 	{
232 		// ggf. Header anzeigen
233 		aHdRect.Left() += nHdLeft;
234 		aHdRect.Right() -= nHdRight;
235 		aHdRect.Bottom() = aRect.Top() + nHdHeight;
236 		aRect.Top() += nHdHeight + nHdDist;
237 		SetFillColor( aHdColor );
238 		DrawRect( aHdRect );
239 	}
240 
241 	if ( bFooter )
242 	{
243 		// ggf. Footer anzeigen
244 		aFtRect.Left() += nFtLeft;
245 		aFtRect.Right() -= nFtRight;
246 		aFtRect.Top() = aRect.Bottom() - nFtHeight;
247 		aRect.Bottom() -= nFtHeight + nFtDist;
248 		SetFillColor( aFtColor );
249 		DrawRect( aFtRect );
250 	}
251 
252 	// Body malen
253 	SetFillColor( aColor );
254 	if ( pImpl->bBitmap )
255 	{
256 		DrawRect( aRect );
257 		Point aBmpPnt = aRect.TopLeft();
258 		Size aBmpSiz = aRect.GetSize();
259 		long nDeltaX = aBmpSiz.Width() / 15;
260 		long nDeltaY = aBmpSiz.Height() / 15;
261 		aBmpPnt.X() += nDeltaX;
262 		aBmpPnt.Y() += nDeltaY;
263 		aBmpSiz.Width() -= nDeltaX * 2;
264 		aBmpSiz.Height() -= nDeltaY * 2;
265 		DrawBitmap( aBmpPnt, aBmpSiz, pImpl->aBitmap );
266 	}
267 	else
268 		DrawRect( aRect );
269 
270     if(pImpl->bFrameDirection && !bTable)
271     {
272        //pImpl->nFrameDirection
273         Point aPos;
274         Font aFont(GetFont());
275         const Size aSaveSize = aFont.GetSize();
276         Size aDrawSize( 0, aRect.GetHeight() / 6);
277         aFont.SetSize(aDrawSize);
278         SetFont(aFont);
279         String sText(String::CreateFromAscii("ABC"));
280         Point aMove(1, GetTextHeight());
281         sal_Unicode cArrow = 0x2193;
282         long nAWidth = GetTextWidth(String(sText.GetChar(0)));
283         switch(pImpl->nFrameDirection)
284         {
285             case FRMDIR_HORI_LEFT_TOP:
286                 aPos = aRect.TopLeft();
287                 aPos.X() += PixelToLogic(Point(1,1)).X();
288                 aMove.Y() = 0;
289                 cArrow = 0x2192;
290             break;
291             case FRMDIR_HORI_RIGHT_TOP:
292                 aPos = aRect.TopRight();
293                 aPos.X() -= nAWidth;
294                 aMove.Y() = 0;
295                 aMove.X() *= -1;
296                 cArrow = 0x2190;
297             break;
298             case FRMDIR_VERT_TOP_LEFT:
299                 aPos = aRect.TopLeft();
300                 aPos.X() += PixelToLogic(Point(1,1)).X();
301                 aMove.X() = 0;
302             break;
303             case FRMDIR_VERT_TOP_RIGHT:
304                 aPos = aRect.TopRight();
305                 aPos.X() -= nAWidth;
306                 aMove.X() = 0;
307             break;
308         }
309         sText.Append(cArrow);
310         for(sal_uInt16 i = 0; i < sText.Len(); i++)
311         {
312             String sDraw(sText.GetChar(i));
313             long nHDiff = 0;
314             long nCharWidth = GetTextWidth(sDraw);
315             sal_Bool bHorizontal = 0 == aMove.Y();
316             if(!bHorizontal)
317             {
318                 nHDiff = (nAWidth - nCharWidth)/2;
319                 aPos.X() += nHDiff;
320             }
321             DrawText(aPos, sDraw);
322             if(bHorizontal)
323             {
324                 aPos.X() += aMove.X() < 0 ? - nCharWidth : nCharWidth;
325             }
326             else
327             {
328                 aPos.X() -= nHDiff;
329                 aPos.Y() += aMove.Y();
330             }
331         }
332         aFont.SetSize(aSaveSize);
333         SetFont(aFont);
334 
335     }
336 	if ( bTable )
337 	{
338 		// Tabelle malen, ggf. zentrieren
339 		SetLineColor( Color(COL_LIGHTGRAY) );
340 
341 		long nW = aRect.GetWidth(), nH = aRect.GetHeight();
342 		long nTW = CELL_WIDTH * 3, nTH = CELL_HEIGHT * 3;
343         long _nLeft = bHorz ? aRect.Left() + ((nW - nTW) / 2) : aRect.Left();
344         long _nTop = bVert ? aRect.Top() + ((nH - nTH) / 2) : aRect.Top();
345         Rectangle aCellRect( Point( _nLeft, _nTop ), Size( CELL_WIDTH, CELL_HEIGHT ) );
346 
347 		for ( sal_uInt16 i = 0; i < 3; ++i )
348 		{
349             aCellRect.Left() = _nLeft;
350             aCellRect.Right() = _nLeft + CELL_WIDTH;
351 			if ( i > 0 )
352 				aCellRect.Move( 0, CELL_HEIGHT );
353 
354 			for ( sal_uInt16 j = 0; j < 3; ++j )
355 			{
356 				if ( j > 0 )
357 					aCellRect.Move( CELL_WIDTH, 0 );
358 				DrawRect( aCellRect );
359 			}
360 		}
361 	}
362 }
363 
364 // -----------------------------------------------------------------------
365 
SetBorder(const SvxBoxItem & rNew)366 void SvxPageWindow::SetBorder( const SvxBoxItem& rNew )
367 {
368 	delete pImpl->pBorder;
369 	pImpl->pBorder = new SvxBoxItem( rNew );
370 }
371 
372 // -----------------------------------------------------------------------
373 
SetBitmap(Bitmap * pBmp)374 void SvxPageWindow::SetBitmap( Bitmap* pBmp )
375 {
376 	if ( pBmp )
377 	{
378 		pImpl->aBitmap = *pBmp;
379 		pImpl->bBitmap = sal_True;
380 	}
381 	else
382 		pImpl->bBitmap = sal_False;
383 }
384 
385 // -----------------------------------------------------------------------
386 
SetHdBorder(const SvxBoxItem & rNew)387 void SvxPageWindow::SetHdBorder( const SvxBoxItem& rNew )
388 {
389 	delete pHdBorder;
390 	pHdBorder = new SvxBoxItem( rNew );
391 }
392 // -----------------------------------------------------------------------
393 
SetFtBorder(const SvxBoxItem & rNew)394 void SvxPageWindow::SetFtBorder( const SvxBoxItem& rNew )
395 {
396 	delete pFtBorder;
397 	pFtBorder = new SvxBoxItem( rNew );
398 }
399 /* -----------------------------13.06.2002 16:16------------------------------
400 
401  ---------------------------------------------------------------------------*/
EnableFrameDirection(sal_Bool bEnable)402 void  SvxPageWindow::EnableFrameDirection(sal_Bool bEnable)
403 {
404     pImpl->EnableFrameDirection(bEnable);
405 }
406 /* -----------------------------13.06.2002 16:16------------------------------
407 
408  ---------------------------------------------------------------------------*/
SetFrameDirection(sal_Int32 nFrameDirection)409 void  SvxPageWindow::SetFrameDirection(sal_Int32 nFrameDirection)
410 {
411     pImpl->SetFrameDirection(nFrameDirection);
412 }
413 
ResetBackground()414 void SvxPageWindow::ResetBackground()
415 {
416     pImpl->bResetBackground = sal_True;
417 }
418