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