xref: /aoo41x/main/sw/source/core/text/porlin.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _PORLIN_HXX
28 #define _PORLIN_HXX
29 
30 #include "possiz.hxx"		// SwPosSize
31 
32 class XubString;
33 class SwTxtSizeInfo;
34 class SwTxtPaintInfo;
35 class SwTxtFormatInfo;
36 class SwPortionHandler;
37 
38 // Die Ausgabeoperatoren der Portions sind virtuelle Methoden der Portion.
39 // Das CLASSIO-Makro implementiert die 'freischwebende' Funktion.
40 // Auf diese Weise erhaelt man beide Vorteile: virtuelle Ausgabeoperatoren
41 // und allgemeine Verwendbarkeit.
42 #ifdef DBG_UTIL
43 #define OUTPUT_OPERATOR  virtual SvStream &operator<<( SvStream & aOs ) const;
44 #else
45 #define OUTPUT_OPERATOR
46 #endif
47 
48 // Portiongruppen
49 #define PORGRP_TXT		0x8000
50 #define PORGRP_EXP		0x4000
51 #define PORGRP_FLD		0x2000
52 #define PORGRP_HYPH		0x1000
53 #define PORGRP_NUMBER	0x0800
54 #define PORGRP_GLUE		0x0400
55 #define PORGRP_FIX		0x0200
56 #define PORGRP_TAB		0x0100
57 #define PORGRP_NOTRECY	0x0080
58 // kleine Spezialgruppen
59 #define PORGRP_FIXMARG	0x0040
60 //#define PORGRP_?	0x0020
61 #define PORGRP_TABNOTLFT 0x0010
62 #define PORGRP_TOXREF	0x0008
63 
64 /*************************************************************************
65  *						class SwLinePortion
66  *************************************************************************/
67 
68 class SwLinePortion: public SwPosSize
69 {
70 protected:
71 	// Hier gibt es Bereiche mit unterschiedlichen Attributen.
72 	SwLinePortion *pPortion;
73 	// Anzahl der Zeichen und Spaces auf der Zeile
74 	xub_StrLen nLineLength;
75 	KSHORT nAscent; 	 // Maximaler Ascender
76 
77 	SwLinePortion();
78 private:
79 	MSHORT nWhichPor;		// Who's who?
80 
81 	void _Truncate();
82 
83 public:
84 	inline 			SwLinePortion(const SwLinePortion &rPortion);
85 		   virtual ~SwLinePortion();
86 
87 	// Zugriffsmethoden
88 	inline SwLinePortion *GetPortion() const { return( pPortion ); }
89 	inline SwLinePortion &operator=(const SwLinePortion &rPortion);
90 	inline sal_Bool operator==( const SwLinePortion &rPortion ) const;
91 	inline xub_StrLen GetLen() const { return nLineLength; }
92 	inline void SetLen( const xub_StrLen nLen ) { nLineLength = nLen; }
93 	inline void SetPortion( SwLinePortion *pNew ){ pPortion = pNew; }
94 	inline KSHORT &GetAscent() { return nAscent; }
95 	inline KSHORT GetAscent() const { return nAscent; }
96 	inline void SetAscent( const KSHORT nNewAsc ) { nAscent = nNewAsc; }
97 	inline void  PrtWidth( KSHORT nNewWidth ) { Width( nNewWidth ); }
98 	inline KSHORT PrtWidth() const { return Width(); }
99 	inline void AddPrtWidth( const KSHORT nNew ) { Width( Width() + nNew ); }
100 	inline void SubPrtWidth( const KSHORT nNew ) { Width( Width() - nNew ); }
101 
102 	inline const SwPosSize &PrtSize() const { return *this; }
103 
104 	// Einfuegeoperationen:
105 	virtual SwLinePortion *Insert( SwLinePortion *pPortion );
106 	virtual SwLinePortion *Append( SwLinePortion *pPortion );
107 			SwLinePortion *Cut( SwLinePortion *pVictim );
108 	inline	void Truncate();
109 
110 	// liefert 0 zurueck, wenn keine Nutzdaten enthalten sind.
111 	virtual SwLinePortion *Compress();
112 
113 	inline void SetWhichPor( const MSHORT nNew )	{ nWhichPor = nNew; }
114 	inline MSHORT GetWhichPor( ) const        { return nWhichPor; }
115 
116 // Gruppenabfragen:
117 	inline sal_Bool InTxtGrp( )	const { return nWhichPor & PORGRP_TXT ? sal_True : sal_False; }
118 	inline sal_Bool InGlueGrp( )	const { return nWhichPor & PORGRP_GLUE ? sal_True : sal_False;}
119 	inline sal_Bool InTabGrp( )	const { return nWhichPor & PORGRP_TAB ? sal_True : sal_False; }
120 	inline sal_Bool InHyphGrp( )	const { return nWhichPor & PORGRP_HYPH ? sal_True : sal_False;}
121 	inline sal_Bool InNumberGrp( )const { return nWhichPor & PORGRP_NUMBER ? sal_True : sal_False;}
122 	inline sal_Bool InFixGrp( )	const { return nWhichPor & PORGRP_FIX ? sal_True : sal_False;  }
123 	inline sal_Bool InFldGrp( )	const { return nWhichPor & PORGRP_FLD ? sal_True : sal_False;  }
124 	inline sal_Bool InToxRefGrp( ) const { return nWhichPor &	PORGRP_TOXREF ? sal_True : sal_False;  }
125 	inline sal_Bool InToxRefOrFldGrp( )	const { return nWhichPor &
126 								( PORGRP_FLD | PORGRP_TOXREF ) ? sal_True : sal_False;  }
127 	inline sal_Bool InExpGrp( )	const { return nWhichPor & PORGRP_EXP ? sal_True : sal_False;  }
128 	inline sal_Bool InTabnLftGrp( ) const
129 		{ return nWhichPor & PORGRP_TABNOTLFT ? sal_True : sal_False;  }
130 	inline sal_Bool InFixMargGrp( )const
131 		{ return nWhichPor & PORGRP_FIXMARG ? sal_True : sal_False;  }
132 	inline sal_Bool InSpaceGrp( )const
133 		{ return InTxtGrp() || IsMultiPortion();  }
134 // Individuelle Abfragen:
135 	inline sal_Bool IsGrfNumPortion( )const{ return nWhichPor == POR_GRFNUM; }
136 	inline sal_Bool IsFlyCntPortion( )const{ return nWhichPor == POR_FLYCNT; }
137 	inline sal_Bool IsBlankPortion( )	const{ return nWhichPor == POR_BLANK; }
138 	inline sal_Bool IsBreakPortion( )	const{ return nWhichPor == POR_BRK; }
139 	inline sal_Bool IsErgoSumPortion()const{ return nWhichPor == POR_ERGOSUM;}
140 	inline sal_Bool IsQuoVadisPortion()const{ return nWhichPor==POR_QUOVADIS;}
141 	inline sal_Bool IsTabCntPortion( )const{ return nWhichPor==POR_TABCENTER;}
142 	inline sal_Bool IsTabDecimalPortion() const { return nWhichPor == POR_TABDECIMAL;}
143 	inline sal_Bool IsTabLeftPortion()const{ return nWhichPor == POR_TABLEFT;}
144 	inline sal_Bool IsFtnNumPortion( )const{ return nWhichPor == POR_FTNNUM; }
145 	inline sal_Bool IsFtnPortion( )	const{ return nWhichPor == POR_FTN; }
146 	inline sal_Bool IsTmpEndPortion( )const{ return nWhichPor == POR_TMPEND; }
147 	inline sal_Bool IsDropPortion( )	const{ return nWhichPor == POR_DROP; }
148 	inline sal_Bool IsLayPortion( )	const{ return nWhichPor == POR_LAY; }
149 	inline sal_Bool IsParaPortion( )	const{ return nWhichPor == POR_PARA; }
150 	inline sal_Bool IsMarginPortion( )const{ return nWhichPor == POR_MARGIN; }
151 	inline sal_Bool IsFlyPortion( )	const{ return nWhichPor == POR_FLY; }
152 	inline sal_Bool IsHolePortion( )	const{ return nWhichPor == POR_HOLE; }
153 	inline sal_Bool IsSoftHyphPortion()const{ return nWhichPor==POR_SOFTHYPH;}
154 	inline sal_Bool IsPostItsPortion()const{ return nWhichPor == POR_POSTITS;}
155 	inline sal_Bool IsCombinedPortion()const{ return nWhichPor==POR_COMBINED;}
156 	inline sal_Bool IsTextPortion( ) const{ return nWhichPor == POR_TXT; }
157 	inline sal_Bool IsURLPortion( ) const{ return nWhichPor == POR_URL; }
158 	inline sal_Bool IsHangingPortion( ) const{ return nWhichPor == POR_HNG; }
159 	inline sal_Bool IsKernPortion( ) const{ return nWhichPor == POR_KERN; }
160 	inline sal_Bool IsArrowPortion( ) const{ return nWhichPor == POR_ARROW; }
161 	inline sal_Bool IsMultiPortion( ) const{ return nWhichPor == POR_MULTI; }
162 	inline sal_Bool IsNumberPortion( ) const{ return nWhichPor == POR_NUMBER; } // #i23726#
163 	inline sal_Bool IsControlCharPortion() const { return nWhichPor == POR_CONTROLCHAR; }
164 
165 	// Positionierung
166 	SwLinePortion *FindPrevPortion( const SwLinePortion *pRoot );
167 	SwLinePortion *FindLastPortion();
168 
169 	virtual xub_StrLen GetCrsrOfst( const KSHORT nOfst ) const;
170 	virtual SwPosSize GetTxtSize( const SwTxtSizeInfo &rInfo ) const;
171 	void CalcTxtSize( const SwTxtSizeInfo &rInfo );
172 
173 	// Ausgabe
174 	virtual void Paint( const SwTxtPaintInfo &rInf ) const = 0;
175     void PrePaint( const SwTxtPaintInfo &rInf, const SwLinePortion *pLast ) const;
176 
177 #ifdef DBG_UTIL
178 	virtual sal_Bool Check( SvStream &rOs, SwTxtSizeInfo &rInfo ); //$ ostream
179 #endif
180 
181 	virtual sal_Bool Format( SwTxtFormatInfo &rInf );
182 	// wird fuer die letzte Portion der Zeile extra gerufen
183 	virtual void FormatEOL( SwTxtFormatInfo &rInf );
184 			void Move( SwTxtPaintInfo &rInf );
185 
186 	// Fuer SwTxtSlot
187 	virtual sal_Bool GetExpTxt( const SwTxtSizeInfo &rInf, XubString &rTxt ) const;
188 
189 	// fuer SwFldPortion, SwSoftHyphPortion
190 	virtual KSHORT GetViewWidth( const SwTxtSizeInfo &rInf ) const;
191 
192 	// for text- and multi-portions
193     virtual long CalcSpacing( long nSpaceAdd, const SwTxtSizeInfo &rInf ) const;
194 
195     // Accessibility: pass information about this portion to the PortionHandler
196     virtual void HandlePortion( SwPortionHandler& rPH ) const;
197 
198 	OUTPUT_OPERATOR
199 };
200 
201 
202 /*************************************************************************
203  *					inline - Implementations
204  *************************************************************************/
205 
206 inline SwLinePortion &SwLinePortion::operator=(const SwLinePortion &rPortion)
207 {
208 	*(SwPosSize*)this = rPortion;
209 	nLineLength = rPortion.nLineLength;
210 	nAscent = rPortion.nAscent;
211 	nWhichPor = rPortion.nWhichPor;
212 	return *this;
213 }
214 
215 inline sal_Bool SwLinePortion::operator==(const SwLinePortion &rPortion ) const
216 {
217 	return( Height() == rPortion.Height() &&
218             Width() == rPortion.Width() &&
219 			nLineLength == rPortion.GetLen() &&
220 			nAscent == rPortion.GetAscent() );
221 }
222 
223 inline SwLinePortion::SwLinePortion(const SwLinePortion &rPortion) :
224 	SwPosSize( rPortion ),
225 	pPortion( 0 ),
226 	nLineLength( rPortion.nLineLength ),
227 	nAscent( rPortion.nAscent ),
228 	nWhichPor( rPortion.nWhichPor )
229 {
230 }
231 
232 inline void SwLinePortion::Truncate()
233 {
234 	if ( pPortion )
235 		_Truncate();
236 }
237 
238 
239 //$ ostream
240 #ifdef DBGTXT
241 #define CLASSIO( class ) \
242 	inline SvStream &operator<<( SvStream &rOs, const class &rClass ) {\
243 			return rClass.operator<<( rOs );\
244 	}
245 #else
246 #define CLASSIO( class )
247 #endif
248 
249 CLASSIO( SwLinePortion )
250 
251 #endif
252