xref: /trunk/main/sw/source/ui/uno/unotxdoc.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 #include <vos/mutex.hxx>
32 #include <vcl/image.hxx>
33 #include <vcl/virdev.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/print.hxx>
36 #include <sfx2/viewfrm.hxx>
37 #include <sfx2/sfxbasecontroller.hxx>
38 #include <sfx2/docfile.hxx>
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <toolkit/awt/vclxdevice.hxx>
41 #include <cmdid.h>
42 #include <swtypes.hxx>
43 #include <wdocsh.hxx>
44 #include <wrtsh.hxx>
45 #include <view.hxx>
46 #include <pview.hxx>
47 #include <srcview.hxx>
48 #include <viewsh.hxx>
49 #include <pvprtdat.hxx>
50 #include <printdata.hxx>
51 #include <svl/stritem.hxx>
52 #include <unotxdoc.hxx>
53 #include <svl/numuno.hxx>
54 #include <fldbas.hxx>
55 #include <unotextbodyhf.hxx>
56 #include <unotextrange.hxx>
57 #include <unotextcursor.hxx>
58 #include <unosett.hxx>
59 #include <unocoll.hxx>
60 #include <unoredlines.hxx>
61 #include <unosrch.hxx>
62 #include <sfx2/dispatch.hxx>
63 #include <sfx2/request.hxx>
64 #include <sfx2/objsh.hxx>   // SfxObjectShellRef <-> SV_DECL_REF(SfxObjectShell)
65 #include <unoprnms.hxx>
66 #include <unostyle.hxx>
67 #include <unodraw.hxx>
68 #include <svl/eitem.hxx>
69 #include <pagedesc.hxx>
70 #include <svtools/txtcmp.hxx>
71 #include <unocrsr.hxx>
72 #include <unofield.hxx>
73 #include <unoidx.hxx>
74 #include <unoflatpara.hxx>
75 #include <unotxvw.hxx>
76 #include <poolfmt.hxx>
77 #include <globdoc.hxx>
78 #include <viewopt.hxx>
79 #include <unochart.hxx>
80 #include <doc.hxx>
81 #include <charatr.hxx>
82 #include <svx/xmleohlp.hxx>
83 #include <globals.hrc>
84 #include <unomid.h>
85 #include <unotools/printwarningoptions.hxx>
86 #include <com/sun/star/util/SearchOptions.hpp>
87 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
88 #include <com/sun/star/lang/DisposedException.hpp>
89 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
90 #include <com/sun/star/beans/PropertyAttribute.hpp>
91 #include <com/sun/star/beans/XFastPropertySet.hpp>
92 #include <com/sun/star/document/RedlineDisplayType.hpp>
93 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
94 #include <com/sun/star/frame/XController.hpp>
95 #include <com/sun/star/frame/XFrame.hpp>
96 #include <com/sun/star/script/XInvocation.hpp>
97 #include <com/sun/star/reflection/XIdlClassProvider.hpp>
98 #include <sfx2/linkmgr.hxx>
99 #include <svx/unofill.hxx>
100 #include <editeng/unolingu.hxx>
101 #include <sfx2/progress.hxx>
102 #include <swmodule.hxx>
103 #include <docstat.hxx>
104 #include <modcfg.hxx>
105 #include <ndtxt.hxx>
106 #include <utlui.hrc>
107 #include <swcont.hxx>
108 #include <unodefaults.hxx>
109 #include <SwXDocumentSettings.hxx>
110 #include <doc.hxx>
111 #include <editeng/forbiddencharacterstable.hxx>
112 #include <svl/zforlist.hxx>
113 #include <drawdoc.hxx>
114 #include <SwStyleNameMapper.hxx>
115 #include <osl/file.hxx>
116 #include <comphelper/storagehelper.hxx>
117 
118 
119 // --> FME 2004-06-08 #i12836# enhanced pdf export
120 #include <EnhancedPDFExportHelper.hxx>
121 // <--
122 #include <numrule.hxx>
123 
124 ///////////////////////////Modified on Jun. 14th//////////////////////////
125 ///////////////////////for getDocumentLanguages///////////////////////////
126 //-->
127 #include <editeng/langitem.hxx>
128 #include <doc.hxx>
129 #include <docary.hxx>      //SwCharFmts
130 #include <i18npool/mslangid.hxx>
131 
132 #include <format.hxx>
133 #include <charfmt.hxx>    //SwCharFmt
134 #include <fmtcol.hxx>     //SwTxtFmtColl
135 #include <unostyle.hxx>   //SwAutoStyleFamily
136 #include <istyleaccess.hxx> // handling of automatic styles
137 
138 #include <svl/stylepool.hxx>
139 #include <swatrset.hxx>
140 #include <view.hxx>
141 #include <srcview.hxx>
142 
143 //#include <com/sun/star/i18n/ScriptType.hpp>
144 #include <svtools/langtab.hxx>
145 #include <map>
146 #include <set>
147 #include <vector>
148 
149 #include <editeng/eeitem.hxx>
150 #include <editeng/editeng.hxx>
151 #include <svx/svdoutl.hxx>
152 #include <svl/languageoptions.hxx>
153 #include <svx/svdview.hxx>
154 
155 //
156 //<--
157 using namespace ::com::sun::star;
158 using namespace ::com::sun::star::text;
159 using namespace ::com::sun::star::i18n;
160 using namespace ::com::sun::star::uno;
161 using namespace ::com::sun::star::beans;
162 using namespace ::com::sun::star::lang;
163 using namespace ::com::sun::star::container;
164 using namespace ::com::sun::star::document;
165 using namespace ::com::sun::star::i18n;
166 using ::rtl::OUString;
167 using ::osl::FileBase;
168 
169 /* -----------------------------17.01.01 15:43--------------------------------
170 
171  ---------------------------------------------------------------------------*/
172 #define SW_CREATE_DASH_TABLE            0x01
173 #define SW_CREATE_GRADIENT_TABLE        0x02
174 #define SW_CREATE_HATCH_TABLE           0x03
175 #define SW_CREATE_BITMAP_TABLE          0x04
176 #define SW_CREATE_TRANSGRADIENT_TABLE   0x05
177 #define SW_CREATE_MARKER_TABLE          0x06
178 #define SW_CREATE_DRAW_DEFAULTS         0x07
179 
180 
181 /******************************************************************************
182  *
183  ******************************************************************************/
184 
185 extern bool lcl_GetPostIts( IDocumentFieldsAccess* pIDFA, _SetGetExpFlds * pSrtLst );
186 
187 SwPrintUIOptions * lcl_GetPrintUIOptions(
188     SwDocShell * pDocShell,
189     const SfxViewShell * pView )
190 {
191     if (!pDocShell)
192         return NULL;
193 
194     const sal_Bool bWebDoc      = NULL != dynamic_cast< const SwWebDocShell * >(pDocShell);
195     const bool bSwSrcView   = NULL != dynamic_cast< const SwSrcView * >(pView);
196     const SwView * pSwView = dynamic_cast< const SwView * >(pView);
197     const bool bHasSelection    = pSwView ? pSwView->HasSelection( sal_False ) : false;  // check for any selection, not just text selection
198     const bool bHasPostIts      = lcl_GetPostIts( pDocShell->GetDoc(), 0 );
199 
200     // get default values to use in dialog from documents SwPrintData
201     const SwPrintData &rPrintData = pDocShell->GetDoc()->getPrintData();
202 
203     return new SwPrintUIOptions( bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
204 }
205 
206 ////////////////////////////////////////////////////////////
207 
208 
209 SwTxtFmtColl *lcl_GetParaStyle(const String& rCollName, SwDoc* pDoc)
210 {
211     SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName( rCollName );
212     if( !pColl )
213     {
214         sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
215         if( USHRT_MAX != nId )
216             pColl = pDoc->GetTxtCollFromPool( nId );
217     }
218     return pColl;
219 }
220 void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell* pDocShell )
221 {
222     // check if the view frame still exists
223     SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell,
224                                 sal_False );
225     while(pFound)
226     {
227         if( pFound == pToClose)
228         {
229             pToClose->DoClose();
230             break;
231         }
232         pFound = SfxViewFrame::GetNext( *pFound,
233                                 pDocShell,
234                                 sal_False );
235     }
236 }
237 /* -----------------------------10.03.00 18:02--------------------------------
238 
239  ---------------------------------------------------------------------------*/
240 const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
241 {
242     static Sequence< sal_Int8 > aSeq = ::CreateUnoTunnelId();
243     return aSeq;
244 }
245 /* -----------------------------10.03.00 18:04--------------------------------
246 
247  ---------------------------------------------------------------------------*/
248 sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
249     throw(RuntimeException)
250 {
251     if( rId.getLength() == 16
252         && 0 == rtl_compareMemory( getUnoTunnelId().getConstArray(),
253                                         rId.getConstArray(), 16 ) )
254     {
255             return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
256     }
257 
258     sal_Int64 nRet = SfxBaseModel::getSomething( rId );
259     if ( nRet )
260         return nRet;
261     else
262     {
263         GetNumberFormatter();
264         Any aNumTunnel = xNumFmtAgg->queryAggregation(::getCppuType((Reference<XUnoTunnel>*)0));
265         Reference<XUnoTunnel> xNumTunnel;
266         aNumTunnel >>= xNumTunnel;
267         if(xNumTunnel.is())
268             return xNumTunnel->getSomething(rId);
269     }
270 
271     return SfxBaseModel::getSomething( rId );
272 }
273 /* -----------------------------16.03.00 14:12--------------------------------
274 
275  ---------------------------------------------------------------------------*/
276 Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException)
277 {
278     Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
279     if ( !aRet.hasValue() )
280         aRet = SfxBaseModel::queryInterface(rType);
281     if ( !aRet.hasValue() &&
282         rType == ::getCppuType((Reference<lang::XMultiServiceFactory>*)0))
283     {
284         Reference<lang::XMultiServiceFactory> xTmp = this;
285         aRet <<= xTmp;
286     }
287 
288     if ( !aRet.hasValue()
289         && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
290         && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0)
291         && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0)
292         && rType != ::getCppuType((Reference< com::sun::star::script::XInvocation>*)0)
293         && rType != ::getCppuType((Reference< com::sun::star::reflection::XIdlClassProvider>*)0)
294         && rType != ::getCppuType((Reference< com::sun::star::beans::XFastPropertySet>*)0)
295         && rType != ::getCppuType((Reference< com::sun::star::awt::XWindow>*)0))
296     {
297         GetNumberFormatter();
298         if(xNumFmtAgg.is())
299             aRet = xNumFmtAgg->queryAggregation(rType);
300     }
301     return aRet;
302 }
303 /* -----------------------------16.03.00 14:12--------------------------------
304 
305  ---------------------------------------------------------------------------*/
306 void SAL_CALL SwXTextDocument::acquire()throw()
307 {
308     SfxBaseModel::acquire();
309 }
310 /* -----------------------------16.03.00 14:12--------------------------------
311 
312  ---------------------------------------------------------------------------*/
313 void SAL_CALL SwXTextDocument::release()throw()
314 {
315     SfxBaseModel::release();
316 }
317 /* -----------------------------07.12.00 11:37--------------------------------
318 
319  ---------------------------------------------------------------------------*/
320 Reference< XAdapter > SwXTextDocument::queryAdapter(  ) throw(RuntimeException)
321 {
322     return SfxBaseModel::queryAdapter();
323 }
324 /* -----------------------------16.03.00 14:12--------------------------------
325 
326  ---------------------------------------------------------------------------*/
327 Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException)
328 {
329     Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
330     Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
331 
332     Sequence< uno::Type > aNumTypes;
333     GetNumberFormatter();
334     if(xNumFmtAgg.is())
335     {
336         const uno::Type& rProvType = ::getCppuType((Reference <XTypeProvider>*)0);
337         Any aNumProv = xNumFmtAgg->queryAggregation(rProvType);
338         Reference<XTypeProvider> xNumProv;
339         if(aNumProv >>= xNumProv)
340         {
341             aNumTypes = xNumProv->getTypes();
342         }
343     }
344     long nIndex = aBaseTypes.getLength();
345     // don't forget the lang::XMultiServiceFactory
346     aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 1);
347     uno::Type* pBaseTypes = aBaseTypes.getArray();
348     const uno::Type* pTextTypes = aTextTypes.getConstArray();
349     long nPos;
350     for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
351     {
352         pBaseTypes[nIndex++] = pTextTypes[nPos];
353     }
354     const uno::Type* pNumTypes = aNumTypes.getConstArray();
355     for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
356     {
357         pBaseTypes[nIndex++] = pNumTypes[nPos];
358     }
359     pBaseTypes[nIndex++] = ::getCppuType((Reference<lang::XMultiServiceFactory>*)0);
360     return aBaseTypes;
361 }
362 /*-- 18.12.98 11:52:59---------------------------------------------------
363 
364   -----------------------------------------------------------------------*/
365 SwXTextDocument::SwXTextDocument(SwDocShell* pShell) :
366     SfxBaseModel(pShell),
367 
368     aRefreshCont ( static_cast < XTextDocument* > ( this ) ),
369 
370     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
371 
372     pDocShell(pShell),
373 
374     bObjectValid(pShell != 0),
375 
376     pDrawPage(0),
377     pxXDrawPage(0),
378 
379     pxXNumberingRules(0),
380     pxXFootnotes(0),
381     pxXFootnoteSettings(0),
382     pxXEndnotes(0),
383     pxXEndnoteSettings(0),
384     pxXReferenceMarks(0),
385     pxXTextFieldTypes(0),
386     pxXTextFieldMasters(0),
387     pxXTextSections(0),
388     pxXBookmarks(0),
389     pxXTextTables(0),
390     pxXTextFrames(0),
391     pxXGraphicObjects(0),
392     pxXEmbeddedObjects(0),
393     pxXStyleFamilies(0),
394     pxXAutoStyles(0),
395     pxXChapterNumbering(0),
396     pxXDocumentIndexes(0),
397 
398     pxXLineNumberingProperties(0),
399     pxLinkTargetSupplier(0),
400     pxXRedlines(0),
401     m_pHiddenViewFrame(0),
402     m_pPrintUIOptions( NULL ),
403     m_pRenderData( NULL )
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 
1296         pFrame->GetViewShell()->ExecuteSlot(aReq);
1297         // Frame schliessen
1298         pFrame->DoClose();
1299 
1300     }
1301     else
1302         throw RuntimeException();
1303 }
1304 /*-- 18.12.98 11:55:25---------------------------------------------------
1305 
1306   -----------------------------------------------------------------------*/
1307 Reference< XNameAccess >  SwXTextDocument::getReferenceMarks(void)
1308                                         throw( RuntimeException )
1309 {
1310     ::vos::OGuard aGuard(Application::GetSolarMutex());
1311     if(!IsValid())
1312         throw RuntimeException();
1313     if(!pxXReferenceMarks)
1314     {
1315         ((SwXTextDocument*)this)->pxXReferenceMarks = new Reference< XNameAccess > ;
1316         *pxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
1317     }
1318     return *pxXReferenceMarks;
1319 }
1320 /* -----------------21.12.98 10:20-------------------
1321  *
1322  * --------------------------------------------------*/
1323 Reference< XEnumerationAccess >  SwXTextDocument::getTextFields(void) throw( RuntimeException )
1324 {
1325     ::vos::OGuard aGuard(Application::GetSolarMutex());
1326     if(!IsValid())
1327         throw RuntimeException();
1328     if(!pxXTextFieldTypes)
1329     {
1330         ((SwXTextDocument*)this)->pxXTextFieldTypes = new Reference< XEnumerationAccess > ;
1331         *pxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
1332     }
1333     return *pxXTextFieldTypes;
1334 }
1335 /*-- 21.12.98 10:21:12---------------------------------------------------
1336 
1337   -----------------------------------------------------------------------*/
1338 Reference< XNameAccess >  SwXTextDocument::getTextFieldMasters(void)
1339     throw( RuntimeException )
1340 {
1341     ::vos::OGuard aGuard(Application::GetSolarMutex());
1342     if(!IsValid())
1343         throw RuntimeException();
1344     if(!pxXTextFieldMasters)
1345     {
1346         ((SwXTextDocument*)this)->pxXTextFieldMasters = new Reference< XNameAccess > ;
1347         *pxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
1348     }
1349     return *pxXTextFieldMasters;
1350 }
1351 /*-- 21.12.98 10:21:12---------------------------------------------------
1352 
1353   -----------------------------------------------------------------------*/
1354 Reference< XNameAccess >  SwXTextDocument::getEmbeddedObjects(void) throw( RuntimeException )
1355 {
1356     ::vos::OGuard aGuard(Application::GetSolarMutex());
1357     if(!IsValid())
1358         throw RuntimeException();
1359     if(!pxXEmbeddedObjects)
1360     {
1361         ((SwXTextDocument*)this)->pxXEmbeddedObjects = new Reference< XNameAccess > ;
1362         *pxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
1363     }
1364     return *pxXEmbeddedObjects;
1365 }
1366 /*-- 21.12.98 10:21:13---------------------------------------------------
1367 
1368   -----------------------------------------------------------------------*/
1369 Reference< XNameAccess >  SwXTextDocument::getBookmarks(void) throw( RuntimeException )
1370 {
1371     ::vos::OGuard aGuard(Application::GetSolarMutex());
1372     if(!IsValid())
1373         throw RuntimeException();
1374     if(!pxXBookmarks)
1375     {
1376         ((SwXTextDocument*)this)->pxXBookmarks = new Reference< XNameAccess > ;
1377         *pxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
1378     }
1379     return *pxXBookmarks;
1380 }
1381 /*-- 21.12.98 10:21:13---------------------------------------------------
1382 
1383   -----------------------------------------------------------------------*/
1384 Reference< XNameAccess >  SwXTextDocument::getTextSections(void) throw( RuntimeException )
1385 {
1386     ::vos::OGuard aGuard(Application::GetSolarMutex());
1387     if(!IsValid())
1388         throw RuntimeException();
1389     if(!pxXTextSections)
1390     {
1391         ((SwXTextDocument*)this)->pxXTextSections = new Reference< XNameAccess > ;
1392         *pxXTextSections = new SwXTextSections(pDocShell->GetDoc());
1393     }
1394     return *pxXTextSections;
1395 }
1396 /*-- 21.12.98 10:21:13---------------------------------------------------
1397 
1398   -----------------------------------------------------------------------*/
1399 Reference< XNameAccess >  SwXTextDocument::getTextTables(void) throw( RuntimeException )
1400 {
1401     ::vos::OGuard aGuard(Application::GetSolarMutex());
1402     if(!IsValid())
1403         throw RuntimeException();
1404     if(!pxXTextTables)
1405     {
1406         ((SwXTextDocument*)this)->pxXTextTables = new Reference< XNameAccess > ;
1407         *pxXTextTables = new SwXTextTables(pDocShell->GetDoc());
1408     }
1409     return *pxXTextTables;
1410 }
1411 /*-- 21.12.98 10:21:13---------------------------------------------------
1412 
1413   -----------------------------------------------------------------------*/
1414 Reference< XNameAccess >  SwXTextDocument::getGraphicObjects(void) throw( RuntimeException )
1415 {
1416     ::vos::OGuard aGuard(Application::GetSolarMutex());
1417     if(!IsValid())
1418         throw RuntimeException();
1419     if(!pxXGraphicObjects)
1420     {
1421         ((SwXTextDocument*)this)->pxXGraphicObjects = new Reference< XNameAccess > ;
1422         *pxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
1423     }
1424     return *pxXGraphicObjects;
1425 }
1426 /*-- 21.12.98 10:21:14---------------------------------------------------
1427 
1428   -----------------------------------------------------------------------*/
1429 Reference< XNameAccess >  SwXTextDocument::getTextFrames(void) throw( RuntimeException )
1430 {
1431     ::vos::OGuard aGuard(Application::GetSolarMutex());
1432     if(!IsValid())
1433         throw RuntimeException();
1434     if(!pxXTextFrames)
1435     {
1436         ((SwXTextDocument*)this)->pxXTextFrames = new Reference< XNameAccess > ;
1437         *pxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
1438     }
1439     return *pxXTextFrames;
1440 }
1441 /* -----------------21.12.98 10:56-------------------
1442  *
1443  * --------------------------------------------------*/
1444 Reference< XNameAccess >  SwXTextDocument::getStyleFamilies(void) throw( RuntimeException )
1445 {
1446     ::vos::OGuard aGuard(Application::GetSolarMutex());
1447     if(!IsValid())
1448         throw RuntimeException();
1449     if(!pxXStyleFamilies)
1450     {
1451         ((SwXTextDocument*)this)->pxXStyleFamilies = new Reference< XNameAccess > ;
1452         *pxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
1453     }
1454     return *pxXStyleFamilies;
1455 }
1456 /*-- 19.05.06 10:15:22---------------------------------------------------
1457 
1458   -----------------------------------------------------------------------*/
1459 uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles(  )
1460     throw (uno::RuntimeException)
1461 {
1462     ::vos::OGuard aGuard(Application::GetSolarMutex());
1463     if(!IsValid())
1464         throw RuntimeException();
1465     if(!pxXAutoStyles)
1466     {
1467         pxXAutoStyles = new Reference< style::XAutoStyles > ;
1468         *pxXAutoStyles = new SwXAutoStyles(*pDocShell);
1469     }
1470     return *pxXAutoStyles;
1471 
1472 }
1473 /*-- 22.01.99 10:18:03---------------------------------------------------
1474 
1475   -----------------------------------------------------------------------*/
1476 Reference< drawing::XDrawPage >  SwXTextDocument::getDrawPage(void) throw( RuntimeException )
1477 {
1478     ::vos::OGuard aGuard(Application::GetSolarMutex());
1479     if(!IsValid())
1480         throw RuntimeException();
1481     if(!pxXDrawPage)
1482     {
1483         // simplified this creation, keeping original below as reference
1484         // for the case that it did something by purpose
1485         ((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1486         ((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage >(pDrawPage);
1487 
1488         //((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage > ;
1489         //((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1490         //Reference< drawing::XShapes >  xTmp = pDrawPage;
1491         //*pxXDrawPage = Reference< drawing::XDrawPage>(xTmp, UNO_QUERY);
1492     }
1493     return *pxXDrawPage;
1494 }
1495 /* -----------------07.04.99 10:11-------------------
1496  *
1497  * --------------------------------------------------*/
1498 SwXDrawPage* SwXTextDocument::GetDrawPage()
1499 {
1500     if(!IsValid())
1501         return 0;
1502     if(!pDrawPage)
1503         getDrawPage();
1504     return pDrawPage;
1505 }
1506 /*-- 18.12.98 11:55:26---------------------------------------------------
1507 
1508   -----------------------------------------------------------------------*/
1509 void SwXTextDocument::Invalidate()
1510 {
1511     bObjectValid = sal_False;
1512     if(xNumFmtAgg.is())
1513     {
1514         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1515         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1516         SvNumberFormatsSupplierObj* pNumFmt = 0;
1517         Reference< XUnoTunnel > xNumTunnel;
1518         if(aNumTunnel >>= xNumTunnel)
1519         {
1520             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1521                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1522             pNumFmt->SetNumberFormatter(0);
1523         }
1524         DBG_ASSERT(pNumFmt, "No number formatter available");
1525     }
1526     InitNewDoc();
1527     pDocShell = 0;
1528     aRefreshCont.Disposing();
1529 }
1530 /* -----------------------------13.07.00 15:59--------------------------------
1531 
1532  ---------------------------------------------------------------------------*/
1533 void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
1534 {
1535     if(pDocShell && pDocShell != pNewDocShell)
1536         Invalidate();
1537     pDocShell = pNewDocShell;
1538     bObjectValid = sal_True;
1539 }
1540 /*-- 18.12.98 11:55:26---------------------------------------------------
1541 
1542   -----------------------------------------------------------------------*/
1543 void    SwXTextDocument::InitNewDoc()
1544 {
1545     // zunaechst alle Collections invalidieren, dann Referenzen loeschen und Null setzen
1546     if(pxXTextTables)
1547     {
1548          XNameAccess* pTbls = pxXTextTables->get();
1549         ((SwXTextTables*)pTbls)->Invalidate();
1550         delete pxXTextTables;
1551         pxXTextTables = 0;
1552     }
1553 
1554     if(pxXTextFrames)
1555     {
1556         XNameAccess* pFrms = pxXTextFrames->get();
1557         ((SwXTextFrames*)pFrms)->Invalidate();
1558         delete pxXTextFrames;
1559         pxXTextFrames = 0;
1560     }
1561 
1562     if(pxXGraphicObjects)
1563     {
1564         XNameAccess* pFrms = pxXGraphicObjects->get();
1565         ((SwXTextGraphicObjects*)pFrms)->Invalidate();
1566         delete pxXGraphicObjects;
1567         pxXGraphicObjects = 0;
1568     }
1569 
1570     if(pxXEmbeddedObjects)
1571     {
1572      XNameAccess* pOLE = pxXEmbeddedObjects->get();
1573         ((SwXTextEmbeddedObjects*)pOLE)->Invalidate();
1574         delete pxXEmbeddedObjects;
1575         pxXEmbeddedObjects = 0;
1576     }
1577 
1578     if(xBodyText.is())
1579     {
1580         xBodyText = 0;
1581         pBodyText = 0;
1582     }
1583 
1584     if(xNumFmtAgg.is())
1585     {
1586         const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1587         Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1588         SvNumberFormatsSupplierObj* pNumFmt = 0;
1589         Reference< XUnoTunnel > xNumTunnel;
1590         if(aNumTunnel >>= xNumTunnel)
1591         {
1592             pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1593                     xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1594 
1595         }
1596         DBG_ASSERT(pNumFmt, "No number formatter available");
1597         pNumFmt->SetNumberFormatter(0);
1598     }
1599 
1600     if(pxXTextFieldTypes)
1601     {
1602         XEnumerationAccess* pT = pxXTextFieldTypes->get();
1603         ((SwXTextFieldTypes*)pT)->Invalidate();
1604         delete pxXTextFieldTypes;
1605         pxXTextFieldTypes = 0;
1606     }
1607 
1608     if(pxXTextFieldMasters)
1609     {
1610         XNameAccess* pT = pxXTextFieldMasters->get();
1611         ((SwXTextFieldMasters*)pT)->Invalidate();
1612         delete pxXTextFieldMasters;
1613         pxXTextFieldMasters = 0;
1614     }
1615 
1616     if(pxXTextSections)
1617     {
1618         XNameAccess* pSect = pxXTextSections->get();
1619         ((SwXTextSections*)pSect)->Invalidate();
1620         delete pxXTextSections;
1621         pxXTextSections = 0;
1622     }
1623 
1624     if(pxXDrawPage)
1625     {
1626         // --> OD 2008-07-23 #i91798#, #i91895#
1627         // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1628         uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
1629         xComp->dispose();
1630         // <--
1631         pDrawPage->InvalidateSwDoc();
1632         delete pxXDrawPage;
1633         pxXDrawPage = 0;
1634     }
1635 
1636     if ( pxXNumberingRules )
1637     {
1638         XIndexAccess* pNum = pxXNumberingRules->get();
1639         ((SwXNumberingRulesCollection*)pNum)->Invalidate();
1640         delete pxXNumberingRules;
1641         pxXNumberingRules = 0;
1642     }
1643 
1644     if(pxXFootnotes)
1645     {
1646         XIndexAccess* pFtn = pxXFootnotes->get();
1647         ((SwXFootnotes*)pFtn)->Invalidate();
1648         delete pxXFootnotes;
1649         pxXFootnotes = 0;
1650     }
1651 
1652     if(pxXEndnotes)
1653     {
1654         XIndexAccess* pFtn = pxXEndnotes->get();
1655         ((SwXFootnotes*)pFtn)->Invalidate();
1656         delete pxXEndnotes;
1657         pxXEndnotes = 0;
1658     }
1659 
1660     if(pxXDocumentIndexes)
1661     {
1662         XIndexAccess* pIdxs = pxXDocumentIndexes->get();
1663         ((SwXDocumentIndexes*)pIdxs)->Invalidate();
1664         delete pxXDocumentIndexes;
1665         pxXDocumentIndexes = 0;
1666     }
1667 
1668     if(pxXStyleFamilies)
1669     {
1670         XNameAccess* pStyles = pxXStyleFamilies->get();
1671         ((SwXStyleFamilies*)pStyles)->Invalidate();
1672         delete pxXStyleFamilies;
1673         pxXStyleFamilies = 0;
1674     }
1675     if(pxXAutoStyles)
1676     {
1677         XNameAccess* pStyles = pxXAutoStyles->get();
1678         ((SwXAutoStyles*)pStyles)->Invalidate();
1679         delete pxXAutoStyles;
1680         pxXAutoStyles = 0;
1681     }
1682 
1683     if(pxXBookmarks)
1684     {
1685         XNameAccess* pBm = pxXBookmarks->get();
1686         ((SwXBookmarks*)pBm)->Invalidate();
1687         delete pxXBookmarks;
1688         pxXBookmarks = 0;
1689     }
1690 
1691     if(pxXChapterNumbering)
1692     {
1693         XIndexReplace* pCh = pxXChapterNumbering->get();
1694         ((SwXChapterNumbering*)pCh)->Invalidate();
1695         delete pxXChapterNumbering;
1696         pxXChapterNumbering = 0;
1697     }
1698 
1699     if(pxXFootnoteSettings)
1700     {
1701         XPropertySet* pFntSet = pxXFootnoteSettings->get();
1702         ((SwXFootnoteProperties*)pFntSet)->Invalidate();
1703         delete pxXFootnoteSettings;
1704         pxXFootnoteSettings = 0;
1705     }
1706 
1707     if(pxXEndnoteSettings)
1708     {
1709         XPropertySet* pEndSet = pxXEndnoteSettings->get();
1710         ((SwXEndnoteProperties*)pEndSet)->Invalidate();
1711         delete pxXEndnoteSettings;
1712         pxXEndnoteSettings = 0;
1713     }
1714 
1715     if(pxXLineNumberingProperties)
1716     {
1717         XPropertySet* pLine = pxXLineNumberingProperties->get();
1718         ((SwXLineNumberingProperties*)pLine)->Invalidate();
1719         delete pxXLineNumberingProperties;
1720         pxXLineNumberingProperties = 0;
1721     }
1722     if(pxXReferenceMarks)
1723     {
1724         XNameAccess* pMarks = pxXReferenceMarks->get();
1725         ((SwXReferenceMarks*)pMarks)->Invalidate();
1726         delete pxXReferenceMarks;
1727         pxXReferenceMarks = 0;
1728     }
1729     if(pxLinkTargetSupplier)
1730     {
1731         XNameAccess* pAccess = (*pxLinkTargetSupplier).get();
1732         ((SwXLinkTargetSupplier*)pAccess)->Invalidate();
1733         delete pxLinkTargetSupplier;
1734         pxLinkTargetSupplier = 0;
1735     }
1736     if(pxXRedlines)
1737     {
1738         XEnumerationAccess* pMarks = pxXRedlines->get();
1739         ((SwXRedlines*)pMarks)->Invalidate();
1740         delete pxXRedlines;
1741         pxXRedlines = 0;
1742     }
1743     if(xPropertyHelper.is())
1744     {
1745         pPropertyHelper->Invalidate();
1746         xPropertyHelper = 0;
1747         pPropertyHelper = 0;
1748     }
1749 }
1750 
1751 /*-- 11.03.99 11:51:40---------------------------------------------------
1752 
1753   -----------------------------------------------------------------------*/
1754 #define COM_SUN_STAR__DRAWING_LENGTH 13
1755 Reference< XInterface >  SwXTextDocument::createInstance(const OUString& rServiceName)
1756                                         throw( Exception, RuntimeException )
1757 {
1758     ::vos::OGuard aGuard(Application::GetSolarMutex());
1759     if(!IsValid())
1760         throw RuntimeException();
1761     Reference< XInterface >  xRet;
1762     sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
1763     if(nType != SW_SERVICE_INVALID)
1764     {
1765         xRet = SwXServiceProvider::MakeInstance(nType, pDocShell->GetDoc());
1766     }
1767     else
1768     {
1769         if( rServiceName.compareToAscii( "com.sun.star.", 13 ) == 0 )
1770         {
1771             sal_Int32 nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1772             OUString sCategory = rServiceName.getToken( 0, '.', nIndex );
1773             sal_Bool bShape = sCategory == C2U("drawing");
1774             if( bShape || sCategory == C2U("form"))
1775             {
1776                 if(bShape)
1777                 {
1778                     short nTable = 0;
1779                     if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
1780                         nTable = SW_CREATE_DASH_TABLE;
1781                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
1782                         nTable = SW_CREATE_GRADIENT_TABLE;
1783                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
1784                         nTable = SW_CREATE_HATCH_TABLE;
1785                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
1786                         nTable = SW_CREATE_BITMAP_TABLE;
1787                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
1788                         nTable = SW_CREATE_TRANSGRADIENT_TABLE;
1789                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
1790                         nTable = SW_CREATE_MARKER_TABLE;
1791                     else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Defaults") ) )
1792                         nTable = SW_CREATE_DRAW_DEFAULTS;
1793                     if(nTable)
1794                     {
1795                         xRet = GetPropertyHelper()->GetDrawTable(nTable);
1796                     }
1797                 }
1798             }
1799             else if (sCategory == C2U ("document") )
1800             {
1801                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.Settings") ) )
1802                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1803                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver") ) )
1804                 {
1805                     xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ );
1806                 }
1807             }
1808             else if (sCategory == C2U ("text") )
1809             {
1810                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.DocumentSettings") ) )
1811                     xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1812             }
1813             else if (sCategory == C2U ("chart2") )
1814             {
1815                 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.data.DataProvider") ) )
1816                     xRet = Reference < XInterface > ( dynamic_cast< chart2::data::XDataProvider * >(pDocShell->getIDocumentChartDataProviderAccess()->GetChartDataProvider()) );
1817             }
1818 
1819             if(!xRet.is())
1820             {
1821                 //! we don't want to insert OLE2 Shapes (e.g. "com.sun.star.drawing.OLE2Shape", ...)
1822                 //! like this (by creating them with the documents factory and
1823                 //! adding the shapes to the draw page).
1824                 //! For inserting OLE objects the proper way is to use
1825                 //! "com.sun.star.text.TextEmbeddedObject"!
1826                 if (rServiceName.lastIndexOf( C2U(".OLE2Shape") ) == rServiceName.getLength() - 10)
1827                     throw ServiceNotRegisteredException();  // declare service to be not registered with this factory
1828 
1829                 // --> OD 2006-02-22 #b6382898#
1830                 // the XML import is allowed to create instances of com.sun.star.drawing.OLE2Shape.
1831                 // Thus, a temporary service name is introduced to make this possible.
1832                 OUString aTmpServiceName( rServiceName );
1833                 if ( bShape &&
1834                      rServiceName.compareToAscii( "com.sun.star.drawing.temporaryForXMLImportOLE2Shape" ) == 0 )
1835                 {
1836                     aTmpServiceName = OUString::createFromAscii( "com.sun.star.drawing.OLE2Shape" );
1837                 }
1838                 //hier den Draw - Service suchen
1839                 Reference< XInterface >  xTmp = SvxFmMSFactory::createInstance(aTmpServiceName);
1840                 // <--
1841                 if(bShape)
1842                 {
1843                     nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1844                     if( 0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.GroupShape" ) ) ||
1845                         0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.Shape3DSceneObject" ) ) )
1846                         xRet = *new SwXGroupShape( xTmp );
1847                     else
1848                         xRet = *new SwXShape( xTmp );
1849                 }
1850                 else
1851                     xRet = xTmp;
1852             }
1853         }
1854         else
1855             throw ServiceNotRegisteredException();
1856     }
1857     return xRet;
1858 }
1859 /*-- 11.03.99 11:51:40---------------------------------------------------
1860 
1861   -----------------------------------------------------------------------*/
1862 Reference< XInterface >  SwXTextDocument::createInstanceWithArguments(
1863         const OUString& ServiceSpecifier,
1864         const Sequence< Any >& /*Arguments*/)
1865         throw( Exception, RuntimeException )
1866 {
1867     Reference< XInterface >  xInt = createInstance(ServiceSpecifier);
1868     //die Any-Sequence dient zur Initialisierung von Objekten, die auf
1869     //Parameter zwingend angewiesen sind - bis jetzt haben wir das nicht
1870     return xInt;
1871 }
1872 /*-- 11.03.99 11:51:41---------------------------------------------------
1873 
1874   -----------------------------------------------------------------------*/
1875 Sequence< OUString > SwXTextDocument::getAvailableServiceNames(void)
1876                                         throw( RuntimeException )
1877 {
1878     static Sequence< OUString > aServices;
1879     if ( aServices.getLength() == 0 )
1880     {
1881         Sequence< OUString > aRet =  SvxFmMSFactory::getAvailableServiceNames();
1882         OUString* pRet = aRet.getArray();
1883         for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
1884         {
1885             if ( pRet[i].compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 )
1886             {
1887                 pRet[i] = pRet[aRet.getLength() - 1];
1888                 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
1889                 break;
1890             }
1891         }
1892         Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
1893         aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
1894     }
1895 
1896     return aServices;
1897 }
1898 /* -----------------18.03.99 11:36-------------------
1899  *
1900  * --------------------------------------------------*/
1901 OUString SwXTextDocument::getImplementationName(void) throw( RuntimeException )
1902 {
1903     return C2U("SwXTextDocument");
1904 }
1905 /* -----------------20.01.04 10:14-------------------
1906  *
1907  * --------------------------------------------------*/
1908 sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException )
1909 {
1910     if (
1911         (rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.document.OfficeDocument" ))) ||
1912         (rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.text.GenericTextDocument")))
1913        )
1914     return sal_True;
1915 
1916     sal_Bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
1917     sal_Bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1918     sal_Bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
1919 
1920     return (
1921             (bWebDoc    && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.WebDocument"   ))) ||
1922             (bGlobalDoc && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.GlobalDocument"))) ||
1923             (bTextDoc   && rServiceName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.TextDocument"  )))
1924            );
1925 }
1926 /* -----------------20.01.04 10:17-------------------
1927  *
1928  * --------------------------------------------------*/
1929 Sequence< OUString > SwXTextDocument::getSupportedServiceNames(void) throw( RuntimeException )
1930 {
1931     sal_Bool bWebDoc    = (0 != PTR_CAST(SwWebDocShell,    pDocShell));
1932     sal_Bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1933     sal_Bool bTextDoc   = (!bWebDoc && !bGlobalDoc);
1934 
1935     Sequence< OUString > aRet (3);
1936     OUString* pArray = aRet.getArray();
1937 
1938     pArray[0] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.document.OfficeDocument"  ) ) );
1939     pArray[1] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.GenericTextDocument" ) ) );
1940 
1941     if (bTextDoc)
1942         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.TextDocument" ) ) );
1943     else
1944     if (bWebDoc)
1945         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.WebDocument" ) ) );
1946     else
1947     if (bGlobalDoc)
1948         pArray[2] = OUString ( RTL_CONSTASCII_USTRINGPARAM ( ( "com.sun.star.text.GlobalDocument" ) ) );
1949 
1950     return aRet;
1951 }
1952 /* -----------------05.05.99 12:10-------------------
1953  *
1954  * --------------------------------------------------*/
1955 Reference< XIndexAccess >  SwXTextDocument::getDocumentIndexes(void) throw( RuntimeException )
1956 {
1957     ::vos::OGuard aGuard(Application::GetSolarMutex());
1958     if(!IsValid())
1959         throw RuntimeException();
1960     if(!pxXDocumentIndexes)
1961     {
1962         ((SwXTextDocument*)this)->pxXDocumentIndexes = new Reference< XIndexAccess > ;
1963         *pxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
1964     }
1965     return *pxXDocumentIndexes;
1966 }
1967 
1968 /*-- 10.05.99 13:58:58---------------------------------------------------
1969 
1970   -----------------------------------------------------------------------*/
1971 Reference< XPropertySetInfo >  SwXTextDocument::getPropertySetInfo(void) throw( RuntimeException )
1972 {
1973     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
1974     return xRet;
1975 }
1976 /*-- 10.05.99 13:58:58---------------------------------------------------
1977 
1978   -----------------------------------------------------------------------*/
1979 void SwXTextDocument::setPropertyValue(const OUString& rPropertyName,
1980     const Any& aValue)
1981     throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException,
1982                                          WrappedTargetException, RuntimeException)
1983 {
1984     ::vos::OGuard aGuard(Application::GetSolarMutex());
1985     if(!IsValid())
1986         throw RuntimeException();
1987     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
1988 
1989     if(!pEntry)
1990         throw UnknownPropertyException();
1991     if(pEntry->nFlags & PropertyAttribute::READONLY)
1992         throw PropertyVetoException();
1993     switch(pEntry->nWID)
1994     {
1995         case  WID_DOC_CHAR_COUNT     :
1996         case  WID_DOC_PARA_COUNT     :
1997         case  WID_DOC_WORD_COUNT     :
1998             throw RuntimeException();
1999         case  WID_DOC_WORD_SEPARATOR :
2000         {
2001             OUString sDelim;
2002             aValue >>= sDelim;
2003             SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
2004         }
2005         break;
2006         case WID_DOC_CHANGES_RECORD:
2007         case WID_DOC_CHANGES_SHOW:
2008         {
2009             sal_Bool bSet = *(sal_Bool*)aValue.getValue();
2010             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
2011             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2012             {
2013                 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
2014                 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
2015                 if( bSet )
2016                     eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
2017             }
2018             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2019             {
2020                 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
2021             }
2022             pDocShell->GetDoc()->SetRedlineMode( (RedlineMode_t)(eMode ));
2023         }
2024         break;
2025         case  WID_DOC_CHANGES_PASSWORD:
2026         {
2027             Sequence <sal_Int8> aNew;
2028             if(aValue >>= aNew)
2029             {
2030                 SwDoc* pDoc = pDocShell->GetDoc();
2031                 pDoc->SetRedlinePassword(aNew);
2032                 if(aNew.getLength())
2033                 {
2034                     sal_uInt16 eMode = pDoc->GetRedlineMode();
2035                     eMode = eMode|nsRedlineMode_t::REDLINE_ON;
2036                     pDoc->SetRedlineMode( (RedlineMode_t)(eMode ));
2037                 }
2038             }
2039         }
2040         break;
2041         case WID_DOC_AUTO_MARK_URL :
2042         {
2043             OUString sURL;
2044             aValue >>= sURL;
2045             pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
2046         }
2047         break;
2048         case WID_DOC_HIDE_TIPS :
2049             SW_MOD()->GetModuleConfig()->SetHideFieldTips(*(sal_Bool*)aValue.getValue());
2050         break;
2051         case WID_DOC_REDLINE_DISPLAY:
2052         {
2053             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
2054             eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
2055             sal_Int16 nSet = 0;
2056             aValue >>= nSet;
2057             switch(nSet)
2058             {
2059                 case RedlineDisplayType::NONE: break;
2060                 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
2061                 case RedlineDisplayType::REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;  break;
2062                 case RedlineDisplayType::
2063                         INSERTED_AND_REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT|nsRedlineMode_t::REDLINE_SHOW_DELETE;
2064                 break;
2065                 default: throw IllegalArgumentException();
2066             }
2067             pDocShell->GetDoc()->SetRedlineMode(eRedMode);
2068         }
2069         break;
2070         case WID_DOC_TWO_DIGIT_YEAR:
2071         {
2072             sal_Int16 nYear = 0;
2073             aValue >>= nYear;
2074             SfxRequest aRequest ( SID_ATTR_YEAR2000, SFX_CALLMODE_SLOT, pDocShell->GetDoc()->GetAttrPool());
2075             aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
2076             pDocShell->Execute ( aRequest );
2077         }
2078         break;
2079         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2080         {
2081             SwDrawDocument * pDrawDoc;
2082             sal_Bool bAuto = *(sal_Bool*) aValue.getValue();
2083 
2084             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * >( pDocShell->GetDoc()->GetDrawModel() ) ) )
2085                 pDrawDoc->SetAutoControlFocus( bAuto );
2086             else if (bAuto)
2087             {
2088                 // if setting to true, and we don't have an
2089                 // SdrModel, then we are changing the default and
2090                 // must thus create an SdrModel, if we don't have an
2091                 // SdrModel and we are leaving the default at false,
2092                 // we don't need to make an SdrModel and can do nothing
2093                 // --> OD 2005-08-08 #i52858# - method name changed
2094                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
2095                 // <--
2096                 pDrawDoc->SetAutoControlFocus ( bAuto );
2097             }
2098         }
2099         break;
2100         case WID_DOC_APPLY_FORM_DESIGN_MODE:
2101         {
2102             SwDrawDocument * pDrawDoc;
2103             sal_Bool bMode = *(sal_Bool*)aValue.getValue();
2104 
2105             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2106                 pDrawDoc->SetOpenInDesignMode( bMode );
2107             else if (!bMode)
2108             {
2109                 // if setting to false, and we don't have an
2110                 // SdrModel, then we are changing the default and
2111                 // must thus create an SdrModel, if we don't have an
2112                 // SdrModel and we are leaving the default at true,
2113                 // we don't need to make an SdrModel and can do
2114                 // nothing
2115                 // --> OD 2005-08-08 #i52858# - method name changed
2116                 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
2117                 // <--
2118                 pDrawDoc->SetOpenInDesignMode ( bMode );
2119             }
2120         }
2121         break;
2122         // --> FME 2005-02-25 #i42634# New property to set the bInReading
2123         // flag at the document, used during binary import
2124         case WID_DOC_LOCK_UPDATES :
2125         {
2126             SwDoc* pDoc = pDocShell->GetDoc();
2127             bool bBool (false);
2128             if( aValue >>= bBool )
2129               pDoc->SetInReading( bBool );
2130         }
2131         break;
2132         // <--
2133         case WID_DOC_BUILDID:
2134             aValue >>= maBuildId;
2135         break;
2136         // --> OD 2006-03-21 #b6375613#
2137         case WID_APPLY_WORKAROUND_FOR_B6375613:
2138         {
2139             bool bApplyWorkaroundForB6375613( false );
2140             aValue >>= bApplyWorkaroundForB6375613;
2141             pDocShell->GetDoc()->SetApplyWorkaroundForB6375613( bApplyWorkaroundForB6375613 );
2142         }
2143         break;
2144         // <--
2145 
2146         default:
2147         {
2148             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2149             SfxPoolItem* pNewItem = rItem.Clone();
2150             pNewItem->PutValue(aValue, pEntry->nMemberId);
2151             pDocShell->GetDoc()->SetDefault(*pNewItem);
2152             delete pNewItem;
2153         }
2154     }
2155 }
2156 /*-- 10.05.99 13:58:59---------------------------------------------------
2157 
2158   -----------------------------------------------------------------------*/
2159 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
2160     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2161 {
2162     ::vos::OGuard aGuard(Application::GetSolarMutex());
2163     if(!IsValid())
2164         throw RuntimeException();
2165     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2166 
2167     if(!pEntry)
2168         throw UnknownPropertyException();
2169     Any aAny;
2170     switch(pEntry->nWID)
2171     {
2172         case  WID_DOC_CHAR_COUNT     :
2173         case  WID_DOC_PARA_COUNT     :
2174         case  WID_DOC_WORD_COUNT     :
2175         {
2176             SwDocStat aStat(pDocShell->GetDoc()->GetDocStat());
2177             if(aStat.bModified)
2178                 pDocShell->GetDoc()->UpdateDocStat( aStat );
2179             sal_Int32 nValue;
2180             switch(pEntry->nWID)
2181             {
2182                 case  WID_DOC_CHAR_COUNT     :nValue = aStat.nChar;break;
2183                 case  WID_DOC_PARA_COUNT     :nValue = aStat.nPara;break;
2184                 case  WID_DOC_WORD_COUNT     :nValue = aStat.nWord;break;
2185             }
2186             aAny <<= nValue;
2187         }
2188         break;
2189         case  WID_DOC_WORD_SEPARATOR :
2190         {
2191             aAny <<= OUString(SW_MOD()->GetDocStatWordDelim());
2192         }
2193         break;
2194         case WID_DOC_CHANGES_RECORD:
2195         case WID_DOC_CHANGES_SHOW:
2196         {
2197             sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
2198             sal_Bool bSet = sal_False;
2199             if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2200             {
2201                 sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
2202                 bSet = (eMode & nMask) == nMask;
2203             }
2204             else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2205             {
2206                 bSet = (eMode& nsRedlineMode_t::REDLINE_ON)  != 0;
2207             }
2208             aAny.setValue(&bSet, ::getBooleanCppuType());
2209         }
2210         break;
2211         case  WID_DOC_CHANGES_PASSWORD:
2212         {
2213             SwDoc* pDoc = pDocShell->GetDoc();
2214             aAny <<= pDoc->GetRedlinePassword();
2215         }
2216         break;
2217         case WID_DOC_AUTO_MARK_URL :
2218             aAny <<= OUString(pDocShell->GetDoc()->GetTOIAutoMarkURL());
2219         break;
2220         case WID_DOC_HIDE_TIPS :
2221         {
2222             sal_Bool bTemp = SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2223             aAny.setValue(&bTemp, ::getBooleanCppuType());
2224         }
2225         break;
2226         case WID_DOC_REDLINE_DISPLAY:
2227         {
2228             sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
2229             eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
2230             sal_Int16 nRet = RedlineDisplayType::NONE;
2231             if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
2232                 nRet = RedlineDisplayType::INSERTED;
2233             else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
2234                 nRet = RedlineDisplayType::REMOVED;
2235             else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
2236                 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2237             aAny <<= nRet;
2238         }
2239         break;
2240         case WID_DOC_FORBIDDEN_CHARS:
2241         {
2242             GetPropertyHelper();
2243             Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
2244             aAny <<= xRet;
2245         }
2246         break;
2247         case WID_DOC_TWO_DIGIT_YEAR:
2248         {
2249             aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ( sal_True )->GetYear2000());
2250         }
2251         break;
2252         case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2253         {
2254             SwDrawDocument * pDrawDoc;
2255             sal_Bool bAuto;
2256             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2257                 bAuto = pDrawDoc->GetAutoControlFocus();
2258             else
2259                 bAuto = sal_False;
2260             aAny.setValue(&bAuto, ::getBooleanCppuType());
2261         }
2262         break;
2263         case WID_DOC_APPLY_FORM_DESIGN_MODE:
2264         {
2265             SwDrawDocument * pDrawDoc;
2266             sal_Bool bMode;
2267             if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2268                 bMode = pDrawDoc->GetOpenInDesignMode();
2269             else
2270                 bMode = sal_True;
2271             aAny.setValue(&bMode, ::getBooleanCppuType());
2272         }
2273         break;
2274         case WID_DOC_BASIC_LIBRARIES:
2275             aAny <<= pDocShell->GetBasicContainer();
2276         break;
2277         case WID_DOC_DIALOG_LIBRARIES:
2278             aAny <<= pDocShell->GetDialogContainer();
2279         break;
2280         case WID_DOC_RUNTIME_UID:
2281             aAny <<= getRuntimeUID();
2282         break;
2283         case WID_DOC_LOCK_UPDATES :
2284             aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
2285         break;
2286         case WID_DOC_BUILDID:
2287             aAny <<= maBuildId;
2288         break;
2289         case WID_DOC_HAS_VALID_SIGNATURES:
2290             aAny <<= hasValidSignatures();
2291         break;
2292         // --> OD 2006-03-21 #b6375613#
2293         case WID_APPLY_WORKAROUND_FOR_B6375613:
2294         {
2295             aAny <<= pDocShell->GetDoc()->ApplyWorkaroundForB6375613();
2296         }
2297         break;
2298         // <--
2299 
2300         default:
2301         {
2302             const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2303             rItem.QueryValue(aAny, pEntry->nMemberId);
2304         }
2305     }
2306     return aAny;
2307 }
2308 /*-- 10.05.99 13:58:59---------------------------------------------------
2309 
2310   -----------------------------------------------------------------------*/
2311 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2312     const Reference< XPropertyChangeListener > & /*aListener*/)
2313     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2314 {
2315     DBG_WARNING("not implemented");
2316 }
2317 /*-- 10.05.99 13:58:59---------------------------------------------------
2318 
2319   -----------------------------------------------------------------------*/
2320 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2321     const Reference< XPropertyChangeListener > & /*aListener*/)
2322     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2323 {
2324     DBG_WARNING("not implemented");
2325 }
2326 /*-- 10.05.99 13:59:00---------------------------------------------------
2327 
2328   -----------------------------------------------------------------------*/
2329 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2330     const Reference< XVetoableChangeListener > & /*aListener*/)
2331     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2332 {
2333     DBG_WARNING("not implemented");
2334 }
2335 /*-- 10.05.99 13:59:00---------------------------------------------------
2336 
2337   -----------------------------------------------------------------------*/
2338 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2339                         const Reference< XVetoableChangeListener > & /*aListener*/)
2340     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2341 {
2342     DBG_WARNING("not implemented");
2343 }
2344 /* -----------------25.10.99 10:42-------------------
2345 
2346  --------------------------------------------------*/
2347 Reference< XNameAccess >  SwXTextDocument::getLinks(void) throw( RuntimeException )
2348 {
2349     if(!pxLinkTargetSupplier)
2350     {
2351         pxLinkTargetSupplier = new Reference< XNameAccess > ;
2352         (*pxLinkTargetSupplier) = new SwXLinkTargetSupplier(*(SwXTextDocument*)this);
2353     }
2354     return (*pxLinkTargetSupplier);
2355 }
2356 /* -----------------------------11.01.01 15:01--------------------------------
2357 
2358  ---------------------------------------------------------------------------*/
2359 Reference< XEnumerationAccess > SwXTextDocument::getRedlines(  ) throw(RuntimeException)
2360 {
2361     if(!pxXRedlines)
2362     {
2363         pxXRedlines = new Reference< XEnumerationAccess > ;
2364         (*pxXRedlines) = new SwXRedlines(pDocShell->GetDoc());
2365     }
2366     return *pxXRedlines;
2367 }
2368 /*-- 21.02.00 08:41:06---------------------------------------------------
2369 
2370   -----------------------------------------------------------------------*/
2371 void SwXTextDocument::refresh(void) throw( RuntimeException )
2372 {
2373     ::vos::OGuard aGuard(Application::GetSolarMutex());
2374     if(!IsValid())
2375         throw RuntimeException();
2376     ViewShell *pViewShell = pDocShell->GetWrtShell();
2377     notifyRefreshListeners();
2378     if(pViewShell)
2379         pViewShell->CalcLayout();
2380 }
2381 /*-- 21.02.00 08:41:06---------------------------------------------------
2382 
2383   -----------------------------------------------------------------------*/
2384 void SwXTextDocument::addRefreshListener(const Reference< util::XRefreshListener > & l)
2385     throw( RuntimeException )
2386 {
2387     ::vos::OGuard aGuard(Application::GetSolarMutex());
2388     if ( !IsValid() )
2389         throw RuntimeException();
2390     aRefreshCont.AddListener ( reinterpret_cast < const Reference < lang::XEventListener > &> ( l ));
2391 }
2392 /*-- 21.02.00 08:41:07---------------------------------------------------
2393 
2394   -----------------------------------------------------------------------*/
2395 void SwXTextDocument::removeRefreshListener(const Reference< util::XRefreshListener > & l)
2396     throw( RuntimeException )
2397 {
2398     ::vos::OGuard aGuard(Application::GetSolarMutex());
2399     if ( !IsValid() || !aRefreshCont.RemoveListener ( reinterpret_cast < const Reference < lang::XEventListener > &> ( l ) ) )
2400         throw RuntimeException();
2401 }
2402 /* -----------------------------26.02.01 12:22--------------------------------
2403 
2404  ---------------------------------------------------------------------------*/
2405 void SwXTextDocument::updateLinks(  ) throw(RuntimeException)
2406 {
2407     ::vos::OGuard aGuard(Application::GetSolarMutex());
2408     if(!IsValid())
2409         throw RuntimeException();
2410     SwDoc* pDoc = pDocShell->GetDoc();
2411     sfx2::LinkManager& rLnkMan = pDoc->GetLinkManager();
2412     if( rLnkMan.GetLinks().Count() )
2413     {
2414         UnoActionContext aAction(pDoc);
2415         rLnkMan.UpdateAllLinks( sal_False, sal_False, sal_True );
2416     }
2417 }
2418 //XPropertyState
2419 PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2420     throw (UnknownPropertyException, RuntimeException)
2421 {
2422     ::vos::OGuard aGuard(Application::GetSolarMutex());
2423     PropertyState eRet = PropertyState_DIRECT_VALUE;
2424     if(!IsValid())
2425         throw RuntimeException();
2426     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2427 
2428     if(!pEntry)
2429         throw UnknownPropertyException();
2430     Any aAny;
2431     switch(pEntry->nWID)
2432     {
2433         case 0:default:break;
2434     }
2435     return eRet;
2436 }
2437 Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2438     throw (UnknownPropertyException, RuntimeException)
2439 {
2440     const sal_Int32 nCount = rPropertyNames.getLength();
2441     const OUString * pNames = rPropertyNames.getConstArray();
2442     Sequence < PropertyState > aRet ( nCount );
2443     PropertyState *pState = aRet.getArray();
2444 
2445     for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
2446         pState[nIndex] = getPropertyState( pNames[nIndex] );
2447 
2448     return aRet;
2449 }
2450 void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2451     throw (UnknownPropertyException, RuntimeException)
2452 {
2453     ::vos::OGuard aGuard(Application::GetSolarMutex());
2454     if(!IsValid())
2455         throw RuntimeException();
2456     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2457     if(!pEntry)
2458         throw UnknownPropertyException();
2459     switch(pEntry->nWID)
2460     {
2461         case 0:default:break;
2462     }
2463 }
2464 Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2465     throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
2466 {
2467     ::vos::OGuard aGuard(Application::GetSolarMutex());
2468     if(!IsValid())
2469         throw RuntimeException();
2470     const SfxItemPropertySimpleEntry*  pEntry = pPropSet->getPropertyMap()->getByName( rPropertyName);
2471     if(!pEntry)
2472         throw UnknownPropertyException();
2473     Any aAny;
2474     switch(pEntry->nWID)
2475     {
2476         case 0:default:break;
2477     }
2478     return aAny;
2479 }
2480 
2481 static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions )
2482 {
2483     OutputDevice *pOut = 0;
2484 
2485     uno::Any aAny( rPrintUIOptions.getValue( C2U( "RenderDevice" ) ));
2486     uno::Reference< awt::XDevice >  xRenderDevice;
2487     aAny >>= xRenderDevice;
2488     if (xRenderDevice.is())
2489     {
2490         VCLXDevice*     pDevice = VCLXDevice::GetImplementation( xRenderDevice );
2491         pOut = pDevice ? pDevice->GetOutputDevice() : 0;
2492     }
2493 
2494     return pOut;
2495 }
2496 
2497 
2498 static bool lcl_SeqHasProperty(
2499     const uno::Sequence< beans::PropertyValue >& rOptions,
2500     const sal_Char *pPropName )
2501 {
2502     bool bRes = false;
2503     const sal_Int32 nLen = rOptions.getLength();
2504     const beans::PropertyValue *pProps = rOptions.getConstArray();
2505     for (sal_Int32 i = 0;  i < nLen && !bRes;  ++i)
2506     {
2507         if (pProps[i].Name.equalsAscii( pPropName ))
2508             bRes = true;
2509     }
2510     return bRes;
2511 }
2512 
2513 
2514 SfxViewShell * SwXTextDocument::GetRenderView(
2515     bool &rbIsSwSrcView,
2516     const uno::Sequence< beans::PropertyValue >& rOptions,
2517     bool bIsPDFExport )
2518 {
2519     // get view shell to use
2520     SfxViewShell *pView = 0;
2521     if (bIsPDFExport)
2522         pView = GuessViewShell( rbIsSwSrcView );
2523     else
2524     {
2525         uno::Any aTmp;
2526         const sal_Int32 nLen = rOptions.getLength();
2527         const beans::PropertyValue *pProps = rOptions.getConstArray();
2528         for (sal_Int32 i = 0; i < nLen; ++i)
2529         {
2530             if (pProps[i].Name.equalsAscii( "View" ))
2531             {
2532                 aTmp = pProps[i].Value;
2533                 break;
2534             }
2535         }
2536 
2537         uno::Reference< frame::XController > xController;
2538         if (aTmp >>= xController)
2539         {
2540             DBG_ASSERT( xController.is(), "controller is empty!" );
2541             pView = GuessViewShell( rbIsSwSrcView, xController );
2542         }
2543     }
2544     return pView;
2545 }
2546 
2547 
2548 /*
2549  *  GetRenderDoc:
2550  *  returns the document to be rendered, usually this will be the 'regular'
2551  *  document but in case of PDF export of (multi-)selection it will
2552  *  be a temporary document that gets created if not already done.
2553  *  The rpView variable will be set (if not already done) to the used
2554  *  SfxViewShell.
2555 */
2556 
2557 SwDoc * SwXTextDocument::GetRenderDoc(
2558     SfxViewShell *&rpView,
2559     const uno::Any& rSelection,
2560     bool bIsPDFExport )
2561 {
2562     SwDoc *pDoc = 0;
2563 
2564     uno::Reference< frame::XModel > xModel;
2565     rSelection >>= xModel;
2566     if (xModel == pDocShell->GetModel())
2567         pDoc = pDocShell->GetDoc();
2568     else
2569     {
2570         DBG_ASSERT( !xModel.is(), "unexpected model found" );
2571 
2572         if (rSelection.hasValue())     // is anything selected ?
2573         {
2574             // this part should only be called when a temporary document needs to be created,
2575             // for example for PDF export or printing of (multi-)selection only.
2576 
2577             bool bIsSwSrcView = false;
2578             if (!rpView)
2579             {
2580                 (void) bIsPDFExport;
2581                 // aside from maybe PDF export the view should always have been provided!
2582                 DBG_ASSERT( bIsPDFExport, "view is missing, guessing one..." );
2583 
2584                 rpView = GuessViewShell( bIsSwSrcView );
2585             }
2586             DBG_ASSERT( rpView, "ViewShell missing" );
2587             // the view shell should be SwView for documents PDF export.
2588             // for the page preview no selection should be possible
2589             // (the export dialog does not allow for this option)
2590             const TypeId aSwViewTypeId = TYPE(SwView);
2591             if (rpView  &&  rpView->IsA(aSwViewTypeId))
2592             {
2593                 SfxObjectShellLock xDocSh(((SwView*)rpView)->GetOrCreateTmpSelectionDoc());
2594                 if (xDocSh.Is())
2595                 {
2596                     pDoc = ((SwDocShell*)&xDocSh)->GetDoc();
2597                     rpView = pDoc->GetDocShell()->GetView();
2598                 }
2599             }
2600             else
2601             {
2602                 DBG_ERROR( "unexpected ViewShell" );
2603             }
2604         }
2605     }
2606     return pDoc;
2607 }
2608 
2609 /* -----------------------------23.08.02 16:00--------------------------------
2610 
2611  ---------------------------------------------------------------------------*/
2612 
2613 static void lcl_SavePrintUIOptionsToDocumentPrintData(
2614     SwDoc &rDoc,
2615     const SwPrintUIOptions &rPrintUIOptions,
2616     bool bIsPDFEXport )
2617 {
2618     SwPrintData aDocPrintData( rDoc.getPrintData() );
2619 
2620     aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2621     aDocPrintData.SetPrintTable( rPrintUIOptions.IsPrintTables() );
2622     aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2623     aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2624     aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2625     aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2626     aDocPrintData.SetPrintReverse( rPrintUIOptions.IsPrintReverse() );
2627     aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2628     aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2629     aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2630     aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2631     aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2632     aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2633     aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2634     // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2635     // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2636     aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2637     aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2638 
2639     rDoc.setPrintData( aDocPrintData );
2640 }
2641 
2642 
2643 sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
2644         const uno::Any& rSelection,
2645         const uno::Sequence< beans::PropertyValue >& rxOptions )
2646     throw (IllegalArgumentException, RuntimeException)
2647 {
2648     ::vos::OGuard aGuard(Application::GetSolarMutex());
2649     if(!IsValid())
2650         throw RuntimeException();
2651 
2652     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2653     bool bIsSwSrcView = false;
2654     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2655 
2656     if (!bIsSwSrcView && !m_pRenderData)
2657         m_pRenderData = new SwRenderData;
2658     if (!m_pPrintUIOptions)
2659         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2660     bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2661     // const bool bIsSkipEmptyPages    = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2662 
2663     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2664     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
2665     if (!pDoc || !pView)
2666         return 0;
2667 
2668     // save current UI options from the print dialog for the next call to that dialog
2669     lcl_SavePrintUIOptionsToDocumentPrintData( *pDoc, *m_pPrintUIOptions, bIsPDFExport );
2670 
2671     sal_Int32 nRet = 0;
2672     if (bIsSwSrcView)
2673     {
2674         SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2675         OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2676         nRet = pSwSrcView->PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2677     }
2678     else
2679     {
2680         SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2681 
2682         // TODO/mba: we really need a generic way to get the ViewShell!
2683         ViewShell* pViewShell = 0;
2684         SwView* pSwView = PTR_CAST(SwView, pView);
2685         if ( pSwView )
2686         {
2687             pViewShell = pSwView->GetWrtShellPtr();
2688         }
2689         else
2690         {
2691             if ( bIsPDFExport && bFormat )
2692             {
2693                 //create a hidden view to be able to export as PDF also in print preview
2694                 //pView and pSwView are not changed intentionally!
2695                 m_pHiddenViewFrame = SfxViewFrame::LoadHiddenDocument( *pRenderDocShell, 2 );
2696                 pViewShell = ((SwView*)m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2697             }
2698             else
2699                 pViewShell = ((SwPagePreView*)pView)->GetViewShell();
2700         }
2701 
2702         if (!pViewShell || !pViewShell->GetLayout())
2703             return 0;
2704 
2705         if (bFormat)
2706         {
2707             // #i38289
2708             if( pViewShell->GetViewOptions()->getBrowseMode() )
2709             {
2710                 SwViewOption aOpt( *pViewShell->GetViewOptions() );
2711                 aOpt.setBrowseMode( false );
2712                 pViewShell->ApplyViewOptions( aOpt );
2713                 pSwView->RecheckBrowseMode();
2714             }
2715 
2716             // reformating the document for printing will show the changes in the view
2717             // which is likely to produce many unwanted and not nice to view actions.
2718             // We don't want that! Thus we disable updating of the view.
2719             pViewShell->StartAction();
2720 
2721             if (pSwView)
2722             {
2723                 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2724                     m_pRenderData->ViewOptionAdjustStop();
2725                 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2726                     m_pRenderData->ViewOptionAdjustStart( *pViewShell, *pViewShell->GetViewOptions() );
2727             }
2728 
2729             m_pRenderData->SetSwPrtOptions( new SwPrintData );
2730             m_pRenderData->MakeSwPrtOptions( m_pRenderData->GetSwPrtOptionsRef(), pRenderDocShell,
2731                     m_pPrintUIOptions, m_pRenderData, bIsPDFExport );
2732 
2733             if (pSwView)
2734             {
2735                 // PDF export should not make use of the SwPrtOptions
2736                 const SwPrintData *pPrtOptions = (bIsPDFExport)
2737                     ? NULL : m_pRenderData->GetSwPrtOptions();
2738                 m_pRenderData->ViewOptionAdjust( pPrtOptions );
2739             }
2740 
2741             // since printing now also use the API for PDF export this option
2742             // should be set for printing as well ...
2743             pViewShell->SetPDFExportOption( sal_True );
2744             bool bOrigStatus = pRenderDocShell->IsEnableSetModified();
2745             // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2746             bool bStateChanged = false;
2747             if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
2748             {
2749                 pRenderDocShell->EnableSetModified( sal_False );
2750                 bStateChanged = true;
2751             }
2752 
2753             // --> FME 2005-05-23 #122919# Force field update before PDF export:
2754             pViewShell->ViewShell::UpdateFlds(sal_True);
2755             // <--
2756             if( bStateChanged )
2757                 pRenderDocShell->EnableSetModified( sal_True );
2758 
2759             // there is some redundancy between those two function calls, but right now
2760             // there is no time to sort this out.
2761             //TODO: check what exatly needs to be done and make just one function for that
2762             pViewShell->CalcLayout();
2763             pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2764 
2765             pViewShell->SetPDFExportOption( sal_False );
2766 
2767             // enable view again
2768             pViewShell->EndAction();
2769         }
2770 
2771         const sal_Int32 nPageCount = pViewShell->GetPageCount();
2772 
2773         //
2774         // get number of pages to be rendered
2775         //
2776         const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2777         if (bPrintProspect)
2778         {
2779             pDoc->CalculatePagePairsForProspectPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, nPageCount );
2780             nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2781         }
2782         else
2783         {
2784             const sal_Int16 nPostItMode = (sal_Int16) m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 );
2785             if (nPostItMode != POSTITS_NONE)
2786             {
2787                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2788                 m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
2789             }
2790 
2791             // get set of valid document pages (according to the current settings)
2792             // and their start frames
2793             pDoc->CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2794 
2795             if (nPostItMode != POSTITS_NONE)
2796             {
2797                 pDoc->UpdatePagesForPrintingWithPostItData( *m_pRenderData,
2798                         *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2799             }
2800 
2801             nRet = m_pRenderData->GetPagesToPrint().size();
2802         }
2803     }
2804     DBG_ASSERT( nRet >= 0, "negative number of pages???" );
2805 
2806     return nRet;
2807 }
2808 /* -----------------------------23.08.02 16:00--------------------------------
2809 
2810  ---------------------------------------------------------------------------*/
2811 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2812         sal_Int32 nRenderer,
2813         const uno::Any& rSelection,
2814         const uno::Sequence< beans::PropertyValue >& rxOptions )
2815     throw (IllegalArgumentException, RuntimeException)
2816 {
2817     ::vos::OGuard aGuard(Application::GetSolarMutex());
2818     if(!IsValid())
2819         throw RuntimeException();
2820 
2821     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2822     bool bIsSwSrcView = false;
2823     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2824 
2825     // m_pRenderData should NOT be created here!
2826     // That should only be done in getRendererCount. If this function is called before
2827     // getRendererCount was called then the caller will probably just retrieve the extra UI options
2828     // and is not interested in getting valid information about the other data that would
2829     // otherwise be provided here!
2830 //    if( ! m_pRenderData )
2831 //        m_pRenderData = new SwRenderData;
2832     if (!m_pPrintUIOptions)
2833         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2834     m_pPrintUIOptions->processProperties( rxOptions );
2835     const bool bPrintProspect    = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2836     const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2837     const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup", false );
2838 
2839     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2840     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
2841     if (!pDoc || !pView)
2842         return uno::Sequence< beans::PropertyValue >();
2843 
2844     // due to #110067# (document page count changes sometimes during
2845     // PDF export/printing) we can not check for the upper bound properly.
2846     // Thus instead of throwing the exception we silently return.
2847     if (0 > nRenderer)
2848         throw IllegalArgumentException();
2849 
2850     // TODO/mba: we really need a generic way to get the ViewShell!
2851     ViewShell* pVwSh = 0;
2852     SwView* pSwView = PTR_CAST(SwView, pView);
2853     if ( pSwView )
2854         pVwSh = pSwView->GetWrtShellPtr();
2855     else
2856         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
2857 
2858     sal_Int32 nMaxRenderer = 0;
2859     if (!bIsSwSrcView && m_pRenderData)
2860     {
2861         DBG_ASSERT( m_pRenderData, "m_pRenderData missing!!" );
2862         nMaxRenderer = bPrintProspect?
2863             m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2864             m_pRenderData->GetPagesToPrint().size() - 1;
2865     }
2866     // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2867     // we obmit checking of the upper bound in this case.
2868     if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2869         return uno::Sequence< beans::PropertyValue >();
2870 
2871     uno::Sequence< beans::PropertyValue > aRenderer;
2872     if (m_pRenderData)
2873     {
2874         // --> TL, OD 2010-09-07 #i114210#
2875         // determine the correct page number from the renderer index
2876         // --> OD 2010-10-01 #i114875
2877         // consider brochure print
2878         const sal_uInt16 nPage = bPrintProspect
2879                              ? nRenderer + 1
2880                              : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2881         // <--
2882 
2883         // get paper tray to use ...
2884         sal_Int32 nPrinterPaperTray = -1;
2885         if (! bPrintPaperFromSetup)
2886         {
2887             // ... from individual page style (see the page tab in Format/Page dialog)
2888             const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2889             std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2890             if (aIt != rPaperTrays.end())
2891                 nPrinterPaperTray = aIt->second;
2892         }
2893 
2894         awt::Size aPageSize;
2895         awt::Size aPreferredPageSize;
2896         Size aTmpSize;
2897         if (bIsSwSrcView || bPrintProspect)
2898         {
2899             // for printing of HTML source code and prospect printing we should use
2900             // the printers paper size since
2901             // a) HTML source view has no page size
2902             // b) prospect printing has a different page size from the documents page
2903             //    since two document pages will get rendered on one printer page
2904 
2905             // since PageIncludesNonprintableArea will be set to true we can return the
2906             // printers paper size here.
2907             // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2908             // case we won't get an OutputDevice here, but then the caller also has no need
2909             // for the correct PageSisze right now...
2910             Printer *pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ));
2911             if (pPrinter)
2912             {
2913                 // HTML source view and prospect adapt to the printer's paper size
2914                 aTmpSize = pPrinter->GetPaperSize();
2915                 aTmpSize = pPrinter->LogicToLogic( aTmpSize,
2916                             pPrinter->GetMapMode(), MapMode( MAP_100TH_MM ));
2917                 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2918                 #if 0
2919                 // #i115048# it seems users didn't like getting double the formatted page size
2920                 // revert to "old" behavior scaling to the current paper size of the printer
2921                 if (bPrintProspect)
2922                 {
2923                     // we just state what output size we would need
2924                     // which may cause vcl to set that page size on the printer
2925                     // (if available and not overriden by the user)
2926                     aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2927                     aPreferredPageSize = awt::Size ( TWIP_TO_MM100( 2 * aTmpSize.Width() ),
2928                                                      TWIP_TO_MM100( aTmpSize.Height() ));
2929                 }
2930                 #else
2931                 if( bPrintProspect )
2932                 {
2933                     // just switch to an appropriate portrait/landscape format
2934                     // FIXME: brochure printing with landscape pages puts the
2935                     // pages next to each other, so landscape is currently always
2936                     // the better choice
2937                     if( aPageSize.Width < aPageSize.Height )
2938                     {
2939                         aPreferredPageSize.Width = aPageSize.Height;
2940                         aPreferredPageSize.Height = aPageSize.Width;
2941                     }
2942                 }
2943                 #endif
2944             }
2945         }
2946         else
2947         {
2948             aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2949             aPageSize = awt::Size ( TWIP_TO_MM100( aTmpSize.Width() ),
2950                                     TWIP_TO_MM100( aTmpSize.Height() ));
2951         }
2952 
2953         sal_Int32 nLen = 2;
2954         aRenderer.realloc(2);
2955         aRenderer[0].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageSize" ) );
2956         aRenderer[0].Value <<= aPageSize;
2957         aRenderer[1].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PageIncludesNonprintableArea" ) );
2958         aRenderer[1].Value <<= sal_True;
2959         if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2960         {
2961             ++nLen;
2962             aRenderer.realloc( nLen );
2963             aRenderer[ nLen - 1 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PreferredPageSize" ) );
2964             aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2965         }
2966         if (nPrinterPaperTray >= 0)
2967         {
2968             ++nLen;
2969             aRenderer.realloc( nLen );
2970             aRenderer[ nLen - 1 ].Name  = OUString( RTL_CONSTASCII_USTRINGPARAM( "PrinterPaperTray" ) );
2971             aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2972         }
2973     }
2974 
2975     m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2976 
2977     return aRenderer;
2978 }
2979 /* -----------------------------28.10.02 16:00--------------------------------
2980 
2981  ---------------------------------------------------------------------------*/
2982 SfxViewShell * SwXTextDocument::GuessViewShell(
2983     /* out */ bool &rbIsSwSrcView,
2984     const uno::Reference< css::frame::XController > xController )
2985 {
2986     // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2987     // must not be used (see comment from MBA)
2988     //
2989     SfxViewShell    *pView = 0;
2990     SwView          *pSwView = 0;
2991     SwPagePreView   *pSwPagePreView = 0;
2992     SwSrcView       *pSwSrcView = 0;
2993     SfxViewFrame    *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
2994 
2995     // look for the view shell with the same controller in use,
2996     // otherwise look for a suitable view, preferably a SwView,
2997     // if that one is not found use a SwPagePreView if found.
2998     while (pFrame)
2999     {
3000         pView = pFrame->GetViewShell();
3001         pSwView = dynamic_cast< SwView * >(pView);
3002         pSwSrcView = dynamic_cast< SwSrcView * >(pView);
3003         if (!pSwPagePreView)
3004             pSwPagePreView = dynamic_cast< SwPagePreView * >(pView);
3005         if (xController.is())
3006         {
3007             if (pView && pView->GetController() == xController)
3008                 break;
3009         }
3010         else if (pSwView || pSwSrcView)
3011             break;
3012         pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell,  sal_False );
3013     }
3014 
3015     DBG_ASSERT( pSwView || pSwPagePreView || pSwSrcView, "failed to get view shell" );
3016     if (pView)
3017         rbIsSwSrcView = pSwSrcView != 0;
3018     return pView;
3019 //    return pSwView ? dynamic_cast< SfxViewShell * >(pSwView) :
3020 //            (pSwSrcView ? dynamic_cast< SfxViewShell * >(pSwSrcView) :
3021 //                          dynamic_cast< SfxViewShell * >(pSwPagePreView) );
3022 }
3023 
3024 
3025 void SAL_CALL SwXTextDocument::render(
3026         sal_Int32 nRenderer,
3027         const uno::Any& rSelection,
3028         const uno::Sequence< beans::PropertyValue >& rxOptions )
3029     throw (IllegalArgumentException, RuntimeException)
3030 {
3031     ::vos::OGuard aGuard(Application::GetSolarMutex());
3032     if(!IsValid())
3033         throw RuntimeException();
3034 
3035     // due to #110067# (document page count changes sometimes during
3036     // PDF export/printing) we can not check for the upper bound properly.
3037     // Thus instead of throwing the exception we silently return.
3038     if (0 > nRenderer)
3039         throw IllegalArgumentException();
3040 
3041     const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
3042     bool bIsSwSrcView = false;
3043     SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
3044 
3045     DBG_ASSERT( m_pRenderData, "data should have been created already in getRendererCount..." );
3046     DBG_ASSERT( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
3047     if (!bIsSwSrcView && !m_pRenderData)
3048         m_pRenderData = new SwRenderData;
3049     if (!m_pPrintUIOptions)
3050         m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
3051     m_pPrintUIOptions->processProperties( rxOptions );
3052     const bool bPrintProspect   = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
3053     const bool bLastPage        = m_pPrintUIOptions->getBoolValue( "IsLastPage", sal_False );
3054 
3055     SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
3056     DBG_ASSERT( pDoc && pView, "doc or view shell missing!" );
3057     if (pDoc && pView)
3058     {
3059         sal_Int32 nMaxRenderer = 0;
3060         if (!bIsSwSrcView)
3061         {
3062             DBG_ASSERT( m_pRenderData, "m_pRenderData missing!!" );
3063             nMaxRenderer = bPrintProspect?
3064                 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
3065                 m_pRenderData->GetPagesToPrint().size() - 1;
3066         }
3067         // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
3068         // we obmit checking of the upper bound in this case.
3069         if (bIsSwSrcView || nRenderer <= nMaxRenderer)
3070         {
3071             if (bIsSwSrcView)
3072             {
3073                 SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
3074                 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
3075                 pSwSrcView->PrintSource( pOutDev, nRenderer + 1, false );
3076             }
3077             else
3078             {
3079                 // the view shell should be SwView for documents PDF export
3080                 // or SwPagePreView for PDF export of the page preview
3081                 //!! (check for SwView first as in GuessViewShell) !!
3082                 DBG_ASSERT( pView, "!! view missing !!" );
3083                 const TypeId aSwViewTypeId = TYPE(SwView);
3084                 ViewShell* pVwSh = 0;
3085                 if (pView)
3086                 {
3087                     // TODO/mba: we really need a generic way to get the ViewShell!
3088                     SwView* pSwView = PTR_CAST(SwView, pView);
3089                     if ( pSwView )
3090                         pVwSh = pSwView->GetWrtShellPtr();
3091                     else
3092                         pVwSh = ((SwPagePreView*)pView)->GetViewShell();
3093                 }
3094 
3095                 // get output device to use
3096                 OutputDevice * pOut = lcl_GetOutputDevice( *m_pPrintUIOptions );
3097 
3098                 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
3099                 {
3100                     const rtl::OUString aPageRange  = m_pPrintUIOptions->getStringValue( "PageRange", OUString() );
3101                     const bool bFirstPage           = m_pPrintUIOptions->getBoolValue( "IsFirstPage", sal_False );
3102                     bool bIsSkipEmptyPages          = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
3103 
3104                     DBG_ASSERT(( pView->IsA(aSwViewTypeId) &&  m_pRenderData->IsViewOptionAdjust())
3105                             || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()),
3106                             "SwView / SwViewOptionAdjust_Impl availability mismatch" );
3107 
3108                     // since printing now also use the API for PDF export this option
3109                     // should be set for printing as well ...
3110                     pVwSh->SetPDFExportOption( sal_True );
3111 
3112                     // --> FME 2004-06-08 #i12836# enhanced pdf export
3113                     //
3114                     // First, we have to export hyperlinks, notes, and outline to pdf.
3115                     // During this process, additional information required for tagging
3116                     // the pdf file are collected, which are evaulated during painting.
3117                     //
3118                     SwWrtShell* pWrtShell = pView->IsA(aSwViewTypeId) ?
3119                                             ((SwView*)pView)->GetWrtShellPtr() :
3120                                             0;
3121 
3122                     if (bIsPDFExport && bFirstPage && pWrtShell)
3123                     {
3124                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_False );
3125                     }
3126                     // <--
3127 
3128                     SwPrintData const& rSwPrtOptions =
3129                         *m_pRenderData->GetSwPrtOptions();
3130                     if (bPrintProspect)
3131                         pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
3132                     else    // normal printing and PDF export
3133                         pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer );
3134 
3135                     // --> FME 2004-10-08 #i35176#
3136                     //
3137                     // After printing the last page, we take care for the links coming
3138                     // from the EditEngine. The links are generated during the painting
3139                     // process, but the destinations are still missing.
3140                     //
3141                     if (bIsPDFExport && bLastPage && pWrtShell)
3142                     {
3143                         SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages,  sal_True );
3144                     }
3145                     // <--
3146 
3147                     pVwSh->SetPDFExportOption( sal_False );
3148 
3149                     // last page to be rendered? (not necessarily the last page of the document)
3150                     // -> do clean-up of data
3151                     if (bLastPage)
3152                     {
3153                         // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3154                         // of the shell, which might get destroyed in lcl_DisposeView!
3155                         if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
3156                             m_pRenderData->ViewOptionAdjustStop();
3157 
3158                         if (m_pRenderData && m_pRenderData->HasPostItData())
3159                             m_pRenderData->DeletePostItData();
3160                         if (m_pHiddenViewFrame)
3161                         {
3162                             lcl_DisposeView( m_pHiddenViewFrame, pDocShell );
3163                             m_pHiddenViewFrame = 0;
3164 
3165                             // prevent crash described in #i108805
3166                             SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3167                             SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3168                             pSet->Put( SfxBoolItem( SID_HIDDEN, sal_False ) );
3169 
3170                         }
3171                     }
3172                 }
3173             }
3174         }
3175     }
3176     if( bLastPage )
3177     {
3178         delete m_pRenderData;       m_pRenderData     = NULL;
3179         delete m_pPrintUIOptions;   m_pPrintUIOptions = NULL;
3180     }
3181 }
3182 /* -----------------------------03.10.04 -------------------------------------
3183 
3184  ---------------------------------------------------------------------------*/
3185     // xforms::XFormsSupplier
3186 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3187     throw( RuntimeException )
3188 {
3189     if ( !pDocShell )
3190         throw DisposedException( ::rtl::OUString(), static_cast< XTextDocument* >( this ) );
3191     SwDoc* pDoc = pDocShell->GetDoc();
3192     return pDoc->getXForms();
3193 }
3194 
3195 /* -----------------------------25.09.07 -------------------------------------
3196 
3197  ---------------------------------------------------------------------------*/
3198 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3199     throw ( uno::RuntimeException )
3200 {
3201     return new SwXFlatParagraphIterator( *pDocShell->GetDoc(), nTextMarkupType, bAutomatic );
3202 }
3203 /*-- 07.05.2009 09:21:12---------------------------------------------------
3204 
3205   -----------------------------------------------------------------------*/
3206 uno::Reference< util::XCloneable > SwXTextDocument::createClone(  ) throw (uno::RuntimeException)
3207 {
3208     ::vos::OGuard aGuard(Application::GetSolarMutex());
3209     if(!IsValid())
3210         throw RuntimeException();
3211 
3212     // create a new document - hidden - copy the storage and return it
3213     // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3214     // and thus SfxObjectShellLock is not allowed here
3215     // the model holds reference to the shell, so the shell will not destructed at the end of method
3216     SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false);
3217     uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3218     uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3219     uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3220     storeToStorage( xNewStorage, aTempMediaDescriptor );
3221     uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3222     xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3223     return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3224 }
3225 /* -----------------------------20.06.00 09:54--------------------------------
3226 
3227  ---------------------------------------------------------------------------*/
3228 void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
3229 {
3230     return SwXTextDocumentBaseClass::operator new(t);
3231 }
3232 /* -----------------------------20.06.00 09:54--------------------------------
3233 
3234  ---------------------------------------------------------------------------*/
3235 void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
3236 {
3237     SwXTextDocumentBaseClass::operator delete(p);
3238 }
3239 
3240 
3241 /*---------------------------------------------------
3242 retrieve languages already used in current document
3243 -----------------------------------------------------*/
3244 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3245         ::sal_Int16 nScriptTypes,
3246         ::sal_Int16 nMaxCount )
3247     throw (lang::IllegalArgumentException, uno::RuntimeException)
3248 {
3249     ::vos::OGuard aGuard(Application::GetSolarMutex());
3250 
3251     // possible canonical values for nScriptTypes
3252     // any bit wise combination is allowed
3253     const sal_Int16 nLatin   = 0x001;
3254     const sal_Int16 nAsian   = 0x002;
3255     const sal_Int16 nComplex = 0x004;
3256 
3257     // script types for which to get the languages
3258     const bool bLatin   = 0 != (nScriptTypes & nLatin);
3259     const bool bAsian   = 0 != (nScriptTypes & nAsian);
3260     const bool bComplex = 0 != (nScriptTypes & nComplex);
3261 
3262     if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3263         throw IllegalArgumentException(::rtl::OUString::createFromAscii("nScriptTypes ranges from 1 to 7!"), Reference< XInterface >(), 1);
3264     if (!pDocShell)
3265         throw DisposedException();
3266     SwDoc* pDoc = pDocShell->GetDoc();
3267 
3268     // avoid duplicate values
3269     std::set< LanguageType > aAllLangs;
3270 
3271     //USER STYLES
3272 
3273     const SwCharFmts *pFmts = pDoc->GetCharFmts();
3274     for(sal_uInt16 i = 0; i < pFmts->Count(); ++i)
3275     {
3276         const SwAttrSet &rAttrSet = (*pFmts)[i]->GetAttrSet();
3277         LanguageType nLang = LANGUAGE_DONTKNOW;
3278         if (bLatin)
3279         {
3280             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3281             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3282                 aAllLangs.insert( nLang );
3283         }
3284         if (bAsian)
3285         {
3286             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3287             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3288                 aAllLangs.insert( nLang );
3289         }
3290         if (bComplex)
3291         {
3292             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3293             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3294                 aAllLangs.insert( nLang );
3295         }
3296     }
3297 
3298     const SwTxtFmtColls *pColls = pDoc->GetTxtFmtColls();
3299     for (sal_uInt16 i = 0; i < pColls->Count(); ++i)
3300     {
3301         const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3302         LanguageType nLang = LANGUAGE_DONTKNOW;;
3303         if (bLatin)
3304         {
3305             nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3306             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3307                 aAllLangs.insert( nLang );
3308         }
3309         if (bAsian)
3310         {
3311             nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3312             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3313                 aAllLangs.insert( nLang );
3314         }
3315         if (bComplex)
3316         {
3317             nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3318             if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3319                 aAllLangs.insert( nLang );
3320         }
3321     }
3322 
3323     //AUTO STYLES
3324     const IStyleAccess::SwAutoStyleFamily aFam[2] =
3325     {
3326       IStyleAccess::AUTO_STYLE_CHAR,
3327       IStyleAccess::AUTO_STYLE_PARA
3328     };
3329     for (sal_uInt16 i = 0; i < 2; ++i)
3330     {
3331         std::vector< SfxItemSet_Pointer_t > rStyles;
3332         pDoc->GetIStyleAccess().getAllStyles(rStyles, aFam[i]);
3333         while (!rStyles.empty())
3334         {
3335             SfxItemSet_Pointer_t pStyle = rStyles.back();
3336             rStyles.pop_back();
3337             const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
3338 
3339             LanguageType nLang = LANGUAGE_DONTKNOW;
3340             if (bLatin)
3341             {
3342                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, sal_False )).GetLanguage();
3343                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3344                     aAllLangs.insert( nLang );
3345             }
3346             if (bAsian)
3347             {
3348                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, sal_False )).GetLanguage();
3349                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3350                     aAllLangs.insert( nLang );
3351             }
3352             if (bComplex)
3353             {
3354                 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, sal_False )).GetLanguage();
3355                 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3356                     aAllLangs.insert( nLang );
3357             }
3358         }
3359     }
3360 
3361     //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3362     SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
3363     SdrView *pSdrView = pWrtSh->GetDrawView();
3364 
3365     if( pSdrView )
3366     {
3367         SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3368         if(pOutliner)
3369         {
3370             EditEngine& rEditEng = (EditEngine&)pOutliner->GetEditEngine();
3371             sal_uLong nParCount = pOutliner->GetParagraphCount();
3372             for (sal_uLong nPar=0; nPar<nParCount; nPar++)
3373             {
3374                 //every paragraph
3375                 SvUShorts aPortions;
3376                 rEditEng.GetPortions( (sal_uInt16)nPar, aPortions );
3377 
3378                 for ( sal_uInt16 nPos = aPortions.Count(); nPos; )
3379                 {
3380                     //every position
3381                     --nPos;
3382                     sal_uInt16 nEnd = aPortions.GetObject( nPos );
3383                     sal_uInt16 nStart = nPos ? aPortions.GetObject( nPos - 1 ) : 0;
3384                     ESelection aSelection( (sal_uInt16)nPar, nStart, (sal_uInt16)nPar, nEnd );
3385                     SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3386 
3387                     LanguageType nLang = LANGUAGE_DONTKNOW;
3388                     if (bLatin)
3389                     {
3390                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, sal_False )).GetLanguage();
3391                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3392                             aAllLangs.insert( nLang );
3393                     }
3394                     if (bAsian)
3395                     {
3396                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, sal_False )).GetLanguage();
3397                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3398                             aAllLangs.insert( nLang );
3399                     }
3400                     if (bComplex)
3401                     {
3402                         nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, sal_False )).GetLanguage();
3403                         if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3404                             aAllLangs.insert( nLang );
3405                     }
3406                 }
3407             }
3408         }
3409     }
3410     // less than nMaxCount languages
3411     if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3412         nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3413 
3414     // build return value
3415     sal_Int32 nCount = 0;
3416     uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3417     lang::Locale* pLanguage = aLanguages.getArray();
3418     if (nMaxCount > 0)
3419     {
3420         const SvtLanguageTable aLangTab;
3421         for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
3422         {
3423             if (nCount >= nMaxCount)
3424                 break;
3425             if (LANGUAGE_NONE != *it)
3426             {
3427                 MsLangId::convertLanguageToLocale( *it, pLanguage[nCount] );
3428                 pLanguage[nCount].Language = aLangTab.GetString( *it );
3429                 nCount += 1;
3430             }
3431         }
3432     }
3433 
3434     return aLanguages;
3435 }
3436 
3437 /* -----------------25.10.99 11:06-------------------
3438 
3439  --------------------------------------------------*/
3440 SwXLinkTargetSupplier::SwXLinkTargetSupplier(SwXTextDocument& rxDoc) :
3441     pxDoc(&rxDoc)
3442 {
3443     sTables     = String(SW_RES(STR_CONTENT_TYPE_TABLE));
3444     sFrames     = String(SW_RES(STR_CONTENT_TYPE_FRAME));
3445     sGraphics   = String(SW_RES(STR_CONTENT_TYPE_GRAPHIC));
3446     sOLEs       = String(SW_RES(STR_CONTENT_TYPE_OLE));
3447     sSections   = String(SW_RES(STR_CONTENT_TYPE_REGION));
3448     sOutlines   = String(SW_RES(STR_CONTENT_TYPE_OUTLINE));
3449     sBookmarks  = String(SW_RES(STR_CONTENT_TYPE_BOOKMARK));
3450 }
3451 /* -----------------25.10.99 11:11-------------------
3452 
3453  --------------------------------------------------*/
3454 SwXLinkTargetSupplier::~SwXLinkTargetSupplier()
3455 {
3456 }
3457 
3458 /*-- 25.10.99 11:12:45---------------------------------------------------
3459 
3460   -----------------------------------------------------------------------*/
3461 Any SwXLinkTargetSupplier::getByName(const OUString& rName)
3462     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3463 {
3464     Any aRet;
3465     if(!pxDoc)
3466         throw RuntimeException();
3467     String sToCompare(rName);
3468     String sSuffix('|');
3469     if(sToCompare == sTables)
3470     {
3471         sSuffix += UniString::CreateFromAscii(pMarkToTable);
3472 
3473         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3474                                         pxDoc->getTextTables(), sToCompare, sSuffix );
3475         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3476         aRet.setValue(&xRet, ::getCppuType((Reference<XPropertySet>*)0));
3477     }
3478     else if(sToCompare == sFrames)
3479     {
3480         sSuffix += UniString::CreateFromAscii(pMarkToFrame);
3481         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3482                                         pxDoc->getTextFrames(), sToCompare, sSuffix );
3483         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3484         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3485     }
3486     else if(sToCompare == sSections)
3487     {
3488         sSuffix += UniString::CreateFromAscii(pMarkToRegion);
3489         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3490                                         pxDoc->getTextSections(), sToCompare, sSuffix );
3491         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3492         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3493     }
3494 /*  else if(sToCompare == )
3495     {
3496         sSuffix += UniString::CreateFromAscii(pMarkToText);
3497         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3498                                         pxDoc->, sSuffix );
3499         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3500         aRet.setValue(&xRet, ::getCppuType((const XPropertySet*)0));
3501     }*/
3502     else if(sToCompare == sGraphics)
3503     {
3504         sSuffix += UniString::CreateFromAscii(pMarkToGraphic);
3505         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3506                                         pxDoc->getGraphicObjects(), sToCompare, sSuffix );
3507         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3508         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3509     }
3510     else if(sToCompare == sOLEs)
3511     {
3512         sSuffix += UniString::CreateFromAscii(pMarkToOLE);
3513         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3514                                         pxDoc->getEmbeddedObjects(), sToCompare, sSuffix );
3515         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3516         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3517     }
3518     else if(sToCompare == sOutlines)
3519     {
3520         sSuffix += UniString::CreateFromAscii(pMarkToOutline);
3521         Reference< XNameAccess >  xTbls = new SwXLinkNameAccessWrapper(
3522                                         *pxDoc, sToCompare, sSuffix );
3523         Reference< XPropertySet >  xRet(xTbls, UNO_QUERY);
3524         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3525     }
3526     else if(sToCompare == sBookmarks)
3527     {
3528         sSuffix.Erase();
3529         Reference< XNameAccess >  xBkms = new SwXLinkNameAccessWrapper(
3530                                         pxDoc->getBookmarks(), sToCompare, sSuffix );
3531         Reference< XPropertySet >  xRet(xBkms, UNO_QUERY);
3532         aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3533     }
3534     else
3535         throw NoSuchElementException();
3536     return aRet;
3537 }
3538 /*-- 25.10.99 11:12:46---------------------------------------------------
3539 
3540   -----------------------------------------------------------------------*/
3541 Sequence< OUString > SwXLinkTargetSupplier::getElementNames(void)
3542                                         throw( RuntimeException )
3543 {
3544     Sequence< OUString > aRet(7);
3545     OUString* pNames = aRet.getArray();
3546     pNames[0] = sTables;
3547     pNames[1] = sFrames  ;
3548     pNames[2] = sGraphics;
3549     pNames[3] = sOLEs   ;
3550     pNames[4] = sSections;
3551     pNames[5] = sOutlines;
3552     pNames[6] = sBookmarks;
3553     return aRet;
3554 }
3555 /*-- 25.10.99 11:12:46---------------------------------------------------
3556 
3557   -----------------------------------------------------------------------*/
3558 sal_Bool SwXLinkTargetSupplier::hasByName(const OUString& rName)
3559                                     throw( RuntimeException )
3560 {
3561     String sToCompare(rName);
3562     if( sToCompare == sTables  ||
3563         sToCompare == sFrames  ||
3564         sToCompare == sGraphics||
3565         sToCompare == sOLEs   ||
3566         sToCompare == sSections ||
3567         sToCompare == sOutlines ||
3568         sToCompare == sBookmarks    )
3569         return sal_True;
3570     return sal_False;
3571 }
3572 /*-- 25.10.99 11:12:47---------------------------------------------------
3573 
3574   -----------------------------------------------------------------------*/
3575 uno::Type  SwXLinkTargetSupplier::getElementType(void)
3576                                     throw( RuntimeException )
3577 {
3578     return ::getCppuType((Reference< XPropertySet>*)0);
3579 
3580 }
3581 /*-- 25.10.99 11:12:47---------------------------------------------------
3582 
3583   -----------------------------------------------------------------------*/
3584 sal_Bool SwXLinkTargetSupplier::hasElements(void) throw( RuntimeException )
3585 {
3586     return 0 != pxDoc;
3587 }
3588 /*-- 25.10.99 11:12:47---------------------------------------------------
3589 
3590   -----------------------------------------------------------------------*/
3591 OUString SwXLinkTargetSupplier::getImplementationName(void) throw( RuntimeException )
3592 {
3593     return C2U("SwXLinkTargetSupplier");
3594 }
3595 /*-- 25.10.99 11:12:48---------------------------------------------------
3596 
3597   -----------------------------------------------------------------------*/
3598 sal_Bool SwXLinkTargetSupplier::supportsService(const OUString& rServiceName)
3599                                                 throw( RuntimeException )
3600 {
3601     return (rServiceName == C2U("com.sun.star.document.LinkTargets"));
3602 }
3603 /*-- 25.10.99 11:12:48---------------------------------------------------
3604 
3605   -----------------------------------------------------------------------*/
3606 Sequence< OUString > SwXLinkTargetSupplier::getSupportedServiceNames(void)
3607                                                 throw( RuntimeException )
3608 {
3609     Sequence< OUString > aRet(1);
3610     OUString* pNames = aRet.getArray();
3611     pNames[0] = C2U("com.sun.star.document.LinkTargets");
3612     return aRet;
3613 }
3614 
3615 /*-- 26.10.99 09:16:23---------------------------------------------------
3616 
3617   -----------------------------------------------------------------------*/
3618 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(
3619             Reference< XNameAccess >  xAccess, const String& rLinkDisplayName, String sSuffix ) :
3620     xRealAccess(xAccess),
3621     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3622     sLinkSuffix(sSuffix),
3623     sLinkDisplayName(rLinkDisplayName),
3624     pxDoc(0)
3625 {
3626 }
3627 /* -----------------26.10.99 14:17-------------------
3628 
3629  --------------------------------------------------*/
3630 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(SwXTextDocument& rxDoc,
3631             const String& rLinkDisplayName, String sSuffix) :
3632     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3633     sLinkSuffix(sSuffix),
3634     sLinkDisplayName(rLinkDisplayName),
3635     xDoc(&rxDoc),
3636     pxDoc(&rxDoc)
3637 {
3638 }
3639 /*-- 26.10.99 09:16:23---------------------------------------------------
3640 
3641   -----------------------------------------------------------------------*/
3642 SwXLinkNameAccessWrapper::~SwXLinkNameAccessWrapper()
3643 {
3644 }
3645 /*-- 26.10.99 09:16:24---------------------------------------------------
3646 
3647   -----------------------------------------------------------------------*/
3648 Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
3649     throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3650 {
3651     Any aRet;
3652     sal_Bool bFound = sal_False;
3653     //cut link extension and call the real NameAccess
3654     String sParam = rName;
3655     String sSuffix(sLinkSuffix);
3656     if(sParam.Len() > sSuffix.Len() )
3657     {
3658         String sCmp = sParam.Copy(sParam.Len() - sSuffix.Len(),
3659                                                     sSuffix.Len());
3660         if(sCmp == sSuffix)
3661         {
3662             if(pxDoc)
3663             {
3664                 sParam = sParam.Copy(0, sParam.Len() - sSuffix.Len());
3665                 if(!pxDoc->GetDocShell())
3666                     throw RuntimeException();
3667                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3668                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().Count();
3669 
3670                 for (sal_uInt16 i = 0; i < nOutlineCount && !bFound; ++i)
3671                 {
3672                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3673                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3674                     if(sParam ==
3675                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3676                     {
3677                         Reference< XPropertySet >  xOutline = new SwXOutlineTarget(sParam);
3678                         aRet.setValue(&xOutline, ::getCppuType((Reference<XPropertySet>*)0));
3679                         bFound = sal_True;
3680                     }
3681                 }
3682             }
3683             else
3684             {
3685                 aRet = xRealAccess->getByName(sParam.Copy(0, sParam.Len() - sSuffix.Len()));
3686                 Reference< XInterface > xInt;
3687                 if(!(aRet >>= xInt))
3688                     throw RuntimeException();
3689                 Reference< XPropertySet >  xProp(xInt, UNO_QUERY);
3690                 aRet <<= xProp;
3691                 bFound = sal_True;
3692             }
3693         }
3694     }
3695     if(!bFound)
3696         throw NoSuchElementException();
3697     return aRet;
3698 }
3699 /*-- 26.10.99 09:16:24---------------------------------------------------
3700 
3701   -----------------------------------------------------------------------*/
3702 Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames(void)
3703                                     throw( RuntimeException )
3704 {
3705     Sequence< OUString > aRet;
3706     if(pxDoc)
3707     {
3708         if(!pxDoc->GetDocShell())
3709             throw RuntimeException();
3710 
3711         SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3712         const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3713         sal_uInt16 nOutlineCount = rOutlineNodes.Count();
3714         aRet.realloc(nOutlineCount);
3715         OUString* pResArr = aRet.getArray();
3716         String sSuffix('|');
3717         sSuffix += UniString::CreateFromAscii(pMarkToOutline);
3718         const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3719         for (sal_uInt16 i = 0; i < nOutlineCount; ++i)
3720         {
3721             String sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule);
3722             sEntry += sSuffix;
3723             pResArr[i] = sEntry;
3724         }
3725     }
3726     else
3727     {
3728         Sequence< OUString > aOrg = xRealAccess->getElementNames();
3729         const OUString* pOrgArr = aOrg.getConstArray();
3730         aRet.realloc(aOrg.getLength());
3731         OUString* pResArr = aRet.getArray();
3732         for(long i = 0; i < aOrg.getLength(); i++)
3733         {
3734             pResArr[i] = pOrgArr[i] + sLinkSuffix;
3735         }
3736     }
3737     return aRet;
3738 }
3739 /*-- 26.10.99 09:16:25---------------------------------------------------
3740 
3741   -----------------------------------------------------------------------*/
3742 sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
3743     throw( RuntimeException )
3744 {
3745     sal_Bool bRet = sal_False;
3746     String sParam(rName);
3747     if(sParam.Len() > sLinkSuffix.Len() )
3748     {
3749         String sCmp = sParam.Copy(sParam.Len() - sLinkSuffix.Len(),
3750                                                     sLinkSuffix.Len());
3751         if(sCmp == sLinkSuffix)
3752         {
3753                 sParam = sParam.Copy(0, sParam.Len() - sLinkSuffix.Len());
3754             if(pxDoc)
3755             {
3756                 if(!pxDoc->GetDocShell())
3757                     throw RuntimeException();
3758                 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3759                 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().Count();
3760 
3761                 for (sal_uInt16 i = 0; i < nOutlineCount && !bRet; ++i)
3762                 {
3763                     const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3764                     const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3765                     if(sParam ==
3766                         lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3767                     {
3768                         bRet = sal_True;
3769                     }
3770                 }
3771             }
3772             else
3773             {
3774                 bRet = xRealAccess->hasByName(sParam);
3775             }
3776         }
3777     }
3778     return bRet;
3779 }
3780 /*-- 26.10.99 09:16:25---------------------------------------------------
3781 
3782   -----------------------------------------------------------------------*/
3783 uno::Type  SwXLinkNameAccessWrapper::getElementType(void)
3784                                 throw( RuntimeException )
3785 {
3786     return ::getCppuType((Reference<XPropertySet>*)0);
3787 }
3788 /*-- 26.10.99 09:16:25---------------------------------------------------
3789 
3790   -----------------------------------------------------------------------*/
3791 sal_Bool SwXLinkNameAccessWrapper::hasElements(void) throw( RuntimeException )
3792 {
3793     sal_Bool bRet = sal_False;
3794     if(pxDoc)
3795     {
3796         DBG_ERROR("not implemented");
3797     }
3798     else
3799     {
3800         bRet = xRealAccess->hasElements();
3801     }
3802     return bRet;
3803 }
3804 /*-- 26.10.99 09:16:26---------------------------------------------------
3805 
3806   -----------------------------------------------------------------------*/
3807 Reference< XPropertySetInfo >  SwXLinkNameAccessWrapper::getPropertySetInfo(void)
3808                                         throw( RuntimeException )
3809 {
3810     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
3811     return xRet;
3812 }
3813 /*-- 26.10.99 09:16:26---------------------------------------------------
3814 
3815   -----------------------------------------------------------------------*/
3816 void SwXLinkNameAccessWrapper::setPropertyValue(
3817     const OUString& , const Any& )
3818     throw( UnknownPropertyException,
3819             PropertyVetoException,
3820             IllegalArgumentException,
3821             WrappedTargetException,
3822             RuntimeException)
3823 {
3824     throw UnknownPropertyException();
3825 }
3826 /* -----------------------------08.12.99 11:10--------------------------------
3827 
3828  ---------------------------------------------------------------------------*/
3829 Any lcl_GetDisplayBitmap(String sLinkSuffix)
3830 {
3831     Any aRet;
3832     if(sLinkSuffix.Len())
3833         sLinkSuffix.Erase(0, 1);
3834     sal_uInt16 nImgId = USHRT_MAX;
3835 
3836     if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOutline))
3837         nImgId = CONTENT_TYPE_OUTLINE;
3838     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToTable))
3839         nImgId = CONTENT_TYPE_TABLE;
3840     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToFrame))
3841         nImgId = CONTENT_TYPE_FRAME;
3842     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToGraphic))
3843         nImgId = CONTENT_TYPE_GRAPHIC;
3844 //  else if(== sLinkSuffix)
3845 //      nImgId = CONTENT_TYPE_BOOKMARK;
3846     else if(COMPARE_EQUAL  == sLinkSuffix.CompareToAscii(pMarkToRegion))
3847         nImgId = CONTENT_TYPE_REGION;
3848     else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOLE))
3849         nImgId = CONTENT_TYPE_OLE;
3850     else if(!sLinkSuffix.Len())
3851         nImgId = CONTENT_TYPE_BOOKMARK;
3852     if(USHRT_MAX != nImgId)
3853     {
3854         nImgId += 20000;
3855         sal_Bool bHighContrast = Application::GetSettings().GetStyleSettings().GetHighContrastMode();
3856         ImageList aEntryImages( SW_RES(bHighContrast ? IMG_NAVI_ENTRYBMPH : IMG_NAVI_ENTRYBMP) );
3857         const Image& rImage = aEntryImages.GetImage( nImgId );
3858         Bitmap aBitmap( rImage.GetBitmapEx().GetBitmap() );
3859         Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( aBitmap );
3860         aRet.setValue( &xBmp, ::getCppuType((Reference<awt::XBitmap>*)0) );
3861     }
3862     return aRet;
3863 }
3864 /*-- 26.10.99 09:16:27---------------------------------------------------
3865 
3866   -----------------------------------------------------------------------*/
3867 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
3868     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3869 {
3870     Any aRet;
3871     if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
3872     {
3873         aRet <<= OUString(sLinkDisplayName);
3874     }
3875     else if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_BITMAP)))
3876     {
3877         aRet = lcl_GetDisplayBitmap(sLinkSuffix);
3878     }
3879     else
3880         throw UnknownPropertyException();
3881     return aRet;
3882 }
3883 /*-- 26.10.99 09:16:27---------------------------------------------------
3884 
3885   -----------------------------------------------------------------------*/
3886 void SwXLinkNameAccessWrapper::addPropertyChangeListener(
3887     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3888     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3889 {}
3890 /*-- 26.10.99 09:16:28---------------------------------------------------
3891 
3892   -----------------------------------------------------------------------*/
3893 void SwXLinkNameAccessWrapper::removePropertyChangeListener(
3894     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3895     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3896 {}
3897 /*-- 26.10.99 09:16:28---------------------------------------------------
3898 
3899   -----------------------------------------------------------------------*/
3900 void SwXLinkNameAccessWrapper::addVetoableChangeListener(
3901     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3902     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3903 {}
3904 /*-- 26.10.99 09:16:29---------------------------------------------------
3905 
3906   -----------------------------------------------------------------------*/
3907 void SwXLinkNameAccessWrapper::removeVetoableChangeListener(
3908     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3909     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3910 {}
3911 /*-- 26.10.99 09:16:32---------------------------------------------------
3912 
3913 
3914   -----------------------------------------------------------------------*/
3915 Reference< XNameAccess >  SwXLinkNameAccessWrapper::getLinks(void)
3916                                     throw( RuntimeException )
3917 {
3918     return (SwXLinkNameAccessWrapper*)this;
3919 }
3920 
3921 /*-- 26.10.99 09:21:48---------------------------------------------------
3922 
3923   -----------------------------------------------------------------------*/
3924 OUString SwXLinkNameAccessWrapper::getImplementationName(void) throw( RuntimeException )
3925 {
3926     return C2U("SwXLinkNameAccessWrapper");
3927 }
3928 /*-- 26.10.99 09:21:48---------------------------------------------------
3929 
3930   -----------------------------------------------------------------------*/
3931 sal_Bool SwXLinkNameAccessWrapper::supportsService(const OUString& rServiceName)
3932                                                     throw( RuntimeException )
3933 {
3934     return (rServiceName == C2U("com.sun.star.document.LinkTargets"));
3935 }
3936 /*-- 26.10.99 09:21:48---------------------------------------------------
3937 
3938   -----------------------------------------------------------------------*/
3939 Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames(void)
3940                                                     throw( RuntimeException )
3941 {
3942     Sequence< OUString > aRet(1);
3943     OUString* pNames = aRet.getArray();
3944     pNames[0] = C2U("com.sun.star.document.LinkTargets");
3945     return aRet;
3946 }
3947 /* -----------------26.10.99 15:50-------------------
3948 
3949  --------------------------------------------------*/
3950 SwXOutlineTarget::SwXOutlineTarget(const String& rOutlineText) :
3951     pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3952     sOutlineText(rOutlineText)
3953 {
3954 }
3955 /*-- 26.10.99 15:51:45---------------------------------------------------
3956 
3957   -----------------------------------------------------------------------*/
3958 SwXOutlineTarget::~SwXOutlineTarget()
3959 {
3960 }
3961 /*-- 26.10.99 15:51:46---------------------------------------------------
3962 
3963   -----------------------------------------------------------------------*/
3964 Reference< XPropertySetInfo >  SwXOutlineTarget::getPropertySetInfo(void) throw( RuntimeException )
3965 {
3966     static Reference< XPropertySetInfo >  xRet = pPropSet->getPropertySetInfo();
3967     return xRet;
3968 }
3969 /*-- 26.10.99 15:51:46---------------------------------------------------
3970 
3971   -----------------------------------------------------------------------*/
3972 void SwXOutlineTarget::setPropertyValue(
3973     const OUString& /*PropertyName*/, const Any& /*aValue*/)
3974     throw( UnknownPropertyException, PropertyVetoException,
3975         IllegalArgumentException, WrappedTargetException, RuntimeException)
3976 {
3977     throw UnknownPropertyException();
3978 }
3979 /*-- 26.10.99 15:51:46---------------------------------------------------
3980 
3981   -----------------------------------------------------------------------*/
3982 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
3983     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3984 {
3985     Any aRet;
3986     if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
3987         aRet <<= OUString(sOutlineText);
3988     else
3989         throw UnknownPropertyException();
3990     return aRet;
3991 }
3992 /*-- 26.10.99 15:51:46---------------------------------------------------
3993 
3994   -----------------------------------------------------------------------*/
3995 void SwXOutlineTarget::addPropertyChangeListener(
3996     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3997     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3998 {
3999 }
4000 /*-- 26.10.99 15:51:47---------------------------------------------------
4001 
4002   -----------------------------------------------------------------------*/
4003 void SwXOutlineTarget::removePropertyChangeListener(
4004     const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4005     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4006 {
4007 }
4008 /*-- 26.10.99 15:51:47---------------------------------------------------
4009 
4010   -----------------------------------------------------------------------*/
4011 void SwXOutlineTarget::addVetoableChangeListener(
4012     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4013     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4014 {
4015 }
4016 /*-- 26.10.99 15:51:47---------------------------------------------------
4017 
4018   -----------------------------------------------------------------------*/
4019 void SwXOutlineTarget::removeVetoableChangeListener(
4020     const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4021     throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
4022 {
4023 }
4024 /* -----------------03.05.99 12:28-------------------
4025  *
4026  * --------------------------------------------------*/
4027 OUString SwXOutlineTarget::getImplementationName(void) throw( RuntimeException )
4028 {
4029     return C2U("SwXOutlineTarget");
4030 }
4031 /* -----------------03.05.99 12:28-------------------
4032  *
4033  * --------------------------------------------------*/
4034 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName) throw( RuntimeException )
4035 {
4036     return C2U("com.sun.star.document.LinkTarget") == ServiceName;
4037 }
4038 /* -----------------03.05.99 12:28-------------------
4039  *
4040  * --------------------------------------------------*/
4041 Sequence< OUString > SwXOutlineTarget::getSupportedServiceNames(void) throw( RuntimeException )
4042 {
4043     Sequence < OUString > aRet(1);
4044     OUString* pArray = aRet.getArray();
4045     pArray[0] = C2U("com.sun.star.document.LinkTarget");
4046 
4047     return aRet;
4048 }
4049 /* -----------------------------17.01.01 16:06--------------------------------
4050 
4051  ---------------------------------------------------------------------------*/
4052 SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
4053 SvxUnoForbiddenCharsTable ( rDoc.getForbiddenCharacterTable() )
4054 ,m_pDoc(&rDoc)
4055 {
4056 }
4057 /* -----------------------------17.01.01 16:06--------------------------------
4058 
4059  ---------------------------------------------------------------------------*/
4060 SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
4061 {
4062 }
4063 /* -----------------------------17.01.01 16:06--------------------------------
4064 
4065  ---------------------------------------------------------------------------*/
4066 Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
4067 {
4068     Reference<XInterface> xRet;
4069     if(m_pDoc)
4070     {
4071         switch(nWhich)
4072         {
4073             // --> OD 2005-08-08 #i52858#
4074             // assure that Draw model is created, if it doesn't exist.
4075             case SW_CREATE_DASH_TABLE         :
4076                 if(!xDashTable.is())
4077                     xDashTable = SvxUnoDashTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4078                 xRet = xDashTable;
4079             break;
4080             case SW_CREATE_GRADIENT_TABLE     :
4081                 if(!xGradientTable.is())
4082                     xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4083                 xRet = xGradientTable;
4084             break;
4085             case SW_CREATE_HATCH_TABLE        :
4086                 if(!xHatchTable.is())
4087                     xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4088                 xRet = xHatchTable;
4089             break;
4090             case SW_CREATE_BITMAP_TABLE       :
4091                 if(!xBitmapTable.is())
4092                     xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4093                 xRet = xBitmapTable;
4094             break;
4095             case SW_CREATE_TRANSGRADIENT_TABLE:
4096                 if(!xTransGradientTable.is())
4097                     xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4098                 xRet = xTransGradientTable;
4099             break;
4100             case SW_CREATE_MARKER_TABLE       :
4101                 if(!xMarkerTable.is())
4102                     xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
4103                 xRet = xMarkerTable;
4104             break;
4105             // <--
4106             case  SW_CREATE_DRAW_DEFAULTS:
4107                 if(!xDrawDefaults.is())
4108                     xDrawDefaults = (cppu::OWeakObject*)new SwSvxUnoDrawPool(m_pDoc);
4109                 xRet = xDrawDefaults;
4110             break;
4111 #ifdef DBG_UTIL
4112             default: DBG_ERROR("which table?");
4113 #endif
4114         }
4115     }
4116     return xRet;
4117 }
4118 
4119 void SwXDocumentPropertyHelper::Invalidate()
4120 {
4121     xDashTable = 0;
4122     xGradientTable = 0;
4123     xHatchTable = 0;
4124     xBitmapTable = 0;
4125     xTransGradientTable = 0;
4126     xMarkerTable = 0;
4127     xDrawDefaults = 0;
4128     m_pDoc = 0;
4129     SvxUnoForbiddenCharsTable::mxForbiddenChars.unbind();
4130 }
4131 /* -----------------13.08.2003 12:43-----------------
4132 
4133  --------------------------------------------------*/
4134 void SwXDocumentPropertyHelper::onChange()
4135 {
4136     if(m_pDoc)
4137        m_pDoc->SetModified();
4138 }
4139 
4140 
4141 /*****************************************************************************/
4142 
4143 SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl( ViewShell& rSh, const SwViewOption &rViewOptions ) :
4144     m_rShell( rSh ),
4145     m_aOldViewOptions( rViewOptions )
4146 {
4147 }
4148 
4149 
4150 SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl()
4151 {
4152     m_rShell.ApplyViewOptions( m_aOldViewOptions );
4153 }
4154 
4155 
4156 void
4157 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions)
4158 {
4159     // to avoid unnecessary reformatting the view options related to the content
4160     // below should only change if necessary, that is if respective content is present
4161     const bool bContainsHiddenChars         = m_rShell.GetDoc()->ContainsHiddenChars();
4162     const SwFieldType* pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENTXTFLD );
4163     const bool bContainsHiddenFields        = pFldType && pFldType->GetDepends();
4164     pFldType = m_rShell.GetDoc()->GetSysFldType( RES_HIDDENPARAFLD );
4165     const bool bContainsHiddenParagraphs    = pFldType && pFldType->GetDepends();
4166     pFldType = m_rShell.GetDoc()->GetSysFldType( RES_JUMPEDITFLD );
4167     const bool bContainsPlaceHolders        = pFldType && pFldType->GetDepends();
4168     const bool bContainsFields              = m_rShell.IsAnyFieldInDoc();
4169 
4170     SwViewOption aRenderViewOptions( m_aOldViewOptions );
4171 
4172     // disable anything in the view that should not be printed (or exported to PDF) by default
4173     // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4174     // in section "Display of ...")
4175     aRenderViewOptions.SetParagraph( sal_False );             // paragraph end
4176     aRenderViewOptions.SetSoftHyph( sal_False );              // aka custom hyphens
4177     aRenderViewOptions.SetBlank( sal_False );                 // spaces
4178     aRenderViewOptions.SetHardBlank( sal_False );             // non-breaking spaces
4179     aRenderViewOptions.SetTab( sal_False );                   // tabs
4180     aRenderViewOptions.SetLineBreak( sal_False );             // breaks (type 1)
4181     aRenderViewOptions.SetPageBreak( sal_False );             // breaks (type 2)
4182     aRenderViewOptions.SetColumnBreak( sal_False );           // breaks (type 3)
4183     sal_Bool bVal = pPrtOptions? pPrtOptions->bPrintHiddenText : sal_False;
4184     if (bContainsHiddenChars)
4185         aRenderViewOptions.SetShowHiddenChar( bVal );     // hidden text
4186     if (bContainsHiddenFields)
4187         aRenderViewOptions.SetShowHiddenField( bVal );
4188     if (bContainsHiddenParagraphs)
4189         aRenderViewOptions.SetShowHiddenPara( bVal );
4190 
4191     if (bContainsPlaceHolders)
4192     {
4193         // should always be printed in PDF export!
4194         bVal = pPrtOptions ? pPrtOptions->bPrintTextPlaceholder : sal_True;
4195         aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4196     }
4197 
4198     if (bContainsFields)
4199         aRenderViewOptions.SetFldName( sal_False );
4200 
4201     // we need to set this flag in order to get to see the visible effect of
4202     // some of the above settings (needed for correct rendering)
4203     aRenderViewOptions.SetViewMetaChars( sal_True );
4204 
4205     if (m_aOldViewOptions != aRenderViewOptions)  // check if reformatting is necessary
4206     {
4207         aRenderViewOptions.SetPrinting( pPrtOptions != NULL );
4208         m_rShell.ApplyViewOptions( aRenderViewOptions );
4209     }
4210 }
4211 
4212 
4213 /*****************************************************************************/
4214 
4215 
4216