xref: /AOO41X/main/svtools/source/edit/textdat2.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #ifndef _TEXTDAT2_HXX
30*cdf0e10cSrcweir #define _TEXTDAT2_HXX
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <svl/svarray.hxx>
33*cdf0e10cSrcweir #include <tools/list.hxx>
34*cdf0e10cSrcweir #include <vcl/seleng.hxx>
35*cdf0e10cSrcweir #include <vcl/virdev.hxx>
36*cdf0e10cSrcweir #include <vcl/cursor.hxx>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir class TextNode;
39*cdf0e10cSrcweir class TextView;
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #define PORTIONKIND_TEXT		0
42*cdf0e10cSrcweir #define PORTIONKIND_TAB         1
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #define DELMODE_SIMPLE			0
45*cdf0e10cSrcweir #define DELMODE_RESTOFWORD		1
46*cdf0e10cSrcweir #define DELMODE_RESTOFCONTENT	2
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir #define DEL_LEFT	1
49*cdf0e10cSrcweir #define DEL_RIGHT	2
50*cdf0e10cSrcweir #define TRAVEL_X_DONTKNOW	0xFFFF
51*cdf0e10cSrcweir #define MAXCHARSINPARA		0x3FFF-CHARPOSGROW
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir #define LINE_SEP	0x0A
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir class TETextPortion
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir private:
59*cdf0e10cSrcweir 	sal_uInt16		nLen;
60*cdf0e10cSrcweir 	long 		nWidth;
61*cdf0e10cSrcweir 	sal_uInt8		nKind;
62*cdf0e10cSrcweir     sal_uInt8        nRightToLeft;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir 				TETextPortion()				{ nLen = 0; nKind = PORTIONKIND_TEXT; nWidth = -1; nRightToLeft = 0;}
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir public:
67*cdf0e10cSrcweir 				TETextPortion( sal_uInt16 nL )	{
68*cdf0e10cSrcweir 												nLen = nL;
69*cdf0e10cSrcweir 												nKind = PORTIONKIND_TEXT;
70*cdf0e10cSrcweir 												nWidth= -1;
71*cdf0e10cSrcweir                                                 nRightToLeft = 0;
72*cdf0e10cSrcweir 											}
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir 	sal_uInt16		GetLen() const				{ return nLen; }
75*cdf0e10cSrcweir 	sal_uInt16&		GetLen() 					{ return nLen; }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 	long		GetWidth()const				{ return nWidth; }
78*cdf0e10cSrcweir 	long&		GetWidth()					{ return nWidth; }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	sal_uInt8		GetKind() const				{ return nKind; }
81*cdf0e10cSrcweir 	sal_uInt8&		GetKind()					{ return nKind; }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     sal_uInt8		GetRightToLeft() const		{ return nRightToLeft; }
84*cdf0e10cSrcweir 	sal_uInt8&		GetRightToLeft()			{ return nRightToLeft; }
85*cdf0e10cSrcweir     sal_Bool        IsRightToLeft() const       { return (nRightToLeft&1); }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	sal_Bool		HasValidSize() const		{ return nWidth != (-1); }
88*cdf0e10cSrcweir };
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir typedef TETextPortion* TextPortionPtr;
93*cdf0e10cSrcweir SV_DECL_PTRARR( TextPortionArray, TextPortionPtr, 0, 8 )
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir class TETextPortionList : public TextPortionArray
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir public:
98*cdf0e10cSrcweir 			TETextPortionList();
99*cdf0e10cSrcweir 			~TETextPortionList();
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 	void	Reset();
102*cdf0e10cSrcweir 	sal_uInt16	FindPortion( sal_uInt16 nCharPos, sal_uInt16& rPortionStart, sal_Bool bPreferStartingPortion = sal_False );
103*cdf0e10cSrcweir     sal_uInt16  GetPortionStartIndex( sal_uInt16 nPortion );
104*cdf0e10cSrcweir 	void	DeleteFromPortion( sal_uInt16 nDelFrom );
105*cdf0e10cSrcweir };
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir struct TEWritingDirectionInfo
108*cdf0e10cSrcweir {
109*cdf0e10cSrcweir     sal_uInt8    nType;
110*cdf0e10cSrcweir     sal_uInt16  nStartPos;
111*cdf0e10cSrcweir     sal_uInt16  nEndPos;
112*cdf0e10cSrcweir     TEWritingDirectionInfo( sal_uInt8 _Type, sal_uInt16 _Start, sal_uInt16 _End )
113*cdf0e10cSrcweir     {
114*cdf0e10cSrcweir         nType = _Type;
115*cdf0e10cSrcweir         nStartPos = _Start;
116*cdf0e10cSrcweir         nEndPos = _End;
117*cdf0e10cSrcweir     }
118*cdf0e10cSrcweir };
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir SV_DECL_VARARR( TEWritingDirectionInfos, TEWritingDirectionInfo, 0, 4 )
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir class TextLine
123*cdf0e10cSrcweir {
124*cdf0e10cSrcweir private:
125*cdf0e10cSrcweir 	sal_uInt16			mnStart;
126*cdf0e10cSrcweir 	sal_uInt16			mnEnd;
127*cdf0e10cSrcweir 	sal_uInt16			mnStartPortion;
128*cdf0e10cSrcweir 	sal_uInt16 			mnEndPortion;
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	short			mnStartX;
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	sal_Bool			mbInvalid;	// fuer geschickte Formatierung/Ausgabe
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir public:
135*cdf0e10cSrcweir 					TextLine() 	{
136*cdf0e10cSrcweir 									mnStart = mnEnd = 0;
137*cdf0e10cSrcweir 									mnStartPortion = mnEndPortion = 0;
138*cdf0e10cSrcweir 									mnStartX = 0;
139*cdf0e10cSrcweir 									mbInvalid = sal_True;
140*cdf0e10cSrcweir 								}
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 	sal_Bool			IsIn( sal_uInt16 nIndex ) const
143*cdf0e10cSrcweir 						{ return ( (nIndex >= mnStart ) && ( nIndex < mnEnd ) ); }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	sal_Bool			IsIn( sal_uInt16 nIndex, sal_Bool bInclEnd ) const
146*cdf0e10cSrcweir 						{ return ( ( nIndex >= mnStart ) && ( bInclEnd ? ( nIndex <= mnEnd ) : ( nIndex < mnEnd ) ) ); }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 	void			SetStart( sal_uInt16 n )			{ mnStart = n; }
149*cdf0e10cSrcweir 	sal_uInt16			GetStart() const				{ return mnStart; }
150*cdf0e10cSrcweir 	sal_uInt16&			GetStart() 						{ return mnStart; }
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	void			SetEnd( sal_uInt16 n )				{ mnEnd = n; }
153*cdf0e10cSrcweir 	sal_uInt16			GetEnd() const					{ return mnEnd; }
154*cdf0e10cSrcweir 	sal_uInt16&			GetEnd() 						{ return mnEnd; }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 	void			SetStartPortion( sal_uInt16 n )		{ mnStartPortion = n; }
157*cdf0e10cSrcweir 	sal_uInt16			GetStartPortion() const			{ return mnStartPortion; }
158*cdf0e10cSrcweir 	sal_uInt16&			GetStartPortion() 				{ return mnStartPortion; }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	void			SetEndPortion( sal_uInt16 n )		{ mnEndPortion = n; }
161*cdf0e10cSrcweir 	sal_uInt16			GetEndPortion() const			{ return mnEndPortion; }
162*cdf0e10cSrcweir 	sal_uInt16&			GetEndPortion() 				{ return mnEndPortion; }
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir 	sal_uInt16			GetLen() const					{ return mnEnd - mnStart; }
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 	sal_Bool			IsInvalid()	const				{ return mbInvalid; }
167*cdf0e10cSrcweir 	sal_Bool			IsValid() const					{ return !mbInvalid; }
168*cdf0e10cSrcweir 	void			SetInvalid()					{ mbInvalid = sal_True; }
169*cdf0e10cSrcweir 	void			SetValid()						{ mbInvalid = sal_False; }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 	sal_Bool			IsEmpty() const					{ return (mnEnd > mnStart) ? sal_False : sal_True; }
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 	short			GetStartX() const				{ return mnStartX; }
174*cdf0e10cSrcweir 	void			SetStartX( short n )			{ mnStartX = n; }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	inline sal_Bool operator == ( const TextLine& rLine ) const;
177*cdf0e10cSrcweir 	inline sal_Bool operator != ( const TextLine& rLine ) const;
178*cdf0e10cSrcweir };
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir typedef TextLine* TextLinePtr;
181*cdf0e10cSrcweir  SV_DECL_PTRARR_DEL( TextLines, TextLinePtr, 1, 4 )
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir inline sal_Bool TextLine::operator == ( const TextLine& rLine ) const
184*cdf0e10cSrcweir {
185*cdf0e10cSrcweir 	return ( 	( mnStart == rLine.mnStart ) &&
186*cdf0e10cSrcweir 				( mnEnd == rLine.mnEnd ) &&
187*cdf0e10cSrcweir 				( mnStartPortion == rLine.mnStartPortion ) &&
188*cdf0e10cSrcweir 				( mnEndPortion == rLine.mnEndPortion ) );
189*cdf0e10cSrcweir }
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir inline sal_Bool TextLine::operator != ( const TextLine& rLine ) const
192*cdf0e10cSrcweir {
193*cdf0e10cSrcweir 	return !( *this == rLine );
194*cdf0e10cSrcweir }
195*cdf0e10cSrcweir 
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir class TEParaPortion
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir private:
201*cdf0e10cSrcweir 	TextNode*			    mpNode;
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir 	TextLines			    maLines;
204*cdf0e10cSrcweir 	TETextPortionList       maTextPortions;
205*cdf0e10cSrcweir     TEWritingDirectionInfos maWritingDirectionInfos;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 	sal_uInt16				mnInvalidPosStart;
209*cdf0e10cSrcweir 	short				mnInvalidDiff;
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	sal_Bool				mbInvalid;
212*cdf0e10cSrcweir 	sal_Bool				mbSimple;	// nur lineares Tippen
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 						TEParaPortion( const TEParaPortion& ) {;}
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir public:
218*cdf0e10cSrcweir 						TEParaPortion( TextNode* pNode );
219*cdf0e10cSrcweir 						~TEParaPortion();
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 	sal_Bool				IsInvalid()	const			{ return mbInvalid; }
223*cdf0e10cSrcweir 	sal_Bool				IsSimpleInvalid() const		{ return mbSimple; }
224*cdf0e10cSrcweir 	void				SetNotSimpleInvalid() 		{ mbSimple = sal_False; }
225*cdf0e10cSrcweir 	void				SetValid()					{ mbInvalid = sal_False; mbSimple = sal_True;}
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 	void				MarkInvalid( sal_uInt16 nStart, short nDiff);
228*cdf0e10cSrcweir 	void				MarkSelectionInvalid( sal_uInt16 nStart, sal_uInt16 nEnd );
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir 	sal_uInt16				GetInvalidPosStart() const	{ return mnInvalidPosStart; }
231*cdf0e10cSrcweir 	short				GetInvalidDiff() const 		{ return mnInvalidDiff; }
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 	TextNode*			GetNode() const				{ return mpNode; }
234*cdf0e10cSrcweir 	TextLines&			GetLines()					{ return maLines; }
235*cdf0e10cSrcweir 	TETextPortionList&	GetTextPortions() 			{ return maTextPortions; }
236*cdf0e10cSrcweir     TEWritingDirectionInfos& GetWritingDirectionInfos() { return maWritingDirectionInfos; }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 	sal_uInt16				GetLineNumber( sal_uInt16 nIndex, sal_Bool bInclEnd );
240*cdf0e10cSrcweir 	void				CorrectValuesBehindLastFormattedLine( sal_uInt16 nLastFormattedLine );
241*cdf0e10cSrcweir };
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir class TEParaPortions : public ToolsList<TEParaPortion*>
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir public:
247*cdf0e10cSrcweir 					TEParaPortions();
248*cdf0e10cSrcweir 					~TEParaPortions();
249*cdf0e10cSrcweir 	void			Reset();
250*cdf0e10cSrcweir };
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir class TextSelFunctionSet: public FunctionSet
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir private:
256*cdf0e10cSrcweir 	TextView* 		mpView;
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir public:
259*cdf0e10cSrcweir 					TextSelFunctionSet( TextView* pView );
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	virtual void	BeginDrag();
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	virtual void 	CreateAnchor();
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir 	virtual sal_Bool 	SetCursorAtPoint( const Point& rPointPixel, sal_Bool bDontSelectAtCursor = sal_False );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir 	virtual sal_Bool 	IsSelectionAtPoint( const Point& rPointPixel );
268*cdf0e10cSrcweir 	virtual void 	DeselectAll();
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	virtual void 	DeselectAtPoint( const Point& );
271*cdf0e10cSrcweir 	virtual void 	DestroyAnchor();
272*cdf0e10cSrcweir };
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir class IdleFormatter : public Timer
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir private:
278*cdf0e10cSrcweir 	TextView* 	mpView;
279*cdf0e10cSrcweir 	sal_uInt16		mnRestarts;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir public:
282*cdf0e10cSrcweir 				IdleFormatter();
283*cdf0e10cSrcweir 				~IdleFormatter();
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir 	void		DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts );
286*cdf0e10cSrcweir 	void		ForceTimeout();
287*cdf0e10cSrcweir 	TextView*	GetView()		{ return mpView; }
288*cdf0e10cSrcweir };
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir struct TextDDInfo
291*cdf0e10cSrcweir {
292*cdf0e10cSrcweir 	Cursor			maCursor;
293*cdf0e10cSrcweir 	TextPaM			maDropPos;
294*cdf0e10cSrcweir 
295*cdf0e10cSrcweir 	sal_Bool 			mbStarterOfDD;
296*cdf0e10cSrcweir 	sal_Bool 			mbVisCursor;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir 	TextDDInfo()
299*cdf0e10cSrcweir 	{
300*cdf0e10cSrcweir 		maCursor.SetStyle( CURSOR_SHADOW );
301*cdf0e10cSrcweir 		mbStarterOfDD = sal_False;
302*cdf0e10cSrcweir 		mbVisCursor = sal_False;
303*cdf0e10cSrcweir 	}
304*cdf0e10cSrcweir };
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir #endif // _TEXTDAT2_HXX
307