LibreOffice Module sw (master)  1
ndhints.hxx
Go to the documentation of this file.
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 #ifndef INCLUDED_SW_INC_NDHINTS_HXX
20 #define INCLUDED_SW_INC_NDHINTS_HXX
21 
22 #include "swtypes.hxx"
23 
24 class SwTextNode;
25 class SwRegHistory; // Is in RolBck.hxx.
26 class SwTextAttr;
27 class SwTextAttrNesting;
28 
29 class SfxPoolItem;
30 class SfxItemSet;
31 class SwDoc;
32 
33 enum class CopyOrNewType { Copy, New };
34 
37  SwDoc & rDoc,
38  SfxPoolItem & rNew,
39  sal_Int32 const nStt,
40  sal_Int32 const nEnd,
41  CopyOrNewType const bIsCopy = CopyOrNewType::New,
42  SwTextNode *const pTextNode = nullptr );
43 
45  SwDoc & rDoc,
46  const SfxItemSet & rSet,
47  sal_Int32 nStt,
48  sal_Int32 nEnd );
49 
52  SwDoc & rDoc,
53  SfxPoolItem const & rAttr );
54 
56 {
57  bool operator()( sal_Int32 nEndPos, const SwTextAttr* rhs ) const;
58  bool operator()( const SwTextAttr* lhs, const SwTextAttr* rhs ) const;
59 };
61 {
62  bool operator()( const SwTextAttr* lhs, const sal_uInt16 nWhich ) const;
63  bool operator()( const SwTextAttr* lhs, const SwTextAttr* rhs ) const;
64 };
65 
67 class SwpHints
68 {
69 private:
71 
72  // SAL_MAX_SIZE is used by GetStartOf to return
73  // failure, so just allow SAL_MAX_SIZE-1 hints
74  static const size_t MAX_HINTS = SAL_MAX_SIZE-1;
75 
76  std::vector<SwTextAttr*> m_HintsByStart;
77  std::vector<SwTextAttr*> m_HintsByEnd;
78  std::vector<SwTextAttr*> m_HintsByWhichAndStart;
79 
81 
83  bool m_bInSplitNode : 1;
84  // m_bHiddenByParaField is invalid, call CalcHiddenParaField()
85  mutable bool m_bCalcHiddenParaField : 1;
86  // if all fields controlling visibility of the paragraph require to hide it
87  // (if there's no such fields, or if any field requires to show, then this is false)
88  mutable bool m_bHiddenByParaField : 1;
89  bool m_bFootnote : 1;
90  bool m_bDDEFields : 1;
91  // Sort on demand to avoid O(n^2) behaviour
92  mutable bool m_bStartMapNeedsSorting : 1;
93  mutable bool m_bEndMapNeedsSorting : 1;
94  mutable bool m_bWhichMapNeedsSorting : 1;
95 
97  void NoteInHistory( SwTextAttr *pAttr, const bool bNew = false );
98 
99  void CalcFlags( );
100 
104  friend class SwTextNode;
105  void DeleteAtPos( size_t nPos );
107  void Delete( SwTextAttr const * pTextHt );
108 
109  void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
111  void SetHiddenByParaField( const bool bNew ) const { m_bHiddenByParaField = bNew; }
112  bool IsHiddenByParaField() const
113  {
115  {
117  }
118  return m_bHiddenByParaField;
119  }
120 
121  void InsertNesting(SwTextAttrNesting & rNewHint);
122  bool TryInsertNesting(SwTextNode & rNode, SwTextAttrNesting & rNewHint);
123  void BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint,
124  const SetAttrMode nMode );
125  bool MergePortions( SwTextNode& rNode );
126 
127  void Insert( const SwTextAttr *pHt );
128  SW_DLLPUBLIC void Resort() const;
129  SW_DLLPUBLIC void ResortStartMap() const;
130  SW_DLLPUBLIC void ResortEndMap() const;
131  SW_DLLPUBLIC void ResortWhichMap() const;
132 
133  size_t GetIndexOf( const SwTextAttr *pHt ) const;
134 
135 #ifdef DBG_UTIL
136  bool Check(bool) const;
137 #endif
138 
139 public:
140  SwpHints(const SwTextNode& rParent);
141 
142  size_t Count() const { return m_HintsByStart.size(); }
143  bool Contains( const SwTextAttr *pHt ) const;
144  SwTextAttr * Get( size_t nPos ) const
145  {
146  assert( !(nPos != 0 && m_bStartMapNeedsSorting) && "going to trigger a resort in the middle of an iteration, that's bad" );
148  ResortStartMap();
149  return m_HintsByStart[nPos];
150  }
151  // Get without triggering resorting - useful if we are modifying start/end pos while iterating
152  SwTextAttr * GetWithoutResorting( size_t nPos ) const
153  {
154  return m_HintsByStart[nPos];
155  }
156 
157  int GetLastPosSortedByEnd(sal_Int32 nEndPos) const;
158  SwTextAttr * GetSortedByEnd( size_t nPos ) const
159  {
160  assert( !(nPos != 0 && m_bEndMapNeedsSorting) && "going to trigger a resort in the middle of an iteration, that's bad" );
162  ResortEndMap();
163  return m_HintsByEnd[nPos];
164  }
165 
166  size_t GetFirstPosSortedByWhichAndStart(sal_uInt16 nWhich) const;
167  SwTextAttr * GetSortedByWhichAndStart( size_t nPos ) const
168  {
169  assert( !(nPos != 0 && m_bWhichMapNeedsSorting) && "going to trigger a resort in the middle of an iteration, that's bad" );
171  ResortWhichMap();
172  return m_HintsByWhichAndStart[nPos];
173  }
174 
176  void SortIfNeedBe() const
177  {
179  ResortStartMap();
181  ResortEndMap();
183  ResortWhichMap();
184  }
185  SwTextAttr * Cut( const size_t nPosInStart )
186  {
187  SwTextAttr *pHt = m_HintsByStart[nPosInStart];
188  DeleteAtPos( nPosInStart );
189  return pHt;
190  }
191 
192  bool CanBeDeleted() const { return m_HintsByStart.empty(); }
193 
195  void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
197  void DeRegister() { Register(nullptr); }
198  SwRegHistory* GetHistory() const { return m_pHistory; }
199 
202  bool TryInsertHint( SwTextAttr * const pHint, SwTextNode & rNode,
203  const SetAttrMode nMode = SetAttrMode::DEFAULT );
204 
205  bool HasFootnote() const { return m_bFootnote; }
206  bool IsInSplitNode() const { return m_bInSplitNode; }
207 
208  // calc current value of m_bHiddenByParaField, returns true iff changed
209  bool CalcHiddenParaField() const; // changes mutable state
210 
211  // Marks the hint-maps as needing sorting because the position of something has changed
214 };
215 
216 #endif
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void BuildPortions(SwTextNode &rNode, SwTextAttr &rNewHint, const SetAttrMode nMode)
Definition: thints.cxx:588
void DeleteAtPos(size_t nPos)
Definition: thints.cxx:3281
bool operator()(const SwTextAttr *lhs, const sal_uInt16 nWhich) const
sort order: Which, Start, End(reverse) at last the pointer
Definition: ndhints.cxx:70
std::vector< SwTextAttr * > m_HintsByEnd
Definition: ndhints.hxx:77
SW_DLLPUBLIC void Resort() const
Definition: ndhints.cxx:414
bool TryInsertNesting(SwTextNode &rNode, SwTextAttrNesting &rNewHint)
The following hints correspond to well-formed XML elements in ODF: RES_TXTATR_INETFMT, RES_TXTATR_CJK_RUBY, RES_TXTATR_META, RES_TXTATR_METAFIELD.
Definition: thints.cxx:359
size_t GetIndexOf(const SwTextAttr *pHt) const
Definition: ndhints.cxx:466
bool m_bFootnote
footnotes
Definition: ndhints.hxx:89
SwTextAttr * MakeTextAttr(SwDoc &rDoc, SfxPoolItem &rNew, sal_Int32 const nStt, sal_Int32 const nEnd, CopyOrNewType const bIsCopy=CopyOrNewType::New, SwTextNode *const pTextNode=nullptr)
if COPY then pTextNode must be given!
Definition: thints.cxx:984
bool CanBeDeleted() const
Definition: ndhints.hxx:192
Definition: doc.hxx:185
SW_DLLPUBLIC void ResortWhichMap() const
Definition: ndhints.cxx:441
SwTextAttr * GetSortedByEnd(size_t nPos) const
Definition: ndhints.hxx:158
void SetCalcHiddenParaField() const
Definition: ndhints.hxx:110
bool TryInsertHint(SwTextAttr *const pHint, SwTextNode &rNode, const SetAttrMode nMode=SetAttrMode::DEFAULT)
try to insert the hint
Definition: thints.cxx:2949
void NoteInHistory(SwTextAttr *pAttr, const bool bNew=false)
records a new attribute in m_pHistory.
Definition: thints.cxx:2636
void SortIfNeedBe() const
Trigger the sorting if necessary.
Definition: ndhints.hxx:176
SwpHints(const SwTextNode &rParent)
Definition: thints.cxx:95
const SwTextNode & m_rParent
Definition: ndhints.hxx:70
SwRegHistory * m_pHistory
for Undo
Definition: ndhints.hxx:80
CopyOrNewType
Definition: ndhints.hxx:33
void Insert(const SwTextAttr *pHt)
Definition: ndhints.cxx:147
bool operator()(sal_Int32 nEndPos, const SwTextAttr *rhs) const
sort order: End, Start(reverse), Which (char style: sort number), at last the pointer(reverse) ...
Definition: ndhints.cxx:108
size_t Count() const
Definition: ndhints.hxx:142
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:197
bool IsInSplitNode() const
Definition: ndhints.hxx:206
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
bool MergePortions(SwTextNode &rNode)
Definition: thints.cxx:2641
bool m_bHiddenByParaField
Definition: ndhints.hxx:88
bool m_bCalcHiddenParaField
Definition: ndhints.hxx:85
void Delete(SwTextAttr const *pTextHt)
Delete the given Hint. The Hint must actually be in the array!
Definition: thints.cxx:3341
SetAttrMode
Definition: swtypes.hxx:143
SW_DLLPUBLIC void ResortEndMap() const
Definition: ndhints.cxx:434
size_t GetFirstPosSortedByWhichAndStart(sal_uInt16 nWhich) const
Definition: ndhints.cxx:448
SW_DLLPUBLIC void ResortStartMap() const
Definition: ndhints.cxx:427
int GetLastPosSortedByEnd(sal_Int32 nEndPos) const
Definition: ndhints.cxx:458
void Register(SwRegHistory *pHist)
register a History, which receives all attribute changes (for Undo)
Definition: ndhints.hxx:195
std::vector< SwTextAttr * > m_HintsByStart
Definition: ndhints.hxx:76
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
void StartPosChanged() const
Definition: ndhints.hxx:212
void SetInSplitNode(bool bInSplit)
Definition: ndhints.hxx:109
bool m_bEndMapNeedsSorting
Definition: ndhints.hxx:93
bool IsHiddenByParaField() const
Definition: ndhints.hxx:112
bool m_bStartMapNeedsSorting
Definition: ndhints.hxx:92
SwRegHistory * GetHistory() const
Definition: ndhints.hxx:198
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void SetHiddenByParaField(const bool bNew) const
Definition: ndhints.hxx:111
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:67
void EndPosChanged() const
Definition: ndhints.hxx:213
SwTextAttr * GetSortedByWhichAndStart(size_t nPos) const
Definition: ndhints.hxx:167
void InsertNesting(SwTextAttrNesting &rNewHint)
Insert nesting hint into the hints array.
Definition: thints.cxx:285
bool m_bInSplitNode
true: the Node is in Split and Frames are moved
Definition: ndhints.hxx:83
SwTextAttr * MakeRedlineTextAttr(SwDoc &rDoc, SfxPoolItem const &rAttr)
create redline dummy text hint that must not be inserted into hints array
Definition: thints.cxx:954
static const size_t MAX_HINTS
Definition: ndhints.hxx:74
bool Check(bool) const
Definition: ndhints.cxx:190
bool CalcHiddenParaField() const
Definition: thints.cxx:2599
bool HasFootnote() const
Definition: ndhints.hxx:205
void CalcFlags()
Definition: thints.cxx:2570
bool m_bDDEFields
the TextNode has DDE fields
Definition: ndhints.hxx:90
std::vector< SwTextAttr * > m_HintsByWhichAndStart
Definition: ndhints.hxx:78
SwTextAttr * GetWithoutResorting(size_t nPos) const
Definition: ndhints.hxx:152
SwTextAttr * Cut(const size_t nPosInStart)
Definition: ndhints.hxx:185
bool Contains(const SwTextAttr *pHt) const
Definition: ndhints.cxx:171
bool m_bWhichMapNeedsSorting
Definition: ndhints.hxx:94