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