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 <o3tl/sorted_vector.hxx>
23 
24 #include "swtypes.hxx"
25 
26 class SwTextNode;
27 class SwRegHistory; // Is in RolBck.hxx.
28 class SwTextAttr;
29 class SwTextAttrNesting;
30 
31 class SfxPoolItem;
32 class SfxItemSet;
33 class SwDoc;
34 
35 enum class CopyOrNewType { Copy, New };
36 
39  SwDoc & rDoc,
40  SfxPoolItem & rNew,
41  sal_Int32 const nStt,
42  sal_Int32 const nEnd,
43  CopyOrNewType const bIsCopy = CopyOrNewType::New,
44  SwTextNode *const pTextNode = nullptr );
45 
47  SwDoc & rDoc,
48  const SfxItemSet & rSet,
49  sal_Int32 nStt,
50  sal_Int32 nEnd );
51 
54  SwDoc & rDoc,
55  SfxPoolItem const & rAttr );
56 
57 
60 {
61  bool operator()(SwTextAttr const * const lhs, SwTextAttr const * const rhs) const;
62 };
63 class SwpHtStart : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtStart,
64  o3tl::find_partialorder_ptrequals> {};
65 
68 {
69  bool operator()(SwTextAttr const * const lhs, SwTextAttr const * const rhs) const;
70 };
71 class SwpHtEnd : public o3tl::sorted_vector<SwTextAttr*, CompareSwpHtEnd,
72  o3tl::find_partialorder_ptrequals> {};
73 
74 
76 class SwpHints
77 {
78 private:
80 
81  // SAL_MAX_SIZE is used by GetStartOf to return
82  // failure, so just allow SAL_MAX_SIZE-1 hints
83  static const size_t MAX_HINTS = SAL_MAX_SIZE-1;
84 
87 
89 
91  bool m_bInSplitNode : 1;
92  // m_bHiddenByParaField is invalid, call CalcHiddenParaField()
93  mutable bool m_bCalcHiddenParaField : 1;
94  // if all fields controlling visibility of the paragraph require to hide it
95  // (if there's no such fields, or if any field requires to show, then this is false)
96  mutable bool m_bHiddenByParaField : 1;
97  bool m_bFootnote : 1;
98  bool m_bDDEFields : 1;
99 
101  void NoteInHistory( SwTextAttr *pAttr, const bool bNew = false );
102 
103  void CalcFlags( );
104 
108  friend class SwTextNode;
109  void DeleteAtPos( size_t nPos );
111  void Delete( SwTextAttr const * pTextHt );
112 
113  void SetInSplitNode(bool bInSplit) { m_bInSplitNode = bInSplit; }
115  void SetHiddenByParaField( const bool bNew ) const { m_bHiddenByParaField = bNew; }
116  bool IsHiddenByParaField() const
117  {
119  {
121  }
122  return m_bHiddenByParaField;
123  }
124 
125  void InsertNesting(SwTextAttrNesting & rNewHint);
126  bool TryInsertNesting(SwTextNode & rNode, SwTextAttrNesting & rNewHint);
127  void BuildPortions( SwTextNode& rNode, SwTextAttr& rNewHint,
128  const SetAttrMode nMode );
129  bool MergePortions( SwTextNode& rNode );
130 
131  void Insert( const SwTextAttr *pHt );
132  void Resort();
133 
134  size_t GetIndexOf( const SwTextAttr *pHt ) const
135  {
136  SwpHtStart::const_iterator const it =
137  m_HintsByStart.find(const_cast<SwTextAttr*>(pHt));
138  if ( it == m_HintsByStart.end() )
139  {
140  return SAL_MAX_SIZE;
141  }
142  return it - m_HintsByStart.begin();
143  }
144 
145 #ifdef DBG_UTIL
146  bool Check(bool) const;
147 #endif
148 
149 public:
150  SwpHints(const SwTextNode& rParent);
151 
152  size_t Count() const { return m_HintsByStart.size(); }
153  bool Contains( const SwTextAttr *pHt ) const;
154  SwTextAttr * Get( size_t nPos ) const
155  {
156  return m_HintsByStart[nPos];
157  }
158  SwTextAttr * GetSortedByEnd( size_t nPos ) const
159  {
160  return m_HintsByEnd[nPos];
161  }
162  SwTextAttr * Cut( const size_t nPosInStart )
163  {
164  SwTextAttr *pHt = m_HintsByStart[nPosInStart];
165  DeleteAtPos( nPosInStart );
166  return pHt;
167  }
168 
169  bool CanBeDeleted() const { return m_HintsByStart.empty(); }
170 
172  void Register( SwRegHistory* pHist ) { m_pHistory = pHist; }
174  void DeRegister() { Register(nullptr); }
175  SwRegHistory* GetHistory() const { return m_pHistory; }
176 
179  bool TryInsertHint( SwTextAttr * const pHint, SwTextNode & rNode,
180  const SetAttrMode nMode = SetAttrMode::DEFAULT );
181 
182  bool HasFootnote() const { return m_bFootnote; }
183  bool IsInSplitNode() const { return m_bInSplitNode; }
184 
185  // calc current value of m_bHiddenByParaField, returns true iff changed
186  bool CalcHiddenParaField() const; // changes mutable state
187 };
188 
189 #endif
190 
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void BuildPortions(SwTextNode &rNode, SwTextAttr &rNewHint, const SetAttrMode nMode)
Definition: thints.cxx:586
void DeleteAtPos(size_t nPos)
Definition: thints.cxx:3270
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:356
size_t GetIndexOf(const SwTextAttr *pHt) const
Definition: ndhints.hxx:134
bool m_bFootnote
footnotes
Definition: ndhints.hxx:97
SwpHtStart m_HintsByStart
Definition: ndhints.hxx:85
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:979
bool CanBeDeleted() const
Definition: ndhints.hxx:169
void Resort()
Definition: ndhints.cxx:371
Definition: doc.hxx:185
const_iterator find(const Value &x) const
SwTextAttr * GetSortedByEnd(size_t nPos) const
Definition: ndhints.hxx:158
void SetCalcHiddenParaField() const
Definition: ndhints.hxx:114
bool TryInsertHint(SwTextAttr *const pHint, SwTextNode &rNode, const SetAttrMode nMode=SetAttrMode::DEFAULT)
try to insert the hint
Definition: thints.cxx:2940
void NoteInHistory(SwTextAttr *pAttr, const bool bNew=false)
records a new attribute in m_pHistory.
Definition: thints.cxx:2627
SwpHints(const SwTextNode &rParent)
Definition: thints.cxx:95
const SwTextNode & m_rParent
Definition: ndhints.hxx:79
SwRegHistory * m_pHistory
for Undo
Definition: ndhints.hxx:88
size_type size() const
CopyOrNewType
Definition: ndhints.hxx:35
void Insert(const SwTextAttr *pHt)
Definition: ndhints.cxx:111
size_t Count() const
Definition: ndhints.hxx:152
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:174
bool IsInSplitNode() const
Definition: ndhints.hxx:183
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:154
bool MergePortions(SwTextNode &rNode)
Definition: thints.cxx:2632
bool m_bHiddenByParaField
Definition: ndhints.hxx:96
bool m_bCalcHiddenParaField
Definition: ndhints.hxx:93
void Delete(SwTextAttr const *pTextHt)
Delete the given Hint. The Hint must actually be in the array!
Definition: thints.cxx:3316
SetAttrMode
Definition: swtypes.hxx:143
bool operator()(SwTextAttr const *const lhs, SwTextAttr const *const rhs) const
Definition: ndhints.cxx:101
void Register(SwRegHistory *pHist)
register a History, which receives all attribute changes (for Undo)
Definition: ndhints.hxx:172
const_iterator end() const
bool empty() const
void SetInSplitNode(bool bInSplit)
Definition: ndhints.hxx:113
SwTextAttr's, sorted by start.
Definition: ndhints.hxx:59
SwpHtEnd m_HintsByEnd
Definition: ndhints.hxx:86
bool IsHiddenByParaField() const
Definition: ndhints.hxx:116
const_iterator begin() const
SwRegHistory * GetHistory() const
Definition: ndhints.hxx:175
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
void SetHiddenByParaField(const bool bNew) const
Definition: ndhints.hxx:115
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:76
void InsertNesting(SwTextAttrNesting &rNewHint)
Insert nesting hint into the hints array.
Definition: thints.cxx:282
SwTextAttr's, sorted by end.
Definition: ndhints.hxx:67
bool m_bInSplitNode
true: the Node is in Split and Frames are moved
Definition: ndhints.hxx:91
SwTextAttr * MakeRedlineTextAttr(SwDoc &rDoc, SfxPoolItem const &rAttr)
create redline dummy text hint that must not be inserted into hints array
Definition: thints.cxx:949
static const size_t MAX_HINTS
Definition: ndhints.hxx:83
bool Check(bool) const
Definition: ndhints.cxx:147
bool CalcHiddenParaField() const
Definition: thints.cxx:2590
bool HasFootnote() const
Definition: ndhints.hxx:182
void CalcFlags()
Definition: thints.cxx:2561
bool m_bDDEFields
the TextNode has DDE fields
Definition: ndhints.hxx:98
SwTextAttr * Cut(const size_t nPosInStart)
Definition: ndhints.hxx:162
bool Contains(const SwTextAttr *pHt) const
Definition: ndhints.cxx:122
bool operator()(SwTextAttr const *const lhs, SwTextAttr const *const rhs) const
Definition: ndhints.cxx:106