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