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"
36 #include "hintids.hxx"
39 #ifndef __SBX_SBXVARIABLE_HXX //autogen
40 #include <basic/sbxvar.hxx>
42 #include <svtools/macitem.hxx>
43 #include <svtools/stritem.hxx>
44 #include <svtools/stylepool.hxx>
45 #include <fmtautofmt.hxx>
46 #include <fchrfmt.hxx>
47 #include <fmtinfmt.hxx>
49 #include <fmtruby.hxx>
50 #include <charfmt.hxx>
51 #include <hints.hxx> // SwUpdateAttr
52 #include <unostyle.hxx>
53 #include <unoevent.hxx> // SwHyperlinkEventDescriptor
54 #ifndef _COM_SUN_STAR_TEXT_RUBYADJUST_HDL_
55 #include <com/sun/star/text/RubyAdjust.hdl>
61 #include <com/sun/star/uno/Any.h>
62 #include <SwStyleNameMapper.hxx>
64 using namespace ::com::sun::star
;
65 using ::rtl::OUString
;
67 TYPEINIT1_AUTOFACTORY(SwFmtINetFmt
, SfxPoolItem
);
68 TYPEINIT1_AUTOFACTORY(SwFmtAutoFmt
, SfxPoolItem
);
70 /*************************************************************************
74 |* Ersterstellung JP 23.11.90
75 |* Letzte Aenderung JP 09.08.94
77 *************************************************************************/
79 SwFmtCharFmt::SwFmtCharFmt( SwCharFmt
*pFmt
)
80 : SfxPoolItem( RES_TXTATR_CHARFMT
),
88 SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt
& rAttr
)
89 : SfxPoolItem( RES_TXTATR_CHARFMT
),
90 SwClient( rAttr
.GetCharFmt() ),
97 SwFmtCharFmt::~SwFmtCharFmt() {}
101 int SwFmtCharFmt::operator==( const SfxPoolItem
& rAttr
) const
103 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
104 return GetCharFmt() == ((SwFmtCharFmt
&)rAttr
).GetCharFmt();
109 SfxPoolItem
* SwFmtCharFmt::Clone( SfxItemPool
* ) const
111 return new SwFmtCharFmt( *this );
116 // weiterleiten an das TextAttribut
117 void SwFmtCharFmt::Modify( SfxPoolItem
* pOld
, SfxPoolItem
* pNew
)
120 pTxtAttr
->Modify( pOld
, pNew
);
125 // weiterleiten an das TextAttribut
126 BOOL
SwFmtCharFmt::GetInfo( SfxPoolItem
& rInfo
) const
128 return pTxtAttr
? pTxtAttr
->GetInfo( rInfo
) : FALSE
;
130 BOOL
SwFmtCharFmt::QueryValue( uno::Any
& rVal
, BYTE
) const
134 SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
135 rVal
<<= OUString( sCharFmtName
);
138 BOOL
SwFmtCharFmt::PutValue( const uno::Any
& , BYTE
)
140 DBG_ERROR("Zeichenvorlage kann mit PutValue nicht gesetzt werden!");
144 /*************************************************************************
146 |* class SwFmtAutoFmt
148 |* Ersterstellung AMA 12.05.06
149 |* Letzte Aenderung AMA 12.05.06
151 *************************************************************************/
153 SwFmtAutoFmt::SwFmtAutoFmt( USHORT nInitWhich
)
154 : SfxPoolItem( nInitWhich
)
158 SwFmtAutoFmt::SwFmtAutoFmt( const SwFmtAutoFmt
& rAttr
)
159 : SfxPoolItem( rAttr
.Which() ), mpHandle( rAttr
.mpHandle
)
163 SwFmtAutoFmt::~SwFmtAutoFmt()
167 int SwFmtAutoFmt::operator==( const SfxPoolItem
& rAttr
) const
169 ASSERT( SfxPoolItem::operator==( rAttr
), "different attributes" );
170 return mpHandle
== ((SwFmtAutoFmt
&)rAttr
).mpHandle
;
173 SfxPoolItem
* SwFmtAutoFmt::Clone( SfxItemPool
* ) const
175 return new SwFmtAutoFmt( *this );
178 BOOL
SwFmtAutoFmt::QueryValue( uno::Any
& rVal
, BYTE
) const
180 String sCharFmtName
= StylePool::nameOf( mpHandle
);
181 rVal
<<= OUString( sCharFmtName
);
185 BOOL
SwFmtAutoFmt::PutValue( const uno::Any
& , BYTE
)
187 //the format is not renameable via API
191 /*************************************************************************
193 |* class SwFmtINetFmt
195 |* Ersterstellung AMA 02.08.96
196 |* Letzte Aenderung AMA 02.08.96
198 *************************************************************************/
200 SwFmtINetFmt::SwFmtINetFmt()
201 : SfxPoolItem( RES_TXTATR_INETFMT
),
208 SwFmtINetFmt::SwFmtINetFmt( const XubString
& rURL
, const XubString
& rTarget
)
209 : SfxPoolItem( RES_TXTATR_INETFMT
),
211 aTargetFrame( rTarget
),
219 SwFmtINetFmt::SwFmtINetFmt( const SwFmtINetFmt
& rAttr
)
220 : SfxPoolItem( RES_TXTATR_INETFMT
),
221 aURL( rAttr
.GetValue() ),
222 aTargetFrame( rAttr
.aTargetFrame
),
223 aINetFmt( rAttr
.aINetFmt
),
224 aVisitedFmt( rAttr
.aVisitedFmt
),
225 aName( rAttr
.aName
),
228 nINetId( rAttr
.nINetId
),
229 nVisitedId( rAttr
.nVisitedId
)
231 if( rAttr
.GetMacroTbl() )
232 pMacroTbl
= new SvxMacroTableDtor( *rAttr
.GetMacroTbl() );
235 SwFmtINetFmt::~SwFmtINetFmt()
242 int SwFmtINetFmt::operator==( const SfxPoolItem
& rAttr
) const
244 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
245 BOOL bRet
= SfxPoolItem::operator==( (SfxPoolItem
&) rAttr
)
246 && aURL
== ((SwFmtINetFmt
&)rAttr
).aURL
247 && aName
== ((SwFmtINetFmt
&)rAttr
).aName
248 && aTargetFrame
== ((SwFmtINetFmt
&)rAttr
).aTargetFrame
249 && aINetFmt
== ((SwFmtINetFmt
&)rAttr
).aINetFmt
250 && aVisitedFmt
== ((SwFmtINetFmt
&)rAttr
).aVisitedFmt
251 && nINetId
== ((SwFmtINetFmt
&)rAttr
).nINetId
252 && nVisitedId
== ((SwFmtINetFmt
&)rAttr
).nVisitedId
;
257 const SvxMacroTableDtor
* pOther
= ((SwFmtINetFmt
&)rAttr
).pMacroTbl
;
259 return ( !pOther
|| !pOther
->Count() );
261 return 0 == pMacroTbl
->Count();
263 const SvxMacroTableDtor
& rOwn
= *pMacroTbl
;
264 const SvxMacroTableDtor
& rOther
= *pOther
;
266 // Anzahl unterschiedlich => auf jeden Fall ungleich
267 if( rOwn
.Count() != rOther
.Count() )
270 // einzeln vergleichen; wegen Performance ist die Reihenfolge wichtig
271 for( USHORT nNo
= 0; nNo
< rOwn
.Count(); ++nNo
)
273 const SvxMacro
*pOwnMac
= rOwn
.GetObject(nNo
);
274 const SvxMacro
*pOtherMac
= rOther
.GetObject(nNo
);
275 if ( rOwn
.GetKey(pOwnMac
) != rOther
.GetKey(pOtherMac
) ||
276 pOwnMac
->GetLibName() != pOtherMac
->GetLibName() ||
277 pOwnMac
->GetMacName() != pOtherMac
->GetMacName() )
285 SfxPoolItem
* SwFmtINetFmt::Clone( SfxItemPool
* ) const
287 return new SwFmtINetFmt( *this );
292 void SwFmtINetFmt::SetMacroTbl( const SvxMacroTableDtor
* pNewTbl
)
297 *pMacroTbl
= *pNewTbl
;
299 pMacroTbl
= new SvxMacroTableDtor( *pNewTbl
);
302 delete pMacroTbl
, pMacroTbl
= 0;
307 void SwFmtINetFmt::SetMacro( USHORT nEvent
, const SvxMacro
& rMacro
)
310 pMacroTbl
= new SvxMacroTableDtor
;
313 if( 0 != ( pOldMacro
= pMacroTbl
->Get( nEvent
)) )
316 pMacroTbl
->Replace( nEvent
, new SvxMacro( rMacro
) );
319 pMacroTbl
->Insert( nEvent
, new SvxMacro( rMacro
) );
324 const SvxMacro
* SwFmtINetFmt::GetMacro( USHORT nEvent
) const
326 const SvxMacro
* pRet
= 0;
327 if( pMacroTbl
&& pMacroTbl
->IsKeyValid( nEvent
) )
328 pRet
= pMacroTbl
->Get( nEvent
);
334 BOOL
SwFmtINetFmt::QueryValue( uno::Any
& rVal
, BYTE nMemberId
) const
338 nMemberId
&= ~CONVERT_TWIPS
;
347 case MID_URL_HYPERLINKNAME
:
350 case MID_URL_VISITED_FMT
:
352 if( !sVal
.Len() && nVisitedId
!= 0 )
353 SwStyleNameMapper::FillUIName( nVisitedId
, sVal
);
355 SwStyleNameMapper::FillProgName( sVal
, sVal
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
357 case MID_URL_UNVISITED_FMT
:
359 if( !sVal
.Len() && nINetId
!= 0 )
360 SwStyleNameMapper::FillUIName( nINetId
, sVal
);
362 SwStyleNameMapper::FillProgName( sVal
, sVal
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
364 case MID_URL_HYPERLINKEVENTS
:
366 // create (and return) event descriptor
367 SwHyperlinkEventDescriptor
* pEvents
=
368 new SwHyperlinkEventDescriptor();
369 pEvents
->copyMacrosFromINetFmt(*this);
370 uno::Reference
<container::XNameReplace
> xNameReplace(pEvents
);
372 // all others return a string; so we just set rVal here and exit
373 rVal
<<= xNameReplace
;
379 rVal
<<= OUString(sVal
);
382 BOOL
SwFmtINetFmt::PutValue( const uno::Any
& rVal
, BYTE nMemberId
)
385 nMemberId
&= ~CONVERT_TWIPS
;
387 // all properties except HyperlinkEvents are of type string, hence
388 // we treat HyperlinkEvents specially
389 if (MID_URL_HYPERLINKEVENTS
== nMemberId
)
391 uno::Reference
<container::XNameReplace
> xReplace
;
395 // Create hyperlink event descriptor. Then copy events
396 // from argument into descriptor. Then copy events from
397 // the descriptor into the format.
398 SwHyperlinkEventDescriptor
* pEvents
= new SwHyperlinkEventDescriptor();
399 uno::Reference
< lang::XServiceInfo
> xHold
= pEvents
;
400 pEvents
->copyMacrosFromNameReplace(xReplace
);
401 pEvents
->copyMacrosIntoINetFmt(*this);
411 // all string properties:
412 if(rVal
.getValueType() != ::getCppuType((rtl::OUString
*)0))
414 XubString sVal
= *(rtl::OUString
*)rVal
.getValue();
423 case MID_URL_HYPERLINKNAME
:
426 case MID_URL_VISITED_FMT
:
429 SwStyleNameMapper::FillUIName( sVal
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
430 aVisitedFmt
= OUString ( aString
);
431 nVisitedId
= SwStyleNameMapper::GetPoolIdFromUIName( aVisitedFmt
,
432 nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
435 case MID_URL_UNVISITED_FMT
:
438 SwStyleNameMapper::FillUIName( sVal
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
439 aINetFmt
= OUString ( aString
);
440 nINetId
= SwStyleNameMapper::GetPoolIdFromUIName( aINetFmt
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);
451 /*************************************************************************
453 *************************************************************************/
455 SwFmtRuby::SwFmtRuby( const String
& rRubyTxt
)
456 : SfxPoolItem( RES_TXTATR_CJK_RUBY
),
457 sRubyTxt( rRubyTxt
),
465 SwFmtRuby::SwFmtRuby( const SwFmtRuby
& rAttr
)
466 : SfxPoolItem( RES_TXTATR_CJK_RUBY
),
467 sRubyTxt( rAttr
.sRubyTxt
),
468 sCharFmtName( rAttr
.sCharFmtName
),
470 nCharFmtId( rAttr
.nCharFmtId
),
471 nPosition( rAttr
.nPosition
),
472 nAdjustment( rAttr
.nAdjustment
)
476 SwFmtRuby::~SwFmtRuby()
480 SwFmtRuby
& SwFmtRuby::operator=( const SwFmtRuby
& rAttr
)
482 sRubyTxt
= rAttr
.sRubyTxt
;
483 sCharFmtName
= rAttr
.sCharFmtName
;
484 nCharFmtId
= rAttr
.nCharFmtId
;
485 nPosition
= rAttr
.nPosition
;
486 nAdjustment
= rAttr
.nAdjustment
;
491 int SwFmtRuby::operator==( const SfxPoolItem
& rAttr
) const
493 ASSERT( SfxPoolItem::operator==( rAttr
), "keine gleichen Attribute" );
494 return sRubyTxt
== ((SwFmtRuby
&)rAttr
).sRubyTxt
&&
495 sCharFmtName
== ((SwFmtRuby
&)rAttr
).sCharFmtName
&&
496 nCharFmtId
== ((SwFmtRuby
&)rAttr
).nCharFmtId
&&
497 nPosition
== ((SwFmtRuby
&)rAttr
).nPosition
&&
498 nAdjustment
== ((SwFmtRuby
&)rAttr
).nAdjustment
;
501 SfxPoolItem
* SwFmtRuby::Clone( SfxItemPool
* ) const
503 return new SwFmtRuby( *this );
506 BOOL
SwFmtRuby::QueryValue( uno::Any
& rVal
,
507 BYTE nMemberId
) const
510 nMemberId
&= ~CONVERT_TWIPS
;
513 case MID_RUBY_TEXT
: rVal
<<= (OUString
)sRubyTxt
; break;
514 case MID_RUBY_ADJUST
: rVal
<<= (sal_Int16
)nAdjustment
; break;
515 case MID_RUBY_CHARSTYLE
:
518 SwStyleNameMapper::FillProgName(sCharFmtName
, aString
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
, sal_True
);
519 rVal
<<= OUString ( aString
);
524 sal_Bool bAbove
= !nPosition
;
525 rVal
.setValue(&bAbove
, ::getBooleanCppuType());
533 BOOL
SwFmtRuby::PutValue( const uno::Any
& rVal
,
537 nMemberId
&= ~CONVERT_TWIPS
;
543 bRet
= rVal
>>= sTmp
;
547 case MID_RUBY_ADJUST
:
551 if(nSet
>= 0 && nSet
<= text::RubyAdjust_INDENT_BLOCK
)
559 const uno::Type
& rType
= ::getBooleanCppuType();
560 if(rVal
.hasValue() && rVal
.getValueType() == rType
)
562 sal_Bool bAbove
= *(sal_Bool
*)rVal
.getValue();
563 nPosition
= bAbove
? 0 : 1;
567 case MID_RUBY_CHARSTYLE
:
570 bRet
= rVal
>>= sTmp
;
572 sCharFmtName
= SwStyleNameMapper::GetUIName(sTmp
, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT
);