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