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: unofield.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_svx.hxx"
33 #include <com/sun/star/util/DateTime.hpp>
34 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
35 #include <com/sun/star/lang/NoSupportException.hpp>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
37 #include <vcl/svapp.hxx>
38 #include <vos/mutex.hxx>
41 #include <rtl/memory.h>
43 #include <svx/eeitem.hxx>
44 #include <svx/flditem.hxx>
45 #include <svx/svdfield.hxx>
46 #include <svx/unofield.hxx>
47 #include <svx/unoprov.hxx>
48 #include <svx/unotext.hxx>
50 using namespace ::rtl
;
51 using namespace ::vos
;
52 using namespace ::cppu
;
53 using namespace ::com::sun::star
;
55 #define QUERYINT( xint ) \
56 if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
57 aAny <<= uno::Reference< xint >(this)
69 class SvxUnoFieldData_Impl
79 util::DateTime maDateTime
;
81 OUString msPresentation
;
84 const SfxItemPropertySet
* ImplGetFieldItemPropertySet( sal_Int32 mnId
)
86 static SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl
[] =
88 { MAP_CHAR_LEN("DateTime"), WID_DATE
, &::getCppuType((const util::DateTime
*)0), 0, 0 },
89 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1
, &::getBooleanCppuType(), 0, 0 },
90 { MAP_CHAR_LEN("IsDate"), WID_BOOL2
, &::getBooleanCppuType(), 0, 0 },
91 { MAP_CHAR_LEN("NumberFormat"), WID_INT32
, &::getCppuType((const sal_Int16
*)0), 0, 0 },
94 static SfxItemPropertySet
aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl
);
96 static SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl
[] =
98 { MAP_CHAR_LEN("IsDate"), WID_BOOL2
, &::getBooleanCppuType(), 0, 0 },
101 static SfxItemPropertySet
aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl
);
103 static SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl
[] =
106 { MAP_CHAR_LEN("Format"), WID_INT16
, &::getCppuType((const sal_Int16
*)0), 0, 0 },
107 { MAP_CHAR_LEN("Representation"), WID_STRING1
, &::getCppuType((const OUString
*)0), 0, 0 },
108 { MAP_CHAR_LEN("TargetFrame"), WID_STRING2
, &::getCppuType((const OUString
*)0), 0, 0 },
109 { MAP_CHAR_LEN("URL"), WID_STRING3
, &::getCppuType((const OUString
*)0), 0, 0 },
112 static SfxItemPropertySet
aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl
);
114 static SfxItemPropertyMapEntry aEmptyPropertyMap_Impl
[] =
118 static SfxItemPropertySet
aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl
);
120 static SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl
[] =
122 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1
, &::getBooleanCppuType(), 0, 0 },
123 { MAP_CHAR_LEN("FileFormat"), WID_INT16
, &::getCppuType((const sal_Int16
*)0), 0, 0 },
124 { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1
,&::getCppuType((const OUString
*)0), 0, 0 },
127 static SfxItemPropertySet
aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl
);
129 static SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl
[] =
131 { MAP_CHAR_LEN("IsFixed"), WID_BOOL1
, &::getBooleanCppuType(), 0, 0 },
132 { MAP_CHAR_LEN("CurrentPresentation"), WID_STRING1
,&::getCppuType((const OUString
*)0), 0, 0 },
133 { MAP_CHAR_LEN("Content"), WID_STRING2
,&::getCppuType((const OUString
*)0), 0, 0 },
134 { MAP_CHAR_LEN("AuthorFormat"), WID_INT16
, &::getCppuType((const sal_Int16
*)0), 0, 0 },
135 { MAP_CHAR_LEN("FullName"), WID_BOOL2
, &::getBooleanCppuType(), 0, 0 },
138 static SfxItemPropertySet
aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl
);
140 static SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl
[] =
142 { MAP_CHAR_LEN("Kind"), WID_INT16
, &::getCppuType((const sal_Int16
*)0), 0, 0 },
145 static SfxItemPropertySet
aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl
);
149 case ID_EXT_DATEFIELD
:
150 case ID_EXT_TIMEFIELD
:
151 return &aExDateTimeFieldPropertySet_Impl
;
153 return &aUrlFieldPropertySet_Impl
;
156 return &aDateTimeFieldPropertySet_Impl
;
157 case ID_EXT_FILEFIELD
:
158 return &aExtFileFieldPropertySet_Impl
;
160 return &aAuthorFieldPropertySet_Impl
;
161 case ID_MEASUREFIELD
:
162 return &aMeasureFieldPropertySet_Impl
;
163 // case ID_PAGEFIELD:
164 // case ID_PAGESFIELD:
165 // case ID_FILEFIELD:
166 // case ID_TABLEFIELD:
167 // case ID_HEADERFIELD:
168 // case ID_FOOTERFIELD:
169 // case ID_DATETIMEFIELD::
171 return &aEmptyPropertySet_Impl
;
175 static sal_Char
const* aFieldItemNameMap_Impl
[] =
195 /* conversion routines */
197 static sal_Int16
getFileNameDisplayFormat( SvxFileFormat nFormat
)
201 case SVXFILEFORMAT_NAME_EXT
: return text::FilenameDisplayFormat::NAME_AND_EXT
;
202 case SVXFILEFORMAT_FULLPATH
: return text::FilenameDisplayFormat::FULL
;
203 case SVXFILEFORMAT_PATH
: return text::FilenameDisplayFormat::PATH
;
204 // case SVXFILEFORMAT_NAME:
205 default: return text::FilenameDisplayFormat::NAME
;
209 static SvxFileFormat
setFileNameDisplayFormat( sal_Int16 nFormat
)
213 case text::FilenameDisplayFormat::FULL
: return SVXFILEFORMAT_FULLPATH
;
214 case text::FilenameDisplayFormat::PATH
: return SVXFILEFORMAT_PATH
;
215 case text::FilenameDisplayFormat::NAME
: return SVXFILEFORMAT_NAME
;
216 // case text::FilenameDisplayFormat::NAME_AND_EXT:
218 return SVXFILEFORMAT_NAME_EXT
;
222 static util::DateTime
getDate( ULONG nDate
)
224 util::DateTime aDate
;
225 memset( &aDate
, 0, sizeof( util::DateTime
) );
227 Date
aTempDate( nDate
);
229 aDate
.Day
= aTempDate
.GetDay();
230 aDate
.Month
= aTempDate
.GetMonth();
231 aDate
.Year
= aTempDate
.GetYear();
236 inline Date
setDate( util::DateTime
& rDate
)
238 return Date( rDate
.Day
, rDate
.Month
, rDate
.Year
);
241 static util::DateTime
getTime( long nTime
)
243 util::DateTime aTime
;
244 memset( &aTime
, 0, sizeof( util::DateTime
) );
246 Time
aTempTime( nTime
);
248 aTime
.HundredthSeconds
= aTempTime
.Get100Sec();
249 aTime
.Seconds
= aTempTime
.GetSec();
250 aTime
.Minutes
= aTempTime
.GetMin();
251 aTime
.Hours
= aTempTime
.GetHour();
256 inline Time
setTime( util::DateTime
& rDate
)
258 return Time( rDate
.Hours
, rDate
.Minutes
, rDate
.Seconds
, rDate
.HundredthSeconds
);
261 // ====================================================================
262 // class SvxUnoTextField
263 // ====================================================================
264 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextField
);
266 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId
) throw()
267 : OComponentHelper( getMutex() )
269 , mnServiceId(nServiceId
)
270 , mpImpl( new SvxUnoFieldData_Impl
)
272 mpPropSet
= ImplGetFieldItemPropertySet(mnServiceId
);
274 memset( &(mpImpl
->maDateTime
), 0, sizeof( util::DateTime
) );
278 case ID_EXT_DATEFIELD
:
280 mpImpl
->mbBoolean2
= sal_True
;
281 mpImpl
->mnInt32
= SVXDATEFORMAT_STDSMALL
;
282 mpImpl
->mbBoolean1
= sal_False
;
285 case ID_EXT_TIMEFIELD
:
287 mpImpl
->mbBoolean2
= sal_False
;
288 mpImpl
->mbBoolean1
= sal_False
;
289 mpImpl
->mnInt32
= SVXTIMEFORMAT_STANDARD
;
293 mpImpl
->mnInt16
= SVXURLFORMAT_REPR
;
296 case ID_EXT_FILEFIELD
:
297 mpImpl
->mbBoolean1
= sal_False
;
298 mpImpl
->mnInt16
= text::FilenameDisplayFormat::FULL
;
302 mpImpl
->mnInt16
= SVXAUTHORFORMAT_FULLNAME
;
303 mpImpl
->mbBoolean1
= sal_False
;
304 mpImpl
->mbBoolean2
= sal_True
;
307 case ID_MEASUREFIELD
:
308 mpImpl
->mnInt16
= SDRMEASUREFIELD_VALUE
;
312 mpImpl
->mbBoolean1
= sal_False
;
313 mpImpl
->mbBoolean2
= sal_False
;
320 SvxUnoTextField::SvxUnoTextField( uno::Reference
< text::XTextRange
> xAnchor
, const OUString
& rPresentation
, const SvxFieldData
* pData
) throw()
321 : OComponentHelper( getMutex() )
322 , mxAnchor( xAnchor
)
324 , mnServiceId(ID_UNKNOWN
)
325 , mpImpl( new SvxUnoFieldData_Impl
)
327 DBG_ASSERT(pData
, "pFieldData == NULL! [CL]" );
329 mpImpl
->msPresentation
= rPresentation
;
333 mnServiceId
= GetFieldId(pData
);
334 DBG_ASSERT(mnServiceId
!= ID_UNKNOWN
, "unknown SvxFieldData! [CL]");
335 if(mnServiceId
!= ID_UNKNOWN
)
337 // extract field properties from data class
338 switch( mnServiceId
)
341 case ID_EXT_DATEFIELD
:
343 mpImpl
->mbBoolean2
= sal_True
;
344 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
345 // use current date instead
346 sal_Bool bFixed
= ((SvxDateField
*)pData
)->GetType() == SVXDATETYPE_FIX
;
347 mpImpl
->maDateTime
= getDate( bFixed
?
348 ((SvxDateField
*)pData
)->GetFixDate() :
350 mpImpl
->mnInt32
= ((SvxDateField
*)pData
)->GetFormat();
351 mpImpl
->mbBoolean1
= bFixed
;
356 mpImpl
->mbBoolean2
= sal_False
;
357 mpImpl
->mbBoolean1
= sal_False
;
358 mpImpl
->mnInt32
= SVXTIMEFORMAT_STANDARD
;
361 case ID_EXT_TIMEFIELD
:
362 mpImpl
->mbBoolean2
= sal_False
;
363 mpImpl
->maDateTime
= getTime( ((SvxExtTimeField
*)pData
)->GetFixTime() );
364 mpImpl
->mbBoolean1
= ((SvxExtTimeField
*)pData
)->GetType() == SVXTIMETYPE_FIX
;
365 mpImpl
->mnInt32
= ((SvxExtTimeField
*)pData
)->GetFormat();
369 mpImpl
->msString1
= ((SvxURLField
*)pData
)->GetRepresentation();
370 mpImpl
->msString2
= ((SvxURLField
*)pData
)->GetTargetFrame();
371 mpImpl
->msString3
= ((SvxURLField
*)pData
)->GetURL();
372 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(
373 ((SvxURLField
*)pData
)->GetFormat());
376 case ID_EXT_FILEFIELD
:
377 mpImpl
->msString1
= ((SvxExtFileField
*)pData
)->GetFile();
378 mpImpl
->mbBoolean1
= ((SvxExtFileField
*)pData
)->GetType() == SVXFILETYPE_FIX
;
379 mpImpl
->mnInt16
= getFileNameDisplayFormat(((SvxExtFileField
*)pData
)->GetFormat());
383 mpImpl
->msString1
= ((SvxAuthorField
*)pData
)->GetFormatted();
384 mpImpl
->msString2
= ((SvxAuthorField
*)pData
)->GetFormatted();
385 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(
386 ((SvxAuthorField
*)pData
)->GetFormat());
387 mpImpl
->mbBoolean1
= ((SvxAuthorField
*)pData
)->GetType() == SVXAUTHORTYPE_FIX
;
388 mpImpl
->mbBoolean2
= ((SvxAuthorField
*)pData
)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME
;
391 case ID_MEASUREFIELD
:
392 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(((SdrMeasureField
*)pData
)->GetMeasureFieldKind());
398 mpPropSet
= ImplGetFieldItemPropertySet(mnServiceId
);
401 SvxUnoTextField::~SvxUnoTextField() throw()
406 SvxFieldData
* SvxUnoTextField::CreateFieldData() const throw()
408 SvxFieldData
* pData
= NULL
;
410 switch( mnServiceId
)
413 case ID_EXT_TIMEFIELD
:
415 case ID_EXT_DATEFIELD
:
417 if( mpImpl
->mbBoolean2
) // IsDate?
419 Date
aDate( setDate( mpImpl
->maDateTime
) );
420 pData
= new SvxDateField( aDate
, mpImpl
->mbBoolean1
?SVXDATETYPE_FIX
:SVXDATETYPE_VAR
);
421 if( mpImpl
->mnInt32
>= SVXDATEFORMAT_APPDEFAULT
&& mpImpl
->mnInt32
<= SVXDATEFORMAT_F
)
422 ((SvxDateField
*)pData
)->SetFormat( (SvxDateFormat
)mpImpl
->mnInt32
);
426 if( mnServiceId
!= ID_TIMEFIELD
&& mnServiceId
!= ID_DATEFIELD
)
428 Time
aTime( setTime( mpImpl
->maDateTime
) );
429 pData
= new SvxExtTimeField( aTime
, mpImpl
->mbBoolean1
?SVXTIMETYPE_FIX
:SVXTIMETYPE_VAR
);
431 if( mpImpl
->mnInt32
>= SVXTIMEFORMAT_APPDEFAULT
&& mpImpl
->mnInt32
<= SVXTIMEFORMAT_AM_HMSH
)
432 ((SvxExtTimeField
*)pData
)->SetFormat( (SvxTimeFormat
)mpImpl
->mnInt32
);
436 pData
= new SvxTimeField();
444 pData
= new SvxURLField( mpImpl
->msString3
, mpImpl
->msString1
, mpImpl
->msString1
.getLength() ? SVXURLFORMAT_REPR
: SVXURLFORMAT_URL
);
445 ((SvxURLField
*)pData
)->SetTargetFrame( mpImpl
->msString2
);
446 if( mpImpl
->mnInt16
>= SVXURLFORMAT_APPDEFAULT
&& mpImpl
->mnInt16
<= SVXURLFORMAT_REPR
)
447 ((SvxURLField
*)pData
)->SetFormat( (SvxURLFormat
)mpImpl
->mnInt16
);
451 pData
= new SvxPageField();
455 pData
= new SvxPagesField();
459 pData
= new SvxFileField();
463 pData
= new SvxTableField();
466 case ID_EXT_FILEFIELD
:
468 // #92009# pass fixed attribute to constructor
469 pData
= new SvxExtFileField( mpImpl
->msString1
,
470 mpImpl
->mbBoolean1
? SVXFILETYPE_FIX
: SVXFILETYPE_VAR
,
471 setFileNameDisplayFormat(mpImpl
->mnInt16
) );
477 ::rtl::OUString aContent
;
482 // do we have CurrentPresentation given?
483 // mimic behaviour of writer, which means:
484 // prefer CurrentPresentation over Content
485 // if both are given.
486 if( mpImpl
->msString1
.getLength() )
487 aContent
= mpImpl
->msString1
;
489 aContent
= mpImpl
->msString2
;
491 sal_Int32 nPos
= aContent
.lastIndexOf( sal_Char(' '), 0 );
494 aFirstName
= aContent
.copy( 0, nPos
);
495 aLastName
= aContent
.copy( nPos
+ 1 );
499 aLastName
= aContent
;
502 // #92009# pass fixed attribute to constructor
503 pData
= new SvxAuthorField( aFirstName
, aLastName
, aEmpty
,
504 mpImpl
->mbBoolean1
? SVXAUTHORTYPE_FIX
: SVXAUTHORTYPE_VAR
);
506 if( !mpImpl
->mbBoolean2
)
508 ((SvxAuthorField
*)pData
)->SetFormat( SVXAUTHORFORMAT_SHORTNAME
);
510 else if( mpImpl
->mnInt16
>= SVXAUTHORFORMAT_FULLNAME
|| mpImpl
->mnInt16
<= SVXAUTHORFORMAT_SHORTNAME
)
512 ((SvxAuthorField
*)pData
)->SetFormat( (SvxAuthorFormat
) mpImpl
->mnInt16
);
518 case ID_MEASUREFIELD
:
520 SdrMeasureFieldKind eKind
= SDRMEASUREFIELD_VALUE
;
521 if( mpImpl
->mnInt16
== (sal_Int16
)SDRMEASUREFIELD_UNIT
|| mpImpl
->mnInt16
== (sal_Int16
)SDRMEASUREFIELD_ROTA90BLANCS
)
522 eKind
= (SdrMeasureFieldKind
) mpImpl
->mnInt16
;
523 pData
= new SdrMeasureField( eKind
);
527 pData
= new SvxHeaderField();
530 pData
= new SvxFooterField();
532 case ID_DATETIMEFIELD
:
533 pData
= new SvxDateTimeField();
541 uno::Any SAL_CALL
SvxUnoTextField::queryAggregation( const uno::Type
& rType
)
542 throw(uno::RuntimeException
)
546 QUERYINT( beans::XPropertySet
);
547 else QUERYINT( text::XTextContent
);
548 else QUERYINT( text::XTextField
);
549 else QUERYINT( lang::XServiceInfo
);
550 else QUERYINT( lang::XUnoTunnel
);
552 return OComponentHelper::queryAggregation( rType
);
559 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextField::getTypes()
560 throw (uno::RuntimeException
)
562 if( maTypeSequence
.getLength() == 0 )
564 maTypeSequence
= OComponentHelper::getTypes();
565 sal_Int32 nOldCount
= maTypeSequence
.getLength();
567 maTypeSequence
.realloc( nOldCount
+ 4 ); // !DANGER! keep this updated
568 uno::Type
* pTypes
= &maTypeSequence
.getArray()[nOldCount
];
570 *pTypes
++ = ::getCppuType(( const uno::Reference
< text::XTextField
>*)0);
571 *pTypes
++ = ::getCppuType(( const uno::Reference
< beans::XPropertySet
>*)0);
572 *pTypes
++ = ::getCppuType(( const uno::Reference
< lang::XServiceInfo
>*)0);
573 *pTypes
++ = ::getCppuType(( const uno::Reference
< lang::XUnoTunnel
>*)0);
575 return maTypeSequence
;
578 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextField::getImplementationId()
579 throw (uno::RuntimeException
)
581 static uno::Sequence
< sal_Int8
> aId
;
582 if( aId
.getLength() == 0 )
585 rtl_createUuid( (sal_uInt8
*)aId
.getArray(), 0, sal_True
);
590 uno::Any SAL_CALL
SvxUnoTextField::queryInterface( const uno::Type
& rType
)
591 throw(uno::RuntimeException
)
593 return OComponentHelper::queryInterface(rType
);
596 void SAL_CALL
SvxUnoTextField::acquire() throw( )
598 OComponentHelper::acquire();
601 void SAL_CALL
SvxUnoTextField::release() throw( )
603 OComponentHelper::release();
606 // Interface text::XTextField
607 OUString SAL_CALL
SvxUnoTextField::getPresentation( sal_Bool bShowCommand
)
608 throw(uno::RuntimeException
)
610 OGuard
aGuard( Application::GetSolarMutex() );
614 DBG_ASSERT( ((sal_uInt32
)mnServiceId
) < ID_UNKNOWN
, "Unknown field type" );
615 return OUString::createFromAscii( aFieldItemNameMap_Impl
[(((sal_uInt32
)mnServiceId
) > ID_UNKNOWN
)? ID_UNKNOWN
: mnServiceId
] );
619 return mpImpl
->msPresentation
;
623 // Interface text::XTextContent
624 void SAL_CALL
SvxUnoTextField::attach( const uno::Reference
< text::XTextRange
>& xTextRange
)
625 throw(lang::IllegalArgumentException
, uno::RuntimeException
)
627 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xTextRange
);
629 throw lang::IllegalArgumentException();
631 SvxFieldData
* pData
= CreateFieldData();
633 pRange
->attachField( pData
);
638 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextField::getAnchor()
639 throw(uno::RuntimeException
)
645 void SAL_CALL
SvxUnoTextField::dispose()
646 throw(uno::RuntimeException
)
648 OComponentHelper::dispose();
651 void SAL_CALL
SvxUnoTextField::addEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
652 throw(uno::RuntimeException
)
654 OComponentHelper::addEventListener(xListener
);
657 void SAL_CALL
SvxUnoTextField::removeEventListener( const uno::Reference
< lang::XEventListener
>& aListener
)
658 throw(uno::RuntimeException
)
660 OComponentHelper::removeEventListener(aListener
);
664 // Interface beans::XPropertySet
665 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SvxUnoTextField::getPropertySetInfo( )
666 throw(uno::RuntimeException
)
668 OGuard
aGuard( Application::GetSolarMutex() );
669 return mpPropSet
->getPropertySetInfo();
672 void SAL_CALL
SvxUnoTextField::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
)
673 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
675 OGuard
aGuard( Application::GetSolarMutex() );
678 throw uno::RuntimeException();
680 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap()->getByName( aPropertyName
);
682 throw beans::UnknownPropertyException();
687 if(aValue
>>= mpImpl
->maDateTime
)
691 if(aValue
>>= mpImpl
->mbBoolean1
)
695 if(aValue
>>= mpImpl
->mbBoolean2
)
699 if(aValue
>>= mpImpl
->mnInt16
)
703 if(aValue
>>= mpImpl
->mnInt32
)
707 if(aValue
>>= mpImpl
->msString1
)
711 if(aValue
>>= mpImpl
->msString2
)
715 if(aValue
>>= mpImpl
->msString3
)
720 throw lang::IllegalArgumentException();
731 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
733 pDate->SetFormat( (SvxDateFormat)nFormat );
738 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
740 pURL->SetFormat( (SvxURLFormat)nFormat );
743 case ID_EXT_TIMEFIELD:
745 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
747 pTime->SetFormat( (SvxTimeFormat)nFormat );
750 case ID_EXT_FILEFIELD:
752 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
754 pFile->SetFormat( (SvxFileFormat)nFormat );
759 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
761 pAuthor->SetFormat( (SvxAuthorFormat)nFormat );
765 throw beans::UnknownPropertyException();
771 if( aValue.hasValue() || aValue.getValueType() != ::getCppuBooleanType() )
772 throw lang::IllegalArgumentException();
773 sal_Bool bFix( *(sal_Bool*)aValue.getValue() );
776 case ID_EXT_TIMEFIELD:
778 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
780 pTime->SetType( (SvxTimeType)bFix?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
785 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
787 pDate->SetType( (SvxDateType)bFix?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
790 case ID_EXT_FILEFIELD:
792 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
794 pFile->SetType( (SvxFileType)bFix?SVXFILETYPE_FIX:SVXFILETYPE_VAR );
799 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
801 pAuthor->SetType( (SvxAuthorType)bFix?SVXAUTHORTYPE_FIX:SVXAUTHORTYPE_VAR );
805 throw beans::UnknownPropertyException();
813 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
817 if(!(aValue >>= aUnoStr))
818 throw lang::IllegalArgumentException();
823 pURL->SetRepresentation( aUnoStr );
826 pURL->SetURL( aUnoStr );
829 pURL->SetTargetFrame( aUnoStr );
837 SfxItemSet aSet = pForwarder->GetAttribs( GetSelection() );
838 aSet.Put( aFieldItem );
842 uno::Any SAL_CALL
SvxUnoTextField::getPropertyValue( const OUString
& PropertyName
)
843 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
845 OGuard
aGuard( Application::GetSolarMutex() );
849 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap()->getByName( PropertyName
);
851 throw beans::UnknownPropertyException();
856 aValue
<<= mpImpl
->maDateTime
;
859 aValue
<<= mpImpl
->mbBoolean1
;
862 aValue
<<= mpImpl
->mbBoolean2
;
865 aValue
<<= mpImpl
->mnInt16
;
868 aValue
<<= mpImpl
->mnInt32
;
871 aValue
<<= mpImpl
->msString1
;
874 aValue
<<= mpImpl
->msString2
;
877 aValue
<<= mpImpl
->msString3
;
891 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
893 aValue <<= (sal_Int32)pDate->GetFormat();
898 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
900 aValue <<= (sal_Int32)pURL->GetFormat();
903 case ID_EXT_TIMEFIELD:
905 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
907 aValue <<= (sal_Int32)pTime->GetFormat();
910 case ID_EXT_FILEFIELD:
912 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
914 aValue <<= (sal_Int32)pFile->GetFormat();
919 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
921 aValue <<= (sal_Int32)pAuthor->GetFormat();
925 throw beans::UnknownPropertyException();
930 sal_Bool bFix = sal_False;
933 case ID_EXT_TIMEFIELD:
935 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
937 bFix = pTime->GetType() == SVXTIMETYPE_FIX;
942 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
944 bFix = pDate->GetType() == SVXDATETYPE_FIX;
947 case ID_EXT_FILEFIELD:
949 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
951 bFix = pFile->GetType() == SVXFILETYPE_FIX;
956 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
958 bFix = pAuthor->GetType() == SVXAUTHORTYPE_FIX;
962 throw beans::UnknownPropertyException();
964 aValue.setValue( &bFix, ::getCppuBooleanType() );
971 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
978 aStr = pURL->GetRepresentation();
981 aStr = pURL->GetURL();
984 aStr = pURL->GetTargetFrame();
994 Color* pFColor = NULL;
995 Color* pTColor = NULL;
996 const ESelection aSel = GetSelection();
998 pForwarder->CalcFieldValue( *pFieldItem, aSel.nStartPara, aSel.nStartPos, pTColor, pFColor );
1000 if( pMap->nWID == WID_FCOLOR )
1001 aValue <<= (sal_Int32)pFColor->GetColor();
1003 aValue <<= (sal_Int32)pTColor->GetColor();
1014 void SAL_CALL
SvxUnoTextField::addPropertyChangeListener( const OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
1015 void SAL_CALL
SvxUnoTextField::removePropertyChangeListener( const OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
1016 void SAL_CALL
SvxUnoTextField::addVetoableChangeListener( const OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
1017 void SAL_CALL
SvxUnoTextField::removeVetoableChangeListener( const OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
) {}
1020 void SvxUnoTextField::disposing()
1025 sal_Int32
SvxUnoTextField::GetFieldId( const SvxFieldData
* pFieldData
) const throw()
1027 if( pFieldData
->ISA( SvxURLField
) )
1029 else if( pFieldData
->ISA( SvxPageField
) )
1030 return ID_PAGEFIELD
;
1031 else if( pFieldData
->ISA( SvxPagesField
) )
1032 return ID_PAGESFIELD
;
1033 else if( pFieldData
->ISA( SvxTimeField
) )
1034 return ID_TIMEFIELD
;
1035 else if( pFieldData
->ISA( SvxFileField
) )
1036 return ID_FILEFIELD
;
1037 else if( pFieldData
->ISA( SvxTableField
) )
1038 return ID_TABLEFIELD
;
1039 else if( pFieldData
->ISA( SvxExtTimeField
) )
1040 return ID_EXT_TIMEFIELD
;
1041 else if( pFieldData
->ISA( SvxExtFileField
) )
1042 return ID_EXT_FILEFIELD
;
1043 else if( pFieldData
->ISA( SvxAuthorField
) )
1044 return ID_AUTHORFIELD
;
1045 else if( pFieldData
->ISA( SvxDateField
) )
1046 return ID_EXT_DATEFIELD
;
1047 else if( pFieldData
->ISA( SdrMeasureField
) )
1048 return ID_MEASUREFIELD
;
1049 else if( pFieldData
->ISA( SvxHeaderField
) )
1050 return ID_HEADERFIELD
;
1051 else if( pFieldData
->ISA( SvxFooterField
) )
1052 return ID_FOOTERFIELD
;
1053 else if( pFieldData
->ISA( SvxDateTimeField
) )
1054 return ID_DATETIMEFIELD
;
1059 // lang::XServiceInfo
1060 OUString SAL_CALL
SvxUnoTextField::getImplementationName() throw(uno::RuntimeException
)
1062 return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextField"));
1065 static const sal_Char
* pOldServiceNames
[] =
1067 "com.sun.star.text.TextField.DateTime",
1068 "com.sun.star.text.TextField.URL",
1069 "com.sun.star.text.TextField.PageNumber",
1070 "com.sun.star.text.TextField.PageCount",
1071 "com.sun.star.text.TextField.DateTime",
1072 "com.sun.star.text.TextField.DocInfo.Title", // SvxFileField is used for title
1073 "com.sun.star.text.TextField.SheetName",
1074 "com.sun.star.text.TextField.DateTime",
1075 "com.sun.star.text.TextField.FileName",
1076 "com.sun.star.text.TextField.Author",
1077 "com.sun.star.text.TextField.Measure",
1078 "com.sun.star.text.TextField.DateTime",
1079 "com.sun.star.presentation.TextField.Header",
1080 "com.sun.star.presentation.TextField.Footer",
1081 "com.sun.star.presentation.TextField.DateTime"
1084 static const sal_Char
* pNewServiceNames
[] =
1086 "com.sun.star.text.textfield.DateTime",
1087 "com.sun.star.text.textfield.URL",
1088 "com.sun.star.text.textfield.PageNumber",
1089 "com.sun.star.text.textfield.PageCount",
1090 "com.sun.star.text.textfield.DateTime",
1091 "com.sun.star.text.textfield.docinfo.Title", // SvxFileField is used for title
1092 "com.sun.star.text.textfield.SheetName",
1093 "com.sun.star.text.textfield.DateTime",
1094 "com.sun.star.text.textfield.FileName",
1095 "com.sun.star.text.textfield.Author",
1096 "com.sun.star.text.textfield.Measure",
1097 "com.sun.star.text.textfield.DateTime",
1098 "com.sun.star.presentation.textfield.Header",
1099 "com.sun.star.presentation.textfield.Footer",
1100 "com.sun.star.presentation.textfield.DateTime"
1103 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextField::getSupportedServiceNames()
1104 throw(uno::RuntimeException
)
1106 uno::Sequence
< OUString
> aSeq( 4 );
1107 OUString
* pServices
= aSeq
.getArray();
1108 pServices
[0] = OUString::createFromAscii( pNewServiceNames
[mnServiceId
] );
1109 pServices
[1] = OUString::createFromAscii( pOldServiceNames
[mnServiceId
] );
1110 pServices
[2] = OUString::createFromAscii( "com.sun.star.text.TextContent" ),
1111 pServices
[3] = OUString::createFromAscii( "com.sun.star.text.TextField" );
1116 sal_Bool SAL_CALL
SvxUnoTextField::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
)
1118 return SvxServiceInfoHelper::supportsService( ServiceName
, getSupportedServiceNames() );