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