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
24class SwTextNode;
25class SwRegHistory; // Is in RolBck.hxx.
26class SwTextAttr;
28
29class SfxPoolItem;
30class SfxItemSet;
31class SwDoc;
32
33enum 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
68{
69private:
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
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; }
113 {
115 {
117 }
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(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
139public:
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" );
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;
168 {
169 assert( !(nPos != 0 && m_bWhichMapNeedsSorting) && "going to trigger a resort in the middle of an iteration, that's bad" );
173 }
174
176 void SortIfNeedBe() const
177 {
181 ResortEndMap();
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: */
Definition: doc.hxx:197
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
An SwTextAttr container, stores all directly formatted text portions for a text node.
Definition: ndhints.hxx:68
SW_DLLPUBLIC void ResortWhichMap() const
Definition: ndhints.cxx:448
bool m_bFootnote
footnotes
Definition: ndhints.hxx:89
std::vector< SwTextAttr * > m_HintsByWhichAndStart
Definition: ndhints.hxx:78
void StartPosChanged() const
Definition: ndhints.hxx:212
void DeRegister()
deregister the currently registered History
Definition: ndhints.hxx:197
std::vector< SwTextAttr * > m_HintsByEnd
Definition: ndhints.hxx:77
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
void SortIfNeedBe() const
Trigger the sorting if necessary.
Definition: ndhints.hxx:176
bool m_bEndMapNeedsSorting
Definition: ndhints.hxx:93
void SetCalcHiddenParaField() const
Definition: ndhints.hxx:110
void Register(SwRegHistory *pHist)
register a History, which receives all attribute changes (for Undo)
Definition: ndhints.hxx:195
SwTextAttr * GetWithoutResorting(size_t nPos) const
Definition: ndhints.hxx:152
size_t GetFirstPosSortedByWhichAndStart(sal_uInt16 nWhich) const
Definition: ndhints.cxx:458
bool IsInSplitNode() const
Definition: ndhints.hxx:206
bool CalcHiddenParaField() const
Definition: thints.cxx:2657
bool Contains(const SwTextAttr *pHt) const
Definition: ndhints.cxx:169
void Delete(SwTextAttr const *pTextHt)
Delete the given Hint. The Hint must actually be in the array!
Definition: thints.cxx:3429
bool m_bDDEFields
the TextNode has DDE fields
Definition: ndhints.hxx:90
size_t GetIndexOf(const SwTextAttr *pHt) const
Definition: ndhints.cxx:476
SwTextAttr * Cut(const size_t nPosInStart)
Definition: ndhints.hxx:185
void SetHiddenByParaField(const bool bNew) const
Definition: ndhints.hxx:111
bool m_bHiddenByParaField
Definition: ndhints.hxx:88
bool IsHiddenByParaField() const
Definition: ndhints.hxx:112
void InsertNesting(SwTextAttrNesting &rNewHint)
Insert nesting hint into the hints array.
Definition: thints.cxx:301
SW_DLLPUBLIC void Resort() const
Definition: ndhints.cxx:406
size_t Count() const
Definition: ndhints.hxx:142
bool HasFootnote() const
Definition: ndhints.hxx:205
bool Check(bool) const
Definition: ndhints.cxx:188
static const size_t MAX_HINTS
Definition: ndhints.hxx:74
SwpHints(const SwTextNode &rParent)
Definition: thints.cxx:92
SwTextAttr * GetSortedByEnd(size_t nPos) const
Definition: ndhints.hxx:158
bool m_bCalcHiddenParaField
Definition: ndhints.hxx:85
void SetInSplitNode(bool bInSplit)
Definition: ndhints.hxx:109
bool TryInsertNesting(SwTextNode &rNode, SwTextAttrNesting &rNewHint)
The following hints correspond to well-formed XML elements in ODF: RES_TXTATR_INETFMT,...
Definition: thints.cxx:378
int GetLastPosSortedByEnd(sal_Int32 nEndPos) const
Definition: ndhints.cxx:468
const SwTextNode & m_rParent
Definition: ndhints.hxx:70
void Insert(SwTextAttr *pHt)
Definition: ndhints.cxx:145
bool m_bWhichMapNeedsSorting
Definition: ndhints.hxx:94
std::vector< SwTextAttr * > m_HintsByStart
Definition: ndhints.hxx:76
SwRegHistory * m_pHistory
for Undo
Definition: ndhints.hxx:80
bool CanBeDeleted() const
Definition: ndhints.hxx:192
bool MergePortions(SwTextNode &rNode)
Definition: thints.cxx:2715
void NoteInHistory(SwTextAttr *pAttr, const bool bNew=false)
records a new attribute in m_pHistory.
Definition: thints.cxx:2694
void EndPosChanged() const
Definition: ndhints.hxx:213
void DeleteAtPos(size_t nPos)
Definition: thints.cxx:3369
bool m_bInSplitNode
true: the Node is in Split and Frames are moved
Definition: ndhints.hxx:83
bool m_bStartMapNeedsSorting
Definition: ndhints.hxx:92
void CalcFlags()
Definition: thints.cxx:2628
bool TryInsertHint(SwTextAttr *const pHint, SwTextNode &rNode, const SetAttrMode nMode=SetAttrMode::DEFAULT)
try to insert the hint
Definition: thints.cxx:3037
SW_DLLPUBLIC void ResortStartMap() const
Definition: ndhints.cxx:428
SW_DLLPUBLIC void ResortEndMap() const
Definition: ndhints.cxx:438
SwTextAttr * GetSortedByWhichAndStart(size_t nPos) const
Definition: ndhints.hxx:167
SwRegHistory * GetHistory() const
Definition: ndhints.hxx:198
void BuildPortions(SwTextNode &rNode, SwTextAttr &rNewHint, const SetAttrMode nMode)
Definition: thints.cxx:635
sal_uInt16 nPos
CopyOrNewType
Definition: ndhints.hxx:33
SwTextAttr * MakeRedlineTextAttr(SwDoc &rDoc, SfxPoolItem const &rAttr)
create redline dummy text hint that must not be inserted into hints array
Definition: thints.cxx:1000
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:1030
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:106
bool operator()(const SwTextAttr *lhs, const sal_uInt16 nWhich) const
sort order: Which, Start, End(reverse) at last the pointer
Definition: ndhints.cxx:68
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SetAttrMode
Definition: swtypes.hxx:133