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