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