bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / edit / textdat2.hxx
blob70396be8435e4ecb6fc94bf9e5fd8fe71cdfafb1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_SOURCE_EDIT_TEXTDAT2_HXX
21 #define INCLUDED_VCL_SOURCE_EDIT_TEXTDAT2_HXX
23 #include <vcl/seleng.hxx>
24 #include <vcl/cursor.hxx>
25 #include <vcl/idle.hxx>
26 #include <vcl/textdata.hxx>
28 #include <cstddef>
29 #include <limits>
30 #include <vector>
32 class TextNode;
33 class TextView;
35 #define PORTIONKIND_TEXT 0
36 #define PORTIONKIND_TAB 1
38 #define DELMODE_SIMPLE 0
39 #define DELMODE_RESTOFWORD 1
40 #define DELMODE_RESTOFCONTENT 2
42 #define DEL_LEFT 1
43 #define DEL_RIGHT 2
44 #define TRAVEL_X_DONTKNOW 0xFFFF
45 #define MAXCHARSINPARA 0x3FFF-CHARPOSGROW
47 #define LINE_SEP 0x0A
49 class TETextPortion
51 private:
52 sal_Int32 nLen;
53 long nWidth;
54 sal_uInt8 nKind;
55 bool bRightToLeft;
57 public:
58 TETextPortion( sal_Int32 nL )
59 : nLen {nL}
60 , nWidth {-1}
61 , nKind {PORTIONKIND_TEXT}
62 , bRightToLeft {false}
65 sal_Int32& GetLen() { return nLen; }
66 long& GetWidth() { return nWidth; }
67 sal_uInt8& GetKind() { return nKind; }
68 void SetRightToLeft(bool b) { bRightToLeft = b; }
69 bool IsRightToLeft() const { return bRightToLeft; }
72 class TETextPortionList
74 private:
75 std::vector<std::unique_ptr<TETextPortion>> maPortions;
77 public:
78 static constexpr auto npos = std::numeric_limits<std::size_t>::max();
80 TETextPortionList();
81 ~TETextPortionList();
83 TETextPortion* operator[]( std::size_t nPos );
84 std::vector<std::unique_ptr<TETextPortion>>::iterator begin();
85 std::vector<std::unique_ptr<TETextPortion>>::const_iterator begin() const;
86 std::vector<std::unique_ptr<TETextPortion>>::iterator end();
87 std::vector<std::unique_ptr<TETextPortion>>::const_iterator end() const;
88 bool empty() const;
89 std::size_t size() const;
90 std::vector<std::unique_ptr<TETextPortion>>::iterator erase( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter );
91 std::vector<std::unique_ptr<TETextPortion>>::iterator insert( const std::vector<std::unique_ptr<TETextPortion>>::iterator& aIter,
92 std::unique_ptr<TETextPortion> pTP );
93 void push_back( std::unique_ptr<TETextPortion> pTP );
95 void Reset();
96 std::size_t FindPortion( sal_Int32 nCharPos, sal_Int32& rPortionStart, bool bPreferStartingPortion = false );
97 void DeleteFromPortion( std::size_t nDelFrom );
100 struct TEWritingDirectionInfo
102 bool const bLeftToRight;
103 sal_Int32 const nStartPos;
104 sal_Int32 const nEndPos;
105 TEWritingDirectionInfo( bool LeftToRight, sal_Int32 Start, sal_Int32 End )
106 : bLeftToRight {LeftToRight}
107 , nStartPos {Start}
108 , nEndPos {End}
112 class TextLine
114 private:
115 sal_Int32 mnStart;
116 sal_Int32 mnEnd;
117 std::size_t mnStartPortion;
118 std::size_t mnEndPortion;
120 short mnStartX;
122 bool mbInvalid; // for clever formatting/output
124 public:
125 TextLine()
126 : mnStart {0}
127 , mnEnd {0}
128 , mnStartPortion {0}
129 , mnEndPortion {0}
130 , mnStartX {0}
131 , mbInvalid {true}
134 bool IsIn( sal_Int32 nIndex, bool bInclEnd ) const
135 { return nIndex >= mnStart && ( bInclEnd ? nIndex <= mnEnd : nIndex < mnEnd ); }
137 void SetStart( sal_Int32 n ) { mnStart = n; }
138 sal_Int32 GetStart() const { return mnStart; }
140 void SetEnd( sal_Int32 n ) { mnEnd = n; }
141 sal_Int32 GetEnd() const { return mnEnd; }
143 void SetStartPortion( std::size_t n ) { mnStartPortion = n; }
144 std::size_t GetStartPortion() const { return mnStartPortion; }
146 void SetEndPortion( std::size_t n ) { mnEndPortion = n; }
147 std::size_t GetEndPortion() const { return mnEndPortion; }
149 sal_Int32 GetLen() const { return mnEnd - mnStart; }
151 bool IsInvalid() const { return mbInvalid; }
152 bool IsValid() const { return !mbInvalid; }
153 void SetInvalid() { mbInvalid = true; }
154 void SetValid() { mbInvalid = false; }
156 short GetStartX() const { return mnStartX; }
157 void SetStartX( short n ) { mnStartX = n; }
159 inline bool operator == ( const TextLine& rLine ) const;
162 inline bool TextLine::operator == ( const TextLine& rLine ) const
164 return mnStart == rLine.mnStart &&
165 mnEnd == rLine.mnEnd &&
166 mnStartPortion == rLine.mnStartPortion &&
167 mnEndPortion == rLine.mnEndPortion;
170 class TEParaPortion
172 private:
173 TextNode* const mpNode;
175 std::vector<TextLine> maLines;
176 TETextPortionList maTextPortions;
177 std::vector<TEWritingDirectionInfo> maWritingDirectionInfos;
179 sal_Int32 mnInvalidPosStart;
180 sal_Int32 mnInvalidDiff;
182 bool mbInvalid;
183 bool mbSimple; // only type linearly
185 public:
186 TEParaPortion( TextNode* pNode );
187 ~TEParaPortion();
189 TEParaPortion( const TEParaPortion& ) = delete;
190 void operator=( const TEParaPortion& ) = delete;
192 bool IsInvalid() const { return mbInvalid; }
193 bool IsSimpleInvalid() const { return mbSimple; }
194 void SetNotSimpleInvalid() { mbSimple = false; }
195 void SetValid() { mbInvalid = false; mbSimple = true;}
197 void MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff );
198 void MarkSelectionInvalid( sal_Int32 nStart );
200 sal_Int32 GetInvalidPosStart() const { return mnInvalidPosStart; }
201 sal_Int32 GetInvalidDiff() const { return mnInvalidDiff; }
203 TextNode* GetNode() const { return mpNode; }
204 std::vector<TextLine>& GetLines() { return maLines; }
205 TETextPortionList& GetTextPortions() { return maTextPortions; }
206 std::vector<TEWritingDirectionInfo>& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
208 std::vector<TextLine>::size_type GetLineNumber( sal_Int32 nIndex, bool bInclEnd );
209 void CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
212 class TEParaPortions
214 private:
215 std::vector<std::unique_ptr<TEParaPortion>> mvData;
217 public:
218 TEParaPortions() : mvData() {}
219 ~TEParaPortions();
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 ); }
227 class TextSelFunctionSet: public FunctionSet
229 private:
230 TextView* mpView;
232 public:
233 TextSelFunctionSet( TextView* pView );
235 virtual void BeginDrag() override;
237 virtual void CreateAnchor() override;
239 virtual void SetCursorAtPoint( const Point& rPointPixel, bool bDontSelectAtCursor = false ) override;
241 virtual bool IsSelectionAtPoint( const Point& rPointPixel ) override;
242 virtual void DeselectAll() override;
244 virtual void DeselectAtPoint( const Point& ) override;
245 virtual void DestroyAnchor() override;
248 class IdleFormatter : public Idle
250 private:
251 TextView* mpView;
252 sal_uInt16 mnRestarts;
254 public:
255 IdleFormatter();
256 virtual ~IdleFormatter() override;
258 void DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts );
259 void ForceTimeout();
260 TextView* GetView() { return mpView; }
263 struct TextDDInfo
265 vcl::Cursor maCursor;
266 TextPaM maDropPos;
268 bool mbStarterOfDD;
269 bool mbVisCursor;
271 TextDDInfo()
272 : maCursor()
273 , maDropPos()
274 , mbStarterOfDD {false}
275 , mbVisCursor {false}
277 maCursor.SetStyle( CURSOR_SHADOW );
281 #endif // INCLUDED_VCL_SOURCE_EDIT_TEXTDAT2_HXX
283 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */