bump product version to 4.1.6.2
[LibreOffice.git] / sw / source / ui / uno / unotxdoc.cxx
blobf8d33f0ce1488a8e845ab900a2eb3ffe73d5698d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <osl/mutex.hxx>
22 #include <vcl/image.hxx>
23 #include <vcl/virdev.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/print.hxx>
26 #include <sfx2/viewfrm.hxx>
27 #include <sfx2/sfxbasecontroller.hxx>
28 #include <sfx2/docfile.hxx>
29 #include <sfx2/printer.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <toolkit/awt/vclxdevice.hxx>
32 #include <cmdid.h>
33 #include <swtypes.hxx>
34 #include <wdocsh.hxx>
35 #include <wrtsh.hxx>
36 #include <pview.hxx>
37 #include <viewsh.hxx>
38 #include <pvprtdat.hxx>
39 #include <printdata.hxx>
40 #include <svl/stritem.hxx>
41 #include <unotxdoc.hxx>
42 #include <svl/numuno.hxx>
43 #include <fldbas.hxx>
44 #include <unotextbodyhf.hxx>
45 #include <unotextrange.hxx>
46 #include <unotextcursor.hxx>
47 #include <unosett.hxx>
48 #include <unocoll.hxx>
49 #include <unoredlines.hxx>
50 #include <unosrch.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include <sfx2/request.hxx>
53 #include <sfx2/objsh.hxx> // SfxObjectShellRef <-> SV_DECL_REF(SfxObjectShell)
54 #include <unoprnms.hxx>
55 #include <unostyle.hxx>
56 #include <unodraw.hxx>
57 #include <svl/eitem.hxx>
58 #include <pagedesc.hxx>
59 #include <unotools/textsearch.hxx>
60 #include <unocrsr.hxx>
61 #include <unofieldcoll.hxx>
62 #include <unoidxcoll.hxx>
63 #include <unocrsrhelper.hxx>
64 #include <unotxvw.hxx>
65 #include <poolfmt.hxx>
66 #include <globdoc.hxx>
67 #include <viewopt.hxx>
68 #include <unochart.hxx>
69 #include <charatr.hxx>
70 #include <svx/xmleohlp.hxx>
71 #include <globals.hrc>
72 #include <unomid.h>
73 #include <unotools/printwarningoptions.hxx>
74 #include <com/sun/star/util/SearchOptions.hpp>
75 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
76 #include <com/sun/star/lang/DisposedException.hpp>
77 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
78 #include <com/sun/star/beans/PropertyAttribute.hpp>
79 #include <com/sun/star/beans/XFastPropertySet.hpp>
80 #include <com/sun/star/document/RedlineDisplayType.hpp>
81 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
82 #include <com/sun/star/frame/XController.hpp>
83 #include <com/sun/star/frame/XFrame.hpp>
84 #include <com/sun/star/script/XInvocation.hpp>
85 #include <sfx2/linkmgr.hxx>
86 #include <svx/unofill.hxx>
87 #include <editeng/unolingu.hxx>
88 #include <sfx2/progress.hxx>
89 #include <swmodule.hxx>
90 #include <docstat.hxx>
91 #include <modcfg.hxx>
92 #include <ndtxt.hxx>
93 #include <utlui.hrc>
94 #include <swcont.hxx>
95 #include <unodefaults.hxx>
96 #include <SwXDocumentSettings.hxx>
97 #include <doc.hxx>
98 #include <editeng/forbiddencharacterstable.hxx>
99 #include <svl/zforlist.hxx>
100 #include <drawdoc.hxx>
101 #include <SwStyleNameMapper.hxx>
102 #include <osl/file.hxx>
103 #include <comphelper/storagehelper.hxx>
105 // #i12836# enhanced pdf export
106 #include <EnhancedPDFExportHelper.hxx>
107 #include <numrule.hxx>
109 #include <editeng/langitem.hxx>
110 #include <docary.hxx> //SwCharFmts
111 #include <i18nlangtag/languagetag.hxx>
113 #include <format.hxx>
114 #include <charfmt.hxx> //SwCharFmt
115 #include <fmtcol.hxx> //SwTxtFmtColl
116 #include <unostyle.hxx> //SwAutoStyleFamily
117 #include <istyleaccess.hxx> // handling of automatic styles
119 #include <svl/stylepool.hxx>
120 #include <swatrset.hxx>
121 #include <view.hxx>
122 #include <srcview.hxx>
124 #include <svtools/langtab.hxx>
125 #include <map>
126 #include <set>
127 #include <vector>
129 #include <editeng/eeitem.hxx>
130 #include <editeng/editeng.hxx>
131 #include <svx/svdoutl.hxx>
132 #include <svl/languageoptions.hxx>
133 #include <svx/svdview.hxx>
134 #include <comphelper/processfactory.hxx>
135 #include <comphelper/servicehelper.hxx>
137 using namespace ::com::sun::star;
138 using namespace ::com::sun::star::text;
139 using namespace ::com::sun::star::i18n;
140 using namespace ::com::sun::star::uno;
141 using namespace ::com::sun::star::beans;
142 using namespace ::com::sun::star::lang;
143 using namespace ::com::sun::star::container;
144 using namespace ::com::sun::star::document;
145 using ::osl::FileBase;
147 #define SW_CREATE_DASH_TABLE 0x01
148 #define SW_CREATE_GRADIENT_TABLE 0x02
149 #define SW_CREATE_HATCH_TABLE 0x03
150 #define SW_CREATE_BITMAP_TABLE 0x04
151 #define SW_CREATE_TRANSGRADIENT_TABLE 0x05
152 #define SW_CREATE_MARKER_TABLE 0x06
153 #define SW_CREATE_DRAW_DEFAULTS 0x07
155 extern bool sw_GetPostIts( IDocumentFieldsAccess* pIDFA, _SetGetExpFlds * pSrtLst );
157 static SwPrintUIOptions * lcl_GetPrintUIOptions(
158 SwDocShell * pDocShell,
159 const SfxViewShell * pView )
161 if (!pDocShell)
162 return NULL;
164 const sal_Bool bWebDoc = NULL != dynamic_cast< const SwWebDocShell * >(pDocShell);
165 const bool bSwSrcView = NULL != dynamic_cast< const SwSrcView * >(pView);
166 const SwView * pSwView = dynamic_cast< const SwView * >(pView);
167 const bool bHasSelection = pSwView ? pSwView->HasSelection( sal_False ) : false; // check for any selection, not just text selection
168 const bool bHasPostIts = sw_GetPostIts( pDocShell->GetDoc(), 0 );
170 // get default values to use in dialog from documents SwPrintData
171 const SwPrintData &rPrintData = pDocShell->GetDoc()->getPrintData();
173 // Get current page number
174 sal_uInt16 nCurrentPage = 1;
175 SwWrtShell* pSh = pDocShell->GetWrtShell();
176 if (pSh)
178 SwPaM* pShellCrsr = pSh->GetCrsr();
179 nCurrentPage = pShellCrsr->GetPageNum(sal_True, 0);
181 else if (!bSwSrcView)
183 const SwPagePreView* pPreView = dynamic_cast< const SwPagePreView* >(pView);
184 OSL_ENSURE(pPreView, "Unexpected type of the view shell");
185 if (pPreView)
186 nCurrentPage = pPreView->GetSelectedPage();
188 return new SwPrintUIOptions( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
191 static SwTxtFmtColl *lcl_GetParaStyle(const String& rCollName, SwDoc* pDoc)
193 SwTxtFmtColl* pColl = pDoc->FindTxtFmtCollByName( rCollName );
194 if( !pColl )
196 sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName( rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
197 if( USHRT_MAX != nId )
198 pColl = pDoc->GetTxtCollFromPool( nId );
200 return pColl;
203 static void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell* pDocShell )
205 // check if the view frame still exists
206 SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell,
207 sal_False );
208 while(pFound)
210 if( pFound == pToClose)
212 pToClose->DoClose();
213 break;
215 pFound = SfxViewFrame::GetNext( *pFound,
216 pDocShell,
217 sal_False );
221 class SwXTextDocument::Impl
223 private:
224 ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper
226 public:
227 ::cppu::OInterfaceContainerHelper m_RefreshListeners;
229 Impl() : m_RefreshListeners(m_Mutex) { }
233 namespace
235 class theSwXTextDocumentUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextDocumentUnoTunnelId > {};
238 const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
240 return theSwXTextDocumentUnoTunnelId::get().getSeq();
243 sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
244 throw(RuntimeException)
246 if( rId.getLength() == 16
247 && 0 == memcmp( getUnoTunnelId().getConstArray(),
248 rId.getConstArray(), 16 ) )
250 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
252 if( rId.getLength() == 16
253 && 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
254 rId.getConstArray(), 16 ) )
256 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
259 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
260 if ( nRet )
261 return nRet;
262 else
264 GetNumberFormatter();
265 Any aNumTunnel = xNumFmtAgg->queryAggregation(::getCppuType((Reference<XUnoTunnel>*)0));
266 Reference<XUnoTunnel> xNumTunnel;
267 aNumTunnel >>= xNumTunnel;
268 if(xNumTunnel.is())
269 return xNumTunnel->getSomething(rId);
272 return SfxBaseModel::getSomething( rId );
275 Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException)
277 Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
278 if ( !aRet.hasValue() )
279 aRet = SfxBaseModel::queryInterface(rType);
280 if ( !aRet.hasValue() &&
281 rType == ::getCppuType((Reference<lang::XMultiServiceFactory>*)0))
283 Reference<lang::XMultiServiceFactory> xTmp = this;
284 aRet <<= xTmp;
287 if ( !aRet.hasValue()
288 && rType != ::getCppuType((Reference< com::sun::star::document::XDocumentEventBroadcaster>*)0)
289 && rType != ::getCppuType((Reference< com::sun::star::frame::XController>*)0)
290 && rType != ::getCppuType((Reference< com::sun::star::frame::XFrame>*)0)
291 && rType != ::getCppuType((Reference< com::sun::star::script::XInvocation>*)0)
292 && rType != ::getCppuType((Reference< com::sun::star::beans::XFastPropertySet>*)0)
293 && rType != ::getCppuType((Reference< com::sun::star::awt::XWindow>*)0))
295 GetNumberFormatter();
296 if(xNumFmtAgg.is())
297 aRet = xNumFmtAgg->queryAggregation(rType);
299 return aRet;
302 void SAL_CALL SwXTextDocument::acquire()throw()
304 SfxBaseModel::acquire();
307 void SAL_CALL SwXTextDocument::release()throw()
309 SfxBaseModel::release();
312 Reference< XAdapter > SwXTextDocument::queryAdapter( ) throw(RuntimeException)
314 return SfxBaseModel::queryAdapter();
317 Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException)
319 Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
320 Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
322 Sequence< uno::Type > aNumTypes;
323 GetNumberFormatter();
324 if(xNumFmtAgg.is())
326 const uno::Type& rProvType = ::getCppuType((Reference <XTypeProvider>*)0);
327 Any aNumProv = xNumFmtAgg->queryAggregation(rProvType);
328 Reference<XTypeProvider> xNumProv;
329 if(aNumProv >>= xNumProv)
331 aNumTypes = xNumProv->getTypes();
334 long nIndex = aBaseTypes.getLength();
335 // don't forget the lang::XMultiServiceFactory
336 aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 1);
337 uno::Type* pBaseTypes = aBaseTypes.getArray();
338 const uno::Type* pTextTypes = aTextTypes.getConstArray();
339 long nPos;
340 for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
342 pBaseTypes[nIndex++] = pTextTypes[nPos];
344 const uno::Type* pNumTypes = aNumTypes.getConstArray();
345 for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
347 pBaseTypes[nIndex++] = pNumTypes[nPos];
349 pBaseTypes[nIndex++] = ::getCppuType((Reference<lang::XMultiServiceFactory>*)0);
350 return aBaseTypes;
353 SwXTextDocument::SwXTextDocument(SwDocShell* pShell)
354 : SfxBaseModel(pShell)
355 , m_pImpl(new Impl)
357 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
359 pDocShell(pShell),
361 bObjectValid(pShell != 0),
363 pDrawPage(0),
364 pxXDrawPage(0),
366 pxXNumberingRules(0),
367 pxXFootnotes(0),
368 pxXFootnoteSettings(0),
369 pxXEndnotes(0),
370 pxXEndnoteSettings(0),
371 pxXReferenceMarks(0),
372 pxXTextFieldTypes(0),
373 pxXTextFieldMasters(0),
374 pxXTextSections(0),
375 pxXBookmarks(0),
376 pxXTextTables(0),
377 pxXTextFrames(0),
378 pxXGraphicObjects(0),
379 pxXEmbeddedObjects(0),
380 pxXStyleFamilies(0),
381 pxXAutoStyles(0),
382 pxXChapterNumbering(0),
383 pxXDocumentIndexes(0),
385 pxXLineNumberingProperties(0),
386 pxLinkTargetSupplier(0),
387 pxXRedlines(0),
388 m_pHiddenViewFrame(0),
389 m_pPrintUIOptions( NULL ),
390 m_pRenderData( NULL ),
391 // #i117783#
392 bApplyPagePrintSettingsFromXPagePrintable( sal_False )
396 SwXTextDocument::~SwXTextDocument()
398 InitNewDoc();
399 if(xNumFmtAgg.is())
401 Reference< XInterface > x0;
402 xNumFmtAgg->setDelegator(x0);
403 xNumFmtAgg = 0;
405 delete m_pPrintUIOptions;
406 if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
407 { // rhbz#827695: this can happen if the last page is not printed
408 // the ViewShell has been deleted already by SwView::~SwView
409 // FIXME: replace this awful implementation of XRenderable with
410 // something less insane that has its own view
411 m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
413 delete m_pRenderData;
416 SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
418 if(!xPropertyHelper.is())
420 pPropertyHelper = new SwXDocumentPropertyHelper(*pDocShell->GetDoc());
421 xPropertyHelper = (cppu::OWeakObject*)pPropertyHelper;
423 return pPropertyHelper;
426 void SwXTextDocument::GetNumberFormatter()
428 if(IsValid())
430 if(!xNumFmtAgg.is())
432 if ( pDocShell->GetDoc() )
434 SvNumberFormatsSupplierObj* pNumFmt = new SvNumberFormatsSupplierObj(
435 pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
436 Reference< util::XNumberFormatsSupplier > xTmp = pNumFmt;
437 xNumFmtAgg = Reference< XAggregation >(xTmp, UNO_QUERY);
439 if(xNumFmtAgg.is())
440 xNumFmtAgg->setDelegator((cppu::OWeakObject*)(SwXTextDocumentBaseClass*)this);
442 else
444 const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
445 Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
446 SvNumberFormatsSupplierObj* pNumFmt = 0;
447 Reference< XUnoTunnel > xNumTunnel;
448 if(aNumTunnel >>= xNumTunnel)
450 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
451 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
454 OSL_ENSURE(pNumFmt, "No number formatter available");
455 if(!pNumFmt->GetNumberFormatter())
456 pNumFmt->SetNumberFormatter(pDocShell->GetDoc()->GetNumberFormatter( sal_True ));
461 Reference< XText > SwXTextDocument::getText(void) throw( RuntimeException )
463 SolarMutexGuard aGuard;
464 if(!IsValid())
465 throw RuntimeException();
466 if(!xBodyText.is())
468 pBodyText = new SwXBodyText(pDocShell->GetDoc());
469 xBodyText = pBodyText;
471 return xBodyText;
474 void SwXTextDocument::reformat(void) throw( RuntimeException )
476 SolarMutexGuard aGuard;
477 if(!IsValid())
478 throw RuntimeException();
481 void SwXTextDocument::lockControllers(void) throw( RuntimeException )
483 SolarMutexGuard aGuard;
484 if(IsValid())
486 UnoActionContext* pContext = new UnoActionContext(pDocShell->GetDoc());
487 aActionArr.push_front(pContext);
489 else
490 throw RuntimeException();
493 void SwXTextDocument::unlockControllers(void) throw( RuntimeException )
495 SolarMutexGuard aGuard;
496 if(!aActionArr.empty())
498 UnoActionContext* pContext = aActionArr.front();
499 aActionArr.pop_front();
500 delete pContext;
502 else
503 throw RuntimeException();
506 sal_Bool SwXTextDocument::hasControllersLocked(void) throw( RuntimeException )
508 SolarMutexGuard aGuard;
509 return !aActionArr.empty();
512 Reference< frame::XController > SwXTextDocument::getCurrentController(void) throw( RuntimeException )
514 return SfxBaseModel::getCurrentController();
517 void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
518 throw( NoSuchElementException, RuntimeException )
520 SfxBaseModel::setCurrentController(xController);
523 Reference< XInterface > SwXTextDocument::getCurrentSelection() throw( RuntimeException )
525 SolarMutexGuard aGuard;
526 Reference< XInterface > xRef;
527 if(IsValid())
530 const TypeId aTypeId = TYPE(SwView);
531 SwView* pView = (SwView*)SfxViewShell::GetFirst(&aTypeId);
532 while(pView && pView->GetObjectShell() != pDocShell)
534 pView = (SwView*)SfxViewShell::GetNext(*pView, &aTypeId);
536 if(pView)
538 Any aRef = pView->GetUNOObject()->getSelection();
539 aRef >>= xRef;
542 return xRef;
545 sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
546 throw( RuntimeException )
548 return SfxBaseModel::attachResource(aURL, aArgs);
551 OUString SwXTextDocument::getURL(void) throw( RuntimeException )
553 return SfxBaseModel::getURL();
556 Sequence< beans::PropertyValue > SwXTextDocument::getArgs(void) throw( RuntimeException )
558 return SfxBaseModel::getArgs();
561 void SwXTextDocument::connectController(const Reference< frame::XController > & xController) throw( RuntimeException )
563 SfxBaseModel::connectController(xController);
566 void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController) throw( RuntimeException )
568 SfxBaseModel::disconnectController(xController);
571 void SwXTextDocument::dispose(void) throw( RuntimeException )
573 SfxBaseModel::dispose();
576 void SwXTextDocument::close( sal_Bool bDeliverOwnership ) throw( util::CloseVetoException, RuntimeException )
578 SolarMutexGuard aGuard;
579 if(IsValid() && m_pHiddenViewFrame)
580 lcl_DisposeView( m_pHiddenViewFrame, pDocShell);
581 SfxBaseModel::close(bDeliverOwnership);
584 void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
586 SfxBaseModel::addEventListener(aListener);
589 void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException )
591 SfxBaseModel::removeEventListener(aListener);
594 Reference< XPropertySet > SwXTextDocument::getLineNumberingProperties(void)
595 throw( RuntimeException )
597 SolarMutexGuard aGuard;
598 if(IsValid())
600 if(!pxXLineNumberingProperties)
602 pxXLineNumberingProperties = new Reference<XPropertySet>;
603 (*pxXLineNumberingProperties) = new SwXLineNumberingProperties(pDocShell->GetDoc());
606 else
607 throw RuntimeException();
608 return *pxXLineNumberingProperties;
611 Reference< XIndexReplace > SwXTextDocument::getChapterNumberingRules(void)
612 throw( RuntimeException )
614 SolarMutexGuard aGuard;
615 if(!IsValid())
616 throw RuntimeException();
617 if(!pxXChapterNumbering)
619 pxXChapterNumbering = new Reference< XIndexReplace > ;
620 *pxXChapterNumbering = new SwXChapterNumbering(*pDocShell);
622 return *pxXChapterNumbering;
625 Reference< XIndexAccess > SwXTextDocument::getNumberingRules(void) throw( RuntimeException )
627 SolarMutexGuard aGuard;
628 if(!IsValid())
629 throw RuntimeException();
630 if(!pxXNumberingRules )
632 ((SwXTextDocument*)this)->pxXNumberingRules = new Reference< XIndexAccess > ;
633 *pxXNumberingRules = new SwXNumberingRulesCollection( pDocShell->GetDoc() );
635 return *pxXNumberingRules;
638 Reference< XIndexAccess > SwXTextDocument::getFootnotes(void) throw( RuntimeException )
640 SolarMutexGuard aGuard;
641 if(!IsValid())
642 throw RuntimeException();
643 if(!pxXFootnotes)
645 ((SwXTextDocument*)this)->pxXFootnotes = new Reference< XIndexAccess > ;
646 *pxXFootnotes = new SwXFootnotes(sal_False, pDocShell->GetDoc());
648 return *pxXFootnotes;
651 Reference< XPropertySet > SAL_CALL
652 SwXTextDocument::getFootnoteSettings(void) throw( RuntimeException )
654 SolarMutexGuard aGuard;
655 if(!IsValid())
656 throw RuntimeException();
657 if(!pxXFootnoteSettings)
659 ((SwXTextDocument*)this)->pxXFootnoteSettings = new Reference< XPropertySet > ;
660 *pxXFootnoteSettings = new SwXFootnoteProperties(pDocShell->GetDoc());
662 return *pxXFootnoteSettings;
665 Reference< XIndexAccess > SwXTextDocument::getEndnotes(void) throw( RuntimeException )
667 SolarMutexGuard aGuard;
668 if(!IsValid())
669 throw RuntimeException();
670 if(!pxXEndnotes)
672 ((SwXTextDocument*)this)->pxXEndnotes = new Reference< XIndexAccess > ;
673 *pxXEndnotes = new SwXFootnotes(sal_True, pDocShell->GetDoc());
675 return *pxXEndnotes;
678 Reference< XPropertySet > SwXTextDocument::getEndnoteSettings(void) throw( RuntimeException )
680 SolarMutexGuard aGuard;
681 if(!IsValid())
682 throw RuntimeException();
683 if(!pxXEndnoteSettings)
685 ((SwXTextDocument*)this)->pxXEndnoteSettings = new Reference< XPropertySet > ;
686 *pxXEndnoteSettings = new SwXEndnoteProperties(pDocShell->GetDoc());
688 return *pxXEndnoteSettings;
691 Reference< util::XReplaceDescriptor > SwXTextDocument::createReplaceDescriptor(void)
692 throw( RuntimeException )
694 SolarMutexGuard aGuard;
695 Reference< util::XReplaceDescriptor > xRet = new SwXTextSearch;
696 return xRet;
699 SwUnoCrsr* SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCrsr)
701 getText();
702 XText *const pText = xBodyText.get();
703 SwXBodyText* pBText = (SwXBodyText*)pText;
704 SwXTextCursor *const pXTextCursor = pBText->CreateTextCursor(true);
705 xCrsr.set( static_cast<text::XWordCursor*>(pXTextCursor) );
707 SwUnoCrsr *const pUnoCrsr = pXTextCursor->GetCursor();
708 pUnoCrsr->SetRemainInSection(sal_False);
709 return pUnoCrsr;
712 sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
713 throw( RuntimeException )
715 SolarMutexGuard aGuard;
716 Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
717 if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
718 throw RuntimeException();
720 Reference< XTextCursor > xCrsr;
721 SwUnoCrsr* pUnoCrsr = CreateCursorForSearch(xCrsr);
723 const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
724 xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
726 int eRanges(FND_IN_BODY|FND_IN_SELALL);
728 util::SearchOptions aSearchOpt;
729 pSearch->FillSearchOptions( aSearchOpt );
731 SwDocPositions eStart = pSearch->bBack ? DOCPOS_END : DOCPOS_START;
732 SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
734 // Search should take place anywhere
735 pUnoCrsr->SetRemainInSection(sal_False);
736 sal_uInt32 nResult;
737 UnoActionContext aContext(pDocShell->GetDoc());
738 //try attribute search first
739 if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
741 SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
742 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
743 RES_PARATR_BEGIN, RES_PARATR_END-1,
744 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
746 SfxItemSet aReplace(pDocShell->GetDoc()->GetAttrPool(),
747 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
748 RES_PARATR_BEGIN, RES_PARATR_END-1,
749 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
751 pSearch->FillSearchItemSet(aSearch);
752 pSearch->FillReplaceItemSet(aReplace);
753 sal_Bool bCancel;
754 nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
755 eStart, eEnd, bCancel,
756 (FindRanges)eRanges,
757 pSearch->sSearchText.Len() ? &aSearchOpt : 0,
758 &aReplace );
760 else if(pSearch->bStyles)
762 SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
763 SwTxtFmtColl *pReplaceColl = lcl_GetParaStyle(pSearch->sReplaceText, pUnoCrsr->GetDoc());
765 sal_Bool bCancel;
766 nResult = pUnoCrsr->Find( *pSearchColl,
767 eStart, eEnd, bCancel,
768 (FindRanges)eRanges, pReplaceColl );
771 else
773 //todo/mba: assuming that notes should be omitted
774 sal_Bool bSearchInNotes = sal_False;
775 sal_Bool bCancel;
776 nResult = pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
777 eStart, eEnd, bCancel,
778 (FindRanges)eRanges,
779 sal_True );
781 return (sal_Int32)nResult;
785 Reference< util::XSearchDescriptor > SwXTextDocument::createSearchDescriptor(void)
786 throw( RuntimeException )
788 SolarMutexGuard aGuard;
789 Reference< util::XSearchDescriptor > xRet = new SwXTextSearch;
790 return xRet;
794 // Used for findAll/First/Next
796 SwUnoCrsr* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
797 Reference< XTextCursor > & xCrsr, sal_Bool bAll,
798 sal_Int32& nResult,
799 Reference< XInterface > xLastResult)
801 Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
802 if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
803 return 0;
805 SwUnoCrsr* pUnoCrsr = CreateCursorForSearch(xCrsr);
806 const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
807 xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
809 sal_Bool bParentInExtra = sal_False;
810 if(xLastResult.is())
812 Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
813 OTextCursorHelper* pPosCrsr = 0;
814 if(xCursorTunnel.is())
816 pPosCrsr = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething(
817 OTextCursorHelper::getUnoTunnelId()));
819 SwPaM* pCrsr = pPosCrsr ? pPosCrsr->GetPaM() : 0;
820 if(pCrsr)
822 *pUnoCrsr->GetPoint() = *pCrsr->End();
823 pUnoCrsr->DeleteMark();
825 else
827 SwXTextRange* pRange = 0;
828 if(xCursorTunnel.is())
830 pRange = reinterpret_cast<SwXTextRange*>(xCursorTunnel->getSomething(
831 SwXTextRange::getUnoTunnelId()));
833 if(!pRange)
834 return 0;
835 pRange->GetPositions(*pUnoCrsr);
836 if(pUnoCrsr->HasMark())
838 if(*pUnoCrsr->GetPoint() < *pUnoCrsr->GetMark())
839 pUnoCrsr->Exchange();
840 pUnoCrsr->DeleteMark();
843 const SwNode* pRangeNode = pUnoCrsr->GetNode();
844 bParentInExtra = pRangeNode->FindFlyStartNode() ||
845 pRangeNode->FindFootnoteStartNode() ||
846 pRangeNode->FindHeaderStartNode() ||
847 pRangeNode->FindFooterStartNode() ;
850 util::SearchOptions aSearchOpt;
851 pSearch->FillSearchOptions( aSearchOpt );
854 * The following combinations are allowed:
855 * - Search in the body: -> FND_IN_BODY
856 * - Search all in the body: -> FND_IN_BODYONLY | FND_IN_SELALL
857 * - Search in selections: one / all -> FND_IN_SEL [ | FND_IN_SELALL ]
858 * - Search outside the body: one / all -> FND_IN_OTHER [ | FND_IN_SELALL ]
859 * - Search everywhere all: -> FND_IN_SELALL
861 int eRanges(FND_IN_BODY);
862 if(bParentInExtra)
863 eRanges = FND_IN_OTHER;
864 if(bAll) //always - everywhere?
865 eRanges = FND_IN_SELALL;
866 SwDocPositions eStart = !bAll ? DOCPOS_CURR : pSearch->bBack ? DOCPOS_END : DOCPOS_START;
867 SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
869 nResult = 0;
870 sal_uInt16 nSearchProc = 0;
871 while(nSearchProc < 2)
873 //try attribute search first
874 if(pSearch->HasSearchAttributes())
876 SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
877 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
878 RES_PARATR_BEGIN, RES_PARATR_END-1,
879 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
880 RES_TXTATR_INETFMT, RES_TXTATR_CHARFMT,
882 pSearch->FillSearchItemSet(aSearch);
883 sal_Bool bCancel;
884 nResult = (sal_Int32)pUnoCrsr->Find( aSearch, !pSearch->bStyles,
885 eStart, eEnd, bCancel,
886 (FindRanges)eRanges,
887 pSearch->sSearchText.Len() ? &aSearchOpt : 0,
888 0 );
890 else if(pSearch->bStyles)
892 SwTxtFmtColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCrsr->GetDoc());
893 //pSearch->sReplaceText
894 SwTxtFmtColl *pReplaceColl = 0;
895 sal_Bool bCancel;
896 nResult = (sal_Int32)pUnoCrsr->Find( *pSearchColl,
897 eStart, eEnd, bCancel,
898 (FindRanges)eRanges, pReplaceColl );
900 else
902 //todo/mba: assuming that notes should be omitted
903 sal_Bool bSearchInNotes = sal_False;
904 sal_Bool bCancel;
905 nResult = (sal_Int32)pUnoCrsr->Find( aSearchOpt, bSearchInNotes,
906 eStart, eEnd, bCancel,
907 (FindRanges)eRanges,
908 /*int bReplace =*/sal_False );
910 nSearchProc++;
911 if(nResult || (eRanges&(FND_IN_SELALL|FND_IN_OTHER)))
912 break;
913 //second step - find in other
914 eRanges = FND_IN_OTHER;
916 return pUnoCrsr;
919 Reference< XIndexAccess >
920 SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
921 throw( RuntimeException )
923 SolarMutexGuard aGuard;
924 Reference< XInterface > xTmp;
925 sal_Int32 nResult = 0;
926 Reference< XTextCursor > xCrsr;
927 SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_True, nResult, xTmp);
928 if(!pResultCrsr)
929 throw RuntimeException();
930 Reference< XIndexAccess > xRet;
931 xRet = new SwXTextRanges( (nResult) ? pResultCrsr : 0 );
932 delete pResultCrsr;
933 return xRet;
936 Reference< XInterface > SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
937 throw( RuntimeException )
939 SolarMutexGuard aGuard;
940 Reference< XInterface > xTmp;
941 sal_Int32 nResult = 0;
942 Reference< XTextCursor > xCrsr;
943 SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xTmp);
944 if(!pResultCrsr)
945 throw RuntimeException();
946 Reference< XInterface > xRet;
947 if(nResult)
949 const uno::Reference< text::XText > xParent =
950 ::sw::CreateParentXText(*pDocShell->GetDoc(),
951 *pResultCrsr->GetPoint());
952 xRet = *new SwXTextCursor(xParent, *pResultCrsr);
953 delete pResultCrsr;
955 return xRet;
958 Reference< XInterface > SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
959 const Reference< util::XSearchDescriptor > & xDesc)
960 throw( RuntimeException )
962 SolarMutexGuard aGuard;
963 Reference< XInterface > xTmp;
964 sal_Int32 nResult = 0;
965 Reference< XTextCursor > xCrsr;
966 if(!xStartAt.is())
967 throw RuntimeException();
968 SwUnoCrsr* pResultCrsr = FindAny(xDesc, xCrsr, sal_False, nResult, xStartAt);
969 if(!pResultCrsr)
970 throw RuntimeException();
971 Reference< XInterface > xRet;
972 if(nResult)
974 const uno::Reference< text::XText > xParent =
975 ::sw::CreateParentXText(*pDocShell->GetDoc(),
976 *pResultCrsr->GetPoint());
978 xRet = *new SwXTextCursor(xParent, *pResultCrsr);
979 delete pResultCrsr;
981 return xRet;
984 Sequence< beans::PropertyValue > SwXTextDocument::getPagePrintSettings(void)
985 throw( RuntimeException )
987 SolarMutexGuard aGuard;
988 Sequence< beans::PropertyValue > aSeq(9);
989 if(IsValid())
991 beans::PropertyValue* pArray = aSeq.getArray();
992 SwPagePreViewPrtData aData;
993 const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
994 if(pData)
995 aData = *pData;
996 Any aVal;
997 aVal <<= (sal_Int16)aData.GetRow();
998 pArray[0] = beans::PropertyValue("PageRows", -1, aVal, PropertyState_DIRECT_VALUE);
999 aVal <<= (sal_Int16)aData.GetCol();
1000 pArray[1] = beans::PropertyValue("PageColumns", -1, aVal, PropertyState_DIRECT_VALUE);
1001 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetLeftSpace());
1002 pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1003 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetRightSpace());
1004 pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1005 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetTopSpace());
1006 pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1007 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetBottomSpace());
1008 pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1009 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetHorzSpace());
1010 pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1011 aVal <<= (sal_Int32)TWIP_TO_MM100_UNSIGNED(aData.GetVertSpace());
1012 pArray[7] = beans::PropertyValue("VertMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1013 sal_Bool bTemp = aData.GetLandscape();
1014 aVal.setValue(&bTemp, ::getCppuBooleanType());
1015 pArray[8] = beans::PropertyValue("IsLandscape", -1, aVal, PropertyState_DIRECT_VALUE);
1017 else
1018 throw RuntimeException();
1019 return aSeq;
1022 static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, sal_Bool& bException)
1024 bException = sal_False;
1025 TypeClass eType = rValue.getValueType().getTypeClass();
1027 sal_uInt32 nRet = 0;
1028 if( eType == TypeClass_UNSIGNED_LONG )
1029 rValue >>= nRet;
1030 else
1032 sal_Int32 nVal=0;
1033 bException = !(rValue >>= nVal);
1034 if( !bException )
1035 nRet = (sal_uInt32)nVal;
1038 return nRet;
1041 static String lcl_CreateOutlineString( sal_uInt16 nIndex,
1042 const SwOutlineNodes& rOutlineNodes, const SwNumRule* pOutlRule)
1044 String sEntry;
1045 const SwTxtNode * pTxtNd = rOutlineNodes[ nIndex ]->GetTxtNode();
1046 SwNumberTree::tNumberVector aNumVector = pTxtNd->GetNumberVector();
1047 if( pOutlRule && pTxtNd->GetNumRule())
1048 for( sal_Int8 nLevel = 0;
1049 nLevel <= pTxtNd->GetActualListLevel();
1050 nLevel++ )
1052 long nVal = aNumVector[nLevel];
1053 nVal ++;
1054 nVal -= pOutlRule->Get(nLevel).GetStart();
1055 sEntry += OUString::number( nVal );
1056 sEntry += '.';
1058 sEntry += rOutlineNodes[ nIndex ]->
1059 GetTxtNode()->GetExpandTxt( 0, STRING_LEN, sal_False );
1060 return sEntry;
1063 void SwXTextDocument::setPagePrintSettings(const Sequence< beans::PropertyValue >& aSettings)
1064 throw( RuntimeException )
1066 SolarMutexGuard aGuard;
1067 if(IsValid())
1069 SwPagePreViewPrtData aData;
1070 //if only a few properties are coming, then use the current settings
1071 const SwPagePreViewPrtData* pData = pDocShell->GetDoc()->GetPreViewPrtData();
1072 if(pData)
1073 aData = *pData;
1074 const beans::PropertyValue* pProperties = aSettings.getConstArray();
1075 int nCount = aSettings.getLength();
1076 for(int i = 0; i < nCount; i++)
1078 String sName = pProperties[i].Name;
1079 const Any& rVal = pProperties[i].Value;
1080 sal_Bool bException;
1081 sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
1082 if( COMPARE_EQUAL == sName.CompareToAscii("PageRows" ) )
1084 if(!nVal || nVal > 0xff)
1085 throw RuntimeException();
1086 aData.SetRow((sal_uInt8)nVal);
1088 else if(COMPARE_EQUAL == sName.CompareToAscii("PageColumns"))
1090 if(!nVal || nVal > 0xff)
1091 throw RuntimeException();
1092 aData.SetCol((sal_uInt8)nVal);
1094 else if(COMPARE_EQUAL == sName.CompareToAscii("LeftMargin"))
1096 aData.SetLeftSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1098 else if(COMPARE_EQUAL == sName.CompareToAscii("RightMargin"))
1100 aData.SetRightSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1102 else if(COMPARE_EQUAL == sName.CompareToAscii("TopMargin"))
1104 aData.SetTopSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1106 else if(COMPARE_EQUAL == sName.CompareToAscii("BottomMargin"))
1108 aData.SetBottomSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1110 else if(COMPARE_EQUAL == sName.CompareToAscii("HoriMargin"))
1112 aData.SetHorzSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1114 else if(COMPARE_EQUAL == sName.CompareToAscii("VertMargin"))
1116 aData.SetVertSpace(MM100_TO_TWIP_UNSIGNED(nVal));
1118 else if(COMPARE_EQUAL == sName.CompareToAscii("IsLandscape"))
1120 bException = (::getBooleanCppuType() != rVal.getValueType());
1121 aData.SetLandscape(*(sal_Bool*)rVal.getValue());
1123 else
1124 bException = sal_True;
1125 if(bException)
1126 throw RuntimeException();
1128 pDocShell->GetDoc()->SetPreViewPrtData(&aData);
1130 else
1131 throw RuntimeException();
1134 void SwXTextDocument::printPages(const Sequence< beans::PropertyValue >& xOptions)
1135 throw( IllegalArgumentException, RuntimeException )
1137 SolarMutexGuard aGuard;
1138 if(IsValid())
1140 SfxViewFrame* pFrame = SfxViewFrame::LoadHiddenDocument( *pDocShell, 7 );
1141 SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SFX_CALLMODE_SYNCHRON,
1142 pDocShell->GetDoc()->GetAttrPool());
1143 aReq.AppendItem(SfxBoolItem(FN_PRINT_PAGEPREVIEW, sal_True));
1145 OUString sFileName(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_FILE_NAME)));
1146 OUString sCopyCount(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_COPY_COUNT)));
1147 OUString sCollate(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_COLLATE)));
1148 OUString sSort(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_SORT)));
1149 OUString sPages(OUString::createFromAscii(SW_PROP_NAME_STR(UNO_NAME_PAGES)));
1151 for ( int n = 0; n < xOptions.getLength(); ++n )
1153 // get Property-Value from options
1154 const beans::PropertyValue &rProp = xOptions.getConstArray()[n];
1155 Any aValue( rProp.Value );
1157 // FileName-Property?
1158 if ( rProp.Name == sFileName )
1160 OUString sFileURL;
1161 if ( (rProp.Value >>= sFileURL ) )
1163 // Convert the File URL into a system dependant path, as the SalPrinter expects
1164 OUString sSystemPath;
1165 FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
1166 aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
1168 else if ( rProp.Value.getValueType() != ::getVoidCppuType() )
1169 throw IllegalArgumentException();
1172 // CopyCount-Property
1173 else if ( rProp.Name == sCopyCount )
1175 sal_Int32 nCopies = 0;
1176 aValue >>= nCopies;
1177 aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, (sal_Int16)nCopies ) );
1180 // Collate-Property
1181 else if ( rProp.Name == sCollate )
1183 if ( rProp.Value.getValueType() == ::getBooleanCppuType())
1185 aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *(sal_Bool*)rProp.Value.getValue() ) );
1186 else
1187 throw IllegalArgumentException();
1190 // Sort-Property
1191 else if ( rProp.Name == sSort )
1193 if ( rProp.Value.getValueType() == ::getBooleanCppuType() )
1194 aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *(sal_Bool*)rProp.Value.getValue() ) );
1195 else
1196 throw IllegalArgumentException();
1199 // Pages-Property
1200 else if ( rProp.Name == sPages )
1202 OUString sTmp;
1203 if ( rProp.Value >>= sTmp )
1204 aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
1205 else
1206 throw IllegalArgumentException();
1210 // #i117783#
1211 bApplyPagePrintSettingsFromXPagePrintable = sal_True;
1212 pFrame->GetViewShell()->ExecuteSlot(aReq);
1213 // Frame close
1214 pFrame->DoClose();
1217 else
1218 throw RuntimeException();
1221 Reference< XNameAccess > SwXTextDocument::getReferenceMarks(void)
1222 throw( RuntimeException )
1224 SolarMutexGuard aGuard;
1225 if(!IsValid())
1226 throw RuntimeException();
1227 if(!pxXReferenceMarks)
1229 ((SwXTextDocument*)this)->pxXReferenceMarks = new Reference< XNameAccess > ;
1230 *pxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
1232 return *pxXReferenceMarks;
1235 Reference< XEnumerationAccess > SwXTextDocument::getTextFields(void) throw( RuntimeException )
1237 SolarMutexGuard aGuard;
1238 if(!IsValid())
1239 throw RuntimeException();
1240 if(!pxXTextFieldTypes)
1242 ((SwXTextDocument*)this)->pxXTextFieldTypes = new Reference< XEnumerationAccess > ;
1243 *pxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
1245 return *pxXTextFieldTypes;
1248 Reference< XNameAccess > SwXTextDocument::getTextFieldMasters(void)
1249 throw( RuntimeException )
1251 SolarMutexGuard aGuard;
1252 if(!IsValid())
1253 throw RuntimeException();
1254 if(!pxXTextFieldMasters)
1256 ((SwXTextDocument*)this)->pxXTextFieldMasters = new Reference< XNameAccess > ;
1257 *pxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
1259 return *pxXTextFieldMasters;
1262 Reference< XNameAccess > SwXTextDocument::getEmbeddedObjects(void) throw( RuntimeException )
1264 SolarMutexGuard aGuard;
1265 if(!IsValid())
1266 throw RuntimeException();
1267 if(!pxXEmbeddedObjects)
1269 ((SwXTextDocument*)this)->pxXEmbeddedObjects = new Reference< XNameAccess > ;
1270 *pxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
1272 return *pxXEmbeddedObjects;
1275 Reference< XNameAccess > SwXTextDocument::getBookmarks(void) throw( RuntimeException )
1277 SolarMutexGuard aGuard;
1278 if(!IsValid())
1279 throw RuntimeException();
1280 if(!pxXBookmarks)
1282 ((SwXTextDocument*)this)->pxXBookmarks = new Reference< XNameAccess > ;
1283 *pxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
1285 return *pxXBookmarks;
1288 Reference< XNameAccess > SwXTextDocument::getTextSections(void) throw( RuntimeException )
1290 SolarMutexGuard aGuard;
1291 if(!IsValid())
1292 throw RuntimeException();
1293 if(!pxXTextSections)
1295 ((SwXTextDocument*)this)->pxXTextSections = new Reference< XNameAccess > ;
1296 *pxXTextSections = new SwXTextSections(pDocShell->GetDoc());
1298 return *pxXTextSections;
1301 Reference< XNameAccess > SwXTextDocument::getTextTables(void) throw( RuntimeException )
1303 SolarMutexGuard aGuard;
1304 if(!IsValid())
1305 throw RuntimeException();
1306 if(!pxXTextTables)
1308 ((SwXTextDocument*)this)->pxXTextTables = new Reference< XNameAccess > ;
1309 *pxXTextTables = new SwXTextTables(pDocShell->GetDoc());
1311 return *pxXTextTables;
1314 Reference< XNameAccess > SwXTextDocument::getGraphicObjects(void) throw( RuntimeException )
1316 SolarMutexGuard aGuard;
1317 if(!IsValid())
1318 throw RuntimeException();
1319 if(!pxXGraphicObjects)
1321 ((SwXTextDocument*)this)->pxXGraphicObjects = new Reference< XNameAccess > ;
1322 *pxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
1324 return *pxXGraphicObjects;
1327 Reference< XNameAccess > SwXTextDocument::getTextFrames(void) throw( RuntimeException )
1329 SolarMutexGuard aGuard;
1330 if(!IsValid())
1331 throw RuntimeException();
1332 if(!pxXTextFrames)
1334 ((SwXTextDocument*)this)->pxXTextFrames = new Reference< XNameAccess > ;
1335 *pxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
1337 return *pxXTextFrames;
1340 Reference< XNameAccess > SwXTextDocument::getStyleFamilies(void) throw( RuntimeException )
1342 SolarMutexGuard aGuard;
1343 if(!IsValid())
1344 throw RuntimeException();
1345 if(!pxXStyleFamilies)
1347 ((SwXTextDocument*)this)->pxXStyleFamilies = new Reference< XNameAccess > ;
1348 *pxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
1350 return *pxXStyleFamilies;
1353 uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles( )
1354 throw (uno::RuntimeException)
1356 SolarMutexGuard aGuard;
1357 if(!IsValid())
1358 throw RuntimeException();
1359 if(!pxXAutoStyles)
1361 pxXAutoStyles = new Reference< style::XAutoStyles > ;
1362 *pxXAutoStyles = new SwXAutoStyles(*pDocShell);
1364 return *pxXAutoStyles;
1368 Reference< drawing::XDrawPage > SwXTextDocument::getDrawPage(void) throw( RuntimeException )
1370 SolarMutexGuard aGuard;
1371 if(!IsValid())
1372 throw RuntimeException();
1373 if(!pxXDrawPage)
1375 ((SwXTextDocument*)this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1376 ((SwXTextDocument*)this)->pxXDrawPage = new Reference< drawing::XDrawPage >(pDrawPage);
1377 // Create a Reference to trigger the complete initialization of the
1378 // object. Otherwise in some corner cases it would get initialized
1379 // at ::InitNewDoc -> which would get called during
1380 // close() or dispose() -> n#681746
1381 uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
1383 return *pxXDrawPage;
1386 SwXDrawPage* SwXTextDocument::GetDrawPage()
1388 if(!IsValid())
1389 return 0;
1390 if(!pDrawPage)
1391 getDrawPage();
1392 return pDrawPage;
1395 void SwXTextDocument::Invalidate()
1397 bObjectValid = sal_False;
1398 if(xNumFmtAgg.is())
1400 const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1401 Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1402 SvNumberFormatsSupplierObj* pNumFmt = 0;
1403 Reference< XUnoTunnel > xNumTunnel;
1404 if(aNumTunnel >>= xNumTunnel)
1406 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1407 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1408 pNumFmt->SetNumberFormatter(0);
1410 OSL_ENSURE(pNumFmt, "No number formatter available");
1412 InitNewDoc();
1413 pDocShell = 0;
1414 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
1415 m_pImpl->m_RefreshListeners.disposeAndClear(ev);
1418 void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
1420 if(pDocShell && pDocShell != pNewDocShell)
1421 Invalidate();
1422 pDocShell = pNewDocShell;
1423 bObjectValid = sal_True;
1426 void SwXTextDocument::InitNewDoc()
1428 // first invalidate all collections, then delete references and Set to zero
1429 if(pxXTextTables)
1431 XNameAccess* pTbls = pxXTextTables->get();
1432 ((SwXTextTables*)pTbls)->Invalidate();
1433 delete pxXTextTables;
1434 pxXTextTables = 0;
1437 if(pxXTextFrames)
1439 XNameAccess* pFrms = pxXTextFrames->get();
1440 ((SwXTextFrames*)pFrms)->Invalidate();
1441 delete pxXTextFrames;
1442 pxXTextFrames = 0;
1445 if(pxXGraphicObjects)
1447 XNameAccess* pFrms = pxXGraphicObjects->get();
1448 ((SwXTextGraphicObjects*)pFrms)->Invalidate();
1449 delete pxXGraphicObjects;
1450 pxXGraphicObjects = 0;
1453 if(pxXEmbeddedObjects)
1455 XNameAccess* pOLE = pxXEmbeddedObjects->get();
1456 ((SwXTextEmbeddedObjects*)pOLE)->Invalidate();
1457 delete pxXEmbeddedObjects;
1458 pxXEmbeddedObjects = 0;
1461 if(xBodyText.is())
1463 xBodyText = 0;
1464 pBodyText = 0;
1467 if(xNumFmtAgg.is())
1469 const uno::Type& rTunnelType = ::getCppuType((Reference <XUnoTunnel>*)0);
1470 Any aNumTunnel = xNumFmtAgg->queryAggregation(rTunnelType);
1471 SvNumberFormatsSupplierObj* pNumFmt = 0;
1472 Reference< XUnoTunnel > xNumTunnel;
1473 if(aNumTunnel >>= xNumTunnel)
1475 pNumFmt = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1476 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1479 OSL_ENSURE(pNumFmt, "No number formatter available");
1480 pNumFmt->SetNumberFormatter(0);
1483 if(pxXTextFieldTypes)
1485 XEnumerationAccess* pT = pxXTextFieldTypes->get();
1486 ((SwXTextFieldTypes*)pT)->Invalidate();
1487 delete pxXTextFieldTypes;
1488 pxXTextFieldTypes = 0;
1491 if(pxXTextFieldMasters)
1493 XNameAccess* pT = pxXTextFieldMasters->get();
1494 ((SwXTextFieldMasters*)pT)->Invalidate();
1495 delete pxXTextFieldMasters;
1496 pxXTextFieldMasters = 0;
1499 if(pxXTextSections)
1501 XNameAccess* pSect = pxXTextSections->get();
1502 ((SwXTextSections*)pSect)->Invalidate();
1503 delete pxXTextSections;
1504 pxXTextSections = 0;
1507 if(pxXDrawPage)
1509 // #i91798#, #i91895#
1510 // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1511 uno::Reference<lang::XComponent> xComp( *pxXDrawPage, uno::UNO_QUERY );
1512 xComp->dispose();
1513 pDrawPage->InvalidateSwDoc();
1514 delete pxXDrawPage;
1515 pxXDrawPage = 0;
1518 if ( pxXNumberingRules )
1520 XIndexAccess* pNum = pxXNumberingRules->get();
1521 ((SwXNumberingRulesCollection*)pNum)->Invalidate();
1522 delete pxXNumberingRules;
1523 pxXNumberingRules = 0;
1526 if(pxXFootnotes)
1528 XIndexAccess* pFtn = pxXFootnotes->get();
1529 ((SwXFootnotes*)pFtn)->Invalidate();
1530 delete pxXFootnotes;
1531 pxXFootnotes = 0;
1534 if(pxXEndnotes)
1536 XIndexAccess* pFtn = pxXEndnotes->get();
1537 ((SwXFootnotes*)pFtn)->Invalidate();
1538 delete pxXEndnotes;
1539 pxXEndnotes = 0;
1542 if(pxXDocumentIndexes)
1544 XIndexAccess* pIdxs = pxXDocumentIndexes->get();
1545 ((SwXDocumentIndexes*)pIdxs)->Invalidate();
1546 delete pxXDocumentIndexes;
1547 pxXDocumentIndexes = 0;
1550 if(pxXStyleFamilies)
1552 XNameAccess* pStyles = pxXStyleFamilies->get();
1553 ((SwXStyleFamilies*)pStyles)->Invalidate();
1554 delete pxXStyleFamilies;
1555 pxXStyleFamilies = 0;
1557 if(pxXAutoStyles)
1559 XNameAccess* pStyles = pxXAutoStyles->get();
1560 ((SwXAutoStyles*)pStyles)->Invalidate();
1561 delete pxXAutoStyles;
1562 pxXAutoStyles = 0;
1565 if(pxXBookmarks)
1567 XNameAccess* pBm = pxXBookmarks->get();
1568 ((SwXBookmarks*)pBm)->Invalidate();
1569 delete pxXBookmarks;
1570 pxXBookmarks = 0;
1573 if(pxXChapterNumbering)
1575 XIndexReplace* pCh = pxXChapterNumbering->get();
1576 ((SwXChapterNumbering*)pCh)->Invalidate();
1577 delete pxXChapterNumbering;
1578 pxXChapterNumbering = 0;
1581 if(pxXFootnoteSettings)
1583 XPropertySet* pFntSet = pxXFootnoteSettings->get();
1584 ((SwXFootnoteProperties*)pFntSet)->Invalidate();
1585 delete pxXFootnoteSettings;
1586 pxXFootnoteSettings = 0;
1589 if(pxXEndnoteSettings)
1591 XPropertySet* pEndSet = pxXEndnoteSettings->get();
1592 ((SwXEndnoteProperties*)pEndSet)->Invalidate();
1593 delete pxXEndnoteSettings;
1594 pxXEndnoteSettings = 0;
1597 if(pxXLineNumberingProperties)
1599 XPropertySet* pLine = pxXLineNumberingProperties->get();
1600 ((SwXLineNumberingProperties*)pLine)->Invalidate();
1601 delete pxXLineNumberingProperties;
1602 pxXLineNumberingProperties = 0;
1604 if(pxXReferenceMarks)
1606 XNameAccess* pMarks = pxXReferenceMarks->get();
1607 ((SwXReferenceMarks*)pMarks)->Invalidate();
1608 delete pxXReferenceMarks;
1609 pxXReferenceMarks = 0;
1611 if(pxLinkTargetSupplier)
1613 XNameAccess* pAccess = (*pxLinkTargetSupplier).get();
1614 ((SwXLinkTargetSupplier*)pAccess)->Invalidate();
1615 delete pxLinkTargetSupplier;
1616 pxLinkTargetSupplier = 0;
1618 if(pxXRedlines)
1620 XEnumerationAccess* pMarks = pxXRedlines->get();
1621 ((SwXRedlines*)pMarks)->Invalidate();
1622 delete pxXRedlines;
1623 pxXRedlines = 0;
1625 if(xPropertyHelper.is())
1627 pPropertyHelper->Invalidate();
1628 xPropertyHelper = 0;
1629 pPropertyHelper = 0;
1633 #define COM_SUN_STAR__DRAWING_LENGTH 13
1634 Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName)
1635 throw( Exception, RuntimeException )
1637 SolarMutexGuard aGuard;
1638 if(!IsValid())
1639 throw RuntimeException();
1640 Reference< XInterface > xRet;
1641 sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
1642 if(nType != SW_SERVICE_INVALID)
1644 xRet = SwXServiceProvider::MakeInstance(nType, pDocShell->GetDoc());
1646 else
1648 if( rServiceName.startsWith("com.sun.star.") )
1650 sal_Int32 nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1651 OUString sCategory = rServiceName.getToken( 0, '.', nIndex );
1652 bool bShape = sCategory == "drawing";
1653 if( bShape || sCategory == "form")
1655 if(bShape)
1657 short nTable = 0;
1658 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.DashTable") ) )
1659 nTable = SW_CREATE_DASH_TABLE;
1660 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.GradientTable") ) )
1661 nTable = SW_CREATE_GRADIENT_TABLE;
1662 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.HatchTable") ) )
1663 nTable = SW_CREATE_HATCH_TABLE;
1664 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.BitmapTable") ) )
1665 nTable = SW_CREATE_BITMAP_TABLE;
1666 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.TransparencyGradientTable") ) )
1667 nTable = SW_CREATE_TRANSGRADIENT_TABLE;
1668 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.MarkerTable") ) )
1669 nTable = SW_CREATE_MARKER_TABLE;
1670 else if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.drawing.Defaults") ) )
1671 nTable = SW_CREATE_DRAW_DEFAULTS;
1672 if(nTable)
1674 xRet = GetPropertyHelper()->GetDrawTable(nTable);
1678 else if (sCategory == "document" )
1680 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.Settings") ) )
1681 xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1682 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.document.ImportEmbeddedObjectResolver") ) )
1684 xRet = (::cppu::OWeakObject * )new SvXMLEmbeddedObjectHelper( *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ );
1687 else if (sCategory == "text" )
1689 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.text.DocumentSettings") ) )
1690 xRet = Reference < XInterface > ( *new SwXDocumentSettings ( this ) );
1692 else if (sCategory == "chart2" )
1694 if( 0 == rServiceName.reverseCompareToAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.chart2.data.DataProvider") ) )
1695 xRet = Reference < XInterface > ( dynamic_cast< chart2::data::XDataProvider * >(pDocShell->getIDocumentChartDataProviderAccess()->GetChartDataProvider()) );
1698 if(!xRet.is())
1700 //! we don't want to insert OLE2 Shapes (e.g. "com.sun.star.drawing.OLE2Shape", ...)
1701 //! like this (by creating them with the documents factory and
1702 //! adding the shapes to the draw page).
1703 //! For inserting OLE objects the proper way is to use
1704 //! "com.sun.star.text.TextEmbeddedObject"!
1705 if (rServiceName.lastIndexOf( ".OLE2Shape" ) == rServiceName.getLength() - 10)
1706 throw ServiceNotRegisteredException(); // declare service to be not registered with this factory
1709 // the XML import is allowed to create instances of com.sun.star.drawing.OLE2Shape.
1710 // Thus, a temporary service name is introduced to make this possible.
1711 OUString aTmpServiceName( rServiceName );
1712 if ( bShape &&
1713 rServiceName.compareToAscii( "com.sun.star.drawing.temporaryForXMLImportOLE2Shape" ) == 0 )
1715 aTmpServiceName = OUString("com.sun.star.drawing.OLE2Shape");
1717 //here search for the draw service
1718 Reference< XInterface > xTmp = SvxFmMSFactory::createInstance(aTmpServiceName);
1719 if(bShape)
1721 nIndex = COM_SUN_STAR__DRAWING_LENGTH;
1722 if( 0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.GroupShape" ) ) ||
1723 0 == rServiceName.reverseCompareToAsciiL ( RTL_CONSTASCII_STRINGPARAM ( "com.sun.star.drawing.Shape3DSceneObject" ) ) )
1724 xRet = *new SwXGroupShape( xTmp );
1725 else
1726 xRet = *new SwXShape( xTmp );
1728 else
1729 xRet = xTmp;
1732 else
1733 throw ServiceNotRegisteredException();
1735 return xRet;
1738 Reference< XInterface > SwXTextDocument::createInstanceWithArguments(
1739 const OUString& ServiceSpecifier,
1740 const Sequence< Any >& /*Arguments*/)
1741 throw( Exception, RuntimeException )
1743 Reference< XInterface > xInt = createInstance(ServiceSpecifier);
1744 // The Any-Sequence is for initializing objects that are dependent
1745 // on parameters necessarily - so far we have not.
1746 return xInt;
1749 Sequence< OUString > SwXTextDocument::getAvailableServiceNames(void)
1750 throw( RuntimeException )
1752 static Sequence< OUString > aServices;
1753 if ( aServices.getLength() == 0 )
1755 Sequence< OUString > aRet = SvxFmMSFactory::getAvailableServiceNames();
1756 OUString* pRet = aRet.getArray();
1757 for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
1759 if ( pRet[i].compareToAscii( "com.sun.star.drawing.OLE2Shape" ) == 0 )
1761 pRet[i] = pRet[aRet.getLength() - 1];
1762 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
1763 break;
1766 Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
1767 aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
1770 return aServices;
1773 OUString SwXTextDocument::getImplementationName(void) throw( RuntimeException )
1775 return OUString("SwXTextDocument");
1778 sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException )
1780 if ( rServiceName == "com.sun.star.document.OfficeDocument" || rServiceName == "com.sun.star.text.GenericTextDocument" )
1781 return sal_True;
1783 bool bWebDoc = (0 != PTR_CAST(SwWebDocShell, pDocShell));
1784 bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1785 bool bTextDoc = (!bWebDoc && !bGlobalDoc);
1787 return ( (bWebDoc && rServiceName == "com.sun.star.text.WebDocument")
1788 || (bGlobalDoc && rServiceName == "com.sun.star.text.GlobalDocument")
1789 || (bTextDoc && rServiceName == "com.sun.star.text.TextDocument") );
1792 Sequence< OUString > SwXTextDocument::getSupportedServiceNames(void) throw( RuntimeException )
1794 bool bWebDoc = (0 != PTR_CAST(SwWebDocShell, pDocShell));
1795 bool bGlobalDoc = (0 != PTR_CAST(SwGlobalDocShell, pDocShell));
1796 bool bTextDoc = (!bWebDoc && !bGlobalDoc);
1798 Sequence< OUString > aRet (3);
1799 OUString* pArray = aRet.getArray();
1801 pArray[0] = OUString ( ( "com.sun.star.document.OfficeDocument" ) );
1802 pArray[1] = OUString ( ( "com.sun.star.text.GenericTextDocument" ) );
1804 if (bTextDoc)
1805 pArray[2] = OUString ( ( "com.sun.star.text.TextDocument" ) );
1806 else if (bWebDoc)
1807 pArray[2] = OUString ( ( "com.sun.star.text.WebDocument" ) );
1808 else if (bGlobalDoc)
1809 pArray[2] = OUString ( ( "com.sun.star.text.GlobalDocument" ) );
1811 return aRet;
1814 Reference< XIndexAccess > SwXTextDocument::getDocumentIndexes(void) throw( RuntimeException )
1816 SolarMutexGuard aGuard;
1817 if(!IsValid())
1818 throw RuntimeException();
1819 if(!pxXDocumentIndexes)
1821 ((SwXTextDocument*)this)->pxXDocumentIndexes = new Reference< XIndexAccess > ;
1822 *pxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
1824 return *pxXDocumentIndexes;
1827 Reference< XPropertySetInfo > SwXTextDocument::getPropertySetInfo(void) throw( RuntimeException )
1829 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
1830 return xRet;
1833 void SwXTextDocument::setPropertyValue(const OUString& rPropertyName,
1834 const Any& aValue)
1835 throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException,
1836 WrappedTargetException, RuntimeException)
1838 SolarMutexGuard aGuard;
1839 if(!IsValid())
1840 throw RuntimeException(
1841 "invalid SwXTextDocument",
1842 static_cast< cppu::OWeakObject * >(
1843 static_cast< SwXTextDocumentBaseClass * >(this)));
1844 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
1846 if(!pEntry)
1847 throw UnknownPropertyException();
1848 if(pEntry->nFlags & PropertyAttribute::READONLY)
1849 throw PropertyVetoException();
1850 switch(pEntry->nWID)
1852 case WID_DOC_CHAR_COUNT :
1853 case WID_DOC_PARA_COUNT :
1854 case WID_DOC_WORD_COUNT :
1855 throw RuntimeException(
1856 "bad WID",
1857 static_cast< cppu::OWeakObject * >(
1858 static_cast< SwXTextDocumentBaseClass * >(this)));
1859 case WID_DOC_WORD_SEPARATOR :
1861 OUString sDelim;
1862 aValue >>= sDelim;
1863 SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
1865 break;
1866 case WID_DOC_CHANGES_RECORD:
1867 case WID_DOC_CHANGES_SHOW:
1869 sal_Bool bSet = *(sal_Bool*)aValue.getValue();
1870 sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
1871 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
1873 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
1874 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
1875 if( bSet )
1876 eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
1878 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
1880 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
1882 pDocShell->GetDoc()->SetRedlineMode( (RedlineMode_t)(eMode ));
1884 break;
1885 case WID_DOC_CHANGES_PASSWORD:
1887 Sequence <sal_Int8> aNew;
1888 if(aValue >>= aNew)
1890 SwDoc* pDoc = pDocShell->GetDoc();
1891 pDoc->SetRedlinePassword(aNew);
1892 if(aNew.getLength())
1894 sal_uInt16 eMode = pDoc->GetRedlineMode();
1895 eMode = eMode|nsRedlineMode_t::REDLINE_ON;
1896 pDoc->SetRedlineMode( (RedlineMode_t)(eMode ));
1900 break;
1901 case WID_DOC_AUTO_MARK_URL :
1903 OUString sURL;
1904 aValue >>= sURL;
1905 pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
1907 break;
1908 case WID_DOC_HIDE_TIPS :
1909 SW_MOD()->GetModuleConfig()->SetHideFieldTips(*(sal_Bool*)aValue.getValue());
1910 break;
1911 case WID_DOC_REDLINE_DISPLAY:
1913 sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
1914 eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
1915 sal_Int16 nSet = 0;
1916 aValue >>= nSet;
1917 switch(nSet)
1919 case RedlineDisplayType::NONE: break;
1920 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
1921 case RedlineDisplayType::REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE; break;
1922 case RedlineDisplayType::
1923 INSERTED_AND_REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT|nsRedlineMode_t::REDLINE_SHOW_DELETE;
1924 break;
1925 default: throw IllegalArgumentException();
1927 pDocShell->GetDoc()->SetRedlineMode(eRedMode);
1929 break;
1930 case WID_DOC_TWO_DIGIT_YEAR:
1932 sal_Int16 nYear = 0;
1933 aValue >>= nYear;
1934 SfxRequest aRequest ( SID_ATTR_YEAR2000, SFX_CALLMODE_SLOT, pDocShell->GetDoc()->GetAttrPool());
1935 aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
1936 pDocShell->Execute ( aRequest );
1938 break;
1939 case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
1941 SwDrawDocument * pDrawDoc;
1942 sal_Bool bAuto = *(sal_Bool*) aValue.getValue();
1944 if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * >( pDocShell->GetDoc()->GetDrawModel() ) ) )
1945 pDrawDoc->SetAutoControlFocus( bAuto );
1946 else if (bAuto)
1948 // if setting to true, and we don't have an
1949 // SdrModel, then we are changing the default and
1950 // must thus create an SdrModel, if we don't have an
1951 // SdrModel and we are leaving the default at false,
1952 // we don't need to make an SdrModel and can do nothing
1953 // #i52858# - method name changed
1954 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
1955 pDrawDoc->SetAutoControlFocus ( bAuto );
1958 break;
1959 case WID_DOC_APPLY_FORM_DESIGN_MODE:
1961 SwDrawDocument * pDrawDoc;
1962 sal_Bool bMode = *(sal_Bool*)aValue.getValue();
1964 if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
1965 pDrawDoc->SetOpenInDesignMode( bMode );
1966 else if (!bMode)
1968 // if setting to false, and we don't have an
1969 // SdrModel, then we are changing the default and
1970 // must thus create an SdrModel, if we don't have an
1971 // SdrModel and we are leaving the default at true,
1972 // we don't need to make an SdrModel and can do
1973 // nothing
1974 // #i52858# - method name changed
1975 pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetOrCreateDrawModel() );
1976 pDrawDoc->SetOpenInDesignMode ( bMode );
1979 break;
1980 // #i42634# New property to set the bInReading
1981 // flag at the document, used during binary import
1982 case WID_DOC_LOCK_UPDATES :
1984 SwDoc* pDoc = pDocShell->GetDoc();
1985 bool bBool (false);
1986 if( aValue >>= bBool )
1987 pDoc->SetInReading( bBool );
1989 break;
1990 case WID_DOC_BUILDID:
1991 aValue >>= maBuildId;
1992 break;
1994 default:
1996 const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
1997 SfxPoolItem* pNewItem = rItem.Clone();
1998 pNewItem->PutValue(aValue, pEntry->nMemberId);
1999 pDocShell->GetDoc()->SetDefault(*pNewItem);
2000 delete pNewItem;
2005 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
2006 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2008 SolarMutexGuard aGuard;
2009 if(!IsValid())
2010 throw RuntimeException();
2011 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2013 if(!pEntry)
2014 throw UnknownPropertyException();
2015 Any aAny;
2016 switch(pEntry->nWID)
2018 case WID_DOC_ISTEMPLATEID :
2019 aAny <<= pDocShell->IsTemplate();
2020 break;
2021 case WID_DOC_CHAR_COUNT :
2022 case WID_DOC_PARA_COUNT :
2023 case WID_DOC_WORD_COUNT :
2025 const SwDocStat& rStat(pDocShell->GetDoc()->GetUpdatedDocStat());
2026 sal_Int32 nValue;
2027 switch(pEntry->nWID)
2029 case WID_DOC_CHAR_COUNT :nValue = rStat.nChar;break;
2030 case WID_DOC_PARA_COUNT :nValue = rStat.nPara;break;
2031 case WID_DOC_WORD_COUNT :nValue = rStat.nWord;break;
2033 aAny <<= nValue;
2035 break;
2036 case WID_DOC_WORD_SEPARATOR :
2038 aAny <<= OUString(SW_MOD()->GetDocStatWordDelim());
2040 break;
2041 case WID_DOC_CHANGES_RECORD:
2042 case WID_DOC_CHANGES_SHOW:
2044 sal_uInt16 eMode = pDocShell->GetDoc()->GetRedlineMode();
2045 sal_Bool bSet = sal_False;
2046 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2048 sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE;
2049 bSet = (eMode & nMask) == nMask;
2051 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2053 bSet = (eMode& nsRedlineMode_t::REDLINE_ON) != 0;
2055 aAny.setValue(&bSet, ::getBooleanCppuType());
2057 break;
2058 case WID_DOC_CHANGES_PASSWORD:
2060 SwDoc* pDoc = pDocShell->GetDoc();
2061 aAny <<= pDoc->GetRedlinePassword();
2063 break;
2064 case WID_DOC_AUTO_MARK_URL :
2065 aAny <<= OUString(pDocShell->GetDoc()->GetTOIAutoMarkURL());
2066 break;
2067 case WID_DOC_HIDE_TIPS :
2069 sal_Bool bTemp = SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2070 aAny.setValue(&bTemp, ::getBooleanCppuType());
2072 break;
2073 case WID_DOC_REDLINE_DISPLAY:
2075 sal_Int16 eRedMode = pDocShell->GetDoc()->GetRedlineMode();
2076 eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
2077 sal_Int16 nRet = RedlineDisplayType::NONE;
2078 if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
2079 nRet = RedlineDisplayType::INSERTED;
2080 else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
2081 nRet = RedlineDisplayType::REMOVED;
2082 else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
2083 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2084 aAny <<= nRet;
2086 break;
2087 case WID_DOC_FORBIDDEN_CHARS:
2089 GetPropertyHelper();
2090 Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
2091 aAny <<= xRet;
2093 break;
2094 case WID_DOC_TWO_DIGIT_YEAR:
2096 aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ( sal_True )->GetYear2000());
2098 break;
2099 case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2101 SwDrawDocument * pDrawDoc;
2102 sal_Bool bAuto;
2103 if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2104 bAuto = pDrawDoc->GetAutoControlFocus();
2105 else
2106 bAuto = sal_False;
2107 aAny.setValue(&bAuto, ::getBooleanCppuType());
2109 break;
2110 case WID_DOC_APPLY_FORM_DESIGN_MODE:
2112 SwDrawDocument * pDrawDoc;
2113 sal_Bool bMode;
2114 if ( 0 != ( pDrawDoc = dynamic_cast< SwDrawDocument * > (pDocShell->GetDoc()->GetDrawModel() ) ) )
2115 bMode = pDrawDoc->GetOpenInDesignMode();
2116 else
2117 bMode = sal_True;
2118 aAny.setValue(&bMode, ::getBooleanCppuType());
2120 break;
2121 case WID_DOC_BASIC_LIBRARIES:
2122 aAny <<= pDocShell->GetBasicContainer();
2123 break;
2124 case WID_DOC_DIALOG_LIBRARIES:
2125 aAny <<= pDocShell->GetDialogContainer();
2126 break;
2127 case WID_DOC_VBA_DOCOBJ:
2129 beans::PropertyValue aProp;
2130 aProp.Name = OUString("ThisWordDoc");
2131 aProp.Value <<= pDocShell->GetModel();
2132 aAny <<= aProp;
2134 break;
2135 case WID_DOC_RUNTIME_UID:
2136 aAny <<= getRuntimeUID();
2137 break;
2138 case WID_DOC_LOCK_UPDATES :
2139 aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
2140 break;
2141 case WID_DOC_BUILDID:
2142 aAny <<= maBuildId;
2143 break;
2144 case WID_DOC_HAS_VALID_SIGNATURES:
2145 aAny <<= hasValidSignatures();
2146 break;
2148 default:
2150 const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2151 rItem.QueryValue(aAny, pEntry->nMemberId);
2154 return aAny;
2157 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2158 const Reference< XPropertyChangeListener > & /*aListener*/)
2159 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2161 OSL_FAIL("not implemented");
2164 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2165 const Reference< XPropertyChangeListener > & /*aListener*/)
2166 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2168 OSL_FAIL("not implemented");
2171 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2172 const Reference< XVetoableChangeListener > & /*aListener*/)
2173 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2175 OSL_FAIL("not implemented");
2178 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2179 const Reference< XVetoableChangeListener > & /*aListener*/)
2180 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
2182 OSL_FAIL("not implemented");
2185 Reference< XNameAccess > SwXTextDocument::getLinks(void) throw( RuntimeException )
2187 if(!pxLinkTargetSupplier)
2189 pxLinkTargetSupplier = new Reference< XNameAccess > ;
2190 (*pxLinkTargetSupplier) = new SwXLinkTargetSupplier(*(SwXTextDocument*)this);
2192 return (*pxLinkTargetSupplier);
2195 Reference< XEnumerationAccess > SwXTextDocument::getRedlines( ) throw(RuntimeException)
2197 if(!pxXRedlines)
2199 pxXRedlines = new Reference< XEnumerationAccess > ;
2200 (*pxXRedlines) = new SwXRedlines(pDocShell->GetDoc());
2202 return *pxXRedlines;
2205 void SwXTextDocument::NotifyRefreshListeners()
2207 // why does SwBaseShell not just call refresh? maybe because it's rSh is
2208 // (sometimes) a different shell than GetWrtShell()?
2209 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
2210 m_pImpl->m_RefreshListeners.notifyEach(
2211 & util::XRefreshListener::refreshed, ev);
2214 void SwXTextDocument::refresh(void) throw( RuntimeException )
2216 SolarMutexGuard aGuard;
2217 if(!IsValid())
2218 throw RuntimeException();
2219 ViewShell *pViewShell = pDocShell->GetWrtShell();
2220 NotifyRefreshListeners();
2221 if(pViewShell)
2222 pViewShell->CalcLayout();
2225 void SAL_CALL SwXTextDocument::addRefreshListener(
2226 const Reference<util::XRefreshListener> & xListener)
2227 throw (RuntimeException)
2229 // no need to lock here as m_pImpl is const and container threadsafe
2230 m_pImpl->m_RefreshListeners.addInterface(xListener);
2233 void SAL_CALL SwXTextDocument::removeRefreshListener(
2234 const Reference<util::XRefreshListener> & xListener)
2235 throw (RuntimeException)
2237 // no need to lock here as m_pImpl is const and container threadsafe
2238 m_pImpl->m_RefreshListeners.removeInterface(xListener);
2241 void SwXTextDocument::updateLinks( ) throw(RuntimeException)
2243 SolarMutexGuard aGuard;
2244 if(!IsValid())
2245 throw RuntimeException();
2246 SwDoc* pDoc = pDocShell->GetDoc();
2247 sfx2::LinkManager& rLnkMan = pDoc->GetLinkManager();
2248 if( !rLnkMan.GetLinks().empty() )
2250 UnoActionContext aAction(pDoc);
2251 rLnkMan.UpdateAllLinks( false, false, true );
2255 //XPropertyState
2256 PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2257 throw (UnknownPropertyException, RuntimeException)
2259 SolarMutexGuard aGuard;
2260 PropertyState eRet = PropertyState_DIRECT_VALUE;
2261 if(!IsValid())
2262 throw RuntimeException();
2263 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2265 if(!pEntry)
2266 throw UnknownPropertyException();
2267 Any aAny;
2268 switch(pEntry->nWID)
2270 case 0:default:break;
2272 return eRet;
2275 Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2276 throw (UnknownPropertyException, RuntimeException)
2278 const sal_Int32 nCount = rPropertyNames.getLength();
2279 const OUString * pNames = rPropertyNames.getConstArray();
2280 Sequence < PropertyState > aRet ( nCount );
2281 PropertyState *pState = aRet.getArray();
2283 for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
2284 pState[nIndex] = getPropertyState( pNames[nIndex] );
2286 return aRet;
2289 void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2290 throw (UnknownPropertyException, RuntimeException)
2292 SolarMutexGuard aGuard;
2293 if(!IsValid())
2294 throw RuntimeException();
2295 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2296 if(!pEntry)
2297 throw UnknownPropertyException();
2298 switch(pEntry->nWID)
2300 case 0:default:break;
2304 Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2305 throw (UnknownPropertyException, WrappedTargetException, RuntimeException)
2307 SolarMutexGuard aGuard;
2308 if(!IsValid())
2309 throw RuntimeException();
2310 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2311 if(!pEntry)
2312 throw UnknownPropertyException();
2313 Any aAny;
2314 switch(pEntry->nWID)
2316 case 0:default:break;
2318 return aAny;
2321 static OutputDevice * lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions )
2323 OutputDevice *pOut = 0;
2325 uno::Any aAny( rPrintUIOptions.getValue( "RenderDevice" ));
2326 uno::Reference< awt::XDevice > xRenderDevice;
2327 aAny >>= xRenderDevice;
2328 if (xRenderDevice.is())
2330 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
2331 pOut = pDevice ? pDevice->GetOutputDevice() : 0;
2334 return pOut;
2337 static bool lcl_SeqHasProperty(
2338 const uno::Sequence< beans::PropertyValue >& rOptions,
2339 const sal_Char *pPropName )
2341 bool bRes = false;
2342 const sal_Int32 nLen = rOptions.getLength();
2343 const beans::PropertyValue *pProps = rOptions.getConstArray();
2344 for (sal_Int32 i = 0; i < nLen && !bRes; ++i)
2346 if (pProps[i].Name.equalsAscii( pPropName ))
2347 bRes = true;
2349 return bRes;
2352 SfxViewShell * SwXTextDocument::GetRenderView(
2353 bool &rbIsSwSrcView,
2354 const uno::Sequence< beans::PropertyValue >& rOptions,
2355 bool bIsPDFExport )
2357 // get view shell to use
2358 SfxViewShell *pView = 0;
2359 if (bIsPDFExport)
2360 pView = GuessViewShell( rbIsSwSrcView );
2361 else
2363 uno::Any aTmp;
2364 const sal_Int32 nLen = rOptions.getLength();
2365 const beans::PropertyValue *pProps = rOptions.getConstArray();
2366 for (sal_Int32 i = 0; i < nLen; ++i)
2368 if ( pProps[i].Name == "View" )
2370 aTmp = pProps[i].Value;
2371 break;
2375 uno::Reference< frame::XController > xController;
2376 if (aTmp >>= xController)
2378 OSL_ENSURE( xController.is(), "controller is empty!" );
2379 pView = GuessViewShell( rbIsSwSrcView, xController );
2382 return pView;
2386 * GetRenderDoc:
2387 * returns the document to be rendered, usually this will be the 'regular'
2388 * document but in case of PDF export of (multi-)selection it will
2389 * be a temporary document that gets created if not already done.
2390 * The rpView variable will be set (if not already done) to the used
2391 * SfxViewShell.
2393 SwDoc * SwXTextDocument::GetRenderDoc(
2394 SfxViewShell *&rpView,
2395 const uno::Any& rSelection,
2396 bool bIsPDFExport )
2398 SwDoc *pDoc = 0;
2400 uno::Reference< frame::XModel > xModel;
2401 rSelection >>= xModel;
2402 if (xModel == pDocShell->GetModel())
2403 pDoc = pDocShell->GetDoc();
2404 else
2406 OSL_ENSURE( !xModel.is(), "unexpected model found" );
2408 if (rSelection.hasValue()) // is anything selected ?
2410 // this part should only be called when a temporary document needs to be created,
2411 // for example for PDF export or printing of (multi-)selection only.
2413 bool bIsSwSrcView = false;
2414 if (!rpView)
2416 (void) bIsPDFExport;
2417 // aside from maybe PDF export the view should always have been provided!
2418 OSL_ENSURE( bIsPDFExport, "view is missing, guessing one..." );
2420 rpView = GuessViewShell( bIsSwSrcView );
2422 OSL_ENSURE( rpView, "ViewShell missing" );
2423 // the view shell should be SwView for documents PDF export.
2424 // for the page preview no selection should be possible
2425 // (the export dialog does not allow for this option)
2426 const TypeId aSwViewTypeId = TYPE(SwView);
2427 if (rpView && rpView->IsA(aSwViewTypeId))
2429 if (!m_pRenderData)
2431 OSL_FAIL("GetRenderDoc: no renderdata");
2432 return 0;
2434 SwView *const pSwView(static_cast<SwView *>(rpView));
2435 SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell());
2436 if (!xDocSh.Is())
2438 xDocSh = pSwView->CreateTmpSelectionDoc();
2439 m_pRenderData->SetTempDocShell(xDocSh);
2441 if (xDocSh.Is())
2443 pDoc = ((SwDocShell*)&xDocSh)->GetDoc();
2444 rpView = pDoc->GetDocShell()->GetView();
2447 else
2449 OSL_FAIL("unexpected ViewShell" );
2453 return pDoc;
2456 static void lcl_SavePrintUIOptionsToDocumentPrintData(
2457 SwDoc &rDoc,
2458 const SwPrintUIOptions &rPrintUIOptions,
2459 bool bIsPDFEXport )
2461 SwPrintData aDocPrintData( rDoc.getPrintData() );
2463 aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2464 aDocPrintData.SetPrintTable( rPrintUIOptions.IsPrintTables() );
2465 aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2466 aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2467 aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2468 aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2469 aDocPrintData.SetPrintReverse( rPrintUIOptions.IsPrintReverse() );
2470 aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2471 aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2472 aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2473 aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2474 aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2475 aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2476 aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2477 // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2478 // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2479 aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2480 aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2482 rDoc.setPrintData( aDocPrintData );
2485 sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
2486 const uno::Any& rSelection,
2487 const uno::Sequence< beans::PropertyValue >& rxOptions )
2488 throw (IllegalArgumentException, RuntimeException)
2490 SolarMutexGuard aGuard;
2491 if(!IsValid())
2493 throw DisposedException( OUString(),
2494 static_cast< XTextDocument* >(this) );
2497 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2498 bool bIsSwSrcView = false;
2499 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2501 if (!bIsSwSrcView && !m_pRenderData)
2502 m_pRenderData = new SwRenderData;
2503 if (!m_pPrintUIOptions)
2504 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2505 bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2507 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2508 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2509 if (!pDoc || !pView)
2510 return 0;
2512 // save current UI options from the print dialog for the next call to that dialog
2513 lcl_SavePrintUIOptionsToDocumentPrintData( *pDoc, *m_pPrintUIOptions, bIsPDFExport );
2515 sal_Int32 nRet = 0;
2516 if (bIsSwSrcView)
2518 SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2519 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2520 nRet = pSwSrcView->PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2522 else
2524 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2526 // TODO/mba: we really need a generic way to get the ViewShell!
2527 ViewShell* pViewShell = 0;
2528 SwView* pSwView = PTR_CAST(SwView, pView);
2529 if ( pSwView )
2531 pViewShell = pSwView->GetWrtShellPtr();
2533 else
2535 if ( bIsPDFExport && bFormat )
2537 //create a hidden view to be able to export as PDF also in print preview
2538 //pView and pSwView are not changed intentionally!
2539 m_pHiddenViewFrame = SfxViewFrame::LoadHiddenDocument( *pRenderDocShell, 2 );
2540 pViewShell = ((SwView*)m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2542 else
2543 pViewShell = ((SwPagePreView*)pView)->GetViewShell();
2546 if (!pViewShell || !pViewShell->GetLayout())
2547 return 0;
2549 if (bFormat)
2551 // #i38289
2552 if( pViewShell->GetViewOptions()->getBrowseMode() )
2554 SwViewOption aOpt( *pViewShell->GetViewOptions() );
2555 aOpt.setBrowseMode( false );
2556 pViewShell->ApplyViewOptions( aOpt );
2557 if (pSwView)
2559 pSwView->RecheckBrowseMode();
2563 // reformating the document for printing will show the changes in the view
2564 // which is likely to produce many unwanted and not nice to view actions.
2565 // We don't want that! Thus we disable updating of the view.
2566 pViewShell->StartAction();
2568 if (pSwView)
2570 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2571 m_pRenderData->ViewOptionAdjustStop();
2572 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2574 m_pRenderData->ViewOptionAdjustStart(
2575 *pViewShell, *pViewShell->GetViewOptions() );
2579 m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
2580 m_pPrintUIOptions, bIsPDFExport );
2582 if (pSwView)
2584 // PDF export should not make use of the SwPrtOptions
2585 const SwPrintData *pPrtOptions = (bIsPDFExport)
2586 ? NULL : m_pRenderData->GetSwPrtOptions();
2587 m_pRenderData->ViewOptionAdjust( pPrtOptions );
2590 // since printing now also use the API for PDF export this option
2591 // should be set for printing as well ...
2592 pViewShell->SetPDFExportOption( sal_True );
2593 bool bOrigStatus = pRenderDocShell->IsEnableSetModified();
2594 // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2595 bool bStateChanged = false;
2596 if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
2598 pRenderDocShell->EnableSetModified( sal_False );
2599 bStateChanged = true;
2602 // #122919# Force field update before PDF export
2603 pViewShell->ViewShell::UpdateFlds(sal_True);
2604 if( bStateChanged )
2605 pRenderDocShell->EnableSetModified( sal_True );
2607 // there is some redundancy between those two function calls, but right now
2608 // there is no time to sort this out.
2609 //TODO: check what exatly needs to be done and make just one function for that
2610 pViewShell->CalcLayout();
2611 pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2613 pViewShell->SetPDFExportOption( sal_False );
2615 // enable view again
2616 pViewShell->EndAction();
2619 const sal_Int32 nPageCount = pViewShell->GetPageCount();
2622 // get number of pages to be rendered
2624 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2625 if (bPrintProspect)
2627 pDoc->CalculatePagePairsForProspectPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, nPageCount );
2628 nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2630 else
2632 const sal_Int16 nPostItMode = (sal_Int16) m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 );
2633 if (nPostItMode != POSTITS_NONE)
2635 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2636 m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
2639 // get set of valid document pages (according to the current settings)
2640 // and their start frames
2641 pDoc->CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2643 if (nPostItMode != POSTITS_NONE)
2645 pDoc->UpdatePagesForPrintingWithPostItData( *m_pRenderData,
2646 *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2649 nRet = m_pRenderData->GetPagesToPrint().size();
2652 OSL_ENSURE( nRet >= 0, "negative number of pages???" );
2654 return nRet;
2657 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2658 sal_Int32 nRenderer,
2659 const uno::Any& rSelection,
2660 const uno::Sequence< beans::PropertyValue >& rxOptions )
2661 throw (IllegalArgumentException, RuntimeException)
2663 SolarMutexGuard aGuard;
2664 if(!IsValid())
2666 throw DisposedException( OUString(),
2667 static_cast< XTextDocument* >(this) );
2670 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2671 bool bIsSwSrcView = false;
2672 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2674 // m_pRenderData should NOT be created here!
2675 // That should only be done in getRendererCount. If this function is called before
2676 // getRendererCount was called then the caller will probably just retrieve the extra UI options
2677 // and is not interested in getting valid information about the other data that would
2678 // otherwise be provided here!
2679 // if( ! m_pRenderData )
2680 // m_pRenderData = new SwRenderData;
2681 if (!m_pPrintUIOptions)
2682 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2683 m_pPrintUIOptions->processProperties( rxOptions );
2684 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2685 const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2686 const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup", false );
2688 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2689 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2690 if (!pDoc || !pView)
2691 return uno::Sequence< beans::PropertyValue >();
2693 // due to #110067# (document page count changes sometimes during
2694 // PDF export/printing) we can not check for the upper bound properly.
2695 // Thus instead of throwing the exception we silently return.
2696 if (0 > nRenderer)
2697 throw IllegalArgumentException();
2699 // TODO/mba: we really need a generic way to get the ViewShell!
2700 ViewShell* pVwSh = 0;
2701 SwView* pSwView = PTR_CAST(SwView, pView);
2702 if ( pSwView )
2703 pVwSh = pSwView->GetWrtShellPtr();
2704 else
2705 pVwSh = ((SwPagePreView*)pView)->GetViewShell();
2707 sal_Int32 nMaxRenderer = 0;
2708 if (!bIsSwSrcView && m_pRenderData)
2710 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2711 nMaxRenderer = bPrintProspect?
2712 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2713 m_pRenderData->GetPagesToPrint().size() - 1;
2715 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2716 // we obmit checking of the upper bound in this case.
2717 if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2718 return uno::Sequence< beans::PropertyValue >();
2720 uno::Sequence< beans::PropertyValue > aRenderer;
2721 if (m_pRenderData)
2723 // #i114210#
2724 // determine the correct page number from the renderer index
2725 // #i114875
2726 // consider brochure print
2727 const sal_uInt16 nPage = bPrintProspect
2728 ? nRenderer + 1
2729 : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2731 // get paper tray to use ...
2732 sal_Int32 nPrinterPaperTray = -1;
2733 if (! bPrintPaperFromSetup)
2735 // ... from individual page style (see the page tab in Format/Page dialog)
2736 const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2737 std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2738 if (aIt != rPaperTrays.end())
2739 nPrinterPaperTray = aIt->second;
2742 awt::Size aPageSize;
2743 awt::Size aPreferredPageSize;
2744 Size aTmpSize;
2745 if (bIsSwSrcView || bPrintProspect)
2747 // for printing of HTML source code and prospect printing we should use
2748 // the printers paper size since
2749 // a) HTML source view has no page size
2750 // b) prospect printing has a different page size from the documents page
2751 // since two document pages will get rendered on one printer page
2753 // since PageIncludesNonprintableArea will be set to true we can return the
2754 // printers paper size here.
2755 // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2756 // case we won't get an OutputDevice here, but then the caller also has no need
2757 // for the correct PageSisze right now...
2758 Printer *pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ));
2759 if (pPrinter)
2761 // HTML source view and prospect adapt to the printer's paper size
2762 aTmpSize = pPrinter->GetPaperSize();
2763 aTmpSize = pPrinter->LogicToLogic( aTmpSize,
2764 pPrinter->GetMapMode(), MapMode( MAP_100TH_MM ));
2765 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2766 #if 0
2767 // #i115048# it seems users didn't like getting double the formatted page size
2768 // revert to "old" behavior scaling to the current paper size of the printer
2769 if (bPrintProspect)
2771 // we just state what output size we would need
2772 // which may cause vcl to set that page size on the printer
2773 // (if available and not overriden by the user)
2774 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2775 aPreferredPageSize = awt::Size ( TWIP_TO_MM100( 2 * aTmpSize.Width() ),
2776 TWIP_TO_MM100( aTmpSize.Height() ));
2778 #else
2779 if( bPrintProspect )
2781 // just switch to an appropriate portrait/landscape format
2782 // FIXME: brochure printing with landscape pages puts the
2783 // pages next to each other, so landscape is currently always
2784 // the better choice
2785 if( aPageSize.Width < aPageSize.Height )
2787 aPreferredPageSize.Width = aPageSize.Height;
2788 aPreferredPageSize.Height = aPageSize.Width;
2791 #endif
2794 else
2796 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2797 aPageSize = awt::Size ( TWIP_TO_MM100( aTmpSize.Width() ),
2798 TWIP_TO_MM100( aTmpSize.Height() ));
2801 sal_Int32 nLen = 2;
2802 aRenderer.realloc(2);
2803 aRenderer[0].Name = OUString( "PageSize" );
2804 aRenderer[0].Value <<= aPageSize;
2805 aRenderer[1].Name = OUString( "PageIncludesNonprintableArea" );
2806 aRenderer[1].Value <<= sal_True;
2807 if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2809 ++nLen;
2810 aRenderer.realloc( nLen );
2811 aRenderer[ nLen - 1 ].Name = OUString( "PreferredPageSize" );
2812 aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2814 if (nPrinterPaperTray >= 0)
2816 ++nLen;
2817 aRenderer.realloc( nLen );
2818 aRenderer[ nLen - 1 ].Name = OUString( "PrinterPaperTray" );
2819 aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2823 // #i117783#
2824 if ( bApplyPagePrintSettingsFromXPagePrintable )
2826 const SwPagePreViewPrtData* pPagePrintSettings =
2827 pDocShell->GetDoc()->GetPreViewPrtData();
2828 if ( pPagePrintSettings &&
2829 ( pPagePrintSettings->GetRow() > 1 ||
2830 pPagePrintSettings->GetCol() > 1 ) )
2832 // extend render data by page print settings attributes
2833 sal_Int32 nLen = aRenderer.getLength();
2834 const sal_Int32 nRenderDataIdxStart = nLen;
2835 nLen += 9;
2836 aRenderer.realloc( nLen );
2837 // put page print settings attribute into render data
2838 const sal_Int32 nRow = pPagePrintSettings->GetRow();
2839 aRenderer[ nRenderDataIdxStart + 0 ].Name = OUString( "NUpRows" );
2840 aRenderer[ nRenderDataIdxStart + 0 ].Value <<= ( nRow > 1 ? nRow : 1 );
2841 const sal_Int32 nCol = pPagePrintSettings->GetCol();
2842 aRenderer[ nRenderDataIdxStart + 1 ].Name = OUString( "NUpColumns" );
2843 aRenderer[ nRenderDataIdxStart + 1 ].Value <<= ( nCol > 1 ? nCol : 1 );
2844 aRenderer[ nRenderDataIdxStart + 2 ].Name = OUString( "NUpPageMarginLeft" );
2845 aRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
2846 aRenderer[ nRenderDataIdxStart + 3 ].Name = OUString( "NUpPageMarginRight" );
2847 aRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
2848 aRenderer[ nRenderDataIdxStart + 4 ].Name = OUString( "NUpPageMarginTop" );
2849 aRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
2850 aRenderer[ nRenderDataIdxStart + 5 ].Name = OUString( "NUpPageMarginBottom" );
2851 aRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
2852 aRenderer[ nRenderDataIdxStart + 6 ].Name = OUString( "NUpHorizontalSpacing" );
2853 aRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
2854 aRenderer[ nRenderDataIdxStart + 7 ].Name = OUString( "NUpVerticalSpacing" );
2855 aRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
2857 Printer* pPrinter = pDocShell->GetDoc()->getPrinter( false );
2858 if ( pPrinter )
2860 awt::Size aNewPageSize;
2861 const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
2862 aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
2863 if ( ( pPagePrintSettings->GetLandscape() &&
2864 aPageSize.Width() < aPageSize.Height() ) ||
2865 ( !pPagePrintSettings->GetLandscape() &&
2866 aPageSize.Width() > aPageSize.Height() ) )
2868 aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
2870 aRenderer[ nRenderDataIdxStart + 8 ].Name = OUString( "NUpPaperSize" );
2871 aRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
2876 bApplyPagePrintSettingsFromXPagePrintable = sal_False;
2879 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2881 return aRenderer;
2884 SfxViewShell * SwXTextDocument::GuessViewShell(
2885 /* out */ bool &rbIsSwSrcView,
2886 const uno::Reference< css::frame::XController > xController )
2888 // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2889 // must not be used (see comment from MBA)
2891 SfxViewShell *pView = 0;
2892 SwView *pSwView = 0;
2893 SwPagePreView *pSwPagePreView = 0;
2894 SwSrcView *pSwSrcView = 0;
2895 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, sal_False );
2897 // look for the view shell with the same controller in use,
2898 // otherwise look for a suitable view, preferably a SwView,
2899 // if that one is not found use a SwPagePreView if found.
2900 while (pFrame)
2902 pView = pFrame->GetViewShell();
2903 pSwView = dynamic_cast< SwView * >(pView);
2904 pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2905 if (!pSwPagePreView)
2906 pSwPagePreView = dynamic_cast< SwPagePreView * >(pView);
2907 if (xController.is())
2909 if (pView && pView->GetController() == xController)
2910 break;
2912 else if (pSwView || pSwSrcView)
2913 break;
2914 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, sal_False );
2917 OSL_ENSURE( pSwView || pSwPagePreView || pSwSrcView, "failed to get view shell" );
2918 if (pView)
2919 rbIsSwSrcView = pSwSrcView != 0;
2920 return pView;
2923 void SAL_CALL SwXTextDocument::render(
2924 sal_Int32 nRenderer,
2925 const uno::Any& rSelection,
2926 const uno::Sequence< beans::PropertyValue >& rxOptions )
2927 throw (IllegalArgumentException, RuntimeException)
2929 SolarMutexGuard aGuard;
2930 if(!IsValid())
2932 throw DisposedException( OUString(),
2933 static_cast< XTextDocument* >(this) );
2936 // due to #110067# (document page count changes sometimes during
2937 // PDF export/printing) we can not check for the upper bound properly.
2938 // Thus instead of throwing the exception we silently return.
2939 if (0 > nRenderer)
2940 throw IllegalArgumentException();
2942 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2943 bool bIsSwSrcView = false;
2944 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2946 OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
2947 OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
2948 if (!bIsSwSrcView && !m_pRenderData)
2949 m_pRenderData = new SwRenderData;
2950 if (!m_pPrintUIOptions)
2951 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2952 m_pPrintUIOptions->processProperties( rxOptions );
2953 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect", false );
2954 const bool bLastPage = m_pPrintUIOptions->getBoolValue( "IsLastPage", sal_False );
2956 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2957 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2958 if (pDoc && pView)
2960 sal_Int32 nMaxRenderer = 0;
2961 if (!bIsSwSrcView)
2963 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2964 nMaxRenderer = bPrintProspect?
2965 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2966 m_pRenderData->GetPagesToPrint().size() - 1;
2968 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2969 // we obmit checking of the upper bound in this case.
2970 if (bIsSwSrcView || nRenderer <= nMaxRenderer)
2972 if (bIsSwSrcView)
2974 SwSrcView *pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2975 OutputDevice *pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2976 pSwSrcView->PrintSource( pOutDev, nRenderer + 1, false );
2978 else
2980 // the view shell should be SwView for documents PDF export
2981 // or SwPagePreView for PDF export of the page preview
2982 //!! (check for SwView first as in GuessViewShell) !!
2983 OSL_ENSURE( pView, "!! view missing !!" );
2984 const TypeId aSwViewTypeId = TYPE(SwView);
2985 ViewShell* pVwSh = 0;
2986 if (pView)
2988 // TODO/mba: we really need a generic way to get the ViewShell!
2989 SwView* pSwView = PTR_CAST(SwView, pView);
2990 if ( pSwView )
2991 pVwSh = pSwView->GetWrtShellPtr();
2992 else
2993 pVwSh = ((SwPagePreView*)pView)->GetViewShell();
2996 // get output device to use
2997 OutputDevice * pOut = lcl_GetOutputDevice( *m_pPrintUIOptions );
2999 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
3001 const OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange", OUString() );
3002 const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage", sal_False );
3003 bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
3005 OSL_ENSURE(( pView->IsA(aSwViewTypeId) && m_pRenderData->IsViewOptionAdjust())
3006 || (!pView->IsA(aSwViewTypeId) && !m_pRenderData->IsViewOptionAdjust()),
3007 "SwView / SwViewOptionAdjust_Impl availability mismatch" );
3009 // since printing now also use the API for PDF export this option
3010 // should be set for printing as well ...
3011 pVwSh->SetPDFExportOption( sal_True );
3013 // #i12836# enhanced pdf export
3015 // First, we have to export hyperlinks, notes, and outline to pdf.
3016 // During this process, additional information required for tagging
3017 // the pdf file are collected, which are evaulated during painting.
3019 SwWrtShell* pWrtShell = pView->IsA(aSwViewTypeId) ?
3020 ((SwView*)pView)->GetWrtShellPtr() :
3023 if (bIsPDFExport && bFirstPage && pWrtShell)
3025 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_False );
3028 SwPrintData const& rSwPrtOptions =
3029 *m_pRenderData->GetSwPrtOptions();
3030 if (bPrintProspect)
3031 pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
3032 else // normal printing and PDF export
3033 pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer );
3035 // #i35176#
3037 // After printing the last page, we take care for the links coming
3038 // from the EditEngine. The links are generated during the painting
3039 // process, but the destinations are still missing.
3041 if (bIsPDFExport && bLastPage && pWrtShell)
3043 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, sal_True );
3046 pVwSh->SetPDFExportOption( sal_False );
3048 // last page to be rendered? (not necessarily the last page of the document)
3049 // -> do clean-up of data
3050 if (bLastPage)
3052 // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3053 // of the shell, which might get destroyed in lcl_DisposeView!
3054 if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
3055 m_pRenderData->ViewOptionAdjustStop();
3057 if (m_pRenderData && m_pRenderData->HasPostItData())
3058 m_pRenderData->DeletePostItData();
3059 if (m_pHiddenViewFrame)
3061 lcl_DisposeView( m_pHiddenViewFrame, pDocShell );
3062 m_pHiddenViewFrame = 0;
3064 // prevent crash described in #i108805
3065 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3066 SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3067 pSet->Put( SfxBoolItem( SID_HIDDEN, sal_False ) );
3075 if( bLastPage )
3077 delete m_pRenderData; m_pRenderData = NULL;
3078 delete m_pPrintUIOptions; m_pPrintUIOptions = NULL;
3082 // xforms::XFormsSupplier
3083 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3084 throw( RuntimeException )
3086 SolarMutexGuard aGuard;
3087 if ( !pDocShell )
3088 throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
3089 SwDoc* pDoc = pDocShell->GetDoc();
3090 return pDoc->getXForms();
3093 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3094 throw ( uno::RuntimeException )
3096 SolarMutexGuard aGuard;
3097 if (!IsValid())
3099 throw DisposedException("SwXTextDocument not valid",
3100 static_cast<XTextDocument*>(this));
3103 return SwUnoCursorHelper::CreateFlatParagraphIterator(
3104 *pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
3107 uno::Reference< util::XCloneable > SwXTextDocument::createClone( ) throw (uno::RuntimeException)
3109 SolarMutexGuard aGuard;
3110 if(!IsValid())
3111 throw RuntimeException();
3113 // create a new document - hidden - copy the storage and return it
3114 // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3115 // and thus SfxObjectShellLock is not allowed here
3116 // the model holds reference to the shell, so the shell will not destructed at the end of method
3117 SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false);
3118 uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3119 uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3120 uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3121 storeToStorage( xNewStorage, aTempMediaDescriptor );
3122 uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3123 xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3124 return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3127 void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
3129 return SwXTextDocumentBaseClass::operator new(t);
3132 void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
3134 SwXTextDocumentBaseClass::operator delete(p);
3138 * retrieve languages already used in current document
3140 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3141 ::sal_Int16 nScriptTypes,
3142 ::sal_Int16 nMaxCount )
3143 throw (lang::IllegalArgumentException, uno::RuntimeException)
3145 SolarMutexGuard aGuard;
3148 // possible canonical values for nScriptTypes
3149 // any bit wise combination is allowed
3150 const sal_Int16 nLatin = 0x001;
3151 const sal_Int16 nAsian = 0x002;
3152 const sal_Int16 nComplex = 0x004;
3154 // script types for which to get the languages
3155 const bool bLatin = 0 != (nScriptTypes & nLatin);
3156 const bool bAsian = 0 != (nScriptTypes & nAsian);
3157 const bool bComplex = 0 != (nScriptTypes & nComplex);
3159 if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3160 throw IllegalArgumentException(OUString("nScriptTypes ranges from 1 to 7!"), Reference< XInterface >(), 1);
3161 if (!pDocShell)
3162 throw DisposedException();
3163 SwDoc* pDoc = pDocShell->GetDoc();
3165 // avoid duplicate values
3166 std::set< LanguageType > aAllLangs;
3168 //USER STYLES
3170 const SwCharFmts *pFmts = pDoc->GetCharFmts();
3171 for(sal_uInt16 i = 0; i < pFmts->size(); ++i)
3173 const SwAttrSet &rAttrSet = (*pFmts)[i]->GetAttrSet();
3174 LanguageType nLang = LANGUAGE_DONTKNOW;
3175 if (bLatin)
3177 nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3178 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3179 aAllLangs.insert( nLang );
3181 if (bAsian)
3183 nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3184 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3185 aAllLangs.insert( nLang );
3187 if (bComplex)
3189 nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3190 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3191 aAllLangs.insert( nLang );
3195 const SwTxtFmtColls *pColls = pDoc->GetTxtFmtColls();
3196 for (sal_uInt16 i = 0; i < pColls->size(); ++i)
3198 const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3199 LanguageType nLang = LANGUAGE_DONTKNOW;
3200 if (bLatin)
3202 nLang = rAttrSet.GetLanguage( sal_False ).GetLanguage();
3203 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3204 aAllLangs.insert( nLang );
3206 if (bAsian)
3208 nLang = rAttrSet.GetCJKLanguage( sal_False ).GetLanguage();
3209 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3210 aAllLangs.insert( nLang );
3212 if (bComplex)
3214 nLang = rAttrSet.GetCTLLanguage( sal_False ).GetLanguage();
3215 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3216 aAllLangs.insert( nLang );
3220 //AUTO STYLES
3221 const IStyleAccess::SwAutoStyleFamily aFam[2] =
3223 IStyleAccess::AUTO_STYLE_CHAR,
3224 IStyleAccess::AUTO_STYLE_PARA
3226 for (sal_uInt16 i = 0; i < 2; ++i)
3228 std::vector< SfxItemSet_Pointer_t > rStyles;
3229 pDoc->GetIStyleAccess().getAllStyles(rStyles, aFam[i]);
3230 while (!rStyles.empty())
3232 SfxItemSet_Pointer_t pStyle = rStyles.back();
3233 rStyles.pop_back();
3234 const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
3236 LanguageType nLang = LANGUAGE_DONTKNOW;
3237 if (bLatin)
3239 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, sal_False )).GetLanguage();
3240 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3241 aAllLangs.insert( nLang );
3243 if (bAsian)
3245 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, sal_False )).GetLanguage();
3246 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3247 aAllLangs.insert( nLang );
3249 if (bComplex)
3251 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, sal_False )).GetLanguage();
3252 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3253 aAllLangs.insert( nLang );
3258 //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3259 SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
3260 SdrView *pSdrView = pWrtSh->GetDrawView();
3262 if( pSdrView )
3264 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3265 if(pOutliner)
3267 EditEngine& rEditEng = (EditEngine&)pOutliner->GetEditEngine();
3268 sal_Int32 nParCount = pOutliner->GetParagraphCount();
3269 for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
3271 //every paragraph
3272 std::vector<sal_uInt16> aPortions;
3273 rEditEng.GetPortions( nPar, aPortions );
3275 for ( size_t nPos = aPortions.size(); nPos; )
3277 //every position
3278 --nPos;
3279 sal_uInt16 nEnd = aPortions[ nPos ];
3280 sal_uInt16 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
3281 ESelection aSelection( nPar, nStart, nPar, nEnd );
3282 SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3284 LanguageType nLang = LANGUAGE_DONTKNOW;
3285 if (bLatin)
3287 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, sal_False )).GetLanguage();
3288 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3289 aAllLangs.insert( nLang );
3291 if (bAsian)
3293 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, sal_False )).GetLanguage();
3294 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3295 aAllLangs.insert( nLang );
3297 if (bComplex)
3299 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, sal_False )).GetLanguage();
3300 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3301 aAllLangs.insert( nLang );
3307 // less than nMaxCount languages
3308 if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3309 nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3311 // build return value
3312 uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3313 lang::Locale* pLanguage = aLanguages.getArray();
3314 if (nMaxCount > 0)
3316 sal_Int32 nCount = 0;
3317 const SvtLanguageTable aLangTab;
3318 for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
3320 if (nCount >= nMaxCount)
3321 break;
3322 if (LANGUAGE_NONE != *it)
3324 pLanguage[nCount] = LanguageTag( *it ).getLocale();
3325 pLanguage[nCount].Language = aLangTab.GetString( *it );
3326 nCount += 1;
3331 return aLanguages;
3334 SwXLinkTargetSupplier::SwXLinkTargetSupplier(SwXTextDocument& rxDoc) :
3335 pxDoc(&rxDoc)
3337 sTables = String(SW_RES(STR_CONTENT_TYPE_TABLE));
3338 sFrames = String(SW_RES(STR_CONTENT_TYPE_FRAME));
3339 sGraphics = String(SW_RES(STR_CONTENT_TYPE_GRAPHIC));
3340 sOLEs = String(SW_RES(STR_CONTENT_TYPE_OLE));
3341 sSections = String(SW_RES(STR_CONTENT_TYPE_REGION));
3342 sOutlines = String(SW_RES(STR_CONTENT_TYPE_OUTLINE));
3343 sBookmarks = String(SW_RES(STR_CONTENT_TYPE_BOOKMARK));
3346 SwXLinkTargetSupplier::~SwXLinkTargetSupplier()
3350 Any SwXLinkTargetSupplier::getByName(const OUString& rName)
3351 throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3353 Any aRet;
3354 if(!pxDoc)
3355 throw RuntimeException();
3356 String sToCompare(rName);
3357 String sSuffix = OUString('|');
3358 if(sToCompare == sTables)
3360 sSuffix += OUString::createFromAscii(pMarkToTable);
3362 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3363 pxDoc->getTextTables(), sToCompare, sSuffix );
3364 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3365 aRet.setValue(&xRet, ::getCppuType((Reference<XPropertySet>*)0));
3367 else if(sToCompare == sFrames)
3369 sSuffix += OUString::createFromAscii(pMarkToFrame);
3370 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3371 pxDoc->getTextFrames(), sToCompare, sSuffix );
3372 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3373 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3375 else if(sToCompare == sSections)
3377 sSuffix += OUString::createFromAscii(pMarkToRegion);
3378 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3379 pxDoc->getTextSections(), sToCompare, sSuffix );
3380 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3381 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3383 else if(sToCompare == sGraphics)
3385 sSuffix += OUString::createFromAscii(pMarkToGraphic);
3386 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3387 pxDoc->getGraphicObjects(), sToCompare, sSuffix );
3388 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3389 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3391 else if(sToCompare == sOLEs)
3393 sSuffix += OUString::createFromAscii(pMarkToOLE);
3394 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3395 pxDoc->getEmbeddedObjects(), sToCompare, sSuffix );
3396 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3397 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3399 else if(sToCompare == sOutlines)
3401 sSuffix += OUString::createFromAscii(pMarkToOutline);
3402 Reference< XNameAccess > xTbls = new SwXLinkNameAccessWrapper(
3403 *pxDoc, sToCompare, sSuffix );
3404 Reference< XPropertySet > xRet(xTbls, UNO_QUERY);
3405 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3407 else if(sToCompare == sBookmarks)
3409 sSuffix.Erase();
3410 Reference< XNameAccess > xBkms = new SwXLinkNameAccessWrapper(
3411 pxDoc->getBookmarks(), sToCompare, sSuffix );
3412 Reference< XPropertySet > xRet(xBkms, UNO_QUERY);
3413 aRet.setValue(&xRet, ::getCppuType((Reference< XPropertySet>*)0));
3415 else
3416 throw NoSuchElementException();
3417 return aRet;
3420 Sequence< OUString > SwXLinkTargetSupplier::getElementNames(void)
3421 throw( RuntimeException )
3423 Sequence< OUString > aRet(7);
3424 OUString* pNames = aRet.getArray();
3425 pNames[0] = sTables;
3426 pNames[1] = sFrames ;
3427 pNames[2] = sGraphics;
3428 pNames[3] = sOLEs ;
3429 pNames[4] = sSections;
3430 pNames[5] = sOutlines;
3431 pNames[6] = sBookmarks;
3432 return aRet;
3435 sal_Bool SwXLinkTargetSupplier::hasByName(const OUString& rName)
3436 throw( RuntimeException )
3438 String sToCompare(rName);
3439 if( sToCompare == sTables ||
3440 sToCompare == sFrames ||
3441 sToCompare == sGraphics||
3442 sToCompare == sOLEs ||
3443 sToCompare == sSections ||
3444 sToCompare == sOutlines ||
3445 sToCompare == sBookmarks )
3446 return sal_True;
3447 return sal_False;
3450 uno::Type SwXLinkTargetSupplier::getElementType(void)
3451 throw( RuntimeException )
3453 return ::getCppuType((Reference< XPropertySet>*)0);
3457 sal_Bool SwXLinkTargetSupplier::hasElements(void) throw( RuntimeException )
3459 return 0 != pxDoc;
3462 OUString SwXLinkTargetSupplier::getImplementationName(void) throw( RuntimeException )
3464 return OUString("SwXLinkTargetSupplier");
3467 sal_Bool SwXLinkTargetSupplier::supportsService(const OUString& rServiceName)
3468 throw( RuntimeException )
3470 return (rServiceName == "com.sun.star.document.LinkTargets");
3473 Sequence< OUString > SwXLinkTargetSupplier::getSupportedServiceNames(void)
3474 throw( RuntimeException )
3476 Sequence< OUString > aRet(1);
3477 OUString* pNames = aRet.getArray();
3478 pNames[0] = "com.sun.star.document.LinkTargets";
3479 return aRet;
3482 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(
3483 Reference< XNameAccess > xAccess, const String& rLinkDisplayName, String sSuffix ) :
3484 xRealAccess(xAccess),
3485 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3486 sLinkSuffix(sSuffix),
3487 sLinkDisplayName(rLinkDisplayName),
3488 pxDoc(0)
3492 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(SwXTextDocument& rxDoc,
3493 const String& rLinkDisplayName, String sSuffix) :
3494 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3495 sLinkSuffix(sSuffix),
3496 sLinkDisplayName(rLinkDisplayName),
3497 xDoc(&rxDoc),
3498 pxDoc(&rxDoc)
3502 SwXLinkNameAccessWrapper::~SwXLinkNameAccessWrapper()
3506 Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
3507 throw( NoSuchElementException, WrappedTargetException, RuntimeException )
3509 Any aRet;
3510 bool bFound = false;
3511 //cut link extension and call the real NameAccess
3512 String sParam = rName;
3513 String sSuffix(sLinkSuffix);
3514 if(sParam.Len() > sSuffix.Len() )
3516 String sCmp = sParam.Copy(sParam.Len() - sSuffix.Len(),
3517 sSuffix.Len());
3518 if(sCmp == sSuffix)
3520 if(pxDoc)
3522 sParam = sParam.Copy(0, sParam.Len() - sSuffix.Len());
3523 if(!pxDoc->GetDocShell())
3524 throw RuntimeException();
3525 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3526 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
3528 for (sal_uInt16 i = 0; i < nOutlineCount && !bFound; ++i)
3530 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3531 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3532 if(sParam ==
3533 lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3535 Reference< XPropertySet > xOutline = new SwXOutlineTarget(sParam);
3536 aRet.setValue(&xOutline, ::getCppuType((Reference<XPropertySet>*)0));
3537 bFound = true;
3541 else
3543 aRet = xRealAccess->getByName(sParam.Copy(0, sParam.Len() - sSuffix.Len()));
3544 Reference< XInterface > xInt;
3545 if(!(aRet >>= xInt))
3546 throw RuntimeException();
3547 Reference< XPropertySet > xProp(xInt, UNO_QUERY);
3548 aRet <<= xProp;
3549 bFound = true;
3553 if(!bFound)
3554 throw NoSuchElementException();
3555 return aRet;
3558 Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames(void)
3559 throw( RuntimeException )
3561 Sequence< OUString > aRet;
3562 if(pxDoc)
3564 if(!pxDoc->GetDocShell())
3565 throw RuntimeException();
3567 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3568 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3569 sal_uInt16 nOutlineCount = rOutlineNodes.size();
3570 aRet.realloc(nOutlineCount);
3571 OUString* pResArr = aRet.getArray();
3572 String sSuffix = OUString('|');
3573 sSuffix += OUString::createFromAscii(pMarkToOutline);
3574 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3575 for (sal_uInt16 i = 0; i < nOutlineCount; ++i)
3577 String sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule);
3578 sEntry += sSuffix;
3579 pResArr[i] = sEntry;
3582 else
3584 Sequence< OUString > aOrg = xRealAccess->getElementNames();
3585 const OUString* pOrgArr = aOrg.getConstArray();
3586 aRet.realloc(aOrg.getLength());
3587 OUString* pResArr = aRet.getArray();
3588 for(long i = 0; i < aOrg.getLength(); i++)
3590 pResArr[i] = pOrgArr[i] + sLinkSuffix;
3593 return aRet;
3596 sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
3597 throw( RuntimeException )
3599 sal_Bool bRet = sal_False;
3600 String sParam(rName);
3601 if(sParam.Len() > sLinkSuffix.Len() )
3603 String sCmp = sParam.Copy(sParam.Len() - sLinkSuffix.Len(),
3604 sLinkSuffix.Len());
3605 if(sCmp == sLinkSuffix)
3607 sParam = sParam.Copy(0, sParam.Len() - sLinkSuffix.Len());
3608 if(pxDoc)
3610 if(!pxDoc->GetDocShell())
3611 throw RuntimeException();
3612 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3613 sal_uInt16 nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
3615 for (sal_uInt16 i = 0; i < nOutlineCount && !bRet; ++i)
3617 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3618 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3619 if(sParam ==
3620 lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3622 bRet = sal_True;
3626 else
3628 bRet = xRealAccess->hasByName(sParam);
3632 return bRet;
3635 uno::Type SwXLinkNameAccessWrapper::getElementType(void)
3636 throw( RuntimeException )
3638 return ::getCppuType((Reference<XPropertySet>*)0);
3641 sal_Bool SwXLinkNameAccessWrapper::hasElements(void) throw( RuntimeException )
3643 sal_Bool bRet = sal_False;
3644 if(pxDoc)
3646 OSL_FAIL("not implemented");
3648 else
3650 bRet = xRealAccess->hasElements();
3652 return bRet;
3655 Reference< XPropertySetInfo > SwXLinkNameAccessWrapper::getPropertySetInfo(void)
3656 throw( RuntimeException )
3658 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
3659 return xRet;
3662 void SwXLinkNameAccessWrapper::setPropertyValue(
3663 const OUString& , const Any& )
3664 throw( UnknownPropertyException,
3665 PropertyVetoException,
3666 IllegalArgumentException,
3667 WrappedTargetException,
3668 RuntimeException)
3670 throw UnknownPropertyException();
3673 static Any lcl_GetDisplayBitmap(String sLinkSuffix)
3675 Any aRet;
3676 if(sLinkSuffix.Len())
3677 sLinkSuffix.Erase(0, 1);
3678 sal_uInt16 nImgId = USHRT_MAX;
3680 if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOutline))
3681 nImgId = CONTENT_TYPE_OUTLINE;
3682 else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToTable))
3683 nImgId = CONTENT_TYPE_TABLE;
3684 else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToFrame))
3685 nImgId = CONTENT_TYPE_FRAME;
3686 else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToGraphic))
3687 nImgId = CONTENT_TYPE_GRAPHIC;
3688 else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToRegion))
3689 nImgId = CONTENT_TYPE_REGION;
3690 else if(COMPARE_EQUAL == sLinkSuffix.CompareToAscii(pMarkToOLE))
3691 nImgId = CONTENT_TYPE_OLE;
3692 else if(!sLinkSuffix.Len())
3693 nImgId = CONTENT_TYPE_BOOKMARK;
3694 if(USHRT_MAX != nImgId)
3696 nImgId += 20000;
3697 ImageList aEntryImages( SW_RES(IMG_NAVI_ENTRYBMP) );
3698 const Image& rImage = aEntryImages.GetImage( nImgId );
3699 Bitmap aBitmap( rImage.GetBitmapEx().GetBitmap() );
3700 Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( aBitmap );
3701 aRet.setValue( &xBmp, ::getCppuType((Reference<awt::XBitmap>*)0) );
3703 return aRet;
3706 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
3707 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3709 Any aRet;
3710 if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
3712 aRet <<= OUString(sLinkDisplayName);
3714 else if( rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_BITMAP)))
3716 aRet = lcl_GetDisplayBitmap(sLinkSuffix);
3718 else
3719 throw UnknownPropertyException();
3720 return aRet;
3723 void SwXLinkNameAccessWrapper::addPropertyChangeListener(
3724 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3725 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3728 void SwXLinkNameAccessWrapper::removePropertyChangeListener(
3729 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3730 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3733 void SwXLinkNameAccessWrapper::addVetoableChangeListener(
3734 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3735 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3738 void SwXLinkNameAccessWrapper::removeVetoableChangeListener(
3739 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3740 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3743 Reference< XNameAccess > SwXLinkNameAccessWrapper::getLinks(void)
3744 throw( RuntimeException )
3746 return (SwXLinkNameAccessWrapper*)this;
3749 OUString SwXLinkNameAccessWrapper::getImplementationName(void) throw( RuntimeException )
3751 return OUString("SwXLinkNameAccessWrapper");
3754 sal_Bool SwXLinkNameAccessWrapper::supportsService(const OUString& rServiceName)
3755 throw( RuntimeException )
3757 return (rServiceName == "com.sun.star.document.LinkTargets");
3760 Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames(void)
3761 throw( RuntimeException )
3763 Sequence< OUString > aRet(1);
3764 OUString* pNames = aRet.getArray();
3765 pNames[0] = "com.sun.star.document.LinkTargets";
3766 return aRet;
3769 SwXOutlineTarget::SwXOutlineTarget(const String& rOutlineText) :
3770 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3771 sOutlineText(rOutlineText)
3775 SwXOutlineTarget::~SwXOutlineTarget()
3779 Reference< XPropertySetInfo > SwXOutlineTarget::getPropertySetInfo(void) throw( RuntimeException )
3781 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
3782 return xRet;
3785 void SwXOutlineTarget::setPropertyValue(
3786 const OUString& /*PropertyName*/, const Any& /*aValue*/)
3787 throw( UnknownPropertyException, PropertyVetoException,
3788 IllegalArgumentException, WrappedTargetException, RuntimeException)
3790 throw UnknownPropertyException();
3793 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
3794 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3796 Any aRet;
3797 if(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_LINK_DISPLAY_NAME)))
3798 aRet <<= OUString(sOutlineText);
3799 else
3800 throw UnknownPropertyException();
3801 return aRet;
3804 void SwXOutlineTarget::addPropertyChangeListener(
3805 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3806 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3810 void SwXOutlineTarget::removePropertyChangeListener(
3811 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
3812 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3816 void SwXOutlineTarget::addVetoableChangeListener(
3817 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3818 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3822 void SwXOutlineTarget::removeVetoableChangeListener(
3823 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
3824 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
3828 OUString SwXOutlineTarget::getImplementationName(void) throw( RuntimeException )
3830 return OUString("SwXOutlineTarget");
3833 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName) throw( RuntimeException )
3835 return ServiceName == "com.sun.star.document.LinkTarget";
3838 Sequence< OUString > SwXOutlineTarget::getSupportedServiceNames(void) throw( RuntimeException )
3840 Sequence < OUString > aRet(1);
3841 OUString* pArray = aRet.getArray();
3842 pArray[0] = "com.sun.star.document.LinkTarget";
3844 return aRet;
3847 SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
3848 SvxUnoForbiddenCharsTable ( rDoc.getForbiddenCharacterTable() )
3849 ,m_pDoc(&rDoc)
3853 SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
3857 Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
3859 Reference<XInterface> xRet;
3860 if(m_pDoc)
3862 switch(nWhich)
3864 // #i52858#
3865 // assure that Draw model is created, if it doesn't exist.
3866 case SW_CREATE_DASH_TABLE :
3867 if(!xDashTable.is())
3868 xDashTable = SvxUnoDashTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3869 xRet = xDashTable;
3870 break;
3871 case SW_CREATE_GRADIENT_TABLE :
3872 if(!xGradientTable.is())
3873 xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3874 xRet = xGradientTable;
3875 break;
3876 case SW_CREATE_HATCH_TABLE :
3877 if(!xHatchTable.is())
3878 xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3879 xRet = xHatchTable;
3880 break;
3881 case SW_CREATE_BITMAP_TABLE :
3882 if(!xBitmapTable.is())
3883 xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3884 xRet = xBitmapTable;
3885 break;
3886 case SW_CREATE_TRANSGRADIENT_TABLE:
3887 if(!xTransGradientTable.is())
3888 xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3889 xRet = xTransGradientTable;
3890 break;
3891 case SW_CREATE_MARKER_TABLE :
3892 if(!xMarkerTable.is())
3893 xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->GetOrCreateDrawModel() );
3894 xRet = xMarkerTable;
3895 break;
3896 case SW_CREATE_DRAW_DEFAULTS:
3897 if(!xDrawDefaults.is())
3898 xDrawDefaults = (cppu::OWeakObject*)new SwSvxUnoDrawPool(m_pDoc);
3899 xRet = xDrawDefaults;
3900 break;
3901 #if OSL_DEBUG_LEVEL > 0
3902 default: OSL_FAIL("which table?");
3903 #endif
3906 return xRet;
3909 void SwXDocumentPropertyHelper::Invalidate()
3911 xDashTable = 0;
3912 xGradientTable = 0;
3913 xHatchTable = 0;
3914 xBitmapTable = 0;
3915 xTransGradientTable = 0;
3916 xMarkerTable = 0;
3917 xDrawDefaults = 0;
3918 m_pDoc = 0;
3919 SvxUnoForbiddenCharsTable::mxForbiddenChars.clear();
3922 void SwXDocumentPropertyHelper::onChange()
3924 if(m_pDoc)
3925 m_pDoc->SetModified();
3928 SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl(
3929 ViewShell& rSh, const SwViewOption &rViewOptions)
3930 : m_pShell(&rSh)
3931 , m_aOldViewOptions( rViewOptions )
3935 SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl()
3937 if (m_pShell)
3939 m_pShell->ApplyViewOptions( m_aOldViewOptions );
3943 void
3944 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions)
3946 // to avoid unnecessary reformatting the view options related to the content
3947 // below should only change if necessary, that is if respective content is present
3948 const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars();
3949 const SwFieldType* pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENTXTFLD );
3950 const bool bContainsHiddenFields = pFldType && pFldType->GetDepends();
3951 pFldType = m_pShell->GetDoc()->GetSysFldType( RES_HIDDENPARAFLD );
3952 const bool bContainsHiddenParagraphs = pFldType && pFldType->GetDepends();
3953 pFldType = m_pShell->GetDoc()->GetSysFldType( RES_JUMPEDITFLD );
3954 const bool bContainsPlaceHolders = pFldType && pFldType->GetDepends();
3955 const bool bContainsFields = m_pShell->IsAnyFieldInDoc();
3957 SwViewOption aRenderViewOptions( m_aOldViewOptions );
3959 // disable anything in the view that should not be printed (or exported to PDF) by default
3960 // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
3961 // in section "Display of ...")
3962 aRenderViewOptions.SetParagraph( sal_False ); // paragraph end
3963 aRenderViewOptions.SetSoftHyph( sal_False ); // aka custom hyphens
3964 aRenderViewOptions.SetBlank( sal_False ); // spaces
3965 aRenderViewOptions.SetHardBlank( sal_False ); // non-breaking spaces
3966 aRenderViewOptions.SetTab( sal_False ); // tabs
3967 aRenderViewOptions.SetLineBreak( sal_False ); // breaks (type 1)
3968 aRenderViewOptions.SetPageBreak( sal_False ); // breaks (type 2)
3969 aRenderViewOptions.SetColumnBreak( sal_False ); // breaks (type 3)
3970 sal_Bool bVal = pPrtOptions? pPrtOptions->bPrintHiddenText : sal_False;
3971 if (bContainsHiddenChars)
3972 aRenderViewOptions.SetShowHiddenChar( bVal ); // hidden text
3973 if (bContainsHiddenFields)
3974 aRenderViewOptions.SetShowHiddenField( bVal );
3975 if (bContainsHiddenParagraphs)
3976 aRenderViewOptions.SetShowHiddenPara( bVal );
3978 if (bContainsPlaceHolders)
3980 // should always be printed in PDF export!
3981 bVal = pPrtOptions ? pPrtOptions->bPrintTextPlaceholder : sal_True;
3982 aRenderViewOptions.SetShowPlaceHolderFields( bVal );
3985 if (bContainsFields)
3986 aRenderViewOptions.SetFldName( sal_False );
3988 // we need to set this flag in order to get to see the visible effect of
3989 // some of the above settings (needed for correct rendering)
3990 aRenderViewOptions.SetViewMetaChars( sal_True );
3992 if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary
3994 aRenderViewOptions.SetPrinting( pPrtOptions != NULL );
3995 m_pShell->ApplyViewOptions( aRenderViewOptions );
3999 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */