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 $
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"
37 #include <unocrsrhelper.hxx>
39 #include <unostyle.hxx>
41 #include <unofield.hxx>
43 #include <unosett.hxx>
44 #include <unoframe.hxx>
46 #include <IDocumentRedlineAccess.hxx>
48 #include <fmtpdsc.hxx>
49 #include <charfmt.hxx>
50 #include <pagedesc.hxx>
51 #include <docstyle.hxx>
53 #include <txtrfmrk.hxx>
56 #include <section.hxx>
57 #include <shellio.hxx>
61 #include <pagefrm.hxx>
62 #include <svtools/eitem.hxx>
63 #include <tools/urlobj.hxx>
65 #include <swtable.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>
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
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
;
118 // --> OD 2008-11-26 #158694#
119 case FN_UNO_PARA_CONT_PREV_SUBTREE
:
122 const SwTxtNode
* pTmpNode
= pNode
;
125 pTmpNode
= rPam
.GetNode()->GetTxtNode();
130 pTmpNode
->GetNum() &&
131 pTmpNode
->GetNum()->IsContinueingPreviousSubTree() )
139 case FN_UNO_PARA_NUM_STRING
:
142 const SwTxtNode
* pTmpNode
= pNode
;
145 pTmpNode
= rPam
.GetNode()->GetTxtNode();
148 if ( pTmpNode
&& pTmpNode
->GetNum() )
150 sRet
= pTmpNode
->GetNumString();
153 *pAny
<<= OUString(sRet
);
157 // --> OD 2008-05-20 #outlinelevel# - no longer needed
158 // case FN_UNO_PARA_CHAPTER_NUMBERING_LEVEL:
161 // const SwTxtNode * pTmpNode = pNode;
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());
173 case RES_PARATR_OUTLINELEVEL
: //#outlinelevel added by zhaojianwei
176 const SwTxtNode
* pTmpNode
= pNode
;
179 pTmpNode
= rPam
.GetNode()->GetTxtNode();
183 nRet
= sal::static_int_cast
< sal_Int16
>( pTmpNode
->GetAttrOutlineLevel() );
187 break; //<-end,zhaojianwei
188 case FN_UNO_PARA_CONDITIONAL_STYLE_NAME
:
189 case FN_UNO_PARA_STYLE
:
193 pFmt
= FN_UNO_PARA_CONDITIONAL_STYLE_NAME
== rEntry
.nWID
194 ? pNode
->GetFmtColl() : &pNode
->GetAnyFmtColl();
196 pFmt
= SwXTextCursor::GetCurTxtFmtColl(rPam
, FN_UNO_PARA_CONDITIONAL_STYLE_NAME
== rEntry
.nWID
);
202 SwStyleNameMapper::FillProgName(pFmt
->GetName(), sVal
, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL
, sal_True
);
203 *pAny
<<= OUString(sVal
);
207 eNewState
= PropertyState_AMBIGUOUS_VALUE
;
210 case FN_UNO_PAGE_STYLE
:
213 GetCurPageStyle(rPam
, sVal
);
215 *pAny
<<= OUString(sVal
);
217 eNewState
= PropertyState_AMBIGUOUS_VALUE
;
220 case FN_UNO_NUM_START_VALUE
:
223 sal_Int16 nValue
= IsNodeNumStart(rPam
, eNewState
);
227 case FN_UNO_NUM_LEVEL
:
228 case FN_UNO_IS_NUMBER
:
229 // --> OD 2008-07-14 #i91601#
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;
239 // hier wird Multiselektion nicht beruecksichtigt
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
);
258 else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
260 BOOL bIsRestart
= pTxtNd
->IsListRestart();
261 pAny
->setValue(&bIsRestart
, ::getBooleanCppuType());
267 eNewState
= PropertyState_DEFAULT_VALUE
;
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
)
276 // --> OD 2008-07-14 #i91601#
277 else if ( rEntry
.nWID
== FN_UNO_LIST_ID
)
279 *pAny
<<= OUString();
282 else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
286 //PROPERTY_MAYBEVOID!
289 case FN_UNO_NUM_RULES
:
291 getNumberingProperty(rPam
, eNewState
, pAny
);
294 if( !rPam
.GetDoc()->GetCurrNumRule( *rPam
.GetPoint() ) )
295 eNewState
= PropertyState_DEFAULT_VALUE
;
298 case FN_UNO_DOCUMENT_INDEX_MARK
:
300 SwTxtAttr
* pTxtAttr
= rPam
.GetNode()->GetTxtNode()->GetTxtAttr(
301 rPam
.GetPoint()->nContent
, RES_TXTATR_TOXMARK
);
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));
313 //auch hier - nicht zu unterscheiden
314 eNewState
= PropertyState_DEFAULT_VALUE
;
317 case FN_UNO_DOCUMENT_INDEX
:
319 const SwTOXBase
* pBase
= rPam
.GetDoc()->GetCurTOX(
325 uno::Reference
< XDocumentIndex
> aRef
=
326 SwXDocumentIndexes::GetObject((SwTOXBaseSection
*)pBase
);
327 pAny
->setValue(&aRef
, ::getCppuType((uno::Reference
<XDocumentIndex
>*)0));
331 eNewState
= PropertyState_DEFAULT_VALUE
;
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
)
346 SwXTextField
* pField
= CreateSwXTextField(*rPam
.GetDoc(),
348 *pAny
<<= uno::Reference
< XTextField
>( pField
);
352 eNewState
= PropertyState_DEFAULT_VALUE
;
355 /* laesst sich nicht feststellen
356 * case FN_UNO_BOOKMARK:
360 uno::Reference< XBookmark > xBkm = SwXBookmarks::GetObject(rBkm);
361 rAny.set(&xBkm, ::getCppuType((const XBookmark*)0)());
365 case FN_UNO_TEXT_TABLE
:
368 SwStartNode
* pSttNode
= rPam
.GetNode()->StartOfSectionNode();
369 SwStartNodeType eType
= pSttNode
->GetStartNodeType();
370 if(SwTableBoxStartNode
== eType
)
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));
384 SwTableBox
* pBox
= pSttNode
->GetTblBox();
385 uno::Reference
< XCell
> xCell
= SwXCell::CreateXCell(pTableFmt
, pBox
);
386 pAny
->setValue(&xCell
, ::getCppuType((uno::Reference
<XCell
>*)0));
391 eNewState
= PropertyState_DEFAULT_VALUE
;
394 case FN_UNO_TEXT_FRAME
:
396 SwStartNode
* pSttNode
= rPam
.GetNode()->StartOfSectionNode();
397 SwStartNodeType eType
= pSttNode
->GetStartNodeType();
400 if(eType
== SwFlyStartNode
&& 0 != (pFmt
= pSttNode
->GetFlyFmt()))
404 uno::Reference
< XTextFrame
> xFrm
= (SwXTextFrame
*) SwXFrames::GetObject(*pFmt
, FLYCNTTYPE_FRM
);
405 pAny
->setValue(&xFrm
, ::getCppuType((uno::Reference
<XTextFrame
>*)0));
409 eNewState
= PropertyState_DEFAULT_VALUE
;
412 case FN_UNO_TEXT_SECTION
:
414 SwSection
* pSect
= rPam
.GetDoc()->GetCurrSection(*rPam
.GetPoint());
419 uno::Reference
< XTextSection
> xSect
= SwXTextSections::GetObject( *pSect
->GetFmt() );
420 pAny
->setValue(&xSect
, ::getCppuType((uno::Reference
<XTextSection
>*)0) );
424 eNewState
= PropertyState_DEFAULT_VALUE
;
428 case FN_UNO_FOOTNOTE
:
430 SwTxtAttr
* pTxtAttr
= rPam
.GetNode()->GetTxtNode()->
431 GetTxtAttr(rPam
.GetPoint()->nContent
, RES_TXTATR_FTN
);
434 const SwFmtFtn
& rFtn
= pTxtAttr
->GetFtn();
435 if(rFtn
.IsEndNote() == (FN_UNO_ENDNOTE
== rEntry
.nWID
))
439 uno::Reference
< XFootnote
> xFoot
= new SwXFootnote(rPam
.GetDoc(), rFtn
);
440 pAny
->setValue(&xFoot
, ::getCppuType((uno::Reference
<XFootnote
>*)0));
444 eNewState
= PropertyState_DEFAULT_VALUE
;
447 eNewState
= PropertyState_DEFAULT_VALUE
;
450 case FN_UNO_REFERENCE_MARK
:
452 SwTxtAttr
* pTxtAttr
= rPam
.GetNode()->GetTxtNode()->
453 GetTxtAttr(rPam
.GetPoint()->nContent
, RES_TXTATR_REFMARK
);
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));
464 eNewState
= PropertyState_DEFAULT_VALUE
;
467 case FN_UNO_CHARFMT_SEQUENCE
:
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
;
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
)
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
||
499 aCharStyles
.realloc(0);
500 eNewState
= PropertyState_AMBIGUOUS_VALUE
;
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
);
520 aCharStyles
.getLength() ?
521 PropertyState_DIRECT_VALUE
: PropertyState_DEFAULT_VALUE
;;
523 (*pAny
) <<= aCharStyles
;
526 eNewState
= PropertyState_DEFAULT_VALUE
;
529 case RES_TXTATR_CHARFMT
:
531 default: bDone
= sal_False
;
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());
554 eState
= PropertyState_DEFAULT_VALUE
;
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
);
571 pSwNum
= reinterpret_cast< SwXNumberingRules
* >(
572 sal::static_int_cast
< sal_IntPtr
>( xNumTunnel
->getSomething( SwXNumberingRules::getUnoTunnelId() )));
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())
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
])
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?
615 pBase
= &pPool
->Make(pNewCharStyles
[i
], SFX_STYLE_FAMILY_PAGE
);
616 pCharFmt
= ((SwDocStyleSheet
*)pBase
)->GetCharFmt();
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
);
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 );
658 pDoc
->EndUndo( UNDO_END
, NULL
);
662 // --> OD 2008-03-17 #refactorlists#
663 // no start of a new list
664 pDoc
->SetNumRule( rPam
, aRule
, false );
670 else if(pSwNum
->GetCreatedNumRuleName().Len())
672 UnoActionContext
aAction(pDoc
);
673 SwNumRule
* pRule
= pDoc
->FindNumRulePtr( pSwNum
->GetCreatedNumRuleName() );
675 throw RuntimeException();
676 // --> OD 2008-03-17 #refactorlists#
677 // no start of a new list
678 pDoc
->SetNumRule( rPam
, *pRule
, false );
681 // --> OD 2009-08-18 #i103817#
685 UnoActionContext
aAction(pDoc
);
686 SwNumRule
* pRule
= pDoc
->GetOutlineNumRule();
688 throw RuntimeException();
689 pDoc
->SetNumRule( rPam
, *pRule
, false );
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() );
709 uno::Reference
< XIndexReplace
> xNum
= new SwXNumberingRules(*pNumRule
);
711 pAny
->setValue(&xNum
, ::getCppuType((const uno::Reference
<XIndexReplace
>*)0));
712 eState
= PropertyState_DIRECT_VALUE
;
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();
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();
734 case FN_UNO_PARA_STYLE
:
735 // lcl_SetTxtFmtColl(aValue, pUnoCrsr);
737 case FN_UNO_PAGE_STYLE
:
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
);
753 pDoc
->SetNodeNumStart( *rPam
.GetPoint(), 0 );
757 case FN_UNO_NUM_LEVEL
:
759 case FN_UNO_NUM_RULES
:
760 // lcl_setNumberingProperty(aValue, pUnoCrsr);
762 case FN_UNO_CHARFMT_SEQUENCE
:
764 SvUShortsSort aWhichIds
;
765 aWhichIds
.Insert(RES_TXTATR_CHARFMT
);
766 pDoc
->ResetAttrs(rPam
, sal_True
, &aWhichIds
);
771 /* -----------------21.07.98 11:36-------------------
773 * --------------------------------------------------*/
774 void InsertFile(SwUnoCrsr
* pUnoCrsr
,
776 const uno::Sequence
< beans::PropertyValue
>& rOptions
777 ) throw( lang::IllegalArgumentException
, io::IOException
, uno::RuntimeException
)
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()))
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
),
819 catch( const io::IOException
& rEx
)
826 if( xInputStream
.is() && !xReadStorage
.is())
828 pMed
= new SfxMedium
;
829 pMed
->setStreamToLoadFrom(xInputStream
, sal_True
);
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
)
843 pMed
->SetFilter( pFilter
);
849 if( xInputStream
.is() && !xReadStorage
.is())
851 pMed
= new SfxMedium
;
852 pMed
->setStreamToLoadFrom(xInputStream
, sal_True
);
853 pMed
->SetFilter( pFilter
);
857 if( xReadStorage
.is() )
859 pMed
= new SfxMedium(xReadStorage
, sBaseURL
, 0 );
860 pMed
->SetFilter( pFilter
);
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
) );
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?
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
);
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
904 pUnoCrsr
->GetMark()->nNode
= aSave
;
906 SwCntntNode
* pCntNode
= aSave
.GetNode().GetCntntNode();
909 pUnoCrsr
->GetMark()->nContent
.Assign( pCntNode
, nCntnt
);
914 // ggfs. alle Verzeichnisse updaten:
915 /* if( pWrtShell->IsUpdateTOX() )
917 SfxRequest aReq( *this, FN_UPDATE_TOX );
919 pWrtShell->SetUpdateTOX( sal_False ); // wieder zurueck setzen
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(
935 const SwPaM
&rNewCursor
, const String
&rText
,
936 const bool bForceExpandHints
)
938 sal_Bool bOK
= sal_True
;
940 const enum IDocumentContentOperations::InsertFlags nInsertFlags
=
942 ? static_cast<IDocumentContentOperations::InsertFlags
>(
943 IDocumentContentOperations::INS_FORCEHINTEXPAND
|
944 IDocumentContentOperations::INS_EMPTYEXPAND
)
945 : IDocumentContentOperations::INS_EMPTYEXPAND
;
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()
954 xub_StrLen nIdx
= rText
.Search( '\r', nStartIdx
);
955 if( ( nIdx
== STRING_NOTFOUND
&& nMaxLength
< rText
.Len() ) ||
956 ( nIdx
!= STRING_NOTFOUND
&& nMaxLength
< nIdx
) )
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." );
970 if (!rDoc
.SplitNode( *rNewCursor
.GetPoint(), false ) )
972 DBG_ERROR( "SplitNode failed" );
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." );
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
);
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
);
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
);
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
);
1065 *(aIt
->second
) = rAny
;
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
)
1076 sal_uInt32 nKey
= (nWhichId
<< 16) + nMemberId
;
1077 AnyMapHelper_t::iterator aIt
= find( nKey
);
1086 }//namespace SwUnoCursorHelper