LibreOffice Module sw (master) 1
txtatr2.cxx
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
20#include <hintids.hxx>
21#include <hints.hxx>
22#include <osl/diagnose.h>
23#include <txtinet.hxx>
24#include <txtatr.hxx>
25#include <fchrfmt.hxx>
26#include <fmtinfmt.hxx>
27#include <charfmt.hxx>
28#include <ndtxt.hxx>
29#include <poolfmt.hxx>
30#include <doc.hxx>
31#include <fmtruby.hxx>
32#include <fmtmeta.hxx>
33#include <IDocumentState.hxx>
35
36
38 sal_Int32 nStt, sal_Int32 nEnd )
39 : SwTextAttr( rAttr, nStt )
40 , SwTextAttrEnd( rAttr, nStt, nEnd )
41 , m_pTextNode( nullptr )
42 , m_nSortNumber( 0 )
43{
44 rAttr.m_pTextAttribute = this;
45 SetCharFormatAttr( true );
46}
47
49{
50}
51
53{
54 const auto nWhich = rHint.GetWhich();
56 !isCHRATR(nWhich) &&
57 RES_OBJECTDYING != nWhich &&
58 RES_ATTRSET_CHG != nWhich &&
59 RES_FMT_CHG != nWhich, "sw.core", "SwTextCharFormat::TriggerNodeUpdate: unknown hint type");
60
61 if(m_pTextNode)
62 {
63 SwUpdateAttr aUpdateAttr(
64 GetStart(),
65 *GetEnd(),
66 nWhich);
67 m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
68 }
69}
70
71bool SwTextCharFormat::GetInfo( SfxPoolItem const & rInfo ) const
72{
73 return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
74 &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode const &>(rInfo).pNodes;
75}
76
78 const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
79 : SwTextAttr( i_rAttr, i_nStart )
80 , SwTextAttrEnd( i_rAttr, i_nStart, i_nEnd )
81{
82 SetDontExpand( true ); // never expand this attribute
83 // lock the expand flag: simple guarantee that nesting will not be
84 // invalidated by expand operations
85 SetLockExpandFlag( true );
87 SetNesting( true );
88}
89
91{
92}
93
95 sal_Int32 nStart, sal_Int32 nEnd )
96 : SwTextAttr( rAttr, nStart )
97 , SwTextAttrNesting( rAttr, nStart, nEnd )
98 , SwClient( nullptr )
99 , m_pTextNode( nullptr )
100 , m_bVisited( false )
101 , m_bVisitedValid( false )
102{
103 rAttr.mpTextAttr = this;
104 SetCharFormatAttr( true );
105}
106
108{
109}
110
112{
114 SwCharFormat* pRet = nullptr;
115
116 if (!rFormat.GetValue().isEmpty())
117 {
118 SwDoc& rDoc = GetTextNode().GetDoc();
119 if( !IsVisitedValid() )
120 {
121 SetVisited( rDoc.IsVisitedURL( rFormat.GetValue() ) );
122 SetVisitedValid( true );
123 }
124
125 const sal_uInt16 nId = IsVisited() ? rFormat.GetVisitedFormatId() : rFormat.GetINetFormatId();
126 const OUString& rStr = IsVisited() ? rFormat.GetVisitedFormat() : rFormat.GetINetFormat();
127 if (rStr.isEmpty())
128 {
129 OSL_ENSURE( false, "<SwTextINetFormat::GetCharFormat()> - missing character format at hyperlink attribute");
130 }
131
132 // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
133 // correct charstyle.
134 bool bModifiedEnabled = rDoc.getIDocumentState().IsEnableSetModified();
136
137 pRet = IsPoolUserFormat( nId )
138 ? rDoc.FindCharFormatByName( rStr )
140
141 rDoc.getIDocumentState().SetEnableSetModified(bModifiedEnabled);
142 }
143
144 if ( pRet )
145 pRet->Add( this );
146 else
148
149 return pRet;
150}
151
153{
154 if (rHint.GetId() != SfxHintId::SwLegacyModify)
155 return;
156 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
157 const auto nWhich = pLegacy->GetWhich();
158 OSL_ENSURE(isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
159 || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
160 "SwTextINetFormat::SwClientNotify: unknown hint.");
161 if(!m_pTextNode)
162 return;
163
164 const SwUpdateAttr aUpdateAttr(GetStart(), *GetEnd(), nWhich);
165 m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
166}
167
169{
170 return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
171 &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
172}
173
175{
176 return m_pTextNode && m_pTextNode->IsProtect();
177}
178
180 sal_Int32 nStart, sal_Int32 nEnd )
181 : SwTextAttr( rAttr, nStart )
182 , SwTextAttrNesting( rAttr, nStart, nEnd )
183 , SwClient( nullptr )
184 , m_pTextNode( nullptr )
185{
186 rAttr.m_pTextAttr = this;
187}
188
190{
191}
192
194{
195 if (rHint.GetId() != SfxHintId::SwLegacyModify)
196 return;
197 auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
198 const auto nWhich = pLegacy->GetWhich();
199 SAL_WARN_IF( !isCHRATR(nWhich)
200 && (RES_OBJECTDYING == nWhich)
201 && (RES_ATTRSET_CHG == nWhich)
202 && (RES_FMT_CHG == nWhich), "sw.core", "SwTextRuby::SwClientNotify(): unknown legacy hint");
203 if(!m_pTextNode)
204 return;
205 SwUpdateAttr aUpdateAttr(GetStart(), *GetEnd(), nWhich);
206 m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
207}
208
210{
211 return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
212 &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
213}
214
216{
217 const SwFormatRuby& rFormat = SwTextAttrEnd::GetRuby();
218 SwCharFormat* pRet = nullptr;
219
220 if( !rFormat.GetText().isEmpty() )
221 {
222 const SwDoc& rDoc = GetTextNode().GetDoc();
223 const OUString& rStr = rFormat.GetCharFormatName();
224 const sal_uInt16 nId = rStr.isEmpty()
225 ? o3tl::narrowing<sal_uInt16>(RES_POOLCHR_RUBYTEXT)
226 : rFormat.GetCharFormatId();
227
228 // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
229 // correct charstyle.
230 const bool bResetMod = !rDoc.getIDocumentState().IsModified();
231 Link<bool,void> aOle2Lnk;
232 if( bResetMod )
233 {
234 aOle2Lnk = rDoc.GetOle2Link();
235 const_cast<SwDoc&>(rDoc).SetOle2Link( Link<bool,void>() );
236 }
237
238 pRet = IsPoolUserFormat( nId )
239 ? rDoc.FindCharFormatByName( rStr )
240 : const_cast<SwDoc&>(rDoc).getIDocumentStylePoolAccess().GetCharFormatFromPool( nId );
241
242 if( bResetMod )
243 {
244 const_cast<SwDoc&>(rDoc).getIDocumentState().ResetModified();
245 const_cast<SwDoc&>(rDoc).SetOle2Link( aOle2Lnk );
246 }
247 }
248
249 if( pRet )
250 pRet->Add( this );
251 else
253
254 return pRet;
255}
256
259 ::sw::MetaFieldManager & i_rTargetDocManager,
260 SwTextNode *const i_pTargetTextNode,
261 SwFormatMeta & i_rAttr,
262 sal_Int32 const i_nStart,
263 sal_Int32 const i_nEnd,
264 bool const i_bIsCopy)
265{
266 if (i_bIsCopy)
267 { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
268 OSL_ENSURE(i_pTargetTextNode, "cannot copy Meta without target node");
269 i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTextNode);
270 }
271 SwTextMeta *const pTextMeta(new SwTextMeta(i_rAttr, i_nStart, i_nEnd));
272 return pTextMeta;
273}
274
276 const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
277 : SwTextAttr( i_rAttr, i_nStart )
278 , SwTextAttrNesting( i_rAttr, i_nStart, i_nEnd )
279{
280 i_rAttr.SetTextAttr( this );
281 SetHasDummyChar(true);
282}
283
285{
286 SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
287 if (rFormatMeta.GetTextAttr() == this)
288 {
289 rFormatMeta.SetTextAttr(nullptr);
290 }
291}
292
294{
295 SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
296 if (rFormatMeta.GetTextAttr() == this)
297 {
298 rFormatMeta.NotifyChangeTextNode(pNode);
299 }
300}
301
302/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SetEnableSetModified(bool bEnableSetModified)=0
virtual bool IsModified() const =0
Changes of document?
virtual bool IsEnableSetModified() const =0
virtual SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)=0
SfxHintId GetId() const
sal_uInt16 Which() const
Represents the style of a text portion.
Definition: charfmt.hxx:27
void EndListeningAll()
Definition: calbck.cxx:136
Definition: doc.hxx:197
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:408
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:786
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1347
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:440
bool IsVisitedURL(std::u16string_view rURL)
Definition: visiturl.cxx:100
SwTextCharFormat * m_pTextAttribute
My text attribute.
Definition: fchrfmt.hxx:33
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
sal_uInt16 GetINetFormatId() const
Definition: fmtinfmt.hxx:107
const OUString & GetINetFormat() const
Definition: fmtinfmt.hxx:102
SwTextINetFormat * mpTextAttr
My TextAttribute.
Definition: fmtinfmt.hxx:47
const OUString & GetVisitedFormat() const
Definition: fmtinfmt.hxx:120
sal_uInt16 GetVisitedFormatId() const
Definition: fmtinfmt.hxx:125
SwFormatMeta is a pool item subclass that owns a Meta.
Definition: fmtmeta.hxx:93
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:101
void NotifyChangeTextNode(SwTextNode *const pTextNode)
notify clients registered at m_pMeta that this meta is being (re-)moved
Definition: fmtatr2.cxx:611
void DoCopy(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode &i_rTargetTextNode)
this method must be called when the hint is actually copied
Definition: fmtatr2.cxx:624
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:588
const OUString & GetCharFormatName() const
Definition: fmtruby.hxx:64
const OUString & GetText() const
Definition: fmtruby.hxx:61
SwTextRuby * m_pTextAttr
The TextAttribute.
Definition: fmtruby.hxx:34
sal_uInt16 GetCharFormatId() const
Definition: fmtruby.hxx:67
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ... including anchor in case of fra...
Definition: node.cxx:449
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
SwDoc & GetDoc()
Definition: node.hxx:233
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
SwTextAttrNesting(SfxPoolItem &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:77
virtual ~SwTextAttrNesting() override
Definition: txtatr2.cxx:90
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
void SetDontExpandStartAttr(bool bFlag)
Definition: txatbase.hxx:76
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
void SetCharFormatAttr(bool bFlag)
Definition: txatbase.hxx:74
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:244
void SetLockExpandFlag(bool bFlag)
Definition: txatbase.hxx:72
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:250
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:78
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:179
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:77
SwTextCharFormat(SwFormatCharFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:37
virtual ~SwTextCharFormat() override
Definition: txtatr2.cxx:48
bool GetInfo(SfxPoolItem const &rInfo) const
Definition: txtatr2.cxx:71
SwTextNode * m_pTextNode
Definition: txtatr.hxx:35
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
Definition: txtatr2.cxx:52
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: txtatr2.cxx:152
SwTextNode * m_pTextNode
Definition: txtinet.hxx:32
void SetVisitedValid(bool bNew)
Definition: txtinet.hxx:59
bool IsVisited() const
Definition: txtinet.hxx:55
virtual ~SwTextINetFormat() override
Definition: txtatr2.cxx:107
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: txtatr2.cxx:168
void SetVisited(bool bNew)
Definition: txtinet.hxx:56
bool IsProtect() const
Definition: txtatr2.cxx:174
bool IsVisitedValid() const
Definition: txtinet.hxx:58
const SwTextNode & GetTextNode() const
Definition: txtinet.hxx:64
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:111
SwTextINetFormat(SwFormatINetFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:94
static SwTextMeta * CreateTextMeta(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode *const i_pTargetTextNode, SwFormatMeta &i_rAttr, sal_Int32 const i_nStart, sal_Int32 const i_nEnd, bool const i_bIsCopy)
Definition: txtatr2.cxx:258
SwTextMeta(SwFormatMeta &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:275
void ChgTextNode(SwTextNode *const pNode)
Definition: txtatr2.cxx:293
virtual ~SwTextMeta() override
Definition: txtatr2.cxx:284
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:112
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5449
const SwTextNode & GetTextNode() const
Get and set TextNode pointer.
Definition: txtatr.hxx:94
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: txtatr2.cxx:209
virtual ~SwTextRuby() override
Definition: txtatr2.cxx:189
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:215
SwTextRuby(SwFormatRuby &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:179
SwTextNode * m_pTextNode
Definition: txtatr.hxx:75
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: txtatr2.cxx:193
knows all meta-fields in the document.
Definition: fmtmeta.hxx:202
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:468
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(169)
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(176)
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_FORMAT_MSG_BEGIN)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(168)
#define SAL_WARN_IF(condition, area, stream)
sal_Int16 nId
@ RES_POOLCHR_RUBYTEXT
Rubytext.
Definition: poolfmt.hxx:129
bool IsPoolUserFormat(sal_uInt16 nId)
Definition: poolfmt.hxx:86
sal_uInt16 GetWhich() const
Definition: calbck.hxx:75