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