Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / editeng / source / uno / unofield.cxx
blob0264e52f0319091b2b66f639fef768dc4ce9245d
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 <sal/config.h>
22 #include <string_view>
24 #include <com/sun/star/util/DateTime.hpp>
25 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
26 #include <o3tl/string_view.hxx>
27 #include <utility>
28 #include <vcl/svapp.hxx>
29 #include <tools/debug.hxx>
30 #include <svl/itemprop.hxx>
32 #include <editeng/flditem.hxx>
33 #include <editeng/CustomPropertyField.hxx>
34 #include <editeng/measfld.hxx>
35 #include <editeng/unofield.hxx>
36 #include <editeng/unotext.hxx>
37 #include <comphelper/sequence.hxx>
38 #include <comphelper/servicehelper.hxx>
39 #include <cppuhelper/supportsservice.hxx>
40 #include <sal/log.hxx>
42 #include <editeng/unonames.hxx>
44 using namespace ::cppu;
45 using namespace ::com::sun::star;
47 #define QUERYINT( xint ) \
48 if( rType == cppu::UnoType<xint>::get() ) \
49 aAny <<= uno::Reference< xint >(this)
52 #define WID_DATE 0
53 #define WID_BOOL1 1
54 #define WID_BOOL2 2
55 #define WID_INT32 3
56 #define WID_INT16 4
57 #define WID_STRING1 5
58 #define WID_STRING2 6
59 #define WID_STRING3 7
61 class SvxUnoFieldData_Impl
63 public:
64 bool mbBoolean1;
65 bool mbBoolean2;
66 sal_Int32 mnInt32;
67 sal_Int16 mnInt16;
68 OUString msString1;
69 OUString msString2;
70 OUString msString3;
71 util::DateTime maDateTime;
73 OUString msPresentation;
76 static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
78 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
80 { UNO_TC_PROP_DATE_TIME, WID_DATE, ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
81 { UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
82 { UNO_TC_PROP_IS_DATE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
83 { UNO_TC_PROP_NUMFORMAT, WID_INT32, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
85 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
87 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
89 { UNO_TC_PROP_IS_DATE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
91 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
93 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
95 { UNO_TC_PROP_URL_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
96 { UNO_TC_PROP_URL_REPRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
97 { UNO_TC_PROP_URL_TARGET, WID_STRING2, ::cppu::UnoType<OUString>::get(), 0, 0 },
98 { UNO_TC_PROP_URL, WID_STRING3, ::cppu::UnoType<OUString>::get(), 0, 0 },
100 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
102 static const SfxItemPropertySet aEmptyPropertySet_Impl({});
104 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
106 { UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
107 { UNO_TC_PROP_FILE_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
108 { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
110 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
112 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
114 { UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
115 { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING1,::cppu::UnoType<OUString>::get(), 0, 0 },
116 { UNO_TC_PROP_AUTHOR_CONTENT, WID_STRING2,::cppu::UnoType<OUString>::get(), 0, 0 },
117 { UNO_TC_PROP_AUTHOR_FORMAT, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
118 { UNO_TC_PROP_AUTHOR_FULLNAME, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
120 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
122 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
124 { UNO_TC_PROP_MEASURE_KIND, WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
126 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
128 static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
130 { UNO_TC_PROP_NAME, WID_STRING1, cppu::UnoType<OUString>::get(), 0, 0 },
131 { UNO_TC_PROP_CURRENT_PRESENTATION, WID_STRING2, cppu::UnoType<OUString>::get(), 0, 0 },
132 { UNO_TC_PROP_IS_FIXED, WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
133 { UNO_TC_PROP_NUMFORMAT, WID_INT32, cppu::UnoType<sal_Int32>::get(), 0, 0 },
134 { UNO_TC_PROP_IS_FIXED_LANGUAGE, WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
136 static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
138 switch( mnId )
140 case text::textfield::Type::EXTENDED_TIME:
141 case text::textfield::Type::DATE:
142 return &aExDateTimeFieldPropertySet_Impl;
143 case text::textfield::Type::URL:
144 return &aUrlFieldPropertySet_Impl;
145 case text::textfield::Type::TIME:
146 return &aDateTimeFieldPropertySet_Impl;
147 case text::textfield::Type::EXTENDED_FILE:
148 return &aExtFileFieldPropertySet_Impl;
149 case text::textfield::Type::AUTHOR:
150 return &aAuthorFieldPropertySet_Impl;
151 case text::textfield::Type::MEASURE:
152 return &aMeasureFieldPropertySet_Impl;
153 case text::textfield::Type::DOCINFO_CUSTOM:
154 return &aDocInfoCustomFieldPropertySet_Impl;
155 default:
156 return &aEmptyPropertySet_Impl;
160 /* conversion routines */
162 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
164 switch( nFormat )
166 case SvxFileFormat::NameAndExt: return text::FilenameDisplayFormat::NAME_AND_EXT;
167 case SvxFileFormat::PathFull: return text::FilenameDisplayFormat::FULL;
168 case SvxFileFormat::PathOnly: return text::FilenameDisplayFormat::PATH;
169 // case SvxFileFormat::NameOnly:
170 default: return text::FilenameDisplayFormat::NAME;
174 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
176 switch( nFormat )
178 case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull;
179 case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly;
180 case text::FilenameDisplayFormat::NAME: return SvxFileFormat::NameOnly;
181 // case text::FilenameDisplayFormat::NAME_AND_EXT:
182 default:
183 return SvxFileFormat::NameAndExt;
187 static util::DateTime getDate( sal_Int32 nDate )
189 util::DateTime aDate;
191 Date aTempDate( nDate );
193 aDate.Day = aTempDate.GetDay();
194 aDate.Month = aTempDate.GetMonth();
195 aDate.Year = aTempDate.GetYear();
197 return aDate;
200 static Date setDate( util::DateTime const & rDate )
202 return Date( rDate.Day, rDate.Month, rDate.Year );
205 static util::DateTime getTime(sal_Int64 const nTime)
207 util::DateTime aTime;
209 tools::Time aTempTime( nTime );
211 aTime.NanoSeconds = aTempTime.GetNanoSec();
212 aTime.Seconds = aTempTime.GetSec();
213 aTime.Minutes = aTempTime.GetMin();
214 aTime.Hours = aTempTime.GetHour();
216 return aTime;
219 static tools::Time setTime( util::DateTime const & rDate )
221 return tools::Time( rDate );
226 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) noexcept
227 : OComponentHelper( m_aMutex )
228 , mpPropSet(nullptr)
229 , mnServiceId(nServiceId)
230 , mpImpl( new SvxUnoFieldData_Impl )
232 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
234 mpImpl->maDateTime.NanoSeconds = 0;
235 mpImpl->maDateTime.Seconds = 0;
236 mpImpl->maDateTime.Minutes = 0;
237 mpImpl->maDateTime.Hours = 0;
238 mpImpl->maDateTime.Day = 0;
239 mpImpl->maDateTime.Month = 0;
240 mpImpl->maDateTime.Year = 0;
241 mpImpl->maDateTime.IsUTC = false;
243 switch( nServiceId )
245 case text::textfield::Type::DATE:
246 mpImpl->mbBoolean2 = true;
247 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxDateFormat::StdSmall);
248 mpImpl->mbBoolean1 = false;
249 break;
251 case text::textfield::Type::EXTENDED_TIME:
252 case text::textfield::Type::TIME:
253 mpImpl->mbBoolean2 = false;
254 mpImpl->mbBoolean1 = false;
255 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
256 break;
258 case text::textfield::Type::URL:
259 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
260 break;
262 case text::textfield::Type::EXTENDED_FILE:
263 mpImpl->mbBoolean1 = false;
264 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
265 break;
267 case text::textfield::Type::AUTHOR:
268 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxAuthorFormat::FullName);
269 mpImpl->mbBoolean1 = false;
270 mpImpl->mbBoolean2 = true;
271 break;
273 case text::textfield::Type::MEASURE:
274 mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
275 break;
277 case text::textfield::Type::DOCINFO_CUSTOM:
278 mpImpl->mbBoolean1 = true;
279 mpImpl->mbBoolean2 = true;
280 mpImpl->mnInt32 = 0;
281 break;
283 default:
284 mpImpl->mbBoolean1 = false;
285 mpImpl->mbBoolean2 = false;
286 mpImpl->mnInt32 = 0;
287 mpImpl->mnInt16 = 0;
292 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) noexcept
293 : OComponentHelper( m_aMutex )
294 , mxAnchor(std::move( xAnchor ))
295 , mpPropSet(nullptr)
296 , mnServiceId(text::textfield::Type::UNSPECIFIED)
297 , mpImpl( new SvxUnoFieldData_Impl )
299 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
301 mpImpl->msPresentation = rPresentation;
303 if(pData)
305 mnServiceId = pData->GetClassId();
306 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
307 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
309 // extract field properties from data class
310 switch( mnServiceId )
312 case text::textfield::Type::DATE:
314 mpImpl->mbBoolean2 = true;
315 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
316 // use current date instead
317 bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SvxDateType::Fix;
318 mpImpl->maDateTime = getDate( bFixed ?
319 static_cast<const SvxDateField*>(pData)->GetFixDate() :
320 Date( Date::SYSTEM ).GetDate() );
321 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxDateField*>(pData)->GetFormat());
322 mpImpl->mbBoolean1 = bFixed;
324 break;
326 case text::textfield::Type::TIME:
327 mpImpl->mbBoolean2 = false;
328 mpImpl->mbBoolean1 = false;
329 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
330 break;
332 case text::textfield::Type::EXTENDED_TIME:
333 mpImpl->mbBoolean2 = false;
334 mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
335 mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SvxTimeType::Fix;
336 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxExtTimeField*>(pData)->GetFormat());
337 break;
339 case text::textfield::Type::URL:
340 mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
341 mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
342 mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
343 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
344 static_cast<const SvxURLField*>(pData)->GetFormat());
345 break;
347 case text::textfield::Type::EXTENDED_FILE:
348 mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
349 mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SvxFileType::Fix;
350 mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
351 break;
353 case text::textfield::Type::AUTHOR:
354 mpImpl->msString1 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
355 mpImpl->msString2 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
356 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
357 static_cast<const SvxAuthorField*>(pData)->GetFormat());
358 mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SvxAuthorType::Fix;
359 mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SvxAuthorFormat::ShortName;
360 break;
362 case text::textfield::Type::MEASURE:
363 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
364 break;
366 case text::textfield::Type::DOCINFO_CUSTOM:
367 mpImpl->msString1 = static_cast<const editeng::CustomPropertyField*>(pData)->GetName();
368 mpImpl->msString2 = static_cast<const editeng::CustomPropertyField*>(pData)->GetCurrentPresentation();
369 mpImpl->mbBoolean1 = false;
370 mpImpl->mbBoolean2 = false;
371 mpImpl->mnInt32 = 0;
372 break;
374 default:
375 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
376 break;
381 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
384 SvxUnoTextField::~SvxUnoTextField() noexcept
388 std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const noexcept
390 std::unique_ptr<SvxFieldData> pData;
392 switch( mnServiceId )
394 case text::textfield::Type::TIME:
395 case text::textfield::Type::EXTENDED_TIME:
396 case text::textfield::Type::DATE:
398 if( mpImpl->mbBoolean2 ) // IsDate?
400 Date aDate( setDate( mpImpl->maDateTime ) );
401 pData.reset( new SvxDateField( aDate, mpImpl->mbBoolean1?SvxDateType::Fix:SvxDateType::Var ) );
402 if( mpImpl->mnInt32 >= static_cast<sal_Int32>(SvxDateFormat::AppDefault) &&
403 mpImpl->mnInt32 <= static_cast<sal_Int32>(SvxDateFormat::F) )
404 static_cast<SvxDateField*>(pData.get())->SetFormat( static_cast<SvxDateFormat>(mpImpl->mnInt32) );
406 else
408 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
410 tools::Time aTime( setTime( mpImpl->maDateTime ) );
411 pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
413 if( static_cast<SvxTimeFormat>(mpImpl->mnInt32) >= SvxTimeFormat::AppDefault &&
414 static_cast<SvxTimeFormat>(mpImpl->mnInt32) <= SvxTimeFormat::HH12_MM_SS_00_AMPM )
415 static_cast<SvxExtTimeField*>(pData.get())->SetFormat( static_cast<SvxTimeFormat>(mpImpl->mnInt32) );
417 else
419 pData.reset( new SvxTimeField() );
424 break;
426 case text::textfield::Type::URL:
427 pData.reset( new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SvxURLFormat::Repr : SvxURLFormat::Url ) );
428 static_cast<SvxURLField*>(pData.get())->SetTargetFrame( mpImpl->msString2 );
429 if( static_cast<SvxURLFormat>(mpImpl->mnInt16) >= SvxURLFormat::AppDefault &&
430 static_cast<SvxURLFormat>(mpImpl->mnInt16) <= SvxURLFormat::Repr )
431 static_cast<SvxURLField*>(pData.get())->SetFormat( static_cast<SvxURLFormat>(mpImpl->mnInt16) );
432 break;
434 case text::textfield::Type::PAGE:
435 pData.reset( new SvxPageField() );
436 break;
438 case text::textfield::Type::PAGES:
439 pData.reset( new SvxPagesField() );
440 break;
442 case text::textfield::Type::DOCINFO_TITLE:
443 pData.reset( new SvxFileField() );
444 break;
446 case text::textfield::Type::TABLE:
447 pData.reset( new SvxTableField() );
448 break;
450 case text::textfield::Type::EXTENDED_FILE:
452 // #92009# pass fixed attribute to constructor
453 pData.reset( new SvxExtFileField( mpImpl->msString1,
454 mpImpl->mbBoolean1 ? SvxFileType::Fix : SvxFileType::Var,
455 setFileNameDisplayFormat(mpImpl->mnInt16 ) ) );
456 break;
459 case text::textfield::Type::AUTHOR:
461 OUString aContent;
462 OUString aFirstName;
463 OUString aLastName;
465 // do we have CurrentPresentation given?
466 // mimic behaviour of writer, which means:
467 // prefer CurrentPresentation over Content
468 // if both are given.
469 if( !mpImpl->msString1.isEmpty() )
470 aContent = mpImpl->msString1;
471 else
472 aContent = mpImpl->msString2;
474 sal_Int32 nPos = aContent.lastIndexOf( ' ', 0 );
475 if( nPos > 0 )
477 aFirstName = aContent.copy( 0, nPos );
478 aLastName = aContent.copy( nPos + 1 );
480 else
482 aLastName = aContent;
485 // #92009# pass fixed attribute to constructor
486 pData.reset( new SvxAuthorField( aFirstName, aLastName, "",
487 mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
489 if( !mpImpl->mbBoolean2 )
491 static_cast<SvxAuthorField*>(pData.get())->SetFormat( SvxAuthorFormat::ShortName );
493 else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
494 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
496 static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
499 break;
502 case text::textfield::Type::MEASURE:
504 SdrMeasureFieldKind eKind = SdrMeasureFieldKind::Value;
505 if( mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Unit) || mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Rotate90Blanks) )
506 eKind = static_cast<SdrMeasureFieldKind>(mpImpl->mnInt16);
507 pData.reset( new SdrMeasureField( eKind) );
508 break;
510 case text::textfield::Type::PRESENTATION_HEADER:
511 pData.reset( new SvxHeaderField() );
512 break;
513 case text::textfield::Type::PRESENTATION_FOOTER:
514 pData.reset( new SvxFooterField() );
515 break;
516 case text::textfield::Type::PRESENTATION_DATE_TIME:
517 pData.reset( new SvxDateTimeField() );
518 break;
519 case text::textfield::Type::PAGE_NAME:
520 pData.reset( new SvxPageTitleField() );
521 break;
522 case text::textfield::Type::DOCINFO_CUSTOM:
523 pData.reset( new editeng::CustomPropertyField(mpImpl->msString1, mpImpl->msString2) );
524 break;
527 return pData;
530 // uno::XInterface
531 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
533 uno::Any aAny;
535 QUERYINT( beans::XPropertySet );
536 else QUERYINT( text::XTextContent );
537 else QUERYINT( text::XTextField );
538 else QUERYINT( lang::XServiceInfo );
539 else
540 return OComponentHelper::queryAggregation( rType );
542 return aAny;
545 // XTypeProvider
547 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
549 if( !maTypeSequence.hasElements() )
551 maTypeSequence = comphelper::concatSequences(
552 OComponentHelper::getTypes(),
553 uno::Sequence {
554 cppu::UnoType<text::XTextField>::get(),
555 cppu::UnoType<beans::XPropertySet>::get(),
556 cppu::UnoType<lang::XServiceInfo>::get(),
557 cppu::UnoType<lang::XUnoTunnel>::get() });
559 return maTypeSequence;
562 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
564 return css::uno::Sequence<sal_Int8>();
567 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
569 return OComponentHelper::queryInterface(rType);
572 void SAL_CALL SvxUnoTextField::acquire() noexcept
574 OComponentHelper::acquire();
577 void SAL_CALL SvxUnoTextField::release() noexcept
579 OComponentHelper::release();
582 // Interface text::XTextField
583 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
585 SolarMutexGuard aGuard;
586 if (bShowCommand)
588 switch (mnServiceId)
590 case text::textfield::Type::DATE:
591 return "Date";
592 case text::textfield::Type::URL:
593 return "URL";
594 case text::textfield::Type::PAGE:
595 return "Page";
596 case text::textfield::Type::PAGES:
597 return "Pages";
598 case text::textfield::Type::TIME:
599 return "Time";
600 case text::textfield::Type::DOCINFO_TITLE:
601 return "File";
602 case text::textfield::Type::TABLE:
603 return "Table";
604 case text::textfield::Type::EXTENDED_TIME:
605 return "ExtTime";
606 case text::textfield::Type::EXTENDED_FILE:
607 return "ExtFile";
608 case text::textfield::Type::AUTHOR:
609 return "Author";
610 case text::textfield::Type::MEASURE:
611 return "Measure";
612 case text::textfield::Type::PRESENTATION_HEADER:
613 return "Header";
614 case text::textfield::Type::PRESENTATION_FOOTER:
615 return "Footer";
616 case text::textfield::Type::PRESENTATION_DATE_TIME:
617 return "DateTime";
618 case text::textfield::Type::PAGE_NAME:
619 return "PageName";
620 case text::textfield::Type::DOCINFO_CUSTOM:
621 return "Custom";
622 default:
623 return "Unknown";
626 else
628 return mpImpl->msPresentation;
632 // Interface text::XTextContent
633 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
635 SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRange>( xTextRange );
636 if(pRange == nullptr)
637 throw lang::IllegalArgumentException();
639 std::unique_ptr<SvxFieldData> pData = CreateFieldData();
640 if( pData )
641 pRange->attachField( std::move(pData) );
644 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
646 return mxAnchor;
649 // lang::XComponent
650 void SAL_CALL SvxUnoTextField::dispose()
652 OComponentHelper::dispose();
655 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
657 OComponentHelper::addEventListener(xListener);
660 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
662 OComponentHelper::removeEventListener(aListener);
666 // Interface beans::XPropertySet
667 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
669 SolarMutexGuard aGuard;
670 return mpPropSet->getPropertySetInfo();
673 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
675 SolarMutexGuard aGuard;
677 if( mpImpl == nullptr )
678 throw uno::RuntimeException();
680 if (aPropertyName == UNO_TC_PROP_ANCHOR)
682 aValue >>= mxAnchor;
683 return;
686 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
687 if ( !pMap )
688 throw beans::UnknownPropertyException(aPropertyName);
690 switch( pMap->nWID )
692 case WID_DATE:
693 if(aValue >>= mpImpl->maDateTime)
694 return;
695 break;
696 case WID_BOOL1:
697 if(aValue >>= mpImpl->mbBoolean1)
698 return;
699 break;
700 case WID_BOOL2:
701 if(aValue >>= mpImpl->mbBoolean2)
702 return;
703 break;
704 case WID_INT16:
705 if(aValue >>= mpImpl->mnInt16)
706 return;
707 break;
708 case WID_INT32:
709 if(aValue >>= mpImpl->mnInt32)
710 return;
711 break;
712 case WID_STRING1:
713 if(aValue >>= mpImpl->msString1)
714 return;
715 break;
716 case WID_STRING2:
717 if(aValue >>= mpImpl->msString2)
718 return;
719 break;
720 case WID_STRING3:
721 if(aValue >>= mpImpl->msString3)
722 return;
723 break;
726 throw lang::IllegalArgumentException();
729 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
731 SolarMutexGuard aGuard;
733 if (PropertyName == UNO_TC_PROP_ANCHOR)
734 return uno::Any(mxAnchor);
736 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
737 return uno::Any(mnServiceId);
739 uno::Any aValue;
741 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
742 if ( !pMap )
743 throw beans::UnknownPropertyException(PropertyName);
745 switch( pMap->nWID )
747 case WID_DATE:
748 aValue <<= mpImpl->maDateTime;
749 break;
750 case WID_BOOL1:
751 aValue <<= mpImpl->mbBoolean1;
752 break;
753 case WID_BOOL2:
754 aValue <<= mpImpl->mbBoolean2;
755 break;
756 case WID_INT16:
757 aValue <<= mpImpl->mnInt16;
758 break;
759 case WID_INT32:
760 aValue <<= mpImpl->mnInt32;
761 break;
762 case WID_STRING1:
763 aValue <<= mpImpl->msString1;
764 break;
765 case WID_STRING2:
766 aValue <<= mpImpl->msString2;
767 break;
768 case WID_STRING3:
769 aValue <<= mpImpl->msString3;
770 break;
773 return aValue;
776 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
777 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
778 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
779 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
781 // OComponentHelper
782 void SvxUnoTextField::disposing()
784 // nothing to do
787 // lang::XServiceInfo
788 OUString SAL_CALL SvxUnoTextField::getImplementationName()
790 return "SvxUnoTextField";
793 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
795 uno::Sequence<OUString> aSeq(4);
796 OUString* pServices = aSeq.getArray();
797 pServices[0] = "com.sun.star.text.TextContent";
798 pServices[1] = "com.sun.star.text.TextField";
800 switch (mnServiceId)
802 case text::textfield::Type::DATE:
803 pServices[2] = "com.sun.star.text.TextField.DateTime";
804 pServices[3] = "com.sun.star.text.textfield.DateTime";
805 break;
806 case text::textfield::Type::URL:
807 pServices[2] = "com.sun.star.text.TextField.URL";
808 pServices[3] = "com.sun.star.text.textfield.URL";
809 break;
810 case text::textfield::Type::PAGE:
811 pServices[2] = "com.sun.star.text.TextField.PageNumber";
812 pServices[3] = "com.sun.star.text.textfield.PageNumber";
813 break;
814 case text::textfield::Type::PAGES:
815 pServices[2] = "com.sun.star.text.TextField.PageCount";
816 pServices[3] = "com.sun.star.text.textfield.PageCount";
817 break;
818 case text::textfield::Type::TIME:
819 pServices[2] = "com.sun.star.text.TextField.DateTime";
820 pServices[3] = "com.sun.star.text.textfield.DateTime";
821 break;
822 case text::textfield::Type::DOCINFO_TITLE:
823 pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
824 pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
825 break;
826 case text::textfield::Type::TABLE:
827 pServices[2] = "com.sun.star.text.TextField.SheetName";
828 pServices[3] = "com.sun.star.text.textfield.SheetName";
829 break;
830 case text::textfield::Type::EXTENDED_TIME:
831 pServices[2] = "com.sun.star.text.TextField.DateTime";
832 pServices[3] = "com.sun.star.text.textfield.DateTime";
833 break;
834 case text::textfield::Type::EXTENDED_FILE:
835 pServices[2] = "com.sun.star.text.TextField.FileName";
836 pServices[3] = "com.sun.star.text.textfield.FileName";
837 break;
838 case text::textfield::Type::AUTHOR:
839 pServices[2] = "com.sun.star.text.TextField.Author";
840 pServices[3] = "com.sun.star.text.textfield.Author";
841 break;
842 case text::textfield::Type::MEASURE:
843 pServices[2] = "com.sun.star.text.TextField.Measure";
844 pServices[3] = "com.sun.star.text.textfield.Measure";
845 break;
846 case text::textfield::Type::PRESENTATION_HEADER:
847 pServices[2] = "com.sun.star.presentation.TextField.Header";
848 pServices[3] = "com.sun.star.presentation.textfield.Header";
849 break;
850 case text::textfield::Type::PRESENTATION_FOOTER:
851 pServices[2] = "com.sun.star.presentation.TextField.Footer";
852 pServices[3] = "com.sun.star.presentation.textfield.Footer";
853 break;
854 case text::textfield::Type::PRESENTATION_DATE_TIME:
855 pServices[2] = "com.sun.star.presentation.TextField.DateTime";
856 pServices[3] = "com.sun.star.presentation.textfield.DateTime";
857 break;
858 case text::textfield::Type::PAGE_NAME:
859 pServices[2] = "com.sun.star.text.TextField.PageName";
860 pServices[3] = "com.sun.star.text.textfield.PageName";
861 break;
862 case text::textfield::Type::DOCINFO_CUSTOM:
863 pServices[2] = "com.sun.star.text.TextField.DocInfo.Custom";
864 pServices[3] = "com.sun.star.text.textfield.DocInfo.Custom";
865 break;
866 default:
867 aSeq.realloc(0);
870 return aSeq;
873 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
875 return cppu::supportsService( this, ServiceName );
878 uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( std::u16string_view ServiceSpecifier )
880 uno::Reference< uno::XInterface > xRet;
882 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
883 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
885 std::u16string_view aFieldType;
886 if( (o3tl::starts_with( ServiceSpecifier, u"com.sun.star.text.textfield.", &aFieldType )) ||
887 (o3tl::starts_with( ServiceSpecifier, u"com.sun.star.text.TextField.", &aFieldType )) )
889 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
891 if ( aFieldType == u"DateTime" )
893 nId = text::textfield::Type::DATE;
895 else if ( aFieldType == u"URL" )
897 nId = text::textfield::Type::URL;
899 else if ( aFieldType == u"PageNumber" )
901 nId = text::textfield::Type::PAGE;
903 else if ( aFieldType == u"PageCount" )
905 nId = text::textfield::Type::PAGES;
907 else if ( aFieldType == u"SheetName" )
909 nId = text::textfield::Type::TABLE;
911 else if ( aFieldType == u"FileName" )
913 nId = text::textfield::Type::EXTENDED_FILE;
915 else if (aFieldType == u"docinfo.Title" ||
916 aFieldType == u"DocInfo.Title" )
918 nId = text::textfield::Type::DOCINFO_TITLE;
920 else if ( aFieldType == u"Author" )
922 nId = text::textfield::Type::AUTHOR;
924 else if ( aFieldType == u"Measure" )
926 nId = text::textfield::Type::MEASURE;
928 else if (aFieldType == u"DocInfo.Custom")
930 nId = text::textfield::Type::DOCINFO_CUSTOM;
933 if (nId != text::textfield::Type::UNSPECIFIED)
934 xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId ));
937 return xRet;
940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */