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