Update ooo320-m1
[ooovba.git] / sw / source / core / unocore / unocrsrhelper.cxx
blob08c22ac8e601cfdf3c5b2a106f2c6278198df281
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocrsrhelper.cxx,v $
11 * $Revision: 1.35 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sw.hxx"
36 #include <cmdid.h>
37 #include <unocrsrhelper.hxx>
38 #include <unoobj.hxx>
39 #include <unostyle.hxx>
40 #include <unoidx.hxx>
41 #include <unofield.hxx>
42 #include <unotbl.hxx>
43 #include <unosett.hxx>
44 #include <unoframe.hxx>
45 #include <doc.hxx>
46 #include <IDocumentRedlineAccess.hxx>
47 #include <fmtftn.hxx>
48 #include <fmtpdsc.hxx>
49 #include <charfmt.hxx>
50 #include <pagedesc.hxx>
51 #include <docstyle.hxx>
52 #include <ndtxt.hxx>
53 #include <txtrfmrk.hxx>
54 #include <fmtfld.hxx>
55 #include <docsh.hxx>
56 #include <section.hxx>
57 #include <shellio.hxx>
58 #include <edimp.hxx>
59 #include <swundo.hxx>
60 #include <cntfrm.hxx>
61 #include <pagefrm.hxx>
62 #include <svtools/eitem.hxx>
63 #include <tools/urlobj.hxx>
64 #include <docary.hxx>
65 #include <swtable.hxx>
66 #include <tox.hxx>
67 #include <fchrfmt.hxx>
68 #include <svx/flstitem.hxx>
69 #include <vcl/metric.hxx>
70 #include <svtools/ctrltool.hxx>
71 #define _SVSTDARR_USHORTS
72 #define _SVSTDARR_USHORTSSORT
73 #include <svtools/svstdarr.hxx>
74 #include <sfx2/docfilt.hxx>
75 #include <sfx2/docfile.hxx>
76 #include <sfx2/fcontnr.hxx>
77 #include <svtools/stritem.hxx>
78 #include <com/sun/star/beans/PropertyState.hpp>
79 #include <SwStyleNameMapper.hxx>
80 #include <redline.hxx>
81 #include <numrule.hxx>
82 #include <comphelper/storagehelper.hxx>
83 #include <comphelper/mediadescriptor.hxx>
84 #include <comphelper/sequenceashashmap.hxx>
85 #include <com/sun/star/embed/ElementModes.hpp>
86 #include <com/sun/star/embed/XStorage.hpp>
87 // --> OD 2008-11-26 #158694#
88 #include <SwNodeNum.hxx>
89 // <--
91 using namespace ::com::sun::star;
92 using namespace ::com::sun::star::uno;
93 using namespace ::com::sun::star::beans;
94 using namespace ::com::sun::star::text;
95 using namespace ::com::sun::star::table;
96 using namespace ::com::sun::star::container;
97 using namespace ::com::sun::star::lang;
98 using ::rtl::OUString;
101 namespace SwUnoCursorHelper
103 /* -----------------16.09.98 12:27-------------------
104 * Lesen spezieller Properties am Cursor
105 * --------------------------------------------------*/
106 sal_Bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry
107 , SwPaM& rPam
108 , Any *pAny
109 , PropertyState& eState
110 , const SwTxtNode* pNode )
112 PropertyState eNewState = PropertyState_DIRECT_VALUE;
113 // PropertyState_DEFAULT_VALUE
114 // PropertyState_AMBIGUOUS_VALUE
115 sal_Bool bDone = sal_True;
116 switch(rEntry.nWID)
118 // --> OD 2008-11-26 #158694#
119 case FN_UNO_PARA_CONT_PREV_SUBTREE:
120 if (pAny)
122 const SwTxtNode * pTmpNode = pNode;
124 if (!pTmpNode)
125 pTmpNode = rPam.GetNode()->GetTxtNode();
127 bool bRet = false;
129 if ( pTmpNode &&
130 pTmpNode->GetNum() &&
131 pTmpNode->GetNum()->IsContinueingPreviousSubTree() )
133 bRet = true;
136 *pAny <<= bRet;
138 break;
139 case FN_UNO_PARA_NUM_STRING:
140 if (pAny)
142 const SwTxtNode * pTmpNode = pNode;
144 if (!pTmpNode)
145 pTmpNode = rPam.GetNode()->GetTxtNode();
147 String sRet;
148 if ( pTmpNode && pTmpNode->GetNum() )
150 sRet = pTmpNode->GetNumString();
153 *pAny <<= OUString(sRet);
155 break;
156 // <--
157 // --> OD 2008-05-20 #outlinelevel# - no longer needed
158 // case FN_UNO_PARA_CHAPTER_NUMBERING_LEVEL:
159 // if (pAny)
160 // {
161 // const SwTxtNode * pTmpNode = pNode;
163 // if (!pTmpNode)
164 // pTmpNode = rPam.GetNode()->GetTxtNode();
166 // sal_Int8 nRet = -1;
167 // if (pTmpNode && pTmpNode->GetOutlineLevel() != NO_NUMBERING)
168 // nRet = sal::static_int_cast< sal_Int8 >(pTmpNode->GetOutlineLevel());
169 // *pAny <<= nRet;
170 // }
171 // break;
172 // <--
173 case RES_PARATR_OUTLINELEVEL: //#outlinelevel added by zhaojianwei
174 if (pAny)
176 const SwTxtNode * pTmpNode = pNode;
178 if (!pTmpNode)
179 pTmpNode = rPam.GetNode()->GetTxtNode();
181 sal_Int16 nRet = -1;
182 if ( pTmpNode )
183 nRet = sal::static_int_cast< sal_Int16 >( pTmpNode->GetAttrOutlineLevel() );
185 *pAny <<= nRet;
187 break; //<-end,zhaojianwei
188 case FN_UNO_PARA_CONDITIONAL_STYLE_NAME:
189 case FN_UNO_PARA_STYLE :
191 SwFmtColl* pFmt = 0;
192 if(pNode)
193 pFmt = FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID
194 ? pNode->GetFmtColl() : &pNode->GetAnyFmtColl();
195 else
196 pFmt = SwXTextCursor::GetCurTxtFmtColl(rPam, FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID);
197 if(pFmt)
199 if( pAny )
201 String sVal;
202 SwStyleNameMapper::FillProgName(pFmt->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
203 *pAny <<= OUString(sVal);
206 else
207 eNewState = PropertyState_AMBIGUOUS_VALUE;
209 break;
210 case FN_UNO_PAGE_STYLE :
212 String sVal;
213 GetCurPageStyle(rPam, sVal);
214 if( pAny )
215 *pAny <<= OUString(sVal);
216 if(!sVal.Len())
217 eNewState = PropertyState_AMBIGUOUS_VALUE;
219 break;
220 case FN_UNO_NUM_START_VALUE :
221 if( pAny )
223 sal_Int16 nValue = IsNodeNumStart(rPam, eNewState);
224 *pAny <<= nValue;
226 break;
227 case FN_UNO_NUM_LEVEL :
228 case FN_UNO_IS_NUMBER :
229 // --> OD 2008-07-14 #i91601#
230 case FN_UNO_LIST_ID:
231 // <--
232 case FN_NUMBER_NEWSTART:
234 const SwTxtNode* pTxtNd = rPam.GetNode()->GetTxtNode();
235 // --> OD 2006-10-19 #134160# - make code robust:
236 // consider case that PaM doesn't denote a text node
237 const SwNumRule* pRule = pTxtNd ? pTxtNd->GetNumRule() : 0;
238 // <--
239 // hier wird Multiselektion nicht beruecksichtigt
240 if( pRule )
242 if( pAny )
244 if(rEntry.nWID == FN_UNO_NUM_LEVEL)
245 *pAny <<= (sal_Int16)(pTxtNd->GetActualListLevel());
246 else if(rEntry.nWID == FN_UNO_IS_NUMBER)
248 BOOL bIsNumber = pTxtNd->IsCountedInList();
249 pAny->setValue(&bIsNumber, ::getBooleanCppuType());
251 // --> OD 2008-07-14 #i91601#
252 else if ( rEntry.nWID == FN_UNO_LIST_ID )
254 const String sListId = pTxtNd->GetListId();
255 *pAny <<= OUString(sListId);
257 // <--
258 else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
260 BOOL bIsRestart = pTxtNd->IsListRestart();
261 pAny->setValue(&bIsRestart, ::getBooleanCppuType());
265 else
267 eNewState = PropertyState_DEFAULT_VALUE;
269 if( pAny )
271 // #i30838# set default values for default properties
272 if(rEntry.nWID == FN_UNO_NUM_LEVEL)
273 *pAny <<= static_cast<sal_Int16>( 0 );
274 else if(rEntry.nWID == FN_UNO_IS_NUMBER)
275 *pAny <<= false;
276 // --> OD 2008-07-14 #i91601#
277 else if ( rEntry.nWID == FN_UNO_LIST_ID )
279 *pAny <<= OUString();
281 // <--
282 else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
283 *pAny <<= false;
286 //PROPERTY_MAYBEVOID!
288 break;
289 case FN_UNO_NUM_RULES :
290 if( pAny )
291 getNumberingProperty(rPam, eNewState, pAny);
292 else
294 if( !rPam.GetDoc()->GetCurrNumRule( *rPam.GetPoint() ) )
295 eNewState = PropertyState_DEFAULT_VALUE;
297 break;
298 case FN_UNO_DOCUMENT_INDEX_MARK:
300 SwTxtAttr* pTxtAttr = rPam.GetNode()->GetTxtNode()->GetTxtAttr(
301 rPam.GetPoint()->nContent, RES_TXTATR_TOXMARK);
302 if(pTxtAttr)
304 if( pAny )
306 const SwTOXMark& rMark = pTxtAttr->GetTOXMark();
307 uno::Reference< XDocumentIndexMark > xRef = SwXDocumentIndexMark::GetObject(
308 (SwTOXType*)rMark.GetTOXType(), &rMark, rPam.GetDoc());
309 pAny->setValue(&xRef, ::getCppuType((uno::Reference<XDocumentIndex>*)0));
312 else
313 //auch hier - nicht zu unterscheiden
314 eNewState = PropertyState_DEFAULT_VALUE;
316 break;
317 case FN_UNO_DOCUMENT_INDEX:
319 const SwTOXBase* pBase = rPam.GetDoc()->GetCurTOX(
320 *rPam.Start() );
321 if( pBase )
323 if( pAny )
325 uno::Reference< XDocumentIndex > aRef =
326 SwXDocumentIndexes::GetObject((SwTOXBaseSection*)pBase);
327 pAny->setValue(&aRef, ::getCppuType((uno::Reference<XDocumentIndex>*)0));
330 else
331 eNewState = PropertyState_DEFAULT_VALUE;
333 break;
334 case FN_UNO_TEXT_FIELD:
336 const SwPosition *pPos = rPam.Start();
337 const SwTxtNode *pTxtNd =
338 rPam.GetDoc()->GetNodes()[pPos->nNode.GetIndex()]->GetTxtNode();
339 SwTxtAttr* pTxtAttr =
340 pTxtNd ? pTxtNd->GetTxtAttr(pPos->nContent, RES_TXTATR_FIELD)
341 : 0;
342 if(pTxtAttr)
344 if( pAny )
346 SwXTextField* pField = CreateSwXTextField(*rPam.GetDoc(),
347 pTxtAttr->GetFld());
348 *pAny <<= uno::Reference< XTextField >( pField );
351 else
352 eNewState = PropertyState_DEFAULT_VALUE;
354 break;
355 /* laesst sich nicht feststellen
356 * case FN_UNO_BOOKMARK:
358 if()
360 uno::Reference< XBookmark > xBkm = SwXBookmarks::GetObject(rBkm);
361 rAny.set(&xBkm, ::getCppuType((const XBookmark*)0)());
364 break;*/
365 case FN_UNO_TEXT_TABLE:
366 case FN_UNO_CELL:
368 SwStartNode* pSttNode = rPam.GetNode()->StartOfSectionNode();
369 SwStartNodeType eType = pSttNode->GetStartNodeType();
370 if(SwTableBoxStartNode == eType)
372 if( pAny )
374 const SwTableNode* pTblNode = pSttNode->FindTableNode();
375 SwFrmFmt* pTableFmt = (SwFrmFmt*)pTblNode->GetTable().GetFrmFmt();
376 //SwTable& rTable = ((SwTableNode*)pSttNode)->GetTable();
377 if(FN_UNO_TEXT_TABLE == rEntry.nWID)
379 uno::Reference< XTextTable > xTable = SwXTextTables::GetObject(*pTableFmt);
380 pAny->setValue(&xTable, ::getCppuType((uno::Reference<XTextTable>*)0));
382 else
384 SwTableBox* pBox = pSttNode->GetTblBox();
385 uno::Reference< XCell > xCell = SwXCell::CreateXCell(pTableFmt, pBox);
386 pAny->setValue(&xCell, ::getCppuType((uno::Reference<XCell>*)0));
390 else
391 eNewState = PropertyState_DEFAULT_VALUE;
393 break;
394 case FN_UNO_TEXT_FRAME:
396 SwStartNode* pSttNode = rPam.GetNode()->StartOfSectionNode();
397 SwStartNodeType eType = pSttNode->GetStartNodeType();
399 SwFrmFmt* pFmt;
400 if(eType == SwFlyStartNode && 0 != (pFmt = pSttNode->GetFlyFmt()))
402 if( pAny )
404 uno::Reference< XTextFrame > xFrm = (SwXTextFrame*) SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM);
405 pAny->setValue(&xFrm, ::getCppuType((uno::Reference<XTextFrame>*)0));
408 else
409 eNewState = PropertyState_DEFAULT_VALUE;
411 break;
412 case FN_UNO_TEXT_SECTION:
414 SwSection* pSect = rPam.GetDoc()->GetCurrSection(*rPam.GetPoint());
415 if(pSect)
417 if( pAny )
419 uno::Reference< XTextSection > xSect = SwXTextSections::GetObject( *pSect->GetFmt() );
420 pAny->setValue(&xSect, ::getCppuType((uno::Reference<XTextSection>*)0) );
423 else
424 eNewState = PropertyState_DEFAULT_VALUE;
426 break;
427 case FN_UNO_ENDNOTE:
428 case FN_UNO_FOOTNOTE:
430 SwTxtAttr* pTxtAttr = rPam.GetNode()->GetTxtNode()->
431 GetTxtAttr(rPam.GetPoint()->nContent, RES_TXTATR_FTN);
432 if(pTxtAttr)
434 const SwFmtFtn& rFtn = pTxtAttr->GetFtn();
435 if(rFtn.IsEndNote() == (FN_UNO_ENDNOTE == rEntry.nWID))
437 if( pAny )
439 uno::Reference< XFootnote > xFoot = new SwXFootnote(rPam.GetDoc(), rFtn);
440 pAny->setValue(&xFoot, ::getCppuType((uno::Reference<XFootnote>*)0));
443 else
444 eNewState = PropertyState_DEFAULT_VALUE;
446 else
447 eNewState = PropertyState_DEFAULT_VALUE;
449 break;
450 case FN_UNO_REFERENCE_MARK:
452 SwTxtAttr* pTxtAttr = rPam.GetNode()->GetTxtNode()->
453 GetTxtAttr(rPam.GetPoint()->nContent, RES_TXTATR_REFMARK);
454 if(pTxtAttr)
456 if( pAny )
458 const SwFmtRefMark& rRef = pTxtAttr->GetRefMark();
459 uno::Reference< XTextContent > xRef = SwXReferenceMarks::GetObject( rPam.GetDoc(), &rRef );
460 pAny->setValue(&xRef, ::getCppuType((uno::Reference<XTextContent>*)0));
463 else
464 eNewState = PropertyState_DEFAULT_VALUE;
466 break;
467 case FN_UNO_CHARFMT_SEQUENCE:
470 SwTxtNode* pTxtNode;
471 if((pTxtNode = (SwTxtNode*)rPam.GetNode( TRUE )) == rPam.GetNode(FALSE) &&
472 pTxtNode->GetpSwpHints())
474 USHORT nPaMStart = rPam.GetPoint()->nContent.GetIndex();
475 USHORT nPaMEnd = rPam.GetMark() ? rPam.GetMark()->nContent.GetIndex() : nPaMStart;
476 if(nPaMStart > nPaMEnd)
478 USHORT nTmp = nPaMStart;
479 nPaMStart = nPaMEnd;
480 nPaMEnd = nTmp;
482 Sequence< ::rtl::OUString> aCharStyles;
483 SwpHints* pHints = pTxtNode->GetpSwpHints();
484 for(USHORT nAttr = 0; nAttr < pHints->GetStartCount(); nAttr++ )
486 SwTxtAttr* pAttr = pHints->GetStart( nAttr );
487 if(pAttr->Which() != RES_TXTATR_CHARFMT)
488 continue;
489 USHORT nAttrStart = *pAttr->GetStart();
490 USHORT nAttrEnd = *pAttr->GetEnd();
491 //check if the attribute touches the selection
492 if( ( nAttrEnd > nPaMStart && nAttrStart < nPaMEnd ) ||
493 ( !nAttrStart && !nAttrEnd && !nPaMStart && !nPaMEnd ) )
495 //check for overlapping
496 if(nAttrStart > nPaMStart ||
497 nAttrEnd < nPaMEnd)
499 aCharStyles.realloc(0);
500 eNewState = PropertyState_AMBIGUOUS_VALUE;
501 break;
503 else
505 //now the attribute should start before or at the selection
506 //and it should end at the end of the selection or behind
507 DBG_ASSERT(nAttrStart <= nPaMStart && nAttrEnd >=nPaMEnd,
508 "attribute overlaps or is outside");
509 //now the name of the style has to be added to the sequence
510 aCharStyles.realloc(aCharStyles.getLength() + 1);
511 DBG_ASSERT(pAttr->GetCharFmt().GetCharFmt(), "no character format set");
512 aCharStyles.getArray()[aCharStyles.getLength() - 1] =
513 SwStyleNameMapper::GetProgName(
514 pAttr->GetCharFmt().GetCharFmt()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
519 eNewState =
520 aCharStyles.getLength() ?
521 PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;;
522 if(pAny)
523 (*pAny) <<= aCharStyles;
525 else
526 eNewState = PropertyState_DEFAULT_VALUE;
528 break;
529 case RES_TXTATR_CHARFMT:
530 // kein break hier!
531 default: bDone = sal_False;
533 if( bDone )
534 eState = eNewState;
535 return bDone;
537 /* -----------------30.06.98 10:30-------------------
539 * --------------------------------------------------*/
540 sal_Int16 IsNodeNumStart(SwPaM& rPam, PropertyState& eState)
542 const SwTxtNode* pTxtNd = rPam.GetNode()->GetTxtNode();
543 // --> OD 2008-02-28 #refactorlists#
544 // correction: check, if restart value is set at the text node and use
545 // new method <SwTxtNode::GetAttrListRestartValue()> to retrieve the value
546 if ( pTxtNd && pTxtNd->GetNumRule() && pTxtNd->IsListRestart() &&
547 pTxtNd->HasAttrListRestartValue() )
549 eState = PropertyState_DIRECT_VALUE;
550 sal_Int16 nTmp = sal::static_int_cast< sal_Int16 >(pTxtNd->GetAttrListRestartValue());
551 return nTmp;
553 // <--
554 eState = PropertyState_DEFAULT_VALUE;
555 return -1;
558 /* -----------------25.05.98 11:41-------------------
560 * --------------------------------------------------*/
561 void setNumberingProperty(const Any& rValue, SwPaM& rPam)
563 uno::Reference<XIndexReplace> xIndexReplace;
564 if(rValue >>= xIndexReplace)
566 SwXNumberingRules* pSwNum = 0;
568 uno::Reference<XUnoTunnel> xNumTunnel(xIndexReplace, UNO_QUERY);
569 if(xNumTunnel.is())
571 pSwNum = reinterpret_cast< SwXNumberingRules * >(
572 sal::static_int_cast< sal_IntPtr >( xNumTunnel->getSomething( SwXNumberingRules::getUnoTunnelId() )));
575 if(pSwNum)
577 SwDoc* pDoc = rPam.GetDoc();
578 if(pSwNum->GetNumRule())
580 SwNumRule aRule(*pSwNum->GetNumRule());
581 const String* pNewCharStyles = pSwNum->GetNewCharStyleNames();
582 const String* pBulletFontNames = pSwNum->GetBulletFontNames();
583 for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
585 SwNumFmt aFmt(aRule.Get( i ));
586 if( pNewCharStyles[i].Len() &&
587 pNewCharStyles[i] != SwXNumberingRules::GetInvalidStyle() &&
588 (!aFmt.GetCharFmt() || pNewCharStyles[i] != aFmt.GetCharFmt()->GetName()))
590 if(!pNewCharStyles[i].Len())
591 aFmt.SetCharFmt(0);
592 else
595 // CharStyle besorgen und an der Rule setzen
596 sal_uInt16 nChCount = pDoc->GetCharFmts()->Count();
597 SwCharFmt* pCharFmt = 0;
598 for(sal_uInt16 nCharFmt = 0; nCharFmt < nChCount; nCharFmt++)
600 SwCharFmt& rChFmt = *((*(pDoc->GetCharFmts()))[nCharFmt]);;
601 if(rChFmt.GetName() == pNewCharStyles[i])
603 pCharFmt = &rChFmt;
604 break;
608 if(!pCharFmt)
610 SfxStyleSheetBasePool* pPool = pDoc->GetDocShell()->GetStyleSheetPool();
611 SfxStyleSheetBase* pBase;
612 pBase = pPool->Find(pNewCharStyles[i], SFX_STYLE_FAMILY_CHAR);
613 // soll das wirklich erzeugt werden?
614 if(!pBase)
615 pBase = &pPool->Make(pNewCharStyles[i], SFX_STYLE_FAMILY_PAGE);
616 pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
618 if(pCharFmt)
619 aFmt.SetCharFmt(pCharFmt);
622 //jetzt nochmal fuer Fonts
624 pBulletFontNames[i] != SwXNumberingRules::GetInvalidStyle() &&
626 (pBulletFontNames[i].Len() && !aFmt.GetBulletFont()) ||
627 (pBulletFontNames[i].Len() &&
628 aFmt.GetBulletFont()->GetName() != pBulletFontNames[i])
632 const SvxFontListItem* pFontListItem =
633 (const SvxFontListItem* )pDoc->GetDocShell()
634 ->GetItem( SID_ATTR_CHAR_FONTLIST );
635 const FontList* pList = pFontListItem->GetFontList();
637 FontInfo aInfo = pList->Get(
638 pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE);
639 Font aFont(aInfo);
640 aFmt.SetBulletFont(&aFont);
642 aRule.Set( i, aFmt );
644 UnoActionContext aAction(pDoc);
646 if( rPam.GetNext() != &rPam ) // Mehrfachselektion ?
648 pDoc->StartUndo( UNDO_START, NULL );
649 SwPamRanges aRangeArr( rPam );
650 SwPaM aPam( *rPam.GetPoint() );
651 for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
653 // --> OD 2008-03-17 #refactorlists#
654 // no start of a new list
655 pDoc->SetNumRule( aRangeArr.SetPam( n, aPam ), aRule, false );
656 // <--
658 pDoc->EndUndo( UNDO_END, NULL );
660 else
662 // --> OD 2008-03-17 #refactorlists#
663 // no start of a new list
664 pDoc->SetNumRule( rPam, aRule, false );
665 // <--
670 else if(pSwNum->GetCreatedNumRuleName().Len())
672 UnoActionContext aAction(pDoc);
673 SwNumRule* pRule = pDoc->FindNumRulePtr( pSwNum->GetCreatedNumRuleName() );
674 if(!pRule)
675 throw RuntimeException();
676 // --> OD 2008-03-17 #refactorlists#
677 // no start of a new list
678 pDoc->SetNumRule( rPam, *pRule, false );
679 // <--
681 // --> OD 2009-08-18 #i103817#
682 // outline numbering
683 else
685 UnoActionContext aAction(pDoc);
686 SwNumRule* pRule = pDoc->GetOutlineNumRule();
687 if(!pRule)
688 throw RuntimeException();
689 pDoc->SetNumRule( rPam, *pRule, false );
691 // <--
694 else if(rValue.getValueType() == ::getVoidCppuType())
696 rPam.GetDoc()->DelNumRules(rPam);
701 /* -----------------25.05.98 11:40-------------------
703 * --------------------------------------------------*/
704 void getNumberingProperty(SwPaM& rPam, PropertyState& eState, Any * pAny )
706 const SwNumRule* pNumRule = rPam.GetDoc()->GetCurrNumRule( *rPam.GetPoint() );
707 if(pNumRule)
709 uno::Reference< XIndexReplace > xNum = new SwXNumberingRules(*pNumRule);
710 if ( pAny )
711 pAny->setValue(&xNum, ::getCppuType((const uno::Reference<XIndexReplace>*)0));
712 eState = PropertyState_DIRECT_VALUE;
714 else
715 eState = PropertyState_DEFAULT_VALUE;
717 /* -----------------04.07.98 15:15-------------------
719 * --------------------------------------------------*/
720 void GetCurPageStyle(SwPaM& rPaM, String &rString)
722 const SwPageFrm* pPage = rPaM.GetCntntNode()->GetFrm()->FindPageFrm();
723 if(pPage)
724 SwStyleNameMapper::FillProgName( pPage->GetPageDesc()->GetName(), rString, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True );
726 /* -----------------30.03.99 10:52-------------------
727 * spezielle Properties am Cursor zuruecksetzen
728 * --------------------------------------------------*/
729 void resetCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry, SwPaM& rPam)
731 SwDoc* pDoc = rPam.GetDoc();
732 switch(rEntry.nWID)
734 case FN_UNO_PARA_STYLE :
735 // lcl_SetTxtFmtColl(aValue, pUnoCrsr);
736 break;
737 case FN_UNO_PAGE_STYLE :
738 break;
739 case FN_UNO_NUM_START_VALUE :
741 UnoActionContext aAction(pDoc);
743 if( rPam.GetNext() != &rPam ) // Mehrfachselektion ?
745 pDoc->StartUndo( UNDO_START, NULL );
746 SwPamRanges aRangeArr( rPam );
747 SwPaM aPam( *rPam.GetPoint() );
748 for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
749 pDoc->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), 1 );
750 pDoc->EndUndo( UNDO_END, NULL );
752 else
753 pDoc->SetNodeNumStart( *rPam.GetPoint(), 0 );
756 break;
757 case FN_UNO_NUM_LEVEL :
758 break;
759 case FN_UNO_NUM_RULES:
760 // lcl_setNumberingProperty(aValue, pUnoCrsr);
761 break;
762 case FN_UNO_CHARFMT_SEQUENCE:
764 SvUShortsSort aWhichIds;
765 aWhichIds.Insert(RES_TXTATR_CHARFMT);
766 pDoc->ResetAttrs(rPam, sal_True, &aWhichIds);
768 break;
771 /* -----------------21.07.98 11:36-------------------
773 * --------------------------------------------------*/
774 void InsertFile(SwUnoCrsr* pUnoCrsr,
775 const String& rURL,
776 const uno::Sequence< beans::PropertyValue >& rOptions
777 ) throw( lang::IllegalArgumentException, io::IOException, uno::RuntimeException )
779 SfxMedium* pMed = 0;
780 SwDoc* pDoc = pUnoCrsr->GetDoc();
781 SwDocShell* pDocSh = pDoc->GetDocShell();
782 comphelper::MediaDescriptor aMediaDescriptor( rOptions );
783 ::rtl::OUString sFileName = rURL;
784 ::rtl::OUString sFilterName, sFilterOptions, sPassword, sBaseURL;
785 uno::Reference < io::XStream > xStream;
786 uno::Reference < io::XInputStream > xInputStream;
788 if( !sFileName.getLength() )
789 aMediaDescriptor[comphelper::MediaDescriptor::PROP_URL()] >>= sFileName;
790 if( !sFileName.getLength() )
791 aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILENAME()] >>= sFileName;
792 aMediaDescriptor[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
793 aMediaDescriptor[comphelper::MediaDescriptor::PROP_STREAM()] >>= xStream;
794 aMediaDescriptor[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
795 aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILTERNAME()] >>= sFilterName;
796 aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILTEROPTIONS()] >>= sFilterOptions;
797 aMediaDescriptor[comphelper::MediaDescriptor::PROP_PASSWORD()] >>= sPassword;
798 aMediaDescriptor[comphelper::MediaDescriptor::PROP_DOCUMENTBASEURL() ] >>= sBaseURL;
799 if ( !xInputStream.is() && xStream.is() )
800 xInputStream = xStream->getInputStream();
802 if(!pDocSh || (!sFileName.getLength() && !xInputStream.is()))
803 return;
805 SfxObjectFactory& rFact = pDocSh->GetFactory();
806 const SfxFilter* pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( sFilterName );
807 uno::Reference < embed::XStorage > xReadStorage;
808 if( xInputStream.is() )
810 uno::Sequence< uno::Any > aArgs( 2 );
811 aArgs[0] <<= xInputStream;
812 aArgs[1] <<= embed::ElementModes::READ;
815 xReadStorage = uno::Reference< embed::XStorage >(
816 ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ),
817 uno::UNO_QUERY );
819 catch( const io::IOException& rEx)
821 (void)rEx;
824 if ( !pFilter )
826 if( xInputStream.is() && !xReadStorage.is())
828 pMed = new SfxMedium;
829 pMed->setStreamToLoadFrom(xInputStream, sal_True );
831 else
832 pMed = xReadStorage.is() ?
833 new SfxMedium(xReadStorage, sBaseURL, 0 ) :
834 new SfxMedium(sFileName, STREAM_READ, sal_True, 0, 0 );
835 if( sBaseURL.getLength() )
836 pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
838 SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() );
839 ErrCode nErr = aMatcher.GuessFilter( *pMed, &pFilter, sal_False );
840 if ( nErr || !pFilter)
841 DELETEZ(pMed);
842 else
843 pMed->SetFilter( pFilter );
845 else
847 if(!pMed)
849 if( xInputStream.is() && !xReadStorage.is())
851 pMed = new SfxMedium;
852 pMed->setStreamToLoadFrom(xInputStream, sal_True );
853 pMed->SetFilter( pFilter );
855 else
857 if( xReadStorage.is() )
859 pMed = new SfxMedium(xReadStorage, sBaseURL, 0 );
860 pMed->SetFilter( pFilter );
862 else
863 pMed = new SfxMedium(sFileName, STREAM_READ, sal_True, pFilter, 0);
866 if(sFilterOptions.getLength())
867 pMed->GetItemSet()->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, sFilterOptions ) );
868 if( sBaseURL.getLength())
869 pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
872 if( !pMed )
873 return;
875 SfxObjectShellRef aRef( pDocSh );
877 pDocSh->RegisterTransfer( *pMed );
878 pMed->DownLoad(); // ggfs. den DownLoad anstossen
879 if( aRef.Is() && 1 < aRef->GetRefCount() ) // noch gueltige Ref?
881 SwReader* pRdr;
882 SfxItemSet* pSet = pMed->GetItemSet();
883 pSet->Put(SfxBoolItem(FN_API_CALL, sal_True));
884 if(sPassword.getLength())
885 pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
886 Reader *pRead = pDocSh->StartConvertFrom( *pMed, &pRdr, 0, pUnoCrsr);
887 if( pRead )
890 UnoActionContext aContext(pDoc);
892 if(pUnoCrsr->HasMark())
893 pDoc->DeleteAndJoin(*pUnoCrsr);
895 SwNodeIndex aSave( pUnoCrsr->GetPoint()->nNode, -1 );
896 xub_StrLen nCntnt = pUnoCrsr->GetPoint()->nContent.GetIndex();
898 sal_uInt32 nErrno = pRdr->Read( *pRead ); // und Dokument einfuegen
900 if(!nErrno)
902 aSave++;
903 pUnoCrsr->SetMark();
904 pUnoCrsr->GetMark()->nNode = aSave;
906 SwCntntNode* pCntNode = aSave.GetNode().GetCntntNode();
907 if( !pCntNode )
908 nCntnt = 0;
909 pUnoCrsr->GetMark()->nContent.Assign( pCntNode, nCntnt );
912 delete pRdr;
914 // ggfs. alle Verzeichnisse updaten:
915 /* if( pWrtShell->IsUpdateTOX() )
917 SfxRequest aReq( *this, FN_UPDATE_TOX );
918 Execute( aReq );
919 pWrtShell->SetUpdateTOX( sal_False ); // wieder zurueck setzen
924 delete pMed;
927 /* -----------------14.07.04 ------------------------
929 * --------------------------------------------------*/
931 // insert text and scan for CR characters in order to insert
932 // paragraph breaks at those positions by calling SplitNode
933 sal_Bool DocInsertStringSplitCR(
934 SwDoc &rDoc,
935 const SwPaM &rNewCursor, const String &rText,
936 const bool bForceExpandHints )
938 sal_Bool bOK = sal_True;
940 const enum IDocumentContentOperations::InsertFlags nInsertFlags =
941 (bForceExpandHints)
942 ? static_cast<IDocumentContentOperations::InsertFlags>(
943 IDocumentContentOperations::INS_FORCEHINTEXPAND |
944 IDocumentContentOperations::INS_EMPTYEXPAND)
945 : IDocumentContentOperations::INS_EMPTYEXPAND;
947 OUString aTxt;
948 xub_StrLen nStartIdx = 0;
949 SwTxtNode* const pTxtNd =
950 rNewCursor.GetPoint()->nNode.GetNode().GetTxtNode();
951 const xub_StrLen nMaxLength = ( pTxtNd )
952 ? STRING_LEN - pTxtNd->GetTxt().Len()
953 : STRING_LEN;
954 xub_StrLen nIdx = rText.Search( '\r', nStartIdx );
955 if( ( nIdx == STRING_NOTFOUND && nMaxLength < rText.Len() ) ||
956 ( nIdx != STRING_NOTFOUND && nMaxLength < nIdx ) )
958 nIdx = nMaxLength;
960 while (nIdx != STRING_NOTFOUND )
962 DBG_ASSERT( nIdx - nStartIdx >= 0, "index negative!" );
963 aTxt = rText.Copy( nStartIdx, nIdx - nStartIdx );
964 if (aTxt.getLength() &&
965 !rDoc.InsertString( rNewCursor, aTxt, nInsertFlags ))
967 DBG_ERROR( "Doc->Insert(Str) failed." );
968 bOK = sal_False;
970 if (!rDoc.SplitNode( *rNewCursor.GetPoint(), false ) )
972 DBG_ERROR( "SplitNode failed" );
973 bOK = sal_False;
975 nStartIdx = nIdx + 1;
976 nIdx = rText.Search( '\r', nStartIdx );
978 aTxt = rText.Copy( nStartIdx );
979 if (aTxt.getLength() &&
980 !rDoc.InsertString( rNewCursor, aTxt, nInsertFlags ))
982 DBG_ERROR( "Doc->Insert(Str) failed." );
983 bOK = sal_False;
986 return bOK;
988 /*-- 10.03.2008 09:58:47---------------------------------------------------
990 -----------------------------------------------------------------------*/
991 void makeRedline( SwPaM& rPaM,
992 const ::rtl::OUString& rRedlineType,
993 const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
994 throw (lang::IllegalArgumentException, uno::RuntimeException)
996 IDocumentRedlineAccess* pRedlineAccess = rPaM.GetDoc();
998 RedlineType_t eType = nsRedlineType_t::REDLINE_INSERT;
999 if( rRedlineType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Delete" ) ))
1000 eType = nsRedlineType_t::REDLINE_DELETE;
1001 else if( rRedlineType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Format" ) ))
1002 eType = nsRedlineType_t::REDLINE_FORMAT;
1003 else if( rRedlineType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "TextTable" ) ))
1004 eType = nsRedlineType_t::REDLINE_TABLE;
1005 else if( !rRedlineType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Insert" ) ))
1006 throw lang::IllegalArgumentException();
1008 //todo: what about REDLINE_FMTCOLL?
1009 comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
1010 uno::Any aAuthorValue;
1011 aAuthorValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("RedlineAuthor"), aAuthorValue);
1012 USHORT nAuthor = 0;
1013 ::rtl::OUString sAuthor;
1014 if( aAuthorValue >>= sAuthor )
1015 nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
1017 ::rtl::OUString sComment;
1018 uno::Any aCommentValue;
1019 aCommentValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("RedlineComment"), aCommentValue);
1021 SwRedlineData aRedlineData( eType, nAuthor );
1022 if( aCommentValue >>= sComment )
1023 aRedlineData.SetComment( sComment );
1025 ::util::DateTime aStamp;
1026 uno::Any aDateTimeValue;
1027 aDateTimeValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("RedlineDateTime"), aDateTimeValue);
1028 if( aDateTimeValue >>= aStamp )
1030 aRedlineData.SetTimeStamp(
1031 DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
1034 SwRedline* pRedline = new SwRedline( aRedlineData, rPaM );
1035 RedlineMode_t nPrevMode = pRedlineAccess->GetRedlineMode( );
1037 pRedlineAccess->SetRedlineMode_intern(nsRedlineMode_t::REDLINE_ON);
1038 bool bRet = pRedlineAccess->AppendRedline( pRedline, false );
1039 pRedlineAccess->SetRedlineMode_intern( nPrevMode );
1040 if( !bRet )
1041 throw lang::IllegalArgumentException();
1044 /*-- 19.02.2009 09:27:26---------------------------------------------------
1046 -----------------------------------------------------------------------*/
1047 SwAnyMapHelper::~SwAnyMapHelper()
1049 AnyMapHelper_t::iterator aIt = begin();
1050 while( aIt != end() )
1052 delete ( aIt->second );
1053 ++aIt;
1056 /*-- 19.02.2009 09:27:26---------------------------------------------------
1058 -----------------------------------------------------------------------*/
1059 void SwAnyMapHelper::SetValue( USHORT nWhichId, USHORT nMemberId, const uno::Any& rAny )
1061 sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
1062 AnyMapHelper_t::iterator aIt = find( nKey );
1063 if( aIt != end() )
1065 *(aIt->second) = rAny;
1067 else
1068 insert( value_type(nKey, new uno::Any( rAny )) );
1070 /*-- 19.02.2009 09:27:26---------------------------------------------------
1072 -----------------------------------------------------------------------*/
1073 bool SwAnyMapHelper::FillValue( USHORT nWhichId, USHORT nMemberId, const uno::Any*& pAny )
1075 bool bRet = false;
1076 sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
1077 AnyMapHelper_t::iterator aIt = find( nKey );
1078 if( aIt != end() )
1080 pAny = aIt->second;
1081 bRet = true;
1083 return bRet;
1086 }//namespace SwUnoCursorHelper