xref: /AOO41X/main/sw/source/core/text/itrtxt.hxx (revision b5da552ccefc4034e06a43bfae43fb8a8b64a7ad)
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 );
64 	inline SwTxtIter(SwTxtNode* pTxtNode) : SwAttrIter(pTxtNode) { }
65 
66 public:
67     inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf ) : SwAttrIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
68            { CtorInitTxtIter( pTxtFrm, pTxtInf ); }
69 	inline const SwLineLayout *GetCurr() const { return pCurr; } // niemals 0!
70 	inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); }
71 		   const SwLineLayout *GetPrev();
72 	inline xub_StrLen GetLength() const { return pCurr->GetLen(); }
73 	inline MSHORT GetLineNr() const { return nLineNr; }
74 	inline xub_StrLen GetStart() const { return nStart; }
75 	inline xub_StrLen GetEnd() const { return GetStart() + GetLength(); }
76 	inline SwTwips Y() const { return nY; }
77 
78 	inline SwTwips RegStart() const { return nRegStart; }
79 	inline KSHORT RegDiff() const { return nRegDiff; }
80 	inline sal_Bool IsRegisterOn() const { return bRegisterOn; }
81 
82 	inline SwTxtInfo &GetInfo() { return *pInf; }
83 	inline const SwTxtInfo &GetInfo() const { return *pInf; }
84 
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 
102 	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
106 	inline sal_Bool IsFirstTxtLine() const
107 	{ return nStart == GetInfo().GetTxtStart() &&
108 		!( pCurr->IsDummy() && GetNextLine() ); }
109 
110 	// Als Ersatz fuer das alte IsFirstLine()
111 	inline sal_Bool IsParaLine() const
112 		{ return pCurr == pInf->GetParaPortion(); }
113 
114 	const SwLineInfo &GetLineInfo() const { return aLineInf; }
115     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 
120 	inline SwTxtFrm *GetTxtFrm() { return pFrm; }
121 	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
148 	inline void Right( const SwTwips nNew ) { nRight = nNew; }
149 	// fuer CalcFlyAdjust
150 	inline void SetDropLeft( const KSHORT nNew ) { nDropLeft = nNew; }
151 
152 	void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
153 	inline SwTxtMargin(SwTxtNode* pTxtNode) : SwTxtIter(pTxtNode) { }
154 public:
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;
159 	inline SwTwips Right() const { return nRight; }
160 	inline SwTwips FirstLeft() const { return nFirst; }
161 	inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); }
162 		   SwTwips GetLineStart() const;
163 	inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); }
164 	inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); }
165 	inline sal_Bool IsOneBlock() const { return bOneBlock; }
166 	inline sal_Bool IsLastBlock() const { return bLastBlock; }
167 	inline sal_Bool IsLastCenter() const { return bLastCenter; }
168 	inline MSHORT GetAdjust() const { return nAdjust; }
169     inline KSHORT GetLineWidth() const
170 		   { return KSHORT( Right() - GetLeftMargin() + 1 ); }
171 	inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; }
172 	inline sal_Bool HasNegFirst() const { return nFirst < nLeft; }
173 
174     // --> OD 2008-06-30 #i91133#
175     inline SwTwips GetTabLeft() const
176     {
177         return mnTabLeft;
178     }
179     // <--
180 	// DropCaps
181 	inline MSHORT GetDropLines() const { return nDropLines; }
182 	inline void SetDropLines( const MSHORT nNew ) { nDropLines = nNew; }
183 	inline KSHORT GetDropLeft() const { return nDropLeft; }
184 	inline KSHORT GetDropHeight() const { return nDropHeight; }
185 	inline void SetDropHeight( const KSHORT nNew ) { nDropHeight = nNew; }
186 	inline KSHORT GetDropDescent() const { return nDropDescent; }
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 
195 	inline SwTxtSizeInfo &GetInfo()
196 		{ return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
197 	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:
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:
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
236 	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 );
262 	inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
263 public:
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 
281 	static inline void SetRightMargin( const sal_Bool bNew ){ bRightMargin = bNew; }
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 
306 inline sal_Bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf )
307 {
308 	return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
309 }
310 
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 
319 inline sal_Bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara )
320 {
321 	return SeekStartAndChgAttrIter( rInf.GetOut(), bPara );
322 }
323 
324 inline SwTwips SwTxtMargin::GetLeftMargin() const
325 {
326 	return IsFirstTxtLine() ? nFirst : Left();
327 }
328 
329 inline SwTwips SwTxtMargin::Left() const
330 {
331 	return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft;
332 }
333 
334 
335 
336 #endif
337