Line data Source code
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 _TEXTDAT2_HXX
21 : #define _TEXTDAT2_HXX
22 :
23 : #include <vcl/seleng.hxx>
24 : #include <vcl/virdev.hxx>
25 : #include <vcl/cursor.hxx>
26 :
27 : #include <vector>
28 :
29 : class TextNode;
30 : class TextView;
31 :
32 : #define PORTIONKIND_TEXT 0
33 : #define PORTIONKIND_TAB 1
34 :
35 : #define DELMODE_SIMPLE 0
36 : #define DELMODE_RESTOFWORD 1
37 : #define DELMODE_RESTOFCONTENT 2
38 :
39 : #define DEL_LEFT 1
40 : #define DEL_RIGHT 2
41 : #define TRAVEL_X_DONTKNOW 0xFFFF
42 : #define MAXCHARSINPARA 0x3FFF-CHARPOSGROW
43 :
44 : #define LINE_SEP 0x0A
45 :
46 : class TETextPortion
47 : {
48 : private:
49 : sal_uInt16 nLen;
50 : long nWidth;
51 : sal_uInt8 nKind;
52 : sal_uInt8 nRightToLeft;
53 :
54 : TETextPortion() { nLen = 0; nKind = PORTIONKIND_TEXT; nWidth = -1; nRightToLeft = 0;}
55 :
56 : public:
57 298 : TETextPortion( sal_uInt16 nL ) {
58 298 : nLen = nL;
59 298 : nKind = PORTIONKIND_TEXT;
60 298 : nWidth= -1;
61 298 : nRightToLeft = 0;
62 298 : }
63 :
64 : sal_uInt16 GetLen() const { return nLen; }
65 835 : sal_uInt16& GetLen() { return nLen; }
66 :
67 : long GetWidth()const { return nWidth; }
68 862 : long& GetWidth() { return nWidth; }
69 :
70 : sal_uInt8 GetKind() const { return nKind; }
71 589 : sal_uInt8& GetKind() { return nKind; }
72 :
73 : sal_uInt8 GetRightToLeft() const { return nRightToLeft; }
74 315 : sal_uInt8& GetRightToLeft() { return nRightToLeft; }
75 204 : sal_Bool IsRightToLeft() const { return (nRightToLeft&1); }
76 :
77 0 : bool HasValidSize() const { return nWidth != (-1); }
78 : };
79 :
80 :
81 :
82 : typedef std::vector<TETextPortion*> TextPortionArray;
83 :
84 : class TETextPortionList : public TextPortionArray
85 : {
86 : public:
87 : TETextPortionList();
88 : ~TETextPortionList();
89 :
90 : void Reset();
91 : sal_uInt16 FindPortion( sal_uInt16 nCharPos, sal_uInt16& rPortionStart, sal_Bool bPreferStartingPortion = sal_False );
92 : sal_uInt16 GetPortionStartIndex( sal_uInt16 nPortion );
93 : void DeleteFromPortion( sal_uInt16 nDelFrom );
94 : };
95 :
96 : struct TEWritingDirectionInfo
97 : {
98 : sal_uInt8 nType;
99 : sal_uInt16 nStartPos;
100 : sal_uInt16 nEndPos;
101 46 : TEWritingDirectionInfo( sal_uInt8 _Type, sal_uInt16 _Start, sal_uInt16 _End )
102 : {
103 46 : nType = _Type;
104 46 : nStartPos = _Start;
105 46 : nEndPos = _End;
106 46 : }
107 : };
108 :
109 : class TextLine
110 : {
111 : private:
112 : sal_uInt16 mnStart;
113 : sal_uInt16 mnEnd;
114 : sal_uInt16 mnStartPortion;
115 : sal_uInt16 mnEndPortion;
116 :
117 : short mnStartX;
118 :
119 : bool mbInvalid; // fuer geschickte Formatierung/Ausgabe
120 :
121 : public:
122 278 : TextLine() {
123 278 : mnStart = mnEnd = 0;
124 278 : mnStartPortion = mnEndPortion = 0;
125 278 : mnStartX = 0;
126 278 : mbInvalid = true;
127 278 : }
128 :
129 : sal_Bool IsIn( sal_uInt16 nIndex ) const
130 : { return ( (nIndex >= mnStart ) && ( nIndex < mnEnd ) ); }
131 :
132 0 : sal_Bool IsIn( sal_uInt16 nIndex, sal_Bool bInclEnd ) const
133 0 : { return ( ( nIndex >= mnStart ) && ( bInclEnd ? ( nIndex <= mnEnd ) : ( nIndex < mnEnd ) ) ); }
134 :
135 252 : void SetStart( sal_uInt16 n ) { mnStart = n; }
136 0 : sal_uInt16 GetStart() const { return mnStart; }
137 701 : sal_uInt16& GetStart() { return mnStart; }
138 :
139 298 : void SetEnd( sal_uInt16 n ) { mnEnd = n; }
140 0 : sal_uInt16 GetEnd() const { return mnEnd; }
141 117 : sal_uInt16& GetEnd() { return mnEnd; }
142 :
143 0 : void SetStartPortion( sal_uInt16 n ) { mnStartPortion = n; }
144 0 : sal_uInt16 GetStartPortion() const { return mnStartPortion; }
145 629 : sal_uInt16& GetStartPortion() { return mnStartPortion; }
146 :
147 46 : void SetEndPortion( sal_uInt16 n ) { mnEndPortion = n; }
148 0 : sal_uInt16 GetEndPortion() const { return mnEndPortion; }
149 674 : sal_uInt16& GetEndPortion() { return mnEndPortion; }
150 :
151 0 : sal_uInt16 GetLen() const { return mnEnd - mnStart; }
152 :
153 298 : bool IsInvalid() const { return mbInvalid; }
154 298 : bool IsValid() const { return !mbInvalid; }
155 46 : void SetInvalid() { mbInvalid = true; }
156 26 : void SetValid() { mbInvalid = false; }
157 :
158 : bool IsEmpty() const { return (mnEnd > mnStart) ? false : true; }
159 :
160 314 : short GetStartX() const { return mnStartX; }
161 285 : void SetStartX( short n ) { mnStartX = n; }
162 :
163 : inline bool operator == ( const TextLine& rLine ) const;
164 : inline bool operator != ( const TextLine& rLine ) const;
165 : };
166 :
167 109 : class TextLines : public std::vector<TextLine*> {
168 : public:
169 109 : ~TextLines()
170 109 : {
171 218 : for( iterator it = begin(); it != end(); ++it )
172 109 : delete *it;
173 109 : }
174 : };
175 :
176 0 : inline bool TextLine::operator == ( const TextLine& rLine ) const
177 : {
178 0 : return ( ( mnStart == rLine.mnStart ) &&
179 0 : ( mnEnd == rLine.mnEnd ) &&
180 0 : ( mnStartPortion == rLine.mnStartPortion ) &&
181 0 : ( mnEndPortion == rLine.mnEndPortion ) );
182 : }
183 :
184 : inline bool TextLine::operator != ( const TextLine& rLine ) const
185 : {
186 : return !( *this == rLine );
187 : }
188 :
189 :
190 :
191 : class TEParaPortion
192 : {
193 : private:
194 : TextNode* mpNode;
195 :
196 : TextLines maLines;
197 : TETextPortionList maTextPortions;
198 : std::vector<TEWritingDirectionInfo> maWritingDirectionInfos;
199 :
200 :
201 : sal_uInt16 mnInvalidPosStart;
202 : short mnInvalidDiff;
203 :
204 : bool mbInvalid;
205 : bool mbSimple; // nur lineares Tippen
206 :
207 :
208 : TEParaPortion( const TEParaPortion& ) {;}
209 :
210 : public:
211 : TEParaPortion( TextNode* pNode );
212 : ~TEParaPortion();
213 :
214 :
215 343 : bool IsInvalid() const { return mbInvalid; }
216 138 : bool IsSimpleInvalid() const { return mbSimple; }
217 0 : void SetNotSimpleInvalid() { mbSimple = false; }
218 298 : void SetValid() { mbInvalid = false; mbSimple = true;}
219 :
220 : void MarkInvalid( sal_uInt16 nStart, short nDiff);
221 : void MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 nEnd );
222 :
223 46 : sal_uInt16 GetInvalidPosStart() const { return mnInvalidPosStart; }
224 46 : short GetInvalidDiff() const { return mnInvalidDiff; }
225 :
226 715 : TextNode* GetNode() const { return mpNode; }
227 4484 : TextLines& GetLines() { return maLines; }
228 2186 : TETextPortionList& GetTextPortions() { return maTextPortions; }
229 276 : std::vector<TEWritingDirectionInfo>& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
230 :
231 :
232 : sal_uInt16 GetLineNumber( sal_uInt16 nIndex, sal_Bool bInclEnd );
233 : void CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
234 : };
235 :
236 :
237 : class TEParaPortions : public ToolsList<TEParaPortion*>
238 : {
239 : public:
240 : TEParaPortions();
241 : ~TEParaPortions();
242 : void Reset();
243 : };
244 :
245 :
246 90 : class TextSelFunctionSet: public FunctionSet
247 : {
248 : private:
249 : TextView* mpView;
250 :
251 : public:
252 : TextSelFunctionSet( TextView* pView );
253 :
254 : virtual void BeginDrag();
255 :
256 : virtual void CreateAnchor();
257 :
258 : virtual sal_Bool SetCursorAtPoint( const Point& rPointPixel, sal_Bool bDontSelectAtCursor = sal_False );
259 :
260 : virtual sal_Bool IsSelectionAtPoint( const Point& rPointPixel );
261 : virtual void DeselectAll();
262 :
263 : virtual void DeselectAtPoint( const Point& );
264 : virtual void DestroyAnchor();
265 : };
266 :
267 :
268 : class IdleFormatter : public Timer
269 : {
270 : private:
271 : TextView* mpView;
272 : sal_uInt16 mnRestarts;
273 :
274 : public:
275 : IdleFormatter();
276 : ~IdleFormatter();
277 :
278 : void DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts );
279 : void ForceTimeout();
280 0 : TextView* GetView() { return mpView; }
281 : };
282 :
283 0 : struct TextDDInfo
284 : {
285 : Cursor maCursor;
286 : TextPaM maDropPos;
287 :
288 : sal_Bool mbStarterOfDD;
289 : sal_Bool mbVisCursor;
290 :
291 0 : TextDDInfo()
292 0 : {
293 0 : maCursor.SetStyle( CURSOR_SHADOW );
294 0 : mbStarterOfDD = sal_False;
295 0 : mbVisCursor = sal_False;
296 0 : }
297 : };
298 :
299 : #endif // _TEXTDAT2_HXX
300 :
301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|