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