xref: /trunk/main/svtools/source/edit/textdoc.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*01aa44aaSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*01aa44aaSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*01aa44aaSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*01aa44aaSAndrew Rist  * distributed with this work for additional information
6*01aa44aaSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*01aa44aaSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*01aa44aaSAndrew Rist  * "License"); you may not use this file except in compliance
9*01aa44aaSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*01aa44aaSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*01aa44aaSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*01aa44aaSAndrew Rist  * software distributed under the License is distributed on an
15*01aa44aaSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*01aa44aaSAndrew Rist  * KIND, either express or implied.  See the License for the
17*01aa44aaSAndrew Rist  * specific language governing permissions and limitations
18*01aa44aaSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*01aa44aaSAndrew Rist  *************************************************************/
21*01aa44aaSAndrew Rist 
22*01aa44aaSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _TEXTDOC_HXX
25cdf0e10cSrcweir #define _TEXTDOC_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svl/svarray.hxx>
28cdf0e10cSrcweir #include <svtools/textdata.hxx>
29cdf0e10cSrcweir #include <svtools/txtattr.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <tools/string.hxx>
33cdf0e10cSrcweir #include <tools/list.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir typedef TextCharAttrib* TextCharAttribPtr;
36cdf0e10cSrcweir SV_DECL_PTRARR_DEL( TextCharAttribs, TextCharAttribPtr, 0, 4 )
37cdf0e10cSrcweir 
38cdf0e10cSrcweir class TextCharAttribList : private TextCharAttribs
39cdf0e10cSrcweir {
40cdf0e10cSrcweir private:
41cdf0e10cSrcweir     sal_Bool            mbHasEmptyAttribs;
42cdf0e10cSrcweir 
TextCharAttribList(const TextCharAttribList &)43cdf0e10cSrcweir                     TextCharAttribList( const TextCharAttribList& ) : TextCharAttribs() {}
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public:
46cdf0e10cSrcweir                     TextCharAttribList();
47cdf0e10cSrcweir                     ~TextCharAttribList();
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     void            Clear( sal_Bool bDestroyAttribs );
Count() const50cdf0e10cSrcweir     sal_uInt16          Count() const               { return TextCharAttribs::Count(); }
51cdf0e10cSrcweir 
GetAttrib(sal_uInt16 n) const52cdf0e10cSrcweir     TextCharAttrib* GetAttrib( sal_uInt16 n ) const { return TextCharAttribs::GetObject( n ); }
RemoveAttrib(sal_uInt16 n)53cdf0e10cSrcweir     void            RemoveAttrib( sal_uInt16 n )    { TextCharAttribs::Remove( n, 1 ); }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     void            InsertAttrib( TextCharAttrib* pAttrib );
56cdf0e10cSrcweir 
57cdf0e10cSrcweir     void            DeleteEmptyAttribs();
58cdf0e10cSrcweir     void            ResortAttribs();
59cdf0e10cSrcweir 
HasEmptyAttribs() const60cdf0e10cSrcweir     sal_Bool            HasEmptyAttribs() const { return mbHasEmptyAttribs; }
HasEmptyAttribs()61cdf0e10cSrcweir     sal_Bool&           HasEmptyAttribs()       { return mbHasEmptyAttribs; }
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
64cdf0e10cSrcweir     TextCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const;
65cdf0e10cSrcweir     TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
66cdf0e10cSrcweir     sal_Bool            HasAttrib( sal_uInt16 nWhich ) const;
67cdf0e10cSrcweir     sal_Bool            HasBoundingAttrib( sal_uInt16 nBound );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir #ifdef  DBG_UTIL
70cdf0e10cSrcweir     sal_Bool            DbgCheckAttribs();
71cdf0e10cSrcweir #endif
72cdf0e10cSrcweir };
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 
75cdf0e10cSrcweir class TextNode
76cdf0e10cSrcweir {
77cdf0e10cSrcweir private:
78cdf0e10cSrcweir     String              maText;
79cdf0e10cSrcweir     TextCharAttribList  maCharAttribs;
80cdf0e10cSrcweir 
TextNode(const TextNode &)81cdf0e10cSrcweir                         TextNode( const TextNode& ) {;}
82cdf0e10cSrcweir protected:
83cdf0e10cSrcweir     void                ExpandAttribs( sal_uInt16 nIndex, sal_uInt16 nNewChars );
84cdf0e10cSrcweir     void                CollapsAttribs( sal_uInt16 nIndex, sal_uInt16 nDelChars );
85cdf0e10cSrcweir 
86cdf0e10cSrcweir public:
87cdf0e10cSrcweir                         TextNode( const String& rText );
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 
GetText() const90cdf0e10cSrcweir     const String&               GetText() const         { return maText; }
91cdf0e10cSrcweir 
GetCharAttribs() const92cdf0e10cSrcweir     const TextCharAttribList&   GetCharAttribs() const  { return maCharAttribs; }
GetCharAttribs()93cdf0e10cSrcweir     TextCharAttribList&         GetCharAttribs()        { return maCharAttribs; }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     void                InsertText( sal_uInt16 nPos, const String& rText );
96cdf0e10cSrcweir     void                InsertText( sal_uInt16 nPos, sal_Unicode c );
97cdf0e10cSrcweir     void                RemoveText( sal_uInt16 nPos, sal_uInt16 nChars );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     TextNode*           Split( sal_uInt16 nPos, sal_Bool bKeepEndigAttribs );
100cdf0e10cSrcweir     void                Append( const TextNode& rNode );
101cdf0e10cSrcweir };
102cdf0e10cSrcweir 
103cdf0e10cSrcweir class TextDoc
104cdf0e10cSrcweir {
105cdf0e10cSrcweir private:
106cdf0e10cSrcweir     ToolsList<TextNode*> maTextNodes;
107cdf0e10cSrcweir     sal_uInt16              mnLeftMargin;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir protected:
110cdf0e10cSrcweir     void                DestroyTextNodes();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir public:
113cdf0e10cSrcweir                         TextDoc();
114cdf0e10cSrcweir                         ~TextDoc();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     void                Clear();
117cdf0e10cSrcweir 
GetNodes()118cdf0e10cSrcweir     ToolsList<TextNode*>&       GetNodes()              { return maTextNodes; }
GetNodes() const119cdf0e10cSrcweir     const ToolsList<TextNode*>& GetNodes() const        { return maTextNodes; }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     TextPaM             RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars );
122cdf0e10cSrcweir     TextPaM             InsertText( const TextPaM& rPaM, sal_Unicode c );
123cdf0e10cSrcweir     TextPaM             InsertText( const TextPaM& rPaM, const String& rStr );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     TextPaM             InsertParaBreak( const TextPaM& rPaM, sal_Bool bKeepEndingAttribs );
126cdf0e10cSrcweir     TextPaM             ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     sal_uLong               GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
129cdf0e10cSrcweir     String              GetText( const sal_Unicode* pSep ) const;
130cdf0e10cSrcweir     String              GetText( sal_uLong nPara ) const;
131cdf0e10cSrcweir 
SetLeftMargin(sal_uInt16 n)132cdf0e10cSrcweir     void                SetLeftMargin( sal_uInt16 n )   { mnLeftMargin = n; }
GetLeftMargin() const133cdf0e10cSrcweir     sal_uInt16              GetLeftMargin() const       { return mnLeftMargin; }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //  sal_Bool                RemoveAttribs( TextNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd ), sal_uInt16 nWhich = 0 );
136cdf0e10cSrcweir //  sal_Bool                RemoveAttribs( TextNode* pNode, sal_uInt16 nStart, sal_uInt16 nEnd, TextCharAttrib*& rpStarting, TextCharAttrib*& rpEnding, sal_uInt16 nWhich = 0 );
137cdf0e10cSrcweir //  void                InsertAttrib( const EditCharAttrib* pAttr );
138cdf0e10cSrcweir //  void                InsertAttribInSelection( const EditCharAttrib* pAttr );
139cdf0e10cSrcweir //  void                FindAttribs( TextNode* pNode, sal_uInt16 nStartPos, sal_uInt16 nEndPos, SfxItemSet& rCurSet );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     sal_Bool                IsValidPaM( const TextPaM& rPaM );
142cdf0e10cSrcweir };
143cdf0e10cSrcweir 
144cdf0e10cSrcweir #endif // _TEXTDOC_HXX
145