LibreOffice Module editeng (master) 1
unofield.cxx
Go to the documentation of this file.
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 <sal/config.h>
21
22#include <string_view>
23
24#include <com/sun/star/util/DateTime.hpp>
25#include <com/sun/star/text/FilenameDisplayFormat.hpp>
26#include <o3tl/string_view.hxx>
27#include <utility>
28#include <vcl/svapp.hxx>
29#include <tools/debug.hxx>
30#include <svl/itemprop.hxx>
31
32#include <editeng/flditem.hxx>
34#include <editeng/measfld.hxx>
35#include <editeng/unofield.hxx>
36#include <editeng/unotext.hxx>
40#include <sal/log.hxx>
41
42#include <editeng/unonames.hxx>
43
44using namespace ::cppu;
45using namespace ::com::sun::star;
46
47#define QUERYINT( xint ) \
48 if( rType == cppu::UnoType<xint>::get() ) \
49 aAny <<= uno::Reference< xint >(this)
50
51
52#define WID_DATE 0
53#define WID_BOOL1 1
54#define WID_BOOL2 2
55#define WID_INT32 3
56#define WID_INT16 4
57#define WID_STRING1 5
58#define WID_STRING2 6
59#define WID_STRING3 7
60
62{
63public:
66 sal_Int32 mnInt32;
67 sal_Int16 mnInt16;
68 OUString msString1;
69 OUString msString2;
70 OUString msString3;
71 util::DateTime maDateTime;
72
74};
75
76static const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
77{
78 static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
79 {
84 };
85 static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
86
87 static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
88 {
90 };
91 static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
92
93 static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
94 {
99 };
100 static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
101
102 static const SfxItemPropertySet aEmptyPropertySet_Impl({});
103
104 static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
105 {
109 };
110 static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
111
112 static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
113 {
119 };
120 static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
121
122 static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
123 {
125 };
126 static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
127
128 static const SfxItemPropertyMapEntry aDocInfoCustomFieldPropertyMap_Impl[] =
129 {
135 };
136 static const SfxItemPropertySet aDocInfoCustomFieldPropertySet_Impl(aDocInfoCustomFieldPropertyMap_Impl);
137
138 switch( mnId )
139 {
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;
155 default:
156 return &aEmptyPropertySet_Impl;
157 }
158}
159
160/* conversion routines */
161
162static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
163{
164 switch( nFormat )
165 {
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;
171 }
172}
173
174static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
175{
176 switch( nFormat )
177 {
178 case text::FilenameDisplayFormat::FULL: return SvxFileFormat::PathFull;
179 case text::FilenameDisplayFormat::PATH: return SvxFileFormat::PathOnly;
181// case text::FilenameDisplayFormat::NAME_AND_EXT:
182 default:
184 }
185}
186
187static util::DateTime getDate( sal_Int32 nDate )
188{
189 util::DateTime aDate;
190
191 Date aTempDate( nDate );
192
193 aDate.Day = aTempDate.GetDay();
194 aDate.Month = aTempDate.GetMonth();
195 aDate.Year = aTempDate.GetYear();
196
197 return aDate;
198}
199
200static Date setDate( util::DateTime const & rDate )
201{
202 return Date( rDate.Day, rDate.Month, rDate.Year );
203}
204
205static util::DateTime getTime(sal_Int64 const nTime)
206{
207 util::DateTime aTime;
208
209 tools::Time aTempTime( nTime );
210
211 aTime.NanoSeconds = aTempTime.GetNanoSec();
212 aTime.Seconds = aTempTime.GetSec();
213 aTime.Minutes = aTempTime.GetMin();
214 aTime.Hours = aTempTime.GetHour();
215
216 return aTime;
217}
218
219static tools::Time setTime( util::DateTime const & rDate )
220{
221 return tools::Time( rDate );
222}
223
224
225
226SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) noexcept
227: OComponentHelper( m_aMutex )
228, mpPropSet(nullptr)
229, mnServiceId(nServiceId)
230, mpImpl( new SvxUnoFieldData_Impl )
231{
232 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
233
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;
242
243 switch( nServiceId )
244 {
245 case text::textfield::Type::DATE:
246 mpImpl->mbBoolean2 = true;
247 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxDateFormat::StdSmall);
248 mpImpl->mbBoolean1 = false;
249 break;
250
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);
256 break;
257
258 case text::textfield::Type::URL:
259 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxURLFormat::Repr);
260 break;
261
262 case text::textfield::Type::EXTENDED_FILE:
263 mpImpl->mbBoolean1 = false;
264 mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
265 break;
266
267 case text::textfield::Type::AUTHOR:
268 mpImpl->mnInt16 = static_cast<sal_uInt16>(SvxAuthorFormat::FullName);
269 mpImpl->mbBoolean1 = false;
270 mpImpl->mbBoolean2 = true;
271 break;
272
273 case text::textfield::Type::MEASURE:
274 mpImpl->mnInt16 = static_cast<sal_uInt16>(SdrMeasureFieldKind::Value);
275 break;
276
277 case text::textfield::Type::DOCINFO_CUSTOM:
278 mpImpl->mbBoolean1 = true;
279 mpImpl->mbBoolean2 = true;
280 mpImpl->mnInt32 = 0;
281 break;
282
283 default:
284 mpImpl->mbBoolean1 = false;
285 mpImpl->mbBoolean2 = false;
286 mpImpl->mnInt32 = 0;
287 mpImpl->mnInt16 = 0;
288
289 }
290}
291
292SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) noexcept
293: OComponentHelper( m_aMutex )
294, mxAnchor(std::move( xAnchor ))
295, mpPropSet(nullptr)
296, mnServiceId(text::textfield::Type::UNSPECIFIED)
297, mpImpl( new SvxUnoFieldData_Impl )
298{
299 DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
300
301 mpImpl->msPresentation = rPresentation;
302
303 if(pData)
304 {
305 mnServiceId = pData->GetClassId();
306 DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
307 if (mnServiceId != text::textfield::Type::UNSPECIFIED)
308 {
309 // extract field properties from data class
310 switch( mnServiceId )
311 {
312 case text::textfield::Type::DATE:
313 {
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;
323 }
324 break;
325
326 case text::textfield::Type::TIME:
327 mpImpl->mbBoolean2 = false;
328 mpImpl->mbBoolean1 = false;
329 mpImpl->mnInt32 = static_cast<sal_Int32>(SvxTimeFormat::Standard);
330 break;
331
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());
337 break;
338
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());
345 break;
346
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());
351 break;
352
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;
360 break;
361
362 case text::textfield::Type::MEASURE:
363 mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
364 break;
365
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;
371 mpImpl->mnInt32 = 0;
372 break;
373
374 default:
375 SAL_WARN("editeng", "Id service unknown: " << mnServiceId);
376 break;
377 }
378 }
379 }
380
381 mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
382}
383
385{
386}
387
388std::unique_ptr<SvxFieldData> SvxUnoTextField::CreateFieldData() const noexcept
389{
390 std::unique_ptr<SvxFieldData> pData;
391
392 switch( mnServiceId )
393 {
394 case text::textfield::Type::TIME:
395 case text::textfield::Type::EXTENDED_TIME:
396 case text::textfield::Type::DATE:
397 {
398 if( mpImpl->mbBoolean2 ) // IsDate?
399 {
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) );
405 }
406 else
407 {
408 if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
409 {
410 tools::Time aTime( setTime( mpImpl->maDateTime ) );
411 pData.reset( new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SvxTimeType::Fix:SvxTimeType::Var ) );
412
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) );
416 }
417 else
418 {
419 pData.reset( new SvxTimeField() );
420 }
421 }
422
423 }
424 break;
425
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) );
432 break;
433
434 case text::textfield::Type::PAGE:
435 pData.reset( new SvxPageField() );
436 break;
437
438 case text::textfield::Type::PAGES:
439 pData.reset( new SvxPagesField() );
440 break;
441
442 case text::textfield::Type::DOCINFO_TITLE:
443 pData.reset( new SvxFileField() );
444 break;
445
446 case text::textfield::Type::TABLE:
447 pData.reset( new SvxTableField() );
448 break;
449
450 case text::textfield::Type::EXTENDED_FILE:
451 {
452 // #92009# pass fixed attribute to constructor
453 pData.reset( new SvxExtFileField( mpImpl->msString1,
455 setFileNameDisplayFormat(mpImpl->mnInt16 ) ) );
456 break;
457 }
458
459 case text::textfield::Type::AUTHOR:
460 {
461 OUString aContent;
462 OUString aFirstName;
463 OUString aLastName;
464
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;
471 else
472 aContent = mpImpl->msString2;
473
474 sal_Int32 nPos = aContent.lastIndexOf( ' ', 0 );
475 if( nPos > 0 )
476 {
477 aFirstName = aContent.copy( 0, nPos );
478 aLastName = aContent.copy( nPos + 1 );
479 }
480 else
481 {
482 aLastName = aContent;
483 }
484
485 // #92009# pass fixed attribute to constructor
486 pData.reset( new SvxAuthorField( aFirstName, aLastName, "",
487 mpImpl->mbBoolean1 ? SvxAuthorType::Fix : SvxAuthorType::Var ) );
488
489 if( !mpImpl->mbBoolean2 )
490 {
492 }
493 else if( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) >= SvxAuthorFormat::FullName &&
494 static_cast<SvxAuthorFormat>(mpImpl->mnInt16) <= SvxAuthorFormat::ShortName )
495 {
496 static_cast<SvxAuthorField*>(pData.get())->SetFormat( static_cast<SvxAuthorFormat>(mpImpl->mnInt16) );
497 }
498
499 break;
500 }
501
502 case text::textfield::Type::MEASURE:
503 {
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) );
508 break;
509 }
510 case text::textfield::Type::PRESENTATION_HEADER:
511 pData.reset( new SvxHeaderField() );
512 break;
513 case text::textfield::Type::PRESENTATION_FOOTER:
514 pData.reset( new SvxFooterField() );
515 break;
516 case text::textfield::Type::PRESENTATION_DATE_TIME:
517 pData.reset( new SvxDateTimeField() );
518 break;
519 case text::textfield::Type::PAGE_NAME:
520 pData.reset( new SvxPageTitleField() );
521 break;
522 case text::textfield::Type::DOCINFO_CUSTOM:
523 pData.reset( new editeng::CustomPropertyField(mpImpl->msString1, mpImpl->msString2) );
524 break;
525 }
526
527 return pData;
528}
529
530// uno::XInterface
532{
533 uno::Any aAny;
534
535 QUERYINT( beans::XPropertySet );
536 else QUERYINT( text::XTextContent );
537 else QUERYINT( text::XTextField );
538 else QUERYINT( lang::XServiceInfo );
539 else
540 return OComponentHelper::queryAggregation( rType );
541
542 return aAny;
543}
544
545// XTypeProvider
546
547uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
548{
549 if( !maTypeSequence.hasElements() )
550 {
552 OComponentHelper::getTypes(),
553 uno::Sequence {
558 }
559 return maTypeSequence;
560}
561
562uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
563{
564 return css::uno::Sequence<sal_Int8>();
565}
566
568{
569 return OComponentHelper::queryInterface(rType);
570}
571
572void SAL_CALL SvxUnoTextField::acquire() noexcept
573{
574 OComponentHelper::acquire();
575}
576
577void SAL_CALL SvxUnoTextField::release() noexcept
578{
579 OComponentHelper::release();
580}
581
582// Interface text::XTextField
583OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
584{
585 SolarMutexGuard aGuard;
586 if (bShowCommand)
587 {
588 switch (mnServiceId)
589 {
590 case text::textfield::Type::DATE:
591 return "Date";
592 case text::textfield::Type::URL:
593 return "URL";
594 case text::textfield::Type::PAGE:
595 return "Page";
596 case text::textfield::Type::PAGES:
597 return "Pages";
598 case text::textfield::Type::TIME:
599 return "Time";
600 case text::textfield::Type::DOCINFO_TITLE:
601 return "File";
602 case text::textfield::Type::TABLE:
603 return "Table";
604 case text::textfield::Type::EXTENDED_TIME:
605 return "ExtTime";
606 case text::textfield::Type::EXTENDED_FILE:
607 return "ExtFile";
608 case text::textfield::Type::AUTHOR:
609 return "Author";
610 case text::textfield::Type::MEASURE:
611 return "Measure";
612 case text::textfield::Type::PRESENTATION_HEADER:
613 return "Header";
614 case text::textfield::Type::PRESENTATION_FOOTER:
615 return "Footer";
616 case text::textfield::Type::PRESENTATION_DATE_TIME:
617 return "DateTime";
618 case text::textfield::Type::PAGE_NAME:
619 return "PageName";
620 case text::textfield::Type::DOCINFO_CUSTOM:
621 return "Custom";
622 default:
623 return "Unknown";
624 }
625 }
626 else
627 {
628 return mpImpl->msPresentation;
629 }
630}
631
632// Interface text::XTextContent
633void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
634{
635 SvxUnoTextRangeBase* pRange = comphelper::getFromUnoTunnel<SvxUnoTextRange>( xTextRange );
636 if(pRange == nullptr)
637 throw lang::IllegalArgumentException();
638
639 std::unique_ptr<SvxFieldData> pData = CreateFieldData();
640 if( pData )
641 pRange->attachField( std::move(pData) );
642}
643
644uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
645{
646 return mxAnchor;
647}
648
649// lang::XComponent
651{
652 OComponentHelper::dispose();
653}
654
655void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
656{
657 OComponentHelper::addEventListener(xListener);
658}
659
660void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
661{
662 OComponentHelper::removeEventListener(aListener);
663}
664
665
666// Interface beans::XPropertySet
667uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
668{
669 SolarMutexGuard aGuard;
671}
672
673void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
674{
675 SolarMutexGuard aGuard;
676
677 if( mpImpl == nullptr )
678 throw uno::RuntimeException();
679
680 if (aPropertyName == UNO_TC_PROP_ANCHOR)
681 {
682 aValue >>= mxAnchor;
683 return;
684 }
685
686 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
687 if ( !pMap )
688 throw beans::UnknownPropertyException(aPropertyName);
689
690 switch( pMap->nWID )
691 {
692 case WID_DATE:
693 if(aValue >>= mpImpl->maDateTime)
694 return;
695 break;
696 case WID_BOOL1:
697 if(aValue >>= mpImpl->mbBoolean1)
698 return;
699 break;
700 case WID_BOOL2:
701 if(aValue >>= mpImpl->mbBoolean2)
702 return;
703 break;
704 case WID_INT16:
705 if(aValue >>= mpImpl->mnInt16)
706 return;
707 break;
708 case WID_INT32:
709 if(aValue >>= mpImpl->mnInt32)
710 return;
711 break;
712 case WID_STRING1:
713 if(aValue >>= mpImpl->msString1)
714 return;
715 break;
716 case WID_STRING2:
717 if(aValue >>= mpImpl->msString2)
718 return;
719 break;
720 case WID_STRING3:
721 if(aValue >>= mpImpl->msString3)
722 return;
723 break;
724 }
725
726 throw lang::IllegalArgumentException();
727}
728
729uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
730{
731 SolarMutexGuard aGuard;
732
733 if (PropertyName == UNO_TC_PROP_ANCHOR)
734 return uno::Any(mxAnchor);
735
736 if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
737 return uno::Any(mnServiceId);
738
739 uno::Any aValue;
740
741 const SfxItemPropertyMapEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
742 if ( !pMap )
743 throw beans::UnknownPropertyException(PropertyName);
744
745 switch( pMap->nWID )
746 {
747 case WID_DATE:
748 aValue <<= mpImpl->maDateTime;
749 break;
750 case WID_BOOL1:
751 aValue <<= mpImpl->mbBoolean1;
752 break;
753 case WID_BOOL2:
754 aValue <<= mpImpl->mbBoolean2;
755 break;
756 case WID_INT16:
757 aValue <<= mpImpl->mnInt16;
758 break;
759 case WID_INT32:
760 aValue <<= mpImpl->mnInt32;
761 break;
762 case WID_STRING1:
763 aValue <<= mpImpl->msString1;
764 break;
765 case WID_STRING2:
766 aValue <<= mpImpl->msString2;
767 break;
768 case WID_STRING3:
769 aValue <<= mpImpl->msString3;
770 break;
771 }
772
773 return aValue;
774}
775
776void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
777void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) {}
778void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
779void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) {}
780
781// OComponentHelper
783{
784 // nothing to do
785}
786
787// lang::XServiceInfo
789{
790 return "SvxUnoTextField";
791}
792
793uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
794{
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";
799
800 switch (mnServiceId)
801 {
802 case text::textfield::Type::DATE:
803 pServices[2] = "com.sun.star.text.TextField.DateTime";
804 pServices[3] = "com.sun.star.text.textfield.DateTime";
805 break;
806 case text::textfield::Type::URL:
807 pServices[2] = "com.sun.star.text.TextField.URL";
808 pServices[3] = "com.sun.star.text.textfield.URL";
809 break;
810 case text::textfield::Type::PAGE:
811 pServices[2] = "com.sun.star.text.TextField.PageNumber";
812 pServices[3] = "com.sun.star.text.textfield.PageNumber";
813 break;
814 case text::textfield::Type::PAGES:
815 pServices[2] = "com.sun.star.text.TextField.PageCount";
816 pServices[3] = "com.sun.star.text.textfield.PageCount";
817 break;
818 case text::textfield::Type::TIME:
819 pServices[2] = "com.sun.star.text.TextField.DateTime";
820 pServices[3] = "com.sun.star.text.textfield.DateTime";
821 break;
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";
825 break;
826 case text::textfield::Type::TABLE:
827 pServices[2] = "com.sun.star.text.TextField.SheetName";
828 pServices[3] = "com.sun.star.text.textfield.SheetName";
829 break;
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";
833 break;
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";
837 break;
838 case text::textfield::Type::AUTHOR:
839 pServices[2] = "com.sun.star.text.TextField.Author";
840 pServices[3] = "com.sun.star.text.textfield.Author";
841 break;
842 case text::textfield::Type::MEASURE:
843 pServices[2] = "com.sun.star.text.TextField.Measure";
844 pServices[3] = "com.sun.star.text.textfield.Measure";
845 break;
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";
849 break;
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";
853 break;
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";
857 break;
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";
861 break;
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";
865 break;
866 default:
867 aSeq.realloc(0);
868 }
869
870 return aSeq;
871}
872
873sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName )
874{
875 return cppu::supportsService( this, ServiceName );
876}
877
878uno::Reference< uno::XInterface > SvxUnoTextCreateTextField( std::u16string_view ServiceSpecifier )
879{
880 uno::Reference< uno::XInterface > xRet;
881
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.
884
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 )) )
888 {
889 sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
890
891 if ( aFieldType == u"DateTime" )
892 {
893 nId = text::textfield::Type::DATE;
894 }
895 else if ( aFieldType == u"URL" )
896 {
897 nId = text::textfield::Type::URL;
898 }
899 else if ( aFieldType == u"PageNumber" )
900 {
901 nId = text::textfield::Type::PAGE;
902 }
903 else if ( aFieldType == u"PageCount" )
904 {
905 nId = text::textfield::Type::PAGES;
906 }
907 else if ( aFieldType == u"SheetName" )
908 {
909 nId = text::textfield::Type::TABLE;
910 }
911 else if ( aFieldType == u"FileName" )
912 {
913 nId = text::textfield::Type::EXTENDED_FILE;
914 }
915 else if (aFieldType == u"docinfo.Title" ||
916 aFieldType == u"DocInfo.Title" )
917 {
918 nId = text::textfield::Type::DOCINFO_TITLE;
919 }
920 else if ( aFieldType == u"Author" )
921 {
922 nId = text::textfield::Type::AUTHOR;
923 }
924 else if ( aFieldType == u"Measure" )
925 {
926 nId = text::textfield::Type::MEASURE;
927 }
928 else if (aFieldType == u"DocInfo.Custom")
929 {
930 nId = text::textfield::Type::DOCINFO_CUSTOM;
931 }
932
933 if (nId != text::textfield::Type::UNSPECIFIED)
934 xRet = getXWeak(new SvxUnoTextField( nId ));
935 }
936
937 return xRet;
938}
939
940/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int16 GetYear() const
sal_uInt16 GetDay() const
sal_uInt16 GetMonth() const
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
this field is used as a placeholder for a header&footer in impress.
Definition: flditem.hxx:421
this field is used as a placeholder for a header&footer in impress.
Definition: flditem.hxx:409
this field is used as a placeholder for a header&footer in impress.
Definition: flditem.hxx:396
OUString msPresentation
Definition: unofield.cxx:73
util::DateTime maDateTime
Definition: unofield.cxx:71
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: unofield.cxx:633
virtual void SAL_CALL disposing() override
Definition: unofield.cxx:782
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: unofield.cxx:793
std::unique_ptr< SvxUnoFieldData_Impl > mpImpl
Definition: unofield.hxx:53
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: unofield.cxx:562
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unofield.cxx:778
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unofield.cxx:779
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: unofield.cxx:667
virtual ~SvxUnoTextField() noexcept override
Definition: unofield.cxx:384
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unofield.cxx:873
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
Definition: unofield.cxx:567
virtual void SAL_CALL release() noexcept override
Definition: unofield.cxx:577
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
Definition: unofield.cxx:660
std::unique_ptr< SvxFieldData > CreateFieldData() const noexcept
Definition: unofield.cxx:388
css::uno::Sequence< css::uno::Type > maTypeSequence
Definition: unofield.hxx:54
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
Definition: unofield.cxx:583
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
Definition: unofield.cxx:777
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: unofield.cxx:547
SvxUnoTextField(sal_Int32 nServiceId) noexcept
Definition: unofield.cxx:226
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unofield.cxx:673
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unofield.cxx:729
virtual void SAL_CALL acquire() noexcept override
Definition: unofield.cxx:572
sal_Int32 mnServiceId
Definition: unofield.hxx:52
virtual OUString SAL_CALL getImplementationName() override
Definition: unofield.cxx:788
virtual css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
Definition: unofield.cxx:531
css::uno::Reference< css::text::XTextRange > mxAnchor
Definition: unofield.hxx:50
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
Definition: unofield.cxx:776
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
Definition: unofield.cxx:655
virtual void SAL_CALL dispose() override
Definition: unofield.cxx:650
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: unofield.cxx:644
const SfxItemPropertySet * mpPropSet
Definition: unofield.hxx:51
css::uno::Type const & get()
sal_uInt16 GetSec() const
sal_uInt16 GetMin() const
sal_uInt16 GetHour() const
sal_uInt32 GetNanoSec() const
#define DBG_ASSERT(sCon, aError)
sal_uInt16 mnId
virtual OUString GetName() const override
virtual OUString GetURL() const override
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
float u
SvxAuthorFormat
Definition: flditem.hxx:355
SvxURLFormat
Definition: flditem.hxx:138
SvxFileFormat
Definition: flditem.hxx:313
SvxTimeFormat
Definition: flditem.hxx:258
SvxDateFormat
Definition: flditem.hxx:89
sal_uInt16 nPos
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
SdrMeasureFieldKind
Definition: measfld.hxx:27
std::unique_ptr< sal_Int32[]> pData
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &rS1, const Ss &... rSn)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
sal_Int16 nId
void SetFormat(LotusContext &rContext, SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt8 nFormat, sal_uInt8 nSt)
unsigned char sal_Bool
#define WID_DATE
Definition: unofield.cxx:52
static tools::Time setTime(util::DateTime const &rDate)
Definition: unofield.cxx:219
static util::DateTime getDate(sal_Int32 nDate)
Definition: unofield.cxx:187
static Date setDate(util::DateTime const &rDate)
Definition: unofield.cxx:200
uno::Reference< uno::XInterface > SvxUnoTextCreateTextField(std::u16string_view ServiceSpecifier)
Definition: unofield.cxx:878
#define WID_STRING1
Definition: unofield.cxx:57
#define WID_STRING3
Definition: unofield.cxx:59
static SvxFileFormat setFileNameDisplayFormat(sal_Int16 nFormat)
Definition: unofield.cxx:174
#define WID_INT32
Definition: unofield.cxx:55
#define WID_STRING2
Definition: unofield.cxx:58
#define WID_INT16
Definition: unofield.cxx:56
static sal_Int16 getFileNameDisplayFormat(SvxFileFormat nFormat)
Definition: unofield.cxx:162
#define WID_BOOL2
Definition: unofield.cxx:54
#define QUERYINT(xint)
Definition: unofield.cxx:47
static const SfxItemPropertySet * ImplGetFieldItemPropertySet(sal_Int32 mnId)
Definition: unofield.cxx:76
static util::DateTime getTime(sal_Int64 const nTime)
Definition: unofield.cxx:205
#define WID_BOOL1
Definition: unofield.cxx:53
constexpr OUStringLiteral UNO_TC_PROP_NUMFORMAT
Definition: unonames.hxx:22
constexpr OUStringLiteral UNO_TC_PROP_AUTHOR_CONTENT
Definition: unonames.hxx:41
constexpr OUStringLiteral UNO_TC_PROP_DATE_TIME
Definition: unonames.hxx:26
constexpr OUStringLiteral UNO_TC_PROP_ANCHOR
Definition: unonames.hxx:16
constexpr OUStringLiteral UNO_TC_PROP_AUTHOR_FORMAT
Definition: unonames.hxx:42
constexpr OUStringLiteral UNO_TC_PROP_URL
Definition: unonames.hxx:32
constexpr OUStringLiteral UNO_TC_PROP_FILE_FORMAT
Definition: unonames.hxx:38
constexpr OUStringLiteral UNO_TC_PROP_IS_DATE
Definition: unonames.hxx:25
constexpr OUStringLiteral UNO_TC_PROP_IS_FIXED_LANGUAGE
Definition: unonames.hxx:21
constexpr OUStringLiteral UNO_TC_PROP_IS_FIXED
Definition: unonames.hxx:18
constexpr OUStringLiteral UNO_TC_PROP_URL_REPRESENTATION
Definition: unonames.hxx:30
constexpr OUStringLiteral UNO_TC_PROP_TEXTFIELD_TYPE
Definition: unonames.hxx:17
constexpr OUStringLiteral UNO_TC_PROP_URL_FORMAT
Definition: unonames.hxx:29
constexpr OUStringLiteral UNO_TC_PROP_CURRENT_PRESENTATION
Definition: unonames.hxx:19
constexpr OUStringLiteral UNO_TC_PROP_AUTHOR_FULLNAME
Definition: unonames.hxx:43
constexpr OUStringLiteral UNO_TC_PROP_NAME
Definition: unonames.hxx:20
constexpr OUStringLiteral UNO_TC_PROP_MEASURE_KIND
Definition: unonames.hxx:46
constexpr OUStringLiteral UNO_TC_PROP_URL_TARGET
Definition: unonames.hxx:31