Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include <viewopt.hxx> // SwViewOptions
21 : : #include <SwPortionHandler.hxx>
22 : : #include <inftxt.hxx>
23 : : #include <porexp.hxx>
24 : :
25 : : /*************************************************************************
26 : : * class SwExpandPortion
27 : : *************************************************************************/
28 : :
29 : 0 : xub_StrLen SwExpandPortion::GetCrsrOfst( const MSHORT nOfst ) const
30 : 0 : { return SwLinePortion::GetCrsrOfst( nOfst ); }
31 : :
32 : : /*************************************************************************
33 : : * virtual SwExpandPortion::GetExpTxt()
34 : : *************************************************************************/
35 : :
36 : 0 : sal_Bool SwExpandPortion::GetExpTxt( const SwTxtSizeInfo&,
37 : : XubString &rTxt ) const
38 : : {
39 : 0 : rTxt.Erase();
40 : : // Nicht etwa: return 0 != rTxt.Len();
41 : : // Weil: leere Felder ersetzen CH_TXTATR gegen einen Leerstring
42 : 0 : return sal_True;
43 : : }
44 : :
45 : : /*************************************************************************
46 : : * virtual SwExpandPortion::HandlePortion()
47 : : *************************************************************************/
48 : :
49 : 0 : void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
50 : : {
51 [ # # ]: 0 : String aString;
52 [ # # ][ # # ]: 0 : rPH.Special( GetLen(), aString, GetWhichPor() );
53 : 0 : }
54 : :
55 : : /*************************************************************************
56 : : * virtual SwExpandPortion::GetTxtSize()
57 : : *************************************************************************/
58 : :
59 : 0 : SwPosSize SwExpandPortion::GetTxtSize( const SwTxtSizeInfo &rInf ) const
60 : : {
61 [ # # ]: 0 : SwTxtSlot aDiffTxt( &rInf, this, false, false );
62 [ # # ][ # # ]: 0 : return rInf.GetTxtSize();
63 : : }
64 : :
65 : : /*************************************************************************
66 : : * virtual SwExpandPortion::Format()
67 : : *************************************************************************/
68 : :
69 : : // 5010: Exp und Tabs
70 : :
71 : 18 : sal_Bool SwExpandPortion::Format( SwTxtFormatInfo &rInf )
72 : : {
73 [ + - ]: 18 : SwTxtSlot aDiffTxt( &rInf, this, true, false );
74 : 18 : const xub_StrLen nFullLen = rInf.GetLen();
75 : :
76 : : // So komisch es aussieht, die Abfrage auf GetLen() muss wegen der
77 : : // ExpandPortions _hinter_ aDiffTxt (vgl. SoftHyphs)
78 : : // sal_False returnen wegen SetFull ...
79 [ - + ]: 18 : if( !nFullLen )
80 : : {
81 : : // nicht Init(), weil wir Hoehe und Ascent brauchen
82 : 0 : Width(0);
83 : 0 : return sal_False;
84 : : }
85 [ + - ][ + - ]: 18 : return SwTxtPortion::Format( rInf );
86 : : }
87 : :
88 : : /*************************************************************************
89 : : * virtual SwExpandPortion::Paint()
90 : : *************************************************************************/
91 : :
92 : 1822 : void SwExpandPortion::Paint( const SwTxtPaintInfo &rInf ) const
93 : : {
94 [ + - ]: 1822 : SwTxtSlot aDiffTxt( &rInf, this, true, true );
95 : :
96 [ + - ]: 1822 : rInf.DrawBackBrush( *this );
97 : :
98 : : // do we have to repaint a post it portion?
99 [ + + ][ + + ]: 1822 : if( rInf.OnWin() && pPortion && !pPortion->Width() )
[ + + ][ + + ]
100 [ + - ]: 166 : pPortion->PrePaint( rInf, this );
101 : :
102 : : // The contents of field portions is not considered during the
103 : : // calculation of the directions. Therefore we let vcl handle
104 : : // the calculation by removing the BIDI_STRONG_FLAG temporarily.
105 [ + - ]: 1822 : SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
106 [ + - ]: 1822 : aLayoutModeModifier.SetAuto();
107 : :
108 : : // ST2
109 [ + - ][ + + ]: 1822 : if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
[ + + ]
110 : 7 : rInf.DrawMarkedText( *this, rInf.GetLen(), sal_False, sal_False,
111 [ + - ]: 14 : 0 != rInf.GetSmartTags(), 0 != rInf.GetGrammarCheckList() );
112 : : else
113 [ + - ][ + - ]: 1822 : rInf.DrawText( *this, rInf.GetLen(), sal_False );
[ + - ]
114 : 1822 : }
115 : :
116 : : /*************************************************************************
117 : : * class SwBlankPortion
118 : : *************************************************************************/
119 : :
120 : 18 : SwLinePortion *SwBlankPortion::Compress() { return this; }
121 : :
122 : : /*************************************************************************
123 : : * SwBlankPortion::MayUnderFlow()
124 : : *************************************************************************/
125 : :
126 : : // 5497: Es gibt schon Gemeinheiten auf der Welt...
127 : : // Wenn eine Zeile voll mit HardBlanks ist und diese ueberlaeuft,
128 : : // dann duerfen keine Underflows generiert werden!
129 : : // Komplikationen bei Flys...
130 : :
131 : 0 : MSHORT SwBlankPortion::MayUnderFlow( const SwTxtFormatInfo &rInf,
132 : : xub_StrLen nIdx, sal_Bool bUnderFlow ) const
133 : : {
134 [ # # ]: 0 : if( rInf.StopUnderFlow() )
135 : 0 : return 0;
136 : 0 : const SwLinePortion *pPos = rInf.GetRoot();
137 [ # # ]: 0 : if( pPos->GetPortion() )
138 : 0 : pPos = pPos->GetPortion();
139 [ # # ][ # # ]: 0 : while( pPos && pPos->IsBlankPortion() )
[ # # ]
140 : 0 : pPos = pPos->GetPortion();
141 [ # # ][ # # ]: 0 : if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
[ # # ][ # # ]
[ # # ]
142 : 0 : return 0; // Nur noch BlankPortions unterwegs
143 : : // Wenn vor uns ein Blank ist, brauchen wir kein Underflow ausloesen,
144 : : // wenn hinter uns ein Blank ist, brauchen wir kein Underflow weiterreichen
145 [ # # ][ # # ]: 0 : if( bUnderFlow && CH_BLANK == rInf.GetTxt().GetChar( nIdx + 1) )
[ # # ]
146 : 0 : return 0;
147 [ # # ][ # # ]: 0 : if( nIdx && !((SwTxtFormatInfo&)rInf).GetFly() )
[ # # ]
148 : : {
149 [ # # ][ # # ]: 0 : while( pPos && !pPos->IsFlyPortion() )
[ # # ]
150 : 0 : pPos = pPos->GetPortion();
151 [ # # ]: 0 : if( !pPos )
152 : : {
153 : : //Hier wird ueberprueft, ob es in dieser Zeile noch sinnvolle Umbrueche
154 : : //gibt, Blanks oder Felder etc., wenn nicht, kein Underflow.
155 : : //Wenn Flys im Spiel sind, lassen wir das Underflow trotzdem zu.
156 : 0 : xub_StrLen nBlank = nIdx;
157 [ # # ]: 0 : while( --nBlank > rInf.GetLineStart() )
158 : : {
159 : 0 : const xub_Unicode cCh = rInf.GetChar( nBlank );
160 [ # # ]: 0 : if( CH_BLANK == cCh ||
[ # # # # ]
[ # # ][ # # ]
161 : : (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
162 : 0 : && rInf.HasHint( nBlank ) ) )
163 : 0 : break;
164 : : }
165 [ # # ]: 0 : if( nBlank <= rInf.GetLineStart() )
166 : 0 : return 0;
167 : : }
168 : : }
169 : : xub_Unicode cCh;
170 [ # # ][ # # ]: 0 : if( nIdx < 2 || CH_BLANK == (cCh = rInf.GetChar( nIdx - 1 )) )
[ # # ]
171 : 0 : return 1;
172 [ # # ]: 0 : if( CH_BREAK == cCh )
173 : 0 : return 0;
174 : 0 : return 2;
175 : : }
176 : :
177 : : /*************************************************************************
178 : : * virtual SwBlankPortion::FormatEOL()
179 : : *************************************************************************/
180 : : // Format end of Line
181 : :
182 : 0 : void SwBlankPortion::FormatEOL( SwTxtFormatInfo &rInf )
183 : : {
184 : 0 : MSHORT nMay = MayUnderFlow( rInf, rInf.GetIdx() - nLineLength, sal_True );
185 [ # # ]: 0 : if( nMay )
186 : : {
187 [ # # ]: 0 : if( nMay > 1 )
188 : : {
189 [ # # ]: 0 : if( rInf.GetLast() == this )
190 : 0 : rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
191 : 0 : rInf.X( rInf.X() - PrtWidth() );
192 : 0 : rInf.SetIdx( rInf.GetIdx() - GetLen() );
193 : : }
194 : 0 : Truncate();
195 : 0 : rInf.SetUnderFlow( this );
196 [ # # ]: 0 : if( rInf.GetLast()->IsKernPortion() )
197 : 0 : rInf.SetUnderFlow( rInf.GetLast() );
198 : : }
199 : 0 : }
200 : :
201 : : /*************************************************************************
202 : : * virtual SwBlankPortion::Format()
203 : : *************************************************************************/
204 : :
205 : : // 7771: UnderFlows weiterreichen und selbst ausloesen!
206 : 18 : sal_Bool SwBlankPortion::Format( SwTxtFormatInfo &rInf )
207 : : {
208 [ + - ][ - + ]: 18 : const sal_Bool bFull = rInf.IsUnderFlow() || SwExpandPortion::Format( rInf );
209 [ - + ][ # # ]: 18 : if( bFull && MayUnderFlow( rInf, rInf.GetIdx(), rInf.IsUnderFlow() ) )
[ - + ]
210 : : {
211 : 0 : Truncate();
212 : 0 : rInf.SetUnderFlow( this );
213 [ # # ]: 0 : if( rInf.GetLast()->IsKernPortion() )
214 : 0 : rInf.SetUnderFlow( rInf.GetLast() );
215 : : }
216 : 18 : return bFull;
217 : : }
218 : :
219 : : /*************************************************************************
220 : : * virtual SwBlankPortion::Paint()
221 : : *************************************************************************/
222 : :
223 : 54 : void SwBlankPortion::Paint( const SwTxtPaintInfo &rInf ) const
224 : : {
225 [ + + ]: 54 : if( !bMulti ) // No gray background for multiportion brackets
226 : 18 : rInf.DrawViewOpt( *this, POR_BLANK );
227 : 54 : SwExpandPortion::Paint( rInf );
228 : 54 : }
229 : :
230 : : /*************************************************************************
231 : : * virtual SwBlankPortion::GetExpTxt()
232 : : *************************************************************************/
233 : :
234 : 72 : sal_Bool SwBlankPortion::GetExpTxt( const SwTxtSizeInfo&, XubString &rTxt ) const
235 : : {
236 : 72 : rTxt = cChar;
237 : 72 : return sal_True;
238 : : }
239 : :
240 : : /*************************************************************************
241 : : * virtual SwBlankPortion::HandlePortion()
242 : : *************************************************************************/
243 : :
244 : 0 : void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
245 : : {
246 : 0 : rtl::OUString aString( cChar );
247 [ # # ][ # # ]: 0 : rPH.Special( GetLen(), aString, GetWhichPor() );
[ # # ]
248 : 0 : }
249 : :
250 : : /*************************************************************************
251 : : * class SwPostItsPortion
252 : : *************************************************************************/
253 : :
254 : 18 : SwPostItsPortion::SwPostItsPortion( sal_Bool bScrpt )
255 : 18 : : nViewWidth(0), bScript( bScrpt )
256 : : {
257 : 18 : nLineLength = 1;
258 : 18 : SetWhichPor( POR_POSTITS );
259 : 18 : }
260 : :
261 : 9 : void SwPostItsPortion::Paint( const SwTxtPaintInfo &rInf ) const
262 : : {
263 [ + + ][ + + ]: 9 : if( rInf.OnWin() && Width() )
[ + + ]
264 : 3 : rInf.DrawPostIts( *this, IsScript() );
265 : 9 : }
266 : :
267 : 3 : KSHORT SwPostItsPortion::GetViewWidth( const SwTxtSizeInfo &rInf ) const
268 : : {
269 : : // Nicht zu fassen: PostIts sind immer zu sehen.
270 : 3 : return rInf.OnWin() ?
271 [ + - ]: 3 : (KSHORT)rInf.GetOpt().GetPostItsWidth( rInf.GetOut() ) : 0;
272 : : }
273 : :
274 : : /*************************************************************************
275 : : * virtual SwPostItsPortion::Format()
276 : : *************************************************************************/
277 : :
278 : 18 : sal_Bool SwPostItsPortion::Format( SwTxtFormatInfo &rInf )
279 : : {
280 : 18 : sal_Bool bRet = SwLinePortion::Format( rInf );
281 : : // 32749: PostIts sollen keine Auswirkung auf Zeilenhoehe etc. haben
282 : 18 : SetAscent( 1 );
283 : 18 : Height( 1 );
284 : 18 : return bRet;
285 : : }
286 : :
287 : : /*************************************************************************
288 : : * virtual SwPostItsPortion::GetExpTxt()
289 : : *************************************************************************/
290 : :
291 : 0 : sal_Bool SwPostItsPortion::GetExpTxt( const SwTxtSizeInfo &rInf,
292 : : XubString &rTxt ) const
293 : : {
294 [ # # ][ # # ]: 0 : if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
[ # # ]
295 : 0 : rTxt = ' ';
296 : : else
297 : 0 : rTxt.Erase();
298 : 0 : return sal_True;
299 : : }
300 : :
301 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|