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 INCLUDED_EDITENG_INC_EDITDOC_HXX
21 #define INCLUDED_EDITENG_INC_EDITDOC_HXX
22
23 #include <com/sun/star/i18n/XExtendedInputSequenceChecker.hpp>
24
25 #include "editattr.hxx"
26 #include "edtspell.hxx"
27 #include "eerdll2.hxx"
28 #include <editeng/svxfont.hxx>
29 #include <svl/itemset.hxx>
30 #include <svl/style.hxx>
31 #include <svl/itempool.hxx>
32 #include <svl/languageoptions.hxx>
33 #include <tools/lineend.hxx>
34 #include <o3tl/typed_flags_set.hxx>
35
36 #include <memory>
37 #include <vector>
38
39 class ImpEditEngine;
40 class SvxTabStop;
41
42
43 #define CHARPOSGROW 16
44 #define DEFTAB 720
45
46 void CreateFont( SvxFont& rFont, const SfxItemSet& rSet, bool bSearchInParent = true, SvtScriptType nScriptType = SvtScriptType::NONE );
47 sal_uInt16 GetScriptItemId( sal_uInt16 nItemId, SvtScriptType nScriptType );
48 bool IsScriptItemValid( sal_uInt16 nItemId, short nScriptType );
49
50 EditCharAttrib* MakeCharAttrib( SfxItemPool& rPool, const SfxPoolItem& rAttr, sal_Int32 nS, sal_Int32 nE );
51
52 class ContentNode;
53 class EditDoc;
54
55 struct EPaM
56 {
57 sal_Int32 nPara;
58 sal_Int32 nIndex;
59
EPaMEPaM60 EPaM() : nPara(0), nIndex(0) {}
EPaMEPaM61 EPaM( sal_Int32 nP, sal_Int32 nI ) : nPara(nP), nIndex(nI) {}
EPaMEPaM62 EPaM( const EPaM& r) : nPara(r.nPara), nIndex(r.nIndex) {}
operator =EPaM63 EPaM& operator = ( const EPaM& r ) { nPara = r.nPara; nIndex = r.nIndex; return *this; }
64 inline bool operator == ( const EPaM& r ) const;
65 inline bool operator < ( const EPaM& r ) const;
66 };
67
operator <(const EPaM & r) const68 inline bool EPaM::operator < ( const EPaM& r ) const
69 {
70 return ( nPara < r.nPara ) || ( ( nPara == r.nPara ) && nIndex < r.nIndex );
71 }
72
operator ==(const EPaM & r) const73 inline bool EPaM::operator == ( const EPaM& r ) const
74 {
75 return ( nPara == r.nPara ) && ( nIndex == r.nIndex );
76 }
77
78 struct ScriptTypePosInfo
79 {
80 short nScriptType;
81 sal_Int32 nStartPos;
82 sal_Int32 nEndPos;
83
ScriptTypePosInfoScriptTypePosInfo84 ScriptTypePosInfo( short Type, sal_Int32 Start, sal_Int32 End )
85 : nScriptType(Type)
86 , nStartPos(Start)
87 , nEndPos(End)
88 {
89 }
90 };
91
92 typedef std::vector<ScriptTypePosInfo> ScriptTypePosInfos;
93
94 struct WritingDirectionInfo
95 {
96 sal_uInt8 nType;
97 sal_Int32 nStartPos;
98 sal_Int32 nEndPos;
99
WritingDirectionInfoWritingDirectionInfo100 WritingDirectionInfo( sal_uInt8 Type, sal_Int32 Start, sal_Int32 End )
101 : nType(Type)
102 , nStartPos(Start)
103 , nEndPos(End)
104 {
105 }
106 };
107
108
109 typedef std::vector<WritingDirectionInfo> WritingDirectionInfos;
110
111 class ContentAttribsInfo
112 {
113 private:
114 typedef std::vector<std::unique_ptr<EditCharAttrib> > CharAttribsType;
115
116 SfxItemSet aPrevParaAttribs;
117 CharAttribsType aPrevCharAttribs;
118
119 public:
120 ContentAttribsInfo( const SfxItemSet& rParaAttribs );
121
GetPrevParaAttribs() const122 const SfxItemSet& GetPrevParaAttribs() const { return aPrevParaAttribs; }
GetPrevCharAttribs() const123 const CharAttribsType& GetPrevCharAttribs() const { return aPrevCharAttribs; }
124
125 void RemoveAllCharAttribsFromPool(SfxItemPool& rPool) const;
126 void AppendCharAttrib(EditCharAttrib* pNew);
127 };
128
129
130 // class SvxColorList
131
132 typedef std::vector<Color> SvxColorList;
133
134
135 // class ItemList
136
137
138 class ItemList
139 {
140 private:
141 typedef std::vector<const SfxPoolItem*> DummyItemList;
142 DummyItemList aItemPool;
143 sal_Int32 CurrentItem;
144
145 public:
146 ItemList();
147 const SfxPoolItem* First();
148 const SfxPoolItem* Next();
Count()149 sal_Int32 Count() { return aItemPool.size(); };
150 void Insert( const SfxPoolItem* pItem );
Clear()151 void Clear() { aItemPool.clear(); };
152 };
153
154
155 // class ContentAttribs
156
157 class ContentAttribs
158 {
159 private:
160 SfxStyleSheet* pStyle;
161 SfxItemSet aAttribSet;
162
163 public:
164 ContentAttribs( SfxItemPool& rItemPool );
165
166 void dumpAsXml(xmlTextWriterPtr pWriter) const;
167
168 SvxTabStop FindTabStop( sal_Int32 nCurPos, sal_uInt16 nDefTab );
GetItems()169 SfxItemSet& GetItems() { return aAttribSet; }
GetItems() const170 const SfxItemSet& GetItems() const { return aAttribSet; }
GetStyleSheet() const171 const SfxStyleSheet* GetStyleSheet() const { return pStyle; }
GetStyleSheet()172 SfxStyleSheet* GetStyleSheet() { return pStyle; }
173 void SetStyleSheet( SfxStyleSheet* pS );
174
175 const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
176 template<class T>
GetItem(TypedWhichId<T> nWhich) const177 const T& GetItem( TypedWhichId<T> nWhich ) const
178 {
179 return static_cast<const T&>(GetItem(sal_uInt16(nWhich)));
180 }
181 bool HasItem( sal_uInt16 nWhich ) const;
182 };
183
184
185 // class CharAttribList
186
187 class CharAttribList
188 {
189 public:
190 typedef std::vector<std::unique_ptr<EditCharAttrib> > AttribsType;
191
192 private:
193 AttribsType aAttribs;
194 SvxFont aDefFont; // faster than ever from the pool!
195 bool bHasEmptyAttribs;
196
197 public:
198 CharAttribList();
199 ~CharAttribList();
200
201 void dumpAsXml(xmlTextWriterPtr pWriter) const;
202
203 void DeleteEmptyAttribs( SfxItemPool& rItemPool );
204
205 const EditCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos ) const;
206 EditCharAttrib* FindAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
207 const EditCharAttrib* FindNextAttrib( sal_uInt16 nWhich, sal_Int32 nFromPos ) const;
208 EditCharAttrib* FindEmptyAttrib( sal_uInt16 nWhich, sal_Int32 nPos );
209 const EditCharAttrib* FindFeature( sal_Int32 nPos ) const;
210
211
212 void ResortAttribs();
213 void OptimizeRanges( SfxItemPool& rItemPool );
214
215 sal_Int32 Count() const;
216
217 void InsertAttrib( EditCharAttrib* pAttrib );
218
GetDefFont()219 SvxFont& GetDefFont() { return aDefFont; }
220
HasEmptyAttribs() const221 bool HasEmptyAttribs() const { return bHasEmptyAttribs; }
222 void SetHasEmptyAttribs(bool b);
223 bool HasBoundingAttrib( sal_Int32 nBound ) const;
224 bool HasAttrib( sal_Int32 nStartPos, sal_Int32 nEndPos ) const;
225
GetAttribs()226 AttribsType& GetAttribs() { return aAttribs;}
GetAttribs() const227 const AttribsType& GetAttribs() const { return aAttribs;}
228
229 void Remove(const EditCharAttrib* p);
230 void Remove(sal_Int32 nPos);
231
232 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
233 static void DbgCheckAttribs(CharAttribList const& rAttribs);
234 #endif
235 };
236
237
238 // class ContentNode
239
240 class ContentNode
241 {
242 private:
243 OUString maString;
244 ContentAttribs aContentAttribs;
245 CharAttribList aCharAttribList;
246 std::unique_ptr<WrongList> mpWrongList;
247
248 void UnExpandPosition( sal_Int32 &rStartPos, bool bBiasStart );
249
250 public:
251 ContentNode( SfxItemPool& rItemPool );
252 ContentNode( const OUString& rStr, const ContentAttribs& rContentAttribs );
253 ~ContentNode();
254 ContentNode(const ContentNode&) = delete;
255 ContentNode& operator=(const ContentNode&) = delete;
256
257 void dumpAsXml(xmlTextWriterPtr pWriter) const;
258
GetContentAttribs()259 ContentAttribs& GetContentAttribs() { return aContentAttribs; }
GetContentAttribs() const260 const ContentAttribs& GetContentAttribs() const { return aContentAttribs; }
GetCharAttribs()261 CharAttribList& GetCharAttribs() { return aCharAttribList; }
GetCharAttribs() const262 const CharAttribList& GetCharAttribs() const { return aCharAttribList; }
263
264 void ExpandAttribs( sal_Int32 nIndex, sal_Int32 nNewChars, SfxItemPool& rItemPool );
265 void CollapseAttribs( sal_Int32 nIndex, sal_Int32 nDelChars, SfxItemPool& rItemPool );
266 void AppendAttribs( ContentNode* pNextNode );
267 void CopyAndCutAttribs( ContentNode* pPrevNode, SfxItemPool& rPool, bool bKeepEndingAttribs );
268
269 void SetStyleSheet( SfxStyleSheet* pS, bool bRecalcFont = true );
270 void SetStyleSheet( SfxStyleSheet* pS, const SvxFont& rFontFromStyle );
GetStyleSheet()271 SfxStyleSheet* GetStyleSheet() { return aContentAttribs.GetStyleSheet(); }
272
273 void CreateDefFont();
274
275 void EnsureWrongList();
276 WrongList* GetWrongList();
277 const WrongList* GetWrongList() const;
278 void SetWrongList( WrongList* p );
279
280 void CreateWrongList();
281 void DestroyWrongList();
282
283 bool IsFeature( sal_Int32 nPos ) const;
284
285 sal_Int32 Len() const;
GetString() const286 const OUString& GetString() const { return maString;}
287
288 /// return length including expanded fields
289 sal_uLong GetExpandedLen() const;
290 /// return content including expanded fields
291 OUString GetExpandedText(sal_Int32 nStartPos = 0, sal_Int32 nEndPos = -1) const;
292 /// re-write offsets in the expanded text to string offsets
293 void UnExpandPositions( sal_Int32 &rStartPos, sal_Int32 &rEndPos );
294
295 void SetChar(sal_Int32 nPos, sal_Unicode c);
296 void Insert(const OUString& rStr, sal_Int32 nPos);
297 void Append(const OUString& rStr);
298 void Erase(sal_Int32 nPos);
299 void Erase(sal_Int32 nPos, sal_Int32 nCount);
300 OUString Copy(sal_Int32 nPos) const;
301 OUString Copy(sal_Int32 nPos, sal_Int32 nCount) const;
302 sal_Unicode GetChar(sal_Int32 nPos) const;
303 };
304
305
306 // class EditPaM
307
308 class EditPaM
309 {
310 private:
311 ContentNode* pNode;
312 sal_Int32 nIndex;
313
314 public:
315 EditPaM();
316 EditPaM(ContentNode* p, sal_Int32 n);
317
GetNode() const318 const ContentNode* GetNode() const { return pNode;}
GetNode()319 ContentNode* GetNode() { return pNode;}
320 void SetNode(ContentNode* p);
321
GetIndex() const322 sal_Int32 GetIndex() const { return nIndex; }
SetIndex(sal_Int32 n)323 void SetIndex( sal_Int32 n ) { nIndex = n; }
324
325 bool DbgIsBuggy( EditDoc const & rDoc ) const;
326
327 friend bool operator == ( const EditPaM& r1, const EditPaM& r2 );
328 friend bool operator != ( const EditPaM& r1, const EditPaM& r2 );
operator !() const329 bool operator !() const { return !pNode && !nIndex; }
330 };
331
332 enum class PortionKind
333 {
334 TEXT = 0,
335 TAB = 1,
336 LINEBREAK = 2,
337 FIELD = 3,
338 HYPHENATOR = 4
339 };
340
341 enum class DeleteMode {
342 Simple, RestOfWord, RestOfContent
343 };
344
345 enum class AsianCompressionFlags {
346 Normal = 0x00,
347 Kana = 0x01,
348 PunctuationLeft = 0x02,
349 PunctuationRight = 0x04,
350 };
351 namespace o3tl {
352 template<> struct typed_flags<AsianCompressionFlags> : is_typed_flags<AsianCompressionFlags, 0x07> {};
353 }
354
355
356
357 // struct ExtraPortionInfos
358
359 struct ExtraPortionInfo
360 {
361 long nOrgWidth;
362 long nWidthFullCompression;
363
364 long nPortionOffsetX;
365
366 sal_uInt16 nMaxCompression100thPercent;
367
368 AsianCompressionFlags nAsianCompressionTypes;
369 bool bFirstCharIsRightPunktuation;
370 bool bCompressed;
371
372 std::unique_ptr<long[]> pOrgDXArray;
373 std::vector< sal_Int32 > lineBreaksList;
374
375
376 ExtraPortionInfo();
377 ~ExtraPortionInfo();
378
379 void SaveOrgDXArray( const long* pDXArray, sal_Int32 nLen );
380 };
381
382
383 // class TextPortion
384
385 class TextPortion
386 {
387 private:
388 std::unique_ptr<ExtraPortionInfo> xExtraInfos;
389 sal_Int32 nLen;
390 Size aOutSz;
391 PortionKind nKind;
392 sal_uInt8 nRightToLeftLevel;
393 sal_Unicode nExtraValue;
394
395
396 public:
TextPortion(sal_Int32 nL)397 TextPortion( sal_Int32 nL )
398 : nLen( nL )
399 , aOutSz( -1, -1 )
400 , nKind( PortionKind::TEXT )
401 , nRightToLeftLevel( 0 )
402 , nExtraValue( 0 )
403 {
404 }
405
TextPortion(const TextPortion & r)406 TextPortion( const TextPortion& r )
407 : nLen( r.nLen )
408 , aOutSz( r.aOutSz )
409 , nKind( r.nKind )
410 , nRightToLeftLevel( r.nRightToLeftLevel )
411 , nExtraValue( r.nExtraValue )
412 {
413 }
414
415
GetLen() const416 sal_Int32 GetLen() const { return nLen; }
SetLen(sal_Int32 nL)417 void SetLen( sal_Int32 nL ) { nLen = nL; }
418
GetSize()419 Size& GetSize() { return aOutSz; }
GetSize() const420 const Size& GetSize() const { return aOutSz; }
421
SetKind(PortionKind n)422 void SetKind(PortionKind n) { nKind = n; }
GetKind() const423 PortionKind GetKind() const { return nKind; }
424
SetRightToLeftLevel(sal_uInt8 n)425 void SetRightToLeftLevel( sal_uInt8 n ) { nRightToLeftLevel = n; }
GetRightToLeftLevel() const426 sal_uInt8 GetRightToLeftLevel() const { return nRightToLeftLevel; }
IsRightToLeft() const427 bool IsRightToLeft() const { return (nRightToLeftLevel&1); }
428
GetExtraValue() const429 sal_Unicode GetExtraValue() const { return nExtraValue; }
SetExtraValue(sal_Unicode n)430 void SetExtraValue( sal_Unicode n ) { nExtraValue = n; }
431
GetExtraInfos() const432 ExtraPortionInfo* GetExtraInfos() const { return xExtraInfos.get(); }
SetExtraInfos(ExtraPortionInfo * p)433 void SetExtraInfos( ExtraPortionInfo* p ) { xExtraInfos.reset(p); }
434 };
435
436
437 // class TextPortionList
438
439 class TextPortionList
440 {
441 typedef std::vector<std::unique_ptr<TextPortion> > PortionsType;
442 PortionsType maPortions;
443
444 public:
445 TextPortionList();
446 ~TextPortionList();
447
448 void Reset();
449 sal_Int32 FindPortion(
450 sal_Int32 nCharPos, sal_Int32& rPortionStart, bool bPreferStartingPortion = false) const;
451 sal_Int32 GetStartPos(sal_Int32 nPortion);
452 void DeleteFromPortion(sal_Int32 nDelFrom);
453 sal_Int32 Count() const;
454 const TextPortion& operator[](sal_Int32 nPos) const;
455 TextPortion& operator[](sal_Int32 nPos);
456
457 void Append(TextPortion* p);
458 void Insert(sal_Int32 nPos, TextPortion* p);
459 void Remove(sal_Int32 nPos);
460 sal_Int32 GetPos(const TextPortion* p) const;
461 };
462
463 class ParaPortion;
464
465
466 // class EditLine
467
468 class EditLine
469 {
470 public:
471 typedef std::vector<long> CharPosArrayType;
472
473 private:
474 CharPosArrayType aPositions;
475 long nTxtWidth;
476 long nStartPosX;
477 sal_Int32 nStart; // could be replaced by nStartPortion
478 sal_Int32 nEnd; // could be replaced by nEndPortion
479 sal_Int32 nStartPortion;
480 sal_Int32 nEndPortion;
481 sal_uInt16 nHeight; // Total height of the line
482 sal_uInt16 nTxtHeight; // Pure Text height
483 sal_uInt16 nMaxAscent;
484 bool bHangingPunctuation:1;
485 bool bInvalid:1; // for skillful formatting
486
487 public:
488 EditLine();
489 EditLine( const EditLine& );
490 ~EditLine();
491
IsIn(sal_Int32 nIndex) const492 bool IsIn( sal_Int32 nIndex ) const
493 { return ( (nIndex >= nStart ) && ( nIndex < nEnd ) ); }
494
IsIn(sal_Int32 nIndex,bool bInclEnd) const495 bool IsIn( sal_Int32 nIndex, bool bInclEnd ) const
496 { return ( ( nIndex >= nStart ) && ( bInclEnd ? ( nIndex <= nEnd ) : ( nIndex < nEnd ) ) ); }
497
SetStart(sal_Int32 n)498 void SetStart( sal_Int32 n ) { nStart = n; }
GetStart() const499 sal_Int32 GetStart() const { return nStart; }
GetStart()500 sal_Int32& GetStart() { return nStart; }
501
SetEnd(sal_Int32 n)502 void SetEnd( sal_Int32 n ) { nEnd = n; }
GetEnd() const503 sal_Int32 GetEnd() const { return nEnd; }
GetEnd()504 sal_Int32& GetEnd() { return nEnd; }
505
SetStartPortion(sal_Int32 n)506 void SetStartPortion( sal_Int32 n ) { nStartPortion = n; }
GetStartPortion() const507 sal_Int32 GetStartPortion() const { return nStartPortion; }
GetStartPortion()508 sal_Int32& GetStartPortion() { return nStartPortion; }
509
SetEndPortion(sal_Int32 n)510 void SetEndPortion( sal_Int32 n ) { nEndPortion = n; }
GetEndPortion() const511 sal_Int32 GetEndPortion() const { return nEndPortion; }
GetEndPortion()512 sal_Int32& GetEndPortion() { return nEndPortion; }
513
514 void SetHeight( sal_uInt16 nH, sal_uInt16 nTxtH = 0 );
GetHeight() const515 sal_uInt16 GetHeight() const { return nHeight; }
GetTxtHeight() const516 sal_uInt16 GetTxtHeight() const { return nTxtHeight; }
517
SetTextWidth(long n)518 void SetTextWidth( long n ) { nTxtWidth = n; }
GetTextWidth() const519 long GetTextWidth() const { return nTxtWidth; }
520
SetMaxAscent(sal_uInt16 n)521 void SetMaxAscent( sal_uInt16 n ) { nMaxAscent = n; }
GetMaxAscent() const522 sal_uInt16 GetMaxAscent() const { return nMaxAscent; }
523
SetHangingPunctuation(bool b)524 void SetHangingPunctuation( bool b ) { bHangingPunctuation = b; }
IsHangingPunctuation() const525 bool IsHangingPunctuation() const { return bHangingPunctuation; }
526
GetLen() const527 sal_Int32 GetLen() const { return nEnd - nStart; }
528
GetStartPosX() const529 long GetStartPosX() const { return nStartPosX; }
530 void SetStartPosX( long start );
531 Size CalcTextSize( ParaPortion& rParaPortion );
532
IsInvalid() const533 bool IsInvalid() const { return bInvalid; }
IsValid() const534 bool IsValid() const { return !bInvalid; }
SetInvalid()535 void SetInvalid() { bInvalid = true; }
SetValid()536 void SetValid() { bInvalid = false; }
537
IsEmpty() const538 bool IsEmpty() const { return nEnd <= nStart; }
539
GetCharPosArray()540 CharPosArrayType& GetCharPosArray() { return aPositions;}
GetCharPosArray() const541 const CharPosArrayType& GetCharPosArray() const { return aPositions;}
542
543 EditLine* Clone() const;
544
545 EditLine& operator = ( const EditLine& rLine );
546 friend bool operator == ( const EditLine& r1, const EditLine& r2 );
547 };
548
549
550 // class LineList
551
552 class EditLineList
553 {
554 typedef std::vector<std::unique_ptr<EditLine> > LinesType;
555 LinesType maLines;
556
557 public:
558 EditLineList();
559 ~EditLineList();
560
561 void Reset();
562 void DeleteFromLine(sal_Int32 nDelFrom);
563 sal_Int32 FindLine(sal_Int32 nChar, bool bInclEnd);
564 sal_Int32 Count() const;
565 const EditLine& operator[](sal_Int32 nPos) const;
566 EditLine& operator[](sal_Int32 nPos);
567
568 void Append(EditLine* p);
569 void Insert(sal_Int32 nPos, EditLine* p);
570 };
571
572
573 // class ParaPortion
574
575 class ParaPortion
576 {
577 friend class ImpEditEngine; // to adjust the height
578 private:
579 EditLineList aLineList;
580 TextPortionList aTextPortionList;
581 ContentNode* pNode;
582 long nHeight;
583
584 ScriptTypePosInfos aScriptInfos;
585 WritingDirectionInfos aWritingDirectionInfos;
586
587 sal_Int32 nInvalidPosStart;
588 sal_Int32 nFirstLineOffset; // For Writer-LineSpacing-Interpretation
589 sal_Int32 nBulletX;
590 sal_Int32 nInvalidDiff;
591
592 bool bInvalid : 1;
593 bool bSimple : 1; // only linear Tap
594 bool bVisible : 1; // Belongs to the node!
595 bool bForceRepaint : 1;
596
597 ParaPortion( const ParaPortion& ) = delete;
598
599 public:
600 ParaPortion( ContentNode* pNode );
601 ~ParaPortion();
602
603 sal_Int32 GetLineNumber( sal_Int32 nIndex ) const;
604
GetLines()605 EditLineList& GetLines() { return aLineList; }
GetLines() const606 const EditLineList& GetLines() const { return aLineList; }
607
IsInvalid() const608 bool IsInvalid() const { return bInvalid; }
IsSimpleInvalid() const609 bool IsSimpleInvalid() const { return bSimple; }
SetValid()610 void SetValid() { bInvalid = false; bSimple = true;}
611
MustRepaint() const612 bool MustRepaint() const { return bForceRepaint; }
SetMustRepaint(bool bRP)613 void SetMustRepaint( bool bRP ) { bForceRepaint = bRP; }
614
GetBulletX() const615 sal_Int32 GetBulletX() const { return nBulletX; }
SetBulletX(sal_Int32 n)616 void SetBulletX( sal_Int32 n ) { nBulletX = n; }
617
618 void MarkInvalid( sal_Int32 nStart, sal_Int32 nDiff);
619 void MarkSelectionInvalid( sal_Int32 nStart );
620
621 void SetVisible( bool bVisible );
IsVisible() const622 bool IsVisible() const { return bVisible; }
623
IsEmpty()624 bool IsEmpty() { return GetTextPortions().Count() == 1 && GetTextPortions()[0].GetLen() == 0; }
625
GetHeight() const626 long GetHeight() const { return ( bVisible ? nHeight : 0 ); }
GetFirstLineOffset() const627 sal_Int32 GetFirstLineOffset() const { return ( bVisible ? nFirstLineOffset : 0 ); }
ResetHeight()628 void ResetHeight() { nHeight = 0; nFirstLineOffset = 0; }
629
GetNode() const630 ContentNode* GetNode() const { return pNode; }
GetTextPortions()631 TextPortionList& GetTextPortions() { return aTextPortionList; }
GetTextPortions() const632 const TextPortionList& GetTextPortions() const { return aTextPortionList; }
633
GetInvalidPosStart() const634 sal_Int32 GetInvalidPosStart() const { return nInvalidPosStart; }
GetInvalidDiff() const635 short GetInvalidDiff() const { return nInvalidDiff; }
636
637 void CorrectValuesBehindLastFormattedLine( sal_Int32 nLastFormattedLine );
638 #if OSL_DEBUG_LEVEL > 0
639 static bool DbgCheckTextPortions(ParaPortion const&);
640 #endif
641 };
642
643
644 // class ParaPortionList
645
646 class ParaPortionList
647 {
648 mutable sal_Int32 nLastCache;
649 std::vector<std::unique_ptr<ParaPortion>> maPortions;
650 public:
651 ParaPortionList();
652 ~ParaPortionList();
653
654 void Reset();
655 long GetYOffset(const ParaPortion* pPPortion) const;
656 sal_Int32 FindParagraph(long nYOffset) const;
657
658 const ParaPortion* SafeGetObject(sal_Int32 nPos) const;
659 ParaPortion* SafeGetObject(sal_Int32 nPos);
660
661 sal_Int32 GetPos(const ParaPortion* p) const;
662 ParaPortion* operator[](sal_Int32 nPos);
663 const ParaPortion* operator[](sal_Int32 nPos) const;
664
665 std::unique_ptr<ParaPortion> Release(sal_Int32 nPos);
666 void Remove(sal_Int32 nPos);
667 void Insert(sal_Int32 nPos, std::unique_ptr<ParaPortion> p);
668 void Append(std::unique_ptr<ParaPortion> p);
669 sal_Int32 Count() const;
670
671 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
672 // temporary:
673 static void DbgCheck(ParaPortionList const&, EditDoc const& rDoc);
674 #endif
675 };
676
677
678 // class EditSelection
679
680 class EditSelection
681 {
682 private:
683 EditPaM aStartPaM;
684 EditPaM aEndPaM;
685
686 public:
687 EditSelection(); // No constructor and destructor
688 // are automatically executed correctly!
689 EditSelection( const EditPaM& rStartAndAnd );
690 EditSelection( const EditPaM& rStart, const EditPaM& rEnd );
691
Min()692 EditPaM& Min() { return aStartPaM; }
Max()693 EditPaM& Max() { return aEndPaM; }
694
Min() const695 const EditPaM& Min() const { return aStartPaM; }
Max() const696 const EditPaM& Max() const { return aEndPaM; }
697
HasRange() const698 bool HasRange() const { return aStartPaM != aEndPaM; }
IsInvalid() const699 bool IsInvalid() const { return !aStartPaM || !aEndPaM; }
700 bool DbgIsBuggy( EditDoc const & rDoc ) const;
701
702 void Adjust( const EditDoc& rNodes );
703
704 EditSelection& operator = ( const EditPaM& r );
operator ==(const EditSelection & r) const705 bool operator == ( const EditSelection& r ) const
706 { return ( aStartPaM == r.aStartPaM ) && ( aEndPaM == r.aEndPaM ); }
operator !=(const EditSelection & r) const707 bool operator != ( const EditSelection& r ) const { return !( r == *this ); }
708 };
709
710
711 // class DeletedNodeInfo
712
713 class DeletedNodeInfo
714 {
715 private:
716 ContentNode* mpInvalidNode;
717 sal_Int32 nInvalidParagraph;
718
719 public:
DeletedNodeInfo(ContentNode * pNode,sal_Int32 nPos)720 DeletedNodeInfo( ContentNode* pNode, sal_Int32 nPos )
721 : mpInvalidNode(pNode)
722 , nInvalidParagraph(nPos)
723 {
724 }
725
GetNode() const726 ContentNode* GetNode() const { return mpInvalidNode; }
GetPosition() const727 sal_Int32 GetPosition() const { return nInvalidParagraph; }
728 };
729
730
731 // class EditDoc
732
733 class EditDoc
734 {
735 private:
736 mutable sal_Int32 nLastCache;
737 std::vector<std::unique_ptr<ContentNode> > maContents;
738
739 SfxItemPool* pItemPool;
740 Link<LinkParamNone*,void> aModifyHdl;
741
742 SvxFont aDefFont; //faster than ever from the pool!!
743 sal_uInt16 nDefTab;
744 bool bIsVertical:1;
745 bool bIsTopToBottomVert : 1;
746 bool bIsFixedCellHeight:1;
747
748 bool bOwnerOfPool:1;
749 bool bModified:1;
750 bool bDisableAttributeExpanding:1;
751
752 private:
753 void ImplDestroyContents();
754
755 public:
756 EditDoc( SfxItemPool* pItemPool );
757 ~EditDoc();
758
759 void dumpAsXml(xmlTextWriterPtr pWriter) const;
760 void ClearSpellErrors();
761
IsModified() const762 bool IsModified() const { return bModified; }
763 void SetModified( bool b );
764
DisableAttributeExpanding()765 void DisableAttributeExpanding() { bDisableAttributeExpanding = true; }
766
SetModifyHdl(const Link<LinkParamNone *,void> & rLink)767 void SetModifyHdl( const Link<LinkParamNone*,void>& rLink ) { aModifyHdl = rLink; }
768
769 void CreateDefFont( bool bUseStyles );
GetDefFont() const770 const SvxFont& GetDefFont() const { return aDefFont; }
771
SetDefTab(sal_uInt16 nTab)772 void SetDefTab( sal_uInt16 nTab ) { nDefTab = nTab ? nTab : DEFTAB; }
GetDefTab() const773 sal_uInt16 GetDefTab() const { return nDefTab; }
774
SetVertical(bool bVertical,bool bTopToBottom)775 void SetVertical( bool bVertical, bool bTopToBottom )
776 { bIsVertical = bVertical; bIsTopToBottomVert = bVertical && bTopToBottom; }
IsVertical() const777 bool IsVertical() const { return bIsVertical; }
IsTopToBottom() const778 bool IsTopToBottom() const { return bIsTopToBottomVert; }
779
SetFixedCellHeight(bool bUseFixedCellHeight)780 void SetFixedCellHeight( bool bUseFixedCellHeight ) { bIsFixedCellHeight = bUseFixedCellHeight; }
IsFixedCellHeight() const781 bool IsFixedCellHeight() const { return bIsFixedCellHeight; }
782
783 EditPaM Clear();
784 EditPaM RemoveText();
785 void RemoveChars( EditPaM aPaM, sal_Int32 nChars );
786 EditPaM InsertText( EditPaM aPaM, const OUString& rStr );
787 EditPaM InsertParaBreak( EditPaM aPaM, bool bKeepEndingAttribs );
788 EditPaM InsertFeature( EditPaM aPaM, const SfxPoolItem& rItem );
789 EditPaM ConnectParagraphs( ContentNode* pLeft, ContentNode* pRight );
790
791 OUString GetText( LineEnd eEnd ) const;
792 sal_uLong GetTextLen() const;
793
794 OUString GetParaAsString( sal_Int32 nNode ) const;
795 static OUString GetParaAsString(const ContentNode* pNode, sal_Int32 nStartPos = 0, sal_Int32 nEndPos = -1);
796
797 EditPaM GetStartPaM() const;
798 EditPaM GetEndPaM() const;
799
GetItemPool()800 SfxItemPool& GetItemPool() { return *pItemPool; }
GetItemPool() const801 const SfxItemPool& GetItemPool() const { return *pItemPool; }
802
803 void RemoveItemsFromPool(const ContentNode& rNode);
804
805 void InsertAttrib( const SfxPoolItem& rItem, ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd );
806 void InsertAttrib( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem );
807 void InsertAttribInSelection( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, const SfxPoolItem& rPoolItem );
808 bool RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, sal_uInt16 nWhich );
809 bool RemoveAttribs( ContentNode* pNode, sal_Int32 nStart, sal_Int32 nEnd, EditCharAttrib*& rpStarting, EditCharAttrib*& rpEnding, sal_uInt16 nWhich );
810 static void FindAttribs( ContentNode* pNode, sal_Int32 nStartPos, sal_Int32 nEndPos, SfxItemSet& rCurSet );
811
812 sal_Int32 GetPos(const ContentNode* pNode) const;
813 const ContentNode* GetObject(sal_Int32 nPos) const;
814 ContentNode* GetObject(sal_Int32 nPos);
815 sal_Int32 Count() const;
816 const ContentNode* operator[](sal_Int32 nPos) const;
817 ContentNode* operator[](sal_Int32 nPos);
818 void Insert(sal_Int32 nPos, ContentNode* p);
819 /// deletes
820 void Remove(sal_Int32 nPos);
821 /// does not delete
822 void Release(sal_Int32 nPos);
823
824 static OUString GetSepStr( LineEnd eEnd );
825 };
826
GetAttrib(CharAttribList::AttribsType & rAttribs,sal_Int32 nAttr)827 inline EditCharAttrib* GetAttrib(CharAttribList::AttribsType& rAttribs, sal_Int32 nAttr)
828 {
829 return (nAttr < static_cast<sal_Int32>(rAttribs.size())) ? rAttribs[nAttr].get() : nullptr;
830 }
831
832 #if OSL_DEBUG_LEVEL > 0 && !defined NDEBUG
833 void CheckOrderedList(const CharAttribList::AttribsType& rAttribs);
834 #endif
835
836 class EditEngineItemPool : public SfxItemPool
837 {
838 private:
839 std::shared_ptr<DefItems> m_xDefItems;
840 public:
841 EditEngineItemPool();
842 protected:
843 virtual ~EditEngineItemPool() override;
844 };
845
846 #endif
847
848 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
849