xref: /aoo41x/main/sw/source/core/doc/doc.cxx (revision c0286415)
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 <doc.hxx>
28 #include <UndoManager.hxx>
29 #include <hintids.hxx>
30 
31 #include <tools/shl.hxx>
32 #include <tools/globname.hxx>
33 #include <svx/svxids.hrc>
34 #include <com/sun/star/i18n/WordType.hdl>
35 #include <com/sun/star/i18n/ForbiddenCharacters.hdl>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/beans/NamedValue.hpp>
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
40 #include <com/sun/star/document/XDocumentProperties.hpp>
41 #include <comphelper/processfactory.hxx>
42 #include <tools/urlobj.hxx>
43 #include <tools/poly.hxx>
44 #include <tools/multisel.hxx>
45 #include <rtl/ustring.hxx>
46 #include <vcl/virdev.hxx>
47 #include <svl/itemiter.hxx>
48 #include <svl/poolitem.hxx>
49 #include <unotools/syslocale.hxx>
50 #include <sfx2/printer.hxx>
51 #include <editeng/keepitem.hxx>
52 #include <editeng/cscoitem.hxx>
53 #include <editeng/brkitem.hxx>
54 #include <sfx2/linkmgr.hxx>
55 #include <editeng/forbiddencharacterstable.hxx>
56 #include <svx/svdmodel.hxx>
57 #include <editeng/pbinitem.hxx>
58 #include <unotools/charclass.hxx>
59 #include <unotools/localedatawrapper.hxx>
60 
61 #include <swatrset.hxx>
62 #include <swmodule.hxx>
63 #include <fmtpdsc.hxx>
64 #include <fmtanchr.hxx>
65 #include <fmtrfmrk.hxx>
66 #include <fmtinfmt.hxx>
67 #include <fmtfld.hxx>
68 #include <txtfld.hxx>
69 #include <dbfld.hxx>
70 #include <txtinet.hxx>
71 #include <txtrfmrk.hxx>
72 #include <frmatr.hxx>
73 #include <linkenum.hxx>
74 #include <errhdl.hxx>
75 #include <pagefrm.hxx>
76 #include <rootfrm.hxx>
77 #include <swtable.hxx>
78 #include <pam.hxx>
79 #include <ndtxt.hxx>
80 #include <swundo.hxx>			// fuer die UndoIds
81 #include <UndoCore.hxx>
82 #include <UndoInsert.hxx>
83 #include <UndoSplitMove.hxx>
84 #include <UndoTable.hxx>
85 #include <pagedesc.hxx> //DTor
86 #include <breakit.hxx>
87 #include <ndole.hxx>
88 #include <ndgrf.hxx>
89 #include <rolbck.hxx>			// Undo-Attr
90 #include <doctxm.hxx>			// fuer die Verzeichnisse
91 #include <grfatr.hxx>
92 #include <poolfmt.hxx>			// PoolVorlagen-Id's
93 #include <mvsave.hxx>			// fuer Server-Funktionalitaet
94 #include <SwGrammarMarkUp.hxx>
95 #include <scriptinfo.hxx>
96 #include <acorrect.hxx>			// Autokorrektur
97 #include <mdiexp.hxx>	   		// Statusanzeige
98 #include <docstat.hxx>
99 #include <docary.hxx>
100 #include <redline.hxx>
101 #include <fldupde.hxx>
102 #include <swbaslnk.hxx>
103 #include <printdata.hxx>
104 #include <cmdid.h>              // fuer den dflt - Printer in SetJob
105 #include <statstr.hrc>      	// StatLine-String
106 #include <comcore.hrc>
107 #include <SwUndoTOXChange.hxx>
108 #include <SwUndoFmt.hxx>
109 #include <unocrsr.hxx>
110 #include <docsh.hxx>
111 #include <viewopt.hxx>
112 #include <docfld.hxx>           // _SetGetExpFld
113 #include <docufld.hxx>          // SwPostItField
114 #include <viewsh.hxx>
115 #include <shellres.hxx>
116 #include <txtfrm.hxx>
117 #include <attrhint.hxx>
118 
119 #include <wdocsh.hxx>           // SwWebDocShell
120 #include <prtopt.hxx>           // SwPrintOptions
121 
122 #include <vector>
123 #include <map>
124 
125 #include <osl/diagnose.h>
126 #include <osl/interlck.h>
127 #include <vbahelper/vbaaccesshelper.hxx>
128 
129 #include "switerator.hxx"
130 
131 /* @@@MAINTAINABILITY-HORROR@@@
132    Probably unwanted dependency on SwDocShell
133 */
134 // --> OD 2005-08-29 #125370#
135 #include <layouter.hxx>
136 // <--
137 
138 using namespace ::com::sun::star;
139 using ::rtl::OUString;
140 
141 
142 // Seiten-Deskriptoren
143 SV_IMPL_PTRARR(SwPageDescs,SwPageDescPtr);
144 // Verzeichnisse
145 SV_IMPL_PTRARR( SwTOXTypes, SwTOXTypePtr )
146 // FeldTypen
147 SV_IMPL_PTRARR( SwFldTypes, SwFldTypePtr)
148 
149 /** IInterface
150 */
151 sal_Int32 SwDoc::acquire()
152 {
153     OSL_ASSERT(mReferenceCount >= 0 && "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
154     return osl_incrementInterlockedCount(&mReferenceCount);
155 }
156 
157 sal_Int32 SwDoc::release()
158 {
159     OSL_PRECOND(mReferenceCount >= 1, "Object is already released! Releasing it again leads to a negative reference count.");
160     return osl_decrementInterlockedCount(&mReferenceCount);
161 }
162 
163 sal_Int32 SwDoc::getReferenceCount() const
164 {
165     OSL_ASSERT(mReferenceCount >= 0 && "Negative reference count detected! This is a sign for unbalanced acquire/release calls.");
166     return mReferenceCount;
167 }
168 
169 /** IDocumentSettingAccess
170 */
171 bool SwDoc::get(/*[in]*/ DocumentSettingId id) const
172 {
173     switch (id)
174     {
175         // COMPATIBILITY FLAGS START
176         case PARA_SPACE_MAX: return mbParaSpaceMax; //(n8Dummy1 & DUMMY_PARASPACEMAX);
177         case PARA_SPACE_MAX_AT_PAGES: return mbParaSpaceMaxAtPages; //(n8Dummy1 & DUMMY_PARASPACEMAX_AT_PAGES);
178         case TAB_COMPAT: return mbTabCompat; //(n8Dummy1 & DUMMY_TAB_COMPAT);
179         case ADD_FLY_OFFSETS: return mbAddFlyOffsets; //(n8Dummy2 & DUMMY_ADD_FLY_OFFSETS);
180         case ADD_EXT_LEADING: return mbAddExternalLeading; //(n8Dummy2 & DUMMY_ADD_EXTERNAL_LEADING);
181         case USE_VIRTUAL_DEVICE: return mbUseVirtualDevice; //(n8Dummy1 & DUMMY_USE_VIRTUAL_DEVICE);
182         case USE_HIRES_VIRTUAL_DEVICE: return mbUseHiResolutionVirtualDevice; //(n8Dummy2 & DUMMY_USE_HIRES_VIR_DEV);
183         case OLD_NUMBERING: return mbOldNumbering;
184         case OLD_LINE_SPACING: return mbOldLineSpacing;
185         case ADD_PARA_SPACING_TO_TABLE_CELLS: return mbAddParaSpacingToTableCells;
186         case USE_FORMER_OBJECT_POS: return mbUseFormerObjectPos;
187         case USE_FORMER_TEXT_WRAPPING: return mbUseFormerTextWrapping;
188         case CONSIDER_WRAP_ON_OBJECT_POSITION: return mbConsiderWrapOnObjPos;
189         case DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK: return mbDoNotJustifyLinesWithManualBreak;
190         case IGNORE_FIRST_LINE_INDENT_IN_NUMBERING: return mbIgnoreFirstLineIndentInNumbering;
191         case OUTLINE_LEVEL_YIELDS_OUTLINE_RULE: return mbOutlineLevelYieldsOutlineRule;
192 	    case TABLE_ROW_KEEP: return mbTableRowKeep;
193 	    case IGNORE_TABS_AND_BLANKS_FOR_LINE_CALCULATION: return mbIgnoreTabsAndBlanksForLineCalculation;
194 	    case DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE: return mbDoNotCaptureDrawObjsOnPage;
195         // --> OD 2006-08-25 #i68949#
196         case CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME: return mbClipAsCharacterAnchoredWriterFlyFrames;
197         // <--
198         case UNIX_FORCE_ZERO_EXT_LEADING: return mbUnixForceZeroExtLeading;
199         case USE_OLD_PRINTER_METRICS: return mbOldPrinterMetrics;
200         case TABS_RELATIVE_TO_INDENT : return mbTabRelativeToIndent;
201         case PROTECT_FORM: return mbProtectForm;
202         // --> OD 2008-06-05 #i89181#
203         case TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST: return mbTabAtLeftIndentForParagraphsInList;
204         // <--
205          // COMPATIBILITY FLAGS END
206 
207         case BROWSE_MODE: return mbLastBrowseMode; // Attention: normally the ViewShell has to be asked!
208         case HTML_MODE: return mbHTMLMode;
209         case GLOBAL_DOCUMENT: return mbIsGlobalDoc;
210         case GLOBAL_DOCUMENT_SAVE_LINKS: return mbGlblDocSaveLinks;
211         case LABEL_DOCUMENT: return mbIsLabelDoc;
212         case PURGE_OLE: return mbPurgeOLE;
213         case KERN_ASIAN_PUNCTUATION: return mbKernAsianPunctuation;
214         case DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT: return mbDoNotResetParaAttrsForNumFont;
215         case MATH_BASELINE_ALIGNMENT: return mbMathBaselineAlignment;
216         default:
217             ASSERT(false, "Invalid setting id");
218     }
219     return false;
220 }
221 
222 void SwDoc::set(/*[in]*/ DocumentSettingId id, /*[in]*/ bool value)
223 {
224     switch (id)
225     {
226         // COMPATIBILITY FLAGS START
227         case PARA_SPACE_MAX:
228             mbParaSpaceMax = value;
229             break;
230         case PARA_SPACE_MAX_AT_PAGES:
231             mbParaSpaceMaxAtPages = value;
232             break;
233         case TAB_COMPAT:
234             mbTabCompat = value;
235             break;
236         case ADD_FLY_OFFSETS:
237             mbAddFlyOffsets = value;
238             break;
239         case ADD_EXT_LEADING:
240             mbAddExternalLeading = value;
241             break;
242         case USE_VIRTUAL_DEVICE:
243             mbUseVirtualDevice = value;
244             break;
245         case USE_HIRES_VIRTUAL_DEVICE:
246             mbUseHiResolutionVirtualDevice = value;
247             break;
248         case OLD_NUMBERING:
249             if (mbOldNumbering != value)
250             {
251                 mbOldNumbering = value;
252 
253                 const SwNumRuleTbl& rNmTbl = GetNumRuleTbl();
254                 for( sal_uInt16 n = 0; n < rNmTbl.Count(); ++n )
255                     rNmTbl[n]->SetInvalidRule(sal_True);
256 
257                 UpdateNumRule();
258 
259                 if (pOutlineRule)
260                 {
261                     pOutlineRule->Validate();
262                     // --> OD 2005-10-21 - counting of phantoms depends on <IsOldNumbering()>
263                     pOutlineRule->SetCountPhantoms( !mbOldNumbering );
264                     // <--
265                 }
266             }
267             break;
268         case OLD_LINE_SPACING:
269             mbOldLineSpacing = value;
270             break;
271         case ADD_PARA_SPACING_TO_TABLE_CELLS:
272             mbAddParaSpacingToTableCells = value;
273             break;
274         case USE_FORMER_OBJECT_POS:
275             mbUseFormerObjectPos = value;
276             break;
277         case USE_FORMER_TEXT_WRAPPING:
278             mbUseFormerTextWrapping = value;
279             break;
280         case CONSIDER_WRAP_ON_OBJECT_POSITION:
281             mbConsiderWrapOnObjPos = value;
282             break;
283         case DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK:
284             mbDoNotJustifyLinesWithManualBreak = value;
285             break;
286         case IGNORE_FIRST_LINE_INDENT_IN_NUMBERING:
287             mbIgnoreFirstLineIndentInNumbering = value;
288             break;
289 
290         case OUTLINE_LEVEL_YIELDS_OUTLINE_RULE:
291             mbOutlineLevelYieldsOutlineRule = value;
292             break;
293 
294 	    case TABLE_ROW_KEEP:
295 	        mbTableRowKeep = value;
296 	        break;
297 
298 	    case IGNORE_TABS_AND_BLANKS_FOR_LINE_CALCULATION:
299 		    mbIgnoreTabsAndBlanksForLineCalculation = value;
300 			break;
301 
302 	    case DO_NOT_CAPTURE_DRAW_OBJS_ON_PAGE:
303 		    mbDoNotCaptureDrawObjsOnPage = value;
304 			break;
305 
306         // --> OD 2006-08-25 #i68949#
307         case CLIP_AS_CHARACTER_ANCHORED_WRITER_FLY_FRAME:
308             mbClipAsCharacterAnchoredWriterFlyFrames = value;
309             break;
310         // <--
311         case UNIX_FORCE_ZERO_EXT_LEADING:
312             mbUnixForceZeroExtLeading = value;
313             break;
314         case PROTECT_FORM:
315 	    mbProtectForm = value;
316 	    break;
317 
318         case USE_OLD_PRINTER_METRICS:
319             mbOldPrinterMetrics = value;
320             break;
321         case TABS_RELATIVE_TO_INDENT:
322             mbTabRelativeToIndent = value;
323         break;
324         // --> OD 2008-06-05 #i89181#
325         case TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST:
326             mbTabAtLeftIndentForParagraphsInList = value;
327         break;
328         // <--
329          // COMPATIBILITY FLAGS END
330 
331         case BROWSE_MODE: //can be used temporary (load/save) when no ViewShell is avaiable
332             mbLastBrowseMode = value;
333             break;
334         case HTML_MODE:
335             mbHTMLMode = value;
336             break;
337         case GLOBAL_DOCUMENT:
338             mbIsGlobalDoc = value;
339             break;
340         case GLOBAL_DOCUMENT_SAVE_LINKS:
341             mbGlblDocSaveLinks = value;
342             break;
343         case LABEL_DOCUMENT:
344             mbIsLabelDoc = value;
345             break;
346         case PURGE_OLE:
347             mbPurgeOLE = value;
348             break;
349         case KERN_ASIAN_PUNCTUATION:
350             mbKernAsianPunctuation = value;
351             break;
352         case DO_NOT_RESET_PARA_ATTRS_FOR_NUM_FONT:
353             mbDoNotResetParaAttrsForNumFont = value;
354             break;
355         case MATH_BASELINE_ALIGNMENT:
356             mbMathBaselineAlignment  = value;
357             break;
358         default:
359             ASSERT(false, "Invalid setting id");
360     }
361 }
362 
363 const i18n::ForbiddenCharacters*
364     SwDoc::getForbiddenCharacters(/*[in]*/ sal_uInt16 nLang, /*[in]*/ bool bLocaleData ) const
365 {
366     const i18n::ForbiddenCharacters* pRet = 0;
367     if( xForbiddenCharsTable.isValid() )
368         pRet = xForbiddenCharsTable->GetForbiddenCharacters( nLang, sal_False );
369     if( bLocaleData && !pRet && pBreakIt )
370         pRet = &pBreakIt->GetForbidden( (LanguageType)nLang );
371     return pRet;
372 }
373 
374 void SwDoc::setForbiddenCharacters(/*[in]*/ sal_uInt16 nLang,
375                                    /*[in]*/ const com::sun::star::i18n::ForbiddenCharacters& rFChars )
376 {
377     if( !xForbiddenCharsTable.isValid() )
378     {
379         uno::Reference<
380             lang::XMultiServiceFactory > xMSF =
381                                     ::comphelper::getProcessServiceFactory();
382         xForbiddenCharsTable = new SvxForbiddenCharactersTable( xMSF );
383     }
384     xForbiddenCharsTable->SetForbiddenCharacters( nLang, rFChars );
385     if( pDrawModel )
386     {
387         pDrawModel->SetForbiddenCharsTable( xForbiddenCharsTable );
388         if( !mbInReading )
389             pDrawModel->ReformatAllTextObjects();
390     }
391 
392     SwRootFrm* pTmpRoot = GetCurrentLayout();
393 	if( pTmpRoot && !mbInReading )
394     {
395         pTmpRoot->StartAllAction();
396 		std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
397 		std::for_each( aAllLayouts.begin(), aAllLayouts.end(), std::bind2nd(std::mem_fun(&SwRootFrm::InvalidateAllCntnt), INV_SIZE));
398         pTmpRoot->EndAllAction();
399     }//swmod 080310
400     SetModified();
401 }
402 
403 vos::ORef<SvxForbiddenCharactersTable>& SwDoc::getForbiddenCharacterTable()
404 {
405     if( !xForbiddenCharsTable.isValid() )
406     {
407         uno::Reference<
408             lang::XMultiServiceFactory > xMSF =
409                                     ::comphelper::getProcessServiceFactory();
410         xForbiddenCharsTable = new SvxForbiddenCharactersTable( xMSF );
411     }
412     return xForbiddenCharsTable;
413 }
414 
415 const vos::ORef<SvxForbiddenCharactersTable>& SwDoc::getForbiddenCharacterTable() const
416 {
417     return xForbiddenCharsTable;
418 }
419 
420 sal_uInt16 SwDoc::getLinkUpdateMode( /*[in]*/bool bGlobalSettings ) const
421 {
422     sal_uInt16 nRet = nLinkUpdMode;
423     if( bGlobalSettings && GLOBALSETTING == nRet )
424         nRet = SW_MOD()->GetLinkUpdMode(get(IDocumentSettingAccess::HTML_MODE));
425     return nRet;
426 }
427 
428 void SwDoc::setLinkUpdateMode( /*[in]*/sal_uInt16 eMode )
429 {
430     nLinkUpdMode = eMode;
431 }
432 
433 SwFldUpdateFlags SwDoc::getFieldUpdateFlags( /*[in]*/bool bGlobalSettings ) const
434 {
435     SwFldUpdateFlags eRet = eFldUpdMode;
436     if( bGlobalSettings && AUTOUPD_GLOBALSETTING == eRet )
437         eRet = SW_MOD()->GetFldUpdateFlags(get(IDocumentSettingAccess::HTML_MODE));
438     return eRet;
439 }
440 
441 void SwDoc::setFieldUpdateFlags(/*[in]*/SwFldUpdateFlags eMode )
442 {
443     eFldUpdMode = eMode;
444 }
445 
446 SwCharCompressType SwDoc::getCharacterCompressionType() const
447 {
448     return eChrCmprType;
449 }
450 
451 void SwDoc::setCharacterCompressionType( /*[in]*/SwCharCompressType n )
452 {
453     if( eChrCmprType != n )
454     {
455         eChrCmprType = n;
456         if( pDrawModel )
457         {
458             pDrawModel->SetCharCompressType( static_cast<sal_uInt16>(n) );
459             if( !mbInReading )
460                 pDrawModel->ReformatAllTextObjects();
461         }
462 
463 		SwRootFrm* pTmpRoot = GetCurrentLayout();
464 		if( pTmpRoot && !mbInReading )
465         {
466 			pTmpRoot->StartAllAction();
467 			std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
468 			std::for_each( aAllLayouts.begin(), aAllLayouts.end(), std::bind2nd(std::mem_fun(&SwRootFrm::InvalidateAllCntnt), INV_SIZE));
469 			pTmpRoot->EndAllAction();
470 		}//swmod 080310
471         SetModified();
472     }
473 }
474 
475 /** IDocumentDeviceAccess
476 */
477 SfxPrinter* SwDoc::getPrinter(/*[in]*/ bool bCreate ) const
478 {
479     SfxPrinter* pRet = 0;
480     if ( !bCreate || pPrt )
481         pRet = pPrt;
482     else
483         pRet = &CreatePrinter_();
484 
485     return pRet;
486 }
487 
488 void SwDoc::setPrinter(/*[in]*/ SfxPrinter *pP,/*[in]*/ bool bDeleteOld,/*[in]*/ bool bCallPrtDataChanged )
489 {
490     if ( pP != pPrt )
491     {
492         if ( bDeleteOld )
493             delete pPrt;
494         pPrt = pP;
495 
496         // our printer should always use TWIP. Don't rely on this being set in ViewShell::InitPrt, there
497         // are situations where this isn't called.
498         // #i108712# / 2010-02-26 / frank.schoenheit@sun.com
499         if ( pPrt )
500         {
501             MapMode aMapMode( pPrt->GetMapMode() );
502             aMapMode.SetMapUnit( MAP_TWIP );
503             pPrt->SetMapMode( aMapMode );
504         }
505 
506         if ( pDrawModel && !get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
507             pDrawModel->SetRefDevice( pPrt );
508     }
509 
510     if ( bCallPrtDataChanged &&
511          // --> FME 2005-01-21 #i41075# Do not call PrtDataChanged() if we do not
512          // use the printer for formatting:
513          !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
514         // <--
515         PrtDataChanged();
516 }
517 
518 VirtualDevice* SwDoc::getVirtualDevice(/*[in]*/ bool bCreate ) const
519 {
520     VirtualDevice* pRet = 0;
521     if ( !bCreate || pVirDev )
522         pRet = pVirDev;
523     else
524         pRet = &CreateVirtualDevice_();
525 
526     return pRet;
527 }
528 
529 void SwDoc::setVirtualDevice(/*[in]*/ VirtualDevice* pVd,/*[in]*/ bool bDeleteOld, /*[in]*/ bool )
530 {
531     if ( pVirDev != pVd )
532     {
533         if ( bDeleteOld )
534             delete pVirDev;
535         pVirDev = pVd;
536 
537         if ( pDrawModel && get( IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
538             pDrawModel->SetRefDevice( pVirDev );
539     }
540 }
541 
542 OutputDevice* SwDoc::getReferenceDevice(/*[in]*/ bool bCreate ) const
543 {
544     OutputDevice* pRet = 0;
545     if ( !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
546     {
547         pRet = getPrinter( bCreate );
548 
549         if ( bCreate && !pPrt->IsValid() )
550         {
551             pRet = getVirtualDevice( sal_True );
552         }
553     }
554     else
555     {
556         pRet = getVirtualDevice( bCreate );
557     }
558 
559     return pRet;
560 }
561 
562 void SwDoc::setReferenceDeviceType(/*[in]*/ bool bNewVirtual,/*[in]*/ bool bNewHiRes )
563 {
564     if ( get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) != bNewVirtual ||
565          get(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE) != bNewHiRes )
566     {
567         if ( bNewVirtual )
568         {
569             VirtualDevice* pMyVirDev = getVirtualDevice( true );
570             if ( !bNewHiRes )
571                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE06 );
572             else
573                 pMyVirDev->SetReferenceDevice( VirtualDevice::REFDEV_MODE_MSO1 );
574 
575             if( pDrawModel )
576                 pDrawModel->SetRefDevice( pMyVirDev );
577         }
578         else
579         {
580             // --> FME 2005-01-21 #i41075#
581             // We have to take care that a printer exists before calling
582             // PrtDataChanged() in order to prevent that PrtDataChanged()
583             // triggers this funny situation:
584             // getReferenceDevice()->getPrinter()->CreatePrinter_()
585             // ->setPrinter()-> PrtDataChanged()
586             SfxPrinter* pPrinter = getPrinter( true );
587             // <--
588             if( pDrawModel )
589                 pDrawModel->SetRefDevice( pPrinter );
590         }
591 
592         set(IDocumentSettingAccess::USE_VIRTUAL_DEVICE, bNewVirtual );
593         set(IDocumentSettingAccess::USE_HIRES_VIRTUAL_DEVICE, bNewHiRes );
594         PrtDataChanged();
595         SetModified();
596     }
597 }
598 
599 const JobSetup* SwDoc::getJobsetup() const
600 {
601     return pPrt ? &pPrt->GetJobSetup() : 0;
602 }
603 
604 void SwDoc::setJobsetup(/*[in]*/ const JobSetup &rJobSetup )
605 {
606     sal_Bool bCheckPageDescs = 0 == pPrt;
607     sal_Bool bDataChanged = sal_False;
608 
609     if ( pPrt )
610     {
611         if ( pPrt->GetName() == rJobSetup.GetPrinterName() )
612         {
613             if ( pPrt->GetJobSetup() != rJobSetup )
614             {
615                 pPrt->SetJobSetup( rJobSetup );
616                 bDataChanged = sal_True;
617             }
618         }
619         else
620             delete pPrt, pPrt = 0;
621     }
622 
623     if( !pPrt )
624     {
625         //Das ItemSet wird vom Sfx geloescht!
626         SfxItemSet *pSet = new SfxItemSet( GetAttrPool(),
627                         FN_PARAM_ADDPRINTER, FN_PARAM_ADDPRINTER,
628                         SID_HTML_MODE,  SID_HTML_MODE,
629                         SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
630                         SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
631                         0 );
632         SfxPrinter *p = new SfxPrinter( pSet, rJobSetup );
633         if ( bCheckPageDescs )
634             setPrinter( p, true, true );
635         else
636         {
637             pPrt = p;
638             bDataChanged = sal_True;
639         }
640     }
641     if ( bDataChanged && !get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) )
642         PrtDataChanged();
643 }
644 
645 const SwPrintData & SwDoc::getPrintData() const
646 {
647     if(!pPrtData)
648     {
649         SwDoc * pThis = const_cast< SwDoc * >(this);
650         pThis->pPrtData = new SwPrintData;
651 
652         // SwPrintData should be initialized from the configuration,
653         // the respective config item is implememted by SwPrintOptions which
654         // is also derived from SwPrintData
655         const SwDocShell *pDocSh = GetDocShell();
656         DBG_ASSERT( pDocSh, "pDocSh is 0, can't determine if this is a WebDoc or not" );
657         bool bWeb = 0 != dynamic_cast< const SwWebDocShell * >(pDocSh);
658         SwPrintOptions aPrintOptions( bWeb );
659         *pThis->pPrtData = aPrintOptions;
660     }
661     return *pPrtData;
662 }
663 
664 void SwDoc::setPrintData(/*[in]*/ const SwPrintData& rPrtData )
665 {
666     if(!pPrtData)
667         pPrtData = new SwPrintData;
668     *pPrtData = rPrtData;
669 }
670 
671 /** Implementations the next Interface here
672 */
673 
674 /*
675  * Dokumenteditieren (Doc-SS) zum Fuellen des Dokuments
676  * durch den RTF Parser und fuer die EditShell.
677  */
678 void SwDoc::ChgDBData(const SwDBData& rNewData)
679 {
680 	if( rNewData != aDBData )
681 	{
682 		aDBData = rNewData;
683 		SetModified();
684 	}
685 	GetSysFldType(RES_DBNAMEFLD)->UpdateFlds();
686 }
687 
688 bool SwDoc::SplitNode( const SwPosition &rPos, bool bChkTableStart )
689 {
690 	SwCntntNode *pNode = rPos.nNode.GetNode().GetCntntNode();
691 	if(0 == pNode)
692         return false;
693 
694 	{
695 		// Bug 26675:	DataChanged vorm loeschen verschicken, dann bekommt
696 		//			man noch mit, welche Objecte sich im Bereich befinden.
697 		//			Danach koennen sie vor/hinter der Position befinden.
698 		SwDataChanged aTmp( this, rPos, 0 );
699 	}
700 
701 	SwUndoSplitNode* pUndo = 0;
702     if (GetIDocumentUndoRedo().DoesUndo())
703     {
704         GetIDocumentUndoRedo().ClearRedo();
705 		// einfuegen vom Undo-Object, z.Z. nur beim TextNode
706 		if( pNode->IsTxtNode() )
707         {
708             pUndo = new SwUndoSplitNode( this, rPos, bChkTableStart );
709             GetIDocumentUndoRedo().AppendUndo(pUndo);
710         }
711     }
712 
713 	//JP 28.01.97: Sonderfall fuer SplitNode am Tabellenanfang:
714 	//				steht die am Doc/Fly/Footer/..-Anfang oder direkt
715 	//				hinter einer Tabelle, dann fuege davor
716 	//				einen Absatz ein
717 	if( bChkTableStart && !rPos.nContent.GetIndex() && pNode->IsTxtNode() )
718 	{
719 		sal_uLong nPrevPos = rPos.nNode.GetIndex() - 1;
720 		const SwTableNode* pTblNd;
721 		const SwNode* pNd = GetNodes()[ nPrevPos ];
722 		if( pNd->IsStartNode() &&
723 			SwTableBoxStartNode == ((SwStartNode*)pNd)->GetStartNodeType() &&
724 			0 != ( pTblNd = GetNodes()[ --nPrevPos ]->GetTableNode() ) &&
725 			((( pNd = GetNodes()[ --nPrevPos ])->IsStartNode() &&
726 			   SwTableBoxStartNode != ((SwStartNode*)pNd)->GetStartNodeType() )
727                || ( pNd->IsEndNode() && pNd->StartOfSectionNode()->IsTableNode() )
728 			   || pNd->IsCntntNode() ))
729 		{
730 			if( pNd->IsCntntNode() )
731 			{
732 				//JP 30.04.99 Bug 65660:
733 				// ausserhalb des normalen BodyBereiches gibt es keine
734 				// Seitenumbrueche, also ist das hier kein gueltige
735 				// Bedingung fuers einfuegen eines Absatzes
736 				if( nPrevPos < GetNodes().GetEndOfExtras().GetIndex() )
737 					pNd = 0;
738 				else
739 				{
740 					// Dann nur, wenn die Tabelle Umbrueche traegt!
741 					const SwFrmFmt* pFrmFmt = pTblNd->GetTable().GetFrmFmt();
742 					if( SFX_ITEM_SET != pFrmFmt->GetItemState(RES_PAGEDESC, sal_False) &&
743 						SFX_ITEM_SET != pFrmFmt->GetItemState( RES_BREAK, sal_False ) )
744 						pNd = 0;
745 				}
746 			}
747 
748 			if( pNd )
749 			{
750 				SwTxtNode* pTxtNd = GetNodes().MakeTxtNode(
751 										SwNodeIndex( *pTblNd ),
752 										GetTxtCollFromPool( RES_POOLCOLL_TEXT ));
753 				if( pTxtNd )
754 				{
755 					((SwPosition&)rPos).nNode = pTblNd->GetIndex()-1;
756 					((SwPosition&)rPos).nContent.Assign( pTxtNd, 0 );
757 
758 					// nur im BodyBereich den SeitenUmbruch/-Vorlage umhaengem
759 					if( nPrevPos > GetNodes().GetEndOfExtras().GetIndex() )
760 					{
761 						SwFrmFmt* pFrmFmt = pTblNd->GetTable().GetFrmFmt();
762 						const SfxPoolItem *pItem;
763 						if( SFX_ITEM_SET == pFrmFmt->GetItemState( RES_PAGEDESC,
764 							sal_False, &pItem ) )
765 						{
766                             pTxtNd->SetAttr( *pItem );
767                             pFrmFmt->ResetFmtAttr( RES_PAGEDESC );
768 						}
769 						if( SFX_ITEM_SET == pFrmFmt->GetItemState( RES_BREAK,
770 							sal_False, &pItem ) )
771 						{
772                             pTxtNd->SetAttr( *pItem );
773                             pFrmFmt->ResetFmtAttr( RES_BREAK );
774 						}
775 					}
776 
777 					if( pUndo )
778 						pUndo->SetTblFlag();
779 					SetModified();
780                     return true;
781                 }
782             }
783         }
784     }
785 
786 	SvULongs aBkmkArr( 15, 15 );
787 	_SaveCntntIdx( this, rPos.nNode.GetIndex(), rPos.nContent.GetIndex(),
788 					aBkmkArr, SAVEFLY_SPLIT );
789     // FIXME: only SwTxtNode has a valid implementation of SplitCntntNode!
790     ASSERT(pNode->IsTxtNode(), "splitting non-text node?");
791     pNode = pNode->SplitCntntNode( rPos );
792     if (pNode)
793 	{
794 		// verschiebe noch alle Bookmarks/TOXMarks/FlyAtCnt
795 		if( aBkmkArr.Count() )
796 			_RestoreCntntIdx( this, aBkmkArr, rPos.nNode.GetIndex()-1, 0, sal_True );
797 
798 		if( IsRedlineOn() || (!IsIgnoreRedline() && pRedlineTbl->Count() ))
799 		{
800 			SwPaM aPam( rPos );
801 			aPam.SetMark();
802 			aPam.Move( fnMoveBackward );
803 			if( IsRedlineOn() )
804 				AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
805 			else
806 				SplitRedline( aPam );
807 		}
808 	}
809 
810 	SetModified();
811     return true;
812 }
813 
814 bool SwDoc::AppendTxtNode( SwPosition& rPos )
815 {
816     // create new node before EndOfContent
817     SwTxtNode * pCurNode = rPos.nNode.GetNode().GetTxtNode();
818 	if( !pCurNode )
819 	{
820 		// dann kann ja einer angelegt werden!
821 		SwNodeIndex aIdx( rPos.nNode, 1 );
822 		pCurNode = GetNodes().MakeTxtNode( aIdx,
823 						GetTxtCollFromPool( RES_POOLCOLL_STANDARD ));
824 	}
825 	else
826 		pCurNode = (SwTxtNode*)pCurNode->AppendNode( rPos );
827 
828 	rPos.nNode++;
829 	rPos.nContent.Assign( pCurNode, 0 );
830 
831     if (GetIDocumentUndoRedo().DoesUndo())
832     {
833         GetIDocumentUndoRedo().AppendUndo( new SwUndoInsert( rPos.nNode ) );
834     }
835 
836 	if( IsRedlineOn() || (!IsIgnoreRedline() && pRedlineTbl->Count() ))
837 	{
838 		SwPaM aPam( rPos );
839 		aPam.SetMark();
840 		aPam.Move( fnMoveBackward );
841 		if( IsRedlineOn() )
842 			AppendRedline( new SwRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
843 		else
844 			SplitRedline( aPam );
845 	}
846 
847 	SetModified();
848 	return sal_True;
849 }
850 
851 bool SwDoc::InsertString( const SwPaM &rRg, const String &rStr,
852         const enum InsertFlags nInsertMode )
853 {
854     if (GetIDocumentUndoRedo().DoesUndo())
855     {
856         GetIDocumentUndoRedo().ClearRedo(); // AppendUndo not always called!
857     }
858 
859     const SwPosition& rPos = *rRg.GetPoint();
860 
861 	if( pACEWord )					// Aufnahme in die Autokorrektur
862 	{
863 		if( 1 == rStr.Len() && pACEWord->IsDeleted() )
864         {
865             pACEWord->CheckChar( rPos, rStr.GetChar( 0 ) );
866         }
867 		delete pACEWord, pACEWord = 0;
868 	}
869 
870     SwTxtNode *const pNode = rPos.nNode.GetNode().GetTxtNode();
871 	if(!pNode)
872     {
873         return false;
874     }
875 
876 	SwDataChanged aTmp( rRg, 0 );
877 
878     if (!GetIDocumentUndoRedo().DoesUndo() ||
879         !GetIDocumentUndoRedo().DoesGroupUndo())
880     {
881         pNode->InsertText( rStr, rPos.nContent, nInsertMode );
882 
883         if (GetIDocumentUndoRedo().DoesUndo())
884         {
885             SwUndoInsert * const pUndo( new SwUndoInsert(
886                 rPos.nNode, rPos.nContent.GetIndex(), rStr.Len(), nInsertMode));
887             GetIDocumentUndoRedo().AppendUndo(pUndo);
888         }
889     }
890     else
891 	{			// ist Undo und Gruppierung eingeschaltet, ist alles anders !
892         SwUndoInsert * pUndo = NULL; // #111827#
893 
894         // don't group the start if hints at the start should be expanded
895         if (!(nInsertMode & IDocumentContentOperations::INS_FORCEHINTEXPAND))
896         // -> #111827#
897         {
898             SwUndo *const pLastUndo = GetUndoManager().GetLastUndo();
899             SwUndoInsert *const pUndoInsert(
900                 dynamic_cast<SwUndoInsert *>(pLastUndo) );
901             if (pUndoInsert && pUndoInsert->CanGrouping(rPos))
902             {
903                 pUndo = pUndoInsert;
904             }
905         }
906         // <- #111827#
907 
908         CharClass const& rCC = GetAppCharClass();
909         xub_StrLen nInsPos = rPos.nContent.GetIndex();
910 
911         if (!pUndo)
912 		{
913             pUndo = new SwUndoInsert( rPos.nNode, nInsPos, 0, nInsertMode,
914 							!rCC.isLetterNumeric( rStr, 0 ) );
915             GetIDocumentUndoRedo().AppendUndo( pUndo );
916         }
917 
918         pNode->InsertText( rStr, rPos.nContent, nInsertMode );
919 
920 		for( xub_StrLen i = 0; i < rStr.Len(); ++i )
921 		{
922 			nInsPos++;
923 			// wenn CanGrouping() sal_True returnt, ist schon alles erledigt
924 			if( !pUndo->CanGrouping( rStr.GetChar( i ) ))
925 			{
926                 pUndo = new SwUndoInsert( rPos.nNode, nInsPos, 1, nInsertMode,
927 							!rCC.isLetterNumeric( rStr, i ) );
928                 GetIDocumentUndoRedo().AppendUndo( pUndo );
929             }
930         }
931     }
932 
933 	if( IsRedlineOn() || (!IsIgnoreRedline() && pRedlineTbl->Count() ))
934 	{
935         SwPaM aPam( rPos.nNode, aTmp.GetCntnt(),
936                     rPos.nNode, rPos.nContent.GetIndex());
937 		if( IsRedlineOn() )
938         {
939             AppendRedline(
940                 new SwRedline( nsRedlineType_t::REDLINE_INSERT, aPam ), true);
941         }
942         else
943         {
944 			SplitRedline( aPam );
945         }
946 	}
947 
948 	SetModified();
949     return true;
950 }
951 
952 SwFlyFrmFmt* SwDoc::_InsNoTxtNode( const SwPosition& rPos, SwNoTxtNode* pNode,
953 									const SfxItemSet* pFlyAttrSet,
954 									const SfxItemSet* pGrfAttrSet,
955 									SwFrmFmt* pFrmFmt)
956 {
957 	SwFlyFrmFmt *pFmt = 0;
958 	if( pNode )
959 	{
960         pFmt = _MakeFlySection( rPos, *pNode, FLY_AT_PARA,
961 								pFlyAttrSet, pFrmFmt );
962 		if( pGrfAttrSet )
963 			pNode->SetAttr( *pGrfAttrSet );
964 	}
965 	return pFmt;
966 }
967 
968 SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg,
969 							const String& rGrfName,
970 							const String& rFltName,
971 							const Graphic* pGraphic,
972 							const SfxItemSet* pFlyAttrSet,
973 							const SfxItemSet* pGrfAttrSet,
974 							SwFrmFmt* pFrmFmt )
975 {
976 	if( !pFrmFmt )
977 		pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC );
978     SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode(
979 							SwNodeIndex( GetNodes().GetEndOfAutotext() ),
980 							rGrfName, rFltName, pGraphic,
981 							pDfltGrfFmtColl );
982     SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode,
983 							pFlyAttrSet, pGrfAttrSet, pFrmFmt );
984     pSwGrfNode->onGraphicChanged();
985     return pSwFlyFrmFmt;
986 }
987 SwFlyFrmFmt* SwDoc::Insert( const SwPaM &rRg, const GraphicObject& rGrfObj,
988 							const SfxItemSet* pFlyAttrSet,
989 							const SfxItemSet* pGrfAttrSet,
990 							SwFrmFmt* pFrmFmt )
991 {
992 	if( !pFrmFmt )
993 		pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_GRAPHIC );
994     SwGrfNode* pSwGrfNode = GetNodes().MakeGrfNode(
995 							SwNodeIndex( GetNodes().GetEndOfAutotext() ),
996 							rGrfObj, pDfltGrfFmtColl );
997 	SwFlyFrmFmt* pSwFlyFrmFmt = _InsNoTxtNode( *rRg.GetPoint(), pSwGrfNode,
998 							pFlyAttrSet, pGrfAttrSet, pFrmFmt );
999     pSwGrfNode->onGraphicChanged();
1000     return pSwFlyFrmFmt;
1001 }
1002 
1003 SwFlyFrmFmt* SwDoc::Insert(const SwPaM &rRg, const svt::EmbeddedObjectRef& xObj,
1004 						const SfxItemSet* pFlyAttrSet,
1005 						const SfxItemSet* pGrfAttrSet,
1006 						SwFrmFmt* pFrmFmt )
1007 {
1008 	if( !pFrmFmt )
1009 	{
1010 		sal_uInt16 nId = RES_POOLFRM_OLE;
1011         SvGlobalName aClassName( xObj->getClassID() );
1012         if (SotExchange::IsMath(aClassName))
1013             nId = RES_POOLFRM_FORMEL;
1014 
1015 		pFrmFmt = GetFrmFmtFromPool( nId );
1016 	}
1017 	return _InsNoTxtNode( *rRg.GetPoint(), GetNodes().MakeOLENode(
1018 							SwNodeIndex( GetNodes().GetEndOfAutotext() ),
1019                             xObj,
1020 							pDfltGrfFmtColl ),
1021 							pFlyAttrSet, pGrfAttrSet,
1022 							pFrmFmt );
1023 }
1024 
1025 SwFlyFrmFmt* SwDoc::InsertOLE(const SwPaM &rRg, const String& rObjName,
1026 						sal_Int64 nAspect,
1027 						const SfxItemSet* pFlyAttrSet,
1028 						const SfxItemSet* pGrfAttrSet,
1029 						SwFrmFmt* pFrmFmt )
1030 {
1031 	if( !pFrmFmt )
1032 		pFrmFmt = GetFrmFmtFromPool( RES_POOLFRM_OLE );
1033 
1034 	return _InsNoTxtNode( *rRg.GetPoint(),
1035 							GetNodes().MakeOLENode(
1036 								SwNodeIndex( GetNodes().GetEndOfAutotext() ),
1037 								rObjName,
1038 								nAspect,
1039 								pDfltGrfFmtColl,
1040 								0 ),
1041 							pFlyAttrSet, pGrfAttrSet,
1042 							pFrmFmt );
1043 }
1044 
1045 /*************************************************************************
1046 |*				  SwDoc::GetFldType()
1047 |*	  Beschreibung: liefert den am Doc eingerichteten Feldtypen zurueck
1048 *************************************************************************/
1049 
1050 SwFieldType *SwDoc::GetSysFldType( const sal_uInt16 eWhich ) const
1051 {
1052 	for( sal_uInt16 i = 0; i < INIT_FLDTYPES; ++i )
1053 		if( eWhich == (*pFldTypes)[i]->Which() )
1054 			return (*pFldTypes)[i];
1055 	return 0;
1056 }
1057 /*************************************************************************
1058  *			   void SetDocStat( const SwDocStat& rStat );
1059  *************************************************************************/
1060 
1061 void SwDoc::SetDocStat( const SwDocStat& rStat )
1062 {
1063 	*pDocStat = rStat;
1064 }
1065 
1066 const SwDocStat& SwDoc::GetDocStat() const
1067 {
1068 	return *pDocStat;
1069 }
1070 
1071 /*************************************************************************/
1072 
1073 
1074 struct _PostItFld : public _SetGetExpFld
1075 {
1076     _PostItFld( const SwNodeIndex& rNdIdx, const SwTxtFld* pFld,  const SwIndex* pIdx = 0 )
1077         : _SetGetExpFld( rNdIdx, pFld, pIdx ) {}
1078 
1079     sal_uInt16 GetPageNo( const StringRangeEnumerator &rRangeEnum,
1080             const std::set< sal_Int32 > &rPossiblePages,
1081             sal_uInt16& rVirtPgNo, sal_uInt16& rLineNo );
1082 
1083     SwPostItField* GetPostIt() const
1084     {
1085         return (SwPostItField*) GetTxtFld()->GetFmtFld().GetField();
1086     }
1087 };
1088 
1089 
1090 sal_uInt16 _PostItFld::GetPageNo(
1091     const StringRangeEnumerator &rRangeEnum,
1092     const std::set< sal_Int32 > &rPossiblePages,
1093     /* out */ sal_uInt16& rVirtPgNo, /* out */ sal_uInt16& rLineNo )
1094 {
1095     //Problem: Wenn ein PostItFld in einem Node steht, der von mehr als
1096     //einer Layout-Instanz repraesentiert wird, steht die Frage im Raum,
1097     //ob das PostIt nur ein- oder n-mal gedruck werden soll.
1098     //Wahrscheinlich nur einmal, als Seitennummer soll hier keine Zufaellige
1099     //sondern die des ersten Auftretens des PostIts innerhalb des selektierten
1100     //Bereichs ermittelt werden.
1101     rVirtPgNo = 0;
1102     sal_uInt16 nPos = GetCntnt();
1103     SwIterator<SwTxtFrm,SwTxtNode> aIter( GetTxtFld()->GetTxtNode() );
1104     for( SwTxtFrm* pFrm = aIter.First(); pFrm;  pFrm = aIter.Next() )
1105     {
1106         if( pFrm->GetOfst() > nPos ||
1107             (pFrm->HasFollow() && pFrm->GetFollow()->GetOfst() <= nPos) )
1108             continue;
1109         sal_uInt16 nPgNo = pFrm->GetPhyPageNum();
1110         if( rRangeEnum.hasValue( nPgNo, &rPossiblePages ))
1111         {
1112             rLineNo = (sal_uInt16)(pFrm->GetLineCount( nPos ) +
1113                       pFrm->GetAllLines() - pFrm->GetThisLines());
1114             rVirtPgNo = pFrm->GetVirtPageNum();
1115             return nPgNo;
1116         }
1117     }
1118     return 0;
1119 }
1120 
1121 
1122 bool lcl_GetPostIts(
1123     IDocumentFieldsAccess* pIDFA,
1124     _SetGetExpFlds * pSrtLst )
1125 {
1126     bool bHasPostIts = false;
1127 
1128     SwFieldType* pFldType = pIDFA->GetSysFldType( RES_POSTITFLD );
1129     DBG_ASSERT( pFldType, "kein PostItType ? ");
1130 
1131     if( pFldType->GetDepends() )
1132     {
1133         // Modify-Object gefunden, trage alle Felder ins Array ein
1134         SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType );
1135         const SwTxtFld* pTxtFld;
1136         for( SwFmtFld* pFld = aIter.First(); pFld;  pFld = aIter.Next() )
1137         {
1138             if( 0 != ( pTxtFld = pFld->GetTxtFld() ) &&
1139                 pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
1140             {
1141                 bHasPostIts = true;
1142                 if (pSrtLst)
1143                 {
1144                     SwNodeIndex aIdx( pTxtFld->GetTxtNode() );
1145                     _PostItFld* pNew = new _PostItFld( aIdx, pTxtFld );
1146                     pSrtLst->Insert( pNew );
1147                 }
1148                 else
1149                     break;  // we just wanted to check for the existence of postits ...
1150             }
1151         }
1152     }
1153 
1154     return bHasPostIts;
1155 }
1156 
1157 
1158 static void lcl_FormatPostIt(
1159     IDocumentContentOperations* pIDCO,
1160     SwPaM& aPam,
1161     SwPostItField* pField,
1162     bool bNewPage, bool bIsFirstPostIt,
1163     sal_uInt16 nPageNo, sal_uInt16 nLineNo )
1164 {
1165     static char __READONLY_DATA sTmp[] = " : ";
1166 
1167     DBG_ASSERT( ViewShell::GetShellRes(), "missing ShellRes" );
1168 
1169     if (bNewPage)
1170     {
1171         pIDCO->InsertPoolItem( aPam, SvxFmtBreakItem( SVX_BREAK_PAGE_AFTER, RES_BREAK ), 0 );
1172         pIDCO->SplitNode( *aPam.GetPoint(), false );
1173     }
1174     else if (!bIsFirstPostIt)
1175     {
1176         // add an empty line between different notes
1177         pIDCO->SplitNode( *aPam.GetPoint(), false );
1178         pIDCO->SplitNode( *aPam.GetPoint(), false );
1179     }
1180 
1181     String aStr( ViewShell::GetShellRes()->aPostItPage );
1182     aStr.AppendAscii(sTmp);
1183 
1184     aStr += XubString::CreateFromInt32( nPageNo );
1185     aStr += ' ';
1186     if( nLineNo )
1187     {
1188         aStr += ViewShell::GetShellRes()->aPostItLine;
1189         aStr.AppendAscii(sTmp);
1190         aStr += XubString::CreateFromInt32( nLineNo );
1191         aStr += ' ';
1192     }
1193     aStr += ViewShell::GetShellRes()->aPostItAuthor;
1194     aStr.AppendAscii(sTmp);
1195     aStr += pField->GetPar1();
1196     aStr += ' ';
1197 	SvtSysLocale aSysLocale;
1198     aStr += /*(LocaleDataWrapper&)*/aSysLocale.GetLocaleData().getDate( pField->GetDate() );
1199     pIDCO->InsertString( aPam, aStr );
1200 
1201     pIDCO->SplitNode( *aPam.GetPoint(), false );
1202     aStr = pField->GetPar2();
1203 #if defined( WNT ) || defined( PM2 )
1204     // Bei Windows und Co alle CR rausschmeissen
1205     aStr.EraseAllChars( '\r' );
1206 #endif
1207     pIDCO->InsertString( aPam, aStr );
1208 }
1209 
1210 
1211 // provide the paper tray to use according to the page style in use,
1212 // but do that only if the respective item is NOT just the default item
1213 static sal_Int32 lcl_GetPaperBin( const SwPageFrm *pStartFrm )
1214 {
1215     sal_Int32 nRes = -1;
1216 
1217     const SwFrmFmt &rFmt = pStartFrm->GetPageDesc()->GetMaster();
1218     const SfxPoolItem *pItem = NULL;
1219     SfxItemState eState = rFmt.GetItemState( RES_PAPER_BIN, sal_False, &pItem );
1220     const SvxPaperBinItem *pPaperBinItem = dynamic_cast< const SvxPaperBinItem * >(pItem);
1221     if (eState > SFX_ITEM_DEFAULT && pPaperBinItem)
1222         nRes = pPaperBinItem->GetValue();
1223 
1224     return nRes;
1225 }
1226 
1227 
1228 void SwDoc::CalculatePagesForPrinting(
1229     const SwRootFrm& rLayout,
1230     /* out */ SwRenderData &rData,
1231     const SwPrintUIOptions &rOptions,
1232     bool bIsPDFExport,
1233     sal_Int32 nDocPageCount )
1234 {
1235     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
1236     const bool bPrintSelection = nContent == 2;
1237 
1238     // properties to take into account when calcualting the set of pages
1239     // (PDF export UI does not allow for selecting left or right pages only)
1240     bool bPrintLeftPages    = bIsPDFExport ? true : rOptions.IsPrintLeftPages();
1241     bool bPrintRightPages   = bIsPDFExport ? true : rOptions.IsPrintRightPages();
1242     // #i103700# printing selections should not allow for automatic inserting empty pages
1243     bool bPrintEmptyPages   = bPrintSelection ? false : rOptions.IsPrintEmptyPages( bIsPDFExport );
1244 
1245     Range aPages( 1, nDocPageCount );
1246 
1247     MultiSelection aMulti( aPages );
1248     aMulti.SetTotalRange( Range( 0, RANGE_MAX ) );
1249     aMulti.Select( aPages );
1250 
1251     const SwPageFrm *pStPage  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
1252     const SwFrm     *pEndPage = pStPage;
1253 
1254     sal_uInt16 nFirstPageNo = 0;
1255     sal_uInt16 nLastPageNo  = 0;
1256     sal_uInt16 nPageNo      = 1;
1257 
1258     for( sal_uInt16 i = 1; i <= (sal_uInt16)aPages.Max(); ++i )
1259     {
1260         if( i < (sal_uInt16)aPages.Min() )
1261         {
1262             if( !pStPage->GetNext() )
1263                 break;
1264             pStPage = (SwPageFrm*)pStPage->GetNext();
1265             pEndPage= pStPage;
1266         }
1267         else if( i == (sal_uInt16)aPages.Min() )
1268         {
1269             nFirstPageNo = i;
1270             nLastPageNo = nFirstPageNo;
1271             if( !pStPage->GetNext() || (i == (sal_uInt16)aPages.Max()) )
1272                 break;
1273             pEndPage = pStPage->GetNext();
1274         }
1275         else if( i > (sal_uInt16)aPages.Min() )
1276         {
1277             nLastPageNo = i;
1278             if( !pEndPage->GetNext() || (i == (sal_uInt16)aPages.Max()) )
1279                 break;
1280             pEndPage = pEndPage->GetNext();
1281         }
1282     }
1283 
1284     DBG_ASSERT( nFirstPageNo, "first page not found!  Should not happen!" );
1285     if (nFirstPageNo)
1286     {
1287 // HACK: Hier muss von der MultiSelection noch eine akzeptable Moeglichkeit
1288 // geschaffen werden, alle Seiten von Seite x an zu deselektieren.
1289 // Z.B. durch SetTotalRange ....
1290 
1291 //              aMulti.Select( Range( nLastPageNo+1, SELECTION_MAX ), sal_False );
1292         MultiSelection aTmpMulti( Range( 1, nLastPageNo ) );
1293         long nTmpIdx = aMulti.FirstSelected();
1294         static long nEndOfSelection = SFX_ENDOFSELECTION;
1295         while ( nEndOfSelection != nTmpIdx && nTmpIdx <= long(nLastPageNo) )
1296         {
1297             aTmpMulti.Select( nTmpIdx );
1298             nTmpIdx = aMulti.NextSelected();
1299         }
1300         aMulti = aTmpMulti;
1301 // Ende des HACKs
1302 
1303         nPageNo = nFirstPageNo;
1304 
1305         std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
1306         std::set< sal_Int32 > &rValidPages = rData.GetValidPagesSet();
1307         std::map< sal_Int32, const SwPageFrm * > &rValidStartFrms = rData.GetValidStartFrames();
1308         rValidPages.clear();
1309         rValidStartFrms.clear();
1310         while ( pStPage )
1311         {
1312             const sal_Bool bRightPg = pStPage->OnRightPage();
1313             if ( aMulti.IsSelected( nPageNo ) &&
1314                 ( (bRightPg && bPrintRightPages) ||
1315                     (!bRightPg && bPrintLeftPages) ) )
1316             {
1317                 // --> FME 2005-12-12 #b6354161# Feature - Print empty pages
1318                 if ( bPrintEmptyPages || pStPage->Frm().Height() )
1319                 // <--
1320                 {
1321                     rValidPages.insert( nPageNo );
1322                     rValidStartFrms[ nPageNo ] = pStPage;
1323 
1324                     rPrinterPaperTrays[ nPageNo ] = lcl_GetPaperBin( pStPage );
1325                 }
1326             }
1327 
1328             if ( pStPage == pEndPage )
1329             {
1330                 pStPage = 0;
1331             }
1332             else
1333             {   ++nPageNo;
1334                 pStPage = (SwPageFrm*)pStPage->GetNext();
1335             }
1336         }
1337     }
1338 
1339 
1340     //
1341     // now that we have identified the valid pages for printing according
1342     // to the print settings we need to get the PageRange to use and
1343     // use both results to get the actual pages to be printed
1344     // (post-it settings need to be taken into account later on!)
1345     //
1346 
1347     // get PageRange value to use
1348     OUString aPageRange;
1349     // --> PL, OD #i116085# - adjusting fix for i113919
1350 //    if (bIsPDFExport)
1351 //    {
1352 //        aPageRange = rOptions.getStringValue( "PageRange", OUString() );
1353 //    }
1354 //    else
1355     if ( !bIsPDFExport )
1356     // <--
1357     {
1358         // PageContent :
1359         // 0 -> print all pages (default if aPageRange is empty)
1360         // 1 -> print range according to PageRange
1361         // 2 -> print selection
1362         if (1 == nContent)
1363             aPageRange = rOptions.getStringValue( "PageRange", OUString() );
1364         if (2 == nContent)
1365         {
1366             // note that printing selections is actually implemented by copying
1367             // the selection to a new temporary document and printing all of that one.
1368             // Thus for Writer "PrintContent" must never be 2.
1369             // See SwXTextDocument::GetRenderDoc for evaluating if a selection is to be
1370             // printed and for creating the temporary document.
1371         }
1372 
1373         // please note
1374     }
1375     if (aPageRange.getLength() == 0)    // empty string -> print all
1376     {
1377         // set page range to print to 'all pages'
1378         aPageRange = OUString::valueOf( (sal_Int32)1 );
1379         aPageRange += OUString::valueOf( (sal_Unicode)'-');
1380         aPageRange += OUString::valueOf( nDocPageCount );
1381     }
1382     rData.SetPageRange( aPageRange );
1383 
1384     // get vector of pages to print according to PageRange and valid pages set from above
1385     // (result may be an empty vector, for example if the range string is not correct)
1386     StringRangeEnumerator::getRangesFromString(
1387             aPageRange, rData.GetPagesToPrint(),
1388             1, nDocPageCount, 0, &rData.GetValidPagesSet() );
1389 }
1390 
1391 
1392 void SwDoc::UpdatePagesForPrintingWithPostItData(
1393     /* out */ SwRenderData &rData,
1394     const SwPrintUIOptions &rOptions,
1395     bool /*bIsPDFExport*/,
1396     sal_Int32 nDocPageCount )
1397 {
1398 
1399     sal_Int16 nPostItMode = (sal_Int16) rOptions.getIntValue( "PrintAnnotationMode", 0 );
1400     DBG_ASSERT(nPostItMode == POSTITS_NONE || rData.HasPostItData(),
1401             "print post-its without post-it data?" );
1402     const sal_uInt16 nPostItCount = rData.HasPostItData() ? rData.m_pPostItFields->Count() : 0;
1403     if (nPostItMode != POSTITS_NONE && nPostItCount > 0)
1404     {
1405         SET_CURR_SHELL( rData.m_pPostItShell );
1406 
1407         // clear document and move to end of it
1408         SwPaM aPam( rData.m_pPostItDoc->GetNodes().GetEndOfContent() );
1409         aPam.Move( fnMoveBackward, fnGoDoc );
1410         aPam.SetMark();
1411         aPam.Move( fnMoveForward, fnGoDoc );
1412         rData.m_pPostItDoc->DeleteRange( aPam );
1413 
1414         const StringRangeEnumerator aRangeEnum( rData.GetPageRange(), 1, nDocPageCount, 0 );
1415 
1416         // For mode POSTITS_ENDPAGE:
1417         // maps a physical page number to the page number in post-it document that holds
1418         // the first post-it for that physical page . Needed to relate the correct start frames
1419         // from the post-it doc to the physical page of the document
1420         std::map< sal_Int32, sal_Int32 >  aPostItLastStartPageNum;
1421 
1422         // add all post-its on valid pages within the the page range to the
1423         // temporary post-it document.
1424         // Since the array of post-it fileds is sorted by page and line number we will
1425         // already get them in the correct order
1426         sal_uInt16 nVirtPg = 0, nLineNo = 0, nLastPageNum = 0, nPhyPageNum = 0;
1427         bool bIsFirstPostIt = true;
1428         for (sal_uInt16 i = 0; i < nPostItCount; ++i)
1429         {
1430             _PostItFld& rPostIt = (_PostItFld&)*(*rData.m_pPostItFields)[ i ];
1431             nLastPageNum = nPhyPageNum;
1432             nPhyPageNum = rPostIt.GetPageNo(
1433                     aRangeEnum, rData.GetValidPagesSet(), nVirtPg, nLineNo );
1434             if (nPhyPageNum)
1435             {
1436                 // need to insert a page break?
1437                 // In POSTITS_ENDPAGE mode for each document page the following
1438                 // post-it page needs to start on a new page
1439                 const bool bNewPage = nPostItMode == POSTITS_ENDPAGE &&
1440                         !bIsFirstPostIt && nPhyPageNum != nLastPageNum;
1441 
1442                 lcl_FormatPostIt( rData.m_pPostItShell->GetDoc(), aPam,
1443                         rPostIt.GetPostIt(), bNewPage, bIsFirstPostIt, nVirtPg, nLineNo );
1444                 bIsFirstPostIt = false;
1445 
1446                 if (nPostItMode == POSTITS_ENDPAGE)
1447                 {
1448                     // get the correct number of current pages for the post-it document
1449                     rData.m_pPostItShell->CalcLayout();
1450                     const sal_Int32 nPages = rData.m_pPostItShell->GetPageCount();
1451                     aPostItLastStartPageNum[ nPhyPageNum ] = nPages;
1452                 }
1453             }
1454         }
1455 
1456         // format post-it doc to get correct number of pages
1457         rData.m_pPostItShell->CalcLayout();
1458         const sal_Int32 nPostItDocPageCount = rData.m_pPostItShell->GetPageCount();
1459 
1460         if (nPostItMode == POSTITS_ONLY || nPostItMode == POSTITS_ENDDOC)
1461         {
1462             // now add those post-it pages to the vector of pages to print
1463             // or replace them if only post-its should be printed
1464 
1465             rData.GetPostItStartFrames().clear();
1466             if (nPostItMode == POSTITS_ENDDOC)
1467             {
1468                 // set all values up to number of pages to print currently known to NULL,
1469                 // meaning none of the pages currently in the vector is from the
1470                 // post-it document, they are the documents pages.
1471                 rData.GetPostItStartFrames().resize( rData.GetPagesToPrint().size() );
1472             }
1473             else if (nPostItMode == POSTITS_ONLY)
1474             {
1475                 // no document page to be printed
1476                 rData.GetPagesToPrint().clear();
1477             }
1478 
1479             // now we just need to add the post-it pages to be printed to the end
1480             // of the vector of pages to print and keep the GetValidStartFrames
1481             // data conform with it
1482             sal_Int32 nPageNum = 0;
1483             const SwPageFrm * pPageFrm = (SwPageFrm*)rData.m_pPostItShell->GetLayout()->Lower();
1484             while( pPageFrm && nPageNum < nPostItDocPageCount )
1485             {
1486                 DBG_ASSERT( pPageFrm, "Empty page frame. How are we going to print this?" );
1487                 ++nPageNum;
1488                 rData.GetPagesToPrint().push_back( 0 );  // a page number of 0 indicates this page is from the post-it doc
1489                 DBG_ASSERT( pPageFrm, "pPageFrm is NULL!" );
1490                 rData.GetPostItStartFrames().push_back( pPageFrm );
1491                 pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
1492             }
1493             DBG_ASSERT( nPageNum == nPostItDocPageCount, "unexpected number of pages" );
1494         }
1495         else if (nPostItMode == POSTITS_ENDPAGE)
1496         {
1497             // the next step is to find all the start frames from the post-it
1498             // document that should be printed for a given physical page of the document
1499             std::map< sal_Int32, std::vector< const SwPageFrm * > > aPhysPageToPostItFrames;
1500 
1501             // ... thus, first collect all post-it doc start frames in a vector
1502             sal_Int32 nPostItPageNum = 0;
1503             std::vector< const SwPageFrm * > aAllPostItStartFrames;
1504             const SwPageFrm * pPageFrm = (SwPageFrm*)rData.m_pPostItShell->GetLayout()->Lower();
1505             while( pPageFrm && sal_Int32(aAllPostItStartFrames.size()) < nPostItDocPageCount )
1506             {
1507                 DBG_ASSERT( pPageFrm, "Empty page frame. How are we going to print this?" );
1508                 ++nPostItPageNum;
1509                 aAllPostItStartFrames.push_back( pPageFrm );
1510                 pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
1511             }
1512             DBG_ASSERT( sal_Int32(aAllPostItStartFrames.size()) == nPostItDocPageCount,
1513                     "unexpected number of frames; does not match number of pages" );
1514 
1515             // get a map that holds all post-it frames to be printed for a
1516             // given physical page from the document
1517             sal_Int32 nLastStartPageNum = 0;
1518             std::map< sal_Int32, sal_Int32 >::const_iterator  aIt;
1519             for (aIt = aPostItLastStartPageNum.begin();  aIt != aPostItLastStartPageNum.end();  ++aIt)
1520             {
1521                 const sal_Int32 nFrames = aIt->second - nLastStartPageNum;
1522                 const sal_Int32 nFirstStartPageNum = aIt == aPostItLastStartPageNum.begin() ?
1523                         1 : aIt->second - nFrames + 1;
1524                 DBG_ASSERT( 1 <= nFirstStartPageNum && nFirstStartPageNum <= nPostItDocPageCount,
1525                         "page number for first frame out of range" );
1526                 std::vector<  const SwPageFrm * > aStartFrames;
1527                 for (sal_Int32 i = 0; i < nFrames; ++i)
1528                 {
1529                     const sal_Int32 nIdx = nFirstStartPageNum - 1 + i;   // -1 because lowest page num is 1
1530                     DBG_ASSERT( 0 <= nIdx && nIdx < sal_Int32(aAllPostItStartFrames.size()),
1531                             "index out of range" );
1532                     aStartFrames.push_back( aAllPostItStartFrames[ nIdx ] );
1533                 }
1534                 aPhysPageToPostItFrames[ aIt->first /* phys page num */ ] = aStartFrames;
1535                 nLastStartPageNum = aIt->second;
1536             }
1537 
1538 
1539             // ok, now that aPhysPageToPostItFrames can give the start frames for all
1540             // post-it pages to be printed we need to merge those at the correct
1541             // position into the GetPagesToPrint vector and build and maintain the
1542             // GetValidStartFrames vector as well.
1543             // Since inserting a larger number of entries in the middle of a vector
1544             // isn't that efficient we will create new vectors by copying the required data
1545             std::vector< sal_Int32 >            aTmpPagesToPrint;
1546             std::vector< const SwPageFrm * >    aTmpPostItStartFrames;
1547             const size_t nNum = rData.GetPagesToPrint().size();
1548             for (size_t i = 0 ;  i < nNum;  ++i)
1549             {
1550                 // add the physical page to print from the document
1551                 const sal_Int32 nPhysPage = rData.GetPagesToPrint()[i];
1552                 aTmpPagesToPrint.push_back( nPhysPage );
1553                 aTmpPostItStartFrames.push_back( NULL );
1554 
1555                 // add the post-it document pages to print, i.e those
1556                 // post-it pages that have the data for the above physical page
1557                 const std::vector< const SwPageFrm * > &rPostItFrames = aPhysPageToPostItFrames[ nPhysPage ];
1558                 const size_t nPostItFrames = rPostItFrames.size();
1559                 for (size_t k = 0;  k < nPostItFrames;  ++k)
1560                 {
1561                     aTmpPagesToPrint.push_back( 0 );
1562                     aTmpPostItStartFrames.push_back( rPostItFrames[k] );
1563                 }
1564             }
1565 
1566             // finally we need to assign those vectors to the resulting ones.
1567             // swapping the data should be more efficient than assigning since
1568             // we won't need the temporary vectors anymore
1569             rData.GetPagesToPrint().swap( aTmpPagesToPrint );
1570             rData.GetPostItStartFrames().swap( aTmpPostItStartFrames );
1571         }
1572     }
1573 }
1574 
1575 
1576 void SwDoc::CalculatePagePairsForProspectPrinting(
1577     const SwRootFrm& rLayout,
1578     /* out */ SwRenderData &rData,
1579     const SwPrintUIOptions &rOptions,
1580     sal_Int32 nDocPageCount )
1581 {
1582     std::map< sal_Int32, sal_Int32 > &rPrinterPaperTrays = rData.GetPrinterPaperTrays();
1583     std::set< sal_Int32 > &rValidPagesSet = rData.GetValidPagesSet();
1584     std::map< sal_Int32, const SwPageFrm * > &rValidStartFrms = rData.GetValidStartFrames();
1585     std::vector< std::pair< sal_Int32, sal_Int32 > > &rPagePairs = rData.GetPagePairsForProspectPrinting();
1586 
1587     rPagePairs.clear();
1588     rValidPagesSet.clear();
1589     rValidStartFrms.clear();
1590 
1591     rtl::OUString aPageRange = rOptions.getStringValue( "PageRange", rtl::OUString() );
1592     // PageContent :
1593     // 0 -> print all pages (default if aPageRange is empty)
1594     // 1 -> print range according to PageRange
1595     // 2 -> print selection
1596     const sal_Int64 nContent = rOptions.getIntValue( "PrintContent", 0 );
1597     if (0 == nContent)
1598     {
1599         // set page range to print to 'all pages'
1600         aPageRange = OUString::valueOf( (sal_Int32)1 );
1601         aPageRange += OUString::valueOf( (sal_Unicode)'-');
1602         aPageRange += OUString::valueOf( nDocPageCount );
1603     }
1604     StringRangeEnumerator aRange( aPageRange, 1, nDocPageCount, 0 );
1605 
1606     if ( aRange.size() <= 0)
1607         return;
1608 
1609     const SwPageFrm *pStPage  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
1610     sal_Int32 i = 0;
1611     for ( i = 1; pStPage && i < nDocPageCount; ++i )
1612         pStPage = (SwPageFrm*)pStPage->GetNext();
1613     if ( !pStPage )          // dann wars das
1614         return;
1615 
1616     // currently for prospect printing all pages are valid to be printed
1617     // thus we add them all to the respective map and set for later use
1618     sal_Int32 nPageNum = 0;
1619     const SwPageFrm *pPageFrm  = dynamic_cast<const SwPageFrm*>( rLayout.Lower() );
1620     while( pPageFrm && nPageNum < nDocPageCount )
1621     {
1622         DBG_ASSERT( pPageFrm, "Empty page frame. How are we going to print this?" );
1623         ++nPageNum;
1624         rValidPagesSet.insert( nPageNum );
1625         rValidStartFrms[ nPageNum ] = pPageFrm;
1626         pPageFrm = (SwPageFrm*)pPageFrm->GetNext();
1627 
1628         rPrinterPaperTrays[ nPageNum ] = lcl_GetPaperBin( pStPage );
1629     }
1630     DBG_ASSERT( nPageNum == nDocPageCount, "unexpected number of pages" );
1631 
1632     // properties to take into account when calcualting the set of pages
1633     // Note: here bPrintLeftPages and bPrintRightPages refer to the (virtual) resulting pages
1634     //      of the prospect!
1635     bool bPrintLeftPages     = rOptions.IsPrintLeftPages();
1636     bool bPrintRightPages    = rOptions.IsPrintRightPages();
1637     bool bPrintProspectRTL = rOptions.getIntValue( "PrintProspectRTL",  0 ) ? true : false;
1638 
1639     // get pages for prospect printing according to the 'PageRange'
1640     // (duplicates and any order allowed!)
1641     std::vector< sal_Int32 > aPagesToPrint;
1642     StringRangeEnumerator::getRangesFromString(
1643             aPageRange, aPagesToPrint, 1, nDocPageCount, 0 );
1644 
1645     // now fill the vector for calculating the page pairs with the start frames
1646     // from the above obtained vector
1647     std::vector< const SwPageFrm * > aVec;
1648     for ( i = 0; i < sal_Int32(aPagesToPrint.size()); ++i)
1649     {
1650         const sal_Int32 nPage = aPagesToPrint[i];
1651         const SwPageFrm *pFrm = rValidStartFrms[ nPage ];
1652         aVec.push_back( pFrm );
1653     }
1654 
1655     // just one page is special ...
1656     if ( 1 == aVec.size() )
1657         aVec.insert( aVec.begin() + 1, 0 ); // insert a second empty page
1658     else
1659     {
1660         // now extend the number of pages to fit a multiple of 4
1661         // (4 'normal' pages are needed for a single prospect paper
1662         //  with back and front)
1663         while( aVec.size() & 3 )
1664             aVec.push_back( 0 );
1665     }
1666 
1667     // dann sorge mal dafuer, das alle Seiten in der richtigen
1668     // Reihenfolge stehen:
1669     sal_uInt16 nSPg = 0;
1670     sal_uInt32 nEPg = aVec.size();
1671     sal_uInt16 nStep = 1;
1672     if ( 0 == (nEPg & 1 ))      // ungerade gibt es nicht!
1673         --nEPg;
1674 
1675     if ( !bPrintLeftPages )
1676         ++nStep;
1677     else if ( !bPrintRightPages )
1678     {
1679         ++nStep;
1680         ++nSPg, --nEPg;
1681     }
1682 
1683     // the number of 'virtual' pages to be printed
1684     sal_Int32 nCntPage = (( nEPg - nSPg ) / ( 2 * nStep )) + 1;
1685 
1686     for ( sal_uInt16 nPrintCount = 0; nSPg < nEPg &&
1687             nPrintCount < nCntPage; ++nPrintCount )
1688     {
1689         pStPage = aVec[ nSPg ];
1690         const SwPageFrm* pNxtPage = nEPg < aVec.size() ? aVec[ nEPg ] : 0;
1691 
1692         short nRtlOfs = bPrintProspectRTL ? 1 : 0;
1693         if ( 0 == (( nSPg + nRtlOfs) & 1 ) )     // switch for odd number in LTR, even number in RTL
1694         {
1695             const SwPageFrm* pTmp = pStPage;
1696             pStPage = pNxtPage;
1697             pNxtPage = pTmp;
1698         }
1699 
1700         sal_Int32 nFirst = -1, nSecond = -1;
1701         for ( int nC = 0; nC < 2; ++nC )
1702         {
1703             sal_Int32 nPage = -1;
1704             if ( pStPage )
1705                 nPage = pStPage->GetPhyPageNum();
1706             if (nC == 0)
1707                 nFirst  = nPage;
1708             else
1709                 nSecond = nPage;
1710 
1711             pStPage = pNxtPage;
1712         }
1713         rPagePairs.push_back( std::pair< sal_Int32, sal_Int32 >(nFirst, nSecond) );
1714 
1715         nSPg = nSPg + nStep;
1716         nEPg = nEPg - nStep;
1717     }
1718     DBG_ASSERT( size_t(nCntPage) == rPagePairs.size(), "size mismatch for number of page pairs" );
1719 
1720     // luckily prospect printing does not make use of post-its so far,
1721     // thus we are done here.
1722 }
1723 
1724 /*************************************************************************
1725  *			  void UpdateDocStat( const SwDocStat& rStat );
1726  *************************************************************************/
1727 
1728 void SwDoc::UpdateDocStat( SwDocStat& rStat )
1729 {
1730 	if( rStat.bModified )
1731 	{
1732 		rStat.Reset();
1733 		rStat.nPara = 0;        // Default ist auf 1 !!
1734 		SwNode* pNd;
1735 
1736         for( sal_uLong i = GetNodes().Count(); i; )
1737         {
1738             switch( ( pNd = GetNodes()[ --i ])->GetNodeType() )
1739 			{
1740             case ND_TEXTNODE:
1741                 ((SwTxtNode*)pNd)->CountWords( rStat, 0, ((SwTxtNode*)pNd)->GetTxt().Len() );
1742                 break;
1743 			case ND_TABLENODE:		++rStat.nTbl;	break;
1744 			case ND_GRFNODE:		++rStat.nGrf;	break;
1745 			case ND_OLENODE:		++rStat.nOLE;	break;
1746 			case ND_SECTIONNODE:	break;
1747 			}
1748         }
1749 
1750         // #i93174#: notes contain paragraphs that are not nodes
1751         {
1752             SwFieldType * const pPostits( GetSysFldType(RES_POSTITFLD) );
1753             SwIterator<SwFmtFld,SwFieldType> aIter( *pPostits );
1754             for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld;  pFmtFld = aIter.Next() )
1755             {
1756                 if (pFmtFld->IsFldInDoc())
1757                 {
1758                     SwPostItField const * const pField(
1759                         static_cast<SwPostItField const*>(pFmtFld->GetField()));
1760                     rStat.nAllPara += pField->GetNumberOfParagraphs();
1761                 }
1762             }
1763         }
1764 
1765 		rStat.nPage 	= GetCurrentLayout() ? GetCurrentLayout()->GetPageNum() : 0;	//swmod 080218
1766 		rStat.bModified = sal_False;
1767 		SetDocStat( rStat );
1768 
1769 		com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aStat( rStat.nPage ? 7 : 6);
1770 		sal_Int32 n=0;
1771 		aStat[n].Name = ::rtl::OUString::createFromAscii("TableCount");
1772 		aStat[n++].Value <<= (sal_Int32)rStat.nTbl;
1773 		aStat[n].Name = ::rtl::OUString::createFromAscii("ImageCount");
1774 		aStat[n++].Value <<= (sal_Int32)rStat.nGrf;
1775 		aStat[n].Name = ::rtl::OUString::createFromAscii("ObjectCount");
1776 		aStat[n++].Value <<= (sal_Int32)rStat.nOLE;
1777 		if ( rStat.nPage )
1778 		{
1779 			aStat[n].Name = ::rtl::OUString::createFromAscii("PageCount");
1780 			aStat[n++].Value <<= (sal_Int32)rStat.nPage;
1781 		}
1782 		aStat[n].Name = ::rtl::OUString::createFromAscii("ParagraphCount");
1783 		aStat[n++].Value <<= (sal_Int32)rStat.nPara;
1784 		aStat[n].Name = ::rtl::OUString::createFromAscii("WordCount");
1785 		aStat[n++].Value <<= (sal_Int32)rStat.nWord;
1786 		aStat[n].Name = ::rtl::OUString::createFromAscii("CharacterCount");
1787 		aStat[n++].Value <<= (sal_Int32)rStat.nChar;
1788 
1789 		// For e.g. autotext documents there is no pSwgInfo (#i79945)
1790         SfxObjectShell * const pObjShell( GetDocShell() );
1791         if (pObjShell)
1792         {
1793             const uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
1794                 pObjShell->GetModel(), uno::UNO_QUERY_THROW);
1795             const uno::Reference<document::XDocumentProperties> xDocProps(
1796                 xDPS->getDocumentProperties());
1797             // #i96786#: do not set modified flag when updating statistics
1798             const bool bDocWasModified( IsModified() );
1799             const ModifyBlocker_Impl b(pObjShell);
1800             xDocProps->setDocumentStatistics(aStat);
1801             if (!bDocWasModified)
1802             {
1803                 ResetModified();
1804             }
1805         }
1806 
1807 		// event. Stat. Felder Updaten
1808 		SwFieldType *pType = GetSysFldType(RES_DOCSTATFLD);
1809 		pType->UpdateFlds();
1810 	}
1811 }
1812 
1813 
1814 // Dokument - Info
1815 
1816 void SwDoc::DocInfoChgd( )
1817 {
1818 	GetSysFldType( RES_DOCINFOFLD )->UpdateFlds();
1819 	GetSysFldType( RES_TEMPLNAMEFLD )->UpdateFlds();
1820 	SetModified();
1821 }
1822 
1823 	// returne zum Namen die im Doc gesetzte Referenz
1824 const SwFmtRefMark* SwDoc::GetRefMark( const String& rName ) const
1825 {
1826 	const SfxPoolItem* pItem;
1827 	sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
1828 	for( sal_uInt32 n = 0; n < nMaxItems; ++n )
1829 	{
1830 		if( 0 == (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n ) ))
1831 			continue;
1832 
1833 		const SwFmtRefMark* pFmtRef = (SwFmtRefMark*)pItem;
1834 		const SwTxtRefMark* pTxtRef = pFmtRef->GetTxtRefMark();
1835 		if( pTxtRef && &pTxtRef->GetTxtNode().GetNodes() == &GetNodes() &&
1836 			rName.Equals( pFmtRef->GetRefName() ) )
1837 			return pFmtRef;
1838 	}
1839 	return 0;
1840 }
1841 
1842 	// returne die RefMark per Index - fuer Uno
1843 const SwFmtRefMark* SwDoc::GetRefMark( sal_uInt16 nIndex ) const
1844 {
1845 	const SfxPoolItem* pItem;
1846 	const SwTxtRefMark* pTxtRef;
1847 	const SwFmtRefMark* pRet = 0;
1848 
1849 	sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
1850 	sal_uInt32 nCount = 0;
1851 	for( sal_uInt32 n = 0; n < nMaxItems; ++n )
1852 		if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
1853 			0 != (pTxtRef = ((SwFmtRefMark*)pItem)->GetTxtRefMark()) &&
1854 			&pTxtRef->GetTxtNode().GetNodes() == &GetNodes() )
1855 		{
1856 			if(nCount == nIndex)
1857 			{
1858 				pRet = (SwFmtRefMark*)pItem;
1859 				break;
1860 			}
1861 			nCount++;
1862 		}
1863    return pRet;
1864 }
1865 
1866 	// returne die Namen aller im Doc gesetzten Referenzen
1867 	//JP 24.06.96: Ist der ArrayPointer 0 dann returne nur, ob im Doc. eine
1868 	//				RefMark gesetzt ist
1869 	// OS 25.06.96: ab jetzt wird immer die Anzahl der Referenzen returnt
1870 sal_uInt16 SwDoc::GetRefMarks( SvStringsDtor* pNames ) const
1871 {
1872     const SfxPoolItem* pItem;
1873     const SwTxtRefMark* pTxtRef;
1874 
1875     const sal_uInt32 nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_REFMARK );
1876     sal_uInt16 nCount = 0;
1877     for( sal_uInt32 n = 0; n < nMaxItems; ++n )
1878         if( 0 != (pItem = GetAttrPool().GetItem2( RES_TXTATR_REFMARK, n )) &&
1879             0 != (pTxtRef = ((SwFmtRefMark*)pItem)->GetTxtRefMark()) &&
1880             &pTxtRef->GetTxtNode().GetNodes() == &GetNodes() )
1881         {
1882             if( pNames )
1883             {
1884                 String* pTmp = new String( ((SwFmtRefMark*)pItem)->GetRefName() );
1885                 pNames->Insert( pTmp, nCount );
1886             }
1887             ++nCount;
1888         }
1889 
1890     return nCount;
1891 }
1892 
1893 bool SwDoc::IsLoaded() const
1894 {
1895 	return mbLoaded;
1896 }
1897 
1898 bool SwDoc::IsUpdateExpFld() const
1899 {
1900 	return mbUpdateExpFld;
1901 }
1902 
1903 bool SwDoc::IsNewDoc() const
1904 {
1905 	return mbNewDoc;
1906 }
1907 
1908 bool SwDoc::IsPageNums() const
1909 {
1910   return mbPageNums;
1911 }
1912 
1913 void SwDoc::SetPageNums(bool b)
1914 {
1915 	mbPageNums = b;
1916 }
1917 
1918 void SwDoc::SetNewDoc(bool b)
1919 {
1920 	mbNewDoc = b;
1921 }
1922 
1923 void SwDoc::SetUpdateExpFldStat(bool b)
1924 {
1925 	mbUpdateExpFld = b;
1926 }
1927 
1928 void SwDoc::SetLoaded(bool b)
1929 {
1930 	mbLoaded = b;
1931 }
1932 
1933 bool SwDoc::IsModified() const
1934 {
1935 	return mbModified;
1936 }
1937 
1938 void SwDoc::SetModified()
1939 {
1940     // --> OD 2005-08-29 #125370#
1941     SwLayouter::ClearMovedFwdFrms( *this );
1942     SwLayouter::ClearObjsTmpConsiderWrapInfluence( *this );
1943     SwLayouter::ClearFrmsNotToWrap( *this );
1944     // <--
1945     // --> OD 2006-05-10 #i65250#
1946     SwLayouter::ClearMoveBwdLayoutInfo( *this );
1947     // <--
1948 	// dem Link wird der Status returnt, wie die Flags waren und werden
1949 	// 	Bit 0:	-> alter Zustand
1950 	//	Bit 1: 	-> neuer Zustand
1951 	long nCall = mbModified ? 3 : 2;
1952 	mbModified = sal_True;
1953 	pDocStat->bModified = sal_True;
1954 	if( aOle2Link.IsSet() )
1955 	{
1956 		mbInCallModified = sal_True;
1957 		aOle2Link.Call( (void*)nCall );
1958 		mbInCallModified = sal_False;
1959 	}
1960 
1961 	if( pACEWord && !pACEWord->IsDeleted() )
1962 		delete pACEWord, pACEWord = 0;
1963 }
1964 
1965 void SwDoc::ResetModified()
1966 {
1967 	// dem Link wird der Status returnt, wie die Flags waren und werden
1968 	// 	Bit 0:	-> alter Zustand
1969 	//	Bit 1: 	-> neuer Zustand
1970     long nCall = mbModified ? 1 : 0;
1971 	mbModified = sal_False;
1972     // If there is already a document statistic, we assume that
1973     // it is correct. In this case we reset the modified flag.
1974     if ( 0 != pDocStat->nChar )
1975         pDocStat->bModified = sal_False;
1976     GetIDocumentUndoRedo().SetUndoNoModifiedPosition();
1977 	if( nCall && aOle2Link.IsSet() )
1978 	{
1979 		mbInCallModified = sal_True;
1980 		aOle2Link.Call( (void*)nCall );
1981 		mbInCallModified = sal_False;
1982 	}
1983 }
1984 
1985 
1986 void SwDoc::ReRead( SwPaM& rPam, const String& rGrfName,
1987 					const String& rFltName, const Graphic* pGraphic,
1988 					const GraphicObject* pGrafObj )
1989 {
1990 	SwGrfNode *pGrfNd;
1991 	if( ( !rPam.HasMark()
1992 		 || rPam.GetPoint()->nNode.GetIndex() == rPam.GetMark()->nNode.GetIndex() )
1993 		 && 0 != ( pGrfNd = rPam.GetPoint()->nNode.GetNode().GetGrfNode() ) )
1994     {
1995         if (GetIDocumentUndoRedo().DoesUndo())
1996         {
1997             GetIDocumentUndoRedo().AppendUndo(new SwUndoReRead(rPam, *pGrfNd));
1998         }
1999 
2000 		// Weil nicht bekannt ist, ob sich die Grafik spiegeln laesst,
2001 		// immer das SpiegelungsAttribut zuruecksetzen
2002         if( RES_MIRROR_GRAPH_DONT != pGrfNd->GetSwAttrSet().
2003 												GetMirrorGrf().GetValue() )
2004 			pGrfNd->SetAttr( SwMirrorGrf() );
2005 
2006 		pGrfNd->ReRead( rGrfName, rFltName, pGraphic, pGrafObj, sal_True );
2007 		SetModified();
2008 	}
2009 }
2010 
2011 sal_Bool lcl_SpellAndGrammarAgain( const SwNodePtr& rpNd, void* pArgs )
2012 {
2013 	SwTxtNode *pTxtNode = (SwTxtNode*)rpNd->GetTxtNode();
2014 	sal_Bool bOnlyWrong = *(sal_Bool*)pArgs;
2015 	if( pTxtNode )
2016 	{
2017 		if( bOnlyWrong )
2018 		{
2019 			if( pTxtNode->GetWrong() &&
2020 				pTxtNode->GetWrong()->InvalidateWrong() )
2021                 pTxtNode->SetWrongDirty( true );
2022             if( pTxtNode->GetGrammarCheck() &&
2023                 pTxtNode->GetGrammarCheck()->InvalidateWrong() )
2024                 pTxtNode->SetGrammarCheckDirty( true );
2025 		}
2026 		else
2027 		{
2028             pTxtNode->SetWrongDirty( true );
2029 			if( pTxtNode->GetWrong() )
2030 				pTxtNode->GetWrong()->SetInvalid( 0, STRING_LEN );
2031             pTxtNode->SetGrammarCheckDirty( true );
2032             if( pTxtNode->GetGrammarCheck() )
2033                 pTxtNode->GetGrammarCheck()->SetInvalid( 0, STRING_LEN );
2034 		}
2035 	}
2036 	return sal_True;
2037 }
2038 
2039 sal_Bool lcl_CheckSmartTagsAgain( const SwNodePtr& rpNd, void*  )
2040 {
2041 	SwTxtNode *pTxtNode = (SwTxtNode*)rpNd->GetTxtNode();
2042 //	sal_Bool bOnlyWrong = *(sal_Bool*)pArgs;
2043 	if( pTxtNode )
2044 	{
2045         pTxtNode->SetSmartTagDirty( true );
2046         if( pTxtNode->GetSmartTags() )
2047         {
2048 //            if ( bOnlyWrong ) // only some smart tag types have been enabled or disabled
2049 //				pTxtNode->GetSmartTags()->SetInvalid( 0, STRING_LEN );
2050 //            else // smart tags all have been enabled or disabled
2051 				pTxtNode->SetSmartTags( NULL );
2052         }
2053 	}
2054 	return sal_True;
2055 }
2056 
2057 
2058 /*************************************************************************
2059  * 		SwDoc::SpellItAgainSam( sal_Bool bInvalid, sal_Bool bOnlyWrong )
2060  *
2061  * stoesst das Spelling im Idle-Handler wieder an.
2062  * Wird bInvalid als sal_True uebergeben, so werden zusaetzlich die WrongListen
2063  * an allen Nodes invalidiert und auf allen Seiten das SpellInvalid-Flag
2064  * gesetzt.
2065  * Mit bOnlyWrong kann man dann steuern, ob nur die Bereiche mit falschen
2066  * Woertern oder die kompletten Bereiche neu ueberprueft werden muessen.
2067  ************************************************************************/
2068 
2069 void SwDoc::SpellItAgainSam( sal_Bool bInvalid, sal_Bool bOnlyWrong, sal_Bool bSmartTags )
2070 {
2071 	std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();//swmod 080307
2072 	ASSERT( GetCurrentLayout(), "SpellAgain: Where's my RootFrm?" );
2073 	if( bInvalid )
2074 	{
2075 		std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::AllInvalidateSmartTagsOrSpelling),bSmartTags));//swmod 080305
2076 		std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::bind2nd(std::mem_fun(&SwRootFrm::SetNeedGrammarCheck), true) );
2077     	if ( bSmartTags )
2078             GetNodes().ForEach( lcl_CheckSmartTagsAgain, &bOnlyWrong );
2079         GetNodes().ForEach( lcl_SpellAndGrammarAgain, &bOnlyWrong );
2080 	}
2081 
2082 	std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));//swmod 080307
2083 }
2084 
2085 void SwDoc::InvalidateAutoCompleteFlag()
2086 {
2087 	SwRootFrm* pTmpRoot = GetCurrentLayout();
2088 	if( pTmpRoot )
2089 	{
2090 		std::set<SwRootFrm*> aAllLayouts = GetAllLayouts();
2091 		std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::AllInvalidateAutoCompleteWords));//swmod 080305
2092 		for( sal_uLong nNd = 1, nCnt = GetNodes().Count(); nNd < nCnt; ++nNd )
2093         {
2094             SwTxtNode* pTxtNode = GetNodes()[ nNd ]->GetTxtNode();
2095             if ( pTxtNode ) pTxtNode->SetAutoCompleteWordDirty( true );
2096         }
2097 
2098 		std::for_each( aAllLayouts.begin(), aAllLayouts.end(),std::mem_fun(&SwRootFrm::SetIdleFlags));//swmod 080228
2099 	}	//swmod 080219
2100 }
2101 
2102 const SwFmtINetFmt* SwDoc::FindINetAttr( const String& rName ) const
2103 {
2104 	const SwFmtINetFmt* pItem;
2105 	const SwTxtINetFmt* pTxtAttr;
2106 	const SwTxtNode* pTxtNd;
2107 	sal_uInt32 n, nMaxItems = GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
2108 	for( n = 0; n < nMaxItems; ++n )
2109 		if( 0 != (pItem = (SwFmtINetFmt*)GetAttrPool().GetItem2(
2110 			RES_TXTATR_INETFMT, n ) ) &&
2111 			pItem->GetName().Equals( rName ) &&
2112 			0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
2113 			0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) &&
2114 			&pTxtNd->GetNodes() == &GetNodes() )
2115 		{
2116 			return pItem;
2117 		}
2118 
2119 	return 0;
2120 }
2121 
2122 void SwDoc::Summary( SwDoc* pExtDoc, sal_uInt8 nLevel, sal_uInt8 nPara, sal_Bool bImpress )
2123 {
2124 	const SwOutlineNodes& rOutNds = GetNodes().GetOutLineNds();
2125 	if( pExtDoc && rOutNds.Count() )
2126 	{
2127 		sal_uInt16 i;
2128 		::StartProgress( STR_STATSTR_SUMMARY, 0, rOutNds.Count(), GetDocShell() );
2129 		SwNodeIndex aEndOfDoc( pExtDoc->GetNodes().GetEndOfContent(), -1 );
2130 		for( i = 0; i < rOutNds.Count(); ++i )
2131 		{
2132 			::SetProgressState( i, GetDocShell() );
2133             const sal_uLong nIndex = rOutNds[ i ]->GetIndex();
2134 			//sal_uInt8 nLvl = ((SwTxtNode*)GetNodes()[ nIndex ])->GetTxtColl()//#outline level,zhaojianwei
2135 						// ->GetOutlineLevel();
2136             const int nLvl = ((SwTxtNode*)GetNodes()[ nIndex ])->GetAttrOutlineLevel()-1;//<-end,zhaojianwei
2137 			if( nLvl > nLevel )
2138 				continue;
2139 			sal_uInt16 nEndOfs = 1;
2140 			sal_uInt8 nWish = nPara;
2141 			sal_uLong nNextOutNd = i + 1 < rOutNds.Count() ?
2142 				rOutNds[ i + 1 ]->GetIndex() : GetNodes().Count();
2143 			sal_Bool bKeep = sal_False;
2144 			while( ( nWish || bKeep ) && nIndex + nEndOfs < nNextOutNd &&
2145 				   GetNodes()[ nIndex + nEndOfs ]->IsTxtNode() )
2146 			{
2147 				SwTxtNode* pTxtNode = (SwTxtNode*)GetNodes()[ nIndex+nEndOfs ];
2148 				if( pTxtNode->GetTxt().Len() && nWish )
2149 					--nWish;
2150 				bKeep = pTxtNode->GetSwAttrSet().GetKeep().GetValue();
2151 				++nEndOfs;
2152 			}
2153 
2154 			SwNodeRange aRange( *rOutNds[ i ], 0, *rOutNds[ i ], nEndOfs );
2155 			GetNodes()._Copy( aRange, aEndOfDoc );
2156 		}
2157 		const SwTxtFmtColls *pColl = pExtDoc->GetTxtFmtColls();
2158 		for( i = 0; i < pColl->Count(); ++i )
2159             (*pColl)[ i ]->ResetFmtAttr( RES_PAGEDESC, RES_BREAK );
2160 		SwNodeIndex aIndx( pExtDoc->GetNodes().GetEndOfExtras() );
2161 		++aEndOfDoc;
2162 		while( aIndx < aEndOfDoc )
2163 		{
2164 			SwNode *pNode;
2165 			sal_Bool bDelete = sal_False;
2166 			if(	(pNode = &aIndx.GetNode())->IsTxtNode() )
2167 			{
2168 				SwTxtNode *pNd = (SwTxtNode*)pNode;
2169 				if( pNd->HasSwAttrSet() )
2170 					pNd->ResetAttr( RES_PAGEDESC, RES_BREAK );
2171 				if( bImpress )
2172 				{
2173 					SwTxtFmtColl* pMyColl = pNd->GetTxtColl();
2174 					//sal_uInt16 nHeadLine = static_cast<sal_uInt16>(pMyColl->GetOutlineLevel()==NO_NUMBERING ?//#outlinelevel,zhaojianwei
2175                     const sal_uInt16 nHeadLine = static_cast<sal_uInt16>(
2176                                 !pMyColl->IsAssignedToListLevelOfOutlineStyle() //<-end,zhaojianwei
2177                                 ? RES_POOLCOLL_HEADLINE2
2178                                 : RES_POOLCOLL_HEADLINE1 );
2179 					pMyColl = pExtDoc->GetTxtCollFromPool( nHeadLine );
2180 					pNd->ChgFmtColl( pMyColl );
2181 				}
2182 				if( !pNd->Len() &&
2183 					pNd->StartOfSectionIndex()+2 < pNd->EndOfSectionIndex() )
2184 				{
2185 					bDelete = sal_True;
2186 					pExtDoc->GetNodes().Delete( aIndx );
2187 				}
2188 			}
2189 			if( !bDelete )
2190 				++aIndx;
2191 		}
2192 		::EndProgress( GetDocShell() );
2193 	}
2194 }
2195 
2196 	// loesche den nicht sichtbaren Content aus dem Document, wie z.B.:
2197 	// versteckte Bereiche, versteckte Absaetze
2198 bool SwDoc::RemoveInvisibleContent()
2199 {
2200 	sal_Bool bRet = sal_False;
2201     GetIDocumentUndoRedo().StartUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
2202 
2203 	{
2204 		SwTxtNode* pTxtNd;
2205         SwIterator<SwFmtFld,SwFieldType> aIter( *GetSysFldType( RES_HIDDENPARAFLD )  );
2206         for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld;  pFmtFld = aIter.Next() )
2207         {
2208 			if( pFmtFld->GetTxtFld() &&
2209 				0 != ( pTxtNd = (SwTxtNode*)pFmtFld->GetTxtFld()->GetpTxtNode() ) &&
2210                 pTxtNd->GetpSwpHints() && pTxtNd->HasHiddenParaField() &&
2211 				&pTxtNd->GetNodes() == &GetNodes() )
2212 			{
2213 				bRet = sal_True;
2214                 SwPaM aPam( *pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().Len() );
2215 
2216                 // Remove hidden paragraph or delete contents:
2217                 // Delete contents if
2218                 // 1. removing the paragraph would result in an empty section or
2219                 // 2. if the paragraph is the last paragraph in the section and
2220                 //    there is no paragraph in front of the paragraph:
2221                 if ( ( 2 == pTxtNd->EndOfSectionIndex() - pTxtNd->StartOfSectionIndex() ) ||
2222                      ( 1 == pTxtNd->EndOfSectionIndex() - pTxtNd->GetIndex() &&
2223                        !GetNodes()[ pTxtNd->GetIndex() - 1 ]->GetTxtNode() ) )
2224                 {
2225                     DeleteRange( aPam );
2226                 }
2227                 else
2228                 {
2229                     aPam.DeleteMark();
2230                     DelFullPara( aPam );
2231                 }
2232             }
2233         }
2234 	}
2235 
2236     //
2237     // Remove any hidden paragraph (hidden text attribute)
2238     //
2239     for( sal_uLong n = GetNodes().Count(); n; )
2240     {
2241         SwTxtNode* pTxtNd = GetNodes()[ --n ]->GetTxtNode();
2242         if ( pTxtNd )
2243         {
2244             bool bRemoved = false;
2245             SwPaM aPam( *pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().Len() );
2246             if ( pTxtNd->HasHiddenCharAttribute( true ) )
2247             {
2248                 bRemoved = sal_True;
2249                 bRet = sal_True;
2250 
2251                 // Remove hidden paragraph or delete contents:
2252                 // Delete contents if
2253                 // 1. removing the paragraph would result in an empty section or
2254                 // 2. if the paragraph is the last paragraph in the section and
2255                 //    there is no paragraph in front of the paragraph:
2256 
2257                 if ( ( 2 == pTxtNd->EndOfSectionIndex() - pTxtNd->StartOfSectionIndex() ) ||
2258                      ( 1 == pTxtNd->EndOfSectionIndex() - pTxtNd->GetIndex() &&
2259                        !GetNodes()[ pTxtNd->GetIndex() - 1 ]->GetTxtNode() ) )
2260                 {
2261                     DeleteRange( aPam );
2262                 }
2263                 else
2264                 {
2265                     aPam.DeleteMark();
2266 					DelFullPara( aPam );
2267 				}
2268             }
2269             else if ( pTxtNd->HasHiddenCharAttribute( false ) )
2270             {
2271                 bRemoved = sal_True;
2272                 bRet = sal_True;
2273                 SwScriptInfo::DeleteHiddenRanges( *pTxtNd );
2274             }
2275 
2276             // --> FME 2006-01-11 #120473#
2277             // Footnotes/Frames may have been removed, therefore we have
2278             // to reset n:
2279             if ( bRemoved )
2280                 n = aPam.GetPoint()->nNode.GetIndex();
2281             // <--
2282         }
2283     }
2284 
2285 	{
2286 		// dann noch alle versteckten Bereiche loeschen/leeren
2287 		SwSectionFmts aSectFmts;
2288 		SwSectionFmts& rSectFmts = GetSections();
2289 		sal_uInt16 n;
2290 
2291 		for( n = rSectFmts.Count(); n; )
2292 		{
2293 			SwSectionFmt* pSectFmt = rSectFmts[ --n ];
2294 		    // don't add sections in Undo/Redo
2295             if( !pSectFmt->IsInNodesArr())
2296                 continue;
2297 			SwSection* pSect = pSectFmt->GetSection();
2298 			if( pSect->CalcHiddenFlag() )
2299 			{
2300 				SwSection* pParent = pSect, *pTmp;
2301 				while( 0 != (pTmp = pParent->GetParent() ))
2302 				{
2303 					if( pTmp->IsHiddenFlag() )
2304 						pSect = pTmp;
2305 					pParent = pTmp;
2306 				}
2307 
2308 				if( USHRT_MAX == aSectFmts.GetPos( pSect->GetFmt() ) )
2309 					aSectFmts.Insert( pSect->GetFmt(), 0 );
2310 			}
2311 			if( pSect->GetCondition().Len() )
2312             {
2313                 SwSectionData aSectionData( *pSect );
2314                 aSectionData.SetCondition( aEmptyStr );
2315                 aSectionData.SetHidden( false );
2316                 UpdateSection( n, aSectionData );
2317             }
2318         }
2319 
2320 		if( 0 != ( n = aSectFmts.Count() ))
2321 		{
2322 			while( n )
2323 			{
2324 				SwSectionFmt* pSectFmt = aSectFmts[ --n ];
2325 				SwSectionNode* pSectNd = pSectFmt->GetSectionNode();
2326 				if( pSectNd )
2327 				{
2328 					bRet = sal_True;
2329 					SwPaM aPam( *pSectNd );
2330 
2331                     if( pSectNd->StartOfSectionNode()->StartOfSectionIndex() ==
2332 						pSectNd->GetIndex() - 1 &&
2333                         pSectNd->StartOfSectionNode()->EndOfSectionIndex() ==
2334 						pSectNd->EndOfSectionIndex() + 1 )
2335 					{
2336 						// nur den Inhalt loeschen
2337 						SwCntntNode* pCNd = GetNodes().GoNext(
2338 												&aPam.GetPoint()->nNode );
2339 						aPam.GetPoint()->nContent.Assign( pCNd, 0 );
2340 						aPam.SetMark();
2341 						aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
2342 						pCNd = GetNodes().GoPrevious(
2343 												&aPam.GetPoint()->nNode );
2344 						aPam.GetPoint()->nContent.Assign( pCNd, pCNd->Len() );
2345 
2346                         DeleteRange( aPam );
2347                     }
2348 					else
2349 					{
2350 						// die gesamte Section loeschen
2351 						aPam.SetMark();
2352 						aPam.GetPoint()->nNode = *pSectNd->EndOfSectionNode();
2353 						DelFullPara( aPam );
2354 					}
2355 
2356 				}
2357 			}
2358 			aSectFmts.Remove( 0, aSectFmts.Count() );
2359 		}
2360 	}
2361 
2362 	if( bRet )
2363 		SetModified();
2364     GetIDocumentUndoRedo().EndUndo( UNDO_UI_DELETE_INVISIBLECNTNT, NULL );
2365 	return bRet;
2366 }
2367 /*-- 25.08.2010 14:18:12---------------------------------------------------
2368 
2369   -----------------------------------------------------------------------*/
2370 bool SwDoc::HasInvisibleContent() const
2371 {
2372     sal_Bool bRet = sal_False;
2373 
2374     SwClientIter aIter( *GetSysFldType( RES_HIDDENPARAFLD ) );
2375     if( aIter.First( TYPE( SwFmtFld ) ) )
2376         bRet = sal_True;
2377 
2378     //
2379     // Search for any hidden paragraph (hidden text attribute)
2380     //
2381     if( ! bRet )
2382     {
2383         for( sal_uLong n = GetNodes().Count(); !bRet && (n > 0); )
2384         {
2385             SwTxtNode* pTxtNd = GetNodes()[ --n ]->GetTxtNode();
2386             if ( pTxtNd )
2387             {
2388                 SwPaM aPam( *pTxtNd, 0, *pTxtNd, pTxtNd->GetTxt().Len() );
2389                 if( pTxtNd->HasHiddenCharAttribute( true ) ||  ( pTxtNd->HasHiddenCharAttribute( false ) ) )
2390                 {
2391                     bRet = sal_True;
2392                 }
2393             }
2394         }
2395     }
2396 
2397     if( ! bRet )
2398     {
2399         const SwSectionFmts& rSectFmts = GetSections();
2400         sal_uInt16 n;
2401 
2402         for( n = rSectFmts.Count(); !bRet && (n > 0); )
2403         {
2404             SwSectionFmt* pSectFmt = rSectFmts[ --n ];
2405             // don't add sections in Undo/Redo
2406             if( !pSectFmt->IsInNodesArr())
2407                 continue;
2408             SwSection* pSect = pSectFmt->GetSection();
2409             if( pSect->IsHidden() )
2410                 bRet = sal_True;
2411         }
2412     }
2413     return bRet;
2414 }
2415 
2416 bool SwDoc::RestoreInvisibleContent()
2417 {
2418     bool bRet = false;
2419     SwUndoId nLastUndoId(UNDO_EMPTY);
2420     if (GetIDocumentUndoRedo().GetLastUndoInfo(0, & nLastUndoId)
2421         && (UNDO_UI_DELETE_INVISIBLECNTNT == nLastUndoId))
2422     {
2423         GetIDocumentUndoRedo().Undo();
2424         GetIDocumentUndoRedo().ClearRedo();
2425         bRet = true;
2426     }
2427     return bRet;
2428 }
2429 
2430 /*-- 11.06.2004 08:34:04---------------------------------------------------
2431 
2432   -----------------------------------------------------------------------*/
2433 sal_Bool SwDoc::ConvertFieldsToText()
2434 {
2435     sal_Bool bRet = sal_False;
2436     LockExpFlds();
2437     GetIDocumentUndoRedo().StartUndo( UNDO_UI_REPLACE, NULL );
2438 
2439     const SwFldTypes* pMyFldTypes = GetFldTypes();
2440     sal_uInt16 nCount = pMyFldTypes->Count();
2441     //go backward, field types are removed
2442     for(sal_uInt16 nType = nCount;  nType > 0;  --nType)
2443     {
2444         const SwFieldType *pCurType = pMyFldTypes->GetObject(nType - 1);
2445 
2446         if ( RES_POSTITFLD == pCurType->Which() )
2447             continue;
2448 
2449         SwIterator<SwFmtFld,SwFieldType> aIter( *pCurType );
2450         ::std::vector<const SwFmtFld*> aFieldFmts;
2451         for( SwFmtFld* pCurFldFmt = aIter.First(); pCurFldFmt; pCurFldFmt = aIter.Next() )
2452             aFieldFmts.push_back(pCurFldFmt);
2453 
2454         ::std::vector<const SwFmtFld*>::iterator aBegin = aFieldFmts.begin();
2455         ::std::vector<const SwFmtFld*>::iterator aEnd = aFieldFmts.end();
2456         while(aBegin != aEnd)
2457         {
2458             const SwTxtFld *pTxtFld = (*aBegin)->GetTxtFld();
2459             // skip fields that are currently not in the document
2460             // e.g. fields in undo or redo array
2461 
2462             sal_Bool bSkip = !pTxtFld ||
2463                          !pTxtFld->GetpTxtNode()->GetNodes().IsDocNodes();
2464 
2465             if (!bSkip)
2466             {
2467                 sal_Bool bInHeaderFooter = IsInHeaderFooter(SwNodeIndex(*pTxtFld->GetpTxtNode()));
2468                 const SwFmtFld& rFmtFld = pTxtFld->GetFmtFld();
2469                 const SwField*  pField = rFmtFld.GetField();
2470 
2471                 //#i55595# some fields have to be excluded in headers/footers
2472                 sal_uInt16 nWhich = pField->GetTyp()->Which();
2473                 if(!bInHeaderFooter ||
2474                         (nWhich != RES_PAGENUMBERFLD &&
2475                         nWhich != RES_CHAPTERFLD &&
2476                         nWhich != RES_GETEXPFLD&&
2477                         nWhich != RES_SETEXPFLD&&
2478                         nWhich != RES_INPUTFLD&&
2479                         nWhich != RES_REFPAGEGETFLD&&
2480                         nWhich != RES_REFPAGESETFLD))
2481                 {
2482                     String sText = pField->ExpandField(true);
2483                     //database fields should not convert their command into text
2484                     if( RES_DBFLD == pCurType->Which() && !static_cast<const SwDBField*>(pField)->IsInitialized())
2485                         sText.Erase();
2486 
2487                     //now remove the field and insert the string
2488                     SwPaM aPam1(*pTxtFld->GetpTxtNode(), *pTxtFld->GetStart());
2489                     aPam1.Move();
2490                     //insert first to keep the field's attributes
2491                     InsertString( aPam1, sText );
2492                     SwPaM aPam2(*pTxtFld->GetpTxtNode(), *pTxtFld->GetStart());
2493                     aPam2.SetMark();
2494                     aPam2.Move();
2495                     DeleteAndJoin(aPam2);//remove the field
2496                 }
2497             }
2498             ++aBegin;
2499         }
2500     }
2501 
2502     if( bRet )
2503         SetModified();
2504     GetIDocumentUndoRedo().EndUndo( UNDO_UI_REPLACE, NULL );
2505     UnlockExpFlds();
2506     return bRet;
2507 
2508 }
2509 
2510 bool SwDoc::IsVisibleLinks() const
2511 {
2512     return mbVisibleLinks;
2513 }
2514 
2515 void SwDoc::SetVisibleLinks(bool bFlag)
2516 {
2517     mbVisibleLinks = bFlag;
2518 }
2519 
2520 sfx2::LinkManager& SwDoc::GetLinkManager()
2521 {
2522     return *pLinkMgr;
2523 }
2524 
2525 const sfx2::LinkManager& SwDoc::GetLinkManager() const
2526 {
2527     return *pLinkMgr;
2528 }
2529 
2530 void SwDoc::SetLinksUpdated(const bool bNewLinksUpdated)
2531 {
2532     mbLinksUpdated = bNewLinksUpdated;
2533 }
2534 
2535 bool SwDoc::LinksUpdated() const
2536 {
2537     return mbLinksUpdated;
2538 }
2539 
2540 	// embedded alle lokalen Links (Bereiche/Grafiken)
2541 ::sfx2::SvBaseLink* lcl_FindNextRemovableLink( const ::sfx2::SvBaseLinks& rLinks, sfx2::LinkManager& rLnkMgr )
2542 {
2543     for( sal_uInt16 n = 0; n < rLinks.Count(); ++n )
2544     {
2545         ::sfx2::SvBaseLink* pLnk = &(*rLinks[ n ]);
2546         if( pLnk &&
2547             ( OBJECT_CLIENT_GRF == pLnk->GetObjType() ||
2548               OBJECT_CLIENT_FILE == pLnk->GetObjType() ) &&
2549             pLnk->ISA( SwBaseLink ) )
2550         {
2551                 ::sfx2::SvBaseLinkRef xLink = pLnk;
2552 
2553                 String sFName;
2554                 rLnkMgr.GetDisplayNames( xLink, 0, &sFName, 0, 0 );
2555 
2556                 INetURLObject aURL( sFName );
2557                 if( INET_PROT_FILE == aURL.GetProtocol() ||
2558                     INET_PROT_CID == aURL.GetProtocol() )
2559                     return pLnk;
2560         }
2561     }
2562     return 0;
2563 }
2564 bool SwDoc::EmbedAllLinks()
2565 {
2566 	sal_Bool bRet = sal_False;
2567 	sfx2::LinkManager& rLnkMgr = GetLinkManager();
2568     const ::sfx2::SvBaseLinks& rLinks = rLnkMgr.GetLinks();
2569     if( rLinks.Count() )
2570 	{
2571         ::sw::UndoGuard const undoGuard(GetIDocumentUndoRedo());
2572 
2573         ::sfx2::SvBaseLink* pLnk = 0;
2574         while( 0 != (pLnk = lcl_FindNextRemovableLink( rLinks, rLnkMgr ) ) )
2575 		{
2576             ::sfx2::SvBaseLinkRef xLink = pLnk;
2577             // dem Link sagen, das er aufgeloest wird!
2578             xLink->Closed();
2579 
2580             // falls einer vergessen hat sich auszutragen
2581             if( xLink.Is() )
2582                 rLnkMgr.Remove( xLink );
2583 
2584             bRet = sal_True;
2585 		}
2586 
2587         GetIDocumentUndoRedo().DelAllUndoObj();
2588 		SetModified();
2589 	}
2590 	return bRet;
2591 }
2592 
2593 /*--------------------------------------------------------------------
2594 	Beschreibung:
2595  --------------------------------------------------------------------*/
2596 
2597 sal_Bool SwDoc::IsInsTblFormatNum() const
2598 {
2599 	return SW_MOD()->IsInsTblFormatNum(get(IDocumentSettingAccess::HTML_MODE));
2600 }
2601 
2602 sal_Bool SwDoc::IsInsTblChangeNumFormat() const
2603 {
2604 	return SW_MOD()->IsInsTblChangeNumFormat(get(IDocumentSettingAccess::HTML_MODE));
2605 }
2606 
2607 /*--------------------------------------------------------------------
2608 	Beschreibung:
2609  --------------------------------------------------------------------*/
2610 
2611 sal_Bool SwDoc::IsInsTblAlignNum() const
2612 {
2613 	return SW_MOD()->IsInsTblAlignNum(get(IDocumentSettingAccess::HTML_MODE));
2614 }
2615 
2616         // setze das InsertDB als Tabelle Undo auf:
2617 void SwDoc::AppendUndoForInsertFromDB( const SwPaM& rPam, sal_Bool bIsTable )
2618 {
2619 	if( bIsTable )
2620 	{
2621 		const SwTableNode* pTblNd = rPam.GetPoint()->nNode.GetNode().FindTableNode();
2622 		if( pTblNd )
2623 		{
2624 			SwUndoCpyTbl* pUndo = new SwUndoCpyTbl;
2625 			pUndo->SetTableSttIdx( pTblNd->GetIndex() );
2626             GetIDocumentUndoRedo().AppendUndo( pUndo );
2627         }
2628     }
2629 	else if( rPam.HasMark() )
2630 	{
2631 		SwUndoCpyDoc* pUndo = new SwUndoCpyDoc( rPam );
2632 		pUndo->SetInsertRange( rPam, sal_False );
2633         GetIDocumentUndoRedo().AppendUndo( pUndo );
2634     }
2635 }
2636 
2637 void SwDoc::ChgTOX(SwTOXBase & rTOX, const SwTOXBase & rNew)
2638 {
2639     if (GetIDocumentUndoRedo().DoesUndo())
2640     {
2641         GetIDocumentUndoRedo().DelAllUndoObj();
2642 
2643         SwUndo * pUndo = new SwUndoTOXChange(&rTOX, rNew);
2644 
2645         GetIDocumentUndoRedo().AppendUndo(pUndo);
2646     }
2647 
2648     rTOX = rNew;
2649 
2650     if (rTOX.ISA(SwTOXBaseSection))
2651     {
2652         static_cast<SwTOXBaseSection &>(rTOX).Update();
2653         static_cast<SwTOXBaseSection &>(rTOX).UpdatePageNum();
2654     }
2655 }
2656 
2657 // #111827#
2658 String SwDoc::GetPaMDescr(const SwPaM & rPam) const
2659 {
2660     String aResult;
2661     bool bOK = false;
2662 
2663     if (rPam.GetNode(sal_True) == rPam.GetNode(sal_False))
2664     {
2665         SwTxtNode * pTxtNode = rPam.GetNode(sal_True)->GetTxtNode();
2666 
2667         if (0 != pTxtNode)
2668         {
2669             xub_StrLen nStart = rPam.Start()->nContent.GetIndex();
2670             xub_StrLen nEnd = rPam.End()->nContent.GetIndex();
2671 
2672             aResult += String(SW_RES(STR_START_QUOTE));
2673             aResult += ShortenString(pTxtNode->GetTxt().
2674                                      Copy(nStart, nEnd - nStart),
2675                                      nUndoStringLength,
2676                                      String(SW_RES(STR_LDOTS)));
2677             aResult += String(SW_RES(STR_END_QUOTE));
2678 
2679             bOK = true;
2680         }
2681     }
2682     else if (0 != rPam.GetNode(sal_True))
2683     {
2684         if (0 != rPam.GetNode(sal_False))
2685             aResult += String(SW_RES(STR_PARAGRAPHS));
2686 
2687         bOK = true;
2688     }
2689 
2690     if (! bOK)
2691         aResult += String("??", RTL_TEXTENCODING_ASCII_US);
2692 
2693     return aResult;
2694 }
2695 
2696 // -> #111840#
2697 SwField * SwDoc::GetField(const SwPosition & rPos)
2698 {
2699     SwTxtFld * const pAttr = GetTxtFld(rPos);
2700 
2701     return (pAttr) ? const_cast<SwField *>( pAttr->GetFmtFld().GetField() ) : 0;
2702 }
2703 
2704 SwTxtFld * SwDoc::GetTxtFld(const SwPosition & rPos)
2705 {
2706     SwTxtNode * const pNode = rPos.nNode.GetNode().GetTxtNode();
2707 
2708     return (pNode)
2709         ? static_cast<SwTxtFld*>( pNode->GetTxtAttrForCharAt(
2710                     rPos.nContent.GetIndex(), RES_TXTATR_FIELD) )
2711         : 0;
2712 }
2713 // <- #111840#
2714 
2715 bool SwDoc::ContainsHiddenChars() const
2716 {
2717     for( sal_uLong n = GetNodes().Count(); n; )
2718     {
2719         SwNode* pNd = GetNodes()[ --n ];
2720         if ( ND_TEXTNODE == pNd->GetNodeType() &&
2721              ((SwTxtNode*)pNd)->HasHiddenCharAttribute( false ) )
2722             return true;
2723     }
2724 
2725     return false;
2726 }
2727 
2728 SwUnoCrsr* SwDoc::CreateUnoCrsr( const SwPosition& rPos, sal_Bool bTblCrsr )
2729 {
2730 	SwUnoCrsr* pNew;
2731 	if( bTblCrsr )
2732 		pNew = new SwUnoTableCrsr( rPos );
2733 	else
2734 		pNew = new SwUnoCrsr( rPos );
2735 
2736 	pUnoCrsrTbl->Insert( pNew, pUnoCrsrTbl->Count() );
2737 	return pNew;
2738 }
2739 
2740 void SwDoc::ChkCondColls()
2741 {
2742      for (sal_uInt16 n = 0; n < pTxtFmtCollTbl->Count(); n++)
2743      {
2744         SwTxtFmtColl *pColl = (*pTxtFmtCollTbl)[n];
2745         if (RES_CONDTXTFMTCOLL == pColl->Which())
2746             pColl->CallSwClientNotify( SwAttrHint(RES_CONDTXTFMTCOLL) );
2747      }
2748 }
2749 
2750 #ifdef FUTURE_VBA
2751 uno::Reference< script::vba::XVBAEventProcessor >
2752 SwDoc::GetVbaEventProcessor()
2753 {
2754 	if( !mxVbaEvents.is() && pDocShell && ooo::vba::isAlienWordDoc( *pDocShell ) )
2755 	{
2756         try
2757         {
2758             uno::Reference< frame::XModel > xModel( pDocShell->GetModel(), uno::UNO_SET_THROW );
2759             uno::Sequence< uno::Any > aArgs(1);
2760             aArgs[0] <<= xModel;
2761             mxVbaEvents.set( ooo::vba::createVBAUnoAPIServiceWithArgs( pDocShell, "com.sun.star.script.vba.VBATextEventProcessor" , aArgs ), uno::UNO_QUERY_THROW );
2762         }
2763         catch( uno::Exception& )
2764         {
2765         }
2766 	}
2767 	return mxVbaEvents;
2768 }
2769 #endif
2770 
2771 void SwDoc::setExternalData(::sw::tExternalDataType eType,
2772                             ::sw::tExternalDataPointer pPayload)
2773 {
2774     m_externalData[eType] = pPayload;
2775 }
2776 
2777 ::sw::tExternalDataPointer SwDoc::getExternalData(::sw::tExternalDataType eType)
2778 {
2779     return m_externalData[eType];
2780 }
2781