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 <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)
55 class SvxUnoFieldData_Impl
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
);
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
;
162 return &aEmptyPropertySet_Impl
;
166 /* conversion routines */
168 static sal_Int16
getFileNameDisplayFormat( SvxFileFormat 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
)
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:
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();
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();
225 static tools::Time
setTime( util::DateTime
const & rDate
)
227 return tools::Time( rDate
);
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));
251 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId
) throw()
252 : OComponentHelper( getMutex() )
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;
270 case text::textfield::Type::DATE
:
271 mpImpl
->mbBoolean2
= true;
272 mpImpl
->mnInt32
= static_cast<sal_Int32
>(SvxDateFormat::StdSmall
);
273 mpImpl
->mbBoolean1
= false;
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
);
283 case text::textfield::Type::URL
:
284 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SvxURLFormat::Repr
);
287 case text::textfield::Type::EXTENDED_FILE
:
288 mpImpl
->mbBoolean1
= false;
289 mpImpl
->mnInt16
= text::FilenameDisplayFormat::FULL
;
292 case text::textfield::Type::AUTHOR
:
293 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SvxAuthorFormat::FullName
);
294 mpImpl
->mbBoolean1
= false;
295 mpImpl
->mbBoolean2
= true;
298 case text::textfield::Type::MEASURE
:
299 mpImpl
->mnInt16
= static_cast<sal_uInt16
>(SdrMeasureFieldKind::Value
);
302 case text::textfield::Type::DOCINFO_CUSTOM
:
303 mpImpl
->mbBoolean1
= true;
304 mpImpl
->mbBoolean2
= true;
309 mpImpl
->mbBoolean1
= false;
310 mpImpl
->mbBoolean2
= false;
317 SvxUnoTextField::SvxUnoTextField( uno::Reference
< text::XTextRange
> const & xAnchor
, const OUString
& rPresentation
, const SvxFieldData
* pData
) throw()
318 : OComponentHelper( getMutex() )
319 , mxAnchor( xAnchor
)
321 , mnServiceId(text::textfield::Type::UNSPECIFIED
)
322 , mpImpl( new SvxUnoFieldData_Impl
)
324 DBG_ASSERT(pData
, "pFieldData == NULL! [CL]" );
326 mpImpl
->msPresentation
= rPresentation
;
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
;
351 case text::textfield::Type::TIME
:
352 mpImpl
->mbBoolean2
= false;
353 mpImpl
->mbBoolean1
= false;
354 mpImpl
->mnInt32
= static_cast<sal_Int32
>(SvxTimeFormat::Standard
);
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());
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());
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());
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
;
387 case text::textfield::Type::MEASURE
:
388 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(static_cast<const SdrMeasureField
*>(pData
)->GetMeasureFieldKind());
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;
400 SAL_WARN("editeng", "Id service unknown: " << mnServiceId
);
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
) );
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
) );
444 pData
.reset( new SvxTimeField() );
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
) );
459 case text::textfield::Type::PAGE
:
460 pData
.reset( new SvxPageField() );
463 case text::textfield::Type::PAGES
:
464 pData
.reset( new SvxPagesField() );
467 case text::textfield::Type::DOCINFO_TITLE
:
468 pData
.reset( new SvxFileField() );
471 case text::textfield::Type::TABLE
:
472 pData
.reset( new SvxTableField() );
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
) ) );
484 case text::textfield::Type::AUTHOR
:
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
;
497 aContent
= mpImpl
->msString2
;
499 sal_Int32 nPos
= aContent
.lastIndexOf( ' ', 0 );
502 aFirstName
= aContent
.copy( 0, nPos
);
503 aLastName
= aContent
.copy( nPos
+ 1 );
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
) );
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
) );
535 case text::textfield::Type::PRESENTATION_HEADER
:
536 pData
.reset( new SvxHeaderField() );
538 case text::textfield::Type::PRESENTATION_FOOTER
:
539 pData
.reset( new SvxFooterField() );
541 case text::textfield::Type::PRESENTATION_DATE_TIME
:
542 pData
.reset( new SvxDateTimeField() );
544 case text::textfield::Type::PAGE_NAME
:
545 pData
.reset( new SvxPageTitleField() );
547 case text::textfield::Type::DOCINFO_CUSTOM
:
548 pData
.reset( new editeng::CustomPropertyField(mpImpl
->msString1
, mpImpl
->msString2
) );
556 uno::Any SAL_CALL
SvxUnoTextField::queryAggregation( const uno::Type
& rType
)
560 QUERYINT( beans::XPropertySet
);
561 else QUERYINT( text::XTextContent
);
562 else QUERYINT( text::XTextField
);
563 else QUERYINT( lang::XServiceInfo
);
564 else QUERYINT( lang::XUnoTunnel
);
566 return OComponentHelper::queryAggregation( rType
);
573 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextField::getTypes()
575 if( !maTypeSequence
.hasElements() )
577 maTypeSequence
= comphelper::concatSequences(
578 OComponentHelper::getTypes(),
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
;
616 case text::textfield::Type::DATE
:
618 case text::textfield::Type::URL
:
620 case text::textfield::Type::PAGE
:
622 case text::textfield::Type::PAGES
:
624 case text::textfield::Type::TIME
:
626 case text::textfield::Type::DOCINFO_TITLE
:
628 case text::textfield::Type::TABLE
:
630 case text::textfield::Type::EXTENDED_TIME
:
632 case text::textfield::Type::EXTENDED_FILE
:
634 case text::textfield::Type::AUTHOR
:
636 case text::textfield::Type::MEASURE
:
638 case text::textfield::Type::PRESENTATION_HEADER
:
640 case text::textfield::Type::PRESENTATION_FOOTER
:
642 case text::textfield::Type::PRESENTATION_DATE_TIME
:
644 case text::textfield::Type::PAGE_NAME
:
646 case text::textfield::Type::DOCINFO_CUSTOM
:
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();
667 pRange
->attachField( std::move(pData
) );
670 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextField::getAnchor()
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
)
712 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( aPropertyName
);
714 throw beans::UnknownPropertyException(aPropertyName
);
719 if(aValue
>>= mpImpl
->maDateTime
)
723 if(aValue
>>= mpImpl
->mbBoolean1
)
727 if(aValue
>>= mpImpl
->mbBoolean2
)
731 if(aValue
>>= mpImpl
->mnInt16
)
735 if(aValue
>>= mpImpl
->mnInt32
)
739 if(aValue
>>= mpImpl
->msString1
)
743 if(aValue
>>= mpImpl
->msString2
)
747 if(aValue
>>= mpImpl
->msString3
)
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
);
767 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( PropertyName
);
769 throw beans::UnknownPropertyException(PropertyName
);
774 aValue
<<= mpImpl
->maDateTime
;
777 aValue
<<= mpImpl
->mbBoolean1
;
780 aValue
<<= mpImpl
->mbBoolean2
;
783 aValue
<<= mpImpl
->mnInt16
;
786 aValue
<<= mpImpl
->mnInt32
;
789 aValue
<<= mpImpl
->msString1
;
792 aValue
<<= mpImpl
->msString2
;
795 aValue
<<= mpImpl
->msString3
;
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
>& ) {}
808 void SvxUnoTextField::disposing()
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";
828 case text::textfield::Type::DATE
:
829 pServices
[2] = "com.sun.star.text.TextField.DateTime";
830 pServices
[3] = "com.sun.star.text.textfield.DateTime";
832 case text::textfield::Type::URL
:
833 pServices
[2] = "com.sun.star.text.TextField.URL";
834 pServices
[3] = "com.sun.star.text.textfield.URL";
836 case text::textfield::Type::PAGE
:
837 pServices
[2] = "com.sun.star.text.TextField.PageNumber";
838 pServices
[3] = "com.sun.star.text.textfield.PageNumber";
840 case text::textfield::Type::PAGES
:
841 pServices
[2] = "com.sun.star.text.TextField.PageCount";
842 pServices
[3] = "com.sun.star.text.textfield.PageCount";
844 case text::textfield::Type::TIME
:
845 pServices
[2] = "com.sun.star.text.TextField.DateTime";
846 pServices
[3] = "com.sun.star.text.textfield.DateTime";
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";
852 case text::textfield::Type::TABLE
:
853 pServices
[2] = "com.sun.star.text.TextField.SheetName";
854 pServices
[3] = "com.sun.star.text.textfield.SheetName";
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";
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";
864 case text::textfield::Type::AUTHOR
:
865 pServices
[2] = "com.sun.star.text.TextField.Author";
866 pServices
[3] = "com.sun.star.text.textfield.Author";
868 case text::textfield::Type::MEASURE
:
869 pServices
[2] = "com.sun.star.text.TextField.Measure";
870 pServices
[3] = "com.sun.star.text.textfield.Measure";
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";
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";
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";
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";
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";
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
));
969 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */