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