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 
161 void SwTextINetFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
162 {
163  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
164  OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
165  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
166  "SwTextINetFormat::Modify(): unknown Modify");
167 
168  if ( m_pTextNode )
169  {
170  SwUpdateAttr aUpdateAttr(
171  GetStart(),
172  *GetEnd(),
173  nWhich);
174 
175  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
176  }
177 }
178 
180 {
181  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
182  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
183 }
184 
186 {
187  return m_pTextNode && m_pTextNode->IsProtect();
188 }
189 
191  sal_Int32 nStart, sal_Int32 nEnd )
192  : SwTextAttr( rAttr, nStart )
193  , SwTextAttrNesting( rAttr, nStart, nEnd )
194  , SwClient( nullptr )
195  , m_pTextNode( nullptr )
196 {
197  rAttr.m_pTextAttr = this;
198 }
199 
201 {
202 }
203 
204 void SwTextRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
205 {
206  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
207  OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
208  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
209  "SwTextRuby::Modify(): unknown Modify");
210 
211  if ( m_pTextNode )
212  {
213  SwUpdateAttr aUpdateAttr(
214  GetStart(),
215  *GetEnd(),
216  nWhich);
217 
218  m_pTextNode->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
219  }
220 }
221 
222 bool SwTextRuby::GetInfo( SfxPoolItem& rInfo ) const
223 {
224  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
225  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
226 }
227 
229 {
230  const SwFormatRuby& rFormat = SwTextAttrEnd::GetRuby();
231  SwCharFormat* pRet = nullptr;
232 
233  if( !rFormat.GetText().isEmpty() )
234  {
235  const SwDoc& rDoc = GetTextNode().GetDoc();
236  const OUString& rStr = rFormat.GetCharFormatName();
237  const sal_uInt16 nId = rStr.isEmpty()
238  ? static_cast<sal_uInt16>(RES_POOLCHR_RUBYTEXT)
239  : rFormat.GetCharFormatId();
240 
241  // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
242  // correct charstyle.
243  const bool bResetMod = !rDoc.getIDocumentState().IsModified();
244  Link<bool,void> aOle2Lnk;
245  if( bResetMod )
246  {
247  aOle2Lnk = rDoc.GetOle2Link();
248  const_cast<SwDoc&>(rDoc).SetOle2Link( Link<bool,void>() );
249  }
250 
251  pRet = IsPoolUserFormat( nId )
252  ? rDoc.FindCharFormatByName( rStr )
253  : const_cast<SwDoc&>(rDoc).getIDocumentStylePoolAccess().GetCharFormatFromPool( nId );
254 
255  if( bResetMod )
256  {
257  const_cast<SwDoc&>(rDoc).getIDocumentState().ResetModified();
258  const_cast<SwDoc&>(rDoc).SetOle2Link( aOle2Lnk );
259  }
260  }
261 
262  if( pRet )
263  pRet->Add( this );
264  else
265  EndListeningAll();
266 
267  return pRet;
268 }
269 
270 SwTextMeta *
272  ::sw::MetaFieldManager & i_rTargetDocManager,
273  SwTextNode *const i_pTargetTextNode,
274  SwFormatMeta & i_rAttr,
275  sal_Int32 const i_nStart,
276  sal_Int32 const i_nEnd,
277  bool const i_bIsCopy)
278 {
279  if (i_bIsCopy)
280  { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
281  OSL_ENSURE(i_pTargetTextNode, "cannot copy Meta without target node");
282  i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTextNode);
283  }
284  SwTextMeta *const pTextMeta(new SwTextMeta(i_rAttr, i_nStart, i_nEnd));
285  return pTextMeta;
286 }
287 
289  const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
290  : SwTextAttr( i_rAttr, i_nStart )
291  , SwTextAttrNesting( i_rAttr, i_nStart, i_nEnd )
292 {
293  i_rAttr.SetTextAttr( this );
294  SetHasDummyChar(true);
295 }
296 
298 {
299  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
300  if (rFormatMeta.GetTextAttr() == this)
301  {
302  rFormatMeta.SetTextAttr(nullptr);
303  }
304 }
305 
307 {
308  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
309  if (rFormatMeta.GetTextAttr() == this)
310  {
311  rFormatMeta.NotifyChangeTextNode(pNode);
312  }
313 }
314 
315 /* 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:271
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:199
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:171
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:68
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:100
virtual ~SwTextINetFormat() override
Definition: txtatr2.cxx:107
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:469
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:72
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: txtatr2.cxx:204
void TriggerNodeUpdate(const sw::LegacyModifyHint &)
for hanging TextFormatCollections somewhere else (Outline-Numbering!)
Definition: ndtxt.cxx:5241
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:608
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:197
Definition: doc.hxx:186
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:1326
sal_Int16 nId
const SwTextNode & GetTextNode() const
Get and set TextNode pointer.
Definition: txtatr.hxx:95
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:595
bool IsVisited() const
Definition: txtinet.hxx:55
virtual const sal_Int32 * GetEnd() const override
end position
Definition: txatbase.cxx:77
virtual ~SwTextRuby() override
Definition: txtatr2.cxx:200
virtual ~SwTextAttrNesting() override
Definition: txtatr2.cxx:90
bool IsProtect() const
Definition: txtatr2.cxx:185
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:71
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:426
const Link< bool, void > & GetOle2Link() const
Definition: doc.hxx:1327
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
constexpr TypedWhichId< SwAttrSetChg > RES_ATTRSET_CHG(161)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(160)
bool IsVisitedValid() const
Definition: txtinet.hxx:58
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:288
void ChgTextNode(SwTextNode *const pNode)
Definition: txtatr2.cxx:306
void EndListeningAll()
Definition: calbck.cxx:127
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:190
sal_uInt16 GetVisitedFormatId() const
Definition: fmtinfmt.hxx:125
void SetVisited(bool bNew)
Definition: txtinet.hxx:56
SwDoc & GetDoc()
Definition: node.hxx:211
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:68
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:394
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: txtatr2.cxx:161
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:696
void SetVisitedValid(bool bNew)
Definition: txtinet.hxx:59
bool IsProtect() const
Is node in something that is protected (range, frame, table cells ...
Definition: node.cxx:424
const SwTextNode & GetTextNode() const
Definition: txtinet.hxx:64
void SetDontExpandStartAttr(bool bFlag)
Definition: txatbase.hxx:70
SwTextRuby * m_pTextAttr
The TextAttribute.
Definition: fmtruby.hxx:34
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:770
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
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:222
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:572
SwTextINetFormat(SwFormatINetFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:94
constexpr TypedWhichId< SwAutoFormatGetDocNode > RES_AUTOFMT_DOCNODE(171)
SwTextNode * m_pTextNode
Definition: txtinet.hxx:30
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
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:179
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:228
sal_uInt16 Which() const
void SetLockExpandFlag(bool bFlag)
Definition: txatbase.hxx:66
const SwFormatRuby & GetRuby() const
Definition: txatbase.hxx:230
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_OBJECTDYING(RES_MSG_BEGIN)
const SwFormatINetFormat & GetINetFormat() const
Definition: txatbase.hxx:224
virtual ~SwTextMeta() override
Definition: txtatr2.cxx:297
virtual void ResetModified()=0