Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <svx/svxids.hrc>
30 : : #include <map>
31 : : #include <com/sun/star/text/XTextSection.hpp>
32 : : #include <cmdid.h>
33 : : #include <unocrsrhelper.hxx>
34 : : #include <unofootnote.hxx>
35 : : #include <unorefmark.hxx>
36 : : #include <unostyle.hxx>
37 : : #include <unoidx.hxx>
38 : : #include <unofield.hxx>
39 : : #include <unotbl.hxx>
40 : : #include <unosett.hxx>
41 : : #include <unoframe.hxx>
42 : : #include <unocrsr.hxx>
43 : : #include <doc.hxx>
44 : : #include <IDocumentUndoRedo.hxx>
45 : : #include <IDocumentRedlineAccess.hxx>
46 : : #include <fmtftn.hxx>
47 : : #include <fmtpdsc.hxx>
48 : : #include <charfmt.hxx>
49 : : #include <pagedesc.hxx>
50 : : #include <docstyle.hxx>
51 : : #include <ndtxt.hxx>
52 : : #include <txtrfmrk.hxx>
53 : : #include <fmtfld.hxx>
54 : : #include <docsh.hxx>
55 : : #include <section.hxx>
56 : : #include <shellio.hxx>
57 : : #include <edimp.hxx>
58 : : #include <swundo.hxx>
59 : : #include <cntfrm.hxx>
60 : : #include <pagefrm.hxx>
61 : : #include <svl/eitem.hxx>
62 : : #include <docary.hxx>
63 : : #include <swtable.hxx>
64 : : #include <tox.hxx>
65 : : #include <doctxm.hxx>
66 : : #include <fchrfmt.hxx>
67 : : #include <editeng/flstitem.hxx>
68 : : #include <vcl/metric.hxx>
69 : : #include <svtools/ctrltool.hxx>
70 : : #include <sfx2/docfilt.hxx>
71 : : #include <sfx2/docfile.hxx>
72 : : #include <sfx2/fcontnr.hxx>
73 : : #include <svl/stritem.hxx>
74 : : #include <com/sun/star/beans/PropertyState.hpp>
75 : : #include <SwStyleNameMapper.hxx>
76 : : #include <redline.hxx>
77 : : #include <numrule.hxx>
78 : : #include <comphelper/storagehelper.hxx>
79 : : #include <comphelper/mediadescriptor.hxx>
80 : : #include <comphelper/sequenceashashmap.hxx>
81 : : #include <com/sun/star/embed/ElementModes.hpp>
82 : : #include <com/sun/star/embed/XStorage.hpp>
83 : : #include <SwNodeNum.hxx>
84 : : #include <fmtmeta.hxx>
85 : :
86 : :
87 : : using namespace ::com::sun::star;
88 : : using namespace ::com::sun::star::uno;
89 : : using namespace ::com::sun::star::beans;
90 : : using namespace ::com::sun::star::text;
91 : : using namespace ::com::sun::star::table;
92 : : using namespace ::com::sun::star::container;
93 : : using namespace ::com::sun::star::lang;
94 : : using ::rtl::OUString;
95 : :
96 : : namespace SwUnoCursorHelper
97 : : {
98 : :
99 : : uno::Reference<text::XTextContent>
100 : 44 : GetNestedTextContent(SwTxtNode & rTextNode, xub_StrLen const nIndex,
101 : : bool const bParent)
102 : : {
103 : : // these should be unambiguous because of the dummy character
104 : : SwTxtNode::GetTxtAttrMode const eMode( (bParent)
105 [ + + ]: 44 : ? SwTxtNode::PARENT : SwTxtNode::EXPAND );
106 : : SwTxtAttr *const pMetaTxtAttr =
107 : 44 : rTextNode.GetTxtAttrAt(nIndex, RES_TXTATR_META, eMode);
108 : : SwTxtAttr *const pMetaFieldTxtAttr =
109 : 44 : rTextNode.GetTxtAttrAt(nIndex, RES_TXTATR_METAFIELD, eMode);
110 : : // which is innermost?
111 : : SwTxtAttr *const pTxtAttr = (pMetaTxtAttr)
112 : : ? ((pMetaFieldTxtAttr)
113 : 20 : ? ((*pMetaFieldTxtAttr->GetStart() >
114 : 20 : *pMetaTxtAttr->GetStart())
115 : : ? pMetaFieldTxtAttr : pMetaTxtAttr)
116 : : : pMetaTxtAttr)
117 [ + + + + ]: 64 : : pMetaFieldTxtAttr;
[ + + ]
118 : 44 : uno::Reference<XTextContent> xRet;
119 [ + + ]: 44 : if (pTxtAttr)
120 : : {
121 : : ::sw::Meta *const pMeta(
122 [ + - ]: 32 : static_cast<SwFmtMeta &>(pTxtAttr->GetAttr()).GetMeta());
123 : : OSL_ASSERT(pMeta);
124 [ + - ][ + - ]: 32 : xRet.set(pMeta->MakeUnoObject(), uno::UNO_QUERY);
125 : : }
126 : 44 : return xRet;
127 : : }
128 : :
129 : : /* --------------------------------------------------
130 : : * Read the special properties of the cursor
131 : : * --------------------------------------------------*/
132 : 5267 : sal_Bool getCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry
133 : : , SwPaM& rPam
134 : : , Any *pAny
135 : : , PropertyState& eState
136 : : , const SwTxtNode* pNode )
137 : : {
138 : 5267 : PropertyState eNewState = PropertyState_DIRECT_VALUE;
139 : : // PropertyState_DEFAULT_VALUE
140 : : // PropertyState_AMBIGUOUS_VALUE
141 : 5267 : sal_Bool bDone = sal_True;
142 [ - - + + : 5267 : switch(rEntry.nWID)
+ + + + -
- - - + +
- - + +
+ ]
143 : : {
144 : : case FN_UNO_PARA_CONT_PREV_SUBTREE:
145 [ # # ]: 0 : if (pAny)
146 : : {
147 : 0 : const SwTxtNode * pTmpNode = pNode;
148 : :
149 [ # # ]: 0 : if (!pTmpNode)
150 : 0 : pTmpNode = rPam.GetNode()->GetTxtNode();
151 : :
152 : 0 : bool bRet = false;
153 : :
154 [ # # # # ]: 0 : if ( pTmpNode &&
[ # # ][ # # ]
155 : 0 : pTmpNode->GetNum() &&
156 [ # # ]: 0 : pTmpNode->GetNum()->IsContinueingPreviousSubTree() )
157 : : {
158 : 0 : bRet = true;
159 : : }
160 : :
161 [ # # ]: 0 : *pAny <<= bRet;
162 : : }
163 : 0 : break;
164 : : case FN_UNO_PARA_NUM_STRING:
165 [ # # ]: 0 : if (pAny)
166 : : {
167 : 0 : const SwTxtNode * pTmpNode = pNode;
168 : :
169 [ # # ]: 0 : if (!pTmpNode)
170 : 0 : pTmpNode = rPam.GetNode()->GetTxtNode();
171 : :
172 [ # # ]: 0 : String sRet;
173 [ # # ][ # # ]: 0 : if ( pTmpNode && pTmpNode->GetNum() )
[ # # ]
174 : : {
175 [ # # ][ # # ]: 0 : sRet = pTmpNode->GetNumString();
[ # # ]
176 : : }
177 : :
178 [ # # ][ # # ]: 0 : *pAny <<= OUString(sRet);
[ # # ]
179 : : }
180 : 0 : break;
181 : : case RES_PARATR_OUTLINELEVEL:
182 [ + - ]: 1117 : if (pAny)
183 : : {
184 : 1117 : const SwTxtNode * pTmpNode = pNode;
185 : :
186 [ + + ]: 1117 : if (!pTmpNode)
187 : 940 : pTmpNode = rPam.GetNode()->GetTxtNode();
188 : :
189 : 1117 : sal_Int16 nRet = -1;
190 [ + - ]: 1117 : if ( pTmpNode )
191 [ + - ]: 1117 : nRet = sal::static_int_cast< sal_Int16 >( pTmpNode->GetAttrOutlineLevel() );
192 : :
193 [ + - ]: 1117 : *pAny <<= nRet;
194 : : }
195 : 1117 : break;
196 : : case FN_UNO_PARA_CONDITIONAL_STYLE_NAME:
197 : : case FN_UNO_PARA_STYLE :
198 : : {
199 : 361 : SwFmtColl* pFmt = 0;
200 [ + + ]: 361 : if(pNode)
201 : : pFmt = FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID
202 [ + + ]: 357 : ? pNode->GetFmtColl() : &pNode->GetAnyFmtColl();
203 : : else
204 : : {
205 : : pFmt = SwUnoCursorHelper::GetCurTxtFmtColl(rPam,
206 [ + - ]: 4 : FN_UNO_PARA_CONDITIONAL_STYLE_NAME == rEntry.nWID);
207 : : }
208 [ + - ]: 361 : if(pFmt)
209 : : {
210 [ + + ]: 361 : if( pAny )
211 : : {
212 [ + - ]: 357 : String sVal;
213 [ + - ]: 357 : SwStyleNameMapper::FillProgName(pFmt->GetName(), sVal, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL, sal_True );
214 [ + - ][ + - ]: 357 : *pAny <<= OUString(sVal);
[ + - ]
215 : : }
216 : : }
217 : : else
218 : 0 : eNewState = PropertyState_AMBIGUOUS_VALUE;
219 : : }
220 : 361 : break;
221 : : case FN_UNO_PAGE_STYLE :
222 : : {
223 [ + - ]: 33 : String sVal;
224 [ + - ]: 33 : GetCurPageStyle(rPam, sVal);
225 [ + - ]: 33 : if( pAny )
226 [ + - ][ + - ]: 33 : *pAny <<= OUString(sVal);
227 [ - + ]: 33 : if(!sVal.Len())
228 [ + - ]: 33 : eNewState = PropertyState_AMBIGUOUS_VALUE;
229 : : }
230 : 33 : break;
231 : : case FN_UNO_NUM_START_VALUE :
232 [ - + ]: 6 : if( pAny )
233 : : {
234 [ # # ]: 0 : sal_Int16 nValue = IsNodeNumStart(rPam, eNewState);
235 [ # # ]: 0 : *pAny <<= nValue;
236 : : }
237 : 6 : break;
238 : : case FN_UNO_NUM_LEVEL :
239 : : case FN_UNO_IS_NUMBER :
240 : : // #i91601#
241 : : case FN_UNO_LIST_ID:
242 : : case FN_NUMBER_NEWSTART:
243 : : {
244 : : // a multi selection is not considered
245 : 370 : const SwTxtNode* pTxtNd = rPam.GetNode()->GetTxtNode();
246 [ + - ][ - + ]: 370 : if ( pTxtNd && pTxtNd->IsInList() )
[ - + ][ + - ]
247 : : {
248 [ # # ]: 0 : if( pAny )
249 : : {
250 [ # # ]: 0 : if(rEntry.nWID == FN_UNO_NUM_LEVEL)
251 [ # # ][ # # ]: 0 : *pAny <<= (sal_Int16)(pTxtNd->GetActualListLevel());
252 [ # # ]: 0 : else if(rEntry.nWID == FN_UNO_IS_NUMBER)
253 : : {
254 [ # # ]: 0 : sal_Bool bIsNumber = pTxtNd->IsCountedInList();
255 [ # # ]: 0 : pAny->setValue(&bIsNumber, ::getBooleanCppuType());
256 : : }
257 : : // #i91601#
258 [ # # ]: 0 : else if ( rEntry.nWID == FN_UNO_LIST_ID )
259 : : {
260 [ # # ]: 0 : const String sListId = pTxtNd->GetListId();
261 [ # # ][ # # ]: 0 : *pAny <<= OUString(sListId);
[ # # ]
262 : : }
263 : : else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
264 : : {
265 [ # # ]: 0 : sal_Bool bIsRestart = pTxtNd->IsListRestart();
266 [ # # ]: 0 : pAny->setValue(&bIsRestart, ::getBooleanCppuType());
267 : : }
268 : : }
269 : : }
270 : : else
271 : : {
272 : 370 : eNewState = PropertyState_DEFAULT_VALUE;
273 : :
274 [ + + ]: 370 : if( pAny )
275 : : {
276 : : // #i30838# set default values for default properties
277 [ + + ]: 354 : if(rEntry.nWID == FN_UNO_NUM_LEVEL)
278 [ + - ]: 177 : *pAny <<= static_cast<sal_Int16>( 0 );
279 [ + - ]: 177 : else if(rEntry.nWID == FN_UNO_IS_NUMBER)
280 [ + - ]: 177 : *pAny <<= false;
281 : : // #i91601#
282 [ # # ]: 0 : else if ( rEntry.nWID == FN_UNO_LIST_ID )
283 : : {
284 [ # # ]: 0 : *pAny <<= OUString();
285 : : }
286 : : else /*if(rEntry.nWID == UNO_NAME_PARA_IS_NUMBERING_RESTART)*/
287 [ # # ]: 0 : *pAny <<= false;
288 : : }
289 : : }
290 : : //PROPERTY_MAYBEVOID!
291 : : }
292 : 370 : break;
293 : : case FN_UNO_NUM_RULES :
294 [ + + ]: 1070 : if( pAny )
295 [ + - ]: 1066 : getNumberingProperty(rPam, eNewState, pAny);
296 : : else
297 : : {
298 [ + - ][ + - ]: 4 : if( !rPam.GetDoc()->GetCurrNumRule( *rPam.GetPoint() ) )
299 : 4 : eNewState = PropertyState_DEFAULT_VALUE;
300 : : }
301 : 1070 : break;
302 : : case FN_UNO_DOCUMENT_INDEX_MARK:
303 : : {
304 : : ::std::vector<SwTxtAttr *> const marks(
305 : : rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
306 [ # # ]: 0 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK));
307 [ # # ]: 0 : if (marks.size())
308 : : {
309 [ # # ]: 0 : if( pAny )
310 : : { // hmm... can only return 1 here
311 : : SwTOXMark & rMark =
312 : 0 : static_cast<SwTOXMark &>((*marks.begin())->GetAttr());
313 : : const uno::Reference< text::XDocumentIndexMark > xRef =
314 : : SwXDocumentIndexMark::CreateXDocumentIndexMark(
315 : 0 : *rPam.GetDoc(),
316 [ # # ]: 0 : *const_cast<SwTOXType*>(rMark.GetTOXType()), rMark);
317 [ # # ]: 0 : (*pAny) <<= xRef;
318 : : }
319 : : }
320 : : else
321 : : //also here - indistinguishable
322 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
323 : : }
324 : 0 : break;
325 : : case FN_UNO_DOCUMENT_INDEX:
326 : : {
327 : : const SwTOXBase* pBase = rPam.GetDoc()->GetCurTOX(
328 [ # # ][ # # ]: 0 : *rPam.Start() );
329 [ # # ]: 0 : if( pBase )
330 : : {
331 [ # # ]: 0 : if( pAny )
332 : : {
333 : : const uno::Reference< text::XDocumentIndex > xRef =
334 : 0 : SwXDocumentIndex::CreateXDocumentIndex(*rPam.GetDoc(),
335 [ # # ]: 0 : *static_cast<SwTOXBaseSection const*>(pBase));
336 [ # # ]: 0 : (*pAny) <<= xRef;
337 : : }
338 : : }
339 : : else
340 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
341 : : }
342 : 0 : break;
343 : : case FN_UNO_TEXT_FIELD:
344 : : {
345 [ # # ]: 0 : const SwPosition *pPos = rPam.Start();
346 : : const SwTxtNode *pTxtNd =
347 [ # # ][ # # ]: 0 : rPam.GetDoc()->GetNodes()[pPos->nNode.GetIndex()]->GetTxtNode();
348 : : SwTxtAttr *const pTxtAttr = (pTxtNd)
349 : : ? pTxtNd->GetTxtAttrForCharAt(
350 : 0 : pPos->nContent.GetIndex(), RES_TXTATR_FIELD)
351 [ # # # # ]: 0 : : 0;
352 [ # # ]: 0 : if(pTxtAttr)
353 : : {
354 [ # # ]: 0 : if( pAny )
355 : : {
356 : 0 : SwXTextField* pField = SwXTextField::CreateSwXTextField(*rPam.GetDoc(),
357 [ # # ]: 0 : pTxtAttr->GetFld());
358 [ # # ][ # # ]: 0 : *pAny <<= uno::Reference< XTextField >( pField );
[ # # ]
359 : : }
360 : : }
361 : : else
362 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
363 : : }
364 : 0 : break;
365 : : case FN_UNO_TEXT_TABLE:
366 : : case FN_UNO_CELL:
367 : : {
368 : 0 : SwStartNode* pSttNode = rPam.GetNode()->StartOfSectionNode();
369 : 0 : SwStartNodeType eType = pSttNode->GetStartNodeType();
370 [ # # ]: 0 : if(SwTableBoxStartNode == eType)
371 : : {
372 [ # # ]: 0 : if( pAny )
373 : : {
374 [ # # ]: 0 : const SwTableNode* pTblNode = pSttNode->FindTableNode();
375 : 0 : SwFrmFmt* pTableFmt = (SwFrmFmt*)pTblNode->GetTable().GetFrmFmt();
376 : : //SwTable& rTable = ((SwTableNode*)pSttNode)->GetTable();
377 [ # # ]: 0 : if(FN_UNO_TEXT_TABLE == rEntry.nWID)
378 : : {
379 [ # # ][ # # ]: 0 : uno::Reference< XTextTable > xTable = SwXTextTables::GetObject(*pTableFmt);
380 [ # # ]: 0 : pAny->setValue(&xTable, ::getCppuType((uno::Reference<XTextTable>*)0));
381 : : }
382 : : else
383 : : {
384 [ # # ]: 0 : SwTableBox* pBox = pSttNode->GetTblBox();
385 [ # # ][ # # ]: 0 : uno::Reference< XCell > xCell = SwXCell::CreateXCell(pTableFmt, pBox);
[ # # ]
386 [ # # ]: 0 : pAny->setValue(&xCell, ::getCppuType((uno::Reference<XCell>*)0));
387 : : }
388 : : }
389 : : }
390 : : else
391 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
392 : : }
393 : 0 : break;
394 : : case FN_UNO_TEXT_FRAME:
395 : : {
396 : 3 : SwStartNode* pSttNode = rPam.GetNode()->StartOfSectionNode();
397 : 3 : SwStartNodeType eType = pSttNode->GetStartNodeType();
398 : :
399 : : SwFrmFmt* pFmt;
400 [ # # ][ # # ]: 3 : if(eType == SwFlyStartNode && 0 != (pFmt = pSttNode->GetFlyFmt()))
[ - + ][ - + ]
401 : : {
402 [ # # ]: 0 : if( pAny )
403 : : {
404 [ # # ][ # # ]: 0 : uno::Reference< XTextFrame > xFrm = (SwXTextFrame*) SwXFrames::GetObject(*pFmt, FLYCNTTYPE_FRM);
[ # # ][ # # ]
405 [ # # ]: 0 : pAny->setValue(&xFrm, ::getCppuType((uno::Reference<XTextFrame>*)0));
406 : : }
407 : : }
408 : : else
409 : 3 : eNewState = PropertyState_DEFAULT_VALUE;
410 : : }
411 : 3 : break;
412 : : case FN_UNO_TEXT_SECTION:
413 : : {
414 [ + - ]: 177 : SwSection* pSect = rPam.GetDoc()->GetCurrSection(*rPam.GetPoint());
415 [ + + ]: 177 : if(pSect)
416 : : {
417 [ + - ]: 18 : if( pAny )
418 : : {
419 [ + - ]: 18 : uno::Reference< XTextSection > xSect = SwXTextSections::GetObject( *pSect->GetFmt() );
420 [ + - ]: 18 : pAny->setValue(&xSect, ::getCppuType((uno::Reference<XTextSection>*)0) );
421 : : }
422 : : }
423 : : else
424 : 159 : eNewState = PropertyState_DEFAULT_VALUE;
425 : : }
426 : 177 : break;
427 : : case FN_UNO_ENDNOTE:
428 : : case FN_UNO_FOOTNOTE:
429 : : {
430 : : SwTxtAttr *const pTxtAttr =
431 : : rPam.GetNode()->GetTxtNode()->GetTxtAttrForCharAt(
432 [ # # ]: 0 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN);
433 [ # # ]: 0 : if(pTxtAttr)
434 : : {
435 : 0 : const SwFmtFtn& rFtn = pTxtAttr->GetFtn();
436 [ # # ]: 0 : if(rFtn.IsEndNote() == (FN_UNO_ENDNOTE == rEntry.nWID))
437 : : {
438 [ # # ]: 0 : if( pAny )
439 : : {
440 : : const uno::Reference< text::XFootnote > xFootnote =
441 [ # # ][ # # ]: 0 : SwXFootnote::CreateXFootnote(*rPam.GetDoc(), rFtn);
[ # # ]
442 [ # # ]: 0 : *pAny <<= xFootnote;
443 : : }
444 : : }
445 : : else
446 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
447 : : }
448 : : else
449 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
450 : : }
451 : 0 : break;
452 : : case FN_UNO_REFERENCE_MARK:
453 : : {
454 : : ::std::vector<SwTxtAttr *> const marks(
455 : : rPam.GetNode()->GetTxtNode()->GetTxtAttrsAt(
456 [ # # ]: 0 : rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_REFMARK));
457 [ # # ]: 0 : if (marks.size())
458 : : {
459 [ # # ]: 0 : if( pAny )
460 : : { // hmm... can only return 1 here
461 : 0 : const SwFmtRefMark& rRef = (*marks.begin())->GetRefMark();
462 [ # # ][ # # ]: 0 : uno::Reference< XTextContent > xRef = SwXReferenceMarks::GetObject( rPam.GetDoc(), &rRef );
[ # # ]
463 [ # # ]: 0 : pAny->setValue(&xRef, ::getCppuType((uno::Reference<XTextContent>*)0));
464 : : }
465 : : }
466 : : else
467 : 0 : eNewState = PropertyState_DEFAULT_VALUE;
468 : : }
469 : 0 : break;
470 : : case FN_UNO_NESTED_TEXT_CONTENT:
471 : : {
472 : : uno::Reference<XTextContent> const xRet(
473 : 32 : GetNestedTextContent(*rPam.GetNode()->GetTxtNode(),
474 [ + - ]: 64 : rPam.GetPoint()->nContent.GetIndex(), false));
475 [ + + ]: 32 : if (xRet.is())
476 : : {
477 [ + - ]: 26 : if (pAny)
478 : : {
479 [ + - ]: 26 : (*pAny) <<= xRet;
480 : : }
481 : : }
482 : : else
483 : : {
484 : 6 : eNewState = PropertyState_DEFAULT_VALUE;
485 : 32 : }
486 : : }
487 : 32 : break;
488 : : case FN_UNO_CHARFMT_SEQUENCE:
489 : : {
490 : :
491 : : SwTxtNode* pTxtNode;
492 [ + - ][ + - ]: 24 : if((pTxtNode = (SwTxtNode*)rPam.GetNode( sal_True )) == rPam.GetNode(sal_False) &&
[ + - + + ]
[ + + ]
493 : 12 : pTxtNode->GetpSwpHints())
494 : : {
495 : 8 : sal_uInt16 nPaMStart = rPam.GetPoint()->nContent.GetIndex();
496 [ + - ]: 8 : sal_uInt16 nPaMEnd = rPam.GetMark() ? rPam.GetMark()->nContent.GetIndex() : nPaMStart;
497 [ - + ]: 8 : if(nPaMStart > nPaMEnd)
498 : : {
499 : 0 : sal_uInt16 nTmp = nPaMStart;
500 : 0 : nPaMStart = nPaMEnd;
501 : 0 : nPaMEnd = nTmp;
502 : : }
503 [ + - ]: 8 : Sequence< ::rtl::OUString> aCharStyles;
504 : 8 : SwpHints* pHints = pTxtNode->GetpSwpHints();
505 [ + + ]: 40 : for(sal_uInt16 nAttr = 0; nAttr < pHints->GetStartCount(); nAttr++ )
506 : : {
507 [ + - ]: 32 : SwTxtAttr* pAttr = pHints->GetStart( nAttr );
508 [ + - ][ + + ]: 32 : if(pAttr->Which() != RES_TXTATR_CHARFMT)
509 : 24 : continue;
510 : 8 : sal_uInt16 nAttrStart = *pAttr->GetStart();
511 [ + - ]: 8 : sal_uInt16 nAttrEnd = *pAttr->GetEnd();
512 : : //check if the attribute touches the selection
513 [ + - ][ - + ]: 8 : if( ( nAttrEnd > nPaMStart && nAttrStart < nPaMEnd ) ||
[ # # ][ # # ]
[ # # ][ # # ]
514 : : ( !nAttrStart && !nAttrEnd && !nPaMStart && !nPaMEnd ) )
515 : : {
516 : : //check for overlapping
517 [ + - ][ - + ]: 8 : if(nAttrStart > nPaMStart ||
518 : : nAttrEnd < nPaMEnd)
519 : : {
520 [ # # ]: 0 : aCharStyles.realloc(0);
521 : 0 : eNewState = PropertyState_AMBIGUOUS_VALUE;
522 : 0 : break;
523 : : }
524 : : else
525 : : {
526 : : //now the attribute should start before or at the selection
527 : : //and it should end at the end of the selection or behind
528 : : OSL_ENSURE(nAttrStart <= nPaMStart && nAttrEnd >=nPaMEnd,
529 : : "attribute overlaps or is outside");
530 : : //now the name of the style has to be added to the sequence
531 [ + - ]: 8 : aCharStyles.realloc(aCharStyles.getLength() + 1);
532 : : OSL_ENSURE(pAttr->GetCharFmt().GetCharFmt(), "no character format set");
533 [ + - ]: 8 : aCharStyles.getArray()[aCharStyles.getLength() - 1] =
534 : : SwStyleNameMapper::GetProgName(
535 [ + - ][ + - ]: 16 : pAttr->GetCharFmt().GetCharFmt()->GetName(), nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
536 : : }
537 : : }
538 : :
539 : : }
540 : : eNewState =
541 : 8 : aCharStyles.getLength() ?
542 : 8 : PropertyState_DIRECT_VALUE : PropertyState_DEFAULT_VALUE;
543 [ + - ]: 8 : if(pAny)
544 [ + - ][ + - ]: 8 : (*pAny) <<= aCharStyles;
545 : : }
546 : : else
547 : 4 : eNewState = PropertyState_DEFAULT_VALUE;
548 : : }
549 : 12 : break;
550 : : case RES_TXTATR_CHARFMT:
551 : : // no break here!
552 : 2086 : default: bDone = sal_False;
553 : : }
554 [ + + ]: 5267 : if( bDone )
555 : 3181 : eState = eNewState;
556 : 5267 : return bDone;
557 : : };
558 : :
559 : 0 : sal_Int16 IsNodeNumStart(SwPaM& rPam, PropertyState& eState)
560 : : {
561 : 0 : const SwTxtNode* pTxtNd = rPam.GetNode()->GetTxtNode();
562 : : // correction: check, if restart value is set at the text node and use
563 : : // new method <SwTxtNode::GetAttrListRestartValue()> to retrieve the value
564 [ # # ]: 0 : if ( pTxtNd && pTxtNd->GetNumRule() && pTxtNd->IsListRestart() &&
[ # # # # ]
[ # # ][ # # ]
565 : 0 : pTxtNd->HasAttrListRestartValue() )
566 : : {
567 : 0 : eState = PropertyState_DIRECT_VALUE;
568 : 0 : sal_Int16 nTmp = sal::static_int_cast< sal_Int16 >(pTxtNd->GetAttrListRestartValue());
569 : 0 : return nTmp;
570 : : }
571 : 0 : eState = PropertyState_DEFAULT_VALUE;
572 : 0 : return -1;
573 : : }
574 : :
575 : 129 : void setNumberingProperty(const Any& rValue, SwPaM& rPam)
576 : : {
577 : 129 : uno::Reference<XIndexReplace> xIndexReplace;
578 [ + - ][ + - ]: 129 : if(rValue >>= xIndexReplace)
579 : : {
580 : 129 : SwXNumberingRules* pSwNum = 0;
581 : :
582 [ + - ]: 129 : uno::Reference<XUnoTunnel> xNumTunnel(xIndexReplace, UNO_QUERY);
583 [ + - ]: 129 : if(xNumTunnel.is())
584 : : {
585 : : pSwNum = reinterpret_cast< SwXNumberingRules * >(
586 [ + - ][ + - ]: 129 : sal::static_int_cast< sal_IntPtr >( xNumTunnel->getSomething( SwXNumberingRules::getUnoTunnelId() )));
[ + - ]
587 : : }
588 : :
589 [ + - ]: 129 : if(pSwNum)
590 : : {
591 : 129 : SwDoc* pDoc = rPam.GetDoc();
592 [ + + ]: 129 : if(pSwNum->GetNumRule())
593 : : {
594 [ + - ]: 109 : SwNumRule aRule(*pSwNum->GetNumRule());
595 : 109 : const String* pNewCharStyles = pSwNum->GetNewCharStyleNames();
596 : 109 : const String* pBulletFontNames = pSwNum->GetBulletFontNames();
597 [ + + ]: 1199 : for(sal_uInt16 i = 0; i < MAXLEVEL; i++)
598 : : {
599 [ + - ][ + - ]: 1090 : SwNumFmt aFmt(aRule.Get( i ));
600 [ + + ]: 3264 : if( pNewCharStyles[i].Len() &&
[ - + # # ]
[ # # ][ - + ]
601 [ + - ][ + - ]: 2174 : !SwXNumberingRules::isInvalidStyle(pNewCharStyles[i]) &&
[ + + ][ # # ]
602 [ # # ]: 0 : (!aFmt.GetCharFmt() || pNewCharStyles[i] != aFmt.GetCharFmt()->GetName()))
603 : : {
604 [ # # ]: 0 : if(!pNewCharStyles[i].Len())
605 [ # # ]: 0 : aFmt.SetCharFmt(0);
606 : : else
607 : : {
608 : :
609 : : // get CharStyle and set the rule
610 : 0 : sal_uInt16 nChCount = pDoc->GetCharFmts()->size();
611 : 0 : SwCharFmt* pCharFmt = 0;
612 [ # # ]: 0 : for(sal_uInt16 nCharFmt = 0; nCharFmt < nChCount; nCharFmt++)
613 : : {
614 [ # # ]: 0 : SwCharFmt& rChFmt = *((*(pDoc->GetCharFmts()))[nCharFmt]);
615 [ # # ][ # # ]: 0 : if(rChFmt.GetName() == pNewCharStyles[i])
616 : : {
617 : 0 : pCharFmt = &rChFmt;
618 : 0 : break;
619 : : }
620 : : }
621 : :
622 [ # # ]: 0 : if(!pCharFmt)
623 : : {
624 [ # # ]: 0 : SfxStyleSheetBasePool* pPool = pDoc->GetDocShell()->GetStyleSheetPool();
625 : : SfxStyleSheetBase* pBase;
626 [ # # ]: 0 : pBase = pPool->Find(pNewCharStyles[i], SFX_STYLE_FAMILY_CHAR);
627 : : // shall it really be created?
628 [ # # ]: 0 : if(!pBase)
629 [ # # ]: 0 : pBase = &pPool->Make(pNewCharStyles[i], SFX_STYLE_FAMILY_PAGE);
630 [ # # ]: 0 : pCharFmt = ((SwDocStyleSheet*)pBase)->GetCharFmt();
631 : : }
632 [ # # ]: 0 : if(pCharFmt)
633 [ # # ]: 0 : aFmt.SetCharFmt(pCharFmt);
634 : : }
635 : : }
636 : : //Now again for fonts
637 [ - + # # : 2180 : if(
# # # # ]
[ # # ][ - + ]
638 [ + - ][ + - ]: 2180 : !SwXNumberingRules::isInvalidStyle(pBulletFontNames[i]) &&
[ + - ][ # # ]
639 : : (
640 : 0 : (pBulletFontNames[i].Len() && !aFmt.GetBulletFont()) ||
641 : 0 : (pBulletFontNames[i].Len() &&
642 [ # # ][ # # ]: 0 : aFmt.GetBulletFont()->GetName() != pBulletFontNames[i])
643 : : )
644 : : )
645 : : {
646 : : const SvxFontListItem* pFontListItem =
647 : 0 : (const SvxFontListItem* )pDoc->GetDocShell()
648 [ # # ]: 0 : ->GetItem( SID_ATTR_CHAR_FONTLIST );
649 : 0 : const FontList* pList = pFontListItem->GetFontList();
650 : :
651 : : FontInfo aInfo = pList->Get(
652 [ # # ]: 0 : pBulletFontNames[i],WEIGHT_NORMAL, ITALIC_NONE);
653 [ # # ]: 0 : Font aFont(aInfo);
654 [ # # ][ # # ]: 0 : aFmt.SetBulletFont(&aFont);
[ # # ]
655 : : }
656 [ + - ]: 1090 : aRule.Set( i, aFmt );
657 [ + - ]: 1090 : }
658 [ + - ]: 109 : UnoActionContext aAction(pDoc);
659 : :
660 [ - + ]: 109 : if( rPam.GetNext() != &rPam ) // Multiple selection?
661 : : {
662 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
663 [ # # ]: 0 : SwPamRanges aRangeArr( rPam );
664 [ # # ]: 0 : SwPaM aPam( *rPam.GetPoint() );
665 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
666 : : {
667 : : // no start of a new list
668 [ # # ][ # # ]: 0 : pDoc->SetNumRule( aRangeArr.SetPam( n, aPam ), aRule, false );
[ # # ][ # # ]
669 : : }
670 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
[ # # ]
671 : : }
672 : : else
673 : : {
674 : : // no start of a new list
675 [ + - ][ + - ]: 109 : pDoc->SetNumRule( rPam, aRule, false );
[ + - ]
676 [ + - ][ + - ]: 109 : }
677 : :
678 : :
679 : : }
680 [ + - ]: 20 : else if(pSwNum->GetCreatedNumRuleName().Len())
681 : : {
682 [ + - ]: 20 : UnoActionContext aAction(pDoc);
683 [ + - ]: 20 : SwNumRule* pRule = pDoc->FindNumRulePtr( pSwNum->GetCreatedNumRuleName() );
684 [ - + ]: 20 : if(!pRule)
685 [ # # ]: 0 : throw RuntimeException();
686 : : // no start of a new list
687 [ + - ][ + - ]: 20 : pDoc->SetNumRule( rPam, *pRule, false );
[ + - ][ + - ]
688 : : }
689 : : // #i103817#
690 : : // outline numbering
691 : : else
692 : : {
693 [ # # ]: 0 : UnoActionContext aAction(pDoc);
694 : 0 : SwNumRule* pRule = pDoc->GetOutlineNumRule();
695 [ # # ]: 0 : if(!pRule)
696 [ # # ]: 0 : throw RuntimeException();
697 [ # # ][ # # ]: 0 : pDoc->SetNumRule( rPam, *pRule, false );
[ # # ][ # # ]
698 : : }
699 : 129 : }
700 : : }
701 [ # # ][ # # ]: 0 : else if(rValue.getValueType() == ::getVoidCppuType())
702 : : {
703 [ # # ]: 0 : rPam.GetDoc()->DelNumRules(rPam);
704 : 129 : }
705 : 129 : }
706 : :
707 : 1066 : void getNumberingProperty(SwPaM& rPam, PropertyState& eState, Any * pAny )
708 : : {
709 : 1066 : const SwNumRule* pNumRule = rPam.GetDoc()->GetCurrNumRule( *rPam.GetPoint() );
710 [ + + ]: 1066 : if(pNumRule)
711 : : {
712 [ + - ][ + - ]: 21 : uno::Reference< XIndexReplace > xNum = new SwXNumberingRules(*pNumRule);
[ + - ]
713 [ + - ]: 21 : if ( pAny )
714 [ + - ]: 21 : pAny->setValue(&xNum, ::getCppuType((const uno::Reference<XIndexReplace>*)0));
715 : 21 : eState = PropertyState_DIRECT_VALUE;
716 : : }
717 : : else
718 : 1045 : eState = PropertyState_DEFAULT_VALUE;
719 : 1066 : }
720 : :
721 : 33 : void GetCurPageStyle(SwPaM& rPaM, String &rString)
722 : : {
723 : 33 : const SwPageFrm* pPage = rPaM.GetCntntNode()->getLayoutFrm(rPaM.GetDoc()->GetCurrentLayout())->FindPageFrm();
724 [ + - ]: 33 : if(pPage)
725 : 33 : SwStyleNameMapper::FillProgName( pPage->GetPageDesc()->GetName(), rString, nsSwGetPoolIdFromName::GET_POOLID_PAGEDESC, sal_True );
726 : 33 : }
727 : :
728 : : /* --------------------------------------------------
729 : : * reset special properties of the cursor
730 : : * --------------------------------------------------*/
731 : 2 : void resetCrsrPropertyValue(const SfxItemPropertySimpleEntry& rEntry, SwPaM& rPam)
732 : : {
733 : 2 : SwDoc* pDoc = rPam.GetDoc();
734 [ - - + - : 2 : switch(rEntry.nWID)
- - - ]
735 : : {
736 : : case FN_UNO_PARA_STYLE :
737 : : // lcl_SetTxtFmtColl(aValue, pUnoCrsr);
738 : 0 : break;
739 : : case FN_UNO_PAGE_STYLE :
740 : 0 : break;
741 : : case FN_UNO_NUM_START_VALUE :
742 : : {
743 [ + - ]: 2 : UnoActionContext aAction(pDoc);
744 : :
745 [ - + ]: 2 : if( rPam.GetNext() != &rPam ) // Multiple selection?
746 : : {
747 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
748 [ # # ]: 0 : SwPamRanges aRangeArr( rPam );
749 [ # # ]: 0 : SwPaM aPam( *rPam.GetPoint() );
750 [ # # ]: 0 : for( sal_uInt16 n = 0; n < aRangeArr.Count(); ++n )
751 [ # # ][ # # ]: 0 : pDoc->SetNodeNumStart( *aRangeArr.SetPam( n, aPam ).GetPoint(), 1 );
752 [ # # ][ # # ]: 0 : pDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
[ # # ]
753 : : }
754 : : else
755 [ + - ][ + - ]: 2 : pDoc->SetNodeNumStart( *rPam.GetPoint(), 0 );
756 : : }
757 : :
758 : 2 : break;
759 : : case FN_UNO_NUM_LEVEL :
760 : 0 : break;
761 : : case FN_UNO_NUM_RULES:
762 : : // lcl_setNumberingProperty(aValue, pUnoCrsr);
763 : 0 : break;
764 : : case FN_UNO_CHARFMT_SEQUENCE:
765 : : {
766 [ # # ]: 0 : std::set<sal_uInt16> aWhichIds;
767 [ # # ]: 0 : aWhichIds.insert( RES_TXTATR_CHARFMT);
768 [ # # ]: 0 : pDoc->ResetAttrs(rPam, sal_True, aWhichIds);
769 : : }
770 : 0 : break;
771 : : }
772 : 2 : }
773 : :
774 : 0 : void InsertFile(SwUnoCrsr* pUnoCrsr,
775 : : const String& rURL,
776 : : const uno::Sequence< beans::PropertyValue >& rOptions
777 : : ) throw( lang::IllegalArgumentException, io::IOException, uno::RuntimeException )
778 : : {
779 : 0 : SfxMedium* pMed = 0;
780 : 0 : SwDoc* pDoc = pUnoCrsr->GetDoc();
781 : 0 : SwDocShell* pDocSh = pDoc->GetDocShell();
782 [ # # ]: 0 : comphelper::MediaDescriptor aMediaDescriptor( rOptions );
783 [ # # ]: 0 : ::rtl::OUString sFileName = rURL;
784 : 0 : ::rtl::OUString sFilterName, sFilterOptions, sPassword, sBaseURL;
785 : 0 : uno::Reference < io::XStream > xStream;
786 : 0 : uno::Reference < io::XInputStream > xInputStream;
787 : :
788 [ # # ]: 0 : if( sFileName.isEmpty() )
789 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_URL()] >>= sFileName;
790 [ # # ]: 0 : if( sFileName.isEmpty() )
791 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILENAME()] >>= sFileName;
792 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
[ # # ]
793 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_STREAM()] >>= xStream;
[ # # ]
794 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
[ # # ]
795 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILTERNAME()] >>= sFilterName;
796 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_FILTEROPTIONS()] >>= sFilterOptions;
797 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_PASSWORD()] >>= sPassword;
798 [ # # ][ # # ]: 0 : aMediaDescriptor[comphelper::MediaDescriptor::PROP_DOCUMENTBASEURL() ] >>= sBaseURL;
799 [ # # ][ # # ]: 0 : if ( !xInputStream.is() && xStream.is() )
[ # # ]
800 [ # # ][ # # ]: 0 : xInputStream = xStream->getInputStream();
[ # # ]
801 : :
802 [ # # ][ # # ]: 0 : if(!pDocSh || (sFileName.isEmpty() && !xInputStream.is()))
[ # # ][ # # ]
803 : : return;
804 : :
805 [ # # ]: 0 : SfxObjectFactory& rFact = pDocSh->GetFactory();
806 [ # # ][ # # ]: 0 : const SfxFilter* pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( sFilterName );
[ # # ][ # # ]
807 : 0 : uno::Reference < embed::XStorage > xReadStorage;
808 [ # # ]: 0 : if( xInputStream.is() )
809 : : {
810 [ # # ]: 0 : uno::Sequence< uno::Any > aArgs( 2 );
811 [ # # ][ # # ]: 0 : aArgs[0] <<= xInputStream;
812 [ # # ][ # # ]: 0 : aArgs[1] <<= embed::ElementModes::READ;
813 : : try
814 : : {
815 : : xReadStorage = uno::Reference< embed::XStorage >(
816 [ # # ]: 0 : ::comphelper::OStorageHelper::GetStorageFactory()->createInstanceWithArguments( aArgs ),
[ # # # # ]
817 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
818 : : }
819 [ # # ]: 0 : catch( const io::IOException& rEx)
820 : : {
821 : : (void)rEx;
822 [ # # ]: 0 : }
823 : : }
824 [ # # ]: 0 : if ( !pFilter )
825 : : {
826 [ # # ][ # # ]: 0 : if( xInputStream.is() && !xReadStorage.is())
[ # # ]
827 : : {
828 [ # # ][ # # ]: 0 : pMed = new SfxMedium;
829 [ # # ]: 0 : pMed->setStreamToLoadFrom(xInputStream, sal_True );
830 : : }
831 : : else
832 : 0 : pMed = xReadStorage.is() ?
833 [ # # ]: 0 : new SfxMedium(xReadStorage, sBaseURL, 0 ) :
834 [ # # ][ # # ]: 0 : new SfxMedium(sFileName, STREAM_READ, 0, 0 );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
[ # # ]
835 [ # # ]: 0 : if( !sBaseURL.isEmpty() )
836 [ # # ][ # # ]: 0 : pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
[ # # ][ # # ]
[ # # ][ # # ]
837 : :
838 [ # # ][ # # ]: 0 : SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() );
[ # # ][ # # ]
839 [ # # ]: 0 : ErrCode nErr = aMatcher.GuessFilter( *pMed, &pFilter, sal_False );
840 [ # # ][ # # ]: 0 : if ( nErr || !pFilter)
841 [ # # ][ # # ]: 0 : DELETEZ(pMed);
842 : : else
843 [ # # ][ # # ]: 0 : pMed->SetFilter( pFilter );
844 : : }
845 : : else
846 : : {
847 [ # # ]: 0 : if(!pMed)
848 : : {
849 [ # # ][ # # ]: 0 : if( xInputStream.is() && !xReadStorage.is())
[ # # ]
850 : : {
851 [ # # ][ # # ]: 0 : pMed = new SfxMedium;
852 [ # # ]: 0 : pMed->setStreamToLoadFrom(xInputStream, sal_True );
853 [ # # ]: 0 : pMed->SetFilter( pFilter );
854 : : }
855 : : else
856 : : {
857 [ # # ]: 0 : if( xReadStorage.is() )
858 : : {
859 [ # # ][ # # ]: 0 : pMed = new SfxMedium(xReadStorage, sBaseURL, 0 );
[ # # ][ # # ]
860 [ # # ]: 0 : pMed->SetFilter( pFilter );
861 : : }
862 : : else
863 [ # # ][ # # ]: 0 : pMed = new SfxMedium(sFileName, STREAM_READ, pFilter, 0);
[ # # ][ # # ]
864 : : }
865 : : }
866 [ # # ]: 0 : if(!sFilterOptions.isEmpty())
867 [ # # ][ # # ]: 0 : pMed->GetItemSet()->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, sFilterOptions ) );
[ # # ][ # # ]
[ # # ][ # # ]
868 [ # # ]: 0 : if(!sBaseURL.isEmpty())
869 [ # # ][ # # ]: 0 : pMed->GetItemSet()->Put( SfxStringItem( SID_DOC_BASEURL, sBaseURL ) );
[ # # ][ # # ]
[ # # ][ # # ]
870 : : }
871 : :
872 [ # # ]: 0 : if( !pMed )
873 : : return;
874 : :
875 : : // this sourcecode is not responsible for the lifetime of the shell, SfxObjectShellLock should not be used
876 : 0 : SfxObjectShellRef aRef( pDocSh );
877 : :
878 [ # # ][ # # ]: 0 : pMed->DownLoad(); // if necessary: start the download
879 [ # # ][ # # ]: 0 : if( aRef.Is() && 1 < aRef->GetRefCount() ) // Ref still valid?
[ # # ]
880 : : {
881 : : SwReader* pRdr;
882 [ # # ]: 0 : SfxItemSet* pSet = pMed->GetItemSet();
883 [ # # ][ # # ]: 0 : pSet->Put(SfxBoolItem(FN_API_CALL, sal_True));
[ # # ]
884 [ # # ]: 0 : if(!sPassword.isEmpty())
885 [ # # ][ # # ]: 0 : pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
[ # # ][ # # ]
[ # # ]
886 [ # # ][ # # ]: 0 : Reader *pRead = pDocSh->StartConvertFrom( *pMed, &pRdr, 0, pUnoCrsr);
887 [ # # ]: 0 : if( pRead )
888 : : {
889 : :
890 [ # # ]: 0 : UnoActionContext aContext(pDoc);
891 : :
892 [ # # ]: 0 : if(pUnoCrsr->HasMark())
893 [ # # ]: 0 : pDoc->DeleteAndJoin(*pUnoCrsr);
894 : :
895 [ # # ]: 0 : SwNodeIndex aSave( pUnoCrsr->GetPoint()->nNode, -1 );
896 : 0 : xub_StrLen nCntnt = pUnoCrsr->GetPoint()->nContent.GetIndex();
897 : :
898 [ # # ]: 0 : sal_uInt32 nErrno = pRdr->Read( *pRead ); // and paste the document
899 : :
900 [ # # ]: 0 : if(!nErrno)
901 : : {
902 [ # # ]: 0 : aSave++;
903 [ # # ]: 0 : pUnoCrsr->SetMark();
904 [ # # ]: 0 : pUnoCrsr->GetMark()->nNode = aSave;
905 : :
906 : 0 : SwCntntNode* pCntNode = aSave.GetNode().GetCntntNode();
907 [ # # ]: 0 : if( !pCntNode )
908 : 0 : nCntnt = 0;
909 [ # # ][ # # ]: 0 : pUnoCrsr->GetMark()->nContent.Assign( pCntNode, nCntnt );
910 : : }
911 : :
912 [ # # ][ # # ]: 0 : delete pRdr;
[ # # ][ # # ]
913 : :
914 : :
915 : : }
916 : : }
917 [ # # ][ # # ]: 0 : delete pMed;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
918 : : }
919 : :
920 : : // insert text and scan for CR characters in order to insert
921 : : // paragraph breaks at those positions by calling SplitNode
922 : 12880 : sal_Bool DocInsertStringSplitCR(
923 : : SwDoc &rDoc,
924 : : const SwPaM &rNewCursor, const String &rText,
925 : : const bool bForceExpandHints )
926 : : {
927 : 12880 : sal_Bool bOK = sal_True;
928 : :
929 : : const enum IDocumentContentOperations::InsertFlags nInsertFlags =
930 : : (bForceExpandHints)
931 : : ? static_cast<IDocumentContentOperations::InsertFlags>(
932 : : IDocumentContentOperations::INS_FORCEHINTEXPAND |
933 : : IDocumentContentOperations::INS_EMPTYEXPAND)
934 [ + + ]: 12880 : : IDocumentContentOperations::INS_EMPTYEXPAND;
935 : :
936 : : // grouping done in InsertString is intended for typing, not API calls
937 [ + - ][ + - ]: 12880 : ::sw::GroupUndoGuard const undoGuard(rDoc.GetIDocumentUndoRedo());
938 : 12880 : OUString aTxt;
939 : 12880 : xub_StrLen nStartIdx = 0;
940 : : SwTxtNode* const pTxtNd =
941 : 12880 : rNewCursor.GetPoint()->nNode.GetNode().GetTxtNode();
942 : : const xub_StrLen nMaxLength = ( pTxtNd )
943 : 12880 : ? STRING_LEN - pTxtNd->GetTxt().Len()
944 [ + - ]: 25760 : : STRING_LEN;
945 [ + - ]: 12880 : xub_StrLen nIdx = rText.Search( '\r', nStartIdx );
946 [ + - ][ + - ]: 12880 : if( ( nIdx == STRING_NOTFOUND && nMaxLength < rText.Len() ) ||
[ - + ][ # # ]
[ - + ]
947 : : ( nIdx != STRING_NOTFOUND && nMaxLength < nIdx ) )
948 : : {
949 : 0 : nIdx = nMaxLength;
950 : : }
951 [ - + ]: 12880 : while (nIdx != STRING_NOTFOUND )
952 : : {
953 : : OSL_ENSURE( nIdx - nStartIdx >= 0, "index negative!" );
954 [ # # ][ # # ]: 0 : aTxt = rText.Copy( nStartIdx, nIdx - nStartIdx );
[ # # ]
955 [ # # ][ # # ]: 0 : if (!aTxt.isEmpty() &&
[ # # ]
956 [ # # ][ # # ]: 0 : !rDoc.InsertString( rNewCursor, aTxt, nInsertFlags ))
[ # # ][ # # ]
[ # # ]
957 : : {
958 : : OSL_FAIL( "Doc->Insert(Str) failed." );
959 : 0 : bOK = sal_False;
960 : : }
961 [ # # ][ # # ]: 0 : if (!rDoc.SplitNode( *rNewCursor.GetPoint(), false ) )
962 : : {
963 : : OSL_FAIL( "SplitNode failed" );
964 : 0 : bOK = sal_False;
965 : : }
966 : 0 : nStartIdx = nIdx + 1;
967 [ # # ]: 0 : nIdx = rText.Search( '\r', nStartIdx );
968 : : }
969 [ + - ][ + - ]: 12880 : aTxt = rText.Copy( nStartIdx );
[ + - ]
970 [ + + ][ - + ]: 38581 : if (!aTxt.isEmpty() &&
[ - + ]
971 [ + - ][ + - ]: 25701 : !rDoc.InsertString( rNewCursor, aTxt, nInsertFlags ))
[ + + ][ + - ]
[ # # ]
972 : : {
973 : : OSL_FAIL( "Doc->Insert(Str) failed." );
974 : 0 : bOK = sal_False;
975 : : }
976 : :
977 [ + - ]: 12880 : return bOK;
978 : : }
979 : :
980 : 0 : void makeRedline( SwPaM& rPaM,
981 : : const ::rtl::OUString& rRedlineType,
982 : : const uno::Sequence< beans::PropertyValue >& rRedlineProperties )
983 : : throw (lang::IllegalArgumentException, uno::RuntimeException)
984 : : {
985 [ # # ]: 0 : IDocumentRedlineAccess* pRedlineAccess = rPaM.GetDoc();
986 : :
987 : 0 : RedlineType_t eType = nsRedlineType_t::REDLINE_INSERT;
988 [ # # ]: 0 : if ( rRedlineType == "Delete" )
989 : 0 : eType = nsRedlineType_t::REDLINE_DELETE;
990 [ # # ]: 0 : else if ( rRedlineType == "Format" )
991 : 0 : eType = nsRedlineType_t::REDLINE_FORMAT;
992 [ # # ]: 0 : else if ( rRedlineType == "TextTable" )
993 : 0 : eType = nsRedlineType_t::REDLINE_TABLE;
994 [ # # ]: 0 : else if( !rRedlineType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM ( "Insert" ) ))
995 [ # # ]: 0 : throw lang::IllegalArgumentException();
996 : :
997 : : //todo: what about REDLINE_FMTCOLL?
998 [ # # ]: 0 : comphelper::SequenceAsHashMap aPropMap( rRedlineProperties );
999 : 0 : uno::Any aAuthorValue;
1000 [ # # ][ # # ]: 0 : aAuthorValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RedlineAuthor")), aAuthorValue);
1001 : 0 : sal_uInt16 nAuthor = 0;
1002 : 0 : ::rtl::OUString sAuthor;
1003 [ # # ]: 0 : if( aAuthorValue >>= sAuthor )
1004 [ # # ][ # # ]: 0 : nAuthor = pRedlineAccess->InsertRedlineAuthor(sAuthor);
[ # # ]
1005 : :
1006 : 0 : ::rtl::OUString sComment;
1007 : 0 : uno::Any aCommentValue;
1008 [ # # ][ # # ]: 0 : aCommentValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RedlineComment")), aCommentValue);
1009 : :
1010 [ # # ]: 0 : SwRedlineData aRedlineData( eType, nAuthor );
1011 [ # # ]: 0 : if( aCommentValue >>= sComment )
1012 [ # # ][ # # ]: 0 : aRedlineData.SetComment( sComment );
[ # # ]
1013 : :
1014 : 0 : ::util::DateTime aStamp;
1015 : 0 : uno::Any aDateTimeValue;
1016 [ # # ][ # # ]: 0 : aDateTimeValue = aPropMap.getUnpackedValueOrDefault( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("RedlineDateTime")), aDateTimeValue);
1017 [ # # ][ # # ]: 0 : if( aDateTimeValue >>= aStamp )
1018 : : {
1019 : : aRedlineData.SetTimeStamp(
1020 [ # # ][ # # ]: 0 : DateTime( Date( aStamp.Day, aStamp.Month, aStamp.Year ), Time( aStamp.Hours, aStamp.Minutes, aStamp.Seconds ) ) );
[ # # ]
1021 : : }
1022 : :
1023 [ # # ][ # # ]: 0 : SwRedline* pRedline = new SwRedline( aRedlineData, rPaM );
1024 [ # # ]: 0 : RedlineMode_t nPrevMode = pRedlineAccess->GetRedlineMode( );
1025 : :
1026 [ # # ]: 0 : pRedlineAccess->SetRedlineMode_intern(nsRedlineMode_t::REDLINE_ON);
1027 [ # # ]: 0 : bool bRet = pRedlineAccess->AppendRedline( pRedline, false );
1028 [ # # ]: 0 : pRedlineAccess->SetRedlineMode_intern( nPrevMode );
1029 [ # # ]: 0 : if( !bRet )
1030 [ # # ][ # # ]: 0 : throw lang::IllegalArgumentException();
[ # # ]
1031 : 0 : }
1032 : :
1033 : 695 : SwAnyMapHelper::~SwAnyMapHelper()
1034 : : {
1035 : 695 : AnyMapHelper_t::iterator aIt = begin();
1036 [ + + ]: 3801 : while( aIt != end() )
1037 : : {
1038 [ + - ]: 3106 : delete ( aIt->second );
1039 : 3106 : ++aIt;
1040 : : }
1041 : 695 : }
1042 : :
1043 : 3121 : void SwAnyMapHelper::SetValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any& rAny )
1044 : : {
1045 : 3121 : sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
1046 [ + - ]: 3121 : AnyMapHelper_t::iterator aIt = find( nKey );
1047 [ + + ]: 3121 : if( aIt != end() )
1048 : : {
1049 : 15 : *(aIt->second) = rAny;
1050 : : }
1051 : : else
1052 [ + - ]: 3106 : insert( value_type(nKey, new uno::Any( rAny )) );
1053 : 3121 : }
1054 : :
1055 : 43193 : bool SwAnyMapHelper::FillValue( sal_uInt16 nWhichId, sal_uInt16 nMemberId, const uno::Any*& pAny )
1056 : : {
1057 : 43193 : bool bRet = false;
1058 : 43193 : sal_uInt32 nKey = (nWhichId << 16) + nMemberId;
1059 [ + - ]: 43193 : AnyMapHelper_t::iterator aIt = find( nKey );
1060 [ + + ]: 43193 : if( aIt != end() )
1061 : : {
1062 : 3439 : pAny = aIt->second;
1063 : 3439 : bRet = true;
1064 : : }
1065 : 43193 : return bRet;
1066 : : }
1067 : :
1068 : : }//namespace SwUnoCursorHelper
1069 : :
1070 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|