bump product version to 6.4.0.3
[LibreOffice.git] / editeng / source / uno / unofield.cxx
blob0a20a3e6cadf7d23ba79a64a8ea0963f9a10a67b
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 <tools/debug.hxx>
26 #include <svl/itemprop.hxx>
28 #include <editeng/eeitem.hxx>
29 #include <editeng/flditem.hxx>
30 #include <editeng/CustomPropertyField.hxx>
31 #include <editeng/measfld.hxx>
32 #include <editeng/unofield.hxx>
33 #include <editeng/unotext.hxx>
34 #include <comphelper/sequence.hxx>
35 #include <comphelper/servicehelper.hxx>
36 #include <cppuhelper/supportsservice.hxx>
37 #include <sal/log.hxx>
39 #include <editeng/unonames.hxx>
41 using namespace ::cppu;
42 using namespace ::com::sun::star;
44 #define QUERYINT( xint ) \
45 if( rType == cppu::UnoType<xint>::get() ) \
46 aAny <<= uno::Reference< xint >(this)
49 #define WID_DATE 0
50 #define WID_BOOL1 1
51 #define WID_BOOL2 2
52 #define WID_INT32 3
53 #define WID_INT16 4
54 #define WID_STRING1 5
55 #define WID_STRING2 6
56 #define WID_STRING3 7
58 class SvxUnoFieldData_Impl
60 public:
61 bool mbBoolean1;
62 bool mbBoolean2;
63 sal_Int32 mnInt32;
64 sal_Int16 mnInt16;
65 OUString msString1;
66 OUString msString2;
67 OUString msString3;
68 util::DateTime maDateTime;
70 OUString msPresentation;
73 static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
75 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
77 { OUString(UNO_TC_PROP_DATE_TIME), WID_DATE, ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
78 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
79 { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
80 { OUString(UNO_TC_PROP_NUMFORMAT), WID_INT32, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
81 { OUString(), 0, css::uno::Type(), 0, 0 }
83 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
85 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
87 { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
88 { OUString(), 0, css::uno::Type(), 0, 0 }
90 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
92 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
95 { OUString(UNO_TC_PROP_URL_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
96 { OUString(UNO_TC_PROP_URL_REPRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
97 { OUString(UNO_TC_PROP_URL_TARGET), WID_STRING2, ::cppu::UnoType<OUString>::get(), 0, 0 },
98 { OUString(UNO_TC_PROP_URL), WID_STRING3, ::cppu::UnoType<OUString>::get(), 0, 0 },
99 { OUString(), 0, css::uno::Type(), 0, 0 }
101 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
103 static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
105 { OUString(), 0, css::uno::Type(), 0, 0 }
107 static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
109 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
111 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
112 { OUString(UNO_TC_PROP_FILE_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
113 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
114 { OUString(), 0, css::uno::Type(), 0, 0 }
116 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
118 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
120 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
121 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1,::cppu::UnoType<OUString>::get(), 0, 0 },
122 { OUString(UNO_TC_PROP_AUTHOR_CONTENT), WID_STRING2,::cppu::UnoType<OUString>::get(), 0, 0 },
123 { OUString(UNO_TC_PROP_AUTHOR_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
124 { OUString(UNO_TC_PROP_AUTHOR_FULLNAME), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
125 { OUString(), 0, css::uno::Type(), 0, 0 }
127 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
129 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
131 { OUString(UNO_TC_PROP_MEASURE_KIND), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
132 { OUString(), 0, css::uno::Type(), 0, 0 }
134 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
136 static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
138 { OUString(UNO_TC_PROP_NAME), WID_STRING1, cppu::UnoType<OUString>::get(), 0, 0 },
139 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING2, cppu::UnoType<OUString>::get(), 0, 0 },
140 { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
141 { OUString(UNO_TC_PROP_NUMFORMAT), WID_INT32, cppu::UnoType<sal_Int32>::get(), 0, 0 },
142 { OUString(UNO_TC_PROP_IS_FIXED_LANGUAGE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
143 { OUString(), 0, css::uno::Type(), 0, 0 }
145 static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_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 case text::textfield::Type::DOCINFO_CUSTOM:
163 return &aDocInfoCustomFieldPropertySet_Impl;
164 default:
165 return &aEmptyPropertySet_Impl;
169 /* conversion routines */
171 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
173 switch( nFormat )
175 case SvxFileFormat::NameAndExt: return text::FilenameDisplayFormat::NAME_AND_EXT;
176 case SvxFileFormat::PathFull: return text::FilenameDisplayFormat::FULL;
177 case SvxFileFormat::PathOnly: return text::FilenameDisplayFormat::PATH;
178 // case SvxFileFormat::NameOnly:
179 default: return text::FilenameDisplayFormat::NAME;
183 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
185 switch( nFormat )
187 case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull;
188 case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly;
189 case text::FilenameDisplayFormat::NAME: return SvxFileFormat::NameOnly;
190 // case text::FilenameDisplayFormat::NAME_AND_EXT:
191 default:
192 return SvxFileFormat::NameAndExt;
196 static util::DateTime getDate( sal_Int32 nDate )
198 util::DateTime aDate;
200 Date aTempDate( nDate );
202 aDate.Day = aTempDate.GetDay();
203 aDate.Month = aTempDate.GetMonth();
204 aDate.Year = aTempDate.GetYear();
206 return aDate;
209 static Date setDate( util::DateTime const & rDate )
211 return Date( rDate.Day, rDate.Month, rDate.Year );
214 static util::DateTime getTime(sal_Int64 const nTime)
216 util::DateTime aTime;
218 tools::Time aTempTime( nTime );
220 aTime.NanoSeconds = aTempTime.GetNanoSec();
221 aTime.Seconds = aTempTime.GetSec();
222 aTime.Minutes = aTempTime.GetMin();
223 aTime.Hours = aTempTime.GetHour();
225 return aTime;
228 static tools::Time setTime( util::DateTime const & rDate )
230 return tools::Time( rDate );
234 // class SvxUnoTextField
236 namespace
238 class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
241 const css::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
243 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
246 sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
248 if( isUnoTunnelId<SvxUnoTextField>(rId) )
250 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
252 return 0;
255 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
256 : OComponentHelper( getMutex() )
257 , mpPropSet(nullptr)
258 , mnServiceId(nServiceId)
259 , mpImpl( new SvxUnoFieldData_Impl )
261 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
263 mpImpl->maDateTime.NanoSeconds = 0;
264 mpImpl->maDateTime.Seconds = 0;
265 mpImpl->maDateTime.Minutes = 0;
266 mpImpl->maDateTime.Hours = 0;
267 mpImpl->maDateTime.Day = 0;
268 mpImpl->maDateTime.Month = 0;
269 mpImpl->maDateTime.Year = 0;
270 mpImpl->maDateTime.IsUTC = false;
272 switch( nServiceId )
274 case text::textfield::Type::DATE:
275 mpImpl->mbBoolean2 = true;
276 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxDateFormat::StdSmall);
277 mpImpl->mbBoolean1 = false;
278 break;
280 case text::textfield::Type::EXTENDED_TIME:
281 case text::textfield::Type::TIME:
282 mpImpl->mbBoolean2 = false;
283 mpImpl->mbBoolean1 = false;
284 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
285 break;
287 case text::textfield::Type::URL:
288 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
289 break;
291 case text::textfield::Type::EXTENDED_FILE:
292 mpImpl->mbBoolean1 = false;
293 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
294 break;
296 case text::textfield::Type::AUTHOR:
297 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxAuthorFormat::FullName);
298 mpImpl->mbBoolean1 = false;
299 mpImpl->mbBoolean2 = true;
300 break;
302 case text::textfield::Type::MEASURE:
303 mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
304 break;
306 case text::textfield::Type::DOCINFO_CUSTOM:
307 mpImpl->mbBoolean1 = true;
308 mpImpl->mbBoolean2 = true;
309 mpImpl->mnInt32 = 0;
310 break;
312 default:
313 mpImpl->mbBoolean1 = false;
314 mpImpl->mbBoolean2 = false;
315 mpImpl->mnInt32 = 0;
316 mpImpl->mnInt16 = 0;
321 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > const & xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
322 : OComponentHelper( getMutex() )
323 , mxAnchor( xAnchor )
324 , mpPropSet(nullptr)
325 , mnServiceId(text::textfield::Type::UNSPECIFIED)
326 , mpImpl( new SvxUnoFieldData_Impl )
328 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
330 mpImpl->msPresentation = rPresentation;
332 if(pData)
334 mnServiceId = pData->GetClassId();
335 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
336 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
338 // extract field properties from data class
339 switch( mnServiceId )
341 case text::textfield::Type::DATE:
343 mpImpl->mbBoolean2 = true;
344 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
345 // use current date instead
346 bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SvxDateType::Fix;
347 mpImpl->maDateTime = getDate( bFixed ?
348 static_cast<const SvxDateField*>(pData)->GetFixDate() :
349 Date( Date::SYSTEM ).GetDate() );
350 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxDateField*>(pData)->GetFormat());
351 mpImpl->mbBoolean1 = bFixed;
353 break;
355 case text::textfield::Type::TIME:
356 mpImpl->mbBoolean2 = false;
357 mpImpl->mbBoolean1 = false;
358 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
359 break;
361 case text::textfield::Type::EXTENDED_TIME:
362 mpImpl->mbBoolean2 = false;
363 mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
364 mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SvxTimeType::Fix;
365 mpImpl->mnInt32 = static_cast<sal_Int32>(static_cast<const SvxExtTimeField*>(pData)->GetFormat());
366 break;
368 case text::textfield::Type::URL:
369 mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
370 mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
371 mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
372 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
373 static_cast<const SvxURLField*>(pData)->GetFormat());
374 break;
376 case text::textfield::Type::EXTENDED_FILE:
377 mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
378 mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SvxFileType::Fix;
379 mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
380 break;
382 case text::textfield::Type::AUTHOR:
383 mpImpl->msString1 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
384 mpImpl->msString2 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
385 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
386 static_cast<const SvxAuthorField*>(pData)->GetFormat());
387 mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SvxAuthorType::Fix;
388 mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SvxAuthorFormat::ShortName;
389 break;
391 case text::textfield::Type::MEASURE:
392 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
393 break;
395 case text::textfield::Type::DOCINFO_CUSTOM:
396 mpImpl->msString1 = static_cast<const editeng::CustomPropertyField*>(pData)->GetName();
397 mpImpl->msString2 = static_cast<const editeng::CustomPropertyField*>(pData)->GetCurrentPresentation();
398 mpImpl->mbBoolean1 = false;
399 mpImpl->mbBoolean2 = false;
400 mpImpl->mnInt32 = 0;
401 break;
403 default:
404 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
405 break;
410 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
413 SvxUnoTextField::~SvxUnoTextField() throw()
417 std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const throw()
419 std::unique_ptr<SvxFieldData> pData;
421 switch( mnServiceId )
423 case text::textfield::Type::TIME:
424 case text::textfield::Type::EXTENDED_TIME:
425 case text::textfield::Type::DATE:
427 if( mpImpl->mbBoolean2 ) // IsDate?
429 Date aDate( setDate( mpImpl->maDateTime ) );
430 pData.reset( new SvxDateField( aDate, mpImpl->mbBoolean1?SvxDateType::Fix:SvxDateType::Var ) );
431 if( mpImpl->mnInt32 >= static_cast<sal_Int32>(SvxDateFormat::AppDefault) &&
432 mpImpl->mnInt32 <= static_cast<sal_Int32>(SvxDateFormat::F) )
433 static_cast<SvxDateField*>(pData.get())->SetFormat( static_cast<SvxDateFormat>(mpImpl->mnInt32) );
435 else
437 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
439 tools::Time aTime( setTime( mpImpl->maDateTime ) );
440 pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
442 if( static_cast<SvxTimeFormat>(mpImpl->mnInt32) >= SvxTimeFormat::AppDefault &&
443 static_cast<SvxTimeFormat>(mpImpl->mnInt32) <= SvxTimeFormat::HH12_MM_SS_00_AMPM )
444 static_cast<SvxExtTimeField*>(pData.get())->SetFormat( static_cast<SvxTimeFormat>(mpImpl->mnInt32) );
446 else
448 pData.reset( new SvxTimeField() );
453 break;
455 case text::textfield::Type::URL:
456 pData.reset( new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SvxURLFormat::Repr : SvxURLFormat::Url ) );
457 static_cast<SvxURLField*>(pData.get())->SetTargetFrame( mpImpl->msString2 );
458 if( static_cast<SvxURLFormat>(mpImpl->mnInt16) >= SvxURLFormat::AppDefault &&
459 static_cast<SvxURLFormat>(mpImpl->mnInt16) <= SvxURLFormat::Repr )
460 static_cast<SvxURLField*>(pData.get())->SetFormat( static_cast<SvxURLFormat>(mpImpl->mnInt16) );
461 break;
463 case text::textfield::Type::PAGE:
464 pData.reset( new SvxPageField() );
465 break;
467 case text::textfield::Type::PAGES:
468 pData.reset( new SvxPagesField() );
469 break;
471 case text::textfield::Type::DOCINFO_TITLE:
472 pData.reset( new SvxFileField() );
473 break;
475 case text::textfield::Type::TABLE:
476 pData.reset( new SvxTableField() );
477 break;
479 case text::textfield::Type::EXTENDED_FILE:
481 // #92009# pass fixed attribute to constructor
482 pData.reset( new SvxExtFileField( mpImpl->msString1,
483 mpImpl->mbBoolean1 ? SvxFileType::Fix : SvxFileType::Var,
484 setFileNameDisplayFormat(mpImpl->mnInt16 ) ) );
485 break;
488 case text::textfield::Type::AUTHOR:
490 OUString aContent;
491 OUString aFirstName;
492 OUString aLastName;
494 // do we have CurrentPresentation given?
495 // mimic behaviour of writer, which means:
496 // prefer CurrentPresentation over Content
497 // if both are given.
498 if( !mpImpl->msString1.isEmpty() )
499 aContent = mpImpl->msString1;
500 else
501 aContent = mpImpl->msString2;
503 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
504 if( nPos > 0 )
506 aFirstName = aContent.copy( 0, nPos );
507 aLastName = aContent.copy( nPos + 1 );
509 else
511 aLastName = aContent;
514 // #92009# pass fixed attribute to constructor
515 pData.reset( new SvxAuthorField( aFirstName, aLastName, "",
516 mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
518 if( !mpImpl->mbBoolean2 )
520 static_cast<SvxAuthorField*>(pData.get())->SetFormat( SvxAuthorFormat::ShortName );
522 else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
523 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
525 static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
528 break;
531 case text::textfield::Type::MEASURE:
533 SdrMeasureFieldKind eKind = SdrMeasureFieldKind::Value;
534 if( mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Unit) || mpImpl->mnInt16 == sal_Int16(SdrMeasureFieldKind::Rotate90Blanks) )
535 eKind = static_cast<SdrMeasureFieldKind>(mpImpl->mnInt16);
536 pData.reset( new SdrMeasureField( eKind) );
537 break;
539 case text::textfield::Type::PRESENTATION_HEADER:
540 pData.reset( new SvxHeaderField() );
541 break;
542 case text::textfield::Type::PRESENTATION_FOOTER:
543 pData.reset( new SvxFooterField() );
544 break;
545 case text::textfield::Type::PRESENTATION_DATE_TIME:
546 pData.reset( new SvxDateTimeField() );
547 break;
548 case text::textfield::Type::PAGE_NAME:
549 pData.reset( new SvxPageTitleField() );
550 break;
551 case text::textfield::Type::DOCINFO_CUSTOM:
552 pData.reset( new editeng::CustomPropertyField(mpImpl->msString1, mpImpl->msString2) );
553 break;
556 return pData;
559 // uno::XInterface
560 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
562 uno::Any aAny;
564 QUERYINT( beans::XPropertySet );
565 else QUERYINT( text::XTextContent );
566 else QUERYINT( text::XTextField );
567 else QUERYINT( lang::XServiceInfo );
568 else QUERYINT( lang::XUnoTunnel );
569 else
570 return OComponentHelper::queryAggregation( rType );
572 return aAny;
575 // XTypeProvider
577 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
579 if( !maTypeSequence.hasElements() )
581 maTypeSequence = comphelper::concatSequences(
582 OComponentHelper::getTypes(),
583 uno::Sequence {
584 cppu::UnoType<text::XTextField>::get(),
585 cppu::UnoType<beans::XPropertySet>::get(),
586 cppu::UnoType<lang::XServiceInfo>::get(),
587 cppu::UnoType<lang::XUnoTunnel>::get() });
589 return maTypeSequence;
592 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
594 return css::uno::Sequence<sal_Int8>();
597 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
599 return OComponentHelper::queryInterface(rType);
602 void SAL_CALL SvxUnoTextField::acquire() throw( )
604 OComponentHelper::acquire();
607 void SAL_CALL SvxUnoTextField::release() throw( )
609 OComponentHelper::release();
612 // Interface text::XTextField
613 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
615 SolarMutexGuard aGuard;
616 if (bShowCommand)
618 switch (mnServiceId)
620 case text::textfield::Type::DATE:
621 return "Date";
622 case text::textfield::Type::URL:
623 return "URL";
624 case text::textfield::Type::PAGE:
625 return "Page";
626 case text::textfield::Type::PAGES:
627 return "Pages";
628 case text::textfield::Type::TIME:
629 return "Time";
630 case text::textfield::Type::DOCINFO_TITLE:
631 return "File";
632 case text::textfield::Type::TABLE:
633 return "Table";
634 case text::textfield::Type::EXTENDED_TIME:
635 return "ExtTime";
636 case text::textfield::Type::EXTENDED_FILE:
637 return "ExtFile";
638 case text::textfield::Type::AUTHOR:
639 return "Author";
640 case text::textfield::Type::MEASURE:
641 return "Measure";
642 case text::textfield::Type::PRESENTATION_HEADER:
643 return "Header";
644 case text::textfield::Type::PRESENTATION_FOOTER:
645 return "Footer";
646 case text::textfield::Type::PRESENTATION_DATE_TIME:
647 return "DateTime";
648 case text::textfield::Type::PAGE_NAME:
649 return "PageName";
650 case text::textfield::Type::DOCINFO_CUSTOM:
651 return "Custom";
652 default:
653 return "Unknown";
656 else
658 return mpImpl->msPresentation;
662 // Interface text::XTextContent
663 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
665 SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xTextRange );
666 if(pRange == nullptr)
667 throw lang::IllegalArgumentException();
669 std::unique_ptr<SvxFieldData> pData = CreateFieldData();
670 if( pData )
671 pRange->attachField( std::move(pData) );
674 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
676 return mxAnchor;
679 // lang::XComponent
680 void SAL_CALL SvxUnoTextField::dispose()
682 OComponentHelper::dispose();
685 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
687 OComponentHelper::addEventListener(xListener);
690 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
692 OComponentHelper::removeEventListener(aListener);
696 // Interface beans::XPropertySet
697 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
699 SolarMutexGuard aGuard;
700 return mpPropSet->getPropertySetInfo();
703 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
705 SolarMutexGuard aGuard;
707 if( mpImpl == nullptr )
708 throw uno::RuntimeException();
710 if (aPropertyName == UNO_TC_PROP_ANCHOR)
712 aValue >>= mxAnchor;
713 return;
716 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
717 if ( !pMap )
718 throw beans::UnknownPropertyException(aPropertyName);
720 switch( pMap->nWID )
722 case WID_DATE:
723 if(aValue >>= mpImpl->maDateTime)
724 return;
725 break;
726 case WID_BOOL1:
727 if(aValue >>= mpImpl->mbBoolean1)
728 return;
729 break;
730 case WID_BOOL2:
731 if(aValue >>= mpImpl->mbBoolean2)
732 return;
733 break;
734 case WID_INT16:
735 if(aValue >>= mpImpl->mnInt16)
736 return;
737 break;
738 case WID_INT32:
739 if(aValue >>= mpImpl->mnInt32)
740 return;
741 break;
742 case WID_STRING1:
743 if(aValue >>= mpImpl->msString1)
744 return;
745 break;
746 case WID_STRING2:
747 if(aValue >>= mpImpl->msString2)
748 return;
749 break;
750 case WID_STRING3:
751 if(aValue >>= mpImpl->msString3)
752 return;
753 break;
756 throw lang::IllegalArgumentException();
759 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
761 SolarMutexGuard aGuard;
763 if (PropertyName == UNO_TC_PROP_ANCHOR)
764 return uno::makeAny(mxAnchor);
766 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
767 return uno::makeAny(mnServiceId);
769 uno::Any aValue;
771 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
772 if ( !pMap )
773 throw beans::UnknownPropertyException(PropertyName);
775 switch( pMap->nWID )
777 case WID_DATE:
778 aValue <<= mpImpl->maDateTime;
779 break;
780 case WID_BOOL1:
781 aValue <<= mpImpl->mbBoolean1;
782 break;
783 case WID_BOOL2:
784 aValue <<= mpImpl->mbBoolean2;
785 break;
786 case WID_INT16:
787 aValue <<= mpImpl->mnInt16;
788 break;
789 case WID_INT32:
790 aValue <<= mpImpl->mnInt32;
791 break;
792 case WID_STRING1:
793 aValue <<= mpImpl->msString1;
794 break;
795 case WID_STRING2:
796 aValue <<= mpImpl->msString2;
797 break;
798 case WID_STRING3:
799 aValue <<= mpImpl->msString3;
800 break;
803 return aValue;
806 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
807 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
808 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
809 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
811 // OComponentHelper
812 void SvxUnoTextField::disposing()
814 // nothing to do
817 // lang::XServiceInfo
818 OUString SAL_CALL SvxUnoTextField::getImplementationName()
820 return "SvxUnoTextField";
823 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
825 uno::Sequence<OUString> aSeq(4);
826 OUString* pServices = aSeq.getArray();
827 pServices[0] = "com.sun.star.text.TextContent";
828 pServices[1] = "com.sun.star.text.TextField";
830 switch (mnServiceId)
832 case text::textfield::Type::DATE:
833 pServices[2] = "com.sun.star.text.TextField.DateTime";
834 pServices[3] = "com.sun.star.text.textfield.DateTime";
835 break;
836 case text::textfield::Type::URL:
837 pServices[2] = "com.sun.star.text.TextField.URL";
838 pServices[3] = "com.sun.star.text.textfield.URL";
839 break;
840 case text::textfield::Type::PAGE:
841 pServices[2] = "com.sun.star.text.TextField.PageNumber";
842 pServices[3] = "com.sun.star.text.textfield.PageNumber";
843 break;
844 case text::textfield::Type::PAGES:
845 pServices[2] = "com.sun.star.text.TextField.PageCount";
846 pServices[3] = "com.sun.star.text.textfield.PageCount";
847 break;
848 case text::textfield::Type::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::DOCINFO_TITLE:
853 pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
854 pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
855 break;
856 case text::textfield::Type::TABLE:
857 pServices[2] = "com.sun.star.text.TextField.SheetName";
858 pServices[3] = "com.sun.star.text.textfield.SheetName";
859 break;
860 case text::textfield::Type::EXTENDED_TIME:
861 pServices[2] = "com.sun.star.text.TextField.DateTime";
862 pServices[3] = "com.sun.star.text.textfield.DateTime";
863 break;
864 case text::textfield::Type::EXTENDED_FILE:
865 pServices[2] = "com.sun.star.text.TextField.FileName";
866 pServices[3] = "com.sun.star.text.textfield.FileName";
867 break;
868 case text::textfield::Type::AUTHOR:
869 pServices[2] = "com.sun.star.text.TextField.Author";
870 pServices[3] = "com.sun.star.text.textfield.Author";
871 break;
872 case text::textfield::Type::MEASURE:
873 pServices[2] = "com.sun.star.text.TextField.Measure";
874 pServices[3] = "com.sun.star.text.textfield.Measure";
875 break;
876 case text::textfield::Type::PRESENTATION_HEADER:
877 pServices[2] = "com.sun.star.presentation.TextField.Header";
878 pServices[3] = "com.sun.star.presentation.textfield.Header";
879 break;
880 case text::textfield::Type::PRESENTATION_FOOTER:
881 pServices[2] = "com.sun.star.presentation.TextField.Footer";
882 pServices[3] = "com.sun.star.presentation.textfield.Footer";
883 break;
884 case text::textfield::Type::PRESENTATION_DATE_TIME:
885 pServices[2] = "com.sun.star.presentation.TextField.DateTime";
886 pServices[3] = "com.sun.star.presentation.textfield.DateTime";
887 break;
888 case text::textfield::Type::PAGE_NAME:
889 pServices[2] = "com.sun.star.text.TextField.PageName";
890 pServices[3] = "com.sun.star.text.textfield.PageName";
891 break;
892 case text::textfield::Type::DOCINFO_CUSTOM:
893 pServices[2] = "com.sun.star.text.TextField.DocInfo.Custom";
894 pServices[3] = "com.sun.star.text.textfield.DocInfo.Custom";
895 break;
896 default:
897 aSeq.realloc(0);
900 return aSeq;
903 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
905 return cppu::supportsService( this, ServiceName );
908 uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( const OUString& ServiceSpecifier )
910 uno::Reference< uno::XInterface > xRet;
912 const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
914 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
915 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
917 if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
918 (ServiceSpecifier.startsWith( "com.sun.star.text.TextField." )) )
920 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
922 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
924 if ( aFieldType == "DateTime" )
926 nId = text::textfield::Type::DATE;
928 else if ( aFieldType == "URL" )
930 nId = text::textfield::Type::URL;
932 else if ( aFieldType == "PageNumber" )
934 nId = text::textfield::Type::PAGE;
936 else if ( aFieldType == "PageCount" )
938 nId = text::textfield::Type::PAGES;
940 else if ( aFieldType == "SheetName" )
942 nId = text::textfield::Type::TABLE;
944 else if ( aFieldType == "FileName" )
946 nId = text::textfield::Type::EXTENDED_FILE;
948 else if (aFieldType == "docinfo.Title" ||
949 aFieldType == "DocInfo.Title" )
951 nId = text::textfield::Type::DOCINFO_TITLE;
953 else if ( aFieldType == "Author" )
955 nId = text::textfield::Type::AUTHOR;
957 else if ( aFieldType == "Measure" )
959 nId = text::textfield::Type::MEASURE;
961 else if (aFieldType == "DocInfo.Custom")
963 nId = text::textfield::Type::DOCINFO_CUSTOM;
966 if (nId != text::textfield::Type::UNSPECIFIED)
967 xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId ));
970 return xRet;
973 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */