LibreOffice Module vcl (master)  1
textdat2.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_TEXTDAT2_HXX
21 #define INCLUDED_VCL_SOURCE_EDIT_TEXTDAT2_HXX
22 
23 #include <vcl/seleng.hxx>
24 #include <vcl/cursor.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/textdata.hxx>
27 
28 #include <cstddef>
29 #include <limits>
30 #include <vector>
31 
32 class TextNode;
33 class TextView;
34 
35 #define PORTIONKIND_TEXT 0
36 #define PORTIONKIND_TAB 1
37 
38 #define DELMODE_SIMPLE 0
39 #define DELMODE_RESTOFWORD 1
40 #define DELMODE_RESTOFCONTENT 2
41 
42 #define DEL_LEFT 1
43 #define DEL_RIGHT 2
44 #define TRAVEL_X_DONTKNOW 0xFFFF
45 #define MAXCHARSINPARA 0x3FFF-CHARPOSGROW
46 
47 #define LINE_SEP 0x0A
48 
50 {
51 private:
53  sal_Int32 nLen;
56 
57 public:
58  TETextPortion( sal_Int32 nL )
59  : nWidth {-1}
60  , nLen {nL}
61  , nKind {PORTIONKIND_TEXT}
62  , bRightToLeft {false}
63  {}
64 
65  sal_Int32& GetLen() { return nLen; }
66  sal_Int32 GetLen() const { return nLen; }
67  tools::Long& GetWidth() { return nWidth; }
68  sal_uInt8& GetKind() { return nKind; }
69  void SetRightToLeft(bool b) { bRightToLeft = b; }
70  bool IsRightToLeft() const { return bRightToLeft; }
71 };
72 
74 {
75 private:
76  std::vector<TETextPortion> maPortions;
77 
78 public:
79  static constexpr auto npos = std::numeric_limits<std::size_t>::max();
80 
83 
84  TETextPortion& operator[]( std::size_t nPos );
85  std::vector<TETextPortion>::iterator begin();
86  std::vector<TETextPortion>::const_iterator begin() const;
87  std::vector<TETextPortion>::iterator end();
88  std::vector<TETextPortion>::const_iterator end() const;
89  bool empty() const;
90  std::size_t size() const;
91  std::vector<TETextPortion>::iterator erase( const std::vector<TETextPortion>::iterator& aIter );
92  std::vector<TETextPortion>::iterator insert( const std::vector<TETextPortion>::iterator& aIter,
93  const TETextPortion& rTP );
94  void push_back( const TETextPortion & aTP );
95 
96  void Reset();
97  std::size_t FindPortion( sal_Int32 nCharPos, sal_Int32& rPortionStart, bool bPreferStartingPortion = false );
98  void DeleteFromPortion( std::size_t nDelFrom );
99 };
100 
102 {
104  sal_Int32 nStartPos;
105  sal_Int32 nEndPos;
106  TEWritingDirectionInfo( bool LeftToRight, sal_Int32 Start, sal_Int32 End )
107  : bLeftToRight {LeftToRight}
108  , nStartPos {Start}
109  , nEndPos {End}
110  {}
111 };
112 
113 class TextLine
114 {
115 private:
116  sal_Int32 mnStart;
117  sal_Int32 mnEnd;
118  std::size_t mnStartPortion;
119  std::size_t mnEndPortion;
120 
121  short mnStartX;
122 
123  bool mbInvalid; // for clever formatting/output
124 
125 public:
127  : mnStart {0}
128  , mnEnd {0}
129  , mnStartPortion {0}
130  , mnEndPortion {0}
131  , mnStartX {0}
132  , mbInvalid {true}
133  {}
134 
135  bool IsIn( sal_Int32 nIndex, bool bInclEnd ) const
136  { return nIndex >= mnStart && ( bInclEnd ? nIndex <= mnEnd : nIndex < mnEnd ); }
137 
138  void SetStart( sal_Int32 n ) { mnStart = n; }
139  sal_Int32 GetStart() const { return mnStart; }
140 
141  void SetEnd( sal_Int32 n ) { mnEnd = n; }
142  sal_Int32 GetEnd() const { return mnEnd; }
143 
144  void SetStartPortion( std::size_t n ) { mnStartPortion = n; }
145  std::size_t GetStartPortion() const { return mnStartPortion; }
146 
147  void SetEndPortion( std::size_t n ) { mnEndPortion = n; }
148  std::size_t GetEndPortion() const { return mnEndPortion; }
149 
150  sal_Int32 GetLen() const { return mnEnd - mnStart; }
151 
152  bool IsInvalid() const { return mbInvalid; }
153  bool IsValid() const { return !mbInvalid; }
154  void SetInvalid() { mbInvalid = true; }
155  void SetValid() { mbInvalid = false; }
156 
157  short GetStartX() const { return mnStartX; }
158  void SetStartX( short n ) { mnStartX = n; }
159 
160  inline bool operator == ( const TextLine& rLine ) const;
161 };
162 
163 inline bool TextLine::operator == ( const TextLine& rLine ) const
164 {
165  return mnStart == rLine.mnStart &&
166  mnEnd == rLine.mnEnd &&
167  mnStartPortion == rLine.mnStartPortion &&
168  mnEndPortion == rLine.mnEndPortion;
169 }
170 
172 {
173 private:
175 
176  std::vector<TextLine> maLines;
178  std::vector<TEWritingDirectionInfo> maWritingDirectionInfos;
179 
180  sal_Int32 mnInvalidPosStart;
181  sal_Int32 mnInvalidDiff;
182 
183  bool mbInvalid;
184  bool mbSimple; // only type linearly
185 
186 public:
187  TEParaPortion( TextNode* pNode );
188  ~TEParaPortion();
189 
190  TEParaPortion( const TEParaPortion& ) = delete;
191  void operator=( const TEParaPortion& ) = delete;
192 
193  bool IsInvalid() const { return mbInvalid; }
194  bool IsSimpleInvalid() const { return mbSimple; }
195  void SetNotSimpleInvalid() { mbSimple = false; }
196  void SetValid() { mbInvalid = false; mbSimple = true;}
197 
198  void MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff );
199  void MarkSelectionInvalid( sal_Int32 nStart );
200 
201  sal_Int32 GetInvalidPosStart() const { return mnInvalidPosStart; }
202  sal_Int32 GetInvalidDiff() const { return mnInvalidDiff; }
203 
204  TextNode* GetNode() const { return mpNode; }
205  std::vector<TextLine>& GetLines() { return maLines; }
207  std::vector<TEWritingDirectionInfo>& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
208 
209  std::vector<TextLine>::size_type GetLineNumber( sal_Int32 nIndex, bool bInclEnd );
210  void CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
211 };
212 
214 {
215 private:
216  std::vector<std::unique_ptr<TEParaPortion>> mvData;
217 
218 public:
219  TEParaPortions() : mvData() {}
220  ~TEParaPortions();
221 
222  sal_uInt32 Count() const { return static_cast<sal_uInt32>(mvData.size()); }
223  TEParaPortion* GetObject( sal_uInt32 nIndex ) { return mvData[nIndex].get(); }
224  void Insert( TEParaPortion* pObject, sal_uInt32 nPos ) { mvData.emplace( mvData.begin()+nPos, pObject ); }
225  void Remove( sal_uInt32 nPos ) { mvData.erase( mvData.begin()+nPos ); }
226 };
227 
229 {
230 private:
232 
233 public:
234  TextSelFunctionSet( TextView* pView );
235 
236  virtual void BeginDrag() override;
237 
238  virtual void CreateAnchor() override;
239 
240  virtual void SetCursorAtPoint( const Point& rPointPixel, bool bDontSelectAtCursor = false ) override;
241 
242  virtual bool IsSelectionAtPoint( const Point& rPointPixel ) override;
243  virtual void DeselectAll() override;
244 
245  virtual void DeselectAtPoint( const Point& ) override;
246  virtual void DestroyAnchor() override;
247 };
248 
249 class IdleFormatter : public Idle
250 {
251 private:
253  sal_uInt16 mnRestarts;
254 
255 public:
256  IdleFormatter();
257  virtual ~IdleFormatter() override;
258 
259  void DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts );
260  void ForceTimeout();
261  TextView* GetView() { return mpView; }
262 };
263 
265 {
268 
271 
273  : maCursor()
274  , maDropPos()
275  , mbStarterOfDD {false}
276  , mbVisCursor {false}
277  {
278  maCursor.SetStyle( CURSOR_SHADOW );
279  }
280 };
281 
282 #endif // INCLUDED_VCL_SOURCE_EDIT_TEXTDAT2_HXX
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::vector< std::unique_ptr< TEParaPortion > > mvData
Definition: textdat2.hxx:216
virtual void DestroyAnchor() override
Definition: textview.cxx:1994
virtual ~IdleFormatter() override
Definition: textdata.cxx:278
std::size_t GetStartPortion() const
Definition: textdat2.hxx:145
TextSelFunctionSet(TextView *pView)
Definition: textview.cxx:1954
sal_Int32 GetInvalidDiff() const
Definition: textdat2.hxx:202
bool mbVisCursor
Definition: textdat2.hxx:270
TextView * mpView
Definition: textdat2.hxx:252
std::vector< TETextPortion >::iterator erase(const std::vector< TETextPortion >::iterator &aIter)
Definition: textdata.cxx:98
std::size_t mnStartPortion
Definition: textdat2.hxx:118
TETextPortion(sal_Int32 nL)
Definition: textdat2.hxx:58
sal_Int32 GetLen() const
Definition: textdat2.hxx:150
void SetNotSimpleInvalid()
Definition: textdat2.hxx:195
short mnStartX
Definition: textdat2.hxx:121
TEParaPortion * GetObject(sal_uInt32 nIndex)
Definition: textdat2.hxx:223
sal_Int32 GetLen() const
Definition: textdat2.hxx:66
long Long
TextView * mpView
Definition: textdat2.hxx:231
void SetStart(sal_Int32 n)
Definition: textdat2.hxx:138
sal_Int32 mnInvalidDiff
Definition: textdat2.hxx:181
TextNode * mpNode
Definition: textdat2.hxx:174
bool IsSimpleInvalid() const
Definition: textdat2.hxx:194
bool IsRightToLeft() const
Definition: textdat2.hxx:70
void SetEndPortion(std::size_t n)
Definition: textdat2.hxx:147
sal_uInt32 Count() const
Definition: textdat2.hxx:222
std::vector< TETextPortion >::iterator end()
Definition: textdata.cxx:78
tools::Long nWidth
Definition: textdat2.hxx:52
bool operator==(const TextLine &rLine) const
Definition: textdat2.hxx:163
void push_back(const TETextPortion &aTP)
Definition: textdata.cxx:109
virtual void SetCursorAtPoint(const Point &rPointPixel, bool bDontSelectAtCursor=false) override
Definition: textview.cxx:1974
sal_Int32 mnInvalidPosStart
Definition: textdat2.hxx:180
bool IsInvalid() const
Definition: textdat2.hxx:193
TextView * GetView()
Definition: textdat2.hxx:261
std::vector< TETextPortion > maPortions
Definition: textdat2.hxx:76
std::vector< TextLine > maLines
Definition: textdat2.hxx:176
static constexpr auto npos
Definition: textdat2.hxx:79
bool IsInvalid() const
Definition: textdat2.hxx:152
void CorrectValuesBehindLastFormattedLine(sal_uInt16 nLastFormattedLine)
Definition: textdata.cxx:231
TEParaPortion(TextNode *pNode)
Definition: textdata.cxx:147
void ForceTimeout()
Definition: textdata.cxx:301
#define CURSOR_SHADOW
Definition: cursor.hxx:36
bool IsIn(sal_Int32 nIndex, bool bInclEnd) const
Definition: textdat2.hxx:135
void SetStyle(sal_uInt16 nStyle)
Definition: cursor.cxx:358
bool empty() const
Definition: textdata.cxx:88
void Remove(sal_uInt32 nPos)
Definition: textdat2.hxx:225
sal_Int32 GetEnd() const
Definition: textdat2.hxx:142
TETextPortionList maTextPortions
Definition: textdat2.hxx:177
sal_Int32 mnEnd
Definition: textdat2.hxx:117
void SetRightToLeft(bool b)
Definition: textdat2.hxx:69
sal_uInt8 & GetKind()
Definition: textdat2.hxx:68
sal_Int32 & GetLen()
Definition: textdat2.hxx:65
sal_uInt8 nKind
Definition: textdat2.hxx:54
void MarkInvalid(sal_Int32 nStart, sal_Int32 nDiff)
Definition: textdata.cxx:160
void SetValid()
Definition: textdat2.hxx:196
virtual void CreateAnchor() override
Definition: textview.cxx:1963
vcl::Cursor maCursor
Definition: textdat2.hxx:266
sal_uInt16 mnRestarts
Definition: textdat2.hxx:253
TETextPortion & operator[](std::size_t nPos)
Definition: textdata.cxx:63
void MarkSelectionInvalid(sal_Int32 nStart)
Definition: textdata.cxx:195
virtual bool IsSelectionAtPoint(const Point &rPointPixel) override
Definition: textview.cxx:1979
void operator=(const TEParaPortion &)=delete
bool bRightToLeft
Definition: textdat2.hxx:55
bool mbInvalid
Definition: textdat2.hxx:123
void DoIdleFormat(TextView *pV, sal_uInt16 nMaxRestarts)
Definition: textdata.cxx:283
virtual void BeginDrag() override
Definition: textview.cxx:1959
sal_Int32 mnStart
Definition: textdat2.hxx:116
bool IsValid() const
Definition: textdat2.hxx:153
void SetEnd(sal_Int32 n)
Definition: textdat2.hxx:141
std::vector< TextLine >::size_type GetLineNumber(sal_Int32 nIndex, bool bInclEnd)
Definition: textdata.cxx:213
std::size_t FindPortion(sal_Int32 nCharPos, sal_Int32 &rPortionStart, bool bPreferStartingPortion=false)
Definition: textdata.cxx:125
void DeleteFromPortion(std::size_t nDelFrom)
Definition: textdata.cxx:119
TextPaM maDropPos
Definition: textdat2.hxx:267
short GetStartX() const
Definition: textdat2.hxx:157
void SetStartPortion(std::size_t n)
Definition: textdat2.hxx:144
sal_Int32 nLen
Definition: textdat2.hxx:53
std::vector< TETextPortion >::iterator begin()
Definition: textdata.cxx:68
std::vector< TEWritingDirectionInfo > & GetWritingDirectionInfos()
Definition: textdat2.hxx:207
virtual void DeselectAtPoint(const Point &) override
Definition: textview.cxx:1989
unsigned char sal_uInt8
std::vector< TEWritingDirectionInfo > maWritingDirectionInfos
Definition: textdat2.hxx:178
std::size_t mnEndPortion
Definition: textdat2.hxx:119
std::size_t size() const
Definition: textdata.cxx:93
void SetStartX(short n)
Definition: textdat2.hxx:158
TextNode * GetNode() const
Definition: textdat2.hxx:204
void SetInvalid()
Definition: textdat2.hxx:154
virtual void DeselectAll() override
Definition: textview.cxx:1984
sal_Int32 GetStart() const
Definition: textdat2.hxx:139
sal_Int32 GetInvalidPosStart() const
Definition: textdat2.hxx:201
TETextPortionList & GetTextPortions()
Definition: textdat2.hxx:206
std::vector< TETextPortion >::iterator insert(const std::vector< TETextPortion >::iterator &aIter, const TETextPortion &rTP)
Definition: textdata.cxx:103
TEWritingDirectionInfo(bool LeftToRight, sal_Int32 Start, sal_Int32 End)
Definition: textdat2.hxx:106
std::size_t GetEndPortion() const
Definition: textdat2.hxx:148
std::vector< TextLine > & GetLines()
Definition: textdat2.hxx:205
An idle is a timer to be scheduled immediately.
Definition: idle.hxx:34
tools::Long & GetWidth()
Definition: textdat2.hxx:67
bool mbStarterOfDD
Definition: textdat2.hxx:269
void SetValid()
Definition: textdat2.hxx:155
#define PORTIONKIND_TEXT
Definition: textdat2.hxx:35
void Insert(TEParaPortion *pObject, sal_uInt32 nPos)
Definition: textdat2.hxx:224