1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmtatr2.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "hintids.hxx"
37 #include <basic/sbxvar.hxx>
38 #include <svtools/macitem.hxx>
39 #include <svtools/stritem.hxx>
40 #include <svtools/stylepool.hxx>
41 #include <fmtautofmt.hxx>
42 #include <fchrfmt.hxx>
43 #include <fmtinfmt.hxx>
45 #include <fmtruby.hxx>
46 #include <charfmt.hxx>
47 #include <hints.hxx> // SwUpdateAttr
48 #include <unostyle.hxx>
49 #include <unoevent.hxx> // SwHyperlinkEventDescriptor
50 #include <com/sun/star/text/RubyAdjust.hdl>
53 #include <com/sun/star/uno/Any.h>
54 #include <SwStyleNameMapper.hxx>
56 #include <fmtmeta.hxx>
57 #include <ndtxt.hxx> // for meta
58 #include <doc.hxx> // for meta
59 #include <unometa.hxx>
60 #include <unoobj.hxx> // SwXTextRange
62 #include <svtools/zforlist.hxx> // GetNumberFormat
64 #include <boost/bind.hpp>
68 using namespace ::com::sun::star
;
69 using ::rtl::OUString
;
71 TYPEINIT1_AUTOFACTORY(SwFmtINetFmt
, SfxPoolItem
);
72 TYPEINIT1_AUTOFACTORY(SwFmtAutoFmt
, SfxPoolItem
);
74 /*************************************************************************
78 |* Ersterstellung JP 23.11.90
79 |* Letzte Aenderung JP 09.08.94
81 *************************************************************************/
83 SwFmtCharFmt::SwFmtCharFmt( SwCharFmt
*pFmt
)
84 : SfxPoolItem( RES_TXTATR_CHARFMT
),
92 SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt
& rAttr
)
93 : SfxPoolItem( RES_TXTATR_CHARFMT
),
94 SwClient( rAttr
.GetCharFmt() ),
101 SwFmtCharFmt::~SwFmtCharFmt() {}
105 int SwFmtCharFmt::operator==( const SfxPoolItem
& rAttr
) const
107 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
108 return GetCharFmt() == ((SwFmtCharFmt
&)rAttr
).GetCharFmt();
113 SfxPoolItem
* SwFmtCharFmt::Clone( SfxItemPool
* ) const
115 return new SwFmtCharFmt( *this );
120 // weiterleiten an das TextAttribut
121 void SwFmtCharFmt::Modify( SfxPoolItem
* pOld
, SfxPoolItem
* pNew
)
124 pTxtAttr
->Modify( pOld
, pNew
);
129 // weiterleiten an das TextAttribut
130 BOOL
SwFmtCharFmt::GetInfo( SfxPoolItem
& rInfo
) const
132 return pTxtAttr
? pTxtAttr
->GetInfo( rInfo
) : FALSE
;
134 BOOL
SwFmtCharFmt::QueryValue( uno::Any
& rVal
, BYTE
) const
138 SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
139 rVal
<<= OUString( sCharFmtName
);
142 BOOL
SwFmtCharFmt::PutValue( const uno::Any
& , BYTE
)
144 DBG_ERROR("Zeichenvorlage kann mit PutValue nicht gesetzt werden!");
148 /*************************************************************************
150 |* class SwFmtAutoFmt
152 |* Ersterstellung AMA 12.05.06
153 |* Letzte Aenderung AMA 12.05.06
155 *************************************************************************/
157 SwFmtAutoFmt::SwFmtAutoFmt( USHORT nInitWhich
)
158 : SfxPoolItem( nInitWhich
)
162 SwFmtAutoFmt::SwFmtAutoFmt( const SwFmtAutoFmt
& rAttr
)
163 : SfxPoolItem( rAttr
.Which() ), mpHandle( rAttr
.mpHandle
)
167 SwFmtAutoFmt::~SwFmtAutoFmt()
171 int SwFmtAutoFmt::operator==( const SfxPoolItem
& rAttr
) const
173 ASSERT( SfxPoolItem::operator==( rAttr
), "different attributes" );
174 return mpHandle
== ((SwFmtAutoFmt
&)rAttr
).mpHandle
;
177 SfxPoolItem
* SwFmtAutoFmt::Clone( SfxItemPool
* ) const
179 return new SwFmtAutoFmt( *this );
182 BOOL
SwFmtAutoFmt::QueryValue( uno::Any
& rVal
, BYTE
) const
184 String sCharFmtName
= StylePool::nameOf( mpHandle
);
185 rVal
<<= OUString( sCharFmtName
);
189 BOOL
SwFmtAutoFmt::PutValue( const uno::Any
& , BYTE
)
191 //the format is not renameable via API
195 /*************************************************************************
197 |* class SwFmtINetFmt
199 |* Ersterstellung AMA 02.08.96
200 |* Letzte Aenderung AMA 02.08.96
202 *************************************************************************/
204 SwFmtINetFmt::SwFmtINetFmt()
205 : SfxPoolItem( RES_TXTATR_INETFMT
),
212 SwFmtINetFmt::SwFmtINetFmt( const XubString
& rURL
, const XubString
& rTarget
)
213 : SfxPoolItem( RES_TXTATR_INETFMT
),
215 aTargetFrame( rTarget
),
223 SwFmtINetFmt::SwFmtINetFmt( const SwFmtINetFmt
& rAttr
)
224 : SfxPoolItem( RES_TXTATR_INETFMT
),
225 aURL( rAttr
.GetValue() ),
226 aTargetFrame( rAttr
.aTargetFrame
),
227 aINetFmt( rAttr
.aINetFmt
),
228 aVisitedFmt( rAttr
.aVisitedFmt
),
229 aName( rAttr
.aName
),
232 nINetId( rAttr
.nINetId
),
233 nVisitedId( rAttr
.nVisitedId
)
235 if( rAttr
.GetMacroTbl() )
236 pMacroTbl
= new SvxMacroTableDtor( *rAttr
.GetMacroTbl() );
239 SwFmtINetFmt::~SwFmtINetFmt()
246 int SwFmtINetFmt::operator==( const SfxPoolItem
& rAttr
) const
248 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
249 BOOL bRet
= SfxPoolItem::operator==( (SfxPoolItem
&) rAttr
)
250 && aURL
== ((SwFmtINetFmt
&)rAttr
).aURL
251 && aName
== ((SwFmtINetFmt
&)rAttr
).aName
252 && aTargetFrame
== ((SwFmtINetFmt
&)rAttr
).aTargetFrame
253 && aINetFmt
== ((SwFmtINetFmt
&)rAttr
).aINetFmt
254 && aVisitedFmt
== ((SwFmtINetFmt
&)rAttr
).aVisitedFmt
255 && nINetId
== ((SwFmtINetFmt
&)rAttr
).nINetId
256 && nVisitedId
== ((SwFmtINetFmt
&)rAttr
).nVisitedId
;
261 const SvxMacroTableDtor
* pOther
= ((SwFmtINetFmt
&)rAttr
).pMacroTbl
;
263 return ( !pOther
|| !pOther
->Count() );
265 return 0 == pMacroTbl
->Count();
267 const SvxMacroTableDtor
& rOwn
= *pMacroTbl
;
268 const SvxMacroTableDtor
& rOther
= *pOther
;
270 // Anzahl unterschiedlich => auf jeden Fall ungleich
271 if( rOwn
.Count() != rOther
.Count() )
274 // einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig
275 for( USHORT nNo
= 0; nNo
< rOwn
.Count(); ++nNo
)
277 const SvxMacro
*pOwnMac
= rOwn
.GetObject(nNo
);
278 const SvxMacro
*pOtherMac
= rOther
.GetObject(nNo
);
279 if ( rOwn
.GetKey(pOwnMac
) != rOther
.GetKey(pOtherMac
) ||
280 pOwnMac
->GetLibName() != pOtherMac
->GetLibName() ||
281 pOwnMac
->GetMacName() != pOtherMac
->GetMacName() )
289 SfxPoolItem
* SwFmtINetFmt::Clone( SfxItemPool
* ) const
291 return new SwFmtINetFmt( *this );
296 void SwFmtINetFmt::SetMacroTbl( const SvxMacroTableDtor
* pNewTbl
)
301 *pMacroTbl
= *pNewTbl
;
303 pMacroTbl
= new SvxMacroTableDtor( *pNewTbl
);
306 delete pMacroTbl
, pMacroTbl
= 0;
311 void SwFmtINetFmt::SetMacro( USHORT nEvent
, const SvxMacro
& rMacro
)
314 pMacroTbl
= new SvxMacroTableDtor
;
317 if( 0 != ( pOldMacro
= pMacroTbl
->Get( nEvent
)) )
320 pMacroTbl
->Replace( nEvent
, new SvxMacro( rMacro
) );
323 pMacroTbl
->Insert( nEvent
, new SvxMacro( rMacro
) );
328 const SvxMacro
* SwFmtINetFmt::GetMacro( USHORT nEvent
) const
330 const SvxMacro
* pRet
= 0;
331 if( pMacroTbl
&& pMacroTbl
->IsKeyValid( nEvent
) )
332 pRet
= pMacroTbl
->Get( nEvent
);
338 BOOL
SwFmtINetFmt::QueryValue( uno::Any
& rVal
, BYTE nMemberId
) const
342 nMemberId
&= ~CONVERT_TWIPS
;
351 case MID_URL_HYPERLINKNAME
:
354 case MID_URL_VISITED_FMT
:
356 if( !sVal
.Len() && nVisitedId
!= 0 )
357 SwStyleNameMapper::FillUIName( nVisitedId
, sVal
);
359 SwStyleNameMapper::FillProgName( sVal
, sVal
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
361 case MID_URL_UNVISITED_FMT
:
363 if( !sVal
.Len() && nINetId
!= 0 )
364 SwStyleNameMapper::FillUIName( nINetId
, sVal
);
366 SwStyleNameMapper::FillProgName( sVal
, sVal
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
368 case MID_URL_HYPERLINKEVENTS
:
370 // create (and return) event descriptor
371 SwHyperlinkEventDescriptor
* pEvents
=
372 new SwHyperlinkEventDescriptor();
373 pEvents
->copyMacrosFromINetFmt(*this);
374 uno::Reference
<container::XNameReplace
> xNameReplace(pEvents
);
376 // all others return a string; so we just set rVal here and exit
377 rVal
<<= xNameReplace
;
383 rVal
<<= OUString(sVal
);
386 BOOL
SwFmtINetFmt::PutValue( const uno::Any
& rVal
, BYTE nMemberId
)
389 nMemberId
&= ~CONVERT_TWIPS
;
391 // all properties except HyperlinkEvents are of type string, hence
392 // we treat HyperlinkEvents specially
393 if (MID_URL_HYPERLINKEVENTS
== nMemberId
)
395 uno::Reference
<container::XNameReplace
> xReplace
;
399 // Create hyperlink event descriptor. Then copy events
400 // from argument into descriptor. Then copy events from
401 // the descriptor into the format.
402 SwHyperlinkEventDescriptor
* pEvents
= new SwHyperlinkEventDescriptor();
403 uno::Reference
< lang::XServiceInfo
> xHold
= pEvents
;
404 pEvents
->copyMacrosFromNameReplace(xReplace
);
405 pEvents
->copyMacrosIntoINetFmt(*this);
415 // all string properties:
416 if(rVal
.getValueType() != ::getCppuType((rtl::OUString
*)0))
418 XubString sVal
= *(rtl::OUString
*)rVal
.getValue();
427 case MID_URL_HYPERLINKNAME
:
430 case MID_URL_VISITED_FMT
:
433 SwStyleNameMapper::FillUIName( sVal
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
434 aVisitedFmt
= OUString ( aString
);
435 nVisitedId
= SwStyleNameMapper::GetPoolIdFromUIName( aVisitedFmt
,
436 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
439 case MID_URL_UNVISITED_FMT
:
442 SwStyleNameMapper::FillUIName( sVal
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
443 aINetFmt
= OUString ( aString
);
444 nINetId
= SwStyleNameMapper::GetPoolIdFromUIName( aINetFmt
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
455 /*************************************************************************
457 *************************************************************************/
459 SwFmtRuby::SwFmtRuby( const String
& rRubyTxt
)
460 : SfxPoolItem( RES_TXTATR_CJK_RUBY
),
461 sRubyTxt( rRubyTxt
),
469 SwFmtRuby::SwFmtRuby( const SwFmtRuby
& rAttr
)
470 : SfxPoolItem( RES_TXTATR_CJK_RUBY
),
471 sRubyTxt( rAttr
.sRubyTxt
),
472 sCharFmtName( rAttr
.sCharFmtName
),
474 nCharFmtId( rAttr
.nCharFmtId
),
475 nPosition( rAttr
.nPosition
),
476 nAdjustment( rAttr
.nAdjustment
)
480 SwFmtRuby::~SwFmtRuby()
484 SwFmtRuby
& SwFmtRuby::operator=( const SwFmtRuby
& rAttr
)
486 sRubyTxt
= rAttr
.sRubyTxt
;
487 sCharFmtName
= rAttr
.sCharFmtName
;
488 nCharFmtId
= rAttr
.nCharFmtId
;
489 nPosition
= rAttr
.nPosition
;
490 nAdjustment
= rAttr
.nAdjustment
;
495 int SwFmtRuby::operator==( const SfxPoolItem
& rAttr
) const
497 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
498 return sRubyTxt
== ((SwFmtRuby
&)rAttr
).sRubyTxt
&&
499 sCharFmtName
== ((SwFmtRuby
&)rAttr
).sCharFmtName
&&
500 nCharFmtId
== ((SwFmtRuby
&)rAttr
).nCharFmtId
&&
501 nPosition
== ((SwFmtRuby
&)rAttr
).nPosition
&&
502 nAdjustment
== ((SwFmtRuby
&)rAttr
).nAdjustment
;
505 SfxPoolItem
* SwFmtRuby::Clone( SfxItemPool
* ) const
507 return new SwFmtRuby( *this );
510 BOOL
SwFmtRuby::QueryValue( uno::Any
& rVal
,
511 BYTE nMemberId
) const
514 nMemberId
&= ~CONVERT_TWIPS
;
517 case MID_RUBY_TEXT
: rVal
<<= (OUString
)sRubyTxt
; break;
518 case MID_RUBY_ADJUST
: rVal
<<= (sal_Int16
)nAdjustment
; break;
519 case MID_RUBY_CHARSTYLE
:
522 SwStyleNameMapper::FillProgName(sCharFmtName
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
523 rVal
<<= OUString ( aString
);
528 sal_Bool bAbove
= !nPosition
;
529 rVal
.setValue(&bAbove
, ::getBooleanCppuType());
537 BOOL
SwFmtRuby::PutValue( const uno::Any
& rVal
,
541 nMemberId
&= ~CONVERT_TWIPS
;
547 bRet
= rVal
>>= sTmp
;
551 case MID_RUBY_ADJUST
:
555 if(nSet
>= 0 && nSet
<= text::RubyAdjust_INDENT_BLOCK
)
563 const uno::Type
& rType
= ::getBooleanCppuType();
564 if(rVal
.hasValue() && rVal
.getValueType() == rType
)
566 sal_Bool bAbove
= *(sal_Bool
*)rVal
.getValue();
567 nPosition
= bAbove
? 0 : 1;
571 case MID_RUBY_CHARSTYLE
:
574 bRet
= rVal
>>= sTmp
;
576 sCharFmtName
= SwStyleNameMapper::GetUIName(sTmp
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
586 /*************************************************************************
588 ************************************************************************/
590 SwFmtMeta
* SwFmtMeta::CreatePoolDefault(const USHORT i_nWhich
)
592 return new SwFmtMeta(i_nWhich
);
595 SwFmtMeta::SwFmtMeta(const USHORT i_nWhich
)
596 : SfxPoolItem( i_nWhich
)
600 ASSERT((RES_TXTATR_META
== i_nWhich
) || (RES_TXTATR_METAFIELD
== i_nWhich
),
601 "ERROR: SwFmtMeta: invalid which id!");
604 SwFmtMeta::SwFmtMeta( ::boost::shared_ptr
< ::sw::Meta
> const & i_pMeta
,
605 const USHORT i_nWhich
)
606 : SfxPoolItem( i_nWhich
)
610 ASSERT((RES_TXTATR_META
== i_nWhich
) || (RES_TXTATR_METAFIELD
== i_nWhich
),
611 "ERROR: SwFmtMeta: invalid which id!");
612 ASSERT(m_pMeta
, "SwFmtMeta: no Meta ?");
613 // DO NOT call m_pMeta->SetFmtMeta(this) here; only from SetTxtAttr!
616 SwFmtMeta::~SwFmtMeta()
618 if (m_pMeta
&& (m_pMeta
->GetFmtMeta() == this))
620 m_pMeta
->SetFmtMeta(0);
624 int SwFmtMeta::operator==( const SfxPoolItem
& i_rOther
) const
626 ASSERT( SfxPoolItem::operator==( i_rOther
), "i just copied this assert" );
627 return SfxPoolItem::operator==( i_rOther
)
628 && (m_pMeta
== static_cast<SwFmtMeta
const &>( i_rOther
).m_pMeta
);
631 SfxPoolItem
* SwFmtMeta::Clone( SfxItemPool
* /*pPool*/ ) const
633 // if this is indeed a copy, then DoCopy must be called later!
634 return (m_pMeta
) // #i105148# pool default may be cloned also!
635 ? new SwFmtMeta( m_pMeta
, Which() ) : new SwFmtMeta( Which() );
638 void SwFmtMeta::SetTxtAttr(SwTxtMeta
* const i_pTxtAttr
)
640 ASSERT(!(m_pTxtAttr
&& i_pTxtAttr
),
641 "SwFmtMeta::SetTxtAttr: already has text attribute?");
642 ASSERT( m_pTxtAttr
|| i_pTxtAttr
,
643 "SwFmtMeta::SetTxtAttr: no attribute to remove?");
644 m_pTxtAttr
= i_pTxtAttr
;
645 ASSERT(m_pMeta
, "inserted SwFmtMeta has no sw::Meta?");
646 // the sw::Meta must be able to find the current text attribute!
647 if (i_pTxtAttr
&& m_pMeta
)
649 m_pMeta
->SetFmtMeta(this);
653 void SwFmtMeta::NotifyRemoval()
655 // N.B.: do not reset m_pTxtAttr here: see call in nodes.cxx,
656 // where the hint is not deleted!
657 ASSERT(m_pMeta
, "NotifyRemoval: no meta ?");
660 SwPtrMsgPoolItem
aMsgHint( RES_REMOVE_UNO_OBJECT
,
661 &static_cast<SwModify
&>(*m_pMeta
) ); // cast to proper base class!
662 m_pMeta
->Modify(&aMsgHint
, &aMsgHint
);
666 void SwFmtMeta::DoCopy(SwFmtMeta
& rOriginalMeta
)
668 ASSERT(m_pMeta
, "DoCopy called for SwFmtMeta with no sw::Meta?");
671 const ::boost::shared_ptr
< ::sw::Meta
> pOriginal( m_pMeta
);
672 // UGLY: original sw::Meta now points at _this_ due to being already
673 // inserted via MakeTxtAttr! so fix it up to point at the original item
674 // (maybe would be better to tell MakeTxtAttr that it creates a copy?)
675 pOriginal
->SetFmtMeta(&rOriginalMeta
);
676 if (RES_TXTATR_META
== Which())
678 m_pMeta
.reset( new ::sw::Meta(this) );
682 ::sw::MetaField
*const pMetaField(
683 static_cast< ::sw::MetaField
* >(pOriginal
.get()));
684 SwDoc
* const pTargetDoc( GetTxtAttr()->GetTxtNode()->GetDoc() );
685 m_pMeta
= pTargetDoc
->GetMetaFieldManager().makeMetaField( this,
686 pMetaField
->m_nNumberFormat
, pMetaField
->IsFixedLanguage() );
688 m_pMeta
->RegisterAsCopyOf(*pOriginal
);
695 /*************************************************************************
697 ************************************************************************/
699 Meta::Meta(SwFmtMeta
* const i_pFmt
)
700 : ::sfx2::Metadatable()
710 SwTxtMeta
* Meta::GetTxtAttr() const
712 return (m_pFmt
) ? m_pFmt
->GetTxtAttr() : 0;
715 SwTxtNode
* Meta::GetTxtNode() const
717 SwTxtMeta
* const pTxtAttr( GetTxtAttr() );
718 return (pTxtAttr
) ? pTxtAttr
->GetTxtNode() : 0;
722 void Meta::Modify( SfxPoolItem
*pOld
, SfxPoolItem
*pNew
)
724 SwTxtNode
* const pTxtNode( GetTxtNode() );
725 if (pTxtNode
&& (GetRegisteredIn() != pTxtNode
))
729 SwModify::Modify(pOld
, pNew
);
733 ::sfx2::IXmlIdRegistry
& Meta::GetRegistry()
735 SwTxtNode
* const pTxtNode( GetTxtNode() );
736 // GetRegistry may only be called on a meta that is actually in the
737 // document, which means it has a pointer to its text node
738 OSL_ENSURE(pTxtNode
, "ERROR: GetRegistry: no text node?");
740 throw uno::RuntimeException();
741 return pTxtNode
->GetRegistry();
744 bool Meta::IsInClipboard() const
746 const SwTxtNode
* const pTxtNode( GetTxtNode() );
747 // no text node: in UNDO OSL_ENSURE(pTxtNode, "IsInClipboard: no text node?");
748 return (pTxtNode
) ? pTxtNode
->IsInClipboard() : false;
751 bool Meta::IsInUndo() const
753 const SwTxtNode
* const pTxtNode( GetTxtNode() );
754 // no text node: in UNDO OSL_ENSURE(pTxtNode, "IsInUndo: no text node?");
755 return (pTxtNode
) ? pTxtNode
->IsInUndo() : true;
758 bool Meta::IsInContent() const
760 const SwTxtNode
* const pTxtNode( GetTxtNode() );
761 OSL_ENSURE(pTxtNode
, "IsInContent: no text node?");
762 return (pTxtNode
) ? pTxtNode
->IsInContent() : true;
765 ::com::sun::star::uno::Reference
< ::com::sun::star::rdf::XMetadatable
>
766 Meta::MakeUnoObject()
768 // re-use existing SwXMeta
769 SwClientIter
iter( *this );
770 SwClient
* pClient( iter
.First( TYPE( SwXMeta
) ) );
772 SwXMeta
*const pMeta( dynamic_cast<SwXMeta
*>(pClient
) );
773 if (pMeta
&& pMeta
->GetCoreObject() == this) {
776 pClient
= iter
.Next();
779 // create new SwXMeta
780 SwTxtMeta
* const pTxtAttr( GetTxtAttr() );
781 OSL_ENSURE(pTxtAttr
, "MakeUnoObject: no text attr?");
782 if (!pTxtAttr
) return 0;
783 SwTxtNode
* const pTxtNode( pTxtAttr
->GetTxtNode() );
784 OSL_ENSURE(pTxtNode
, "MakeUnoObject: no text node?");
785 if (!pTxtNode
) return 0;
786 const SwPosition
aPos(*pTxtNode
, *pTxtAttr
->GetStart());
787 const uno::Reference
<text::XText
> xParentText(
788 SwXTextRange::CreateParentXText(pTxtNode
->GetDoc(), aPos
) );
789 if (!xParentText
.is()) return 0;
790 return (RES_TXTATR_META
== m_pFmt
->Which())
791 ? new SwXMeta (pTxtNode
->GetDoc(), xParentText
, 0, pTxtAttr
)
792 : new SwXMetaField(pTxtNode
->GetDoc(), xParentText
, 0, pTxtAttr
);
795 /*************************************************************************
797 ************************************************************************/
799 MetaField::MetaField(SwFmtMeta
* const i_pFmt
,
800 const sal_uInt32 nNumberFormat
, const bool bIsFixedLanguage
)
802 , m_nNumberFormat( nNumberFormat
)
803 , m_bIsFixedLanguage( bIsFixedLanguage
)
807 void MetaField::GetPrefixAndSuffix(
808 ::rtl::OUString
*const o_pPrefix
, ::rtl::OUString
*const o_pSuffix
)
812 const uno::Reference
<rdf::XMetadatable
> xMetaField( MakeUnoObject() );
813 OSL_ENSURE(dynamic_cast<SwXMetaField
*>(xMetaField
.get()),
814 "GetPrefixAndSuffix: no SwXMetaField?");
817 SwTxtNode
* const pTxtNode( GetTxtNode() );
818 SwDocShell
const * const pShell(pTxtNode
->GetDoc()->GetDocShell());
819 const uno::Reference
<frame::XModel
> xModel(
820 (pShell
) ? pShell
->GetModel() : 0, uno::UNO_SET_THROW
);
821 getPrefixAndSuffix(xModel
, xMetaField
, o_pPrefix
, o_pSuffix
);
823 } catch (uno::Exception
) {
824 OSL_ENSURE(false, "exception?");
828 sal_uInt32
MetaField::GetNumberFormat(::rtl::OUString
const & rContent
) const
830 //TODO: this probably lacks treatment for some special cases
831 sal_uInt32
nNumberFormat( m_nNumberFormat
);
832 SwTxtNode
* const pTxtNode( GetTxtNode() );
835 SvNumberFormatter
*const pNumberFormatter(
836 pTxtNode
->GetDoc()->GetNumberFormatter() );
838 (void) pNumberFormatter
->IsNumberFormat(
839 rContent
, nNumberFormat
, number
);
841 return nNumberFormat
;
844 void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat
)
846 // effectively, the member is only a default:
847 // GetNumberFormat checks if the text actually conforms
848 m_nNumberFormat
= nNumberFormat
;
852 /*************************************************************************
853 class sw::MetaFieldManager
854 ************************************************************************/
857 MetaFieldManager::MetaFieldManager()
861 ::boost::shared_ptr
<MetaField
>
862 MetaFieldManager::makeMetaField(SwFmtMeta
* const i_pFmt
,
863 const sal_uInt32 nNumberFormat
, const bool bIsFixedLanguage
)
865 const ::boost::shared_ptr
<MetaField
> pMetaField(
866 new MetaField(i_pFmt
, nNumberFormat
, bIsFixedLanguage
) );
867 m_MetaFields
.push_back(pMetaField
);
873 bool operator()(::boost::weak_ptr
<MetaField
> const & pMetaField
) {
874 return pMetaField
.lock()->IsInUndo();
880 uno::Reference
<text::XTextField
>
881 operator()(::boost::weak_ptr
<MetaField
> const & pMetaField
) {
882 return uno::Reference
<text::XTextField
>(
883 pMetaField
.lock()->MakeUnoObject(), uno::UNO_QUERY
);
887 ::std::vector
< uno::Reference
<text::XTextField
> >
888 MetaFieldManager::getMetaFields()
890 // erase deleted fields
891 const MetaFieldList_t::iterator
iter(
892 ::std::remove_if(m_MetaFields
.begin(), m_MetaFields
.end(),
893 ::boost::bind(&::boost::weak_ptr
<MetaField
>::expired
, _1
)));
894 m_MetaFields
.erase(iter
, m_MetaFields
.end());
895 // filter out fields in UNDO
896 MetaFieldList_t
filtered(m_MetaFields
.size());
897 const MetaFieldList_t::iterator
iter2(
898 ::std::remove_copy_if(m_MetaFields
.begin(), m_MetaFields
.end(),
899 filtered
.begin(), IsInUndo()));
900 filtered
.erase(iter2
, filtered
.end());
901 // create uno objects
902 ::std::vector
< uno::Reference
<text::XTextField
> > ret(filtered
.size());
903 ::std::transform(filtered
.begin(), filtered
.end(), ret
.begin(),