xref: /aoo42x/main/editeng/source/uno/unofield.cxx (revision 190118d0)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_editeng.hxx"
26 #include <com/sun/star/util/DateTime.hpp>
27 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
28 #include <com/sun/star/lang/NoSupportException.hpp>
29 #include <com/sun/star/beans/PropertyAttribute.hpp>
30 #include <vcl/svapp.hxx>
31 #include <vos/mutex.hxx>
32 
33 #include <rtl/uuid.h>
34 #include <rtl/memory.h>
35 
36 #include <editeng/eeitem.hxx>
37 #include <editeng/flditem.hxx>
38 #include <editeng/measfld.hxx>
39 #include <editeng/unofield.hxx>
40 #include <editeng/unotext.hxx>
41 #include <comphelper/serviceinfohelper.hxx>
42 
43 using namespace ::rtl;
44 using namespace ::vos;
45 using namespace ::cppu;
46 using namespace ::com::sun::star;
47 
48 #define QUERYINT( xint ) \
49 	if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
50 		aAny <<= uno::Reference< xint >(this)
51 
52 
53 #define WID_DATE	0
54 #define WID_BOOL1	1
55 #define WID_BOOL2	2
56 #define WID_INT32	3
57 #define WID_INT16	4
58 #define WID_STRING1	5
59 #define WID_STRING2	6
60 #define WID_STRING3	7
61 
62 class SvxUnoFieldData_Impl
63 {
64 public:
65 	sal_Bool	mbBoolean1;
66 	sal_Bool	mbBoolean2;
67 	sal_Int32	mnInt32;
68 	sal_Int16	mnInt16;
69 	OUString	msString1;
70 	OUString	msString2;
71 	OUString	msString3;
72 	util::DateTime maDateTime;
73 
74 	OUString	msPresentation;
75 };
76 
ImplGetFieldItemPropertySet(sal_Int32 mnId)77 const SfxItemPropertySet* ImplGetFieldItemPropertySet( sal_Int32 mnId )
78 {
79     static SfxItemPropertyMapEntry aExDateTimeFieldPropertyMap_Impl[] =
80 	{
81 		{ MAP_CHAR_LEN("DateTime"),			WID_DATE,		&::getCppuType((const util::DateTime*)0),		0, 0 },
82 		{ MAP_CHAR_LEN("IsFixed"),			WID_BOOL1,		&::getBooleanCppuType(),				0, 0 },
83 		{ MAP_CHAR_LEN("IsDate"),			WID_BOOL2,		&::getBooleanCppuType(),				0, 0 },
84 		{ MAP_CHAR_LEN("NumberFormat"),		WID_INT32,		&::getCppuType((const sal_Int16*)0),	0, 0 },
85 		{0,0,0,0,0,0}
86 	};
87     static SfxItemPropertySet aExDateTimeFieldPropertySet_Impl(aExDateTimeFieldPropertyMap_Impl);
88 
89     static SfxItemPropertyMapEntry aDateTimeFieldPropertyMap_Impl[] =
90 	{
91 		{ MAP_CHAR_LEN("IsDate"),			WID_BOOL2,		&::getBooleanCppuType(),				0, 0 },
92 		{0,0,0,0,0,0}
93 	};
94     static SfxItemPropertySet aDateTimeFieldPropertySet_Impl(aDateTimeFieldPropertyMap_Impl);
95 
96     static SfxItemPropertyMapEntry aUrlFieldPropertyMap_Impl[] =
97 	{
98 
99 		{ MAP_CHAR_LEN("Format"),			WID_INT16,		&::getCppuType((const sal_Int16*)0),	0, 0 },
100 		{ MAP_CHAR_LEN("Representation"),	WID_STRING1,	&::getCppuType((const OUString*)0),		0, 0 },
101 		{ MAP_CHAR_LEN("TargetFrame"),		WID_STRING2,	&::getCppuType((const OUString*)0),		0, 0 },
102 		{ MAP_CHAR_LEN("URL"),				WID_STRING3,	&::getCppuType((const OUString*)0),		0, 0 },
103 		{0,0,0,0,0,0}
104 	};
105     static SfxItemPropertySet aUrlFieldPropertySet_Impl(aUrlFieldPropertyMap_Impl);
106 
107     static SfxItemPropertyMapEntry aEmptyPropertyMap_Impl[] =
108 	{
109 		{0,0,0,0,0,0}
110 	};
111     static SfxItemPropertySet aEmptyPropertySet_Impl(aEmptyPropertyMap_Impl);
112 
113     static SfxItemPropertyMapEntry aExtFileFieldPropertyMap_Impl[] =
114 	{
115 		{ MAP_CHAR_LEN("IsFixed"),				WID_BOOL1,	&::getBooleanCppuType(),				0, 0 },
116 		{ MAP_CHAR_LEN("FileFormat"),			WID_INT16,	&::getCppuType((const sal_Int16*)0),	0, 0 },
117 		{ MAP_CHAR_LEN("CurrentPresentation"),	WID_STRING1,&::getCppuType((const OUString*)0),		0, 0 },
118 		{0,0,0,0,0,0}
119 	};
120     static SfxItemPropertySet aExtFileFieldPropertySet_Impl(aExtFileFieldPropertyMap_Impl);
121 
122     static SfxItemPropertyMapEntry aAuthorFieldPropertyMap_Impl[] =
123 	{
124 		{ MAP_CHAR_LEN("IsFixed"),				WID_BOOL1,	&::getBooleanCppuType(),				0, 0 },
125 		{ MAP_CHAR_LEN("CurrentPresentation"),	WID_STRING1,&::getCppuType((const OUString*)0),		0, 0 },
126 		{ MAP_CHAR_LEN("Content"),				WID_STRING2,&::getCppuType((const OUString*)0),		0, 0 },
127 		{ MAP_CHAR_LEN("AuthorFormat"),			WID_INT16,	&::getCppuType((const sal_Int16*)0),	0, 0 },
128 		{ MAP_CHAR_LEN("FullName"),				WID_BOOL2,	&::getBooleanCppuType(),				0, 0 },
129 		{0,0,0,0,0,0}
130 	};
131     static SfxItemPropertySet aAuthorFieldPropertySet_Impl(aAuthorFieldPropertyMap_Impl);
132 
133     static SfxItemPropertyMapEntry aMeasureFieldPropertyMap_Impl[] =
134 	{
135 		{ MAP_CHAR_LEN("Kind"),					WID_INT16,	&::getCppuType((const sal_Int16*)0),	0, 0 },
136 		{0,0,0,0,0,0}
137 	};
138     static SfxItemPropertySet aMeasureFieldPropertySet_Impl(aMeasureFieldPropertyMap_Impl);
139 
140 	switch( mnId )
141 	{
142 	case ID_EXT_DATEFIELD:
143 	case ID_EXT_TIMEFIELD:
144 		return &aExDateTimeFieldPropertySet_Impl;
145 	case ID_URLFIELD:
146 		return &aUrlFieldPropertySet_Impl;
147 	case ID_DATEFIELD:
148 	case ID_TIMEFIELD:
149 		return &aDateTimeFieldPropertySet_Impl;
150 	case ID_EXT_FILEFIELD:
151 		return &aExtFileFieldPropertySet_Impl;
152 	case ID_AUTHORFIELD:
153 		return &aAuthorFieldPropertySet_Impl;
154 	case ID_MEASUREFIELD:
155 		return &aMeasureFieldPropertySet_Impl;
156 //	case ID_PAGEFIELD:
157 //	case ID_PAGESFIELD:
158 //	case ID_FILEFIELD:
159 //	case ID_TABLEFIELD:
160 //	case ID_HEADERFIELD:
161 //	case ID_FOOTERFIELD:
162 //	case ID_DATETIMEFIELD::
163 	default:
164 		return &aEmptyPropertySet_Impl;
165 	}
166 }
167 
168 static sal_Char const* aFieldItemNameMap_Impl[] =
169 {
170 	"Date",
171 	"URL",
172 	"Page",
173 	"Pages",
174 	"Time",
175 	"File",
176 	"Table",
177 	"ExtTime",
178 	"ExtFile",
179 	"Author",
180 	"Measure",
181 	"ExtDate",
182 	"Header",
183 	"Footer",
184 	"DateTime",
185 	"Unknown"
186 };
187 
188 /* conversion routines */
189 
getFileNameDisplayFormat(SvxFileFormat nFormat)190 static sal_Int16 getFileNameDisplayFormat( SvxFileFormat nFormat )
191 {
192 	switch( nFormat )
193 	{
194 	case SVXFILEFORMAT_NAME_EXT:	return text::FilenameDisplayFormat::NAME_AND_EXT;
195 	case SVXFILEFORMAT_FULLPATH:	return text::FilenameDisplayFormat::FULL;
196 	case SVXFILEFORMAT_PATH:	return text::FilenameDisplayFormat::PATH;
197 //	case SVXFILEFORMAT_NAME:
198 	default: return text::FilenameDisplayFormat::NAME;
199 	}
200 }
201 
setFileNameDisplayFormat(sal_Int16 nFormat)202 static SvxFileFormat setFileNameDisplayFormat( sal_Int16 nFormat )
203 {
204 	switch( nFormat )
205 	{
206 	case text::FilenameDisplayFormat::FULL:	return SVXFILEFORMAT_FULLPATH;
207 	case text::FilenameDisplayFormat::PATH:	return SVXFILEFORMAT_PATH;
208 	case text::FilenameDisplayFormat::NAME:	return SVXFILEFORMAT_NAME;
209 //	case text::FilenameDisplayFormat::NAME_AND_EXT:
210 	default:
211 		return SVXFILEFORMAT_NAME_EXT;
212 	}
213 }
214 
getDate(sal_uLong nDate)215 static util::DateTime getDate( sal_uLong nDate )
216 {
217 	util::DateTime aDate;
218 	memset( &aDate, 0, sizeof( util::DateTime ) );
219 
220 	Date aTempDate( nDate );
221 
222 	aDate.Day = aTempDate.GetDay();
223     aDate.Month = aTempDate.GetMonth();
224     aDate.Year = aTempDate.GetYear();
225 
226 	return aDate;
227 }
228 
setDate(util::DateTime & rDate)229 inline Date setDate( util::DateTime& rDate )
230 {
231 	return Date( rDate.Day, rDate.Month, rDate.Year );
232 }
233 
getTime(long nTime)234 static util::DateTime getTime( long nTime )
235 {
236 	util::DateTime aTime;
237 	memset( &aTime, 0, sizeof( util::DateTime ) );
238 
239 	Time aTempTime( nTime );
240 
241 	aTime.HundredthSeconds = aTempTime.Get100Sec();
242 	aTime.Seconds = aTempTime.GetSec();
243 	aTime.Minutes = aTempTime.GetMin();
244 	aTime.Hours = aTempTime.GetHour();
245 
246 	return aTime;
247 }
248 
setTime(util::DateTime & rDate)249 inline Time setTime( util::DateTime& rDate )
250 {
251 	return Time( rDate.Hours, rDate.Minutes, rDate.Seconds, rDate.HundredthSeconds  );
252 }
253 
254 // ====================================================================
255 // class SvxUnoTextField
256 // ====================================================================
257 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextField );
258 
SvxUnoTextField(sal_Int32 nServiceId)259 SvxUnoTextField::SvxUnoTextField( sal_Int32 nServiceId ) throw()
260 :	OComponentHelper( getMutex() )
261 ,	mpPropSet(NULL)
262 ,	mnServiceId(nServiceId)
263 ,	mpImpl( new SvxUnoFieldData_Impl )
264 {
265 	mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
266 
267 	memset( &(mpImpl->maDateTime), 0, sizeof( util::DateTime ) );
268 
269 	switch( nServiceId )
270 	{
271 	case ID_EXT_DATEFIELD:
272 	case ID_DATEFIELD:
273 		mpImpl->mbBoolean2 = sal_True;
274 		mpImpl->mnInt32 = SVXDATEFORMAT_STDSMALL;
275 		mpImpl->mbBoolean1 = sal_False;
276 		break;
277 
278 	case ID_EXT_TIMEFIELD:
279 	case ID_TIMEFIELD:
280 		mpImpl->mbBoolean2 = sal_False;
281 		mpImpl->mbBoolean1 = sal_False;
282 		mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
283 		break;
284 
285 	case ID_URLFIELD:
286 		mpImpl->mnInt16 = SVXURLFORMAT_REPR;
287 		break;
288 
289 	case ID_EXT_FILEFIELD:
290 		mpImpl->mbBoolean1 = sal_False;
291 		mpImpl->mnInt16 = text::FilenameDisplayFormat::FULL;
292 		break;
293 
294 	case ID_AUTHORFIELD:
295 		mpImpl->mnInt16 = SVXAUTHORFORMAT_FULLNAME;
296 		mpImpl->mbBoolean1 = sal_False;
297 		mpImpl->mbBoolean2 = sal_True;
298 		break;
299 
300 	case ID_MEASUREFIELD:
301 		mpImpl->mnInt16 = SDRMEASUREFIELD_VALUE;
302 		break;
303 
304 	default:
305 		mpImpl->mbBoolean1 = sal_False;
306 		mpImpl->mbBoolean2 = sal_False;
307 		mpImpl->mnInt32 = 0;
308 		mpImpl->mnInt16 = 0;
309 
310 	}
311 }
312 
SvxUnoTextField(uno::Reference<text::XTextRange> xAnchor,const OUString & rPresentation,const SvxFieldData * pData)313 SvxUnoTextField::SvxUnoTextField( uno::Reference< text::XTextRange > xAnchor, const OUString& rPresentation, const SvxFieldData* pData ) throw()
314 :	OComponentHelper( getMutex() )
315 ,	mxAnchor( xAnchor )
316 ,	mpPropSet(NULL)
317 ,	mnServiceId(ID_UNKNOWN)
318 ,	mpImpl( new SvxUnoFieldData_Impl )
319 {
320 	DBG_ASSERT(pData, "pFieldData == NULL! [CL]" );
321 
322 	mpImpl->msPresentation = rPresentation;
323 
324 	if(pData)
325 	{
326 		mnServiceId = GetFieldId(pData);
327 		DBG_ASSERT(mnServiceId != ID_UNKNOWN, "unknown SvxFieldData! [CL]");
328 		if(mnServiceId != ID_UNKNOWN)
329 		{
330 			// extract field properties from data class
331 			switch( mnServiceId )
332 			{
333 			case ID_DATEFIELD:
334 			case ID_EXT_DATEFIELD:
335                 {
336                     mpImpl->mbBoolean2 = sal_True;
337                     // #i35416# for variable date field, don't use invalid "0000-00-00" date,
338                     // use current date instead
339                     sal_Bool bFixed = ((SvxDateField*)pData)->GetType() == SVXDATETYPE_FIX;
340                     mpImpl->maDateTime = getDate( bFixed ?
341                                             ((SvxDateField*)pData)->GetFixDate() :
342                                             Date().GetDate() );
343                     mpImpl->mnInt32 = ((SvxDateField*)pData)->GetFormat();
344                     mpImpl->mbBoolean1 = bFixed;
345                 }
346 				break;
347 
348 			case ID_TIMEFIELD:
349 				mpImpl->mbBoolean2 = sal_False;
350 				mpImpl->mbBoolean1 = sal_False;
351 				mpImpl->mnInt32 = SVXTIMEFORMAT_STANDARD;
352 				break;
353 
354 			case ID_EXT_TIMEFIELD:
355 				mpImpl->mbBoolean2 = sal_False;
356 				mpImpl->maDateTime = getTime( ((SvxExtTimeField*)pData)->GetFixTime() );
357 				mpImpl->mbBoolean1 = ((SvxExtTimeField*)pData)->GetType() == SVXTIMETYPE_FIX;
358 				mpImpl->mnInt32 = ((SvxExtTimeField*)pData)->GetFormat();
359 				break;
360 
361 			case ID_URLFIELD:
362 				mpImpl->msString1 = ((SvxURLField*)pData)->GetRepresentation();
363 				mpImpl->msString2 = ((SvxURLField*)pData)->GetTargetFrame();
364 				mpImpl->msString3 = ((SvxURLField*)pData)->GetURL();
365 				mpImpl->mnInt16 = sal::static_int_cast< sal_Int16 >(
366                     ((SvxURLField*)pData)->GetFormat());
367 				break;
368 
369 			case ID_EXT_FILEFIELD:
370 				mpImpl->msString1 = ((SvxExtFileField*)pData)->GetFile();
371 				mpImpl->mbBoolean1 = ((SvxExtFileField*)pData)->GetType() == SVXFILETYPE_FIX;
372 				mpImpl->mnInt16 = getFileNameDisplayFormat(((SvxExtFileField*)pData)->GetFormat());
373 				break;
374 
375 			case ID_AUTHORFIELD:
376 				mpImpl->msString1  = ((SvxAuthorField*)pData)->GetFormatted();
377 				mpImpl->msString2  = ((SvxAuthorField*)pData)->GetFormatted();
378 				mpImpl->mnInt16	   = sal::static_int_cast< sal_Int16 >(
379                     ((SvxAuthorField*)pData)->GetFormat());
380 				mpImpl->mbBoolean1 = ((SvxAuthorField*)pData)->GetType() == SVXAUTHORTYPE_FIX;
381 				mpImpl->mbBoolean2 = ((SvxAuthorField*)pData)->GetFormat() != SVXAUTHORFORMAT_SHORTNAME;
382 				break;
383 
384 			case ID_MEASUREFIELD:
385 				mpImpl->mnInt16		= sal::static_int_cast< sal_Int16 >(((SdrMeasureField*)pData)->GetMeasureFieldKind());
386 				break;
387 			}
388 		}
389 	}
390 
391 	mpPropSet = ImplGetFieldItemPropertySet(mnServiceId);
392 }
393 
~SvxUnoTextField()394 SvxUnoTextField::~SvxUnoTextField() throw()
395 {
396 	delete mpImpl;
397 }
398 
CreateFieldData() const399 SvxFieldData* SvxUnoTextField::CreateFieldData() const throw()
400 {
401 	SvxFieldData* pData = NULL;
402 
403 	switch( mnServiceId )
404 	{
405 	case ID_TIMEFIELD:
406 	case ID_EXT_TIMEFIELD:
407 	case ID_DATEFIELD:
408 	case ID_EXT_DATEFIELD:
409 	{
410 		if( mpImpl->mbBoolean2 ) // IsDate?
411 		{
412 			Date aDate( setDate( mpImpl->maDateTime ) );
413 			pData = new SvxDateField( aDate, mpImpl->mbBoolean1?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
414 			if( mpImpl->mnInt32 >= SVXDATEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXDATEFORMAT_F )
415 				((SvxDateField*)pData)->SetFormat( (SvxDateFormat)mpImpl->mnInt32 );
416 		}
417 		else
418 		{
419 			if( mnServiceId != ID_TIMEFIELD && mnServiceId != ID_DATEFIELD )
420 			{
421 				Time aTime( setTime( mpImpl->maDateTime ) );
422 				pData = new SvxExtTimeField( aTime, mpImpl->mbBoolean1?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
423 
424 				if( mpImpl->mnInt32 >= SVXTIMEFORMAT_APPDEFAULT && mpImpl->mnInt32 <= SVXTIMEFORMAT_AM_HMSH )
425 					((SvxExtTimeField*)pData)->SetFormat( (SvxTimeFormat)mpImpl->mnInt32 );
426 			}
427 			else
428 			{
429 				pData = new SvxTimeField();
430 			}
431 		}
432 
433 	}
434 		break;
435 
436 	case ID_URLFIELD:
437 		pData = new SvxURLField( mpImpl->msString3, mpImpl->msString1, mpImpl->msString1.getLength() ? SVXURLFORMAT_REPR : SVXURLFORMAT_URL );
438 		((SvxURLField*)pData)->SetTargetFrame( mpImpl->msString2 );
439 		if( mpImpl->mnInt16 >= SVXURLFORMAT_APPDEFAULT && mpImpl->mnInt16 <= SVXURLFORMAT_REPR )
440 			((SvxURLField*)pData)->SetFormat( (SvxURLFormat)mpImpl->mnInt16 );
441 		break;
442 
443 	case ID_PAGEFIELD:
444 		pData = new SvxPageField();
445 		break;
446 
447 	case ID_PAGESFIELD:
448 		pData = new SvxPagesField();
449 		break;
450 
451 	case ID_FILEFIELD:
452 		pData = new SvxFileField();
453 		break;
454 
455 	case ID_TABLEFIELD:
456 		pData = new SvxTableField();
457 		break;
458 
459 	case ID_EXT_FILEFIELD:
460 	{
461         // #92009# pass fixed attribute to constructor
462 		pData = new SvxExtFileField( mpImpl->msString1,
463                                      mpImpl->mbBoolean1 ? SVXFILETYPE_FIX : SVXFILETYPE_VAR,
464                                      setFileNameDisplayFormat(mpImpl->mnInt16 ) );
465 		break;
466 	}
467 
468 	case ID_AUTHORFIELD:
469 	{
470 		::rtl::OUString aContent;
471 		String aFirstName;
472 		String aLastName;
473 		String aEmpty;
474 
475         // do we have CurrentPresentation given?
476         // mimic behaviour of writer, which means:
477         // prefer CurrentPresentation over Content
478         // if both are given.
479         if( mpImpl->msString1.getLength() )
480             aContent = mpImpl->msString1;
481         else
482             aContent = mpImpl->msString2;
483 
484         sal_Int32 nPos = aContent.lastIndexOf( sal_Char(' '), 0 );
485         if( nPos > 0 )
486         {
487             aFirstName = aContent.copy( 0, nPos );
488             aLastName = aContent.copy( nPos + 1 );
489         }
490         else
491         {
492             aLastName = aContent;
493         }
494 
495         // #92009# pass fixed attribute to constructor
496         pData = new SvxAuthorField( aFirstName, aLastName, aEmpty,
497                                     mpImpl->mbBoolean1 ? SVXAUTHORTYPE_FIX : SVXAUTHORTYPE_VAR );
498 
499 		if( !mpImpl->mbBoolean2 )
500 		{
501 			((SvxAuthorField*)pData)->SetFormat( SVXAUTHORFORMAT_SHORTNAME );
502 		}
503 		else if( mpImpl->mnInt16 >= SVXAUTHORFORMAT_FULLNAME || mpImpl->mnInt16 <= SVXAUTHORFORMAT_SHORTNAME )
504 		{
505 			((SvxAuthorField*)pData)->SetFormat( (SvxAuthorFormat) mpImpl->mnInt16 );
506 		}
507 
508 		break;
509 	}
510 
511 	case ID_MEASUREFIELD:
512 	{
513 		SdrMeasureFieldKind eKind = SDRMEASUREFIELD_VALUE;
514 		if( mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_UNIT || mpImpl->mnInt16 == (sal_Int16)SDRMEASUREFIELD_ROTA90BLANCS )
515 			eKind = (SdrMeasureFieldKind) mpImpl->mnInt16;
516 		pData = new SdrMeasureField( eKind);
517 		break;
518 	}
519 	case ID_HEADERFIELD:
520 		pData = new SvxHeaderField();
521 		break;
522 	case ID_FOOTERFIELD:
523 		pData = new SvxFooterField();
524 		break;
525 	case ID_DATETIMEFIELD:
526 		pData = new SvxDateTimeField();
527 		break;
528 	};
529 
530 	return pData;
531 }
532 
533 // uno::XInterface
queryAggregation(const uno::Type & rType)534 uno::Any SAL_CALL SvxUnoTextField::queryAggregation( const uno::Type & rType )
535 	throw(uno::RuntimeException)
536 {
537 	uno::Any aAny;
538 
539 	QUERYINT( beans::XPropertySet );
540 	else QUERYINT( text::XTextContent );
541 	else QUERYINT( text::XTextField );
542 	else QUERYINT( lang::XServiceInfo );
543 	else QUERYINT( lang::XUnoTunnel );
544 	else
545 		return OComponentHelper::queryAggregation( rType );
546 
547 	return aAny;
548 }
549 
550 // XTypeProvider
551 
getTypes()552 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextField::getTypes()
553 	throw (uno::RuntimeException)
554 {
555 	if( maTypeSequence.getLength() == 0 )
556 	{
557 		maTypeSequence = OComponentHelper::getTypes();
558 		sal_Int32 nOldCount = maTypeSequence.getLength();
559 
560 		maTypeSequence.realloc( nOldCount + 4 ); // !DANGER! keep this updated
561 		uno::Type* pTypes = &maTypeSequence.getArray()[nOldCount];
562 
563 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XTextField >*)0);
564 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
565 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
566 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
567 	}
568 	return maTypeSequence;
569 }
570 
getImplementationId()571 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextField::getImplementationId()
572 	throw (uno::RuntimeException)
573 {
574 	static uno::Sequence< sal_Int8 > aId;
575 	if( aId.getLength() == 0 )
576 	{
577 		aId.realloc( 16 );
578 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
579 	}
580 	return aId;
581 }
582 
queryInterface(const uno::Type & rType)583 uno::Any SAL_CALL SvxUnoTextField::queryInterface( const uno::Type & rType )
584 	throw(uno::RuntimeException)
585 {
586 	return OComponentHelper::queryInterface(rType);
587 }
588 
acquire()589 void SAL_CALL SvxUnoTextField::acquire() throw( )
590 {
591 	OComponentHelper::acquire();
592 }
593 
release()594 void SAL_CALL SvxUnoTextField::release() throw( )
595 {
596 	OComponentHelper::release();
597 }
598 
599 // Interface text::XTextField
getPresentation(sal_Bool bShowCommand)600 OUString SAL_CALL SvxUnoTextField::getPresentation( sal_Bool bShowCommand )
601 	throw(uno::RuntimeException)
602 {
603 	OGuard aGuard( Application::GetSolarMutex() );
604 
605 	if(bShowCommand)
606 	{
607 		DBG_ASSERT( ((sal_uInt32)mnServiceId) < ID_UNKNOWN, "Unknown field type" );
608 		return OUString::createFromAscii( aFieldItemNameMap_Impl[(((sal_uInt32)mnServiceId) > ID_UNKNOWN)? ID_UNKNOWN : mnServiceId ] );
609 	}
610 	else
611 	{
612 		return mpImpl->msPresentation;
613 	}
614 }
615 
616 // Interface text::XTextContent
attach(const uno::Reference<text::XTextRange> & xTextRange)617 void SAL_CALL SvxUnoTextField::attach( const uno::Reference< text::XTextRange >& xTextRange )
618 	throw(lang::IllegalArgumentException, uno::RuntimeException)
619 {
620 	SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xTextRange );
621 	if(pRange == NULL)
622 		throw lang::IllegalArgumentException();
623 
624 	SvxFieldData* pData = CreateFieldData();
625 	if( pData )
626 		pRange->attachField( pData );
627 
628 	delete pData;
629 }
630 
getAnchor()631 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextField::getAnchor()
632 	throw(uno::RuntimeException)
633 {
634 	return mxAnchor;
635 }
636 
637 // lang::XComponent
dispose()638 void SAL_CALL SvxUnoTextField::dispose()
639 	throw(uno::RuntimeException)
640 {
641 	OComponentHelper::dispose();
642 }
643 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)644 void SAL_CALL SvxUnoTextField::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
645 	throw(uno::RuntimeException)
646 {
647 	OComponentHelper::addEventListener(xListener);
648 }
649 
removeEventListener(const uno::Reference<lang::XEventListener> & aListener)650 void SAL_CALL SvxUnoTextField::removeEventListener( const uno::Reference< lang::XEventListener >& aListener )
651 	throw(uno::RuntimeException)
652 {
653 	OComponentHelper::removeEventListener(aListener);
654 }
655 
656 
657 // Interface beans::XPropertySet
getPropertySetInfo()658 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextField::getPropertySetInfo(  )
659 	throw(uno::RuntimeException)
660 {
661 	OGuard aGuard( Application::GetSolarMutex() );
662 	return mpPropSet->getPropertySetInfo();
663 }
664 
setPropertyValue(const OUString & aPropertyName,const uno::Any & aValue)665 void SAL_CALL SvxUnoTextField::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
666 	throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
667 {
668 	OGuard aGuard( Application::GetSolarMutex() );
669 
670 	if( mpImpl == NULL )
671 		throw uno::RuntimeException();
672 
673     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( aPropertyName );
674 	if ( !pMap )
675 		throw beans::UnknownPropertyException();
676 
677 	switch( pMap->nWID )
678 	{
679 	case WID_DATE:
680 		if(aValue >>= mpImpl->maDateTime)
681 			return;
682 		break;
683 	case WID_BOOL1:
684 		if(aValue >>= mpImpl->mbBoolean1)
685 			return;
686 		break;
687 	case WID_BOOL2:
688 		if(aValue >>= mpImpl->mbBoolean2)
689 			return;
690 		break;
691 	case WID_INT16:
692 		if(aValue >>= mpImpl->mnInt16)
693 			return;
694 		break;
695 	case WID_INT32:
696 		if(aValue >>= mpImpl->mnInt32)
697 			return;
698 		break;
699 	case WID_STRING1:
700 		if(aValue >>= mpImpl->msString1)
701 			return;
702 		break;
703 	case WID_STRING2:
704 		if(aValue >>= mpImpl->msString2)
705 			return;
706 		break;
707 	case WID_STRING3:
708 		if(aValue >>= mpImpl->msString3)
709 			return;
710 		break;
711 	}
712 
713 	throw lang::IllegalArgumentException();
714 
715 /*
716 	case WID_FORMAT:
717 		{
718 		sal_Int32 nFormat;
719 
720 		switch( mnId )
721 		{
722 		case ID_DATEFIELD:
723 		{
724 			SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
725 			if(pDate)
726 				pDate->SetFormat( (SvxDateFormat)nFormat );
727 			break;
728 		}
729 		case ID_URLFIELD:
730 		{
731 			SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
732 			if(pURL)
733 				pURL->SetFormat( (SvxURLFormat)nFormat );
734 			break;
735 		}
736 		case ID_EXT_TIMEFIELD:
737 		{
738 			SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
739 			if(pTime)
740 				pTime->SetFormat( (SvxTimeFormat)nFormat );
741 			break;
742 		}
743 		case ID_EXT_FILEFIELD:
744 		{
745 			SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
746 			if(pFile)
747 				pFile->SetFormat( (SvxFileFormat)nFormat );
748 			break;
749 		}
750 		case ID_AUTHORFIELD:
751 		{
752 			SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
753 			if(pAuthor)
754 				pAuthor->SetFormat( (SvxAuthorFormat)nFormat );
755 			break;
756 		}
757 		default:
758 			throw beans::UnknownPropertyException();
759 		}
760 		}
761 		break;
762 	case WID_FIX:
763 		{
764 		if( aValue.hasValue() || aValue.getValueType() != ::getCppuBooleanType() )
765 			throw lang::IllegalArgumentException();
766 		sal_Bool bFix( *(sal_Bool*)aValue.getValue() );
767 		switch( mnId )
768 		{
769 		case ID_EXT_TIMEFIELD:
770 		{
771 			SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, aFieldItem.GetField() );
772 			if(pTime)
773 				pTime->SetType( (SvxTimeType)bFix?SVXTIMETYPE_FIX:SVXTIMETYPE_VAR );
774 			break;
775 		}
776 		case ID_DATEFIELD:
777 		{
778 			SvxDateField* pDate = PTR_CAST( SvxDateField, aFieldItem.GetField() );
779 			if(pDate)
780 				pDate->SetType( (SvxDateType)bFix?SVXDATETYPE_FIX:SVXDATETYPE_VAR );
781 			break;
782 		}
783 		case ID_EXT_FILEFIELD:
784 		{
785 			SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, aFieldItem.GetField() );
786 			if(pFile)
787 				pFile->SetType( (SvxFileType)bFix?SVXFILETYPE_FIX:SVXFILETYPE_VAR );
788 			break;
789 		}
790 		case ID_AUTHORFIELD:
791 		{
792 			SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, aFieldItem.GetField() );
793 			if(pAuthor)
794 				pAuthor->SetType( (SvxAuthorType)bFix?SVXAUTHORTYPE_FIX:SVXAUTHORTYPE_VAR );
795 			break;
796 		}
797 		default:
798 			throw beans::UnknownPropertyException();
799 		}
800 		}
801 		break;
802 	case WID_PRES:
803 	case WID_URL:
804 	case WID_TARGET:
805 	{
806 		SvxURLField* pURL = PTR_CAST( SvxURLField, aFieldItem.GetField() );
807 		if(pURL)
808 		{
809 			OUString aUnoStr;
810 			if(!(aValue >>= aUnoStr))
811 				throw lang::IllegalArgumentException();
812 
813 			switch( pMap->nWID )
814 			{
815 			case WID_PRES:
816 				pURL->SetRepresentation( aUnoStr );
817 				break;
818 			case WID_URL:
819 				pURL->SetURL( aUnoStr );
820 				break;
821 			case WID_TARGET:
822 				pURL->SetTargetFrame( aUnoStr );
823 				break;
824 			}
825 		}
826 		break;
827 	}
828 	}
829 
830 	SfxItemSet aSet = pForwarder->GetAttribs( GetSelection() );
831 	aSet.Put( aFieldItem );
832 */
833 }
834 
getPropertyValue(const OUString & PropertyName)835 uno::Any SAL_CALL SvxUnoTextField::getPropertyValue( const OUString& PropertyName )
836 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
837 {
838 	OGuard aGuard( Application::GetSolarMutex() );
839 
840 	uno::Any aValue;
841 
842     const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMap()->getByName( PropertyName );
843 	if ( !pMap )
844 		throw beans::UnknownPropertyException();
845 
846 	switch( pMap->nWID )
847 	{
848 	case WID_DATE:
849 		aValue <<= mpImpl->maDateTime;
850 		break;
851 	case WID_BOOL1:
852 		aValue <<= mpImpl->mbBoolean1;
853 		break;
854 	case WID_BOOL2:
855 		aValue <<= mpImpl->mbBoolean2;
856 		break;
857 	case WID_INT16:
858 		aValue <<= mpImpl->mnInt16;
859 		break;
860 	case WID_INT32:
861 		aValue <<= mpImpl->mnInt32;
862 		break;
863 	case WID_STRING1:
864 		aValue <<= mpImpl->msString1;
865 		break;
866 	case WID_STRING2:
867 		aValue <<= mpImpl->msString2;
868 		break;
869 	case WID_STRING3:
870 		aValue <<= mpImpl->msString3;
871 		break;
872 	}
873 
874 	return aValue;
875 
876 /*
877 	switch(pMap->nWID)
878 	{
879 	case WID_FORMAT:
880 		switch( mnId )
881 		{
882 		case ID_DATEFIELD:
883 		{
884 			SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
885 			if(pDate)
886 				aValue <<= (sal_Int32)pDate->GetFormat();
887 			break;
888 		}
889 		case ID_URLFIELD:
890 		{
891 			SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
892 			if(pURL)
893 				aValue <<= (sal_Int32)pURL->GetFormat();
894 			break;
895 		}
896 		case ID_EXT_TIMEFIELD:
897 		{
898 			SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
899 			if(pTime)
900 				aValue <<= (sal_Int32)pTime->GetFormat();
901 			break;
902 		}
903 		case ID_EXT_FILEFIELD:
904 		{
905 			SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
906 			if(pFile)
907 				aValue <<= (sal_Int32)pFile->GetFormat();
908 			break;
909 		}
910 		case ID_AUTHORFIELD:
911 		{
912 			SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
913 			if(pAuthor)
914 				aValue <<= (sal_Int32)pAuthor->GetFormat();
915 			break;
916 		}
917 		default:
918 			throw beans::UnknownPropertyException();
919 		}
920 		break;
921 	case WID_FIX:
922 		{
923 			sal_Bool bFix = sal_False;
924 		switch( mnId )
925 		{
926 		case ID_EXT_TIMEFIELD:
927 		{
928 			SvxExtTimeField* pTime = PTR_CAST( SvxExtTimeField, pFieldItem->GetField() );
929 			if(pTime)
930 				bFix = pTime->GetType() == SVXTIMETYPE_FIX;
931 			break;
932 		}
933 		case ID_DATEFIELD:
934 		{
935 			SvxDateField* pDate = PTR_CAST( SvxDateField, pFieldItem->GetField() );
936 			if(pDate)
937 				bFix = pDate->GetType() == SVXDATETYPE_FIX;
938 			break;
939 		}
940 		case ID_EXT_FILEFIELD:
941 		{
942 			SvxExtFileField* pFile = PTR_CAST( SvxExtFileField, pFieldItem->GetField() );
943 			if(pFile)
944 				bFix = pFile->GetType() == SVXFILETYPE_FIX;
945 			break;
946 		}
947 		case ID_AUTHORFIELD:
948 		{
949 			SvxAuthorField* pAuthor = PTR_CAST( SvxAuthorField, pFieldItem->GetField() );
950 			if(pAuthor)
951 				bFix = pAuthor->GetType() == SVXAUTHORTYPE_FIX;
952 			break;
953 		}
954 		default:
955 			throw beans::UnknownPropertyException();
956 		}
957 		aValue.setValue( &bFix, ::getCppuBooleanType() );
958 		}
959 		break;
960 	case WID_PRES:
961 	case WID_URL:
962 	case WID_TARGET:
963 	{
964 		SvxURLField* pURL = PTR_CAST( SvxURLField, pFieldItem->GetField() );
965 		if(pURL)
966 		{
967 			OUString aStr;
968 			switch( pMap->nWID )
969 			{
970 			case WID_PRES:
971 				aStr = pURL->GetRepresentation();
972 				break;
973 			case WID_URL:
974 				aStr = pURL->GetURL();
975 				break;
976 			case WID_TARGET:
977 				aStr = pURL->GetTargetFrame();
978 				break;
979 			}
980 			aValue <<= aStr;
981 		}
982 		break;
983 	}
984 	case WID_FCOLOR:
985 	case WID_TCOLOR:
986 	{
987 		Color* pFColor = NULL;
988 		Color* pTColor = NULL;
989 		const ESelection aSel = GetSelection();
990 
991 		pForwarder->CalcFieldValue( *pFieldItem, aSel.nStartPara, aSel.nStartPos, pTColor, pFColor );
992 
993 		if( pMap->nWID == WID_FCOLOR )
994 			aValue <<= (sal_Int32)pFColor->GetColor();
995 		else
996 			aValue <<= (sal_Int32)pTColor->GetColor();
997 		break;
998 
999 		delete pTColor;
1000 		delete pFColor;
1001 	}
1002 	}
1003 	return aValue;
1004 */
1005 }
1006 
addPropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1007 void SAL_CALL SvxUnoTextField::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
removePropertyChangeListener(const OUString &,const uno::Reference<beans::XPropertyChangeListener> &)1008 void SAL_CALL SvxUnoTextField::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
addVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1009 void SAL_CALL SvxUnoTextField::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
removeVetoableChangeListener(const OUString &,const uno::Reference<beans::XVetoableChangeListener> &)1010 void SAL_CALL SvxUnoTextField::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& ) throw(::com::sun::star::beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
1011 
1012 // OComponentHelper
disposing()1013 void SvxUnoTextField::disposing()
1014 {
1015 	// nothing to do
1016 }
1017 
GetFieldId(const SvxFieldData * pFieldData) const1018 sal_Int32 SvxUnoTextField::GetFieldId( const SvxFieldData* pFieldData ) const throw()
1019 {
1020 	if( pFieldData->ISA( SvxURLField ) )
1021 		return ID_URLFIELD;
1022 	else if( pFieldData->ISA( SvxPageField ) )
1023 		return ID_PAGEFIELD;
1024 	else if( pFieldData->ISA( SvxPagesField ) )
1025 		return ID_PAGESFIELD;
1026 	else if( pFieldData->ISA( SvxTimeField )	)
1027 		return ID_TIMEFIELD;
1028 	else if( pFieldData->ISA( SvxFileField )	)
1029 		return ID_FILEFIELD;
1030 	else if( pFieldData->ISA( SvxTableField ) )
1031 		return ID_TABLEFIELD;
1032 	else if( pFieldData->ISA( SvxExtTimeField ) )
1033 		return ID_EXT_TIMEFIELD;
1034 	else if( pFieldData->ISA( SvxExtFileField ) )
1035 		return ID_EXT_FILEFIELD;
1036 	else if( pFieldData->ISA( SvxAuthorField ) )
1037 		return ID_AUTHORFIELD;
1038 	else if( pFieldData->ISA( SvxDateField ) )
1039 		return ID_EXT_DATEFIELD;
1040 	else if( pFieldData->ISA( SdrMeasureField )	)
1041 		return ID_MEASUREFIELD;
1042 	else if( pFieldData->ISA( SvxHeaderField ) )
1043 		return ID_HEADERFIELD;
1044 	else if( pFieldData->ISA( SvxFooterField ) )
1045 		return ID_FOOTERFIELD;
1046 	else if( pFieldData->ISA( SvxDateTimeField ) )
1047 		return ID_DATETIMEFIELD;
1048 
1049 	return ID_UNKNOWN;
1050 }
1051 
1052 // lang::XServiceInfo
getImplementationName()1053 OUString SAL_CALL SvxUnoTextField::getImplementationName() throw(uno::RuntimeException)
1054 {
1055 	return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextField"));
1056 }
1057 
1058 static const sal_Char* pOldServiceNames[] =
1059 {
1060 	"com.sun.star.text.TextField.DateTime",
1061 	"com.sun.star.text.TextField.URL",
1062 	"com.sun.star.text.TextField.PageNumber",
1063 	"com.sun.star.text.TextField.PageCount",
1064 	"com.sun.star.text.TextField.DateTime",
1065 	"com.sun.star.text.TextField.DocInfo.Title",	// SvxFileField is used for title
1066 	"com.sun.star.text.TextField.SheetName",
1067 	"com.sun.star.text.TextField.DateTime",
1068 	"com.sun.star.text.TextField.FileName",
1069 	"com.sun.star.text.TextField.Author",
1070 	"com.sun.star.text.TextField.Measure",
1071 	"com.sun.star.text.TextField.DateTime",
1072 	"com.sun.star.presentation.TextField.Header",
1073 	"com.sun.star.presentation.TextField.Footer",
1074 	"com.sun.star.presentation.TextField.DateTime"
1075 };
1076 
1077 static const sal_Char* pNewServiceNames[] =
1078 {
1079     "com.sun.star.text.textfield.DateTime",
1080     "com.sun.star.text.textfield.URL",
1081     "com.sun.star.text.textfield.PageNumber",
1082     "com.sun.star.text.textfield.PageCount",
1083     "com.sun.star.text.textfield.DateTime",
1084     "com.sun.star.text.textfield.docinfo.Title",    // SvxFileField is used for title
1085     "com.sun.star.text.textfield.SheetName",
1086     "com.sun.star.text.textfield.DateTime",
1087     "com.sun.star.text.textfield.FileName",
1088     "com.sun.star.text.textfield.Author",
1089     "com.sun.star.text.textfield.Measure",
1090     "com.sun.star.text.textfield.DateTime",
1091     "com.sun.star.presentation.textfield.Header",
1092     "com.sun.star.presentation.textfield.Footer",
1093     "com.sun.star.presentation.textfield.DateTime"
1094 };
1095 
getSupportedServiceNames()1096 uno::Sequence< OUString > SAL_CALL SvxUnoTextField::getSupportedServiceNames()
1097 	throw(uno::RuntimeException)
1098 {
1099     uno::Sequence< OUString > aSeq( 4 );
1100 	OUString* pServices = aSeq.getArray();
1101     pServices[0] = OUString::createFromAscii( pNewServiceNames[mnServiceId] );
1102     pServices[1] = OUString::createFromAscii( pOldServiceNames[mnServiceId] );
1103     pServices[2] = OUString::createFromAscii( "com.sun.star.text.TextContent" ),
1104     pServices[3] = OUString::createFromAscii( "com.sun.star.text.TextField" );
1105 
1106 	return aSeq;
1107 }
1108 
supportsService(const OUString & ServiceName)1109 sal_Bool SAL_CALL SvxUnoTextField::supportsService( const OUString& ServiceName ) throw( uno::RuntimeException )
1110 {
1111 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
1112 }
1113 
SvxUnoTextCreateTextField(const::rtl::OUString & ServiceSpecifier)1114 uno::Reference< uno::XInterface > SAL_CALL SvxUnoTextCreateTextField( const ::rtl::OUString& ServiceSpecifier ) throw(::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
1115 {
1116 	uno::Reference< uno::XInterface > xRet;
1117 
1118 	const OUString aTextFieldPrexit( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.textfield.") );
1119 
1120 	// #i93308# up to OOo 3.2 we used this wrong namespace name with the capital T & F. This is
1121 	// fixed since OOo 3.2 but for compatibility we will still provide support for the wrong notation.
1122 	const OUString aTextFieldPrexit2( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.") );
1123 
1124 	if( (ServiceSpecifier.compareTo( aTextFieldPrexit, aTextFieldPrexit.getLength() ) == 0) ||
1125 	    (ServiceSpecifier.compareTo( aTextFieldPrexit2, aTextFieldPrexit2.getLength() ) == 0) )
1126 	{
1127 		OUString aFieldType( ServiceSpecifier.copy( aTextFieldPrexit.getLength() ) );
1128 
1129 		sal_Int32 nId = ID_UNKNOWN;
1130 
1131 		if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("DateTime") ) )
1132 		{
1133 			nId = ID_DATEFIELD;
1134 		}
1135 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("URL") ) )
1136 		{
1137 			nId = ID_URLFIELD;
1138 		}
1139 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageNumber") ) )
1140 		{
1141 			nId = ID_PAGEFIELD;
1142 		}
1143 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("PageCount") ) )
1144 		{
1145 			nId = ID_PAGESFIELD;
1146 		}
1147 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("SheetName") ) )
1148 		{
1149 			nId = ID_TABLEFIELD;
1150 		}
1151 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("FileName") ) )
1152 		{
1153 			nId = ID_EXT_FILEFIELD;
1154 		}
1155         else if (aFieldType.equalsAsciiL(
1156                     RTL_CONSTASCII_STRINGPARAM("docinfo.Title") ) ||
1157                  aFieldType.equalsAsciiL(
1158                     RTL_CONSTASCII_STRINGPARAM("DocInfo.Title") ) )
1159 		{
1160 			nId = ID_FILEFIELD;
1161 		}
1162 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Author") ) )
1163 		{
1164 			nId = ID_AUTHORFIELD;
1165 		}
1166 		else if( aFieldType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("Measure") ) )
1167 		{
1168 			nId = ID_MEASUREFIELD;
1169 		}
1170 
1171 		if( nId != ID_UNKNOWN )
1172 			xRet = (::cppu::OWeakObject * )new SvxUnoTextField( nId );
1173 	}
1174 
1175 	return xRet;
1176 }
1177