xref: /trunk/main/svx/source/dialog/paraprev.cxx (revision f6e50924)
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 #include <svx/paraprev.hxx>
30 
31 // STATIC DATA -----------------------------------------------------------
32 
33 #define FOUR_POINTS	80
34 
35 // class SvxParaPrevWindow -----------------------------------------------
36 
SvxParaPrevWindow(Window * pParent,const ResId & rId)37 SvxParaPrevWindow::SvxParaPrevWindow( Window* pParent, const ResId& rId ) :
38 
39 	Window( pParent, rId ),
40 
41     nLeftMargin     ( 0 ),
42 	nRightMargin	( 0 ),
43     nFirstLineOfst  ( 0 ),
44     nUpper          ( 0 ),
45 	nLower			( 0 ),
46 	eAdjust			( SVX_ADJUST_LEFT ),
47 	eLastLine       ( SVX_ADJUST_LEFT ),
48 	eLine			( SVX_PREV_LINESPACE_1 ),
49 	nLineVal		( 0 )
50 
51 {
52 	// defaultmaessing in Twips rechnen
53 	SetMapMode( MapMode( MAP_TWIP ) );
54 	aWinSize = GetOutputSizePixel();
55 	aWinSize = PixelToLogic( aWinSize );
56     Size aTmp(1, 1);
57     aTmp = PixelToLogic(aTmp);
58     aWinSize.Width() -= aTmp.Width() /2;
59     aWinSize.Height() -= aTmp.Height() /2;
60 
61 	aSize = Size( 11905, 16837 );
62 
63     SetBorderStyle( WINDOW_BORDER_MONO );
64 }
65 
66 // -----------------------------------------------------------------------
67 
Paint(const Rectangle &)68 void SvxParaPrevWindow::Paint( const Rectangle& )
69 {
70 	DrawParagraph( sal_True );
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 #define DEF_MARGIN	120
76 
DrawParagraph(sal_Bool bAll)77 void SvxParaPrevWindow::DrawParagraph( sal_Bool bAll )
78 {
79     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
80     const Color& rWinColor = rStyleSettings.GetWindowColor();
81     Color aGrayColor(COL_LIGHTGRAY);
82 
83     SetFillColor( Color( rWinColor ) );
84     if( bAll )
85         DrawRect( Rectangle( Point(), aWinSize ) );
86 
87     SetLineColor();
88 
89 	long nH = aWinSize.Height() / 19;
90 	Size aLineSiz( aWinSize.Width() - DEF_MARGIN, nH ),
91 		 aSiz = aLineSiz;
92 	Point aPnt;
93 	aPnt.X() = DEF_MARGIN / 2;
94     SetFillColor( aGrayColor );
95 
96 	for ( sal_uInt16 i = 0; i < 9; ++i )
97 	{
98 		if ( 3 == i )
99 		{
100             SetFillColor( Color( COL_GRAY ) );
101             long nTop = nUpper * aLineSiz.Height() / aSize.Height();
102 			aPnt.Y() += nTop * 2;
103 		}
104 
105 		if ( 6 == i )
106             SetFillColor( aGrayColor );
107 
108 		if ( 3 <= i && 6 > i )
109 		{
110 			long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
111 			long nFirst = nFirstLineOfst * aLineSiz.Width() / aSize.Width();
112 			long nTmp = nLeft + nFirst;
113 
114 			if ( 3 == i )
115 			{
116 				aPnt.X() += nTmp;
117 				aSiz.Width() -= nTmp;
118 			}
119 			else
120 			{
121 				aPnt.X() += nLeft;
122 				aSiz.Width() -= nLeft;
123 			}
124             long nRight = nRightMargin * aLineSiz.Width() / aSize.Width();
125             aSiz.Width() -= nRight;
126 		}
127 
128 		if ( 4 == i || 5 == i || 6 == i )
129 		{
130 			switch ( eLine )
131 			{
132 				case SVX_PREV_LINESPACE_1:						break;
133 				case SVX_PREV_LINESPACE_15:	aPnt.Y() += nH / 2;	break;
134 				case SVX_PREV_LINESPACE_2:	aPnt.Y() += nH;		break;
135 
136 				case SVX_PREV_LINESPACE_PROP:
137 				case SVX_PREV_LINESPACE_MIN:
138 				case SVX_PREV_LINESPACE_DURCH:					break;
139 			}
140 		}
141 
142 		aPnt.Y() += nH;
143 
144         if ( (3 <= i) && (5 >= i) )
145 		{
146             long nLW;
147             switch( i )
148             {
149 				default:
150                 case 3: nLW = aLineSiz.Width() * 8 / 10;    break;
151                 case 4: nLW = aLineSiz.Width() * 9 / 10;    break;
152                 case 5: nLW = aLineSiz.Width() / 2;         break;
153             }
154 
155 			if ( nLW > aSiz.Width() )
156 				nLW = aSiz.Width();
157 
158 			switch ( eAdjust )
159 			{
160 				case SVX_ADJUST_LEFT:
161 					break;
162 				case SVX_ADJUST_RIGHT:
163 					aPnt.X() += ( aSiz.Width() - nLW );
164 					break;
165 				case SVX_ADJUST_CENTER:
166 					aPnt.X() += ( aSiz.Width() - nLW ) / 2;
167 					break;
168                 default: ; //prevent warning
169             }
170             if( SVX_ADJUST_BLOCK == eAdjust )
171             {
172                 if( 5 == i )
173                 {
174                     switch( eLastLine )
175                     {
176                         case SVX_ADJUST_LEFT:
177                             break;
178                         case SVX_ADJUST_RIGHT:
179                             aPnt.X() += ( aSiz.Width() - nLW );
180                             break;
181                         case SVX_ADJUST_CENTER:
182                             aPnt.X() += ( aSiz.Width() - nLW ) / 2;
183                             break;
184                         case SVX_ADJUST_BLOCK:
185                             nLW = aSiz.Width();
186                             break;
187                         default: ; //prevent warning
188                     }
189                 }
190                 else
191                     nLW = aSiz.Width();
192 			}
193             aSiz.Width() = nLW;
194 		}
195 
196         Rectangle aRect( aPnt, aSiz );
197 
198 		if ( Lines[i] != aRect || bAll )
199 		{
200 			if ( !bAll )
201 			{
202 				Color aFillCol = GetFillColor();
203                 SetFillColor( rWinColor );
204                 DrawRect( Lines[i] );
205 				SetFillColor( aFillCol );
206 			}
207 			DrawRect( aRect );
208 			Lines[i] = aRect;
209 		}
210 
211 		if ( 5 == i )
212 		{
213 			long nBottom = nLower * aLineSiz.Height() / aSize.Height();
214 			aPnt.Y() += nBottom * 2;
215 		}
216 
217 		aPnt.Y() += nH;
218 		// wieder zuruecksetzen, fuer jede Linie neu berechnen
219 		aPnt.X() = DEF_MARGIN / 2;
220 		aSiz = aLineSiz;
221 	}
222 }
223 
224 #undef DEF_MARGIN
225 
226 // -----------------------------------------------------------------------
227 
OutputSizeChanged()228 void SvxParaPrevWindow::OutputSizeChanged()
229 {
230 	aWinSize = GetOutputSizePixel();
231 	aWinSize = PixelToLogic( aWinSize );
232 	Invalidate();
233 }
234 
235