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 <basic/sbxvar.hxx>
26 #include <o3tl/any.hxx>
27 #include <svl/macitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/stylepool.hxx>
30 #include <fmtautofmt.hxx>
31 #include <fchrfmt.hxx>
32 #include <fmtinfmt.hxx>
33 #include <txtatr.hxx>
34 #include <fmtruby.hxx>
35 #include <charfmt.hxx>
36 #include <hints.hxx>
37 #include <unostyle.hxx>
38 #include <unoevent.hxx>
39 #include <com/sun/star/text/RubyAdjust.hpp>
40 #include <com/sun/star/text/RubyPosition.hpp>
41 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
42 #include <com/sun/star/util/XCloneable.hpp>
43 #include <com/sun/star/frame/XModel.hpp>
44 
45 #include <cmdid.h>
46 #include <com/sun/star/uno/Any.h>
47 #include <SwStyleNameMapper.hxx>
48 
49 #include <fmtmeta.hxx>
50 #include <ndtxt.hxx>
51 #include <doc.hxx>
52 #include <unometa.hxx>
53 #include <docsh.hxx>
54 #include <svl/zforlist.hxx>
55 #include <osl/diagnose.h>
56 
57 #include <algorithm>
58 
59 using namespace ::com::sun::star;
60 
61 
63 
66  SwClient(pFormat),
67  m_pTextAttribute( nullptr )
68 {
69 }
70 
73  SwClient( rAttr.GetCharFormat() ),
74  m_pTextAttribute( nullptr )
75 {
76 }
77 
79 
80 bool SwFormatCharFormat::operator==( const SfxPoolItem& rAttr ) const
81 {
82  assert(SfxPoolItem::operator==(rAttr));
83  return GetCharFormat() == static_cast<const SwFormatCharFormat&>(rAttr).GetCharFormat();
84 }
85 
87 {
88  return new SwFormatCharFormat( *this );
89 }
90 
91 // forward to the TextAttribute
92 void SwFormatCharFormat::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
93 {
94  if( m_pTextAttribute )
95  m_pTextAttribute->ModifyNotification( pOld, pNew );
96 }
97 
98 // forward to the TextAttribute
100 {
101  return m_pTextAttribute && m_pTextAttribute->GetInfo( rInfo );
102 }
104 {
105  OUString sCharFormatName;
106  if(GetCharFormat())
108  rVal <<= sCharFormatName;
109  return true;
110 }
112 {
113  OSL_FAIL("format cannot be set with PutValue!");
114  return false;
115 }
116 
118  : SfxPoolItem( nInitWhich )
119 {
120 }
121 
122 bool SwFormatAutoFormat::operator==( const SfxPoolItem& rAttr ) const
123 {
124  assert(SfxPoolItem::operator==(rAttr));
125  return mpHandle == static_cast<const SwFormatAutoFormat&>(rAttr).mpHandle;
126 }
127 
129 {
130  return new SwFormatAutoFormat( *this );
131 }
132 
134 {
135  rVal <<= StylePool::nameOf( mpHandle );
136  return true;
137 }
138 
140 {
141  //the format is not renameable via API
142  return false;
143 }
144 
146 {
147  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFormatAutoFormat"));
148  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
149  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
150  mpHandle->dumpAsXml(pWriter);
151  xmlTextWriterEndElement(pWriter);
152 }
153 
156  , msURL()
157  , msTargetFrame()
158  , msINetFormatName()
159  , msVisitedFormatName()
160  , msHyperlinkName()
161  , mpTextAttr( nullptr )
162  , mnINetFormatId( 0 )
163  , mnVisitedFormatId( 0 )
164 {}
165 
166 SwFormatINetFormat::SwFormatINetFormat( const OUString& rURL, const OUString& rTarget )
168  , msURL( rURL )
169  , msTargetFrame( rTarget )
170  , msINetFormatName()
171  , msVisitedFormatName()
172  , msHyperlinkName()
173  , mpTextAttr( nullptr )
174  , mnINetFormatId( RES_POOLCHR_INET_NORMAL )
175  , mnVisitedFormatId( RES_POOLCHR_INET_VISIT )
176 {
179 }
180 
183  , sw::BroadcasterMixin()
184  , msURL( rAttr.GetValue() )
185  , msTargetFrame( rAttr.msTargetFrame )
186  , msINetFormatName( rAttr.msINetFormatName )
187  , msVisitedFormatName( rAttr.msVisitedFormatName )
188  , msHyperlinkName( rAttr.msHyperlinkName )
189  , mpTextAttr( nullptr )
190  , mnINetFormatId( rAttr.mnINetFormatId )
191  , mnVisitedFormatId( rAttr.mnVisitedFormatId )
192 {
193  if ( rAttr.GetMacroTable() )
194  mpMacroTable.reset( new SvxMacroTableDtor( *rAttr.GetMacroTable() ) );
195 }
196 
198 {
199 }
200 
201 bool SwFormatINetFormat::operator==( const SfxPoolItem& rAttr ) const
202 {
203  assert(SfxPoolItem::operator==(rAttr));
204  bool bRet = SfxPoolItem::operator==( rAttr )
205  && msURL == static_cast<const SwFormatINetFormat&>(rAttr).msURL
206  && msHyperlinkName == static_cast<const SwFormatINetFormat&>(rAttr).msHyperlinkName
207  && msTargetFrame == static_cast<const SwFormatINetFormat&>(rAttr).msTargetFrame
208  && msINetFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msINetFormatName
209  && msVisitedFormatName == static_cast<const SwFormatINetFormat&>(rAttr).msVisitedFormatName
210  && mnINetFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnINetFormatId
211  && mnVisitedFormatId == static_cast<const SwFormatINetFormat&>(rAttr).mnVisitedFormatId;
212 
213  if( !bRet )
214  return false;
215 
216  const SvxMacroTableDtor* pOther = static_cast<const SwFormatINetFormat&>(rAttr).mpMacroTable.get();
217  if( !mpMacroTable )
218  return ( !pOther || pOther->empty() );
219  if( !pOther )
220  return mpMacroTable->empty();
221 
222  const SvxMacroTableDtor& rOwn = *mpMacroTable;
223  const SvxMacroTableDtor& rOther = *pOther;
224 
225  return rOwn == rOther;
226 }
227 
229 {
230  return new SwFormatINetFormat( *this );
231 }
232 
234 {
235  if( pNewTable )
236  {
237  if( mpMacroTable )
238  *mpMacroTable = *pNewTable;
239  else
240  mpMacroTable.reset( new SvxMacroTableDtor( *pNewTable ) );
241  }
242  else
243  {
244  mpMacroTable.reset();
245  }
246 }
247 
249 {
250  if( !mpMacroTable )
251  mpMacroTable.reset( new SvxMacroTableDtor );
252 
253  mpMacroTable->Insert( nEvent, rMacro );
254 }
255 
257 {
258  const SvxMacro* pRet = nullptr;
259  if( mpMacroTable && mpMacroTable->IsKeyValid( nEvent ) )
260  pRet = mpMacroTable->Get( nEvent );
261  return pRet;
262 }
263 
264 bool SwFormatINetFormat::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
265 {
266  nMemberId &= ~CONVERT_TWIPS;
267  switch(nMemberId)
268  {
269  case MID_URL_URL:
270  rVal <<= msURL;
271  break;
272  case MID_URL_TARGET:
273  rVal <<= msTargetFrame;
274  break;
276  rVal <<= msHyperlinkName;
277  break;
278  case MID_URL_VISITED_FMT:
279  {
280  OUString sVal = msVisitedFormatName;
281  if (sVal.isEmpty() && mnVisitedFormatId != 0)
283  if (!sVal.isEmpty())
286  rVal <<= sVal;
287  }
288  break;
290  {
291  OUString sVal = msINetFormatName;
292  if (sVal.isEmpty() && mnINetFormatId != 0)
294  if (!sVal.isEmpty())
297  rVal <<= sVal;
298  }
299  break;
301  {
302  // create (and return) event descriptor
303  SwHyperlinkEventDescriptor* pEvents =
305  pEvents->copyMacrosFromINetFormat(*this);
306  uno::Reference<container::XNameReplace> xNameReplace(pEvents);
307 
308  // all others return a string; so we just set rVal here and exit
309  rVal <<= xNameReplace;
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  assert(SfxPoolItem::operator==(i_rOther));
566  return SfxPoolItem::operator==( i_rOther )
567  && (m_pMeta == static_cast<SwFormatMeta const &>( i_rOther ).m_pMeta);
568 }
569 
571 {
572  // if this is indeed a copy, then DoCopy must be called later!
573  return m_pMeta // #i105148# pool default may be cloned also!
574  ? new SwFormatMeta( m_pMeta, Which() ) : new SwFormatMeta( Which() );
575 }
576 
577 void SwFormatMeta::SetTextAttr(SwTextMeta * const i_pTextAttr)
578 {
579  OSL_ENSURE(!(m_pTextAttr && i_pTextAttr),
580  "SwFormatMeta::SetTextAttr: already has text attribute?");
581  OSL_ENSURE( m_pTextAttr || i_pTextAttr ,
582  "SwFormatMeta::SetTextAttr: no attribute to remove?");
583  m_pTextAttr = i_pTextAttr;
584  OSL_ENSURE(m_pMeta, "inserted SwFormatMeta has no sw::Meta?");
585  // the sw::Meta must be able to find the current text attribute!
586  if (m_pMeta)
587  {
588  if (i_pTextAttr)
589  {
590  m_pMeta->SetFormatMeta(this);
591  }
592  else if (m_pMeta->GetFormatMeta() == this)
593  { // text attribute gone => de-register from text node!
594  NotifyChangeTextNode(nullptr);
595  m_pMeta->SetFormatMeta(nullptr);
596  }
597  }
598 }
599 
601 {
602  // N.B.: do not reset m_pTextAttr here: see call in nodes.cxx,
603  // where the hint is not deleted!
604  OSL_ENSURE(m_pMeta, "SwFormatMeta::NotifyChangeTextNode: no Meta?");
605  if (m_pMeta && (m_pMeta->GetFormatMeta() == this))
606  { // do not call Modify, that would call SwXMeta::Modify!
607  m_pMeta->NotifyChangeTextNode(pTextNode);
608  }
609 }
610 
611 // this SwFormatMeta has been cloned and points at the same sw::Meta as the source
612 // this method copies the sw::Meta
613 void SwFormatMeta::DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
614  SwTextNode & i_rTargetTextNode)
615 {
616  OSL_ENSURE(m_pMeta, "DoCopy called for SwFormatMeta with no sw::Meta?");
617  if (m_pMeta)
618  {
619  const std::shared_ptr< ::sw::Meta> pOriginal( m_pMeta );
620  if (RES_TXTATR_META == Which())
621  {
622  m_pMeta.reset( new ::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 
638 namespace sw {
639 
640 Meta::Meta(SwFormatMeta * const i_pFormat)
641  : ::sfx2::Metadatable()
642  , SwModify()
643  , m_pFormat(i_pFormat)
644  , m_pTextNode(nullptr)
645 {
646 }
647 
649 {
650 }
651 
653 {
654  return m_pFormat ? m_pFormat->GetTextAttr() : nullptr;
655 }
656 
657 
659 {
660  m_pTextNode = pTextNode;
662  {
663  m_pTextNode->Add(this);
664  }
665  else if (!m_pTextNode)
666  {
667  EndListeningAll();
668  }
669  if (!pTextNode) // text node gone? invalidate UNO object!
670  {
671  GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
672  }
673 }
674 
675 // SwClient
676 void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew )
677 {
678  NotifyClients(pOld, pNew);
679  GetNotifier().Broadcast(SfxHint(SfxHintId::DataChanged));
680  if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
681  { // invalidate cached uno object
682  SetXMeta(uno::Reference<rdf::XMetadatable>(nullptr));
683  GetNotifier().Broadcast(SfxHint(SfxHintId::Deinitializing));
684  }
685 }
686 
687 // sfx2::Metadatable
689 {
690  SwTextNode * const pTextNode( GetTextNode() );
691  // GetRegistry may only be called on a meta that is actually in the
692  // document, which means it has a pointer to its text node
693  OSL_ENSURE(pTextNode, "ERROR: GetRegistry: no text node?");
694  if (!pTextNode)
695  throw uno::RuntimeException();
696  return pTextNode->GetRegistry();
697 }
698 
700 {
701  const SwTextNode * const pTextNode( GetTextNode() );
702 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInClipboard: no text node?");
703  return pTextNode && pTextNode->IsInClipboard();
704 }
705 
706 bool Meta::IsInUndo() const
707 {
708  const SwTextNode * const pTextNode( GetTextNode() );
709 // no text node: in UNDO OSL_ENSURE(pTextNode, "IsInUndo: no text node?");
710  return pTextNode == nullptr || pTextNode->IsInUndo();
711 }
712 
713 bool Meta::IsInContent() const
714 {
715  const SwTextNode * const pTextNode( GetTextNode() );
716  OSL_ENSURE(pTextNode, "IsInContent: no text node?");
717  return pTextNode == nullptr || pTextNode->IsInContent();
718 }
719 
720 css::uno::Reference< css::rdf::XMetadatable > Meta::MakeUnoObject()
721 {
722  return SwXMeta::CreateXMeta(*this);
723 }
724 
726  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
727  : Meta(i_pFormat)
728  , m_nNumberFormat( nNumberFormat )
729  , m_bIsFixedLanguage( bIsFixedLanguage )
730 {
731 }
732 
734  OUString *const o_pPrefix, OUString *const o_pSuffix)
735 {
736  try
737  {
738  const uno::Reference<rdf::XMetadatable> xMetaField( MakeUnoObject() );
739  OSL_ENSURE(dynamic_cast<SwXMetaField*>(xMetaField.get()),
740  "GetPrefixAndSuffix: no SwXMetaField?");
741  if (xMetaField.is())
742  {
743  SwTextNode * const pTextNode( GetTextNode() );
744  SwDocShell const * const pShell(pTextNode->GetDoc()->GetDocShell());
745  const uno::Reference<frame::XModel> xModel(
746  pShell ? pShell->GetModel() : nullptr, uno::UNO_SET_THROW);
747  getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
748  }
749  }
750  catch (const uno::Exception&)
751  {
752  OSL_FAIL("exception?");
753  }
754 }
755 
756 sal_uInt32 MetaField::GetNumberFormat(OUString const & rContent) const
757 {
758  //TODO: this probably lacks treatment for some special cases
759  sal_uInt32 nNumberFormat( m_nNumberFormat );
760  SwTextNode * const pTextNode( GetTextNode() );
761  if (pTextNode)
762  {
763  double number;
764  (void) pTextNode->GetDoc()->IsNumberFormat( rContent, nNumberFormat, number );
765  }
766  return nNumberFormat;
767 }
768 
769 void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat)
770 {
771  // effectively, the member is only a default:
772  // GetNumberFormat checks if the text actually conforms
773  m_nNumberFormat = nNumberFormat;
774 }
775 
777 {
778 }
779 
780 std::shared_ptr<MetaField>
782  const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
783 {
784  const std::shared_ptr<MetaField> pMetaField(
785  new MetaField(i_pFormat, nNumberFormat, bIsFixedLanguage) );
786  m_MetaFields.push_back(pMetaField);
787  return pMetaField;
788 }
789 
790 struct IsInUndo
791 {
792  bool operator()(std::weak_ptr<MetaField> const & pMetaField) {
793  return pMetaField.lock()->IsInUndo();
794  }
795 };
796 
798 {
799  uno::Reference<text::XTextField>
800  operator()(std::weak_ptr<MetaField> const & pMetaField) {
801  return uno::Reference<text::XTextField>(
802  pMetaField.lock()->MakeUnoObject(), uno::UNO_QUERY);
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()
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 >())
const css::uno::Reference< css::document::XDocumentProperties > & getDocumentProperties()
Definition: fmtatr2.cxx:838
std::shared_ptr< MetaField > makeMetaField(SwFormatMeta *const i_pFormat=nullptr, const sal_uInt32 nNumberFormat=SAL_MAX_UINT32, const bool bIsFixedLanguage=false)
Definition: fmtatr2.cxx:781
static SfxPoolItem * CreateDefault()
Definition: fmtatr2.cxx:62
virtual bool operator==(const SfxPoolItem &) const override
"pure virtual methods" of SfxPoolItem
Definition: fmtatr2.cxx:80
static SwFormatMeta * CreatePoolDefault(const sal_uInt16 i_nWhich)
Definition: fmtatr2.cxx:528
bool GetInfo(SfxPoolItem const &rInfo) const
Definition: txtatr2.cxx:73
bool hasValue()
void Add(SwClient *pDepend)
Definition: calbck.cxx:217
void GetPrefixAndSuffix(OUString *const o_pPrefix, OUString *const o_pSuffix)
get prefix/suffix from the RDF repository.
Definition: fmtatr2.cxx:733
virtual ~SwFormatINetFormat() override
Definition: fmtatr2.cxx:197
SwTextMeta * GetTextAttr()
Definition: fmtmeta.hxx:100
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:443
#define RES_TXTATR_CJK_RUBY
Definition: hintids.hxx:143
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:228
virtual bool operator==(const SfxPoolItem &) const =0
#define RES_TXTATR_METAFIELD
Definition: hintids.hxx:139
SwDocShell * GetDocShell()
Definition: doc.hxx:1341
std::string GetValue
static void FillUIName(const OUString &rName, OUString &rFillName, SwGetPoolIdFromName)
OUString msINetFormatName
Definition: fmtinfmt.hxx:43
sal_uInt16 mnVisitedFormatId
Definition: fmtinfmt.hxx:49
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:438
virtual bool IsInContent() const override
Definition: fmtatr2.cxx:713
void DoCopy(::sw::MetaFieldManager &i_rTargetDocManager, SwTextNode &i_rTargetTextNode)
this method must be called when the hint is actually copied
Definition: fmtatr2.cxx:613
#define MID_RUBY_CHARSTYLE
Definition: unomid.h:115
std::unique_ptr< SvxMacroTableDtor > mpMacroTable
Definition: fmtinfmt.hxx:46
knows all meta-fields in the document.
Definition: fmtmeta.hxx:198
#define MID_URL_HYPERLINKNAME
Definition: unomid.h:47
Definition: doc.hxx:185
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:122
#define MID_RUBY_TEXT
Definition: unomid.h:113
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:139
void NotifyChangeTextNode(SwTextNode *const pTextNode)
notify clients registered at m_pMeta that this meta is being (re-)moved
Definition: fmtatr2.cxx:600
SvMacroItemId
bool IsFixedLanguage() const
Definition: fmtmeta.hxx:184
MetaField(SwFormatMeta *const i_pFormat, const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
Definition: fmtatr2.cxx:725
const SvxMacro * GetMacro(SvMacroItemId nEvent) const
Definition: fmtatr2.cxx:256
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: fmtatr2.cxx:720
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:38
virtual bool operator==(const SfxPoolItem &) const override
"Pure virtual methods" of SfxPoolItem.
Definition: fmtatr2.cxx:201
css::uno::Reference< css::frame::XModel > GetModel() const
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:142
Meta(SwFormatMeta *const i_pFormat)
Definition: fmtatr2.cxx:640
#define RES_REMOVE_UNO_OBJECT
Definition: hintids.hxx:304
virtual void Modify(const SfxPoolItem *, const SfxPoolItem *) override
Definition: fmtatr2.cxx:92
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:145
virtual ~Meta() override
Definition: fmtatr2.cxx:648
virtual bool IsInUndo() const override
Definition: fmtatr2.cxx:706
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:233
SwFormatRuby & operator=(const SwFormatRuby &rAttr)
Definition: fmtatr2.cxx:414
#define RES_TXTATR_META
Definition: hintids.hxx:138
void ModifyNotification(const SfxPoolItem *, const SfxPoolItem *)
Definition: txtatr2.cxx:55
SwFormatMeta * m_pFormat
Definition: fmtmeta.hxx:138
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:128
#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:117
sal_uInt32 m_nNumberFormat
Definition: fmtmeta.hxx:179
static SW_DLLPUBLIC sal_uInt16 GetPoolIdFromUIName(const OUString &rName, SwGetPoolIdFromName)
const SvxMacroTableDtor * GetMacroTable() const
Definition: fmtinfmt.hxx:132
void EndListeningAll()
Definition: calbck.cxx:124
virtual bool GetInfo(SfxPoolItem &rInfo) const override
Definition: fmtatr2.cxx:99
struct _xmlTextWriter * xmlTextWriterPtr
OUString m_sRubyText
The ruby text.
Definition: fmtruby.hxx:32
bool empty() const
virtual bool IsInUndo() const override
Definition: ndtxt.cxx:5250
void Broadcast(const SfxHint &rHint)
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: fmtatr2.cxx:688
Internet visited.
Definition: poolfmt.hxx:122
#define MID_URL_URL
Definition: unomid.h:50
SwTextMeta * GetTextAttr() const
Definition: fmtatr2.cxx:652
void SetXMeta(css::uno::Reference< css::rdf::XMetadatable > const &xMeta)
Definition: fmtmeta.hxx:153
css::uno::Reference< css::document::XDocumentProperties > m_xDocumentProperties
Document properties of a clipboard document, empty for non-clipboard documents.
Definition: fmtmeta.hxx:204
SwDoc * GetDoc()
Definition: node.hxx:702
Internet normal.
Definition: poolfmt.hxx:121
void NotifyChangeTextNode(SwTextNode *const pTextNode)
Definition: fmtatr2.cxx:658
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
sfx2::Metadatable
Definition: ndtxt.cxx:5240
css::uno::Type const & get()
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:133
OUString m_sCharFormatName
Name of the charformat.
Definition: fmtruby.hxx:33
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:141
SwTextNode * GetTextNode() const
Definition: fmtmeta.hxx:144
sal_uInt16 mnINetFormatId
Definition: fmtinfmt.hxx:48
OUString msHyperlinkName
Name of the link.
Definition: fmtinfmt.hxx:45
SwTextNode * m_pTextNode
Definition: fmtmeta.hxx:139
void NotifyClients(const SfxPoolItem *pOldValue, const SfxPoolItem *pNewValue)
Definition: calbck.cxx:167
SvtBroadcaster & GetNotifier()
Definition: calbck.hxx:93
SwTextRuby * m_pTextAttr
The TextAttribute.
Definition: fmtruby.hxx:34
uno::Reference< text::XTextField > operator()(std::weak_ptr< MetaField > const &pMetaField)
Definition: fmtatr2.cxx:800
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:5245
void copyDocumentProperties(const SwDoc &rSource)
Copy document properties from rSource to m_xDocumentProperties.
Definition: fmtatr2.cxx:827
void copyMacrosFromINetFormat(const SwFormatINetFormat &aFormat)
Definition: unoevent.cxx:112
virtual bool IsInContent() const override
Definition: ndtxt.cxx:5255
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:86
SwCharFormat * GetCharFormat() const
Definition: fchrfmt.hxx:70
SwFormatCharFormat(SwCharFormat *pFormat)
single argument ctors shall be explicit.
Definition: fmtatr2.cxx:64
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: fmtatr2.cxx:103
std::vector< std::weak_ptr< MetaField > > MetaFieldList_t
Definition: fmtmeta.hxx:201
std::vector< css::uno::Reference< css::text::XTextField > > getMetaFields()
get all meta fields
Definition: fmtatr2.cxx:807
unsigned char sal_uInt8
void SetMacro(SvMacroItemId nEvent, const SvxMacro &rMacro)
Macro getter and setter.
Definition: fmtatr2.cxx:248
std::shared_ptr< ::sw::Meta > m_pMeta
Definition: fmtmeta.hxx:97
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
SwClient.
Definition: fmtatr2.cxx:676
MetaFieldList_t m_MetaFields
Definition: fmtmeta.hxx:202
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
const SwModify * GetRegisteredIn() const
Definition: calbck.hxx:157
sal_uInt32 GetNumberFormat(OUString const &rContent) const
Definition: fmtatr2.cxx:756
OUString msVisitedFormatName
Definition: fmtinfmt.hxx:44
static const OUString & GetUIName(const OUString &rName, SwGetPoolIdFromName)
void SetTextAttr(SwTextMeta *const i_pTextAttr)
Definition: fmtatr2.cxx:577
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:264
virtual ~SwFormatRuby() override
Definition: fmtatr2.cxx:410
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:3973
virtual ~SwFormatCharFormat() override
Definition: fmtatr2.cxx:78
virtual bool IsInClipboard() const override
Definition: fmtatr2.cxx:699
def text(shape, st)
Reference< XModel > xModel
#define MID_URL_TARGET
Definition: unomid.h:51
bool operator()(std::weak_ptr< MetaField > const &pMetaField)
Definition: fmtatr2.cxx:792
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: fmtatr2.cxx:111
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:769
#define MID_RUBY_POSITION
Definition: unomid.h:117
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: fmtatr2.cxx:570
#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:154
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo