1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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)
61 class SvxUnoFieldData_Impl
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
);
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
;
156 return &aEmptyPropertySet_Impl
;
160 /* conversion routines */
162 static sal_Int16
getFileNameDisplayFormat( SvxFileFormat 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
)
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:
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();
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();
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
)
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;
245 case text::textfield::Type::DATE
:
246 mpImpl
->mbBoolean2
= true;
247 mpImpl
->mnInt32
= static_cast<sal_Int32
>(SvxDateFormat::StdSmall
);
248 mpImpl
->mbBoolean1
= false;
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
);
258 case text::textfield::Type::URL
:
259 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SvxURLFormat::Repr
);
262 case text::textfield::Type::EXTENDED_FILE
:
263 mpImpl
->mbBoolean1
= false;
264 mpImpl
->mnInt16
= text::FilenameDisplayFormat::FULL
;
267 case text::textfield::Type::AUTHOR
:
268 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SvxAuthorFormat::FullName
);
269 mpImpl
->mbBoolean1
= false;
270 mpImpl
->mbBoolean2
= true;
273 case text::textfield::Type::MEASURE
:
274 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SdrMeasureFieldKind::Value
);
277 case text::textfield::Type::DOCINFO_CUSTOM
:
278 mpImpl
->mbBoolean1
= true;
279 mpImpl
->mbBoolean2
= true;
284 mpImpl
->mbBoolean1
= false;
285 mpImpl
->mbBoolean2
= false;
292 SvxUnoTextField::SvxUnoTextField( uno::Reference
< text::XTextRange
> xAnchor
, const OUString
& rPresentation
, const SvxFieldData
* pData
) noexcept
293 : OComponentHelper( m_aMutex
)
294 , mxAnchor(std::move( xAnchor
))
296 , mnServiceId(text::textfield::Type::UNSPECIFIED
)
297 , mpImpl( new SvxUnoFieldData_Impl
)
299 DBG_ASSERT(pData
, "pFieldData == NULL! [CL]" );
301 mpImpl
->msPresentation
= rPresentation
;
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
;
326 case text::textfield::Type::TIME
:
327 mpImpl
->mbBoolean2
= false;
328 mpImpl
->mbBoolean1
= false;
329 mpImpl
->mnInt32
= static_cast<sal_Int32
>(SvxTimeFormat::Standard
);
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());
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());
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());
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
;
362 case text::textfield::Type::MEASURE
:
363 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(static_cast<const SdrMeasureField
*>(pData
)->GetMeasureFieldKind());
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;
375 SAL_WARN("editeng", "Id service unknown: " << mnServiceId
);
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
) );
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
) );
419 pData
.reset( new SvxTimeField() );
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
) );
434 case text::textfield::Type::PAGE
:
435 pData
.reset( new SvxPageField() );
438 case text::textfield::Type::PAGES
:
439 pData
.reset( new SvxPagesField() );
442 case text::textfield::Type::DOCINFO_TITLE
:
443 pData
.reset( new SvxFileField() );
446 case text::textfield::Type::TABLE
:
447 pData
.reset( new SvxTableField() );
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
) ) );
459 case text::textfield::Type::AUTHOR
:
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
;
472 aContent
= mpImpl
->msString2
;
474 sal_Int32 nPos
= aContent
.lastIndexOf( ' ', 0 );
477 aFirstName
= aContent
.copy( 0, nPos
);
478 aLastName
= aContent
.copy( nPos
+ 1 );
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
) );
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
) );
510 case text::textfield::Type::PRESENTATION_HEADER
:
511 pData
.reset( new SvxHeaderField() );
513 case text::textfield::Type::PRESENTATION_FOOTER
:
514 pData
.reset( new SvxFooterField() );
516 case text::textfield::Type::PRESENTATION_DATE_TIME
:
517 pData
.reset( new SvxDateTimeField() );
519 case text::textfield::Type::PAGE_NAME
:
520 pData
.reset( new SvxPageTitleField() );
522 case text::textfield::Type::DOCINFO_CUSTOM
:
523 pData
.reset( new editeng::CustomPropertyField(mpImpl
->msString1
, mpImpl
->msString2
) );
531 uno::Any SAL_CALL
SvxUnoTextField::queryAggregation( const uno::Type
& rType
)
535 QUERYINT( beans::XPropertySet
);
536 else QUERYINT( text::XTextContent
);
537 else QUERYINT( text::XTextField
);
538 else QUERYINT( lang::XServiceInfo
);
540 return OComponentHelper::queryAggregation( rType
);
547 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextField::getTypes()
549 if( !maTypeSequence
.hasElements() )
551 maTypeSequence
= comphelper::concatSequences(
552 OComponentHelper::getTypes(),
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
;
590 case text::textfield::Type::DATE
:
592 case text::textfield::Type::URL
:
594 case text::textfield::Type::PAGE
:
596 case text::textfield::Type::PAGES
:
598 case text::textfield::Type::TIME
:
600 case text::textfield::Type::DOCINFO_TITLE
:
602 case text::textfield::Type::TABLE
:
604 case text::textfield::Type::EXTENDED_TIME
:
606 case text::textfield::Type::EXTENDED_FILE
:
608 case text::textfield::Type::AUTHOR
:
610 case text::textfield::Type::MEASURE
:
612 case text::textfield::Type::PRESENTATION_HEADER
:
614 case text::textfield::Type::PRESENTATION_FOOTER
:
616 case text::textfield::Type::PRESENTATION_DATE_TIME
:
618 case text::textfield::Type::PAGE_NAME
:
620 case text::textfield::Type::DOCINFO_CUSTOM
:
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();
641 pRange
->attachField( std::move(pData
) );
644 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextField::getAnchor()
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
)
686 const SfxItemPropertyMapEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( aPropertyName
);
688 throw beans::UnknownPropertyException(aPropertyName
);
693 if(aValue
>>= mpImpl
->maDateTime
)
697 if(aValue
>>= mpImpl
->mbBoolean1
)
701 if(aValue
>>= mpImpl
->mbBoolean2
)
705 if(aValue
>>= mpImpl
->mnInt16
)
709 if(aValue
>>= mpImpl
->mnInt32
)
713 if(aValue
>>= mpImpl
->msString1
)
717 if(aValue
>>= mpImpl
->msString2
)
721 if(aValue
>>= mpImpl
->msString3
)
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
);
741 const SfxItemPropertyMapEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( PropertyName
);
743 throw beans::UnknownPropertyException(PropertyName
);
748 aValue
<<= mpImpl
->maDateTime
;
751 aValue
<<= mpImpl
->mbBoolean1
;
754 aValue
<<= mpImpl
->mbBoolean2
;
757 aValue
<<= mpImpl
->mnInt16
;
760 aValue
<<= mpImpl
->mnInt32
;
763 aValue
<<= mpImpl
->msString1
;
766 aValue
<<= mpImpl
->msString2
;
769 aValue
<<= mpImpl
->msString3
;
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
>& ) {}
782 void SvxUnoTextField::disposing()
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";
802 case text::textfield::Type::DATE
:
803 pServices
[2] = "com.sun.star.text.TextField.DateTime";
804 pServices
[3] = "com.sun.star.text.textfield.DateTime";
806 case text::textfield::Type::URL
:
807 pServices
[2] = "com.sun.star.text.TextField.URL";
808 pServices
[3] = "com.sun.star.text.textfield.URL";
810 case text::textfield::Type::PAGE
:
811 pServices
[2] = "com.sun.star.text.TextField.PageNumber";
812 pServices
[3] = "com.sun.star.text.textfield.PageNumber";
814 case text::textfield::Type::PAGES
:
815 pServices
[2] = "com.sun.star.text.TextField.PageCount";
816 pServices
[3] = "com.sun.star.text.textfield.PageCount";
818 case text::textfield::Type::TIME
:
819 pServices
[2] = "com.sun.star.text.TextField.DateTime";
820 pServices
[3] = "com.sun.star.text.textfield.DateTime";
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";
826 case text::textfield::Type::TABLE
:
827 pServices
[2] = "com.sun.star.text.TextField.SheetName";
828 pServices
[3] = "com.sun.star.text.textfield.SheetName";
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";
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";
838 case text::textfield::Type::AUTHOR
:
839 pServices
[2] = "com.sun.star.text.TextField.Author";
840 pServices
[3] = "com.sun.star.text.textfield.Author";
842 case text::textfield::Type::MEASURE
:
843 pServices
[2] = "com.sun.star.text.TextField.Measure";
844 pServices
[3] = "com.sun.star.text.textfield.Measure";
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";
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";
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";
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";
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";
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
));
940 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */