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