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 
71 bool 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 );
86  SetDontExpandStartAttr( 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 bResetMod = !rDoc.getIDocumentState().IsModified();
135  Link<bool,void> aOle2Lnk;
136  if ( bResetMod )
137  {
138  aOle2Lnk = rDoc.GetOle2Link();
139  rDoc.SetOle2Link( Link<bool,void>() );
140  }
141 
142  pRet = IsPoolUserFormat( nId )
143  ? rDoc.FindCharFormatByName( rStr )
145 
146  if ( bResetMod )
147  {
149  rDoc.SetOle2Link( aOle2Lnk );
150  }
151  }
152 
153  if ( pRet )
154  pRet->Add( this );
155  else
156  EndListeningAll();
157 
158  return pRet;
159 }
160 
162 {
163  if (rHint.GetId() != SfxHintId::SwLegacyModify)
164  return;
165  auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
166  const auto nWhich = pLegacy->GetWhich();
167  OSL_ENSURE(isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
168  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
169  "SwTextINetFormat::SwClientNotify: unknown hint.");
170  if(!m_pTextNode)
171  return;
172 
173  const SwUpdateAttr aUpdateAttr(GetStart(), *GetEnd(), nWhich);
174  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
175 }
176 
178 {
179  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
180  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
181 }
182 
184 {
185  return m_pTextNode && m_pTextNode->IsProtect();
186 }
187 
189  sal_Int32 nStart, sal_Int32 nEnd )
190  : SwTextAttr( rAttr, nStart )
191  , SwTextAttrNesting( rAttr, nStart, nEnd )
192  , SwClient( nullptr )
193  , m_pTextNode( nullptr )
194 {
195  rAttr.m_pTextAttr = this;
196 }
197 
199 {
200 }
201 
202 void SwTextRuby::SwClientNotify(const SwModify&, const SfxHint& rHint)
203 {
204  if (rHint.GetId() != SfxHintId::SwLegacyModify)
205  return;
206  auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint);
207  const auto nWhich = pLegacy->GetWhich();
208  SAL_WARN_IF( !isCHRATR(nWhich)
209  && (RES_OBJECTDYING == nWhich)
210  && (RES_ATTRSET_CHG == nWhich)
211  && (RES_FMT_CHG == nWhich), "sw.core", "SwTextRuby::SwClientNotify(): unknown legacy hint");
212  if(!m_pTextNode)
213  return;
214  SwUpdateAttr aUpdateAttr(GetStart(), *GetEnd(), nWhich);
215  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
216 }
217 
218 bool SwTextRuby::GetInfo( SfxPoolItem& rInfo ) const
219 {
220  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
221  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
222 }
223 
225 {
226  const SwFormatRuby& rFormat = SwTextAttrEnd::GetRuby();
227  SwCharFormat* pRet = nullptr;
228 
229  if( !rFormat.GetText().isEmpty() )
230  {
231  const SwDoc& rDoc = GetTextNode().GetDoc();
232  const OUString& rStr = rFormat.GetCharFormatName();
233  const sal_uInt16 nId = rStr.isEmpty()
234  ? o3tl::narrowing<sal_uInt16>(RES_POOLCHR_RUBYTEXT)
235  : rFormat.GetCharFormatId();
236 
237  // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
238  // correct charstyle.
239  const bool bResetMod = !rDoc.getIDocumentState().IsModified();
240  Link<bool,void> aOle2Lnk;
241  if( bResetMod )
242  {
243  aOle2Lnk = rDoc.GetOle2Link();
244  const_cast<SwDoc&>(rDoc).SetOle2Link( Link<bool,void>() );
245  }
246 
247  pRet = IsPoolUserFormat( nId )
248  ? rDoc.FindCharFormatByName( rStr )
249  : const_cast<SwDoc&>(rDoc).getIDocumentStylePoolAccess().GetCharFormatFromPool( nId );
250 
251  if( bResetMod )
252  {
253  const_cast<SwDoc&>(rDoc).getIDocumentState().ResetModified();
254  const_cast<SwDoc&>(rDoc).SetOle2Link( aOle2Lnk );
255  }
256  }
257 
258  if( pRet )
259  pRet->Add( this );
260  else
261  EndListeningAll();
262 
263  return pRet;
264 }
265 
266 SwTextMeta *
268  ::sw::MetaFieldManager & i_rTargetDocManager,
269  SwTextNode *const i_pTargetTextNode,
270  SwFormatMeta & i_rAttr,
271  sal_Int32 const i_nStart,
272  sal_Int32 const i_nEnd,
273  bool const i_bIsCopy)
274 {
275  if (i_bIsCopy)
276  { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
277  OSL_ENSURE(i_pTargetTextNode, "cannot copy Meta without target node");
278  i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTextNode);
279  }
280  SwTextMeta *const pTextMeta(new SwTextMeta(i_rAttr, i_nStart, i_nEnd));
281  return pTextMeta;
282 }
283 
285  const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
286  : SwTextAttr( i_rAttr, i_nStart )
287  , SwTextAttrNesting( i_rAttr, i_nStart, i_nEnd )
288 {
289  i_rAttr.SetTextAttr( this );
290  SetHasDummyChar(true);
291 }
292 
294 {
295  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
296  if (rFormatMeta.GetTextAttr() == this)
297  {
298  rFormatMeta.SetTextAttr(nullptr);
299  }
300 }
301 
303 {
304  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
305  if (rFormatMeta.GetTextAttr() == this)
306  {
307  rFormatMeta.NotifyChangeTextNode(pNode);
308  }
309 }
310 
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual SwCharFormat * GetCharFormatFromPool(sal_uInt16 nId)=0
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:267
const OUString & GetCharFormatName() const
Definition: fmtruby.hxx:64
bool GetInfo(SfxPoolItem const &rInfo) const
Definition: txtatr2.cxx:71
void Add(SwClient *pDepend)
Definition: calbck.cxx:173
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:175
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:111
SwTextCharFormat(SwFormatCharFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:37
sal_uInt16 GetWhich() const
Definition: calbck.hxx:75
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:100
virtual ~SwTextINetFormat() override
Definition: txtatr2.cxx:107
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:476
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(162)
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: txtatr2.cxx:161
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:76
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5206
SwTextNode * m_pTextNode
Definition: txtatr.hxx:75
void DoCopy(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode &i_rTargetTextNode)
this method must be called when the hint is actually copied
Definition: fmtatr2.cxx:612
SwTextAttrNesting(SfxPoolItem &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:77
knows all meta-fields in the document.
Definition: fmtmeta.hxx:196
Definition: doc.hxx:188
SwTextCharFormat * m_pTextAttribute
My text attribute.
Definition: fchrfmt.hxx:33
bool IsVisitedURL(const OUString &rURL)
Definition: visiturl.cxx:100
void SetOle2Link(const Link< bool, void > &rLink)
Definition: doc.hxx:1328
sal_Int16 nId
const SwTextNode & GetTextNode() const
Get and set TextNode pointer.
Definition: txtatr.hxx:94
bool IsPoolUserFormat(sal_uInt16 nId)
Definition: poolfmt.hxx:86
void NotifyChangeTextNode(SwTextNode *const pTextNode)
notify clients registered at m_pMeta that this meta is being (re-)moved
Definition: fmtatr2.cxx:599
bool IsVisited() const
Definition: txtinet.hxx:54
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: txtatr2.cxx:202
virtual ~SwTextRuby() override
Definition: txtatr2.cxx:198
virtual ~SwTextAttrNesting() override
Definition: txtatr2.cxx:90
SfxHintId GetId() const
bool IsProtect() const
Definition: txtatr2.cxx:183
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:75
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1329
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
bool IsVisitedValid() const
Definition: txtinet.hxx:57
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
Definition: txtatr2.cxx:52
SwTextMeta(SwFormatMeta &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:284
void ChgTextNode(SwTextNode *const pNode)
Definition: txtatr2.cxx:302
void EndListeningAll()
Definition: calbck.cxx:137
sal_uInt16 GetINetFormatId() const
Definition: fmtinfmt.hxx:107
const OUString & GetText() const
Definition: fmtruby.hxx:61
SwTextRuby(SwFormatRuby &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:188
sal_uInt16 GetVisitedFormatId() const
Definition: fmtinfmt.hxx:125
void SetVisited(bool bNew)
Definition: txtinet.hxx:55
SwDoc & GetDoc()
Definition: node.hxx:212
virtual bool IsModified() const =0
Changes of document?
SwTextINetFormat * mpTextAttr
My TextAttribute.
Definition: fmtinfmt.hxx:47
sal_uInt16 GetCharFormatId() const
Definition: fmtruby.hxx:67
void SetCharFormatAttr(bool bFlag)
Definition: txatbase.hxx:72
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(163)
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(173)
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:694
void SetVisitedValid(bool bNew)
Definition: txtinet.hxx:58
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ...
Definition: node.cxx:426
Represents the style of a text portion.
Definition: charfmt.hxx:26
const SwTextNode & GetTextNode() const
Definition: txtinet.hxx:63
void SetDontExpandStartAttr(bool bFlag)
Definition: txatbase.hxx:74
SwTextRuby * m_pTextAttr
The TextAttribute.
Definition: fmtruby.hxx:34
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:771
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
const OUString & GetVisitedFormat() const
Definition: fmtinfmt.hxx:120
#define SAL_WARN_IF(condition, area, stream)
SwTextNode * m_pTextNode
Definition: txtatr.hxx:35
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: txtatr2.cxx:218
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:576
SwTextINetFormat(SwFormatINetFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:94
SwTextNode * m_pTextNode
Definition: txtinet.hxx:31
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
const OUString & GetINetFormat() const
Definition: fmtinfmt.hxx:102
virtual ~SwTextCharFormat() override
Definition: txtatr2.cxx:48
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: txtatr2.cxx:177
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:224
sal_uInt16 Which() const
void SetLockExpandFlag(bool bFlag)
Definition: txatbase.hxx:70
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:234
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_MSG_BEGIN)
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:228
virtual ~SwTextMeta() override
Definition: txtatr2.cxx:293
virtual void ResetModified()=0