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 <com/sun/star/lang/NoSupportException.hpp>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <vcl/svapp.hxx>
25 #include <osl/mutex.hxx>
27 #include <editeng/eeitem.hxx>
28 #include <editeng/flditem.hxx>
29 #include <editeng/measfld.hxx>
30 #include <editeng/unofield.hxx>
31 #include <editeng/unotext.hxx>
32 #include <comphelper/servicehelper.hxx>
33 #include <cppuhelper/supportsservice.hxx>
35 #include "editeng/unonames.hxx"
37 using namespace ::cppu
;
38 using namespace ::com::sun::star
;
40 #define QUERYINT( xint ) \
41 if( rType == cppu::UnoType<xint>::get() ) \
42 aAny <<= uno::Reference< xint >(this)
54 class SvxUnoFieldData_Impl
64 util::DateTime maDateTime
;
66 OUString msPresentation
;
69 const SfxItemPropertySet
* ImplGetFieldItemPropertySet( sal_Int32 mnId
)
71 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl
[] =
73 { OUString(UNO_TC_PROP_DATE_TIME
), WID_DATE
, ::cppu::UnoType
<util::DateTime
>::get(), 0, 0 },
74 { OUString(UNO_TC_PROP_IS_FIXED
), WID_BOOL1
, cppu::UnoType
<bool>::get(), 0, 0 },
75 { OUString(UNO_TC_PROP_IS_DATE
), WID_BOOL2
, cppu::UnoType
<bool>::get(), 0, 0 },
76 { OUString(UNO_TC_PROP_NUMFORMAT
), WID_INT32
, ::cppu::UnoType
<sal_Int32
>::get(), 0, 0 },
77 { OUString(), 0, css::uno::Type(), 0, 0 }
79 static const SfxItemPropertySet
aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl
);
81 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl
[] =
83 { OUString(UNO_TC_PROP_IS_DATE
), WID_BOOL2
, cppu::UnoType
<bool>::get(), 0, 0 },
84 { OUString(), 0, css::uno::Type(), 0, 0 }
86 static const SfxItemPropertySet
aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl
);
88 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl
[] =
91 { OUString(UNO_TC_PROP_URL_FORMAT
), WID_INT16
, ::cppu::UnoType
<sal_Int16
>::get(), 0, 0 },
92 { OUString(UNO_TC_PROP_URL_REPRESENTATION
), WID_STRING1
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
93 { OUString(UNO_TC_PROP_URL_TARGET
), WID_STRING2
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
94 { OUString(UNO_TC_PROP_URL
), WID_STRING3
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
95 { OUString(), 0, css::uno::Type(), 0, 0 }
97 static const SfxItemPropertySet
aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl
);
99 static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl
[] =
101 { OUString(), 0, css::uno::Type(), 0, 0 }
103 static const SfxItemPropertySet
aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl
);
105 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl
[] =
107 { OUString(UNO_TC_PROP_IS_FIXED
), WID_BOOL1
, cppu::UnoType
<bool>::get(), 0, 0 },
108 { OUString(UNO_TC_PROP_FILE_FORMAT
), WID_INT16
, ::cppu::UnoType
<sal_Int16
>::get(), 0, 0 },
109 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION
), WID_STRING1
, ::cppu::UnoType
<OUString
>::get(), 0, 0 },
110 { OUString(), 0, css::uno::Type(), 0, 0 }
112 static const SfxItemPropertySet
aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl
);
114 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl
[] =
116 { OUString(UNO_TC_PROP_IS_FIXED
), WID_BOOL1
, cppu::UnoType
<bool>::get(), 0, 0 },
117 { OUString(UNO_TC_PROP_CURRENT_PRESENTATION
), WID_STRING1
,::cppu::UnoType
<OUString
>::get(), 0, 0 },
118 { OUString(UNO_TC_PROP_AUTHOR_CONTENT
), WID_STRING2
,::cppu::UnoType
<OUString
>::get(), 0, 0 },
119 { OUString(UNO_TC_PROP_AUTHOR_FORMAT
), WID_INT16
, ::cppu::UnoType
<sal_Int16
>::get(), 0, 0 },
120 { OUString(UNO_TC_PROP_AUTHOR_FULLNAME
), WID_BOOL2
, cppu::UnoType
<bool>::get(), 0, 0 },
121 { OUString(), 0, css::uno::Type(), 0, 0 }
123 static const SfxItemPropertySet
aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl
);
125 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl
[] =
127 { OUString(UNO_TC_PROP_MEASURE_KIND
), WID_INT16
, ::cppu::UnoType
<sal_Int16
>::get(), 0, 0 },
128 { OUString(), 0, css::uno::Type(), 0, 0 }
130 static const SfxItemPropertySet
aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl
);
134 case text::textfield::Type::EXTENDED_TIME
:
135 case text::textfield::Type::DATE
:
136 return &aExDateTimeFieldPropertySet_Impl
;
137 case text::textfield::Type::URL
:
138 return &aUrlFieldPropertySet_Impl
;
139 case text::textfield::Type::TIME
:
140 return &aDateTimeFieldPropertySet_Impl
;
141 case text::textfield::Type::EXTENDED_FILE
:
142 return &aExtFileFieldPropertySet_Impl
;
143 case text::textfield::Type::AUTHOR
:
144 return &aAuthorFieldPropertySet_Impl
;
145 case text::textfield::Type::MEASURE
:
146 return &aMeasureFieldPropertySet_Impl
;
148 return &aEmptyPropertySet_Impl
;
152 /* conversion routines */
154 static sal_Int16
getFileNameDisplayFormat( SvxFileFormat nFormat
)
158 case SVXFILEFORMAT_NAME_EXT
: return text::FilenameDisplayFormat::NAME_AND_EXT
;
159 case SVXFILEFORMAT_FULLPATH
: return text::FilenameDisplayFormat::FULL
;
160 case SVXFILEFORMAT_PATH
: return text::FilenameDisplayFormat::PATH
;
161 // case SVXFILEFORMAT_NAME:
162 default: return text::FilenameDisplayFormat::NAME
;
166 static SvxFileFormat
setFileNameDisplayFormat( sal_Int16 nFormat
)
170 case text::FilenameDisplayFormat::FULL
: return SVXFILEFORMAT_FULLPATH
;
171 case text::FilenameDisplayFormat::PATH
: return SVXFILEFORMAT_PATH
;
172 case text::FilenameDisplayFormat::NAME
: return SVXFILEFORMAT_NAME
;
173 // case text::FilenameDisplayFormat::NAME_AND_EXT:
175 return SVXFILEFORMAT_NAME_EXT
;
179 static util::DateTime
getDate( sal_uLong nDate
)
181 util::DateTime aDate
;
182 memset( &aDate
, 0, sizeof( util::DateTime
) );
184 Date
aTempDate( nDate
);
186 aDate
.Day
= aTempDate
.GetDay();
187 aDate
.Month
= aTempDate
.GetMonth();
188 aDate
.Year
= aTempDate
.GetYear();
193 inline Date
setDate( util::DateTime
& rDate
)
195 return Date( rDate
.Day
, rDate
.Month
, rDate
.Year
);
198 static util::DateTime
getTime(sal_Int64
const nTime
)
200 util::DateTime aTime
;
201 memset( &aTime
, 0, sizeof( util::DateTime
) );
203 tools::Time
aTempTime( nTime
);
205 aTime
.NanoSeconds
= aTempTime
.GetNanoSec();
206 aTime
.Seconds
= aTempTime
.GetSec();
207 aTime
.Minutes
= aTempTime
.GetMin();
208 aTime
.Hours
= aTempTime
.GetHour();
213 inline tools::Time
setTime( util::DateTime
& rDate
)
215 return tools::Time( rDate
);
219 // class SvxUnoTextField
223 class theSvxUnoTextFieldUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theSvxUnoTextFieldUnoTunnelId
> {};
226 const ::com::sun::star::uno::Sequence
< sal_Int8
> & SvxUnoTextField::getUnoTunnelId() throw()
228 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
231 sal_Int64 SAL_CALL
SvxUnoTextField::getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
233 if( rId
.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
234 rId
.getConstArray(), 16 ) )
236 return sal::static_int_cast
<sal_Int64
>(reinterpret_cast<sal_IntPtr
>(this));
241 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId
) throw()
242 : OComponentHelper( getMutex() )
244 , mnServiceId(nServiceId
)
245 , mpImpl( new SvxUnoFieldData_Impl
)
247 mpPropSet
= ImplGetFieldItemPropertySet(mnServiceId
);
249 memset( &(mpImpl
->maDateTime
), 0, sizeof( util::DateTime
) );
253 case text::textfield::Type::DATE
:
254 mpImpl
->mbBoolean2
= true;
255 mpImpl
->mnInt32
= SVXDATEFORMAT_STDSMALL
;
256 mpImpl
->mbBoolean1
= false;
259 case text::textfield::Type::EXTENDED_TIME
:
260 case text::textfield::Type::TIME
:
261 mpImpl
->mbBoolean2
= false;
262 mpImpl
->mbBoolean1
= false;
263 mpImpl
->mnInt32
= SVXTIMEFORMAT_STANDARD
;
266 case text::textfield::Type::URL
:
267 mpImpl
->mnInt16
= SVXURLFORMAT_REPR
;
270 case text::textfield::Type::EXTENDED_FILE
:
271 mpImpl
->mbBoolean1
= false;
272 mpImpl
->mnInt16
= text::FilenameDisplayFormat::FULL
;
275 case text::textfield::Type::AUTHOR
:
276 mpImpl
->mnInt16
= SVXAUTHORFORMAT_FULLNAME
;
277 mpImpl
->mbBoolean1
= false;
278 mpImpl
->mbBoolean2
= true;
281 case text::textfield::Type::MEASURE
:
282 mpImpl
->mnInt16
= SDRMEASUREFIELD_VALUE
;
286 mpImpl
->mbBoolean1
= false;
287 mpImpl
->mbBoolean2
= false;
294 SvxUnoTextField::SvxUnoTextField( uno::Reference
< text::XTextRange
> xAnchor
, const OUString
& rPresentation
, const SvxFieldData
* pData
) throw()
295 : OComponentHelper( getMutex() )
296 , mxAnchor( xAnchor
)
298 , mnServiceId(text::textfield::Type::UNSPECIFIED
)
299 , mpImpl( new SvxUnoFieldData_Impl
)
301 DBG_ASSERT(pData
, "pFieldData == NULL! [CL]" );
303 mpImpl
->msPresentation
= rPresentation
;
307 mnServiceId
= pData
->GetClassId();
308 DBG_ASSERT(mnServiceId
!= text::textfield::Type::UNSPECIFIED
, "unknown SvxFieldData! [CL]");
309 if (mnServiceId
!= text::textfield::Type::UNSPECIFIED
)
311 // extract field properties from data class
312 switch( mnServiceId
)
314 case text::textfield::Type::DATE
:
316 mpImpl
->mbBoolean2
= true;
317 // #i35416# for variable date field, don't use invalid "0000-00-00" date,
318 // use current date instead
319 bool bFixed
= static_cast<const SvxDateField
*>(pData
)->GetType() == SVXDATETYPE_FIX
;
320 mpImpl
->maDateTime
= getDate( bFixed
?
321 static_cast<const SvxDateField
*>(pData
)->GetFixDate() :
322 Date( Date::SYSTEM
).GetDate() );
323 mpImpl
->mnInt32
= static_cast<const SvxDateField
*>(pData
)->GetFormat();
324 mpImpl
->mbBoolean1
= bFixed
;
328 case text::textfield::Type::TIME
:
329 mpImpl
->mbBoolean2
= false;
330 mpImpl
->mbBoolean1
= false;
331 mpImpl
->mnInt32
= SVXTIMEFORMAT_STANDARD
;
334 case text::textfield::Type::EXTENDED_TIME
:
335 mpImpl
->mbBoolean2
= false;
336 mpImpl
->maDateTime
= getTime( static_cast<const SvxExtTimeField
*>(pData
)->GetFixTime() );
337 mpImpl
->mbBoolean1
= static_cast<const SvxExtTimeField
*>(pData
)->GetType() == SVXTIMETYPE_FIX
;
338 mpImpl
->mnInt32
= static_cast<const SvxExtTimeField
*>(pData
)->GetFormat();
341 case text::textfield::Type::URL
:
342 mpImpl
->msString1
= static_cast<const SvxURLField
*>(pData
)->GetRepresentation();
343 mpImpl
->msString2
= static_cast<const SvxURLField
*>(pData
)->GetTargetFrame();
344 mpImpl
->msString3
= static_cast<const SvxURLField
*>(pData
)->GetURL();
345 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(
346 static_cast<const SvxURLField
*>(pData
)->GetFormat());
349 case text::textfield::Type::EXTENDED_FILE
:
350 mpImpl
->msString1
= static_cast<const SvxExtFileField
*>(pData
)->GetFile();
351 mpImpl
->mbBoolean1
= static_cast<const SvxExtFileField
*>(pData
)->GetType() == SVXFILETYPE_FIX
;
352 mpImpl
->mnInt16
= getFileNameDisplayFormat(static_cast<const SvxExtFileField
*>(pData
)->GetFormat());
355 case text::textfield::Type::AUTHOR
:
356 mpImpl
->msString1
= static_cast<const SvxAuthorField
*>(pData
)->GetFormatted();
357 mpImpl
->msString2
= static_cast<const SvxAuthorField
*>(pData
)->GetFormatted();
358 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(
359 static_cast<const SvxAuthorField
*>(pData
)->GetFormat());
360 mpImpl
->mbBoolean1
= static_cast<const SvxAuthorField
*>(pData
)->GetType() == SVXAUTHORTYPE_FIX
;
361 mpImpl
->mbBoolean2
= static_cast<const SvxAuthorField
*>(pData
)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME
;
364 case text::textfield::Type::MEASURE
:
365 mpImpl
->mnInt16
= sal::static_int_cast
< sal_Int16
>(static_cast<const SdrMeasureField
*>(pData
)->GetMeasureFieldKind());
369 SAL_WARN("editeng.uno", "Id service unknown: " << mnServiceId
);
375 mpPropSet
= ImplGetFieldItemPropertySet(mnServiceId
);
378 SvxUnoTextField::~SvxUnoTextField() throw()
383 SvxFieldData
* SvxUnoTextField::CreateFieldData() const throw()
385 SvxFieldData
* pData
= NULL
;
387 switch( mnServiceId
)
389 case text::textfield::Type::TIME
:
390 case text::textfield::Type::EXTENDED_TIME
:
391 case text::textfield::Type::DATE
:
393 if( mpImpl
->mbBoolean2
) // IsDate?
395 Date
aDate( setDate( mpImpl
->maDateTime
) );
396 pData
= new SvxDateField( aDate
, mpImpl
->mbBoolean1
?SVXDATETYPE_FIX
:SVXDATETYPE_VAR
);
397 if( mpImpl
->mnInt32
>= SVXDATEFORMAT_APPDEFAULT
&& mpImpl
->mnInt32
<= SVXDATEFORMAT_F
)
398 static_cast<SvxDateField
*>(pData
)->SetFormat( (SvxDateFormat
)mpImpl
->mnInt32
);
402 if( mnServiceId
!= text::textfield::Type::TIME
&& mnServiceId
!= text::textfield::Type::DATE
)
404 tools::Time
aTime( setTime( mpImpl
->maDateTime
) );
405 pData
= new SvxExtTimeField( aTime
, mpImpl
->mbBoolean1
?SVXTIMETYPE_FIX
:SVXTIMETYPE_VAR
);
407 if( mpImpl
->mnInt32
>= SVXTIMEFORMAT_APPDEFAULT
&& mpImpl
->mnInt32
<= SVXTIMEFORMAT_AM_HMSH
)
408 static_cast<SvxExtTimeField
*>(pData
)->SetFormat( (SvxTimeFormat
)mpImpl
->mnInt32
);
412 pData
= new SvxTimeField();
419 case text::textfield::Type::URL
:
420 pData
= new SvxURLField( mpImpl
->msString3
, mpImpl
->msString1
, !mpImpl
->msString1
.isEmpty() ? SVXURLFORMAT_REPR
: SVXURLFORMAT_URL
);
421 static_cast<SvxURLField
*>(pData
)->SetTargetFrame( mpImpl
->msString2
);
422 if( mpImpl
->mnInt16
>= SVXURLFORMAT_APPDEFAULT
&& mpImpl
->mnInt16
<= SVXURLFORMAT_REPR
)
423 static_cast<SvxURLField
*>(pData
)->SetFormat( (SvxURLFormat
)mpImpl
->mnInt16
);
426 case text::textfield::Type::PAGE
:
427 pData
= new SvxPageField();
430 case text::textfield::Type::PAGES
:
431 pData
= new SvxPagesField();
434 case text::textfield::Type::DOCINFO_TITLE
:
435 pData
= new SvxFileField();
438 case text::textfield::Type::TABLE
:
439 pData
= new SvxTableField();
442 case text::textfield::Type::EXTENDED_FILE
:
444 // #92009# pass fixed attribute to constructor
445 pData
= new SvxExtFileField( mpImpl
->msString1
,
446 mpImpl
->mbBoolean1
? SVXFILETYPE_FIX
: SVXFILETYPE_VAR
,
447 setFileNameDisplayFormat(mpImpl
->mnInt16
) );
451 case text::textfield::Type::AUTHOR
:
458 // do we have CurrentPresentation given?
459 // mimic behaviour of writer, which means:
460 // prefer CurrentPresentation over Content
461 // if both are given.
462 if( !mpImpl
->msString1
.isEmpty() )
463 aContent
= mpImpl
->msString1
;
465 aContent
= mpImpl
->msString2
;
467 sal_Int32 nPos
= aContent
.lastIndexOf( sal_Char(' '), 0 );
470 aFirstName
= aContent
.copy( 0, nPos
);
471 aLastName
= aContent
.copy( nPos
+ 1 );
475 aLastName
= aContent
;
478 // #92009# pass fixed attribute to constructor
479 pData
= new SvxAuthorField( aFirstName
, aLastName
, aEmpty
,
480 mpImpl
->mbBoolean1
? SVXAUTHORTYPE_FIX
: SVXAUTHORTYPE_VAR
);
482 if( !mpImpl
->mbBoolean2
)
484 static_cast<SvxAuthorField
*>(pData
)->SetFormat( SVXAUTHORFORMAT_SHORTNAME
);
486 else if( mpImpl
->mnInt16
>= SVXAUTHORFORMAT_FULLNAME
|| mpImpl
->mnInt16
<= SVXAUTHORFORMAT_SHORTNAME
)
488 static_cast<SvxAuthorField
*>(pData
)->SetFormat( (SvxAuthorFormat
) mpImpl
->mnInt16
);
494 case text::textfield::Type::MEASURE
:
496 SdrMeasureFieldKind eKind
= SDRMEASUREFIELD_VALUE
;
497 if( mpImpl
->mnInt16
== (sal_Int16
)SDRMEASUREFIELD_UNIT
|| mpImpl
->mnInt16
== (sal_Int16
)SDRMEASUREFIELD_ROTA90BLANCS
)
498 eKind
= (SdrMeasureFieldKind
) mpImpl
->mnInt16
;
499 pData
= new SdrMeasureField( eKind
);
502 case text::textfield::Type::PRESENTATION_HEADER
:
503 pData
= new SvxHeaderField();
505 case text::textfield::Type::PRESENTATION_FOOTER
:
506 pData
= new SvxFooterField();
508 case text::textfield::Type::PRESENTATION_DATE_TIME
:
509 pData
= new SvxDateTimeField();
511 case text::textfield::Type::PAGE_NAME
:
512 pData
= new SvxPageTitleField();
520 uno::Any SAL_CALL
SvxUnoTextField::queryAggregation( const uno::Type
& rType
)
521 throw(uno::RuntimeException
, std::exception
)
525 QUERYINT( beans::XPropertySet
);
526 else QUERYINT( text::XTextContent
);
527 else QUERYINT( text::XTextField
);
528 else QUERYINT( lang::XServiceInfo
);
529 else QUERYINT( lang::XUnoTunnel
);
531 return OComponentHelper::queryAggregation( rType
);
538 uno::Sequence
< uno::Type
> SAL_CALL
SvxUnoTextField::getTypes()
539 throw (uno::RuntimeException
, std::exception
)
541 if( maTypeSequence
.getLength() == 0 )
543 maTypeSequence
= OComponentHelper::getTypes();
544 sal_Int32 nOldCount
= maTypeSequence
.getLength();
546 maTypeSequence
.realloc( nOldCount
+ 4 ); // !DANGER! keep this updated
547 uno::Type
* pTypes
= &maTypeSequence
.getArray()[nOldCount
];
549 *pTypes
++ = cppu::UnoType
<text::XTextField
>::get();
550 *pTypes
++ = cppu::UnoType
<beans::XPropertySet
>::get();
551 *pTypes
++ = cppu::UnoType
<lang::XServiceInfo
>::get();
552 *pTypes
++ = cppu::UnoType
<lang::XUnoTunnel
>::get();
554 return maTypeSequence
;
557 uno::Sequence
< sal_Int8
> SAL_CALL
SvxUnoTextField::getImplementationId()
558 throw (uno::RuntimeException
, std::exception
)
560 return css::uno::Sequence
<sal_Int8
>();
563 uno::Any SAL_CALL
SvxUnoTextField::queryInterface( const uno::Type
& rType
)
564 throw(uno::RuntimeException
, std::exception
)
566 return OComponentHelper::queryInterface(rType
);
569 void SAL_CALL
SvxUnoTextField::acquire() throw( )
571 OComponentHelper::acquire();
574 void SAL_CALL
SvxUnoTextField::release() throw( )
576 OComponentHelper::release();
579 // Interface text::XTextField
580 OUString SAL_CALL
SvxUnoTextField::getPresentation( sal_Bool bShowCommand
)
581 throw(uno::RuntimeException
, std::exception
)
583 SolarMutexGuard aGuard
;
588 case text::textfield::Type::DATE
:
589 return OUString("Date");
590 case text::textfield::Type::URL
:
591 return OUString("URL");
592 case text::textfield::Type::PAGE
:
593 return OUString("Page");
594 case text::textfield::Type::PAGES
:
595 return OUString("Pages");
596 case text::textfield::Type::TIME
:
597 return OUString("Time");
598 case text::textfield::Type::DOCINFO_TITLE
:
599 return OUString("File");
600 case text::textfield::Type::TABLE
:
601 return OUString("Table");
602 case text::textfield::Type::EXTENDED_TIME
:
603 return OUString("ExtTime");
604 case text::textfield::Type::EXTENDED_FILE
:
605 return OUString("ExtFile");
606 case text::textfield::Type::AUTHOR
:
607 return OUString("Author");
608 case text::textfield::Type::MEASURE
:
609 return OUString("Measure");
610 case text::textfield::Type::PRESENTATION_HEADER
:
611 return OUString("Header");
612 case text::textfield::Type::PRESENTATION_FOOTER
:
613 return OUString("Footer");
614 case text::textfield::Type::PRESENTATION_DATE_TIME
:
615 return OUString("DateTime");
616 case text::textfield::Type::PAGE_NAME
:
617 return OUString("PageName");
619 return OUString("Unknown");
624 return mpImpl
->msPresentation
;
628 // Interface text::XTextContent
629 void SAL_CALL
SvxUnoTextField::attach( const uno::Reference
< text::XTextRange
>& xTextRange
)
630 throw(lang::IllegalArgumentException
, uno::RuntimeException
, std::exception
)
632 SvxUnoTextRangeBase
* pRange
= SvxUnoTextRange::getImplementation( xTextRange
);
634 throw lang::IllegalArgumentException();
636 SvxFieldData
* pData
= CreateFieldData();
638 pRange
->attachField( pData
);
643 uno::Reference
< text::XTextRange
> SAL_CALL
SvxUnoTextField::getAnchor()
644 throw(uno::RuntimeException
, std::exception
)
650 void SAL_CALL
SvxUnoTextField::dispose()
651 throw(uno::RuntimeException
, std::exception
)
653 OComponentHelper::dispose();
656 void SAL_CALL
SvxUnoTextField::addEventListener( const uno::Reference
< lang::XEventListener
>& xListener
)
657 throw(uno::RuntimeException
, std::exception
)
659 OComponentHelper::addEventListener(xListener
);
662 void SAL_CALL
SvxUnoTextField::removeEventListener( const uno::Reference
< lang::XEventListener
>& aListener
)
663 throw(uno::RuntimeException
, std::exception
)
665 OComponentHelper::removeEventListener(aListener
);
669 // Interface beans::XPropertySet
670 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
SvxUnoTextField::getPropertySetInfo( )
671 throw(uno::RuntimeException
, std::exception
)
673 SolarMutexGuard aGuard
;
674 return mpPropSet
->getPropertySetInfo();
677 void SAL_CALL
SvxUnoTextField::setPropertyValue( const OUString
& aPropertyName
, const uno::Any
& aValue
)
678 throw(beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
680 SolarMutexGuard aGuard
;
683 throw uno::RuntimeException();
685 if (aPropertyName
== UNO_TC_PROP_ANCHOR
)
691 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( aPropertyName
);
693 throw beans::UnknownPropertyException();
698 if(aValue
>>= mpImpl
->maDateTime
)
702 if(aValue
>>= mpImpl
->mbBoolean1
)
706 if(aValue
>>= mpImpl
->mbBoolean2
)
710 if(aValue
>>= mpImpl
->mnInt16
)
714 if(aValue
>>= mpImpl
->mnInt32
)
718 if(aValue
>>= mpImpl
->msString1
)
722 if(aValue
>>= mpImpl
->msString2
)
726 if(aValue
>>= mpImpl
->msString3
)
731 throw lang::IllegalArgumentException();
734 uno::Any SAL_CALL
SvxUnoTextField::getPropertyValue( const OUString
& PropertyName
)
735 throw(beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
737 SolarMutexGuard aGuard
;
739 if (PropertyName
== UNO_TC_PROP_ANCHOR
)
740 return uno::makeAny(mxAnchor
);
742 if (PropertyName
== UNO_TC_PROP_TEXTFIELD_TYPE
)
743 return uno::makeAny(mnServiceId
);
747 const SfxItemPropertySimpleEntry
* pMap
= mpPropSet
->getPropertyMap().getByName( PropertyName
);
749 throw beans::UnknownPropertyException();
754 aValue
<<= mpImpl
->maDateTime
;
757 aValue
<<= mpImpl
->mbBoolean1
;
760 aValue
<<= mpImpl
->mbBoolean2
;
763 aValue
<<= mpImpl
->mnInt16
;
766 aValue
<<= mpImpl
->mnInt32
;
769 aValue
<<= mpImpl
->msString1
;
772 aValue
<<= mpImpl
->msString2
;
775 aValue
<<= mpImpl
->msString3
;
782 void SAL_CALL
SvxUnoTextField::addPropertyChangeListener( const OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
783 void SAL_CALL
SvxUnoTextField::removePropertyChangeListener( const OUString
&, const uno::Reference
< beans::XPropertyChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
784 void SAL_CALL
SvxUnoTextField::addVetoableChangeListener( const OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
785 void SAL_CALL
SvxUnoTextField::removeVetoableChangeListener( const OUString
&, const uno::Reference
< beans::XVetoableChangeListener
>& ) throw(::com::sun::star::beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
) {}
788 void SvxUnoTextField::disposing()
793 // lang::XServiceInfo
794 OUString SAL_CALL
SvxUnoTextField::getImplementationName() throw(uno::RuntimeException
, std::exception
)
796 return OUString("SvxUnoTextField");
799 uno::Sequence
< OUString
> SAL_CALL
SvxUnoTextField::getSupportedServiceNames()
800 throw(uno::RuntimeException
, std::exception
)
802 uno::Sequence
<OUString
> aSeq(4);
803 OUString
* pServices
= aSeq
.getArray();
804 pServices
[0] = "com.sun.star.text.TextContent";
805 pServices
[1] = "com.sun.star.text.TextField";
809 case text::textfield::Type::DATE
:
810 pServices
[2] = "com.sun.star.text.TextField.DateTime";
811 pServices
[3] = "com.sun.star.text.textfield.DateTime";
813 case text::textfield::Type::URL
:
814 pServices
[2] = "com.sun.star.text.TextField.URL";
815 pServices
[3] = "com.sun.star.text.textfield.URL";
817 case text::textfield::Type::PAGE
:
818 pServices
[2] = "com.sun.star.text.TextField.PageNumber";
819 pServices
[3] = "com.sun.star.text.textfield.PageNumber";
821 case text::textfield::Type::PAGES
:
822 pServices
[2] = "com.sun.star.text.TextField.PageCount";
823 pServices
[3] = "com.sun.star.text.textfield.PageCount";
825 case text::textfield::Type::TIME
:
826 pServices
[2] = "com.sun.star.text.TextField.DateTime";
827 pServices
[3] = "com.sun.star.text.textfield.DateTime";
829 case text::textfield::Type::DOCINFO_TITLE
:
830 pServices
[2] = "com.sun.star.text.TextField.docinfo.Title";
831 pServices
[3] = "com.sun.star.text.textfield.docinfo.Title";
833 case text::textfield::Type::TABLE
:
834 pServices
[2] = "com.sun.star.text.TextField.SheetName";
835 pServices
[3] = "com.sun.star.text.textfield.SheetName";
837 case text::textfield::Type::EXTENDED_TIME
:
838 pServices
[2] = "com.sun.star.text.TextField.DateTime";
839 pServices
[3] = "com.sun.star.text.textfield.DateTime";
841 case text::textfield::Type::EXTENDED_FILE
:
842 pServices
[2] = "com.sun.star.text.TextField.FileName";
843 pServices
[3] = "com.sun.star.text.textfield.FileName";
845 case text::textfield::Type::AUTHOR
:
846 pServices
[2] = "com.sun.star.text.TextField.Author";
847 pServices
[3] = "com.sun.star.text.textfield.Author";
849 case text::textfield::Type::MEASURE
:
850 pServices
[2] = "com.sun.star.text.TextField.Measure";
851 pServices
[3] = "com.sun.star.text.textfield.Measure";
853 case text::textfield::Type::PRESENTATION_HEADER
:
854 pServices
[2] = "com.sun.star.presentation.TextField.Header";
855 pServices
[3] = "com.sun.star.presentation.textfield.Header";
857 case text::textfield::Type::PRESENTATION_FOOTER
:
858 pServices
[2] = "com.sun.star.presentation.TextField.Footer";
859 pServices
[3] = "com.sun.star.presentation.textfield.Footer";
861 case text::textfield::Type::PRESENTATION_DATE_TIME
:
862 pServices
[2] = "com.sun.star.presentation.TextField.DateTime";
863 pServices
[3] = "com.sun.star.presentation.textfield.DateTime";
865 case text::textfield::Type::PAGE_NAME
:
866 pServices
[2] = "com.sun.star.text.TextField.PageName";
867 pServices
[3] = "com.sun.star.text.textfield.PageName";
876 sal_Bool SAL_CALL
SvxUnoTextField::supportsService( const OUString
& ServiceName
) throw( uno::RuntimeException
, std::exception
)
878 return cppu::supportsService( this, ServiceName
);
881 uno::Reference
< uno::XInterface
> SAL_CALL
SvxUnoTextCreateTextField( const OUString
& ServiceSpecifier
) throw(::com::sun::star::uno::Exception
, ::com::sun::star::uno::RuntimeException
)
883 uno::Reference
< uno::XInterface
> xRet
;
885 const OUString
aTextFieldPrexit( "com.sun.star.text.textfield." );
887 // #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
888 // fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
889 const OUString
aTextFieldPrexit2( "com.sun.star.text.TextField." );
891 if( (ServiceSpecifier
.startsWith( aTextFieldPrexit
)) ||
892 (ServiceSpecifier
.startsWith( aTextFieldPrexit2
)) )
894 OUString
aFieldType( ServiceSpecifier
.copy( aTextFieldPrexit
.getLength() ) );
896 sal_Int32 nId
= text::textfield::Type::UNSPECIFIED
;
898 if ( aFieldType
== "DateTime" )
900 nId
= text::textfield::Type::DATE
;
902 else if ( aFieldType
== "URL" )
904 nId
= text::textfield::Type::URL
;
906 else if ( aFieldType
== "PageNumber" )
908 nId
= text::textfield::Type::PAGE
;
910 else if ( aFieldType
== "PageCount" )
912 nId
= text::textfield::Type::PAGES
;
914 else if ( aFieldType
== "SheetName" )
916 nId
= text::textfield::Type::TABLE
;
918 else if ( aFieldType
== "FileName" )
920 nId
= text::textfield::Type::EXTENDED_FILE
;
922 else if (aFieldType
== "docinfo.Title" ||
923 aFieldType
== "DocInfo.Title" )
925 nId
= text::textfield::Type::DOCINFO_TITLE
;
927 else if ( aFieldType
== "Author" )
929 nId
= text::textfield::Type::AUTHOR
;
931 else if ( aFieldType
== "Measure" )
933 nId
= text::textfield::Type::MEASURE
;
936 if (nId
!= text::textfield::Type::UNSPECIFIED
)
937 xRet
= (::cppu::OWeakObject
* )new SvxUnoTextField( nId
);
943 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */