xref: /AOO41X/main/sw/source/ui/uno/unotxdoc.cxx (revision 707fc0d4d52eb4f69d89a98ffec6918ca5de6326)
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 <vos/mutex.hxx>
28 #include <vcl/image.hxx>
29 #include <vcl/virdev.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/print.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/sfxbasecontroller.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/printer.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <toolkit/awt/vclxdevice.hxx>
38 #include <cmdid.h>
39 #include <swtypes.hxx>
40 #include <wdocsh.hxx>
41 #include <wrtsh.hxx>
42 #include <view.hxx>
43 #include <pview.hxx>
44 #include <srcview.hxx>
45 #include <viewsh.hxx>
46 #include <pvprtdat.hxx>
47 #include <printdata.hxx>
48 #include <svl/stritem.hxx>
49 #include <unotxdoc.hxx>
50 #include <svl/numuno.hxx>
51 #include <fldbas.hxx>
52 #include <unotextbodyhf.hxx>
53 #include <unotextrange.hxx>
54 #include <unotextcursor.hxx>
55 #include <unosett.hxx>
56 #include <unocoll.hxx>
57 #include <unoredlines.hxx>
58 #include <unosrch.hxx>
59 #include <sfx2/dispatch.hxx>
60 #include <sfx2/request.hxx>
61 #include <sfx2/objsh.hxx>   // SfxObjectShellRef <-> SV_DECL_REF(SfxObjectShell)
62 #include <unoprnms.hxx>
63 #include <unostyle.hxx>
64 #include <unodraw.hxx>
65 #include <svl/eitem.hxx>
66 #include <pagedesc.hxx>
67 #include <svtools/txtcmp.hxx>
68 #include <unocrsr.hxx>
69 #include <unofield.hxx>
70 #include <unoidx.hxx>
71 #include <unoflatpara.hxx>
72 #include <unotxvw.hxx>
73 #include <poolfmt.hxx>
74 #include <globdoc.hxx>
75 #include <viewopt.hxx>
76 #include <unochart.hxx>
77 #include <doc.hxx>
78 #include <charatr.hxx>
79 #include <svx/xmleohlp.hxx>
80 #include <globals.hrc>
81 #include <unomid.h>
82 #include <unotools/printwarningoptions.hxx>
83 #include <com/sun/star/util/SearchOptions.hpp>
84 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
85 #include <com/sun/star/lang/DisposedException.hpp>
86 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
87 #include <com/sun/star/beans/PropertyAttribute.hpp>
88 #include <com/sun/star/beans/XFastPropertySet.hpp>
89 #include <com/sun/star/document/RedlineDisplayType.hpp>
90 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
91 #include <com/sun/star/frame/XController.hpp>
92 #include <com/sun/star/frame/XFrame.hpp>
93 #include <com/sun/star/script/XInvocation.hpp>
94 #include <com/sun/star/reflection/XIdlClassProvider.hpp>
95 #include <sfx2/linkmgr.hxx>
96 #include <svx/unofill.hxx>
97 #include <editeng/unolingu.hxx>
98 #include <sfx2/progress.hxx>
99 #include <swmodule.hxx>
100 #include <docstat.hxx>
101 #include <modcfg.hxx>
102 #include <ndtxt.hxx>
103 #include <utlui.hrc>
104 #include <swcont.hxx>
105 #include <unodefaults.hxx>
106 #include <SwXDocumentSettings.hxx>
107 #include <doc.hxx>
108 #include <editeng/forbiddencharacterstable.hxx>
109 #include <svl/zforlist.hxx>
110 #include <drawdoc.hxx>
111 #include <SwStyleNameMapper.hxx>
112 #include <osl/file.hxx>
113 #include <comphelper/storagehelper.hxx>
114 
115 
116 // --> FME 2004-06-08 #i12836# enhanced pdf export
117 #include <EnhancedPDFExportHelper.hxx>
118 // <--
119 #include <numrule.hxx>
120 
121 ///////////////////////////Modified on Jun. 14th//////////////////////////
122 ///////////////////////for getDocumentLanguages///////////////////////////
123 //-->
124 #include <editeng/langitem.hxx>
125 #include <doc.hxx>
126 #include <docary.hxx>      //SwCharFmts
127 #include <i18npool/mslangid.hxx>
128 
129 #include <format.hxx>
130 #include <charfmt.hxx>    //SwCharFmt
131 #include <fmtcol.hxx>     //SwTxtFmtColl
132 #include <unostyle.hxx>   //SwAutoStyleFamily
133 #include <istyleaccess.hxx> // handling of automatic styles
134 
135 #include <svl/stylepool.hxx>
136 #include <swatrset.hxx>
137 #include <view.hxx>
138 #include <srcview.hxx>
139 
140 //#include <com/sun/star/i18n/ScriptType.hpp>
141 #include <svtools/langtab.hxx>
142 #include <map>
143 #include <set>
144 #include <vector>
145 
146 #include <editeng/eeitem.hxx>
147 #include <editeng/editeng.hxx>
148 #include <svx/svdoutl.hxx>
149 #include <svl/languageoptions.hxx>
150 #include <svx/svdview.hxx>
151 
152 //
153 //<--
154 using namespace ::com::sun::star;
155 using namespace ::com::sun::star::text;
156 using namespace ::com::sun::star::i18n;
157 using namespace ::com::sun::star::uno;
158 using namespace ::com::sun::star::beans;
159 using namespace ::com::sun::star::lang;
160 using namespace ::com::sun::star::container;
161 using namespace ::com::sun::star::document;
162 using namespace ::com::sun::star::i18n;
163 using ::rtl::OUString;
164 using ::osl::FileBase;
165 
166 /* -----------------------------17.01.01 15:43--------------------------------
167 
168  ---------------------------------------------------------------------------*/
169 #define SW_CREATE_DASH_TABLE            0x01
170 #define SW_CREATE_GRADIENT_TABLE        0x02
171 #define SW_CREATE_HATCH_TABLE           0x03
172 #define SW_CREATE_BITMAP_TABLE          0x04
173 #define SW_CREATE_TRANSGRADIENT_TABLE   0x05
174 #define SW_CREATE_MARKER_TABLE          0x06
175 #define SW_CREATE_DRAW_DEFAULTS         0x07
176 
177 
178 /******************************************************************************
179  *
180  ******************************************************************************/
181 
182 extern bool lcl_GetPostIts( IDocumentFieldsAccess* pIDFA, _SetGetExpFlds * pSrtLst );
183 
184 SwPrintUIOptions * lcl_GetPrintUIOptions(
185     SwDocShell * pDocShell,
186     const SfxViewShell * pView )
187 {
188     if (!pDocShell)
189         return NULL;
190 
191     const sal_Bool bWebDoc      = NULL != dynamic_cast< const SwWebDocShell * >(pDocShell);
192     const bool bSwSrcView   = NULL != dynamic_cast< const SwSrcView * >(pView);
193     const SwView * pSwView = dynamic_cast< const SwView * >(pView);
194     const bool bHasSelection    = pSwView ? pSwView->HasSelection( sal_False ) : false;  // check for any selection, not just text selection
195     const bool bHasPostIts      = lcl_GetPostIts( pDocShell->GetDoc(), 0 );
196 
197     // get default values to use in dialog from documents SwPrintData
198     const SwPrintData &rPrintData = pDocShell->GetDoc()->getPrintData();
199 
200     return new SwPrintUIOptions( bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
201 }
202 
203 ////////////////////////////////////////////////////////////
204 
205 
206 SwTxtFmtColl *lcl_GetParaStyle(const String& rCollName, SwDoc* pDoc)
207 {
208     SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName( rCollName );
209     if( !pColl )
210     {
211         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
212         if( USHRT_MAX != nId )
213             pColl = pDoc->GetTxtCollFromPool( nId );
214     }
215     return pColl;
216 }
217 void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell* pDocShell )
218 {
219     // check if the view frame still exists
220     SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell,
221                                 sal_False );
222     while(pFound)
223     {
224         if( pFound == pToClose)
225         {
226             pToClose->DoClose();
227             break;
228         }
229         pFound = SfxViewFrame::GetNext( *pFound,
230                                 pDocShell,
231                                 sal_False );
232     }
233 }
234 /* -----------------------------10.03.00 18:02--------------------------------
235 
236  ---------------------------------------------------------------------------*/
237 const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
238 {
239     static Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
240     return aSeq;
241 }
242 /* -----------------------------10.03.00 18:04--------------------------------
243 
244  ---------------------------------------------------------------------------*/
245 sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
246     throw(RuntimeException)
247 {
248     if( rId.getLength() == 16
249         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
250                                         rId.getConstArray(), 16 ) )
251     {
252             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
253     }
254 
255     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
256     if ( nRet )
257         return nRet;
258     else
259     {
260         GetNumberFormatter();
261         Any aNumTunnel = xNumFmtAgg->queryAggregation(::getCppuType((Reference<XUnoTunnel>*)0));
262         Reference<XUnoTunnel> xNumTunnel;
263         aNumTunnel >>= xNumTunnel;
264         if(xNumTunnel.is())
265             return xNumTunnel->getSomething(rId);
266     }
267 
268     return SfxBaseModel::getSomething( rId );
269 }
270 /* -----------------------------16.03.00 14:12--------------------------------
271 
272  ---------------------------------------------------------------------------*/
273 Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException)
274 {
275     Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
276     if ( !aRet.hasValue() )
277         aRet = SfxBaseModel::queryInterface(rType);
278     if ( !aRet.hasValue() &&
279         rType == ::getCppuType((Reference<lang::XMultiServiceFactory>*)0))
280     {
281         Reference<lang::XMultiServiceFactory> xTmp = this;
282         aRet <<= xTmp;
283     }
284 
285     if ( !aRet.hasValue()
286         && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
287         && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0)
288         && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0)
289         && rType != ::getCppuType((Reference< com::sun::star::script::XInvocation>*)0)
290         && rType != ::getCppuType((Reference< com::sun::star::reflection::XIdlClassProvider>*)0)
291         && rType != ::getCppuType((Reference< com::sun::star::beans::XFastPropertySet>*)0)
292         && rType != ::getCppuType((Reference< com::sun::star::awt::XWindow>*)0))
293     {
294         GetNumberFormatter();
295         if(xNumFmtAgg.is())
296             aRet = xNumFmtAgg->queryAggregation(rType);
297     }
298     return aRet;
299 }
300 /* -----------------------------16.03.00 14:12--------------------------------
301 
302  ---------------------------------------------------------------------------*/
303 void SAL_CALL SwXTextDocument::acquire()throw()
304 {
305     SfxBaseModel::acquire();
306 }
307 /* -----------------------------16.03.00 14:12--------------------------------
308 
309  ---------------------------------------------------------------------------*/
310 void SAL_CALL SwXTextDocument::release()throw()
311 {
312     SfxBaseModel::release();
313 }
314 /* -----------------------------07.12.00 11:37--------------------------------
315 
316  ---------------------------------------------------------------------------*/
317 Reference< XAdapter > SwXTextDocument::queryAdapter(  ) throw(RuntimeException)
318 {
319     return SfxBaseModel::queryAdapter();
320 }
321 /* -----------------------------16.03.00 14:12--------------------------------
322 
323  ---------------------------------------------------------------------------*/
324 Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException)
325 {
326     Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
327     Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
328 
329     Sequence< uno::Type > aNumTypes;
330     GetNumberFormatter();
331     if(xNumFmtAgg.is())
332     {
333         const uno::Type& rProvType = ::getCppuType((Reference <XTypeProvider>*)0);
334         Any aNumProv = xNumFmtAgg->queryAggregation(rProvType);
335         Reference<XTypeProvider> xNumProv;
336         if(aNumProv >>= xNumProv)
337         {
338             aNumTypes = xNumProv->getTypes();
339         }
340     }
341     long nIndex = aBaseTypes.getLength();
342     // don't forget the lang::XMultiServiceFactory
343     aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 1);
344     uno::Type* pBaseTypes = aBaseTypes.getArray();
345     const uno::Type* pTextTypes = aTextTypes.getConstArray();
346     long nPos;
347     for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
348     {
349         pBaseTypes[nIndex++] = pTextTypes[nPos];
350     }
351     const uno::Type* pNumTypes = aNumTypes.getConstArray();
352     for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
353     {
354         pBaseTypes[nIndex++] = pNumTypes[nPos];
355     }
356     pBaseTypes[nIndex++] = ::getCppuType((Reference<lang::XMultiServiceFactory>*)0);
357     return aBaseTypes;
358 }
359 /*-- 18.12.98 11:52:59---------------------------------------------------
360 
361   -----------------------------------------------------------------------*/
362 SwXTextDocument::SwXTextDocument(SwDocShell* pShell) :
363     SfxBaseModel(pShell),
364 
365     aRefreshCont ( static_cast < XTextDocument* > ( this ) ),
366 
367     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
368 
369     pDocShell(pShell),
370 
371     bObjectValid(pShell != 0),
372 
373     pDrawPage(0),
374     pxXDrawPage(0),
375 
376     pxXNumberingRules(0),
377     pxXFootnotes(0),
378     pxXFootnoteSettings(0),
379     pxXEndnotes(0),
380     pxXEndnoteSettings(0),
381     pxXReferenceMarks(0),
382     pxXTextFieldTypes(0),
383     pxXTextFieldMasters(0),
384     pxXTextSections(0),
385     pxXBookmarks(0),
386     pxXTextTables(0),
387     pxXTextFrames(0),
388     pxXGraphicObjects(0),
389     pxXEmbeddedObjects(0),
390     pxXStyleFamilies(0),
391     pxXAutoStyles(0),
392     pxXChapterNumbering(0),
393     pxXDocumentIndexes(0),
394 
395     pxXLineNumberingProperties(0),
396     pxLinkTargetSupplier(0),
397     pxXRedlines(0),
398     m_pHiddenViewFrame(0),
399     m_pPrintUIOptions( NULL ),
400     m_pRenderData( NULL ),
401     // --> OD #i117783#
402     bApplyPagePrintSettingsFromXPagePrintable( sal_False )
403     // <--
404 {
405 }
406 /*-- 18.12.98 11:53:00---------------------------------------------------
407 
408   -----------------------------------------------------------------------*/
409 SwXTextDocument::~SwXTextDocument()
410 {
411     InitNewDoc();
412     if(xNumFmtAgg.is())
413     {
414         Reference< XInterface >  x0;
415         xNumFmtAgg->setDelegator(x0);
416         xNumFmtAgg = 0;
417     }
418     delete m_pPrintUIOptions;
419     delete m_pRenderData;
420 }
421 
422 
423 /*-- 18.12.98 11:55:08---------------------------------------------------
424 
425   -----------------------------------------------------------------------*/
426 /* -----------------18.12.98 12:49-------------------
427  *
428  * --------------------------------------------------*/
429 SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
430 {
431     if(!xPropertyHelper.is())
432     {
433         pPropertyHelper = new SwXDocumentPropertyHelper(*pDocShell->GetDoc());
434         xPropertyHelper = (cppu::OWeakObject*)pPropertyHelper;
435     }
436     return pPropertyHelper;
437 }
438 void SwXTextDocument::GetNumberFormatter()
439 {
440     if(IsValid())
441     {
442         if(!xNumFmtAgg.is())
443         {
444             if ( pDocShell->GetDoc() )
445             {
446                 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj(
447                                     pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
448                 Reference< util::XNumberFormatsSupplier >  xTmp = pNumFmt;
449                 xNumFmtAgg = Reference< XAggregation >(xTmp, UNO_QUERY);
450             }
451             if(xNumFmtAgg.is())
452                 xNumFmtAgg->setDelegator((cppu::OWeakObject*)(SwXTextDocumentBaseClass*)this);
453         }
454         else
455         {
456             const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
457             Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
458             SvNumberFormatsSupplierObj* pNumFmt = 0;
459             Reference< XUnoTunnel > xNumTunnel;
460             if(aNumTunnel >>= xNumTunnel)
461             {
462                 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
463                         xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
464 
465             }
466             DBG_ASSERT(pNumFmt, "No number formatter available");
467             if(!pNumFmt->GetNumberFormatter())
468                 pNumFmt->SetNumberFormatter(pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
469         }
470     }
471 }
472 /*-- 18.12.98 11:55:11---------------------------------------------------
473 
474   -----------------------------------------------------------------------*/
475 Reference< XText >  SwXTextDocument::getText(void) throw( RuntimeException )
476 {
477     ::vos::OGuard aGuard(Application::GetSolarMutex());
478     if(!IsValid())
479         throw RuntimeException();
480     if(!xBodyText.is())
481     {
482         pBodyText = new SwXBodyText(pDocShell->GetDoc());
483         xBodyText = pBodyText;
484     }
485     return xBodyText;
486 }
487 /*-- 18.12.98 11:55:11---------------------------------------------------
488 
489   -----------------------------------------------------------------------*/
490 void SwXTextDocument::reformat(void) throw( RuntimeException )
491 {
492     ::vos::OGuard aGuard(Application::GetSolarMutex());
493     if(!IsValid())
494         throw RuntimeException();
495 }
496 /*-- 18.12.98 11:55:16---------------------------------------------------
497 
498   -----------------------------------------------------------------------*/
499 void SwXTextDocument::lockControllers(void) throw( RuntimeException )
500 {
501     ::vos::OGuard aGuard(Application::GetSolarMutex());
502     if(IsValid())
503     {
504         UnoActionContext* pContext = new UnoActionContext(pDocShell->GetDoc());
505         aActionArr.Insert(pContext, 0);
506     }
507     else
508         throw RuntimeException();
509 }
510 /*-- 18.12.98 11:55:16---------------------------------------------------
511 
512   -----------------------------------------------------------------------*/
513 void SwXTextDocument::unlockControllers(void) throw( RuntimeException )
514 {
515     ::vos::OGuard aGuard(Application::GetSolarMutex());
516     if(aActionArr.Count())
517     {
518         UnoActionContext* pContext = aActionArr.GetObject(0);
519         aActionArr.Remove(0);
520         delete pContext;
521     }
522     else
523         throw RuntimeException();
524 }
525 /*-- 18.12.98 11:55:17---------------------------------------------------
526 
527   -----------------------------------------------------------------------*/
528 sal_Bool SwXTextDocument::hasControllersLocked(void) throw( RuntimeException )
529 {
530     ::vos::OGuard aGuard(Application::GetSolarMutex());
531     return aActionArr.Count() > 0;
532 }
533 /*-- 18.12.98 13:12:23---------------------------------------------------
534 
535   -----------------------------------------------------------------------*/
536 Reference< frame::XController >  SwXTextDocument::getCurrentController(void) throw( RuntimeException )
537 {
538     return SfxBaseModel::getCurrentController();
539 }
540 /*-- 18.12.98 13:12:24---------------------------------------------------
541 
542   -----------------------------------------------------------------------*/
543 void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
544     throw( NoSuchElementException, RuntimeException )
545 {
546     SfxBaseModel::setCurrentController(xController);
547 }
548 /* -----------------27.01.99 11:48-------------------
549  *
550  * --------------------------------------------------*/
551 Reference< XInterface >  SwXTextDocument::getCurrentSelection() throw( RuntimeException )
552 {
553     ::vos::OGuard aGuard(Application::GetSolarMutex());
554     Reference< XInterface >  xRef;
555     if(IsValid())
556     {
557 
558         const TypeId aTypeId = TYPE(SwView);
559         SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
560         while(pView && pView->GetObjectShell() != pDocShell)
561         {
562             pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
563         }
564         if(pView)
565         {
566             Any aRef = pView->GetUNOObject()->getSelection();
567             aRef >>= xRef;
568         }
569     }
570     return xRef;
571 }
572 
573 /*-- 18.12.98 13:12:24---------------------------------------------------
574 
575   -----------------------------------------------------------------------*/
576 sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
577         throw( RuntimeException )
578 {
579     return SfxBaseModel::attachResource(aURL, aArgs);
580 }
581 /*-- 18.12.98 13:12:24---------------------------------------------------
582 
583   -----------------------------------------------------------------------*/
584 OUString SwXTextDocument::getURL(void) throw( RuntimeException )
585 {
586     return SfxBaseModel::getURL();
587 }
588 /*-- 18.12.98 13:12:24---------------------------------------------------
589 
590   -----------------------------------------------------------------------*/
591 Sequence< beans::PropertyValue > SwXTextDocument::getArgs(void) throw( RuntimeException )
592 {
593     return SfxBaseModel::getArgs();
594 }
595 /*-- 18.12.98 13:12:24---------------------------------------------------
596 
597   -----------------------------------------------------------------------*/
598 void SwXTextDocument::connectController(const Reference< frame::XController > & xController) throw( RuntimeException )
599 {
600     SfxBaseModel::connectController(xController);
601 }
602 /*-- 18.12.98 13:12:25---------------------------------------------------
603 
604   -----------------------------------------------------------------------*/
605 void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController) throw( RuntimeException )
606 {
607     SfxBaseModel::disconnectController(xController);
608 }
609 /*-- 18.12.98 13:12:25---------------------------------------------------
610 
611   -----------------------------------------------------------------------*/
612 void SwXTextDocument::dispose(void) throw( RuntimeException )
613 {
614     SfxBaseModel::dispose();
615 }
616 /*-- 10.05.2005 14:14:39---------------------------------------------------
617 
618   -----------------------------------------------------------------------*/
619 void SwXTextDocument::close( sal_Bool bDeliverOwnership ) throw( util::CloseVetoException, RuntimeException )
620 {
621     if(IsValid() && m_pHiddenViewFrame)
622         lcl_DisposeView( m_pHiddenViewFrame, pDocShell);
623     SfxBaseModel::close(bDeliverOwnership);
624 }
625 /*-- 18.12.98 13:12:25---------------------------------------------------
626 
627   -----------------------------------------------------------------------*/
628 void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
629 {
630     SfxBaseModel::addEventListener(aListener);
631 }
632 /*-- 18.12.98 13:12:26---------------------------------------------------
633 
634   -----------------------------------------------------------------------*/
635 void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
636 {
637     SfxBaseModel::removeEventListener(aListener);
638 }
639 
640 /*-- 18.12.98 11:55:19---------------------------------------------------
641 
642   -----------------------------------------------------------------------*/
643 Reference< XPropertySet > SwXTextDocument::getLineNumberingProperties(void)
644             throw( RuntimeException )
645 {
646     ::vos::OGuard aGuard(Application::GetSolarMutex());
647     if(IsValid())
648     {
649         if(!pxXLineNumberingProperties)
650         {
651             pxXLineNumberingProperties = new Reference<XPropertySet>;
652             (*pxXLineNumberingProperties) = new SwXLineNumberingProperties(pDocShell->GetDoc());
653         }
654     }
655     else
656         throw RuntimeException();
657     return *pxXLineNumberingProperties;
658 }
659 /*-- 18.12.98 11:55:20---------------------------------------------------
660 
661   -----------------------------------------------------------------------*/
662 Reference< XIndexReplace >  SwXTextDocument::getChapterNumberingRules(void)
663                                     throw( RuntimeException )
664 {
665     ::vos::OGuard aGuard(Application::GetSolarMutex());
666     if(!IsValid())
667         throw RuntimeException();
668     if(!pxXChapterNumbering)
669     {
670         pxXChapterNumbering = new Reference< XIndexReplace > ;
671         *pxXChapterNumbering = new SwXChapterNumbering(*pDocShell);
672     }
673     return *pxXChapterNumbering;
674 }
675 
676 Reference< XIndexAccess >  SwXTextDocument::getNumberingRules(void) throw( RuntimeException )
677 {
678     ::vos::OGuard aGuard(Application::GetSolarMutex());
679     if(!IsValid())
680         throw RuntimeException();
681     if(!pxXNumberingRules )
682     {
683         ((SwXTextDocument*)this)->pxXNumberingRules = new Reference< XIndexAccess > ;
684         *pxXNumberingRules = new SwXNumberingRulesCollection( pDocShell->GetDoc() );
685     }
686     return *pxXNumberingRules;
687 }
688 
689 /*-- 18.12.98 11:55:21---------------------------------------------------
690 
691   -----------------------------------------------------------------------*/
692 Reference< XIndexAccess >  SwXTextDocument::getFootnotes(void) throw( RuntimeException )
693 {
694     ::vos::OGuard aGuard(Application::GetSolarMutex());
695     if(!IsValid())
696         throw RuntimeException();
697     if(!pxXFootnotes)
698     {
699         ((SwXTextDocument*)this)->pxXFootnotes = new Reference< XIndexAccess > ;
700         *pxXFootnotes = new SwXFootnotes(sal_False, pDocShell->GetDoc());
701     }
702     return *pxXFootnotes;
703 }
704 /*-- 18.12.98 11:55:21---------------------------------------------------
705 
706   -----------------------------------------------------------------------*/
707 Reference< XPropertySet >  SAL_CALL
708         SwXTextDocument::getFootnoteSettings(void) throw( RuntimeException )
709 {
710     ::vos::OGuard aGuard(Application::GetSolarMutex());
711     if(!IsValid())
712         throw RuntimeException();
713     if(!pxXFootnoteSettings)
714     {
715         ((SwXTextDocument*)this)->pxXFootnoteSettings = new Reference< XPropertySet > ;
716         *pxXFootnoteSettings = new SwXFootnoteProperties(pDocShell->GetDoc());
717     }
718     return *pxXFootnoteSettings;
719 }
720 /*-- 18.12.98 11:55:21---------------------------------------------------
721 
722   -----------------------------------------------------------------------*/
723 Reference< XIndexAccess >  SwXTextDocument::getEndnotes(void) throw( RuntimeException )
724 {
725     ::vos::OGuard aGuard(Application::GetSolarMutex());
726     if(!IsValid())
727         throw RuntimeException();
728     if(!pxXEndnotes)
729     {
730         ((SwXTextDocument*)this)->pxXEndnotes = new Reference< XIndexAccess > ;
731         *pxXEndnotes = new SwXFootnotes(sal_True, pDocShell->GetDoc());
732     }
733     return *pxXEndnotes;
734 }
735 /*-- 18.12.98 11:55:22---------------------------------------------------
736 
737   -----------------------------------------------------------------------*/
738 Reference< XPropertySet >  SwXTextDocument::getEndnoteSettings(void) throw( RuntimeException )
739 {
740     ::vos::OGuard aGuard(Application::GetSolarMutex());
741     if(!IsValid())
742         throw RuntimeException();
743     if(!pxXEndnoteSettings)
744     {
745         ((SwXTextDocument*)this)->pxXEndnoteSettings = new Reference< XPropertySet > ;
746         *pxXEndnoteSettings = new SwXEndnoteProperties(pDocShell->GetDoc());
747     }
748     return *pxXEndnoteSettings;
749 }
750 /*-- 18.12.98 11:55:22---------------------------------------------------
751 
752   -----------------------------------------------------------------------*/
753 Reference< util::XReplaceDescriptor >  SwXTextDocument::createReplaceDescriptor(void)
754     throw( RuntimeException )
755 {
756     ::vos::OGuard aGuard(Application::GetSolarMutex());
757     Reference< util::XReplaceDescriptor >  xRet = new SwXTextSearch;
758     return xRet;
759 }
760 /* -----------------26.02.99 15:52-------------------
761  *
762  * --------------------------------------------------*/
763 SwUnoCrsr*  SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCrsr)
764 {
765     getText();
766     XText *const pText = xBodyText.get();
767     SwXBodyText* pBText = (SwXBodyText*)pText;
768     SwXTextCursor *const pXTextCursor = pBText->CreateTextCursor(true);
769     xCrsr.set( static_cast<text::XWordCursor*>(pXTextCursor) );
770 
771     SwUnoCrsr *const pUnoCrsr = pXTextCursor->GetCursor();
772     pUnoCrsr->SetRemainInSection(sal_False);
773     return pUnoCrsr;
774 }
775 
776 /*-- 18.12.98 11:55:22---------------------------------------------------
777 
778   -----------------------------------------------------------------------*/
779 sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
780                                         throw( RuntimeException )
781 {
782     ::vos::OGuard aGuard(Application::GetSolarMutex());
783     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
784     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
785         throw RuntimeException();
786 
787     Reference< XTextCursor >  xCrsr;
788     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
789 
790     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
791             xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
792 
793     int eRanges(FND_IN_BODY|FND_IN_SELALL);
794 
795     util::SearchOptions aSearchOpt;
796     pSearch->FillSearchOptions( aSearchOpt );
797 
798     SwDocPositions eStart = pSearch->bBack ? DOCPOS_END : DOCPOS_START;
799     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
800 
801     // Suche soll ueberall stattfinden
802     pUnoCrsr->SetRemainInSection(sal_False);
803     sal_uInt32 nResult;
804     UnoActionContext aContext(pDocShell->GetDoc());
805     //try attribute search first
806     if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
807     {
808         SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
809                             RES_CHRATR_BEGIN, RES_CHRATR_END-1,
810                             RES_PARATR_BEGIN, RES_PARATR_END-1,
811                             RES_FRMATR_BEGIN, RES_FRMATR_END-1,
812                             0);
813         SfxItemSet aReplace(pDocShell->GetDoc()->GetAttrPool(),
814                             RES_CHRATR_BEGIN, RES_CHRATR_END-1,
815                             RES_PARATR_BEGIN, RES_PARATR_END-1,
816                             RES_FRMATR_BEGIN, RES_FRMATR_END-1,
817                             0);
818         pSearch->FillSearchItemSet(aSearch);
819         pSearch->FillReplaceItemSet(aReplace);
820         sal_Bool bCancel;
821         nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
822                     eStart, eEnd, bCancel,
823                     (FindRanges)eRanges,
824                     pSearch->sSearchText.Len() ? &aSearchOpt : 0,
825                     &aReplace );
826     }
827     else if(pSearch->bStyles)
828     {
829         SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
830         SwTxtFmtColl *pReplaceColl = lcl_GetParaStyle(pSearch->sReplaceText, pUnoCrsr->GetDoc());;
831 
832         sal_Bool bCancel;
833         nResult = pUnoCrsr->Find( *pSearchColl,
834                     eStart, eEnd, bCancel,
835                     (FindRanges)eRanges, pReplaceColl );
836 
837     }
838     else
839     {
840         //todo/mba: assuming that notes should be omitted
841         sal_Bool bSearchInNotes = sal_False;
842         sal_Bool bCancel;
843         nResult = pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
844             eStart, eEnd, bCancel,
845             (FindRanges)eRanges,
846             sal_True );
847     }
848     return (sal_Int32)nResult;
849 
850 }
851 /*-- 18.12.98 11:55:22---------------------------------------------------
852 
853   -----------------------------------------------------------------------*/
854 Reference< util::XSearchDescriptor >  SwXTextDocument::createSearchDescriptor(void)
855                                                     throw( RuntimeException )
856 {
857     ::vos::OGuard aGuard(Application::GetSolarMutex());
858     Reference< util::XSearchDescriptor >  xRet = new SwXTextSearch;
859     return xRet;
860 
861 }
862 /* -----------------26.02.99 16:08-------------------
863  * wird fuer findAll/First/Next verwendet
864  * --------------------------------------------------*/
865 SwUnoCrsr*  SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
866                                         Reference< XTextCursor > & xCrsr, sal_Bool bAll,
867                                                 sal_Int32& nResult,
868                                                 Reference< XInterface >  xLastResult)
869 {
870     Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
871     if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
872         return 0;
873 
874     SwUnoCrsr*  pUnoCrsr = CreateCursorForSearch(xCrsr);
875     const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
876         xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
877 
878     sal_Bool bParentInExtra = sal_False;
879     if(xLastResult.is())
880     {
881         Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
882         OTextCursorHelper* pPosCrsr = 0;
883         if(xCursorTunnel.is())
884         {
885             pPosCrsr = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething(
886                                     OTextCursorHelper::getUnoTunnelId()));
887         }
888         SwPaM* pCrsr = pPosCrsr ? pPosCrsr->GetPaM() : 0;
889         if(pCrsr)
890         {
891             *pUnoCrsr->GetPoint() = *pCrsr->End();
892             pUnoCrsr->DeleteMark();
893         }
894         else
895         {
896             SwXTextRange* pRange = 0;
897             if(xCursorTunnel.is())
898             {
899                 pRange = reinterpret_cast<SwXTextRange*>(xCursorTunnel->getSomething(
900                                         SwXTextRange::getUnoTunnelId()));
901             }
902             if(!pRange)
903                 return 0;
904             pRange->GetPositions(*pUnoCrsr);
905             if(pUnoCrsr->HasMark())
906             {
907                 if(*pUnoCrsr->GetPoint() < *pUnoCrsr->GetMark())
908                     pUnoCrsr->Exchange();
909                 pUnoCrsr->DeleteMark();
910             }
911         }
912         const SwNode* pRangeNode = pUnoCrsr->GetNode();
913         bParentInExtra = pRangeNode->FindFlyStartNode() ||
914                             pRangeNode->FindFootnoteStartNode() ||
915                             pRangeNode->FindHeaderStartNode() ||
916                             pRangeNode->FindFooterStartNode() ;
917     }
918 
919     util::SearchOptions aSearchOpt;
920     pSearch->FillSearchOptions( aSearchOpt );
921 
922 /*
923  * folgende Kombinationen sind erlaubt:
924  *  - suche einen im Body:                  -> FND_IN_BODY
925  *  - suche alle im Body:                   -> FND_IN_BODYONLY | FND_IN_SELALL
926  *  - suche in Selectionen: einen / alle    -> FND_IN_SEL  [ | FND_IN_SELALL ]
927  *  - suche im nicht Body: einen / alle     -> FND_IN_OTHER [ | FND_IN_SELALL ]
928  *  - suche ueberall alle:                  -> FND_IN_SELALL
929  */
930     int eRanges(FND_IN_BODY);
931     if(bParentInExtra)
932         eRanges = FND_IN_OTHER;
933     if(bAll) //immer - ueberall?
934         eRanges = FND_IN_SELALL;
935     SwDocPositions eStart = !bAll ? DOCPOS_CURR : pSearch->bBack ? DOCPOS_END : DOCPOS_START;
936     SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
937 
938     nResult = 0;
939     sal_uInt16 nSearchProc = 0;
940     while(nSearchProc < 2)
941     {
942         //try attribute search first
943         if(pSearch->HasSearchAttributes())
944         {
945             SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
946                                 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
947                                 RES_PARATR_BEGIN, RES_PARATR_END-1,
948                                 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
949                                 RES_TXTATR_INETFMT, RES_TXTATR_CHARFMT,
950                                 0);
951             pSearch->FillSearchItemSet(aSearch);
952             sal_Bool bCancel;
953             nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
954                         eStart, eEnd, bCancel,
955                         (FindRanges)eRanges,
956                         pSearch->sSearchText.Len() ? &aSearchOpt : 0,
957                         0 );
958         }
959         else if(pSearch->bStyles)
960         {
961             SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
962             //pSearch->sReplaceText
963             SwTxtFmtColl *pReplaceColl = 0;
964             sal_Bool bCancel;
965             nResult = (sal_Int32)pUnoCrsr->Find( *pSearchColl,
966                         eStart, eEnd, bCancel,
967                         (FindRanges)eRanges, pReplaceColl );
968         }
969         else
970         {
971             //todo/mba: assuming that notes should be omitted
972             sal_Bool bSearchInNotes = sal_False;
973             sal_Bool bCancel;
974             nResult = (sal_Int32)pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
975                     eStart, eEnd, bCancel,
976                     (FindRanges)eRanges,
977                     /*int bReplace =*/sal_False );
978         }
979         nSearchProc++;
980         if(nResult || (eRanges&(FND_IN_SELALL|FND_IN_OTHER)))
981             break;
982         //second step - find in other
983         eRanges = FND_IN_OTHER;
984     }
985     return pUnoCrsr;
986 }
987 /*-- 18.12.98 11:55:23---------------------------------------------------
988 
989   -----------------------------------------------------------------------*/
990 Reference< XIndexAccess >
991     SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
992                                                 throw( RuntimeException )
993 {
994     ::vos::OGuard aGuard(Application::GetSolarMutex());
995     Reference< XInterface >  xTmp;
996     sal_Int32 nResult = 0;
997     Reference< XTextCursor >  xCrsr;
998     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_True, nResult, xTmp);
999     if(!pResultCrsr)
1000         throw RuntimeException();
1001     Reference< XIndexAccess >  xRet;
1002     xRet = new SwXTextRanges( (nResult) ? pResultCrsr : 0 );
1003     delete pResultCrsr;
1004     return xRet;
1005 }
1006 /*-- 18.12.98 11:55:23---------------------------------------------------
1007 
1008   -----------------------------------------------------------------------*/
1009 Reference< XInterface >  SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
1010                                             throw( RuntimeException )
1011 {
1012     ::vos::OGuard aGuard(Application::GetSolarMutex());
1013     Reference< XInterface >  xTmp;
1014     sal_Int32 nResult = 0;
1015     Reference< XTextCursor >  xCrsr;
1016     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xTmp);
1017     if(!pResultCrsr)
1018         throw RuntimeException();
1019     Reference< XInterface >  xRet;
1020     if(nResult)
1021     {
1022         const uno::Reference< text::XText >  xParent =
1023             ::sw::CreateParentXText(*pDocShell->GetDoc(),
1024                     *pResultCrsr->GetPoint());
1025         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
1026         delete pResultCrsr;
1027     }
1028     return xRet;
1029 }
1030 /*-- 18.12.98 11:55:24---------------------------------------------------
1031 
1032   -----------------------------------------------------------------------*/
1033 Reference< XInterface >  SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
1034             const Reference< util::XSearchDescriptor > & xDesc)
1035             throw( RuntimeException )
1036 {
1037     ::vos::OGuard aGuard(Application::GetSolarMutex());
1038     Reference< XInterface >  xTmp;
1039     sal_Int32 nResult = 0;
1040     Reference< XTextCursor >  xCrsr;
1041     if(!xStartAt.is())
1042         throw RuntimeException();
1043     SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xStartAt);
1044     if(!pResultCrsr)
1045         throw RuntimeException();
1046     Reference< XInterface >  xRet;
1047     if(nResult)
1048     {
1049         const uno::Reference< text::XText >  xParent =
1050             ::sw::CreateParentXText(*pDocShell->GetDoc(),
1051                     *pResultCrsr->GetPoint());
1052 
1053         xRet = *new SwXTextCursor(xParent, *pResultCrsr);
1054         delete pResultCrsr;
1055     }
1056     return xRet;
1057 }
1058 /*-- 18.12.98 11:55:24---------------------------------------------------
1059 
1060   -----------------------------------------------------------------------*/
1061 Sequence< beans::PropertyValue > SwXTextDocument::getPagePrintSettings(void)
1062     throw( RuntimeException )
1063 {
1064     ::vos::OGuard aGuard(Application::GetSolarMutex());
1065     Sequence< beans::PropertyValue > aSeq(9);
1066     if(IsValid())
1067     {
1068         beans::PropertyValue* pArray = aSeq.getArray();
1069         SwPagePreViewPrtData aData;
1070         const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
1071         if(pData)
1072             aData = *pData;
1073         Any aVal;
1074         aVal <<= (sal_Int16)aData.GetRow();
1075         pArray[0] = beans::PropertyValue(C2U("PageRows"), -1, aVal, PropertyState_DIRECT_VALUE);
1076         aVal <<= (sal_Int16)aData.GetCol();
1077         pArray[1] = beans::PropertyValue(C2U("PageColumns"), -1, aVal, PropertyState_DIRECT_VALUE);
1078         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetLeftSpace());
1079         pArray[2] = beans::PropertyValue(C2U("LeftMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1080         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetRightSpace());
1081         pArray[3] = beans::PropertyValue(C2U("RightMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1082         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetTopSpace());
1083         pArray[4] = beans::PropertyValue(C2U("TopMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1084         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetBottomSpace());
1085         pArray[5] = beans::PropertyValue(C2U("BottomMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1086         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetHorzSpace());
1087         pArray[6] = beans::PropertyValue(C2U("HoriMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1088         aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetVertSpace());
1089         pArray[7] = beans::PropertyValue(C2U("VertMargin"), -1, aVal, PropertyState_DIRECT_VALUE);
1090         sal_Bool bTemp = aData.GetLandscape();
1091         aVal.setValue(&bTemp, ::getCppuBooleanType());
1092         pArray[8] = beans::PropertyValue(C2U("IsLandscape"), -1, aVal, PropertyState_DIRECT_VALUE);
1093     }
1094     else
1095         throw RuntimeException();
1096     return aSeq;
1097 }
1098 /* -----------------24.02.99 10:57-------------------
1099  *
1100  * --------------------------------------------------*/
1101 sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, sal_Bool& bException)
1102 {
1103     bException = sal_False;
1104     TypeClass eType = rValue.getValueType().getTypeClass();
1105 
1106     sal_uInt32 nRet = 0;
1107     if( eType == TypeClass_UNSIGNED_LONG )
1108         rValue >>= nRet;
1109     else
1110     {
1111          sal_Int32 nVal=0;
1112          bException = !(rValue >>= nVal);
1113          if( !bException )
1114             nRet = (sal_uInt32)nVal;
1115     }
1116 
1117     return nRet;
1118 }
1119 /*-- 09.06.2004 12:18:10---------------------------------------------------
1120 
1121   -----------------------------------------------------------------------*/
1122 String lcl_CreateOutlineString( sal_uInt16 nIndex,
1123             const SwOutlineNodes& rOutlineNodes, const SwNumRule* pOutlRule)
1124 {
1125     String sEntry;
1126     const SwTxtNode * pTxtNd = rOutlineNodes[ nIndex ]->GetTxtNode();
1127     SwNumberTree::tNumberVector aNumVector = pTxtNd->GetNumberVector();
1128     if( pOutlRule && pTxtNd->GetNumRule())
1129         for( sal_Int8 nLevel = 0;
1130              nLevel <= pTxtNd->GetActualListLevel();
1131              nLevel++ )
1132         {
1133             long nVal = aNumVector[nLevel];
1134             nVal ++;
1135             nVal -= pOutlRule->Get(nLevel).GetStart();
1136             sEntry += String::CreateFromInt32( nVal );
1137             sEntry += '.';
1138         }
1139     sEntry += rOutlineNodes[ nIndex ]->
1140                     GetTxtNode()->GetExpandTxt( 0, STRING_LEN, sal_False );
1141     return sEntry;
1142 }
1143 /*-- 18.12.98 11:55:25---------------------------------------------------
1144 
1145   -----------------------------------------------------------------------*/
1146 void SwXTextDocument::setPagePrintSettings(const Sequence< beans::PropertyValue >& aSettings)
1147     throw( RuntimeException )
1148 {
1149     ::vos::OGuard aGuard(Application::GetSolarMutex());
1150     if(IsValid())
1151     {
1152         SwPagePreViewPrtData aData;
1153         //falls nur einige Properties kommen, dann die akt. Einstellungen benutzen
1154         const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
1155         if(pData)
1156             aData = *pData;
1157         const beans::PropertyValue* pProperties = aSettings.getConstArray();
1158         int nCount = aSettings.getLength();
1159         for(int i = 0; i < nCount; i++)
1160         {
1161             String sName = pProperties[i].Name;
1162             const Any& rVal = pProperties[i].Value;
1163             sal_Bool bException;
1164             sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
1165             if( COMPARE_EQUAL == sName.CompareToAscii("PageRows" ) )
1166             {
1167                 if(!nVal || nVal > 0xff)
1168                     throw RuntimeException();
1169                 aData.SetRow((sal_uInt8)nVal);
1170             }
1171             else if(COMPARE_EQUAL == sName.CompareToAscii("PageColumns"))
1172             {
1173                 if(!nVal  || nVal > 0xff)
1174                     throw RuntimeException();
1175                 aData.SetCol((sal_uInt8)nVal);
1176             }
1177             else if(COMPARE_EQUAL == sName.CompareToAscii("LeftMargin"))
1178             {
1179                 aData.SetLeftSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1180             }
1181             else if(COMPARE_EQUAL == sName.CompareToAscii("RightMargin"))
1182             {
1183                 aData.SetRightSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1184             }
1185             else if(COMPARE_EQUAL == sName.CompareToAscii("TopMargin"))
1186             {
1187                 aData.SetTopSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1188             }
1189             else if(COMPARE_EQUAL == sName.CompareToAscii("BottomMargin"))
1190             {
1191                 aData.SetBottomSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1192             }
1193             else if(COMPARE_EQUAL == sName.CompareToAscii("HoriMargin"))
1194             {
1195                 aData.SetHorzSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1196             }
1197             else if(COMPARE_EQUAL == sName.CompareToAscii("VertMargin"))
1198             {
1199                 aData.SetVertSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1200             }
1201             else if(COMPARE_EQUAL == sName.CompareToAscii("IsLandscape"))
1202             {
1203                 bException =  (::getBooleanCppuType() != rVal.getValueType());
1204                 aData.SetLandscape(*(sal_Bool*)rVal.getValue());
1205             }
1206             else
1207                 bException = sal_True;
1208             if(bException)
1209                 throw RuntimeException();
1210         }
1211         pDocShell->GetDoc()->SetPreViewPrtData(&aData);
1212     }
1213     else
1214         throw RuntimeException();
1215 }
1216 /*-- 18.12.98 11:55:25---------------------------------------------------
1217 
1218   -----------------------------------------------------------------------*/
1219 void SwXTextDocument::printPages(const Sequence< beans::PropertyValue >& xOptions)
1220     throw( IllegalArgumentException, RuntimeException )
1221 {
1222     ::vos::OGuard aGuard(Application::GetSolarMutex());
1223     if(IsValid())
1224     {
1225         SfxViewFrame* pFrame = SfxViewFrame::LoadHiddenDocument( *pDocShell, 7 );
1226         SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SFX_CALLMODE_SYNCHRON,
1227                                     pDocShell->GetDoc()->GetAttrPool());
1228             aReq.AppendItem(SfxBoolItem(FN_PRINT_PAGEPREVIEW, sal_True));
1229 
1230         OUString sFileName( C2U(SW_PROP_NAME_STR(UNO_NAME_FILE_NAME)));
1231         OUString sCopyCount(C2U(SW_PROP_NAME_STR(UNO_NAME_COPY_COUNT)));
1232         OUString sCollate(C2U(SW_PROP_NAME_STR(UNO_NAME_COLLATE)));
1233         OUString sSort(C2U(SW_PROP_NAME_STR(UNO_NAME_SORT)));
1234         OUString sPages(C2U(SW_PROP_NAME_STR(UNO_NAME_PAGES)));
1235 
1236         for ( int n = 0; n < xOptions.getLength(); ++n )
1237         {
1238             // get Property-Value from options
1239             const beans::PropertyValue &rProp = xOptions.getConstArray()[n];
1240             Any aValue( rProp.Value );
1241 
1242             // FileName-Property?
1243             if ( rProp.Name == sFileName )
1244             {
1245                 OUString sFileURL;
1246                 if ( (rProp.Value >>= sFileURL ) )
1247                 {
1248                     // Convert the File URL into a system dependant path, as the SalPrinter expects
1249                     OUString sSystemPath;
1250                     FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
1251                     aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
1252                 }
1253                 else if ( rProp.Value.getValueType() != ::getVoidCppuType() )
1254                     throw IllegalArgumentException();
1255             }
1256 
1257             // CopyCount-Property
1258             else if ( rProp.Name == sCopyCount )
1259             {
1260                 sal_Int32 nCopies = 0;
1261                 aValue >>= nCopies;
1262                 aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, (sal_Int16)nCopies ) );
1263             }
1264 
1265             // Collate-Property
1266             else if ( rProp.Name == sCollate )
1267             {
1268                 if ( rProp.Value.getValueType() == ::getBooleanCppuType())
1269 
1270                     aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *(sal_Bool*)rProp.Value.getValue() ) );
1271                 else
1272                     throw IllegalArgumentException();
1273             }
1274 
1275             // Sort-Property
1276             else if ( rProp.Name == sSort )
1277             {
1278                 if ( rProp.Value.getValueType() == ::getBooleanCppuType() )
1279                     aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *(sal_Bool*)rProp.Value.getValue() ) );
1280                 else
1281                     throw IllegalArgumentException();
1282             }
1283 
1284             // Pages-Property
1285             else if ( rProp.Name == sPages )
1286             {
1287                 OUString sTmp;
1288                 if ( rProp.Value >>= sTmp )
1289                     aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
1290                 else
1291                     throw IllegalArgumentException();
1292             }
1293         }
1294 
1295         // --> OD #i117783#
1296         bApplyPagePrintSettingsFromXPagePrintable = sal_True;
1297         // <--
1298         pFrame->GetViewShell()->ExecuteSlot(aReq);
1299         // Frame schliessen
1300         pFrame->DoClose();
1301 
1302     }
1303     else
1304         throw RuntimeException();
1305 }
1306 /*-- 18.12.98 11:55:25---------------------------------------------------
1307 
1308   -----------------------------------------------------------------------*/
1309 Reference< XNameAccess >  SwXTextDocument::getReferenceMarks(void)
1310                                         throw( RuntimeException )
1311 {
1312     ::vos::OGuard aGuard(Application::GetSolarMutex());
1313     if(!IsValid())
1314         throw RuntimeException();
1315     if(!pxXReferenceMarks)
1316     {
1317         ((SwXTextDocument*)this)->pxXReferenceMarks = new Reference< XNameAccess > ;
1318         *pxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
1319     }
1320     return *pxXReferenceMarks;
1321 }
1322 /* -----------------21.12.98 10:20-------------------
1323  *
1324  * --------------------------------------------------*/
1325 Reference< XEnumerationAccess >  SwXTextDocument::getTextFields(void) throw( RuntimeException )
1326 {
1327     ::vos::OGuard aGuard(Application::GetSolarMutex());
1328     if(!IsValid())
1329         throw RuntimeException();
1330     if(!pxXTextFieldTypes)
1331     {
1332         ((SwXTextDocument*)this)->pxXTextFieldTypes = new Reference< XEnumerationAccess > ;
1333         *pxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
1334     }
1335     return *pxXTextFieldTypes;
1336 }
1337 /*-- 21.12.98 10:21:12---------------------------------------------------
1338 
1339   -----------------------------------------------------------------------*/
1340 Reference< XNameAccess >  SwXTextDocument::getTextFieldMasters(void)
1341     throw( RuntimeException )
1342 {
1343     ::vos::OGuard aGuard(Application::GetSolarMutex());
1344     if(!IsValid())
1345         throw RuntimeException();
1346     if(!pxXTextFieldMasters)
1347     {
1348         ((SwXTextDocument*)this)->pxXTextFieldMasters = new Reference< XNameAccess > ;
1349         *pxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
1350     }
1351     return *pxXTextFieldMasters;
1352 }
1353 /*-- 21.12.98 10:21:12---------------------------------------------------
1354 
1355   -----------------------------------------------------------------------*/
1356 Reference< XNameAccess >  SwXTextDocument::getEmbeddedObjects(void) throw( RuntimeException )
1357 {
1358     ::vos::OGuard aGuard(Application::GetSolarMutex());
1359     if(!IsValid())
1360         throw RuntimeException();
1361     if(!pxXEmbeddedObjects)
1362     {
1363         ((SwXTextDocument*)this)->pxXEmbeddedObjects = new Reference< XNameAccess > ;
1364         *pxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
1365     }
1366     return *pxXEmbeddedObjects;
1367 }
1368 /*-- 21.12.98 10:21:13---------------------------------------------------
1369 
1370   -----------------------------------------------------------------------*/
1371 Reference< XNameAccess >  SwXTextDocument::getBookmarks(void) throw( RuntimeException )
1372 {
1373     ::vos::OGuard aGuard(Application::GetSolarMutex());
1374     if(!IsValid())
1375         throw RuntimeException();
1376     if(!pxXBookmarks)
1377     {
1378         ((SwXTextDocument*)this)->pxXBookmarks = new Reference< XNameAccess > ;
1379         *pxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
1380     }
1381     return *pxXBookmarks;
1382 }
1383 /*-- 21.12.98 10:21:13---------------------------------------------------
1384 
1385   -----------------------------------------------------------------------*/
1386 Reference< XNameAccess >  SwXTextDocument::getTextSections(void) throw( RuntimeException )
1387 {
1388     ::vos::OGuard aGuard(Application::GetSolarMutex());
1389     if(!IsValid())
1390         throw RuntimeException();
1391     if(!pxXTextSections)
1392     {
1393         ((SwXTextDocument*)this)->pxXTextSections = new Reference< XNameAccess > ;
1394         *pxXTextSections = new SwXTextSections(pDocShell->GetDoc());
1395     }
1396     return *pxXTextSections;
1397 }
1398 /*-- 21.12.98 10:21:13---------------------------------------------------
1399 
1400   -----------------------------------------------------------------------*/
1401 Reference< XNameAccess >  SwXTextDocument::getTextTables(void) throw( RuntimeException )
1402 {
1403     ::vos::OGuard aGuard(Application::GetSolarMutex());
1404     if(!IsValid())
1405         throw RuntimeException();
1406     if(!pxXTextTables)
1407     {
1408         ((SwXTextDocument*)this)->pxXTextTables = new Reference< XNameAccess > ;
1409         *pxXTextTables = new SwXTextTables(pDocShell->GetDoc());
1410     }
1411     return *pxXTextTables;
1412 }
1413 /*-- 21.12.98 10:21:13---------------------------------------------------
1414 
1415   -----------------------------------------------------------------------*/
1416 Reference< XNameAccess >  SwXTextDocument::getGraphicObjects(void) throw( RuntimeException )
1417 {
1418     ::vos::OGuard aGuard(Application::GetSolarMutex());
1419     if(!IsValid())
1420         throw RuntimeException();
1421     if(!pxXGraphicObjects)
1422     {
1423         ((SwXTextDocument*)this)->pxXGraphicObjects = new Reference< XNameAccess > ;
1424         *pxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
1425     }
1426     return *pxXGraphicObjects;
1427 }
1428 /*-- 21.12.98 10:21:14---------------------------------------------------
1429 
1430   -----------------------------------------------------------------------*/
1431 Reference< XNameAccess >  SwXTextDocument::getTextFrames(void) throw( RuntimeException )
1432 {
1433     ::vos::OGuard aGuard(Application::GetSolarMutex());
1434     if(!IsValid())
1435         throw RuntimeException();
1436     if(!pxXTextFrames)
1437     {
1438         ((SwXTextDocument*)this)->pxXTextFrames = new Reference< XNameAccess > ;
1439         *pxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
1440     }
1441     return *pxXTextFrames;
1442 }
1443 /* -----------------21.12.98 10:56-------------------
1444  *
1445  * --------------------------------------------------*/
1446 Reference< XNameAccess >  SwXTextDocument::getStyleFamilies(void) throw( RuntimeException )
1447 {
1448     ::vos::OGuard aGuard(Application::GetSolarMutex());
1449     if(!IsValid())
1450         throw RuntimeException();
1451     if(!pxXStyleFamilies)
1452     {
1453         ((SwXTextDocument*)this)->pxXStyleFamilies = new Reference< XNameAccess > ;
1454         *pxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
1455     }
1456     return *pxXStyleFamilies;
1457 }
1458 /*-- 19.05.06 10:15:22---------------------------------------------------
1459 
1460   -----------------------------------------------------------------------*/
1461 uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles(  )
1462     throw (uno::RuntimeException)
1463 {
1464     ::vos::OGuard aGuard(Application::GetSolarMutex());
1465     if(!IsValid())
1466         throw RuntimeException();
1467     if(!pxXAutoStyles)
1468     {
1469         pxXAutoStyles = new Reference< style::XAutoStyles > ;
1470         *pxXAutoStyles = new SwXAutoStyles(*pDocShell);
1471     }
1472     return *pxXAutoStyles;
1473 
1474 }
1475 /*-- 22.01.99 10:18:03---------------------------------------------------
1476 
1477   -----------------------------------------------------------------------*/
1478 Reference< drawing::XDrawPage >  SwXTextDocument::getDrawPage(void) throw( RuntimeException )
1479 {
1480     ::vos::OGuard aGuard(Application::GetSolarMutex());
1481     if(!IsValid())
1482         throw RuntimeException();
1483     if(!pxXDrawPage)
1484     {
1485         // simplified this creation, keeping original below as reference
1486         // for the case that it did something by purpose
1487         ((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1488         ((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage >(pDrawPage);
1489 
1490         //((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage > ;
1491         //((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1492         //Reference< drawing::XShapes >  xTmp = pDrawPage;
1493         //*pxXDrawPage = Reference< drawing::XDrawPage>(xTmp, UNO_QUERY);
1494     }
1495     return *pxXDrawPage;
1496 }
1497 /* -----------------07.04.99 10:11-------------------
1498  *
1499  * --------------------------------------------------*/
1500 SwXDrawPage* SwXTextDocument::GetDrawPage()
1501 {
1502     if(!IsValid())
1503         return 0;
1504     if(!pDrawPage)
1505         getDrawPage();
1506     return pDrawPage;
1507 }
1508 /*-- 18.12.98 11:55:26---------------------------------------------------
1509 
1510   -----------------------------------------------------------------------*/
1511 void SwXTextDocument::Invalidate()
1512 {
1513     bObjectValid = sal_False;
1514     if(xNumFmtAgg.is())
1515     {
1516         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1517         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1518         SvNumberFormatsSupplierObj* pNumFmt = 0;
1519         Reference< XUnoTunnel > xNumTunnel;
1520         if(aNumTunnel >>= xNumTunnel)
1521         {
1522             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1523                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1524             pNumFmt->SetNumberFormatter(0);
1525         }
1526         DBG_ASSERT(pNumFmt, "No number formatter available");
1527     }
1528     InitNewDoc();
1529     pDocShell = 0;
1530     aRefreshCont.Disposing();
1531 }
1532 /* -----------------------------13.07.00 15:59--------------------------------
1533 
1534  ---------------------------------------------------------------------------*/
1535 void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
1536 {
1537     if(pDocShell && pDocShell != pNewDocShell)
1538         Invalidate();
1539     pDocShell = pNewDocShell;
1540     bObjectValid = sal_True;
1541 }
1542 /*-- 18.12.98 11:55:26---------------------------------------------------
1543 
1544   -----------------------------------------------------------------------*/
1545 void    SwXTextDocument::InitNewDoc()
1546 {
1547     // zunaechst alle Collections invalidieren, dann Referenzen loeschen und Null setzen
1548     if(pxXTextTables)
1549     {
1550          XNameAccess* pTbls = pxXTextTables->get();
1551         ((SwXTextTables*)pTbls)->Invalidate();
1552         delete pxXTextTables;
1553         pxXTextTables = 0;
1554     }
1555 
1556     if(pxXTextFrames)
1557     {
1558         XNameAccess* pFrms = pxXTextFrames->get();
1559         ((SwXTextFrames*)pFrms)->Invalidate();
1560         delete pxXTextFrames;
1561         pxXTextFrames = 0;
1562     }
1563 
1564     if(pxXGraphicObjects)
1565     {
1566         XNameAccess* pFrms = pxXGraphicObjects->get();
1567         ((SwXTextGraphicObjects*)pFrms)->Invalidate();
1568         delete pxXGraphicObjects;
1569         pxXGraphicObjects = 0;
1570     }
1571 
1572     if(pxXEmbeddedObjects)
1573     {
1574      XNameAccess* pOLE = pxXEmbeddedObjects->get();
1575         ((SwXTextEmbeddedObjects*)pOLE)->Invalidate();
1576         delete pxXEmbeddedObjects;
1577         pxXEmbeddedObjects = 0;
1578     }
1579 
1580     if(xBodyText.is())
1581     {
1582         xBodyText = 0;
1583         pBodyText = 0;
1584     }
1585 
1586     if(xNumFmtAgg.is())
1587     {
1588         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1589         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1590         SvNumberFormatsSupplierObj* pNumFmt = 0;
1591         Reference< XUnoTunnel > xNumTunnel;
1592         if(aNumTunnel >>= xNumTunnel)
1593         {
1594             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1595                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1596 
1597         }
1598         DBG_ASSERT(pNumFmt, "No number formatter available");
1599         pNumFmt->SetNumberFormatter(0);
1600     }
1601 
1602     if(pxXTextFieldTypes)
1603     {
1604         XEnumerationAccess* pT = pxXTextFieldTypes->get();
1605         ((SwXTextFieldTypes*)pT)->Invalidate();
1606         delete pxXTextFieldTypes;
1607         pxXTextFieldTypes = 0;
1608     }
1609 
1610     if(pxXTextFieldMasters)
1611     {
1612         XNameAccess* pT = pxXTextFieldMasters->get();
1613         ((SwXTextFieldMasters*)pT)->Invalidate();
1614         delete pxXTextFieldMasters;
1615         pxXTextFieldMasters = 0;
1616     }
1617 
1618     if(pxXTextSections)
1619     {
1620         XNameAccess* pSect = pxXTextSections->get();
1621         ((SwXTextSections*)pSect)->Invalidate();
1622         delete pxXTextSections;
1623         pxXTextSections = 0;
1624     }
1625 
1626     if(pxXDrawPage)
1627     {
1628         // --> OD 2008-07-23 #i91798#, #i91895#
1629         // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1630         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
1631         xComp->dispose();
1632         // <--
1633         pDrawPage->InvalidateSwDoc();
1634         delete pxXDrawPage;
1635         pxXDrawPage = 0;
1636     }
1637 
1638     if ( pxXNumberingRules )
1639     {
1640         XIndexAccess* pNum = pxXNumberingRules->get();
1641         ((SwXNumberingRulesCollection*)pNum)->Invalidate();
1642         delete pxXNumberingRules;
1643         pxXNumberingRules = 0;
1644     }
1645 
1646     if(pxXFootnotes)
1647     {
1648         XIndexAccess* pFtn = pxXFootnotes->get();
1649         ((SwXFootnotes*)pFtn)->Invalidate();
1650         delete pxXFootnotes;
1651         pxXFootnotes = 0;
1652     }
1653 
1654     if(pxXEndnotes)
1655     {
1656         XIndexAccess* pFtn = pxXEndnotes->get();
1657         ((SwXFootnotes*)pFtn)->Invalidate();
1658         delete pxXEndnotes;
1659         pxXEndnotes = 0;
1660     }
1661 
1662     if(pxXDocumentIndexes)
1663     {
1664         XIndexAccess* pIdxs = pxXDocumentIndexes->get();
1665         ((SwXDocumentIndexes*)pIdxs)->Invalidate();
1666         delete pxXDocumentIndexes;
1667         pxXDocumentIndexes = 0;
1668     }
1669 
1670     if(pxXStyleFamilies)
1671     {
1672         XNameAccess* pStyles = pxXStyleFamilies->get();
1673         ((SwXStyleFamilies*)pStyles)->Invalidate();
1674         delete pxXStyleFamilies;
1675         pxXStyleFamilies = 0;
1676     }
1677     if(pxXAutoStyles)
1678     {
1679         XNameAccess* pStyles = pxXAutoStyles->get();
1680         ((SwXAutoStyles*)pStyles)->Invalidate();
1681         delete pxXAutoStyles;
1682         pxXAutoStyles = 0;
1683     }
1684 
1685     if(pxXBookmarks)
1686     {
1687         XNameAccess* pBm = pxXBookmarks->get();
1688         ((SwXBookmarks*)pBm)->Invalidate();
1689         delete pxXBookmarks;
1690         pxXBookmarks = 0;
1691     }
1692 
1693     if(pxXChapterNumbering)
1694     {
1695         XIndexReplace* pCh = pxXChapterNumbering->get();
1696         ((SwXChapterNumbering*)pCh)->Invalidate();
1697         delete pxXChapterNumbering;
1698         pxXChapterNumbering = 0;
1699     }
1700 
1701     if(pxXFootnoteSettings)
1702     {
1703         XPropertySet* pFntSet = pxXFootnoteSettings->get();
1704         ((SwXFootnoteProperties*)pFntSet)->Invalidate();
1705         delete pxXFootnoteSettings;
1706         pxXFootnoteSettings = 0;
1707     }
1708 
1709     if(pxXEndnoteSettings)
1710     {
1711         XPropertySet* pEndSet = pxXEndnoteSettings->get();
1712         ((SwXEndnoteProperties*)pEndSet)->Invalidate();
1713         delete pxXEndnoteSettings;
1714         pxXEndnoteSettings = 0;
1715     }
1716 
1717     if(pxXLineNumberingProperties)
1718     {
1719         XPropertySet* pLine = pxXLineNumberingProperties->get();
1720         ((SwXLineNumberingProperties*)pLine)->Invalidate();
1721         delete pxXLineNumberingProperties;
1722         pxXLineNumberingProperties = 0;
1723     }
1724     if(pxXReferenceMarks)
1725     {
1726         XNameAccess* pMarks = pxXReferenceMarks->get();
1727         ((SwXReferenceMarks*)pMarks)->Invalidate();
1728         delete pxXReferenceMarks;
1729         pxXReferenceMarks = 0;
1730     }
1731     if(pxLinkTargetSupplier)
1732     {
1733         XNameAccess* pAccess = (*pxLinkTargetSupplier).get();
1734         ((SwXLinkTargetSupplier*)pAccess)->Invalidate();
1735         delete pxLinkTargetSupplier;
1736         pxLinkTargetSupplier = 0;
1737     }
1738     if(pxXRedlines)
1739     {
1740         XEnumerationAccess* pMarks = pxXRedlines->get();
1741         ((SwXRedlines*)pMarks)->Invalidate();
1742         delete pxXRedlines;
1743         pxXRedlines = 0;
1744     }
1745     if(xPropertyHelper.is())
1746     {
1747         pPropertyHelper->Invalidate();
1748         xPropertyHelper = 0;
1749         pPropertyHelper = 0;
1750     }
1751 }
1752 
1753 /*-- 11.03.99 11:51:40---------------------------------------------------
1754 
1755   -----------------------------------------------------------------------*/
1756 #define COM_SUN_STAR__DRAWING_LENGTH 13
1757 Reference< XInterface >  SwXTextDocument::createInstance(const OUString& rServiceName)
1758                                         throw( Exception, RuntimeException )
1759 {
1760     ::vos::OGuard aGuard(Application::GetSolarMutex());
1761     if(!IsValid())
1762         throw RuntimeException();
1763     Reference< XInterface >  xRet;
1764     sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
1765     if(nType != SW_SERVICE_INVALID)
1766     {
1767         xRet = SwXServiceProvider::MakeInstance(nType, pDocShell->GetDoc());
1768     }
1769     else
1770     {
1771         if( rServiceName.compareToAscii( "com.sun.star.", 13 ) == 0 )
1772         {
1773             sal_Int32 nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1774             OUString sCategory = rServiceName.getToken( 0, '.', nIndex );
1775             sal_Bool bShape = sCategory == C2U("drawing");
1776             if( bShape || sCategory == C2U("form"))
1777             {
1778                 if(bShape)
1779                 {
1780                     short nTable = 0;
1781                     if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
1782                         nTable = SW_CREATE_DASH_TABLE;
1783                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
1784                         nTable = SW_CREATE_GRADIENT_TABLE;
1785                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
1786                         nTable = SW_CREATE_HATCH_TABLE;
1787                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
1788                         nTable = SW_CREATE_BITMAP_TABLE;
1789                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
1790                         nTable = SW_CREATE_TRANSGRADIENT_TABLE;
1791                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
1792                         nTable = SW_CREATE_MARKER_TABLE;
1793                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Defaults") ) )
1794                         nTable = SW_CREATE_DRAW_DEFAULTS;
1795                     if(nTable)
1796                     {
1797                         xRet = GetPropertyHelper()->GetDrawTable(nTable);
1798                     }
1799                 }
1800             }
1801             else if (sCategory == C2U ("document") )
1802             {
1803                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.Settings") ) )
1804                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1805                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver") ) )
1806                 {
1807                     xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ );
1808                 }
1809             }
1810             else if (sCategory == C2U ("text") )
1811             {
1812                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.DocumentSettings") ) )
1813                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1814             }
1815             else if (sCategory == C2U ("chart2") )
1816             {
1817                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.data.DataProvider") ) )
1818                     xRet = Reference < XInterface > ( dynamic_cast< chart2::data::XDataProvider * >(pDocShell->getIDocumentChartDataProviderAccess()->GetChartDataProvider()) );
1819             }
1820 
1821             if(!xRet.is())
1822             {
1823                 //! we don't want to insert OLE2 Shapes (e.g. "com.sun.star.drawing.OLE2Shape", ...)
1824                 //! like this (by creating them with the documents factory and
1825                 //! adding the shapes to the draw page).
1826                 //! For inserting OLE objects the proper way is to use
1827                 //! "com.sun.star.text.TextEmbeddedObject"!
1828                 if (rServiceName.lastIndexOf( C2U(".OLE2Shape") ) == rServiceName.getLength() - 10)
1829                     throw ServiceNotRegisteredException();  // declare service to be not registered with this factory
1830 
1831                 // --> OD 2006-02-22 #b6382898#
1832                 // the XML import is allowed to create instances of com.sun.star.drawing.OLE2Shape.
1833                 // Thus, a temporary service name is introduced to make this possible.
1834                 OUString aTmpServiceName( rServiceName );
1835                 if ( bShape &&
1836                      rServiceName.compareToAscii( "com.sun.star.drawing.temporaryForXMLImportOLE2Shape" ) == 0 )
1837                 {
1838                     aTmpServiceName = OUString::createFromAscii( "com.sun.star.drawing.OLE2Shape" );
1839                 }
1840                 //hier den Draw - Service suchen
1841                 Reference< XInterface >  xTmp = SvxFmMSFactory::createInstance(aTmpServiceName);
1842                 // <--
1843                 if(bShape)
1844                 {
1845                     nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1846                     if( 0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.GroupShape" ) ) ||
1847                         0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.Shape3DSceneObject" ) ) )
1848                         xRet = *new SwXGroupShape( xTmp );
1849                     else
1850                         xRet = *new SwXShape( xTmp );
1851                 }
1852                 else
1853                     xRet = xTmp;
1854             }
1855         }
1856         else
1857             throw ServiceNotRegisteredException();
1858     }
1859     return xRet;
1860 }
1861 /*-- 11.03.99 11:51:40---------------------------------------------------
1862 
1863   -----------------------------------------------------------------------*/
1864 Reference< XInterface >  SwXTextDocument::createInstanceWithArguments(
1865         const OUString& ServiceSpecifier,
1866         const Sequence< Any >& /*Arguments*/)
1867         throw( Exception, RuntimeException )
1868 {
1869     Reference< XInterface >  xInt = createInstance(ServiceSpecifier);
1870     //die Any-Sequence dient zur Initialisierung von Objekten, die auf
1871     //Parameter zwingend angewiesen sind - bis jetzt haben wir das nicht
1872     return xInt;
1873 }
1874 /*-- 11.03.99 11:51:41---------------------------------------------------
1875 
1876   -----------------------------------------------------------------------*/
1877 Sequence< OUString > SwXTextDocument::getAvailableServiceNames(void)
1878                                         throw( RuntimeException )
1879 {
1880     static Sequence< OUString > aServices;
1881     if ( aServices.getLength() == 0 )
1882     {
1883         Sequence< OUString > aRet =  SvxFmMSFactory::getAvailableServiceNames();
1884         OUString* pRet = aRet.getArray();
1885         for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
1886         {
1887             if ( pRet[i].compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 )
1888             {
1889                 pRet[i] = pRet[aRet.getLength() - 1];
1890                 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
1891                 break;
1892             }
1893         }
1894         Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
1895         aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
1896     }
1897 
1898     return aServices;
1899 }
1900 /* -----------------18.03.99 11:36-------------------
1901  *
1902  * --------------------------------------------------*/
1903 OUString SwXTextDocument::getImplementationName(void) throw( RuntimeException )
1904 {
1905     return C2U("SwXTextDocument");
1906 }
1907 /* -----------------20.01.04 10:14-------------------
1908  *
1909  * --------------------------------------------------*/
1910 sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException )
1911 {
1912     if (
1913         (rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.document.OfficeDocument" ))) ||
1914         (rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.text.GenericTextDocument")))
1915        )
1916     return sal_True;
1917 
1918     sal_Bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
1919     sal_Bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1920     sal_Bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
1921 
1922     return (
1923             (bWebDoc    && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.WebDocument"   ))) ||
1924             (bGlobalDoc && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.GlobalDocument"))) ||
1925             (bTextDoc   && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextDocument"  )))
1926            );
1927 }
1928 /* -----------------20.01.04 10:17-------------------
1929  *
1930  * --------------------------------------------------*/
1931 Sequence< OUString > SwXTextDocument::getSupportedServiceNames(void) throw( RuntimeException )
1932 {
1933     sal_Bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
1934     sal_Bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1935     sal_Bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
1936 
1937     Sequence< OUString > aRet (3);
1938     OUString* pArray = aRet.getArray();
1939 
1940     pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.document.OfficeDocument"  ) ) );
1941     pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.GenericTextDocument" ) ) );
1942 
1943     if (bTextDoc)
1944         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.TextDocument" ) ) );
1945     else
1946     if (bWebDoc)
1947         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.WebDocument" ) ) );
1948     else
1949     if (bGlobalDoc)
1950         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.GlobalDocument" ) ) );
1951 
1952     return aRet;
1953 }
1954 /* -----------------05.05.99 12:10-------------------
1955  *
1956  * --------------------------------------------------*/
1957 Reference< XIndexAccess >  SwXTextDocument::getDocumentIndexes(void) throw( RuntimeException )
1958 {
1959     ::vos::OGuard aGuard(Application::GetSolarMutex());
1960     if(!IsValid())
1961         throw RuntimeException();
1962     if(!pxXDocumentIndexes)
1963     {
1964         ((SwXTextDocument*)this)->pxXDocumentIndexes = new Reference< XIndexAccess > ;
1965         *pxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
1966     }
1967     return *pxXDocumentIndexes;
1968 }
1969 
1970 /*-- 10.05.99 13:58:58---------------------------------------------------
1971 
1972   -----------------------------------------------------------------------*/
1973 Reference< XPropertySetInfo >  SwXTextDocument::getPropertySetInfo(void) throw( RuntimeException )
1974 {
1975     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
1976     return xRet;
1977 }
1978 /*-- 10.05.99 13:58:58---------------------------------------------------
1979 
1980   -----------------------------------------------------------------------*/
1981 void SwXTextDocument::setPropertyValue(const OUString& rPropertyName,
1982     const Any& aValue)
1983     throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException,
1984                                          WrappedTargetException, RuntimeException)
1985 {
1986     ::vos::OGuard aGuard(Application::GetSolarMutex());
1987     if(!IsValid())
1988         throw RuntimeException();
1989     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
1990 
1991     if(!pEntry)
1992         throw UnknownPropertyException();
1993     if(pEntry->nFlags & PropertyAttribute::READONLY)
1994         throw PropertyVetoException();
1995     switch(pEntry->nWID)
1996     {
1997         case  WID_DOC_CHAR_COUNT     :
1998         case  WID_DOC_PARA_COUNT     :
1999         case  WID_DOC_WORD_COUNT     :
2000             throw RuntimeException();
2001         case  WID_DOC_WORD_SEPARATOR :
2002         {
2003             OUString sDelim;
2004             aValue >>= sDelim;
2005             SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
2006         }
2007         break;
2008         case WID_DOC_CHANGES_RECORD:
2009         case WID_DOC_CHANGES_SHOW:
2010         {
2011             sal_Bool bSet = *(sal_Bool*)aValue.getValue();
2012             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
2013             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2014             {
2015                 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
2016                 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
2017                 if( bSet )
2018                     eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
2019             }
2020             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2021             {
2022                 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
2023             }
2024             pDocShell->GetDoc()->SetRedlineMode( (RedlineMode_t)(eMode ));
2025         }
2026         break;
2027         case  WID_DOC_CHANGES_PASSWORD:
2028         {
2029             Sequence <sal_Int8> aNew;
2030             if(aValue >>= aNew)
2031             {
2032                 SwDoc* pDoc = pDocShell->GetDoc();
2033                 pDoc->SetRedlinePassword(aNew);
2034                 if(aNew.getLength())
2035                 {
2036                     sal_uInt16 eMode = pDoc->GetRedlineMode();
2037                     eMode = eMode|nsRedlineMode_t::REDLINE_ON;
2038                     pDoc->SetRedlineMode( (RedlineMode_t)(eMode ));
2039                 }
2040             }
2041         }
2042         break;
2043         case WID_DOC_AUTO_MARK_URL :
2044         {
2045             OUString sURL;
2046             aValue >>= sURL;
2047             pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
2048         }
2049         break;
2050         case WID_DOC_HIDE_TIPS :
2051             SW_MOD()->GetModuleConfig()->SetHideFieldTips(*(sal_Bool*)aValue.getValue());
2052         break;
2053         case WID_DOC_REDLINE_DISPLAY:
2054         {
2055             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
2056             eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
2057             sal_Int16 nSet = 0;
2058             aValue >>= nSet;
2059             switch(nSet)
2060             {
2061                 case RedlineDisplayType::NONE: break;
2062                 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
2063                 case RedlineDisplayType::REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;  break;
2064                 case RedlineDisplayType::
2065                         INSERTED_AND_REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT|nsRedlineMode_t::REDLINE_SHOW_DELETE;
2066                 break;
2067                 default: throw IllegalArgumentException();
2068             }
2069             pDocShell->GetDoc()->SetRedlineMode(eRedMode);
2070         }
2071         break;
2072         case WID_DOC_TWO_DIGIT_YEAR:
2073         {
2074             sal_Int16 nYear = 0;
2075             aValue >>= nYear;
2076             SfxRequest aRequest ( SID_ATTR_YEAR2000, SFX_CALLMODE_SLOT, pDocShell->GetDoc()->GetAttrPool());
2077             aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
2078             pDocShell->Execute ( aRequest );
2079         }
2080         break;
2081         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2082         {
2083             SwDrawDocument * pDrawDoc;
2084             sal_Bool bAuto = *(sal_Bool*) aValue.getValue();
2085 
2086             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * >( pDocShell->GetDoc()->GetDrawModel() ) ) )
2087                 pDrawDoc->SetAutoControlFocus( bAuto );
2088             else if (bAuto)
2089             {
2090                 // if setting to true, and we don't have an
2091                 // SdrModel, then we are changing the default and
2092                 // must thus create an SdrModel, if we don't have an
2093                 // SdrModel and we are leaving the default at false,
2094                 // we don't need to make an SdrModel and can do nothing
2095                 // --> OD 2005-08-08 #i52858# - method name changed
2096                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
2097                 // <--
2098                 pDrawDoc->SetAutoControlFocus ( bAuto );
2099             }
2100         }
2101         break;
2102         case WID_DOC_APPLY_FORM_DESIGN_MODE:
2103         {
2104             SwDrawDocument * pDrawDoc;
2105             sal_Bool bMode = *(sal_Bool*)aValue.getValue();
2106 
2107             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2108                 pDrawDoc->SetOpenInDesignMode( bMode );
2109             else if (!bMode)
2110             {
2111                 // if setting to false, and we don't have an
2112                 // SdrModel, then we are changing the default and
2113                 // must thus create an SdrModel, if we don't have an
2114                 // SdrModel and we are leaving the default at true,
2115                 // we don't need to make an SdrModel and can do
2116                 // nothing
2117                 // --> OD 2005-08-08 #i52858# - method name changed
2118                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
2119                 // <--
2120                 pDrawDoc->SetOpenInDesignMode ( bMode );
2121             }
2122         }
2123         break;
2124         // --> FME 2005-02-25 #i42634# New property to set the bInReading
2125         // flag at the document, used during binary import
2126         case WID_DOC_LOCK_UPDATES :
2127         {
2128             SwDoc* pDoc = pDocShell->GetDoc();
2129             bool bBool (false);
2130             if( aValue >>= bBool )
2131               pDoc->SetInReading( bBool );
2132         }
2133         break;
2134         // <--
2135         case WID_DOC_BUILDID:
2136             aValue >>= maBuildId;
2137         break;
2138         // --> OD 2006-03-21 #b6375613#
2139         case WID_APPLY_WORKAROUND_FOR_B6375613:
2140         {
2141             bool bApplyWorkaroundForB6375613( false );
2142             aValue >>= bApplyWorkaroundForB6375613;
2143             pDocShell->GetDoc()->SetApplyWorkaroundForB6375613( bApplyWorkaroundForB6375613 );
2144         }
2145         break;
2146         // <--
2147 
2148         default:
2149         {
2150             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2151             SfxPoolItem* pNewItem = rItem.Clone();
2152             pNewItem->PutValue(aValue, pEntry->nMemberId);
2153             pDocShell->GetDoc()->SetDefault(*pNewItem);
2154             delete pNewItem;
2155         }
2156     }
2157 }
2158 /*-- 10.05.99 13:58:59---------------------------------------------------
2159 
2160   -----------------------------------------------------------------------*/
2161 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
2162     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2163 {
2164     ::vos::OGuard aGuard(Application::GetSolarMutex());
2165     if(!IsValid())
2166         throw RuntimeException();
2167     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2168 
2169     if(!pEntry)
2170         throw UnknownPropertyException();
2171     Any aAny;
2172     switch(pEntry->nWID)
2173     {
2174         case  WID_DOC_CHAR_COUNT     :
2175         case  WID_DOC_PARA_COUNT     :
2176         case  WID_DOC_WORD_COUNT     :
2177         {
2178             SwDocStat aStat(pDocShell->GetDoc()->GetDocStat());
2179             if(aStat.bModified)
2180                 pDocShell->GetDoc()->UpdateDocStat( aStat );
2181             sal_Int32 nValue;
2182             switch(pEntry->nWID)
2183             {
2184                 case  WID_DOC_CHAR_COUNT     :nValue = aStat.nChar;break;
2185                 case  WID_DOC_PARA_COUNT     :nValue = aStat.nPara;break;
2186                 case  WID_DOC_WORD_COUNT     :nValue = aStat.nWord;break;
2187             }
2188             aAny <<= nValue;
2189         }
2190         break;
2191         case  WID_DOC_WORD_SEPARATOR :
2192         {
2193             aAny <<= OUString(SW_MOD()->GetDocStatWordDelim());
2194         }
2195         break;
2196         case WID_DOC_CHANGES_RECORD:
2197         case WID_DOC_CHANGES_SHOW:
2198         {
2199             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
2200             sal_Bool bSet = sal_False;
2201             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2202             {
2203                 sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
2204                 bSet = (eMode & nMask) == nMask;
2205             }
2206             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2207             {
2208                 bSet = (eMode& nsRedlineMode_t::REDLINE_ON)  != 0;
2209             }
2210             aAny.setValue(&bSet, ::getBooleanCppuType());
2211         }
2212         break;
2213         case  WID_DOC_CHANGES_PASSWORD:
2214         {
2215             SwDoc* pDoc = pDocShell->GetDoc();
2216             aAny <<= pDoc->GetRedlinePassword();
2217         }
2218         break;
2219         case WID_DOC_AUTO_MARK_URL :
2220             aAny <<= OUString(pDocShell->GetDoc()->GetTOIAutoMarkURL());
2221         break;
2222         case WID_DOC_HIDE_TIPS :
2223         {
2224             sal_Bool bTemp = SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2225             aAny.setValue(&bTemp, ::getBooleanCppuType());
2226         }
2227         break;
2228         case WID_DOC_REDLINE_DISPLAY:
2229         {
2230             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
2231             eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
2232             sal_Int16 nRet = RedlineDisplayType::NONE;
2233             if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
2234                 nRet = RedlineDisplayType::INSERTED;
2235             else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
2236                 nRet = RedlineDisplayType::REMOVED;
2237             else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
2238                 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2239             aAny <<= nRet;
2240         }
2241         break;
2242         case WID_DOC_FORBIDDEN_CHARS:
2243         {
2244             GetPropertyHelper();
2245             Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
2246             aAny <<= xRet;
2247         }
2248         break;
2249         case WID_DOC_TWO_DIGIT_YEAR:
2250         {
2251             aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ( sal_True )->GetYear2000());
2252         }
2253         break;
2254         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2255         {
2256             SwDrawDocument * pDrawDoc;
2257             sal_Bool bAuto;
2258             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2259                 bAuto = pDrawDoc->GetAutoControlFocus();
2260             else
2261                 bAuto = sal_False;
2262             aAny.setValue(&bAuto, ::getBooleanCppuType());
2263         }
2264         break;
2265         case WID_DOC_APPLY_FORM_DESIGN_MODE:
2266         {
2267             SwDrawDocument * pDrawDoc;
2268             sal_Bool bMode;
2269             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2270                 bMode = pDrawDoc->GetOpenInDesignMode();
2271             else
2272                 bMode = sal_True;
2273             aAny.setValue(&bMode, ::getBooleanCppuType());
2274         }
2275         break;
2276         case WID_DOC_BASIC_LIBRARIES:
2277             aAny <<= pDocShell->GetBasicContainer();
2278         break;
2279         case WID_DOC_DIALOG_LIBRARIES:
2280             aAny <<= pDocShell->GetDialogContainer();
2281         break;
2282         case WID_DOC_RUNTIME_UID:
2283             aAny <<= getRuntimeUID();
2284         break;
2285         case WID_DOC_LOCK_UPDATES :
2286             aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
2287         break;
2288         case WID_DOC_BUILDID:
2289             aAny <<= maBuildId;
2290         break;
2291         case WID_DOC_HAS_VALID_SIGNATURES:
2292             aAny <<= hasValidSignatures();
2293         break;
2294         // --> OD 2006-03-21 #b6375613#
2295         case WID_APPLY_WORKAROUND_FOR_B6375613:
2296         {
2297             aAny <<= pDocShell->GetDoc()->ApplyWorkaroundForB6375613();
2298         }
2299         break;
2300         // <--
2301 
2302         default:
2303         {
2304             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2305             rItem.QueryValue(aAny, pEntry->nMemberId);
2306         }
2307     }
2308     return aAny;
2309 }
2310 /*-- 10.05.99 13:58:59---------------------------------------------------
2311 
2312   -----------------------------------------------------------------------*/
2313 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2314     const Reference< XPropertyChangeListener > & /*aListener*/)
2315     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2316 {
2317     DBG_WARNING("not implemented");
2318 }
2319 /*-- 10.05.99 13:58:59---------------------------------------------------
2320 
2321   -----------------------------------------------------------------------*/
2322 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2323     const Reference< XPropertyChangeListener > & /*aListener*/)
2324     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2325 {
2326     DBG_WARNING("not implemented");
2327 }
2328 /*-- 10.05.99 13:59:00---------------------------------------------------
2329 
2330   -----------------------------------------------------------------------*/
2331 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2332     const Reference< XVetoableChangeListener > & /*aListener*/)
2333     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2334 {
2335     DBG_WARNING("not implemented");
2336 }
2337 /*-- 10.05.99 13:59:00---------------------------------------------------
2338 
2339   -----------------------------------------------------------------------*/
2340 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2341                         const Reference< XVetoableChangeListener > & /*aListener*/)
2342     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2343 {
2344     DBG_WARNING("not implemented");
2345 }
2346 /* -----------------25.10.99 10:42-------------------
2347 
2348  --------------------------------------------------*/
2349 Reference< XNameAccess >  SwXTextDocument::getLinks(void) throw( RuntimeException )
2350 {
2351     if(!pxLinkTargetSupplier)
2352     {
2353         pxLinkTargetSupplier = new Reference< XNameAccess > ;
2354         (*pxLinkTargetSupplier) = new SwXLinkTargetSupplier(*(SwXTextDocument*)this);
2355     }
2356     return (*pxLinkTargetSupplier);
2357 }
2358 /* -----------------------------11.01.01 15:01--------------------------------
2359 
2360  ---------------------------------------------------------------------------*/
2361 Reference< XEnumerationAccess > SwXTextDocument::getRedlines(  ) throw(RuntimeException)
2362 {
2363     if(!pxXRedlines)
2364     {
2365         pxXRedlines = new Reference< XEnumerationAccess > ;
2366         (*pxXRedlines) = new SwXRedlines(pDocShell->GetDoc());
2367     }
2368     return *pxXRedlines;
2369 }
2370 /*-- 21.02.00 08:41:06---------------------------------------------------
2371 
2372   -----------------------------------------------------------------------*/
2373 void SwXTextDocument::refresh(void) throw( RuntimeException )
2374 {
2375     ::vos::OGuard aGuard(Application::GetSolarMutex());
2376     if(!IsValid())
2377         throw RuntimeException();
2378     ViewShell *pViewShell = pDocShell->GetWrtShell();
2379     notifyRefreshListeners();
2380     if(pViewShell)
2381         pViewShell->CalcLayout();
2382 }
2383 /*-- 21.02.00 08:41:06---------------------------------------------------
2384 
2385   -----------------------------------------------------------------------*/
2386 void SwXTextDocument::addRefreshListener(const Reference< util::XRefreshListener > & l)
2387     throw( RuntimeException )
2388 {
2389     ::vos::OGuard aGuard(Application::GetSolarMutex());
2390     if ( !IsValid() )
2391         throw RuntimeException();
2392     aRefreshCont.AddListener ( reinterpret_cast < const Reference < lang::XEventListener > &> ( l ));
2393 }
2394 /*-- 21.02.00 08:41:07---------------------------------------------------
2395 
2396   -----------------------------------------------------------------------*/
2397 void SwXTextDocument::removeRefreshListener(const Reference< util::XRefreshListener > & l)
2398     throw( RuntimeException )
2399 {
2400     ::vos::OGuard aGuard(Application::GetSolarMutex());
2401     if ( !IsValid() || !aRefreshCont.RemoveListener ( reinterpret_cast < const Reference < lang::XEventListener > &> ( l ) ) )
2402         throw RuntimeException();
2403 }
2404 /* -----------------------------26.02.01 12:22--------------------------------
2405 
2406  ---------------------------------------------------------------------------*/
2407 void SwXTextDocument::updateLinks(  ) throw(RuntimeException)
2408 {
2409     ::vos::OGuard aGuard(Application::GetSolarMutex());
2410     if(!IsValid())
2411         throw RuntimeException();
2412     SwDoc* pDoc = pDocShell->GetDoc();
2413     sfx2::LinkManager& rLnkMan = pDoc->GetLinkManager();
2414     if( rLnkMan.GetLinks().Count() )
2415     {
2416         UnoActionContext aAction(pDoc);
2417         rLnkMan.UpdateAllLinks( sal_False, sal_False, sal_True );
2418     }
2419 }
2420 //XPropertyState
2421 PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2422     throw (UnknownPropertyException, RuntimeException)
2423 {
2424     ::vos::OGuard aGuard(Application::GetSolarMutex());
2425     PropertyState eRet = PropertyState_DIRECT_VALUE;
2426     if(!IsValid())
2427         throw RuntimeException();
2428     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2429 
2430     if(!pEntry)
2431         throw UnknownPropertyException();
2432     Any aAny;
2433     switch(pEntry->nWID)
2434     {
2435         case 0:default:break;
2436     }
2437     return eRet;
2438 }
2439 Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2440     throw (UnknownPropertyException, RuntimeException)
2441 {
2442     const sal_Int32 nCount = rPropertyNames.getLength();
2443     const OUString * pNames = rPropertyNames.getConstArray();
2444     Sequence < PropertyState > aRet ( nCount );
2445     PropertyState *pState = aRet.getArray();
2446 
2447     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
2448         pState[nIndex] = getPropertyState( pNames[nIndex] );
2449 
2450     return aRet;
2451 }
2452 void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2453     throw (UnknownPropertyException, RuntimeException)
2454 {
2455     ::vos::OGuard aGuard(Application::GetSolarMutex());
2456     if(!IsValid())
2457         throw RuntimeException();
2458     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2459     if(!pEntry)
2460         throw UnknownPropertyException();
2461     switch(pEntry->nWID)
2462     {
2463         case 0:default:break;
2464     }
2465 }
2466 Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2467     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
2468 {
2469     ::vos::OGuard aGuard(Application::GetSolarMutex());
2470     if(!IsValid())
2471         throw RuntimeException();
2472     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2473     if(!pEntry)
2474         throw UnknownPropertyException();
2475     Any aAny;
2476     switch(pEntry->nWID)
2477     {
2478         case 0:default:break;
2479     }
2480     return aAny;
2481 }
2482 
2483 static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions )
2484 {
2485     OutputDevice *pOut = 0;
2486 
2487     uno::Any aAny( rPrintUIOptions.getValue( C2U( "RenderDevice" ) ));
2488     uno::Reference< awt::XDevice >  xRenderDevice;
2489     aAny >>= xRenderDevice;
2490     if (xRenderDevice.is())
2491     {
2492         VCLXDevice*     pDevice = VCLXDevice::GetImplementation( xRenderDevice );
2493         pOut = pDevice ? pDevice->GetOutputDevice() : 0;
2494     }
2495 
2496     return pOut;
2497 }
2498 
2499 
2500 static bool lcl_SeqHasProperty(
2501     const uno::Sequence< beans::PropertyValue >& rOptions,
2502     const sal_Char *pPropName )
2503 {
2504     bool bRes = false;
2505     const sal_Int32 nLen = rOptions.getLength();
2506     const beans::PropertyValue *pProps = rOptions.getConstArray();
2507     for (sal_Int32 i = 0;  i < nLen && !bRes;  ++i)
2508     {
2509         if (pProps[i].Name.equalsAscii( pPropName ))
2510             bRes = true;
2511     }
2512     return bRes;
2513 }
2514 
2515 
2516 SfxViewShell * SwXTextDocument::GetRenderView(
2517     bool &rbIsSwSrcView,
2518     const uno::Sequence< beans::PropertyValue >& rOptions,
2519     bool bIsPDFExport )
2520 {
2521     // get view shell to use
2522     SfxViewShell *pView = 0;
2523     if (bIsPDFExport)
2524         pView = GuessViewShell( rbIsSwSrcView );
2525     else
2526     {
2527         uno::Any aTmp;
2528         const sal_Int32 nLen = rOptions.getLength();
2529         const beans::PropertyValue *pProps = rOptions.getConstArray();
2530         for (sal_Int32 i = 0; i < nLen; ++i)
2531         {
2532             if (pProps[i].Name.equalsAscii( "View" ))
2533             {
2534                 aTmp = pProps[i].Value;
2535                 break;
2536             }
2537         }
2538 
2539         uno::Reference< frame::XController > xController;
2540         if (aTmp >>= xController)
2541         {
2542             DBG_ASSERT( xController.is(), "controller is empty!" );
2543             pView = GuessViewShell( rbIsSwSrcView, xController );
2544         }
2545     }
2546     return pView;
2547 }
2548 
2549 
2550 /*
2551  *  GetRenderDoc:
2552  *  returns the document to be rendered, usually this will be the 'regular'
2553  *  document but in case of PDF export of (multi-)selection it will
2554  *  be a temporary document that gets created if not already done.
2555  *  The rpView variable will be set (if not already done) to the used
2556  *  SfxViewShell.
2557 */
2558 
2559 SwDoc * SwXTextDocument::GetRenderDoc(
2560     SfxViewShell *&rpView,
2561     const uno::Any& rSelection,
2562     bool bIsPDFExport )
2563 {
2564     SwDoc *pDoc = 0;
2565 
2566     uno::Reference< frame::XModel > xModel;
2567     rSelection >>= xModel;
2568     if (xModel == pDocShell->GetModel())
2569         pDoc = pDocShell->GetDoc();
2570     else
2571     {
2572         DBG_ASSERT( !xModel.is(), "unexpected model found" );
2573 
2574         if (rSelection.hasValue())     // is anything selected ?
2575         {
2576             // this part should only be called when a temporary document needs to be created,
2577             // for example for PDF export or printing of (multi-)selection only.
2578 
2579             bool bIsSwSrcView = false;
2580             if (!rpView)
2581             {
2582                 (void) bIsPDFExport;
2583                 // aside from maybe PDF export the view should always have been provided!
2584                 DBG_ASSERT( bIsPDFExport, "view is missing, guessing one..." );
2585 
2586                 rpView = GuessViewShell( bIsSwSrcView );
2587             }
2588             DBG_ASSERT( rpView, "ViewShell missing" );
2589             // the view shell should be SwView for documents PDF export.
2590             // for the page preview no selection should be possible
2591             // (the export dialog does not allow for this option)
2592             const TypeId aSwViewTypeId = TYPE(SwView);
2593             if (rpView  &&  rpView->IsA(aSwViewTypeId))
2594             {
2595                 SfxObjectShellLock xDocSh(((SwView*)rpView)->GetOrCreateTmpSelectionDoc());
2596                 if (xDocSh.Is())
2597                 {
2598                     pDoc = ((SwDocShell*)&xDocSh)->GetDoc();
2599                     rpView = pDoc->GetDocShell()->GetView();
2600                 }
2601             }
2602             else
2603             {
2604                 DBG_ERROR( "unexpected ViewShell" );
2605             }
2606         }
2607     }
2608     return pDoc;
2609 }
2610 
2611 /* -----------------------------23.08.02 16:00--------------------------------
2612 
2613  ---------------------------------------------------------------------------*/
2614 
2615 static void lcl_SavePrintUIOptionsToDocumentPrintData(
2616     SwDoc &rDoc,
2617     const SwPrintUIOptions &rPrintUIOptions,
2618     bool bIsPDFEXport )
2619 {
2620     SwPrintData aDocPrintData( rDoc.getPrintData() );
2621 
2622     aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2623     aDocPrintData.SetPrintTable( rPrintUIOptions.IsPrintTables() );
2624     aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2625     aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2626     aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2627     aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2628     aDocPrintData.SetPrintReverse( rPrintUIOptions.IsPrintReverse() );
2629     aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2630     aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2631     aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2632     aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2633     aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2634     aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2635     aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2636     // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2637     // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2638     aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2639     aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2640 
2641     rDoc.setPrintData( aDocPrintData );
2642 }
2643 
2644 
2645 sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
2646         const uno::Any& rSelection,
2647         const uno::Sequence< beans::PropertyValue >& rxOptions )
2648     throw (IllegalArgumentException, RuntimeException)
2649 {
2650     ::vos::OGuard aGuard(Application::GetSolarMutex());
2651     if(!IsValid())
2652         throw RuntimeException();
2653 
2654     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2655     bool bIsSwSrcView = false;
2656     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2657 
2658     if (!bIsSwSrcView && !m_pRenderData)
2659         m_pRenderData = new SwRenderData;
2660     if (!m_pPrintUIOptions)
2661         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2662     bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2663     // const bool bIsSkipEmptyPages    = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2664 
2665     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2666     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
2667     if (!pDoc || !pView)
2668         return 0;
2669 
2670     // save current UI options from the print dialog for the next call to that dialog
2671     lcl_SavePrintUIOptionsToDocumentPrintData( *pDoc, *m_pPrintUIOptions, bIsPDFExport );
2672 
2673     sal_Int32 nRet = 0;
2674     if (bIsSwSrcView)
2675     {
2676         SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2677         OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2678         nRet = pSwSrcView->PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2679     }
2680     else
2681     {
2682         SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2683 
2684         // TODO/mba: we really need a generic way to get the ViewShell!
2685         ViewShell* pViewShell = 0;
2686         SwView* pSwView = PTR_CAST(SwView, pView);
2687         if ( pSwView )
2688         {
2689             pViewShell = pSwView->GetWrtShellPtr();
2690         }
2691         else
2692         {
2693             if ( bIsPDFExport && bFormat )
2694             {
2695                 //create a hidden view to be able to export as PDF also in print preview
2696                 //pView and pSwView are not changed intentionally!
2697                 m_pHiddenViewFrame = SfxViewFrame::LoadHiddenDocument( *pRenderDocShell, 2 );
2698                 pViewShell = ((SwView*)m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2699             }
2700             else
2701                 pViewShell = ((SwPagePreView*)pView)->GetViewShell();
2702         }
2703 
2704         if (!pViewShell || !pViewShell->GetLayout())
2705             return 0;
2706 
2707         if (bFormat)
2708         {
2709             // #i38289
2710             if( pViewShell->GetViewOptions()->getBrowseMode() )
2711             {
2712                 SwViewOption aOpt( *pViewShell->GetViewOptions() );
2713                 aOpt.setBrowseMode( false );
2714                 pViewShell->ApplyViewOptions( aOpt );
2715                 pSwView->RecheckBrowseMode();
2716             }
2717 
2718             // reformating the document for printing will show the changes in the view
2719             // which is likely to produce many unwanted and not nice to view actions.
2720             // We don't want that! Thus we disable updating of the view.
2721             pViewShell->StartAction();
2722 
2723             if (pSwView)
2724             {
2725                 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2726                     m_pRenderData->ViewOptionAdjustStop();
2727                 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2728                     m_pRenderData->ViewOptionAdjustStart( *pViewShell, *pViewShell->GetViewOptions() );
2729             }
2730 
2731             m_pRenderData->SetSwPrtOptions( new SwPrintData );
2732             m_pRenderData->MakeSwPrtOptions( m_pRenderData->GetSwPrtOptionsRef(), pRenderDocShell,
2733                     m_pPrintUIOptions, m_pRenderData, bIsPDFExport );
2734 
2735             if (pSwView)
2736             {
2737                 // PDF export should not make use of the SwPrtOptions
2738                 const SwPrintData *pPrtOptions = (bIsPDFExport)
2739                     ? NULL : m_pRenderData->GetSwPrtOptions();
2740                 m_pRenderData->ViewOptionAdjust( pPrtOptions );
2741             }
2742 
2743             // since printing now also use the API for PDF export this option
2744             // should be set for printing as well ...
2745             pViewShell->SetPDFExportOption( sal_True );
2746             bool bOrigStatus = pRenderDocShell->IsEnableSetModified();
2747             // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2748             bool bStateChanged = false;
2749             if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
2750             {
2751                 pRenderDocShell->EnableSetModified( sal_False );
2752                 bStateChanged = true;
2753             }
2754 
2755             // --> FME 2005-05-23 #122919# Force field update before PDF export:
2756             pViewShell->ViewShell::UpdateFlds(sal_True);
2757             // <--
2758             if( bStateChanged )
2759                 pRenderDocShell->EnableSetModified( sal_True );
2760 
2761             // there is some redundancy between those two function calls, but right now
2762             // there is no time to sort this out.
2763             //TODO: check what exatly needs to be done and make just one function for that
2764             pViewShell->CalcLayout();
2765             pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2766 
2767             pViewShell->SetPDFExportOption( sal_False );
2768 
2769             // enable view again
2770             pViewShell->EndAction();
2771         }
2772 
2773         const sal_Int32 nPageCount = pViewShell->GetPageCount();
2774 
2775         //
2776         // get number of pages to be rendered
2777         //
2778         const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2779         if (bPrintProspect)
2780         {
2781             pDoc->CalculatePagePairsForProspectPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, nPageCount );
2782             nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2783         }
2784         else
2785         {
2786             const sal_Int16 nPostItMode = (sal_Int16) m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 );
2787             if (nPostItMode != POSTITS_NONE)
2788             {
2789                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2790                 m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
2791             }
2792 
2793             // get set of valid document pages (according to the current settings)
2794             // and their start frames
2795             pDoc->CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2796 
2797             if (nPostItMode != POSTITS_NONE)
2798             {
2799                 pDoc->UpdatePagesForPrintingWithPostItData( *m_pRenderData,
2800                         *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2801             }
2802 
2803             nRet = m_pRenderData->GetPagesToPrint().size();
2804         }
2805     }
2806     DBG_ASSERT( nRet >= 0, "negative number of pages???" );
2807 
2808     return nRet;
2809 }
2810 /* -----------------------------23.08.02 16:00--------------------------------
2811 
2812  ---------------------------------------------------------------------------*/
2813 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2814         sal_Int32 nRenderer,
2815         const uno::Any& rSelection,
2816         const uno::Sequence< beans::PropertyValue >& rxOptions )
2817     throw (IllegalArgumentException, RuntimeException)
2818 {
2819     ::vos::OGuard aGuard(Application::GetSolarMutex());
2820     if(!IsValid())
2821         throw RuntimeException();
2822 
2823     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2824     bool bIsSwSrcView = false;
2825     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2826 
2827     // m_pRenderData should NOT be created here!
2828     // That should only be done in getRendererCount. If this function is called before
2829     // getRendererCount was called then the caller will probably just retrieve the extra UI options
2830     // and is not interested in getting valid information about the other data that would
2831     // otherwise be provided here!
2832 //    if( ! m_pRenderData )
2833 //        m_pRenderData = new SwRenderData;
2834     if (!m_pPrintUIOptions)
2835         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2836     m_pPrintUIOptions->processProperties( rxOptions );
2837     const bool bPrintProspect    = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2838     const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2839     const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup", false );
2840 
2841     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2842     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
2843     if (!pDoc || !pView)
2844         return uno::Sequence< beans::PropertyValue >();
2845 
2846     // due to #110067# (document page count changes sometimes during
2847     // PDF export/printing) we can not check for the upper bound properly.
2848     // Thus instead of throwing the exception we silently return.
2849     if (0 > nRenderer)
2850         throw IllegalArgumentException();
2851 
2852     // TODO/mba: we really need a generic way to get the ViewShell!
2853     ViewShell* pVwSh = 0;
2854     SwView* pSwView = PTR_CAST(SwView, pView);
2855     if ( pSwView )
2856         pVwSh = pSwView->GetWrtShellPtr();
2857     else
2858         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
2859 
2860     sal_Int32 nMaxRenderer = 0;
2861     if (!bIsSwSrcView && m_pRenderData)
2862     {
2863         DBG_ASSERT( m_pRenderData, "m_pRenderData missing!!" );
2864         nMaxRenderer = bPrintProspect?
2865             m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2866             m_pRenderData->GetPagesToPrint().size() - 1;
2867     }
2868     // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2869     // we obmit checking of the upper bound in this case.
2870     if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2871         return uno::Sequence< beans::PropertyValue >();
2872 
2873     uno::Sequence< beans::PropertyValue > aRenderer;
2874     if (m_pRenderData)
2875     {
2876         // --> TL, OD 2010-09-07 #i114210#
2877         // determine the correct page number from the renderer index
2878         // --> OD 2010-10-01 #i114875
2879         // consider brochure print
2880         const sal_uInt16 nPage = bPrintProspect
2881                              ? nRenderer + 1
2882                              : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2883         // <--
2884 
2885         // get paper tray to use ...
2886         sal_Int32 nPrinterPaperTray = -1;
2887         if (! bPrintPaperFromSetup)
2888         {
2889             // ... from individual page style (see the page tab in Format/Page dialog)
2890             const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2891             std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2892             if (aIt != rPaperTrays.end())
2893                 nPrinterPaperTray = aIt->second;
2894         }
2895 
2896         awt::Size aPageSize;
2897         awt::Size aPreferredPageSize;
2898         Size aTmpSize;
2899         if (bIsSwSrcView || bPrintProspect)
2900         {
2901             // for printing of HTML source code and prospect printing we should use
2902             // the printers paper size since
2903             // a) HTML source view has no page size
2904             // b) prospect printing has a different page size from the documents page
2905             //    since two document pages will get rendered on one printer page
2906 
2907             // since PageIncludesNonprintableArea will be set to true we can return the
2908             // printers paper size here.
2909             // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2910             // case we won't get an OutputDevice here, but then the caller also has no need
2911             // for the correct PageSisze right now...
2912             Printer *pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ));
2913             if (pPrinter)
2914             {
2915                 // HTML source view and prospect adapt to the printer's paper size
2916                 aTmpSize = pPrinter->GetPaperSize();
2917                 aTmpSize = pPrinter->LogicToLogic( aTmpSize,
2918                             pPrinter->GetMapMode(), MapMode( MAP_100TH_MM ));
2919                 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2920                 #if 0
2921                 // #i115048# it seems users didn't like getting double the formatted page size
2922                 // revert to "old" behavior scaling to the current paper size of the printer
2923                 if (bPrintProspect)
2924                 {
2925                     // we just state what output size we would need
2926                     // which may cause vcl to set that page size on the printer
2927                     // (if available and not overriden by the user)
2928                     aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2929                     aPreferredPageSize = awt::Size ( TWIP_TO_MM100( 2 * aTmpSize.Width() ),
2930                                                      TWIP_TO_MM100( aTmpSize.Height() ));
2931                 }
2932                 #else
2933                 if( bPrintProspect )
2934                 {
2935                     // just switch to an appropriate portrait/landscape format
2936                     // FIXME: brochure printing with landscape pages puts the
2937                     // pages next to each other, so landscape is currently always
2938                     // the better choice
2939                     if( aPageSize.Width < aPageSize.Height )
2940                     {
2941                         aPreferredPageSize.Width = aPageSize.Height;
2942                         aPreferredPageSize.Height = aPageSize.Width;
2943                     }
2944                 }
2945                 #endif
2946             }
2947         }
2948         else
2949         {
2950             aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2951             aPageSize = awt::Size ( TWIP_TO_MM100( aTmpSize.Width() ),
2952                                     TWIP_TO_MM100( aTmpSize.Height() ));
2953         }
2954 
2955         sal_Int32 nLen = 2;
2956         aRenderer.realloc(2);
2957         aRenderer[0].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
2958         aRenderer[0].Value <<= aPageSize;
2959         aRenderer[1].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageIncludesNonprintableArea" ) );
2960         aRenderer[1].Value <<= sal_True;
2961         if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2962         {
2963             ++nLen;
2964             aRenderer.realloc( nLen );
2965             aRenderer[ nLen - 1 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PreferredPageSize" ) );
2966             aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2967         }
2968         if (nPrinterPaperTray >= 0)
2969         {
2970             ++nLen;
2971             aRenderer.realloc( nLen );
2972             aRenderer[ nLen - 1 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PrinterPaperTray" ) );
2973             aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2974         }
2975     }
2976 
2977     // --> OD #i117783#
2978     if ( bApplyPagePrintSettingsFromXPagePrintable )
2979     {
2980         const SwPagePreViewPrtData* pPagePrintSettings =
2981                                         pDocShell->GetDoc()->GetPreViewPrtData();
2982         if ( pPagePrintSettings &&
2983              ( pPagePrintSettings->GetRow() > 1 ||
2984                pPagePrintSettings->GetCol() > 1 ) )
2985         {
2986             // extend render data by page print settings attributes
2987             sal_Int32 nLen = aRenderer.getLength();
2988             const sal_Int32 nRenderDataIdxStart = nLen;
2989             nLen += 9;
2990             aRenderer.realloc( nLen );
2991             // put page print settings attribute into render data
2992             const sal_Int32 nRow = pPagePrintSettings->GetRow();
2993             aRenderer[ nRenderDataIdxStart + 0 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpRows" ) );
2994             aRenderer[ nRenderDataIdxStart + 0 ].Value <<= ( nRow > 1 ? nRow : 1 );
2995             const sal_Int32 nCol = pPagePrintSettings->GetCol();
2996             aRenderer[ nRenderDataIdxStart + 1 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpColumns" ) );
2997             aRenderer[ nRenderDataIdxStart + 1 ].Value <<= ( nCol > 1 ? nCol : 1 );
2998             aRenderer[ nRenderDataIdxStart + 2 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpPageMarginLeft" ) );
2999             aRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
3000             aRenderer[ nRenderDataIdxStart + 3 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpPageMarginRight" ) );
3001             aRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
3002             aRenderer[ nRenderDataIdxStart + 4 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpPageMarginTop" ) );
3003             aRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
3004             aRenderer[ nRenderDataIdxStart + 5 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpPageMarginBottom" ) );
3005             aRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
3006             aRenderer[ nRenderDataIdxStart + 6 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpHorizontalSpacing" ) );
3007             aRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
3008             aRenderer[ nRenderDataIdxStart + 7 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpVerticalSpacing" ) );
3009             aRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
3010             {
3011                 Printer* pPrinter = pDocShell->GetDoc()->getPrinter( false );
3012                 if ( pPrinter )
3013                 {
3014                     awt::Size aNewPageSize;
3015                     const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
3016                     aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
3017                     if ( ( pPagePrintSettings->GetLandscape() &&
3018                            aPageSize.Width() < aPageSize.Height() ) ||
3019                          ( !pPagePrintSettings->GetLandscape() &&
3020                            aPageSize.Width() > aPageSize.Height() ) )
3021                     {
3022                         aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
3023                     }
3024                     aRenderer[ nRenderDataIdxStart + 8 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "NUpPaperSize" ) );
3025                     aRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
3026                 }
3027             }
3028         }
3029 
3030         bApplyPagePrintSettingsFromXPagePrintable = sal_False;
3031     }
3032     // <--
3033 
3034     m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
3035 
3036     return aRenderer;
3037 }
3038 /* -----------------------------28.10.02 16:00--------------------------------
3039 
3040  ---------------------------------------------------------------------------*/
3041 SfxViewShell * SwXTextDocument::GuessViewShell(
3042     /* out */ bool &rbIsSwSrcView,
3043     const uno::Reference< css::frame::XController > xController )
3044 {
3045     // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
3046     // must not be used (see comment from MBA)
3047     //
3048     SfxViewShell    *pView = 0;
3049     SwView          *pSwView = 0;
3050     SwPagePreView   *pSwPagePreView = 0;
3051     SwSrcView       *pSwSrcView = 0;
3052     SfxViewFrame    *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
3053 
3054     // look for the view shell with the same controller in use,
3055     // otherwise look for a suitable view, preferably a SwView,
3056     // if that one is not found use a SwPagePreView if found.
3057     while (pFrame)
3058     {
3059         pView = pFrame->GetViewShell();
3060         pSwView = dynamic_cast< SwView * >(pView);
3061         pSwSrcView = dynamic_cast< SwSrcView * >(pView);
3062         if (!pSwPagePreView)
3063             pSwPagePreView = dynamic_cast< SwPagePreView * >(pView);
3064         if (xController.is())
3065         {
3066             if (pView && pView->GetController() == xController)
3067                 break;
3068         }
3069         else if (pSwView || pSwSrcView)
3070             break;
3071         pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell,  sal_False );
3072     }
3073 
3074     DBG_ASSERT( pSwView || pSwPagePreView || pSwSrcView, "failed to get view shell" );
3075     if (pView)
3076         rbIsSwSrcView = pSwSrcView != 0;
3077     return pView;
3078 //    return pSwView ? dynamic_cast< SfxViewShell * >(pSwView) :
3079 //            (pSwSrcView ? dynamic_cast< SfxViewShell * >(pSwSrcView) :
3080 //                          dynamic_cast< SfxViewShell * >(pSwPagePreView) );
3081 }
3082 
3083 
3084 void SAL_CALL SwXTextDocument::render(
3085         sal_Int32 nRenderer,
3086         const uno::Any& rSelection,
3087         const uno::Sequence< beans::PropertyValue >& rxOptions )
3088     throw (IllegalArgumentException, RuntimeException)
3089 {
3090     ::vos::OGuard aGuard(Application::GetSolarMutex());
3091     if(!IsValid())
3092         throw RuntimeException();
3093 
3094     // due to #110067# (document page count changes sometimes during
3095     // PDF export/printing) we can not check for the upper bound properly.
3096     // Thus instead of throwing the exception we silently return.
3097     if (0 > nRenderer)
3098         throw IllegalArgumentException();
3099 
3100     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
3101     bool bIsSwSrcView = false;
3102     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
3103 
3104     DBG_ASSERT( m_pRenderData, "data should have been created already in getRendererCount..." );
3105     DBG_ASSERT( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
3106     if (!bIsSwSrcView && !m_pRenderData)
3107         m_pRenderData = new SwRenderData;
3108     if (!m_pPrintUIOptions)
3109         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
3110     m_pPrintUIOptions->processProperties( rxOptions );
3111     const bool bPrintProspect   = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
3112     const bool bLastPage        = m_pPrintUIOptions->getBoolValue( "IsLastPage", sal_False );
3113 
3114     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
3115     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
3116     if (pDoc && pView)
3117     {
3118         sal_Int32 nMaxRenderer = 0;
3119         if (!bIsSwSrcView)
3120         {
3121             DBG_ASSERT( m_pRenderData, "m_pRenderData missing!!" );
3122             nMaxRenderer = bPrintProspect?
3123                 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
3124                 m_pRenderData->GetPagesToPrint().size() - 1;
3125         }
3126         // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
3127         // we obmit checking of the upper bound in this case.
3128         if (bIsSwSrcView || nRenderer <= nMaxRenderer)
3129         {
3130             if (bIsSwSrcView)
3131             {
3132                 SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
3133                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
3134                 pSwSrcView->PrintSource( pOutDev, nRenderer + 1, false );
3135             }
3136             else
3137             {
3138                 // the view shell should be SwView for documents PDF export
3139                 // or SwPagePreView for PDF export of the page preview
3140                 //!! (check for SwView first as in GuessViewShell) !!
3141                 DBG_ASSERT( pView, "!! view missing !!" );
3142                 const TypeId aSwViewTypeId = TYPE(SwView);
3143                 ViewShell* pVwSh = 0;
3144                 if (pView)
3145                 {
3146                     // TODO/mba: we really need a generic way to get the ViewShell!
3147                     SwView* pSwView = PTR_CAST(SwView, pView);
3148                     if ( pSwView )
3149                         pVwSh = pSwView->GetWrtShellPtr();
3150                     else
3151                         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
3152                 }
3153 
3154                 // get output device to use
3155                 OutputDevice * pOut = lcl_GetOutputDevice( *m_pPrintUIOptions );
3156 
3157                 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
3158                 {
3159                     const rtl::OUString aPageRange  = m_pPrintUIOptions->getStringValue( "PageRange", OUString() );
3160                     const bool bFirstPage           = m_pPrintUIOptions->getBoolValue( "IsFirstPage", sal_False );
3161                     bool bIsSkipEmptyPages          = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
3162 
3163                     DBG_ASSERT(( pView->IsA(aSwViewTypeId) &&  m_pRenderData->IsViewOptionAdjust())
3164                             || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()),
3165                             "SwView / SwViewOptionAdjust_Impl availability mismatch" );
3166 
3167                     // since printing now also use the API for PDF export this option
3168                     // should be set for printing as well ...
3169                     pVwSh->SetPDFExportOption( sal_True );
3170 
3171                     // --> FME 2004-06-08 #i12836# enhanced pdf export
3172                     //
3173                     // First, we have to export hyperlinks, notes, and outline to pdf.
3174                     // During this process, additional information required for tagging
3175                     // the pdf file are collected, which are evaulated during painting.
3176                     //
3177                     SwWrtShell* pWrtShell = pView->IsA(aSwViewTypeId) ?
3178                                             ((SwView*)pView)->GetWrtShellPtr() :
3179                                             0;
3180 
3181                     if (bIsPDFExport && bFirstPage && pWrtShell)
3182                     {
3183                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_False );
3184                     }
3185                     // <--
3186 
3187                     SwPrintData const& rSwPrtOptions =
3188                         *m_pRenderData->GetSwPrtOptions();
3189                     if (bPrintProspect)
3190                         pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
3191                     else    // normal printing and PDF export
3192                         pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer );
3193 
3194                     // --> FME 2004-10-08 #i35176#
3195                     //
3196                     // After printing the last page, we take care for the links coming
3197                     // from the EditEngine. The links are generated during the painting
3198                     // process, but the destinations are still missing.
3199                     //
3200                     if (bIsPDFExport && bLastPage && pWrtShell)
3201                     {
3202                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages,  sal_True );
3203                     }
3204                     // <--
3205 
3206                     pVwSh->SetPDFExportOption( sal_False );
3207 
3208                     // last page to be rendered? (not necessarily the last page of the document)
3209                     // -> do clean-up of data
3210                     if (bLastPage)
3211                     {
3212                         // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3213                         // of the shell, which might get destroyed in lcl_DisposeView!
3214                         if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
3215                             m_pRenderData->ViewOptionAdjustStop();
3216 
3217                         if (m_pRenderData && m_pRenderData->HasPostItData())
3218                             m_pRenderData->DeletePostItData();
3219                         if (m_pHiddenViewFrame)
3220                         {
3221                             lcl_DisposeView( m_pHiddenViewFrame, pDocShell );
3222                             m_pHiddenViewFrame = 0;
3223 
3224                             // prevent crash described in #i108805
3225                             SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3226                             SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3227                             pSet->Put( SfxBoolItem( SID_HIDDEN, sal_False ) );
3228 
3229                         }
3230                     }
3231                 }
3232             }
3233         }
3234     }
3235     if( bLastPage )
3236     {
3237         delete m_pRenderData;       m_pRenderData     = NULL;
3238         delete m_pPrintUIOptions;   m_pPrintUIOptions = NULL;
3239     }
3240 }
3241 /* -----------------------------03.10.04 -------------------------------------
3242 
3243  ---------------------------------------------------------------------------*/
3244     // xforms::XFormsSupplier
3245 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3246     throw( RuntimeException )
3247 {
3248     if ( !pDocShell )
3249         throw DisposedException( ::rtl::OUString(), static_cast< XTextDocument* >( this ) );
3250     SwDoc* pDoc = pDocShell->GetDoc();
3251     return pDoc->getXForms();
3252 }
3253 
3254 /* -----------------------------25.09.07 -------------------------------------
3255 
3256  ---------------------------------------------------------------------------*/
3257 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3258     throw ( uno::RuntimeException )
3259 {
3260     return new SwXFlatParagraphIterator( *pDocShell->GetDoc(), nTextMarkupType, bAutomatic );
3261 }
3262 /*-- 07.05.2009 09:21:12---------------------------------------------------
3263 
3264   -----------------------------------------------------------------------*/
3265 uno::Reference< util::XCloneable > SwXTextDocument::createClone(  ) throw (uno::RuntimeException)
3266 {
3267     ::vos::OGuard aGuard(Application::GetSolarMutex());
3268     if(!IsValid())
3269         throw RuntimeException();
3270 
3271     // create a new document - hidden - copy the storage and return it
3272     // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3273     // and thus SfxObjectShellLock is not allowed here
3274     // the model holds reference to the shell, so the shell will not destructed at the end of method
3275     SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false);
3276     uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3277     uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3278     uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3279     storeToStorage( xNewStorage, aTempMediaDescriptor );
3280     uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3281     xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3282     return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3283 }
3284 /* -----------------------------20.06.00 09:54--------------------------------
3285 
3286  ---------------------------------------------------------------------------*/
3287 void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
3288 {
3289     return SwXTextDocumentBaseClass::operator new(t);
3290 }
3291 /* -----------------------------20.06.00 09:54--------------------------------
3292 
3293  ---------------------------------------------------------------------------*/
3294 void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
3295 {
3296     SwXTextDocumentBaseClass::operator delete(p);
3297 }
3298 
3299 
3300 /*---------------------------------------------------
3301 retrieve languages already used in current document
3302 -----------------------------------------------------*/
3303 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3304         ::sal_Int16 nScriptTypes,
3305         ::sal_Int16 nMaxCount )
3306     throw (lang::IllegalArgumentException, uno::RuntimeException)
3307 {
3308     ::vos::OGuard aGuard(Application::GetSolarMutex());
3309 
3310     // possible canonical values for nScriptTypes
3311     // any bit wise combination is allowed
3312     const sal_Int16 nLatin   = 0x001;
3313     const sal_Int16 nAsian   = 0x002;
3314     const sal_Int16 nComplex = 0x004;
3315 
3316     // script types for which to get the languages
3317     const bool bLatin   = 0 != (nScriptTypes & nLatin);
3318     const bool bAsian   = 0 != (nScriptTypes & nAsian);
3319     const bool bComplex = 0 != (nScriptTypes & nComplex);
3320 
3321     if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3322         throw IllegalArgumentException(::rtl::OUString::createFromAscii("nScriptTypes ranges from 1 to 7!"), Reference< XInterface >(), 1);
3323     if (!pDocShell)
3324         throw DisposedException();
3325     SwDoc* pDoc = pDocShell->GetDoc();
3326 
3327     // avoid duplicate values
3328     std::set< LanguageType > aAllLangs;
3329 
3330     //USER STYLES
3331 
3332     const SwCharFmts *pFmts = pDoc->GetCharFmts();
3333     for(sal_uInt16 i = 0; i < pFmts->Count(); ++i)
3334     {
3335         const SwAttrSet &rAttrSet = (*pFmts)[i]->GetAttrSet();
3336         LanguageType nLang = LANGUAGE_DONTKNOW;
3337         if (bLatin)
3338         {
3339             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3340             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3341                 aAllLangs.insert( nLang );
3342         }
3343         if (bAsian)
3344         {
3345             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3346             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3347                 aAllLangs.insert( nLang );
3348         }
3349         if (bComplex)
3350         {
3351             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3352             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3353                 aAllLangs.insert( nLang );
3354         }
3355     }
3356 
3357     const SwTxtFmtColls *pColls = pDoc->GetTxtFmtColls();
3358     for (sal_uInt16 i = 0; i < pColls->Count(); ++i)
3359     {
3360         const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3361         LanguageType nLang = LANGUAGE_DONTKNOW;;
3362         if (bLatin)
3363         {
3364             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3365             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3366                 aAllLangs.insert( nLang );
3367         }
3368         if (bAsian)
3369         {
3370             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3371             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3372                 aAllLangs.insert( nLang );
3373         }
3374         if (bComplex)
3375         {
3376             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3377             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3378                 aAllLangs.insert( nLang );
3379         }
3380     }
3381 
3382     //AUTO STYLES
3383     const IStyleAccess::SwAutoStyleFamily aFam[2] =
3384     {
3385       IStyleAccess::AUTO_STYLE_CHAR,
3386       IStyleAccess::AUTO_STYLE_PARA
3387     };
3388     for (sal_uInt16 i = 0; i < 2; ++i)
3389     {
3390         std::vector< SfxItemSet_Pointer_t > rStyles;
3391         pDoc->GetIStyleAccess().getAllStyles(rStyles, aFam[i]);
3392         while (!rStyles.empty())
3393         {
3394             SfxItemSet_Pointer_t pStyle = rStyles.back();
3395             rStyles.pop_back();
3396             const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
3397 
3398             LanguageType nLang = LANGUAGE_DONTKNOW;
3399             if (bLatin)
3400             {
3401                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, sal_False )).GetLanguage();
3402                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3403                     aAllLangs.insert( nLang );
3404             }
3405             if (bAsian)
3406             {
3407                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, sal_False )).GetLanguage();
3408                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3409                     aAllLangs.insert( nLang );
3410             }
3411             if (bComplex)
3412             {
3413                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, sal_False )).GetLanguage();
3414                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3415                     aAllLangs.insert( nLang );
3416             }
3417         }
3418     }
3419 
3420     //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3421     SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
3422     SdrView *pSdrView = pWrtSh->GetDrawView();
3423 
3424     if( pSdrView )
3425     {
3426         SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3427         if(pOutliner)
3428         {
3429             EditEngine& rEditEng = (EditEngine&)pOutliner->GetEditEngine();
3430             sal_uLong nParCount = pOutliner->GetParagraphCount();
3431             for (sal_uLong nPar=0; nPar<nParCount; nPar++)
3432             {
3433                 //every paragraph
3434                 SvUShorts aPortions;
3435                 rEditEng.GetPortions( (sal_uInt16)nPar, aPortions );
3436 
3437                 for ( sal_uInt16 nPos = aPortions.Count(); nPos; )
3438                 {
3439                     //every position
3440                     --nPos;
3441                     sal_uInt16 nEnd = aPortions.GetObject( nPos );
3442                     sal_uInt16 nStart = nPos ? aPortions.GetObject( nPos - 1 ) : 0;
3443                     ESelection aSelection( (sal_uInt16)nPar, nStart, (sal_uInt16)nPar, nEnd );
3444                     SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3445 
3446                     LanguageType nLang = LANGUAGE_DONTKNOW;
3447                     if (bLatin)
3448                     {
3449                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, sal_False )).GetLanguage();
3450                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3451                             aAllLangs.insert( nLang );
3452                     }
3453                     if (bAsian)
3454                     {
3455                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, sal_False )).GetLanguage();
3456                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3457                             aAllLangs.insert( nLang );
3458                     }
3459                     if (bComplex)
3460                     {
3461                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, sal_False )).GetLanguage();
3462                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3463                             aAllLangs.insert( nLang );
3464                     }
3465                 }
3466             }
3467         }
3468     }
3469     // less than nMaxCount languages
3470     if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3471         nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3472 
3473     // build return value
3474     sal_Int32 nCount = 0;
3475     uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3476     lang::Locale* pLanguage = aLanguages.getArray();
3477     if (nMaxCount > 0)
3478     {
3479         const SvtLanguageTable aLangTab;
3480         for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
3481         {
3482             if (nCount >= nMaxCount)
3483                 break;
3484             if (LANGUAGE_NONE != *it)
3485             {
3486                 MsLangId::convertLanguageToLocale( *it, pLanguage[nCount] );
3487                 pLanguage[nCount].Language = aLangTab.GetString( *it );
3488                 nCount += 1;
3489             }
3490         }
3491     }
3492 
3493     return aLanguages;
3494 }
3495 
3496 /* -----------------25.10.99 11:06-------------------
3497 
3498  --------------------------------------------------*/
3499 SwXLinkTargetSupplier::SwXLinkTargetSupplier(SwXTextDocument& rxDoc) :
3500     pxDoc(&rxDoc)
3501 {
3502     sTables     = String(SW_RES(STR_CONTENT_TYPE_TABLE));
3503     sFrames     = String(SW_RES(STR_CONTENT_TYPE_FRAME));
3504     sGraphics   = String(SW_RES(STR_CONTENT_TYPE_GRAPHIC));
3505     sOLEs       = String(SW_RES(STR_CONTENT_TYPE_OLE));
3506     sSections   = String(SW_RES(STR_CONTENT_TYPE_REGION));
3507     sOutlines   = String(SW_RES(STR_CONTENT_TYPE_OUTLINE));
3508     sBookmarks  = String(SW_RES(STR_CONTENT_TYPE_BOOKMARK));
3509 }
3510 /* -----------------25.10.99 11:11-------------------
3511 
3512  --------------------------------------------------*/
3513 SwXLinkTargetSupplier::~SwXLinkTargetSupplier()
3514 {
3515 }
3516 
3517 /*-- 25.10.99 11:12:45---------------------------------------------------
3518 
3519   -----------------------------------------------------------------------*/
3520 Any SwXLinkTargetSupplier::getByName(const OUString& rName)
3521     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3522 {
3523     Any aRet;
3524     if(!pxDoc)
3525         throw RuntimeException();
3526     String sToCompare(rName);
3527     String sSuffix('|');
3528     if(sToCompare == sTables)
3529     {
3530         sSuffix += UniString::CreateFromAscii(pMarkToTable);
3531 
3532         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3533                                         pxDoc->getTextTables(), sToCompare, sSuffix );
3534         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3535         aRet.setValue(&xRet, ::getCppuType((Reference<XPropertySet>*)0));
3536     }
3537     else if(sToCompare == sFrames)
3538     {
3539         sSuffix += UniString::CreateFromAscii(pMarkToFrame);
3540         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3541                                         pxDoc->getTextFrames(), sToCompare, sSuffix );
3542         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3543         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3544     }
3545     else if(sToCompare == sSections)
3546     {
3547         sSuffix += UniString::CreateFromAscii(pMarkToRegion);
3548         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3549                                         pxDoc->getTextSections(), sToCompare, sSuffix );
3550         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3551         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3552     }
3553 /*  else if(sToCompare == )
3554     {
3555         sSuffix += UniString::CreateFromAscii(pMarkToText);
3556         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3557                                         pxDoc->, sSuffix );
3558         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3559         aRet.setValue(&xRet, ::getCppuType((const XPropertySet*)0));
3560     }*/
3561     else if(sToCompare == sGraphics)
3562     {
3563         sSuffix += UniString::CreateFromAscii(pMarkToGraphic);
3564         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3565                                         pxDoc->getGraphicObjects(), sToCompare, sSuffix );
3566         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3567         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3568     }
3569     else if(sToCompare == sOLEs)
3570     {
3571         sSuffix += UniString::CreateFromAscii(pMarkToOLE);
3572         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3573                                         pxDoc->getEmbeddedObjects(), sToCompare, sSuffix );
3574         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3575         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3576     }
3577     else if(sToCompare == sOutlines)
3578     {
3579         sSuffix += UniString::CreateFromAscii(pMarkToOutline);
3580         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3581                                         *pxDoc, sToCompare, sSuffix );
3582         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3583         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3584     }
3585     else if(sToCompare == sBookmarks)
3586     {
3587         sSuffix.Erase();
3588         Reference< XNameAccess >  xBkms = new SwXLinkNameAccessWrapper(
3589                                         pxDoc->getBookmarks(), sToCompare, sSuffix );
3590         Reference< XPropertySet >  xRet(xBkms, UNO_QUERY);
3591         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3592     }
3593     else
3594         throw NoSuchElementException();
3595     return aRet;
3596 }
3597 /*-- 25.10.99 11:12:46---------------------------------------------------
3598 
3599   -----------------------------------------------------------------------*/
3600 Sequence< OUString > SwXLinkTargetSupplier::getElementNames(void)
3601                                         throw( RuntimeException )
3602 {
3603     Sequence< OUString > aRet(7);
3604     OUString* pNames = aRet.getArray();
3605     pNames[0] = sTables;
3606     pNames[1] = sFrames  ;
3607     pNames[2] = sGraphics;
3608     pNames[3] = sOLEs   ;
3609     pNames[4] = sSections;
3610     pNames[5] = sOutlines;
3611     pNames[6] = sBookmarks;
3612     return aRet;
3613 }
3614 /*-- 25.10.99 11:12:46---------------------------------------------------
3615 
3616   -----------------------------------------------------------------------*/
3617 sal_Bool SwXLinkTargetSupplier::hasByName(const OUString& rName)
3618                                     throw( RuntimeException )
3619 {
3620     String sToCompare(rName);
3621     if( sToCompare == sTables  ||
3622         sToCompare == sFrames  ||
3623         sToCompare == sGraphics||
3624         sToCompare == sOLEs   ||
3625         sToCompare == sSections ||
3626         sToCompare == sOutlines ||
3627         sToCompare == sBookmarks    )
3628         return sal_True;
3629     return sal_False;
3630 }
3631 /*-- 25.10.99 11:12:47---------------------------------------------------
3632 
3633   -----------------------------------------------------------------------*/
3634 uno::Type  SwXLinkTargetSupplier::getElementType(void)
3635                                     throw( RuntimeException )
3636 {
3637     return ::getCppuType((Reference< XPropertySet>*)0);
3638 
3639 }
3640 /*-- 25.10.99 11:12:47---------------------------------------------------
3641 
3642   -----------------------------------------------------------------------*/
3643 sal_Bool SwXLinkTargetSupplier::hasElements(void) throw( RuntimeException )
3644 {
3645     return 0 != pxDoc;
3646 }
3647 /*-- 25.10.99 11:12:47---------------------------------------------------
3648 
3649   -----------------------------------------------------------------------*/
3650 OUString SwXLinkTargetSupplier::getImplementationName(void) throw( RuntimeException )
3651 {
3652     return C2U("SwXLinkTargetSupplier");
3653 }
3654 /*-- 25.10.99 11:12:48---------------------------------------------------
3655 
3656   -----------------------------------------------------------------------*/
3657 sal_Bool SwXLinkTargetSupplier::supportsService(const OUString& rServiceName)
3658                                                 throw( RuntimeException )
3659 {
3660     return (rServiceName == C2U("com.sun.star.document.LinkTargets"));
3661 }
3662 /*-- 25.10.99 11:12:48---------------------------------------------------
3663 
3664   -----------------------------------------------------------------------*/
3665 Sequence< OUString > SwXLinkTargetSupplier::getSupportedServiceNames(void)
3666                                                 throw( RuntimeException )
3667 {
3668     Sequence< OUString > aRet(1);
3669     OUString* pNames = aRet.getArray();
3670     pNames[0] = C2U("com.sun.star.document.LinkTargets");
3671     return aRet;
3672 }
3673 
3674 /*-- 26.10.99 09:16:23---------------------------------------------------
3675 
3676   -----------------------------------------------------------------------*/
3677 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(
3678             Reference< XNameAccess >  xAccess, const String& rLinkDisplayName, String sSuffix ) :
3679     xRealAccess(xAccess),
3680     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3681     sLinkSuffix(sSuffix),
3682     sLinkDisplayName(rLinkDisplayName),
3683     pxDoc(0)
3684 {
3685 }
3686 /* -----------------26.10.99 14:17-------------------
3687 
3688  --------------------------------------------------*/
3689 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(SwXTextDocument& rxDoc,
3690             const String& rLinkDisplayName, String sSuffix) :
3691     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3692     sLinkSuffix(sSuffix),
3693     sLinkDisplayName(rLinkDisplayName),
3694     xDoc(&rxDoc),
3695     pxDoc(&rxDoc)
3696 {
3697 }
3698 /*-- 26.10.99 09:16:23---------------------------------------------------
3699 
3700   -----------------------------------------------------------------------*/
3701 SwXLinkNameAccessWrapper::~SwXLinkNameAccessWrapper()
3702 {
3703 }
3704 /*-- 26.10.99 09:16:24---------------------------------------------------
3705 
3706   -----------------------------------------------------------------------*/
3707 Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
3708     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3709 {
3710     Any aRet;
3711     sal_Bool bFound = sal_False;
3712     //cut link extension and call the real NameAccess
3713     String sParam = rName;
3714     String sSuffix(sLinkSuffix);
3715     if(sParam.Len() > sSuffix.Len() )
3716     {
3717         String sCmp = sParam.Copy(sParam.Len() - sSuffix.Len(),
3718                                                     sSuffix.Len());
3719         if(sCmp == sSuffix)
3720         {
3721             if(pxDoc)
3722             {
3723                 sParam = sParam.Copy(0, sParam.Len() - sSuffix.Len());
3724                 if(!pxDoc->GetDocShell())
3725                     throw RuntimeException();
3726                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3727                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().Count();
3728 
3729                 for (sal_uInt16 i = 0; i < nOutlineCount && !bFound; ++i)
3730                 {
3731                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3732                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3733                     if(sParam ==
3734                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3735                     {
3736                         Reference< XPropertySet >  xOutline = new SwXOutlineTarget(sParam);
3737                         aRet.setValue(&xOutline, ::getCppuType((Reference<XPropertySet>*)0));
3738                         bFound = sal_True;
3739                     }
3740                 }
3741             }
3742             else
3743             {
3744                 aRet = xRealAccess->getByName(sParam.Copy(0, sParam.Len() - sSuffix.Len()));
3745                 Reference< XInterface > xInt;
3746                 if(!(aRet >>= xInt))
3747                     throw RuntimeException();
3748                 Reference< XPropertySet >  xProp(xInt, UNO_QUERY);
3749                 aRet <<= xProp;
3750                 bFound = sal_True;
3751             }
3752         }
3753     }
3754     if(!bFound)
3755         throw NoSuchElementException();
3756     return aRet;
3757 }
3758 /*-- 26.10.99 09:16:24---------------------------------------------------
3759 
3760   -----------------------------------------------------------------------*/
3761 Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames(void)
3762                                     throw( RuntimeException )
3763 {
3764     Sequence< OUString > aRet;
3765     if(pxDoc)
3766     {
3767         if(!pxDoc->GetDocShell())
3768             throw RuntimeException();
3769 
3770         SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3771         const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3772         sal_uInt16 nOutlineCount = rOutlineNodes.Count();
3773         aRet.realloc(nOutlineCount);
3774         OUString* pResArr = aRet.getArray();
3775         String sSuffix('|');
3776         sSuffix += UniString::CreateFromAscii(pMarkToOutline);
3777         const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3778         for (sal_uInt16 i = 0; i < nOutlineCount; ++i)
3779         {
3780             String sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule);
3781             sEntry += sSuffix;
3782             pResArr[i] = sEntry;
3783         }
3784     }
3785     else
3786     {
3787         Sequence< OUString > aOrg = xRealAccess->getElementNames();
3788         const OUString* pOrgArr = aOrg.getConstArray();
3789         aRet.realloc(aOrg.getLength());
3790         OUString* pResArr = aRet.getArray();
3791         for(long i = 0; i < aOrg.getLength(); i++)
3792         {
3793             pResArr[i] = pOrgArr[i] + sLinkSuffix;
3794         }
3795     }
3796     return aRet;
3797 }
3798 /*-- 26.10.99 09:16:25---------------------------------------------------
3799 
3800   -----------------------------------------------------------------------*/
3801 sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
3802     throw( RuntimeException )
3803 {
3804     sal_Bool bRet = sal_False;
3805     String sParam(rName);
3806     if(sParam.Len() > sLinkSuffix.Len() )
3807     {
3808         String sCmp = sParam.Copy(sParam.Len() - sLinkSuffix.Len(),
3809                                                     sLinkSuffix.Len());
3810         if(sCmp == sLinkSuffix)
3811         {
3812                 sParam = sParam.Copy(0, sParam.Len() - sLinkSuffix.Len());
3813             if(pxDoc)
3814             {
3815                 if(!pxDoc->GetDocShell())
3816                     throw RuntimeException();
3817                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3818                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().Count();
3819 
3820                 for (sal_uInt16 i = 0; i < nOutlineCount && !bRet; ++i)
3821                 {
3822                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3823                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3824                     if(sParam ==
3825                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3826                     {
3827                         bRet = sal_True;
3828                     }
3829                 }
3830             }
3831             else
3832             {
3833                 bRet = xRealAccess->hasByName(sParam);
3834             }
3835         }
3836     }
3837     return bRet;
3838 }
3839 /*-- 26.10.99 09:16:25---------------------------------------------------
3840 
3841   -----------------------------------------------------------------------*/
3842 uno::Type  SwXLinkNameAccessWrapper::getElementType(void)
3843                                 throw( RuntimeException )
3844 {
3845     return ::getCppuType((Reference<XPropertySet>*)0);
3846 }
3847 /*-- 26.10.99 09:16:25---------------------------------------------------
3848 
3849   -----------------------------------------------------------------------*/
3850 sal_Bool SwXLinkNameAccessWrapper::hasElements(void) throw( RuntimeException )
3851 {
3852     sal_Bool bRet = sal_False;
3853     if(pxDoc)
3854     {
3855         DBG_ERROR("not implemented");
3856     }
3857     else
3858     {
3859         bRet = xRealAccess->hasElements();
3860     }
3861     return bRet;
3862 }
3863 /*-- 26.10.99 09:16:26---------------------------------------------------
3864 
3865   -----------------------------------------------------------------------*/
3866 Reference< XPropertySetInfo >  SwXLinkNameAccessWrapper::getPropertySetInfo(void)
3867                                         throw( RuntimeException )
3868 {
3869     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
3870     return xRet;
3871 }
3872 /*-- 26.10.99 09:16:26---------------------------------------------------
3873 
3874   -----------------------------------------------------------------------*/
3875 void SwXLinkNameAccessWrapper::setPropertyValue(
3876     const OUString& , const Any& )
3877     throw( UnknownPropertyException,
3878             PropertyVetoException,
3879             IllegalArgumentException,
3880             WrappedTargetException,
3881             RuntimeException)
3882 {
3883     throw UnknownPropertyException();
3884 }
3885 /* -----------------------------08.12.99 11:10--------------------------------
3886 
3887  ---------------------------------------------------------------------------*/
3888 Any lcl_GetDisplayBitmap(String sLinkSuffix)
3889 {
3890     Any aRet;
3891     if(sLinkSuffix.Len())
3892         sLinkSuffix.Erase(0, 1);
3893     sal_uInt16 nImgId = USHRT_MAX;
3894 
3895     if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOutline))
3896         nImgId = CONTENT_TYPE_OUTLINE;
3897     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToTable))
3898         nImgId = CONTENT_TYPE_TABLE;
3899     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToFrame))
3900         nImgId = CONTENT_TYPE_FRAME;
3901     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToGraphic))
3902         nImgId = CONTENT_TYPE_GRAPHIC;
3903 //  else if(== sLinkSuffix)
3904 //      nImgId = CONTENT_TYPE_BOOKMARK;
3905     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToRegion))
3906         nImgId = CONTENT_TYPE_REGION;
3907     else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOLE))
3908         nImgId = CONTENT_TYPE_OLE;
3909     else if(!sLinkSuffix.Len())
3910         nImgId = CONTENT_TYPE_BOOKMARK;
3911     if(USHRT_MAX != nImgId)
3912     {
3913         nImgId += 20000;
3914         sal_Bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
3915         ImageList aEntryImages( SW_RES(bHighContrast ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP) );
3916         const Image& rImage = aEntryImages.GetImage( nImgId );
3917         Bitmap aBitmap( rImage.GetBitmapEx().GetBitmap() );
3918         Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( aBitmap );
3919         aRet.setValue( &xBmp, ::getCppuType((Reference<awt::XBitmap>*)0) );
3920     }
3921     return aRet;
3922 }
3923 /*-- 26.10.99 09:16:27---------------------------------------------------
3924 
3925   -----------------------------------------------------------------------*/
3926 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
3927     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3928 {
3929     Any aRet;
3930     if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
3931     {
3932         aRet <<= OUString(sLinkDisplayName);
3933     }
3934     else if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_BITMAP)))
3935     {
3936         aRet = lcl_GetDisplayBitmap(sLinkSuffix);
3937     }
3938     else
3939         throw UnknownPropertyException();
3940     return aRet;
3941 }
3942 /*-- 26.10.99 09:16:27---------------------------------------------------
3943 
3944   -----------------------------------------------------------------------*/
3945 void SwXLinkNameAccessWrapper::addPropertyChangeListener(
3946     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3947     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3948 {}
3949 /*-- 26.10.99 09:16:28---------------------------------------------------
3950 
3951   -----------------------------------------------------------------------*/
3952 void SwXLinkNameAccessWrapper::removePropertyChangeListener(
3953     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3954     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3955 {}
3956 /*-- 26.10.99 09:16:28---------------------------------------------------
3957 
3958   -----------------------------------------------------------------------*/
3959 void SwXLinkNameAccessWrapper::addVetoableChangeListener(
3960     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3961     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3962 {}
3963 /*-- 26.10.99 09:16:29---------------------------------------------------
3964 
3965   -----------------------------------------------------------------------*/
3966 void SwXLinkNameAccessWrapper::removeVetoableChangeListener(
3967     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3968     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3969 {}
3970 /*-- 26.10.99 09:16:32---------------------------------------------------
3971 
3972 
3973   -----------------------------------------------------------------------*/
3974 Reference< XNameAccess >  SwXLinkNameAccessWrapper::getLinks(void)
3975                                     throw( RuntimeException )
3976 {
3977     return (SwXLinkNameAccessWrapper*)this;
3978 }
3979 
3980 /*-- 26.10.99 09:21:48---------------------------------------------------
3981 
3982   -----------------------------------------------------------------------*/
3983 OUString SwXLinkNameAccessWrapper::getImplementationName(void) throw( RuntimeException )
3984 {
3985     return C2U("SwXLinkNameAccessWrapper");
3986 }
3987 /*-- 26.10.99 09:21:48---------------------------------------------------
3988 
3989   -----------------------------------------------------------------------*/
3990 sal_Bool SwXLinkNameAccessWrapper::supportsService(const OUString& rServiceName)
3991                                                     throw( RuntimeException )
3992 {
3993     return (rServiceName == C2U("com.sun.star.document.LinkTargets"));
3994 }
3995 /*-- 26.10.99 09:21:48---------------------------------------------------
3996 
3997   -----------------------------------------------------------------------*/
3998 Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames(void)
3999                                                     throw( RuntimeException )
4000 {
4001     Sequence< OUString > aRet(1);
4002     OUString* pNames = aRet.getArray();
4003     pNames[0] = C2U("com.sun.star.document.LinkTargets");
4004     return aRet;
4005 }
4006 /* -----------------26.10.99 15:50-------------------
4007 
4008  --------------------------------------------------*/
4009 SwXOutlineTarget::SwXOutlineTarget(const String& rOutlineText) :
4010     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4011     sOutlineText(rOutlineText)
4012 {
4013 }
4014 /*-- 26.10.99 15:51:45---------------------------------------------------
4015 
4016   -----------------------------------------------------------------------*/
4017 SwXOutlineTarget::~SwXOutlineTarget()
4018 {
4019 }
4020 /*-- 26.10.99 15:51:46---------------------------------------------------
4021 
4022   -----------------------------------------------------------------------*/
4023 Reference< XPropertySetInfo >  SwXOutlineTarget::getPropertySetInfo(void) throw( RuntimeException )
4024 {
4025     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
4026     return xRet;
4027 }
4028 /*-- 26.10.99 15:51:46---------------------------------------------------
4029 
4030   -----------------------------------------------------------------------*/
4031 void SwXOutlineTarget::setPropertyValue(
4032     const OUString& /*PropertyName*/, const Any& /*aValue*/)
4033     throw( UnknownPropertyException, PropertyVetoException,
4034         IllegalArgumentException, WrappedTargetException, RuntimeException)
4035 {
4036     throw UnknownPropertyException();
4037 }
4038 /*-- 26.10.99 15:51:46---------------------------------------------------
4039 
4040   -----------------------------------------------------------------------*/
4041 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
4042     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4043 {
4044     Any aRet;
4045     if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
4046         aRet <<= OUString(sOutlineText);
4047     else
4048         throw UnknownPropertyException();
4049     return aRet;
4050 }
4051 /*-- 26.10.99 15:51:46---------------------------------------------------
4052 
4053   -----------------------------------------------------------------------*/
4054 void SwXOutlineTarget::addPropertyChangeListener(
4055     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4056     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4057 {
4058 }
4059 /*-- 26.10.99 15:51:47---------------------------------------------------
4060 
4061   -----------------------------------------------------------------------*/
4062 void SwXOutlineTarget::removePropertyChangeListener(
4063     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4064     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4065 {
4066 }
4067 /*-- 26.10.99 15:51:47---------------------------------------------------
4068 
4069   -----------------------------------------------------------------------*/
4070 void SwXOutlineTarget::addVetoableChangeListener(
4071     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4072     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4073 {
4074 }
4075 /*-- 26.10.99 15:51:47---------------------------------------------------
4076 
4077   -----------------------------------------------------------------------*/
4078 void SwXOutlineTarget::removeVetoableChangeListener(
4079     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4080     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4081 {
4082 }
4083 /* -----------------03.05.99 12:28-------------------
4084  *
4085  * --------------------------------------------------*/
4086 OUString SwXOutlineTarget::getImplementationName(void) throw( RuntimeException )
4087 {
4088     return C2U("SwXOutlineTarget");
4089 }
4090 /* -----------------03.05.99 12:28-------------------
4091  *
4092  * --------------------------------------------------*/
4093 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName) throw( RuntimeException )
4094 {
4095     return C2U("com.sun.star.document.LinkTarget") == ServiceName;
4096 }
4097 /* -----------------03.05.99 12:28-------------------
4098  *
4099  * --------------------------------------------------*/
4100 Sequence< OUString > SwXOutlineTarget::getSupportedServiceNames(void) throw( RuntimeException )
4101 {
4102     Sequence < OUString > aRet(1);
4103     OUString* pArray = aRet.getArray();
4104     pArray[0] = C2U("com.sun.star.document.LinkTarget");
4105 
4106     return aRet;
4107 }
4108 /* -----------------------------17.01.01 16:06--------------------------------
4109 
4110  ---------------------------------------------------------------------------*/
4111 SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
4112 SvxUnoForbiddenCharsTable ( rDoc.getForbiddenCharacterTable() )
4113 ,m_pDoc(&rDoc)
4114 {
4115 }
4116 /* -----------------------------17.01.01 16:06--------------------------------
4117 
4118  ---------------------------------------------------------------------------*/
4119 SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
4120 {
4121 }
4122 /* -----------------------------17.01.01 16:06--------------------------------
4123 
4124  ---------------------------------------------------------------------------*/
4125 Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
4126 {
4127     Reference<XInterface> xRet;
4128     if(m_pDoc)
4129     {
4130         switch(nWhich)
4131         {
4132             // --> OD 2005-08-08 #i52858#
4133             // assure that Draw model is created, if it doesn't exist.
4134             case SW_CREATE_DASH_TABLE         :
4135                 if(!xDashTable.is())
4136                     xDashTable = SvxUnoDashTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4137                 xRet = xDashTable;
4138             break;
4139             case SW_CREATE_GRADIENT_TABLE     :
4140                 if(!xGradientTable.is())
4141                     xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4142                 xRet = xGradientTable;
4143             break;
4144             case SW_CREATE_HATCH_TABLE        :
4145                 if(!xHatchTable.is())
4146                     xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4147                 xRet = xHatchTable;
4148             break;
4149             case SW_CREATE_BITMAP_TABLE       :
4150                 if(!xBitmapTable.is())
4151                     xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4152                 xRet = xBitmapTable;
4153             break;
4154             case SW_CREATE_TRANSGRADIENT_TABLE:
4155                 if(!xTransGradientTable.is())
4156                     xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4157                 xRet = xTransGradientTable;
4158             break;
4159             case SW_CREATE_MARKER_TABLE       :
4160                 if(!xMarkerTable.is())
4161                     xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4162                 xRet = xMarkerTable;
4163             break;
4164             // <--
4165             case  SW_CREATE_DRAW_DEFAULTS:
4166                 if(!xDrawDefaults.is())
4167                     xDrawDefaults = (cppu::OWeakObject*)new SwSvxUnoDrawPool(m_pDoc);
4168                 xRet = xDrawDefaults;
4169             break;
4170 #ifdef DBG_UTIL
4171             default: DBG_ERROR("which table?");
4172 #endif
4173         }
4174     }
4175     return xRet;
4176 }
4177 
4178 void SwXDocumentPropertyHelper::Invalidate()
4179 {
4180     xDashTable = 0;
4181     xGradientTable = 0;
4182     xHatchTable = 0;
4183     xBitmapTable = 0;
4184     xTransGradientTable = 0;
4185     xMarkerTable = 0;
4186     xDrawDefaults = 0;
4187     m_pDoc = 0;
4188     SvxUnoForbiddenCharsTable::mxForbiddenChars.unbind();
4189 }
4190 /* -----------------13.08.2003 12:43-----------------
4191 
4192  --------------------------------------------------*/
4193 void SwXDocumentPropertyHelper::onChange()
4194 {
4195     if(m_pDoc)
4196        m_pDoc->SetModified();
4197 }
4198 
4199 
4200 /*****************************************************************************/
4201 
4202 SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( ViewShell& rSh, const SwViewOption &rViewOptions ) :
4203     m_rShell( rSh ),
4204     m_aOldViewOptions( rViewOptions )
4205 {
4206 }
4207 
4208 
4209 SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl()
4210 {
4211     m_rShell.ApplyViewOptions( m_aOldViewOptions );
4212 }
4213 
4214 
4215 void
4216 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions)
4217 {
4218     // to avoid unnecessary reformatting the view options related to the content
4219     // below should only change if necessary, that is if respective content is present
4220     const bool bContainsHiddenChars         = m_rShell.GetDoc()->ContainsHiddenChars();
4221     const SwFieldType* pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENTXTFLD );
4222     const bool bContainsHiddenFields        = pFldType && pFldType->GetDepends();
4223     pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENPARAFLD );
4224     const bool bContainsHiddenParagraphs    = pFldType && pFldType->GetDepends();
4225     pFldType = m_rShell.GetDoc()->GetSysFldType( RES_JUMPEDITFLD );
4226     const bool bContainsPlaceHolders        = pFldType && pFldType->GetDepends();
4227     const bool bContainsFields              = m_rShell.IsAnyFieldInDoc();
4228 
4229     SwViewOption aRenderViewOptions( m_aOldViewOptions );
4230 
4231     // disable anything in the view that should not be printed (or exported to PDF) by default
4232     // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4233     // in section "Display of ...")
4234     aRenderViewOptions.SetParagraph( sal_False );             // paragraph end
4235     aRenderViewOptions.SetSoftHyph( sal_False );              // aka custom hyphens
4236     aRenderViewOptions.SetBlank( sal_False );                 // spaces
4237     aRenderViewOptions.SetHardBlank( sal_False );             // non-breaking spaces
4238     aRenderViewOptions.SetTab( sal_False );                   // tabs
4239     aRenderViewOptions.SetLineBreak( sal_False );             // breaks (type 1)
4240     aRenderViewOptions.SetPageBreak( sal_False );             // breaks (type 2)
4241     aRenderViewOptions.SetColumnBreak( sal_False );           // breaks (type 3)
4242     sal_Bool bVal = pPrtOptions? pPrtOptions->bPrintHiddenText : sal_False;
4243     if (bContainsHiddenChars)
4244         aRenderViewOptions.SetShowHiddenChar( bVal );     // hidden text
4245     if (bContainsHiddenFields)
4246         aRenderViewOptions.SetShowHiddenField( bVal );
4247     if (bContainsHiddenParagraphs)
4248         aRenderViewOptions.SetShowHiddenPara( bVal );
4249 
4250     if (bContainsPlaceHolders)
4251     {
4252         // should always be printed in PDF export!
4253         bVal = pPrtOptions ? pPrtOptions->bPrintTextPlaceholder : sal_True;
4254         aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4255     }
4256 
4257     if (bContainsFields)
4258         aRenderViewOptions.SetFldName( sal_False );
4259 
4260     // we need to set this flag in order to get to see the visible effect of
4261     // some of the above settings (needed for correct rendering)
4262     aRenderViewOptions.SetViewMetaChars( sal_True );
4263 
4264     if (m_aOldViewOptions != aRenderViewOptions)  // check if reformatting is necessary
4265     {
4266         aRenderViewOptions.SetPrinting( pPrtOptions != NULL );
4267         m_rShell.ApplyViewOptions( aRenderViewOptions );
4268     }
4269 }
4270 
4271 
4272 /*****************************************************************************/
4273 
4274 
4275