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