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