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