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