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  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatAutoFormat"));
144  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
145  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
146  mpHandle->dumpAsXml(pWriter);
147  xmlTextWriterEndElement(pWriter);
148 }
149 
152  , msURL()
153  , msTargetFrame()
154  , msINetFormatName()
155  , msVisitedFormatName()
156  , msHyperlinkName()
157  , mpTextAttr( nullptr )
158  , mnINetFormatId( 0 )
159  , mnVisitedFormatId( 0 )
160 {}
161 
162 SwFormatINetFormat::SwFormatINetFormat( const OUString& rURL, const OUString& rTarget )
164  , msURL( rURL )
165  , msTargetFrame( rTarget )
166  , msINetFormatName()
167  , msVisitedFormatName()
168  , msHyperlinkName()
169  , mpTextAttr( nullptr )
170  , mnINetFormatId( RES_POOLCHR_INET_NORMAL )
171  , mnVisitedFormatId( RES_POOLCHR_INET_VISIT )
172 {
175 }
176 
179  , sw::BroadcasterMixin()
180  , msURL( rAttr.GetValue() )
181  , msTargetFrame( rAttr.msTargetFrame )
182  , msINetFormatName( rAttr.msINetFormatName )
183  , msVisitedFormatName( rAttr.msVisitedFormatName )
184  , msHyperlinkName( rAttr.msHyperlinkName )
185  , mpTextAttr( nullptr )
186  , mnINetFormatId( rAttr.mnINetFormatId )
187  , mnVisitedFormatId( rAttr.mnVisitedFormatId )
188 {
189  if ( rAttr.GetMacroTable() )
190  mpMacroTable.reset( new SvxMacroTableDtor( *rAttr.GetMacroTable() ) );
191 }
192 
194 {
195 }
196 
197 bool SwFormatINetFormat::operator==( const SfxPoolItem& rAttr ) const
198 {
199  assert(SfxPoolItem::operator==(rAttr));
200  bool bRet = SfxPoolItem::operator==( rAttr )
201  && msURL == static_cast<const SwFormatINetFormat&>(rAttr).msURL
202  && msHyperlinkName == static_cast<const SwFormatINetFormat&>(rAttr).msHyperlinkName
203  && msTargetFrame == static_cast<const SwFormatINetFormat&>(rAttr).msTargetFrame
204  && msINetFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msINetFormatName
205  && msVisitedFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msVisitedFormatName
206  && mnINetFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnINetFormatId
207  && mnVisitedFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnVisitedFormatId;
208 
209  if( !bRet )
210  return false;
211 
212  const SvxMacroTableDtor* pOther = static_cast<const SwFormatINetFormat&>(rAttr).mpMacroTable.get();
213  if( !mpMacroTable )
214  return ( !pOther || pOther->empty() );
215  if( !pOther )
216  return mpMacroTable->empty();
217 
218  const SvxMacroTableDtor& rOwn = *mpMacroTable;
219  const SvxMacroTableDtor& rOther = *pOther;
220 
221  return rOwn == rOther;
222 }
223 
225 {
226  return new SwFormatINetFormat( *this );
227 }
228 
230 {
231  if( pNewTable )
232  {
233  if( mpMacroTable )
234  *mpMacroTable = *pNewTable;
235  else
236  mpMacroTable.reset( new SvxMacroTableDtor( *pNewTable ) );
237  }
238  else
239  {
240  mpMacroTable.reset();
241  }
242 }
243 
245 {
246  if( !mpMacroTable )
247  mpMacroTable.reset( new SvxMacroTableDtor );
248 
249  mpMacroTable->Insert( nEvent, rMacro );
250 }
251 
253 {
254  const SvxMacro* pRet = nullptr;
255  if( mpMacroTable && mpMacroTable->IsKeyValid( nEvent ) )
256  pRet = mpMacroTable->Get( nEvent );
257  return pRet;
258 }
259 
260 bool SwFormatINetFormat::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
261 {
262  nMemberId &= ~CONVERT_TWIPS;
263  switch(nMemberId)
264  {
265  case MID_URL_URL:
266  rVal <<= msURL;
267  break;
268  case MID_URL_TARGET:
269  rVal <<= msTargetFrame;
270  break;
272  rVal <<= msHyperlinkName;
273  break;
274  case MID_URL_VISITED_FMT:
275  {
276  OUString sVal = msVisitedFormatName;
277  if (sVal.isEmpty() && mnVisitedFormatId != 0)
279  if (!sVal.isEmpty())
282  rVal <<= sVal;
283  }
284  break;
286  {
287  OUString sVal = msINetFormatName;
288  if (sVal.isEmpty() && mnINetFormatId != 0)
290  if (!sVal.isEmpty())
293  rVal <<= sVal;
294  }
295  break;
297  {
298  // create (and return) event descriptor
301  pEvents->copyMacrosFromINetFormat(*this);
302 
303  // all others return a string; so we just set rVal here and exit
304  rVal <<= uno::Reference<container::XNameReplace>(pEvents);
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::SwClientNotify
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  return;
613 
614  const std::shared_ptr< ::sw::Meta> pOriginal( m_pMeta );
615  if (RES_TXTATR_META == Which())
616  {
617  m_pMeta = std::make_shared<::sw::Meta>(this);
618  }
619  else
620  {
621  ::sw::MetaField *const pMetaField(
622  static_cast< ::sw::MetaField* >(pOriginal.get()));
623  m_pMeta = i_rTargetDocManager.makeMetaField( this,
624  pMetaField->m_nNumberFormat, pMetaField->IsFixedLanguage() );
625  }
626  // Meta must have a text node before calling RegisterAsCopyOf
627  m_pMeta->NotifyChangeTextNode(& i_rTargetTextNode);
628  // this cannot be done in Clone: a Clone is not necessarily a copy!
629  m_pMeta->RegisterAsCopyOf(*pOriginal);
630 }
631 
632 namespace sw {
633 
634 Meta::Meta(SwFormatMeta * const i_pFormat)
635  : ::sfx2::Metadatable()
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 void Meta::SwClientNotify(const SwModify&, const SfxHint& rHint)
670 {
671  auto pLegacy = dynamic_cast<const sw::LegacyModifyHint*>(&rHint);
672  if(!pLegacy)
673  return;
674  CallSwClientNotify(rHint);
675  GetNotifier().Broadcast(SfxHint(SfxHintId::DataChanged));
676  if(RES_REMOVE_UNO_OBJECT == pLegacy->GetWhich())
677  { // invalidate cached uno object
678  SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr));
679  GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
680  }
681 }
682 
683 // sfx2::Metadatable
685 {
686  SwTextNode * const pTextNode( GetTextNode() );
687  // GetRegistry may only be called on a meta that is actually in the
688  // document, which means it has a pointer to its text node
689  OSL_ENSURE(pTextNode, "ERROR: GetRegistry: no text node?");
690  if (!pTextNode)
691  throw uno::RuntimeException();
692  return pTextNode->GetRegistry();
693 }
694 
696 {
697  const SwTextNode * const pTextNode( GetTextNode() );
698 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInClipboard: no text node?");
699  return pTextNode && pTextNode->IsInClipboard();
700 }
701 
702 bool Meta::IsInUndo() const
703 {
704  const SwTextNode * const pTextNode( GetTextNode() );
705 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInUndo: no text node?");
706  return pTextNode == nullptr || pTextNode->IsInUndo();
707 }
708 
709 bool Meta::IsInContent() const
710 {
711  const SwTextNode * const pTextNode( GetTextNode() );
712  OSL_ENSURE(pTextNode, "IsInContent: no text node?");
713  return pTextNode == nullptr || pTextNode->IsInContent();
714 }
715 
716 css::uno::Reference< css::rdf::XMetadatable > Meta::MakeUnoObject()
717 {
718  return SwXMeta::CreateXMeta(*this);
719 }
720 
722  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
723  : Meta(i_pFormat)
724  , m_nNumberFormat( nNumberFormat )
725  , m_bIsFixedLanguage( bIsFixedLanguage )
726 {
727 }
728 
730  OUString *const o_pPrefix, OUString *const o_pSuffix)
731 {
732  try
733  {
734  const uno::Reference<rdf::XMetadatable> xMetaField( MakeUnoObject() );
735  OSL_ENSURE(dynamic_cast<SwXMetaField*>(xMetaField.get()),
736  "GetPrefixAndSuffix: no SwXMetaField?");
737  if (xMetaField.is())
738  {
739  SwTextNode * const pTextNode( GetTextNode() );
740  SwDocShell const * const pShell(pTextNode->GetDoc().GetDocShell());
741  const uno::Reference<frame::XModel> xModel(
742  pShell ? pShell->GetModel() : nullptr, uno::UNO_SET_THROW);
743  getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
744  }
745  }
746  catch (const uno::Exception&)
747  {
748  TOOLS_WARN_EXCEPTION( "sw", "");
749  }
750 }
751 
752 sal_uInt32 MetaField::GetNumberFormat(OUString const & rContent) const
753 {
754  //TODO: this probably lacks treatment for some special cases
755  sal_uInt32 nNumberFormat( m_nNumberFormat );
756  SwTextNode * const pTextNode( GetTextNode() );
757  if (pTextNode)
758  {
759  double number;
760  (void) pTextNode->GetDoc().IsNumberFormat( rContent, nNumberFormat, number );
761  }
762  return nNumberFormat;
763 }
764 
765 void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat)
766 {
767  // effectively, the member is only a default:
768  // GetNumberFormat checks if the text actually conforms
769  m_nNumberFormat = nNumberFormat;
770 }
771 
773 {
774 }
775 
776 std::shared_ptr<MetaField>
778  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
779 {
780  const std::shared_ptr<MetaField> pMetaField(
781  new MetaField(i_pFormat, nNumberFormat, bIsFixedLanguage) );
782  m_MetaFields.push_back(pMetaField);
783  return pMetaField;
784 }
785 
786 namespace {
787 
788 struct IsInUndo
789 {
790  bool operator()(std::weak_ptr<MetaField> const & pMetaField) {
791  return pMetaField.lock()->IsInUndo();
792  }
793 };
794 
795 struct MakeUnoObject
796 {
797  uno::Reference<text::XTextField>
798  operator()(std::weak_ptr<MetaField> const & pMetaField) {
799  return uno::Reference<text::XTextField>(
800  pMetaField.lock()->MakeUnoObject(), uno::UNO_QUERY);
801  }
802 };
803 
804 }
805 
806 std::vector< uno::Reference<text::XTextField> >
808 {
809  // erase deleted fields
810  const MetaFieldList_t::iterator iter(
811  std::remove_if(m_MetaFields.begin(), m_MetaFields.end(),
812  [] (std::weak_ptr<MetaField> const& rField) { return rField.expired(); }));
813  m_MetaFields.erase(iter, m_MetaFields.end());
814  // filter out fields in UNDO
815  MetaFieldList_t filtered(m_MetaFields.size());
816  const MetaFieldList_t::iterator iter2(
817  std::remove_copy_if(m_MetaFields.begin(), m_MetaFields.end(),
818  filtered.begin(), IsInUndo()));
819  filtered.erase(iter2, filtered.end());
820  // create uno objects
821  std::vector< uno::Reference<text::XTextField> > ret(filtered.size());
822  std::transform(filtered.begin(), filtered.end(), ret.begin(),
823  MakeUnoObject());
824  return ret;
825 }
826 
828 {
829  const SwDocShell* pDocShell = rSource.GetDocShell();
830  if (!pDocShell)
831  return;
832 
833  uno::Reference<document::XDocumentPropertiesSupplier> xDocumentPropertiesSupplier(pDocShell->GetModel(), uno::UNO_QUERY);
834  uno::Reference<util::XCloneable> xCloneable(xDocumentPropertiesSupplier->getDocumentProperties(), uno::UNO_QUERY);
835  m_xDocumentProperties.set(xCloneable->createClone(), uno::UNO_QUERY);
836 }
837 
838 const uno::Reference<document::XDocumentProperties>& MetaFieldManager::getDocumentProperties() const
839 {
840  return m_xDocumentProperties;
841 }
842 
843 } // namespace sw
844 
845 /* 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:777
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: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:729
virtual ~SwFormatINetFormat() override
Definition: fmtatr2.cxx:193
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:1354
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:224
virtual bool IsInContent() const override
Definition: fmtatr2.cxx:709
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: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
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:594
SvMacroItemId
bool IsFixedLanguage() const
Definition: fmtmeta.hxx:182
MetaField(SwFormatMeta *const i_pFormat, const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
Definition: fmtatr2.cxx:721
const SvxMacro * GetMacro(SvMacroItemId nEvent) const
Definition: fmtatr2.cxx:252
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: fmtatr2.cxx:716
Dialog to specify the properties of date form field.
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: fmtatr2.cxx:197
css::uno::Reference< css::frame::XModel > GetModel() const
Meta(SwFormatMeta *const i_pFormat)
Definition: fmtatr2.cxx:634
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:141
virtual ~Meta() override
Definition: fmtatr2.cxx:642
virtual bool IsInUndo() const override
Definition: fmtatr2.cxx:702
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:229
SwFormatRuby & operator=(const SwFormatRuby &rAttr)
Definition: fmtatr2.cxx:409
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:5256
void Broadcast(const SfxHint &rHint)
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: fmtatr2.cxx:684
Internet visited.
Definition: poolfmt.hxx:121
#define MID_URL_URL
Definition: unomid.h:50
SwTextMeta * GetTextAttr() const
Definition: fmtatr2.cxx:646
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:652
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: ndtxt.cxx:5246
css::uno::Type const & get()
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: fmtatr2.cxx:669
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
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:138
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:99
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:5251
void copyDocumentProperties(const SwDoc &rSource)
Copy document properties from rSource to m_xDocumentProperties.
Definition: fmtatr2.cxx:827
virtual bool IsInContent() const override
Definition: ndtxt.cxx:5261
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:807
unsigned char sal_uInt8
void SetMacro(SvMacroItemId nEvent, const SvxMacro &rMacro)
Macro getter and setter.
Definition: fmtatr2.cxx:244
const css::uno::Reference< css::document::XDocumentProperties > & getDocumentProperties() const
Definition: fmtatr2.cxx:838
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: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:159
sal_uInt32 GetNumberFormat(OUString const &rContent) const
Definition: fmtatr2.cxx:752
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:260
virtual ~SwFormatRuby() override
Definition: fmtatr2.cxx:405
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:324
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:4022
virtual ~SwFormatCharFormat() override
Definition: fmtatr2.cxx:73
virtual bool IsInClipboard() const override
Definition: fmtatr2.cxx:695
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: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:765
#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:150
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo