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 sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
55  OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
56  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
57  "SwTextCharFormat::Modify(): unknown Modify");
58 
59  if ( m_pTextNode )
60  {
61  SwUpdateAttr aUpdateAttr(
62  GetStart(),
63  *GetEnd(),
64  nWhich);
65 
66  m_pTextNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
67  }
68 }
69 
70 bool SwTextCharFormat::GetInfo( SfxPoolItem const & rInfo ) const
71 {
72  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
73  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode const &>(rInfo).pNodes;
74 }
75 
77  const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
78  : SwTextAttr( i_rAttr, i_nStart )
79  , SwTextAttrEnd( i_rAttr, i_nStart, i_nEnd )
80 {
81  SetDontExpand( true ); // never expand this attribute
82  // lock the expand flag: simple guarantee that nesting will not be
83  // invalidated by expand operations
84  SetLockExpandFlag( true );
85  SetDontExpandStartAttr( true );
86  SetNesting( true );
87 }
88 
90 {
91 }
92 
94  sal_Int32 nStart, sal_Int32 nEnd )
95  : SwTextAttr( rAttr, nStart )
96  , SwTextAttrNesting( rAttr, nStart, nEnd )
97  , SwClient( nullptr )
98  , m_pTextNode( nullptr )
99  , m_bVisited( false )
100  , m_bVisitedValid( false )
101 {
102  rAttr.mpTextAttr = this;
103  SetCharFormatAttr( true );
104 }
105 
107 {
108 }
109 
111 {
113  SwCharFormat* pRet = nullptr;
114 
115  if (!rFormat.GetValue().isEmpty())
116  {
117  SwDoc* pDoc = GetTextNode().GetDoc();
118  if( !IsVisitedValid() )
119  {
120  SetVisited( pDoc->IsVisitedURL( rFormat.GetValue() ) );
121  SetVisitedValid( true );
122  }
123 
124  const sal_uInt16 nId = IsVisited() ? rFormat.GetVisitedFormatId() : rFormat.GetINetFormatId();
125  const OUString& rStr = IsVisited() ? rFormat.GetVisitedFormat() : rFormat.GetINetFormat();
126  if (rStr.isEmpty())
127  {
128  OSL_ENSURE( false, "<SwTextINetFormat::GetCharFormat()> - missing character format at hyperlink attribute");
129  }
130 
131  // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
132  // correct charstyle.
133  bool bResetMod = !pDoc->getIDocumentState().IsModified();
134  Link<bool,void> aOle2Lnk;
135  if ( bResetMod )
136  {
137  aOle2Lnk = pDoc->GetOle2Link();
138  pDoc->SetOle2Link( Link<bool,void>() );
139  }
140 
141  pRet = IsPoolUserFormat( nId )
142  ? pDoc->FindCharFormatByName( rStr )
144 
145  if ( bResetMod )
146  {
148  pDoc->SetOle2Link( aOle2Lnk );
149  }
150  }
151 
152  if ( pRet )
153  pRet->Add( this );
154  else
155  EndListeningAll();
156 
157  return pRet;
158 }
159 
160 void SwTextINetFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
161 {
162  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
163  OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
164  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
165  "SwTextINetFormat::Modify(): unknown Modify");
166 
167  if ( m_pTextNode )
168  {
169  SwUpdateAttr aUpdateAttr(
170  GetStart(),
171  *GetEnd(),
172  nWhich);
173 
174  m_pTextNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
175  }
176 }
177 
179 {
180  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
181  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
182 }
183 
185 {
186  return m_pTextNode && m_pTextNode->IsProtect();
187 }
188 
190  sal_Int32 nStart, sal_Int32 nEnd )
191  : SwTextAttr( rAttr, nStart )
192  , SwTextAttrNesting( rAttr, nStart, nEnd )
193  , SwClient( nullptr )
194  , m_pTextNode( nullptr )
195 {
196  rAttr.m_pTextAttr = this;
197 }
198 
200 {
201 }
202 
203 void SwTextRuby::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew )
204 {
205  const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0;
206  OSL_ENSURE( isCHRATR(nWhich) || (RES_OBJECTDYING == nWhich)
207  || (RES_ATTRSET_CHG == nWhich) || (RES_FMT_CHG == nWhich),
208  "SwTextRuby::Modify(): unknown Modify");
209 
210  if ( m_pTextNode )
211  {
212  SwUpdateAttr aUpdateAttr(
213  GetStart(),
214  *GetEnd(),
215  nWhich);
216 
217  m_pTextNode->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
218  }
219 }
220 
221 bool SwTextRuby::GetInfo( SfxPoolItem& rInfo ) const
222 {
223  return RES_AUTOFMT_DOCNODE != rInfo.Which() || !m_pTextNode ||
224  &m_pTextNode->GetNodes() != static_cast<SwAutoFormatGetDocNode&>(rInfo).pNodes;
225 }
226 
228 {
229  const SwFormatRuby& rFormat = SwTextAttrEnd::GetRuby();
230  SwCharFormat* pRet = nullptr;
231 
232  if( !rFormat.GetText().isEmpty() )
233  {
234  const SwDoc* pDoc = GetTextNode().GetDoc();
235  const OUString& rStr = rFormat.GetCharFormatName();
236  const sal_uInt16 nId = rStr.isEmpty()
237  ? static_cast<sal_uInt16>(RES_POOLCHR_RUBYTEXT)
238  : rFormat.GetCharFormatId();
239 
240  // JP 10.02.2000, Bug 72806: don't modify the doc for getting the
241  // correct charstyle.
242  const bool bResetMod = !pDoc->getIDocumentState().IsModified();
243  Link<bool,void> aOle2Lnk;
244  if( bResetMod )
245  {
246  aOle2Lnk = pDoc->GetOle2Link();
247  const_cast<SwDoc*>(pDoc)->SetOle2Link( Link<bool,void>() );
248  }
249 
250  pRet = IsPoolUserFormat( nId )
251  ? pDoc->FindCharFormatByName( rStr )
252  : const_cast<SwDoc*>(pDoc)->getIDocumentStylePoolAccess().GetCharFormatFromPool( nId );
253 
254  if( bResetMod )
255  {
256  const_cast<SwDoc*>(pDoc)->getIDocumentState().ResetModified();
257  const_cast<SwDoc*>(pDoc)->SetOle2Link( aOle2Lnk );
258  }
259  }
260 
261  if( pRet )
262  pRet->Add( this );
263  else
264  EndListeningAll();
265 
266  return pRet;
267 }
268 
269 SwTextMeta *
271  ::sw::MetaFieldManager & i_rTargetDocManager,
272  SwTextNode *const i_pTargetTextNode,
273  SwFormatMeta & i_rAttr,
274  sal_Int32 const i_nStart,
275  sal_Int32 const i_nEnd,
276  bool const i_bIsCopy)
277 {
278  if (i_bIsCopy)
279  { // i_rAttr is already cloned, now call DoCopy to copy the sw::Meta
280  OSL_ENSURE(i_pTargetTextNode, "cannot copy Meta without target node");
281  i_rAttr.DoCopy(i_rTargetDocManager, *i_pTargetTextNode);
282  }
283  SwTextMeta *const pTextMeta(new SwTextMeta(i_rAttr, i_nStart, i_nEnd));
284  return pTextMeta;
285 }
286 
288  const sal_Int32 i_nStart, const sal_Int32 i_nEnd )
289  : SwTextAttr( i_rAttr, i_nStart )
290  , SwTextAttrNesting( i_rAttr, i_nStart, i_nEnd )
291 {
292  i_rAttr.SetTextAttr( this );
293  SetHasDummyChar(true);
294 }
295 
297 {
298  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
299  if (rFormatMeta.GetTextAttr() == this)
300  {
301  rFormatMeta.SetTextAttr(nullptr);
302  }
303 }
304 
306 {
307  SwFormatMeta & rFormatMeta( static_cast<SwFormatMeta &>(GetAttr()) );
308  if (rFormatMeta.GetTextAttr() == this)
309  {
310  rFormatMeta.NotifyChangeTextNode(pNode);
311  }
312 }
313 
314 /* 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:270
const OUString & GetCharFormatName() const
Definition: fmtruby.hxx:64
bool GetInfo(SfxPoolItem const &rInfo) const
Definition: txtatr2.cxx:70
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
void SetDontExpand(bool bDontExpand)
Definition: txatbase.hxx:171
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:110
SwTextCharFormat(SwFormatCharFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:37
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:100
virtual ~SwTextINetFormat() override
Definition: txtatr2.cxx:106
virtual void ModifyNotification(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: node.hxx:475
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:471
void SetHasDummyChar(const bool bFlag)
Definition: txatbase.hxx:72
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: txtatr2.cxx:203
SwTextNode * m_pTextNode
Definition: txtatr.hxx:76
void DoCopy(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode &i_rTargetTextNode)
this method must be called when the hint is actually copied
Definition: fmtatr2.cxx:607
SwTextAttrNesting(SfxPoolItem &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:76
knows all meta-fields in the document.
Definition: fmtmeta.hxx:198
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:96
bool IsPoolUserFormat(sal_uInt16 nId)
Definition: poolfmt.hxx:87
void NotifyChangeTextNode(SwTextNode *const pTextNode)
notify clients registered at m_pMeta that this meta is being (re-)moved
Definition: fmtatr2.cxx:594
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:199
virtual ~SwTextAttrNesting() override
Definition: txtatr2.cxx:89
bool IsProtect() const
Definition: txtatr2.cxx:184
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
void ModifyNotification(const SfxPoolItem *, const SfxPoolItem *)
Definition: txtatr2.cxx:52
void SetNesting(const bool bFlag)
Definition: txatbase.hxx:71
IDocumentStylePoolAccess const & getIDocumentStylePoolAccess() const
Definition: doc.cxx:425
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
SwTextMeta(SwFormatMeta &i_rAttr, const sal_Int32 i_nStart, const sal_Int32 i_nEnd)
Definition: txtatr2.cxx:287
void ChgTextNode(SwTextNode *const pNode)
Definition: txtatr2.cxx:305
void EndListeningAll()
Definition: calbck.cxx:124
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:189
sal_uInt16 GetVisitedFormatId() const
Definition: fmtinfmt.hxx:125
void SetVisited(bool bNew)
Definition: txtinet.hxx:56
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
SwDoc * GetDoc()
Definition: node.hxx:702
IDocumentState const & getIDocumentState() const
Definition: doc.cxx:393
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: txtatr2.cxx:160
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
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:419
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
SwTextNode * m_pTextNode
Definition: txtatr.hxx:35
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: txtatr2.cxx:221
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:571
SwTextINetFormat(SwFormatINetFormat &rAttr, sal_Int32 nStart, sal_Int32 nEnd)
Definition: txtatr2.cxx:93
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:178
SwCharFormat * GetCharFormat()
Definition: txtatr2.cxx:227
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:296
virtual void ResetModified()=0