/src/libreoffice/vcl/source/edit/textdoc.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <rtl/ustring.hxx> |
23 | | #include <vcl/textdata.hxx> |
24 | | #include <vcl/txtattr.hxx> |
25 | | #include <vector> |
26 | | #include <memory> |
27 | | |
28 | | class TextCharAttribList |
29 | | { |
30 | | private: |
31 | | TextCharAttribList(const TextCharAttribList&) = delete; |
32 | | TextCharAttribList& operator=(const TextCharAttribList&) = delete; |
33 | | |
34 | | std::vector<std::unique_ptr<TextCharAttrib> > maAttribs; |
35 | | bool mbHasEmptyAttribs; |
36 | | |
37 | | public: |
38 | | TextCharAttribList(); |
39 | | ~TextCharAttribList(); |
40 | | |
41 | | void Clear(); |
42 | 0 | sal_uInt16 Count() const { return maAttribs.size(); } |
43 | | |
44 | 0 | const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return *maAttribs[n]; } |
45 | 0 | TextCharAttrib& GetAttrib( sal_uInt16 n ) { return *maAttribs[n]; } |
46 | | std::unique_ptr<TextCharAttrib> RemoveAttrib( sal_uInt16 n ) |
47 | 0 | { |
48 | 0 | std::unique_ptr<TextCharAttrib> pReleased = std::move(maAttribs[n]); |
49 | 0 | maAttribs.erase( maAttribs.begin() + n ); |
50 | 0 | return pReleased; |
51 | 0 | } |
52 | | |
53 | | void InsertAttrib( std::unique_ptr<TextCharAttrib> pAttrib ); |
54 | | |
55 | | void DeleteEmptyAttribs(); |
56 | | void ResortAttribs(); |
57 | | |
58 | 0 | bool& HasEmptyAttribs() { return mbHasEmptyAttribs; } |
59 | | |
60 | | TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos ); |
61 | | TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_Int32 nPos ); |
62 | | bool HasBoundingAttrib( sal_Int32 nBound ); |
63 | | }; |
64 | | |
65 | | class TextNode |
66 | | { |
67 | | OUString maText; |
68 | | TextCharAttribList maCharAttribs; |
69 | | |
70 | | void ExpandAttribs( sal_Int32 nIndex, sal_Int32 nNewChars ); |
71 | | void CollapseAttribs( sal_Int32 nIndex, sal_Int32 nDelChars ); |
72 | | |
73 | | public: |
74 | | TextNode( OUString aText ); |
75 | | |
76 | | TextNode( const TextNode& ) = delete; |
77 | | void operator=( const TextNode& ) = delete; |
78 | | |
79 | 0 | const OUString& GetText() const { return maText; } |
80 | | |
81 | 0 | const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); } |
82 | 0 | const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; } |
83 | 0 | TextCharAttribList& GetCharAttribs() { return maCharAttribs; } |
84 | | |
85 | | void InsertText( sal_Int32 nPos, std::u16string_view rText ); |
86 | | void InsertText( sal_Int32 nPos, sal_Unicode c ); |
87 | | void RemoveText( sal_Int32 nPos, sal_Int32 nChars ); |
88 | | |
89 | | std::unique_ptr<TextNode> Split( sal_Int32 nPos ); |
90 | | void Append( const TextNode& rNode ); |
91 | | }; |
92 | | |
93 | | class TextDoc |
94 | | { |
95 | | std::vector<std::unique_ptr<TextNode>> maTextNodes; |
96 | | sal_uInt16 mnLeftMargin; |
97 | | |
98 | | void DestroyTextNodes(); |
99 | | |
100 | | public: |
101 | | TextDoc(); |
102 | | ~TextDoc(); |
103 | | |
104 | | void Clear(); |
105 | | |
106 | 0 | std::vector<std::unique_ptr<TextNode>>& GetNodes() { return maTextNodes; } |
107 | 0 | const std::vector<std::unique_ptr<TextNode>>& GetNodes() const { return maTextNodes; } |
108 | | |
109 | | void RemoveChars( const TextPaM& rPaM, sal_Int32 nChars ); |
110 | | TextPaM InsertText( const TextPaM& rPaM, sal_Unicode c ); |
111 | | TextPaM InsertText( const TextPaM& rPaM, std::u16string_view rStr ); |
112 | | |
113 | | TextPaM InsertParaBreak( const TextPaM& rPaM ); |
114 | | TextPaM ConnectParagraphs( TextNode* pLeft, const TextNode* pRight ); |
115 | | |
116 | | sal_Int32 GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = nullptr ) const; |
117 | | OUString GetText( const sal_Unicode* pSep ) const; |
118 | | OUString GetText( sal_uInt32 nPara ) const; |
119 | | |
120 | 0 | void SetLeftMargin( sal_uInt16 n ) { mnLeftMargin = n; } |
121 | 0 | sal_uInt16 GetLeftMargin() const { return mnLeftMargin; } |
122 | | |
123 | | bool IsValidPaM( const TextPaM& rPaM ); |
124 | | }; |
125 | | |
126 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |