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/ptr_container/ptr_vector.hpp>
27 :
28 : class TextCharAttribList
29 : {
30 : private:
31 : TextCharAttribList(const TextCharAttribList&) SAL_DELETED_FUNCTION;
32 : TextCharAttribList& operator=(const TextCharAttribList&) SAL_DELETED_FUNCTION;
33 :
34 : typedef boost::ptr_vector<TextCharAttrib> TextCharAttribs;
35 : TextCharAttribs maAttribs;
36 : bool mbHasEmptyAttribs;
37 :
38 : public:
39 : TextCharAttribList();
40 : ~TextCharAttribList();
41 :
42 : void Clear();
43 298 : sal_uInt16 Count() const { return maAttribs.size(); }
44 :
45 0 : const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return maAttribs[n]; }
46 0 : TextCharAttrib* GetAttrib( sal_uInt16 n ) { return &maAttribs[n]; }
47 0 : void RemoveAttrib( sal_uInt16 n ) { maAttribs.release( maAttribs.begin() + n ).release(); }
48 :
49 : void InsertAttrib( TextCharAttrib* pAttrib );
50 :
51 : void DeleteEmptyAttribs();
52 : void ResortAttribs();
53 :
54 : bool HasEmptyAttribs() const { return mbHasEmptyAttribs; }
55 198 : bool& HasEmptyAttribs() { return mbHasEmptyAttribs; }
56 :
57 : TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
58 : const TextCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_uInt16 nFromPos, sal_uInt16 nMaxPos = 0xFFFF ) const;
59 : TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_uInt16 nPos );
60 : bool HasAttrib( sal_uInt16 nWhich ) const;
61 : bool HasBoundingAttrib( sal_uInt16 nBound );
62 : };
63 :
64 179 : class TextNode
65 : {
66 : private:
67 : OUString maText;
68 : TextCharAttribList maCharAttribs;
69 :
70 : TextNode( const TextNode& ) {;}
71 : protected:
72 : void ExpandAttribs( sal_uInt16 nIndex, sal_uInt16 nNewChars );
73 : void CollapsAttribs( sal_uInt16 nIndex, sal_uInt16 nDelChars );
74 :
75 : public:
76 : TextNode( const OUString& rText );
77 :
78 2702 : const OUString& GetText() const { return maText; }
79 :
80 0 : const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); }
81 0 : const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
82 454 : TextCharAttribList& GetCharAttribs() { return maCharAttribs; }
83 :
84 : void InsertText( sal_uInt16 nPos, const OUString& rText );
85 : void InsertText( sal_uInt16 nPos, sal_Unicode c );
86 : void RemoveText( sal_uInt16 nPos, sal_uInt16 nChars );
87 :
88 : TextNode* Split( sal_uInt16 nPos, bool bKeepEndigAttribs );
89 : void Append( const TextNode& rNode );
90 : };
91 :
92 : class TextDoc
93 : {
94 : private:
95 : std::vector<TextNode*> maTextNodes;
96 : sal_uInt16 mnLeftMargin;
97 :
98 : protected:
99 : void DestroyTextNodes();
100 :
101 : public:
102 : TextDoc();
103 : ~TextDoc();
104 :
105 : void Clear();
106 :
107 2494 : std::vector<TextNode*>& GetNodes() { return maTextNodes; }
108 : const std::vector<TextNode*>& GetNodes() const { return maTextNodes; }
109 :
110 : TextPaM RemoveChars( const TextPaM& rPaM, sal_uInt16 nChars );
111 : TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c );
112 : TextPaM InsertText( const TextPaM& rPaM, const OUString& rStr );
113 :
114 : TextPaM InsertParaBreak( const TextPaM& rPaM, bool bKeepEndingAttribs );
115 : TextPaM ConnectParagraphs( TextNode* pLeft, TextNode* pRight );
116 :
117 : sal_uLong GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = NULL ) const;
118 : OUString GetText( const sal_Unicode* pSep ) const;
119 : OUString GetText( sal_uLong nPara ) const;
120 :
121 18 : void SetLeftMargin( sal_uInt16 n ) { mnLeftMargin = n; }
122 433 : sal_uInt16 GetLeftMargin() const { return mnLeftMargin; }
123 :
124 : bool IsValidPaM( const TextPaM& rPaM );
125 : };
126 :
127 : #endif // INCLUDED_VCL_SOURCE_EDIT_TEXTDOC_HXX
128 :
129 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|