Update ooo320-m1
[ooovba.git] / sw / source / core / text / porexp.cxx
blobcef17646f7bd90736b2a3f61296973ac0eea5414
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: porexp.cxx,v $
10 * $Revision: 1.19 $
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_sw.hxx"
35 #include <viewopt.hxx> // SwViewOptions
36 #include <SwPortionHandler.hxx>
37 #include <inftxt.hxx>
38 #include <porexp.hxx>
40 /*************************************************************************
41 * class SwExpandPortion
42 *************************************************************************/
44 xub_StrLen SwExpandPortion::GetCrsrOfst( const MSHORT nOfst ) const
45 { return SwLinePortion::GetCrsrOfst( nOfst ); }
47 /*************************************************************************
48 * virtual SwExpandPortion::GetExpTxt()
49 *************************************************************************/
51 sal_Bool SwExpandPortion::GetExpTxt( const SwTxtSizeInfo&,
52 XubString &rTxt ) const
54 rTxt.Erase();
55 // Nicht etwa: return 0 != rTxt.Len();
56 // Weil: leere Felder ersetzen CH_TXTATR gegen einen Leerstring
57 return sal_True;
60 /*************************************************************************
61 * virtual SwExpandPortion::HandlePortion()
62 *************************************************************************/
64 void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
66 String aString;
67 rPH.Special( GetLen(), aString, GetWhichPor() );
70 /*************************************************************************
71 * virtual SwExpandPortion::GetTxtSize()
72 *************************************************************************/
74 SwPosSize SwExpandPortion::GetTxtSize( const SwTxtSizeInfo &rInf ) const
76 SwTxtSlot aDiffTxt( &rInf, this, false, false );
77 return rInf.GetTxtSize();
80 /*************************************************************************
81 * virtual SwExpandPortion::Format()
82 *************************************************************************/
84 // 5010: Exp und Tabs
86 sal_Bool SwExpandPortion::Format( SwTxtFormatInfo &rInf )
88 SwTxtSlot aDiffTxt( &rInf, this, true, false );
89 const xub_StrLen nFullLen = rInf.GetLen();
91 // So komisch es aussieht, die Abfrage auf GetLen() muss wegen der
92 // ExpandPortions _hinter_ aDiffTxt (vgl. SoftHyphs)
93 // sal_False returnen wegen SetFull ...
94 if( !nFullLen )
96 // nicht Init(), weil wir Hoehe und Ascent brauchen
97 Width(0);
98 return sal_False;
100 return SwTxtPortion::Format( rInf );
103 /*************************************************************************
104 * virtual SwExpandPortion::Paint()
105 *************************************************************************/
107 void SwExpandPortion::Paint( const SwTxtPaintInfo &rInf ) const
109 SwTxtSlot aDiffTxt( &rInf, this, true, true );
111 rInf.DrawBackBrush( *this );
113 // do we have to repaint a post it portion?
114 if( rInf.OnWin() && pPortion && !pPortion->Width() )
115 pPortion->PrePaint( rInf, this );
117 // The contents of field portions is not considered during the
118 // calculation of the directions. Therefore we let vcl handle
119 // the calculation by removing the BIDI_STRONG_FLAG temporarily.
120 SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
121 aLayoutModeModifier.SetAuto();
123 // ST2
124 if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
125 rInf.DrawMarkedText( *this, rInf.GetLen(), sal_False, sal_False,
126 0 != rInf.GetSmartTags(), 0 != rInf.GetGrammarCheckList() );
127 else
128 rInf.DrawText( *this, rInf.GetLen(), sal_False );
131 /*************************************************************************
132 * class SwBlankPortion
133 *************************************************************************/
135 SwLinePortion *SwBlankPortion::Compress() { return this; }
137 /*************************************************************************
138 * SwBlankPortion::MayUnderFlow()
139 *************************************************************************/
141 // 5497: Es gibt schon Gemeinheiten auf der Welt...
142 // Wenn eine Zeile voll mit HardBlanks ist und diese ueberlaeuft,
143 // dann duerfen keine Underflows generiert werden!
144 // Komplikationen bei Flys...
146 MSHORT SwBlankPortion::MayUnderFlow( const SwTxtFormatInfo &rInf,
147 xub_StrLen nIdx, sal_Bool bUnderFlow ) const
149 if( rInf.StopUnderFlow() )
150 return 0;
151 const SwLinePortion *pPos = rInf.GetRoot();
152 if( pPos->GetPortion() )
153 pPos = pPos->GetPortion();
154 while( pPos && pPos->IsBlankPortion() )
155 pPos = pPos->GetPortion();
156 if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
157 return 0; // Nur noch BlankPortions unterwegs
158 // Wenn vor uns ein Blank ist, brauchen wir kein Underflow ausloesen,
159 // wenn hinter uns ein Blank ist, brauchen wir kein Underflow weiterreichen
160 if( bUnderFlow && CH_BLANK == rInf.GetTxt().GetChar( nIdx + 1) )
161 return 0;
162 if( nIdx && !((SwTxtFormatInfo&)rInf).GetFly() )
164 while( pPos && !pPos->IsFlyPortion() )
165 pPos = pPos->GetPortion();
166 if( !pPos )
168 //Hier wird ueberprueft, ob es in dieser Zeile noch sinnvolle Umbrueche
169 //gibt, Blanks oder Felder etc., wenn nicht, kein Underflow.
170 //Wenn Flys im Spiel sind, lassen wir das Underflow trotzdem zu.
171 xub_StrLen nBlank = nIdx;
172 while( --nBlank > rInf.GetLineStart() )
174 const xub_Unicode cCh = rInf.GetChar( nBlank );
175 if( CH_BLANK == cCh ||
176 (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
177 && rInf.HasHint( nBlank ) ) )
178 break;
180 if( nBlank <= rInf.GetLineStart() )
181 return 0;
184 xub_Unicode cCh;
185 if( nIdx < 2 || CH_BLANK == (cCh = rInf.GetChar( nIdx - 1 )) )
186 return 1;
187 if( CH_BREAK == cCh )
188 return 0;
189 return 2;
192 /*************************************************************************
193 * virtual SwBlankPortion::FormatEOL()
194 *************************************************************************/
195 // Format end of Line
197 void SwBlankPortion::FormatEOL( SwTxtFormatInfo &rInf )
199 MSHORT nMay = MayUnderFlow( rInf, rInf.GetIdx() - nLineLength, sal_True );
200 if( nMay )
202 if( nMay > 1 )
204 if( rInf.GetLast() == this )
205 rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
206 rInf.X( rInf.X() - PrtWidth() );
207 rInf.SetIdx( rInf.GetIdx() - GetLen() );
209 Truncate();
210 rInf.SetUnderFlow( this );
211 if( rInf.GetLast()->IsKernPortion() )
212 rInf.SetUnderFlow( rInf.GetLast() );
216 /*************************************************************************
217 * virtual SwBlankPortion::Format()
218 *************************************************************************/
220 // 7771: UnderFlows weiterreichen und selbst ausloesen!
221 sal_Bool SwBlankPortion::Format( SwTxtFormatInfo &rInf )
223 const sal_Bool bFull = rInf.IsUnderFlow() || SwExpandPortion::Format( rInf );
224 if( bFull && MayUnderFlow( rInf, rInf.GetIdx(), rInf.IsUnderFlow() ) )
226 Truncate();
227 rInf.SetUnderFlow( this );
228 if( rInf.GetLast()->IsKernPortion() )
229 rInf.SetUnderFlow( rInf.GetLast() );
231 return bFull;
234 /*************************************************************************
235 * virtual SwBlankPortion::Paint()
236 *************************************************************************/
238 void SwBlankPortion::Paint( const SwTxtPaintInfo &rInf ) const
240 if( !bMulti ) // No gray background for multiportion brackets
241 rInf.DrawViewOpt( *this, POR_BLANK );
242 SwExpandPortion::Paint( rInf );
245 /*************************************************************************
246 * virtual SwBlankPortion::GetExpTxt()
247 *************************************************************************/
249 sal_Bool SwBlankPortion::GetExpTxt( const SwTxtSizeInfo&, XubString &rTxt ) const
251 rTxt = cChar;
252 return sal_True;
255 /*************************************************************************
256 * virtual SwBlankPortion::HandlePortion()
257 *************************************************************************/
259 void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
261 String aString( cChar );
262 rPH.Special( GetLen(), aString, GetWhichPor() );
265 /*************************************************************************
266 * class SwPostItsPortion
267 *************************************************************************/
269 SwPostItsPortion::SwPostItsPortion( sal_Bool bScrpt )
270 : nViewWidth(0), bScript( bScrpt )
272 nLineLength = 1;
273 SetWhichPor( POR_POSTITS );
276 void SwPostItsPortion::Paint( const SwTxtPaintInfo &rInf ) const
278 if( rInf.OnWin() && Width() )
279 rInf.DrawPostIts( *this, IsScript() );
282 KSHORT SwPostItsPortion::GetViewWidth( const SwTxtSizeInfo &rInf ) const
284 // Nicht zu fassen: PostIts sind immer zu sehen.
285 return rInf.OnWin() ?
286 (KSHORT)rInf.GetOpt().GetPostItsWidth( rInf.GetOut() ) : 0;
289 /*************************************************************************
290 * virtual SwPostItsPortion::Format()
291 *************************************************************************/
293 sal_Bool SwPostItsPortion::Format( SwTxtFormatInfo &rInf )
295 sal_Bool bRet = SwLinePortion::Format( rInf );
296 // 32749: PostIts sollen keine Auswirkung auf Zeilenhoehe etc. haben
297 SetAscent( 1 );
298 Height( 1 );
299 return bRet;
302 /*************************************************************************
303 * virtual SwPostItsPortion::GetExpTxt()
304 *************************************************************************/
306 sal_Bool SwPostItsPortion::GetExpTxt( const SwTxtSizeInfo &rInf,
307 XubString &rTxt ) const
309 if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
310 rTxt = ' ';
311 else
312 rTxt.Erase();
313 return sal_True;