xref: /trunk/main/editeng/source/uno/unotext.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_editeng.hxx"
30 #include <vcl/svapp.hxx>
31 #include <com/sun/star/style/LineSpacing.hpp>
32 #include <com/sun/star/text/ControlCharacter.hpp>
33 #include <com/sun/star/text/ControlCharacter.hpp>
34 #include <com/sun/star/text/XTextField.hdl>
35 #include <vos/mutex.hxx>
36 #include <svl/itemset.hxx>
37 #include <svl/itempool.hxx>
38 #include <svl/intitem.hxx>
39 #include <svl/eitem.hxx>
40 #include <rtl/uuid.h>
41 #include <rtl/memory.h>
42 
43 #include <editeng/fontitem.hxx>
44 #include <editeng/tstpitem.hxx>
45 #include <editeng/unoprnms.hxx>
46 #include <editeng/unotext.hxx>
47 #include <editeng/unoedsrc.hxx>
48 #include <editeng/unonrule.hxx>
49 #include <editeng/unofdesc.hxx>
50 #include <editeng/unofield.hxx>
51 #include <editeng/flditem.hxx>
52 #include <editeng/numitem.hxx>
53 #include <editeng/editeng.hxx>
54 #include <editeng/outliner.hxx>
55 #include <editeng/unoipset.hxx>
56 #include <comphelper/serviceinfohelper.hxx>
57 
58 using namespace ::rtl;
59 using namespace ::vos;
60 using namespace ::cppu;
61 using namespace ::com::sun::star;
62 
63 #define QUERYINT( xint ) \
64 	if( rType == ::getCppuType((const uno::Reference< xint >*)0) ) \
65         return uno::makeAny(uno::Reference< xint >(this))
66 
67 const SvxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSvxPropertySet()
68 {
69 	static SvxItemPropertySet aTextCursorSvxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap(), EditEngine::GetGlobalItemPool() );
70     return &aTextCursorSvxPropertySet;
71 }
72 
73 const SfxItemPropertyMapEntry* ImplGetSvxTextPortionPropertyMap()
74 {
75 	// Propertymap fuer einen Outliner Text
76     static const SfxItemPropertyMapEntry aSvxTextPortionPropertyMap[] =
77 	{
78 		SVX_UNOEDIT_CHAR_PROPERTIES,
79 		SVX_UNOEDIT_FONT_PROPERTIES,
80 		SVX_UNOEDIT_OUTLINER_PROPERTIES,
81 		SVX_UNOEDIT_PARA_PROPERTIES,
82 		{MAP_CHAR_LEN("TextField"),						EE_FEATURE_FIELD,	&::getCppuType((const uno::Reference< text::XTextField >*)0),	beans::PropertyAttribute::READONLY, 0 },
83 		{MAP_CHAR_LEN("TextPortionType"),				WID_PORTIONTYPE,	&::getCppuType((const ::rtl::OUString*)0), beans::PropertyAttribute::READONLY, 0 },
84 		{MAP_CHAR_LEN("TextUserDefinedAttributes"),			EE_CHAR_XMLATTRIBS,		&::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  , 		0,     0},
85 		{MAP_CHAR_LEN("ParaUserDefinedAttributes"),			EE_PARA_XMLATTRIBS,		&::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  , 		0,     0},
86 		{0,0,0,0,0,0}
87 	};
88 	return aSvxTextPortionPropertyMap;
89 }
90 const SvxItemPropertySet* ImplGetSvxTextPortionSvxPropertySet()
91 {
92 	static SvxItemPropertySet aSvxTextPortionPropertySet( ImplGetSvxTextPortionPropertyMap(), EditEngine::GetGlobalItemPool() );
93     return &aSvxTextPortionPropertySet;
94 }
95 
96 const SfxItemPropertySet* ImplGetSvxTextPortionSfxPropertySet()
97 {
98     static SfxItemPropertySet aSvxTextPortionSfxPropertySet( ImplGetSvxTextPortionPropertyMap() );
99     return &aSvxTextPortionSfxPropertySet;
100 }
101 
102 const SfxItemPropertyMapEntry* ImplGetSvxUnoOutlinerTextCursorPropertyMap()
103 {
104 	// Propertymap fuer einen Outliner Text
105     static const SfxItemPropertyMapEntry aSvxUnoOutlinerTextCursorPropertyMap[] =
106 	{
107 		SVX_UNOEDIT_CHAR_PROPERTIES,
108 		SVX_UNOEDIT_FONT_PROPERTIES,
109 		SVX_UNOEDIT_OUTLINER_PROPERTIES,
110 		SVX_UNOEDIT_PARA_PROPERTIES,
111 		{MAP_CHAR_LEN("TextUserDefinedAttributes"),			EE_CHAR_XMLATTRIBS,		&::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  , 		0,     0},
112 		{MAP_CHAR_LEN("ParaUserDefinedAttributes"),			EE_PARA_XMLATTRIBS,		&::getCppuType((const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >*)0)  , 		0,     0},
113 		{0,0,0,0,0,0}
114 	};
115 
116 	return aSvxUnoOutlinerTextCursorPropertyMap;
117 }
118 const SfxItemPropertySet* ImplGetSvxUnoOutlinerTextCursorSfxPropertySet()
119 {
120     static SfxItemPropertySet aTextCursorSfxPropertySet( ImplGetSvxUnoOutlinerTextCursorPropertyMap() );
121     return &aTextCursorSfxPropertySet;
122 }
123 
124 // ====================================================================
125 // helper fuer Item/Property Konvertierung
126 // ====================================================================
127 
128 void GetSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw()
129 {
130 	DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" );
131 	if( pForwarder )
132 	{
133 		sal_Int16 nParaCount = pForwarder->GetParagraphCount();
134 		if(nParaCount>0)
135 			nParaCount--;
136 
137 		rSel = ESelection( 0,0, nParaCount, pForwarder->GetTextLen( nParaCount ));
138 	}
139 }
140 
141 void CheckSelection( struct ESelection& rSel, SvxTextForwarder* pForwarder ) throw()
142 {
143 	DBG_ASSERT( pForwarder, "I need a valid SvxTextForwarder!" );
144 	if( pForwarder )
145 	{
146 		if( rSel.nStartPara == 0xffff )
147 		{
148 			::GetSelection( rSel, pForwarder );
149 		}
150 		else
151 		{
152 			ESelection aMaxSelection;
153 			GetSelection( aMaxSelection, pForwarder );
154 
155 			// check start position
156 			if( rSel.nStartPara < aMaxSelection.nStartPara )
157 			{
158 				rSel.nStartPara = aMaxSelection.nStartPara;
159 				rSel.nStartPos = aMaxSelection.nStartPos;
160 			}
161 			else if( rSel.nStartPara > aMaxSelection.nEndPara )
162 			{
163 				rSel.nStartPara = aMaxSelection.nEndPara;
164 				rSel.nStartPos = aMaxSelection.nEndPos;
165 			}
166 			else if( rSel.nStartPos  > pForwarder->GetTextLen( rSel.nStartPara ) )
167 			{
168 				rSel.nStartPos = pForwarder->GetTextLen( rSel.nStartPara );
169 			}
170 
171 			// check end position
172 			if( rSel.nEndPara < aMaxSelection.nStartPara )
173 			{
174 				rSel.nEndPara = aMaxSelection.nStartPara;
175 				rSel.nEndPos = aMaxSelection.nStartPos;
176 			}
177 			else if( rSel.nEndPara > aMaxSelection.nEndPara )
178 			{
179 				rSel.nEndPara = aMaxSelection.nEndPara;
180 				rSel.nEndPos = aMaxSelection.nEndPos;
181 			}
182 			else if( rSel.nEndPos > pForwarder->GetTextLen( rSel.nEndPara ) )
183 			{
184 				rSel.nEndPos = pForwarder->GetTextLen( rSel.nEndPara );
185 			}
186 		}
187 	}
188 }
189 
190 // ====================================================================
191 // class SvxUnoTextRangeBase
192 // ====================================================================
193 
194 #ifdef DEBUG
195 class check_me
196 {
197 public:
198 	check_me() : mnAllocNum(0) {};
199 	~check_me();
200 
201 	void add( SvxUnoTextRangeBase* pRange );
202 	void remove( SvxUnoTextRangeBase* pRange );
203 
204 	std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > > maRanges;
205 	sal_uInt32 mnAllocNum;
206 };
207 
208 void check_me::add( SvxUnoTextRangeBase* pRange )
209 {
210 	maRanges.push_back( std::pair< sal_uInt32, SvxUnoTextRangeBase* >( mnAllocNum++, pRange ) );
211 }
212 
213 void check_me::remove( SvxUnoTextRangeBase* pRange )
214 {
215 	std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > >::iterator aIter;
216 	for( aIter = maRanges.begin(); aIter != maRanges.end(); aIter++ )
217 	{
218 		if( pRange == (*aIter).second )
219 		{
220 			maRanges.erase( aIter );
221 			break;
222 		}
223 	}
224 }
225 
226 check_me::~check_me()
227 {
228 	if( !maRanges.empty() )
229 	{
230 		DBG_ERROR("living text range detected!");
231 		std::list< std::pair< sal_uInt32, SvxUnoTextRangeBase* > >::iterator aIter;
232 		for( aIter = maRanges.begin(); aIter != maRanges.end(); aIter++ )
233 		{
234 			sal_Int32 nAllocNum;
235 			SvxUnoTextRangeBase* pRange;
236             nAllocNum = (*aIter).first;
237             pRange = (*aIter).second;
238 		}
239 	}
240 }
241 
242 static check_me gNumRanges;
243 #endif
244 
245 UNO3_GETIMPLEMENTATION_IMPL( SvxUnoTextRangeBase );
246 
247 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxItemPropertySet* _pSet ) throw()
248 : mpEditSource(NULL) , mpPropSet(_pSet)
249 {
250 #ifdef DEBUG
251 	gNumRanges.add(this);
252 #endif
253 }
254 
255 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet ) throw()
256 : mpPropSet(_pSet)
257 {
258 	OGuard aGuard( Application::GetSolarMutex() );
259 
260 	DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
261 
262 	mpEditSource = pSource->Clone();
263     if (mpEditSource != NULL)
264     {
265         ESelection aSelection;
266         ::GetSelection( aSelection, mpEditSource->GetTextForwarder() );
267         SetSelection( aSelection );
268 
269 		mpEditSource->addRange( this );
270     }
271 #ifdef DEBUG
272 	gNumRanges.add(this);
273 #endif
274 }
275 
276 SvxUnoTextRangeBase::SvxUnoTextRangeBase( const SvxUnoTextRangeBase& rRange ) throw()
277 :	text::XTextRange()
278 ,	beans::XPropertySet()
279 ,	beans::XMultiPropertySet()
280 ,   beans::XMultiPropertyStates()
281 ,	beans::XPropertyState()
282 ,	lang::XServiceInfo()
283 ,	text::XTextRangeCompare()
284 ,	lang::XUnoTunnel()
285 ,	mpPropSet(rRange.getPropertySet())
286 {
287 	OGuard aGuard( Application::GetSolarMutex() );
288 
289 	mpEditSource = rRange.mpEditSource ? rRange.mpEditSource->Clone() : NULL;
290 
291 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
292 	if( pForwarder )
293 	{
294 		maSelection  = rRange.maSelection;
295 		CheckSelection( maSelection, pForwarder );
296 	}
297 
298 	if( mpEditSource )
299 		mpEditSource->addRange( this );
300 
301 #ifdef DEBUG
302 	gNumRanges.add(this);
303 #endif
304 }
305 
306 SvxUnoTextRangeBase::~SvxUnoTextRangeBase() throw()
307 {
308 #ifdef DEBUG
309 	gNumRanges.remove(this);
310 #endif
311 
312 	if( mpEditSource )
313 		mpEditSource->removeRange( this );
314 
315 	delete mpEditSource;
316 }
317 
318 void SvxUnoTextRangeBase::SetEditSource( SvxEditSource* pSource ) throw()
319 {
320 	DBG_ASSERT(pSource,"SvxUnoTextRangeBase: I need a valid SvxEditSource!");
321 	DBG_ASSERT(mpEditSource==NULL,"SvxUnoTextRangeBase::SetEditSource called while SvxEditSource already set" );
322 
323 	mpEditSource = pSource;
324 
325 	maSelection.nStartPara = 0xffff;
326 
327 	if( mpEditSource )
328 		mpEditSource->addRange( this );
329 }
330 
331 /** puts a field item with a copy of the given FieldData into the itemset
332     corresponding with this range */
333 void SvxUnoTextRangeBase::attachField( const SvxFieldData* pData ) throw()
334 {
335 	OGuard aGuard( Application::GetSolarMutex() );
336 
337 	if( pData )
338 	{
339 		SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
340 		if( pForwarder )
341 		{
342             SvxFieldItem aField( *pData, EE_FEATURE_FIELD );
343 			pForwarder->QuickInsertField( aField, maSelection );
344 		}
345 	}
346 }
347 
348 void SvxUnoTextRangeBase::SetSelection( const ESelection& rSelection ) throw()
349 {
350 	OGuard aGuard( Application::GetSolarMutex() );
351 
352 	maSelection = rSelection;
353     if (mpEditSource != NULL)
354         CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
355 }
356 
357 // Interface XTextRange ( XText )
358 
359 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getStart(void)
360 	throw( uno::RuntimeException )
361 {
362 	OGuard aGuard( Application::GetSolarMutex() );
363 
364 	uno::Reference< text::XTextRange > xRange;
365 
366 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
367 	if( pForwarder )
368 	{
369 
370 		CheckSelection( maSelection, pForwarder );
371 
372 		SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() );
373 
374 		if(pText == NULL)
375 			throw uno::RuntimeException();
376 
377 		SvxUnoTextRange* pRange = new SvxUnoTextRange( *pText );
378 		xRange = pRange;
379 
380 		ESelection aNewSel = maSelection;
381 		aNewSel.nEndPara = aNewSel.nStartPara;
382 		aNewSel.nEndPos  = aNewSel.nStartPos;
383 		pRange->SetSelection( aNewSel );
384 	}
385 
386 	return xRange;
387 }
388 
389 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextRangeBase::getEnd(void)
390 	throw( uno::RuntimeException )
391 {
392 	OGuard aGuard( Application::GetSolarMutex() );
393 
394 	uno::Reference< text::XTextRange > xRet;
395 
396 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
397 	if( pForwarder )
398 	{
399 		CheckSelection( maSelection, pForwarder );
400 
401 		SvxUnoTextBase* pText = SvxUnoTextBase::getImplementation( getText() );
402 
403 		if(pText == NULL)
404 			throw uno::RuntimeException();
405 
406 		SvxUnoTextRange* pNew = new SvxUnoTextRange( *pText );
407 		xRet = pNew;
408 
409 		ESelection aNewSel = maSelection;
410 		aNewSel.nStartPara = aNewSel.nEndPara;
411 		aNewSel.nStartPos  = aNewSel.nEndPos;
412 		pNew->SetSelection( aNewSel );
413 	}
414 	return xRet;
415 }
416 
417 OUString SAL_CALL SvxUnoTextRangeBase::getString(void)
418 	throw( uno::RuntimeException )
419 {
420 	OGuard aGuard( Application::GetSolarMutex() );
421 
422 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
423 	if( pForwarder )
424 	{
425 		CheckSelection( maSelection, pForwarder );
426 
427 		return pForwarder->GetText( maSelection );
428 	}
429 	else
430 	{
431 		const OUString aEmpty;
432 		return aEmpty;
433 	}
434 }
435 
436 void SAL_CALL SvxUnoTextRangeBase::setString(const OUString& aString)
437 	throw( uno::RuntimeException )
438 {
439 	OGuard aGuard( Application::GetSolarMutex() );
440 
441 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
442 	if( pForwarder )
443 	{
444 		CheckSelection( maSelection, pForwarder );
445 
446 		String aConverted( aString );
447 		aConverted.ConvertLineEnd( LINEEND_LF );		// Zeilenenden nur einfach zaehlen
448 
449 		pForwarder->QuickInsertText( aConverted, maSelection );
450 		mpEditSource->UpdateData();
451 
452 		//	Selektion anpassen
453 		//!	Wenn die EditEngine bei QuickInsertText die Selektion zurueckgeben wuerde,
454 		//!	waer's einfacher...
455 		CollapseToStart();
456 
457 		sal_uInt16 nLen = aConverted.Len();
458 		if (nLen)
459 			GoRight( nLen, sal_True );
460 	}
461 }
462 
463 // Interface beans::XPropertySet
464 uno::Reference< beans::XPropertySetInfo > SAL_CALL SvxUnoTextRangeBase::getPropertySetInfo(void)
465 	throw( uno::RuntimeException )
466 {
467 	return mpPropSet->getPropertySetInfo();
468 }
469 
470 void SAL_CALL SvxUnoTextRangeBase::setPropertyValue(const OUString& PropertyName, const uno::Any& aValue)
471 	throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
472 {
473 	_setPropertyValue( PropertyName, aValue, -1 );
474 }
475 
476 void SAL_CALL SvxUnoTextRangeBase::_setPropertyValue( const OUString& PropertyName, const uno::Any& aValue, sal_Int32 nPara )
477 	throw( beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException )
478 {
479 	OGuard aGuard( Application::GetSolarMutex() );
480 
481 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
482 	if( pForwarder )
483 	{
484 
485 		CheckSelection( maSelection, pForwarder );
486 
487         const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName );
488 		if ( pMap )
489 		{
490 			ESelection aSel( GetSelection() );
491 			sal_Bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END );
492 
493 			if( nPara == -1 && !bParaAttrib )
494 			{
495 				SfxItemSet aOldSet( pForwarder->GetAttribs( aSel ) );
496 				// we have a selection and no para attribute
497 				SfxItemSet aNewSet( *aOldSet.GetPool(), aOldSet.GetRanges() );
498 
499 				setPropertyValue( pMap, aValue, maSelection, aOldSet, aNewSet );
500 
501 
502 				pForwarder->QuickSetAttribs( aNewSet, GetSelection() );
503 			}
504 			else
505 			{
506 				sal_Int32 nEndPara;
507 
508 				if( nPara == -1 )
509 				{
510 					nPara = aSel.nStartPara;
511 					nEndPara = aSel.nEndPara;
512 				}
513 				else
514 				{
515 					// only one paragraph
516 					nEndPara = nPara;
517 				}
518 
519 				while( nPara <= nEndPara )
520 				{
521 					// we have a paragraph
522 					SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nPara ) );
523 					setPropertyValue( pMap, aValue, maSelection, aSet, aSet );
524 					pForwarder->SetParaAttribs( (sal_uInt16)nPara, aSet );
525 					nPara++;
526 				}
527 			}
528 
529 			GetEditSource()->UpdateData();
530 			return;
531 		}
532 	}
533 
534 	throw beans::UnknownPropertyException();
535 }
536 
537 void SvxUnoTextRangeBase::setPropertyValue( const SfxItemPropertySimpleEntry* pMap, const uno::Any& rValue, const ESelection& rSelection, const SfxItemSet& rOldSet, SfxItemSet& rNewSet ) throw( beans::UnknownPropertyException, lang::IllegalArgumentException )
538 {
539 	if(!SetPropertyValueHelper( rOldSet, pMap, rValue, rNewSet, &rSelection, GetEditSource() ))
540 	{
541 		//	Fuer Teile von zusammengesetzten Items mit mehreren Properties (z.B. Hintergrund)
542 		//	muss vorher das alte Item aus dem Dokument geholt werden
543 		rNewSet.Put(rOldSet.Get(pMap->nWID));			// altes Item in neuen Set
544 		mpPropSet->setPropertyValue(pMap, rValue, rNewSet, false );
545 	}
546 }
547 
548 sal_Bool SvxUnoTextRangeBase::SetPropertyValueHelper( const SfxItemSet&, const SfxItemPropertySimpleEntry* pMap, const uno::Any& aValue, SfxItemSet& rNewSet, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL*/ ) throw( uno::RuntimeException )
549 {
550 	switch( pMap->nWID )
551 	{
552 	case WID_FONTDESC:
553 		{
554 			awt::FontDescriptor aDesc;
555 			if(aValue >>= aDesc)
556 			{
557 				SvxUnoFontDescriptor::FillItemSet( aDesc, rNewSet );
558 				return sal_True;
559 			}
560 		}
561 		break;
562 
563 	case EE_PARA_NUMBULLET:
564 		{
565 			uno::Reference< container::XIndexReplace > xRule;
566 			if( !aValue.hasValue() || ((aValue >>= xRule) && !xRule.is()) )
567 				return sal_True;
568 
569 			return sal_False;
570 		}
571 
572 	case WID_NUMLEVEL:
573 		{
574 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
575 			if(pForwarder && pSelection)
576 			{
577 				sal_Int16 nLevel = sal_Int16();
578 				if( aValue >>= nLevel )
579 				{
580                     // #101004# Call interface method instead of unsafe cast
581                     if(! pForwarder->SetDepth( pSelection->nStartPara, nLevel ) )
582 						throw lang::IllegalArgumentException();
583 
584 					return sal_True;
585 				}
586 			}
587 		}
588 		break;
589     case WID_NUMBERINGSTARTVALUE:
590 		{
591 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
592 			if(pForwarder && pSelection)
593 			{
594 				sal_Int16 nStartValue = -1;
595 				if( aValue >>= nStartValue )
596                 {
597                     pForwarder->SetNumberingStartValue( pSelection->nStartPara, nStartValue );
598 	    			return sal_True;
599                 }
600 			}
601 		}
602 		break;
603     case WID_PARAISNUMBERINGRESTART:
604 		{
605 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
606 			if(pForwarder && pSelection)
607 			{
608 				sal_Bool bParaIsNumberingRestart = sal_False;
609 				if( aValue >>= bParaIsNumberingRestart )
610                 {
611                     pForwarder->SetParaIsNumberingRestart( pSelection->nStartPara, bParaIsNumberingRestart );
612 				    return sal_True;
613                 }
614 			}
615 		}
616 		break;
617 	case EE_PARA_BULLETSTATE:
618 		{
619 			sal_Bool bBullet = sal_True;
620 			if( aValue >>= bBullet )
621 			{
622 				SfxBoolItem aItem( EE_PARA_BULLETSTATE, bBullet );
623 				rNewSet.Put(aItem);
624 				return sal_True;
625 			}
626 		}
627 		break;
628 
629 	default:
630 		return sal_False;
631 	}
632 
633 	throw lang::IllegalArgumentException();
634 }
635 
636 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyValue(const OUString& PropertyName)
637 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
638 {
639 	return _getPropertyValue( PropertyName, -1 );
640 }
641 
642 uno::Any SAL_CALL SvxUnoTextRangeBase::_getPropertyValue(const OUString& PropertyName, sal_Int32 nPara )
643 	throw( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException )
644 {
645 	OGuard aGuard( Application::GetSolarMutex() );
646 
647 	uno::Any aAny;
648 
649 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
650 	if( pForwarder )
651 	{
652         const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName );
653 		if( pMap )
654 		{
655 			SfxItemSet* pAttribs = NULL;
656 			if( nPara != -1 )
657 				pAttribs = pForwarder->GetParaAttribs( (sal_uInt16)nPara ).Clone();
658 			else
659 				pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone();
660 
661 			//	Dontcare durch Default ersetzen, damit man immer eine Reflection hat
662 			pAttribs->ClearInvalidItems();
663 
664 			getPropertyValue( pMap, aAny, *pAttribs );
665 
666 			delete pAttribs;
667 			return aAny;
668 		}
669 	}
670 
671 	throw beans::UnknownPropertyException();
672 }
673 
674 void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry* pMap, uno::Any& rAny, const SfxItemSet& rSet ) throw( beans::UnknownPropertyException )
675 {
676 	switch( pMap->nWID )
677 	{
678 	case EE_FEATURE_FIELD:
679 		if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET )
680 		{
681 			SvxFieldItem* pItem = (SvxFieldItem*)rSet.GetItem( EE_FEATURE_FIELD );
682 			const SvxFieldData* pData = pItem->GetField();
683 			uno::Reference< text::XTextRange > xAnchor( this );
684 
685 			// get presentation string for field
686 			Color* pTColor = NULL;
687 			Color* pFColor = NULL;
688 
689 			SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder();
690             OUString aPresentation( pForwarder->CalcFieldValue( SvxFieldItem(*pData, EE_FEATURE_FIELD), maSelection.nStartPara, maSelection.nStartPos, pTColor, pFColor ) );
691 
692 			delete pTColor;
693 			delete pFColor;
694 
695 			uno::Reference< text::XTextField > xField( new SvxUnoTextField( xAnchor, aPresentation, pData ) );
696 			rAny <<= xField;
697 		}
698 		break;
699 
700 	case WID_PORTIONTYPE:
701 		if ( rSet.GetItemState( EE_FEATURE_FIELD, sal_False ) == SFX_ITEM_SET )
702 		{
703 			OUString aType( RTL_CONSTASCII_USTRINGPARAM("TextField") );
704 			rAny <<= aType;
705 		}
706 		else
707 		{
708 			OUString aType( RTL_CONSTASCII_USTRINGPARAM("Text") );
709 			rAny <<= aType;
710 		}
711 		break;
712 
713 	default:
714 		if(!GetPropertyValueHelper( *((SfxItemSet*)(&rSet)), pMap, rAny, &maSelection, GetEditSource() ))
715 			rAny = mpPropSet->getPropertyValue(pMap, rSet, true, false );
716 	}
717 }
718 
719 sal_Bool SvxUnoTextRangeBase::GetPropertyValueHelper(  SfxItemSet& rSet, const SfxItemPropertySimpleEntry* pMap, uno::Any& aAny, const ESelection* pSelection /* = NULL */, SvxEditSource* pEditSource /* = NULL */ )
720 	throw( uno::RuntimeException )
721 {
722 	switch( pMap->nWID )
723 	{
724 	case WID_FONTDESC:
725 		{
726 			awt::FontDescriptor aDesc;
727 			SvxUnoFontDescriptor::FillFromItemSet( rSet, aDesc );
728 			aAny <<= aDesc;
729 		}
730 		break;
731 
732 	case EE_PARA_NUMBULLET:
733 		{
734 			if((rSet.GetItemState( EE_PARA_NUMBULLET, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT)) == 0)
735 				throw uno::RuntimeException();
736 
737 			SvxNumBulletItem* pBulletItem = (SvxNumBulletItem*)rSet.GetItem( EE_PARA_NUMBULLET, sal_True );
738 
739 			if( pBulletItem == NULL )
740 				throw uno::RuntimeException();
741 
742 			aAny <<= SvxCreateNumRule( pBulletItem->GetNumRule() );
743 		}
744 		break;
745 
746 	case WID_NUMLEVEL:
747 		{
748 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
749 			if(pForwarder && pSelection)
750 			{
751 				sal_Int16 nLevel = pForwarder->GetDepth( pSelection->nStartPara );
752 				if( nLevel >= 0 )
753 					aAny <<= nLevel;
754 			}
755 		}
756 		break;
757     case WID_NUMBERINGSTARTVALUE:
758 		{
759 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
760 			if(pForwarder && pSelection)
761 				aAny <<= pForwarder->GetNumberingStartValue( pSelection->nStartPara );
762 		}
763 		break;
764     case WID_PARAISNUMBERINGRESTART:
765 		{
766 			SvxTextForwarder* pForwarder = pEditSource? pEditSource->GetTextForwarder() : NULL;
767 			if(pForwarder && pSelection)
768 				aAny <<= pForwarder->IsParaIsNumberingRestart( pSelection->nStartPara );
769 		}
770 		break;
771 
772 	case EE_PARA_BULLETSTATE:
773 		{
774 			sal_Bool bState = sal_False;
775 			if( rSet.GetItemState( EE_PARA_BULLETSTATE, sal_True ) & (SFX_ITEM_SET|SFX_ITEM_DEFAULT))
776 			{
777 				SfxBoolItem* pItem = (SfxBoolItem*)rSet.GetItem( EE_PARA_BULLETSTATE, sal_True );
778                 bState = pItem->GetValue() ? sal_True : sal_False;
779 			}
780 
781 			aAny <<= bState;
782 		}
783 		break;
784 	default:
785 
786 		return sal_False;
787 	}
788 
789 	return sal_True;
790 }
791 
792 // wird (noch) nicht unterstuetzt
793 void SAL_CALL SvxUnoTextRangeBase::addPropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
794 void SAL_CALL SvxUnoTextRangeBase::removePropertyChangeListener( const OUString& , const uno::Reference< beans::XPropertyChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
795 void SAL_CALL SvxUnoTextRangeBase::addVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
796 void SAL_CALL SvxUnoTextRangeBase::removeVetoableChangeListener( const OUString& , const uno::Reference< beans::XVetoableChangeListener >& ) throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) {}
797 
798 // XMultiPropertySet
799 void SAL_CALL SvxUnoTextRangeBase::setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
800 {
801 	_setPropertyValues( aPropertyNames, aValues, -1 );
802 }
803 
804 void SAL_CALL SvxUnoTextRangeBase::_setPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, const uno::Sequence< uno::Any >& aValues, sal_Int32 nPara ) throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
805 {
806 	OGuard aGuard( Application::GetSolarMutex() );
807 
808 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
809 	if( pForwarder )
810 	{
811 		CheckSelection( maSelection, pForwarder );
812 
813 		ESelection aSel( GetSelection() );
814 
815 		const OUString* pPropertyNames = aPropertyNames.getConstArray();
816 		const uno::Any* pValues = aValues.getConstArray();
817 		sal_Int32 nCount = aPropertyNames.getLength();
818 
819 		sal_Int32 nEndPara = nPara;
820 		sal_Int32 nTempPara = nPara;
821 
822 		if( nTempPara == -1 )
823 		{
824 			nTempPara = aSel.nStartPara;
825 			nEndPara = aSel.nEndPara;
826 		}
827 
828 		SfxItemSet* pOldAttrSet = NULL;
829 		SfxItemSet* pNewAttrSet = NULL;
830 
831 		SfxItemSet* pOldParaSet = NULL;
832 		SfxItemSet* pNewParaSet = NULL;
833 
834 		for( ; nCount; nCount--, pPropertyNames++, pValues++ )
835 		{
836             const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
837 
838 			if( pMap )
839 			{
840 				sal_Bool bParaAttrib = (pMap->nWID >= EE_PARA_START) && ( pMap->nWID <= EE_PARA_END );
841 
842 				if( (nPara == -1) && !bParaAttrib )
843 				{
844 					if( NULL == pNewAttrSet )
845 					{
846 						const SfxItemSet aSet( pForwarder->GetAttribs( aSel ) );
847 						pOldAttrSet = new SfxItemSet( aSet );
848 						pNewAttrSet = new SfxItemSet( *pOldAttrSet->GetPool(), pOldAttrSet->GetRanges() );
849 					}
850 
851 					setPropertyValue( pMap, *pValues, GetSelection(), *pOldAttrSet, *pNewAttrSet );
852 
853 					if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
854 					{
855 						const SfxPoolItem* pItem;
856 						if( pNewAttrSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET )
857 						{
858 							pOldAttrSet->Put( *pItem );
859 						}
860 					}
861 				}
862 				else
863 				{
864 					if( NULL == pNewParaSet )
865 					{
866 						const SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nTempPara ) );
867 						pOldParaSet = new SfxItemSet( aSet );
868 						pNewParaSet = new SfxItemSet( *pOldParaSet->GetPool(), pOldParaSet->GetRanges() );
869 					}
870 
871 					setPropertyValue( pMap, *pValues, GetSelection(), *pOldParaSet, *pNewParaSet );
872 
873 					if( pMap->nWID >= EE_ITEMS_START && pMap->nWID <= EE_ITEMS_END )
874 					{
875 						const SfxPoolItem* pItem;
876 						if( pNewParaSet->GetItemState( pMap->nWID, sal_True, &pItem ) == SFX_ITEM_SET )
877 						{
878 							pOldParaSet->Put( *pItem );
879 						}
880 					}
881 
882 				}
883 			}
884 		}
885 
886 		sal_Bool bNeedsUpdate = sal_False;
887 
888 		if( pNewParaSet )
889 		{
890 			if( pNewParaSet->Count() )
891 			{
892 				while( nTempPara <= nEndPara )
893 				{
894 					SfxItemSet aSet( pForwarder->GetParaAttribs( (sal_uInt16)nTempPara ) );
895 					aSet.Put( *pNewParaSet );
896 					pForwarder->SetParaAttribs( (sal_uInt16)nTempPara, aSet );
897 					nTempPara++;
898 				}
899 				bNeedsUpdate = sal_True;
900 			}
901 
902 			delete pNewParaSet;
903 			delete pOldParaSet;
904 		}
905 
906 		if( pNewAttrSet )
907 		{
908 			if( pNewAttrSet->Count() )
909 			{
910 				pForwarder->QuickSetAttribs( *pNewAttrSet, GetSelection() );
911 				bNeedsUpdate = sal_True;
912 			}
913 			delete pNewAttrSet;
914 			delete pOldAttrSet;
915 
916 		}
917 
918 		if( bNeedsUpdate )
919 			GetEditSource()->UpdateData();
920 	}
921 }
922 
923 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames ) throw (uno::RuntimeException)
924 {
925 	return _getPropertyValues( aPropertyNames, -1 );
926 }
927 
928 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::_getPropertyValues( const uno::Sequence< ::rtl::OUString >& aPropertyNames, sal_Int32 nPara ) throw (uno::RuntimeException)
929 {
930 	OGuard aGuard( Application::GetSolarMutex() );
931 
932 	sal_Int32 nCount = aPropertyNames.getLength();
933 
934 
935 	uno::Sequence< uno::Any > aValues( nCount );
936 
937 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
938 	if( pForwarder )
939 	{
940 		SfxItemSet* pAttribs = NULL;
941 		if( nPara != -1 )
942 			pAttribs = pForwarder->GetParaAttribs( (sal_uInt16)nPara ).Clone();
943 		else
944 			pAttribs = pForwarder->GetAttribs( GetSelection() ).Clone();
945 
946 		pAttribs->ClearInvalidItems();
947 
948 		const OUString* pPropertyNames = aPropertyNames.getConstArray();
949 		uno::Any* pValues = aValues.getArray();
950 
951 		for( ; nCount; nCount--, pPropertyNames++, pValues++ )
952 		{
953             const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pPropertyNames );
954 			if( pMap )
955 			{
956 				getPropertyValue( pMap, *pValues, *pAttribs );
957 			}
958 		}
959 
960 		delete pAttribs;
961 
962 	}
963 
964 	return aValues;
965 }
966 
967 void SAL_CALL SvxUnoTextRangeBase::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
968 {
969 }
970 
971 void SAL_CALL SvxUnoTextRangeBase::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
972 {
973 }
974 
975 void SAL_CALL SvxUnoTextRangeBase::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException)
976 {
977 }
978 
979 // beans::XPropertyState
980 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::getPropertyState( const OUString& PropertyName )
981 	throw(beans::UnknownPropertyException, uno::RuntimeException)
982 {
983 	return _getPropertyState( PropertyName, -1 );
984 }
985 
986 static sal_uInt16 aSvxUnoFontDescriptorWhichMap[] = { EE_CHAR_FONTINFO, EE_CHAR_FONTHEIGHT, EE_CHAR_ITALIC,
987 												  EE_CHAR_UNDERLINE, EE_CHAR_WEIGHT, EE_CHAR_STRIKEOUT,
988 												  EE_CHAR_WLM, 0 };
989 
990 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara)
991 	throw( beans::UnknownPropertyException, uno::RuntimeException )
992 {
993 	if ( pMap )
994 	{
995 	    SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
996 	    if( pForwarder )
997 	    {
998 		    SfxItemState eItemState = SFX_ITEM_UNKNOWN;
999 		    sal_uInt16 nWID = 0;
1000 
1001 		    switch( pMap->nWID )
1002 		    {
1003 		    case WID_FONTDESC:
1004 			    {
1005 				    sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
1006 				    SfxItemState eTempItemState;
1007 				    while( *pWhichId )
1008 				    {
1009 					    if(nPara != -1)
1010 						    eTempItemState = pForwarder->GetItemState( (sal_uInt16)nPara, *pWhichId );
1011 					    else
1012 						    eTempItemState = pForwarder->GetItemState( GetSelection(), *pWhichId );
1013 
1014 					    switch( eTempItemState )
1015 					    {
1016 					    case SFX_ITEM_DISABLED:
1017 					    case SFX_ITEM_DONTCARE:
1018 						    eItemState = SFX_ITEM_DONTCARE;
1019 						    break;
1020 
1021 					    case SFX_ITEM_DEFAULT:
1022 						    if( eItemState != SFX_ITEM_DEFAULT )
1023 						    {
1024 							    if( eItemState == SFX_ITEM_UNKNOWN )
1025 								    eItemState = SFX_ITEM_DEFAULT;
1026 						    }
1027 						    break;
1028 
1029 					    case SFX_ITEM_READONLY:
1030 					    case SFX_ITEM_SET:
1031 						    if( eItemState != SFX_ITEM_SET )
1032 						    {
1033 							    if( eItemState == SFX_ITEM_UNKNOWN )
1034 								    eItemState = SFX_ITEM_SET;
1035 						    }
1036 						    break;
1037 					    default:
1038 						    throw beans::UnknownPropertyException();
1039 					    }
1040 
1041 					    pWhichId++;
1042 				    }
1043 			    }
1044 			    break;
1045 
1046 		    case WID_NUMLEVEL:
1047             case WID_NUMBERINGSTARTVALUE:
1048             case WID_PARAISNUMBERINGRESTART:
1049 			    eItemState = SFX_ITEM_SET;
1050                 break;
1051 
1052 		    default:
1053 			    nWID = pMap->nWID;
1054 		    }
1055 
1056 		    if( nWID != 0 )
1057 		    {
1058 			    if( nPara != -1 )
1059 				    eItemState = pForwarder->GetItemState( (sal_uInt16)nPara, nWID );
1060 			    else
1061 				    eItemState = pForwarder->GetItemState( GetSelection(), nWID );
1062 		    }
1063 
1064 		    switch( eItemState )
1065 		    {
1066 		    case SFX_ITEM_DONTCARE:
1067 		    case SFX_ITEM_DISABLED:
1068 			    return beans::PropertyState_AMBIGUOUS_VALUE;
1069 		    case SFX_ITEM_READONLY:
1070 		    case SFX_ITEM_SET:
1071 			    return beans::PropertyState_DIRECT_VALUE;
1072 		    case SFX_ITEM_DEFAULT:
1073 			    return beans::PropertyState_DEFAULT_VALUE;
1074 //  			case SFX_ITEM_UNKNOWN:
1075 		    }
1076         }
1077 	}
1078 	throw beans::UnknownPropertyException();
1079 }
1080 
1081 beans::PropertyState SAL_CALL SvxUnoTextRangeBase::_getPropertyState(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1082 	throw( beans::UnknownPropertyException, uno::RuntimeException )
1083 {
1084 	OGuard aGuard( Application::GetSolarMutex() );
1085 
1086     return _getPropertyState( mpPropSet->getPropertyMapEntry( PropertyName ), nPara);
1087 }
1088 
1089 uno::Sequence< beans::PropertyState > SAL_CALL SvxUnoTextRangeBase::getPropertyStates( const uno::Sequence< OUString >& aPropertyName )
1090 	throw(beans::UnknownPropertyException, uno::RuntimeException)
1091 {
1092 	return _getPropertyStates( aPropertyName, -1 );
1093 }
1094 
1095 uno::Sequence< beans::PropertyState > SvxUnoTextRangeBase::_getPropertyStates(const uno::Sequence< OUString >& PropertyName, sal_Int32 nPara /* = -1 */)
1096 	throw( beans::UnknownPropertyException, uno::RuntimeException )
1097 {
1098 	const sal_Int32 nCount = PropertyName.getLength();
1099 	const OUString* pNames = PropertyName.getConstArray();
1100 
1101 	uno::Sequence< beans::PropertyState > aRet( nCount );
1102 	beans::PropertyState* pState = aRet.getArray();
1103 
1104 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1105 	if( pForwarder )
1106 	{
1107 		SfxItemSet* pSet = NULL;
1108 		if( nPara != -1 )
1109 		{
1110 			pSet = new SfxItemSet( pForwarder->GetParaAttribs( (sal_uInt16)nPara ) );
1111 		}
1112 		else
1113 		{
1114 			ESelection aSel( GetSelection() );
1115 			CheckSelection( aSel, pForwarder );
1116 			pSet = new SfxItemSet( pForwarder->GetAttribs( aSel, EditEngineAttribs_OnlyHard ) );
1117 		}
1118 
1119 		sal_Bool bUnknownPropertyFound = sal_False;
1120 		for( sal_Int32 nIdx = 0; nIdx < nCount; nIdx++ )
1121 		{
1122             const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( *pNames++ );
1123 			if( NULL == pMap )
1124 			{
1125 				bUnknownPropertyFound = sal_True;
1126 				break;
1127 			}
1128             bUnknownPropertyFound = !_getOnePropertyStates(pSet, pMap, *pState++);
1129 		}
1130 
1131 		delete pSet;
1132 
1133 		if( bUnknownPropertyFound )
1134 			throw beans::UnknownPropertyException();
1135 	}
1136 
1137 	return aRet;
1138 }
1139 
1140 sal_Bool SvxUnoTextRangeBase::_getOnePropertyStates(const SfxItemSet* pSet, const SfxItemPropertySimpleEntry* pMap, beans::PropertyState& rState)
1141 {
1142     sal_Bool bUnknownPropertyFound = sal_False;
1143     if(pSet && pMap)
1144     {
1145 		SfxItemState eItemState = SFX_ITEM_UNKNOWN;
1146 		sal_uInt16 nWID = 0;
1147 
1148 		switch( pMap->nWID )
1149 		{
1150 			case WID_FONTDESC:
1151 				{
1152 					sal_uInt16* pWhichId = aSvxUnoFontDescriptorWhichMap;
1153 					SfxItemState eTempItemState;
1154 					while( *pWhichId )
1155 					{
1156 						eTempItemState = pSet->GetItemState( *pWhichId );
1157 
1158 						switch( eTempItemState )
1159 						{
1160 						case SFX_ITEM_DISABLED:
1161 						case SFX_ITEM_DONTCARE:
1162 							eItemState = SFX_ITEM_DONTCARE;
1163 							break;
1164 
1165 						case SFX_ITEM_DEFAULT:
1166 							if( eItemState != SFX_ITEM_DEFAULT )
1167 							{
1168 								if( eItemState == SFX_ITEM_UNKNOWN )
1169 									eItemState = SFX_ITEM_DEFAULT;
1170 							}
1171 							break;
1172 
1173 						case SFX_ITEM_READONLY:
1174 						case SFX_ITEM_SET:
1175 							if( eItemState != SFX_ITEM_SET )
1176 							{
1177 								if( eItemState == SFX_ITEM_UNKNOWN )
1178 									eItemState = SFX_ITEM_SET;
1179 							}
1180 							break;
1181 						default:
1182 							bUnknownPropertyFound = sal_True;
1183 							break;
1184 						}
1185 
1186 						pWhichId++;
1187 					}
1188 				}
1189 				break;
1190 
1191 			case WID_NUMLEVEL:
1192             case WID_NUMBERINGSTARTVALUE:
1193             case WID_PARAISNUMBERINGRESTART:
1194 				eItemState = SFX_ITEM_SET;
1195 				break;
1196 
1197 			default:
1198 				nWID = pMap->nWID;
1199 		}
1200 
1201 		if( bUnknownPropertyFound )
1202 			return !bUnknownPropertyFound;
1203 
1204 		if( nWID != 0 )
1205 			eItemState = pSet->GetItemState( nWID, sal_False );
1206 
1207 		switch( eItemState )
1208 		{
1209 				case SFX_ITEM_READONLY:
1210 				case SFX_ITEM_SET:
1211 					rState = beans::PropertyState_DIRECT_VALUE;
1212 					break;
1213 				case SFX_ITEM_DEFAULT:
1214 					rState = beans::PropertyState_DEFAULT_VALUE;
1215 					break;
1216 //					case SFX_ITEM_UNKNOWN:
1217 //					case SFX_ITEM_DONTCARE:
1218 //					case SFX_ITEM_DISABLED:
1219 				default:
1220 					rState = beans::PropertyState_AMBIGUOUS_VALUE;
1221 		}
1222     }
1223     return !bUnknownPropertyFound;
1224 }
1225 
1226 void SAL_CALL SvxUnoTextRangeBase::setPropertyToDefault( const OUString& PropertyName )
1227 	throw(beans::UnknownPropertyException, uno::RuntimeException)
1228 {
1229 	_setPropertyToDefault( PropertyName, -1 );
1230 }
1231 
1232 void SvxUnoTextRangeBase::_setPropertyToDefault(const OUString& PropertyName, sal_Int32 nPara /* = -1 */)
1233 	throw( beans::UnknownPropertyException, uno::RuntimeException )
1234 {
1235 	OGuard aGuard( Application::GetSolarMutex() );
1236 
1237 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1238 
1239     if( pForwarder )
1240     {
1241         const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( PropertyName );
1242 		if ( pMap )
1243         {
1244     		CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1245             _setPropertyToDefault( pForwarder, pMap, nPara );
1246             return;
1247         }
1248     }
1249 
1250 	throw beans::UnknownPropertyException();
1251 }
1252 
1253 void SvxUnoTextRangeBase::_setPropertyToDefault(SvxTextForwarder* pForwarder, const SfxItemPropertySimpleEntry* pMap, sal_Int32 nPara )
1254 	throw( beans::UnknownPropertyException, uno::RuntimeException )
1255 {
1256 	do
1257 	{
1258 		SfxItemSet aSet( *pForwarder->GetPool(), sal_True );
1259 
1260 		if( pMap->nWID == WID_FONTDESC )
1261 		{
1262 			SvxUnoFontDescriptor::setPropertyToDefault( aSet );
1263 		}
1264 		else if( pMap->nWID == WID_NUMLEVEL )
1265 		{
1266             // #101004# Call interface method instead of unsafe cast
1267             pForwarder->SetDepth( maSelection.nStartPara, -1 );
1268             return;
1269 		}
1270         else if( pMap->nWID == WID_NUMBERINGSTARTVALUE )
1271         {
1272             pForwarder->SetNumberingStartValue( maSelection.nStartPara, -1 );
1273         }
1274         else if( pMap->nWID == WID_PARAISNUMBERINGRESTART )
1275         {
1276             pForwarder->SetParaIsNumberingRestart( maSelection.nStartPara, sal_False );
1277         }
1278 		else
1279 		{
1280 			aSet.InvalidateItem( pMap->nWID );
1281 		}
1282 
1283 		if(nPara != -1)
1284 			pForwarder->SetParaAttribs( (sal_uInt16)nPara, aSet );
1285 		else
1286 			pForwarder->QuickSetAttribs( aSet, GetSelection() );
1287 
1288 		GetEditSource()->UpdateData();
1289 
1290 		return;
1291 	}
1292 	while(0);
1293 }
1294 
1295 uno::Any SAL_CALL SvxUnoTextRangeBase::getPropertyDefault( const OUString& aPropertyName )
1296 	throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1297 {
1298 	OGuard aGuard( Application::GetSolarMutex() );
1299 
1300 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1301 	if( pForwarder )
1302 	{
1303         const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry( aPropertyName );
1304 		if( pMap )
1305 		{
1306 			SfxItemPool* pPool = pForwarder->GetPool();
1307 
1308 			switch( pMap->nWID )
1309 			{
1310 			case WID_FONTDESC:
1311 				return SvxUnoFontDescriptor::getPropertyDefault( pPool );
1312 
1313 			case WID_NUMLEVEL:
1314                 {
1315                     uno::Any aAny;
1316 				    return aAny;
1317                 }
1318 
1319             case WID_NUMBERINGSTARTVALUE:
1320                 return uno::Any( (sal_Int16)-1 );
1321 
1322             case WID_PARAISNUMBERINGRESTART:
1323                 return uno::Any( (sal_Bool)sal_False );
1324 
1325 			default:
1326 				{
1327 					// Default aus ItemPool holen
1328 					if(pPool->IsWhich(pMap->nWID))
1329 					{
1330 						SfxItemSet aSet( *pPool,	pMap->nWID, pMap->nWID);
1331 						aSet.Put(pPool->GetDefaultItem(pMap->nWID));
1332 						return mpPropSet->getPropertyValue(pMap, aSet, true, false );
1333 					}
1334 				}
1335 			}
1336 		}
1337 	}
1338 	throw beans::UnknownPropertyException();
1339 }
1340 
1341 // beans::XMultiPropertyStates
1342 void SAL_CALL SvxUnoTextRangeBase::setAllPropertiesToDefault(  ) throw (uno::RuntimeException)
1343 {
1344 	OGuard aGuard( Application::GetSolarMutex() );
1345 
1346 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1347 
1348     if( pForwarder )
1349     {
1350         PropertyEntryVector_t aEntries = mpPropSet->getPropertyMap()->getPropertyEntries();
1351         PropertyEntryVector_t::const_iterator aIt = aEntries.begin();
1352         while( aIt != aEntries.end() )
1353         {
1354             _setPropertyToDefault( pForwarder, &(*aIt), -1 );
1355             ++aIt;
1356         }
1357     }
1358 }
1359 
1360 void SAL_CALL SvxUnoTextRangeBase::setPropertiesToDefault( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, uno::RuntimeException)
1361 {
1362     sal_Int32 nCount = aPropertyNames.getLength();
1363     for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount-- )
1364     {
1365         setPropertyToDefault( *pName );
1366     }
1367 }
1368 
1369 uno::Sequence< uno::Any > SAL_CALL SvxUnoTextRangeBase::getPropertyDefaults( const uno::Sequence< OUString >& aPropertyNames ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
1370 {
1371     sal_Int32 nCount = aPropertyNames.getLength();
1372     uno::Sequence< uno::Any > ret( nCount );
1373     uno::Any* pDefaults = ret.getArray();
1374 
1375     for( const OUString* pName = aPropertyNames.getConstArray(); nCount; pName++, nCount--, pDefaults++ )
1376     {
1377         *pDefaults = getPropertyDefault( *pName );
1378     }
1379 
1380     return ret;
1381 }
1382 
1383 // internal
1384 void SvxUnoTextRangeBase::CollapseToStart(void) throw()
1385 {
1386 	CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1387 
1388 	maSelection.nEndPara = maSelection.nStartPara;
1389 	maSelection.nEndPos  = maSelection.nStartPos;
1390 }
1391 
1392 void SvxUnoTextRangeBase::CollapseToEnd(void) throw()
1393 {
1394 	CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1395 
1396 	maSelection.nStartPara = maSelection.nEndPara;
1397 	maSelection.nStartPos  = maSelection.nEndPos;
1398 }
1399 
1400 sal_Bool SvxUnoTextRangeBase::IsCollapsed(void) throw()
1401 {
1402 	CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1403 
1404 	return ( maSelection.nStartPara == maSelection.nEndPara &&
1405 			 maSelection.nStartPos  == maSelection.nEndPos );
1406 }
1407 
1408 sal_Bool SvxUnoTextRangeBase::GoLeft(sal_Int16 nCount, sal_Bool Expand) throw()
1409 {
1410 	CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1411 
1412 	//	#75098# use end position, as in Writer (start is anchor, end is cursor)
1413 	sal_uInt16 nNewPos = maSelection.nEndPos;
1414 	sal_uInt16 nNewPar = maSelection.nEndPara;
1415 
1416 	sal_Bool bOk = sal_True;
1417 	SvxTextForwarder* pForwarder = NULL;
1418 	while ( nCount > nNewPos && bOk )
1419 	{
1420 		if ( nNewPar == 0 )
1421 			bOk = sal_False;
1422 		else
1423 		{
1424 			if ( !pForwarder )
1425 				pForwarder = mpEditSource->GetTextForwarder();	// erst hier, wenn's noetig ist...
1426 
1427 			--nNewPar;
1428 			nCount -= nNewPos + 1;
1429 			nNewPos = pForwarder->GetTextLen( nNewPar );
1430 		}
1431 	}
1432 
1433 	if ( bOk )
1434 	{
1435 		nNewPos = nNewPos - nCount;
1436 		maSelection.nStartPara = nNewPar;
1437 		maSelection.nStartPos  = nNewPos;
1438 	}
1439 
1440 	if (!Expand)
1441 		CollapseToStart();
1442 
1443 	return bOk;
1444 }
1445 
1446 sal_Bool SvxUnoTextRangeBase::GoRight(sal_Int16 nCount, sal_Bool Expand)  throw()
1447 {
1448 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1449 	if( pForwarder )
1450 	{
1451 		CheckSelection( maSelection, pForwarder );
1452 
1453 
1454 		sal_uInt16 nNewPos = maSelection.nEndPos + nCount;			//! Ueberlauf ???
1455 		sal_uInt16 nNewPar = maSelection.nEndPara;
1456 
1457 		sal_Bool bOk = sal_True;
1458 		sal_uInt16 nParCount = pForwarder->GetParagraphCount();
1459 		sal_uInt16 nThisLen = pForwarder->GetTextLen( nNewPar );
1460 		while ( nNewPos > nThisLen && bOk )
1461 		{
1462 			if ( nNewPar + 1 >= nParCount )
1463 				bOk = sal_False;
1464 			else
1465 			{
1466 				nNewPos -= nThisLen+1;
1467 				++nNewPar;
1468 				nThisLen = pForwarder->GetTextLen( nNewPar );
1469 			}
1470 		}
1471 
1472 		if (bOk)
1473 		{
1474 			maSelection.nEndPara = nNewPar;
1475 			maSelection.nEndPos  = nNewPos;
1476 		}
1477 
1478 		if (!Expand)
1479 			CollapseToEnd();
1480 
1481 		return bOk;
1482 	}
1483 	return sal_False;
1484 }
1485 
1486 void SvxUnoTextRangeBase::GotoStart(sal_Bool Expand) throw()
1487 {
1488 	maSelection.nStartPara = 0;
1489 	maSelection.nStartPos  = 0;
1490 
1491 	if (!Expand)
1492 		CollapseToStart();
1493 }
1494 
1495 void SvxUnoTextRangeBase::GotoEnd(sal_Bool Expand) throw()
1496 {
1497 	CheckSelection( maSelection, mpEditSource->GetTextForwarder() );
1498 
1499 	SvxTextForwarder* pForwarder = mpEditSource ? mpEditSource->GetTextForwarder() : NULL;
1500 	if( pForwarder )
1501 	{
1502 
1503 		sal_uInt16 nPar = pForwarder->GetParagraphCount();
1504 		if (nPar)
1505 			--nPar;
1506 
1507 		maSelection.nEndPara = nPar;
1508 		maSelection.nEndPos  = pForwarder->GetTextLen( nPar );
1509 
1510 		if (!Expand)
1511 			CollapseToEnd();
1512 	}
1513 }
1514 
1515 // lang::XServiceInfo
1516 sal_Bool SAL_CALL SvxUnoTextRangeBase::supportsService( const OUString& ServiceName )
1517 	throw(uno::RuntimeException)
1518 {
1519 	return comphelper::ServiceInfoHelper::supportsService( ServiceName, getSupportedServiceNames() );
1520 }
1521 
1522 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames()
1523 	throw(uno::RuntimeException)
1524 {
1525     return getSupportedServiceNames_Static();
1526 }
1527 
1528 uno::Sequence< OUString > SAL_CALL SvxUnoTextRangeBase::getSupportedServiceNames_Static()
1529 	SAL_THROW(())
1530 {
1531 	uno::Sequence< OUString >	aSeq;
1532 	comphelper::ServiceInfoHelper::addToSequence( aSeq, 3, "com.sun.star.style.CharacterProperties",
1533 												  "com.sun.star.style.CharacterPropertiesComplex",
1534 												  "com.sun.star.style.CharacterPropertiesAsian");
1535 	return aSeq;
1536 }
1537 
1538 // XTextRangeCompare
1539 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionStarts( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException)
1540 {
1541 	SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1542 	SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1543 
1544 	if( (pR1 == 0) || (pR2 == 0) )
1545 		throw lang::IllegalArgumentException();
1546 
1547 	const ESelection& r1 = pR1->maSelection;
1548 	const ESelection& r2 = pR2->maSelection;
1549 
1550 	if( r1.nStartPara == r2.nStartPara )
1551 	{
1552 		if( r1.nStartPos == r2.nStartPos )
1553 			return 0;
1554 		else
1555 			return r1.nStartPos < r2.nStartPos ? 1 : -1;
1556 	}
1557 	else
1558 	{
1559 		return r1.nStartPara < r2.nStartPara ? 1 : -1;
1560 	}
1561 }
1562 
1563 sal_Int16 SAL_CALL SvxUnoTextRangeBase::compareRegionEnds( const uno::Reference< text::XTextRange >& xR1, const uno::Reference< text::XTextRange >& xR2 ) throw (lang::IllegalArgumentException, uno::RuntimeException)
1564 {
1565 	SvxUnoTextRangeBase* pR1 = SvxUnoTextRangeBase::getImplementation( xR1 );
1566 	SvxUnoTextRangeBase* pR2 = SvxUnoTextRangeBase::getImplementation( xR2 );
1567 
1568 	if( (pR1 == 0) || (pR2 == 0) )
1569 		throw lang::IllegalArgumentException();
1570 
1571 	const ESelection& r1 = pR1->maSelection;
1572 	const ESelection& r2 = pR2->maSelection;
1573 
1574 	if( r1.nEndPara == r2.nEndPara )
1575 	{
1576 		if( r1.nEndPos == r2.nEndPos )
1577 			return 0;
1578 		else
1579 			return r1.nEndPos < r2.nEndPos ? 1 : -1;
1580 	}
1581 	else
1582 	{
1583 		return r1.nEndPara < r2.nEndPara ? 1 : -1;
1584 	}
1585 }
1586 
1587 // ====================================================================
1588 // class SvxUnoTextRange
1589 // ====================================================================
1590 
1591 uno::Sequence< uno::Type > SvxUnoTextRange::maTypeSequence;
1592 
1593 uno::Reference< uno::XInterface > SvxUnoTextRange_NewInstance()
1594 {
1595 	SvxUnoText aText;
1596 	uno::Reference< text::XTextRange > xRange( new SvxUnoTextRange( aText ) );
1597 #if (_MSC_VER < 1300)
1598 	return xRange;
1599 #else
1600 	return (uno::Reference< uno::XInterface >)xRange;
1601 #endif
1602 }
1603 
1604 SvxUnoTextRange::SvxUnoTextRange( const SvxUnoTextBase& rParent, sal_Bool bPortion /* = sal_False */ ) throw()
1605 :SvxUnoTextRangeBase( rParent.GetEditSource(), bPortion ? ImplGetSvxTextPortionSvxPropertySet() : rParent.getPropertySet() ),
1606  mbPortion( bPortion )
1607 {
1608 	xParentText =  (text::XText*)&rParent;
1609 }
1610 
1611 SvxUnoTextRange::~SvxUnoTextRange() throw()
1612 {
1613 }
1614 
1615 uno::Any SAL_CALL SvxUnoTextRange::queryAggregation( const uno::Type & rType )
1616 	throw(uno::RuntimeException)
1617 {
1618 	QUERYINT( text::XTextRange );
1619 	else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertyStates >*)0) )
1620 		return uno::makeAny(uno::Reference< beans::XMultiPropertyStates >(this));
1621 	else if( rType == ::getCppuType((const uno::Reference< beans::XPropertySet >*)0) )
1622 		return uno::makeAny(uno::Reference< beans::XPropertySet >(this));
1623 	else QUERYINT( beans::XPropertyState );
1624 	else QUERYINT( text::XTextRangeCompare );
1625 	else if( rType == ::getCppuType((const uno::Reference< beans::XMultiPropertySet >*)0) )
1626 		return uno::makeAny(uno::Reference< beans::XMultiPropertySet >(this));
1627 	else QUERYINT( lang::XServiceInfo );
1628 	else QUERYINT( lang::XTypeProvider );
1629 	else QUERYINT( lang::XUnoTunnel );
1630 	else
1631 		return OWeakAggObject::queryAggregation( rType );
1632 }
1633 
1634 uno::Any SAL_CALL SvxUnoTextRange::queryInterface( const uno::Type & rType )
1635 	throw(uno::RuntimeException)
1636 {
1637 	return OWeakAggObject::queryInterface(rType);
1638 }
1639 
1640 void SAL_CALL SvxUnoTextRange::acquire()
1641 	throw( )
1642 {
1643 	OWeakAggObject::acquire();
1644 }
1645 
1646 void SAL_CALL SvxUnoTextRange::release()
1647 	throw( )
1648 {
1649 	OWeakAggObject::release();
1650 }
1651 
1652 // XTypeProvider
1653 
1654 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextRange::getTypes()
1655 	throw (uno::RuntimeException)
1656 {
1657 	if( maTypeSequence.getLength() == 0 )
1658 	{
1659 		maTypeSequence.realloc( 9 ); // !DANGER! keep this updated
1660 		uno::Type* pTypes = maTypeSequence.getArray();
1661 
1662 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRange >*)0);
1663 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
1664 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0);
1665 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0);
1666 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0);
1667 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
1668 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0);
1669 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
1670 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0);
1671 	}
1672 	return maTypeSequence;
1673 }
1674 
1675 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextRange::getImplementationId()
1676 	throw (uno::RuntimeException)
1677 {
1678 	static uno::Sequence< sal_Int8 > aId;
1679 	if( aId.getLength() == 0 )
1680 	{
1681 		aId.realloc( 16 );
1682 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1683 	}
1684 	return aId;
1685 }
1686 
1687 // XTextRange
1688 uno::Reference< text::XText > SAL_CALL SvxUnoTextRange::getText()
1689 	throw(uno::RuntimeException)
1690 {
1691 	return xParentText;
1692 }
1693 
1694 // lang::XServiceInfo
1695 OUString SAL_CALL SvxUnoTextRange::getImplementationName()
1696 	throw(uno::RuntimeException)
1697 {
1698 	return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextRange"));
1699 }
1700 
1701 // ====================================================================
1702 // class SvxUnoText
1703 // ====================================================================
1704 
1705 // UNO3_GETIMPLEMENTATION2_IMPL( SvxUnoText, SvxUnoTextRangeBase );
1706 
1707 uno::Sequence< uno::Type > SvxUnoTextBase::maTypeSequence;
1708 
1709 SvxUnoTextBase::SvxUnoTextBase() throw()
1710 : SvxUnoTextRangeBase( NULL )
1711 {
1712 
1713 }
1714 
1715 SvxUnoTextBase::SvxUnoTextBase( const SvxItemPropertySet* _pSet  ) throw()
1716 : SvxUnoTextRangeBase( _pSet )
1717 {
1718 }
1719 
1720 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet  ) throw()
1721 : SvxUnoTextRangeBase( pSource, _pSet )
1722 {
1723 	ESelection aSelection;
1724 	::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1725 	SetSelection( aSelection );
1726 }
1727 
1728 SvxUnoTextBase::SvxUnoTextBase( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
1729 : SvxUnoTextRangeBase( pSource, _pSet )
1730 {
1731 	xParentText = xParent;
1732 	ESelection aSelection;
1733 	::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1734 	SetSelection( aSelection );
1735 }
1736 
1737 SvxUnoTextBase::SvxUnoTextBase( const SvxUnoTextBase& rText ) throw()
1738 :	SvxUnoTextRangeBase( rText )
1739 , text::XTextAppend()
1740 ,   text::XTextCopy()
1741 ,	container::XEnumerationAccess()
1742 ,	text::XTextRangeMover()
1743 ,	lang::XTypeProvider()
1744 {
1745 	xParentText = rText.xParentText;
1746 }
1747 
1748 SvxUnoTextBase::~SvxUnoTextBase() throw()
1749 {
1750 }
1751 
1752 // Internal
1753 ESelection SvxUnoTextBase::InsertField( const SvxFieldItem& rField ) throw()
1754 {
1755 	SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1756 	if( pForwarder )
1757 	{
1758 		pForwarder->QuickInsertField( rField, GetSelection() );
1759 		GetEditSource()->UpdateData();
1760 
1761 		//	Selektion anpassen
1762 		//!	Wenn die EditEngine bei QuickInsertText die Selektion zurueckgeben wuerde,
1763 		//!	waer's einfacher...
1764 
1765 		CollapseToStart();
1766 		GoRight( 1, sal_True );		// Feld ist immer 1 Zeichen
1767 	}
1768 
1769 	return GetSelection();	// Selektion mit dem Feld
1770 }
1771 
1772 // XInterface
1773 uno::Any SAL_CALL SvxUnoTextBase::queryAggregation( const uno::Type & rType )
1774 	throw(uno::RuntimeException)
1775 {
1776 	QUERYINT( text::XText );
1777 	QUERYINT( text::XSimpleText );
1778 	if( rType == ::getCppuType((const uno::Reference< text::XTextRange >*)0) )
1779         return uno::makeAny(uno::Reference< text::XTextRange >((text::XText*)(this)));
1780 	QUERYINT(container::XEnumerationAccess );
1781 	QUERYINT( container::XElementAccess );
1782 	QUERYINT( beans::XMultiPropertyStates );
1783 	QUERYINT( beans::XPropertySet );
1784 	QUERYINT( beans::XMultiPropertySet );
1785 	QUERYINT( beans::XPropertyState );
1786 	QUERYINT( text::XTextRangeCompare );
1787 	QUERYINT( lang::XServiceInfo );
1788 	QUERYINT( text::XTextRangeMover );
1789     QUERYINT( text::XTextCopy );
1790     QUERYINT( text::XTextAppend );
1791     QUERYINT( text::XParagraphAppend );
1792     QUERYINT( text::XTextPortionAppend );
1793 	QUERYINT( lang::XTypeProvider );
1794 	QUERYINT( lang::XUnoTunnel );
1795 
1796     return uno::Any();
1797 }
1798 
1799 // XTypeProvider
1800 
1801 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getStaticTypes() throw()
1802 {
1803 	if( maTypeSequence.getLength() == 0 )
1804 	{
1805         maTypeSequence.realloc( 15 ); // !DANGER! keep this updated
1806 		uno::Type* pTypes = maTypeSequence.getArray();
1807 
1808 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XText >*)0);
1809 		*pTypes++ = ::getCppuType(( const uno::Reference< container::XEnumerationAccess >*)0);
1810 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertySet >*)0);
1811 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertySet >*)0);
1812 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XMultiPropertyStates >*)0);
1813 		*pTypes++ = ::getCppuType(( const uno::Reference< beans::XPropertyState >*)0);
1814 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeMover >*)0);
1815         *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextAppend >*)0);
1816         *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextCopy >*)0);
1817         *pTypes++ = ::getCppuType(( const uno::Reference< text::XParagraphAppend >*)0);
1818         *pTypes++ = ::getCppuType(( const uno::Reference< text::XTextPortionAppend >*)0);
1819 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XServiceInfo >*)0);
1820 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XTypeProvider >*)0);
1821 		*pTypes++ = ::getCppuType(( const uno::Reference< lang::XUnoTunnel >*)0);
1822 		*pTypes++ = ::getCppuType(( const uno::Reference< text::XTextRangeCompare >*)0);
1823 	}
1824 	return maTypeSequence;
1825 }
1826 
1827 uno::Sequence< uno::Type > SAL_CALL SvxUnoTextBase::getTypes()
1828 	throw (uno::RuntimeException)
1829 {
1830 	return getStaticTypes();
1831 }
1832 
1833 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoTextBase::getImplementationId()
1834 	throw (uno::RuntimeException)
1835 {
1836 	static uno::Sequence< sal_Int8 > aId;
1837 	if( aId.getLength() == 0 )
1838 	{
1839 		aId.realloc( 16 );
1840 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
1841 	}
1842 	return aId;
1843 }
1844 
1845 uno::Reference< text::XTextCursor > SvxUnoTextBase::createTextCursorBySelection( const ESelection& rSel )
1846 {
1847 	SvxUnoTextCursor* pCursor = new SvxUnoTextCursor( *this );
1848 	uno::Reference< text::XTextCursor >  xCursor( pCursor );
1849 	pCursor->SetSelection( rSel );
1850 	return xCursor;
1851 }
1852 
1853 // XSimpleText
1854 
1855 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursor()
1856 	throw(uno::RuntimeException)
1857 {
1858 	OGuard aGuard( Application::GetSolarMutex() );
1859 	return new SvxUnoTextCursor( *this );
1860 }
1861 
1862 uno::Reference< text::XTextCursor > SAL_CALL SvxUnoTextBase::createTextCursorByRange( const uno::Reference< text::XTextRange >& aTextPosition )
1863 	throw(uno::RuntimeException)
1864 {
1865 	OGuard aGuard( Application::GetSolarMutex() );
1866 
1867 	uno::Reference< text::XTextCursor >  xCursor;
1868 
1869 	if( aTextPosition.is() )
1870 	{
1871 		SvxUnoTextRangeBase* pRange = SvxUnoTextRangeBase::getImplementation( aTextPosition );
1872 		if(pRange)
1873 			xCursor = createTextCursorBySelection( pRange->GetSelection() );
1874 	}
1875 
1876 	return xCursor;
1877 }
1878 
1879 void SAL_CALL SvxUnoTextBase::insertString( const uno::Reference< text::XTextRange >& xRange, const OUString& aString, sal_Bool bAbsorb )
1880 	throw(uno::RuntimeException)
1881 {
1882 	OGuard aGuard( Application::GetSolarMutex() );
1883 
1884 	if( !xRange.is() )
1885 		return;
1886 
1887 	ESelection aSelection;
1888 	::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
1889 	SetSelection( aSelection );
1890 
1891 	SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1892 	if(pRange)
1893 	{
1894 		//	setString am SvxUnoTextRangeBase statt selber QuickInsertText und UpdateData,
1895 		//	damit die Selektion am SvxUnoTextRangeBase angepasst wird.
1896 		//!	Eigentlich muessten alle Cursor-Objekte dieses Textes angepasst werden!
1897 
1898 		if (!bAbsorb)					// nicht ersetzen -> hinten anhaengen
1899 			pRange->CollapseToEnd();
1900 
1901 		pRange->setString( aString );
1902 
1903 		pRange->CollapseToEnd();
1904 	}
1905 }
1906 
1907 void SAL_CALL SvxUnoTextBase::insertControlCharacter( const uno::Reference< text::XTextRange >& xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb )
1908 	throw(lang::IllegalArgumentException, uno::RuntimeException)
1909 {
1910 	OGuard aGuard( Application::GetSolarMutex() );
1911 
1912 	SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
1913 
1914 	if( pForwarder )
1915 	{
1916 		ESelection aSelection;
1917 		::GetSelection( aSelection, pForwarder );
1918 		SetSelection( aSelection );
1919 
1920 		switch( nControlCharacter )
1921 		{
1922 		case text::ControlCharacter::PARAGRAPH_BREAK:
1923 		{
1924 			const String aText( (sal_Unicode)13 );	// '\r' geht auf'm Mac nicht
1925 			insertString( xRange, aText, bAbsorb );
1926 
1927 			return;
1928 		}
1929 		case text::ControlCharacter::LINE_BREAK:
1930 		{
1931 			SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1932 			if(pRange)
1933 			{
1934 				ESelection aRange = pRange->GetSelection();
1935 
1936 				if( bAbsorb )
1937 				{
1938 					const String aEmpty;
1939 					pForwarder->QuickInsertText( aEmpty, aRange );
1940 
1941 					aRange.nEndPos = aRange.nStartPos;
1942 					aRange.nEndPara = aRange.nStartPara;
1943 				}
1944 				else
1945 				{
1946 					aRange.nStartPos = aRange.nEndPos;
1947 					aRange.nStartPara = aRange.nStartPara;
1948 				}
1949 
1950 				pForwarder->QuickInsertLineBreak( aRange );
1951 				GetEditSource()->UpdateData();
1952 
1953 				aRange.nEndPos += 1;
1954 				if( !bAbsorb )
1955 					aRange.nStartPos += 1;
1956 
1957 				pRange->SetSelection( aRange );
1958 			}
1959 			return;
1960 		}
1961 		case text::ControlCharacter::APPEND_PARAGRAPH:
1962 		{
1963 			SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
1964 			if(pRange)
1965 			{
1966 				ESelection aRange = pRange->GetSelection();
1967 //				ESelection aOldSelection = aRange;
1968 
1969 				aRange.nStartPos  = pForwarder->GetTextLen( aRange.nStartPara );
1970 
1971 				aRange.nEndPara = aRange.nStartPara;
1972 				aRange.nEndPos  = aRange.nStartPos;
1973 
1974 				pRange->SetSelection( aRange );
1975 				const String aText( (sal_Unicode)13 );	// '\r' geht auf'm Mac nicht
1976 				pRange->setString( aText );
1977 
1978 				aRange.nStartPos = 0;
1979 				aRange.nStartPara += 1;
1980 				aRange.nEndPos = 0;
1981 				aRange.nEndPara += 1;
1982 
1983 				pRange->SetSelection( aRange );
1984 
1985 				return;
1986 			}
1987 		}
1988 		}
1989 	}
1990 
1991 	throw lang::IllegalArgumentException();
1992 }
1993 
1994 // XText
1995 void SAL_CALL SvxUnoTextBase::insertTextContent( const uno::Reference< text::XTextRange >& xRange, const uno::Reference< text::XTextContent >& xContent, sal_Bool bAbsorb )
1996 	throw(lang::IllegalArgumentException, uno::RuntimeException)
1997 {
1998 	OGuard aGuard( Application::GetSolarMutex() );
1999 
2000 	SvxTextForwarder* pForwarder = GetEditSource() ? GetEditSource()->GetTextForwarder() : NULL;
2001 	if( pForwarder )
2002 	{
2003 
2004 		SvxUnoTextRangeBase* pRange = SvxUnoTextRange::getImplementation( xRange );
2005 		SvxUnoTextField* pField = SvxUnoTextField::getImplementation( xContent );
2006 
2007 		if( pRange == NULL || pField == NULL )
2008 			throw lang::IllegalArgumentException();
2009 
2010 		ESelection aSelection = pRange->GetSelection();
2011 		if( !bAbsorb )
2012 		{
2013 			aSelection.nStartPara = aSelection.nEndPara;
2014 			aSelection.nStartPos  = aSelection.nEndPos;
2015 		}
2016 
2017 		SvxFieldData* pFieldData = pField->CreateFieldData();
2018 		if( pFieldData == NULL )
2019 			throw lang::IllegalArgumentException();
2020 
2021         SvxFieldItem aField( *pFieldData, EE_FEATURE_FIELD );
2022 		pForwarder->QuickInsertField( aField, aSelection );
2023 		GetEditSource()->UpdateData();
2024 
2025 		pField->SetAnchor( uno::Reference< text::XTextRange >::query( (cppu::OWeakObject*)this ) );
2026 
2027         aSelection.nEndPos += 1;
2028         aSelection.nStartPos = aSelection.nEndPos;
2029         //maSelection = aSelection; //???
2030         pRange->SetSelection( aSelection );
2031 
2032 		delete pFieldData;
2033 	}
2034 }
2035 
2036 void SAL_CALL SvxUnoTextBase::removeTextContent( const uno::Reference< text::XTextContent >& ) throw(container::NoSuchElementException, uno::RuntimeException)
2037 {
2038 }
2039 
2040 // XTextRange
2041 
2042 uno::Reference< text::XText > SAL_CALL SvxUnoTextBase::getText()
2043 	throw(uno::RuntimeException)
2044 {
2045 	OGuard aGuard( Application::GetSolarMutex() );
2046 
2047 	if (GetEditSource())
2048 	{
2049 		ESelection aSelection;
2050 		::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
2051 		((SvxUnoTextBase*)this)->SetSelection( aSelection );
2052 	}
2053 
2054 	return (text::XText*)this;
2055 }
2056 
2057 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getStart()
2058 	throw(uno::RuntimeException)
2059 {
2060 	return SvxUnoTextRangeBase::getStart();
2061 }
2062 
2063 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::getEnd()
2064 	throw(uno::RuntimeException)
2065 {
2066 	return SvxUnoTextRangeBase::getEnd();
2067 }
2068 
2069 OUString SAL_CALL SvxUnoTextBase::getString() throw( uno::RuntimeException )
2070 {
2071 	return SvxUnoTextRangeBase::getString();
2072 }
2073 
2074 void SAL_CALL SvxUnoTextBase::setString( const OUString& aString ) throw(uno::RuntimeException)
2075 {
2076 	SvxUnoTextRangeBase::setString(aString);
2077 }
2078 
2079 
2080 // XEnumerationAccess
2081 uno::Reference< container::XEnumeration > SAL_CALL SvxUnoTextBase::createEnumeration()
2082 	throw(uno::RuntimeException)
2083 {
2084 	OGuard aGuard( Application::GetSolarMutex() );
2085 
2086 	ESelection aSelection;
2087 	::GetSelection( aSelection, GetEditSource()->GetTextForwarder() );
2088 	SetSelection( aSelection );
2089 
2090 	uno::Reference< container::XEnumeration > xEnum( (container::XEnumeration*) new SvxUnoTextContentEnumeration( *this ) );
2091 	return xEnum;
2092 }
2093 
2094 // XElementAccess ( container::XEnumerationAccess )
2095 uno::Type SAL_CALL SvxUnoTextBase::getElementType(  ) throw(uno::RuntimeException)
2096 {
2097 	return ::getCppuType((const uno::Reference< text::XTextRange >*)0 );
2098 }
2099 
2100 sal_Bool SAL_CALL SvxUnoTextBase::hasElements(  ) throw(uno::RuntimeException)
2101 {
2102 	OGuard aGuard( Application::GetSolarMutex() );
2103 
2104 	if(GetEditSource())
2105 	{
2106 		SvxTextForwarder* pForwarder = GetEditSource()->GetTextForwarder();
2107 		if(pForwarder)
2108 			return pForwarder->GetParagraphCount() != 0;
2109 	}
2110 
2111 	return sal_False;
2112 }
2113 
2114 // text::XTextRangeMover
2115 void SAL_CALL SvxUnoTextBase::moveTextRange( const uno::Reference< text::XTextRange >&, sal_Int16 )
2116 	throw(uno::RuntimeException)
2117 {
2118 }
2119 
2120 void SvxPropertyValuesToItemSet(
2121 		SfxItemSet &rItemSet,
2122 		const uno::Sequence< beans::PropertyValue > rPropertyVaules,
2123         const SfxItemPropertySet *pPropSet,
2124         SvxTextForwarder *pForwarder /*needed for WID_NUMLEVEL*/,
2125         sal_uInt16 nPara /*needed for WID_NUMLEVEL*/)
2126 	throw(lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2127 {
2128     sal_Int32 nProps = rPropertyVaules.getLength();
2129     const beans::PropertyValue *pProps = rPropertyVaules.getConstArray();
2130     for (sal_Int32 i = 0;  i < nProps;  ++i)
2131     {
2132         const SfxItemPropertySimpleEntry *pEntry = pPropSet->getPropertyMap()->getByName( pProps[i].Name );
2133         if (pEntry)
2134         {
2135             // Note: there is no need to take special care of the properties
2136             //      TextField (EE_FEATURE_FIELD) and
2137             //      TextPortionType (WID_PORTIONTYPE)
2138             //  since they are read-only and thus are already taken care of below.
2139 
2140             if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2141                 // should be PropertyVetoException which is not yet defined for the new import API's functions
2142                 throw uno::RuntimeException( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2143                 //throw PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2144 
2145             if (pEntry->nWID == WID_FONTDESC)
2146             {
2147                 awt::FontDescriptor aDesc;
2148                 if (pProps[i].Value >>= aDesc)
2149                     SvxUnoFontDescriptor::FillItemSet( aDesc, rItemSet );
2150             }
2151             else if (pEntry->nWID == WID_NUMLEVEL)
2152             {
2153                 if (pForwarder)
2154                 {
2155                     sal_Int16 nLevel = -1;
2156                     pProps[i].Value >>= nLevel;
2157 
2158 					// #101004# Call interface method instead of unsafe cast
2159 					if (!pForwarder->SetDepth( nPara, nLevel ))
2160 						throw lang::IllegalArgumentException();
2161                 }
2162             }
2163             else if (pEntry->nWID == WID_NUMBERINGSTARTVALUE )
2164             {
2165                 if( pForwarder )
2166                 {
2167                     sal_Int16 nStartValue = -1;
2168                     if( !(pProps[i].Value >>= nStartValue) )
2169 						throw lang::IllegalArgumentException();
2170 
2171                     pForwarder->SetNumberingStartValue( nPara, nStartValue );
2172                 }
2173             }
2174             else if (pEntry->nWID == WID_PARAISNUMBERINGRESTART )
2175             {
2176                 if( pForwarder )
2177                 {
2178                     sal_Bool bParaIsNumberingRestart = sal_False;
2179                     if( !(pProps[i].Value >>= bParaIsNumberingRestart) )
2180 						throw lang::IllegalArgumentException();
2181 
2182                     pForwarder->SetParaIsNumberingRestart( nPara, bParaIsNumberingRestart );
2183                 }
2184             }
2185             else
2186                 pPropSet->setPropertyValue( pProps[i].Name, pProps[i].Value, rItemSet );
2187         }
2188         else
2189             throw beans::UnknownPropertyException(OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Unknown property: " ) ) + pProps[i].Name, static_cast < cppu::OWeakObject * > ( 0 ) );
2190     }
2191 }
2192 
2193 // com::sun::star::text::XParagraphAppend (new import API)
2194 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendParagraph(
2195         const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2196     throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2197 {
2198     OGuard aGuard( Application::GetSolarMutex() );
2199 	uno::Reference< text::XTextRange > xRet;
2200     SvxEditSource *pEditSource = GetEditSource();
2201     SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2202     if (pTextForwarder)
2203     {
2204         sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount();
2205         DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2206 		pTextForwarder->AppendParagraph();
2207 
2208         // set properties for new appended (now last) paragraph
2209         ESelection aSel( nParaCount, 0, nParaCount, 0 );
2210         SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2211         SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2212                             ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(),
2213                             pTextForwarder,
2214                             nParaCount );
2215         pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2216         pEditSource->UpdateData();
2217 		SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2218 		xRet = pRange;
2219 		pRange->SetSelection( aSel );
2220     }
2221 	return xRet;
2222 }
2223 
2224 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::finishParagraph(
2225         const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2226     throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2227 {
2228     OGuard aGuard( Application::GetSolarMutex() );
2229 
2230 	uno::Reference< text::XTextRange > xRet;
2231     SvxEditSource *pEditSource = GetEditSource();
2232     SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2233     if (pTextForwarder)
2234     {
2235         sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount();
2236         DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2237         pTextForwarder->AppendParagraph();
2238 
2239         // set properties for the previously last paragraph
2240         sal_uInt16 nPara = nParaCount - 1;
2241         ESelection aSel( nPara, 0, nPara, 0 );
2242         SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2243         SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2244                 ImplGetSvxUnoOutlinerTextCursorSfxPropertySet(), pTextForwarder, nPara );
2245 		pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2246         pEditSource->UpdateData();
2247 		SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2248 		xRet = pRange;
2249 		pRange->SetSelection( aSel );
2250 	}
2251 	return xRet;
2252 }
2253 
2254 // com::sun::star::text::XTextPortionAppend (new import API)
2255 uno::Reference< text::XTextRange > SAL_CALL SvxUnoTextBase::appendTextPortion(
2256         const ::rtl::OUString& rText,
2257         const uno::Sequence< beans::PropertyValue >& rCharAndParaProps )
2258     throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
2259 {
2260     OGuard aGuard( Application::GetSolarMutex() );
2261 
2262     SvxEditSource *pEditSource = GetEditSource();
2263     SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2264 	uno::Reference< text::XTextRange > xRet;
2265     if (pTextForwarder)
2266     {
2267         sal_uInt16 nParaCount = pTextForwarder->GetParagraphCount();
2268         DBG_ASSERT( nParaCount > 0, "paragraph count is 0 or negative" );
2269 		sal_uInt16 nPara = nParaCount - 1;
2270         SfxItemSet aSet( pTextForwarder->GetParaAttribs( nPara ) );
2271 		xub_StrLen nStart = pTextForwarder->AppendTextPortion( nPara, rText, aSet );
2272         pEditSource->UpdateData();
2273 		xub_StrLen nEnd   = pTextForwarder->GetTextLen( nPara );
2274 
2275         // set properties for the new text portion
2276         ESelection aSel( nPara, nStart, nPara, nEnd );
2277         pTextForwarder->RemoveAttribs( aSel, sal_False, 0 );
2278         pEditSource->UpdateData();
2279 
2280         SfxItemSet aItemSet( *pTextForwarder->GetEmptyItemSetPtr() );
2281         SvxPropertyValuesToItemSet( aItemSet, rCharAndParaProps,
2282                 ImplGetSvxTextPortionSfxPropertySet(), pTextForwarder, nPara );
2283 		pTextForwarder->QuickSetAttribs( aItemSet, aSel );
2284 		SvxUnoTextRange* pRange = new SvxUnoTextRange( *this );
2285 		xRet = pRange;
2286 		pRange->SetSelection( aSel );
2287         const beans::PropertyValue* pProps = rCharAndParaProps.getConstArray();
2288         for( sal_Int32 nProp = 0; nProp < rCharAndParaProps.getLength(); ++nProp )
2289             pRange->setPropertyValue( pProps[nProp].Name, pProps[nProp].Value );
2290 	}
2291 	return xRet;
2292 }
2293 /*-- 25.03.2008 08:16:09---------------------------------------------------
2294 
2295   -----------------------------------------------------------------------*/
2296 void SvxUnoTextBase::copyText(
2297     const uno::Reference< text::XTextCopy >& xSource ) throw ( uno::RuntimeException )
2298 {
2299     OGuard aGuard( Application::GetSolarMutex() );
2300     uno::Reference< lang::XUnoTunnel > xUT( xSource, uno::UNO_QUERY );
2301     SvxEditSource *pEditSource = GetEditSource();
2302     SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : 0;
2303     if( !pTextForwarder )
2304         return;
2305     if( xUT.is() )
2306     {
2307         SvxUnoTextBase* pSource = reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(
2308                                                                     xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2309         SvxEditSource *pSourceEditSource = pSource->GetEditSource();
2310         SvxTextForwarder *pSourceTextForwarder = pSourceEditSource ? pSourceEditSource->GetTextForwarder() : 0;
2311         if( pSourceTextForwarder )
2312         {
2313             pTextForwarder->CopyText( *pSourceTextForwarder );
2314             pEditSource->UpdateData();
2315         }
2316     }
2317     else
2318     {
2319         uno::Reference< text::XText > xSourceText( xSource, uno::UNO_QUERY );
2320         if( xSourceText.is() )
2321         {
2322             setString( xSourceText->getString() );
2323         }
2324     }
2325 }
2326 
2327 // lang::XServiceInfo
2328 OUString SAL_CALL SvxUnoTextBase::getImplementationName()
2329 	throw(uno::RuntimeException)
2330 {
2331 	return OUString(RTL_CONSTASCII_USTRINGPARAM("SvxUnoTextBase"));
2332 }
2333 
2334 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames(  )
2335 	throw(uno::RuntimeException)
2336 {
2337     return getSupportedServiceNames_Static();
2338 }
2339 
2340 uno::Sequence< OUString > SAL_CALL SvxUnoTextBase::getSupportedServiceNames_Static(  )
2341 	SAL_THROW(())
2342 {
2343 	uno::Sequence< OUString > aSeq( SvxUnoTextRangeBase::getSupportedServiceNames_Static() );
2344 	comphelper::ServiceInfoHelper::addToSequence( aSeq, 1, "com.sun.star.text.Text" );
2345 	return aSeq;
2346 }
2347 
2348 const uno::Sequence< sal_Int8 > & SvxUnoTextBase::getUnoTunnelId() throw()
2349 {
2350 	static uno::Sequence< sal_Int8 > * pSeq = 0;
2351 	if( !pSeq )
2352 	{
2353 		::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
2354 		if( !pSeq )
2355 		{
2356 			static uno::Sequence< sal_Int8 > aSeq( 16 );
2357 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
2358 			pSeq = &aSeq;
2359 		}
2360 	}
2361 	return *pSeq;
2362 }
2363 
2364 SvxUnoTextBase* SvxUnoTextBase::getImplementation( const uno::Reference< uno::XInterface >& xInt )
2365 {
2366 	uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2367 	if( xUT.is() )
2368 		return reinterpret_cast<SvxUnoTextBase*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoTextBase::getUnoTunnelId())));
2369 	else
2370 		return NULL;
2371 }
2372 
2373 sal_Int64 SAL_CALL SvxUnoTextBase::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \
2374 {
2375 	if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2376 														 rId.getConstArray(), 16 ) )
2377 	{
2378 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2379 	}
2380 	else
2381 	{
2382 		return SvxUnoTextRangeBase::getSomething( rId );
2383 	}
2384 }
2385 
2386 // --------------------------------------------------------------------
2387 
2388 SvxUnoText::SvxUnoText( ) throw()
2389 {
2390 }
2391 
2392 SvxUnoText::SvxUnoText( const SvxItemPropertySet* _pSet ) throw()
2393 : SvxUnoTextBase( _pSet )
2394 {
2395 }
2396 
2397 SvxUnoText::SvxUnoText( const SvxEditSource* pSource, const SvxItemPropertySet* _pSet, uno::Reference < text::XText > xParent ) throw()
2398 : SvxUnoTextBase( pSource, _pSet, xParent )
2399 {
2400 }
2401 
2402 SvxUnoText::SvxUnoText( const SvxUnoText& rText ) throw()
2403 : SvxUnoTextBase( rText )
2404 , cppu::OWeakAggObject()
2405 {
2406 }
2407 
2408 SvxUnoText::~SvxUnoText() throw()
2409 {
2410 }
2411 
2412 uno::Sequence< uno::Type > SAL_CALL getStaticTypes() throw()
2413 {
2414 	return SvxUnoTextBase::getStaticTypes();
2415 }
2416 
2417 // uno::XInterface
2418 uno::Any SAL_CALL SvxUnoText::queryAggregation( const uno::Type & rType ) throw( uno::RuntimeException )
2419 {
2420 	uno::Any aAny( SvxUnoTextBase::queryAggregation( rType ) );
2421 	if( !aAny.hasValue() )
2422 		aAny = OWeakAggObject::queryAggregation( rType );
2423 
2424 	return aAny;
2425 }
2426 
2427 uno::Any SAL_CALL SvxUnoText::queryInterface( const uno::Type & rType ) throw( uno::RuntimeException )
2428 {
2429 	return OWeakAggObject::queryInterface( rType );
2430 }
2431 
2432 void SAL_CALL SvxUnoText::acquire() throw( )
2433 {
2434 	OWeakAggObject::acquire();
2435 }
2436 
2437 void SAL_CALL SvxUnoText::release() throw( )
2438 {
2439 	OWeakAggObject::release();
2440 }
2441 
2442 // lang::XTypeProvider
2443 uno::Sequence< uno::Type > SAL_CALL SvxUnoText::getTypes(  ) throw( uno::RuntimeException )
2444 {
2445 	return SvxUnoTextBase::getTypes();
2446 }
2447 
2448 uno::Sequence< sal_Int8 > SAL_CALL SvxUnoText::getImplementationId(  ) throw( uno::RuntimeException )
2449 {
2450 	static uno::Sequence< sal_Int8 > aId;
2451 	if( aId.getLength() == 0 )
2452 	{
2453 		aId.realloc( 16 );
2454 		rtl_createUuid( (sal_uInt8 *)aId.getArray(), 0, sal_True );
2455 	}
2456 	return aId;
2457 }
2458 
2459 SvxUnoText* SvxUnoText::getImplementation( const uno::Reference< uno::XInterface >& xInt )
2460 {
2461 	uno::Reference< lang::XUnoTunnel > xUT( xInt, uno::UNO_QUERY );
2462 	if( xUT.is() )
2463 		return reinterpret_cast<SvxUnoText*>(sal::static_int_cast<sal_uIntPtr>(xUT->getSomething( SvxUnoText::getUnoTunnelId())));
2464 	else
2465 		return NULL;
2466 }
2467 
2468 const uno::Sequence< sal_Int8 > & SvxUnoText::getUnoTunnelId() throw()
2469 {
2470 	static uno::Sequence< sal_Int8 > * pSeq = 0;
2471 	if( !pSeq )
2472 	{
2473 		::osl::Guard< ::osl::Mutex > aGuard( ::osl::Mutex::getGlobalMutex() );
2474 		if( !pSeq )
2475 		{
2476 			static uno::Sequence< sal_Int8 > aSeq( 16 );
2477 			rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
2478 			pSeq = &aSeq;
2479 		}
2480 	}
2481 	return *pSeq;
2482 }
2483 
2484 sal_Int64 SAL_CALL SvxUnoText::getSomething( const uno::Sequence< sal_Int8 >& rId ) throw(uno::RuntimeException) \
2485 {
2486 	if( rId.getLength() == 16 && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
2487 														 rId.getConstArray(), 16 ) )
2488 	{
2489 		return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_uIntPtr>(this));
2490 	}
2491 	else
2492 	{
2493 		return SvxUnoTextBase::getSomething( rId );
2494 	}
2495 }
2496 
2497 
2498 // --------------------------------------------------------------------
2499 
2500 SvxDummyTextSource::~SvxDummyTextSource()
2501 {
2502 };
2503 
2504 SvxEditSource* SvxDummyTextSource::Clone() const
2505 {
2506 	return new SvxDummyTextSource();
2507 }
2508 
2509 SvxTextForwarder* SvxDummyTextSource::GetTextForwarder()
2510 {
2511 	return this;
2512 }
2513 
2514 void SvxDummyTextSource::UpdateData()
2515 {
2516 }
2517 
2518 sal_uInt16 SvxDummyTextSource::GetParagraphCount() const
2519 {
2520 	return 0;
2521 }
2522 
2523 sal_uInt16 SvxDummyTextSource::GetTextLen( sal_uInt16 ) const
2524 {
2525 	return 0;
2526 }
2527 
2528 String SvxDummyTextSource::GetText( const ESelection& ) const
2529 {
2530 	return String();
2531 }
2532 
2533 SfxItemSet SvxDummyTextSource::GetAttribs( const ESelection&, sal_Bool ) const
2534 {
2535     // AW: Very dangerous: The former implementation used a SfxItemPool created on the
2536     // fly which of course was deleted again ASAP. Thus, the returned SfxItemSet was using
2537     // a deleted Pool by design.
2538 	return SfxItemSet(EditEngine::GetGlobalItemPool());
2539 }
2540 
2541 SfxItemSet SvxDummyTextSource::GetParaAttribs( sal_uInt16 ) const
2542 {
2543 	return GetAttribs(ESelection());
2544 }
2545 
2546 void SvxDummyTextSource::SetParaAttribs( sal_uInt16, const SfxItemSet& )
2547 {
2548 }
2549 
2550 void SvxDummyTextSource::RemoveAttribs( const ESelection& , sal_Bool , sal_uInt16 )
2551 {
2552 }
2553 
2554 void SvxDummyTextSource::GetPortions( sal_uInt16, SvUShorts& ) const
2555 {
2556 }
2557 
2558 sal_uInt16 SvxDummyTextSource::GetItemState( const ESelection&, sal_uInt16 ) const
2559 {
2560 	return 0;
2561 }
2562 
2563 sal_uInt16 SvxDummyTextSource::GetItemState( sal_uInt16, sal_uInt16 ) const
2564 {
2565 	return 0;
2566 }
2567 
2568 SfxItemPool* SvxDummyTextSource::GetPool() const
2569 {
2570 	return NULL;
2571 }
2572 
2573 void SvxDummyTextSource::QuickInsertText( const String&, const ESelection& )
2574 {
2575 }
2576 
2577 void SvxDummyTextSource::QuickInsertField( const SvxFieldItem&, const ESelection& )
2578 {
2579 }
2580 
2581 void SvxDummyTextSource::QuickSetAttribs( const SfxItemSet&, const ESelection& )
2582 {
2583 }
2584 
2585 void SvxDummyTextSource::QuickInsertLineBreak( const ESelection& )
2586 {
2587 };
2588 
2589 XubString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_uInt16, sal_uInt16, Color*&, Color*& )
2590 {
2591 	return XubString();
2592 }
2593 
2594 void SvxDummyTextSource::FieldClicked( const SvxFieldItem&, sal_uInt16, xub_StrLen )
2595 {
2596 }
2597 
2598 sal_Bool SvxDummyTextSource::IsValid() const
2599 {
2600 	return sal_False;
2601 }
2602 
2603 void SvxDummyTextSource::SetNotifyHdl( const Link& )
2604 {
2605 }
2606 
2607 LanguageType SvxDummyTextSource::GetLanguage( sal_uInt16, sal_uInt16 ) const
2608 {
2609     return LANGUAGE_DONTKNOW;
2610 }
2611 
2612 sal_uInt16 SvxDummyTextSource::GetFieldCount( sal_uInt16 ) const
2613 {
2614     return 0;
2615 }
2616 
2617 EFieldInfo SvxDummyTextSource::GetFieldInfo( sal_uInt16, sal_uInt16 ) const
2618 {
2619     return EFieldInfo();
2620 }
2621 
2622 EBulletInfo SvxDummyTextSource::GetBulletInfo( sal_uInt16 ) const
2623 {
2624     return EBulletInfo();
2625 }
2626 
2627 Rectangle SvxDummyTextSource::GetCharBounds( sal_uInt16, sal_uInt16 ) const
2628 {
2629     return Rectangle();
2630 }
2631 
2632 Rectangle SvxDummyTextSource::GetParaBounds( sal_uInt16 ) const
2633 {
2634     return Rectangle();
2635 }
2636 
2637 MapMode SvxDummyTextSource::GetMapMode() const
2638 {
2639     return MapMode();
2640 }
2641 
2642 OutputDevice* SvxDummyTextSource::GetRefDevice() const
2643 {
2644     return NULL;
2645 }
2646 
2647 sal_Bool SvxDummyTextSource::GetIndexAtPoint( const Point&, sal_uInt16&, sal_uInt16& ) const
2648 {
2649     return sal_False;
2650 }
2651 
2652 sal_Bool SvxDummyTextSource::GetWordIndices( sal_uInt16, sal_uInt16, sal_uInt16&, sal_uInt16& ) const
2653 {
2654     return sal_False;
2655 }
2656 
2657 sal_Bool SvxDummyTextSource::GetAttributeRun( sal_uInt16&, sal_uInt16&, sal_uInt16, sal_uInt16 ) const
2658 {
2659     return sal_False;
2660 }
2661 
2662 sal_uInt16 SvxDummyTextSource::GetLineCount( sal_uInt16 ) const
2663 {
2664     return 0;
2665 }
2666 
2667 sal_uInt16 SvxDummyTextSource::GetLineLen( sal_uInt16, sal_uInt16 ) const
2668 {
2669     return 0;
2670 }
2671 
2672 void SvxDummyTextSource::GetLineBoundaries( /*out*/sal_uInt16 &rStart, /*out*/sal_uInt16 &rEnd, sal_uInt16 /*nParagraph*/, sal_uInt16 /*nLine*/ ) const
2673 {
2674     rStart = rEnd = 0;
2675 }
2676 
2677 sal_uInt16 SvxDummyTextSource::GetLineNumberAtIndex( sal_uInt16 /*nPara*/, sal_uInt16 /*nIndex*/ ) const
2678 {
2679     return 0;
2680 }
2681 
2682 sal_Bool SvxDummyTextSource::QuickFormatDoc( sal_Bool )
2683 {
2684     return sal_False;
2685 }
2686 
2687 sal_Int16 SvxDummyTextSource::GetDepth( sal_uInt16 ) const
2688 {
2689     return -1;
2690 }
2691 
2692 sal_Bool SvxDummyTextSource::SetDepth( sal_uInt16, sal_Int16 nNewDepth )
2693 {
2694     return nNewDepth == 0 ? sal_True : sal_False;
2695 }
2696 
2697 sal_Bool SvxDummyTextSource::Delete( const ESelection& )
2698 {
2699     return sal_False;
2700 }
2701 
2702 sal_Bool SvxDummyTextSource::InsertText( const String&, const ESelection& )
2703 {
2704     return sal_False;
2705 }
2706 
2707 const SfxItemSet * SvxDummyTextSource::GetEmptyItemSetPtr()
2708 {
2709     return 0;
2710 }
2711 
2712 void SvxDummyTextSource::AppendParagraph()
2713 {
2714 }
2715 
2716 xub_StrLen SvxDummyTextSource::AppendTextPortion( sal_uInt16, const String &, const SfxItemSet & )
2717 {
2718     return 0;
2719 }
2720 
2721 void  SvxDummyTextSource::CopyText(const SvxTextForwarder& )
2722 {
2723 }
2724 
2725