nss: upgrade to release 3.73
[LibreOffice.git] / editeng / source / uno / unofield.cxx
blob9fdc097132da34b9fd6f207ae0dab7d6eaac7f6c
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 <vcl/svapp.hxx>
23 #include <tools/debug.hxx>
24 #include <svl/itemprop.hxx>
26 #include <editeng/flditem.hxx>
27 #include <editeng/CustomPropertyField.hxx>
28 #include <editeng/measfld.hxx>
29 #include <editeng/unofield.hxx>
30 #include <editeng/unotext.hxx>
31 #include <comphelper/sequence.hxx>
32 #include <comphelper/servicehelper.hxx>
33 #include <cppuhelper/supportsservice.hxx>
34 #include <sal/log.hxx>
36 #include <editeng/unonames.hxx>
38 using namespace ::cppu;
39 using namespace ::com::sun::star;
41 #define QUERYINT( xint ) \
42 if( rType == cppu::UnoType<xint>::get() ) \
43 aAny <<= uno::Reference< xint >(this)
46 #define WID_DATE 0
47 #define WID_BOOL1 1
48 #define WID_BOOL2 2
49 #define WID_INT32 3
50 #define WID_INT16 4
51 #define WID_STRING1 5
52 #define WID_STRING2 6
53 #define WID_STRING3 7
55 class SvxUnoFieldData_Impl
57 public:
58 bool mbBoolean1;
59 bool mbBoolean2;
60 sal_Int32 mnInt32;
61 sal_Int16 mnInt16;
62 OUString msString1;
63 OUString msString2;
64 OUString msString3;
65 util::DateTime maDateTime;
67 OUString msPresentation;
70 static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
72 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
74 { u"" UNO_TC_PROP_DATE_TIME, WID_DATE, ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
75 { u"" UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
76 { u"" UNO_TC_PROP_IS_DATE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
77 { u"" UNO_TC_PROP_NUMFORMAT, WID_INT32, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
78 { u"", 0, css::uno::Type(), 0, 0 }
80 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
82 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
84 { u"" UNO_TC_PROP_IS_DATE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
85 { u"", 0, css::uno::Type(), 0, 0 }
87 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
89 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
92 { u"" UNO_TC_PROP_URL_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
93 { u"" UNO_TC_PROP_URL_REPRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
94 { u"" UNO_TC_PROP_URL_TARGET, WID_STRING2, ::cppu::UnoType<OUString>::get(), 0, 0 },
95 { u"" UNO_TC_PROP_URL, WID_STRING3, ::cppu::UnoType<OUString>::get(), 0, 0 },
96 { u"", 0, css::uno::Type(), 0, 0 }
98 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
100 static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
102 { u"", 0, css::uno::Type(), 0, 0 }
104 static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
106 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
108 { u"" UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
109 { u"" UNO_TC_PROP_FILE_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
110 { u"" UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
111 { u"", 0, css::uno::Type(), 0, 0 }
113 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
115 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
117 { u"" UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
118 { u"" UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1,::cppu::UnoType<OUString>::get(), 0, 0 },
119 { u"" UNO_TC_PROP_AUTHOR_CONTENT, WID_STRING2,::cppu::UnoType<OUString>::get(), 0, 0 },
120 { u"" UNO_TC_PROP_AUTHOR_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
121 { u"" UNO_TC_PROP_AUTHOR_FULLNAME, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
122 { u"", 0, css::uno::Type(), 0, 0 }
124 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
126 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
128 { u"" UNO_TC_PROP_MEASURE_KIND, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
129 { u"", 0, css::uno::Type(), 0, 0 }
131 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
133 static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
135 { u"" UNO_TC_PROP_NAME, WID_STRING1, cppu::UnoType<OUString>::get(), 0, 0 },
136 { u"" UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING2, cppu::UnoType<OUString>::get(), 0, 0 },
137 { u"" UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
138 { u"" UNO_TC_PROP_NUMFORMAT, WID_INT32, cppu::UnoType<sal_Int32>::get(), 0, 0 },
139 { u"" UNO_TC_PROP_IS_FIXED_LANGUAGE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
140 { u"", 0, css::uno::Type(), 0, 0 }
142 static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
144 switch( mnId )
146 case text::textfield::Type::EXTENDED_TIME:
147 case text::textfield::Type::DATE:
148 return &aExDateTimeFieldPropertySet_Impl;
149 case text::textfield::Type::URL:
150 return &aUrlFieldPropertySet_Impl;
151 case text::textfield::Type::TIME:
152 return &aDateTimeFieldPropertySet_Impl;
153 case text::textfield::Type::EXTENDED_FILE:
154 return &aExtFileFieldPropertySet_Impl;
155 case text::textfield::Type::AUTHOR:
156 return &aAuthorFieldPropertySet_Impl;
157 case text::textfield::Type::MEASURE:
158 return &aMeasureFieldPropertySet_Impl;
159 case text::textfield::Type::DOCINFO_CUSTOM:
160 return &aDocInfoCustomFieldPropertySet_Impl;
161 default:
162 return &aEmptyPropertySet_Impl;
166 /* conversion routines */
168 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
170 switch( nFormat )
172 case SvxFileFormat::NameAndExt: return text::FilenameDisplayFormat::NAME_AND_EXT;
173 case SvxFileFormat::PathFull: return text::FilenameDisplayFormat::FULL;
174 case SvxFileFormat::PathOnly: return text::FilenameDisplayFormat::PATH;
175 // case SvxFileFormat::NameOnly:
176 default: return text::FilenameDisplayFormat::NAME;
180 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
182 switch( nFormat )
184 case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull;
185 case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly;
186 case text::FilenameDisplayFormat::NAME: return SvxFileFormat::NameOnly;
187 // case text::FilenameDisplayFormat::NAME_AND_EXT:
188 default:
189 return SvxFileFormat::NameAndExt;
193 static util::DateTime getDate( sal_Int32 nDate )
195 util::DateTime aDate;
197 Date aTempDate( nDate );
199 aDate.Day = aTempDate.GetDay();
200 aDate.Month = aTempDate.GetMonth();
201 aDate.Year = aTempDate.GetYear();
203 return aDate;
206 static Date setDate( util::DateTime const & rDate )
208 return Date( rDate.Day, rDate.Month, rDate.Year );
211 static util::DateTime getTime(sal_Int64 const nTime)
213 util::DateTime aTime;
215 tools::Time aTempTime( nTime );
217 aTime.NanoSeconds = aTempTime.GetNanoSec();
218 aTime.Seconds = aTempTime.GetSec();
219 aTime.Minutes = aTempTime.GetMin();
220 aTime.Hours = aTempTime.GetHour();
222 return aTime;
225 static tools::Time setTime( util::DateTime const & rDate )
227 return tools::Time( rDate );
232 namespace
234 class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
237 const css::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
239 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
242 sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
244 if( isUnoTunnelId<SvxUnoTextField>(rId) )
246 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
248 return 0;
251 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
252 : OComponentHelper( getMutex() )
253 , mpPropSet(nullptr)
254 , mnServiceId(nServiceId)
255 , mpImpl( new SvxUnoFieldData_Impl )
257 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
259 mpImpl->maDateTime.NanoSeconds = 0;
260 mpImpl->maDateTime.Seconds = 0;
261 mpImpl->maDateTime.Minutes = 0;
262 mpImpl->maDateTime.Hours = 0;
263 mpImpl->maDateTime.Day = 0;
264 mpImpl->maDateTime.Month = 0;
265 mpImpl->maDateTime.Year = 0;
266 mpImpl->maDateTime.IsUTC = false;
268 switch( nServiceId )
270 case text::textfield::Type::DATE:
271 mpImpl->mbBoolean2 = true;
272 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxDateFormat::StdSmall);
273 mpImpl->mbBoolean1 = false;
274 break;
276 case text::textfield::Type::EXTENDED_TIME:
277 case text::textfield::Type::TIME:
278 mpImpl->mbBoolean2 = false;
279 mpImpl->mbBoolean1 = false;
280 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
281 break;
283 case text::textfield::Type::URL:
284 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
285 break;
287 case text::textfield::Type::EXTENDED_FILE:
288 mpImpl->mbBoolean1 = false;
289 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
290 break;
292 case text::textfield::Type::AUTHOR:
293 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxAuthorFormat::FullName);
294 mpImpl->mbBoolean1 = false;
295 mpImpl->mbBoolean2 = true;
296 break;
298 case text::textfield::Type::MEASURE:
299 mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
300 break;
302 case text::textfield::Type::DOCINFO_CUSTOM:
303 mpImpl->mbBoolean1 = true;
304 mpImpl->mbBoolean2 = true;
305 mpImpl->mnInt32 = 0;
306 break;
308 default:
309 mpImpl->mbBoolean1 = false;
310 mpImpl->mbBoolean2 = false;
311 mpImpl->mnInt32 = 0;
312 mpImpl->mnInt16 = 0;
317 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > const & xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
318 : OComponentHelper( getMutex() )
319 , mxAnchor( xAnchor )
320 , mpPropSet(nullptr)
321 , mnServiceId(text::textfield::Type::UNSPECIFIED)
322 , mpImpl( new SvxUnoFieldData_Impl )
324 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
326 mpImpl->msPresentation = rPresentation;
328 if(pData)
330 mnServiceId = pData->GetClassId();
331 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
332 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
334 // extract field properties from data class
335 switch( mnServiceId )
337 case text::textfield::Type::DATE:
339 mpImpl->mbBoolean2 = true;
340 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
341 // use current date instead
342 bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SvxDateType::Fix;
343 mpImpl->maDateTime = getDate( bFixed ?
344 static_cast<const SvxDateField*>(pData)->GetFixDate() :
345 Date( Date::SYSTEM ).GetDate() );
346 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxDateField*>(pData)->GetFormat());
347 mpImpl->mbBoolean1 = bFixed;
349 break;
351 case text::textfield::Type::TIME:
352 mpImpl->mbBoolean2 = false;
353 mpImpl->mbBoolean1 = false;
354 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
355 break;
357 case text::textfield::Type::EXTENDED_TIME:
358 mpImpl->mbBoolean2 = false;
359 mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
360 mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SvxTimeType::Fix;
361 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxExtTimeField*>(pData)->GetFormat());
362 break;
364 case text::textfield::Type::URL:
365 mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
366 mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
367 mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
368 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
369 static_cast<const SvxURLField*>(pData)->GetFormat());
370 break;
372 case text::textfield::Type::EXTENDED_FILE:
373 mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
374 mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SvxFileType::Fix;
375 mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
376 break;
378 case text::textfield::Type::AUTHOR:
379 mpImpl->msString1 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
380 mpImpl->msString2 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
381 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
382 static_cast<const SvxAuthorField*>(pData)->GetFormat());
383 mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SvxAuthorType::Fix;
384 mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SvxAuthorFormat::ShortName;
385 break;
387 case text::textfield::Type::MEASURE:
388 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
389 break;
391 case text::textfield::Type::DOCINFO_CUSTOM:
392 mpImpl->msString1 = static_cast<const editeng::CustomPropertyField*>(pData)->GetName();
393 mpImpl->msString2 = static_cast<const editeng::CustomPropertyField*>(pData)->GetCurrentPresentation();
394 mpImpl->mbBoolean1 = false;
395 mpImpl->mbBoolean2 = false;
396 mpImpl->mnInt32 = 0;
397 break;
399 default:
400 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
401 break;
406 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
409 SvxUnoTextField::~SvxUnoTextField() throw()
413 std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const throw()
415 std::unique_ptr<SvxFieldData> pData;
417 switch( mnServiceId )
419 case text::textfield::Type::TIME:
420 case text::textfield::Type::EXTENDED_TIME:
421 case text::textfield::Type::DATE:
423 if( mpImpl->mbBoolean2 ) // IsDate?
425 Date aDate( setDate( mpImpl->maDateTime ) );
426 pData.reset( new SvxDateField( aDate, mpImpl->mbBoolean1?SvxDateType::Fix:SvxDateType::Var ) );
427 if( mpImpl->mnInt32 >= static_cast<sal_Int32>(SvxDateFormat::AppDefault) &&
428 mpImpl->mnInt32 <= static_cast<sal_Int32>(SvxDateFormat::F) )
429 static_cast<SvxDateField*>(pData.get())->SetFormat( static_cast<SvxDateFormat>(mpImpl->mnInt32) );
431 else
433 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
435 tools::Time aTime( setTime( mpImpl->maDateTime ) );
436 pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
438 if( static_cast<SvxTimeFormat>(mpImpl->mnInt32) >= SvxTimeFormat::AppDefault &&
439 static_cast<SvxTimeFormat>(mpImpl->mnInt32) <= SvxTimeFormat::HH12_MM_SS_00_AMPM )
440 static_cast<SvxExtTimeField*>(pData.get())->SetFormat( static_cast<SvxTimeFormat>(mpImpl->mnInt32) );
442 else
444 pData.reset( new SvxTimeField() );
449 break;
451 case text::textfield::Type::URL:
452 pData.reset( new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SvxURLFormat::Repr : SvxURLFormat::Url ) );
453 static_cast<SvxURLField*>(pData.get())->SetTargetFrame( mpImpl->msString2 );
454 if( static_cast<SvxURLFormat>(mpImpl->mnInt16) >= SvxURLFormat::AppDefault &&
455 static_cast<SvxURLFormat>(mpImpl->mnInt16) <= SvxURLFormat::Repr )
456 static_cast<SvxURLField*>(pData.get())->SetFormat( static_cast<SvxURLFormat>(mpImpl->mnInt16) );
457 break;
459 case text::textfield::Type::PAGE:
460 pData.reset( new SvxPageField() );
461 break;
463 case text::textfield::Type::PAGES:
464 pData.reset( new SvxPagesField() );
465 break;
467 case text::textfield::Type::DOCINFO_TITLE:
468 pData.reset( new SvxFileField() );
469 break;
471 case text::textfield::Type::TABLE:
472 pData.reset( new SvxTableField() );
473 break;
475 case text::textfield::Type::EXTENDED_FILE:
477 // #92009# pass fixed attribute to constructor
478 pData.reset( new SvxExtFileField( mpImpl->msString1,
479 mpImpl->mbBoolean1 ? SvxFileType::Fix : SvxFileType::Var,
480 setFileNameDisplayFormat(mpImpl->mnInt16 ) ) );
481 break;
484 case text::textfield::Type::AUTHOR:
486 OUString aContent;
487 OUString aFirstName;
488 OUString aLastName;
490 // do we have CurrentPresentation given?
491 // mimic behaviour of writer, which means:
492 // prefer CurrentPresentation over Content
493 // if both are given.
494 if( !mpImpl->msString1.isEmpty() )
495 aContent = mpImpl->msString1;
496 else
497 aContent = mpImpl->msString2;
499 sal_Int32 nPos = aContent.lastIndexOf( ' ', 0 );
500 if( nPos > 0 )
502 aFirstName = aContent.copy( 0, nPos );
503 aLastName = aContent.copy( nPos + 1 );
505 else
507 aLastName = aContent;
510 // #92009# pass fixed attribute to constructor
511 pData.reset( new SvxAuthorField( aFirstName, aLastName, "",
512 mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
514 if( !mpImpl->mbBoolean2 )
516 static_cast<SvxAuthorField*>(pData.get())->SetFormat( SvxAuthorFormat::ShortName );
518 else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
519 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
521 static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
524 break;
527 case text::textfield::Type::MEASURE:
529 SdrMeasureFieldKind eKind = SdrMeasureFieldKind::Value;
530 if( mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Unit) || mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Rotate90Blanks) )
531 eKind = static_cast<SdrMeasureFieldKind>(mpImpl->mnInt16);
532 pData.reset( new SdrMeasureField( eKind) );
533 break;
535 case text::textfield::Type::PRESENTATION_HEADER:
536 pData.reset( new SvxHeaderField() );
537 break;
538 case text::textfield::Type::PRESENTATION_FOOTER:
539 pData.reset( new SvxFooterField() );
540 break;
541 case text::textfield::Type::PRESENTATION_DATE_TIME:
542 pData.reset( new SvxDateTimeField() );
543 break;
544 case text::textfield::Type::PAGE_NAME:
545 pData.reset( new SvxPageTitleField() );
546 break;
547 case text::textfield::Type::DOCINFO_CUSTOM:
548 pData.reset( new editeng::CustomPropertyField(mpImpl->msString1, mpImpl->msString2) );
549 break;
552 return pData;
555 // uno::XInterface
556 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
558 uno::Any aAny;
560 QUERYINT( beans::XPropertySet );
561 else QUERYINT( text::XTextContent );
562 else QUERYINT( text::XTextField );
563 else QUERYINT( lang::XServiceInfo );
564 else QUERYINT( lang::XUnoTunnel );
565 else
566 return OComponentHelper::queryAggregation( rType );
568 return aAny;
571 // XTypeProvider
573 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
575 if( !maTypeSequence.hasElements() )
577 maTypeSequence = comphelper::concatSequences(
578 OComponentHelper::getTypes(),
579 uno::Sequence {
580 cppu::UnoType<text::XTextField>::get(),
581 cppu::UnoType<beans::XPropertySet>::get(),
582 cppu::UnoType<lang::XServiceInfo>::get(),
583 cppu::UnoType<lang::XUnoTunnel>::get() });
585 return maTypeSequence;
588 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
590 return css::uno::Sequence<sal_Int8>();
593 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
595 return OComponentHelper::queryInterface(rType);
598 void SAL_CALL SvxUnoTextField::acquire() throw( )
600 OComponentHelper::acquire();
603 void SAL_CALL SvxUnoTextField::release() throw( )
605 OComponentHelper::release();
608 // Interface text::XTextField
609 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
611 SolarMutexGuard aGuard;
612 if (bShowCommand)
614 switch (mnServiceId)
616 case text::textfield::Type::DATE:
617 return "Date";
618 case text::textfield::Type::URL:
619 return "URL";
620 case text::textfield::Type::PAGE:
621 return "Page";
622 case text::textfield::Type::PAGES:
623 return "Pages";
624 case text::textfield::Type::TIME:
625 return "Time";
626 case text::textfield::Type::DOCINFO_TITLE:
627 return "File";
628 case text::textfield::Type::TABLE:
629 return "Table";
630 case text::textfield::Type::EXTENDED_TIME:
631 return "ExtTime";
632 case text::textfield::Type::EXTENDED_FILE:
633 return "ExtFile";
634 case text::textfield::Type::AUTHOR:
635 return "Author";
636 case text::textfield::Type::MEASURE:
637 return "Measure";
638 case text::textfield::Type::PRESENTATION_HEADER:
639 return "Header";
640 case text::textfield::Type::PRESENTATION_FOOTER:
641 return "Footer";
642 case text::textfield::Type::PRESENTATION_DATE_TIME:
643 return "DateTime";
644 case text::textfield::Type::PAGE_NAME:
645 return "PageName";
646 case text::textfield::Type::DOCINFO_CUSTOM:
647 return "Custom";
648 default:
649 return "Unknown";
652 else
654 return mpImpl->msPresentation;
658 // Interface text::XTextContent
659 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
661 SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xTextRange );
662 if(pRange == nullptr)
663 throw lang::IllegalArgumentException();
665 std::unique_ptr<SvxFieldData> pData = CreateFieldData();
666 if( pData )
667 pRange->attachField( std::move(pData) );
670 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
672 return mxAnchor;
675 // lang::XComponent
676 void SAL_CALL SvxUnoTextField::dispose()
678 OComponentHelper::dispose();
681 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
683 OComponentHelper::addEventListener(xListener);
686 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
688 OComponentHelper::removeEventListener(aListener);
692 // Interface beans::XPropertySet
693 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
695 SolarMutexGuard aGuard;
696 return mpPropSet->getPropertySetInfo();
699 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
701 SolarMutexGuard aGuard;
703 if( mpImpl == nullptr )
704 throw uno::RuntimeException();
706 if (aPropertyName == UNO_TC_PROP_ANCHOR)
708 aValue >>= mxAnchor;
709 return;
712 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
713 if ( !pMap )
714 throw beans::UnknownPropertyException(aPropertyName);
716 switch( pMap->nWID )
718 case WID_DATE:
719 if(aValue >>= mpImpl->maDateTime)
720 return;
721 break;
722 case WID_BOOL1:
723 if(aValue >>= mpImpl->mbBoolean1)
724 return;
725 break;
726 case WID_BOOL2:
727 if(aValue >>= mpImpl->mbBoolean2)
728 return;
729 break;
730 case WID_INT16:
731 if(aValue >>= mpImpl->mnInt16)
732 return;
733 break;
734 case WID_INT32:
735 if(aValue >>= mpImpl->mnInt32)
736 return;
737 break;
738 case WID_STRING1:
739 if(aValue >>= mpImpl->msString1)
740 return;
741 break;
742 case WID_STRING2:
743 if(aValue >>= mpImpl->msString2)
744 return;
745 break;
746 case WID_STRING3:
747 if(aValue >>= mpImpl->msString3)
748 return;
749 break;
752 throw lang::IllegalArgumentException();
755 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
757 SolarMutexGuard aGuard;
759 if (PropertyName == UNO_TC_PROP_ANCHOR)
760 return uno::makeAny(mxAnchor);
762 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
763 return uno::makeAny(mnServiceId);
765 uno::Any aValue;
767 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
768 if ( !pMap )
769 throw beans::UnknownPropertyException(PropertyName);
771 switch( pMap->nWID )
773 case WID_DATE:
774 aValue <<= mpImpl->maDateTime;
775 break;
776 case WID_BOOL1:
777 aValue <<= mpImpl->mbBoolean1;
778 break;
779 case WID_BOOL2:
780 aValue <<= mpImpl->mbBoolean2;
781 break;
782 case WID_INT16:
783 aValue <<= mpImpl->mnInt16;
784 break;
785 case WID_INT32:
786 aValue <<= mpImpl->mnInt32;
787 break;
788 case WID_STRING1:
789 aValue <<= mpImpl->msString1;
790 break;
791 case WID_STRING2:
792 aValue <<= mpImpl->msString2;
793 break;
794 case WID_STRING3:
795 aValue <<= mpImpl->msString3;
796 break;
799 return aValue;
802 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
803 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
804 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
805 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
807 // OComponentHelper
808 void SvxUnoTextField::disposing()
810 // nothing to do
813 // lang::XServiceInfo
814 OUString SAL_CALL SvxUnoTextField::getImplementationName()
816 return "SvxUnoTextField";
819 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
821 uno::Sequence<OUString> aSeq(4);
822 OUString* pServices = aSeq.getArray();
823 pServices[0] = "com.sun.star.text.TextContent";
824 pServices[1] = "com.sun.star.text.TextField";
826 switch (mnServiceId)
828 case text::textfield::Type::DATE:
829 pServices[2] = "com.sun.star.text.TextField.DateTime";
830 pServices[3] = "com.sun.star.text.textfield.DateTime";
831 break;
832 case text::textfield::Type::URL:
833 pServices[2] = "com.sun.star.text.TextField.URL";
834 pServices[3] = "com.sun.star.text.textfield.URL";
835 break;
836 case text::textfield::Type::PAGE:
837 pServices[2] = "com.sun.star.text.TextField.PageNumber";
838 pServices[3] = "com.sun.star.text.textfield.PageNumber";
839 break;
840 case text::textfield::Type::PAGES:
841 pServices[2] = "com.sun.star.text.TextField.PageCount";
842 pServices[3] = "com.sun.star.text.textfield.PageCount";
843 break;
844 case text::textfield::Type::TIME:
845 pServices[2] = "com.sun.star.text.TextField.DateTime";
846 pServices[3] = "com.sun.star.text.textfield.DateTime";
847 break;
848 case text::textfield::Type::DOCINFO_TITLE:
849 pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
850 pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
851 break;
852 case text::textfield::Type::TABLE:
853 pServices[2] = "com.sun.star.text.TextField.SheetName";
854 pServices[3] = "com.sun.star.text.textfield.SheetName";
855 break;
856 case text::textfield::Type::EXTENDED_TIME:
857 pServices[2] = "com.sun.star.text.TextField.DateTime";
858 pServices[3] = "com.sun.star.text.textfield.DateTime";
859 break;
860 case text::textfield::Type::EXTENDED_FILE:
861 pServices[2] = "com.sun.star.text.TextField.FileName";
862 pServices[3] = "com.sun.star.text.textfield.FileName";
863 break;
864 case text::textfield::Type::AUTHOR:
865 pServices[2] = "com.sun.star.text.TextField.Author";
866 pServices[3] = "com.sun.star.text.textfield.Author";
867 break;
868 case text::textfield::Type::MEASURE:
869 pServices[2] = "com.sun.star.text.TextField.Measure";
870 pServices[3] = "com.sun.star.text.textfield.Measure";
871 break;
872 case text::textfield::Type::PRESENTATION_HEADER:
873 pServices[2] = "com.sun.star.presentation.TextField.Header";
874 pServices[3] = "com.sun.star.presentation.textfield.Header";
875 break;
876 case text::textfield::Type::PRESENTATION_FOOTER:
877 pServices[2] = "com.sun.star.presentation.TextField.Footer";
878 pServices[3] = "com.sun.star.presentation.textfield.Footer";
879 break;
880 case text::textfield::Type::PRESENTATION_DATE_TIME:
881 pServices[2] = "com.sun.star.presentation.TextField.DateTime";
882 pServices[3] = "com.sun.star.presentation.textfield.DateTime";
883 break;
884 case text::textfield::Type::PAGE_NAME:
885 pServices[2] = "com.sun.star.text.TextField.PageName";
886 pServices[3] = "com.sun.star.text.textfield.PageName";
887 break;
888 case text::textfield::Type::DOCINFO_CUSTOM:
889 pServices[2] = "com.sun.star.text.TextField.DocInfo.Custom";
890 pServices[3] = "com.sun.star.text.textfield.DocInfo.Custom";
891 break;
892 default:
893 aSeq.realloc(0);
896 return aSeq;
899 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
901 return cppu::supportsService( this, ServiceName );
904 uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( const OUString& ServiceSpecifier )
906 uno::Reference< uno::XInterface > xRet;
908 const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
910 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
911 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
913 if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
914 (ServiceSpecifier.startsWith( "com.sun.star.text.TextField." )) )
916 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
918 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
920 if ( aFieldType == "DateTime" )
922 nId = text::textfield::Type::DATE;
924 else if ( aFieldType == "URL" )
926 nId = text::textfield::Type::URL;
928 else if ( aFieldType == "PageNumber" )
930 nId = text::textfield::Type::PAGE;
932 else if ( aFieldType == "PageCount" )
934 nId = text::textfield::Type::PAGES;
936 else if ( aFieldType == "SheetName" )
938 nId = text::textfield::Type::TABLE;
940 else if ( aFieldType == "FileName" )
942 nId = text::textfield::Type::EXTENDED_FILE;
944 else if (aFieldType == "docinfo.Title" ||
945 aFieldType == "DocInfo.Title" )
947 nId = text::textfield::Type::DOCINFO_TITLE;
949 else if ( aFieldType == "Author" )
951 nId = text::textfield::Type::AUTHOR;
953 else if ( aFieldType == "Measure" )
955 nId = text::textfield::Type::MEASURE;
957 else if (aFieldType == "DocInfo.Custom")
959 nId = text::textfield::Type::DOCINFO_CUSTOM;
962 if (nId != text::textfield::Type::UNSPECIFIED)
963 xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId ));
966 return xRet;
969 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */