merge the formfield patch from ooo-build
[ooovba.git] / svx / source / unoedit / unofield.cxx
blobf058a44ba884a60cdd89a8f2688ab26483ab92f3
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: unofield.cxx,v $
10 * $Revision: 1.31 $
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>
40 #include <rtl/uuid.h>
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)
60 #define WID_DATE 0
61 #define WID_BOOL1 1
62 #define WID_BOOL2 2
63 #define WID_INT32 3
64 #define WID_INT16 4
65 #define WID_STRING1 5
66 #define WID_STRING2 6
67 #define WID_STRING3 7
69 class SvxUnoFieldData_Impl
71 public:
72 sal_Bool mbBoolean1;
73 sal_Bool mbBoolean2;
74 sal_Int32 mnInt32;
75 sal_Int16 mnInt16;
76 OUString msString1;
77 OUString msString2;
78 OUString msString3;
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 },
92 {0,0,0,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 },
99 {0,0,0,0,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 },
110 {0,0,0,0,0,0}
112 static SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
114 static SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
116 {0,0,0,0,0,0}
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 },
125 {0,0,0,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 },
136 {0,0,0,0,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 },
143 {0,0,0,0,0,0}
145 static SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
147 switch( mnId )
149 case ID_EXT_DATEFIELD:
150 case ID_EXT_TIMEFIELD:
151 return &aExDateTimeFieldPropertySet_Impl;
152 case ID_URLFIELD:
153 return &aUrlFieldPropertySet_Impl;
154 case ID_DATEFIELD:
155 case ID_TIMEFIELD:
156 return &aDateTimeFieldPropertySet_Impl;
157 case ID_EXT_FILEFIELD:
158 return &aExtFileFieldPropertySet_Impl;
159 case ID_AUTHORFIELD:
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::
170 default:
171 return &aEmptyPropertySet_Impl;
175 static sal_Char const* aFieldItemNameMap_Impl[] =
177 "Date",
178 "URL",
179 "Page",
180 "Pages",
181 "Time",
182 "File",
183 "Table",
184 "ExtTime",
185 "ExtFile",
186 "Author",
187 "Measure",
188 "ExtDate",
189 "Header",
190 "Footer",
191 "DateTime",
192 "Unknown"
195 /* conversion routines */
197 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
199 switch( 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 )
211 switch( 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:
217 default:
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();
233 return aDate;
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();
253 return aTime;
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() )
268 , mpPropSet(NULL)
269 , mnServiceId(nServiceId)
270 , mpImpl( new SvxUnoFieldData_Impl )
272 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
274 memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
276 switch( nServiceId )
278 case ID_EXT_DATEFIELD:
279 case ID_DATEFIELD:
280 mpImpl->mbBoolean2 = sal_True;
281 mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
282 mpImpl->mbBoolean1 = sal_False;
283 break;
285 case ID_EXT_TIMEFIELD:
286 case ID_TIMEFIELD:
287 mpImpl->mbBoolean2 = sal_False;
288 mpImpl->mbBoolean1 = sal_False;
289 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
290 break;
292 case ID_URLFIELD:
293 mpImpl->mnInt16 = SVXURLFORMAT_REPR;
294 break;
296 case ID_EXT_FILEFIELD:
297 mpImpl->mbBoolean1 = sal_False;
298 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
299 break;
301 case ID_AUTHORFIELD:
302 mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
303 mpImpl->mbBoolean1 = sal_False;
304 mpImpl->mbBoolean2 = sal_True;
305 break;
307 case ID_MEASUREFIELD:
308 mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
309 break;
311 default:
312 mpImpl->mbBoolean1 = sal_False;
313 mpImpl->mbBoolean2 = sal_False;
314 mpImpl->mnInt32 = 0;
315 mpImpl->mnInt16 = 0;
320 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
321 : OComponentHelper( getMutex() )
322 , mxAnchor( xAnchor )
323 , mpPropSet(NULL)
324 , mnServiceId(ID_UNKNOWN)
325 , mpImpl( new SvxUnoFieldData_Impl )
327 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
329 mpImpl->msPresentation = rPresentation;
331 if(pData)
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 )
340 case ID_DATEFIELD:
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() :
349 Date().GetDate() );
350 mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat();
351 mpImpl->mbBoolean1 = bFixed;
353 break;
355 case ID_TIMEFIELD:
356 mpImpl->mbBoolean2 = sal_False;
357 mpImpl->mbBoolean1 = sal_False;
358 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
359 break;
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();
366 break;
368 case ID_URLFIELD:
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());
374 break;
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());
380 break;
382 case ID_AUTHORFIELD:
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;
389 break;
391 case ID_MEASUREFIELD:
392 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(((SdrMeasureField*)pData)->GetMeasureFieldKind());
393 break;
398 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
401 SvxUnoTextField::~SvxUnoTextField() throw()
403 delete mpImpl;
406 SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
408 SvxFieldData* pData = NULL;
410 switch( mnServiceId )
412 case ID_TIMEFIELD:
413 case ID_EXT_TIMEFIELD:
414 case ID_DATEFIELD:
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 );
424 else
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 );
434 else
436 pData = new SvxTimeField();
441 break;
443 case ID_URLFIELD:
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 );
448 break;
450 case ID_PAGEFIELD:
451 pData = new SvxPageField();
452 break;
454 case ID_PAGESFIELD:
455 pData = new SvxPagesField();
456 break;
458 case ID_FILEFIELD:
459 pData = new SvxFileField();
460 break;
462 case ID_TABLEFIELD:
463 pData = new SvxTableField();
464 break;
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 ) );
472 break;
475 case ID_AUTHORFIELD:
477 ::rtl::OUString aContent;
478 String aFirstName;
479 String aLastName;
480 String aEmpty;
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;
488 else
489 aContent = mpImpl->msString2;
491 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
492 if( nPos > 0 )
494 aFirstName = aContent.copy( 0, nPos );
495 aLastName = aContent.copy( nPos + 1 );
497 else
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 );
515 break;
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);
524 break;
526 case ID_HEADERFIELD:
527 pData = new SvxHeaderField();
528 break;
529 case ID_FOOTERFIELD:
530 pData = new SvxFooterField();
531 break;
532 case ID_DATETIMEFIELD:
533 pData = new SvxDateTimeField();
534 break;
537 return pData;
540 // uno::XInterface
541 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
542 throw(uno::RuntimeException)
544 uno::Any aAny;
546 QUERYINT( beans::XPropertySet );
547 else QUERYINT( text::XTextContent );
548 else QUERYINT( text::XTextField );
549 else QUERYINT( lang::XServiceInfo );
550 else QUERYINT( lang::XUnoTunnel );
551 else
552 return OComponentHelper::queryAggregation( rType );
554 return aAny;
557 // XTypeProvider
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 )
584 aId.realloc( 16 );
585 rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
587 return aId;
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() );
612 if(bShowCommand)
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 ] );
617 else
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 );
628 if(pRange == NULL)
629 throw lang::IllegalArgumentException();
631 SvxFieldData* pData = CreateFieldData();
632 if( pData )
633 pRange->attachField( pData );
635 delete pData;
638 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
639 throw(uno::RuntimeException)
641 return mxAnchor;
644 // lang::XComponent
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() );
677 if( mpImpl == NULL )
678 throw uno::RuntimeException();
680 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( aPropertyName );
681 if ( !pMap )
682 throw beans::UnknownPropertyException();
684 switch( pMap->nWID )
686 case WID_DATE:
687 if(aValue >>= mpImpl->maDateTime)
688 return;
689 break;
690 case WID_BOOL1:
691 if(aValue >>= mpImpl->mbBoolean1)
692 return;
693 break;
694 case WID_BOOL2:
695 if(aValue >>= mpImpl->mbBoolean2)
696 return;
697 break;
698 case WID_INT16:
699 if(aValue >>= mpImpl->mnInt16)
700 return;
701 break;
702 case WID_INT32:
703 if(aValue >>= mpImpl->mnInt32)
704 return;
705 break;
706 case WID_STRING1:
707 if(aValue >>= mpImpl->msString1)
708 return;
709 break;
710 case WID_STRING2:
711 if(aValue >>= mpImpl->msString2)
712 return;
713 break;
714 case WID_STRING3:
715 if(aValue >>= mpImpl->msString3)
716 return;
717 break;
720 throw lang::IllegalArgumentException();
723 case WID_FORMAT:
725 sal_Int32 nFormat;
727 switch( mnId )
729 case ID_DATEFIELD:
731 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
732 if(pDate)
733 pDate->SetFormat( (SvxDateFormat)nFormat );
734 break;
736 case ID_URLFIELD:
738 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
739 if(pURL)
740 pURL->SetFormat( (SvxURLFormat)nFormat );
741 break;
743 case ID_EXT_TIMEFIELD:
745 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
746 if(pTime)
747 pTime->SetFormat( (SvxTimeFormat)nFormat );
748 break;
750 case ID_EXT_FILEFIELD:
752 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
753 if(pFile)
754 pFile->SetFormat( (SvxFileFormat)nFormat );
755 break;
757 case ID_AUTHORFIELD:
759 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
760 if(pAuthor)
761 pAuthor->SetFormat( (SvxAuthorFormat)nFormat );
762 break;
764 default:
765 throw beans::UnknownPropertyException();
768 break;
769 case WID_FIX:
771 if( aValue.hasValue() || aValue.getValueType() != ::getCppuBooleanType() )
772 throw lang::IllegalArgumentException();
773 sal_Bool bFix( *(sal_Bool*)aValue.getValue() );
774 switch( mnId )
776 case ID_EXT_TIMEFIELD:
778 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
779 if(pTime)
780 pTime->SetType( (SvxTimeType)bFix?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
781 break;
783 case ID_DATEFIELD:
785 SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
786 if(pDate)
787 pDate->SetType( (SvxDateType)bFix?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
788 break;
790 case ID_EXT_FILEFIELD:
792 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
793 if(pFile)
794 pFile->SetType( (SvxFileType)bFix?SVXFILETYPE_FIX:SVXFILETYPE_VAR );
795 break;
797 case ID_AUTHORFIELD:
799 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
800 if(pAuthor)
801 pAuthor->SetType( (SvxAuthorType)bFix?SVXAUTHORTYPE_FIX:SVXAUTHORTYPE_VAR );
802 break;
804 default:
805 throw beans::UnknownPropertyException();
808 break;
809 case WID_PRES:
810 case WID_URL:
811 case WID_TARGET:
813 SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
814 if(pURL)
816 OUString aUnoStr;
817 if(!(aValue >>= aUnoStr))
818 throw lang::IllegalArgumentException();
820 switch( pMap->nWID )
822 case WID_PRES:
823 pURL->SetRepresentation( aUnoStr );
824 break;
825 case WID_URL:
826 pURL->SetURL( aUnoStr );
827 break;
828 case WID_TARGET:
829 pURL->SetTargetFrame( aUnoStr );
830 break;
833 break;
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() );
847 uno::Any aValue;
849 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( PropertyName );
850 if ( !pMap )
851 throw beans::UnknownPropertyException();
853 switch( pMap->nWID )
855 case WID_DATE:
856 aValue <<= mpImpl->maDateTime;
857 break;
858 case WID_BOOL1:
859 aValue <<= mpImpl->mbBoolean1;
860 break;
861 case WID_BOOL2:
862 aValue <<= mpImpl->mbBoolean2;
863 break;
864 case WID_INT16:
865 aValue <<= mpImpl->mnInt16;
866 break;
867 case WID_INT32:
868 aValue <<= mpImpl->mnInt32;
869 break;
870 case WID_STRING1:
871 aValue <<= mpImpl->msString1;
872 break;
873 case WID_STRING2:
874 aValue <<= mpImpl->msString2;
875 break;
876 case WID_STRING3:
877 aValue <<= mpImpl->msString3;
878 break;
881 return aValue;
884 switch(pMap->nWID)
886 case WID_FORMAT:
887 switch( mnId )
889 case ID_DATEFIELD:
891 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
892 if(pDate)
893 aValue <<= (sal_Int32)pDate->GetFormat();
894 break;
896 case ID_URLFIELD:
898 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
899 if(pURL)
900 aValue <<= (sal_Int32)pURL->GetFormat();
901 break;
903 case ID_EXT_TIMEFIELD:
905 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
906 if(pTime)
907 aValue <<= (sal_Int32)pTime->GetFormat();
908 break;
910 case ID_EXT_FILEFIELD:
912 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
913 if(pFile)
914 aValue <<= (sal_Int32)pFile->GetFormat();
915 break;
917 case ID_AUTHORFIELD:
919 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
920 if(pAuthor)
921 aValue <<= (sal_Int32)pAuthor->GetFormat();
922 break;
924 default:
925 throw beans::UnknownPropertyException();
927 break;
928 case WID_FIX:
930 sal_Bool bFix = sal_False;
931 switch( mnId )
933 case ID_EXT_TIMEFIELD:
935 SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
936 if(pTime)
937 bFix = pTime->GetType() == SVXTIMETYPE_FIX;
938 break;
940 case ID_DATEFIELD:
942 SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
943 if(pDate)
944 bFix = pDate->GetType() == SVXDATETYPE_FIX;
945 break;
947 case ID_EXT_FILEFIELD:
949 SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
950 if(pFile)
951 bFix = pFile->GetType() == SVXFILETYPE_FIX;
952 break;
954 case ID_AUTHORFIELD:
956 SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
957 if(pAuthor)
958 bFix = pAuthor->GetType() == SVXAUTHORTYPE_FIX;
959 break;
961 default:
962 throw beans::UnknownPropertyException();
964 aValue.setValue( &bFix, ::getCppuBooleanType() );
966 break;
967 case WID_PRES:
968 case WID_URL:
969 case WID_TARGET:
971 SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
972 if(pURL)
974 OUString aStr;
975 switch( pMap->nWID )
977 case WID_PRES:
978 aStr = pURL->GetRepresentation();
979 break;
980 case WID_URL:
981 aStr = pURL->GetURL();
982 break;
983 case WID_TARGET:
984 aStr = pURL->GetTargetFrame();
985 break;
987 aValue <<= aStr;
989 break;
991 case WID_FCOLOR:
992 case WID_TCOLOR:
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();
1002 else
1003 aValue <<= (sal_Int32)pTColor->GetColor();
1004 break;
1006 delete pTColor;
1007 delete pFColor;
1010 return aValue;
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) {}
1019 // OComponentHelper
1020 void SvxUnoTextField::disposing()
1022 // nothing to do
1025 sal_Int32 SvxUnoTextField::GetFieldId( const SvxFieldData* pFieldData ) const throw()
1027 if( pFieldData->ISA( SvxURLField ) )
1028 return ID_URLFIELD;
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;
1056 return ID_UNKNOWN;
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" );
1113 return aSeq;
1116 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
1118 return SvxServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );