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