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