Line data Source code
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 <osl/mutex.hxx>
26 :
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>
34 :
35 : #include "editeng/unonames.hxx"
36 :
37 : using namespace ::cppu;
38 : using namespace ::com::sun::star;
39 :
40 : #define QUERYINT( xint ) \
41 : if( rType == cppu::UnoType<xint>::get() ) \
42 : aAny <<= uno::Reference< xint >(this)
43 :
44 :
45 : #define WID_DATE 0
46 : #define WID_BOOL1 1
47 : #define WID_BOOL2 2
48 : #define WID_INT32 3
49 : #define WID_INT16 4
50 : #define WID_STRING1 5
51 : #define WID_STRING2 6
52 : #define WID_STRING3 7
53 :
54 2608 : class SvxUnoFieldData_Impl
55 : {
56 : public:
57 : bool mbBoolean1;
58 : bool mbBoolean2;
59 : sal_Int32 mnInt32;
60 : sal_Int16 mnInt16;
61 : OUString msString1;
62 : OUString msString2;
63 : OUString msString3;
64 : util::DateTime maDateTime;
65 :
66 : OUString msPresentation;
67 : };
68 :
69 1304 : const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
70 : {
71 : static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
72 : {
73 18 : { OUString(UNO_TC_PROP_DATE_TIME), WID_DATE, ::cppu::UnoType<util::DateTime>::get(), 0, 0 },
74 18 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
75 18 : { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
76 18 : { OUString(UNO_TC_PROP_NUMFORMAT), WID_INT32, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
77 : { OUString(), 0, css::uno::Type(), 0, 0 }
78 1394 : };
79 1304 : static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
80 :
81 : static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
82 : {
83 18 : { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
84 : { OUString(), 0, css::uno::Type(), 0, 0 }
85 1340 : };
86 1304 : static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
87 :
88 : static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
89 : {
90 :
91 18 : { OUString(UNO_TC_PROP_URL_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
92 18 : { OUString(UNO_TC_PROP_URL_REPRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
93 18 : { OUString(UNO_TC_PROP_URL_TARGET), WID_STRING2, ::cppu::UnoType<OUString>::get(), 0, 0 },
94 18 : { OUString(UNO_TC_PROP_URL), WID_STRING3, ::cppu::UnoType<OUString>::get(), 0, 0 },
95 : { OUString(), 0, css::uno::Type(), 0, 0 }
96 1394 : };
97 1304 : static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
98 :
99 : static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
100 : {
101 : { OUString(), 0, css::uno::Type(), 0, 0 }
102 1322 : };
103 1304 : static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
104 :
105 : static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
106 : {
107 18 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
108 18 : { OUString(UNO_TC_PROP_FILE_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
109 18 : { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1, ::cppu::UnoType<OUString>::get(), 0, 0 },
110 : { OUString(), 0, css::uno::Type(), 0, 0 }
111 1376 : };
112 1304 : static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
113 :
114 : static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
115 : {
116 18 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, cppu::UnoType<bool>::get(), 0, 0 },
117 18 : { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1,::cppu::UnoType<OUString>::get(), 0, 0 },
118 18 : { OUString(UNO_TC_PROP_AUTHOR_CONTENT), WID_STRING2,::cppu::UnoType<OUString>::get(), 0, 0 },
119 18 : { OUString(UNO_TC_PROP_AUTHOR_FORMAT), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
120 18 : { OUString(UNO_TC_PROP_AUTHOR_FULLNAME), WID_BOOL2, cppu::UnoType<bool>::get(), 0, 0 },
121 : { OUString(), 0, css::uno::Type(), 0, 0 }
122 1412 : };
123 1304 : static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
124 :
125 : static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
126 : {
127 18 : { OUString(UNO_TC_PROP_MEASURE_KIND), WID_INT16, ::cppu::UnoType<sal_Int16>::get(), 0, 0 },
128 : { OUString(), 0, css::uno::Type(), 0, 0 }
129 1340 : };
130 1304 : static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
131 :
132 1304 : switch( mnId )
133 : {
134 : case text::textfield::Type::EXTENDED_TIME:
135 : case text::textfield::Type::DATE:
136 181 : return &aExDateTimeFieldPropertySet_Impl;
137 : case text::textfield::Type::URL:
138 3 : return &aUrlFieldPropertySet_Impl;
139 : case text::textfield::Type::TIME:
140 11 : return &aDateTimeFieldPropertySet_Impl;
141 : case text::textfield::Type::EXTENDED_FILE:
142 1 : return &aExtFileFieldPropertySet_Impl;
143 : case text::textfield::Type::AUTHOR:
144 1 : return &aAuthorFieldPropertySet_Impl;
145 : case text::textfield::Type::MEASURE:
146 6 : return &aMeasureFieldPropertySet_Impl;
147 : default:
148 1101 : return &aEmptyPropertySet_Impl;
149 : }
150 : }
151 :
152 : /* conversion routines */
153 :
154 0 : static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
155 : {
156 0 : switch( nFormat )
157 : {
158 0 : case SVXFILEFORMAT_NAME_EXT: return text::FilenameDisplayFormat::NAME_AND_EXT;
159 0 : case SVXFILEFORMAT_FULLPATH: return text::FilenameDisplayFormat::FULL;
160 0 : case SVXFILEFORMAT_PATH: return text::FilenameDisplayFormat::PATH;
161 : // case SVXFILEFORMAT_NAME:
162 0 : default: return text::FilenameDisplayFormat::NAME;
163 : }
164 : }
165 :
166 0 : static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
167 : {
168 0 : switch( nFormat )
169 : {
170 0 : case text::FilenameDisplayFormat::FULL: return SVXFILEFORMAT_FULLPATH;
171 0 : case text::FilenameDisplayFormat::PATH: return SVXFILEFORMAT_PATH;
172 0 : case text::FilenameDisplayFormat::NAME: return SVXFILEFORMAT_NAME;
173 : // case text::FilenameDisplayFormat::NAME_AND_EXT:
174 : default:
175 0 : return SVXFILEFORMAT_NAME_EXT;
176 : }
177 : }
178 :
179 86 : static util::DateTime getDate( sal_uLong nDate )
180 : {
181 86 : util::DateTime aDate;
182 86 : memset( &aDate, 0, sizeof( util::DateTime ) );
183 :
184 86 : Date aTempDate( nDate );
185 :
186 86 : aDate.Day = aTempDate.GetDay();
187 86 : aDate.Month = aTempDate.GetMonth();
188 86 : aDate.Year = aTempDate.GetYear();
189 :
190 86 : return aDate;
191 : }
192 :
193 1 : inline Date setDate( util::DateTime& rDate )
194 : {
195 1 : return Date( rDate.Day, rDate.Month, rDate.Year );
196 : }
197 :
198 48 : static util::DateTime getTime(sal_Int64 const nTime)
199 : {
200 48 : util::DateTime aTime;
201 48 : memset( &aTime, 0, sizeof( util::DateTime ) );
202 :
203 48 : tools::Time aTempTime( nTime );
204 :
205 48 : aTime.NanoSeconds = aTempTime.GetNanoSec();
206 48 : aTime.Seconds = aTempTime.GetSec();
207 48 : aTime.Minutes = aTempTime.GetMin();
208 48 : aTime.Hours = aTempTime.GetHour();
209 :
210 48 : return aTime;
211 : }
212 :
213 0 : inline tools::Time setTime( util::DateTime& rDate )
214 : {
215 0 : return tools::Time( rDate );
216 : }
217 :
218 :
219 : // class SvxUnoTextField
220 :
221 : namespace
222 : {
223 : class theSvxUnoTextFieldUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSvxUnoTextFieldUnoTunnelId> {};
224 : }
225 :
226 0 : const ::com::sun::star::uno::Sequence< sal_Int8 > & SvxUnoTextField::getUnoTunnelId() throw()
227 : {
228 0 : return theSvxUnoTextFieldUnoTunnelId::get().getSeq();
229 : }
230 :
231 0 : sal_Int64 SAL_CALL SvxUnoTextField::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw(::com::sun::star::uno::RuntimeException, std::exception)
232 : {
233 0 : if( rId.getLength() == 16 && 0 == memcmp( getUnoTunnelId().getConstArray(),
234 0 : rId.getConstArray(), 16 ) )
235 : {
236 0 : return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(this));
237 : }
238 0 : return 0;
239 : }
240 :
241 563 : SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
242 563 : : OComponentHelper( getMutex() )
243 : , mpPropSet(NULL)
244 : , mnServiceId(nServiceId)
245 1126 : , mpImpl( new SvxUnoFieldData_Impl )
246 : {
247 563 : mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
248 :
249 563 : memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
250 :
251 563 : switch( nServiceId )
252 : {
253 : case text::textfield::Type::DATE:
254 46 : mpImpl->mbBoolean2 = true;
255 46 : mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
256 46 : mpImpl->mbBoolean1 = false;
257 46 : break;
258 :
259 : case text::textfield::Type::EXTENDED_TIME:
260 : case text::textfield::Type::TIME:
261 2 : mpImpl->mbBoolean2 = false;
262 2 : mpImpl->mbBoolean1 = false;
263 2 : mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
264 2 : break;
265 :
266 : case text::textfield::Type::URL:
267 3 : mpImpl->mnInt16 = SVXURLFORMAT_REPR;
268 3 : break;
269 :
270 : case text::textfield::Type::EXTENDED_FILE:
271 1 : mpImpl->mbBoolean1 = false;
272 1 : mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
273 1 : break;
274 :
275 : case text::textfield::Type::AUTHOR:
276 1 : mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
277 1 : mpImpl->mbBoolean1 = false;
278 1 : mpImpl->mbBoolean2 = true;
279 1 : break;
280 :
281 : case text::textfield::Type::MEASURE:
282 6 : mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
283 6 : break;
284 :
285 : default:
286 504 : mpImpl->mbBoolean1 = false;
287 504 : mpImpl->mbBoolean2 = false;
288 504 : mpImpl->mnInt32 = 0;
289 504 : mpImpl->mnInt16 = 0;
290 :
291 : }
292 563 : }
293 :
294 741 : SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
295 741 : : OComponentHelper( getMutex() )
296 : , mxAnchor( xAnchor )
297 : , mpPropSet(NULL)
298 : , mnServiceId(text::textfield::Type::UNSPECIFIED)
299 1482 : , mpImpl( new SvxUnoFieldData_Impl )
300 : {
301 : DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
302 :
303 741 : mpImpl->msPresentation = rPresentation;
304 :
305 741 : if(pData)
306 : {
307 741 : mnServiceId = pData->GetClassId();
308 : DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
309 741 : if (mnServiceId != text::textfield::Type::UNSPECIFIED)
310 : {
311 : // extract field properties from data class
312 741 : switch( mnServiceId )
313 : {
314 : case text::textfield::Type::DATE:
315 : {
316 86 : mpImpl->mbBoolean2 = true;
317 : // #i35416# for variable date field, don't use invalid "0000-00-00" date,
318 : // use current date instead
319 86 : bool bFixed = static_cast<const SvxDateField*>(pData)->GetType() == SVXDATETYPE_FIX;
320 : mpImpl->maDateTime = getDate( bFixed ?
321 0 : static_cast<const SvxDateField*>(pData)->GetFixDate() :
322 86 : Date( Date::SYSTEM ).GetDate() );
323 86 : mpImpl->mnInt32 = static_cast<const SvxDateField*>(pData)->GetFormat();
324 86 : mpImpl->mbBoolean1 = bFixed;
325 : }
326 86 : break;
327 :
328 : case text::textfield::Type::TIME:
329 10 : mpImpl->mbBoolean2 = false;
330 10 : mpImpl->mbBoolean1 = false;
331 10 : mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
332 10 : break;
333 :
334 : case text::textfield::Type::EXTENDED_TIME:
335 48 : mpImpl->mbBoolean2 = false;
336 48 : mpImpl->maDateTime = getTime( static_cast<const SvxExtTimeField*>(pData)->GetFixTime() );
337 48 : mpImpl->mbBoolean1 = static_cast<const SvxExtTimeField*>(pData)->GetType() == SVXTIMETYPE_FIX;
338 48 : mpImpl->mnInt32 = static_cast<const SvxExtTimeField*>(pData)->GetFormat();
339 48 : break;
340 :
341 : case text::textfield::Type::URL:
342 0 : mpImpl->msString1 = static_cast<const SvxURLField*>(pData)->GetRepresentation();
343 0 : mpImpl->msString2 = static_cast<const SvxURLField*>(pData)->GetTargetFrame();
344 0 : mpImpl->msString3 = static_cast<const SvxURLField*>(pData)->GetURL();
345 : mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
346 0 : static_cast<const SvxURLField*>(pData)->GetFormat());
347 0 : break;
348 :
349 : case text::textfield::Type::EXTENDED_FILE:
350 0 : mpImpl->msString1 = static_cast<const SvxExtFileField*>(pData)->GetFile();
351 0 : mpImpl->mbBoolean1 = static_cast<const SvxExtFileField*>(pData)->GetType() == SVXFILETYPE_FIX;
352 0 : mpImpl->mnInt16 = getFileNameDisplayFormat(static_cast<const SvxExtFileField*>(pData)->GetFormat());
353 0 : break;
354 :
355 : case text::textfield::Type::AUTHOR:
356 0 : mpImpl->msString1 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
357 0 : mpImpl->msString2 = static_cast<const SvxAuthorField*>(pData)->GetFormatted();
358 : mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
359 0 : static_cast<const SvxAuthorField*>(pData)->GetFormat());
360 0 : mpImpl->mbBoolean1 = static_cast<const SvxAuthorField*>(pData)->GetType() == SVXAUTHORTYPE_FIX;
361 0 : mpImpl->mbBoolean2 = static_cast<const SvxAuthorField*>(pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME;
362 0 : break;
363 :
364 : case text::textfield::Type::MEASURE:
365 0 : mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(static_cast<const SdrMeasureField*>(pData)->GetMeasureFieldKind());
366 0 : break;
367 :
368 : default:
369 : SAL_WARN("editeng.uno", "Id service unknown: " << mnServiceId);
370 597 : break;
371 : }
372 : }
373 : }
374 :
375 741 : mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
376 741 : }
377 :
378 3898 : SvxUnoTextField::~SvxUnoTextField() throw()
379 : {
380 1304 : delete mpImpl;
381 2594 : }
382 :
383 1 : SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
384 : {
385 1 : SvxFieldData* pData = NULL;
386 :
387 1 : switch( mnServiceId )
388 : {
389 : case text::textfield::Type::TIME:
390 : case text::textfield::Type::EXTENDED_TIME:
391 : case text::textfield::Type::DATE:
392 : {
393 1 : if( mpImpl->mbBoolean2 ) // IsDate?
394 : {
395 1 : Date aDate( setDate( mpImpl->maDateTime ) );
396 1 : pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
397 1 : if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F )
398 1 : static_cast<SvxDateField*>(pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 );
399 : }
400 : else
401 : {
402 0 : if( mnServiceId != text::textfield::Type::TIME && mnServiceId != text::textfield::Type::DATE )
403 : {
404 0 : tools::Time aTime( setTime( mpImpl->maDateTime ) );
405 0 : pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
406 :
407 0 : if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH )
408 0 : static_cast<SvxExtTimeField*>(pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 );
409 : }
410 : else
411 : {
412 0 : pData = new SvxTimeField();
413 : }
414 : }
415 :
416 : }
417 1 : break;
418 :
419 : case text::textfield::Type::URL:
420 0 : pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, !mpImpl->msString1.isEmpty() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL );
421 0 : static_cast<SvxURLField*>(pData)->SetTargetFrame( mpImpl->msString2 );
422 0 : if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR )
423 0 : static_cast<SvxURLField*>(pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 );
424 0 : break;
425 :
426 : case text::textfield::Type::PAGE:
427 0 : pData = new SvxPageField();
428 0 : break;
429 :
430 : case text::textfield::Type::PAGES:
431 0 : pData = new SvxPagesField();
432 0 : break;
433 :
434 : case text::textfield::Type::DOCINFO_TITLE:
435 0 : pData = new SvxFileField();
436 0 : break;
437 :
438 : case text::textfield::Type::TABLE:
439 0 : pData = new SvxTableField();
440 0 : break;
441 :
442 : case text::textfield::Type::EXTENDED_FILE:
443 : {
444 : // #92009# pass fixed attribute to constructor
445 : pData = new SvxExtFileField( mpImpl->msString1,
446 : mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR,
447 0 : setFileNameDisplayFormat(mpImpl->mnInt16 ) );
448 0 : break;
449 : }
450 :
451 : case text::textfield::Type::AUTHOR:
452 : {
453 0 : OUString aContent;
454 0 : OUString aFirstName;
455 0 : OUString aLastName;
456 0 : OUString aEmpty;
457 :
458 : // do we have CurrentPresentation given?
459 : // mimic behaviour of writer, which means:
460 : // prefer CurrentPresentation over Content
461 : // if both are given.
462 0 : if( !mpImpl->msString1.isEmpty() )
463 0 : aContent = mpImpl->msString1;
464 : else
465 0 : aContent = mpImpl->msString2;
466 :
467 0 : sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
468 0 : if( nPos > 0 )
469 : {
470 0 : aFirstName = aContent.copy( 0, nPos );
471 0 : aLastName = aContent.copy( nPos + 1 );
472 : }
473 : else
474 : {
475 0 : aLastName = aContent;
476 : }
477 :
478 : // #92009# pass fixed attribute to constructor
479 : pData = new SvxAuthorField( aFirstName, aLastName, aEmpty,
480 0 : mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR );
481 :
482 0 : if( !mpImpl->mbBoolean2 )
483 : {
484 0 : static_cast<SvxAuthorField*>(pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME );
485 : }
486 0 : else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME )
487 : {
488 0 : static_cast<SvxAuthorField*>(pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 );
489 : }
490 :
491 0 : break;
492 : }
493 :
494 : case text::textfield::Type::MEASURE:
495 : {
496 0 : SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE;
497 0 : if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS )
498 0 : eKind = (SdrMeasureFieldKind) mpImpl->mnInt16;
499 0 : pData = new SdrMeasureField( eKind);
500 0 : break;
501 : }
502 : case text::textfield::Type::PRESENTATION_HEADER:
503 0 : pData = new SvxHeaderField();
504 0 : break;
505 : case text::textfield::Type::PRESENTATION_FOOTER:
506 0 : pData = new SvxFooterField();
507 0 : break;
508 : case text::textfield::Type::PRESENTATION_DATE_TIME:
509 0 : pData = new SvxDateTimeField();
510 0 : break;
511 : case text::textfield::Type::PAGE_NAME:
512 0 : pData = new SvxPageTitleField();
513 0 : break;
514 : };
515 :
516 1 : return pData;
517 : }
518 :
519 : // uno::XInterface
520 5970 : uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
521 : throw(uno::RuntimeException, std::exception)
522 : {
523 5970 : uno::Any aAny;
524 :
525 5970 : QUERYINT( beans::XPropertySet );
526 3640 : else QUERYINT( text::XTextContent );
527 3092 : else QUERYINT( text::XTextField );
528 2390 : else QUERYINT( lang::XServiceInfo );
529 1779 : else QUERYINT( lang::XUnoTunnel );
530 : else
531 1779 : return OComponentHelper::queryAggregation( rType );
532 :
533 4191 : return aAny;
534 : }
535 :
536 : // XTypeProvider
537 :
538 0 : uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
539 : throw (uno::RuntimeException, std::exception)
540 : {
541 0 : if( maTypeSequence.getLength() == 0 )
542 : {
543 0 : maTypeSequence = OComponentHelper::getTypes();
544 0 : sal_Int32 nOldCount = maTypeSequence.getLength();
545 :
546 0 : maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated
547 0 : uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount];
548 :
549 0 : *pTypes++ = cppu::UnoType<text::XTextField>::get();
550 0 : *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
551 0 : *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
552 0 : *pTypes++ = cppu::UnoType<lang::XUnoTunnel>::get();
553 : }
554 0 : return maTypeSequence;
555 : }
556 :
557 0 : uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
558 : throw (uno::RuntimeException, std::exception)
559 : {
560 0 : return css::uno::Sequence<sal_Int8>();
561 : }
562 :
563 5970 : uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
564 : throw(uno::RuntimeException, std::exception)
565 : {
566 5970 : return OComponentHelper::queryInterface(rType);
567 : }
568 :
569 21410 : void SAL_CALL SvxUnoTextField::acquire() throw( )
570 : {
571 21410 : OComponentHelper::acquire();
572 21410 : }
573 :
574 21410 : void SAL_CALL SvxUnoTextField::release() throw( )
575 : {
576 21410 : OComponentHelper::release();
577 21410 : }
578 :
579 : // Interface text::XTextField
580 383 : OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
581 : throw(uno::RuntimeException, std::exception)
582 : {
583 383 : SolarMutexGuard aGuard;
584 383 : if (bShowCommand)
585 : {
586 77 : switch (mnServiceId)
587 : {
588 : case text::textfield::Type::DATE:
589 14 : return OUString("Date");
590 : case text::textfield::Type::URL:
591 0 : return OUString("URL");
592 : case text::textfield::Type::PAGE:
593 28 : return OUString("Page");
594 : case text::textfield::Type::PAGES:
595 0 : return OUString("Pages");
596 : case text::textfield::Type::TIME:
597 0 : return OUString("Time");
598 : case text::textfield::Type::DOCINFO_TITLE:
599 0 : return OUString("File");
600 : case text::textfield::Type::TABLE:
601 0 : return OUString("Table");
602 : case text::textfield::Type::EXTENDED_TIME:
603 0 : return OUString("ExtTime");
604 : case text::textfield::Type::EXTENDED_FILE:
605 0 : return OUString("ExtFile");
606 : case text::textfield::Type::AUTHOR:
607 0 : return OUString("Author");
608 : case text::textfield::Type::MEASURE:
609 0 : return OUString("Measure");
610 : case text::textfield::Type::PRESENTATION_HEADER:
611 5 : return OUString("Header");
612 : case text::textfield::Type::PRESENTATION_FOOTER:
613 15 : return OUString("Footer");
614 : case text::textfield::Type::PRESENTATION_DATE_TIME:
615 15 : return OUString("DateTime");
616 : case text::textfield::Type::PAGE_NAME:
617 0 : return OUString("PageName");
618 : default:
619 0 : return OUString("Unknown");
620 : }
621 : }
622 : else
623 : {
624 306 : return mpImpl->msPresentation;
625 383 : }
626 : }
627 :
628 : // Interface text::XTextContent
629 1 : void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
630 : throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
631 : {
632 1 : SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange );
633 1 : if(pRange == NULL)
634 0 : throw lang::IllegalArgumentException();
635 :
636 1 : SvxFieldData* pData = CreateFieldData();
637 1 : if( pData )
638 1 : pRange->attachField( pData );
639 :
640 1 : delete pData;
641 1 : }
642 :
643 611 : uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
644 : throw(uno::RuntimeException, std::exception)
645 : {
646 611 : return mxAnchor;
647 : }
648 :
649 : // lang::XComponent
650 1290 : void SAL_CALL SvxUnoTextField::dispose()
651 : throw(uno::RuntimeException, std::exception)
652 : {
653 1290 : OComponentHelper::dispose();
654 1290 : }
655 :
656 2 : void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
657 : throw(uno::RuntimeException, std::exception)
658 : {
659 2 : OComponentHelper::addEventListener(xListener);
660 2 : }
661 :
662 1 : void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
663 : throw(uno::RuntimeException, std::exception)
664 : {
665 1 : OComponentHelper::removeEventListener(aListener);
666 1 : }
667 :
668 :
669 : // Interface beans::XPropertySet
670 648 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
671 : throw(uno::RuntimeException, std::exception)
672 : {
673 648 : SolarMutexGuard aGuard;
674 648 : return mpPropSet->getPropertySetInfo();
675 : }
676 :
677 647 : 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)
679 : {
680 647 : SolarMutexGuard aGuard;
681 :
682 647 : if( mpImpl == NULL )
683 0 : throw uno::RuntimeException();
684 :
685 647 : if (aPropertyName == UNO_TC_PROP_ANCHOR)
686 : {
687 548 : aValue >>= mxAnchor;
688 548 : return;
689 : }
690 :
691 99 : const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
692 99 : if ( !pMap )
693 0 : throw beans::UnknownPropertyException();
694 :
695 99 : switch( pMap->nWID )
696 : {
697 : case WID_DATE:
698 2 : if(aValue >>= mpImpl->maDateTime)
699 2 : return;
700 0 : break;
701 : case WID_BOOL1:
702 43 : if(aValue >>= mpImpl->mbBoolean1)
703 43 : return;
704 0 : break;
705 : case WID_BOOL2:
706 43 : if(aValue >>= mpImpl->mbBoolean2)
707 43 : return;
708 0 : break;
709 : case WID_INT16:
710 5 : if(aValue >>= mpImpl->mnInt16)
711 5 : return;
712 0 : break;
713 : case WID_INT32:
714 4 : if(aValue >>= mpImpl->mnInt32)
715 4 : return;
716 0 : break;
717 : case WID_STRING1:
718 1 : if(aValue >>= mpImpl->msString1)
719 1 : return;
720 0 : break;
721 : case WID_STRING2:
722 0 : if(aValue >>= mpImpl->msString2)
723 0 : return;
724 0 : break;
725 : case WID_STRING3:
726 1 : if(aValue >>= mpImpl->msString3)
727 1 : return;
728 0 : break;
729 : }
730 :
731 0 : throw lang::IllegalArgumentException();
732 : }
733 :
734 1091 : uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
735 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
736 : {
737 1091 : SolarMutexGuard aGuard;
738 :
739 1091 : if (PropertyName == UNO_TC_PROP_ANCHOR)
740 0 : return uno::makeAny(mxAnchor);
741 :
742 1091 : if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
743 548 : return uno::makeAny(mnServiceId);
744 :
745 1086 : uno::Any aValue;
746 :
747 543 : const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
748 543 : if ( !pMap )
749 0 : throw beans::UnknownPropertyException();
750 :
751 543 : switch( pMap->nWID )
752 : {
753 : case WID_DATE:
754 103 : aValue <<= mpImpl->maDateTime;
755 103 : break;
756 : case WID_BOOL1:
757 103 : aValue <<= mpImpl->mbBoolean1;
758 103 : break;
759 : case WID_BOOL2:
760 167 : aValue <<= mpImpl->mbBoolean2;
761 167 : break;
762 : case WID_INT16:
763 7 : aValue <<= mpImpl->mnInt16;
764 7 : break;
765 : case WID_INT32:
766 157 : aValue <<= mpImpl->mnInt32;
767 157 : break;
768 : case WID_STRING1:
769 2 : aValue <<= mpImpl->msString1;
770 2 : break;
771 : case WID_STRING2:
772 2 : aValue <<= mpImpl->msString2;
773 2 : break;
774 : case WID_STRING3:
775 2 : aValue <<= mpImpl->msString3;
776 2 : break;
777 : }
778 :
779 1634 : return aValue;
780 : }
781 :
782 0 : 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 0 : 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 0 : 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 0 : void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception) {}
786 :
787 : // OComponentHelper
788 1290 : void SvxUnoTextField::disposing()
789 : {
790 : // nothing to do
791 1290 : }
792 :
793 : // lang::XServiceInfo
794 0 : OUString SAL_CALL SvxUnoTextField::getImplementationName() throw(uno::RuntimeException, std::exception)
795 : {
796 0 : return OUString("SvxUnoTextField");
797 : }
798 :
799 625 : uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
800 : throw(uno::RuntimeException, std::exception)
801 : {
802 625 : uno::Sequence<OUString> aSeq(4);
803 625 : OUString* pServices = aSeq.getArray();
804 625 : pServices[0] = "com.sun.star.text.TextContent";
805 625 : pServices[1] = "com.sun.star.text.TextField";
806 :
807 625 : switch (mnServiceId)
808 : {
809 : case text::textfield::Type::DATE:
810 62 : pServices[2] = "com.sun.star.text.TextField.DateTime";
811 62 : pServices[3] = "com.sun.star.text.textfield.DateTime";
812 62 : break;
813 : case text::textfield::Type::URL:
814 1 : pServices[2] = "com.sun.star.text.TextField.URL";
815 1 : pServices[3] = "com.sun.star.text.textfield.URL";
816 1 : break;
817 : case text::textfield::Type::PAGE:
818 157 : pServices[2] = "com.sun.star.text.TextField.PageNumber";
819 157 : pServices[3] = "com.sun.star.text.textfield.PageNumber";
820 157 : break;
821 : case text::textfield::Type::PAGES:
822 59 : pServices[2] = "com.sun.star.text.TextField.PageCount";
823 59 : pServices[3] = "com.sun.star.text.textfield.PageCount";
824 59 : break;
825 : case text::textfield::Type::TIME:
826 11 : pServices[2] = "com.sun.star.text.TextField.DateTime";
827 11 : pServices[3] = "com.sun.star.text.textfield.DateTime";
828 11 : break;
829 : case text::textfield::Type::DOCINFO_TITLE:
830 59 : pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
831 59 : pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
832 59 : break;
833 : case text::textfield::Type::TABLE:
834 117 : pServices[2] = "com.sun.star.text.TextField.SheetName";
835 117 : pServices[3] = "com.sun.star.text.textfield.SheetName";
836 117 : break;
837 : case text::textfield::Type::EXTENDED_TIME:
838 49 : pServices[2] = "com.sun.star.text.TextField.DateTime";
839 49 : pServices[3] = "com.sun.star.text.textfield.DateTime";
840 49 : break;
841 : case text::textfield::Type::EXTENDED_FILE:
842 1 : pServices[2] = "com.sun.star.text.TextField.FileName";
843 1 : pServices[3] = "com.sun.star.text.textfield.FileName";
844 1 : break;
845 : case text::textfield::Type::AUTHOR:
846 1 : pServices[2] = "com.sun.star.text.TextField.Author";
847 1 : pServices[3] = "com.sun.star.text.textfield.Author";
848 1 : break;
849 : case text::textfield::Type::MEASURE:
850 1 : pServices[2] = "com.sun.star.text.TextField.Measure";
851 1 : pServices[3] = "com.sun.star.text.textfield.Measure";
852 1 : break;
853 : case text::textfield::Type::PRESENTATION_HEADER:
854 29 : pServices[2] = "com.sun.star.presentation.TextField.Header";
855 29 : pServices[3] = "com.sun.star.presentation.textfield.Header";
856 29 : break;
857 : case text::textfield::Type::PRESENTATION_FOOTER:
858 39 : pServices[2] = "com.sun.star.presentation.TextField.Footer";
859 39 : pServices[3] = "com.sun.star.presentation.textfield.Footer";
860 39 : break;
861 : case text::textfield::Type::PRESENTATION_DATE_TIME:
862 39 : pServices[2] = "com.sun.star.presentation.TextField.DateTime";
863 39 : pServices[3] = "com.sun.star.presentation.textfield.DateTime";
864 39 : break;
865 : case text::textfield::Type::PAGE_NAME:
866 0 : pServices[2] = "com.sun.star.text.TextField.PageName";
867 0 : pServices[3] = "com.sun.star.text.textfield.PageName";
868 0 : break;
869 : default:
870 0 : aSeq.realloc(0);
871 : }
872 :
873 625 : return aSeq;
874 : }
875 :
876 1 : sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
877 : {
878 1 : return cppu::supportsService( this, ServiceName );
879 : }
880 :
881 1890 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
882 : {
883 1890 : uno::Reference< uno::XInterface > xRet;
884 :
885 3780 : const OUString aTextFieldPrexit( "com.sun.star.text.textfield." );
886 :
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 3780 : const OUString aTextFieldPrexit2( "com.sun.star.text.TextField." );
890 :
891 3780 : if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
892 1890 : (ServiceSpecifier.startsWith( aTextFieldPrexit2 )) )
893 : {
894 182 : OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
895 :
896 182 : sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
897 :
898 182 : if ( aFieldType == "DateTime" )
899 : {
900 0 : nId = text::textfield::Type::DATE;
901 : }
902 182 : else if ( aFieldType == "URL" )
903 : {
904 1 : nId = text::textfield::Type::URL;
905 : }
906 181 : else if ( aFieldType == "PageNumber" )
907 : {
908 174 : nId = text::textfield::Type::PAGE;
909 : }
910 7 : else if ( aFieldType == "PageCount" )
911 : {
912 0 : nId = text::textfield::Type::PAGES;
913 : }
914 7 : else if ( aFieldType == "SheetName" )
915 : {
916 0 : nId = text::textfield::Type::TABLE;
917 : }
918 7 : else if ( aFieldType == "FileName" )
919 : {
920 0 : nId = text::textfield::Type::EXTENDED_FILE;
921 : }
922 14 : else if (aFieldType == "docinfo.Title" ||
923 7 : aFieldType == "DocInfo.Title" )
924 : {
925 0 : nId = text::textfield::Type::DOCINFO_TITLE;
926 : }
927 7 : else if ( aFieldType == "Author" )
928 : {
929 0 : nId = text::textfield::Type::AUTHOR;
930 : }
931 7 : else if ( aFieldType == "Measure" )
932 : {
933 5 : nId = text::textfield::Type::MEASURE;
934 : }
935 :
936 182 : if (nId != text::textfield::Type::UNSPECIFIED)
937 180 : xRet = static_cast<cppu::OWeakObject *>(new SvxUnoTextField( nId ));
938 : }
939 :
940 3780 : return xRet;
941 : }
942 :
943 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|