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