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