Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/table/TableSortField.hpp>
21 : #include <comphelper/string.hxx>
22 : #include <osl/endian.h>
23 : #include <rtl/ustrbuf.hxx>
24 : #include <unotools/collatorwrapper.hxx>
25 : #include <swtypes.hxx>
26 : #include <hintids.hxx>
27 : #include <cmdid.h>
28 : #include <hints.hxx>
29 : #include <IMark.hxx>
30 : #include <frmfmt.hxx>
31 : #include <doc.hxx>
32 : #include <IDocumentUndoRedo.hxx>
33 : #include <istyleaccess.hxx>
34 : #include <ndtxt.hxx>
35 : #include <ndnotxt.hxx>
36 : #include <unocrsr.hxx>
37 : #include <unocrsrhelper.hxx>
38 : #include <swundo.hxx>
39 : #include <rootfrm.hxx>
40 : #include <flyfrm.hxx>
41 : #include <ftnidx.hxx>
42 : #include <sfx2/linkmgr.hxx>
43 : #include <docary.hxx>
44 : #include <paratr.hxx>
45 : #include <pam.hxx>
46 : #include <tools/cachestr.hxx>
47 : #include <shellio.hxx>
48 : #include <swerror.h>
49 : #include <swtblfmt.hxx>
50 : #include <fmtruby.hxx>
51 : #include <docsh.hxx>
52 : #include <docstyle.hxx>
53 : #include <charfmt.hxx>
54 : #include <txtfld.hxx>
55 : #include <fmtfld.hxx>
56 : #include <fmtpdsc.hxx>
57 : #include <pagedesc.hxx>
58 : #include <poolfmt.hrc>
59 : #include <poolfmt.hxx>
60 : #include <edimp.hxx>
61 : #include <fchrfmt.hxx>
62 : #include <fmtautofmt.hxx>
63 : #include <cntfrm.hxx>
64 : #include <pagefrm.hxx>
65 : #include <doctxm.hxx>
66 : #include <sfx2/docfilt.hxx>
67 : #include <sfx2/docfile.hxx>
68 : #include <sfx2/fcontnr.hxx>
69 : #include <fmtrfmrk.hxx>
70 : #include <txtrfmrk.hxx>
71 : #include <unotextrange.hxx>
72 : #include <unotextcursor.hxx>
73 : #include <unomap.hxx>
74 : #include <unosett.hxx>
75 : #include <unoprnms.hxx>
76 : #include <unotbl.hxx>
77 : #include <unodraw.hxx>
78 : #include <unocoll.hxx>
79 : #include <unostyle.hxx>
80 : #include <unofield.hxx>
81 : #include <unometa.hxx>
82 : #include <fmtanchr.hxx>
83 : #include <editeng/flstitem.hxx>
84 : #include <svtools/ctrltool.hxx>
85 : #include <flypos.hxx>
86 : #include <txtftn.hxx>
87 : #include <fmtftn.hxx>
88 : #include <com/sun/star/text/WrapTextMode.hpp>
89 : #include <com/sun/star/text/TextContentAnchorType.hpp>
90 : #include <com/sun/star/style/PageStyleLayout.hpp>
91 : #include <com/sun/star/text/XTextDocument.hpp>
92 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
93 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
94 : #include <unoidx.hxx>
95 : #include <unoframe.hxx>
96 : #include <fmthdft.hxx>
97 : #include <osl/mutex.hxx>
98 : #include <vcl/svapp.hxx>
99 : #include <fmtflcnt.hxx>
100 : #include <editeng/brshitem.hxx>
101 : #include <editeng/unolingu.hxx>
102 : #include <fmtclds.hxx>
103 : #include <dcontact.hxx>
104 : #include <SwStyleNameMapper.hxx>
105 : #include <crsskip.hxx>
106 : #include <sortopt.hxx>
107 : #include <com/sun/star/beans/PropertyAttribute.hpp>
108 : #include <memory>
109 : #include <unoparaframeenum.hxx>
110 : #include <unoparagraph.hxx>
111 : #include <comphelper/servicehelper.hxx>
112 :
113 :
114 : using namespace ::com::sun::star;
115 : using ::rtl::OUString;
116 : using ::rtl::OUStringBuffer;
117 :
118 : /****************************************************************************
119 : Hilfsklassen
120 : ****************************************************************************/
121 1750 : SwUnoInternalPaM::SwUnoInternalPaM(SwDoc& rDoc) :
122 1750 : SwPaM(rDoc.GetNodes())
123 : {
124 1750 : }
125 :
126 3549 : SwUnoInternalPaM::~SwUnoInternalPaM()
127 : {
128 3500 : while( GetNext() != this)
129 : {
130 0 : delete GetNext();
131 : }
132 1799 : }
133 :
134 10 : SwUnoInternalPaM& SwUnoInternalPaM::operator=(const SwPaM& rPaM)
135 : {
136 10 : const SwPaM* pTmp = &rPaM;
137 10 : *GetPoint() = *rPaM.GetPoint();
138 10 : if(rPaM.HasMark())
139 : {
140 0 : SetMark();
141 0 : *GetMark() = *rPaM.GetMark();
142 : }
143 : else
144 10 : DeleteMark();
145 20 : while(&rPaM != (pTmp = (const SwPaM*)pTmp->GetNext()))
146 : {
147 0 : if(pTmp->HasMark())
148 0 : new SwPaM(*pTmp->GetMark(), *pTmp->GetPoint(), this);
149 : else
150 0 : new SwPaM(*pTmp->GetPoint(), this);
151 : }
152 10 : return *this;
153 : }
154 :
155 6174 : void SwUnoCursorHelper::SelectPam(SwPaM & rPam, const bool bExpand)
156 : {
157 6174 : if (bExpand)
158 : {
159 2366 : if (!rPam.HasMark())
160 : {
161 2335 : rPam.SetMark();
162 : }
163 : }
164 3808 : else if (rPam.HasMark())
165 : {
166 58 : rPam.DeleteMark();
167 : }
168 6174 : }
169 :
170 20 : void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer)
171 : {
172 20 : if (!rPam.HasMark())
173 : {
174 20 : return;
175 : }
176 20 : SvCacheStream aStream( 20480 );
177 : #ifdef OSL_BIGENDIAN
178 : aStream.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
179 : #else
180 20 : aStream.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
181 : #endif
182 20 : WriterRef xWrt;
183 : // TODO/MBA: looks like a BaseURL doesn't make sense here
184 20 : SwReaderWriter::GetWriter( rtl::OUString(FILTER_TEXT_DLG), String(), xWrt );
185 20 : if( xWrt.Is() )
186 : {
187 20 : SwWriter aWriter( aStream, rPam );
188 20 : xWrt->bASCII_NoLastLineEnd = sal_True;
189 20 : xWrt->bExportPargraphNumbering = sal_False;
190 20 : SwAsciiOptions aOpt = xWrt->GetAsciiOptions();
191 20 : aOpt.SetCharSet( RTL_TEXTENCODING_UNICODE );
192 20 : xWrt->SetAsciiOptions( aOpt );
193 20 : xWrt->bUCS2_WithStartChar = sal_False;
194 : // #i68522#
195 20 : const sal_Bool bOldShowProgress = xWrt->bShowProgress;
196 20 : xWrt->bShowProgress = sal_False;
197 :
198 : long lLen;
199 40 : if( !IsError( aWriter.Write( xWrt ) ) &&
200 20 : 0x7ffffff > (( lLen = aStream.GetSize() )
201 : / sizeof( sal_Unicode )) + 1 )
202 : {
203 20 : aStream << (sal_Unicode)'\0';
204 :
205 20 : aStream.Seek( 0 );
206 20 : aStream.ResetError();
207 :
208 20 : long lUniLen = (lLen / sizeof( sal_Unicode ));
209 20 : rtl_uString *pStr = rtl_uString_alloc(lUniLen);
210 20 : aStream.Read(pStr->buffer, lUniLen * sizeof(sal_Unicode));
211 20 : rBuffer = rtl::OUString(pStr, SAL_NO_ACQUIRE);
212 : }
213 20 : xWrt->bShowProgress = bOldShowProgress;
214 20 : }
215 : }
216 :
217 : static void
218 6 : lcl_setCharStyle(SwDoc *const pDoc, const uno::Any & rValue, SfxItemSet & rSet)
219 : throw (lang::IllegalArgumentException)
220 : {
221 6 : SwDocShell *const pDocSh = pDoc->GetDocShell();
222 6 : if(pDocSh)
223 : {
224 6 : OUString uStyle;
225 6 : if (!(rValue >>= uStyle))
226 : {
227 0 : throw lang::IllegalArgumentException();
228 : }
229 6 : String sStyle;
230 : SwStyleNameMapper::FillUIName(uStyle, sStyle,
231 6 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true);
232 : SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
233 6 : pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR));
234 6 : if (!pStyle)
235 : {
236 0 : throw lang::IllegalArgumentException();
237 : }
238 6 : const SwFmtCharFmt aFmt(pStyle->GetCharFmt());
239 6 : rSet.Put(aFmt);
240 : }
241 6 : };
242 :
243 : static void
244 31 : lcl_setAutoStyle(IStyleAccess & rStyleAccess, const uno::Any & rValue,
245 : SfxItemSet & rSet, const bool bPara)
246 : throw (lang::IllegalArgumentException)
247 : {
248 31 : OUString uStyle;
249 31 : if (!(rValue >>= uStyle))
250 : {
251 0 : throw lang::IllegalArgumentException();
252 : }
253 : StylePool::SfxItemSet_Pointer_t pStyle = bPara ?
254 23 : rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_PARA ):
255 54 : rStyleAccess.getByName(uStyle, IStyleAccess::AUTO_STYLE_CHAR );
256 31 : if(pStyle.get())
257 : {
258 : SwFmtAutoFmt aFmt( (bPara)
259 23 : ? sal::static_int_cast< sal_uInt16 >(RES_AUTO_STYLE)
260 54 : : sal::static_int_cast< sal_uInt16 >(RES_TXTATR_AUTOFMT) );
261 31 : aFmt.SetStyleHandle( pStyle );
262 31 : rSet.Put(aFmt);
263 : }
264 : else
265 : {
266 0 : throw lang::IllegalArgumentException();
267 62 : }
268 31 : };
269 :
270 : void
271 932 : SwUnoCursorHelper::SetTxtFmtColl(const uno::Any & rAny, SwPaM & rPaM)
272 : throw (lang::IllegalArgumentException)
273 : {
274 932 : SwDoc *const pDoc = rPaM.GetDoc();
275 932 : SwDocShell *const pDocSh = pDoc->GetDocShell();
276 932 : if(!pDocSh)
277 932 : return;
278 932 : OUString uStyle;
279 932 : rAny >>= uStyle;
280 932 : String sStyle;
281 : SwStyleNameMapper::FillUIName(uStyle, sStyle,
282 932 : nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, true );
283 : SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
284 932 : pDocSh->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_PARA));
285 932 : if (!pStyle)
286 : {
287 0 : throw lang::IllegalArgumentException();
288 : }
289 :
290 932 : SwTxtFmtColl *const pLocal = pStyle->GetCollection();
291 932 : UnoActionContext aAction(pDoc);
292 932 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
293 932 : SwPaM *pTmpCrsr = &rPaM;
294 932 : do {
295 932 : pDoc->SetTxtFmtColl(*pTmpCrsr, pLocal);
296 932 : pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext());
297 : } while ( pTmpCrsr != &rPaM );
298 932 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
299 : }
300 :
301 : bool
302 219 : SwUnoCursorHelper::SetPageDesc(
303 : const uno::Any& rValue, SwDoc & rDoc, SfxItemSet & rSet)
304 : {
305 219 : OUString uDescName;
306 219 : if (!(rValue >>= uDescName))
307 : {
308 0 : return false;
309 : }
310 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
311 219 : ::std::auto_ptr<SwFmtPageDesc> pNewDesc;
312 : SAL_WNODEPRECATED_DECLARATIONS_POP
313 : const SfxPoolItem* pItem;
314 219 : if(SFX_ITEM_SET == rSet.GetItemState( RES_PAGEDESC, sal_True, &pItem ) )
315 : {
316 : pNewDesc.reset(new SwFmtPageDesc(
317 8 : *static_cast<const SwFmtPageDesc*>(pItem)));
318 : }
319 219 : if (!pNewDesc.get())
320 : {
321 211 : pNewDesc.reset(new SwFmtPageDesc());
322 : }
323 219 : String sDescName;
324 : SwStyleNameMapper::FillUIName(uDescName, sDescName,
325 219 : nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, true);
326 219 : if (!pNewDesc->GetPageDesc() ||
327 0 : (pNewDesc->GetPageDesc()->GetName() != sDescName))
328 : {
329 219 : bool bPut = false;
330 219 : if(sDescName.Len())
331 : {
332 : SwPageDesc *const pPageDesc =
333 215 : ::GetPageDescByName_Impl(rDoc, sDescName);
334 215 : if (!pPageDesc)
335 : {
336 0 : throw lang::IllegalArgumentException();
337 : }
338 215 : pNewDesc.get()->RegisterToPageDesc( *pPageDesc );
339 215 : bPut = true;
340 : }
341 219 : if(!bPut)
342 : {
343 4 : rSet.ClearItem(RES_BREAK);
344 4 : rSet.Put(SwFmtPageDesc());
345 : }
346 : else
347 : {
348 215 : rSet.Put(*pNewDesc);
349 : }
350 : }
351 219 : return true;
352 : }
353 :
354 : static void
355 0 : lcl_SetNodeNumStart(SwPaM & rCrsr, uno::Any const& rValue)
356 : {
357 0 : sal_Int16 nTmp = 1;
358 0 : rValue >>= nTmp;
359 0 : sal_uInt16 nStt = (nTmp < 0 ? USHRT_MAX : (sal_uInt16)nTmp);
360 0 : SwDoc* pDoc = rCrsr.GetDoc();
361 0 : UnoActionContext aAction(pDoc);
362 :
363 0 : if( rCrsr.GetNext() != &rCrsr ) // Mehrfachselektion ?
364 : {
365 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
366 0 : SwPamRanges aRangeArr( rCrsr );
367 0 : SwPaM aPam( *rCrsr.GetPoint() );
368 0 : for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
369 : {
370 0 : pDoc->SetNumRuleStart(*aRangeArr.SetPam( n, aPam ).GetPoint());
371 0 : pDoc->SetNodeNumStart(*aRangeArr.SetPam( n, aPam ).GetPoint(),
372 0 : nStt );
373 : }
374 0 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
375 : }
376 : else
377 : {
378 0 : pDoc->SetNumRuleStart( *rCrsr.GetPoint());
379 0 : pDoc->SetNodeNumStart( *rCrsr.GetPoint(), nStt );
380 0 : }
381 0 : }
382 :
383 : static bool
384 0 : lcl_setCharFmtSequence(SwPaM & rPam, uno::Any const& rValue)
385 : {
386 0 : uno::Sequence<OUString> aCharStyles;
387 0 : if (!(rValue >>= aCharStyles))
388 : {
389 0 : return false;
390 : }
391 :
392 0 : for (sal_Int32 nStyle = 0; nStyle < aCharStyles.getLength(); nStyle++)
393 : {
394 0 : uno::Any aStyle;
395 0 : rPam.GetDoc()->GetIDocumentUndoRedo().StartUndo(UNDO_START, NULL);
396 0 : aStyle <<= aCharStyles.getConstArray()[nStyle];
397 : // create a local set and apply each format directly
398 0 : SfxItemSet aSet(rPam.GetDoc()->GetAttrPool(),
399 0 : RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT);
400 0 : lcl_setCharStyle(rPam.GetDoc(), aStyle, aSet);
401 : // the first style should replace the current attributes,
402 : // all other have to be added
403 : SwUnoCursorHelper::SetCrsrAttr(rPam, aSet, (nStyle)
404 : ? nsSetAttrMode::SETATTR_DONTREPLACE
405 0 : : nsSetAttrMode::SETATTR_DEFAULT);
406 0 : rPam.GetDoc()->GetIDocumentUndoRedo().EndUndo(UNDO_START, NULL);
407 0 : }
408 0 : return true;
409 : }
410 :
411 : static void
412 0 : lcl_setDropcapCharStyle(SwPaM & rPam, SfxItemSet & rItemSet,
413 : uno::Any const& rValue)
414 : {
415 0 : OUString uStyle;
416 0 : if (!(rValue >>= uStyle))
417 : {
418 0 : throw lang::IllegalArgumentException();
419 : }
420 0 : String sStyle;
421 : SwStyleNameMapper::FillUIName(uStyle, sStyle,
422 0 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true);
423 0 : SwDoc *const pDoc = rPam.GetDoc();
424 : //default character style must not be set as default format
425 : SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
426 0 : pDoc->GetDocShell()
427 0 : ->GetStyleSheetPool()->Find(sStyle, SFX_STYLE_FAMILY_CHAR));
428 0 : if (!pStyle ||
429 0 : (static_cast<SwDocStyleSheet*>(pStyle)->GetCharFmt() ==
430 0 : pDoc->GetDfltCharFmt()))
431 : {
432 0 : throw lang::IllegalArgumentException();
433 : }
434 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
435 0 : ::std::auto_ptr<SwFmtDrop> pDrop;
436 : SAL_WNODEPRECATED_DECLARATIONS_POP
437 0 : SfxPoolItem const* pItem(0);
438 0 : if (SFX_ITEM_SET ==
439 0 : rItemSet.GetItemState(RES_PARATR_DROP, sal_True, &pItem))
440 : {
441 0 : pDrop.reset(new SwFmtDrop(*static_cast<const SwFmtDrop*>(pItem)));
442 : }
443 0 : if (!pDrop.get())
444 : {
445 0 : pDrop.reset(new SwFmtDrop);
446 : }
447 0 : const rtl::Reference<SwDocStyleSheet> xStyle(new SwDocStyleSheet(*pStyle));
448 0 : pDrop->SetCharFmt(xStyle->GetCharFmt());
449 0 : rItemSet.Put(*pDrop);
450 0 : }
451 :
452 : static void
453 0 : lcl_setRubyCharstyle(SfxItemSet & rItemSet, uno::Any const& rValue)
454 : {
455 0 : OUString sTmp;
456 0 : if (!(rValue >>= sTmp))
457 : {
458 0 : throw lang::IllegalArgumentException();
459 : }
460 :
461 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
462 0 : ::std::auto_ptr<SwFmtRuby> pRuby;
463 : SAL_WNODEPRECATED_DECLARATIONS_POP
464 : const SfxPoolItem* pItem;
465 0 : if (SFX_ITEM_SET ==
466 0 : rItemSet.GetItemState(RES_TXTATR_CJK_RUBY, sal_True, &pItem))
467 : {
468 0 : pRuby.reset(new SwFmtRuby(*static_cast<const SwFmtRuby*>(pItem)));
469 : }
470 0 : if (!pRuby.get())
471 : {
472 0 : pRuby.reset(new SwFmtRuby(aEmptyStr));
473 : }
474 0 : String sStyle;
475 : SwStyleNameMapper::FillUIName(sTmp, sStyle,
476 0 : nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
477 0 : pRuby->SetCharFmtName(sStyle);
478 0 : pRuby->SetCharFmtId(0);
479 0 : if (sStyle.Len() > 0)
480 : {
481 : const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
482 0 : sStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
483 0 : pRuby->SetCharFmtId(nId);
484 : }
485 0 : rItemSet.Put(*pRuby);
486 0 : }
487 :
488 : bool
489 4848 : SwUnoCursorHelper::SetCursorPropertyValue(
490 : SfxItemPropertySimpleEntry const& rEntry, const uno::Any& rValue,
491 : SwPaM & rPam, SfxItemSet & rItemSet)
492 : throw (lang::IllegalArgumentException)
493 : {
494 4848 : if (!(rEntry.nFlags & beans::PropertyAttribute::MAYBEVOID) &&
495 0 : (rValue.getValueType() == ::getCppuVoidType()))
496 : {
497 0 : return false;
498 : }
499 4848 : bool bRet = true;
500 4848 : switch (rEntry.nWID)
501 : {
502 : case RES_TXTATR_CHARFMT:
503 6 : lcl_setCharStyle(rPam.GetDoc(), rValue, rItemSet);
504 6 : break;
505 : case RES_TXTATR_AUTOFMT:
506 8 : lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(),
507 8 : rValue, rItemSet, false);
508 8 : break;
509 : case FN_UNO_CHARFMT_SEQUENCE:
510 0 : lcl_setCharFmtSequence(rPam, rValue);
511 0 : break;
512 : case FN_UNO_PARA_STYLE :
513 932 : SwUnoCursorHelper::SetTxtFmtColl(rValue, rPam);
514 932 : break;
515 : case RES_AUTO_STYLE:
516 23 : lcl_setAutoStyle(rPam.GetDoc()->GetIStyleAccess(),
517 23 : rValue, rItemSet, true);
518 23 : break;
519 : case FN_UNO_PAGE_STYLE:
520 : //FIXME nothing here?
521 0 : break;
522 : case FN_UNO_NUM_START_VALUE:
523 0 : lcl_SetNodeNumStart( rPam, rValue );
524 0 : break;
525 : case FN_UNO_NUM_LEVEL:
526 : // #i91601#
527 : case FN_UNO_LIST_ID:
528 : case FN_UNO_IS_NUMBER:
529 : {
530 : // multi selection is not considered
531 32 : SwTxtNode *const pTxtNd = rPam.GetNode()->GetTxtNode();
532 32 : if (FN_UNO_NUM_LEVEL == rEntry.nWID)
533 : {
534 25 : sal_Int16 nLevel = 0;
535 25 : if (rValue >>= nLevel)
536 : {
537 25 : pTxtNd->SetAttrListLevel(nLevel);
538 : }
539 : }
540 : // #i91601#
541 7 : else if (FN_UNO_LIST_ID == rEntry.nWID)
542 : {
543 7 : ::rtl::OUString sListId;
544 7 : if (rValue >>= sListId)
545 : {
546 7 : pTxtNd->SetListId( sListId );
547 7 : }
548 : }
549 0 : else if (FN_UNO_IS_NUMBER == rEntry.nWID)
550 : {
551 0 : sal_Bool bIsNumber(sal_False);
552 0 : if (rValue >>= bIsNumber)
553 : {
554 0 : if (!bIsNumber)
555 : {
556 0 : pTxtNd->SetCountedInList( false );
557 : }
558 : }
559 : }
560 : //PROPERTY_MAYBEVOID!
561 : }
562 32 : break;
563 : case FN_NUMBER_NEWSTART:
564 : {
565 0 : sal_Bool bVal = sal_False;
566 0 : if (!(rValue >>= bVal))
567 : {
568 0 : throw lang::IllegalArgumentException();
569 : }
570 0 : rPam.GetDoc()->SetNumRuleStart(*rPam.GetPoint(), bVal);
571 : }
572 0 : break;
573 : case FN_UNO_NUM_RULES:
574 29 : SwUnoCursorHelper::setNumberingProperty(rValue, rPam);
575 29 : break;
576 : case RES_PARATR_DROP:
577 : {
578 0 : if (MID_DROPCAP_CHAR_STYLE_NAME == rEntry.nMemberId)
579 : {
580 0 : lcl_setDropcapCharStyle(rPam, rItemSet, rValue);
581 : }
582 : else
583 : {
584 0 : bRet = false;
585 : }
586 : }
587 0 : break;
588 : case RES_TXTATR_CJK_RUBY:
589 : {
590 0 : if (MID_RUBY_CHARSTYLE == rEntry.nMemberId)
591 : {
592 0 : lcl_setRubyCharstyle(rItemSet, rValue);
593 : }
594 : else
595 : {
596 0 : bRet = false;
597 : }
598 : }
599 0 : break;
600 : case RES_PAGEDESC:
601 : {
602 219 : if (MID_PAGEDESC_PAGEDESCNAME == rEntry.nMemberId)
603 : {
604 : SwUnoCursorHelper::SetPageDesc(
605 219 : rValue, *rPam.GetDoc(), rItemSet);
606 : }
607 : else
608 : {
609 0 : bRet = false;
610 : }
611 : }
612 219 : break;
613 : default:
614 3599 : bRet = false;
615 : }
616 4848 : return bRet;
617 : }
618 :
619 : SwFmtColl *
620 0 : SwUnoCursorHelper::GetCurTxtFmtColl(SwPaM & rPaM, const bool bConditional)
621 : {
622 : static const sal_uInt16 nMaxLookup = 1000;
623 0 : SwFmtColl *pFmt = 0;
624 :
625 : // if ( GetCrsrCnt() > nMaxLookup )
626 : // return 0;
627 0 : bool bError = false;
628 0 : SwPaM *pTmpCrsr = &rPaM;
629 0 : do
630 : {
631 0 : const sal_uLong nSttNd = pTmpCrsr->Start()->nNode.GetIndex();
632 0 : const sal_uLong nEndNd = pTmpCrsr->End()->nNode.GetIndex();
633 :
634 0 : if( nEndNd - nSttNd >= nMaxLookup )
635 : {
636 0 : pFmt = 0;
637 0 : break;
638 : }
639 :
640 0 : const SwNodes& rNds = rPaM.GetDoc()->GetNodes();
641 0 : for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
642 : {
643 0 : SwTxtNode const*const pNd = rNds[ n ]->GetTxtNode();
644 0 : if( pNd )
645 : {
646 : SwFmtColl *const pNdFmt = (bConditional)
647 0 : ? pNd->GetFmtColl() : &pNd->GetAnyFmtColl();
648 0 : if( !pFmt )
649 : {
650 0 : pFmt = pNdFmt;
651 : }
652 0 : else if( pFmt != pNdFmt )
653 : {
654 0 : bError = true;
655 0 : break;
656 : }
657 : }
658 : }
659 :
660 0 : pTmpCrsr = static_cast<SwPaM*>(pTmpCrsr->GetNext());
661 : } while ( pTmpCrsr != &rPaM );
662 0 : return (bError) ? 0 : pFmt;
663 : }
664 :
665 : /* --------------------------------------------------
666 : * Hilfsfunktion fuer PageDesc
667 : * --------------------------------------------------*/
668 226 : SwPageDesc* GetPageDescByName_Impl(SwDoc& rDoc, const String& rName)
669 : {
670 226 : SwPageDesc* pRet = 0;
671 226 : sal_uInt16 nDCount = rDoc.GetPageDescCnt();
672 : sal_uInt16 i;
673 :
674 262 : for( i = 0; i < nDCount; i++ )
675 : {
676 260 : SwPageDesc* pDsc = &rDoc.GetPageDesc( i );
677 260 : if(pDsc->GetName() == rName)
678 : {
679 224 : pRet = pDsc;
680 224 : break;
681 : }
682 : }
683 226 : if(!pRet)
684 : {
685 4 : for(i = RC_POOLPAGEDESC_BEGIN; i <= STR_POOLPAGE_LANDSCAPE; ++i)
686 : {
687 4 : const String aFmtName(SW_RES(i));
688 4 : if(aFmtName == rName)
689 : {
690 : pRet = rDoc.GetPageDescFromPool( static_cast< sal_uInt16 >(
691 2 : RES_POOLPAGE_BEGIN + i - RC_POOLPAGEDESC_BEGIN) );
692 : break;
693 : }
694 4 : }
695 : }
696 :
697 226 : return pRet;
698 : }
699 :
700 : /******************************************************************
701 : * SwXTextCursor
702 : ******************************************************************/
703 : class SwXTextCursor::Impl
704 : : public SwClient
705 : {
706 :
707 : public:
708 :
709 : const SfxItemPropertySet & m_rPropSet;
710 : const enum CursorType m_eType;
711 : const uno::Reference< text::XText > m_xParentText;
712 : SwEventListenerContainer m_ListenerContainer;
713 : bool m_bIsDisposed;
714 :
715 3281 : Impl( SwXTextCursor & rThis,
716 : SwDoc & rDoc,
717 : const enum CursorType eType,
718 : uno::Reference<text::XText> xParent,
719 : SwPosition const& rPoint, SwPosition const*const pMark)
720 3281 : : SwClient(rDoc.CreateUnoCrsr(rPoint, false))
721 3281 : , m_rPropSet(*aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_CURSOR))
722 : , m_eType(eType)
723 : , m_xParentText(xParent)
724 : , m_ListenerContainer(static_cast< ::cppu::OWeakObject* >(&rThis))
725 6562 : , m_bIsDisposed(false)
726 : {
727 3281 : if (pMark)
728 : {
729 441 : GetCursor()->SetMark();
730 441 : *GetCursor()->GetMark() = *pMark;
731 : }
732 3281 : }
733 :
734 9843 : ~Impl() {
735 : // Impl owns the cursor; delete it here: SolarMutex is locked
736 3281 : delete GetRegisteredIn();
737 6562 : }
738 :
739 14380 : SwUnoCrsr * GetCursor() {
740 : return (m_bIsDisposed) ? 0 :
741 14380 : static_cast<SwUnoCrsr*>(const_cast<SwModify*>(GetRegisteredIn()));
742 : }
743 :
744 7808 : SwUnoCrsr & GetCursorOrThrow() {
745 7808 : SwUnoCrsr *const pUnoCursor( GetCursor() );
746 7808 : if (!pUnoCursor) {
747 : throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
748 0 : "SwXTextCursor: disposed or invalid")), 0);
749 : }
750 7808 : return *pUnoCursor;
751 : }
752 :
753 3398 : void Invalidate() {
754 3398 : m_bIsDisposed = true;
755 3398 : m_ListenerContainer.Disposing();
756 3398 : }
757 : protected:
758 : // SwClient
759 : virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew);
760 :
761 : };
762 :
763 3398 : void SwXTextCursor::Impl::Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew)
764 : {
765 3398 : ClientModify(this, pOld, pNew);
766 :
767 3515 : if (!GetRegisteredIn() ||
768 : // if the cursor leaves its designated section, it becomes invalid
769 117 : ((pOld != NULL) && (pOld->Which() == RES_UNOCURSOR_LEAVES_SECTION)))
770 : {
771 3398 : Invalidate();
772 : }
773 3398 : }
774 :
775 0 : SwUnoCrsr const* SwXTextCursor::GetCursor() const
776 : {
777 0 : return m_pImpl->GetCursor();
778 : }
779 :
780 767 : SwUnoCrsr * SwXTextCursor::GetCursor()
781 : {
782 767 : return m_pImpl->GetCursor();
783 : }
784 :
785 0 : SwPaM const* SwXTextCursor::GetPaM() const
786 : {
787 0 : return m_pImpl->GetCursor();
788 : }
789 :
790 1492 : SwPaM * SwXTextCursor::GetPaM()
791 : {
792 1492 : return m_pImpl->GetCursor();
793 : }
794 :
795 0 : SwDoc const* SwXTextCursor::GetDoc() const
796 : {
797 0 : return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0;
798 : }
799 :
800 1557 : SwDoc * SwXTextCursor::GetDoc()
801 : {
802 1557 : return m_pImpl->GetCursor() ? m_pImpl->GetCursor()->GetDoc() : 0;
803 : }
804 :
805 3281 : SwXTextCursor::SwXTextCursor(
806 : SwDoc & rDoc,
807 : uno::Reference< text::XText > const& xParent,
808 : const enum CursorType eType,
809 : const SwPosition& rPos,
810 : SwPosition const*const pMark)
811 : : m_pImpl( new SwXTextCursor::Impl(*this, rDoc, eType, xParent,
812 3281 : rPos, pMark ) )
813 : {
814 3281 : }
815 :
816 0 : SwXTextCursor::SwXTextCursor(uno::Reference< text::XText > const& xParent,
817 : SwPaM const& rSourceCursor, const enum CursorType eType)
818 : : m_pImpl( new SwXTextCursor::Impl(*this, *rSourceCursor.GetDoc(), eType,
819 : xParent, *rSourceCursor.GetPoint(),
820 0 : rSourceCursor.HasMark() ? rSourceCursor.GetMark() : 0) )
821 : {
822 0 : }
823 :
824 6562 : SwXTextCursor::~SwXTextCursor()
825 : {
826 6562 : }
827 :
828 297 : void SwXTextCursor::DeleteAndInsert(const ::rtl::OUString& rText,
829 : const bool bForceExpandHints)
830 : {
831 297 : SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor();
832 297 : if(pUnoCrsr)
833 : {
834 : // Start/EndAction
835 297 : SwDoc* pDoc = pUnoCrsr->GetDoc();
836 297 : UnoActionContext aAction(pDoc);
837 297 : const xub_StrLen nTxtLen = rText.getLength();
838 297 : pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
839 297 : SwCursor * pCurrent = pUnoCrsr;
840 297 : do
841 : {
842 297 : if (pCurrent->HasMark())
843 : {
844 297 : pDoc->DeleteAndJoin(*pCurrent);
845 : }
846 297 : if(nTxtLen)
847 : {
848 : const bool bSuccess(
849 : SwUnoCursorHelper::DocInsertStringSplitCR(
850 0 : *pDoc, *pCurrent, rText, bForceExpandHints ) );
851 : OSL_ENSURE( bSuccess, "Doc->Insert(Str) failed." );
852 : (void) bSuccess;
853 :
854 0 : SwUnoCursorHelper::SelectPam(*pUnoCrsr, true);
855 0 : pCurrent->Left(rText.getLength(),
856 0 : CRSR_SKIP_CHARS, sal_False, sal_False);
857 : }
858 297 : pCurrent = static_cast<SwCursor *>(pCurrent->GetNext());
859 : } while (pCurrent != pUnoCrsr);
860 297 : pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
861 : }
862 297 : }
863 :
864 : enum ForceIntoMetaMode { META_CHECK_BOTH, META_INIT_START, META_INIT_END };
865 :
866 : static sal_Bool
867 0 : lcl_ForceIntoMeta(SwPaM & rCursor,
868 : uno::Reference<text::XText> const & xParentText,
869 : const enum ForceIntoMetaMode eMode)
870 : {
871 0 : sal_Bool bRet( sal_True ); // means not forced in META_CHECK_BOTH
872 0 : SwXMeta const * const pXMeta( dynamic_cast<SwXMeta*>(xParentText.get()) );
873 : OSL_ENSURE(pXMeta, "no parent?");
874 0 : if (!pXMeta)
875 0 : throw uno::RuntimeException();
876 : SwTxtNode * pTxtNode;
877 : xub_StrLen nStart;
878 : xub_StrLen nEnd;
879 0 : const bool bSuccess( pXMeta->SetContentRange(pTxtNode, nStart, nEnd) );
880 : OSL_ENSURE(bSuccess, "no pam?");
881 0 : if (!bSuccess)
882 0 : throw uno::RuntimeException();
883 : // force the cursor back into the meta if it has moved outside
884 0 : SwPosition start(*pTxtNode, nStart);
885 0 : SwPosition end(*pTxtNode, nEnd);
886 0 : switch (eMode)
887 : {
888 : case META_INIT_START:
889 0 : *rCursor.GetPoint() = start;
890 0 : break;
891 : case META_INIT_END:
892 0 : *rCursor.GetPoint() = end;
893 0 : break;
894 : case META_CHECK_BOTH:
895 0 : if (*rCursor.Start() < start)
896 : {
897 0 : *rCursor.Start() = start;
898 0 : bRet = sal_False;
899 : }
900 0 : if (*rCursor.End() > end)
901 : {
902 0 : *rCursor.End() = end;
903 0 : bRet = sal_False;
904 : }
905 0 : break;
906 : }
907 0 : return bRet;
908 : }
909 :
910 6 : bool SwXTextCursor::IsAtEndOfMeta() const
911 : {
912 6 : if (CURSOR_META == m_pImpl->m_eType)
913 : {
914 0 : SwUnoCrsr const * const pCursor( m_pImpl->GetCursor() );
915 : SwXMeta const*const pXMeta(
916 0 : dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get()) );
917 : OSL_ENSURE(pXMeta, "no meta?");
918 0 : if (pCursor && pXMeta)
919 : {
920 : SwTxtNode * pTxtNode;
921 : xub_StrLen nStart;
922 : xub_StrLen nEnd;
923 : const bool bSuccess(
924 0 : pXMeta->SetContentRange(pTxtNode, nStart, nEnd) );
925 : OSL_ENSURE(bSuccess, "no pam?");
926 0 : if (bSuccess)
927 : {
928 0 : const SwPosition end(*pTxtNode, nEnd);
929 0 : if ( (*pCursor->GetPoint() == end)
930 0 : || (*pCursor->GetMark() == end))
931 : {
932 0 : return true;
933 0 : }
934 : }
935 : }
936 : }
937 6 : return false;
938 : }
939 :
940 0 : OUString SwXTextCursor::getImplementationName() throw (uno::RuntimeException)
941 : {
942 0 : return C2U("SwXTextCursor");
943 : }
944 :
945 : static char const*const g_ServicesTextCursor[] =
946 : {
947 : "com.sun.star.text.TextCursor",
948 : "com.sun.star.style.CharacterProperties",
949 : "com.sun.star.style.CharacterPropertiesAsian",
950 : "com.sun.star.style.CharacterPropertiesComplex",
951 : "com.sun.star.style.ParagraphProperties",
952 : "com.sun.star.style.ParagraphPropertiesAsian",
953 : "com.sun.star.style.ParagraphPropertiesComplex",
954 : "com.sun.star.text.TextSortable",
955 : };
956 :
957 : static const size_t g_nServicesTextCursor(
958 : sizeof(g_ServicesTextCursor)/sizeof(g_ServicesTextCursor[0]));
959 :
960 0 : sal_Bool SAL_CALL SwXTextCursor::supportsService(const OUString& rServiceName)
961 : throw (uno::RuntimeException)
962 : {
963 : return ::sw::SupportsServiceImpl(
964 0 : g_nServicesTextCursor, g_ServicesTextCursor, rServiceName);
965 : }
966 :
967 : uno::Sequence< OUString > SAL_CALL
968 0 : SwXTextCursor::getSupportedServiceNames() throw (uno::RuntimeException)
969 : {
970 : return ::sw::GetSupportedServiceNamesImpl(
971 0 : g_nServicesTextCursor, g_ServicesTextCursor);
972 : }
973 :
974 : namespace
975 : {
976 : class theSwXTextCursorUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextCursorUnoTunnelId > {};
977 : }
978 :
979 6001 : const uno::Sequence< sal_Int8 > & SwXTextCursor::getUnoTunnelId()
980 : {
981 6001 : return theSwXTextCursorUnoTunnelId::get().getSeq();
982 : }
983 :
984 : sal_Int64 SAL_CALL
985 5404 : SwXTextCursor::getSomething(const uno::Sequence< sal_Int8 >& rId)
986 : throw (uno::RuntimeException)
987 : {
988 5404 : const sal_Int64 nRet( ::sw::UnoTunnelImpl<SwXTextCursor>(rId, this) );
989 5404 : return (nRet) ? nRet : OTextCursorHelper::getSomething(rId);
990 : }
991 :
992 0 : void SAL_CALL SwXTextCursor::collapseToStart() throw (uno::RuntimeException)
993 : {
994 0 : SolarMutexGuard aGuard;
995 :
996 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
997 :
998 0 : if (rUnoCursor.HasMark())
999 : {
1000 0 : if (*rUnoCursor.GetPoint() > *rUnoCursor.GetMark())
1001 : {
1002 0 : rUnoCursor.Exchange();
1003 : }
1004 0 : rUnoCursor.DeleteMark();
1005 0 : }
1006 0 : }
1007 :
1008 0 : void SAL_CALL SwXTextCursor::collapseToEnd() throw (uno::RuntimeException)
1009 : {
1010 0 : SolarMutexGuard aGuard;
1011 :
1012 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1013 :
1014 0 : if (rUnoCursor.HasMark())
1015 : {
1016 0 : if (*rUnoCursor.GetPoint() < *rUnoCursor.GetMark())
1017 : {
1018 0 : rUnoCursor.Exchange();
1019 : }
1020 0 : rUnoCursor.DeleteMark();
1021 0 : }
1022 0 : }
1023 :
1024 20 : sal_Bool SAL_CALL SwXTextCursor::isCollapsed() throw (uno::RuntimeException)
1025 : {
1026 20 : SolarMutexGuard aGuard;
1027 :
1028 20 : sal_Bool bRet = sal_True;
1029 20 : SwUnoCrsr *const pUnoCrsr = m_pImpl->GetCursor();
1030 20 : if(pUnoCrsr && pUnoCrsr->GetMark())
1031 : {
1032 20 : bRet = (*pUnoCrsr->GetPoint() == *pUnoCrsr->GetMark());
1033 : }
1034 20 : return bRet;
1035 : }
1036 :
1037 : sal_Bool SAL_CALL
1038 1030 : SwXTextCursor::goLeft(sal_Int16 nCount, sal_Bool Expand)
1039 : throw (uno::RuntimeException)
1040 : {
1041 1030 : SolarMutexGuard aGuard;
1042 :
1043 1030 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1044 :
1045 1030 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1046 1030 : sal_Bool bRet = rUnoCursor.Left( nCount, CRSR_SKIP_CHARS, sal_False, sal_False);
1047 1030 : if (CURSOR_META == m_pImpl->m_eType)
1048 : {
1049 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1050 0 : META_CHECK_BOTH)
1051 0 : && bRet;
1052 : }
1053 1030 : return bRet;
1054 : }
1055 :
1056 : sal_Bool SAL_CALL
1057 27 : SwXTextCursor::goRight(sal_Int16 nCount, sal_Bool Expand)
1058 : throw (uno::RuntimeException)
1059 : {
1060 27 : SolarMutexGuard aGuard;
1061 :
1062 27 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1063 :
1064 27 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1065 27 : sal_Bool bRet = rUnoCursor.Right(nCount, CRSR_SKIP_CHARS, sal_False, sal_False);
1066 27 : if (CURSOR_META == m_pImpl->m_eType)
1067 : {
1068 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1069 0 : META_CHECK_BOTH)
1070 0 : && bRet;
1071 : }
1072 27 : return bRet;
1073 : }
1074 :
1075 : void SAL_CALL
1076 1636 : SwXTextCursor::gotoStart(sal_Bool Expand) throw (uno::RuntimeException)
1077 : {
1078 1636 : SolarMutexGuard aGuard;
1079 :
1080 1636 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1081 :
1082 1636 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1083 1636 : if (CURSOR_BODY == m_pImpl->m_eType)
1084 : {
1085 1635 : rUnoCursor.Move( fnMoveBackward, fnGoDoc );
1086 : //check, that the cursor is not in a table
1087 1635 : SwTableNode * pTblNode = rUnoCursor.GetNode()->FindTableNode();
1088 1635 : SwCntntNode * pCNode = 0;
1089 3280 : while (pTblNode)
1090 : {
1091 10 : rUnoCursor.GetPoint()->nNode = *pTblNode->EndOfSectionNode();
1092 10 : pCNode = GetDoc()->GetNodes().GoNext(&rUnoCursor.GetPoint()->nNode);
1093 10 : pTblNode = (pCNode) ? pCNode->FindTableNode() : 0;
1094 : }
1095 1635 : if (pCNode)
1096 : {
1097 10 : rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0);
1098 : }
1099 : SwStartNode const*const pTmp =
1100 1635 : rUnoCursor.GetNode()->StartOfSectionNode();
1101 1635 : if (pTmp->IsSectionNode())
1102 : {
1103 : SwSectionNode const*const pSectionStartNode =
1104 13 : static_cast<SwSectionNode const*>(pTmp);
1105 13 : if (pSectionStartNode->GetSection().IsHiddenFlag())
1106 : {
1107 0 : pCNode = GetDoc()->GetNodes().GoNextSection(
1108 0 : &rUnoCursor.GetPoint()->nNode, sal_True, sal_False);
1109 0 : if (pCNode)
1110 : {
1111 0 : rUnoCursor.GetPoint()->nContent.Assign(pCNode, 0);
1112 : }
1113 : }
1114 : }
1115 : }
1116 3 : else if ( (CURSOR_FRAME == m_pImpl->m_eType)
1117 1 : || (CURSOR_TBLTEXT == m_pImpl->m_eType)
1118 1 : || (CURSOR_HEADER == m_pImpl->m_eType)
1119 0 : || (CURSOR_FOOTER == m_pImpl->m_eType)
1120 0 : || (CURSOR_FOOTNOTE== m_pImpl->m_eType)
1121 0 : || (CURSOR_REDLINE == m_pImpl->m_eType))
1122 : {
1123 1 : rUnoCursor.MoveSection(fnSectionCurr, fnSectionStart);
1124 : }
1125 0 : else if (CURSOR_META == m_pImpl->m_eType)
1126 : {
1127 0 : lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_START);
1128 1636 : }
1129 1636 : }
1130 :
1131 : void SAL_CALL
1132 2154 : SwXTextCursor::gotoEnd(sal_Bool Expand) throw (uno::RuntimeException)
1133 : {
1134 2154 : SolarMutexGuard aGuard;
1135 :
1136 2154 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1137 :
1138 2154 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1139 2154 : if (CURSOR_BODY == m_pImpl->m_eType)
1140 : {
1141 1982 : rUnoCursor.Move( fnMoveForward, fnGoDoc );
1142 : }
1143 495 : else if ( (CURSOR_FRAME == m_pImpl->m_eType)
1144 126 : || (CURSOR_TBLTEXT == m_pImpl->m_eType)
1145 126 : || (CURSOR_HEADER == m_pImpl->m_eType)
1146 58 : || (CURSOR_FOOTER == m_pImpl->m_eType)
1147 13 : || (CURSOR_FOOTNOTE== m_pImpl->m_eType)
1148 0 : || (CURSOR_REDLINE == m_pImpl->m_eType))
1149 : {
1150 172 : rUnoCursor.MoveSection( fnSectionCurr, fnSectionEnd);
1151 : }
1152 0 : else if (CURSOR_META == m_pImpl->m_eType)
1153 : {
1154 0 : lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText, META_INIT_END);
1155 2154 : }
1156 2154 : }
1157 :
1158 : void SAL_CALL
1159 851 : SwXTextCursor::gotoRange(
1160 : const uno::Reference< text::XTextRange > & xRange, sal_Bool bExpand)
1161 : throw (uno::RuntimeException)
1162 : {
1163 851 : SolarMutexGuard aGuard;
1164 :
1165 851 : if (!xRange.is())
1166 : {
1167 0 : throw uno::RuntimeException();
1168 : }
1169 :
1170 851 : SwUnoCrsr & rOwnCursor( m_pImpl->GetCursorOrThrow() );
1171 :
1172 851 : uno::Reference<lang::XUnoTunnel> xRangeTunnel( xRange, uno::UNO_QUERY);
1173 851 : SwXTextRange* pRange = 0;
1174 851 : OTextCursorHelper* pCursor = 0;
1175 851 : if(xRangeTunnel.is())
1176 : {
1177 851 : pRange = ::sw::UnoTunnelGetImplementation<SwXTextRange>(xRangeTunnel);
1178 : pCursor =
1179 851 : ::sw::UnoTunnelGetImplementation<OTextCursorHelper>(xRangeTunnel);
1180 : }
1181 :
1182 851 : if (!pRange && !pCursor)
1183 : {
1184 0 : throw uno::RuntimeException();
1185 : }
1186 :
1187 851 : SwStartNodeType eSearchNodeType = SwNormalStartNode;
1188 851 : switch (m_pImpl->m_eType)
1189 : {
1190 13 : case CURSOR_FRAME: eSearchNodeType = SwFlyStartNode; break;
1191 115 : case CURSOR_TBLTEXT: eSearchNodeType = SwTableBoxStartNode; break;
1192 7 : case CURSOR_FOOTNOTE: eSearchNodeType = SwFootnoteStartNode; break;
1193 29 : case CURSOR_HEADER: eSearchNodeType = SwHeaderStartNode; break;
1194 19 : case CURSOR_FOOTER: eSearchNodeType = SwFooterStartNode; break;
1195 : //case CURSOR_INVALID:
1196 : //case CURSOR_BODY:
1197 : default:
1198 : ;
1199 : }
1200 : const SwStartNode* pOwnStartNode =
1201 851 : rOwnCursor.GetNode()->FindSttNodeByType(eSearchNodeType);
1202 :
1203 851 : SwPaM aPam(GetDoc()->GetNodes());
1204 851 : const SwPaM * pPam(0);
1205 851 : if (pCursor)
1206 : {
1207 603 : pPam = pCursor->GetPaM();
1208 : }
1209 248 : else if (pRange)
1210 : {
1211 248 : if (pRange->GetPositions(aPam))
1212 : {
1213 248 : pPam = & aPam;
1214 : }
1215 : }
1216 :
1217 851 : if (!pPam)
1218 : {
1219 0 : throw uno::RuntimeException();
1220 : }
1221 : const SwStartNode* pTmp =
1222 851 : pPam->GetNode()->FindSttNodeByType(eSearchNodeType);
1223 :
1224 : //SectionNodes ueberspringen
1225 1703 : while(pTmp && pTmp->IsSectionNode())
1226 : {
1227 1 : pTmp = pTmp->StartOfSectionNode();
1228 : }
1229 1707 : while(pOwnStartNode && pOwnStartNode->IsSectionNode())
1230 : {
1231 5 : pOwnStartNode = pOwnStartNode->StartOfSectionNode();
1232 : }
1233 851 : if(pOwnStartNode != pTmp)
1234 : {
1235 0 : throw uno::RuntimeException();
1236 : }
1237 :
1238 851 : if (CURSOR_META == m_pImpl->m_eType)
1239 : {
1240 0 : SwPaM CopyPam(*pPam->GetMark(), *pPam->GetPoint());
1241 : const bool bNotForced( lcl_ForceIntoMeta(
1242 0 : CopyPam, m_pImpl->m_xParentText, META_CHECK_BOTH) );
1243 0 : if (!bNotForced)
1244 : {
1245 : throw uno::RuntimeException(
1246 : C2U("gotoRange: parameter range not contained in nesting"
1247 : " text content for which this cursor was created"),
1248 0 : static_cast<text::XWordCursor*>(this));
1249 0 : }
1250 : }
1251 :
1252 : //jetzt muss die Selektion erweitert werden
1253 851 : if(bExpand)
1254 : {
1255 : // der Cursor soll alles einschliessen, was bisher von ihm und dem uebergebenen
1256 : // Range eingeschlossen wurde
1257 253 : const SwPosition aOwnLeft(*rOwnCursor.Start());
1258 253 : const SwPosition aOwnRight(*rOwnCursor.End());
1259 253 : SwPosition const& rParamLeft = *pPam->Start();
1260 253 : SwPosition const& rParamRight = *pPam->End();
1261 :
1262 : // jetzt sind vier SwPositions da, zwei davon werden gebraucht, also welche?
1263 253 : *rOwnCursor.GetPoint() = (aOwnRight > rParamRight)
1264 253 : ? aOwnRight : *rOwnCursor.GetPoint() = rParamRight;
1265 253 : rOwnCursor.SetMark();
1266 253 : *rOwnCursor.GetMark() = (aOwnLeft < rParamLeft)
1267 253 : ? aOwnLeft : *rOwnCursor.GetMark() = rParamLeft;
1268 : }
1269 : else
1270 : {
1271 : // cursor should be the given range
1272 598 : *rOwnCursor.GetPoint() = *pPam->GetPoint();
1273 598 : if (pPam->HasMark())
1274 : {
1275 0 : rOwnCursor.SetMark();
1276 0 : *rOwnCursor.GetMark() = *pPam->GetMark();
1277 : }
1278 : else
1279 : {
1280 598 : rOwnCursor.DeleteMark();
1281 : }
1282 851 : }
1283 851 : }
1284 :
1285 0 : sal_Bool SAL_CALL SwXTextCursor::isStartOfWord() throw (uno::RuntimeException)
1286 : {
1287 0 : SolarMutexGuard aGuard;
1288 :
1289 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1290 :
1291 : const sal_Bool bRet =
1292 0 : rUnoCursor.IsStartWordWT( i18n::WordType::DICTIONARY_WORD );
1293 0 : return bRet;
1294 : }
1295 :
1296 0 : sal_Bool SAL_CALL SwXTextCursor::isEndOfWord() throw (uno::RuntimeException)
1297 : {
1298 0 : SolarMutexGuard aGuard;
1299 :
1300 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1301 :
1302 : const sal_Bool bRet =
1303 0 : rUnoCursor.IsEndWordWT( i18n::WordType::DICTIONARY_WORD );
1304 0 : return bRet;
1305 : }
1306 :
1307 : sal_Bool SAL_CALL
1308 0 : SwXTextCursor::gotoNextWord(sal_Bool Expand) throw (uno::RuntimeException)
1309 : {
1310 0 : SolarMutexGuard aGuard;
1311 :
1312 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1313 :
1314 : //Probleme gibt's noch mit einem Absatzanfang, an dem kein Wort beginnt.
1315 0 : sal_Bool bRet = sal_False;
1316 : // remember old position to check if cursor has moved
1317 : // since the called functions are sometimes a bit unreliable
1318 : // in specific cases...
1319 0 : SwPosition *const pPoint = rUnoCursor.GetPoint();
1320 0 : SwNode *const pOldNode = &pPoint->nNode.GetNode();
1321 0 : xub_StrLen const nOldIndex = pPoint->nContent.GetIndex();
1322 :
1323 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1324 : // end of paragraph
1325 0 : if (rUnoCursor.GetCntntNode() &&
1326 0 : (pPoint->nContent == rUnoCursor.GetCntntNode()->Len()))
1327 : {
1328 0 : rUnoCursor.Right(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1329 : }
1330 : else
1331 : {
1332 : const bool bTmp =
1333 0 : rUnoCursor.GoNextWordWT( i18n::WordType::DICTIONARY_WORD );
1334 : // if there is no next word within the current paragraph
1335 : // try to go to the start of the next paragraph
1336 0 : if (!bTmp)
1337 : {
1338 0 : rUnoCursor.MovePara(fnParaNext, fnParaStart);
1339 : }
1340 : }
1341 :
1342 : // return true if cursor has moved
1343 0 : bRet = (&pPoint->nNode.GetNode() != pOldNode) ||
1344 0 : (pPoint->nContent.GetIndex() != nOldIndex);
1345 0 : if (bRet && (CURSOR_META == m_pImpl->m_eType))
1346 : {
1347 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1348 0 : META_CHECK_BOTH);
1349 : }
1350 :
1351 0 : return bRet;
1352 : }
1353 :
1354 : sal_Bool SAL_CALL
1355 0 : SwXTextCursor::gotoPreviousWord(sal_Bool Expand) throw (uno::RuntimeException)
1356 : {
1357 0 : SolarMutexGuard aGuard;
1358 :
1359 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1360 :
1361 : // hier machen Leerzeichen am Absatzanfang Probleme
1362 0 : sal_Bool bRet = sal_False;
1363 0 : SwPosition *const pPoint = rUnoCursor.GetPoint();
1364 0 : SwNode *const pOldNode = &pPoint->nNode.GetNode();
1365 0 : xub_StrLen const nOldIndex = pPoint->nContent.GetIndex();
1366 :
1367 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1368 : // start of paragraph?
1369 0 : if (pPoint->nContent == 0)
1370 : {
1371 0 : rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1372 : }
1373 : else
1374 : {
1375 0 : rUnoCursor.GoPrevWordWT( i18n::WordType::DICTIONARY_WORD );
1376 0 : if (pPoint->nContent == 0)
1377 : {
1378 0 : rUnoCursor.Left(1, CRSR_SKIP_CHARS, sal_False, sal_False);
1379 : }
1380 : }
1381 :
1382 : // return true if cursor has moved
1383 0 : bRet = (&pPoint->nNode.GetNode() != pOldNode) ||
1384 0 : (pPoint->nContent.GetIndex() != nOldIndex);
1385 0 : if (bRet && (CURSOR_META == m_pImpl->m_eType))
1386 : {
1387 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1388 0 : META_CHECK_BOTH);
1389 : }
1390 :
1391 0 : return bRet;
1392 : }
1393 :
1394 : sal_Bool SAL_CALL
1395 0 : SwXTextCursor::gotoEndOfWord(sal_Bool Expand) throw (uno::RuntimeException)
1396 : {
1397 0 : SolarMutexGuard aGuard;
1398 :
1399 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1400 :
1401 0 : sal_Bool bRet = sal_False;
1402 0 : SwPosition *const pPoint = rUnoCursor.GetPoint();
1403 0 : SwNode & rOldNode = pPoint->nNode.GetNode();
1404 0 : xub_StrLen const nOldIndex = pPoint->nContent.GetIndex();
1405 :
1406 0 : const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1407 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1408 0 : if (!rUnoCursor.IsEndWordWT( nWordType ))
1409 : {
1410 0 : rUnoCursor.GoEndWordWT( nWordType );
1411 : }
1412 :
1413 : // restore old cursor if we are not at the end of a word by now
1414 : // otherwise use current one
1415 0 : bRet = rUnoCursor.IsEndWordWT( nWordType );
1416 0 : if (!bRet)
1417 : {
1418 0 : pPoint->nNode = rOldNode;
1419 0 : pPoint->nContent = nOldIndex;
1420 : }
1421 0 : else if (CURSOR_META == m_pImpl->m_eType)
1422 : {
1423 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1424 0 : META_CHECK_BOTH);
1425 : }
1426 :
1427 0 : return bRet;
1428 : }
1429 :
1430 : sal_Bool SAL_CALL
1431 0 : SwXTextCursor::gotoStartOfWord(sal_Bool Expand) throw (uno::RuntimeException)
1432 : {
1433 0 : SolarMutexGuard aGuard;
1434 :
1435 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1436 :
1437 0 : sal_Bool bRet = sal_False;
1438 0 : SwPosition *const pPoint = rUnoCursor.GetPoint();
1439 0 : SwNode & rOldNode = pPoint->nNode.GetNode();
1440 0 : xub_StrLen const nOldIndex = pPoint->nContent.GetIndex();
1441 :
1442 0 : const sal_Int16 nWordType = i18n::WordType::DICTIONARY_WORD;
1443 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1444 0 : if (!rUnoCursor.IsStartWordWT( nWordType ))
1445 : {
1446 0 : rUnoCursor.GoStartWordWT( nWordType );
1447 : }
1448 :
1449 : // restore old cursor if we are not at the start of a word by now
1450 : // otherwise use current one
1451 0 : bRet = rUnoCursor.IsStartWordWT( nWordType );
1452 0 : if (!bRet)
1453 : {
1454 0 : pPoint->nNode = rOldNode;
1455 0 : pPoint->nContent = nOldIndex;
1456 : }
1457 0 : else if (CURSOR_META == m_pImpl->m_eType)
1458 : {
1459 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1460 0 : META_CHECK_BOTH);
1461 : }
1462 :
1463 0 : return bRet;
1464 : }
1465 :
1466 : sal_Bool SAL_CALL
1467 0 : SwXTextCursor::isStartOfSentence() throw (uno::RuntimeException)
1468 : {
1469 0 : SolarMutexGuard aGuard;
1470 :
1471 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1472 :
1473 : // start of paragraph?
1474 0 : sal_Bool bRet = rUnoCursor.GetPoint()->nContent == 0;
1475 : // with mark ->no sentence start
1476 : // (check if cursor is no selection, i.e. it does not have
1477 : // a mark or else point and mark are identical)
1478 0 : if (!bRet && (!rUnoCursor.HasMark() ||
1479 0 : *rUnoCursor.GetPoint() == *rUnoCursor.GetMark()))
1480 : {
1481 0 : SwCursor aCrsr(*rUnoCursor.GetPoint(),0,false);
1482 0 : SwPosition aOrigPos = *aCrsr.GetPoint();
1483 0 : aCrsr.GoSentence(SwCursor::START_SENT );
1484 0 : bRet = aOrigPos == *aCrsr.GetPoint();
1485 : }
1486 0 : return bRet;
1487 : }
1488 :
1489 : sal_Bool SAL_CALL
1490 0 : SwXTextCursor::isEndOfSentence() throw (uno::RuntimeException)
1491 : {
1492 0 : SolarMutexGuard aGuard;
1493 :
1494 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1495 :
1496 : // end of paragraph?
1497 0 : sal_Bool bRet = rUnoCursor.GetCntntNode() &&
1498 0 : (rUnoCursor.GetPoint()->nContent == rUnoCursor.GetCntntNode()->Len());
1499 : // with mark->no sentence end
1500 : // (check if cursor is no selection, i.e. it does not have
1501 : // a mark or else point and mark are identical)
1502 0 : if (!bRet && (!rUnoCursor.HasMark() ||
1503 0 : *rUnoCursor.GetPoint() == *rUnoCursor.GetMark()))
1504 : {
1505 0 : SwCursor aCrsr(*rUnoCursor.GetPoint(), 0, false);
1506 0 : SwPosition aOrigPos = *aCrsr.GetPoint();
1507 0 : aCrsr.GoSentence(SwCursor::END_SENT);
1508 0 : bRet = aOrigPos == *aCrsr.GetPoint();
1509 : }
1510 0 : return bRet;
1511 : }
1512 :
1513 : sal_Bool SAL_CALL
1514 0 : SwXTextCursor::gotoNextSentence(sal_Bool Expand) throw (uno::RuntimeException)
1515 : {
1516 0 : SolarMutexGuard aGuard;
1517 :
1518 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1519 :
1520 0 : const bool bWasEOS = isEndOfSentence();
1521 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1522 0 : sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::NEXT_SENT);
1523 0 : if (!bRet)
1524 : {
1525 0 : bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart);
1526 : }
1527 :
1528 : // if at the end of the sentence (i.e. at the space after the '.')
1529 : // advance to next word in order for GoSentence to work properly
1530 : // next time and have isStartOfSentence return true after this call
1531 0 : if (!rUnoCursor.IsStartWord())
1532 : {
1533 0 : const bool bNextWord = rUnoCursor.GoNextWord();
1534 0 : if (bWasEOS && !bNextWord)
1535 : {
1536 0 : bRet = sal_False;
1537 : }
1538 : }
1539 0 : if (CURSOR_META == m_pImpl->m_eType)
1540 : {
1541 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1542 0 : META_CHECK_BOTH)
1543 0 : && bRet;
1544 : }
1545 0 : return bRet;
1546 : }
1547 :
1548 : sal_Bool SAL_CALL
1549 0 : SwXTextCursor::gotoPreviousSentence(sal_Bool Expand)
1550 : throw (uno::RuntimeException)
1551 : {
1552 0 : SolarMutexGuard aGuard;
1553 :
1554 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1555 :
1556 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1557 0 : sal_Bool bRet = rUnoCursor.GoSentence(SwCursor::PREV_SENT);
1558 0 : if (!bRet)
1559 : {
1560 0 : bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart);
1561 0 : if (bRet)
1562 : {
1563 0 : rUnoCursor.MovePara(fnParaCurr, fnParaEnd);
1564 : // at the end of a paragraph move to the sentence end again
1565 0 : rUnoCursor.GoSentence(SwCursor::PREV_SENT);
1566 : }
1567 : }
1568 0 : if (CURSOR_META == m_pImpl->m_eType)
1569 : {
1570 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1571 0 : META_CHECK_BOTH)
1572 0 : && bRet;
1573 : }
1574 0 : return bRet;
1575 : }
1576 :
1577 : sal_Bool SAL_CALL
1578 0 : SwXTextCursor::gotoStartOfSentence(sal_Bool Expand)
1579 : throw (uno::RuntimeException)
1580 : {
1581 0 : SolarMutexGuard aGuard;
1582 :
1583 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1584 :
1585 0 : sal_Bool bRet = sal_False;
1586 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1587 : // if we're at the para start then we wont move
1588 : // but bRet is also true if GoSentence failed but
1589 : // the start of the sentence is reached
1590 0 : bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor)
1591 0 : || rUnoCursor.GoSentence(SwCursor::START_SENT)
1592 0 : || SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1593 0 : if (CURSOR_META == m_pImpl->m_eType)
1594 : {
1595 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1596 0 : META_CHECK_BOTH)
1597 0 : && bRet;
1598 : }
1599 0 : return bRet;
1600 : }
1601 :
1602 : sal_Bool SAL_CALL
1603 0 : SwXTextCursor::gotoEndOfSentence(sal_Bool Expand) throw (uno::RuntimeException)
1604 : {
1605 0 : SolarMutexGuard aGuard;
1606 :
1607 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1608 :
1609 0 : sal_Bool bRet = sal_False;
1610 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1611 : // bRet is true if GoSentence() succeeded or if the
1612 : // MovePara() succeeded while the end of the para is
1613 : // not reached already
1614 0 : sal_Bool bAlreadyParaEnd = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1615 : bRet = !bAlreadyParaEnd
1616 0 : && (rUnoCursor.GoSentence(SwCursor::END_SENT)
1617 0 : || rUnoCursor.MovePara(fnParaCurr, fnParaEnd));
1618 0 : if (CURSOR_META == m_pImpl->m_eType)
1619 : {
1620 0 : bRet = lcl_ForceIntoMeta(rUnoCursor, m_pImpl->m_xParentText,
1621 0 : META_CHECK_BOTH)
1622 0 : && bRet;
1623 : }
1624 0 : return bRet;
1625 : }
1626 :
1627 : sal_Bool SAL_CALL
1628 0 : SwXTextCursor::isStartOfParagraph() throw (uno::RuntimeException)
1629 : {
1630 0 : SolarMutexGuard aGuard;
1631 :
1632 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1633 :
1634 0 : const sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1635 0 : return bRet;
1636 : }
1637 :
1638 : sal_Bool SAL_CALL
1639 0 : SwXTextCursor::isEndOfParagraph() throw (uno::RuntimeException)
1640 : {
1641 0 : SolarMutexGuard aGuard;
1642 :
1643 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1644 :
1645 0 : const sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1646 0 : return bRet;
1647 : }
1648 :
1649 : sal_Bool SAL_CALL
1650 20 : SwXTextCursor::gotoStartOfParagraph(sal_Bool Expand)
1651 : throw (uno::RuntimeException)
1652 : {
1653 20 : SolarMutexGuard aGuard;
1654 :
1655 20 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1656 :
1657 20 : if (CURSOR_META == m_pImpl->m_eType)
1658 : {
1659 0 : return sal_False;
1660 : }
1661 20 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1662 20 : sal_Bool bRet = SwUnoCursorHelper::IsStartOfPara(rUnoCursor);
1663 20 : if (!bRet)
1664 : {
1665 16 : bRet = rUnoCursor.MovePara(fnParaCurr, fnParaStart);
1666 : }
1667 :
1668 : // since MovePara(fnParaCurr, fnParaStart) only returns false
1669 : // if we were already at the start of the paragraph this function
1670 : // should always complete successfully.
1671 : OSL_ENSURE( bRet, "gotoStartOfParagraph failed" );
1672 20 : return bRet;
1673 : }
1674 :
1675 : sal_Bool SAL_CALL
1676 0 : SwXTextCursor::gotoEndOfParagraph(sal_Bool Expand) throw (uno::RuntimeException)
1677 : {
1678 0 : SolarMutexGuard aGuard;
1679 :
1680 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1681 :
1682 0 : if (CURSOR_META == m_pImpl->m_eType)
1683 : {
1684 0 : return sal_False;
1685 : }
1686 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1687 0 : sal_Bool bRet = SwUnoCursorHelper::IsEndOfPara(rUnoCursor);
1688 0 : if (!bRet)
1689 : {
1690 0 : bRet = rUnoCursor.MovePara(fnParaCurr, fnParaEnd);
1691 : }
1692 :
1693 : // since MovePara(fnParaCurr, fnParaEnd) only returns false
1694 : // if we were already at the end of the paragraph this function
1695 : // should always complete successfully.
1696 : OSL_ENSURE( bRet, "gotoEndOfParagraph failed" );
1697 0 : return bRet;
1698 : }
1699 :
1700 : sal_Bool SAL_CALL
1701 0 : SwXTextCursor::gotoNextParagraph(sal_Bool Expand) throw (uno::RuntimeException)
1702 : {
1703 0 : SolarMutexGuard aGuard;
1704 :
1705 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1706 :
1707 0 : if (CURSOR_META == m_pImpl->m_eType)
1708 : {
1709 0 : return sal_False;
1710 : }
1711 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1712 0 : const sal_Bool bRet = rUnoCursor.MovePara(fnParaNext, fnParaStart);
1713 0 : return bRet;
1714 : }
1715 :
1716 : sal_Bool SAL_CALL
1717 0 : SwXTextCursor::gotoPreviousParagraph(sal_Bool Expand)
1718 : throw (uno::RuntimeException)
1719 : {
1720 0 : SolarMutexGuard aGuard;
1721 :
1722 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1723 :
1724 0 : if (CURSOR_META == m_pImpl->m_eType)
1725 : {
1726 0 : return sal_False;
1727 : }
1728 0 : SwUnoCursorHelper::SelectPam(rUnoCursor, Expand);
1729 0 : const sal_Bool bRet = rUnoCursor.MovePara(fnParaPrev, fnParaStart);
1730 0 : return bRet;
1731 : }
1732 :
1733 : uno::Reference< text::XText > SAL_CALL
1734 1016 : SwXTextCursor::getText() throw (uno::RuntimeException)
1735 : {
1736 1016 : SolarMutexGuard g;
1737 :
1738 1016 : return m_pImpl->m_xParentText;
1739 : }
1740 :
1741 : uno::Reference< text::XTextRange > SAL_CALL
1742 756 : SwXTextCursor::getStart() throw (uno::RuntimeException)
1743 : {
1744 756 : SolarMutexGuard aGuard;
1745 :
1746 756 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1747 :
1748 756 : uno::Reference< text::XTextRange > xRet;
1749 756 : SwPaM aPam(*rUnoCursor.Start());
1750 756 : const uno::Reference< text::XText > xParent = getText();
1751 756 : if (CURSOR_META == m_pImpl->m_eType)
1752 : {
1753 : // return cursor to prevent modifying SwXTextRange for META
1754 : SwXTextCursor * const pXCursor(
1755 0 : new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META,
1756 0 : *rUnoCursor.GetPoint()) );
1757 0 : pXCursor->gotoStart(sal_False);
1758 0 : xRet = static_cast<text::XWordCursor*>(pXCursor);
1759 : }
1760 : else
1761 : {
1762 756 : xRet = new SwXTextRange(aPam, xParent);
1763 : }
1764 756 : return xRet;
1765 : }
1766 :
1767 : uno::Reference< text::XTextRange > SAL_CALL
1768 0 : SwXTextCursor::getEnd() throw (uno::RuntimeException)
1769 : {
1770 0 : SolarMutexGuard aGuard;
1771 :
1772 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1773 :
1774 0 : uno::Reference< text::XTextRange > xRet;
1775 0 : SwPaM aPam(*rUnoCursor.End());
1776 0 : const uno::Reference< text::XText > xParent = getText();
1777 0 : if (CURSOR_META == m_pImpl->m_eType)
1778 : {
1779 : // return cursor to prevent modifying SwXTextRange for META
1780 : SwXTextCursor * const pXCursor(
1781 0 : new SwXTextCursor(*rUnoCursor.GetDoc(), xParent, CURSOR_META,
1782 0 : *rUnoCursor.GetPoint()) );
1783 0 : pXCursor->gotoEnd(sal_False);
1784 0 : xRet = static_cast<text::XWordCursor*>(pXCursor);
1785 : }
1786 : else
1787 : {
1788 0 : xRet = new SwXTextRange(aPam, xParent);
1789 : }
1790 0 : return xRet;
1791 : }
1792 :
1793 7 : OUString SAL_CALL SwXTextCursor::getString() throw (uno::RuntimeException)
1794 : {
1795 7 : SolarMutexGuard aGuard;
1796 :
1797 7 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1798 :
1799 7 : OUString aTxt;
1800 7 : SwUnoCursorHelper::GetTextFromPam(rUnoCursor, aTxt);
1801 7 : return aTxt;
1802 : }
1803 :
1804 : void SAL_CALL
1805 294 : SwXTextCursor::setString(const OUString& aString) throw (uno::RuntimeException)
1806 : {
1807 294 : SolarMutexGuard aGuard;
1808 :
1809 294 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
1810 : (void) rUnoCursor; // just to check if valid
1811 :
1812 294 : const bool bForceExpandHints( (CURSOR_META != m_pImpl->m_eType)
1813 : ? false
1814 0 : : dynamic_cast<SwXMeta*>(m_pImpl->m_xParentText.get())
1815 294 : ->CheckForOwnMemberMeta(*GetPaM(), true) );
1816 294 : DeleteAndInsert(aString, bForceExpandHints);
1817 294 : }
1818 :
1819 544 : uno::Any SwUnoCursorHelper::GetPropertyValue(
1820 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1821 : const OUString& rPropertyName)
1822 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
1823 : uno::RuntimeException)
1824 : {
1825 544 : uno::Any aAny;
1826 : SfxItemPropertySimpleEntry const*const pEntry =
1827 544 : rPropSet.getPropertyMap().getByName(rPropertyName);
1828 :
1829 544 : if (!pEntry)
1830 : {
1831 : throw beans::UnknownPropertyException(
1832 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
1833 0 : + rPropertyName, static_cast<cppu::OWeakObject *>(0));
1834 : }
1835 :
1836 : beans::PropertyState eTemp;
1837 : const bool bDone = SwUnoCursorHelper::getCrsrPropertyValue(
1838 544 : *pEntry, rPaM, &aAny, eTemp );
1839 :
1840 544 : if (!bDone)
1841 : {
1842 104 : SfxItemSet aSet(rPaM.GetDoc()->GetAttrPool(),
1843 : RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
1844 : RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
1845 : RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1846 104 : 0L);
1847 104 : SwUnoCursorHelper::GetCrsrAttr(rPaM, aSet);
1848 :
1849 104 : rPropSet.getPropertyValue(*pEntry, aSet, aAny);
1850 : }
1851 :
1852 544 : return aAny;
1853 : }
1854 :
1855 4848 : void SwUnoCursorHelper::SetPropertyValue(
1856 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1857 : const OUString& rPropertyName,
1858 : const uno::Any& rValue,
1859 : const SetAttrMode nAttrMode, const bool bTableMode)
1860 : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
1861 : lang::IllegalArgumentException, lang::WrappedTargetException,
1862 : uno::RuntimeException)
1863 : {
1864 4848 : SwDoc *const pDoc = rPaM.GetDoc();
1865 : SfxItemPropertySimpleEntry const*const pEntry =
1866 4848 : rPropSet.getPropertyMap().getByName(rPropertyName);
1867 4848 : if (!pEntry)
1868 : {
1869 : throw beans::UnknownPropertyException(
1870 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
1871 0 : + rPropertyName,
1872 0 : static_cast<cppu::OWeakObject *>(0));
1873 : }
1874 :
1875 4848 : if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
1876 : {
1877 : throw beans::PropertyVetoException(
1878 : OUString(RTL_CONSTASCII_USTRINGPARAM("Property is read-only: "))
1879 0 : + rPropertyName,
1880 0 : static_cast<cppu::OWeakObject *>(0));
1881 : }
1882 :
1883 4848 : SfxItemSet aItemSet( pDoc->GetAttrPool(), pEntry->nWID, pEntry->nWID );
1884 4848 : SwUnoCursorHelper::GetCrsrAttr( rPaM, aItemSet );
1885 :
1886 4848 : if (!SwUnoCursorHelper::SetCursorPropertyValue(
1887 4848 : *pEntry, rValue, rPaM, aItemSet))
1888 : {
1889 3599 : rPropSet.setPropertyValue(*pEntry, rValue, aItemSet );
1890 : }
1891 4848 : SwUnoCursorHelper::SetCrsrAttr(rPaM, aItemSet, nAttrMode, bTableMode);
1892 4848 : }
1893 :
1894 : uno::Sequence< beans::PropertyState >
1895 35 : SwUnoCursorHelper::GetPropertyStates(
1896 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
1897 : const uno::Sequence< OUString >& rPropertyNames,
1898 : const SwGetPropertyStatesCaller eCaller)
1899 : throw (beans::UnknownPropertyException, uno::RuntimeException)
1900 : {
1901 35 : const OUString* pNames = rPropertyNames.getConstArray();
1902 35 : uno::Sequence< beans::PropertyState > aRet(rPropertyNames.getLength());
1903 35 : beans::PropertyState* pStates = aRet.getArray();
1904 35 : const SfxItemPropertyMap &rMap = rPropSet.getPropertyMap();
1905 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
1906 35 : ::std::auto_ptr<SfxItemSet> pSet;
1907 35 : ::std::auto_ptr<SfxItemSet> pSetParent;
1908 : SAL_WNODEPRECATED_DECLARATIONS_POP
1909 :
1910 2240 : for (sal_Int32 i = 0, nEnd = rPropertyNames.getLength(); i < nEnd; i++)
1911 : {
1912 : SfxItemPropertySimpleEntry const*const pEntry =
1913 2205 : rMap.getByName( pNames[i] );
1914 2205 : if(!pEntry)
1915 : {
1916 0 : if (pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
1917 0 : pNames[i].equalsAsciiL( SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
1918 : {
1919 0 : pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1920 0 : continue;
1921 : }
1922 0 : else if (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT ==
1923 : eCaller)
1924 : {
1925 : //this values marks the element as unknown property
1926 0 : pStates[i] = beans::PropertyState_MAKE_FIXED_SIZE;
1927 0 : continue;
1928 : }
1929 : else
1930 : {
1931 : throw beans::UnknownPropertyException(
1932 : OUString( RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
1933 0 : + pNames[i],
1934 0 : static_cast<cppu::OWeakObject *>(0));
1935 : }
1936 : }
1937 2205 : if (((SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION == eCaller) ||
1938 : (SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT == eCaller)) &&
1939 : pEntry->nWID < FN_UNO_RANGE_BEGIN &&
1940 : pEntry->nWID > FN_UNO_RANGE_END &&
1941 : pEntry->nWID < RES_CHRATR_BEGIN &&
1942 : pEntry->nWID > RES_TXTATR_END )
1943 : {
1944 0 : pStates[i] = beans::PropertyState_DEFAULT_VALUE;
1945 : }
1946 : else
1947 : {
1948 2205 : if ( pEntry->nWID >= FN_UNO_RANGE_BEGIN &&
1949 : pEntry->nWID <= FN_UNO_RANGE_END )
1950 : {
1951 : SwUnoCursorHelper::getCrsrPropertyValue(
1952 0 : *pEntry, rPaM, 0, pStates[i] );
1953 : }
1954 : else
1955 : {
1956 2205 : if (!pSet.get())
1957 : {
1958 35 : switch ( eCaller )
1959 : {
1960 : case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION_TOLERANT:
1961 : case SW_PROPERTY_STATE_CALLER_SWX_TEXT_PORTION:
1962 : pSet.reset(
1963 33 : new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
1964 33 : RES_CHRATR_BEGIN, RES_TXTATR_END ));
1965 33 : break;
1966 : case SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY:
1967 : pSet.reset(
1968 0 : new SfxItemSet( rPaM.GetDoc()->GetAttrPool(),
1969 0 : pEntry->nWID, pEntry->nWID ));
1970 0 : break;
1971 : default:
1972 : pSet.reset( new SfxItemSet(
1973 2 : rPaM.GetDoc()->GetAttrPool(),
1974 : RES_CHRATR_BEGIN, RES_FRMATR_END - 1,
1975 : RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER,
1976 : RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
1977 2 : 0L ));
1978 : }
1979 : // #i63870#
1980 35 : SwUnoCursorHelper::GetCrsrAttr( rPaM, *pSet );
1981 : }
1982 :
1983 2205 : pStates[i] = ( pSet->Count() )
1984 315 : ? rPropSet.getPropertyState( *pEntry, *pSet )
1985 2520 : : beans::PropertyState_DEFAULT_VALUE;
1986 :
1987 : //try again to find out if a value has been inherited
1988 2205 : if( beans::PropertyState_DIRECT_VALUE == pStates[i] )
1989 : {
1990 5 : if (!pSetParent.get())
1991 : {
1992 5 : pSetParent.reset( pSet->Clone( sal_False ) );
1993 : // #i63870#
1994 : SwUnoCursorHelper::GetCrsrAttr(
1995 5 : rPaM, *pSetParent, sal_True, sal_False );
1996 : }
1997 :
1998 5 : pStates[i] = ( (pSetParent)->Count() )
1999 0 : ? rPropSet.getPropertyState( *pEntry, *pSetParent )
2000 5 : : beans::PropertyState_DEFAULT_VALUE;
2001 : }
2002 : }
2003 : }
2004 : }
2005 35 : return aRet;
2006 : }
2007 :
2008 0 : beans::PropertyState SwUnoCursorHelper::GetPropertyState(
2009 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2010 : const OUString& rPropertyName)
2011 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2012 : {
2013 0 : uno::Sequence< OUString > aStrings ( 1 );
2014 0 : aStrings[0] = rPropertyName;
2015 : uno::Sequence< beans::PropertyState > aSeq =
2016 : GetPropertyStates(rPaM, rPropSet, aStrings,
2017 0 : SW_PROPERTY_STATE_CALLER_SINGLE_VALUE_ONLY );
2018 0 : return aSeq[0];
2019 : }
2020 :
2021 : static void
2022 0 : lcl_SelectParaAndReset( SwPaM &rPaM, SwDoc & rDoc,
2023 : std::set<sal_uInt16> const &rWhichIds )
2024 : {
2025 : // if we are reseting paragraph attributes, we need to select the full paragraph first
2026 0 : SwPosition aStart = *rPaM.Start();
2027 0 : SwPosition aEnd = *rPaM.End();
2028 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2029 0 : ::std::auto_ptr< SwUnoCrsr > pTemp ( rDoc.CreateUnoCrsr(aStart, false) );
2030 : SAL_WNODEPRECATED_DECLARATIONS_POP
2031 0 : if(!SwUnoCursorHelper::IsStartOfPara(*pTemp))
2032 : {
2033 0 : pTemp->MovePara(fnParaCurr, fnParaStart);
2034 : }
2035 0 : pTemp->SetMark();
2036 0 : *pTemp->GetPoint() = aEnd;
2037 0 : SwUnoCursorHelper::SelectPam(*pTemp, true);
2038 0 : if(!SwUnoCursorHelper::IsEndOfPara(*pTemp))
2039 : {
2040 0 : pTemp->MovePara(fnParaCurr, fnParaEnd);
2041 : }
2042 0 : rDoc.ResetAttrs(*pTemp, true, rWhichIds);
2043 0 : }
2044 :
2045 0 : void SwUnoCursorHelper::SetPropertyToDefault(
2046 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2047 : const OUString& rPropertyName)
2048 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2049 : {
2050 0 : SwDoc & rDoc = *rPaM.GetDoc();
2051 : SfxItemPropertySimpleEntry const*const pEntry =
2052 0 : rPropSet.getPropertyMap().getByName(rPropertyName);
2053 0 : if (!pEntry)
2054 : {
2055 : throw beans::UnknownPropertyException(
2056 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2057 0 : + rPropertyName, static_cast<cppu::OWeakObject *>(0));
2058 : }
2059 :
2060 0 : if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2061 : {
2062 : throw uno::RuntimeException(OUString(RTL_CONSTASCII_USTRINGPARAM(
2063 : "setPropertyToDefault: property is read-only: "))
2064 0 : + rPropertyName, 0);
2065 : }
2066 :
2067 0 : if (pEntry->nWID < RES_FRMATR_END)
2068 : {
2069 0 : std::set<sal_uInt16> aWhichIds;
2070 0 : aWhichIds.insert( pEntry->nWID );
2071 0 : if (pEntry->nWID < RES_PARATR_BEGIN)
2072 : {
2073 0 : rDoc.ResetAttrs(rPaM, true, aWhichIds);
2074 : }
2075 : else
2076 : {
2077 0 : lcl_SelectParaAndReset ( rPaM, rDoc, aWhichIds );
2078 0 : }
2079 : }
2080 : else
2081 : {
2082 0 : SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rPaM);
2083 : }
2084 0 : }
2085 :
2086 0 : uno::Any SwUnoCursorHelper::GetPropertyDefault(
2087 : SwPaM& rPaM, const SfxItemPropertySet& rPropSet,
2088 : const OUString& rPropertyName)
2089 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2090 : uno::RuntimeException)
2091 : {
2092 : SfxItemPropertySimpleEntry const*const pEntry =
2093 0 : rPropSet.getPropertyMap().getByName(rPropertyName);
2094 0 : if (!pEntry)
2095 : {
2096 : throw beans::UnknownPropertyException(
2097 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2098 0 : + rPropertyName, static_cast<cppu::OWeakObject *>(0));
2099 : }
2100 :
2101 0 : uno::Any aRet;
2102 0 : if (pEntry->nWID < RES_FRMATR_END)
2103 : {
2104 0 : SwDoc & rDoc = *rPaM.GetDoc();
2105 : const SfxPoolItem& rDefItem =
2106 0 : rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID);
2107 0 : rDefItem.QueryValue(aRet, pEntry->nMemberId);
2108 : }
2109 0 : return aRet;
2110 : }
2111 :
2112 : uno::Reference< beans::XPropertySetInfo > SAL_CALL
2113 312 : SwXTextCursor::getPropertySetInfo() throw (uno::RuntimeException)
2114 : {
2115 312 : SolarMutexGuard g;
2116 :
2117 312 : static uno::Reference< beans::XPropertySetInfo > xRef;
2118 312 : if(!xRef.is())
2119 : {
2120 : static SfxItemPropertyMapEntry aCrsrExtMap_Impl[] =
2121 : {
2122 15 : { SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT), FN_SKIP_HIDDEN_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0},
2123 15 : { SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT), FN_SKIP_PROTECTED_TEXT, &::getBooleanCppuType(), PROPERTY_NONE, 0},
2124 : {0,0,0,0,0,0}
2125 35 : };
2126 : const uno::Reference< beans::XPropertySetInfo > xInfo =
2127 5 : m_pImpl->m_rPropSet.getPropertySetInfo();
2128 : // PropertySetInfo verlaengern!
2129 5 : const uno::Sequence<beans::Property> aPropSeq = xInfo->getProperties();
2130 : xRef = new SfxExtItemPropertySetInfo(
2131 : aCrsrExtMap_Impl,
2132 5 : aPropSeq );
2133 : }
2134 312 : return xRef;
2135 : }
2136 :
2137 : void SAL_CALL
2138 342 : SwXTextCursor::setPropertyValue(
2139 : const OUString& rPropertyName, const uno::Any& rValue)
2140 : throw (beans::UnknownPropertyException, beans::PropertyVetoException,
2141 : lang::IllegalArgumentException, lang::WrappedTargetException,
2142 : uno::RuntimeException)
2143 : {
2144 342 : SolarMutexGuard aGuard;
2145 :
2146 342 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2147 :
2148 342 : if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2149 : {
2150 0 : sal_Bool bSet(sal_False);
2151 0 : if (!(rValue >>= bSet))
2152 : {
2153 0 : throw lang::IllegalArgumentException();
2154 : }
2155 0 : rUnoCursor.SetSkipOverHiddenSections(bSet);
2156 : }
2157 342 : else if (rPropertyName.equalsAsciiL(
2158 342 : SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2159 : {
2160 0 : sal_Bool bSet(sal_False);
2161 0 : if (!(rValue >>= bSet))
2162 : {
2163 0 : throw lang::IllegalArgumentException();
2164 : }
2165 0 : rUnoCursor.SetSkipOverProtectSections(bSet);
2166 : }
2167 : else
2168 : {
2169 : SwUnoCursorHelper::SetPropertyValue(rUnoCursor,
2170 342 : m_pImpl->m_rPropSet, rPropertyName, rValue);
2171 342 : }
2172 342 : }
2173 :
2174 : uno::Any SAL_CALL
2175 541 : SwXTextCursor::getPropertyValue(const OUString& rPropertyName)
2176 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2177 : uno::RuntimeException)
2178 : {
2179 541 : SolarMutexGuard aGuard;
2180 :
2181 541 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2182 :
2183 541 : uno::Any aAny;
2184 541 : if (rPropertyName.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)))
2185 : {
2186 0 : const sal_Bool bSet = rUnoCursor.IsSkipOverHiddenSections();
2187 0 : aAny <<= bSet;
2188 : }
2189 541 : else if (rPropertyName.equalsAsciiL(
2190 541 : SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2191 : {
2192 0 : const sal_Bool bSet = rUnoCursor.IsSkipOverProtectSections();
2193 0 : aAny <<= bSet;
2194 : }
2195 : else
2196 : {
2197 : aAny = SwUnoCursorHelper::GetPropertyValue(rUnoCursor,
2198 541 : m_pImpl->m_rPropSet, rPropertyName);
2199 : }
2200 541 : return aAny;
2201 : }
2202 :
2203 : void SAL_CALL
2204 0 : SwXTextCursor::addPropertyChangeListener(
2205 : const ::rtl::OUString& /*rPropertyName*/,
2206 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2207 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2208 : uno::RuntimeException)
2209 : {
2210 : OSL_FAIL("SwXTextCursor::addPropertyChangeListener(): not implemented");
2211 0 : }
2212 :
2213 : void SAL_CALL
2214 0 : SwXTextCursor::removePropertyChangeListener(
2215 : const ::rtl::OUString& /*rPropertyName*/,
2216 : const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/)
2217 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2218 : uno::RuntimeException)
2219 : {
2220 : OSL_FAIL("SwXTextCursor::removePropertyChangeListener(): not implemented");
2221 0 : }
2222 :
2223 : void SAL_CALL
2224 0 : SwXTextCursor::addVetoableChangeListener(
2225 : const ::rtl::OUString& /*rPropertyName*/,
2226 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2227 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2228 : uno::RuntimeException)
2229 : {
2230 : OSL_FAIL("SwXTextCursor::addVetoableChangeListener(): not implemented");
2231 0 : }
2232 :
2233 : void SAL_CALL
2234 0 : SwXTextCursor::removeVetoableChangeListener(
2235 : const ::rtl::OUString& /*rPropertyName*/,
2236 : const uno::Reference< beans::XVetoableChangeListener >& /*xListener*/)
2237 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2238 : uno::RuntimeException)
2239 : {
2240 : OSL_FAIL("SwXTextCursor::removeVetoableChangeListener(): not implemented");
2241 0 : }
2242 :
2243 : beans::PropertyState SAL_CALL
2244 0 : SwXTextCursor::getPropertyState(const OUString& rPropertyName)
2245 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2246 : {
2247 0 : SolarMutexGuard aGuard;
2248 :
2249 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2250 :
2251 : const beans::PropertyState eRet = SwUnoCursorHelper::GetPropertyState(
2252 0 : rUnoCursor, m_pImpl->m_rPropSet, rPropertyName);
2253 0 : return eRet;
2254 : }
2255 :
2256 : uno::Sequence< beans::PropertyState > SAL_CALL
2257 0 : SwXTextCursor::getPropertyStates(
2258 : const uno::Sequence< OUString >& rPropertyNames)
2259 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2260 : {
2261 0 : SolarMutexGuard aGuard;
2262 :
2263 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2264 :
2265 : return SwUnoCursorHelper::GetPropertyStates(
2266 0 : rUnoCursor, m_pImpl->m_rPropSet, rPropertyNames);
2267 : }
2268 :
2269 : void SAL_CALL
2270 0 : SwXTextCursor::setPropertyToDefault(const OUString& rPropertyName)
2271 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2272 : {
2273 : // forward: need no solar mutex here
2274 0 : uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
2275 0 : setPropertiesToDefault ( aSequence );
2276 0 : }
2277 :
2278 : uno::Any SAL_CALL
2279 0 : SwXTextCursor::getPropertyDefault(const OUString& rPropertyName)
2280 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2281 : uno::RuntimeException)
2282 : {
2283 : // forward: need no solar mutex here
2284 0 : const uno::Sequence < OUString > aSequence ( &rPropertyName, 1 );
2285 0 : return getPropertyDefaults ( aSequence ).getConstArray()[0];
2286 : }
2287 :
2288 : // para specific attribut ranges
2289 : static sal_uInt16 g_ParaResetableSetRange[] = {
2290 : RES_FRMATR_BEGIN, RES_FRMATR_END-1,
2291 : RES_PARATR_BEGIN, RES_PARATR_END-1,
2292 : RES_PARATR_LIST_BEGIN, RES_PARATR_LIST_END-1,
2293 : RES_UNKNOWNATR_BEGIN, RES_UNKNOWNATR_END-1,
2294 : 0
2295 : };
2296 :
2297 : // selection specific attribut ranges
2298 : static sal_uInt16 g_ResetableSetRange[] = {
2299 : RES_CHRATR_BEGIN, RES_CHRATR_END-1,
2300 : RES_TXTATR_INETFMT, RES_TXTATR_INETFMT,
2301 : RES_TXTATR_CHARFMT, RES_TXTATR_CHARFMT,
2302 : RES_TXTATR_CJK_RUBY, RES_TXTATR_CJK_RUBY,
2303 : RES_TXTATR_UNKNOWN_CONTAINER, RES_TXTATR_UNKNOWN_CONTAINER,
2304 : 0
2305 : };
2306 :
2307 : static void
2308 0 : lcl_EnumerateIds(sal_uInt16 const* pIdRange, std::set<sal_uInt16> &rWhichIds)
2309 : {
2310 0 : while (*pIdRange)
2311 : {
2312 0 : const sal_uInt16 nStart = sal::static_int_cast<sal_uInt16>(*pIdRange++);
2313 0 : const sal_uInt16 nEnd = sal::static_int_cast<sal_uInt16>(*pIdRange++);
2314 0 : for (sal_uInt16 nId = nStart + 1; nId <= nEnd; ++nId)
2315 : {
2316 0 : rWhichIds.insert( rWhichIds.end(), nId );
2317 : }
2318 : }
2319 0 : }
2320 :
2321 : void SAL_CALL
2322 0 : SwXTextCursor::setAllPropertiesToDefault()
2323 : throw (uno::RuntimeException)
2324 : {
2325 0 : SolarMutexGuard aGuard;
2326 :
2327 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2328 :
2329 0 : std::set<sal_uInt16> aParaWhichIds;
2330 0 : std::set<sal_uInt16> aWhichIds;
2331 0 : lcl_EnumerateIds(g_ParaResetableSetRange, aParaWhichIds);
2332 0 : lcl_EnumerateIds(g_ResetableSetRange, aWhichIds);
2333 0 : if (!aParaWhichIds.empty())
2334 : {
2335 0 : lcl_SelectParaAndReset(rUnoCursor, *rUnoCursor.GetDoc(),
2336 0 : aParaWhichIds);
2337 : }
2338 0 : if (!aWhichIds.empty())
2339 : {
2340 0 : rUnoCursor.GetDoc()->ResetAttrs(rUnoCursor, true, aWhichIds);
2341 0 : }
2342 0 : }
2343 :
2344 : void SAL_CALL
2345 0 : SwXTextCursor::setPropertiesToDefault(
2346 : const uno::Sequence< OUString >& rPropertyNames)
2347 : throw (beans::UnknownPropertyException, uno::RuntimeException)
2348 : {
2349 0 : SolarMutexGuard aGuard;
2350 :
2351 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2352 :
2353 0 : const sal_Int32 nCount = rPropertyNames.getLength();
2354 0 : if ( nCount )
2355 : {
2356 0 : SwDoc & rDoc = *rUnoCursor.GetDoc();
2357 0 : const OUString * pNames = rPropertyNames.getConstArray();
2358 0 : std::set<sal_uInt16> aWhichIds;
2359 0 : std::set<sal_uInt16> aParaWhichIds;
2360 0 : for (sal_Int32 i = 0; i < nCount; i++)
2361 : {
2362 : SfxItemPropertySimpleEntry const*const pEntry =
2363 0 : m_pImpl->m_rPropSet.getPropertyMap().getByName( pNames[i] );
2364 0 : if (!pEntry)
2365 : {
2366 0 : if (pNames[i].equalsAsciiL(
2367 0 : SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2368 : pNames[i].equalsAsciiL(
2369 0 : SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2370 : {
2371 0 : continue;
2372 : }
2373 : throw beans::UnknownPropertyException(
2374 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2375 0 : + pNames[i],
2376 0 : static_cast<cppu::OWeakObject *>(this));
2377 : }
2378 0 : if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
2379 : {
2380 : throw uno::RuntimeException(
2381 : OUString(RTL_CONSTASCII_USTRINGPARAM(
2382 : "setPropertiesToDefault: property is read-only: "))
2383 0 : + pNames[i],
2384 0 : static_cast<cppu::OWeakObject *>(this));
2385 : }
2386 :
2387 0 : if (pEntry->nWID < RES_FRMATR_END)
2388 : {
2389 0 : if (pEntry->nWID < RES_PARATR_BEGIN)
2390 : {
2391 0 : aWhichIds.insert( pEntry->nWID );
2392 : }
2393 : else
2394 : {
2395 0 : aParaWhichIds.insert( pEntry->nWID );
2396 : }
2397 : }
2398 0 : else if (pEntry->nWID == FN_UNO_NUM_START_VALUE)
2399 : {
2400 0 : SwUnoCursorHelper::resetCrsrPropertyValue(*pEntry, rUnoCursor);
2401 : }
2402 : }
2403 :
2404 0 : if (!aParaWhichIds.empty())
2405 : {
2406 0 : lcl_SelectParaAndReset(rUnoCursor, rDoc, aParaWhichIds);
2407 : }
2408 0 : if (!aWhichIds.empty())
2409 : {
2410 0 : rDoc.ResetAttrs(rUnoCursor, true, aWhichIds);
2411 0 : }
2412 0 : }
2413 0 : }
2414 :
2415 : uno::Sequence< uno::Any > SAL_CALL
2416 0 : SwXTextCursor::getPropertyDefaults(
2417 : const uno::Sequence< OUString >& rPropertyNames)
2418 : throw (beans::UnknownPropertyException, lang::WrappedTargetException,
2419 : uno::RuntimeException)
2420 : {
2421 0 : SolarMutexGuard aGuard;
2422 :
2423 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2424 :
2425 0 : const sal_Int32 nCount = rPropertyNames.getLength();
2426 0 : uno::Sequence< uno::Any > aRet(nCount);
2427 0 : if ( nCount )
2428 : {
2429 0 : SwDoc & rDoc = *rUnoCursor.GetDoc();
2430 0 : const OUString *pNames = rPropertyNames.getConstArray();
2431 0 : uno::Any *pAny = aRet.getArray();
2432 0 : for (sal_Int32 i = 0; i < nCount; i++)
2433 : {
2434 : SfxItemPropertySimpleEntry const*const pEntry =
2435 0 : m_pImpl->m_rPropSet.getPropertyMap().getByName( pNames[i] );
2436 0 : if (!pEntry)
2437 : {
2438 0 : if (pNames[i].equalsAsciiL(
2439 0 : SW_PROP_NAME(UNO_NAME_IS_SKIP_HIDDEN_TEXT)) ||
2440 : pNames[i].equalsAsciiL(
2441 0 : SW_PROP_NAME(UNO_NAME_IS_SKIP_PROTECTED_TEXT)))
2442 : {
2443 0 : continue;
2444 : }
2445 : throw beans::UnknownPropertyException(
2446 : OUString(RTL_CONSTASCII_USTRINGPARAM("Unknown property: "))
2447 0 : + pNames[i],
2448 0 : static_cast<cppu::OWeakObject *>(0));
2449 : }
2450 0 : if (pEntry->nWID < RES_FRMATR_END)
2451 : {
2452 : const SfxPoolItem& rDefItem =
2453 0 : rDoc.GetAttrPool().GetDefaultItem(pEntry->nWID);
2454 0 : rDefItem.QueryValue(pAny[i], pEntry->nMemberId);
2455 : }
2456 : }
2457 : }
2458 0 : return aRet;
2459 : }
2460 :
2461 : void SAL_CALL
2462 0 : SwXTextCursor::makeRedline(
2463 : const ::rtl::OUString& rRedlineType,
2464 : const uno::Sequence< beans::PropertyValue >& rRedlineProperties)
2465 : throw (lang::IllegalArgumentException, uno::RuntimeException)
2466 : {
2467 0 : SolarMutexGuard aGuard;
2468 :
2469 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2470 :
2471 0 : SwUnoCursorHelper::makeRedline(rUnoCursor, rRedlineType, rRedlineProperties);
2472 0 : }
2473 :
2474 0 : void SAL_CALL SwXTextCursor::insertDocumentFromURL(const OUString& rURL,
2475 : const uno::Sequence< beans::PropertyValue >& rOptions)
2476 : throw (lang::IllegalArgumentException, io::IOException,
2477 : uno::RuntimeException)
2478 : {
2479 0 : SolarMutexGuard aGuard;
2480 :
2481 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2482 :
2483 0 : SwUnoCursorHelper::InsertFile(&rUnoCursor, rURL, rOptions);
2484 0 : }
2485 :
2486 : uno::Sequence< beans::PropertyValue >
2487 0 : SwUnoCursorHelper::CreateSortDescriptor(const bool bFromTable)
2488 : {
2489 0 : uno::Sequence< beans::PropertyValue > aRet(5);
2490 0 : beans::PropertyValue* pArray = aRet.getArray();
2491 :
2492 0 : uno::Any aVal;
2493 0 : aVal.setValue( &bFromTable, ::getCppuBooleanType());
2494 : pArray[0] = beans::PropertyValue(C2U("IsSortInTable"), -1, aVal,
2495 0 : beans::PropertyState_DIRECT_VALUE);
2496 :
2497 0 : aVal <<= sal_Unicode(' ');
2498 : pArray[1] = beans::PropertyValue(C2U("Delimiter"), -1, aVal,
2499 0 : beans::PropertyState_DIRECT_VALUE);
2500 :
2501 0 : aVal <<= (sal_Bool) sal_False;
2502 : pArray[2] = beans::PropertyValue(C2U("IsSortColumns"), -1, aVal,
2503 0 : beans::PropertyState_DIRECT_VALUE);
2504 :
2505 0 : aVal <<= (sal_Int32) 3;
2506 : pArray[3] = beans::PropertyValue(C2U("MaxSortFieldsCount"), -1, aVal,
2507 0 : beans::PropertyState_DIRECT_VALUE);
2508 :
2509 0 : uno::Sequence< table::TableSortField > aFields(3);
2510 0 : table::TableSortField* pFields = aFields.getArray();
2511 :
2512 0 : lang::Locale aLang( SvtSysLocale().GetLanguageTag().getLocale());
2513 : // get collator algorithm to be used for the locale
2514 : uno::Sequence< OUString > aSeq(
2515 0 : GetAppCollator().listCollatorAlgorithms( aLang ) );
2516 0 : const sal_Int32 nLen = aSeq.getLength();
2517 : OSL_ENSURE( nLen > 0, "list of collator algorithms is empty!");
2518 0 : OUString aCollAlg;
2519 0 : if (nLen > 0)
2520 : {
2521 0 : aCollAlg = aSeq.getConstArray()[0];
2522 : }
2523 :
2524 : #if OSL_DEBUG_LEVEL > 1
2525 : const OUString *pTxt = aSeq.getConstArray();
2526 : (void)pTxt;
2527 : #endif
2528 :
2529 0 : pFields[0].Field = 1;
2530 0 : pFields[0].IsAscending = sal_True;
2531 0 : pFields[0].IsCaseSensitive = sal_False;
2532 0 : pFields[0].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2533 0 : pFields[0].CollatorLocale = aLang;
2534 0 : pFields[0].CollatorAlgorithm = aCollAlg;
2535 :
2536 0 : pFields[1].Field = 1;
2537 0 : pFields[1].IsAscending = sal_True;
2538 0 : pFields[1].IsCaseSensitive = sal_False;
2539 0 : pFields[1].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2540 0 : pFields[1].CollatorLocale = aLang;
2541 0 : pFields[1].CollatorAlgorithm = aCollAlg;
2542 :
2543 0 : pFields[2].Field = 1;
2544 0 : pFields[2].IsAscending = sal_True;
2545 0 : pFields[2].IsCaseSensitive = sal_False;
2546 0 : pFields[2].FieldType = table::TableSortFieldType_ALPHANUMERIC;
2547 0 : pFields[2].CollatorLocale = aLang;
2548 0 : pFields[2].CollatorAlgorithm = aCollAlg;
2549 :
2550 0 : aVal <<= aFields;
2551 : pArray[4] = beans::PropertyValue(C2U("SortFields"), -1, aVal,
2552 0 : beans::PropertyState_DIRECT_VALUE);
2553 :
2554 0 : return aRet;
2555 : }
2556 :
2557 : uno::Sequence< beans::PropertyValue > SAL_CALL
2558 0 : SwXTextCursor::createSortDescriptor() throw (uno::RuntimeException)
2559 : {
2560 0 : SolarMutexGuard aGuard;
2561 :
2562 0 : return SwUnoCursorHelper::CreateSortDescriptor(false);
2563 : }
2564 :
2565 0 : sal_Bool SwUnoCursorHelper::ConvertSortProperties(
2566 : const uno::Sequence< beans::PropertyValue >& rDescriptor,
2567 : SwSortOptions& rSortOpt)
2568 : {
2569 0 : sal_Bool bRet = sal_True;
2570 0 : const beans::PropertyValue* pProperties = rDescriptor.getConstArray();
2571 :
2572 0 : rSortOpt.bTable = false;
2573 0 : rSortOpt.cDeli = ' ';
2574 0 : rSortOpt.eDirection = SRT_COLUMNS; //!! UI text may be contrary though !!
2575 :
2576 0 : SwSortKey* pKey1 = new SwSortKey;
2577 0 : pKey1->nColumnId = USHRT_MAX;
2578 0 : pKey1->bIsNumeric = true;
2579 0 : pKey1->eSortOrder = SRT_ASCENDING;
2580 :
2581 0 : SwSortKey* pKey2 = new SwSortKey;
2582 0 : pKey2->nColumnId = USHRT_MAX;
2583 0 : pKey2->bIsNumeric = true;
2584 0 : pKey2->eSortOrder = SRT_ASCENDING;
2585 :
2586 0 : SwSortKey* pKey3 = new SwSortKey;
2587 0 : pKey3->nColumnId = USHRT_MAX;
2588 0 : pKey3->bIsNumeric = true;
2589 0 : pKey3->eSortOrder = SRT_ASCENDING;
2590 0 : SwSortKey* aKeys[3] = {pKey1, pKey2, pKey3};
2591 :
2592 0 : sal_Bool bOldSortdescriptor(sal_False);
2593 0 : sal_Bool bNewSortdescriptor(sal_False);
2594 :
2595 0 : for (sal_Int32 n = 0; n < rDescriptor.getLength(); ++n)
2596 : {
2597 0 : uno::Any aValue( pProperties[n].Value );
2598 : // String sPropName = pProperties[n].Name;
2599 0 : const OUString& rPropName = pProperties[n].Name;
2600 :
2601 : // old and new sortdescriptor
2602 0 : if ( rPropName == "IsSortInTable" )
2603 : {
2604 0 : if (aValue.getValueType() == ::getBooleanCppuType())
2605 : {
2606 0 : rSortOpt.bTable = *(sal_Bool*)aValue.getValue();
2607 : }
2608 : else
2609 : {
2610 0 : bRet = sal_False;
2611 : }
2612 : }
2613 0 : else if ( rPropName == "Delimiter" )
2614 : {
2615 0 : sal_Unicode uChar = sal_Unicode();
2616 0 : if (aValue >>= uChar)
2617 : {
2618 0 : rSortOpt.cDeli = uChar;
2619 : }
2620 : else
2621 : {
2622 0 : bRet = sal_False;
2623 : }
2624 : }
2625 : // old sortdescriptor
2626 0 : else if ( rPropName == "SortColumns" )
2627 : {
2628 0 : bOldSortdescriptor = sal_True;
2629 0 : sal_Bool bTemp(sal_False);
2630 0 : if (aValue >>= bTemp)
2631 : {
2632 0 : rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS;
2633 : }
2634 : else
2635 : {
2636 0 : bRet = sal_False;
2637 : }
2638 : }
2639 0 : else if ( rPropName == "IsCaseSensitive" )
2640 : {
2641 0 : bOldSortdescriptor = sal_True;
2642 0 : sal_Bool bTemp(sal_False);
2643 0 : if (aValue >>= bTemp)
2644 : {
2645 0 : rSortOpt.bIgnoreCase = !bTemp;
2646 : }
2647 : else
2648 : {
2649 0 : bRet = sal_False;
2650 : }
2651 : }
2652 0 : else if ( rPropName == "CollatorLocale" )
2653 : {
2654 0 : bOldSortdescriptor = sal_True;
2655 0 : lang::Locale aLocale;
2656 0 : if (aValue >>= aLocale)
2657 : {
2658 0 : rSortOpt.nLanguage = LanguageTag( aLocale).getLanguageType();
2659 : }
2660 : else
2661 : {
2662 0 : bRet = sal_False;
2663 0 : }
2664 : }
2665 0 : else if (rPropName.matchAsciiL("CollatorAlgorithm", 17) &&
2666 0 : rPropName.getLength() == 18 &&
2667 0 : (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9'))
2668 : {
2669 0 : bOldSortdescriptor = sal_True;
2670 0 : sal_uInt16 nIndex = rPropName.getStr()[17];
2671 0 : nIndex -= '0';
2672 0 : OUString aTxt;
2673 0 : if ((aValue >>= aTxt) && nIndex < 3)
2674 : {
2675 0 : aKeys[nIndex]->sSortType = aTxt;
2676 : }
2677 : else
2678 : {
2679 0 : bRet = sal_False;
2680 0 : }
2681 : }
2682 0 : else if (rPropName.matchAsciiL("SortRowOrColumnNo", 17) &&
2683 0 : rPropName.getLength() == 18 &&
2684 0 : (rPropName.getStr()[17] >= '0' && rPropName.getStr()[17] <= '9'))
2685 : {
2686 0 : bOldSortdescriptor = sal_True;
2687 0 : sal_uInt16 nIndex = rPropName.getStr()[17];
2688 0 : nIndex -= '0';
2689 0 : sal_Int16 nCol = -1;
2690 0 : if (aValue.getValueType() == ::getCppuType((const sal_Int16*)0)
2691 : && nIndex < 3)
2692 : {
2693 0 : aValue >>= nCol;
2694 : }
2695 0 : if (nCol >= 0)
2696 : {
2697 0 : aKeys[nIndex]->nColumnId = nCol;
2698 : }
2699 : else
2700 : {
2701 0 : bRet = sal_False;
2702 : }
2703 : }
2704 0 : else if (0 == rPropName.indexOf(C2U("IsSortNumeric")) &&
2705 0 : rPropName.getLength() == 14 &&
2706 0 : (rPropName.getStr()[13] >= '0' && rPropName.getStr()[13] <= '9'))
2707 : {
2708 0 : bOldSortdescriptor = sal_True;
2709 0 : sal_uInt16 nIndex = rPropName.getStr()[13];
2710 0 : nIndex = nIndex - '0';
2711 0 : if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3)
2712 : {
2713 0 : sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2714 0 : aKeys[nIndex]->bIsNumeric = bTemp;
2715 : }
2716 : else
2717 : {
2718 0 : bRet = sal_False;
2719 : }
2720 : }
2721 0 : else if (0 == rPropName.indexOf(C2U("IsSortAscending")) &&
2722 0 : rPropName.getLength() == 16 &&
2723 0 : (rPropName.getStr()[15] >= '0' && rPropName.getStr()[15] <= '9'))
2724 : {
2725 0 : bOldSortdescriptor = sal_True;
2726 0 : sal_uInt16 nIndex = rPropName.getStr()[15];
2727 0 : nIndex -= '0';
2728 0 : if (aValue.getValueType() == ::getBooleanCppuType() && nIndex < 3)
2729 : {
2730 0 : sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2731 0 : aKeys[nIndex]->eSortOrder = (bTemp)
2732 0 : ? SRT_ASCENDING : SRT_DESCENDING;
2733 : }
2734 : else
2735 : {
2736 0 : bRet = sal_False;
2737 : }
2738 : }
2739 : // new sortdescriptor
2740 0 : else if ( rPropName == "IsSortColumns" )
2741 : {
2742 0 : bNewSortdescriptor = sal_True;
2743 0 : if (aValue.getValueType() == ::getBooleanCppuType())
2744 : {
2745 0 : sal_Bool bTemp = *(sal_Bool*)aValue.getValue();
2746 0 : rSortOpt.eDirection = bTemp ? SRT_COLUMNS : SRT_ROWS;
2747 : }
2748 : else
2749 : {
2750 0 : bRet = sal_False;
2751 : }
2752 : }
2753 0 : else if ( rPropName == "SortFields" )
2754 : {
2755 0 : bNewSortdescriptor = sal_True;
2756 0 : uno::Sequence < table::TableSortField > aFields;
2757 0 : if (aValue >>= aFields)
2758 : {
2759 0 : sal_Int32 nCount(aFields.getLength());
2760 0 : if (nCount <= 3)
2761 : {
2762 0 : table::TableSortField* pFields = aFields.getArray();
2763 0 : for (sal_Int32 i = 0; i < nCount; ++i)
2764 : {
2765 0 : rSortOpt.bIgnoreCase = !pFields[i].IsCaseSensitive;
2766 : rSortOpt.nLanguage =
2767 0 : LanguageTag( pFields[i].CollatorLocale ).getLanguageType();
2768 0 : aKeys[i]->sSortType = pFields[i].CollatorAlgorithm;
2769 0 : aKeys[i]->nColumnId =
2770 0 : static_cast<sal_uInt16>(pFields[i].Field);
2771 0 : aKeys[i]->bIsNumeric = (pFields[i].FieldType ==
2772 0 : table::TableSortFieldType_NUMERIC);
2773 0 : aKeys[i]->eSortOrder = (pFields[i].IsAscending)
2774 0 : ? SRT_ASCENDING : SRT_DESCENDING;
2775 : }
2776 : }
2777 : else
2778 : {
2779 0 : bRet = sal_False;
2780 : }
2781 : }
2782 : else
2783 : {
2784 0 : bRet = sal_False;
2785 0 : }
2786 : }
2787 0 : }
2788 :
2789 0 : if (bNewSortdescriptor && bOldSortdescriptor)
2790 : {
2791 : OSL_FAIL("someone tried to set the old deprecated and "
2792 : "the new sortdescriptor");
2793 0 : bRet = sal_False;
2794 : }
2795 :
2796 0 : if (pKey1->nColumnId != USHRT_MAX)
2797 : {
2798 0 : rSortOpt.aKeys.push_back(pKey1);
2799 : }
2800 0 : if (pKey2->nColumnId != USHRT_MAX)
2801 : {
2802 0 : rSortOpt.aKeys.push_back(pKey2);
2803 : }
2804 0 : if (pKey3->nColumnId != USHRT_MAX)
2805 : {
2806 0 : rSortOpt.aKeys.push_back(pKey3);
2807 : }
2808 :
2809 0 : return bRet && !rSortOpt.aKeys.empty();
2810 : }
2811 :
2812 : void SAL_CALL
2813 0 : SwXTextCursor::sort(const uno::Sequence< beans::PropertyValue >& rDescriptor)
2814 : throw (uno::RuntimeException)
2815 : {
2816 0 : SolarMutexGuard aGuard;
2817 :
2818 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2819 :
2820 0 : if (rUnoCursor.HasMark())
2821 : {
2822 0 : SwSortOptions aSortOpt;
2823 0 : if (!SwUnoCursorHelper::ConvertSortProperties(rDescriptor, aSortOpt))
2824 : {
2825 0 : throw uno::RuntimeException();
2826 : }
2827 0 : UnoActionContext aContext( rUnoCursor.GetDoc() );
2828 :
2829 0 : SwPosition & rStart = *rUnoCursor.Start();
2830 0 : SwPosition & rEnd = *rUnoCursor.End();
2831 :
2832 0 : SwNodeIndex aPrevIdx( rStart.nNode, -1 );
2833 0 : const sal_uLong nOffset = rEnd.nNode.GetIndex() - rStart.nNode.GetIndex();
2834 0 : const xub_StrLen nCntStt = rStart.nContent.GetIndex();
2835 :
2836 0 : rUnoCursor.GetDoc()->SortText(rUnoCursor, aSortOpt);
2837 :
2838 : // Selektion wieder setzen
2839 0 : rUnoCursor.DeleteMark();
2840 0 : rUnoCursor.GetPoint()->nNode.Assign( aPrevIdx.GetNode(), +1 );
2841 0 : SwCntntNode *const pCNd = rUnoCursor.GetCntntNode();
2842 0 : xub_StrLen nLen = pCNd->Len();
2843 0 : if (nLen > nCntStt)
2844 : {
2845 0 : nLen = nCntStt;
2846 : }
2847 0 : rUnoCursor.GetPoint()->nContent.Assign(pCNd, nLen );
2848 0 : rUnoCursor.SetMark();
2849 :
2850 0 : rUnoCursor.GetPoint()->nNode += nOffset;
2851 0 : SwCntntNode *const pCNd2 = rUnoCursor.GetCntntNode();
2852 0 : rUnoCursor.GetPoint()->nContent.Assign( pCNd2, pCNd2->Len() );
2853 0 : }
2854 0 : }
2855 :
2856 : uno::Reference< container::XEnumeration > SAL_CALL
2857 0 : SwXTextCursor::createContentEnumeration(const OUString& rServiceName)
2858 : throw (uno::RuntimeException)
2859 : {
2860 0 : SolarMutexGuard g;
2861 :
2862 0 : if (!rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextContent")))
2863 : {
2864 0 : throw uno::RuntimeException();
2865 : }
2866 :
2867 0 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2868 :
2869 : uno::Reference< container::XEnumeration > xRet =
2870 0 : new SwXParaFrameEnumeration(rUnoCursor, PARAFRAME_PORTION_TEXTRANGE);
2871 0 : return xRet;
2872 : }
2873 :
2874 : uno::Reference< container::XEnumeration > SAL_CALL
2875 150 : SwXTextCursor::createEnumeration() throw (uno::RuntimeException)
2876 : {
2877 150 : SolarMutexGuard g;
2878 :
2879 150 : SwUnoCrsr & rUnoCursor( m_pImpl->GetCursorOrThrow() );
2880 :
2881 : const uno::Reference<lang::XUnoTunnel> xTunnel(
2882 150 : m_pImpl->m_xParentText, uno::UNO_QUERY);
2883 150 : SwXText* pParentText = 0;
2884 150 : if (xTunnel.is())
2885 : {
2886 150 : pParentText = ::sw::UnoTunnelGetImplementation<SwXText>(xTunnel);
2887 : }
2888 : OSL_ENSURE(pParentText, "parent is not a SwXText");
2889 150 : if (!pParentText)
2890 : {
2891 0 : throw uno::RuntimeException();
2892 : }
2893 :
2894 : SAL_WNODEPRECATED_DECLARATIONS_PUSH
2895 : ::std::auto_ptr<SwUnoCrsr> pNewCrsr(
2896 150 : rUnoCursor.GetDoc()->CreateUnoCrsr(*rUnoCursor.GetPoint()) );
2897 : SAL_WNODEPRECATED_DECLARATIONS_POP
2898 150 : if (rUnoCursor.HasMark())
2899 : {
2900 0 : pNewCrsr->SetMark();
2901 0 : *pNewCrsr->GetMark() = *rUnoCursor.GetMark();
2902 : }
2903 150 : const CursorType eSetType = (CURSOR_TBLTEXT == m_pImpl->m_eType)
2904 150 : ? CURSOR_SELECTION_IN_TABLE : CURSOR_SELECTION;
2905 150 : SwTableNode const*const pStartNode( (CURSOR_TBLTEXT == m_pImpl->m_eType)
2906 115 : ? rUnoCursor.GetPoint()->nNode.GetNode().FindTableNode()
2907 265 : : 0);
2908 : SwTable const*const pTable(
2909 150 : (pStartNode) ? & pStartNode->GetTable() : 0 );
2910 : const uno::Reference< container::XEnumeration > xRet =
2911 : new SwXParagraphEnumeration(
2912 150 : pParentText, pNewCrsr, eSetType, pStartNode, pTable);
2913 :
2914 150 : return xRet;
2915 : }
2916 :
2917 : uno::Type SAL_CALL
2918 0 : SwXTextCursor::getElementType() throw (uno::RuntimeException)
2919 : {
2920 0 : return text::XTextRange::static_type();
2921 : }
2922 :
2923 0 : sal_Bool SAL_CALL SwXTextCursor::hasElements() throw (uno::RuntimeException)
2924 : {
2925 0 : return sal_True;
2926 : }
2927 :
2928 : uno::Sequence< OUString > SAL_CALL
2929 0 : SwXTextCursor::getAvailableServiceNames() throw (uno::RuntimeException)
2930 : {
2931 0 : uno::Sequence< OUString > aRet(1);
2932 0 : OUString* pArray = aRet.getArray();
2933 0 : pArray[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextContent"));
2934 0 : return aRet;
2935 : }
2936 :
2937 21228 : IMPLEMENT_FORWARD_REFCOUNT( SwXTextCursor,SwXTextCursor_Base )
2938 :
2939 : uno::Any SAL_CALL
2940 4834 : SwXTextCursor::queryInterface(const uno::Type& rType)
2941 : throw (uno::RuntimeException)
2942 : {
2943 4834 : return (rType == lang::XUnoTunnel::static_type())
2944 : ? OTextCursorHelper::queryInterface(rType)
2945 4834 : : SwXTextCursor_Base::queryInterface(rType);
2946 : }
2947 :
2948 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|