update dev300-m58
[ooovba.git] / sw / source / core / txtnode / fmtatr2.cxx
blob9e61c7ca700954c29b084011a8c6a08187ac1542
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmtatr2.cxx,v $
10 * $Revision: 1.30 $
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"
37 #include "unomid.h"
39 #ifndef __SBX_SBXVARIABLE_HXX //autogen
40 #include <basic/sbxvar.hxx>
41 #endif
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>
48 #include <txtatr.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>
56 #endif
58 #ifndef _CMDID_H
59 #include <cmdid.h>
60 #endif
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 /*************************************************************************
72 |* class SwFmtCharFmt
73 |* Beschreibung
74 |* Ersterstellung JP 23.11.90
75 |* Letzte Aenderung JP 09.08.94
77 *************************************************************************/
79 SwFmtCharFmt::SwFmtCharFmt( SwCharFmt *pFmt )
80 : SfxPoolItem( RES_TXTATR_CHARFMT ),
81 SwClient(pFmt),
82 pTxtAttr( 0 )
88 SwFmtCharFmt::SwFmtCharFmt( const SwFmtCharFmt& rAttr )
89 : SfxPoolItem( RES_TXTATR_CHARFMT ),
90 SwClient( rAttr.GetCharFmt() ),
91 pTxtAttr( 0 )
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 )
119 if( pTxtAttr )
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
132 String sCharFmtName;
133 if(GetCharFmt())
134 SwStyleNameMapper::FillProgName(GetCharFmt()->GetName(), sCharFmtName, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
135 rVal <<= OUString( sCharFmtName );
136 return TRUE;
138 BOOL SwFmtCharFmt::PutValue( const uno::Any& , BYTE )
140 DBG_ERROR("Zeichenvorlage kann mit PutValue nicht gesetzt werden!");
141 return FALSE;
144 /*************************************************************************
146 |* class SwFmtAutoFmt
147 |* Beschreibung
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 );
182 return TRUE;
185 BOOL SwFmtAutoFmt::PutValue( const uno::Any& , BYTE )
187 //the format is not renameable via API
188 return FALSE;
191 /*************************************************************************
193 |* class SwFmtINetFmt
194 |* Beschreibung
195 |* Ersterstellung AMA 02.08.96
196 |* Letzte Aenderung AMA 02.08.96
198 *************************************************************************/
200 SwFmtINetFmt::SwFmtINetFmt()
201 : SfxPoolItem( RES_TXTATR_INETFMT ),
202 pMacroTbl( 0 ),
203 pTxtAttr( 0 ),
204 nINetId( 0 ),
205 nVisitedId( 0 )
208 SwFmtINetFmt::SwFmtINetFmt( const XubString& rURL, const XubString& rTarget )
209 : SfxPoolItem( RES_TXTATR_INETFMT ),
210 aURL( rURL ),
211 aTargetFrame( rTarget ),
212 pMacroTbl( 0 ),
213 pTxtAttr( 0 ),
214 nINetId( 0 ),
215 nVisitedId( 0 )
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 ),
226 pMacroTbl( 0 ),
227 pTxtAttr( 0 ),
228 nINetId( rAttr.nINetId ),
229 nVisitedId( rAttr.nVisitedId )
231 if( rAttr.GetMacroTbl() )
232 pMacroTbl = new SvxMacroTableDtor( *rAttr.GetMacroTbl() );
235 SwFmtINetFmt::~SwFmtINetFmt()
237 delete pMacroTbl;
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;
254 if( !bRet )
255 return FALSE;
257 const SvxMacroTableDtor* pOther = ((SwFmtINetFmt&)rAttr).pMacroTbl;
258 if( !pMacroTbl )
259 return ( !pOther || !pOther->Count() );
260 if( !pOther )
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() )
268 return FALSE;
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() )
278 return FALSE;
280 return TRUE;
285 SfxPoolItem* SwFmtINetFmt::Clone( SfxItemPool* ) const
287 return new SwFmtINetFmt( *this );
292 void SwFmtINetFmt::SetMacroTbl( const SvxMacroTableDtor* pNewTbl )
294 if( pNewTbl )
296 if( pMacroTbl )
297 *pMacroTbl = *pNewTbl;
298 else
299 pMacroTbl = new SvxMacroTableDtor( *pNewTbl );
301 else if( pMacroTbl )
302 delete pMacroTbl, pMacroTbl = 0;
307 void SwFmtINetFmt::SetMacro( USHORT nEvent, const SvxMacro& rMacro )
309 if( !pMacroTbl )
310 pMacroTbl = new SvxMacroTableDtor;
312 SvxMacro *pOldMacro;
313 if( 0 != ( pOldMacro = pMacroTbl->Get( nEvent )) )
315 delete pOldMacro;
316 pMacroTbl->Replace( nEvent, new SvxMacro( rMacro ) );
318 else
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 );
329 return pRet;
334 BOOL SwFmtINetFmt::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
336 BOOL bRet = TRUE;
337 XubString sVal;
338 nMemberId &= ~CONVERT_TWIPS;
339 switch(nMemberId)
341 case MID_URL_URL:
342 sVal = aURL;
343 break;
344 case MID_URL_TARGET:
345 sVal = aTargetFrame;
346 break;
347 case MID_URL_HYPERLINKNAME:
348 sVal = aName;
349 break;
350 case MID_URL_VISITED_FMT:
351 sVal = aVisitedFmt;
352 if( !sVal.Len() && nVisitedId != 0 )
353 SwStyleNameMapper::FillUIName( nVisitedId, sVal );
354 if( sVal.Len() )
355 SwStyleNameMapper::FillProgName( sVal, sVal, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
356 break;
357 case MID_URL_UNVISITED_FMT:
358 sVal = aINetFmt;
359 if( !sVal.Len() && nINetId != 0 )
360 SwStyleNameMapper::FillUIName( nINetId, sVal );
361 if( sVal.Len() )
362 SwStyleNameMapper::FillProgName( sVal, sVal, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
363 break;
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;
374 return bRet;
376 default:
377 break;
379 rVal <<= OUString(sVal);
380 return bRet;
382 BOOL SwFmtINetFmt::PutValue( const uno::Any& rVal, BYTE nMemberId )
384 BOOL bRet = TRUE;
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;
392 rVal >>= xReplace;
393 if (xReplace.is())
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);
403 else
405 // wrong type!
406 bRet = FALSE;
409 else
411 // all string properties:
412 if(rVal.getValueType() != ::getCppuType((rtl::OUString*)0))
413 return FALSE;
414 XubString sVal = *(rtl::OUString*)rVal.getValue();
415 switch(nMemberId)
417 case MID_URL_URL:
418 aURL = sVal;
419 break;
420 case MID_URL_TARGET:
421 aTargetFrame = sVal;
422 break;
423 case MID_URL_HYPERLINKNAME:
424 aName = sVal;
425 break;
426 case MID_URL_VISITED_FMT:
428 String aString;
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 );
434 break;
435 case MID_URL_UNVISITED_FMT:
437 String aString;
438 SwStyleNameMapper::FillUIName( sVal, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
439 aINetFmt = OUString ( aString );
440 nINetId = SwStyleNameMapper::GetPoolIdFromUIName( aINetFmt, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
442 break;
443 default:
444 bRet = FALSE;
447 return bRet;
451 /*************************************************************************
452 |* class SwFmtRuby
453 *************************************************************************/
455 SwFmtRuby::SwFmtRuby( const String& rRubyTxt )
456 : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
457 sRubyTxt( rRubyTxt ),
458 pTxtAttr( 0 ),
459 nCharFmtId( 0 ),
460 nPosition( 0 ),
461 nAdjustment( 0 )
465 SwFmtRuby::SwFmtRuby( const SwFmtRuby& rAttr )
466 : SfxPoolItem( RES_TXTATR_CJK_RUBY ),
467 sRubyTxt( rAttr.sRubyTxt ),
468 sCharFmtName( rAttr.sCharFmtName ),
469 pTxtAttr( 0 ),
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;
487 pTxtAttr = 0;
488 return *this;
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
509 BOOL bRet = TRUE;
510 nMemberId &= ~CONVERT_TWIPS;
511 switch( nMemberId )
513 case MID_RUBY_TEXT: rVal <<= (OUString)sRubyTxt; break;
514 case MID_RUBY_ADJUST: rVal <<= (sal_Int16)nAdjustment; break;
515 case MID_RUBY_CHARSTYLE:
517 String aString;
518 SwStyleNameMapper::FillProgName(sCharFmtName, aString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, sal_True );
519 rVal <<= OUString ( aString );
521 break;
522 case MID_RUBY_ABOVE:
524 sal_Bool bAbove = !nPosition;
525 rVal.setValue(&bAbove, ::getBooleanCppuType());
527 break;
528 default:
529 bRet = FALSE;
531 return bRet;
533 BOOL SwFmtRuby::PutValue( const uno::Any& rVal,
534 BYTE nMemberId )
536 BOOL bRet = TRUE;
537 nMemberId &= ~CONVERT_TWIPS;
538 switch( nMemberId )
540 case MID_RUBY_TEXT:
542 OUString sTmp;
543 bRet = rVal >>= sTmp;
544 sRubyTxt = sTmp;
546 break;
547 case MID_RUBY_ADJUST:
549 sal_Int16 nSet = 0;
550 rVal >>= nSet;
551 if(nSet >= 0 && nSet <= text::RubyAdjust_INDENT_BLOCK)
552 nAdjustment = nSet;
553 else
554 bRet = sal_False;
556 break;
557 case MID_RUBY_ABOVE:
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;
566 break;
567 case MID_RUBY_CHARSTYLE:
569 OUString sTmp;
570 bRet = rVal >>= sTmp;
571 if(bRet)
572 sCharFmtName = SwStyleNameMapper::GetUIName(sTmp, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT );
574 break;
575 default:
576 bRet = FALSE;
578 return bRet;