xref: /trunk/main/svtools/source/edit/textdat2.hxx (revision 01aa44aa)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #ifndef _TEXTDAT2_HXX
26 #define _TEXTDAT2_HXX
27 
28 #include <svl/svarray.hxx>
29 #include <tools/list.hxx>
30 #include <vcl/seleng.hxx>
31 #include <vcl/virdev.hxx>
32 #include <vcl/cursor.hxx>
33 
34 class TextNode;
35 class TextView;
36 
37 #define PORTIONKIND_TEXT		0
38 #define PORTIONKIND_TAB         1
39 
40 #define DELMODE_SIMPLE			0
41 #define DELMODE_RESTOFWORD		1
42 #define DELMODE_RESTOFCONTENT	2
43 
44 #define DEL_LEFT	1
45 #define DEL_RIGHT	2
46 #define TRAVEL_X_DONTKNOW	0xFFFF
47 #define MAXCHARSINPARA		0x3FFF-CHARPOSGROW
48 
49 #define LINE_SEP	0x0A
50 
51 
52 class TETextPortion
53 {
54 private:
55 	sal_uInt16		nLen;
56 	long 		nWidth;
57 	sal_uInt8		nKind;
58     sal_uInt8        nRightToLeft;
59 
TETextPortion()60 				TETextPortion()				{ nLen = 0; nKind = PORTIONKIND_TEXT; nWidth = -1; nRightToLeft = 0;}
61 
62 public:
TETextPortion(sal_uInt16 nL)63 				TETextPortion( sal_uInt16 nL )	{
64 												nLen = nL;
65 												nKind = PORTIONKIND_TEXT;
66 												nWidth= -1;
67                                                 nRightToLeft = 0;
68 											}
69 
GetLen() const70 	sal_uInt16		GetLen() const				{ return nLen; }
GetLen()71 	sal_uInt16&		GetLen() 					{ return nLen; }
72 
GetWidth() const73 	long		GetWidth()const				{ return nWidth; }
GetWidth()74 	long&		GetWidth()					{ return nWidth; }
75 
GetKind() const76 	sal_uInt8		GetKind() const				{ return nKind; }
GetKind()77 	sal_uInt8&		GetKind()					{ return nKind; }
78 
GetRightToLeft() const79     sal_uInt8		GetRightToLeft() const		{ return nRightToLeft; }
GetRightToLeft()80 	sal_uInt8&		GetRightToLeft()			{ return nRightToLeft; }
IsRightToLeft() const81     sal_Bool        IsRightToLeft() const       { return (nRightToLeft&1); }
82 
HasValidSize() const83 	sal_Bool		HasValidSize() const		{ return nWidth != (-1); }
84 };
85 
86 
87 
88 typedef TETextPortion* TextPortionPtr;
89 SV_DECL_PTRARR( TextPortionArray, TextPortionPtr, 0, 8 )
90 
91 class TETextPortionList : public TextPortionArray
92 {
93 public:
94 			TETextPortionList();
95 			~TETextPortionList();
96 
97 	void	Reset();
98 	sal_uInt16	FindPortion( sal_uInt16 nCharPos, sal_uInt16& rPortionStart, sal_Bool bPreferStartingPortion = sal_False );
99     sal_uInt16  GetPortionStartIndex( sal_uInt16 nPortion );
100 	void	DeleteFromPortion( sal_uInt16 nDelFrom );
101 };
102 
103 struct TEWritingDirectionInfo
104 {
105     sal_uInt8    nType;
106     sal_uInt16  nStartPos;
107     sal_uInt16  nEndPos;
TEWritingDirectionInfoTEWritingDirectionInfo108     TEWritingDirectionInfo( sal_uInt8 _Type, sal_uInt16 _Start, sal_uInt16 _End )
109     {
110         nType = _Type;
111         nStartPos = _Start;
112         nEndPos = _End;
113     }
114 };
115 
116 SV_DECL_VARARR( TEWritingDirectionInfos, TEWritingDirectionInfo, 0, 4 )
117 
118 class TextLine
119 {
120 private:
121 	sal_uInt16			mnStart;
122 	sal_uInt16			mnEnd;
123 	sal_uInt16			mnStartPortion;
124 	sal_uInt16 			mnEndPortion;
125 
126 	short			mnStartX;
127 
128 	sal_Bool			mbInvalid;	// fuer geschickte Formatierung/Ausgabe
129 
130 public:
TextLine()131 					TextLine() 	{
132 									mnStart = mnEnd = 0;
133 									mnStartPortion = mnEndPortion = 0;
134 									mnStartX = 0;
135 									mbInvalid = sal_True;
136 								}
137 
IsIn(sal_uInt16 nIndex) const138 	sal_Bool			IsIn( sal_uInt16 nIndex ) const
139 						{ return ( (nIndex >= mnStart ) && ( nIndex < mnEnd ) ); }
140 
IsIn(sal_uInt16 nIndex,sal_Bool bInclEnd) const141 	sal_Bool			IsIn( sal_uInt16 nIndex, sal_Bool bInclEnd ) const
142 						{ return ( ( nIndex >= mnStart ) && ( bInclEnd ? ( nIndex <= mnEnd ) : ( nIndex < mnEnd ) ) ); }
143 
SetStart(sal_uInt16 n)144 	void			SetStart( sal_uInt16 n )			{ mnStart = n; }
GetStart() const145 	sal_uInt16			GetStart() const				{ return mnStart; }
GetStart()146 	sal_uInt16&			GetStart() 						{ return mnStart; }
147 
SetEnd(sal_uInt16 n)148 	void			SetEnd( sal_uInt16 n )				{ mnEnd = n; }
GetEnd() const149 	sal_uInt16			GetEnd() const					{ return mnEnd; }
GetEnd()150 	sal_uInt16&			GetEnd() 						{ return mnEnd; }
151 
SetStartPortion(sal_uInt16 n)152 	void			SetStartPortion( sal_uInt16 n )		{ mnStartPortion = n; }
GetStartPortion() const153 	sal_uInt16			GetStartPortion() const			{ return mnStartPortion; }
GetStartPortion()154 	sal_uInt16&			GetStartPortion() 				{ return mnStartPortion; }
155 
SetEndPortion(sal_uInt16 n)156 	void			SetEndPortion( sal_uInt16 n )		{ mnEndPortion = n; }
GetEndPortion() const157 	sal_uInt16			GetEndPortion() const			{ return mnEndPortion; }
GetEndPortion()158 	sal_uInt16&			GetEndPortion() 				{ return mnEndPortion; }
159 
GetLen() const160 	sal_uInt16			GetLen() const					{ return mnEnd - mnStart; }
161 
IsInvalid() const162 	sal_Bool			IsInvalid()	const				{ return mbInvalid; }
IsValid() const163 	sal_Bool			IsValid() const					{ return !mbInvalid; }
SetInvalid()164 	void			SetInvalid()					{ mbInvalid = sal_True; }
SetValid()165 	void			SetValid()						{ mbInvalid = sal_False; }
166 
IsEmpty() const167 	sal_Bool			IsEmpty() const					{ return (mnEnd > mnStart) ? sal_False : sal_True; }
168 
GetStartX() const169 	short			GetStartX() const				{ return mnStartX; }
SetStartX(short n)170 	void			SetStartX( short n )			{ mnStartX = n; }
171 
172 	inline sal_Bool operator == ( const TextLine& rLine ) const;
173 	inline sal_Bool operator != ( const TextLine& rLine ) const;
174 };
175 
176 typedef TextLine* TextLinePtr;
177  SV_DECL_PTRARR_DEL( TextLines, TextLinePtr, 1, 4 )
178 
operator ==(const TextLine & rLine) const179 inline sal_Bool TextLine::operator == ( const TextLine& rLine ) const
180 {
181 	return ( 	( mnStart == rLine.mnStart ) &&
182 				( mnEnd == rLine.mnEnd ) &&
183 				( mnStartPortion == rLine.mnStartPortion ) &&
184 				( mnEndPortion == rLine.mnEndPortion ) );
185 }
186 
operator !=(const TextLine & rLine) const187 inline sal_Bool TextLine::operator != ( const TextLine& rLine ) const
188 {
189 	return !( *this == rLine );
190 }
191 
192 
193 
194 class TEParaPortion
195 {
196 private:
197 	TextNode*			    mpNode;
198 
199 	TextLines			    maLines;
200 	TETextPortionList       maTextPortions;
201     TEWritingDirectionInfos maWritingDirectionInfos;
202 
203 
204 	sal_uInt16				mnInvalidPosStart;
205 	short				mnInvalidDiff;
206 
207 	sal_Bool				mbInvalid;
208 	sal_Bool				mbSimple;	// nur lineares Tippen
209 
210 
TEParaPortion(const TEParaPortion &)211 						TEParaPortion( const TEParaPortion& ) {;}
212 
213 public:
214 						TEParaPortion( TextNode* pNode );
215 						~TEParaPortion();
216 
217 
IsInvalid() const218 	sal_Bool				IsInvalid()	const			{ return mbInvalid; }
IsSimpleInvalid() const219 	sal_Bool				IsSimpleInvalid() const		{ return mbSimple; }
SetNotSimpleInvalid()220 	void				SetNotSimpleInvalid() 		{ mbSimple = sal_False; }
SetValid()221 	void				SetValid()					{ mbInvalid = sal_False; mbSimple = sal_True;}
222 
223 	void				MarkInvalid( sal_uInt16 nStart, short nDiff);
224 	void				MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 nEnd );
225 
GetInvalidPosStart() const226 	sal_uInt16				GetInvalidPosStart() const	{ return mnInvalidPosStart; }
GetInvalidDiff() const227 	short				GetInvalidDiff() const 		{ return mnInvalidDiff; }
228 
GetNode() const229 	TextNode*			GetNode() const				{ return mpNode; }
GetLines()230 	TextLines&			GetLines()					{ return maLines; }
GetTextPortions()231 	TETextPortionList&	GetTextPortions() 			{ return maTextPortions; }
GetWritingDirectionInfos()232     TEWritingDirectionInfos& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
233 
234 
235 	sal_uInt16				GetLineNumber( sal_uInt16 nIndex, sal_Bool bInclEnd );
236 	void				CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
237 };
238 
239 
240 class TEParaPortions : public ToolsList<TEParaPortion*>
241 {
242 public:
243 					TEParaPortions();
244 					~TEParaPortions();
245 	void			Reset();
246 };
247 
248 
249 class TextSelFunctionSet: public FunctionSet
250 {
251 private:
252 	TextView* 		mpView;
253 
254 public:
255 					TextSelFunctionSet( TextView* pView );
256 
257 	virtual void	BeginDrag();
258 
259 	virtual void 	CreateAnchor();
260 
261 	virtual sal_Bool 	SetCursorAtPoint( const Point& rPointPixel, sal_Bool bDontSelectAtCursor = sal_False );
262 
263 	virtual sal_Bool 	IsSelectionAtPoint( const Point& rPointPixel );
264 	virtual void 	DeselectAll();
265 
266 	virtual void 	DeselectAtPoint( const Point& );
267 	virtual void 	DestroyAnchor();
268 };
269 
270 
271 class IdleFormatter : public Timer
272 {
273 private:
274 	TextView* 	mpView;
275 	sal_uInt16		mnRestarts;
276 
277 public:
278 				IdleFormatter();
279 				~IdleFormatter();
280 
281 	void		DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts );
282 	void		ForceTimeout();
GetView()283 	TextView*	GetView()		{ return mpView; }
284 };
285 
286 struct TextDDInfo
287 {
288 	Cursor			maCursor;
289 	TextPaM			maDropPos;
290 
291 	sal_Bool 			mbStarterOfDD;
292 	sal_Bool 			mbVisCursor;
293 
TextDDInfoTextDDInfo294 	TextDDInfo()
295 	{
296 		maCursor.SetStyle( CURSOR_SHADOW );
297 		mbStarterOfDD = sal_False;
298 		mbVisCursor = sal_False;
299 	}
300 };
301 
302 #endif // _TEXTDAT2_HXX
303