xref: /aoo41x/main/svx/source/dialog/paraprev.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // include ---------------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <svx/paraprev.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #define FOUR_POINTS	80
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // class SvxParaPrevWindow -----------------------------------------------
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir SvxParaPrevWindow::SvxParaPrevWindow( Window* pParent, const ResId& rId ) :
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir 	Window( pParent, rId ),
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir     nLeftMargin     ( 0 ),
46*cdf0e10cSrcweir 	nRightMargin	( 0 ),
47*cdf0e10cSrcweir     nFirstLineOfst  ( 0 ),
48*cdf0e10cSrcweir     nUpper          ( 0 ),
49*cdf0e10cSrcweir 	nLower			( 0 ),
50*cdf0e10cSrcweir 	eAdjust			( SVX_ADJUST_LEFT ),
51*cdf0e10cSrcweir 	eLastLine       ( SVX_ADJUST_LEFT ),
52*cdf0e10cSrcweir 	eLine			( SVX_PREV_LINESPACE_1 ),
53*cdf0e10cSrcweir 	nLineVal		( 0 )
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir 	// defaultmaessing in Twips rechnen
57*cdf0e10cSrcweir 	SetMapMode( MapMode( MAP_TWIP ) );
58*cdf0e10cSrcweir 	aWinSize = GetOutputSizePixel();
59*cdf0e10cSrcweir 	aWinSize = PixelToLogic( aWinSize );
60*cdf0e10cSrcweir     Size aTmp(1, 1);
61*cdf0e10cSrcweir     aTmp = PixelToLogic(aTmp);
62*cdf0e10cSrcweir     aWinSize.Width() -= aTmp.Width() /2;
63*cdf0e10cSrcweir     aWinSize.Height() -= aTmp.Height() /2;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir 	aSize = Size( 11905, 16837 );
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
68*cdf0e10cSrcweir }
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir // -----------------------------------------------------------------------
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir void SvxParaPrevWindow::Paint( const Rectangle& )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 	DrawParagraph( sal_True );
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir // -----------------------------------------------------------------------
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir #define DEF_MARGIN	120
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir void SvxParaPrevWindow::DrawParagraph( sal_Bool bAll )
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
84*cdf0e10cSrcweir     const Color& rWinColor = rStyleSettings.GetWindowColor();
85*cdf0e10cSrcweir     Color aGrayColor(COL_LIGHTGRAY);
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     SetFillColor( Color( rWinColor ) );
88*cdf0e10cSrcweir     if( bAll )
89*cdf0e10cSrcweir         DrawRect( Rectangle( Point(), aWinSize ) );
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     SetLineColor();
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 	long nH = aWinSize.Height() / 19;
94*cdf0e10cSrcweir 	Size aLineSiz( aWinSize.Width() - DEF_MARGIN, nH ),
95*cdf0e10cSrcweir 		 aSiz = aLineSiz;
96*cdf0e10cSrcweir 	Point aPnt;
97*cdf0e10cSrcweir 	aPnt.X() = DEF_MARGIN / 2;
98*cdf0e10cSrcweir     SetFillColor( aGrayColor );
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < 9; ++i )
101*cdf0e10cSrcweir 	{
102*cdf0e10cSrcweir 		if ( 3 == i )
103*cdf0e10cSrcweir 		{
104*cdf0e10cSrcweir             SetFillColor( Color( COL_GRAY ) );
105*cdf0e10cSrcweir             long nTop = nUpper * aLineSiz.Height() / aSize.Height();
106*cdf0e10cSrcweir 			aPnt.Y() += nTop * 2;
107*cdf0e10cSrcweir 		}
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir 		if ( 6 == i )
110*cdf0e10cSrcweir             SetFillColor( aGrayColor );
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir 		if ( 3 <= i && 6 > i )
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir 			long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
115*cdf0e10cSrcweir 			long nFirst = nFirstLineOfst * aLineSiz.Width() / aSize.Width();
116*cdf0e10cSrcweir 			long nTmp = nLeft + nFirst;
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 			if ( 3 == i )
119*cdf0e10cSrcweir 			{
120*cdf0e10cSrcweir 				aPnt.X() += nTmp;
121*cdf0e10cSrcweir 				aSiz.Width() -= nTmp;
122*cdf0e10cSrcweir 			}
123*cdf0e10cSrcweir 			else
124*cdf0e10cSrcweir 			{
125*cdf0e10cSrcweir 				aPnt.X() += nLeft;
126*cdf0e10cSrcweir 				aSiz.Width() -= nLeft;
127*cdf0e10cSrcweir 			}
128*cdf0e10cSrcweir             long nRight = nRightMargin * aLineSiz.Width() / aSize.Width();
129*cdf0e10cSrcweir             aSiz.Width() -= nRight;
130*cdf0e10cSrcweir 		}
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 		if ( 4 == i || 5 == i || 6 == i )
133*cdf0e10cSrcweir 		{
134*cdf0e10cSrcweir 			switch ( eLine )
135*cdf0e10cSrcweir 			{
136*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_1:						break;
137*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_15:	aPnt.Y() += nH / 2;	break;
138*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_2:	aPnt.Y() += nH;		break;
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_PROP:
141*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_MIN:
142*cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_DURCH:					break;
143*cdf0e10cSrcweir 			}
144*cdf0e10cSrcweir 		}
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir 		aPnt.Y() += nH;
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir         if ( (3 <= i) && (5 >= i) )
149*cdf0e10cSrcweir 		{
150*cdf0e10cSrcweir             long nLW;
151*cdf0e10cSrcweir             switch( i )
152*cdf0e10cSrcweir             {
153*cdf0e10cSrcweir 				default:
154*cdf0e10cSrcweir                 case 3: nLW = aLineSiz.Width() * 8 / 10;    break;
155*cdf0e10cSrcweir                 case 4: nLW = aLineSiz.Width() * 9 / 10;    break;
156*cdf0e10cSrcweir                 case 5: nLW = aLineSiz.Width() / 2;         break;
157*cdf0e10cSrcweir             }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			if ( nLW > aSiz.Width() )
160*cdf0e10cSrcweir 				nLW = aSiz.Width();
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 			switch ( eAdjust )
163*cdf0e10cSrcweir 			{
164*cdf0e10cSrcweir 				case SVX_ADJUST_LEFT:
165*cdf0e10cSrcweir 					break;
166*cdf0e10cSrcweir 				case SVX_ADJUST_RIGHT:
167*cdf0e10cSrcweir 					aPnt.X() += ( aSiz.Width() - nLW );
168*cdf0e10cSrcweir 					break;
169*cdf0e10cSrcweir 				case SVX_ADJUST_CENTER:
170*cdf0e10cSrcweir 					aPnt.X() += ( aSiz.Width() - nLW ) / 2;
171*cdf0e10cSrcweir 					break;
172*cdf0e10cSrcweir                 default: ; //prevent warning
173*cdf0e10cSrcweir             }
174*cdf0e10cSrcweir             if( SVX_ADJUST_BLOCK == eAdjust )
175*cdf0e10cSrcweir             {
176*cdf0e10cSrcweir                 if( 5 == i )
177*cdf0e10cSrcweir                 {
178*cdf0e10cSrcweir                     switch( eLastLine )
179*cdf0e10cSrcweir                     {
180*cdf0e10cSrcweir                         case SVX_ADJUST_LEFT:
181*cdf0e10cSrcweir                             break;
182*cdf0e10cSrcweir                         case SVX_ADJUST_RIGHT:
183*cdf0e10cSrcweir                             aPnt.X() += ( aSiz.Width() - nLW );
184*cdf0e10cSrcweir                             break;
185*cdf0e10cSrcweir                         case SVX_ADJUST_CENTER:
186*cdf0e10cSrcweir                             aPnt.X() += ( aSiz.Width() - nLW ) / 2;
187*cdf0e10cSrcweir                             break;
188*cdf0e10cSrcweir                         case SVX_ADJUST_BLOCK:
189*cdf0e10cSrcweir                             nLW = aSiz.Width();
190*cdf0e10cSrcweir                             break;
191*cdf0e10cSrcweir                         default: ; //prevent warning
192*cdf0e10cSrcweir                     }
193*cdf0e10cSrcweir                 }
194*cdf0e10cSrcweir                 else
195*cdf0e10cSrcweir                     nLW = aSiz.Width();
196*cdf0e10cSrcweir 			}
197*cdf0e10cSrcweir             aSiz.Width() = nLW;
198*cdf0e10cSrcweir 		}
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir         Rectangle aRect( aPnt, aSiz );
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir 		if ( Lines[i] != aRect || bAll )
203*cdf0e10cSrcweir 		{
204*cdf0e10cSrcweir 			if ( !bAll )
205*cdf0e10cSrcweir 			{
206*cdf0e10cSrcweir 				Color aFillCol = GetFillColor();
207*cdf0e10cSrcweir                 SetFillColor( rWinColor );
208*cdf0e10cSrcweir                 DrawRect( Lines[i] );
209*cdf0e10cSrcweir 				SetFillColor( aFillCol );
210*cdf0e10cSrcweir 			}
211*cdf0e10cSrcweir 			DrawRect( aRect );
212*cdf0e10cSrcweir 			Lines[i] = aRect;
213*cdf0e10cSrcweir 		}
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 		if ( 5 == i )
216*cdf0e10cSrcweir 		{
217*cdf0e10cSrcweir 			long nBottom = nLower * aLineSiz.Height() / aSize.Height();
218*cdf0e10cSrcweir 			aPnt.Y() += nBottom * 2;
219*cdf0e10cSrcweir 		}
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		aPnt.Y() += nH;
222*cdf0e10cSrcweir 		// wieder zuruecksetzen, fuer jede Linie neu berechnen
223*cdf0e10cSrcweir 		aPnt.X() = DEF_MARGIN / 2;
224*cdf0e10cSrcweir 		aSiz = aLineSiz;
225*cdf0e10cSrcweir 	}
226*cdf0e10cSrcweir }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir #undef DEF_MARGIN
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir // -----------------------------------------------------------------------
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir void SvxParaPrevWindow::OutputSizeChanged()
233*cdf0e10cSrcweir {
234*cdf0e10cSrcweir 	aWinSize = GetOutputSizePixel();
235*cdf0e10cSrcweir 	aWinSize = PixelToLogic( aWinSize );
236*cdf0e10cSrcweir 	Invalidate();
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239