1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: itrtxt.hxx,v $
10 * $Revision: 1.21.40.3 $
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 ************************************************************************/
32 #include "swtypes.hxx"
38 struct SwCrsrMoveState
;
39 class SwMarginPortion
;
42 /*************************************************************************
44 *************************************************************************/
46 class SwTxtIter
: public SwAttrIter
56 SwTwips nRegStart
; // Anfangsposition (Y) des Registers
57 xub_StrLen nStart
; // Start im Textstring, Ende = pCurr->GetLen()
58 KSHORT nRegDiff
; // Zeilenabstand des Registers
59 MSHORT nLineNr
; // Zeilennummer
61 sal_Bool bRegisterOn
: 1; // Registerhaltigkeit
62 sal_Bool bOneBlock
: 1; // Blocksatz: Einzelwoerter austreiben
63 sal_Bool bLastBlock
: 1; // Blocksatz: Auch die letzte Zeile
64 sal_Bool bLastCenter
: 1; // Blocksatz: Letzte Zeile zentrieren
66 SwLineLayout
*_GetPrev();
68 // Zuruecksetzen in die erste Zeile.
70 void CtorInitTxtIter( SwTxtFrm
*pFrm
, SwTxtInfo
*pInf
);
71 inline SwTxtIter(SwTxtNode
* pTxtNode
) : SwAttrIter(pTxtNode
) { }
74 inline SwTxtIter( SwTxtFrm
*pTxtFrm
, SwTxtInfo
*pTxtInf
) : SwAttrIter(pTxtFrm
!=NULL
?pTxtFrm
->GetTxtNode():NULL
)
75 { CtorInitTxtIter( pTxtFrm
, pTxtInf
); }
76 inline const SwLineLayout
*GetCurr() const { return pCurr
; } // niemals 0!
77 inline const SwLineLayout
*GetNext() const { return pCurr
->GetNext(); }
78 const SwLineLayout
*GetPrev();
79 inline xub_StrLen
GetLength() const { return pCurr
->GetLen(); }
80 inline MSHORT
GetLineNr() const { return nLineNr
; }
81 inline xub_StrLen
GetStart() const { return nStart
; }
82 inline xub_StrLen
GetEnd() const { return GetStart() + GetLength(); }
83 inline SwTwips
Y() const { return nY
; }
85 inline SwTwips
RegStart() const { return nRegStart
; }
86 inline KSHORT
RegDiff() const { return nRegDiff
; }
87 inline sal_Bool
IsRegisterOn() const { return bRegisterOn
; }
89 inline SwTxtInfo
&GetInfo() { return *pInf
; }
90 inline const SwTxtInfo
&GetInfo() const { return *pInf
; }
92 inline void Top() { Init(); }
94 const SwLineLayout
*Next();
95 const SwLineLayout
*Prev();
97 // Ueberspringt die Dummyzeilen der FlyFrms
98 const SwLineLayout
*NextLine();
99 const SwLineLayout
*PrevLine();
100 const SwLineLayout
*GetNextLine() const;
101 const SwLineLayout
*GetPrevLine();
103 void CharToLine( const xub_StrLen
);
104 const SwLineLayout
*TwipsToLine(const SwTwips
);
106 // schneidet ab pCurr alle ab.
107 void TruncLines( sal_Bool bNoteFollow
= sal_False
);
109 inline KSHORT
GetLineHeight() const { return pCurr
->GetRealHeight(); }
110 void CalcAscentAndHeight( KSHORT
&rAscent
, KSHORT
&rHeight
) const;
112 // 5298, viel Aerger durch die Abfrage auf pCurr == pPara
113 inline sal_Bool
IsFirstTxtLine() const
114 { return nStart
== GetInfo().GetTxtStart() &&
115 !( pCurr
->IsDummy() && GetNextLine() ); }
117 // Als Ersatz fuer das alte IsFirstLine()
118 inline sal_Bool
IsParaLine() const
119 { return pCurr
== pInf
->GetParaPortion(); }
121 const SwLineInfo
&GetLineInfo() const { return aLineInf
; }
122 inline SwTwips
GetFirstPos() const { return nFrameStart
; }
123 inline sal_Bool
SeekAndChg( SwTxtSizeInfo
&rInf
);
124 inline sal_Bool
SeekAndChgBefore( SwTxtSizeInfo
&rInf
);
125 inline sal_Bool
SeekStartAndChg( SwTxtSizeInfo
&rInf
, const sal_Bool bPara
=sal_False
);
127 inline SwTxtFrm
*GetTxtFrm() { return pFrm
; }
128 inline const SwTxtFrm
*GetTxtFrm() const { return pFrm
; }
130 // zaehlt aufeinanderfolgende Trennungen, um MaxHyphens einzuhalten
131 void CntHyphens( sal_uInt8
&nEndCnt
, sal_uInt8
&nMidCnt
) const;
134 /*************************************************************************
136 *************************************************************************/
138 class SwTxtMargin
: public SwTxtIter
149 // --> OD 2008-06-30 #i91133#
154 // fuer FormatQuoVadis
155 inline void Right( const SwTwips nNew
) { nRight
= nNew
; }
156 // fuer CalcFlyAdjust
157 inline void SetDropLeft( const KSHORT nNew
) { nDropLeft
= nNew
; }
159 void CtorInitTxtMargin( SwTxtFrm
*pFrm
, SwTxtSizeInfo
*pInf
);
160 inline SwTxtMargin(SwTxtNode
* pTxtNode
) : SwTxtIter(pTxtNode
) { }
162 inline SwTxtMargin( SwTxtFrm
*pTxtFrm
, SwTxtSizeInfo
*pTxtSizeInf
) : SwTxtIter(pTxtFrm
!=NULL
?pTxtFrm
->GetTxtNode():NULL
)
163 { CtorInitTxtMargin( pTxtFrm
, pTxtSizeInf
); }
164 inline SwTwips
GetLeftMargin() const;
165 inline SwTwips
Left() const;
166 inline SwTwips
Right() const { return nRight
; }
167 inline SwTwips
FirstLeft() const { return nFirst
; }
168 inline SwTwips
CurrWidth() const { return pCurr
->PrtWidth(); }
169 SwTwips
GetLineStart() const;
170 inline SwTwips
GetLineEnd() const { return GetLineStart() + CurrWidth(); }
171 inline Point
GetTopLeft() const { return Point( GetLineStart(), Y() ); }
172 inline sal_Bool
IsOneBlock() const { return bOneBlock
; }
173 inline sal_Bool
IsLastBlock() const { return bLastBlock
; }
174 inline sal_Bool
IsLastCenter() const { return bLastCenter
; }
175 inline MSHORT
GetAdjust() const { return nAdjust
; }
176 inline KSHORT
GetLineWidth() const
177 { return KSHORT( Right() - GetLeftMargin() + 1 ); }
178 inline SwTwips
GetLeftMin() const { return nFirst
< nLeft
? nFirst
: nLeft
; }
179 inline sal_Bool
HasNegFirst() const { return nFirst
< nLeft
; }
181 // --> OD 2008-06-30 #i91133#
182 inline SwTwips
GetTabLeft() const
188 inline MSHORT
GetDropLines() const { return nDropLines
; }
189 inline void SetDropLines( const MSHORT nNew
) { nDropLines
= nNew
; }
190 inline KSHORT
GetDropLeft() const { return nDropLeft
; }
191 inline KSHORT
GetDropHeight() const { return nDropHeight
; }
192 inline void SetDropHeight( const KSHORT nNew
) { nDropHeight
= nNew
; }
193 inline KSHORT
GetDropDescent() const { return nDropDescent
; }
194 inline void SetDropDescent( const KSHORT nNew
) { nDropDescent
= nNew
; }
197 // liefert TxtPos fuer Start und Ende der aktuellen Zeile ohne whitespaces
198 // In frminf.cxx implementiert.
199 xub_StrLen
GetTxtStart() const;
200 xub_StrLen
GetTxtEnd() const;
202 inline SwTxtSizeInfo
&GetInfo()
203 { return (SwTxtSizeInfo
&)SwTxtIter::GetInfo(); }
204 inline const SwTxtSizeInfo
&GetInfo() const
205 { return (const SwTxtSizeInfo
&)SwTxtIter::GetInfo(); }
210 /*************************************************************************
211 * class SwTxtAdjuster
212 *************************************************************************/
214 class SwTxtAdjuster
: public SwTxtMargin
216 // Gleicht die Portions aus, wenn Adjustment und FlyFrms vorliegen.
217 void CalcFlyAdjust( SwLineLayout
*pCurr
);
219 // ruft SplitGlues und CalcBlockAdjust
222 // Erstellt bei kurzen Zeilen die Glue-Kette.
223 SwMarginPortion
* CalcRightMargin( SwLineLayout
*pCurr
, SwTwips nReal
= 0 );
225 // Berechnung des Adjustments (FlyPortions)
226 SwFlyPortion
*CalcFlyPortion( const long nRealWidth
,
227 const SwRect
&rCurrRect
);
230 inline SwTxtAdjuster(SwTxtNode
* pTxtNode
) : SwTxtMargin(pTxtNode
) { }
231 // spannt beim Blocksatz die Glues auf.
232 void CalcNewBlock( SwLineLayout
*pCurr
, const SwLinePortion
*pStopAt
,
233 SwTwips nReal
= 0, bool bSkipKashida
= false );
234 SwTwips
CalcKanaAdj( SwLineLayout
*pCurr
);
236 inline SwTxtAdjuster( SwTxtFrm
*pTxtFrm
, SwTxtSizeInfo
*pTxtSizeInf
) : SwTxtMargin(pTxtFrm
!=NULL
?pTxtFrm
->GetTxtNode():NULL
)
237 { CtorInitTxtMargin( pTxtFrm
, pTxtSizeInf
); }
239 // wird von SwTxtFormatter wegen UpdatePos ueberladen
240 void CalcAdjLine( SwLineLayout
*pCurr
);
242 // sorgt fuer das nachtraegliche adjustieren
243 inline void GetAdjusted() const
245 if( pCurr
->IsFormatAdj() )
246 ((SwTxtAdjuster
*)this)->CalcAdjLine( pCurr
);
249 // DropCaps-Extrawurst
250 void CalcDropAdjust();
251 void CalcDropRepaint();
254 /*************************************************************************
256 *************************************************************************/
258 class SwTxtCursor
: public SwTxtAdjuster
260 // A small helper-class to save SwTxtCursor member, manipulate them
261 // and to restore them
262 friend class SwTxtCursorSave
;
264 // 1170: Mehrdeutigkeiten
265 static sal_Bool bRightMargin
;
266 void _GetCharRect(SwRect
*, const xub_StrLen
, SwCrsrMoveState
* );
268 void CtorInitTxtCursor( SwTxtFrm
*pFrm
, SwTxtSizeInfo
*pInf
);
269 inline SwTxtCursor(SwTxtNode
* pTxtNode
) : SwTxtAdjuster(pTxtNode
) { }
271 inline SwTxtCursor( SwTxtFrm
*pTxtFrm
, SwTxtSizeInfo
*pTxtSizeInf
) : SwTxtAdjuster(pTxtFrm
!=NULL
?pTxtFrm
->GetTxtNode():NULL
)
272 { CtorInitTxtCursor( pTxtFrm
, pTxtSizeInf
); }
273 sal_Bool
GetCharRect(SwRect
*, const xub_StrLen
, SwCrsrMoveState
* = 0,
274 const long nMax
= 0 );
275 sal_Bool
GetEndCharRect(SwRect
*, const xub_StrLen
, SwCrsrMoveState
* = 0,
276 const long nMax
= 0 );
277 xub_StrLen
GetCrsrOfst( SwPosition
*pPos
, const Point
&rPoint
,
278 const MSHORT nChgNode
, SwCrsrMoveState
* = 0 ) const;
279 // 1170: beruecksichtigt Mehrdeutigkeiten; Implementierung s.u.
280 const SwLineLayout
*CharCrsrToLine( const xub_StrLen nPos
);
282 // calculates baseline for portion rPor
283 // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE
284 USHORT
AdjustBaseLine( const SwLineLayout
& rLine
, const SwLinePortion
* pPor
,
285 USHORT nPorHeight
= 0, USHORT nAscent
= 0,
286 const sal_Bool bAutoToCentered
= sal_False
) const;
288 static inline void SetRightMargin( const sal_Bool bNew
){ bRightMargin
= bNew
; }
289 static inline sal_Bool
IsRightMargin() { return bRightMargin
; }
292 /*************************************************************************
295 * Change current output device to printer, this has to be done before
297 *************************************************************************/
305 SwHookOut( SwTxtSizeInfo
& rInfo
);
309 /*************************************************************************
310 * Inline-Implementierungen
311 *************************************************************************/
313 inline sal_Bool
SwTxtIter::SeekAndChg( SwTxtSizeInfo
&rInf
)
315 return SeekAndChgAttrIter( rInf
.GetIdx(), rInf
.GetOut() );
318 inline sal_Bool
SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo
&rInf
)
321 return SeekAndChgAttrIter( rInf
.GetIdx()-1, rInf
.GetOut() );
323 return SeekAndChgAttrIter( rInf
.GetIdx(), rInf
.GetOut() );
326 inline sal_Bool
SwTxtIter::SeekStartAndChg( SwTxtSizeInfo
&rInf
, const sal_Bool bPara
)
328 return SeekStartAndChgAttrIter( rInf
.GetOut(), bPara
);
331 inline SwTwips
SwTxtMargin::GetLeftMargin() const
333 return IsFirstTxtLine() ? nFirst
: Left();
336 inline SwTwips
SwTxtMargin::Left() const
338 return (nDropLines
>= nLineNr
&& 1 != nLineNr
) ? nFirst
+ nDropLeft
: nLeft
;