LibreOffice Module sw (master)  1
fmtatr2.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 <libxml/xmlwriter.h>
21 #include <hintids.hxx>
22 #include <poolfmt.hxx>
23 #include <unomid.h>
24 
25 #include <o3tl/any.hxx>
26 #include <svl/macitem.hxx>
27 #include <svl/stylepool.hxx>
28 #include <fmtautofmt.hxx>
29 #include <fchrfmt.hxx>
30 #include <fmtinfmt.hxx>
31 #include <txtatr.hxx>
32 #include <fmtruby.hxx>
33 #include <charfmt.hxx>
34 #include <hints.hxx>
35 #include <unoevent.hxx>
36 #include <com/sun/star/text/RubyAdjust.hpp>
37 #include <com/sun/star/text/RubyPosition.hpp>
38 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
39 #include <com/sun/star/util/XCloneable.hpp>
40 #include <com/sun/star/frame/XModel.hpp>
41 
42 #include <com/sun/star/uno/Any.h>
43 #include <SwStyleNameMapper.hxx>
44 
45 #include <fmtmeta.hxx>
46 #include <ndtxt.hxx>
47 #include <doc.hxx>
48 #include <unometa.hxx>
49 #include <docsh.hxx>
50 #include <osl/diagnose.h>
51 
52 #include <algorithm>
53 
54 using namespace ::com::sun::star;
55 
56 
58 
61  SwClient(pFormat),
62  m_pTextAttribute( nullptr )
63 {
64 }
65 
68  SwClient( rAttr.GetCharFormat() ),
69  m_pTextAttribute( nullptr )
70 {
71 }
72 
74 
75 bool SwFormatCharFormat::operator==( const SfxPoolItem& rAttr ) const
76 {
77  assert(SfxPoolItem::operator==(rAttr));
78  return GetCharFormat() == static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
79 }
80 
82 {
83  return new SwFormatCharFormat( *this );
84 }
85 
86 // forward to the TextAttribute
87 void SwFormatCharFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
88 {
89  if( m_pTextAttribute )
90  m_pTextAttribute->ModifyNotification( pOld, pNew );
91 }
92 
93 // forward to the TextAttribute
95 {
96  return m_pTextAttribute && m_pTextAttribute->GetInfo( rInfo );
97 }
99 {
100  OUString sCharFormatName;
101  if(GetCharFormat())
103  rVal <<= sCharFormatName;
104  return true;
105 }
107 {
108  OSL_FAIL("format cannot be set with PutValue!");
109  return false;
110 }
111 
113  : SfxPoolItem( nInitWhich )
114 {
115 }
116 
117 bool SwFormatAutoFormat::operator==( const SfxPoolItem& rAttr ) const
118 {
119  assert(SfxPoolItem::operator==(rAttr));
120  return mpHandle == static_cast<const SwFormatAutoFormat&>(rAttr).mpHandle;
121 }
122 
124 {
125  return new SwFormatAutoFormat( *this );
126 }
127 
129 {
130  rVal <<= StylePool::nameOf( mpHandle );
131  return true;
132 }
133 
135 {
136  //the format is not renameable via API
137  return false;
138 }
139 
141 {
142  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatAutoFormat"));
143  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
144  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
145  mpHandle->dumpAsXml(pWriter);
146  xmlTextWriterEndElement(pWriter);
147 }
148 
151  , msURL()
152  , msTargetFrame()
153  , msINetFormatName()
154  , msVisitedFormatName()
155  , msHyperlinkName()
156  , mpTextAttr( nullptr )
157  , mnINetFormatId( 0 )
158  , mnVisitedFormatId( 0 )
159 {}
160 
161 SwFormatINetFormat::SwFormatINetFormat( const OUString& rURL, const OUString& rTarget )
163  , msURL( rURL )
164  , msTargetFrame( rTarget )
165  , msINetFormatName()
166  , msVisitedFormatName()
167  , msHyperlinkName()
168  , mpTextAttr( nullptr )
169  , mnINetFormatId( RES_POOLCHR_INET_NORMAL )
170  , mnVisitedFormatId( RES_POOLCHR_INET_VISIT )
171 {
174 }
175 
178  , sw::BroadcasterMixin()
179  , msURL( rAttr.GetValue() )
180  , msTargetFrame( rAttr.msTargetFrame )
181  , msINetFormatName( rAttr.msINetFormatName )
182  , msVisitedFormatName( rAttr.msVisitedFormatName )
183  , msHyperlinkName( rAttr.msHyperlinkName )
184  , mpTextAttr( nullptr )
185  , mnINetFormatId( rAttr.mnINetFormatId )
186  , mnVisitedFormatId( rAttr.mnVisitedFormatId )
187 {
188  if ( rAttr.GetMacroTable() )
189  mpMacroTable.reset( new SvxMacroTableDtor( *rAttr.GetMacroTable() ) );
190 }
191 
193 {
194 }
195 
196 bool SwFormatINetFormat::operator==( const SfxPoolItem& rAttr ) const
197 {
198  assert(SfxPoolItem::operator==(rAttr));
199  bool bRet = SfxPoolItem::operator==( rAttr )
200  && msURL == static_cast<const SwFormatINetFormat&>(rAttr).msURL
201  && msHyperlinkName == static_cast<const SwFormatINetFormat&>(rAttr).msHyperlinkName
202  && msTargetFrame == static_cast<const SwFormatINetFormat&>(rAttr).msTargetFrame
203  && msINetFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msINetFormatName
204  && msVisitedFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msVisitedFormatName
205  && mnINetFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnINetFormatId
206  && mnVisitedFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnVisitedFormatId;
207 
208  if( !bRet )
209  return false;
210 
211  const SvxMacroTableDtor* pOther = static_cast<const SwFormatINetFormat&>(rAttr).mpMacroTable.get();
212  if( !mpMacroTable )
213  return ( !pOther || pOther->empty() );
214  if( !pOther )
215  return mpMacroTable->empty();
216 
217  const SvxMacroTableDtor& rOwn = *mpMacroTable;
218  const SvxMacroTableDtor& rOther = *pOther;
219 
220  return rOwn == rOther;
221 }
222 
224 {
225  return new SwFormatINetFormat( *this );
226 }
227 
229 {
230  if( pNewTable )
231  {
232  if( mpMacroTable )
233  *mpMacroTable = *pNewTable;
234  else
235  mpMacroTable.reset( new SvxMacroTableDtor( *pNewTable ) );
236  }
237  else
238  {
239  mpMacroTable.reset();
240  }
241 }
242 
244 {
245  if( !mpMacroTable )
246  mpMacroTable.reset( new SvxMacroTableDtor );
247 
248  mpMacroTable->Insert( nEvent, rMacro );
249 }
250 
252 {
253  const SvxMacro* pRet = nullptr;
254  if( mpMacroTable && mpMacroTable->IsKeyValid( nEvent ) )
255  pRet = mpMacroTable->Get( nEvent );
256  return pRet;
257 }
258 
259 bool SwFormatINetFormat::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
260 {
261  nMemberId &= ~CONVERT_TWIPS;
262  switch(nMemberId)
263  {
264  case MID_URL_URL:
265  rVal <<= msURL;
266  break;
267  case MID_URL_TARGET:
268  rVal <<= msTargetFrame;
269  break;
271  rVal <<= msHyperlinkName;
272  break;
273  case MID_URL_VISITED_FMT:
274  {
275  OUString sVal = msVisitedFormatName;
276  if (sVal.isEmpty() && mnVisitedFormatId != 0)
278  if (!sVal.isEmpty())
281  rVal <<= sVal;
282  }
283  break;
285  {
286  OUString sVal = msINetFormatName;
287  if (sVal.isEmpty() && mnINetFormatId != 0)
289  if (!sVal.isEmpty())
292  rVal <<= sVal;
293  }
294  break;
296  {
297  // create (and return) event descriptor
298  SwHyperlinkEventDescriptor* pEvents =
300  pEvents->copyMacrosFromINetFormat(*this);
301  uno::Reference<container::XNameReplace> xNameReplace(pEvents);
302 
303  // all others return a string; so we just set rVal here and exit
304  rVal <<= xNameReplace;
305  }
306  break;
307  default:
308  rVal <<= OUString();
309  break;
310  }
311  return true;
312 }
313 bool SwFormatINetFormat::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
314 {
315  bool bRet = true;
316  nMemberId &= ~CONVERT_TWIPS;
317 
318  // all properties except HyperlinkEvents are of type string, hence
319  // we treat HyperlinkEvents specially
320  if (MID_URL_HYPERLINKEVENTS == nMemberId)
321  {
322  uno::Reference<container::XNameReplace> xReplace;
323  rVal >>= xReplace;
324  if (xReplace.is())
325  {
326  // Create hyperlink event descriptor. Then copy events
327  // from argument into descriptor. Then copy events from
328  // the descriptor into the format.
330  pEvents->copyMacrosFromNameReplace(xReplace);
331  pEvents->copyMacrosIntoINetFormat(*this);
332  }
333  else
334  {
335  // wrong type!
336  bRet = false;
337  }
338  }
339  else
340  {
341  // all string properties:
342  if(rVal.getValueType() != ::cppu::UnoType<OUString>::get())
343  return false;
344 
345  switch(nMemberId)
346  {
347  case MID_URL_URL:
348  rVal >>= msURL;
349  break;
350  case MID_URL_TARGET:
351  rVal >>= msTargetFrame;
352  break;
354  rVal >>= msHyperlinkName;
355  break;
356  case MID_URL_VISITED_FMT:
357  {
358  OUString sVal;
359  rVal >>= sVal;
360  OUString aString;
362  msVisitedFormatName = aString;
365  }
366  break;
368  {
369  OUString sVal;
370  rVal >>= sVal;
371  OUString aString;
373  msINetFormatName = aString;
375  }
376  break;
377  default:
378  bRet = false;
379  }
380  }
381  return bRet;
382 }
383 
384 SwFormatRuby::SwFormatRuby( const OUString& rRubyText )
386  m_sRubyText( rRubyText ),
387  m_pTextAttr( nullptr ),
388  m_nCharFormatId( 0 ),
389  m_nPosition( 0 ),
390  m_eAdjustment( css::text::RubyAdjust_LEFT )
391 {
392 }
393 
396  m_sRubyText( rAttr.m_sRubyText ),
397  m_sCharFormatName( rAttr.m_sCharFormatName ),
398  m_pTextAttr( nullptr ),
399  m_nCharFormatId( rAttr.m_nCharFormatId),
400  m_nPosition( rAttr.m_nPosition ),
401  m_eAdjustment( rAttr.m_eAdjustment )
402 {
403 }
404 
406 {
407 }
408 
410 {
411  if(this == &rAttr)
412  return *this;
413 
414  m_sRubyText = rAttr.m_sRubyText;
417  m_nPosition = rAttr.m_nPosition;
419  m_pTextAttr = nullptr;
420  return *this;
421 }
422 
423 bool SwFormatRuby::operator==( const SfxPoolItem& rAttr ) const
424 {
425  assert(SfxPoolItem::operator==(rAttr));
426  return m_sRubyText == static_cast<const SwFormatRuby&>(rAttr).m_sRubyText &&
427  m_sCharFormatName == static_cast<const SwFormatRuby&>(rAttr).m_sCharFormatName &&
428  m_nCharFormatId == static_cast<const SwFormatRuby&>(rAttr).m_nCharFormatId &&
429  m_nPosition == static_cast<const SwFormatRuby&>(rAttr).m_nPosition &&
430  m_eAdjustment == static_cast<const SwFormatRuby&>(rAttr).m_eAdjustment;
431 }
432 
434 {
435  return new SwFormatRuby( *this );
436 }
437 
439  sal_uInt8 nMemberId ) const
440 {
441  bool bRet = true;
442  nMemberId &= ~CONVERT_TWIPS;
443  switch( nMemberId )
444  {
445  case MID_RUBY_TEXT: rVal <<= m_sRubyText; break;
446  case MID_RUBY_ADJUST: rVal <<= static_cast<sal_Int16>(m_eAdjustment); break;
447  case MID_RUBY_CHARSTYLE:
448  {
449  OUString aString;
451  rVal <<= aString;
452  }
453  break;
454  case MID_RUBY_ABOVE:
455  {
456  rVal <<= static_cast<bool>(!m_nPosition);
457  }
458  break;
459  case MID_RUBY_POSITION:
460  {
461  rVal <<= m_nPosition;
462  }
463  break;
464  default:
465  bRet = false;
466  }
467  return bRet;
468 }
470  sal_uInt8 nMemberId )
471 {
472  bool bRet = true;
473  nMemberId &= ~CONVERT_TWIPS;
474  switch( nMemberId )
475  {
476  case MID_RUBY_TEXT:
477  bRet = rVal >>= m_sRubyText;
478  break;
479  case MID_RUBY_ADJUST:
480  {
481  sal_Int16 nSet = 0;
482  rVal >>= nSet;
483  if(nSet >= sal_Int16(text::RubyAdjust_LEFT) && nSet <= sal_Int16(text::RubyAdjust_INDENT_BLOCK))
484  m_eAdjustment = static_cast<text::RubyAdjust>(nSet);
485  else
486  bRet = false;
487  }
488  break;
489  case MID_RUBY_ABOVE:
490  {
491  const uno::Type& rType = cppu::UnoType<bool>::get();
492  if(rVal.hasValue() && rVal.getValueType() == rType)
493  {
494  bool bAbove = *o3tl::doAccess<bool>(rVal);
495  m_nPosition = bAbove ? 0 : 1;
496  }
497  }
498  break;
499  case MID_RUBY_POSITION:
500  {
501  sal_Int16 nSet = 0;
502  rVal >>= nSet;
503  if(nSet >= sal_Int16(text::RubyPosition::ABOVE) && nSet <= sal_Int16(text::RubyPosition::INTER_CHARACTER))
504  m_nPosition = nSet;
505  else
506  bRet = false;
507  }
508  break;
509  case MID_RUBY_CHARSTYLE:
510  {
511  OUString sTmp;
512  bRet = rVal >>= sTmp;
513  if(bRet)
515  }
516  break;
517  default:
518  bRet = false;
519  }
520  return bRet;
521 }
522 
523 SwFormatMeta * SwFormatMeta::CreatePoolDefault(const sal_uInt16 i_nWhich)
524 {
525  return new SwFormatMeta(i_nWhich);
526 }
527 
528 SwFormatMeta::SwFormatMeta(const sal_uInt16 i_nWhich)
529  : SfxPoolItem( i_nWhich )
530  , m_pMeta()
531  , m_pTextAttr( nullptr )
532 {
533  OSL_ENSURE((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
534  "ERROR: SwFormatMeta: invalid which id!");
535 }
536 
537 SwFormatMeta::SwFormatMeta( std::shared_ptr< ::sw::Meta > const & i_pMeta,
538  const sal_uInt16 i_nWhich )
539  : SfxPoolItem( i_nWhich )
540  , m_pMeta( i_pMeta )
541  , m_pTextAttr( nullptr )
542 {
543  OSL_ENSURE((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
544  "ERROR: SwFormatMeta: invalid which id!");
545  OSL_ENSURE(m_pMeta, "SwFormatMeta: no Meta ?");
546  // DO NOT call m_pMeta->SetFormatMeta(this) here; only from SetTextAttr!
547 }
548 
550 {
551  if (m_pMeta && (m_pMeta->GetFormatMeta() == this))
552  {
553  NotifyChangeTextNode(nullptr);
554  m_pMeta->SetFormatMeta(nullptr);
555  }
556 }
557 
558 bool SwFormatMeta::operator==( const SfxPoolItem & i_rOther ) const
559 {
560  return SfxPoolItem::operator==( i_rOther )
561  && m_pMeta == static_cast<SwFormatMeta const &>( i_rOther ).m_pMeta;
562 }
563 
565 {
566  // if this is indeed a copy, then DoCopy must be called later!
567  return m_pMeta // #i105148# pool default may be cloned also!
568  ? new SwFormatMeta( m_pMeta, Which() ) : new SwFormatMeta( Which() );
569 }
570 
571 void SwFormatMeta::SetTextAttr(SwTextMeta * const i_pTextAttr)
572 {
573  OSL_ENSURE(!(m_pTextAttr && i_pTextAttr),
574  "SwFormatMeta::SetTextAttr: already has text attribute?");
575  OSL_ENSURE( m_pTextAttr || i_pTextAttr ,
576  "SwFormatMeta::SetTextAttr: no attribute to remove?");
577  m_pTextAttr = i_pTextAttr;
578  OSL_ENSURE(m_pMeta, "inserted SwFormatMeta has no sw::Meta?");
579  // the sw::Meta must be able to find the current text attribute!
580  if (m_pMeta)
581  {
582  if (i_pTextAttr)
583  {
584  m_pMeta->SetFormatMeta(this);
585  }
586  else if (m_pMeta->GetFormatMeta() == this)
587  { // text attribute gone => de-register from text node!
588  NotifyChangeTextNode(nullptr);
589  m_pMeta->SetFormatMeta(nullptr);
590  }
591  }
592 }
593 
595 {
596  // N.B.: do not reset m_pTextAttr here: see call in nodes.cxx,
597  // where the hint is not deleted!
598  OSL_ENSURE(m_pMeta, "SwFormatMeta::NotifyChangeTextNode: no Meta?");
599  if (m_pMeta && (m_pMeta->GetFormatMeta() == this))
600  { // do not call Modify, that would call SwXMeta::Modify!
601  m_pMeta->NotifyChangeTextNode(pTextNode);
602  }
603 }
604 
605 // this SwFormatMeta has been cloned and points at the same sw::Meta as the source
606 // this method copies the sw::Meta
607 void SwFormatMeta::DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
608  SwTextNode & i_rTargetTextNode)
609 {
610  OSL_ENSURE(m_pMeta, "DoCopy called for SwFormatMeta with no sw::Meta?");
611  if (m_pMeta)
612  {
613  const std::shared_ptr< ::sw::Meta> pOriginal( m_pMeta );
614  if (RES_TXTATR_META == Which())
615  {
616  m_pMeta = std::make_shared<::sw::Meta>(this);
617  }
618  else
619  {
620  ::sw::MetaField *const pMetaField(
621  static_cast< ::sw::MetaField* >(pOriginal.get()));
622  m_pMeta = i_rTargetDocManager.makeMetaField( this,
623  pMetaField->m_nNumberFormat, pMetaField->IsFixedLanguage() );
624  }
625  // Meta must have a text node before calling RegisterAsCopyOf
626  m_pMeta->NotifyChangeTextNode(& i_rTargetTextNode);
627  // this cannot be done in Clone: a Clone is not necessarily a copy!
628  m_pMeta->RegisterAsCopyOf(*pOriginal);
629  }
630 }
631 
632 namespace sw {
633 
634 Meta::Meta(SwFormatMeta * const i_pFormat)
635  : ::sfx2::Metadatable()
636  , SwModify()
637  , m_pFormat(i_pFormat)
638  , m_pTextNode(nullptr)
639 {
640 }
641 
643 {
644 }
645 
647 {
648  return m_pFormat ? m_pFormat->GetTextAttr() : nullptr;
649 }
650 
651 
653 {
654  m_pTextNode = pTextNode;
656  {
657  m_pTextNode->Add(this);
658  }
659  else if (!m_pTextNode)
660  {
661  EndListeningAll();
662  }
663  if (!pTextNode) // text node gone? invalidate UNO object!
664  {
665  GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
666  }
667 }
668 
669 // SwClient
670 void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew )
671 {
672  NotifyClients(pOld, pNew);
673  GetNotifier().Broadcast(SfxHint(SfxHintId::DataChanged));
674  if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
675  { // invalidate cached uno object
676  SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr));
677  GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
678  }
679 }
680 
681 // sfx2::Metadatable
683 {
684  SwTextNode * const pTextNode( GetTextNode() );
685  // GetRegistry may only be called on a meta that is actually in the
686  // document, which means it has a pointer to its text node
687  OSL_ENSURE(pTextNode, "ERROR: GetRegistry: no text node?");
688  if (!pTextNode)
689  throw uno::RuntimeException();
690  return pTextNode->GetRegistry();
691 }
692 
694 {
695  const SwTextNode * const pTextNode( GetTextNode() );
696 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInClipboard: no text node?");
697  return pTextNode && pTextNode->IsInClipboard();
698 }
699 
700 bool Meta::IsInUndo() const
701 {
702  const SwTextNode * const pTextNode( GetTextNode() );
703 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInUndo: no text node?");
704  return pTextNode == nullptr || pTextNode->IsInUndo();
705 }
706 
707 bool Meta::IsInContent() const
708 {
709  const SwTextNode * const pTextNode( GetTextNode() );
710  OSL_ENSURE(pTextNode, "IsInContent: no text node?");
711  return pTextNode == nullptr || pTextNode->IsInContent();
712 }
713 
714 css::uno::Reference< css::rdf::XMetadatable > Meta::MakeUnoObject()
715 {
716  return SwXMeta::CreateXMeta(*this);
717 }
718 
720  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
721  : Meta(i_pFormat)
722  , m_nNumberFormat( nNumberFormat )
723  , m_bIsFixedLanguage( bIsFixedLanguage )
724 {
725 }
726 
728  OUString *const o_pPrefix, OUString *const o_pSuffix)
729 {
730  try
731  {
732  const uno::Reference<rdf::XMetadatable> xMetaField( MakeUnoObject() );
733  OSL_ENSURE(dynamic_cast<SwXMetaField*>(xMetaField.get()),
734  "GetPrefixAndSuffix: no SwXMetaField?");
735  if (xMetaField.is())
736  {
737  SwTextNode * const pTextNode( GetTextNode() );
738  SwDocShell const * const pShell(pTextNode->GetDoc()->GetDocShell());
739  const uno::Reference<frame::XModel> xModel(
740  pShell ? pShell->GetModel() : nullptr, uno::UNO_SET_THROW);
741  getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
742  }
743  }
744  catch (const uno::Exception&)
745  {
746  OSL_FAIL("exception?");
747  }
748 }
749 
750 sal_uInt32 MetaField::GetNumberFormat(OUString const & rContent) const
751 {
752  //TODO: this probably lacks treatment for some special cases
753  sal_uInt32 nNumberFormat( m_nNumberFormat );
754  SwTextNode * const pTextNode( GetTextNode() );
755  if (pTextNode)
756  {
757  double number;
758  (void) pTextNode->GetDoc()->IsNumberFormat( rContent, nNumberFormat, number );
759  }
760  return nNumberFormat;
761 }
762 
763 void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat)
764 {
765  // effectively, the member is only a default:
766  // GetNumberFormat checks if the text actually conforms
767  m_nNumberFormat = nNumberFormat;
768 }
769 
771 {
772 }
773 
774 std::shared_ptr<MetaField>
776  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
777 {
778  const std::shared_ptr<MetaField> pMetaField(
779  new MetaField(i_pFormat, nNumberFormat, bIsFixedLanguage) );
780  m_MetaFields.push_back(pMetaField);
781  return pMetaField;
782 }
783 
784 namespace {
785 
786 struct IsInUndo
787 {
788  bool operator()(std::weak_ptr<MetaField> const & pMetaField) {
789  return pMetaField.lock()->IsInUndo();
790  }
791 };
792 
793 struct MakeUnoObject
794 {
795  uno::Reference<text::XTextField>
796  operator()(std::weak_ptr<MetaField> const & pMetaField) {
797  return uno::Reference<text::XTextField>(
798  pMetaField.lock()->MakeUnoObject(), uno::UNO_QUERY);
799  }
800 };
801 
802 }
803 
804 std::vector< uno::Reference<text::XTextField> >
806 {
807  // erase deleted fields
808  const MetaFieldList_t::iterator iter(
809  std::remove_if(m_MetaFields.begin(), m_MetaFields.end(),
810  [] (std::weak_ptr<MetaField> const& rField) { return rField.expired(); }));
811  m_MetaFields.erase(iter, m_MetaFields.end());
812  // filter out fields in UNDO
813  MetaFieldList_t filtered(m_MetaFields.size());
814  const MetaFieldList_t::iterator iter2(
815  std::remove_copy_if(m_MetaFields.begin(), m_MetaFields.end(),
816  filtered.begin(), IsInUndo()));
817  filtered.erase(iter2, filtered.end());
818  // create uno objects
819  std::vector< uno::Reference<text::XTextField> > ret(filtered.size());
820  std::transform(filtered.begin(), filtered.end(), ret.begin(),
821  MakeUnoObject());
822  return ret;
823 }
824 
826 {
827  const SwDocShell* pDocShell = rSource.GetDocShell();
828  if (!pDocShell)
829  return;
830 
831  uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(pDocShell->GetModel(), uno::UNO_QUERY);
832  uno::Reference<util::XCloneable> xCloneable(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
833  m_xDocumentProperties.set(xCloneable->createClone(), uno::UNO_QUERY);
834 }
835 
836 const uno::Reference<document::XDocumentProperties>& MetaFieldManager::getDocumentProperties() const
837 {
838  return m_xDocumentProperties;
839 }
840 
841 } // namespace sw
842 
843 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static css::uno::Reference< css::rdf::XMetadatable > CreateXMeta(::sw::Meta &rMeta, css::uno::Reference< css::text::XText > const &xParentText=nullptr, std::unique_ptr< TextRangeList_t const > &&pPortions=std::unique_ptr< TextRangeList_t const >())
std::shared_ptr< MetaField > makeMetaField(SwFormatMeta *const i_pFormat=nullptr, const sal_uInt32 nNumberFormat=SAL_MAX_UINT32, const bool bIsFixedLanguage=false)
Definition: fmtatr2.cxx:775
static SfxPoolItem * CreateDefault()
Definition: fmtatr2.cxx:57
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: fmtatr2.cxx:75
static SwFormatMeta * CreatePoolDefault(const sal_uInt16 i_nWhich)
Definition: fmtatr2.cxx:523
bool GetInfo(SfxPoolItem const &rInfo) const
Definition: txtatr2.cxx:70
bool hasValue()
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
void GetPrefixAndSuffix(OUString *const o_pPrefix, OUString *const o_pSuffix)
get prefix/suffix from the RDF repository.
Definition: fmtatr2.cxx:727
virtual ~SwFormatINetFormat() override
Definition: fmtatr2.cxx:192
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:100
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:438
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
virtual bool operator==(const SfxPoolItem &) const =0
SwDocShell * GetDocShell()
Definition: doc.hxx:1348
std::string GetValue
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
OUString msINetFormatName
Definition: fmtinfmt.hxx:43
sal_uInt16 mnVisitedFormatId
Definition: fmtinfmt.hxx:49
virtual SwFormatINetFormat * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:223
virtual bool IsInContent() const override
Definition: fmtatr2.cxx:707
virtual SwFormatRuby * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:433
void DoCopy(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode &i_rTargetTextNode)
this method must be called when the hint is actually copied
Definition: fmtatr2.cxx:607
#define MID_RUBY_CHARSTYLE
Definition: unomid.h:115
std::unique_ptr< SvxMacroTableDtor > mpMacroTable
Definition: fmtinfmt.hxx:46
virtual SwFormatMeta * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:564
virtual SwFormatAutoFormat * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:123
knows all meta-fields in the document.
Definition: fmtmeta.hxx:198
#define MID_URL_HYPERLINKNAME
Definition: unomid.h:47
Definition: doc.hxx:184
SwTextCharFormat * m_pTextAttribute
My text attribute.
Definition: fchrfmt.hxx:33
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: fmtatr2.cxx:117
#define MID_RUBY_TEXT
Definition: unomid.h:113
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:134
void NotifyChangeTextNode(SwTextNode *const pTextNode)
notify clients registered at m_pMeta that this meta is being (re-)moved
Definition: fmtatr2.cxx:594
SvMacroItemId
bool IsFixedLanguage() const
Definition: fmtmeta.hxx:184
MetaField(SwFormatMeta *const i_pFormat, const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
Definition: fmtatr2.cxx:719
const SvxMacro * GetMacro(SvMacroItemId nEvent) const
Definition: fmtatr2.cxx:251
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: fmtatr2.cxx:714
Dialog to specify the properties of date form field.
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: fmtatr2.cxx:196
css::uno::Reference< css::frame::XModel > GetModel() const
Meta(SwFormatMeta *const i_pFormat)
Definition: fmtatr2.cxx:634
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: fmtatr2.cxx:87
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:469
#define MID_URL_HYPERLINKEVENTS
Definition: unomid.h:54
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fmtatr2.cxx:140
virtual ~Meta() override
Definition: fmtatr2.cxx:642
virtual bool IsInUndo() const override
Definition: fmtatr2.cxx:700
void getPrefixAndSuffix(const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::rdf::XMetadatable > &xMetaField, OUString *const o_pPrefix, OUString *const o_pSuffix)
get prefix/suffix from the RDF repository.
void SetMacroTable(const SvxMacroTableDtor *pTable)
Set a new MacroTable or clear the current one.
Definition: fmtatr2.cxx:228
SwFormatRuby & operator=(const SwFormatRuby &rAttr)
Definition: fmtatr2.cxx:409
OUString m_sRubyText
void ModifyNotification(const SfxPoolItem *, const SfxPoolItem *)
Definition: txtatr2.cxx:52
SwFormatMeta * m_pFormat
Definition: fmtmeta.hxx:138
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define MID_RUBY_ABOVE
Definition: unomid.h:116
static OUString nameOf(const std::shared_ptr< SfxItemSet > &pSet)
SwFormatAutoFormat(sal_uInt16 nWhich=RES_TXTATR_AUTOFMT)
Definition: fmtatr2.cxx:112
sal_uInt32 m_nNumberFormat
Definition: fmtmeta.hxx:179
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
constexpr TypedWhichId< SwFormatRuby > RES_TXTATR_CJK_RUBY(53)
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:132
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
void EndListeningAll()
Definition: calbck.cxx:124
exports com.sun.star. text
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: fmtatr2.cxx:94
struct _xmlTextWriter * xmlTextWriterPtr
OUString m_sRubyText
The ruby text.
Definition: fmtruby.hxx:32
bool empty() const
virtual bool IsInUndo() const override
Definition: ndtxt.cxx:5243
void Broadcast(const SfxHint &rHint)
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: fmtatr2.cxx:682
Internet visited.
Definition: poolfmt.hxx:122
#define MID_URL_URL
Definition: unomid.h:50
SwTextMeta * GetTextAttr() const
Definition: fmtatr2.cxx:646
void SetXMeta(css::uno::Reference< css::rdf::XMetadatable > const &xMeta)
Definition: fmtmeta.hxx:153
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties of a clipboard document, empty for non-clipboard documents.
Definition: fmtmeta.hxx:204
SwDoc * GetDoc()
Definition: node.hxx:702
Internet normal.
Definition: poolfmt.hxx:121
void NotifyChangeTextNode(SwTextNode *const pTextNode)
Definition: fmtatr2.cxx:652
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: ndtxt.cxx:5233
css::uno::Type const & get()
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:128
OUString m_sCharFormatName
Name of the charformat.
Definition: fmtruby.hxx:33
SwTextNode * GetTextNode() const
Definition: fmtmeta.hxx:144
constexpr TypedWhichId< SwPtrMsgPoolItem > RES_REMOVE_UNO_OBJECT(179)
sal_uInt16 mnINetFormatId
Definition: fmtinfmt.hxx:48
OUString msHyperlinkName
Name of the link.
Definition: fmtinfmt.hxx:45
SwTextNode * m_pTextNode
Definition: fmtmeta.hxx:139
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:167
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:93
SwTextRuby * m_pTextAttr
The TextAttribute.
Definition: fmtruby.hxx:34
SwFormatRuby(const OUString &rRubyText)
Definition: fmtatr2.cxx:384
virtual bool operator==(const SfxPoolItem &) const override
SfxPoolItem.
Definition: fmtatr2.cxx:558
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
virtual bool IsInClipboard() const override
Definition: ndtxt.cxx:5238
void copyDocumentProperties(const SwDoc &rSource)
Copy document properties from rSource to m_xDocumentProperties.
Definition: fmtatr2.cxx:825
void copyMacrosFromINetFormat(const SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:108
virtual bool IsInContent() const override
Definition: ndtxt.cxx:5248
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
SwFormatCharFormat(SwCharFormat *pFormat)
single argument ctors shall be explicit.
Definition: fmtatr2.cxx:59
sal_Int32 m_nPosition
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:98
std::vector< std::weak_ptr< MetaField > > MetaFieldList_t
Definition: fmtmeta.hxx:201
std::vector< css::uno::Reference< css::text::XTextField > > getMetaFields()
get all meta fields
Definition: fmtatr2.cxx:805
unsigned char sal_uInt8
void SetMacro(SvMacroItemId nEvent, const SvxMacro &rMacro)
Macro getter and setter.
Definition: fmtatr2.cxx:243
const css::uno::Reference< css::document::XDocumentProperties > & getDocumentProperties() const
Definition: fmtatr2.cxx:836
std::shared_ptr< ::sw::Meta > m_pMeta
Definition: fmtmeta.hxx:97
virtual SwFormatCharFormat * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:81
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
SwClient.
Definition: fmtatr2.cxx:670
MetaFieldList_t m_MetaFields
Definition: fmtmeta.hxx:202
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:313
static void FillProgName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
#define MID_URL_UNVISITED_FMT
Definition: unomid.h:53
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
sal_uInt32 GetNumberFormat(OUString const &rContent) const
Definition: fmtatr2.cxx:750
OUString msVisitedFormatName
Definition: fmtinfmt.hxx:44
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:571
OUString msTargetFrame
Target frame for URL.
Definition: fmtinfmt.hxx:42
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:259
virtual ~SwFormatRuby() override
Definition: fmtatr2.cxx:405
virtual bool operator==(const SfxPoolItem &) const override
Definition: fmtatr2.cxx:423
bool IsNumberFormat(const OUString &rString, sal_uInt32 &F_Index, double &fOutNumber)
Definition: ndtbl.cxx:4006
virtual ~SwFormatCharFormat() override
Definition: fmtatr2.cxx:73
virtual bool IsInClipboard() const override
Definition: fmtatr2.cxx:693
Reference< XModel > xModel
#define MID_URL_TARGET
Definition: unomid.h:51
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:106
virtual ~SwFormatMeta() override
Definition: fmtatr2.cxx:549
#define MID_RUBY_ADJUST
Definition: unomid.h:114
OUString msURL
URL.
Definition: fmtinfmt.hxx:41
sal_uInt16 m_nCharFormatId
PoolId of the charformat.
Definition: fmtruby.hxx:35
SwTextMeta * m_pTextAttr
Definition: fmtmeta.hxx:98
std::shared_ptr< SfxItemSet > mpHandle
Definition: fmtautofmt.hxx:28
sal_uInt16 Which() const
css::text::RubyAdjust m_eAdjustment
Specific adjustment of the Ruby-ch.
Definition: fmtruby.hxx:37
SwFormatMeta(const sal_uInt16 i_nWhich)
Definition: fmtatr2.cxx:528
void SetNumberFormat(sal_uInt32 nNumberFormat)
Definition: fmtatr2.cxx:763
#define MID_RUBY_POSITION
Definition: unomid.h:117
#define CONVERT_TWIPS
sal_uInt16 m_nPosition
Position of the Ruby-character.
Definition: fmtruby.hxx:36
#define MID_URL_VISITED_FMT
Definition: unomid.h:52
SwFormatINetFormat()
For TypeInfo.
Definition: fmtatr2.cxx:149
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo