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