xref: /aoo42x/main/svtools/source/edit/textdoc.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 
28 #ifndef _TEXTDOC_HXX
29 #define _TEXTDOC_HXX
30 
31 #include <svl/svarray.hxx>
32 #include <svtools/textdata.hxx>
33 #include <svtools/txtattr.hxx>
34 
35 #include <tools/debug.hxx>
36 #include <tools/string.hxx>
37 #include <tools/list.hxx>
38 
39 typedef TextCharAttrib* TextCharAttribPtr;
40 SV_DECL_PTRARR_DEL( TextCharAttribs, TextCharAttribPtr, 0, 4 )
41 
42 class TextCharAttribList : private TextCharAttribs
43 {
44 private:
45 	sal_Bool			mbHasEmptyAttribs;
46 
47 					TextCharAttribList( const TextCharAttribList& ) : TextCharAttribs() {}
48 
49 public:
50 					TextCharAttribList();
51 					~TextCharAttribList();
52 
53 	void			Clear( sal_Bool bDestroyAttribs );
54 	sal_uInt16			Count()	const				{ return TextCharAttribs::Count(); }
55 
56 	TextCharAttrib*	GetAttrib( sal_uInt16 n ) const	{ return TextCharAttribs::GetObject( n ); }
57 	void			RemoveAttrib( sal_uInt16 n )	{ TextCharAttribs::Remove( n, 1 ); }
58 
59 	void			InsertAttrib( TextCharAttrib* pAttrib );
60 
61 	void			DeleteEmptyAttribs();
62 	void			ResortAttribs();
63 
64 	sal_Bool			HasEmptyAttribs() const	{ return mbHasEmptyAttribs; }
65 	sal_Bool&			HasEmptyAttribs() 		{ return mbHasEmptyAttribs; }
66 
67 	TextCharAttrib*	FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
68 	TextCharAttrib*	FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const;
69 	TextCharAttrib*	FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
70 	sal_Bool 			HasAttrib( sal_uInt16 nWhich ) const;
71 	sal_Bool			HasBoundingAttrib( sal_uInt16 nBound );
72 
73 #ifdef  DBG_UTIL
74 	sal_Bool 			DbgCheckAttribs();
75 #endif
76 };
77 
78 
79 class TextNode
80 {
81 private:
82 	String				maText;
83 	TextCharAttribList	maCharAttribs;
84 
85 						TextNode( const TextNode& ) {;}
86 protected:
87 	void				ExpandAttribs( sal_uInt16 nIndex, sal_uInt16 nNewChars );
88 	void				CollapsAttribs( sal_uInt16 nIndex, sal_uInt16 nDelChars );
89 
90 public:
91 						TextNode( const String& rText );
92 
93 
94 	const String&				GetText() const 		{ return maText; }
95 
96 	const TextCharAttribList&	GetCharAttribs() const	{ return maCharAttribs; }
97 	TextCharAttribList&			GetCharAttribs() 		{ return maCharAttribs; }
98 
99 	void				InsertText( sal_uInt16 nPos, const String& rText );
100 	void				InsertText( sal_uInt16 nPos, sal_Unicode c );
101 	void 				RemoveText( sal_uInt16 nPos, sal_uInt16 nChars );
102 
103 	TextNode*			Split( sal_uInt16 nPos, sal_Bool bKeepEndigAttribs );
104 	void				Append( const TextNode& rNode );
105 };
106 
107 class TextDoc
108 {
109 private:
110 	ToolsList<TextNode*> maTextNodes;
111 	sal_uInt16				mnLeftMargin;
112 
113 protected:
114 	void				DestroyTextNodes();
115 
116 public:
117 						TextDoc();
118 						~TextDoc();
119 
120 	void				Clear();
121 
122 	ToolsList<TextNode*>&		GetNodes() 				{ return maTextNodes; }
123 	const ToolsList<TextNode*>&	GetNodes() const 		{ return maTextNodes; }
124 
125 	TextPaM				RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars );
126 	TextPaM				InsertText( const TextPaM& rPaM, sal_Unicode c );
127 	TextPaM				InsertText( const TextPaM& rPaM, const String& rStr );
128 
129 	TextPaM				InsertParaBreak( const TextPaM& rPaM, sal_Bool bKeepEndingAttribs );
130 	TextPaM				ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
131 
132 	sal_uLong				GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
133 	String				GetText( const sal_Unicode* pSep ) const;
134 	String				GetText( sal_uLong nPara ) const;
135 
136 	void				SetLeftMargin( sal_uInt16 n )	{ mnLeftMargin = n; }
137 	sal_uInt16				GetLeftMargin() const		{ return mnLeftMargin; }
138 
139 //	sal_Bool				RemoveAttribs( TextNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd ), sal_uInt16 nWhich = 0 );
140 //	sal_Bool				RemoveAttribs( TextNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, TextCharAttrib*& rpStarting, TextCharAttrib*& rpEnding, sal_uInt16 nWhich = 0 );
141 //	void				InsertAttrib( const EditCharAttrib* pAttr );
142 //	void				InsertAttribInSelection( const EditCharAttrib* pAttr );
143 //	void				FindAttribs( TextNode* pNode, sal_uInt16 nStartPos, sal_uInt16 nEndPos, SfxItemSet& rCurSet );
144 
145 	sal_Bool				IsValidPaM( const TextPaM& rPaM );
146 };
147 
148 #endif // _TEXTDOC_HXX
149