1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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>
27
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>
38
39 #include <editeng/unonames.hxx>
40
41 using namespace ::cppu;
42 using namespace ::com::sun::star;
43
44 #define QUERYINT( xint ) \
45 if( rType == cppu::UnoType<xint>::get() ) \
46 aAny <<= uno::Reference< xint >(this)
47
48
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
57
58 class SvxUnoFieldData_Impl
59 {
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;
69
70 OUString msPresentation;
71 };
72
ImplGetFieldItemPropertySet(sal_Int32 mnId)73 static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
74 {
75 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
76 {
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 }
82 };
83 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
84
85 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
86 {
87 { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
88 { OUString(), 0, css::uno::Type(), 0, 0 }
89 };
90 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
91
92 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
93 {
94
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 }
100 };
101 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
102
103 static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
104 {
105 { OUString(), 0, css::uno::Type(), 0, 0 }
106 };
107 static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
108
109 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
110 {
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 }
115 };
116 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
117
118 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
119 {
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 }
126 };
127 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
128
129 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
130 {
131 { OUString(UNO_TC_PROP_MEASURE_KIND), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
132 { OUString(), 0, css::uno::Type(), 0, 0 }
133 };
134 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
135
136 static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
137 {
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 }
144 };
145 static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
146
147 switch( mnId )
148 {
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;
166 }
167 }
168
169 /* conversion routines */
170
getFileNameDisplayFormat(SvxFileFormat nFormat)171 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
172 {
173 switch( nFormat )
174 {
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;
180 }
181 }
182
setFileNameDisplayFormat(sal_Int16 nFormat)183 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
184 {
185 switch( nFormat )
186 {
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;
193 }
194 }
195
getDate(sal_Int32 nDate)196 static util::DateTime getDate( sal_Int32 nDate )
197 {
198 util::DateTime aDate;
199
200 Date aTempDate( nDate );
201
202 aDate.Day = aTempDate.GetDay();
203 aDate.Month = aTempDate.GetMonth();
204 aDate.Year = aTempDate.GetYear();
205
206 return aDate;
207 }
208
setDate(util::DateTime const & rDate)209 static Date setDate( util::DateTime const & rDate )
210 {
211 return Date( rDate.Day, rDate.Month, rDate.Year );
212 }
213
getTime(sal_Int64 const nTime)214 static util::DateTime getTime(sal_Int64 const nTime)
215 {
216 util::DateTime aTime;
217
218 tools::Time aTempTime( nTime );
219
220 aTime.NanoSeconds = aTempTime.GetNanoSec();
221 aTime.Seconds = aTempTime.GetSec();
222 aTime.Minutes = aTempTime.GetMin();
223 aTime.Hours = aTempTime.GetHour();
224
225 return aTime;
226 }
227
setTime(util::DateTime const & rDate)228 static tools::Time setTime( util::DateTime const & rDate )
229 {
230 return tools::Time( rDate );
231 }
232
233
234 // class SvxUnoTextField
235
236 namespace
237 {
238 class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
239 }
240
getUnoTunnelId()241 const css::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
242 {
243 return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
244 }
245
getSomething(const css::uno::Sequence<sal_Int8> & rId)246 sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const css::uno::Sequence< sal_Int8 >& rId )
247 {
248 if( isUnoTunnelId<SvxUnoTextField>(rId) )
249 {
250 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
251 }
252 return 0;
253 }
254
SvxUnoTextField(sal_Int32 nServiceId)255 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
256 : OComponentHelper( getMutex() )
257 , mpPropSet(nullptr)
258 , mnServiceId(nServiceId)
259 , mpImpl( new SvxUnoFieldData_Impl )
260 {
261 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
262
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;
271
272 switch( nServiceId )
273 {
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;
279
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;
286
287 case text::textfield::Type::URL:
288 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
289 break;
290
291 case text::textfield::Type::EXTENDED_FILE:
292 mpImpl->mbBoolean1 = false;
293 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
294 break;
295
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;
301
302 case text::textfield::Type::MEASURE:
303 mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
304 break;
305
306 case text::textfield::Type::DOCINFO_CUSTOM:
307 mpImpl->mbBoolean1 = true;
308 mpImpl->mbBoolean2 = true;
309 mpImpl->mnInt32 = 0;
310 break;
311
312 default:
313 mpImpl->mbBoolean1 = false;
314 mpImpl->mbBoolean2 = false;
315 mpImpl->mnInt32 = 0;
316 mpImpl->mnInt16 = 0;
317
318 }
319 }
320
SvxUnoTextField(uno::Reference<text::XTextRange> const & xAnchor,const OUString & rPresentation,const SvxFieldData * pData)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 )
327 {
328 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
329
330 mpImpl->msPresentation = rPresentation;
331
332 if(pData)
333 {
334 mnServiceId = pData->GetClassId();
335 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
336 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
337 {
338 // extract field properties from data class
339 switch( mnServiceId )
340 {
341 case text::textfield::Type::DATE:
342 {
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;
352 }
353 break;
354
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;
360
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;
367
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;
375
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;
381
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;
390
391 case text::textfield::Type::MEASURE:
392 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
393 break;
394
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;
402
403 default:
404 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
405 break;
406 }
407 }
408 }
409
410 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
411 }
412
~SvxUnoTextField()413 SvxUnoTextField::~SvxUnoTextField() throw()
414 {
415 }
416
CreateFieldData() const417 std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const throw()
418 {
419 std::unique_ptr<SvxFieldData> pData;
420
421 switch( mnServiceId )
422 {
423 case text::textfield::Type::TIME:
424 case text::textfield::Type::EXTENDED_TIME:
425 case text::textfield::Type::DATE:
426 {
427 if( mpImpl->mbBoolean2 ) // IsDate?
428 {
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) );
434 }
435 else
436 {
437 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
438 {
439 tools::Time aTime( setTime( mpImpl->maDateTime ) );
440 pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
441
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) );
445 }
446 else
447 {
448 pData.reset( new SvxTimeField() );
449 }
450 }
451
452 }
453 break;
454
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;
462
463 case text::textfield::Type::PAGE:
464 pData.reset( new SvxPageField() );
465 break;
466
467 case text::textfield::Type::PAGES:
468 pData.reset( new SvxPagesField() );
469 break;
470
471 case text::textfield::Type::DOCINFO_TITLE:
472 pData.reset( new SvxFileField() );
473 break;
474
475 case text::textfield::Type::TABLE:
476 pData.reset( new SvxTableField() );
477 break;
478
479 case text::textfield::Type::EXTENDED_FILE:
480 {
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;
486 }
487
488 case text::textfield::Type::AUTHOR:
489 {
490 OUString aContent;
491 OUString aFirstName;
492 OUString aLastName;
493
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;
502
503 sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
504 if( nPos > 0 )
505 {
506 aFirstName = aContent.copy( 0, nPos );
507 aLastName = aContent.copy( nPos + 1 );
508 }
509 else
510 {
511 aLastName = aContent;
512 }
513
514 // #92009# pass fixed attribute to constructor
515 pData.reset( new SvxAuthorField( aFirstName, aLastName, "",
516 mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
517
518 if( !mpImpl->mbBoolean2 )
519 {
520 static_cast<SvxAuthorField*>(pData.get())->SetFormat( SvxAuthorFormat::ShortName );
521 }
522 else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
523 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
524 {
525 static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
526 }
527
528 break;
529 }
530
531 case text::textfield::Type::MEASURE:
532 {
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;
538 }
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;
554 };
555
556 return pData;
557 }
558
559 // uno::XInterface
queryAggregation(const uno::Type & rType)560 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
561 {
562 uno::Any aAny;
563
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 );
571
572 return aAny;
573 }
574
575 // XTypeProvider
576
getTypes()577 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
578 {
579 if( !maTypeSequence.hasElements() )
580 {
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() });
588 }
589 return maTypeSequence;
590 }
591
getImplementationId()592 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
593 {
594 return css::uno::Sequence<sal_Int8>();
595 }
596
queryInterface(const uno::Type & rType)597 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
598 {
599 return OComponentHelper::queryInterface(rType);
600 }
601
acquire()602 void SAL_CALL SvxUnoTextField::acquire() throw( )
603 {
604 OComponentHelper::acquire();
605 }
606
release()607 void SAL_CALL SvxUnoTextField::release() throw( )
608 {
609 OComponentHelper::release();
610 }
611
612 // Interface text::XTextField
getPresentation(sal_Bool bShowCommand)613 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
614 {
615 SolarMutexGuard aGuard;
616 if (bShowCommand)
617 {
618 switch (mnServiceId)
619 {
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";
654 }
655 }
656 else
657 {
658 return mpImpl->msPresentation;
659 }
660 }
661
662 // Interface text::XTextContent
attach(const uno::Reference<text::XTextRange> & xTextRange)663 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
664 {
665 SvxUnoTextRangeBase* pRange = comphelper::getUnoTunnelImplementation<SvxUnoTextRange>( xTextRange );
666 if(pRange == nullptr)
667 throw lang::IllegalArgumentException();
668
669 std::unique_ptr<SvxFieldData> pData = CreateFieldData();
670 if( pData )
671 pRange->attachField( std::move(pData) );
672 }
673
getAnchor()674 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
675 {
676 return mxAnchor;
677 }
678
679 // lang::XComponent
dispose()680 void SAL_CALL SvxUnoTextField::dispose()
681 {
682 OComponentHelper::dispose();
683 }
684
addEventListener(const uno::Reference<lang::XEventListener> & xListener)685 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
686 {
687 OComponentHelper::addEventListener(xListener);
688 }
689
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)690 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
691 {
692 OComponentHelper::removeEventListener(aListener);
693 }
694
695
696 // Interface beans::XPropertySet
getPropertySetInfo()697 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
698 {
699 SolarMutexGuard aGuard;
700 return mpPropSet->getPropertySetInfo();
701 }
702
setPropertyValue(const OUString & aPropertyName,const uno::Any & aValue)703 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
704 {
705 SolarMutexGuard aGuard;
706
707 if( mpImpl == nullptr )
708 throw uno::RuntimeException();
709
710 if (aPropertyName == UNO_TC_PROP_ANCHOR)
711 {
712 aValue >>= mxAnchor;
713 return;
714 }
715
716 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
717 if ( !pMap )
718 throw beans::UnknownPropertyException(aPropertyName);
719
720 switch( pMap->nWID )
721 {
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;
754 }
755
756 throw lang::IllegalArgumentException();
757 }
758
getPropertyValue(const OUString & PropertyName)759 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
760 {
761 SolarMutexGuard aGuard;
762
763 if (PropertyName == UNO_TC_PROP_ANCHOR)
764 return uno::makeAny(mxAnchor);
765
766 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
767 return uno::makeAny(mnServiceId);
768
769 uno::Any aValue;
770
771 const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
772 if ( !pMap )
773 throw beans::UnknownPropertyException(PropertyName);
774
775 switch( pMap->nWID )
776 {
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;
801 }
802
803 return aValue;
804 }
805
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)806 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)807 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)808 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)809 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
810
811 // OComponentHelper
disposing()812 void SvxUnoTextField::disposing()
813 {
814 // nothing to do
815 }
816
817 // lang::XServiceInfo
getImplementationName()818 OUString SAL_CALL SvxUnoTextField::getImplementationName()
819 {
820 return "SvxUnoTextField";
821 }
822
getSupportedServiceNames()823 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
824 {
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";
829
830 switch (mnServiceId)
831 {
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);
898 }
899
900 return aSeq;
901 }
902
supportsService(const OUString & ServiceName)903 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
904 {
905 return cppu::supportsService( this, ServiceName );
906 }
907
SvxUnoTextCreateTextField(const OUString & ServiceSpecifier)908 uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( const OUString& ServiceSpecifier )
909 {
910 uno::Reference< uno::XInterface > xRet;
911
912 const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
913
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.
916
917 if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
918 (ServiceSpecifier.startsWith( "com.sun.star.text.TextField." )) )
919 {
920 OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
921
922 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
923
924 if ( aFieldType == "DateTime" )
925 {
926 nId = text::textfield::Type::DATE;
927 }
928 else if ( aFieldType == "URL" )
929 {
930 nId = text::textfield::Type::URL;
931 }
932 else if ( aFieldType == "PageNumber" )
933 {
934 nId = text::textfield::Type::PAGE;
935 }
936 else if ( aFieldType == "PageCount" )
937 {
938 nId = text::textfield::Type::PAGES;
939 }
940 else if ( aFieldType == "SheetName" )
941 {
942 nId = text::textfield::Type::TABLE;
943 }
944 else if ( aFieldType == "FileName" )
945 {
946 nId = text::textfield::Type::EXTENDED_FILE;
947 }
948 else if (aFieldType == "docinfo.Title" ||
949 aFieldType == "DocInfo.Title" )
950 {
951 nId = text::textfield::Type::DOCINFO_TITLE;
952 }
953 else if ( aFieldType == "Author" )
954 {
955 nId = text::textfield::Type::AUTHOR;
956 }
957 else if ( aFieldType == "Measure" )
958 {
959 nId = text::textfield::Type::MEASURE;
960 }
961 else if (aFieldType == "DocInfo.Custom")
962 {
963 nId = text::textfield::Type::DOCINFO_CUSTOM;
964 }
965
966 if (nId != text::textfield::Type::UNSPECIFIED)
967 xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId ));
968 }
969
970 return xRet;
971 }
972
973 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
974