xref: /trunk/main/editeng/source/editeng/editdoc.hxx (revision bb99baf4)
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 
24 #ifndef _EDITDOC_HXX
25 #define _EDITDOC_HXX
26 
27 #ifndef _COM_SUN_STAR_I18N_XEXTENDEDINPUTSEQUENCECHECKER_HDL_
28 #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp>
29 #endif
30 
31 #include <baselist.hxx>
32 #include <editattr.hxx>
33 #include <edtspell.hxx>
34 #include <editeng/svxfont.hxx>
35 #include <svl/itemset.hxx>
36 #include <svl/style.hxx>
37 #include <svl/itempool.hxx>
38 #include <tools/table.hxx>
39 
40 #include <deque>
41 
42 class ImpEditEngine;
43 class SvxTabStop;
44 class SvtCTLOptions;
45 
46 DBG_NAMEEX( EE_TextPortion )
47 
48 #define CHARPOSGROW		16
49 #define DEFTAB 			720
50 
51 void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent = true, short nScriptType = 0 );
52 sal_uInt16 GetScriptItemId( sal_uInt16 nItemId, short nScriptType );
53 sal_Bool IsScriptItemValid( sal_uInt16 nItemId, short nScriptType );
54 
55 EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const SfxPoolItem& rAttr, sal_uInt16 nS, sal_uInt16 nE );
56 
57 class ContentNode;
58 class EditDoc;
59 
60 struct EPaM
61 {
62 	sal_uInt32 nPara;
63 	sal_uInt16 nIndex;
64 
EPaMEPaM65 	EPaM()								{ nPara = 0; nIndex = 0; }
EPaMEPaM66 	EPaM( sal_uInt32 nP, sal_uInt16 nI )		{ nPara = nP; nIndex = nI; }
EPaMEPaM67 	EPaM( const EPaM& r)				{ nPara = r.nPara; nIndex = r.nIndex; }
operator =EPaM68 	EPaM& operator = ( const EPaM& r )	{ nPara = r.nPara; nIndex = r.nIndex; return *this; }
69 	inline sal_Bool operator == ( const EPaM& r ) const;
70 	inline sal_Bool operator < ( const EPaM& r ) const;
71 };
72 
operator <(const EPaM & r) const73 inline sal_Bool EPaM::operator < ( const EPaM& r ) const
74 {
75 	return ( ( nPara < r.nPara ) ||
76 			 ( ( nPara == r.nPara ) && nIndex < r.nIndex ) ) ? sal_True : sal_False;
77 }
78 
operator ==(const EPaM & r) const79 inline sal_Bool EPaM::operator == ( const EPaM& r ) const
80 {
81 	return ( ( nPara == r.nPara ) && ( nIndex == r.nIndex ) ) ? sal_True : sal_False;
82 }
83 
84 struct ScriptTypePosInfo
85 {
86 	short	nScriptType;
87 	sal_uInt16	nStartPos;
88 	sal_uInt16	nEndPos;
89 
ScriptTypePosInfoScriptTypePosInfo90 	ScriptTypePosInfo( short _Type, sal_uInt16 _Start, sal_uInt16 _End )
91 	{
92 		nScriptType = _Type;
93 		nStartPos = _Start;
94 		nEndPos = _End;
95 	}
96 };
97 
98 typedef std::deque< ScriptTypePosInfo > ScriptTypePosInfos;
99 
100 struct WritingDirectionInfo
101 {
102 	sal_uInt8	nType;
103 	sal_uInt16	nStartPos;
104 	sal_uInt16	nEndPos;
105 
WritingDirectionInfoWritingDirectionInfo106 	WritingDirectionInfo( sal_uInt8 _Type, sal_uInt16 _Start, sal_uInt16 _End )
107 	{
108 		nType = _Type;
109 		nStartPos = _Start;
110 		nEndPos = _End;
111 	}
112 };
113 
114 
115 typedef std::deque< WritingDirectionInfo > WritingDirectionInfos;
116 
117 typedef EditCharAttrib* EditCharAttribPtr;
118 SV_DECL_PTRARR( CharAttribArray, EditCharAttribPtr, 0, 4 )
119 
120 class ContentAttribsInfo
121 {
122 private:
123 	SfxItemSet			aPrevParaAttribs;
124 	CharAttribArray		aPrevCharAttribs;
125 
126 public:
127 						ContentAttribsInfo( const SfxItemSet& rParaAttribs );
128 
GetPrevParaAttribs() const129 	const SfxItemSet&		GetPrevParaAttribs() const	{ return aPrevParaAttribs; }
GetPrevCharAttribs() const130 	const CharAttribArray&	GetPrevCharAttribs() const	{ return aPrevCharAttribs; }
131 
GetPrevCharAttribs()132 	CharAttribArray&		GetPrevCharAttribs() 		{ return aPrevCharAttribs; }
133 };
134 
135 typedef ContentAttribsInfo* ContentAttribsInfoPtr;
136 SV_DECL_PTRARR( ContentInfoArray, ContentAttribsInfoPtr, 1, 1 )
137 
138 //	----------------------------------------------------------------------
139 //	class SvxFontTable
140 //	----------------------------------------------------------------------
141 DECLARE_TABLE( DummyFontTable, SvxFontItem* )
142 class SvxFontTable : public DummyFontTable
143 {
144 public:
145 			SvxFontTable();
146 			~SvxFontTable();
147 
148 	sal_uLong	GetId( const SvxFontItem& rFont );
149 };
150 
151 //	----------------------------------------------------------------------
152 //	class SvxColorList
153 //	----------------------------------------------------------------------
154 typedef ContentNode* ContentNodePtr;
155 DECLARE_LIST( DummyColorList, SvxColorItem* )
156 class SvxColorList : public DummyColorList
157 {
158 public:
159 			SvxColorList();
160 			~SvxColorList();
161 
162 	sal_uLong	GetId( const SvxColorItem& rColor );
163 };
164 
165 //	----------------------------------------------------------------------
166 //	class ItemList
167 //	----------------------------------------------------------------------
168 typedef const SfxPoolItem* ConstPoolItemPtr;
169 DECLARE_LIST( DummyItemList, ConstPoolItemPtr )
170 class ItemList : public DummyItemList
171 {
172 public:
173 	const SfxPoolItem*	FindAttrib( sal_uInt16 nWhich );
174 };
175 
176 // -------------------------------------------------------------------------
177 // class ContentAttribs
178 // -------------------------------------------------------------------------
179 class ContentAttribs
180 {
181 private:
182 	SfxStyleSheet*	pStyle;
183 	SfxItemSet		aAttribSet;
184 
185 public:
186 					ContentAttribs( SfxItemPool& rItemPool );
187 					ContentAttribs( const ContentAttribs& );
188 					~ContentAttribs();	// erst bei umfangreicheren Tabs
189 
190 	SvxTabStop		FindTabStop( long nCurPos, sal_uInt16 nDefTab );
GetItems()191 	SfxItemSet&		GetItems()							{ return aAttribSet; }
GetStyleSheet() const192 	SfxStyleSheet*	GetStyleSheet() const				{ return pStyle; }
193 	void			SetStyleSheet( SfxStyleSheet* pS );
194 
195 	const SfxPoolItem&	GetItem( sal_uInt16 nWhich );
196 	sal_Bool				HasItem( sal_uInt16 nWhich );
197 };
198 
199 // -------------------------------------------------------------------------
200 // class CharAttribList
201 // -------------------------------------------------------------------------
202 class CharAttribList
203 {
204 private:
205 	CharAttribArray	aAttribs;
206 	SvxFont			aDefFont;				// schneller, als jedesmal vom Pool!
207 	sal_Bool			bHasEmptyAttribs;
208 
CharAttribList(const CharAttribList &)209 					CharAttribList( const CharAttribList& ) {;}
210 
211 public:
212 					CharAttribList();
213 					~CharAttribList();
214 
215 	void			DeleteEmptyAttribs(  SfxItemPool& rItemPool );
216 	void			RemoveItemsFromPool( SfxItemPool* pItemPool );
217 
218 	EditCharAttrib*	FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
219 	EditCharAttrib*	FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos ) const;
220 	EditCharAttrib*	FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
221 	EditCharAttrib*	FindFeature( sal_uInt16 nPos ) const;
222 
223 
224 	void			ResortAttribs();
225     void            OptimizeRanges( SfxItemPool& rItemPool );
226 
Count()227 	sal_uInt16			Count()					{ return aAttribs.Count(); }
Clear()228 	void			Clear()					{ aAttribs.Remove( 0, aAttribs.Count()); }
229 	void			InsertAttrib( EditCharAttrib* pAttrib );
230 
GetDefFont()231 	SvxFont&		GetDefFont() 			{ return aDefFont; }
232 
HasEmptyAttribs() const233 	sal_Bool			HasEmptyAttribs() const	{ return bHasEmptyAttribs; }
HasEmptyAttribs()234 	sal_Bool&			HasEmptyAttribs() 		{ return bHasEmptyAttribs; }
235 	sal_Bool			HasBoundingAttrib( sal_uInt16 nBound );
236 	sal_Bool 			HasAttrib( sal_uInt16 nWhich ) const;
237 	sal_Bool			HasAttrib( sal_uInt16 nStartPos, sal_uInt16 nEndPos ) const;
238 
GetAttribs()239 	CharAttribArray&		GetAttribs() 		{ return aAttribs; }
GetAttribs() const240 	const CharAttribArray&	GetAttribs() const	{ return aAttribs; }
241 
242 	// Debug:
243 	sal_Bool			DbgCheckAttribs();
244 };
245 
246 // -------------------------------------------------------------------------
247 // class ContentNode
248 // -------------------------------------------------------------------------
249 class ContentNode : public XubString
250 {
251 private:
252 	ContentAttribs	aContentAttribs;
253 	CharAttribList	aCharAttribList;
254 	WrongList*		pWrongList;
255 
256 public:
257 					ContentNode( SfxItemPool& rItemPool );
258 					ContentNode( const XubString& rStr, const ContentAttribs& rContentAttribs );
259 					~ContentNode();
260 
GetContentAttribs()261 	ContentAttribs&	GetContentAttribs() 	{ return aContentAttribs; }
GetCharAttribs()262 	CharAttribList&	GetCharAttribs()		{ return aCharAttribList; }
263 
264 	void			ExpandAttribs( sal_uInt16 nIndex, sal_uInt16 nNewChars, SfxItemPool& rItemPool );
265 	void			CollapsAttribs( sal_uInt16 nIndex, sal_uInt16 nDelChars, SfxItemPool& rItemPool );
266 	void			AppendAttribs( ContentNode* pNextNode );
267 	void			CopyAndCutAttribs( ContentNode* pPrevNode, SfxItemPool& rPool, sal_Bool bKeepEndingAttribs );
268 
269 	void			SetStyleSheet( SfxStyleSheet* pS, sal_Bool bRecalcFont = sal_True );
270 	void			SetStyleSheet( SfxStyleSheet* pS, const SvxFont& rFontFromStyle );
GetStyleSheet()271 	SfxStyleSheet*	GetStyleSheet()	{ return aContentAttribs.GetStyleSheet(); }
272 
273 	void			CreateDefFont();
274 
GetWrongList()275 	WrongList*		GetWrongList() 			{ return pWrongList; }
276 	void			SetWrongList( WrongList* p );
277 
278 	void			CreateWrongList();
279 	void			DestroyWrongList();
280 
IsFeature(sal_uInt16 nPos) const281 	sal_Bool			IsFeature( sal_uInt16 nPos ) const { return ( GetChar( nPos ) == CH_FEATURE ); }
282 };
283 
284 typedef ContentNode* ContentNodePtr;
285 
286 class ContentList : public BaseList<ContentNode>
287 {
288     sal_uInt32 nLastCache;
289 public:
ContentList()290     ContentList() : nLastCache(0) {}
291     sal_uInt32 GetPos( const ContentNodePtr &rPtr ) const;
292 };
293 
294 // -------------------------------------------------------------------------
295 // class EditPaM
296 // -------------------------------------------------------------------------
297 class EditPaM
298 {
299 private:
300 	ContentNode*	pNode;
301 	sal_uInt16			nIndex;
302 
303 public:
EditPaM()304 					EditPaM() 							{ pNode = NULL; nIndex = 0; }
EditPaM(ContentNode * p,sal_uInt16 n)305 					EditPaM( ContentNode* p, sal_uInt16 n )	{ pNode = p; nIndex = n; }
306 
GetNode() const307 	ContentNode*	GetNode() const					{ return pNode; }
SetNode(ContentNode * p)308 	void			SetNode( ContentNode* p) 		{ pNode = p; }
309 
GetIndex() const310 	sal_uInt16			GetIndex() const				{ return nIndex; }
GetIndex()311 	sal_uInt16&			GetIndex() 						{ return nIndex; }
SetIndex(sal_uInt16 n)312 	void			SetIndex( sal_uInt16 n )			{ nIndex = n; }
313 
IsParaStart() const314 	sal_Bool			IsParaStart() const				{ return nIndex == 0; }
IsParaEnd() const315 	sal_Bool			IsParaEnd() const 				{ return nIndex == pNode->Len(); }
316 
317 	sal_Bool			DbgIsBuggy( EditDoc& rDoc );
318 
319 	EditPaM&	operator = ( const EditPaM& rPaM );
320 	friend sal_Bool operator == ( const EditPaM& r1,  const EditPaM& r2  );
321 	friend sal_Bool operator != ( const EditPaM& r1,  const EditPaM& r2  );
322 };
323 
324 #define PORTIONKIND_TEXT		0
325 #define PORTIONKIND_TAB         1
326 #define PORTIONKIND_LINEBREAK	2
327 #define PORTIONKIND_FIELD		3
328 #define PORTIONKIND_HYPHENATOR	4
329 // #define PORTIONKIND_EXTRASPACE	5
330 
331 #define DELMODE_SIMPLE			0
332 #define DELMODE_RESTOFWORD		1
333 #define DELMODE_RESTOFCONTENT	2
334 
335 #define CHAR_NORMAL            0x00
336 #define CHAR_KANA              0x01
337 #define CHAR_PUNCTUATIONLEFT   0x02
338 #define CHAR_PUNCTUATIONRIGHT  0x04
339 
340 // -------------------------------------------------------------------------
341 // struct ExtraPortionInfos
342 // -------------------------------------------------------------------------
343 struct ExtraPortionInfo
344 {
345     long    nOrgWidth;
346     long    nWidthFullCompression;
347 
348     long    nPortionOffsetX;
349 
350     sal_uInt16  nMaxCompression100thPercent;
351 
352     sal_uInt8    nAsianCompressionTypes;
353     sal_Bool    bFirstCharIsRightPunktuation;
354     sal_Bool    bCompressed;
355 
356     sal_Int32*    pOrgDXArray;
357 
358 
359             ExtraPortionInfo();
360             ~ExtraPortionInfo();
361 
362     void    SaveOrgDXArray( const sal_Int32* pDXArray, sal_uInt16 nLen );
363     void    DestroyOrgDXArray();
364 };
365 
366 
367 // -------------------------------------------------------------------------
368 // class TextPortion
369 // -------------------------------------------------------------------------
370 class TextPortion
371 {
372 private:
373     ExtraPortionInfo*   pExtraInfos;
374 	sal_uInt16		        nLen;
375 	Size		        aOutSz;
376 	sal_uInt8		        nKind;
377     sal_uInt8                nRightToLeft;
378 	sal_Unicode	        nExtraValue;
379 
380 
TextPortion()381 				TextPortion()				{ DBG_CTOR( EE_TextPortion, 0 );
382                                               pExtraInfos = NULL; nLen = 0; nKind = PORTIONKIND_TEXT; nExtraValue = 0; nRightToLeft = sal_False;}
383 
384 public:
TextPortion(sal_uInt16 nL)385 				TextPortion( sal_uInt16 nL ) : aOutSz( -1, -1 )
386 											{	DBG_CTOR( EE_TextPortion, 0 );
387 												pExtraInfos = NULL; nLen = nL; nKind = PORTIONKIND_TEXT; nExtraValue = 0; nRightToLeft = sal_False;}
TextPortion(const TextPortion & r)388 				TextPortion( const TextPortion& r )	: aOutSz( r.aOutSz )
389 											{ DBG_CTOR( EE_TextPortion, 0 );
390 												pExtraInfos = NULL; nLen = r.nLen; nKind = r.nKind; nExtraValue = r.nExtraValue; nRightToLeft = r.nRightToLeft; }
391 
~TextPortion()392                 ~TextPortion()				{ 	DBG_DTOR( EE_TextPortion, 0 ); delete pExtraInfos; }
393 
GetLen() const394     sal_uInt16		GetLen() const				{ return nLen; }
GetLen()395 	sal_uInt16&		GetLen() 					{ return nLen; }
SetLen(sal_uInt16 nL)396 	void		SetLen( sal_uInt16 nL )			{ nLen = nL; }
397 
GetSize()398 	Size&		GetSize()					{ return aOutSz; }
GetSize() const399 	Size		GetSize() const				{ return aOutSz; }
400 
GetKind()401 	sal_uInt8&		GetKind()					{ return nKind; }
GetKind() const402 	sal_uInt8		GetKind() const				{ return nKind; }
403 
SetRightToLeft(sal_uInt8 b)404     void        SetRightToLeft( sal_uInt8 b )    { nRightToLeft = b; }
GetRightToLeft() const405     sal_uInt8        GetRightToLeft() const      { return nRightToLeft; }
IsRightToLeft() const406     sal_Bool        IsRightToLeft() const       { return (nRightToLeft&1); }
407 
GetExtraValue() const408 	sal_Unicode	GetExtraValue() const		{ return nExtraValue; }
SetExtraValue(sal_Unicode n)409 	void		SetExtraValue( sal_Unicode n ) 	{ nExtraValue = n; }
410 
HasValidSize() const411 	sal_Bool		HasValidSize() const		{ return aOutSz.Width() != (-1); }
412 
GetExtraInfos() const413     ExtraPortionInfo*   GetExtraInfos() const { return pExtraInfos; }
SetExtraInfos(ExtraPortionInfo * p)414     void                SetExtraInfos( ExtraPortionInfo* p ) { delete pExtraInfos; pExtraInfos = p; }
415 };
416 
417 // -------------------------------------------------------------------------
418 // class TextPortionList
419 // -------------------------------------------------------------------------
420 typedef TextPortion* TextPortionPtr;
421 SV_DECL_PTRARR( TextPortionArray, TextPortionPtr, 0, 8 )
422 
423 class TextPortionList : public TextPortionArray
424 {
425 public:
426 			TextPortionList();
427 			~TextPortionList();
428 
429 	void	Reset();
430 	sal_uInt16	FindPortion( sal_uInt16 nCharPos, sal_uInt16& rPortionStart, sal_Bool bPreferStartingPortion = sal_False );
431     sal_uInt16  GetStartPos( sal_uInt16 nPortion );
432 	void	DeleteFromPortion( sal_uInt16 nDelFrom );
433 };
434 
435 class ParaPortion;
436 
437 SV_DECL_VARARR( CharPosArray, sal_Int32, 0, CHARPOSGROW )
438 
439 // ------------------------------------------------------------------------
440 // class EditLine
441 // -------------------------------------------------------------------------
442 class EditLine
443 {
444 private:
445 	CharPosArray	aPositions;
446     long            nTxtWidth;
447 	sal_uInt16			nStartPosX;
448 	sal_uInt16			nStart;		// koennte durch nStartPortion ersetzt werden
449 	sal_uInt16			nEnd;       // koennte durch nEndPortion ersetzt werden
450 	sal_uInt16			nStartPortion; // index of TextPortion in TextPortionList
451 	sal_uInt16 			nEndPortion; // index of TextPortion in TextPortionList
452 	sal_uInt16			nHeight;	// Gesamthoehe der Zeile
453 	sal_uInt16			nTxtHeight;	// Reine Texthoehe
454 	sal_uInt16			nCrsrHeight;	// Bei Konturfluss hohe Zeilen => Cursor zu gro?.
455 	sal_uInt16			nMaxAscent;
456 	sal_Bool			bHangingPunctuation;
457 	sal_Bool			bInvalid;	// fuer geschickte Formatierung
458 
459 public:
460 					EditLine();
461 					EditLine( const EditLine& );
462 					~EditLine();
463 
IsIn(sal_uInt16 nIndex) const464 	sal_Bool			IsIn( sal_uInt16 nIndex ) const
465 						{ return ( (nIndex >= nStart ) && ( nIndex < nEnd ) ); }
466 
IsIn(sal_uInt16 nIndex,sal_Bool bInclEnd) const467 	sal_Bool			IsIn( sal_uInt16 nIndex, sal_Bool bInclEnd ) const
468 						{ return ( ( nIndex >= nStart ) && ( bInclEnd ? ( nIndex <= nEnd ) : ( nIndex < nEnd ) ) ); }
469 
SetStart(sal_uInt16 n)470 	void			SetStart( sal_uInt16 n )			{ nStart = n; }
GetStart() const471 	sal_uInt16			GetStart() const				{ return nStart; }
GetStart()472 	sal_uInt16&			GetStart() 						{ return nStart; }
473 
SetEnd(sal_uInt16 n)474 	void			SetEnd( sal_uInt16 n )				{ nEnd = n; }
GetEnd() const475 	sal_uInt16			GetEnd() const					{ return nEnd; }
GetEnd()476 	sal_uInt16&			GetEnd() 						{ return nEnd; }
477 
SetStartPortion(sal_uInt16 n)478 	void			SetStartPortion( sal_uInt16 n )		{ nStartPortion = n; }
GetStartPortion() const479 	sal_uInt16			GetStartPortion() const			{ return nStartPortion; }
GetStartPortion()480 	sal_uInt16&			GetStartPortion() 				{ return nStartPortion; }
481 
SetEndPortion(sal_uInt16 n)482 	void			SetEndPortion( sal_uInt16 n )		{ nEndPortion = n; }
GetEndPortion() const483 	sal_uInt16			GetEndPortion() const			{ return nEndPortion; }
GetEndPortion()484 	sal_uInt16&			GetEndPortion() 				{ return nEndPortion; }
485 
SetHeight(sal_uInt16 nH,sal_uInt16 nTxtH=0,sal_uInt16 nCrsrH=0)486 	void			SetHeight( sal_uInt16 nH, sal_uInt16 nTxtH = 0, sal_uInt16 nCrsrH = 0 )
487 					{ 	nHeight = nH;
488 						nTxtHeight = ( nTxtH ? nTxtH : nH );
489 						nCrsrHeight = ( nCrsrH ? nCrsrH : nTxtHeight );
490 					}
GetHeight() const491 	sal_uInt16			GetHeight() const				{ return nHeight; }
GetTxtHeight() const492 	sal_uInt16			GetTxtHeight() const			{ return nTxtHeight; }
GetCrsrHeight() const493 	sal_uInt16			GetCrsrHeight() const			{ return nCrsrHeight; }
494 
SetTextWidth(long n)495     void            SetTextWidth( long n )          { nTxtWidth = n; }
GetTextWidth() const496     long            GetTextWidth() const            { return nTxtWidth; }
497 
SetMaxAscent(sal_uInt16 n)498 	void			SetMaxAscent( sal_uInt16 n )		{ nMaxAscent = n; }
GetMaxAscent() const499 	sal_uInt16			GetMaxAscent() const			{ return nMaxAscent; }
500 
SetHangingPunctuation(sal_Bool b)501 	void			SetHangingPunctuation( sal_Bool b )		{ bHangingPunctuation = b; }
IsHangingPunctuation() const502 	sal_Bool			IsHangingPunctuation() const		{ return bHangingPunctuation; }
503 
GetLen() const504 	sal_uInt16			GetLen() const					{ return nEnd - nStart; }
505 
GetStartPosX() const506 	sal_uInt16			GetStartPosX() const			{ return nStartPosX; }
SetStartPosX(sal_uInt16 start)507 	void			SetStartPosX( sal_uInt16 start )	{ nStartPosX = start; }
508 
509 	Size			CalcTextSize( ParaPortion& rParaPortion );
510 
IsInvalid() const511 	sal_Bool			IsInvalid()	const				{ return bInvalid; }
IsValid() const512 	sal_Bool			IsValid() const					{ return !bInvalid; }
SetInvalid()513 	void			SetInvalid()					{ bInvalid = sal_True; }
SetValid()514 	void			SetValid()						{ bInvalid = sal_False; }
515 
IsEmpty() const516 	sal_Bool			IsEmpty() const					{ return (nEnd > nStart) ? sal_False : sal_True; }
517 
GetCharPosArray()518 	CharPosArray&	GetCharPosArray()				{ return aPositions; }
519 
520 	EditLine*		Clone() const;
521 
522 	EditLine&	operator = ( const EditLine& rLine );
523 	friend sal_Bool operator == ( const EditLine& r1,  const EditLine& r2  );
524 	friend sal_Bool operator != ( const EditLine& r1,  const EditLine& r2  );
525 };
526 
527 
528 // -------------------------------------------------------------------------
529 // class LineList
530 // -------------------------------------------------------------------------
531 typedef EditLine* EditLinePtr;
532 SV_DECL_PTRARR( LineArray, EditLinePtr, 0, 4 )
533 
534 class EditLineList : public LineArray
535 {
536 public:
537 			EditLineList();
538 			~EditLineList();
539 
540 	void	Reset();
541 	void	DeleteFromLine( sal_uInt16 nDelFrom );
542 	sal_uInt16	FindLine( sal_uInt16 nChar, sal_Bool bInclEnd );
543 };
544 
545 // -------------------------------------------------------------------------
546 // class ParaPortion
547 // -------------------------------------------------------------------------
548 class ParaPortion
549 {
550 	friend class ImpEditEngine;	// zum Einstellen der Hoehe
551 private:
552 	EditLineList		aLineList;
553 	TextPortionList		aTextPortionList;
554 	ContentNode*		pNode;
555 	long				nHeight;
556 
557 	ScriptTypePosInfos	    aScriptInfos;
558     WritingDirectionInfos   aWritingDirectionInfos;
559 
560 	sal_uInt16				nInvalidPosStart;
561 	sal_uInt16				nFirstLineOffset;	// Fuer Writer-LineSpacing-Interpretation
562 	sal_uInt16				nBulletX;
563 	short				nInvalidDiff;
564 
565 	sal_Bool				bInvalid 			: 1;
566 	sal_Bool				bSimple				: 1;	// nur lineares Tippen
567 	sal_Bool				bVisible			: 1;	// MT 05/00: Gehoert an den Node!!!
568 	sal_Bool				bForceRepaint		: 1;
569 
570 						ParaPortion( const ParaPortion& );
571 
572 public:
573 						ParaPortion( ContentNode* pNode );
574 						~ParaPortion();
575 
576 	sal_uInt16				GetLineNumber( sal_uInt16 nIndex );
577 
GetLines()578 	EditLineList&		GetLines()					{ return aLineList; }
579 
IsInvalid() const580 	sal_Bool				IsInvalid()	const			{ return bInvalid; }
IsSimpleInvalid() const581 	sal_Bool				IsSimpleInvalid()	const	{ return bSimple; }
SetValid()582 	void				SetValid()					{ bInvalid = sal_False; bSimple = sal_True;}
583 
MustRepaint() const584 	sal_Bool				MustRepaint() const			{ return bForceRepaint; }
SetMustRepaint(sal_Bool bRP)585 	void				SetMustRepaint( sal_Bool bRP )	{ bForceRepaint = bRP; }
586 
GetBulletX() const587 	sal_uInt16				GetBulletX() const			{ return nBulletX; }
SetBulletX(sal_uInt16 n)588 	void				SetBulletX( sal_uInt16 n ) 		{ nBulletX = n; }
589 
590 	void				MarkInvalid( sal_uInt16 nStart, short nDiff);
591 	void				MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 nEnd );
592 
593 	void				SetVisible( sal_Bool bVisible );
IsVisible()594 	sal_Bool				IsVisible()					{ return bVisible; }
595 
GetHeight() const596 	long				GetHeight() const 			{ return ( bVisible ? nHeight : 0 ); }
GetFirstLineOffset() const597 	sal_uInt16				GetFirstLineOffset() const 	{ return ( bVisible ? nFirstLineOffset : 0 ); }
ResetHeight()598 	void				ResetHeight()	{ nHeight = 0; nFirstLineOffset = 0; }
599 
GetNode() const600 	ContentNode*		GetNode() const				{ return pNode; }
GetTextPortions()601 	TextPortionList&	GetTextPortions() 			{ return aTextPortionList; }
602 
GetInvalidPosStart() const603 	sal_uInt16				GetInvalidPosStart() const	{ return nInvalidPosStart; }
GetInvalidDiff() const604 	short				GetInvalidDiff() const 		{ return nInvalidDiff; }
605 
606 	void				CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
607 
608 	sal_Bool				DbgCheckTextPortions();
609 };
610 
611 typedef ParaPortion* ParaPortionPtr;
612 
613 // -------------------------------------------------------------------------
614 // class ParaPortionList
615 // -------------------------------------------------------------------------
616 class ParaPortionList : public BaseList<ParaPortion>
617 {
618 	sal_uInt32 nLastCache;
619 public:
620 					ParaPortionList();
621 					~ParaPortionList();
622 
623 	void			Reset();
624 	long			GetYOffset( ParaPortion* pPPortion );
625 	sal_uInt32			FindParagraph( long nYOffset );
626 
SaveGetObject(sal_uInt32 nPos) const627 	inline ParaPortion*	SaveGetObject( sal_uInt32 nPos ) const
628 		{ return ( nPos < Count() ) ? GetObject( nPos ) : 0; }
629 
630 	sal_uInt32                  GetPos( const ParaPortionPtr &rPtr ) const;
631 
632 	// temporaer:
633 	void			DbgCheck( EditDoc& rDoc );
634 };
635 
636 // -------------------------------------------------------------------------
637 // class EditSelection
638 // -------------------------------------------------------------------------
639 class EditSelection
640 {
641 private:
642 	EditPaM 		aStartPaM;
643 	EditPaM 		aEndPaM;
644 
645 public:
646 					EditSelection();	// kein CCTOR und DTOR, geht autom. richtig!
647 					EditSelection( const EditPaM& rStartAndAnd );
648 					EditSelection( const EditPaM& rStart, const EditPaM& rEnd );
649 
Min()650 	EditPaM&		Min()				{ return aStartPaM; }
Max()651 	EditPaM&		Max()				{ return aEndPaM; }
652 
Min() const653 	const EditPaM&	Min() const			{ return aStartPaM; }
Max() const654 	const EditPaM&	Max() const			{ return aEndPaM; }
655 
HasRange() const656 	sal_Bool			HasRange() const	{ return aStartPaM != aEndPaM; }
657     sal_Bool            IsInvalid() const;
658 	sal_Bool			DbgIsBuggy( EditDoc& rDoc );
659 
660 	sal_Bool			Adjust( const ContentList& rNodes );
661 
662 	EditSelection&	operator = ( const EditPaM& r );
operator ==(const EditSelection & r) const663 	sal_Bool 			operator == ( const EditSelection& r ) const
664 					{ return ( ( aStartPaM == r.aStartPaM ) && ( aEndPaM == r.aEndPaM ) )
665 							? sal_True : sal_False; }
operator !=(const EditSelection & r) const666 	sal_Bool 			operator != ( const EditSelection& r ) const { return !( r == *this ); }
667 };
668 
669 // -------------------------------------------------------------------------
670 // class DeletedNodeInfo
671 // -------------------------------------------------------------------------
672 class DeletedNodeInfo
673 {
674 private:
675 	sal_uIntPtr 	nInvalidAdressPtr;
676 	sal_uInt32	nInvalidParagraph;
677 
678 public:
DeletedNodeInfo(sal_uIntPtr nInvAdr,sal_uInt32 nPos)679 			DeletedNodeInfo( sal_uIntPtr nInvAdr, sal_uInt32 nPos )
680 											{ 	nInvalidAdressPtr = nInvAdr;
681 												nInvalidParagraph = nPos; }
682 
GetInvalidAdress()683 	sal_uIntPtr	GetInvalidAdress()				{	return nInvalidAdressPtr; }
GetPosition()684 	sal_uInt32	GetPosition()					{	return nInvalidParagraph; }
685 };
686 
687 typedef DeletedNodeInfo* DeletedNodeInfoPtr;
688 SV_DECL_PTRARR( DeletedNodesList, DeletedNodeInfoPtr, 0, 4 )
689 
690 // -------------------------------------------------------------------------
691 // class EditDoc
692 // -------------------------------------------------------------------------
693 class EditDoc : public ContentList
694 {
695 private:
696 	SfxItemPool*	pItemPool;
697     Link            aModifyHdl;
698 
699 	SvxFont			aDefFont;			//schneller, als jedesmal vom Pool!
700 	sal_uInt16			nDefTab;
701 	sal_Bool			bIsVertical;
702 	sal_Bool			bIsFixedCellHeight;
703 
704 	sal_Bool			bOwnerOfPool;
705 	sal_Bool			bModified;
706 
707 protected:
708 	void			ImplDestroyContents();
709 
710 public:
711 					EditDoc( SfxItemPool* pItemPool );
712 					~EditDoc();
713 
IsModified() const714 	sal_Bool			IsModified() const		{ return bModified; }
715 	void			SetModified( sal_Bool b );
716 
SetModifyHdl(const Link & rLink)717     void            SetModifyHdl( const Link& rLink ) { aModifyHdl = rLink; }
GetModifyHdl() const718     Link            GetModifyHdl() const { return aModifyHdl; }
719 
720 	void			CreateDefFont( sal_Bool bUseStyles );
GetDefFont()721 	const SvxFont&	GetDefFont() { return aDefFont; }
722 
SetDefTab(sal_uInt16 nTab)723 	void			SetDefTab( sal_uInt16 nTab )	{ nDefTab = nTab ? nTab : DEFTAB; }
GetDefTab() const724 	sal_uInt16			GetDefTab() const 			{ return nDefTab; }
725 
SetVertical(sal_Bool bVertical)726 	void			SetVertical( sal_Bool bVertical )	{ bIsVertical = bVertical; }
IsVertical() const727 	sal_Bool			IsVertical() const 				{ return bIsVertical; }
728 
SetFixedCellHeight(sal_Bool bUseFixedCellHeight)729 	void			SetFixedCellHeight( sal_Bool bUseFixedCellHeight )	{ bIsFixedCellHeight = bUseFixedCellHeight; }
IsFixedCellHeight() const730 	sal_Bool			IsFixedCellHeight() const 				{ return bIsFixedCellHeight; }
731 
732 	EditPaM			Clear();
733 	EditPaM			RemoveText();
734 	EditPaM			RemoveChars( EditPaM aPaM, sal_uInt16 nChars );
735     void            InsertText( const EditPaM& rPaM, xub_Unicode c );
736 	EditPaM			InsertText( EditPaM aPaM, const XubString& rStr );
737 	EditPaM			InsertParaBreak( EditPaM aPaM, sal_Bool bKeepEndingAttribs );
738 	EditPaM			InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem );
739 	EditPaM			ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight );
740 
741 	String			GetText( LineEnd eEnd ) const;
742 	sal_uLong			GetTextLen() const;
743 
744 	XubString 		GetParaAsString( sal_uInt32 nNode ) const;
745 	XubString 		GetParaAsString( ContentNode* pNode, sal_uInt16 nStartPos = 0, sal_uInt16 nEndPos = 0xFFFF, sal_Bool bResolveFields = sal_True ) const;
746 
747 	inline EditPaM	GetStartPaM() const;
748 	inline EditPaM	GetEndPaM() const;
749 
GetItemPool()750 	SfxItemPool&		GetItemPool()					{ return *pItemPool; }
GetItemPool() const751 	const SfxItemPool&	GetItemPool() const				{ return *pItemPool; }
752 
753 	void			RemoveItemsFromPool( ContentNode* pNode );
754 
755 	void			InsertAttrib( const SfxPoolItem& rItem, ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd );
756 	void 			InsertAttrib( ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, const SfxPoolItem& rPoolItem );
757 	void			InsertAttribInSelection( ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, const SfxPoolItem& rPoolItem );
758 	sal_Bool			RemoveAttribs( ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, sal_uInt16 nWhich = 0 );
759 	sal_Bool			RemoveAttribs( ContentNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, EditCharAttrib*& rpStarting, EditCharAttrib*& rpEnding, sal_uInt16 nWhich = 0 );
760 	void			FindAttribs( ContentNode* pNode, sal_uInt16 nStartPos, sal_uInt16 nEndPos, SfxItemSet& rCurSet );
761 
GetPos(ContentNode * pNode) const762 	sal_uInt32			GetPos( ContentNode* pNode ) const { return ContentList::GetPos(pNode); }
SaveGetObject(sal_uInt32 nPos) const763 	ContentNode*	SaveGetObject( sal_uInt32 nPos ) const { return ( nPos < Count() ) ? GetObject( nPos ) : 0; }
764 
765 	static XubString	GetSepStr( LineEnd eEnd );
766 };
767 
GetStartPaM() const768 inline EditPaM EditDoc::GetStartPaM() const
769 {
770 	return EditPaM( GetObject( 0 ), 0 );
771 }
772 
GetEndPaM() const773 inline EditPaM EditDoc::GetEndPaM() const
774 {
775 	ContentNode* pLastNode = GetObject( Count()-1 );
776 	return EditPaM( pLastNode, pLastNode->Len() );
777 }
778 
GetAttrib(const CharAttribArray & rAttribs,sal_uInt16 nAttr)779 inline EditCharAttrib* GetAttrib( const CharAttribArray& rAttribs, sal_uInt16 nAttr )
780 {
781 	return ( nAttr < rAttribs.Count() ) ? rAttribs[nAttr] : 0;
782 }
783 
784 sal_Bool CheckOrderedList( CharAttribArray& rAttribs, sal_Bool bStart );
785 
786 // -------------------------------------------------------------------------
787 // class EditEngineItemPool
788 // -------------------------------------------------------------------------
789 class EditEngineItemPool : public SfxItemPool
790 {
791 public:
792 						EditEngineItemPool( sal_Bool bPersistenRefCounts );
793 protected:
794 						virtual ~EditEngineItemPool();
795 public:
796 
797 	virtual SvStream&	Store( SvStream& rStream ) const;
798 };
799 
800 #endif // _EDITDOC_HXX
801