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