Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_VCL_SOURCE_EDIT_TEXTDOC_HXX
21 : #define INCLUDED_VCL_SOURCE_EDIT_TEXTDOC_HXX
22 :
23 : #include <rtl/ustring.hxx>
24 : #include <vcl/textdata.hxx>
25 : #include <vcl/txtattr.hxx>
26 : #include <boost/noncopyable.hpp>
27 : #include <boost/ptr_container/ptr_vector.hpp>
28 :
29 : class TextCharAttribList : boost::noncopyable
30 : {
31 : private:
32 : typedef boost::ptr_vector<TextCharAttrib> TextCharAttribs;
33 : TextCharAttribs maAttribs;
34 : bool mbHasEmptyAttribs;
35 :
36 : public:
37 : TextCharAttribList();
38 : ~TextCharAttribList();
39 :
40 : void Clear();
41 279 : sal_uInt16 Count() const { return maAttribs.size(); }
42 :
43 0 : const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return maAttribs[n]; }
44 0 : TextCharAttrib* GetAttrib( sal_uInt16 n ) { return &maAttribs[n]; }
45 0 : void RemoveAttrib( sal_uInt16 n ) { maAttribs.release( maAttribs.begin() + n ).release(); }
46 :
47 : void InsertAttrib( TextCharAttrib* pAttrib );
48 :
49 : void DeleteEmptyAttribs();
50 : void ResortAttribs();
51 :
52 : bool HasEmptyAttribs() const { return mbHasEmptyAttribs; }
53 210 : bool& HasEmptyAttribs() { return mbHasEmptyAttribs; }
54 :
55 : TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
56 : const TextCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const;
57 : TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
58 : bool HasAttrib( sal_uInt16 nWhich ) const;
59 : bool HasBoundingAttrib( sal_uInt16 nBound );
60 : };
61 :
62 206 : class TextNode
63 : {
64 : private:
65 : OUString maText;
66 : TextCharAttribList maCharAttribs;
67 :
68 : TextNode( const TextNode& ) {;}
69 : protected:
70 : void ExpandAttribs( sal_uInt16 nIndex, sal_uInt16 nNewChars );
71 : void CollapsAttribs( sal_uInt16 nIndex, sal_uInt16 nDelChars );
72 :
73 : public:
74 : TextNode( const OUString& rText );
75 :
76 3457 : const OUString& GetText() const { return maText; }
77 :
78 0 : const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); }
79 0 : const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
80 437 : TextCharAttribList& GetCharAttribs() { return maCharAttribs; }
81 :
82 : void InsertText( sal_uInt16 nPos, const OUString& rText );
83 : void InsertText( sal_uInt16 nPos, sal_Unicode c );
84 : void RemoveText( sal_uInt16 nPos, sal_uInt16 nChars );
85 :
86 : TextNode* Split( sal_uInt16 nPos, bool bKeepEndigAttribs );
87 : void Append( const TextNode& rNode );
88 : };
89 :
90 : class TextDoc
91 : {
92 : private:
93 : ToolsList<TextNode*> maTextNodes;
94 : sal_uInt16 mnLeftMargin;
95 :
96 : protected:
97 : void DestroyTextNodes();
98 :
99 : public:
100 : TextDoc();
101 : ~TextDoc();
102 :
103 : void Clear();
104 :
105 2715 : ToolsList<TextNode*>& GetNodes() { return maTextNodes; }
106 : const ToolsList<TextNode*>& GetNodes() const { return maTextNodes; }
107 :
108 : TextPaM RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars );
109 : TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c );
110 : TextPaM InsertText( const TextPaM& rPaM, const OUString& rStr );
111 :
112 : TextPaM InsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs );
113 : TextPaM ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
114 :
115 : sal_uLong GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
116 : OUString GetText( const sal_Unicode* pSep ) const;
117 : OUString GetText( sal_uLong nPara ) const;
118 :
119 46 : void SetLeftMargin( sal_uInt16 n ) { mnLeftMargin = n; }
120 514 : sal_uInt16 GetLeftMargin() const { return mnLeftMargin; }
121 :
122 : bool IsValidPaM( const TextPaM& rPaM );
123 : };
124 :
125 : #endif // INCLUDED_VCL_SOURCE_EDIT_TEXTDOC_HXX
126 :
127 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|