Update ooo320-m1
[ooovba.git] / sw / source / core / text / itrtxt.hxx
blob021741ea4ada19a9c66a7932e370d2950ba9b16c
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 ************************************************************************/
30 #ifndef _ITRTXT_HXX
31 #define _ITRTXT_HXX
32 #include "swtypes.hxx"
33 #include "itratr.hxx"
34 #include "inftxt.hxx"
36 class SwTxtFrm;
37 struct SwPosition;
38 struct SwCrsrMoveState;
39 class SwMarginPortion;
40 class SwFlyPortion;
42 /*************************************************************************
43 * class SwTxtIter
44 *************************************************************************/
46 class SwTxtIter : public SwAttrIter
48 protected:
49 SwLineInfo aLineInf;
50 SwTxtFrm *pFrm;
51 SwTxtInfo *pInf;
52 SwLineLayout *pCurr;
53 SwLineLayout *pPrev;
54 SwTwips nFrameStart;
55 SwTwips nY;
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
60 sal_Bool bPrev : 1;
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.
69 void Init();
70 void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf );
71 inline SwTxtIter(SwTxtNode* pTxtNode) : SwAttrIter(pTxtNode) { }
73 public:
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(); }
93 void Bottom();
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 /*************************************************************************
135 * class SwTxtMargin
136 *************************************************************************/
138 class SwTxtMargin : public SwTxtIter
140 private:
141 SwTwips nLeft;
142 SwTwips nRight;
143 SwTwips nFirst;
144 KSHORT nDropLeft;
145 KSHORT nDropHeight;
146 KSHORT nDropDescent;
147 MSHORT nDropLines;
148 MSHORT nAdjust;
149 // --> OD 2008-06-30 #i91133#
150 SwTwips mnTabLeft;
151 // <--
153 protected:
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) { }
161 public:
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
184 return mnTabLeft;
186 // <--
187 // DropCaps
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; }
195 void DropInit();
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
220 void FormatBlock( );
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 );
229 protected:
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 );
235 public:
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 /*************************************************************************
255 * class SwTxtCursor
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* );
267 protected:
268 void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
269 inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
270 public:
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 /*************************************************************************
293 * SwHookOut
295 * Change current output device to printer, this has to be done before
296 * formatting.
297 *************************************************************************/
299 class SwHookOut
301 SwTxtSizeInfo* pInf;
302 OutputDevice* pOut;
303 sal_Bool bOnWin;
304 public:
305 SwHookOut( SwTxtSizeInfo& rInfo );
306 ~SwHookOut();
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 )
320 if ( rInf.GetIdx() )
321 return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() );
322 else
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;
343 #endif