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