xref: /trunk/main/sw/source/core/text/itrtxt.hxx (revision 1d2dbeb0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ITRTXT_HXX
24 #define _ITRTXT_HXX
25 #include "swtypes.hxx"
26 #include "itratr.hxx"
27 #include "inftxt.hxx"
28 
29 class SwTxtFrm;
30 struct SwPosition;
31 struct SwCrsrMoveState;
32 class SwMarginPortion;
33 class SwFlyPortion;
34 
35 /*************************************************************************
36  *						class SwTxtIter
37  *************************************************************************/
38 
39 class SwTxtIter : public SwAttrIter
40 {
41 protected:
42 	SwLineInfo aLineInf;
43     SwTxtFrm  *pFrm;
44 	SwTxtInfo *pInf;
45 	SwLineLayout *pCurr;
46 	SwLineLayout *pPrev;
47     SwTwips nFrameStart;
48     SwTwips nY;
49 	SwTwips	nRegStart;			// Anfangsposition (Y) des Registers
50 	xub_StrLen nStart;			// Start im Textstring, Ende = pCurr->GetLen()
51 	KSHORT nRegDiff;			// Zeilenabstand des Registers
52 	MSHORT nLineNr;				// Zeilennummer
53 	sal_Bool bPrev			: 1;
54 	sal_Bool bRegisterOn	: 1;	// Registerhaltigkeit
55 	sal_Bool bOneBlock		: 1;	// Blocksatz: Einzelwoerter austreiben
56 	sal_Bool bLastBlock		: 1;	// Blocksatz: Auch die letzte Zeile
57 	sal_Bool bLastCenter	: 1;	// Blocksatz: Letzte Zeile zentrieren
58 
59 	SwLineLayout *_GetPrev();
60 
61 	// Zuruecksetzen in die erste Zeile.
62 	void Init();
63 	void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf );
SwTxtIter(SwTxtNode * pTxtNode)64 	inline SwTxtIter(SwTxtNode* pTxtNode) : SwAttrIter(pTxtNode) { }
65 
66 public:
SwTxtIter(SwTxtFrm * pTxtFrm,SwTxtInfo * pTxtInf)67     inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf ) : SwAttrIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
68            { CtorInitTxtIter( pTxtFrm, pTxtInf ); }
GetCurr() const69 	inline const SwLineLayout *GetCurr() const { return pCurr; } // niemals 0!
GetNext() const70 	inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); }
71 		   const SwLineLayout *GetPrev();
GetLength() const72 	inline xub_StrLen GetLength() const { return pCurr->GetLen(); }
GetLineNr() const73 	inline MSHORT GetLineNr() const { return nLineNr; }
GetStart() const74 	inline xub_StrLen GetStart() const { return nStart; }
GetEnd() const75 	inline xub_StrLen GetEnd() const { return GetStart() + GetLength(); }
Y() const76 	inline SwTwips Y() const { return nY; }
77 
RegStart() const78 	inline SwTwips RegStart() const { return nRegStart; }
RegDiff() const79 	inline KSHORT RegDiff() const { return nRegDiff; }
IsRegisterOn() const80 	inline sal_Bool IsRegisterOn() const { return bRegisterOn; }
81 
GetInfo()82 	inline SwTxtInfo &GetInfo() { return *pInf; }
GetInfo() const83 	inline const SwTxtInfo &GetInfo() const { return *pInf; }
84 
Top()85 	inline void Top() { Init(); }
86 	void Bottom();
87 	const SwLineLayout *Next();
88 	const SwLineLayout *Prev();
89 
90 	// Ueberspringt die Dummyzeilen der FlyFrms
91 	const SwLineLayout *NextLine();
92 	const SwLineLayout *PrevLine();
93 	const SwLineLayout *GetNextLine() const;
94 	const SwLineLayout *GetPrevLine();
95 
96 	void CharToLine( const xub_StrLen );
97 	const SwLineLayout *TwipsToLine(const SwTwips);
98 
99 	// schneidet ab pCurr alle ab.
100 	void TruncLines( sal_Bool bNoteFollow = sal_False );
101 
GetLineHeight() const102 	inline KSHORT GetLineHeight() const { return pCurr->GetRealHeight(); }
103 	void CalcAscentAndHeight( KSHORT &rAscent, KSHORT &rHeight ) const;
104 
105 	// 5298, viel Aerger durch die Abfrage auf pCurr == pPara
IsFirstTxtLine() const106 	inline sal_Bool IsFirstTxtLine() const
107 	{ return nStart == GetInfo().GetTxtStart() &&
108 		!( pCurr->IsDummy() && GetNextLine() ); }
109 
110 	// Als Ersatz fuer das alte IsFirstLine()
IsParaLine() const111 	inline sal_Bool IsParaLine() const
112 		{ return pCurr == pInf->GetParaPortion(); }
113 
GetLineInfo() const114 	const SwLineInfo &GetLineInfo() const { return aLineInf; }
GetFirstPos() const115     inline SwTwips GetFirstPos() const { return nFrameStart; }
116 	inline sal_Bool SeekAndChg( SwTxtSizeInfo &rInf );
117 	inline sal_Bool SeekAndChgBefore( SwTxtSizeInfo &rInf );
118 	inline sal_Bool SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara=sal_False );
119 
GetTxtFrm()120 	inline SwTxtFrm *GetTxtFrm() { return pFrm; }
GetTxtFrm() const121 	inline const SwTxtFrm *GetTxtFrm() const { return pFrm; }
122 
123 	// zaehlt aufeinanderfolgende Trennungen, um MaxHyphens einzuhalten
124 	void CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const;
125 };
126 
127 /*************************************************************************
128  *                      class SwTxtMargin
129  *************************************************************************/
130 
131 class SwTxtMargin : public SwTxtIter
132 {
133 private:
134 		  SwTwips nLeft;
135 		  SwTwips nRight;
136 		  SwTwips nFirst;
137 		  KSHORT  nDropLeft;
138 		  KSHORT  nDropHeight;
139 		  KSHORT  nDropDescent;
140 		  MSHORT  nDropLines;
141 		  MSHORT  nAdjust;
142           // --> OD 2008-06-30 #i91133#
143           SwTwips mnTabLeft;
144           // <--
145 
146 protected:
147 	// fuer FormatQuoVadis
Right(const SwTwips nNew)148 	inline void Right( const SwTwips nNew ) { nRight = nNew; }
149 	// fuer CalcFlyAdjust
SetDropLeft(const KSHORT nNew)150 	inline void SetDropLeft( const KSHORT nNew ) { nDropLeft = nNew; }
151 
152 	void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
SwTxtMargin(SwTxtNode * pTxtNode)153 	inline SwTxtMargin(SwTxtNode* pTxtNode) : SwTxtIter(pTxtNode) { }
154 public:
SwTxtMargin(SwTxtFrm * pTxtFrm,SwTxtSizeInfo * pTxtSizeInf)155     inline SwTxtMargin( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
156            { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
157 	inline SwTwips GetLeftMargin() const;
158 	inline SwTwips Left() const;
Right() const159 	inline SwTwips Right() const { return nRight; }
FirstLeft() const160 	inline SwTwips FirstLeft() const { return nFirst; }
CurrWidth() const161 	inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); }
162 		   SwTwips GetLineStart() const;
GetLineEnd() const163 	inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); }
GetTopLeft() const164 	inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); }
IsOneBlock() const165 	inline sal_Bool IsOneBlock() const { return bOneBlock; }
IsLastBlock() const166 	inline sal_Bool IsLastBlock() const { return bLastBlock; }
IsLastCenter() const167 	inline sal_Bool IsLastCenter() const { return bLastCenter; }
GetAdjust() const168 	inline MSHORT GetAdjust() const { return nAdjust; }
GetLineWidth() const169     inline KSHORT GetLineWidth() const
170 		   { return KSHORT( Right() - GetLeftMargin() + 1 ); }
GetLeftMin() const171 	inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; }
HasNegFirst() const172 	inline sal_Bool HasNegFirst() const { return nFirst < nLeft; }
173 
174     // --> OD 2008-06-30 #i91133#
GetTabLeft() const175     inline SwTwips GetTabLeft() const
176     {
177         return mnTabLeft;
178     }
179     // <--
180 	// DropCaps
GetDropLines() const181 	inline MSHORT GetDropLines() const { return nDropLines; }
SetDropLines(const MSHORT nNew)182 	inline void SetDropLines( const MSHORT nNew ) { nDropLines = nNew; }
GetDropLeft() const183 	inline KSHORT GetDropLeft() const { return nDropLeft; }
GetDropHeight() const184 	inline KSHORT GetDropHeight() const { return nDropHeight; }
SetDropHeight(const KSHORT nNew)185 	inline void SetDropHeight( const KSHORT nNew ) { nDropHeight = nNew; }
GetDropDescent() const186 	inline KSHORT GetDropDescent() const { return nDropDescent; }
SetDropDescent(const KSHORT nNew)187 	inline void SetDropDescent( const KSHORT nNew ) { nDropDescent = nNew; }
188 	void DropInit();
189 
190 	// liefert TxtPos fuer Start und Ende der aktuellen Zeile ohne whitespaces
191 	// In frminf.cxx implementiert.
192 	xub_StrLen GetTxtStart() const;
193 	xub_StrLen GetTxtEnd() const;
194 
GetInfo()195 	inline SwTxtSizeInfo &GetInfo()
196 		{ return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
GetInfo() const197 	inline const SwTxtSizeInfo &GetInfo() const
198 		{ return (const SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
199 
200 };
201 
202 
203 /*************************************************************************
204  *                      class SwTxtAdjuster
205  *************************************************************************/
206 
207 class SwTxtAdjuster : public SwTxtMargin
208 {
209 	// Gleicht die Portions aus, wenn Adjustment und FlyFrms vorliegen.
210 	void CalcFlyAdjust( SwLineLayout *pCurr );
211 
212 	// ruft SplitGlues und CalcBlockAdjust
213 	void FormatBlock( );
214 
215 	// Erstellt bei kurzen Zeilen die Glue-Kette.
216     SwMarginPortion* CalcRightMargin( SwLineLayout *pCurr, SwTwips nReal = 0 );
217 
218 	// Berechnung des Adjustments (FlyPortions)
219 	SwFlyPortion *CalcFlyPortion( const long nRealWidth,
220 								  const SwRect &rCurrRect );
221 
222 protected:
SwTxtAdjuster(SwTxtNode * pTxtNode)223 	inline SwTxtAdjuster(SwTxtNode* pTxtNode) : SwTxtMargin(pTxtNode) { }
224 	// spannt beim Blocksatz die Glues auf.
225 	void CalcNewBlock( SwLineLayout *pCurr, const SwLinePortion *pStopAt,
226         SwTwips nReal = 0, bool bSkipKashida = false );
227     SwTwips CalcKanaAdj( SwLineLayout *pCurr );
228 public:
SwTxtAdjuster(SwTxtFrm * pTxtFrm,SwTxtSizeInfo * pTxtSizeInf)229     inline SwTxtAdjuster( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtMargin(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
230            { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
231 
232 	// wird von SwTxtFormatter wegen UpdatePos ueberladen
233 	void CalcAdjLine( SwLineLayout *pCurr );
234 
235 	// sorgt fuer das nachtraegliche adjustieren
GetAdjusted() const236 	inline void GetAdjusted() const
237 	{
238 		if( pCurr->IsFormatAdj() )
239 			((SwTxtAdjuster*)this)->CalcAdjLine( pCurr );
240 	}
241 
242 	// DropCaps-Extrawurst
243 	void CalcDropAdjust();
244     void CalcDropRepaint();
245 };
246 
247 /*************************************************************************
248  *                      class SwTxtCursor
249  *************************************************************************/
250 
251 class SwTxtCursor : public SwTxtAdjuster
252 {
253 	// A small helper-class to save SwTxtCursor member, manipulate them
254 	// and to restore them
255 	friend class SwTxtCursorSave;
256 
257 	// 1170: Mehrdeutigkeiten
258 	static sal_Bool bRightMargin;
259 	void _GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* );
260 protected:
261 	void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
SwTxtCursor(SwTxtNode * pTxtNode)262 	inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
263 public:
SwTxtCursor(SwTxtFrm * pTxtFrm,SwTxtSizeInfo * pTxtSizeInf)264     inline SwTxtCursor( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtAdjuster(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
265            { CtorInitTxtCursor( pTxtFrm, pTxtSizeInf ); }
266 	sal_Bool GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
267 		const long nMax = 0 );
268 	sal_Bool GetEndCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
269 		const long nMax = 0 );
270 	xub_StrLen GetCrsrOfst( SwPosition *pPos, const Point &rPoint,
271 				const MSHORT nChgNode, SwCrsrMoveState* = 0 ) const;
272 	// 1170: beruecksichtigt Mehrdeutigkeiten; Implementierung s.u.
273 	const SwLineLayout *CharCrsrToLine( const xub_StrLen nPos );
274 
275     // calculates baseline for portion rPor
276     // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE
277     sal_uInt16 AdjustBaseLine( const SwLineLayout& rLine, const SwLinePortion* pPor,
278                            sal_uInt16 nPorHeight = 0, sal_uInt16 nAscent = 0,
279                            const sal_Bool bAutoToCentered = sal_False ) const;
280 
SetRightMargin(const sal_Bool bNew)281 	static inline void SetRightMargin( const sal_Bool bNew ){ bRightMargin = bNew; }
IsRightMargin()282 	static inline sal_Bool IsRightMargin() { return bRightMargin; }
283 };
284 
285 /*************************************************************************
286  *                          SwHookOut
287  *
288  * Change current output device to printer, this has to be done before
289  * formatting.
290  *************************************************************************/
291 
292 class SwHookOut
293 {
294     SwTxtSizeInfo* pInf;
295     OutputDevice* pOut;
296     sal_Bool bOnWin;
297 public:
298     SwHookOut( SwTxtSizeInfo& rInfo );
299     ~SwHookOut();
300 };
301 
302 /*************************************************************************
303  *						Inline-Implementierungen
304  *************************************************************************/
305 
SeekAndChg(SwTxtSizeInfo & rInf)306 inline sal_Bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf )
307 {
308 	return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
309 }
310 
SeekAndChgBefore(SwTxtSizeInfo & rInf)311 inline sal_Bool SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo &rInf )
312 {
313 	if ( rInf.GetIdx() )
314 		return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() );
315 	else
316 		return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
317 }
318 
SeekStartAndChg(SwTxtSizeInfo & rInf,const sal_Bool bPara)319 inline sal_Bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara )
320 {
321 	return SeekStartAndChgAttrIter( rInf.GetOut(), bPara );
322 }
323 
GetLeftMargin() const324 inline SwTwips SwTxtMargin::GetLeftMargin() const
325 {
326 	return IsFirstTxtLine() ? nFirst : Left();
327 }
328 
Left() const329 inline SwTwips SwTxtMargin::Left() const
330 {
331 	return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft;
332 }
333 
334 
335 
336 #endif
337