update dev300-m58
[ooovba.git] / svx / source / dialog / paraprev.cxx
blobfbe5c771b3a35de84291eeec7ae25f60cea26158
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: paraprev.cxx,v $
10 * $Revision: 1.14 $
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 ---------------------------------------------------------------
36 #include <svx/paraprev.hxx>
38 // STATIC DATA -----------------------------------------------------------
40 #define FOUR_POINTS 80
42 // class SvxParaPrevWindow -----------------------------------------------
44 SvxParaPrevWindow::SvxParaPrevWindow( Window* pParent, const ResId& rId ) :
46 Window( pParent, rId ),
48 nLeftMargin ( 0 ),
49 nRightMargin ( 0 ),
50 nFirstLineOfst ( 0 ),
51 nUpper ( 0 ),
52 nLower ( 0 ),
53 eAdjust ( SVX_ADJUST_LEFT ),
54 eLastLine ( SVX_ADJUST_LEFT ),
55 eLine ( SVX_PREV_LINESPACE_1 ),
56 nLineVal ( 0 )
59 // defaultmaessing in Twips rechnen
60 SetMapMode( MapMode( MAP_TWIP ) );
61 aWinSize = GetOutputSizePixel();
62 aWinSize = PixelToLogic( aWinSize );
63 Size aTmp(1, 1);
64 aTmp = PixelToLogic(aTmp);
65 aWinSize.Width() -= aTmp.Width() /2;
66 aWinSize.Height() -= aTmp.Height() /2;
68 aSize = Size( 11905, 16837 );
70 SetBorderStyle( WINDOW_BORDER_MONO );
73 // -----------------------------------------------------------------------
75 void SvxParaPrevWindow::Paint( const Rectangle& )
77 DrawParagraph( TRUE );
80 // -----------------------------------------------------------------------
82 #define DEF_MARGIN 120
84 void SvxParaPrevWindow::DrawParagraph( BOOL bAll )
86 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
87 const Color& rWinColor = rStyleSettings.GetWindowColor();
88 Color aGrayColor(COL_LIGHTGRAY);
90 SetFillColor( Color( rWinColor ) );
91 if( bAll )
92 DrawRect( Rectangle( Point(), aWinSize ) );
94 SetLineColor();
96 long nH = aWinSize.Height() / 19;
97 Size aLineSiz( aWinSize.Width() - DEF_MARGIN, nH ),
98 aSiz = aLineSiz;
99 Point aPnt;
100 aPnt.X() = DEF_MARGIN / 2;
101 SetFillColor( aGrayColor );
103 for ( USHORT i = 0; i < 9; ++i )
105 if ( 3 == i )
107 SetFillColor( Color( COL_GRAY ) );
108 long nTop = nUpper * aLineSiz.Height() / aSize.Height();
109 aPnt.Y() += nTop * 2;
112 if ( 6 == i )
113 SetFillColor( aGrayColor );
115 if ( 3 <= i && 6 > i )
117 long nLeft = nLeftMargin * aLineSiz.Width() / aSize.Width();
118 long nFirst = nFirstLineOfst * aLineSiz.Width() / aSize.Width();
119 long nTmp = nLeft + nFirst;
121 if ( 3 == i )
123 aPnt.X() += nTmp;
124 aSiz.Width() -= nTmp;
126 else
128 aPnt.X() += nLeft;
129 aSiz.Width() -= nLeft;
131 long nRight = nRightMargin * aLineSiz.Width() / aSize.Width();
132 aSiz.Width() -= nRight;
135 if ( 4 == i || 5 == i || 6 == i )
137 switch ( eLine )
139 case SVX_PREV_LINESPACE_1: break;
140 case SVX_PREV_LINESPACE_15: aPnt.Y() += nH / 2; break;
141 case SVX_PREV_LINESPACE_2: aPnt.Y() += nH; break;
143 case SVX_PREV_LINESPACE_PROP:
144 case SVX_PREV_LINESPACE_MIN:
145 case SVX_PREV_LINESPACE_DURCH: break;
149 aPnt.Y() += nH;
151 if ( (3 <= i) && (5 >= i) )
153 long nLW;
154 switch( i )
156 default:
157 case 3: nLW = aLineSiz.Width() * 8 / 10; break;
158 case 4: nLW = aLineSiz.Width() * 9 / 10; break;
159 case 5: nLW = aLineSiz.Width() / 2; break;
162 if ( nLW > aSiz.Width() )
163 nLW = aSiz.Width();
165 switch ( eAdjust )
167 case SVX_ADJUST_LEFT:
168 break;
169 case SVX_ADJUST_RIGHT:
170 aPnt.X() += ( aSiz.Width() - nLW );
171 break;
172 case SVX_ADJUST_CENTER:
173 aPnt.X() += ( aSiz.Width() - nLW ) / 2;
174 break;
175 default: ; //prevent warning
177 if( SVX_ADJUST_BLOCK == eAdjust )
179 if( 5 == i )
181 switch( eLastLine )
183 case SVX_ADJUST_LEFT:
184 break;
185 case SVX_ADJUST_RIGHT:
186 aPnt.X() += ( aSiz.Width() - nLW );
187 break;
188 case SVX_ADJUST_CENTER:
189 aPnt.X() += ( aSiz.Width() - nLW ) / 2;
190 break;
191 case SVX_ADJUST_BLOCK:
192 nLW = aSiz.Width();
193 break;
194 default: ; //prevent warning
197 else
198 nLW = aSiz.Width();
200 aSiz.Width() = nLW;
203 Rectangle aRect( aPnt, aSiz );
205 if ( Lines[i] != aRect || bAll )
207 if ( !bAll )
209 Color aFillCol = GetFillColor();
210 SetFillColor( rWinColor );
211 DrawRect( Lines[i] );
212 SetFillColor( aFillCol );
214 DrawRect( aRect );
215 Lines[i] = aRect;
218 if ( 5 == i )
220 long nBottom = nLower * aLineSiz.Height() / aSize.Height();
221 aPnt.Y() += nBottom * 2;
224 aPnt.Y() += nH;
225 // wieder zuruecksetzen, fuer jede Linie neu berechnen
226 aPnt.X() = DEF_MARGIN / 2;
227 aSiz = aLineSiz;
231 #undef DEF_MARGIN
233 // -----------------------------------------------------------------------
235 void SvxParaPrevWindow::OutputSizeChanged()
237 aWinSize = GetOutputSizePixel();
238 aWinSize = PixelToLogic( aWinSize );
239 Invalidate();