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 0 : 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 0 : const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
71 : {
72 : static const SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
73 : {
74 0 : { OUString(UNO_TC_PROP_DATE_TIME), WID_DATE, ::getCppuType((const util::DateTime*)0), 0, 0 },
75 0 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, ::getBooleanCppuType(), 0, 0 },
76 0 : { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, ::getBooleanCppuType(), 0, 0 },
77 0 : { OUString(UNO_TC_PROP_NUMFORMAT), WID_INT32, ::getCppuType((const sal_Int32*)0), 0, 0 },
78 : { OUString(), 0, css::uno::Type(), 0, 0 }
79 0 : };
80 0 : static const SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
81 :
82 : static const SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
83 : {
84 0 : { OUString(UNO_TC_PROP_IS_DATE), WID_BOOL2, ::getBooleanCppuType(), 0, 0 },
85 : { OUString(), 0, css::uno::Type(), 0, 0 }
86 0 : };
87 0 : static const SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
88 :
89 : static const SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
90 : {
91 :
92 0 : { OUString(UNO_TC_PROP_URL_FORMAT), WID_INT16, ::getCppuType((const sal_Int16*)0), 0, 0 },
93 0 : { OUString(UNO_TC_PROP_URL_REPRESENTATION), WID_STRING1, ::getCppuType((const OUString*)0), 0, 0 },
94 0 : { OUString(UNO_TC_PROP_URL_TARGET), WID_STRING2, ::getCppuType((const OUString*)0), 0, 0 },
95 0 : { OUString(UNO_TC_PROP_URL), WID_STRING3, ::getCppuType((const OUString*)0), 0, 0 },
96 : { OUString(), 0, css::uno::Type(), 0, 0 }
97 0 : };
98 0 : static const SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
99 :
100 : static const SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
101 : {
102 : { OUString(), 0, css::uno::Type(), 0, 0 }
103 0 : };
104 0 : static const SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
105 :
106 : static const SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
107 : {
108 0 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, ::getBooleanCppuType(), 0, 0 },
109 0 : { OUString(UNO_TC_PROP_FILE_FORMAT), WID_INT16, ::getCppuType((const sal_Int16*)0), 0, 0 },
110 0 : { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1, ::getCppuType((const OUString*)0), 0, 0 },
111 : { OUString(), 0, css::uno::Type(), 0, 0 }
112 0 : };
113 0 : static const SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
114 :
115 : static const SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
116 : {
117 0 : { OUString(UNO_TC_PROP_IS_FIXED), WID_BOOL1, ::getBooleanCppuType(), 0, 0 },
118 0 : { OUString(UNO_TC_PROP_CURRENT_PRESENTATION), WID_STRING1,::getCppuType((const OUString*)0), 0, 0 },
119 0 : { OUString(UNO_TC_PROP_AUTHOR_CONTENT), WID_STRING2,::getCppuType((const OUString*)0), 0, 0 },
120 0 : { OUString(UNO_TC_PROP_AUTHOR_FORMAT), WID_INT16, ::getCppuType((const sal_Int16*)0), 0, 0 },
121 0 : { OUString(UNO_TC_PROP_AUTHOR_FULLNAME), WID_BOOL2, ::getBooleanCppuType(), 0, 0 },
122 : { OUString(), 0, css::uno::Type(), 0, 0 }
123 0 : };
124 0 : static const SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
125 :
126 : static const SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
127 : {
128 0 : { OUString(UNO_TC_PROP_MEASURE_KIND), WID_INT16, ::getCppuType((const sal_Int16*)0), 0, 0 },
129 : { OUString(), 0, css::uno::Type(), 0, 0 }
130 0 : };
131 0 : static const SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
132 :
133 0 : switch( mnId )
134 : {
135 : case text::textfield::Type::EXTENDED_TIME:
136 : case text::textfield::Type::DATE:
137 0 : return &aExDateTimeFieldPropertySet_Impl;
138 : case text::textfield::Type::URL:
139 0 : return &aUrlFieldPropertySet_Impl;
140 : case text::textfield::Type::TIME:
141 0 : return &aDateTimeFieldPropertySet_Impl;
142 : case text::textfield::Type::EXTENDED_FILE:
143 0 : return &aExtFileFieldPropertySet_Impl;
144 : case text::textfield::Type::AUTHOR:
145 0 : return &aAuthorFieldPropertySet_Impl;
146 : case text::textfield::Type::MEASURE:
147 0 : return &aMeasureFieldPropertySet_Impl;
148 : default:
149 0 : 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 0 : static util::DateTime getDate( sal_uLong nDate )
181 : {
182 0 : util::DateTime aDate;
183 0 : memset( &aDate, 0, sizeof( util::DateTime ) );
184 :
185 0 : Date aTempDate( nDate );
186 :
187 0 : aDate.Day = aTempDate.GetDay();
188 0 : aDate.Month = aTempDate.GetMonth();
189 0 : aDate.Year = aTempDate.GetYear();
190 :
191 0 : return aDate;
192 : }
193 :
194 0 : inline Date setDate( util::DateTime& rDate )
195 : {
196 0 : return Date( rDate.Day, rDate.Month, rDate.Year );
197 : }
198 :
199 0 : static util::DateTime getTime(sal_Int64 const nTime)
200 : {
201 0 : util::DateTime aTime;
202 0 : memset( &aTime, 0, sizeof( util::DateTime ) );
203 :
204 0 : Time aTempTime( nTime );
205 :
206 0 : aTime.NanoSeconds = aTempTime.GetNanoSec();
207 0 : aTime.Seconds = aTempTime.GetSec();
208 0 : aTime.Minutes = aTempTime.GetMin();
209 0 : aTime.Hours = aTempTime.GetHour();
210 :
211 0 : 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 0 : SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
243 0 : : OComponentHelper( getMutex() )
244 : , mpPropSet(NULL)
245 : , mnServiceId(nServiceId)
246 0 : , mpImpl( new SvxUnoFieldData_Impl )
247 : {
248 0 : mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
249 :
250 0 : memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
251 :
252 0 : switch( nServiceId )
253 : {
254 : case text::textfield::Type::DATE:
255 0 : mpImpl->mbBoolean2 = sal_True;
256 0 : mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
257 0 : mpImpl->mbBoolean1 = sal_False;
258 0 : break;
259 :
260 : case text::textfield::Type::EXTENDED_TIME:
261 : case text::textfield::Type::TIME:
262 0 : mpImpl->mbBoolean2 = sal_False;
263 0 : mpImpl->mbBoolean1 = sal_False;
264 0 : mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
265 0 : break;
266 :
267 : case text::textfield::Type::URL:
268 0 : mpImpl->mnInt16 = SVXURLFORMAT_REPR;
269 0 : break;
270 :
271 : case text::textfield::Type::EXTENDED_FILE:
272 0 : mpImpl->mbBoolean1 = sal_False;
273 0 : mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
274 0 : break;
275 :
276 : case text::textfield::Type::AUTHOR:
277 0 : mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
278 0 : mpImpl->mbBoolean1 = sal_False;
279 0 : mpImpl->mbBoolean2 = sal_True;
280 0 : break;
281 :
282 : case text::textfield::Type::MEASURE:
283 0 : mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
284 0 : break;
285 :
286 : default:
287 0 : mpImpl->mbBoolean1 = sal_False;
288 0 : mpImpl->mbBoolean2 = sal_False;
289 0 : mpImpl->mnInt32 = 0;
290 0 : mpImpl->mnInt16 = 0;
291 :
292 : }
293 0 : }
294 :
295 0 : SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
296 0 : : OComponentHelper( getMutex() )
297 : , mxAnchor( xAnchor )
298 : , mpPropSet(NULL)
299 : , mnServiceId(text::textfield::Type::UNSPECIFIED)
300 0 : , mpImpl( new SvxUnoFieldData_Impl )
301 : {
302 : DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
303 :
304 0 : mpImpl->msPresentation = rPresentation;
305 :
306 0 : if(pData)
307 : {
308 0 : mnServiceId = pData->GetClassId();
309 : DBG_ASSERT(mnServiceId != text::textfield::Type::UNSPECIFIED, "unknown SvxFieldData! [CL]");
310 0 : if (mnServiceId != text::textfield::Type::UNSPECIFIED)
311 : {
312 : // extract field properties from data class
313 0 : switch( mnServiceId )
314 : {
315 : case text::textfield::Type::DATE:
316 : {
317 0 : mpImpl->mbBoolean2 = sal_True;
318 : // #i35416# for variable date field, don't use invalid "0000-00-00" date,
319 : // use current date instead
320 0 : sal_Bool bFixed = ((SvxDateField*)pData)->GetType() == SVXDATETYPE_FIX;
321 : mpImpl->maDateTime = getDate( bFixed ?
322 : ((SvxDateField*)pData)->GetFixDate() :
323 0 : Date( Date::SYSTEM ).GetDate() );
324 0 : mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat();
325 0 : mpImpl->mbBoolean1 = bFixed;
326 : }
327 0 : break;
328 :
329 : case text::textfield::Type::TIME:
330 0 : mpImpl->mbBoolean2 = sal_False;
331 0 : mpImpl->mbBoolean1 = sal_False;
332 0 : mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
333 0 : break;
334 :
335 : case text::textfield::Type::EXTENDED_TIME:
336 0 : mpImpl->mbBoolean2 = sal_False;
337 0 : mpImpl->maDateTime = getTime( ((SvxExtTimeField*)pData)->GetFixTime() );
338 0 : mpImpl->mbBoolean1 = ((SvxExtTimeField*)pData)->GetType() == SVXTIMETYPE_FIX;
339 0 : mpImpl->mnInt32 = ((SvxExtTimeField*)pData)->GetFormat();
340 0 : 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 0 : mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
373 0 : }
374 :
375 0 : SvxUnoTextField::~SvxUnoTextField() throw()
376 : {
377 0 : delete mpImpl;
378 0 : }
379 :
380 0 : SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
381 : {
382 0 : SvxFieldData* pData = NULL;
383 :
384 0 : switch( mnServiceId )
385 : {
386 : case text::textfield::Type::TIME:
387 : case text::textfield::Type::EXTENDED_TIME:
388 : case text::textfield::Type::DATE:
389 : {
390 0 : if( mpImpl->mbBoolean2 ) // IsDate?
391 : {
392 0 : Date aDate( setDate( mpImpl->maDateTime ) );
393 0 : pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
394 0 : if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F )
395 0 : ((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 0 : 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 0 : return pData;
511 : }
512 :
513 : // uno::XInterface
514 0 : uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
515 : throw(uno::RuntimeException, std::exception)
516 : {
517 0 : uno::Any aAny;
518 :
519 0 : QUERYINT( beans::XPropertySet );
520 0 : else QUERYINT( text::XTextContent );
521 0 : else QUERYINT( text::XTextField );
522 0 : else QUERYINT( lang::XServiceInfo );
523 0 : else QUERYINT( lang::XUnoTunnel );
524 : else
525 0 : return OComponentHelper::queryAggregation( rType );
526 :
527 0 : 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 0 : uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
558 : throw(uno::RuntimeException, std::exception)
559 : {
560 0 : return OComponentHelper::queryInterface(rType);
561 : }
562 :
563 0 : void SAL_CALL SvxUnoTextField::acquire() throw( )
564 : {
565 0 : OComponentHelper::acquire();
566 0 : }
567 :
568 0 : void SAL_CALL SvxUnoTextField::release() throw( )
569 : {
570 0 : OComponentHelper::release();
571 0 : }
572 :
573 : // Interface text::XTextField
574 0 : OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
575 : throw(uno::RuntimeException, std::exception)
576 : {
577 0 : SolarMutexGuard aGuard;
578 0 : if (bShowCommand)
579 : {
580 0 : switch (mnServiceId)
581 : {
582 : case text::textfield::Type::DATE:
583 0 : return OUString("Date");
584 : case text::textfield::Type::URL:
585 0 : return OUString("URL");
586 : case text::textfield::Type::PAGE:
587 0 : 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 0 : return OUString("Header");
606 : case text::textfield::Type::PRESENTATION_FOOTER:
607 0 : return OUString("Footer");
608 : case text::textfield::Type::PRESENTATION_DATE_TIME:
609 0 : return OUString("DateTime");
610 : default:
611 0 : return OUString("Unknown");
612 : }
613 : }
614 : else
615 : {
616 0 : return mpImpl->msPresentation;
617 0 : }
618 : }
619 :
620 : // Interface text::XTextContent
621 0 : void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
622 : throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
623 : {
624 0 : SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange );
625 0 : if(pRange == NULL)
626 0 : throw lang::IllegalArgumentException();
627 :
628 0 : SvxFieldData* pData = CreateFieldData();
629 0 : if( pData )
630 0 : pRange->attachField( pData );
631 :
632 0 : delete pData;
633 0 : }
634 :
635 0 : uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
636 : throw(uno::RuntimeException, std::exception)
637 : {
638 0 : return mxAnchor;
639 : }
640 :
641 : // lang::XComponent
642 0 : void SAL_CALL SvxUnoTextField::dispose()
643 : throw(uno::RuntimeException, std::exception)
644 : {
645 0 : OComponentHelper::dispose();
646 0 : }
647 :
648 0 : void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
649 : throw(uno::RuntimeException, std::exception)
650 : {
651 0 : OComponentHelper::addEventListener(xListener);
652 0 : }
653 :
654 0 : void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
655 : throw(uno::RuntimeException, std::exception)
656 : {
657 0 : OComponentHelper::removeEventListener(aListener);
658 0 : }
659 :
660 :
661 : // Interface beans::XPropertySet
662 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo( )
663 : throw(uno::RuntimeException, std::exception)
664 : {
665 0 : SolarMutexGuard aGuard;
666 0 : return mpPropSet->getPropertySetInfo();
667 : }
668 :
669 0 : 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 0 : SolarMutexGuard aGuard;
673 :
674 0 : if( mpImpl == NULL )
675 0 : throw uno::RuntimeException();
676 :
677 0 : if (aPropertyName == UNO_TC_PROP_ANCHOR)
678 : {
679 0 : aValue >>= mxAnchor;
680 0 : return;
681 : }
682 :
683 0 : const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( aPropertyName );
684 0 : if ( !pMap )
685 0 : throw beans::UnknownPropertyException();
686 :
687 0 : switch( pMap->nWID )
688 : {
689 : case WID_DATE:
690 0 : if(aValue >>= mpImpl->maDateTime)
691 0 : return;
692 0 : break;
693 : case WID_BOOL1:
694 0 : if(aValue >>= mpImpl->mbBoolean1)
695 0 : return;
696 0 : break;
697 : case WID_BOOL2:
698 0 : if(aValue >>= mpImpl->mbBoolean2)
699 0 : return;
700 0 : break;
701 : case WID_INT16:
702 0 : if(aValue >>= mpImpl->mnInt16)
703 0 : return;
704 0 : break;
705 : case WID_INT32:
706 0 : if(aValue >>= mpImpl->mnInt32)
707 0 : return;
708 0 : break;
709 : case WID_STRING1:
710 0 : if(aValue >>= mpImpl->msString1)
711 0 : 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 0 : if(aValue >>= mpImpl->msString3)
719 0 : return;
720 0 : break;
721 : }
722 :
723 0 : throw lang::IllegalArgumentException();
724 : }
725 :
726 0 : uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
727 : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
728 : {
729 0 : SolarMutexGuard aGuard;
730 :
731 0 : if (PropertyName == UNO_TC_PROP_ANCHOR)
732 0 : return uno::makeAny(mxAnchor);
733 :
734 0 : if (PropertyName == UNO_TC_PROP_TEXTFIELD_TYPE)
735 0 : return uno::makeAny(mnServiceId);
736 :
737 0 : uno::Any aValue;
738 :
739 0 : const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap().getByName( PropertyName );
740 0 : if ( !pMap )
741 0 : throw beans::UnknownPropertyException();
742 :
743 0 : switch( pMap->nWID )
744 : {
745 : case WID_DATE:
746 0 : aValue <<= mpImpl->maDateTime;
747 0 : break;
748 : case WID_BOOL1:
749 0 : aValue <<= mpImpl->mbBoolean1;
750 0 : break;
751 : case WID_BOOL2:
752 0 : aValue <<= mpImpl->mbBoolean2;
753 0 : break;
754 : case WID_INT16:
755 0 : aValue <<= mpImpl->mnInt16;
756 0 : break;
757 : case WID_INT32:
758 0 : aValue <<= mpImpl->mnInt32;
759 0 : break;
760 : case WID_STRING1:
761 0 : aValue <<= mpImpl->msString1;
762 0 : break;
763 : case WID_STRING2:
764 0 : aValue <<= mpImpl->msString2;
765 0 : break;
766 : case WID_STRING3:
767 0 : aValue <<= mpImpl->msString3;
768 0 : break;
769 : }
770 :
771 0 : 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 0 : void SvxUnoTextField::disposing()
781 : {
782 : // nothing to do
783 0 : }
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 0 : uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
792 : throw(uno::RuntimeException, std::exception)
793 : {
794 0 : uno::Sequence<OUString> aSeq(4);
795 0 : OUString* pServices = aSeq.getArray();
796 0 : pServices[0] = "com.sun.star.text.TextContent";
797 0 : pServices[1] = "com.sun.star.text.TextField";
798 :
799 0 : switch (mnServiceId)
800 : {
801 : case text::textfield::Type::DATE:
802 0 : pServices[2] = "com.sun.star.text.TextField.DateTime";
803 0 : pServices[3] = "com.sun.star.text.textfield.DateTime";
804 0 : break;
805 : case text::textfield::Type::URL:
806 0 : pServices[2] = "com.sun.star.text.TextField.URL";
807 0 : pServices[3] = "com.sun.star.text.textfield.URL";
808 0 : break;
809 : case text::textfield::Type::PAGE:
810 0 : pServices[2] = "com.sun.star.text.TextField.PageNumber";
811 0 : pServices[3] = "com.sun.star.text.textfield.PageNumber";
812 0 : break;
813 : case text::textfield::Type::PAGES:
814 0 : pServices[2] = "com.sun.star.text.TextField.PageCount";
815 0 : pServices[3] = "com.sun.star.text.textfield.PageCount";
816 0 : break;
817 : case text::textfield::Type::TIME:
818 0 : pServices[2] = "com.sun.star.text.TextField.DateTime";
819 0 : pServices[3] = "com.sun.star.text.textfield.DateTime";
820 0 : break;
821 : case text::textfield::Type::DOCINFO_TITLE:
822 0 : pServices[2] = "com.sun.star.text.TextField.docinfo.Title";
823 0 : pServices[3] = "com.sun.star.text.textfield.docinfo.Title";
824 0 : break;
825 : case text::textfield::Type::TABLE:
826 0 : pServices[2] = "com.sun.star.text.TextField.SheetName";
827 0 : pServices[3] = "com.sun.star.text.textfield.SheetName";
828 0 : break;
829 : case text::textfield::Type::EXTENDED_TIME:
830 0 : pServices[2] = "com.sun.star.text.TextField.DateTime";
831 0 : pServices[3] = "com.sun.star.text.textfield.DateTime";
832 0 : break;
833 : case text::textfield::Type::EXTENDED_FILE:
834 0 : pServices[2] = "com.sun.star.text.TextField.FileName";
835 0 : pServices[3] = "com.sun.star.text.textfield.FileName";
836 0 : break;
837 : case text::textfield::Type::AUTHOR:
838 0 : pServices[2] = "com.sun.star.text.TextField.Author";
839 0 : pServices[3] = "com.sun.star.text.textfield.Author";
840 0 : break;
841 : case text::textfield::Type::MEASURE:
842 0 : pServices[2] = "com.sun.star.text.TextField.Measure";
843 0 : pServices[3] = "com.sun.star.text.textfield.Measure";
844 0 : break;
845 : case text::textfield::Type::PRESENTATION_HEADER:
846 0 : pServices[2] = "com.sun.star.presentation.TextField.Header";
847 0 : pServices[3] = "com.sun.star.presentation.textfield.Header";
848 0 : break;
849 : case text::textfield::Type::PRESENTATION_FOOTER:
850 0 : pServices[2] = "com.sun.star.presentation.TextField.Footer";
851 0 : pServices[3] = "com.sun.star.presentation.textfield.Footer";
852 0 : break;
853 : case text::textfield::Type::PRESENTATION_DATE_TIME:
854 0 : pServices[2] = "com.sun.star.presentation.TextField.DateTime";
855 0 : pServices[3] = "com.sun.star.presentation.textfield.DateTime";
856 0 : break;
857 : default:
858 0 : aSeq.realloc(0);
859 : }
860 :
861 0 : return aSeq;
862 : }
863 :
864 0 : sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException, std::exception )
865 : {
866 0 : return cppu::supportsService( this, ServiceName );
867 : }
868 :
869 0 : uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
870 : {
871 0 : uno::Reference< uno::XInterface > xRet;
872 :
873 0 : 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 0 : const OUString aTextFieldPrexit2( "com.sun.star.text.TextField." );
878 :
879 0 : if( (ServiceSpecifier.startsWith( aTextFieldPrexit )) ||
880 0 : (ServiceSpecifier.startsWith( aTextFieldPrexit2 )) )
881 : {
882 0 : OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
883 :
884 0 : sal_Int32 nId = text::textfield::Type::UNSPECIFIED;
885 :
886 0 : if ( aFieldType == "DateTime" )
887 : {
888 0 : nId = text::textfield::Type::DATE;
889 : }
890 0 : else if ( aFieldType == "URL" )
891 : {
892 0 : nId = text::textfield::Type::URL;
893 : }
894 0 : else if ( aFieldType == "PageNumber" )
895 : {
896 0 : nId = text::textfield::Type::PAGE;
897 : }
898 0 : else if ( aFieldType == "PageCount" )
899 : {
900 0 : nId = text::textfield::Type::PAGES;
901 : }
902 0 : else if ( aFieldType == "SheetName" )
903 : {
904 0 : nId = text::textfield::Type::TABLE;
905 : }
906 0 : else if ( aFieldType == "FileName" )
907 : {
908 0 : nId = text::textfield::Type::EXTENDED_FILE;
909 : }
910 0 : else if (aFieldType == "docinfo.Title" ||
911 0 : aFieldType == "DocInfo.Title" )
912 : {
913 0 : nId = text::textfield::Type::DOCINFO_TITLE;
914 : }
915 0 : else if ( aFieldType == "Author" )
916 : {
917 0 : nId = text::textfield::Type::AUTHOR;
918 : }
919 0 : else if ( aFieldType == "Measure" )
920 : {
921 0 : nId = text::textfield::Type::MEASURE;
922 : }
923 :
924 0 : if (nId != text::textfield::Type::UNSPECIFIED)
925 0 : xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId );
926 : }
927 :
928 0 : return xRet;
929 : }
930 :
931 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|