bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / uno / unofield.cxx
blobd5df68a302d286e1af85d3ce0cf5016b330114db
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/util/DateTime.hpp>
21 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
22 #include <com/sun/star/lang/NoSupportException.hpp>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <vcl/svapp.hxx>
25 #include <osl/mutex.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/flditem.hxx>
29 #include <editeng/measfld.hxx>
30 #include <editeng/unofield.hxx>
31 #include <editeng/unotext.hxx>
32 #include <comphelper/servicehelper.hxx>
33 #include <cppuhelper/supportsservice.hxx>
35 #include "editeng/unonames.hxx"
37 using namespace ::cppu;
38 using namespace ::com::sun::star;
40 #define QUERYINT( xint ) \
41 if( rType == cppu::UnoType<xint>::get() ) \
42 aAny <<= uno::Reference< xint >(this)
45 #define WID_DATE 0
46 #define WID_BOOL1 1
47 #define WID_BOOL2 2
48 #define WID_INT32 3
49 #define WID_INT16 4
50 #define WID_STRING1 5
51 #define WID_STRING2 6
52 #define WID_STRING3 7
54 class SvxUnoFieldData_Impl
56 public:
57 bool mbBoolean1;
58 bool mbBoolean2;
59 sal_Int32 mnInt32;
60 sal_Int16 mnInt16;
61 OUString msString1;
62 OUString msString2;
63 OUString msString3;
64 util::DateTime maDateTime;
66 OUString msPresentation;
69 const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
71 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
73 { OUString(UNO_TC_PROP_DATE_TIME), WID_DATE, ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
74 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
75 { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
76 { OUString(UNO_TC_PROP_NUMFORMAT), WID_INT32, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
77 { OUString(), 0, css::uno::Type(), 0, 0 }
79 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
81 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
83 { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
84 { OUString(), 0, css::uno::Type(), 0, 0 }
86 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
88 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
91 { OUString(UNO_TC_PROP_URL_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
92 { OUString(UNO_TC_PROP_URL_REPRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
93 { OUString(UNO_TC_PROP_URL_TARGET), WID_STRING2, ::cppu::UnoType<OUString>::get(), 0, 0 },
94 { OUString(UNO_TC_PROP_URL), WID_STRING3, ::cppu::UnoType<OUString>::get(), 0, 0 },
95 { OUString(), 0, css::uno::Type(), 0, 0 }
97 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
99 static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
101 { OUString(), 0, css::uno::Type(), 0, 0 }
103 static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
105 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
107 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
108 { OUString(UNO_TC_PROP_FILE_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
109 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
110 { OUString(), 0, css::uno::Type(), 0, 0 }
112 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
114 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
116 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
117 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1,::cppu::UnoType<OUString>::get(), 0, 0 },
118 { OUString(UNO_TC_PROP_AUTHOR_CONTENT), WID_STRING2,::cppu::UnoType<OUString>::get(), 0, 0 },
119 { OUString(UNO_TC_PROP_AUTHOR_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
120 { OUString(UNO_TC_PROP_AUTHOR_FULLNAME), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
121 { OUString(), 0, css::uno::Type(), 0, 0 }
123 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
125 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
127 { OUString(UNO_TC_PROP_MEASURE_KIND), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
128 { OUString(), 0, css::uno::Type(), 0, 0 }
130 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
132 switch( mnId )
134 case text::textfield::Type::EXTENDED_TIME:
135 case text::textfield::Type::DATE:
136 return &aExDateTimeFieldPropertySet_Impl;
137 case text::textfield::Type::URL:
138 return &aUrlFieldPropertySet_Impl;
139 case text::textfield::Type::TIME:
140 return &aDateTimeFieldPropertySet_Impl;
141 case text::textfield::Type::EXTENDED_FILE:
142 return &aExtFileFieldPropertySet_Impl;
143 case text::textfield::Type::AUTHOR:
144 return &aAuthorFieldPropertySet_Impl;
145 case text::textfield::Type::MEASURE:
146 return &aMeasureFieldPropertySet_Impl;
147 default:
148 return &aEmptyPropertySet_Impl;
152 /* conversion routines */
154 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
156 switch( nFormat )
158 case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT;
159 case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL;
160 case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH;
161 // case SVXFILEFORMAT_NAME:
162 default: return text::FilenameDisplayFormat::NAME;
166 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
168 switch( nFormat )
170 case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH;
171 case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH;
172 case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME;
173 // case text::FilenameDisplayFormat::NAME_AND_EXT:
174 default:
175 return SVXFILEFORMAT_NAME_EXT;
179 static util::DateTime getDate( sal_uLong nDate )
181 util::DateTime aDate;
182 memset( &aDate, 0, sizeof( util::DateTime ) );
184 Date aTempDate( nDate );
186 aDate.Day = aTempDate.GetDay();
187 aDate.Month = aTempDate.GetMonth();
188 aDate.Year = aTempDate.GetYear();
190 return aDate;
193 inline Date setDate( util::DateTime& rDate )
195 return Date( rDate.Day, rDate.Month, rDate.Year );
198 static util::DateTime getTime(sal_Int64 const nTime)
200 util::DateTime aTime;
201 memset( &aTime, 0, sizeof( util::DateTime ) );
203 tools::Time aTempTime( nTime );
205 aTime.NanoSeconds = aTempTime.GetNanoSec();
206 aTime.Seconds = aTempTime.GetSec();
207 aTime.Minutes = aTempTime.GetMin();
208 aTime.Hours = aTempTime.GetHour();
210 return aTime;
213 inline tools::Time setTime( util::DateTime& rDate )
215 return tools::Time( rDate );
219 // class SvxUnoTextField
221 namespace
223 class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
226 const ::com::sun::star::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
228 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
231 sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException, std::exception)
233 if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
234 rId.getConstArray(), 16 ) )
236 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
238 return 0;
241 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
242 : OComponentHelper( getMutex() )
243 , mpPropSet(NULL)
244 , mnServiceId(nServiceId)
245 , mpImpl( new SvxUnoFieldData_Impl )
247 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
249 memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
251 switch( nServiceId )
253 case text::textfield::Type::DATE:
254 mpImpl->mbBoolean2 = true;
255 mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
256 mpImpl->mbBoolean1 = false;
257 break;
259 case text::textfield::Type::EXTENDED_TIME:
260 case text::textfield::Type::TIME:
261 mpImpl->mbBoolean2 = false;
262 mpImpl->mbBoolean1 = false;
263 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
264 break;
266 case text::textfield::Type::URL:
267 mpImpl->mnInt16 = SVXURLFORMAT_REPR;
268 break;
270 case text::textfield::Type::EXTENDED_FILE:
271 mpImpl->mbBoolean1 = false;
272 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
273 break;
275 case text::textfield::Type::AUTHOR:
276 mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
277 mpImpl->mbBoolean1 = false;
278 mpImpl->mbBoolean2 = true;
279 break;
281 case text::textfield::Type::MEASURE:
282 mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
283 break;
285 default:
286 mpImpl->mbBoolean1 = false;
287 mpImpl->mbBoolean2 = false;
288 mpImpl->mnInt32 = 0;
289 mpImpl->mnInt16 = 0;
294 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
295 : OComponentHelper( getMutex() )
296 , mxAnchor( xAnchor )
297 , mpPropSet(NULL)
298 , mnServiceId(text::textfield::Type::UNSPECIFIED)
299 , mpImpl( new SvxUnoFieldData_Impl )
301 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
303 mpImpl->msPresentation = rPresentation;
305 if(pData)
307 mnServiceId = pData->GetClassId();
308 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
309 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
311 // extract field properties from data class
312 switch( mnServiceId )
314 case text::textfield::Type::DATE:
316 mpImpl->mbBoolean2 = true;
317 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
318 // use current date instead
319 bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SVXDATETYPE_FIX;
320 mpImpl->maDateTime = getDate( bFixed ?
321 static_cast<const SvxDateField*>(pData)->GetFixDate() :
322 Date( Date::SYSTEM ).GetDate() );
323 mpImpl->mnInt32 = static_cast<const SvxDateField*>(pData)->GetFormat();
324 mpImpl->mbBoolean1 = bFixed;
326 break;
328 case text::textfield::Type::TIME:
329 mpImpl->mbBoolean2 = false;
330 mpImpl->mbBoolean1 = false;
331 mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
332 break;
334 case text::textfield::Type::EXTENDED_TIME:
335 mpImpl->mbBoolean2 = false;
336 mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
337 mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SVXTIMETYPE_FIX;
338 mpImpl->mnInt32 = static_cast<const SvxExtTimeField*>(pData)->GetFormat();
339 break;
341 case text::textfield::Type::URL:
342 mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
343 mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
344 mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
345 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
346 static_cast<const SvxURLField*>(pData)->GetFormat());
347 break;
349 case text::textfield::Type::EXTENDED_FILE:
350 mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
351 mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SVXFILETYPE_FIX;
352 mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
353 break;
355 case text::textfield::Type::AUTHOR:
356 mpImpl->msString1 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
357 mpImpl->msString2 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
358 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
359 static_cast<const SvxAuthorField*>(pData)->GetFormat());
360 mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SVXAUTHORTYPE_FIX;
361 mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME;
362 break;
364 case text::textfield::Type::MEASURE:
365 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
366 break;
368 default:
369 SAL_WARN("editeng.uno", "Id service unknown: " << mnServiceId);
370 break;
375 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
378 SvxUnoTextField::~SvxUnoTextField() throw()
380 delete mpImpl;
383 SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
385 SvxFieldData* pData = NULL;
387 switch( mnServiceId )
389 case text::textfield::Type::TIME:
390 case text::textfield::Type::EXTENDED_TIME:
391 case text::textfield::Type::DATE:
393 if( mpImpl->mbBoolean2 ) // IsDate?
395 Date aDate( setDate( mpImpl->maDateTime ) );
396 pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
397 if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F )
398 static_cast<SvxDateField*>(pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 );
400 else
402 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
404 tools::Time aTime( setTime( mpImpl->maDateTime ) );
405 pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
407 if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH )
408 static_cast<SvxExtTimeField*>(pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 );
410 else
412 pData = new SvxTimeField();
417 break;
419 case text::textfield::Type::URL:
420 pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL );
421 static_cast<SvxURLField*>(pData)->SetTargetFrame( mpImpl->msString2 );
422 if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR )
423 static_cast<SvxURLField*>(pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 );
424 break;
426 case text::textfield::Type::PAGE:
427 pData = new SvxPageField();
428 break;
430 case text::textfield::Type::PAGES:
431 pData = new SvxPagesField();
432 break;
434 case text::textfield::Type::DOCINFO_TITLE:
435 pData = new SvxFileField();
436 break;
438 case text::textfield::Type::TABLE:
439 pData = new SvxTableField();
440 break;
442 case text::textfield::Type::EXTENDED_FILE:
444 // #92009# pass fixed attribute to constructor
445 pData = new SvxExtFileField( mpImpl->msString1,
446 mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR,
447 setFileNameDisplayFormat(mpImpl->mnInt16 ) );
448 break;
451 case text::textfield::Type::AUTHOR:
453 OUString aContent;
454 OUString aFirstName;
455 OUString aLastName;
456 OUString aEmpty;
458 // do we have CurrentPresentation given?
459 // mimic behaviour of writer, which means:
460 // prefer CurrentPresentation over Content
461 // if both are given.
462 if( !mpImpl->msString1.isEmpty() )
463 aContent = mpImpl->msString1;
464 else
465 aContent = mpImpl->msString2;
467 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
468 if( nPos > 0 )
470 aFirstName = aContent.copy( 0, nPos );
471 aLastName = aContent.copy( nPos + 1 );
473 else
475 aLastName = aContent;
478 // #92009# pass fixed attribute to constructor
479 pData = new SvxAuthorField( aFirstName, aLastName, aEmpty,
480 mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR );
482 if( !mpImpl->mbBoolean2 )
484 static_cast<SvxAuthorField*>(pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME );
486 else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME )
488 static_cast<SvxAuthorField*>(pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 );
491 break;
494 case text::textfield::Type::MEASURE:
496 SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE;
497 if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS )
498 eKind = (SdrMeasureFieldKind) mpImpl->mnInt16;
499 pData = new SdrMeasureField( eKind);
500 break;
502 case text::textfield::Type::PRESENTATION_HEADER:
503 pData = new SvxHeaderField();
504 break;
505 case text::textfield::Type::PRESENTATION_FOOTER:
506 pData = new SvxFooterField();
507 break;
508 case text::textfield::Type::PRESENTATION_DATE_TIME:
509 pData = new SvxDateTimeField();
510 break;
511 case text::textfield::Type::PAGE_NAME:
512 pData = new SvxPageTitleField();
513 break;
516 return pData;
519 // uno::XInterface
520 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
521 throw(uno::RuntimeException, std::exception)
523 uno::Any aAny;
525 QUERYINT( beans::XPropertySet );
526 else QUERYINT( text::XTextContent );
527 else QUERYINT( text::XTextField );
528 else QUERYINT( lang::XServiceInfo );
529 else QUERYINT( lang::XUnoTunnel );
530 else
531 return OComponentHelper::queryAggregation( rType );
533 return aAny;
536 // XTypeProvider
538 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
539 throw (uno::RuntimeException, std::exception)
541 if( maTypeSequence.getLength() == 0 )
543 maTypeSequence = OComponentHelper::getTypes();
544 sal_Int32 nOldCount = maTypeSequence.getLength();
546 maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated
547 uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount];
549 *pTypes++ = cppu::UnoType<text::XTextField>::get();
550 *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
551 *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
552 *pTypes++ = cppu::UnoType<lang::XUnoTunnel>::get();
554 return maTypeSequence;
557 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
558 throw (uno::RuntimeException, std::exception)
560 return css::uno::Sequence<sal_Int8>();
563 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
564 throw(uno::RuntimeException, std::exception)
566 return OComponentHelper::queryInterface(rType);
569 void SAL_CALL SvxUnoTextField::acquire() throw( )
571 OComponentHelper::acquire();
574 void SAL_CALL SvxUnoTextField::release() throw( )
576 OComponentHelper::release();
579 // Interface text::XTextField
580 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
581 throw(uno::RuntimeException, std::exception)
583 SolarMutexGuard aGuard;
584 if (bShowCommand)
586 switch (mnServiceId)
588 case text::textfield::Type::DATE:
589 return OUString("Date");
590 case text::textfield::Type::URL:
591 return OUString("URL");
592 case text::textfield::Type::PAGE:
593 return OUString("Page");
594 case text::textfield::Type::PAGES:
595 return OUString("Pages");
596 case text::textfield::Type::TIME:
597 return OUString("Time");
598 case text::textfield::Type::DOCINFO_TITLE:
599 return OUString("File");
600 case text::textfield::Type::TABLE:
601 return OUString("Table");
602 case text::textfield::Type::EXTENDED_TIME:
603 return OUString("ExtTime");
604 case text::textfield::Type::EXTENDED_FILE:
605 return OUString("ExtFile");
606 case text::textfield::Type::AUTHOR:
607 return OUString("Author");
608 case text::textfield::Type::MEASURE:
609 return OUString("Measure");
610 case text::textfield::Type::PRESENTATION_HEADER:
611 return OUString("Header");
612 case text::textfield::Type::PRESENTATION_FOOTER:
613 return OUString("Footer");
614 case text::textfield::Type::PRESENTATION_DATE_TIME:
615 return OUString("DateTime");
616 case text::textfield::Type::PAGE_NAME:
617 return OUString("PageName");
618 default:
619 return OUString("Unknown");
622 else
624 return mpImpl->msPresentation;
628 // Interface text::XTextContent
629 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
630 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
632 SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange );
633 if(pRange == NULL)
634 throw lang::IllegalArgumentException();
636 SvxFieldData* pData = CreateFieldData();
637 if( pData )
638 pRange->attachField( pData );
640 delete pData;
643 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
644 throw(uno::RuntimeException, std::exception)
646 return mxAnchor;
649 // lang::XComponent
650 void SAL_CALL SvxUnoTextField::dispose()
651 throw(uno::RuntimeException, std::exception)
653 OComponentHelper::dispose();
656 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
657 throw(uno::RuntimeException, std::exception)
659 OComponentHelper::addEventListener(xListener);
662 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
663 throw(uno::RuntimeException, std::exception)
665 OComponentHelper::removeEventListener(aListener);
669 // Interface beans::XPropertySet
670 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
671 throw(uno::RuntimeException, std::exception)
673 SolarMutexGuard aGuard;
674 return mpPropSet->getPropertySetInfo();
677 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
678 throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
680 SolarMutexGuard aGuard;
682 if( mpImpl == NULL )
683 throw uno::RuntimeException();
685 if (aPropertyName == UNO_TC_PROP_ANCHOR)
687 aValue >>= mxAnchor;
688 return;
691 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
692 if ( !pMap )
693 throw beans::UnknownPropertyException();
695 switch( pMap->nWID )
697 case WID_DATE:
698 if(aValue >>= mpImpl->maDateTime)
699 return;
700 break;
701 case WID_BOOL1:
702 if(aValue >>= mpImpl->mbBoolean1)
703 return;
704 break;
705 case WID_BOOL2:
706 if(aValue >>= mpImpl->mbBoolean2)
707 return;
708 break;
709 case WID_INT16:
710 if(aValue >>= mpImpl->mnInt16)
711 return;
712 break;
713 case WID_INT32:
714 if(aValue >>= mpImpl->mnInt32)
715 return;
716 break;
717 case WID_STRING1:
718 if(aValue >>= mpImpl->msString1)
719 return;
720 break;
721 case WID_STRING2:
722 if(aValue >>= mpImpl->msString2)
723 return;
724 break;
725 case WID_STRING3:
726 if(aValue >>= mpImpl->msString3)
727 return;
728 break;
731 throw lang::IllegalArgumentException();
734 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
735 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
737 SolarMutexGuard aGuard;
739 if (PropertyName == UNO_TC_PROP_ANCHOR)
740 return uno::makeAny(mxAnchor);
742 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
743 return uno::makeAny(mnServiceId);
745 uno::Any aValue;
747 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
748 if ( !pMap )
749 throw beans::UnknownPropertyException();
751 switch( pMap->nWID )
753 case WID_DATE:
754 aValue <<= mpImpl->maDateTime;
755 break;
756 case WID_BOOL1:
757 aValue <<= mpImpl->mbBoolean1;
758 break;
759 case WID_BOOL2:
760 aValue <<= mpImpl->mbBoolean2;
761 break;
762 case WID_INT16:
763 aValue <<= mpImpl->mnInt16;
764 break;
765 case WID_INT32:
766 aValue <<= mpImpl->mnInt32;
767 break;
768 case WID_STRING1:
769 aValue <<= mpImpl->msString1;
770 break;
771 case WID_STRING2:
772 aValue <<= mpImpl->msString2;
773 break;
774 case WID_STRING3:
775 aValue <<= mpImpl->msString3;
776 break;
779 return aValue;
782 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
783 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
784 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
785 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
787 // OComponentHelper
788 void SvxUnoTextField::disposing()
790 // nothing to do
793 // lang::XServiceInfo
794 OUString SAL_CALL SvxUnoTextField::getImplementationName() throw(uno::RuntimeException, std::exception)
796 return OUString("SvxUnoTextField");
799 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
800 throw(uno::RuntimeException, std::exception)
802 uno::Sequence<OUString> aSeq(4);
803 OUString* pServices = aSeq.getArray();
804 pServices[0] = "com.sun.star.text.TextContent";
805 pServices[1] = "com.sun.star.text.TextField";
807 switch (mnServiceId)
809 case text::textfield::Type::DATE:
810 pServices[2] = "com.sun.star.text.TextField.DateTime";
811 pServices[3] = "com.sun.star.text.textfield.DateTime";
812 break;
813 case text::textfield::Type::URL:
814 pServices[2] = "com.sun.star.text.TextField.URL";
815 pServices[3] = "com.sun.star.text.textfield.URL";
816 break;
817 case text::textfield::Type::PAGE:
818 pServices[2] = "com.sun.star.text.TextField.PageNumber";
819 pServices[3] = "com.sun.star.text.textfield.PageNumber";
820 break;
821 case text::textfield::Type::PAGES:
822 pServices[2] = "com.sun.star.text.TextField.PageCount";
823 pServices[3] = "com.sun.star.text.textfield.PageCount";
824 break;
825 case text::textfield::Type::TIME:
826 pServices[2] = "com.sun.star.text.TextField.DateTime";
827 pServices[3] = "com.sun.star.text.textfield.DateTime";
828 break;
829 case text::textfield::Type::DOCINFO_TITLE:
830 pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
831 pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
832 break;
833 case text::textfield::Type::TABLE:
834 pServices[2] = "com.sun.star.text.TextField.SheetName";
835 pServices[3] = "com.sun.star.text.textfield.SheetName";
836 break;
837 case text::textfield::Type::EXTENDED_TIME:
838 pServices[2] = "com.sun.star.text.TextField.DateTime";
839 pServices[3] = "com.sun.star.text.textfield.DateTime";
840 break;
841 case text::textfield::Type::EXTENDED_FILE:
842 pServices[2] = "com.sun.star.text.TextField.FileName";
843 pServices[3] = "com.sun.star.text.textfield.FileName";
844 break;
845 case text::textfield::Type::AUTHOR:
846 pServices[2] = "com.sun.star.text.TextField.Author";
847 pServices[3] = "com.sun.star.text.textfield.Author";
848 break;
849 case text::textfield::Type::MEASURE:
850 pServices[2] = "com.sun.star.text.TextField.Measure";
851 pServices[3] = "com.sun.star.text.textfield.Measure";
852 break;
853 case text::textfield::Type::PRESENTATION_HEADER:
854 pServices[2] = "com.sun.star.presentation.TextField.Header";
855 pServices[3] = "com.sun.star.presentation.textfield.Header";
856 break;
857 case text::textfield::Type::PRESENTATION_FOOTER:
858 pServices[2] = "com.sun.star.presentation.TextField.Footer";
859 pServices[3] = "com.sun.star.presentation.textfield.Footer";
860 break;
861 case text::textfield::Type::PRESENTATION_DATE_TIME:
862 pServices[2] = "com.sun.star.presentation.TextField.DateTime";
863 pServices[3] = "com.sun.star.presentation.textfield.DateTime";
864 break;
865 case text::textfield::Type::PAGE_NAME:
866 pServices[2] = "com.sun.star.text.TextField.PageName";
867 pServices[3] = "com.sun.star.text.textfield.PageName";
868 break;
869 default:
870 aSeq.realloc(0);
873 return aSeq;
876 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
878 return cppu::supportsService( this, ServiceName );
881 uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
883 uno::Reference< uno::XInterface > xRet;
885 const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
887 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
888 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
889 const OUString aTextFieldPrexit2( "com.sun.star.text.TextField." );
891 if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
892 (ServiceSpecifier.startsWith( aTextFieldPrexit2 )) )
894 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
896 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
898 if ( aFieldType == "DateTime" )
900 nId = text::textfield::Type::DATE;
902 else if ( aFieldType == "URL" )
904 nId = text::textfield::Type::URL;
906 else if ( aFieldType == "PageNumber" )
908 nId = text::textfield::Type::PAGE;
910 else if ( aFieldType == "PageCount" )
912 nId = text::textfield::Type::PAGES;
914 else if ( aFieldType == "SheetName" )
916 nId = text::textfield::Type::TABLE;
918 else if ( aFieldType == "FileName" )
920 nId = text::textfield::Type::EXTENDED_FILE;
922 else if (aFieldType == "docinfo.Title" ||
923 aFieldType == "DocInfo.Title" )
925 nId = text::textfield::Type::DOCINFO_TITLE;
927 else if ( aFieldType == "Author" )
929 nId = text::textfield::Type::AUTHOR;
931 else if ( aFieldType == "Measure" )
933 nId = text::textfield::Type::MEASURE;
936 if (nId != text::textfield::Type::UNSPECIFIED)
937 xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId );
940 return xRet;
943 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */