LibreOffice Module vcl (master)  1
textdoc.hxx
Go to the documentation of this file.
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 <vector>
27 #include <memory>
28 
30 {
31 private:
32  TextCharAttribList(const TextCharAttribList&) = delete;
34 
35  std::vector<std::unique_ptr<TextCharAttrib> > maAttribs;
37 
38 public:
41 
42  void Clear();
43  sal_uInt16 Count() const { return maAttribs.size(); }
44 
45  const TextCharAttrib& GetAttrib( sal_uInt16 n ) const { return *maAttribs[n]; }
46  TextCharAttrib& GetAttrib( sal_uInt16 n ) { return *maAttribs[n]; }
47  std::unique_ptr<TextCharAttrib> RemoveAttrib( sal_uInt16 n )
48  {
49  std::unique_ptr<TextCharAttrib> pReleased = std::move(maAttribs[n]);
50  maAttribs.erase( maAttribs.begin() + n );
51  return pReleased;
52  }
53 
54  void InsertAttrib( std::unique_ptr<TextCharAttrib> pAttrib );
55 
56  void DeleteEmptyAttribs();
57  void ResortAttribs();
58 
59  bool& HasEmptyAttribs() { return mbHasEmptyAttribs; }
60 
61  TextCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
62  TextCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
63  bool HasBoundingAttrib( sal_Int32 nBound );
64 };
65 
66 class TextNode
67 {
68  OUString maText;
70 
71  void ExpandAttribs( sal_Int32 nIndex, sal_Int32 nNewChars );
72  void CollapseAttribs( sal_Int32 nIndex, sal_Int32 nDelChars );
73 
74 public:
75  TextNode( const OUString& rText );
76 
77  TextNode( const TextNode& ) = delete;
78  void operator=( const TextNode& ) = delete;
79 
80  const OUString& GetText() const { return maText; }
81 
82  const TextCharAttrib& GetCharAttrib(sal_uInt16 nPos) const { return maCharAttribs.GetAttrib(nPos); }
83  const TextCharAttribList& GetCharAttribs() const { return maCharAttribs; }
85 
86  void InsertText( sal_Int32 nPos, const OUString& rText );
87  void InsertText( sal_Int32 nPos, sal_Unicode c );
88  void RemoveText( sal_Int32 nPos, sal_Int32 nChars );
89 
90  std::unique_ptr<TextNode> Split( sal_Int32 nPos );
91  void Append( const TextNode& rNode );
92 };
93 
94 class TextDoc
95 {
96  std::vector<std::unique_ptr<TextNode>> maTextNodes;
97  sal_uInt16 mnLeftMargin;
98 
99  void DestroyTextNodes();
100 
101 public:
102  TextDoc();
103  ~TextDoc();
104 
105  void Clear();
106 
107  std::vector<std::unique_ptr<TextNode>>& GetNodes() { return maTextNodes; }
108  const std::vector<std::unique_ptr<TextNode>>& GetNodes() const { return maTextNodes; }
109 
110  void RemoveChars( const TextPaM& rPaM, sal_Int32 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 );
115  TextPaM ConnectParagraphs( TextNode* pLeft, const TextNode* pRight );
116 
117  sal_Int32 GetTextLen( const sal_Unicode* pSep, const TextSelection* pSel = nullptr ) const;
118  OUString GetText( const sal_Unicode* pSep ) const;
119  OUString GetText( sal_uInt32 nPara ) const;
120 
121  void SetLeftMargin( sal_uInt16 n ) { mnLeftMargin = n; }
122  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: */
void operator=(const TextNode &)=delete
sal_uInt16 GetLeftMargin() const
Definition: textdoc.hxx:122
std::vector< std::unique_ptr< TextNode > > & GetNodes()
Definition: textdoc.hxx:107
~TextDoc()
Definition: textdoc.cxx:385
OUString GetText(const sal_Unicode *pSep) const
Definition: textdoc.cxx:400
sal_uInt16 mnLeftMargin
Definition: textdoc.hxx:97
const std::vector< std::unique_ptr< TextNode > > & GetNodes() const
Definition: textdoc.hxx:108
TextDoc()
Definition: textdoc.cxx:380
void DestroyTextNodes()
Definition: textdoc.cxx:395
void InsertText(sal_Int32 nPos, const OUString &rText)
Definition: textdoc.cxx:265
void DeleteEmptyAttribs()
Definition: textdoc.cxx:125
std::unique_ptr< TextCharAttrib > RemoveAttrib(sal_uInt16 n)
Definition: textdoc.hxx:47
TextCharAttribList & operator=(const TextCharAttribList &)=delete
const TextCharAttrib & GetAttrib(sal_uInt16 n) const
Definition: textdoc.hxx:45
sal_Int32 GetTextLen(const sal_Unicode *pSep, const TextSelection *pSel=nullptr) const
Definition: textdoc.cxx:426
sal_uInt16 sal_Unicode
TextPaM InsertParaBreak(const TextPaM &rPaM)
Definition: textdoc.cxx:485
const TextCharAttrib & GetCharAttrib(sal_uInt16 nPos) const
Definition: textdoc.hxx:82
sal_uInt16 Count() const
Definition: textdoc.hxx:43
void SetLeftMargin(sal_uInt16 n)
Definition: textdoc.hxx:121
bool & HasEmptyAttribs()
Definition: textdoc.hxx:59
void ExpandAttribs(sal_Int32 nIndex, sal_Int32 nNewChars)
Definition: textdoc.cxx:139
bool mbHasEmptyAttribs
Definition: textdoc.hxx:36
TextCharAttrib * FindEmptyAttrib(sal_uInt16 nWhich, sal_Int32 nPos)
Definition: textdoc.cxx:109
void Clear()
Definition: textdoc.cxx:390
void RemoveChars(const TextPaM &rPaM, sal_Int32 nChars)
Definition: textdoc.cxx:513
TextCharAttribList & GetCharAttribs()
Definition: textdoc.hxx:84
std::vector< std::unique_ptr< TextCharAttrib > > maAttribs
Definition: textdoc.hxx:35
const TextCharAttribList & GetCharAttribs() const
Definition: textdoc.hxx:83
void Append(const TextNode &rNode)
Definition: textdoc.cxx:338
bool IsValidPaM(const TextPaM &rPaM)
Definition: textdoc.cxx:519
void InsertAttrib(std::unique_ptr< TextCharAttrib > pAttrib)
Definition: textdoc.cxx:60
TextNode(const OUString &rText)
Definition: textdoc.cxx:134
bool HasBoundingAttrib(sal_Int32 nBound)
Definition: textdoc.cxx:96
OUString maText
Definition: textdoc.hxx:68
void ResortAttribs()
Definition: textdoc.cxx:78
std::unique_ptr< TextNode > Split(sal_Int32 nPos)
Definition: textdoc.cxx:283
TextPaM InsertText(const TextPaM &rPaM, sal_Unicode c)
Definition: textdoc.cxx:461
void RemoveText(sal_Int32 nPos, sal_Int32 nChars)
Definition: textdoc.cxx:277
const OUString & GetText() const
Definition: textdoc.hxx:80
TextCharAttrib & GetAttrib(sal_uInt16 n)
Definition: textdoc.hxx:46
TextPaM ConnectParagraphs(TextNode *pLeft, const TextNode *pRight)
Definition: textdoc.cxx:497
TextCharAttrib * FindAttrib(sal_uInt16 nWhich, sal_Int32 nPos)
Definition: textdoc.cxx:83
TextCharAttribList maCharAttribs
Definition: textdoc.hxx:69
void CollapseAttribs(sal_Int32 nIndex, sal_Int32 nDelChars)
Definition: textdoc.cxx:203
std::vector< std::unique_ptr< TextNode > > maTextNodes
Definition: textdoc.hxx:96