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