xref: /aoo42x/main/sw/source/core/txtnode/fmtatr2.cxx (revision 782a276c)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10efeef26fSAndrew Rist  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12efeef26fSAndrew Rist  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19efeef26fSAndrew Rist  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27*782a276cSOliver-Rainer Wittmann #include <hintids.hxx>
28*782a276cSOliver-Rainer Wittmann #include <poolfmt.hxx>
29cdf0e10cSrcweir #include "unomid.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <basic/sbxvar.hxx>
32cdf0e10cSrcweir #include <svl/macitem.hxx>
33cdf0e10cSrcweir #include <svl/stritem.hxx>
34cdf0e10cSrcweir #include <svl/stylepool.hxx>
35cdf0e10cSrcweir #include <fmtautofmt.hxx>
36cdf0e10cSrcweir #include <fchrfmt.hxx>
37cdf0e10cSrcweir #include <fmtinfmt.hxx>
38cdf0e10cSrcweir #include <txtatr.hxx>
39cdf0e10cSrcweir #include <fmtruby.hxx>
40cdf0e10cSrcweir #include <charfmt.hxx>
41cdf0e10cSrcweir #include <hints.hxx>        // SwUpdateAttr
42cdf0e10cSrcweir #include <unostyle.hxx>
43cdf0e10cSrcweir #include <unoevent.hxx>		// SwHyperlinkEventDescriptor
44cdf0e10cSrcweir #include <com/sun/star/text/RubyAdjust.hdl>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <cmdid.h>
47cdf0e10cSrcweir #include <com/sun/star/uno/Any.h>
48cdf0e10cSrcweir #include <SwStyleNameMapper.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include <fmtmeta.hxx>
51cdf0e10cSrcweir #include <ndtxt.hxx> // for meta
52cdf0e10cSrcweir #include <doc.hxx> // for meta
53cdf0e10cSrcweir #include <unometa.hxx>
54cdf0e10cSrcweir #include <docsh.hxx>
55cdf0e10cSrcweir #include <svl/zforlist.hxx> // GetNumberFormat
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #include <boost/bind.hpp>
58cdf0e10cSrcweir #include <algorithm>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace ::com::sun::star;
62cdf0e10cSrcweir using ::rtl::OUString;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SwFmtINetFmt, SfxPoolItem);
65cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(SwFmtAutoFmt, SfxPoolItem);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*************************************************************************
68cdf0e10cSrcweir |*
69cdf0e10cSrcweir |*    class SwFmtCharFmt
70cdf0e10cSrcweir |*    Beschreibung
71cdf0e10cSrcweir |*    Ersterstellung    JP 23.11.90
72cdf0e10cSrcweir |*    Letzte Aenderung  JP 09.08.94
73cdf0e10cSrcweir |*
74cdf0e10cSrcweir *************************************************************************/
75cdf0e10cSrcweir 
SwFmtCharFmt(SwCharFmt * pFmt)76cdf0e10cSrcweir SwFmtCharFmt::SwFmtCharFmt( SwCharFmt *pFmt )
77cdf0e10cSrcweir 	: SfxPoolItem( RES_TXTATR_CHARFMT ),
78cdf0e10cSrcweir 	SwClient(pFmt),
79cdf0e10cSrcweir     pTxtAttr( 0 )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 
SwFmtCharFmt(const SwFmtCharFmt & rAttr)85cdf0e10cSrcweir SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt& rAttr )
86cdf0e10cSrcweir 	: SfxPoolItem( RES_TXTATR_CHARFMT ),
87cdf0e10cSrcweir 	SwClient( rAttr.GetCharFmt() ),
88cdf0e10cSrcweir     pTxtAttr( 0 )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
~SwFmtCharFmt()94cdf0e10cSrcweir SwFmtCharFmt::~SwFmtCharFmt() {}
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const98cdf0e10cSrcweir int SwFmtCharFmt::operator==( const SfxPoolItem& rAttr ) const
99cdf0e10cSrcweir {
100cdf0e10cSrcweir 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
101cdf0e10cSrcweir 	return GetCharFmt() == ((SwFmtCharFmt&)rAttr).GetCharFmt();
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 
Clone(SfxItemPool *) const106cdf0e10cSrcweir SfxPoolItem* SwFmtCharFmt::Clone( SfxItemPool* ) const
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	return new SwFmtCharFmt( *this );
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 
113cdf0e10cSrcweir // weiterleiten an das TextAttribut
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)114cdf0e10cSrcweir void SwFmtCharFmt::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir 	if( pTxtAttr )
117cdf0e10cSrcweir 		pTxtAttr->ModifyNotification( pOld, pNew );
118cdf0e10cSrcweir }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // weiterleiten an das TextAttribut
GetInfo(SfxPoolItem & rInfo) const123cdf0e10cSrcweir sal_Bool SwFmtCharFmt::GetInfo( SfxPoolItem& rInfo ) const
124cdf0e10cSrcweir {
125cdf0e10cSrcweir 	return pTxtAttr ? pTxtAttr->GetInfo( rInfo ) : sal_False;
126cdf0e10cSrcweir }
QueryValue(uno::Any & rVal,sal_uInt8) const127cdf0e10cSrcweir sal_Bool SwFmtCharFmt::QueryValue( uno::Any& rVal, sal_uInt8 ) const
128cdf0e10cSrcweir {
129cdf0e10cSrcweir 	String sCharFmtName;
130cdf0e10cSrcweir 	if(GetCharFmt())
131cdf0e10cSrcweir 		SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName,  nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
132cdf0e10cSrcweir 	rVal <<= OUString( sCharFmtName );
133cdf0e10cSrcweir 	return sal_True;
134cdf0e10cSrcweir }
PutValue(const uno::Any &,sal_uInt8)135cdf0e10cSrcweir sal_Bool SwFmtCharFmt::PutValue( const uno::Any& , sal_uInt8   )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir 	DBG_ERROR("Zeichenvorlage kann mit PutValue nicht gesetzt werden!");
138cdf0e10cSrcweir 	return sal_False;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir /*************************************************************************
142cdf0e10cSrcweir |*
143cdf0e10cSrcweir |*    class SwFmtAutoFmt
144cdf0e10cSrcweir |*    Beschreibung
145cdf0e10cSrcweir |*    Ersterstellung    AMA 12.05.06
146cdf0e10cSrcweir |*    Letzte Aenderung  AMA 12.05.06
147cdf0e10cSrcweir |*
148cdf0e10cSrcweir *************************************************************************/
149cdf0e10cSrcweir 
SwFmtAutoFmt(sal_uInt16 nInitWhich)150cdf0e10cSrcweir SwFmtAutoFmt::SwFmtAutoFmt( sal_uInt16 nInitWhich )
151cdf0e10cSrcweir     : SfxPoolItem( nInitWhich )
152cdf0e10cSrcweir {
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
SwFmtAutoFmt(const SwFmtAutoFmt & rAttr)155cdf0e10cSrcweir SwFmtAutoFmt::SwFmtAutoFmt( const SwFmtAutoFmt& rAttr )
156cdf0e10cSrcweir     : SfxPoolItem( rAttr.Which() ), mpHandle( rAttr.mpHandle )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
~SwFmtAutoFmt()160cdf0e10cSrcweir SwFmtAutoFmt::~SwFmtAutoFmt()
161cdf0e10cSrcweir {
162cdf0e10cSrcweir }
163cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const164cdf0e10cSrcweir int SwFmtAutoFmt::operator==( const SfxPoolItem& rAttr ) const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir 	ASSERT( SfxPoolItem::operator==( rAttr ), "different attributes" );
167cdf0e10cSrcweir     return mpHandle == ((SwFmtAutoFmt&)rAttr).mpHandle;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
Clone(SfxItemPool *) const170cdf0e10cSrcweir SfxPoolItem* SwFmtAutoFmt::Clone( SfxItemPool* ) const
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	return new SwFmtAutoFmt( *this );
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
QueryValue(uno::Any & rVal,sal_uInt8) const175cdf0e10cSrcweir sal_Bool SwFmtAutoFmt::QueryValue( uno::Any& rVal, sal_uInt8 ) const
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	String sCharFmtName = StylePool::nameOf( mpHandle );
178cdf0e10cSrcweir 	rVal <<= OUString( sCharFmtName );
179cdf0e10cSrcweir 	return sal_True;
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
PutValue(const uno::Any &,sal_uInt8)182cdf0e10cSrcweir sal_Bool SwFmtAutoFmt::PutValue( const uno::Any& , sal_uInt8 )
183cdf0e10cSrcweir {
184cdf0e10cSrcweir     //the format is not renameable via API
185cdf0e10cSrcweir 	return sal_False;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir /*************************************************************************
189cdf0e10cSrcweir |*
190cdf0e10cSrcweir |*    class SwFmtINetFmt
191cdf0e10cSrcweir |*    Beschreibung
192cdf0e10cSrcweir |*    Ersterstellung    AMA 02.08.96
193cdf0e10cSrcweir |*    Letzte Aenderung  AMA 02.08.96
194cdf0e10cSrcweir |*
195cdf0e10cSrcweir *************************************************************************/
196cdf0e10cSrcweir 
SwFmtINetFmt()197cdf0e10cSrcweir SwFmtINetFmt::SwFmtINetFmt()
198*782a276cSOliver-Rainer Wittmann 	: SfxPoolItem( RES_TXTATR_INETFMT )
199*782a276cSOliver-Rainer Wittmann     , msURL()
200*782a276cSOliver-Rainer Wittmann     , msTargetFrame()
201*782a276cSOliver-Rainer Wittmann     , msINetFmtName()
202*782a276cSOliver-Rainer Wittmann     , msVisitedFmtName()
203*782a276cSOliver-Rainer Wittmann     , msHyperlinkName()
204*782a276cSOliver-Rainer Wittmann     , mpMacroTbl( 0 )
205*782a276cSOliver-Rainer Wittmann     , mpTxtAttr( 0 )
206*782a276cSOliver-Rainer Wittmann     , mnINetFmtId( 0 )
207*782a276cSOliver-Rainer Wittmann     , mnVisitedFmtId( 0 )
208cdf0e10cSrcweir {}
209cdf0e10cSrcweir 
SwFmtINetFmt(const XubString & rURL,const XubString & rTarget)210cdf0e10cSrcweir SwFmtINetFmt::SwFmtINetFmt( const XubString& rURL, const XubString& rTarget )
211*782a276cSOliver-Rainer Wittmann     : SfxPoolItem( RES_TXTATR_INETFMT )
212*782a276cSOliver-Rainer Wittmann     , msURL( rURL )
213*782a276cSOliver-Rainer Wittmann     , msTargetFrame( rTarget )
214*782a276cSOliver-Rainer Wittmann     , msINetFmtName()
215*782a276cSOliver-Rainer Wittmann     , msVisitedFmtName()
216*782a276cSOliver-Rainer Wittmann     , msHyperlinkName()
217*782a276cSOliver-Rainer Wittmann     , mpMacroTbl( 0 )
218*782a276cSOliver-Rainer Wittmann     , mpTxtAttr( 0 )
219*782a276cSOliver-Rainer Wittmann     , mnINetFmtId( RES_POOLCHR_INET_NORMAL )
220*782a276cSOliver-Rainer Wittmann     , mnVisitedFmtId( RES_POOLCHR_INET_VISIT )
221cdf0e10cSrcweir {
222*782a276cSOliver-Rainer Wittmann     SwStyleNameMapper::FillUIName( mnINetFmtId, msINetFmtName );
223*782a276cSOliver-Rainer Wittmann     SwStyleNameMapper::FillUIName( mnVisitedFmtId, msVisitedFmtName );
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
SwFmtINetFmt(const SwFmtINetFmt & rAttr)226cdf0e10cSrcweir SwFmtINetFmt::SwFmtINetFmt( const SwFmtINetFmt& rAttr )
227*782a276cSOliver-Rainer Wittmann 	: SfxPoolItem( RES_TXTATR_INETFMT )
228*782a276cSOliver-Rainer Wittmann     , msURL( rAttr.GetValue() )
229*782a276cSOliver-Rainer Wittmann     , msTargetFrame( rAttr.msTargetFrame )
230*782a276cSOliver-Rainer Wittmann     , msINetFmtName( rAttr.msINetFmtName )
231*782a276cSOliver-Rainer Wittmann     , msVisitedFmtName( rAttr.msVisitedFmtName )
232*782a276cSOliver-Rainer Wittmann     , msHyperlinkName( rAttr.msHyperlinkName )
233*782a276cSOliver-Rainer Wittmann     , mpMacroTbl( 0 )
234*782a276cSOliver-Rainer Wittmann     , mpTxtAttr( 0 )
235*782a276cSOliver-Rainer Wittmann     , mnINetFmtId( rAttr.mnINetFmtId )
236*782a276cSOliver-Rainer Wittmann     , mnVisitedFmtId( rAttr.mnVisitedFmtId )
237cdf0e10cSrcweir {
238*782a276cSOliver-Rainer Wittmann     if ( rAttr.GetMacroTbl() )
239*782a276cSOliver-Rainer Wittmann         mpMacroTbl = new SvxMacroTableDtor( *rAttr.GetMacroTbl() );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
~SwFmtINetFmt()242cdf0e10cSrcweir SwFmtINetFmt::~SwFmtINetFmt()
243cdf0e10cSrcweir {
244*782a276cSOliver-Rainer Wittmann 	delete mpMacroTbl;
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const249cdf0e10cSrcweir int SwFmtINetFmt::operator==( const SfxPoolItem& rAttr ) const
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
252cdf0e10cSrcweir 	sal_Bool bRet = SfxPoolItem::operator==( (SfxPoolItem&) rAttr )
253*782a276cSOliver-Rainer Wittmann 				&& msURL == ((SwFmtINetFmt&)rAttr).msURL
254*782a276cSOliver-Rainer Wittmann 				&& msHyperlinkName == ((SwFmtINetFmt&)rAttr).msHyperlinkName
255*782a276cSOliver-Rainer Wittmann 				&& msTargetFrame == ((SwFmtINetFmt&)rAttr).msTargetFrame
256*782a276cSOliver-Rainer Wittmann 				&& msINetFmtName == ((SwFmtINetFmt&)rAttr).msINetFmtName
257*782a276cSOliver-Rainer Wittmann 				&& msVisitedFmtName == ((SwFmtINetFmt&)rAttr).msVisitedFmtName
258*782a276cSOliver-Rainer Wittmann 				&& mnINetFmtId == ((SwFmtINetFmt&)rAttr).mnINetFmtId
259*782a276cSOliver-Rainer Wittmann 				&& mnVisitedFmtId == ((SwFmtINetFmt&)rAttr).mnVisitedFmtId;
260cdf0e10cSrcweir 
261cdf0e10cSrcweir 	if( !bRet )
262cdf0e10cSrcweir 		return sal_False;
263cdf0e10cSrcweir 
264*782a276cSOliver-Rainer Wittmann 	const SvxMacroTableDtor* pOther = ((SwFmtINetFmt&)rAttr).mpMacroTbl;
265*782a276cSOliver-Rainer Wittmann 	if( !mpMacroTbl )
266cdf0e10cSrcweir 		return ( !pOther || !pOther->Count() );
267cdf0e10cSrcweir 	if( !pOther )
268*782a276cSOliver-Rainer Wittmann 		return 0 == mpMacroTbl->Count();
269cdf0e10cSrcweir 
270*782a276cSOliver-Rainer Wittmann 	const SvxMacroTableDtor& rOwn = *mpMacroTbl;
271cdf0e10cSrcweir 	const SvxMacroTableDtor& rOther = *pOther;
272cdf0e10cSrcweir 
273cdf0e10cSrcweir 	// Anzahl unterschiedlich => auf jeden Fall ungleich
274cdf0e10cSrcweir 	if( rOwn.Count() != rOther.Count() )
275cdf0e10cSrcweir 		return sal_False;
276cdf0e10cSrcweir 
277cdf0e10cSrcweir 	// einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig
278cdf0e10cSrcweir 	for( sal_uInt16 nNo = 0; nNo < rOwn.Count(); ++nNo )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		const SvxMacro *pOwnMac = rOwn.GetObject(nNo);
281cdf0e10cSrcweir 		const SvxMacro *pOtherMac = rOther.GetObject(nNo);
282cdf0e10cSrcweir 		if ( 	rOwn.GetKey(pOwnMac) != rOther.GetKey(pOtherMac)  ||
283cdf0e10cSrcweir 				pOwnMac->GetLibName() != pOtherMac->GetLibName() ||
284cdf0e10cSrcweir 				pOwnMac->GetMacName() != pOtherMac->GetMacName() )
285cdf0e10cSrcweir 			return sal_False;
286cdf0e10cSrcweir 	}
287cdf0e10cSrcweir 	return sal_True;
288cdf0e10cSrcweir }
289cdf0e10cSrcweir 
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
Clone(SfxItemPool *) const292cdf0e10cSrcweir SfxPoolItem* SwFmtINetFmt::Clone( SfxItemPool* ) const
293cdf0e10cSrcweir {
294cdf0e10cSrcweir 	return new SwFmtINetFmt( *this );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir 
297cdf0e10cSrcweir 
298cdf0e10cSrcweir 
SetMacroTbl(const SvxMacroTableDtor * pNewTbl)299cdf0e10cSrcweir void SwFmtINetFmt::SetMacroTbl( const SvxMacroTableDtor* pNewTbl )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir 	if( pNewTbl )
302cdf0e10cSrcweir 	{
303*782a276cSOliver-Rainer Wittmann 		if( mpMacroTbl )
304*782a276cSOliver-Rainer Wittmann 			*mpMacroTbl = *pNewTbl;
305cdf0e10cSrcweir 		else
306*782a276cSOliver-Rainer Wittmann 			mpMacroTbl = new SvxMacroTableDtor( *pNewTbl );
307cdf0e10cSrcweir 	}
308*782a276cSOliver-Rainer Wittmann 	else if( mpMacroTbl )
309*782a276cSOliver-Rainer Wittmann 		delete mpMacroTbl, mpMacroTbl = 0;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 
SetMacro(sal_uInt16 nEvent,const SvxMacro & rMacro)314cdf0e10cSrcweir void SwFmtINetFmt::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
315cdf0e10cSrcweir {
316*782a276cSOliver-Rainer Wittmann 	if( !mpMacroTbl )
317*782a276cSOliver-Rainer Wittmann 		mpMacroTbl = new SvxMacroTableDtor;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir 	SvxMacro *pOldMacro;
320*782a276cSOliver-Rainer Wittmann 	if( 0 != ( pOldMacro = mpMacroTbl->Get( nEvent )) )
321cdf0e10cSrcweir 	{
322cdf0e10cSrcweir 		delete pOldMacro;
323*782a276cSOliver-Rainer Wittmann 		mpMacroTbl->Replace( nEvent, new SvxMacro( rMacro ) );
324cdf0e10cSrcweir 	}
325cdf0e10cSrcweir 	else
326*782a276cSOliver-Rainer Wittmann 		mpMacroTbl->Insert( nEvent, new SvxMacro( rMacro ) );
327cdf0e10cSrcweir }
328cdf0e10cSrcweir 
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 
GetMacro(sal_uInt16 nEvent) const331cdf0e10cSrcweir const SvxMacro* SwFmtINetFmt::GetMacro( sal_uInt16 nEvent ) const
332cdf0e10cSrcweir {
333cdf0e10cSrcweir 	const SvxMacro* pRet = 0;
334*782a276cSOliver-Rainer Wittmann 	if( mpMacroTbl && mpMacroTbl->IsKeyValid( nEvent ) )
335*782a276cSOliver-Rainer Wittmann 		pRet = mpMacroTbl->Get( nEvent );
336cdf0e10cSrcweir 	return pRet;
337cdf0e10cSrcweir }
338cdf0e10cSrcweir 
339cdf0e10cSrcweir 
340cdf0e10cSrcweir 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const341cdf0e10cSrcweir sal_Bool SwFmtINetFmt::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
342cdf0e10cSrcweir {
343cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
344cdf0e10cSrcweir 	XubString sVal;
345cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
346cdf0e10cSrcweir 	switch(nMemberId)
347cdf0e10cSrcweir 	{
348cdf0e10cSrcweir 		case MID_URL_URL:
349*782a276cSOliver-Rainer Wittmann 			sVal = msURL;
350cdf0e10cSrcweir 		break;
351cdf0e10cSrcweir 		case MID_URL_TARGET:
352*782a276cSOliver-Rainer Wittmann 			sVal = msTargetFrame;
353cdf0e10cSrcweir 		break;
354cdf0e10cSrcweir 		case MID_URL_HYPERLINKNAME:
355*782a276cSOliver-Rainer Wittmann 			sVal = msHyperlinkName;
356cdf0e10cSrcweir 		break;
357cdf0e10cSrcweir 		case MID_URL_VISITED_FMT:
358*782a276cSOliver-Rainer Wittmann 			sVal = msVisitedFmtName;
359*782a276cSOliver-Rainer Wittmann 			if( !sVal.Len() && mnVisitedFmtId != 0 )
360*782a276cSOliver-Rainer Wittmann 				SwStyleNameMapper::FillUIName( mnVisitedFmtId, sVal );
361cdf0e10cSrcweir 			if( sVal.Len() )
362cdf0e10cSrcweir 				SwStyleNameMapper::FillProgName( sVal, sVal, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
363cdf0e10cSrcweir 		break;
364cdf0e10cSrcweir 		case MID_URL_UNVISITED_FMT:
365*782a276cSOliver-Rainer Wittmann 			sVal = msINetFmtName;
366*782a276cSOliver-Rainer Wittmann 			if( !sVal.Len() && mnINetFmtId != 0 )
367*782a276cSOliver-Rainer Wittmann 				SwStyleNameMapper::FillUIName( mnINetFmtId, sVal );
368cdf0e10cSrcweir 			if( sVal.Len() )
369cdf0e10cSrcweir 				SwStyleNameMapper::FillProgName( sVal, sVal, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
370cdf0e10cSrcweir 		break;
371cdf0e10cSrcweir 		case MID_URL_HYPERLINKEVENTS:
372cdf0e10cSrcweir 		{
373cdf0e10cSrcweir 			// create (and return) event descriptor
374cdf0e10cSrcweir 			SwHyperlinkEventDescriptor* pEvents =
375cdf0e10cSrcweir 				new SwHyperlinkEventDescriptor();
376cdf0e10cSrcweir 			pEvents->copyMacrosFromINetFmt(*this);
377cdf0e10cSrcweir 			uno::Reference<container::XNameReplace> xNameReplace(pEvents);
378cdf0e10cSrcweir 
379cdf0e10cSrcweir 			// all others return a string; so we just set rVal here and exit
380cdf0e10cSrcweir 			rVal <<= xNameReplace;
381cdf0e10cSrcweir 			return bRet;
382cdf0e10cSrcweir 		}
383cdf0e10cSrcweir         default:
384cdf0e10cSrcweir         break;
385cdf0e10cSrcweir 	}
386cdf0e10cSrcweir 	rVal <<= OUString(sVal);
387cdf0e10cSrcweir 	return bRet;
388cdf0e10cSrcweir }
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)389cdf0e10cSrcweir sal_Bool SwFmtINetFmt::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId  )
390cdf0e10cSrcweir {
391cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
392cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 	// all properties except HyperlinkEvents are of type string, hence
395cdf0e10cSrcweir 	// we treat HyperlinkEvents specially
396cdf0e10cSrcweir 	if (MID_URL_HYPERLINKEVENTS == nMemberId)
397cdf0e10cSrcweir 	{
398cdf0e10cSrcweir 		uno::Reference<container::XNameReplace> xReplace;
399cdf0e10cSrcweir 		rVal >>= xReplace;
400cdf0e10cSrcweir 		if (xReplace.is())
401cdf0e10cSrcweir 		{
402cdf0e10cSrcweir 			// Create hyperlink event descriptor. Then copy events
403cdf0e10cSrcweir 			// from argument into descriptor. Then copy events from
404cdf0e10cSrcweir 			// the descriptor into the format.
405cdf0e10cSrcweir 			SwHyperlinkEventDescriptor* pEvents = new SwHyperlinkEventDescriptor();
406cdf0e10cSrcweir             uno::Reference< lang::XServiceInfo> xHold = pEvents;
407cdf0e10cSrcweir 			pEvents->copyMacrosFromNameReplace(xReplace);
408cdf0e10cSrcweir 			pEvents->copyMacrosIntoINetFmt(*this);
409cdf0e10cSrcweir 		}
410cdf0e10cSrcweir 		else
411cdf0e10cSrcweir 		{
412cdf0e10cSrcweir 			// wrong type!
413cdf0e10cSrcweir 			bRet = sal_False;
414cdf0e10cSrcweir 		}
415cdf0e10cSrcweir 	}
416cdf0e10cSrcweir 	else
417cdf0e10cSrcweir 	{
418cdf0e10cSrcweir 		// all string properties:
419cdf0e10cSrcweir 		if(rVal.getValueType() != ::getCppuType((rtl::OUString*)0))
420cdf0e10cSrcweir 			return sal_False;
421cdf0e10cSrcweir 		XubString sVal = *(rtl::OUString*)rVal.getValue();
422cdf0e10cSrcweir 		switch(nMemberId)
423cdf0e10cSrcweir 		{
424cdf0e10cSrcweir 			case MID_URL_URL:
425*782a276cSOliver-Rainer Wittmann 				msURL = sVal;
426cdf0e10cSrcweir 				break;
427cdf0e10cSrcweir 			case MID_URL_TARGET:
428*782a276cSOliver-Rainer Wittmann 				msTargetFrame = sVal;
429cdf0e10cSrcweir 				break;
430cdf0e10cSrcweir 			case MID_URL_HYPERLINKNAME:
431*782a276cSOliver-Rainer Wittmann 				msHyperlinkName = sVal;
432cdf0e10cSrcweir 				break;
433cdf0e10cSrcweir 			case MID_URL_VISITED_FMT:
434cdf0e10cSrcweir 			{
435cdf0e10cSrcweir 				String aString;
436cdf0e10cSrcweir 				SwStyleNameMapper::FillUIName( sVal, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
437*782a276cSOliver-Rainer Wittmann 				msVisitedFmtName = OUString ( aString );
438*782a276cSOliver-Rainer Wittmann 				mnVisitedFmtId = SwStyleNameMapper::GetPoolIdFromUIName( msVisitedFmtName,
439cdf0e10cSrcweir 											   nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
440cdf0e10cSrcweir 			}
441cdf0e10cSrcweir 			break;
442cdf0e10cSrcweir 			case MID_URL_UNVISITED_FMT:
443cdf0e10cSrcweir 			{
444cdf0e10cSrcweir 				String aString;
445cdf0e10cSrcweir 				SwStyleNameMapper::FillUIName( sVal, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
446*782a276cSOliver-Rainer Wittmann 				msINetFmtName = OUString ( aString );
447*782a276cSOliver-Rainer Wittmann 				mnINetFmtId = SwStyleNameMapper::GetPoolIdFromUIName( msINetFmtName,	nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
448cdf0e10cSrcweir 			}
449cdf0e10cSrcweir 			break;
450cdf0e10cSrcweir 			default:
451cdf0e10cSrcweir 				bRet = sal_False;
452cdf0e10cSrcweir 		}
453cdf0e10cSrcweir 	}
454cdf0e10cSrcweir 	return bRet;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 
458cdf0e10cSrcweir /*************************************************************************
459cdf0e10cSrcweir |*    class SwFmtRuby
460cdf0e10cSrcweir *************************************************************************/
461cdf0e10cSrcweir 
SwFmtRuby(const String & rRubyTxt)462cdf0e10cSrcweir SwFmtRuby::SwFmtRuby( const String& rRubyTxt )
463cdf0e10cSrcweir 	: SfxPoolItem( RES_TXTATR_CJK_RUBY ),
464cdf0e10cSrcweir 	sRubyTxt( rRubyTxt ),
465cdf0e10cSrcweir     pTxtAttr( 0 ),
466cdf0e10cSrcweir     nCharFmtId( 0 ),
467cdf0e10cSrcweir     nPosition( 0 ),
468cdf0e10cSrcweir     nAdjustment( 0 )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
SwFmtRuby(const SwFmtRuby & rAttr)472cdf0e10cSrcweir SwFmtRuby::SwFmtRuby( const SwFmtRuby& rAttr )
473cdf0e10cSrcweir 	: SfxPoolItem( RES_TXTATR_CJK_RUBY ),
474cdf0e10cSrcweir 	sRubyTxt( rAttr.sRubyTxt ),
475cdf0e10cSrcweir 	sCharFmtName( rAttr.sCharFmtName ),
476cdf0e10cSrcweir     pTxtAttr( 0 ),
477cdf0e10cSrcweir     nCharFmtId( rAttr.nCharFmtId),
478cdf0e10cSrcweir     nPosition( rAttr.nPosition ),
479cdf0e10cSrcweir     nAdjustment( rAttr.nAdjustment )
480cdf0e10cSrcweir {
481cdf0e10cSrcweir }
482cdf0e10cSrcweir 
~SwFmtRuby()483cdf0e10cSrcweir SwFmtRuby::~SwFmtRuby()
484cdf0e10cSrcweir {
485cdf0e10cSrcweir }
486cdf0e10cSrcweir 
operator =(const SwFmtRuby & rAttr)487cdf0e10cSrcweir SwFmtRuby& SwFmtRuby::operator=( const SwFmtRuby& rAttr )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	sRubyTxt = rAttr.sRubyTxt;
490cdf0e10cSrcweir 	sCharFmtName = rAttr.sCharFmtName;
491cdf0e10cSrcweir 	nCharFmtId = rAttr.nCharFmtId;
492cdf0e10cSrcweir 	nPosition = rAttr.nPosition;
493cdf0e10cSrcweir 	nAdjustment = rAttr.nAdjustment;
494cdf0e10cSrcweir 	pTxtAttr =  0;
495cdf0e10cSrcweir 	return *this;
496cdf0e10cSrcweir }
497cdf0e10cSrcweir 
operator ==(const SfxPoolItem & rAttr) const498cdf0e10cSrcweir int SwFmtRuby::operator==( const SfxPoolItem& rAttr ) const
499cdf0e10cSrcweir {
500cdf0e10cSrcweir 	ASSERT( SfxPoolItem::operator==( rAttr ), "keine gleichen Attribute" );
501cdf0e10cSrcweir 	return sRubyTxt == ((SwFmtRuby&)rAttr).sRubyTxt &&
502cdf0e10cSrcweir 		   sCharFmtName == ((SwFmtRuby&)rAttr).sCharFmtName &&
503cdf0e10cSrcweir 		   nCharFmtId == ((SwFmtRuby&)rAttr).nCharFmtId &&
504cdf0e10cSrcweir 		   nPosition == ((SwFmtRuby&)rAttr).nPosition &&
505cdf0e10cSrcweir 		   nAdjustment == ((SwFmtRuby&)rAttr).nAdjustment;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
Clone(SfxItemPool *) const508cdf0e10cSrcweir SfxPoolItem* SwFmtRuby::Clone( SfxItemPool* ) const
509cdf0e10cSrcweir {
510cdf0e10cSrcweir 	return new SwFmtRuby( *this );
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
QueryValue(uno::Any & rVal,sal_uInt8 nMemberId) const513cdf0e10cSrcweir sal_Bool SwFmtRuby::QueryValue( uno::Any& rVal,
514cdf0e10cSrcweir 							sal_uInt8 nMemberId ) const
515cdf0e10cSrcweir {
516cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
517cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
518cdf0e10cSrcweir 	switch( nMemberId )
519cdf0e10cSrcweir 	{
520cdf0e10cSrcweir 		case MID_RUBY_TEXT: rVal <<= (OUString)sRubyTxt; 					break;
521cdf0e10cSrcweir  		case MID_RUBY_ADJUST:	rVal <<= (sal_Int16)nAdjustment;	break;
522cdf0e10cSrcweir 		case MID_RUBY_CHARSTYLE:
523cdf0e10cSrcweir 		{
524cdf0e10cSrcweir 			String aString;
525cdf0e10cSrcweir 			SwStyleNameMapper::FillProgName(sCharFmtName, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
526cdf0e10cSrcweir 			rVal <<= OUString ( aString );
527cdf0e10cSrcweir 		}
528cdf0e10cSrcweir 		break;
529cdf0e10cSrcweir         case MID_RUBY_ABOVE:
530cdf0e10cSrcweir         {
531cdf0e10cSrcweir             sal_Bool bAbove = !nPosition;
532cdf0e10cSrcweir             rVal.setValue(&bAbove, ::getBooleanCppuType());
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir         break;
535cdf0e10cSrcweir         default:
536cdf0e10cSrcweir 			bRet = sal_False;
537cdf0e10cSrcweir 	}
538cdf0e10cSrcweir 	return bRet;
539cdf0e10cSrcweir }
PutValue(const uno::Any & rVal,sal_uInt8 nMemberId)540cdf0e10cSrcweir sal_Bool SwFmtRuby::PutValue( const uno::Any& rVal,
541cdf0e10cSrcweir 							sal_uInt8 nMemberId  )
542cdf0e10cSrcweir {
543cdf0e10cSrcweir 	sal_Bool bRet = sal_True;
544cdf0e10cSrcweir     nMemberId &= ~CONVERT_TWIPS;
545cdf0e10cSrcweir 	switch( nMemberId )
546cdf0e10cSrcweir 	{
547cdf0e10cSrcweir 		case MID_RUBY_TEXT:
548cdf0e10cSrcweir 		{
549cdf0e10cSrcweir 			OUString sTmp;
550cdf0e10cSrcweir 			bRet = rVal >>= sTmp;
551cdf0e10cSrcweir 			sRubyTxt = sTmp;
552cdf0e10cSrcweir 		}
553cdf0e10cSrcweir 		break;
554cdf0e10cSrcweir  		case MID_RUBY_ADJUST:
555cdf0e10cSrcweir 		{
556cdf0e10cSrcweir 			sal_Int16 nSet = 0;
557cdf0e10cSrcweir 			rVal >>= nSet;
558cdf0e10cSrcweir             if(nSet >= 0 && nSet <= text::RubyAdjust_INDENT_BLOCK)
559cdf0e10cSrcweir 				nAdjustment = nSet;
560cdf0e10cSrcweir 			else
561cdf0e10cSrcweir 				bRet = sal_False;
562cdf0e10cSrcweir 		}
563cdf0e10cSrcweir 		break;
564cdf0e10cSrcweir         case MID_RUBY_ABOVE:
565cdf0e10cSrcweir         {
566cdf0e10cSrcweir             const uno::Type& rType = ::getBooleanCppuType();
567cdf0e10cSrcweir             if(rVal.hasValue() && rVal.getValueType() == rType)
568cdf0e10cSrcweir             {
569cdf0e10cSrcweir                 sal_Bool bAbove = *(sal_Bool*)rVal.getValue();
570cdf0e10cSrcweir                 nPosition = bAbove ? 0 : 1;
571cdf0e10cSrcweir             }
572cdf0e10cSrcweir         }
573cdf0e10cSrcweir         break;
574cdf0e10cSrcweir         case MID_RUBY_CHARSTYLE:
575cdf0e10cSrcweir         {
576cdf0e10cSrcweir             OUString sTmp;
577cdf0e10cSrcweir             bRet = rVal >>= sTmp;
578cdf0e10cSrcweir             if(bRet)
579cdf0e10cSrcweir                 sCharFmtName = SwStyleNameMapper::GetUIName(sTmp, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
580cdf0e10cSrcweir         }
581cdf0e10cSrcweir         break;
582cdf0e10cSrcweir 		default:
583cdf0e10cSrcweir 			bRet = sal_False;
584cdf0e10cSrcweir 	}
585cdf0e10cSrcweir 	return bRet;
586cdf0e10cSrcweir }
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 
589cdf0e10cSrcweir /*************************************************************************
590cdf0e10cSrcweir  class SwFmtMeta
591cdf0e10cSrcweir  ************************************************************************/
592cdf0e10cSrcweir 
CreatePoolDefault(const sal_uInt16 i_nWhich)593cdf0e10cSrcweir SwFmtMeta * SwFmtMeta::CreatePoolDefault(const sal_uInt16 i_nWhich)
594cdf0e10cSrcweir {
595cdf0e10cSrcweir     return new SwFmtMeta(i_nWhich);
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
SwFmtMeta(const sal_uInt16 i_nWhich)598cdf0e10cSrcweir SwFmtMeta::SwFmtMeta(const sal_uInt16 i_nWhich)
599cdf0e10cSrcweir     : SfxPoolItem( i_nWhich )
600cdf0e10cSrcweir     , m_pMeta()
601cdf0e10cSrcweir     , m_pTxtAttr( 0 )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir     ASSERT((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
604cdf0e10cSrcweir             "ERROR: SwFmtMeta: invalid which id!");
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
SwFmtMeta(::boost::shared_ptr<::sw::Meta> const & i_pMeta,const sal_uInt16 i_nWhich)607cdf0e10cSrcweir SwFmtMeta::SwFmtMeta( ::boost::shared_ptr< ::sw::Meta > const & i_pMeta,
608cdf0e10cSrcweir                         const sal_uInt16 i_nWhich )
609cdf0e10cSrcweir     : SfxPoolItem( i_nWhich )
610cdf0e10cSrcweir     , m_pMeta( i_pMeta )
611cdf0e10cSrcweir     , m_pTxtAttr( 0 )
612cdf0e10cSrcweir {
613cdf0e10cSrcweir     ASSERT((RES_TXTATR_META == i_nWhich) || (RES_TXTATR_METAFIELD == i_nWhich),
614cdf0e10cSrcweir             "ERROR: SwFmtMeta: invalid which id!");
615cdf0e10cSrcweir     ASSERT(m_pMeta, "SwFmtMeta: no Meta ?");
616cdf0e10cSrcweir     // DO NOT call m_pMeta->SetFmtMeta(this) here; only from SetTxtAttr!
617cdf0e10cSrcweir }
618cdf0e10cSrcweir 
~SwFmtMeta()619cdf0e10cSrcweir SwFmtMeta::~SwFmtMeta()
620cdf0e10cSrcweir {
621cdf0e10cSrcweir     if (m_pMeta && (m_pMeta->GetFmtMeta() == this))
622cdf0e10cSrcweir     {
623cdf0e10cSrcweir         NotifyChangeTxtNode(0);
624cdf0e10cSrcweir         m_pMeta->SetFmtMeta(0);
625cdf0e10cSrcweir     }
626cdf0e10cSrcweir }
627cdf0e10cSrcweir 
operator ==(const SfxPoolItem & i_rOther) const628cdf0e10cSrcweir int SwFmtMeta::operator==( const SfxPoolItem & i_rOther ) const
629cdf0e10cSrcweir {
630cdf0e10cSrcweir     ASSERT( SfxPoolItem::operator==( i_rOther ), "i just copied this assert" );
631cdf0e10cSrcweir     return SfxPoolItem::operator==( i_rOther )
632cdf0e10cSrcweir         && (m_pMeta == static_cast<SwFmtMeta const &>( i_rOther ).m_pMeta);
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
Clone(SfxItemPool *) const635cdf0e10cSrcweir SfxPoolItem * SwFmtMeta::Clone( SfxItemPool * /*pPool*/ ) const
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     // if this is indeed a copy, then DoCopy must be called later!
638cdf0e10cSrcweir     return (m_pMeta) // #i105148# pool default may be cloned also!
639cdf0e10cSrcweir         ? new SwFmtMeta( m_pMeta, Which() ) : new SwFmtMeta( Which() );
640cdf0e10cSrcweir }
641cdf0e10cSrcweir 
SetTxtAttr(SwTxtMeta * const i_pTxtAttr)642cdf0e10cSrcweir void SwFmtMeta::SetTxtAttr(SwTxtMeta * const i_pTxtAttr)
643cdf0e10cSrcweir {
644cdf0e10cSrcweir     OSL_ENSURE(!(m_pTxtAttr && i_pTxtAttr),
645cdf0e10cSrcweir         "SwFmtMeta::SetTxtAttr: already has text attribute?");
646cdf0e10cSrcweir     OSL_ENSURE(  m_pTxtAttr || i_pTxtAttr ,
647cdf0e10cSrcweir         "SwFmtMeta::SetTxtAttr: no attribute to remove?");
648cdf0e10cSrcweir     m_pTxtAttr = i_pTxtAttr;
649cdf0e10cSrcweir     OSL_ENSURE(m_pMeta, "inserted SwFmtMeta has no sw::Meta?");
650cdf0e10cSrcweir     // the sw::Meta must be able to find the current text attribute!
651cdf0e10cSrcweir     if (m_pMeta)
652cdf0e10cSrcweir     {
653cdf0e10cSrcweir         if (i_pTxtAttr)
654cdf0e10cSrcweir         {
655cdf0e10cSrcweir             m_pMeta->SetFmtMeta(this);
656cdf0e10cSrcweir         }
657cdf0e10cSrcweir         else if (m_pMeta->GetFmtMeta() == this)
658cdf0e10cSrcweir         {   // text attribute gone => de-register from text node!
659cdf0e10cSrcweir             NotifyChangeTxtNode(0);
660cdf0e10cSrcweir             m_pMeta->SetFmtMeta(0);
661cdf0e10cSrcweir         }
662cdf0e10cSrcweir     }
663cdf0e10cSrcweir }
664cdf0e10cSrcweir 
NotifyChangeTxtNode(SwTxtNode * const pTxtNode)665cdf0e10cSrcweir void SwFmtMeta::NotifyChangeTxtNode(SwTxtNode *const pTxtNode)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir     // N.B.: do not reset m_pTxtAttr here: see call in nodes.cxx,
668cdf0e10cSrcweir     // where the hint is not deleted!
669cdf0e10cSrcweir     OSL_ENSURE(m_pMeta, "SwFmtMeta::NotifyChangeTxtNode: no Meta?");
670cdf0e10cSrcweir     if (m_pMeta && (m_pMeta->GetFmtMeta() == this))
671cdf0e10cSrcweir     {   // do not call Modify, that would call SwXMeta::Modify!
672cdf0e10cSrcweir         m_pMeta->NotifyChangeTxtNode(pTxtNode);
673cdf0e10cSrcweir     }
674cdf0e10cSrcweir }
675cdf0e10cSrcweir 
676cdf0e10cSrcweir // this SwFmtMeta has been cloned and points at the same sw::Meta as the source
677cdf0e10cSrcweir // this method copies the sw::Meta
DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,SwTxtNode & i_rTargetTxtNode)678cdf0e10cSrcweir void SwFmtMeta::DoCopy(::sw::MetaFieldManager & i_rTargetDocManager,
679cdf0e10cSrcweir         SwTxtNode & i_rTargetTxtNode)
680cdf0e10cSrcweir {
681cdf0e10cSrcweir     OSL_ENSURE(m_pMeta, "DoCopy called for SwFmtMeta with no sw::Meta?");
682cdf0e10cSrcweir     if (m_pMeta)
683cdf0e10cSrcweir     {
684cdf0e10cSrcweir         const ::boost::shared_ptr< ::sw::Meta> pOriginal( m_pMeta );
685cdf0e10cSrcweir         if (RES_TXTATR_META == Which())
686cdf0e10cSrcweir         {
687cdf0e10cSrcweir             m_pMeta.reset( new ::sw::Meta(this) );
688cdf0e10cSrcweir         }
689cdf0e10cSrcweir         else
690cdf0e10cSrcweir         {
691cdf0e10cSrcweir             ::sw::MetaField *const pMetaField(
692cdf0e10cSrcweir                 static_cast< ::sw::MetaField* >(pOriginal.get()));
693cdf0e10cSrcweir             m_pMeta = i_rTargetDocManager.makeMetaField( this,
694cdf0e10cSrcweir                 pMetaField->m_nNumberFormat, pMetaField->IsFixedLanguage() );
695cdf0e10cSrcweir         }
696cdf0e10cSrcweir         // Meta must have a text node before calling RegisterAsCopyOf
697cdf0e10cSrcweir         m_pMeta->NotifyChangeTxtNode(& i_rTargetTxtNode);
698cdf0e10cSrcweir         // this cannot be done in Clone: a Clone is not necessarily a copy!
699cdf0e10cSrcweir         m_pMeta->RegisterAsCopyOf(*pOriginal);
700cdf0e10cSrcweir     }
701cdf0e10cSrcweir }
702cdf0e10cSrcweir 
703cdf0e10cSrcweir 
704cdf0e10cSrcweir namespace sw {
705cdf0e10cSrcweir 
706cdf0e10cSrcweir /*************************************************************************
707cdf0e10cSrcweir  class sw::Meta
708cdf0e10cSrcweir  ************************************************************************/
709cdf0e10cSrcweir 
Meta(SwFmtMeta * const i_pFmt)710cdf0e10cSrcweir Meta::Meta(SwFmtMeta * const i_pFmt)
711cdf0e10cSrcweir     : ::sfx2::Metadatable()
712cdf0e10cSrcweir     , SwModify()
713cdf0e10cSrcweir     , m_pFmt( i_pFmt )
714cdf0e10cSrcweir {
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
~Meta()717cdf0e10cSrcweir Meta::~Meta()
718cdf0e10cSrcweir {
719cdf0e10cSrcweir }
720cdf0e10cSrcweir 
GetTxtAttr() const721cdf0e10cSrcweir SwTxtMeta * Meta::GetTxtAttr() const
722cdf0e10cSrcweir {
723cdf0e10cSrcweir     return (m_pFmt) ? m_pFmt->GetTxtAttr() : 0;
724cdf0e10cSrcweir }
725cdf0e10cSrcweir 
GetTxtNode() const726cdf0e10cSrcweir SwTxtNode * Meta::GetTxtNode() const
727cdf0e10cSrcweir {
728cdf0e10cSrcweir     return m_pTxtNode;
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
NotifyChangeTxtNodeImpl()731cdf0e10cSrcweir void Meta::NotifyChangeTxtNodeImpl()
732cdf0e10cSrcweir {
733cdf0e10cSrcweir     if (m_pTxtNode && (GetRegisteredIn() != m_pTxtNode))
734cdf0e10cSrcweir     {
735cdf0e10cSrcweir         m_pTxtNode->Add(this);
736cdf0e10cSrcweir     }
737cdf0e10cSrcweir     else if (!m_pTxtNode && GetRegisteredIn())
738cdf0e10cSrcweir     {
739cdf0e10cSrcweir         GetRegisteredInNonConst()->Remove(this);
740cdf0e10cSrcweir     }
741cdf0e10cSrcweir }
742cdf0e10cSrcweir 
NotifyChangeTxtNode(SwTxtNode * const pTxtNode)743cdf0e10cSrcweir void Meta::NotifyChangeTxtNode(SwTxtNode *const pTxtNode)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir     m_pTxtNode = pTxtNode;
746cdf0e10cSrcweir     NotifyChangeTxtNodeImpl();
747cdf0e10cSrcweir     if (!pTxtNode) // text node gone? invalidate UNO object!
748cdf0e10cSrcweir     {
749cdf0e10cSrcweir         SwPtrMsgPoolItem aMsgHint( RES_REMOVE_UNO_OBJECT,
750cdf0e10cSrcweir             &static_cast<SwModify&>(*this) ); // cast to base class!
751cdf0e10cSrcweir         this->Modify(&aMsgHint, &aMsgHint);
752cdf0e10cSrcweir     }
753cdf0e10cSrcweir }
754cdf0e10cSrcweir 
755cdf0e10cSrcweir // SwClient
Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)756cdf0e10cSrcweir void Meta::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew )
757cdf0e10cSrcweir {
758cdf0e10cSrcweir     NotifyClients(pOld, pNew);
759cdf0e10cSrcweir     if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which()))
760cdf0e10cSrcweir     {   // invalidate cached uno object
761cdf0e10cSrcweir         SetXMeta(uno::Reference<rdf::XMetadatable>(0));
762cdf0e10cSrcweir     }
763cdf0e10cSrcweir }
764cdf0e10cSrcweir 
765cdf0e10cSrcweir // sfx2::Metadatable
GetRegistry()766cdf0e10cSrcweir ::sfx2::IXmlIdRegistry& Meta::GetRegistry()
767cdf0e10cSrcweir {
768cdf0e10cSrcweir     SwTxtNode * const pTxtNode( GetTxtNode() );
769cdf0e10cSrcweir     // GetRegistry may only be called on a meta that is actually in the
770cdf0e10cSrcweir     // document, which means it has a pointer to its text node
771cdf0e10cSrcweir     OSL_ENSURE(pTxtNode, "ERROR: GetRegistry: no text node?");
772cdf0e10cSrcweir     if (!pTxtNode)
773cdf0e10cSrcweir         throw uno::RuntimeException();
774cdf0e10cSrcweir     return pTxtNode->GetRegistry();
775cdf0e10cSrcweir }
776cdf0e10cSrcweir 
IsInClipboard() const777cdf0e10cSrcweir bool Meta::IsInClipboard() const
778cdf0e10cSrcweir {
779cdf0e10cSrcweir     const SwTxtNode * const pTxtNode( GetTxtNode() );
780cdf0e10cSrcweir // no text node: in UNDO  OSL_ENSURE(pTxtNode, "IsInClipboard: no text node?");
781cdf0e10cSrcweir     return (pTxtNode) ? pTxtNode->IsInClipboard() : false;
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
IsInUndo() const784cdf0e10cSrcweir bool Meta::IsInUndo() const
785cdf0e10cSrcweir {
786cdf0e10cSrcweir     const SwTxtNode * const pTxtNode( GetTxtNode() );
787cdf0e10cSrcweir // no text node: in UNDO  OSL_ENSURE(pTxtNode, "IsInUndo: no text node?");
788cdf0e10cSrcweir     return (pTxtNode) ? pTxtNode->IsInUndo() : true;
789cdf0e10cSrcweir }
790cdf0e10cSrcweir 
IsInContent() const791cdf0e10cSrcweir bool Meta::IsInContent() const
792cdf0e10cSrcweir {
793cdf0e10cSrcweir     const SwTxtNode * const pTxtNode( GetTxtNode() );
794cdf0e10cSrcweir     OSL_ENSURE(pTxtNode, "IsInContent: no text node?");
795cdf0e10cSrcweir     return (pTxtNode) ? pTxtNode->IsInContent() : true;
796cdf0e10cSrcweir }
797cdf0e10cSrcweir 
798cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::rdf::XMetadatable >
MakeUnoObject()799cdf0e10cSrcweir Meta::MakeUnoObject()
800cdf0e10cSrcweir {
801cdf0e10cSrcweir     return SwXMeta::CreateXMeta(*this);
802cdf0e10cSrcweir }
803cdf0e10cSrcweir 
804cdf0e10cSrcweir /*************************************************************************
805cdf0e10cSrcweir  class sw::MetaField
806cdf0e10cSrcweir  ************************************************************************/
807cdf0e10cSrcweir 
MetaField(SwFmtMeta * const i_pFmt,const sal_uInt32 nNumberFormat,const bool bIsFixedLanguage)808cdf0e10cSrcweir MetaField::MetaField(SwFmtMeta * const i_pFmt,
809cdf0e10cSrcweir             const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
810cdf0e10cSrcweir     : Meta(i_pFmt)
811cdf0e10cSrcweir     , m_nNumberFormat( nNumberFormat )
812cdf0e10cSrcweir     , m_bIsFixedLanguage( bIsFixedLanguage )
813cdf0e10cSrcweir {
814cdf0e10cSrcweir }
815cdf0e10cSrcweir 
GetPrefixAndSuffix(::rtl::OUString * const o_pPrefix,::rtl::OUString * const o_pSuffix)816cdf0e10cSrcweir void MetaField::GetPrefixAndSuffix(
817cdf0e10cSrcweir         ::rtl::OUString *const o_pPrefix, ::rtl::OUString *const o_pSuffix)
818cdf0e10cSrcweir {
819cdf0e10cSrcweir     try
820cdf0e10cSrcweir     {
821cdf0e10cSrcweir         const uno::Reference<rdf::XMetadatable> xMetaField( MakeUnoObject() );
822cdf0e10cSrcweir         OSL_ENSURE(dynamic_cast<SwXMetaField*>(xMetaField.get()),
823cdf0e10cSrcweir                 "GetPrefixAndSuffix: no SwXMetaField?");
824cdf0e10cSrcweir         if (xMetaField.is())
825cdf0e10cSrcweir         {
826cdf0e10cSrcweir             SwTxtNode * const pTxtNode( GetTxtNode() );
827cdf0e10cSrcweir             SwDocShell const * const pShell(pTxtNode->GetDoc()->GetDocShell());
828cdf0e10cSrcweir             const uno::Reference<frame::XModel> xModel(
829cdf0e10cSrcweir                 (pShell) ? pShell->GetModel() : 0,  uno::UNO_SET_THROW);
830cdf0e10cSrcweir             getPrefixAndSuffix(xModel, xMetaField, o_pPrefix, o_pSuffix);
831cdf0e10cSrcweir         }
832cdf0e10cSrcweir     } catch (uno::Exception) {
833cdf0e10cSrcweir         OSL_ENSURE(false, "exception?");
834cdf0e10cSrcweir     }
835cdf0e10cSrcweir }
836cdf0e10cSrcweir 
GetNumberFormat(::rtl::OUString const & rContent) const837cdf0e10cSrcweir sal_uInt32 MetaField::GetNumberFormat(::rtl::OUString const & rContent) const
838cdf0e10cSrcweir {
839cdf0e10cSrcweir     //TODO: this probably lacks treatment for some special cases
840cdf0e10cSrcweir     sal_uInt32 nNumberFormat( m_nNumberFormat );
841cdf0e10cSrcweir     SwTxtNode * const pTxtNode( GetTxtNode() );
842cdf0e10cSrcweir     if (pTxtNode)
843cdf0e10cSrcweir     {
844cdf0e10cSrcweir         SvNumberFormatter *const pNumberFormatter(
845cdf0e10cSrcweir                 pTxtNode->GetDoc()->GetNumberFormatter() );
846cdf0e10cSrcweir         double number;
847cdf0e10cSrcweir         (void) pNumberFormatter->IsNumberFormat(
848cdf0e10cSrcweir                 rContent, nNumberFormat, number );
849cdf0e10cSrcweir     }
850cdf0e10cSrcweir     return nNumberFormat;
851cdf0e10cSrcweir }
852cdf0e10cSrcweir 
SetNumberFormat(sal_uInt32 nNumberFormat)853cdf0e10cSrcweir void MetaField::SetNumberFormat(sal_uInt32 nNumberFormat)
854cdf0e10cSrcweir {
855cdf0e10cSrcweir     // effectively, the member is only a default:
856cdf0e10cSrcweir     // GetNumberFormat checks if the text actually conforms
857cdf0e10cSrcweir     m_nNumberFormat = nNumberFormat;
858cdf0e10cSrcweir }
859cdf0e10cSrcweir 
860cdf0e10cSrcweir 
861cdf0e10cSrcweir /*************************************************************************
862cdf0e10cSrcweir  class sw::MetaFieldManager
863cdf0e10cSrcweir  ************************************************************************/
864cdf0e10cSrcweir 
865cdf0e10cSrcweir 
MetaFieldManager()866cdf0e10cSrcweir MetaFieldManager::MetaFieldManager()
867cdf0e10cSrcweir {
868cdf0e10cSrcweir }
869cdf0e10cSrcweir 
870cdf0e10cSrcweir ::boost::shared_ptr<MetaField>
makeMetaField(SwFmtMeta * const i_pFmt,const sal_uInt32 nNumberFormat,const bool bIsFixedLanguage)871cdf0e10cSrcweir MetaFieldManager::makeMetaField(SwFmtMeta * const i_pFmt,
872cdf0e10cSrcweir         const sal_uInt32 nNumberFormat, const bool bIsFixedLanguage)
873cdf0e10cSrcweir {
874cdf0e10cSrcweir     const ::boost::shared_ptr<MetaField> pMetaField(
875cdf0e10cSrcweir         new MetaField(i_pFmt, nNumberFormat, bIsFixedLanguage) );
876cdf0e10cSrcweir     m_MetaFields.push_back(pMetaField);
877cdf0e10cSrcweir     return pMetaField;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir 
880cdf0e10cSrcweir struct IsInUndo
881cdf0e10cSrcweir {
operator ()sw::IsInUndo882cdf0e10cSrcweir     bool operator()(::boost::weak_ptr<MetaField> const & pMetaField) {
883cdf0e10cSrcweir         return pMetaField.lock()->IsInUndo();
884cdf0e10cSrcweir     }
885cdf0e10cSrcweir };
886cdf0e10cSrcweir 
887cdf0e10cSrcweir struct MakeUnoObject
888cdf0e10cSrcweir {
889cdf0e10cSrcweir     uno::Reference<text::XTextField>
operator ()sw::MakeUnoObject890cdf0e10cSrcweir     operator()(::boost::weak_ptr<MetaField> const & pMetaField) {
891cdf0e10cSrcweir         return uno::Reference<text::XTextField>(
892cdf0e10cSrcweir                 pMetaField.lock()->MakeUnoObject(), uno::UNO_QUERY);
893cdf0e10cSrcweir     }
894cdf0e10cSrcweir };
895cdf0e10cSrcweir 
896cdf0e10cSrcweir ::std::vector< uno::Reference<text::XTextField> >
getMetaFields()897cdf0e10cSrcweir MetaFieldManager::getMetaFields()
898cdf0e10cSrcweir {
899cdf0e10cSrcweir     // erase deleted fields
900cdf0e10cSrcweir     const MetaFieldList_t::iterator iter(
901cdf0e10cSrcweir         ::std::remove_if(m_MetaFields.begin(), m_MetaFields.end(),
902cdf0e10cSrcweir             ::boost::bind(&::boost::weak_ptr<MetaField>::expired, _1)));
903cdf0e10cSrcweir     m_MetaFields.erase(iter, m_MetaFields.end());
904cdf0e10cSrcweir     // filter out fields in UNDO
905cdf0e10cSrcweir     MetaFieldList_t filtered(m_MetaFields.size());
906cdf0e10cSrcweir     const MetaFieldList_t::iterator iter2(
907cdf0e10cSrcweir     ::std::remove_copy_if(m_MetaFields.begin(), m_MetaFields.end(),
908cdf0e10cSrcweir         filtered.begin(), IsInUndo()));
909cdf0e10cSrcweir     filtered.erase(iter2, filtered.end());
910cdf0e10cSrcweir     // create uno objects
911cdf0e10cSrcweir     ::std::vector< uno::Reference<text::XTextField> > ret(filtered.size());
912cdf0e10cSrcweir     ::std::transform(filtered.begin(), filtered.end(), ret.begin(),
913cdf0e10cSrcweir             MakeUnoObject());
914cdf0e10cSrcweir     return ret;
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir } // namespace sw
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 
920