xref: /aoo41x/main/svx/source/dialog/paraprev.cxx (revision f6e50924)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <svx/paraprev.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // STATIC DATA -----------------------------------------------------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #define FOUR_POINTS	80
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // class SvxParaPrevWindow -----------------------------------------------
36cdf0e10cSrcweir 
SvxParaPrevWindow(Window * pParent,const ResId & rId)37cdf0e10cSrcweir SvxParaPrevWindow::SvxParaPrevWindow( Window* pParent, const ResId& rId ) :
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 	Window( pParent, rId ),
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     nLeftMargin     ( 0 ),
42cdf0e10cSrcweir 	nRightMargin	( 0 ),
43cdf0e10cSrcweir     nFirstLineOfst  ( 0 ),
44cdf0e10cSrcweir     nUpper          ( 0 ),
45cdf0e10cSrcweir 	nLower			( 0 ),
46cdf0e10cSrcweir 	eAdjust			( SVX_ADJUST_LEFT ),
47cdf0e10cSrcweir 	eLastLine       ( SVX_ADJUST_LEFT ),
48cdf0e10cSrcweir 	eLine			( SVX_PREV_LINESPACE_1 ),
49cdf0e10cSrcweir 	nLineVal		( 0 )
50cdf0e10cSrcweir 
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	// defaultmaessing in Twips rechnen
53cdf0e10cSrcweir 	SetMapMode( MapMode( MAP_TWIP ) );
54cdf0e10cSrcweir 	aWinSize = GetOutputSizePixel();
55cdf0e10cSrcweir 	aWinSize = PixelToLogic( aWinSize );
56cdf0e10cSrcweir     Size aTmp(1, 1);
57cdf0e10cSrcweir     aTmp = PixelToLogic(aTmp);
58cdf0e10cSrcweir     aWinSize.Width() -= aTmp.Width() /2;
59cdf0e10cSrcweir     aWinSize.Height() -= aTmp.Height() /2;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	aSize = Size( 11905, 16837 );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     SetBorderStyle( WINDOW_BORDER_MONO );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir // -----------------------------------------------------------------------
67cdf0e10cSrcweir 
Paint(const Rectangle &)68cdf0e10cSrcweir void SvxParaPrevWindow::Paint( const Rectangle& )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	DrawParagraph( sal_True );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #define DEF_MARGIN	120
76cdf0e10cSrcweir 
DrawParagraph(sal_Bool bAll)77cdf0e10cSrcweir void SvxParaPrevWindow::DrawParagraph( sal_Bool bAll )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
80cdf0e10cSrcweir     const Color& rWinColor = rStyleSettings.GetWindowColor();
81cdf0e10cSrcweir     Color aGrayColor(COL_LIGHTGRAY);
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     SetFillColor( Color( rWinColor ) );
84cdf0e10cSrcweir     if( bAll )
85cdf0e10cSrcweir         DrawRect( Rectangle( Point(), aWinSize ) );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     SetLineColor();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	long nH = aWinSize.Height() / 19;
90cdf0e10cSrcweir 	Size aLineSiz( aWinSize.Width() - DEF_MARGIN, nH ),
91cdf0e10cSrcweir 		 aSiz = aLineSiz;
92cdf0e10cSrcweir 	Point aPnt;
93cdf0e10cSrcweir 	aPnt.X() = DEF_MARGIN / 2;
94cdf0e10cSrcweir     SetFillColor( aGrayColor );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < 9; ++i )
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir 		if ( 3 == i )
99cdf0e10cSrcweir 		{
100cdf0e10cSrcweir             SetFillColor( Color( COL_GRAY ) );
101cdf0e10cSrcweir             long nTop = nUpper * aLineSiz.Height() / aSize.Height();
102cdf0e10cSrcweir 			aPnt.Y() += nTop * 2;
103cdf0e10cSrcweir 		}
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 		if ( 6 == i )
106cdf0e10cSrcweir             SetFillColor( aGrayColor );
107cdf0e10cSrcweir 
108cdf0e10cSrcweir 		if ( 3 <= i && 6 > i )
109cdf0e10cSrcweir 		{
110cdf0e10cSrcweir 			long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
111cdf0e10cSrcweir 			long nFirst = nFirstLineOfst * aLineSiz.Width() / aSize.Width();
112cdf0e10cSrcweir 			long nTmp = nLeft + nFirst;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 			if ( 3 == i )
115cdf0e10cSrcweir 			{
116cdf0e10cSrcweir 				aPnt.X() += nTmp;
117cdf0e10cSrcweir 				aSiz.Width() -= nTmp;
118cdf0e10cSrcweir 			}
119cdf0e10cSrcweir 			else
120cdf0e10cSrcweir 			{
121cdf0e10cSrcweir 				aPnt.X() += nLeft;
122cdf0e10cSrcweir 				aSiz.Width() -= nLeft;
123cdf0e10cSrcweir 			}
124cdf0e10cSrcweir             long nRight = nRightMargin * aLineSiz.Width() / aSize.Width();
125cdf0e10cSrcweir             aSiz.Width() -= nRight;
126cdf0e10cSrcweir 		}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir 		if ( 4 == i || 5 == i || 6 == i )
129cdf0e10cSrcweir 		{
130cdf0e10cSrcweir 			switch ( eLine )
131cdf0e10cSrcweir 			{
132cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_1:						break;
133cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_15:	aPnt.Y() += nH / 2;	break;
134cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_2:	aPnt.Y() += nH;		break;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_PROP:
137cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_MIN:
138cdf0e10cSrcweir 				case SVX_PREV_LINESPACE_DURCH:					break;
139cdf0e10cSrcweir 			}
140cdf0e10cSrcweir 		}
141cdf0e10cSrcweir 
142cdf0e10cSrcweir 		aPnt.Y() += nH;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         if ( (3 <= i) && (5 >= i) )
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir             long nLW;
147cdf0e10cSrcweir             switch( i )
148cdf0e10cSrcweir             {
149cdf0e10cSrcweir 				default:
150cdf0e10cSrcweir                 case 3: nLW = aLineSiz.Width() * 8 / 10;    break;
151cdf0e10cSrcweir                 case 4: nLW = aLineSiz.Width() * 9 / 10;    break;
152cdf0e10cSrcweir                 case 5: nLW = aLineSiz.Width() / 2;         break;
153cdf0e10cSrcweir             }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 			if ( nLW > aSiz.Width() )
156cdf0e10cSrcweir 				nLW = aSiz.Width();
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 			switch ( eAdjust )
159cdf0e10cSrcweir 			{
160cdf0e10cSrcweir 				case SVX_ADJUST_LEFT:
161cdf0e10cSrcweir 					break;
162cdf0e10cSrcweir 				case SVX_ADJUST_RIGHT:
163cdf0e10cSrcweir 					aPnt.X() += ( aSiz.Width() - nLW );
164cdf0e10cSrcweir 					break;
165cdf0e10cSrcweir 				case SVX_ADJUST_CENTER:
166cdf0e10cSrcweir 					aPnt.X() += ( aSiz.Width() - nLW ) / 2;
167cdf0e10cSrcweir 					break;
168cdf0e10cSrcweir                 default: ; //prevent warning
169cdf0e10cSrcweir             }
170cdf0e10cSrcweir             if( SVX_ADJUST_BLOCK == eAdjust )
171cdf0e10cSrcweir             {
172cdf0e10cSrcweir                 if( 5 == i )
173cdf0e10cSrcweir                 {
174cdf0e10cSrcweir                     switch( eLastLine )
175cdf0e10cSrcweir                     {
176cdf0e10cSrcweir                         case SVX_ADJUST_LEFT:
177cdf0e10cSrcweir                             break;
178cdf0e10cSrcweir                         case SVX_ADJUST_RIGHT:
179cdf0e10cSrcweir                             aPnt.X() += ( aSiz.Width() - nLW );
180cdf0e10cSrcweir                             break;
181cdf0e10cSrcweir                         case SVX_ADJUST_CENTER:
182cdf0e10cSrcweir                             aPnt.X() += ( aSiz.Width() - nLW ) / 2;
183cdf0e10cSrcweir                             break;
184cdf0e10cSrcweir                         case SVX_ADJUST_BLOCK:
185cdf0e10cSrcweir                             nLW = aSiz.Width();
186cdf0e10cSrcweir                             break;
187cdf0e10cSrcweir                         default: ; //prevent warning
188cdf0e10cSrcweir                     }
189cdf0e10cSrcweir                 }
190cdf0e10cSrcweir                 else
191cdf0e10cSrcweir                     nLW = aSiz.Width();
192cdf0e10cSrcweir 			}
193cdf0e10cSrcweir             aSiz.Width() = nLW;
194cdf0e10cSrcweir 		}
195cdf0e10cSrcweir 
196cdf0e10cSrcweir         Rectangle aRect( aPnt, aSiz );
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 		if ( Lines[i] != aRect || bAll )
199cdf0e10cSrcweir 		{
200cdf0e10cSrcweir 			if ( !bAll )
201cdf0e10cSrcweir 			{
202cdf0e10cSrcweir 				Color aFillCol = GetFillColor();
203cdf0e10cSrcweir                 SetFillColor( rWinColor );
204cdf0e10cSrcweir                 DrawRect( Lines[i] );
205cdf0e10cSrcweir 				SetFillColor( aFillCol );
206cdf0e10cSrcweir 			}
207cdf0e10cSrcweir 			DrawRect( aRect );
208cdf0e10cSrcweir 			Lines[i] = aRect;
209cdf0e10cSrcweir 		}
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 		if ( 5 == i )
212cdf0e10cSrcweir 		{
213cdf0e10cSrcweir 			long nBottom = nLower * aLineSiz.Height() / aSize.Height();
214cdf0e10cSrcweir 			aPnt.Y() += nBottom * 2;
215cdf0e10cSrcweir 		}
216cdf0e10cSrcweir 
217cdf0e10cSrcweir 		aPnt.Y() += nH;
218cdf0e10cSrcweir 		// wieder zuruecksetzen, fuer jede Linie neu berechnen
219cdf0e10cSrcweir 		aPnt.X() = DEF_MARGIN / 2;
220cdf0e10cSrcweir 		aSiz = aLineSiz;
221cdf0e10cSrcweir 	}
222cdf0e10cSrcweir }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir #undef DEF_MARGIN
225cdf0e10cSrcweir 
226cdf0e10cSrcweir // -----------------------------------------------------------------------
227cdf0e10cSrcweir 
OutputSizeChanged()228cdf0e10cSrcweir void SvxParaPrevWindow::OutputSizeChanged()
229cdf0e10cSrcweir {
230cdf0e10cSrcweir 	aWinSize = GetOutputSizePixel();
231cdf0e10cSrcweir 	aWinSize = PixelToLogic( aWinSize );
232cdf0e10cSrcweir 	Invalidate();
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235