Bump for 3.6-28
[LibreOffice.git] / editeng / source / uno / unofield.cxx
blob8bc3fccddde78301fb3830db657401b9e05d23fa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/util/DateTime.hpp>
30 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
31 #include <com/sun/star/lang/NoSupportException.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <vcl/svapp.hxx>
34 #include <osl/mutex.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <editeng/flditem.hxx>
38 #include <editeng/measfld.hxx>
39 #include <editeng/unofield.hxx>
40 #include <editeng/unotext.hxx>
41 #include <comphelper/serviceinfohelper.hxx>
42 #include <comphelper/servicehelper.hxx>
44 #include "editeng/unonames.hxx"
46 using namespace ::rtl;
47 using namespace ::cppu;
48 using namespace ::com::sun::star;
50 #define QUERYINT( xint ) \
51 if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
52 aAny <<= uno::Reference< xint >(this)
55 #define WID_DATE 0
56 #define WID_BOOL1 1
57 #define WID_BOOL2 2
58 #define WID_INT32 3
59 #define WID_INT16 4
60 #define WID_STRING1 5
61 #define WID_STRING2 6
62 #define WID_STRING3 7
64 inline bool isValidFieldId(sal_Int32 nId)
66 return nId >= 0;
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(UNO_TC_PROP_DATE_TIME), WID_DATE, &::getCppuType((const util::DateTime*)0), 0, 0 },
89 { MAP_CHAR_LEN(UNO_TC_PROP_IS_FIXED), WID_BOOL1, &::getBooleanCppuType(), 0, 0 },
90 { MAP_CHAR_LEN(UNO_TC_PROP_IS_DATE), WID_BOOL2, &::getBooleanCppuType(), 0, 0 },
91 { MAP_CHAR_LEN(UNO_TC_PROP_NUMFORMAT), WID_INT32, &::getCppuType((const sal_Int32*)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(UNO_TC_PROP_IS_DATE), 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(UNO_TC_PROP_URL_FORMAT), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 },
107 { MAP_CHAR_LEN(UNO_TC_PROP_URL_REPRESENTATION), WID_STRING1, &::getCppuType((const OUString*)0), 0, 0 },
108 { MAP_CHAR_LEN(UNO_TC_PROP_URL_TARGET), WID_STRING2, &::getCppuType((const OUString*)0), 0, 0 },
109 { MAP_CHAR_LEN(UNO_TC_PROP_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(UNO_TC_PROP_IS_FIXED), WID_BOOL1, &::getBooleanCppuType(), 0, 0 },
123 { MAP_CHAR_LEN(UNO_TC_PROP_FILE_FORMAT), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 },
124 { MAP_CHAR_LEN(UNO_TC_PROP_CURRENT_PRESENTATION), 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(UNO_TC_PROP_IS_FIXED), WID_BOOL1, &::getBooleanCppuType(), 0, 0 },
132 { MAP_CHAR_LEN(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1,&::getCppuType((const OUString*)0), 0, 0 },
133 { MAP_CHAR_LEN(UNO_TC_PROP_AUTHOR_CONTENT), WID_STRING2,&::getCppuType((const OUString*)0), 0, 0 },
134 { MAP_CHAR_LEN(UNO_TC_PROP_AUTHOR_FORMAT), WID_INT16, &::getCppuType((const sal_Int16*)0), 0, 0 },
135 { MAP_CHAR_LEN(UNO_TC_PROP_AUTHOR_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(UNO_TC_PROP_MEASURE_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 text::textfield::Type::EXTENDED_TIME:
150 case text::textfield::Type::DATE:
151 return &aExDateTimeFieldPropertySet_Impl;
152 case text::textfield::Type::URL:
153 return &aUrlFieldPropertySet_Impl;
154 case text::textfield::Type::TIME:
155 return &aDateTimeFieldPropertySet_Impl;
156 case text::textfield::Type::EXTENDED_FILE:
157 return &aExtFileFieldPropertySet_Impl;
158 case text::textfield::Type::AUTHOR:
159 return &aAuthorFieldPropertySet_Impl;
160 case text::textfield::Type::MEASURE:
161 return &aMeasureFieldPropertySet_Impl;
162 default:
163 return &aEmptyPropertySet_Impl;
167 /* conversion routines */
169 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
171 switch( nFormat )
173 case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT;
174 case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL;
175 case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH;
176 // case SVXFILEFORMAT_NAME:
177 default: return text::FilenameDisplayFormat::NAME;
181 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
183 switch( nFormat )
185 case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH;
186 case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH;
187 case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME;
188 // case text::FilenameDisplayFormat::NAME_AND_EXT:
189 default:
190 return SVXFILEFORMAT_NAME_EXT;
194 static util::DateTime getDate( sal_uLong nDate )
196 util::DateTime aDate;
197 memset( &aDate, 0, sizeof( util::DateTime ) );
199 Date aTempDate( nDate );
201 aDate.Day = aTempDate.GetDay();
202 aDate.Month = aTempDate.GetMonth();
203 aDate.Year = aTempDate.GetYear();
205 return aDate;
208 inline Date setDate( util::DateTime& rDate )
210 return Date( rDate.Day, rDate.Month, rDate.Year );
213 static util::DateTime getTime( long nTime )
215 util::DateTime aTime;
216 memset( &aTime, 0, sizeof( util::DateTime ) );
218 Time aTempTime( nTime );
220 aTime.HundredthSeconds = aTempTime.Get100Sec();
221 aTime.Seconds = aTempTime.GetSec();
222 aTime.Minutes = aTempTime.GetMin();
223 aTime.Hours = aTempTime.GetHour();
225 return aTime;
228 inline Time setTime( util::DateTime& rDate )
230 return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.HundredthSeconds );
233 // ====================================================================
234 // class SvxUnoTextField
235 // ====================================================================
236 namespace
238 class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
241 const ::com::sun::star::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
243 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
246 sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException)
248 if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
249 rId.getConstArray(), 16 ) )
251 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
253 return 0;
256 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
257 : OComponentHelper( getMutex() )
258 , mpPropSet(NULL)
259 , mnServiceId(nServiceId)
260 , mpImpl( new SvxUnoFieldData_Impl )
262 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
264 memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
266 switch( nServiceId )
268 case text::textfield::Type::DATE:
269 mpImpl->mbBoolean2 = sal_True;
270 mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
271 mpImpl->mbBoolean1 = sal_False;
272 break;
274 case text::textfield::Type::EXTENDED_TIME:
275 case text::textfield::Type::TIME:
276 mpImpl->mbBoolean2 = sal_False;
277 mpImpl->mbBoolean1 = sal_False;
278 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
279 break;
281 case text::textfield::Type::URL:
282 mpImpl->mnInt16 = SVXURLFORMAT_REPR;
283 break;
285 case text::textfield::Type::EXTENDED_FILE:
286 mpImpl->mbBoolean1 = sal_False;
287 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
288 break;
290 case text::textfield::Type::AUTHOR:
291 mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
292 mpImpl->mbBoolean1 = sal_False;
293 mpImpl->mbBoolean2 = sal_True;
294 break;
296 case text::textfield::Type::MEASURE:
297 mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
298 break;
300 default:
301 mpImpl->mbBoolean1 = sal_False;
302 mpImpl->mbBoolean2 = sal_False;
303 mpImpl->mnInt32 = 0;
304 mpImpl->mnInt16 = 0;
309 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
310 : OComponentHelper( getMutex() )
311 , mxAnchor( xAnchor )
312 , mpPropSet(NULL)
313 , mnServiceId(text::textfield::Type::UNSPECIFIED)
314 , mpImpl( new SvxUnoFieldData_Impl )
316 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
318 mpImpl->msPresentation = rPresentation;
320 if(pData)
322 mnServiceId = pData->GetClassId();
323 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
324 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
326 // extract field properties from data class
327 switch( mnServiceId )
329 case text::textfield::Type::DATE:
331 mpImpl->mbBoolean2 = sal_True;
332 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
333 // use current date instead
334 sal_Bool bFixed = ((SvxDateField*)pData)->GetType() == SVXDATETYPE_FIX;
335 mpImpl->maDateTime = getDate( bFixed ?
336 ((SvxDateField*)pData)->GetFixDate() :
337 Date( Date::SYSTEM ).GetDate() );
338 mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat();
339 mpImpl->mbBoolean1 = bFixed;
341 break;
343 case text::textfield::Type::TIME:
344 mpImpl->mbBoolean2 = sal_False;
345 mpImpl->mbBoolean1 = sal_False;
346 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
347 break;
349 case text::textfield::Type::EXTENDED_TIME:
350 mpImpl->mbBoolean2 = sal_False;
351 mpImpl->maDateTime = getTime( ((SvxExtTimeField*)pData)->GetFixTime() );
352 mpImpl->mbBoolean1 = ((SvxExtTimeField*)pData)->GetType() == SVXTIMETYPE_FIX;
353 mpImpl->mnInt32 = ((SvxExtTimeField*)pData)->GetFormat();
354 break;
356 case text::textfield::Type::URL:
357 mpImpl->msString1 = ((SvxURLField*)pData)->GetRepresentation();
358 mpImpl->msString2 = ((SvxURLField*)pData)->GetTargetFrame();
359 mpImpl->msString3 = ((SvxURLField*)pData)->GetURL();
360 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
361 ((SvxURLField*)pData)->GetFormat());
362 break;
364 case text::textfield::Type::EXTENDED_FILE:
365 mpImpl->msString1 = ((SvxExtFileField*)pData)->GetFile();
366 mpImpl->mbBoolean1 = ((SvxExtFileField*)pData)->GetType() == SVXFILETYPE_FIX;
367 mpImpl->mnInt16 = getFileNameDisplayFormat(((SvxExtFileField*)pData)->GetFormat());
368 break;
370 case text::textfield::Type::AUTHOR:
371 mpImpl->msString1 = ((SvxAuthorField*)pData)->GetFormatted();
372 mpImpl->msString2 = ((SvxAuthorField*)pData)->GetFormatted();
373 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
374 ((SvxAuthorField*)pData)->GetFormat());
375 mpImpl->mbBoolean1 = ((SvxAuthorField*)pData)->GetType() == SVXAUTHORTYPE_FIX;
376 mpImpl->mbBoolean2 = ((SvxAuthorField*)pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME;
377 break;
379 case text::textfield::Type::MEASURE:
380 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(((SdrMeasureField*)pData)->GetMeasureFieldKind());
381 break;
386 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
389 SvxUnoTextField::~SvxUnoTextField() throw()
391 delete mpImpl;
394 SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
396 SvxFieldData* pData = NULL;
398 switch( mnServiceId )
400 case text::textfield::Type::TIME:
401 case text::textfield::Type::EXTENDED_TIME:
402 case text::textfield::Type::DATE:
404 if( mpImpl->mbBoolean2 ) // IsDate?
406 Date aDate( setDate( mpImpl->maDateTime ) );
407 pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
408 if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F )
409 ((SvxDateField*)pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 );
411 else
413 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
415 Time aTime( setTime( mpImpl->maDateTime ) );
416 pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
418 if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH )
419 ((SvxExtTimeField*)pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 );
421 else
423 pData = new SvxTimeField();
428 break;
430 case text::textfield::Type::URL:
431 pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL );
432 ((SvxURLField*)pData)->SetTargetFrame( mpImpl->msString2 );
433 if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR )
434 ((SvxURLField*)pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 );
435 break;
437 case text::textfield::Type::PAGE:
438 pData = new SvxPageField();
439 break;
441 case text::textfield::Type::PAGES:
442 pData = new SvxPagesField();
443 break;
445 case text::textfield::Type::DOCINFO_TITLE:
446 pData = new SvxFileField();
447 break;
449 case text::textfield::Type::TABLE:
450 pData = new SvxTableField();
451 break;
453 case text::textfield::Type::EXTENDED_FILE:
455 // #92009# pass fixed attribute to constructor
456 pData = new SvxExtFileField( mpImpl->msString1,
457 mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR,
458 setFileNameDisplayFormat(mpImpl->mnInt16 ) );
459 break;
462 case text::textfield::Type::AUTHOR:
464 ::rtl::OUString aContent;
465 String aFirstName;
466 String aLastName;
467 String aEmpty;
469 // do we have CurrentPresentation given?
470 // mimic behaviour of writer, which means:
471 // prefer CurrentPresentation over Content
472 // if both are given.
473 if( !mpImpl->msString1.isEmpty() )
474 aContent = mpImpl->msString1;
475 else
476 aContent = mpImpl->msString2;
478 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
479 if( nPos > 0 )
481 aFirstName = aContent.copy( 0, nPos );
482 aLastName = aContent.copy( nPos + 1 );
484 else
486 aLastName = aContent;
489 // #92009# pass fixed attribute to constructor
490 pData = new SvxAuthorField( aFirstName, aLastName, aEmpty,
491 mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR );
493 if( !mpImpl->mbBoolean2 )
495 ((SvxAuthorField*)pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME );
497 else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME )
499 ((SvxAuthorField*)pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 );
502 break;
505 case text::textfield::Type::MEASURE:
507 SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE;
508 if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS )
509 eKind = (SdrMeasureFieldKind) mpImpl->mnInt16;
510 pData = new SdrMeasureField( eKind);
511 break;
513 case text::textfield::Type::PRESENTATION_HEADER:
514 pData = new SvxHeaderField();
515 break;
516 case text::textfield::Type::PRESENTATION_FOOTER:
517 pData = new SvxFooterField();
518 break;
519 case text::textfield::Type::PRESENTATION_DATE_TIME:
520 pData = new SvxDateTimeField();
521 break;
524 return pData;
527 // uno::XInterface
528 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
529 throw(uno::RuntimeException)
531 uno::Any aAny;
533 QUERYINT( beans::XPropertySet );
534 else QUERYINT( text::XTextContent );
535 else QUERYINT( text::XTextField );
536 else QUERYINT( lang::XServiceInfo );
537 else QUERYINT( lang::XUnoTunnel );
538 else
539 return OComponentHelper::queryAggregation( rType );
541 return aAny;
544 // XTypeProvider
546 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
547 throw (uno::RuntimeException)
549 if( maTypeSequence.getLength() == 0 )
551 maTypeSequence = OComponentHelper::getTypes();
552 sal_Int32 nOldCount = maTypeSequence.getLength();
554 maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated
555 uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount];
557 *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextField >*)0);
558 *pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
559 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
560 *pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
562 return maTypeSequence;
565 namespace
567 class theSvxUnoTextFieldImplementationId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldImplementationId > {};
570 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
571 throw (uno::RuntimeException)
573 return theSvxUnoTextFieldImplementationId::get().getSeq();
576 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
577 throw(uno::RuntimeException)
579 return OComponentHelper::queryInterface(rType);
582 void SAL_CALL SvxUnoTextField::acquire() throw( )
584 OComponentHelper::acquire();
587 void SAL_CALL SvxUnoTextField::release() throw( )
589 OComponentHelper::release();
592 // Interface text::XTextField
593 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
594 throw(uno::RuntimeException)
596 SolarMutexGuard aGuard;
597 if (bShowCommand)
599 switch (mnServiceId)
601 case text::textfield::Type::DATE:
602 return OUString("Date");
603 case text::textfield::Type::URL:
604 return OUString("URL");
605 case text::textfield::Type::PAGE:
606 return OUString("Page");
607 case text::textfield::Type::PAGES:
608 return OUString("Pages");
609 case text::textfield::Type::TIME:
610 return OUString("Time");
611 case text::textfield::Type::DOCINFO_TITLE:
612 return OUString("File");
613 case text::textfield::Type::TABLE:
614 return OUString("Table");
615 case text::textfield::Type::EXTENDED_TIME:
616 return OUString("ExtTime");
617 case text::textfield::Type::EXTENDED_FILE:
618 return OUString("ExtFile");
619 case text::textfield::Type::AUTHOR:
620 return OUString("Author");
621 case text::textfield::Type::MEASURE:
622 return OUString("Measure");
623 case text::textfield::Type::PRESENTATION_HEADER:
624 return OUString("Header");
625 case text::textfield::Type::PRESENTATION_FOOTER:
626 return OUString("Footer");
627 case text::textfield::Type::PRESENTATION_DATE_TIME:
628 return OUString("DateTime");
629 default:
630 return OUString("Unknown");
633 else
635 return mpImpl->msPresentation;
639 // Interface text::XTextContent
640 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
641 throw(lang::IllegalArgumentException, uno::RuntimeException)
643 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange );
644 if(pRange == NULL)
645 throw lang::IllegalArgumentException();
647 SvxFieldData* pData = CreateFieldData();
648 if( pData )
649 pRange->attachField( pData );
651 delete pData;
654 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
655 throw(uno::RuntimeException)
657 return mxAnchor;
660 // lang::XComponent
661 void SAL_CALL SvxUnoTextField::dispose()
662 throw(uno::RuntimeException)
664 OComponentHelper::dispose();
667 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
668 throw(uno::RuntimeException)
670 OComponentHelper::addEventListener(xListener);
673 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
674 throw(uno::RuntimeException)
676 OComponentHelper::removeEventListener(aListener);
680 // Interface beans::XPropertySet
681 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
682 throw(uno::RuntimeException)
684 SolarMutexGuard aGuard;
685 return mpPropSet->getPropertySetInfo();
688 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
689 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
691 SolarMutexGuard aGuard;
693 if( mpImpl == NULL )
694 throw uno::RuntimeException();
696 if (aPropertyName == UNO_TC_PROP_ANCHOR)
698 aValue >>= mxAnchor;
699 return;
702 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
703 if ( !pMap )
704 throw beans::UnknownPropertyException();
706 switch( pMap->nWID )
708 case WID_DATE:
709 if(aValue >>= mpImpl->maDateTime)
710 return;
711 break;
712 case WID_BOOL1:
713 if(aValue >>= mpImpl->mbBoolean1)
714 return;
715 break;
716 case WID_BOOL2:
717 if(aValue >>= mpImpl->mbBoolean2)
718 return;
719 break;
720 case WID_INT16:
721 if(aValue >>= mpImpl->mnInt16)
722 return;
723 break;
724 case WID_INT32:
725 if(aValue >>= mpImpl->mnInt32)
726 return;
727 break;
728 case WID_STRING1:
729 if(aValue >>= mpImpl->msString1)
730 return;
731 break;
732 case WID_STRING2:
733 if(aValue >>= mpImpl->msString2)
734 return;
735 break;
736 case WID_STRING3:
737 if(aValue >>= mpImpl->msString3)
738 return;
739 break;
742 throw lang::IllegalArgumentException();
745 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
746 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
748 SolarMutexGuard aGuard;
750 if (PropertyName == UNO_TC_PROP_ANCHOR)
751 return uno::makeAny(mxAnchor);
753 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
754 return uno::makeAny(mnServiceId);
756 uno::Any aValue;
758 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
759 if ( !pMap )
760 throw beans::UnknownPropertyException();
762 switch( pMap->nWID )
764 case WID_DATE:
765 aValue <<= mpImpl->maDateTime;
766 break;
767 case WID_BOOL1:
768 aValue <<= mpImpl->mbBoolean1;
769 break;
770 case WID_BOOL2:
771 aValue <<= mpImpl->mbBoolean2;
772 break;
773 case WID_INT16:
774 aValue <<= mpImpl->mnInt16;
775 break;
776 case WID_INT32:
777 aValue <<= mpImpl->mnInt32;
778 break;
779 case WID_STRING1:
780 aValue <<= mpImpl->msString1;
781 break;
782 case WID_STRING2:
783 aValue <<= mpImpl->msString2;
784 break;
785 case WID_STRING3:
786 aValue <<= mpImpl->msString3;
787 break;
790 return aValue;
793 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
794 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
795 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
796 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
798 // OComponentHelper
799 void SvxUnoTextField::disposing()
801 // nothing to do
804 // lang::XServiceInfo
805 OUString SAL_CALL SvxUnoTextField::getImplementationName() throw(uno::RuntimeException)
807 return OUString("SvxUnoTextField");
810 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
811 throw(uno::RuntimeException)
813 uno::Sequence<OUString> aSeq(4);
814 OUString* pServices = aSeq.getArray();
815 pServices[0] = "com.sun.star.text.TextContent";
816 pServices[1] = "com.sun.star.text.TextField";
818 switch (mnServiceId)
820 case text::textfield::Type::DATE:
821 pServices[2] = "com.sun.star.text.TextField.DateTime";
822 pServices[3] = "com.sun.star.text.textfield.DateTime";
823 break;
824 case text::textfield::Type::URL:
825 pServices[2] = "com.sun.star.text.TextField.URL";
826 pServices[3] = "com.sun.star.text.textfield.URL";
827 break;
828 case text::textfield::Type::PAGE:
829 pServices[2] = "com.sun.star.text.TextField.PageNumber";
830 pServices[3] = "com.sun.star.text.textfield.PageNumber";
831 break;
832 case text::textfield::Type::PAGES:
833 pServices[2] = "com.sun.star.text.TextField.PageCount";
834 pServices[3] = "com.sun.star.text.textfield.PageCount";
835 break;
836 case text::textfield::Type::TIME:
837 pServices[2] = "com.sun.star.text.TextField.DateTime";
838 pServices[3] = "com.sun.star.text.textfield.DateTime";
839 break;
840 case text::textfield::Type::DOCINFO_TITLE:
841 pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
842 pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
843 break;
844 case text::textfield::Type::TABLE:
845 pServices[2] = "com.sun.star.text.TextField.SheetName";
846 pServices[3] = "com.sun.star.text.textfield.SheetName";
847 break;
848 case text::textfield::Type::EXTENDED_TIME:
849 pServices[2] = "com.sun.star.text.TextField.DateTime";
850 pServices[3] = "com.sun.star.text.textfield.DateTime";
851 break;
852 case text::textfield::Type::EXTENDED_FILE:
853 pServices[2] = "com.sun.star.text.TextField.FileName";
854 pServices[3] = "com.sun.star.text.textfield.FileName";
855 break;
856 case text::textfield::Type::AUTHOR:
857 pServices[2] = "com.sun.star.text.TextField.Author";
858 pServices[3] = "com.sun.star.text.textfield.Author";
859 break;
860 case text::textfield::Type::MEASURE:
861 pServices[2] = "com.sun.star.text.TextField.Measure";
862 pServices[3] = "com.sun.star.text.textfield.Measure";
863 break;
864 case text::textfield::Type::PRESENTATION_HEADER:
865 pServices[2] = "com.sun.star.presentation.TextField.Header";
866 pServices[3] = "com.sun.star.presentation.textfield.Header";
867 break;
868 case text::textfield::Type::PRESENTATION_FOOTER:
869 pServices[2] = "com.sun.star.presentation.TextField.Footer";
870 pServices[3] = "com.sun.star.presentation.textfield.Footer";
871 break;
872 case text::textfield::Type::PRESENTATION_DATE_TIME:
873 pServices[2] = "com.sun.star.presentation.TextField.DateTime";
874 pServices[3] = "com.sun.star.presentation.textfield.DateTime";
875 break;
876 default:
877 aSeq.realloc(0);
880 return aSeq;
883 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
885 return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
888 uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rtl::OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
890 uno::Reference< uno::XInterface > xRet;
892 const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
894 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
895 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
896 const OUString aTextFieldPrexit2( "com.sun.star.text.TextField." );
898 if( (ServiceSpecifier.compareTo( aTextFieldPrexit, aTextFieldPrexit.getLength() ) == 0) ||
899 (ServiceSpecifier.compareTo( aTextFieldPrexit2, aTextFieldPrexit2.getLength() ) == 0) )
901 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
903 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
905 if ( aFieldType == "DateTime" )
907 nId = text::textfield::Type::DATE;
909 else if ( aFieldType == "URL" )
911 nId = text::textfield::Type::URL;
913 else if ( aFieldType == "PageNumber" )
915 nId = text::textfield::Type::PAGE;
917 else if ( aFieldType == "PageCount" )
919 nId = text::textfield::Type::PAGES;
921 else if ( aFieldType == "SheetName" )
923 nId = text::textfield::Type::TABLE;
925 else if ( aFieldType == "FileName" )
927 nId = text::textfield::Type::EXTENDED_FILE;
929 else if (aFieldType.equalsAsciiL(
930 RTL_CONSTASCII_STRINGPARAM("docinfo.Title") ) ||
931 aFieldType.equalsAsciiL(
932 RTL_CONSTASCII_STRINGPARAM("DocInfo.Title") ) )
934 nId = text::textfield::Type::DOCINFO_TITLE;
936 else if ( aFieldType == "Author" )
938 nId = text::textfield::Type::AUTHOR;
940 else if ( aFieldType == "Measure" )
942 nId = text::textfield::Type::MEASURE;
945 if (nId != text::textfield::Type::UNSPECIFIED)
946 xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId );
949 return xRet;
952 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */