Clean up uses of Any::getValue() in sw
[LibreOffice.git] / sw / source / uibase / uno / unotxdoc.cxx
blobed63dbb30d315272f605ee81b0e6ebb00654aff0
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 .
20 #include <sal/config.h>
22 #include <o3tl/any.hxx>
23 #include <osl/mutex.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/virdev.hxx>
26 #include <vcl/sysdata.hxx>
27 #include <vcl/svapp.hxx>
28 #include <vcl/print.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/sfxbasecontroller.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <sfx2/printer.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
34 #include <toolkit/awt/vclxdevice.hxx>
35 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
36 #include <cmdid.h>
37 #include <swtypes.hxx>
38 #include <wdocsh.hxx>
39 #include <wrtsh.hxx>
40 #include <pview.hxx>
41 #include <viewsh.hxx>
42 #include <pvprtdat.hxx>
43 #include <printdata.hxx>
44 #include <pagefrm.hxx>
45 #include <rootfrm.hxx>
46 #include <svl/stritem.hxx>
47 #include <unotxdoc.hxx>
48 #include <svl/numuno.hxx>
49 #include <fldbas.hxx>
50 #include <unotextbodyhf.hxx>
51 #include <unotextrange.hxx>
52 #include <unotextcursor.hxx>
53 #include <unosett.hxx>
54 #include <unocoll.hxx>
55 #include <unoredlines.hxx>
56 #include <unosrch.hxx>
57 #include <sfx2/dispatch.hxx>
58 #include <sfx2/request.hxx>
59 #include <sfx2/objsh.hxx>
60 #include <unoprnms.hxx>
61 #include <unostyle.hxx>
62 #include <unodraw.hxx>
63 #include <svl/eitem.hxx>
64 #include <pagedesc.hxx>
65 #include <unotools/textsearch.hxx>
66 #include <unocrsr.hxx>
67 #include <unofieldcoll.hxx>
68 #include <unoidxcoll.hxx>
69 #include <unocrsrhelper.hxx>
70 #include <unotxvw.hxx>
71 #include <poolfmt.hxx>
72 #include <globdoc.hxx>
73 #include <viewopt.hxx>
74 #include <unochart.hxx>
75 #include <charatr.hxx>
76 #include <svx/xmleohlp.hxx>
77 #include <globals.hrc>
78 #include <unomid.h>
79 #include <unotools/printwarningoptions.hxx>
80 #include <com/sun/star/util/SearchOptions2.hpp>
81 #include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
82 #include <com/sun/star/lang/DisposedException.hpp>
83 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
84 #include <com/sun/star/beans/PropertyAttribute.hpp>
85 #include <com/sun/star/beans/XFastPropertySet.hpp>
86 #include <com/sun/star/document/RedlineDisplayType.hpp>
87 #include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
88 #include <com/sun/star/frame/XController.hpp>
89 #include <com/sun/star/frame/XFrame.hpp>
90 #include <com/sun/star/script/XInvocation.hpp>
91 #include <sfx2/linkmgr.hxx>
92 #include <svx/unofill.hxx>
93 #include <editeng/unolingu.hxx>
94 #include <sfx2/progress.hxx>
95 #include <swmodule.hxx>
96 #include <docstat.hxx>
97 #include <modcfg.hxx>
98 #include <ndtxt.hxx>
99 #include <utlui.hrc>
100 #include <swcont.hxx>
101 #include <unodefaults.hxx>
102 #include <SwXDocumentSettings.hxx>
103 #include <doc.hxx>
104 #include <IDocumentSettingAccess.hxx>
105 #include <IDocumentDeviceAccess.hxx>
106 #include <IDocumentDrawModelAccess.hxx>
107 #include <IDocumentChartDataProviderAccess.hxx>
108 #include <IDocumentLinksAdministration.hxx>
109 #include <IDocumentRedlineAccess.hxx>
110 #include <IDocumentFieldsAccess.hxx>
111 #include <IDocumentStatistics.hxx>
112 #include <IDocumentStylePoolAccess.hxx>
113 #include <IDocumentLayoutAccess.hxx>
114 #include <IDocumentState.hxx>
115 #include <editeng/forbiddencharacterstable.hxx>
116 #include <svl/zforlist.hxx>
117 #include <drawdoc.hxx>
118 #include <SwStyleNameMapper.hxx>
119 #include <osl/file.hxx>
120 #include <comphelper/storagehelper.hxx>
121 #include <cppuhelper/supportsservice.hxx>
122 #include <unotools/saveopt.hxx>
124 #include <EnhancedPDFExportHelper.hxx>
125 #include <numrule.hxx>
127 #include <editeng/langitem.hxx>
128 #include <docary.hxx>
129 #include <i18nlangtag/languagetag.hxx>
131 #include <format.hxx>
132 #include <charfmt.hxx>
133 #include <fmtcol.hxx>
134 #include <istyleaccess.hxx>
136 #include <svl/stylepool.hxx>
137 #include <swatrset.hxx>
138 #include <view.hxx>
139 #include <srcview.hxx>
140 #include <edtwin.hxx>
141 #include <swdtflvr.hxx>
142 #include <SidebarWin.hxx>
143 #include <PostItMgr.hxx>
145 #include <svtools/langtab.hxx>
146 #include <map>
147 #include <set>
148 #include <vector>
150 #include <editeng/eeitem.hxx>
151 #include <editeng/editeng.hxx>
152 #include <editeng/editview.hxx>
153 #include <svx/svdoutl.hxx>
154 #include <svl/languageoptions.hxx>
155 #include <svx/svdview.hxx>
156 #include <comphelper/processfactory.hxx>
157 #include <comphelper/servicehelper.hxx>
158 #include <memory>
160 using namespace ::com::sun::star;
161 using namespace ::com::sun::star::text;
162 using namespace ::com::sun::star::i18n;
163 using namespace ::com::sun::star::uno;
164 using namespace ::com::sun::star::beans;
165 using namespace ::com::sun::star::lang;
166 using namespace ::com::sun::star::container;
167 using namespace ::com::sun::star::document;
168 using ::osl::FileBase;
170 #define SW_CREATE_DASH_TABLE 0x01
171 #define SW_CREATE_GRADIENT_TABLE 0x02
172 #define SW_CREATE_HATCH_TABLE 0x03
173 #define SW_CREATE_BITMAP_TABLE 0x04
174 #define SW_CREATE_TRANSGRADIENT_TABLE 0x05
175 #define SW_CREATE_MARKER_TABLE 0x06
176 #define SW_CREATE_DRAW_DEFAULTS 0x07
178 static SwPrintUIOptions * lcl_GetPrintUIOptions(
179 SwDocShell * pDocShell,
180 const SfxViewShell * pView )
182 if (!pDocShell)
183 return nullptr;
185 const bool bWebDoc = nullptr != dynamic_cast< const SwWebDocShell * >(pDocShell);
186 const bool bSwSrcView = nullptr != dynamic_cast< const SwSrcView * >(pView);
187 const SwView * pSwView = dynamic_cast< const SwView * >(pView);
188 const bool bHasSelection = pSwView && pSwView->HasSelection( false ); // check for any selection, not just text selection
189 const bool bHasPostIts = sw_GetPostIts( &pDocShell->GetDoc()->getIDocumentFieldsAccess(), nullptr );
191 // get default values to use in dialog from documents SwPrintData
192 const SwPrintData &rPrintData = pDocShell->GetDoc()->getIDocumentDeviceAccess().getPrintData();
194 // Get current page number
195 sal_uInt16 nCurrentPage = 1;
196 const SwWrtShell* pSh = pDocShell->GetWrtShell();
197 const SwRootFrame *pFrame = nullptr;
198 if (pSh)
200 SwPaM* pShellCursor = pSh->GetCursor();
201 nCurrentPage = pShellCursor->GetPageNum();
202 pFrame = pSh->GetLayout();
204 else if (!bSwSrcView)
206 const SwPagePreview* pPreview = dynamic_cast< const SwPagePreview* >(pView);
207 OSL_ENSURE(pPreview, "Unexpected type of the view shell");
208 if (pPreview)
210 nCurrentPage = pPreview->GetSelectedPage();
211 pFrame = pPreview->GetViewShell()->GetLayout();
215 // If blanks are skipped, account for them in initial page range value
216 if (pFrame && !rPrintData.IsPrintEmptyPages())
218 sal_uInt16 nMax = nCurrentPage;
219 const SwPageFrame *pPage = dynamic_cast<const SwPageFrame*>(pFrame->Lower());
220 for ( ; nMax-- > 0; )
222 if (pPage->Frame().Height() == 0)
223 nCurrentPage--;
224 pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
227 return new SwPrintUIOptions( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
230 static SwTextFormatColl *lcl_GetParaStyle(const OUString& rCollName, SwDoc* pDoc)
232 SwTextFormatColl* pColl = pDoc->FindTextFormatCollByName( rCollName );
233 if( !pColl )
235 const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
236 rCollName, nsSwGetPoolIdFromName::GET_POOLID_TXTCOLL );
237 if( USHRT_MAX != nId )
238 pColl = pDoc->getIDocumentStylePoolAccess().GetTextCollFromPool( nId );
240 return pColl;
243 static void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell* pDocShell )
245 // check if the view frame still exists
246 SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell, false );
247 while(pFound)
249 if( pFound == pToClose)
251 pToClose->DoClose();
252 break;
254 pFound = SfxViewFrame::GetNext( *pFound, pDocShell, false );
258 class SwXTextDocument::Impl
260 private:
261 ::osl::Mutex m_Mutex; // just for OInterfaceContainerHelper2
263 public:
264 ::comphelper::OInterfaceContainerHelper2 m_RefreshListeners;
266 Impl() : m_RefreshListeners(m_Mutex) { }
270 namespace
272 class theSwXTextDocumentUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theSwXTextDocumentUnoTunnelId > {};
275 const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
277 return theSwXTextDocumentUnoTunnelId::get().getSeq();
280 sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
281 throw(RuntimeException, std::exception)
283 if( rId.getLength() == 16
284 && 0 == memcmp( getUnoTunnelId().getConstArray(),
285 rId.getConstArray(), 16 ) )
287 return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
289 if( rId.getLength() == 16
290 && 0 == memcmp( SfxObjectShell::getUnoTunnelId().getConstArray(),
291 rId.getConstArray(), 16 ) )
293 return sal::static_int_cast<sal_Int64>(reinterpret_cast<sal_IntPtr>(pDocShell ));
296 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
297 if (nRet)
298 return nRet;
300 GetNumberFormatter();
301 if (!xNumFormatAgg.is()) // may happen if not valid or no SwDoc
302 return 0;
303 Any aNumTunnel = xNumFormatAgg->queryAggregation(cppu::UnoType<XUnoTunnel>::get());
304 Reference<XUnoTunnel> xNumTunnel;
305 aNumTunnel >>= xNumTunnel;
306 return (xNumTunnel.is()) ? xNumTunnel->getSomething(rId) : 0;
309 Any SAL_CALL SwXTextDocument::queryInterface( const uno::Type& rType ) throw(RuntimeException, std::exception)
311 Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
312 if ( !aRet.hasValue() )
313 aRet = SfxBaseModel::queryInterface(rType);
314 if ( !aRet.hasValue() &&
315 rType == cppu::UnoType<lang::XMultiServiceFactory>::get())
317 Reference<lang::XMultiServiceFactory> xTmp = this;
318 aRet <<= xTmp;
320 if ( !aRet.hasValue() &&
321 rType == cppu::UnoType<tiledrendering::XTiledRenderable>::get())
323 Reference<tiledrendering::XTiledRenderable> xTmp = this;
324 aRet <<= xTmp;
327 if ( !aRet.hasValue()
328 && rType != cppu::UnoType<css::document::XDocumentEventBroadcaster>::get()
329 && rType != cppu::UnoType<css::frame::XController>::get()
330 && rType != cppu::UnoType<css::frame::XFrame>::get()
331 && rType != cppu::UnoType<css::script::XInvocation>::get()
332 && rType != cppu::UnoType<css::beans::XFastPropertySet>::get()
333 && rType != cppu::UnoType<css::awt::XWindow>::get())
335 GetNumberFormatter();
336 if(xNumFormatAgg.is())
337 aRet = xNumFormatAgg->queryAggregation(rType);
339 return aRet;
342 void SAL_CALL SwXTextDocument::acquire()throw()
344 SfxBaseModel::acquire();
347 void SAL_CALL SwXTextDocument::release()throw()
349 SfxBaseModel::release();
352 Reference< XAdapter > SwXTextDocument::queryAdapter( ) throw(RuntimeException, std::exception)
354 return SfxBaseModel::queryAdapter();
357 Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes() throw(RuntimeException, std::exception)
359 Sequence< uno::Type > aBaseTypes = SfxBaseModel::getTypes();
360 Sequence< uno::Type > aTextTypes = SwXTextDocumentBaseClass::getTypes();
362 Sequence< uno::Type > aNumTypes;
363 GetNumberFormatter();
364 if(xNumFormatAgg.is())
366 const uno::Type& rProvType = cppu::UnoType<XTypeProvider>::get();
367 Any aNumProv = xNumFormatAgg->queryAggregation(rProvType);
368 Reference<XTypeProvider> xNumProv;
369 if(aNumProv >>= xNumProv)
371 aNumTypes = xNumProv->getTypes();
374 long nIndex = aBaseTypes.getLength();
375 // don't forget the lang::XMultiServiceFactory and the XTiledRenderable
376 aBaseTypes.realloc(aBaseTypes.getLength() + aTextTypes.getLength() + aNumTypes.getLength() + 2);
377 uno::Type* pBaseTypes = aBaseTypes.getArray();
378 const uno::Type* pTextTypes = aTextTypes.getConstArray();
379 long nPos;
380 for(nPos = 0; nPos < aTextTypes.getLength(); nPos++)
382 pBaseTypes[nIndex++] = pTextTypes[nPos];
384 const uno::Type* pNumTypes = aNumTypes.getConstArray();
385 for(nPos = 0; nPos < aNumTypes.getLength(); nPos++)
387 pBaseTypes[nIndex++] = pNumTypes[nPos];
389 pBaseTypes[nIndex++] = cppu::UnoType<lang::XMultiServiceFactory>::get();
390 pBaseTypes[nIndex++] = cppu::UnoType<tiledrendering::XTiledRenderable>::get();
391 return aBaseTypes;
394 SwXTextDocument::SwXTextDocument(SwDocShell* pShell)
395 : SfxBaseModel(pShell)
396 , m_pImpl(new Impl)
398 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
400 pDocShell(pShell),
402 bObjectValid(pShell != nullptr),
404 pDrawPage(nullptr),
405 mxXDrawPage(),
406 pBodyText(nullptr),
407 mxXNumberingRules(),
408 mxXFootnotes(),
409 mxXFootnoteSettings(),
410 mxXEndnotes(),
411 mxXEndnoteSettings(),
412 mxXReferenceMarks(),
413 mxXTextFieldTypes(),
414 mxXTextFieldMasters(),
415 mxXTextSections(),
416 mxXBookmarks(),
417 mxXTextTables(),
418 mxXTextFrames(),
419 mxXGraphicObjects(),
420 mxXEmbeddedObjects(),
421 mxXStyleFamilies(),
422 mxXAutoStyles(),
423 mxXChapterNumbering(),
424 mxXDocumentIndexes(),
426 mxXLineNumberingProperties(),
427 mxLinkTargetSupplier(),
428 mxXRedlines(),
429 m_pHiddenViewFrame(nullptr),
430 pPropertyHelper(nullptr),
431 m_pPrintUIOptions( nullptr ),
432 m_pRenderData( nullptr ),
433 // #i117783#
434 bApplyPagePrintSettingsFromXPagePrintable( false )
438 SwXTextDocument::~SwXTextDocument()
440 InitNewDoc();
441 if(xNumFormatAgg.is())
443 Reference< XInterface > x0;
444 xNumFormatAgg->setDelegator(x0);
445 xNumFormatAgg = nullptr;
447 delete m_pPrintUIOptions;
448 if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
449 { // rhbz#827695: this can happen if the last page is not printed
450 // the SwViewShell has been deleted already by SwView::~SwView
451 // FIXME: replace this awful implementation of XRenderable with
452 // something less insane that has its own view
453 m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
455 delete m_pRenderData;
458 SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
460 if(!xPropertyHelper.is())
462 pPropertyHelper = new SwXDocumentPropertyHelper(*pDocShell->GetDoc());
463 xPropertyHelper = static_cast<cppu::OWeakObject*>(pPropertyHelper);
465 return pPropertyHelper;
468 void SwXTextDocument::GetNumberFormatter()
470 if(IsValid())
472 if(!xNumFormatAgg.is())
474 if ( pDocShell->GetDoc() )
476 SvNumberFormatsSupplierObj* pNumFormat = new SvNumberFormatsSupplierObj(
477 pDocShell->GetDoc()->GetNumberFormatter());
478 Reference< util::XNumberFormatsSupplier > xTmp = pNumFormat;
479 xNumFormatAgg.set(xTmp, UNO_QUERY);
481 if(xNumFormatAgg.is())
482 xNumFormatAgg->setDelegator(static_cast<cppu::OWeakObject*>(static_cast<SwXTextDocumentBaseClass*>(this)));
484 else
486 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
487 Any aNumTunnel = xNumFormatAgg->queryAggregation(rTunnelType);
488 SvNumberFormatsSupplierObj* pNumFormat = nullptr;
489 Reference< XUnoTunnel > xNumTunnel;
490 if(aNumTunnel >>= xNumTunnel)
492 pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>(
493 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
496 OSL_ENSURE(pNumFormat, "No number formatter available");
497 if (pNumFormat && !pNumFormat->GetNumberFormatter())
498 pNumFormat->SetNumberFormatter(pDocShell->GetDoc()->GetNumberFormatter());
503 Reference< XText > SwXTextDocument::getText() throw( RuntimeException, std::exception )
505 SolarMutexGuard aGuard;
506 if(!IsValid())
507 throw RuntimeException();
508 if(!xBodyText.is())
510 pBodyText = new SwXBodyText(pDocShell->GetDoc());
511 xBodyText = pBodyText;
513 return xBodyText;
516 void SwXTextDocument::reformat() throw( RuntimeException, std::exception )
518 SolarMutexGuard aGuard;
519 if(!IsValid())
520 throw RuntimeException();
523 void SwXTextDocument::lockControllers() throw( RuntimeException, std::exception )
525 SolarMutexGuard aGuard;
526 if(IsValid())
528 UnoActionContext* pContext = new UnoActionContext(pDocShell->GetDoc());
529 aActionArr.push_front(pContext);
531 else
532 throw RuntimeException();
535 void SwXTextDocument::unlockControllers() throw( RuntimeException, std::exception )
537 SolarMutexGuard aGuard;
538 if(!aActionArr.empty())
540 UnoActionContext* pContext = aActionArr.front();
541 aActionArr.pop_front();
542 delete pContext;
544 else
545 throw RuntimeException();
548 sal_Bool SwXTextDocument::hasControllersLocked() throw( RuntimeException, std::exception )
550 SolarMutexGuard aGuard;
551 return !aActionArr.empty();
554 Reference< frame::XController > SwXTextDocument::getCurrentController() throw( RuntimeException, std::exception )
556 return SfxBaseModel::getCurrentController();
559 void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
560 throw( NoSuchElementException, RuntimeException, std::exception )
562 SfxBaseModel::setCurrentController(xController);
565 Reference< XInterface > SwXTextDocument::getCurrentSelection() throw( RuntimeException, std::exception )
567 SolarMutexGuard aGuard;
568 Reference< XInterface > xRef;
569 if(IsValid())
571 SwView* pView = static_cast<SwView*>(SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>));
572 while(pView && pView->GetObjectShell() != pDocShell)
574 pView = static_cast<SwView*>(SfxViewShell::GetNext(*pView, true, checkSfxViewShell<SwView>));
576 if(pView)
578 Any aRef = pView->GetUNOObject()->getSelection();
579 aRef >>= xRef;
582 return xRef;
585 sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
586 throw( RuntimeException, std::exception )
588 return SfxBaseModel::attachResource(aURL, aArgs);
591 OUString SwXTextDocument::getURL() throw( RuntimeException, std::exception )
593 return SfxBaseModel::getURL();
596 Sequence< beans::PropertyValue > SwXTextDocument::getArgs() throw( RuntimeException, std::exception )
598 return SfxBaseModel::getArgs();
601 void SwXTextDocument::connectController(const Reference< frame::XController > & xController) throw( RuntimeException, std::exception )
603 SfxBaseModel::connectController(xController);
606 void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController) throw( RuntimeException, std::exception )
608 SfxBaseModel::disconnectController(xController);
611 void SwXTextDocument::dispose() throw( RuntimeException, std::exception )
613 SfxBaseModel::dispose();
616 void SwXTextDocument::close( sal_Bool bDeliverOwnership ) throw( util::CloseVetoException, RuntimeException, std::exception )
618 SolarMutexGuard aGuard;
619 if(IsValid() && m_pHiddenViewFrame)
620 lcl_DisposeView( m_pHiddenViewFrame, pDocShell);
621 SfxBaseModel::close(bDeliverOwnership);
624 void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException, std::exception )
626 SfxBaseModel::addEventListener(aListener);
629 void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener) throw( RuntimeException, std::exception )
631 SfxBaseModel::removeEventListener(aListener);
634 Reference< XPropertySet > SwXTextDocument::getLineNumberingProperties()
635 throw( RuntimeException, std::exception )
637 SolarMutexGuard aGuard;
638 if(IsValid())
640 if(!mxXLineNumberingProperties.is())
642 mxXLineNumberingProperties = new SwXLineNumberingProperties(pDocShell->GetDoc());
645 else
646 throw RuntimeException();
647 return mxXLineNumberingProperties;
650 Reference< XIndexReplace > SwXTextDocument::getChapterNumberingRules()
651 throw( RuntimeException, std::exception )
653 SolarMutexGuard aGuard;
654 if(!IsValid())
655 throw RuntimeException();
656 if(!mxXChapterNumbering.is())
658 mxXChapterNumbering = new SwXChapterNumbering(*pDocShell);
660 return mxXChapterNumbering;
663 Reference< XIndexAccess > SwXTextDocument::getNumberingRules() throw( RuntimeException, std::exception )
665 SolarMutexGuard aGuard;
666 if(!IsValid())
667 throw RuntimeException();
668 if(!mxXNumberingRules.is() )
670 mxXNumberingRules = new SwXNumberingRulesCollection( pDocShell->GetDoc() );
672 return mxXNumberingRules;
675 Reference< XIndexAccess > SwXTextDocument::getFootnotes() throw( RuntimeException, std::exception )
677 SolarMutexGuard aGuard;
678 if(!IsValid())
679 throw RuntimeException();
680 if(!mxXFootnotes.is())
682 mxXFootnotes = new SwXFootnotes(false, pDocShell->GetDoc());
684 return mxXFootnotes;
687 Reference< XPropertySet > SAL_CALL
688 SwXTextDocument::getFootnoteSettings() throw( RuntimeException, std::exception )
690 SolarMutexGuard aGuard;
691 if(!IsValid())
692 throw RuntimeException();
693 if(!mxXFootnoteSettings.is())
695 mxXFootnoteSettings = new SwXFootnoteProperties(pDocShell->GetDoc());
697 return mxXFootnoteSettings;
700 Reference< XIndexAccess > SwXTextDocument::getEndnotes() throw( RuntimeException, std::exception )
702 SolarMutexGuard aGuard;
703 if(!IsValid())
704 throw RuntimeException();
705 if(!mxXEndnotes.is())
707 mxXEndnotes = new SwXFootnotes(true, pDocShell->GetDoc());
709 return mxXEndnotes;
712 Reference< XPropertySet > SwXTextDocument::getEndnoteSettings() throw( RuntimeException, std::exception )
714 SolarMutexGuard aGuard;
715 if(!IsValid())
716 throw RuntimeException();
717 if(!mxXEndnoteSettings.is())
719 mxXEndnoteSettings = new SwXEndnoteProperties(pDocShell->GetDoc());
721 return mxXEndnoteSettings;
724 Reference< util::XReplaceDescriptor > SwXTextDocument::createReplaceDescriptor()
725 throw( RuntimeException, std::exception )
727 SolarMutexGuard aGuard;
728 Reference< util::XReplaceDescriptor > xRet = new SwXTextSearch;
729 return xRet;
732 SwUnoCursor* SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCursor)
734 getText();
735 XText *const pText = xBodyText.get();
736 SwXBodyText* pBText = static_cast<SwXBodyText*>(pText);
737 SwXTextCursor *const pXTextCursor = pBText->CreateTextCursor(true);
738 xCursor.set( static_cast<text::XWordCursor*>(pXTextCursor) );
740 auto& rUnoCursor(pXTextCursor->GetCursor());
741 rUnoCursor.SetRemainInSection(false);
742 return &rUnoCursor;
745 sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
746 throw( RuntimeException, std::exception )
748 SolarMutexGuard aGuard;
749 Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
750 if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
751 throw RuntimeException();
753 Reference< XTextCursor > xCursor;
754 auto pUnoCursor(CreateCursorForSearch(xCursor));
756 const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
757 xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
759 int eRanges(FND_IN_BODY|FND_IN_SELALL);
761 util::SearchOptions2 aSearchOpt;
762 pSearch->FillSearchOptions( aSearchOpt );
764 SwDocPositions eStart = pSearch->bBack ? DOCPOS_END : DOCPOS_START;
765 SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
767 // Search should take place anywhere
768 pUnoCursor->SetRemainInSection(false);
769 sal_uInt32 nResult;
770 UnoActionContext aContext(pDocShell->GetDoc());
771 //try attribute search first
772 if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
774 SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
775 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
776 RES_PARATR_BEGIN, RES_PARATR_END-1,
777 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
779 SfxItemSet aReplace(pDocShell->GetDoc()->GetAttrPool(),
780 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
781 RES_PARATR_BEGIN, RES_PARATR_END-1,
782 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
784 pSearch->FillSearchItemSet(aSearch);
785 pSearch->FillReplaceItemSet(aReplace);
786 bool bCancel;
787 nResult = (sal_Int32)pUnoCursor->Find( aSearch, !pSearch->bStyles,
788 eStart, eEnd, bCancel,
789 (FindRanges)eRanges,
790 !pSearch->sSearchText.isEmpty() ? &aSearchOpt : nullptr,
791 &aReplace );
793 else if(pSearch->bStyles)
795 SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCursor->GetDoc());
796 SwTextFormatColl *pReplaceColl = lcl_GetParaStyle(pSearch->sReplaceText, pUnoCursor->GetDoc());
798 bool bCancel;
799 nResult = pUnoCursor->Find( *pSearchColl,
800 eStart, eEnd, bCancel,
801 (FindRanges)eRanges, pReplaceColl );
804 else
806 //todo/mba: assuming that notes should be omitted
807 bool bSearchInNotes = false;
808 bool bCancel;
809 nResult = pUnoCursor->Find( aSearchOpt, bSearchInNotes,
810 eStart, eEnd, bCancel,
811 (FindRanges)eRanges,
812 true );
814 return (sal_Int32)nResult;
818 Reference< util::XSearchDescriptor > SwXTextDocument::createSearchDescriptor()
819 throw( RuntimeException, std::exception )
821 SolarMutexGuard aGuard;
822 Reference< util::XSearchDescriptor > xRet = new SwXTextSearch;
823 return xRet;
827 // Used for findAll/First/Next
829 SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
830 Reference< XTextCursor > & xCursor,
831 bool bAll,
832 sal_Int32& nResult,
833 Reference< XInterface > xLastResult)
835 Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY);
836 if(!IsValid() || !xDescTunnel.is() || !xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()))
837 return nullptr;
839 auto pUnoCursor(CreateCursorForSearch(xCursor));
840 const SwXTextSearch* pSearch = reinterpret_cast<const SwXTextSearch*>(
841 xDescTunnel->getSomething(SwXTextSearch::getUnoTunnelId()));
843 bool bParentInExtra = false;
844 if(xLastResult.is())
846 Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
847 OTextCursorHelper* pPosCursor = nullptr;
848 if(xCursorTunnel.is())
850 pPosCursor = reinterpret_cast<OTextCursorHelper*>(xCursorTunnel->getSomething(
851 OTextCursorHelper::getUnoTunnelId()));
853 SwPaM* pCursor = pPosCursor ? pPosCursor->GetPaM() : nullptr;
854 if(pCursor)
856 *pUnoCursor->GetPoint() = *pCursor->End();
857 pUnoCursor->DeleteMark();
859 else
861 SwXTextRange* pRange = nullptr;
862 if(xCursorTunnel.is())
864 pRange = reinterpret_cast<SwXTextRange*>(xCursorTunnel->getSomething(
865 SwXTextRange::getUnoTunnelId()));
867 if(!pRange)
868 return nullptr;
869 pRange->GetPositions(*pUnoCursor);
870 if(pUnoCursor->HasMark())
872 if(*pUnoCursor->GetPoint() < *pUnoCursor->GetMark())
873 pUnoCursor->Exchange();
874 pUnoCursor->DeleteMark();
877 const SwNode& rRangeNode = pUnoCursor->GetNode();
878 bParentInExtra = rRangeNode.FindFlyStartNode() ||
879 rRangeNode.FindFootnoteStartNode() ||
880 rRangeNode.FindHeaderStartNode() ||
881 rRangeNode.FindFooterStartNode() ;
884 util::SearchOptions2 aSearchOpt;
885 pSearch->FillSearchOptions( aSearchOpt );
888 * The following combinations are allowed:
889 * - Search in the body: -> FND_IN_BODY
890 * - Search all in the body: -> FND_IN_BODYONLY | FND_IN_SELALL
891 * - Search in selections: one / all -> FND_IN_SEL [ | FND_IN_SELALL ]
892 * - Search outside the body: one / all -> FND_IN_OTHER [ | FND_IN_SELALL ]
893 * - Search everywhere all: -> FND_IN_SELALL
895 int eRanges(FND_IN_BODY);
896 if(bParentInExtra)
897 eRanges = FND_IN_OTHER;
898 if(bAll) //always - everywhere?
899 eRanges = FND_IN_SELALL;
900 SwDocPositions eStart = !bAll ? DOCPOS_CURR : pSearch->bBack ? DOCPOS_END : DOCPOS_START;
901 SwDocPositions eEnd = pSearch->bBack ? DOCPOS_START : DOCPOS_END;
903 nResult = 0;
904 for (int nSearchProc = 0; nSearchProc < 2; ++nSearchProc)
906 //try attribute search first
907 if(pSearch->HasSearchAttributes())
909 SfxItemSet aSearch(pDocShell->GetDoc()->GetAttrPool(),
910 RES_CHRATR_BEGIN, RES_CHRATR_END-1,
911 RES_PARATR_BEGIN, RES_PARATR_END-1,
912 RES_FRMATR_BEGIN, RES_FRMATR_END-1,
913 RES_TXTATR_INETFMT, RES_TXTATR_CHARFMT,
915 pSearch->FillSearchItemSet(aSearch);
916 bool bCancel;
917 nResult = (sal_Int32)pUnoCursor->Find( aSearch, !pSearch->bStyles,
918 eStart, eEnd, bCancel,
919 (FindRanges)eRanges,
920 !pSearch->sSearchText.isEmpty() ? &aSearchOpt : nullptr );
922 else if(pSearch->bStyles)
924 SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->sSearchText, pUnoCursor->GetDoc());
925 //pSearch->sReplaceText
926 SwTextFormatColl *pReplaceColl = nullptr;
927 bool bCancel;
928 nResult = (sal_Int32)pUnoCursor->Find( *pSearchColl,
929 eStart, eEnd, bCancel,
930 (FindRanges)eRanges, pReplaceColl );
932 else
934 //todo/mba: assuming that notes should be omitted
935 bool bSearchInNotes = false;
936 bool bCancel;
937 nResult = (sal_Int32)pUnoCursor->Find( aSearchOpt, bSearchInNotes,
938 eStart, eEnd, bCancel,
939 (FindRanges)eRanges );
941 if(nResult || (eRanges&(FND_IN_SELALL|FND_IN_OTHER)))
942 break;
943 //second step - find in other
944 eRanges = FND_IN_OTHER;
946 return pUnoCursor;
949 Reference< XIndexAccess >
950 SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
951 throw( RuntimeException, std::exception )
953 SolarMutexGuard aGuard;
954 Reference< XInterface > xTmp;
955 sal_Int32 nResult = 0;
956 Reference< XTextCursor > xCursor;
957 auto pResultCursor(FindAny(xDesc, xCursor, true, nResult, xTmp));
958 if(!pResultCursor)
959 throw RuntimeException();
960 Reference< XIndexAccess > xRet;
961 xRet = SwXTextRanges::Create( (nResult) ? &(*pResultCursor) : nullptr );
962 return xRet;
965 Reference< XInterface > SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
966 throw( RuntimeException, std::exception )
968 SolarMutexGuard aGuard;
969 Reference< XInterface > xTmp;
970 sal_Int32 nResult = 0;
971 Reference< XTextCursor > xCursor;
972 auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xTmp));
973 if(!pResultCursor)
974 throw RuntimeException();
975 Reference< XInterface > xRet;
976 if(nResult)
978 const uno::Reference< text::XText > xParent =
979 ::sw::CreateParentXText(*pDocShell->GetDoc(),
980 *pResultCursor->GetPoint());
981 xRet = *new SwXTextCursor(xParent, *pResultCursor);
983 return xRet;
986 Reference< XInterface > SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
987 const Reference< util::XSearchDescriptor > & xDesc)
988 throw( RuntimeException, std::exception )
990 SolarMutexGuard aGuard;
991 Reference< XInterface > xTmp;
992 sal_Int32 nResult = 0;
993 Reference< XTextCursor > xCursor;
994 if(!xStartAt.is())
995 throw RuntimeException();
996 auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xStartAt));
997 if(!pResultCursor)
998 throw RuntimeException();
999 Reference< XInterface > xRet;
1000 if(nResult)
1002 const uno::Reference< text::XText > xParent =
1003 ::sw::CreateParentXText(*pDocShell->GetDoc(),
1004 *pResultCursor->GetPoint());
1006 xRet = *new SwXTextCursor(xParent, *pResultCursor);
1008 return xRet;
1011 Sequence< beans::PropertyValue > SwXTextDocument::getPagePrintSettings()
1012 throw( RuntimeException, std::exception )
1014 SolarMutexGuard aGuard;
1015 Sequence< beans::PropertyValue > aSeq(9);
1016 if(IsValid())
1018 beans::PropertyValue* pArray = aSeq.getArray();
1019 SwPagePreviewPrtData aData;
1020 const SwPagePreviewPrtData* pData = pDocShell->GetDoc()->GetPreviewPrtData();
1021 if(pData)
1022 aData = *pData;
1023 Any aVal;
1024 aVal <<= (sal_Int16)aData.GetRow();
1025 pArray[0] = beans::PropertyValue("PageRows", -1, aVal, PropertyState_DIRECT_VALUE);
1026 aVal <<= (sal_Int16)aData.GetCol();
1027 pArray[1] = beans::PropertyValue("PageColumns", -1, aVal, PropertyState_DIRECT_VALUE);
1028 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetLeftSpace());
1029 pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1030 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetRightSpace());
1031 pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1032 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetTopSpace());
1033 pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1034 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetBottomSpace());
1035 pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1036 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetHorzSpace());
1037 pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1038 aVal <<= (sal_Int32)convertTwipToMm100(aData.GetVertSpace());
1039 pArray[7] = beans::PropertyValue("VertMargin", -1, aVal, PropertyState_DIRECT_VALUE);
1040 aVal <<= aData.GetLandscape();
1041 pArray[8] = beans::PropertyValue("IsLandscape", -1, aVal, PropertyState_DIRECT_VALUE);
1043 else
1044 throw RuntimeException();
1045 return aSeq;
1048 static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, bool& bException)
1050 bException = false;
1051 TypeClass eType = rValue.getValueType().getTypeClass();
1053 sal_uInt32 nRet = 0;
1054 if( eType == TypeClass_UNSIGNED_LONG )
1055 rValue >>= nRet;
1056 else
1058 sal_Int32 nVal=0;
1059 bException = !(rValue >>= nVal);
1060 if( !bException )
1061 nRet = (sal_uInt32)nVal;
1064 return nRet;
1067 static OUString lcl_CreateOutlineString( size_t nIndex,
1068 const SwOutlineNodes& rOutlineNodes, const SwNumRule* pOutlRule)
1070 OUString sEntry;
1071 const SwTextNode * pTextNd = rOutlineNodes[ nIndex ]->GetTextNode();
1072 SwNumberTree::tNumberVector aNumVector = pTextNd->GetNumberVector();
1073 if( pOutlRule && pTextNd->GetNumRule())
1074 for( int nLevel = 0;
1075 nLevel <= pTextNd->GetActualListLevel();
1076 nLevel++ )
1078 long nVal = aNumVector[nLevel];
1079 nVal ++;
1080 nVal -= pOutlRule->Get(nLevel).GetStart();
1081 sEntry += OUString::number( nVal );
1082 sEntry += ".";
1084 sEntry += rOutlineNodes[ nIndex ]->
1085 GetTextNode()->GetExpandText();
1086 return sEntry;
1089 void SwXTextDocument::setPagePrintSettings(const Sequence< beans::PropertyValue >& aSettings)
1090 throw( RuntimeException, std::exception )
1092 SolarMutexGuard aGuard;
1093 if(IsValid())
1095 SwPagePreviewPrtData aData;
1096 //if only a few properties are coming, then use the current settings
1097 const SwPagePreviewPrtData* pData = pDocShell->GetDoc()->GetPreviewPrtData();
1098 if(pData)
1099 aData = *pData;
1100 const beans::PropertyValue* pProperties = aSettings.getConstArray();
1101 int nCount = aSettings.getLength();
1102 for(int i = 0; i < nCount; i++)
1104 OUString sName = pProperties[i].Name;
1105 const Any& rVal = pProperties[i].Value;
1106 bool bException;
1107 sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
1108 if( sName == "PageRows" )
1110 if(!nVal || nVal > 0xff)
1111 throw RuntimeException();
1112 aData.SetRow((sal_uInt8)nVal);
1114 else if(sName == "PageColumns")
1116 if(!nVal || nVal > 0xff)
1117 throw RuntimeException();
1118 aData.SetCol((sal_uInt8)nVal);
1120 else if(sName == "LeftMargin")
1122 aData.SetLeftSpace(convertMm100ToTwip(nVal));
1124 else if(sName == "RightMargin")
1126 aData.SetRightSpace(convertMm100ToTwip(nVal));
1128 else if(sName == "TopMargin")
1130 aData.SetTopSpace(convertMm100ToTwip(nVal));
1132 else if(sName == "BottomMargin")
1134 aData.SetBottomSpace(convertMm100ToTwip(nVal));
1136 else if(sName == "HoriMargin")
1138 aData.SetHorzSpace(convertMm100ToTwip(nVal));
1140 else if(sName == "VertMargin")
1142 aData.SetVertSpace(convertMm100ToTwip(nVal));
1144 else if(sName == "IsLandscape")
1146 auto b = o3tl::tryAccess<bool>(rVal);
1147 bException = bool(b);
1148 if (b)
1150 aData.SetLandscape(*b);
1153 else
1154 bException = true;
1155 if(bException)
1156 throw RuntimeException();
1158 pDocShell->GetDoc()->SetPreviewPrtData(&aData);
1160 else
1161 throw RuntimeException();
1164 void SwXTextDocument::printPages(const Sequence< beans::PropertyValue >& xOptions)
1165 throw( IllegalArgumentException, RuntimeException, std::exception )
1167 SolarMutexGuard aGuard;
1168 if(IsValid())
1170 SfxViewFrame* pFrame = SfxViewFrame::LoadHiddenDocument( *pDocShell, 7 );
1171 SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SfxCallMode::SYNCHRON,
1172 pDocShell->GetDoc()->GetAttrPool());
1173 aReq.AppendItem(SfxBoolItem(FN_PRINT_PAGEPREVIEW, true));
1175 for ( int n = 0; n < xOptions.getLength(); ++n )
1177 // get Property-Value from options
1178 const beans::PropertyValue &rProp = xOptions.getConstArray()[n];
1179 Any aValue( rProp.Value );
1181 // FileName-Property?
1182 if ( rProp.Name == UNO_NAME_FILE_NAME )
1184 OUString sFileURL;
1185 if ( (rProp.Value >>= sFileURL ) )
1187 // Convert the File URL into a system dependent path, as the SalPrinter expects
1188 OUString sSystemPath;
1189 FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
1190 aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
1192 else if ( rProp.Value.getValueType() != cppu::UnoType<void>::get() )
1193 throw IllegalArgumentException();
1196 // CopyCount-Property
1197 else if ( rProp.Name == UNO_NAME_COPY_COUNT )
1199 sal_Int32 nCopies = 0;
1200 aValue >>= nCopies;
1201 aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, (sal_Int16)nCopies ) );
1204 // Collate-Property
1205 else if ( rProp.Name == UNO_NAME_COLLATE )
1207 if ( auto b = o3tl::tryAccess<bool>(rProp.Value) )
1209 aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *b ) );
1210 else
1211 throw IllegalArgumentException();
1214 // Sort-Property
1215 else if ( rProp.Name == UNO_NAME_SORT )
1217 if ( auto b = o3tl::tryAccess<bool>(rProp.Value) )
1218 aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *b ) );
1219 else
1220 throw IllegalArgumentException();
1223 // Pages-Property
1224 else if ( rProp.Name == UNO_NAME_PAGES )
1226 OUString sTmp;
1227 if ( rProp.Value >>= sTmp )
1228 aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
1229 else
1230 throw IllegalArgumentException();
1234 // #i117783#
1235 bApplyPagePrintSettingsFromXPagePrintable = true;
1236 pFrame->GetViewShell()->ExecuteSlot(aReq);
1237 // Frame close
1238 pFrame->DoClose();
1241 else
1242 throw RuntimeException();
1245 Reference< XNameAccess > SwXTextDocument::getReferenceMarks()
1246 throw( RuntimeException, std::exception )
1248 SolarMutexGuard aGuard;
1249 if(!IsValid())
1250 throw RuntimeException();
1251 if(!mxXReferenceMarks.is())
1253 mxXReferenceMarks = new SwXReferenceMarks(pDocShell->GetDoc());
1255 return mxXReferenceMarks;
1258 Reference< XEnumerationAccess > SwXTextDocument::getTextFields() throw( RuntimeException, std::exception )
1260 SolarMutexGuard aGuard;
1261 if(!IsValid())
1262 throw RuntimeException();
1263 if(!mxXTextFieldTypes.is())
1265 mxXTextFieldTypes = new SwXTextFieldTypes(pDocShell->GetDoc());
1267 return mxXTextFieldTypes;
1270 Reference< XNameAccess > SwXTextDocument::getTextFieldMasters()
1271 throw( RuntimeException, std::exception )
1273 SolarMutexGuard aGuard;
1274 if(!IsValid())
1275 throw RuntimeException();
1276 if(!mxXTextFieldMasters.is())
1278 mxXTextFieldMasters = new SwXTextFieldMasters(pDocShell->GetDoc());
1280 return mxXTextFieldMasters;
1283 Reference< XNameAccess > SwXTextDocument::getEmbeddedObjects() throw( RuntimeException, std::exception )
1285 SolarMutexGuard aGuard;
1286 if(!IsValid())
1287 throw RuntimeException();
1288 if(!mxXEmbeddedObjects.is())
1290 mxXEmbeddedObjects = new SwXTextEmbeddedObjects(pDocShell->GetDoc());
1292 return mxXEmbeddedObjects;
1295 Reference< XNameAccess > SwXTextDocument::getBookmarks() throw( RuntimeException, std::exception )
1297 SolarMutexGuard aGuard;
1298 if(!IsValid())
1299 throw RuntimeException();
1300 if(!mxXBookmarks.is())
1302 mxXBookmarks = new SwXBookmarks(pDocShell->GetDoc());
1304 return mxXBookmarks;
1307 Reference< XNameAccess > SwXTextDocument::getTextSections() throw( RuntimeException, std::exception )
1309 SolarMutexGuard aGuard;
1310 if(!IsValid())
1311 throw RuntimeException();
1312 if(!mxXTextSections.is())
1314 mxXTextSections = new SwXTextSections(pDocShell->GetDoc());
1316 return mxXTextSections;
1319 Reference< XNameAccess > SwXTextDocument::getTextTables() throw( RuntimeException, std::exception )
1321 SolarMutexGuard aGuard;
1322 if(!IsValid())
1323 throw RuntimeException();
1324 if(!mxXTextTables.is())
1326 mxXTextTables = new SwXTextTables(pDocShell->GetDoc());
1328 return mxXTextTables;
1331 Reference< XNameAccess > SwXTextDocument::getGraphicObjects() throw( RuntimeException, std::exception )
1333 SolarMutexGuard aGuard;
1334 if(!IsValid())
1335 throw RuntimeException();
1336 if(!mxXGraphicObjects.is())
1338 mxXGraphicObjects = new SwXTextGraphicObjects(pDocShell->GetDoc());
1340 return mxXGraphicObjects;
1343 Reference< XNameAccess > SwXTextDocument::getTextFrames() throw( RuntimeException, std::exception )
1345 SolarMutexGuard aGuard;
1346 if(!IsValid())
1347 throw RuntimeException();
1348 if(!mxXTextFrames.is())
1350 mxXTextFrames = new SwXTextFrames(pDocShell->GetDoc());
1352 return mxXTextFrames;
1355 Reference< XNameAccess > SwXTextDocument::getStyleFamilies() throw( RuntimeException, std::exception )
1357 SolarMutexGuard aGuard;
1358 if(!IsValid())
1359 throw RuntimeException();
1360 if(!mxXStyleFamilies.is())
1362 mxXStyleFamilies = new SwXStyleFamilies(*pDocShell);
1364 return mxXStyleFamilies;
1367 uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles( )
1368 throw (uno::RuntimeException, std::exception)
1370 SolarMutexGuard aGuard;
1371 if(!IsValid())
1372 throw RuntimeException();
1373 if(!mxXAutoStyles.is())
1375 mxXAutoStyles = new SwXAutoStyles(*pDocShell);
1377 return mxXAutoStyles;
1381 Reference< drawing::XDrawPage > SwXTextDocument::getDrawPage() throw( RuntimeException, std::exception )
1383 SolarMutexGuard aGuard;
1384 if(!IsValid())
1385 throw RuntimeException();
1386 if(!mxXDrawPage.is())
1388 static_cast<SwXTextDocument*>(this)->pDrawPage = new SwXDrawPage(pDocShell->GetDoc());
1389 static_cast<SwXTextDocument*>(this)->mxXDrawPage = pDrawPage;
1390 // Create a Reference to trigger the complete initialization of the
1391 // object. Otherwise in some corner cases it would get initialized
1392 // at ::InitNewDoc -> which would get called during
1393 // close() or dispose() -> n#681746
1394 uno::Reference<lang::XComponent> xComp( mxXDrawPage, uno::UNO_QUERY );
1396 return mxXDrawPage;
1399 void SwXTextDocument::Invalidate()
1401 bObjectValid = false;
1402 if(xNumFormatAgg.is())
1404 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1405 Any aNumTunnel = xNumFormatAgg->queryAggregation(rTunnelType);
1406 SvNumberFormatsSupplierObj* pNumFormat = nullptr;
1407 Reference< XUnoTunnel > xNumTunnel;
1408 if(aNumTunnel >>= xNumTunnel)
1410 pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1411 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1412 pNumFormat->SetNumberFormatter(nullptr);
1414 OSL_ENSURE(pNumFormat, "No number formatter available");
1416 InitNewDoc();
1417 pDocShell = nullptr;
1418 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
1419 m_pImpl->m_RefreshListeners.disposeAndClear(ev);
1422 void SwXTextDocument::Reactivate(SwDocShell* pNewDocShell)
1424 if(pDocShell && pDocShell != pNewDocShell)
1425 Invalidate();
1426 pDocShell = pNewDocShell;
1427 bObjectValid = true;
1430 void SwXTextDocument::InitNewDoc()
1432 // first invalidate all collections, then delete references and Set to zero
1433 if(mxXTextTables.is())
1435 XNameAccess* pTables = mxXTextTables.get();
1436 static_cast<SwXTextTables*>(pTables)->Invalidate();
1437 mxXTextTables.clear();
1440 if(mxXTextFrames.is())
1442 XNameAccess* pFrames = mxXTextFrames.get();
1443 static_cast<SwXTextFrames*>(pFrames)->Invalidate();
1444 mxXTextFrames.clear();
1447 if(mxXGraphicObjects.is())
1449 XNameAccess* pFrames = mxXGraphicObjects.get();
1450 static_cast<SwXTextGraphicObjects*>(pFrames)->Invalidate();
1451 mxXGraphicObjects.clear();
1454 if(mxXEmbeddedObjects.is())
1456 XNameAccess* pOLE = mxXEmbeddedObjects.get();
1457 static_cast<SwXTextEmbeddedObjects*>(pOLE)->Invalidate();
1458 mxXEmbeddedObjects.clear();
1461 if(xBodyText.is())
1463 xBodyText = nullptr;
1464 pBodyText = nullptr;
1467 if(xNumFormatAgg.is())
1469 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1470 Any aNumTunnel = xNumFormatAgg->queryAggregation(rTunnelType);
1471 SvNumberFormatsSupplierObj* pNumFormat = nullptr;
1472 Reference< XUnoTunnel > xNumTunnel;
1473 if(aNumTunnel >>= xNumTunnel)
1475 pNumFormat = reinterpret_cast<SvNumberFormatsSupplierObj*>(
1476 xNumTunnel->getSomething(SvNumberFormatsSupplierObj::getUnoTunnelId()));
1479 OSL_ENSURE(pNumFormat, "No number formatter available");
1480 if (pNumFormat)
1481 pNumFormat->SetNumberFormatter(nullptr);
1484 if(mxXTextFieldTypes.is())
1486 XEnumerationAccess* pT = mxXTextFieldTypes.get();
1487 static_cast<SwXTextFieldTypes*>(pT)->Invalidate();
1488 mxXTextFieldTypes.clear();
1491 if(mxXTextFieldMasters.is())
1493 XNameAccess* pT = mxXTextFieldMasters.get();
1494 static_cast<SwXTextFieldMasters*>(pT)->Invalidate();
1495 mxXTextFieldMasters.clear();
1498 if(mxXTextSections.is())
1500 XNameAccess* pSect = mxXTextSections.get();
1501 static_cast<SwXTextSections*>(pSect)->Invalidate();
1502 mxXTextSections.clear();
1505 if(mxXDrawPage.is())
1507 // #i91798#, #i91895#
1508 // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1509 uno::Reference<lang::XComponent> xComp( mxXDrawPage, uno::UNO_QUERY );
1510 xComp->dispose();
1511 pDrawPage->InvalidateSwDoc();
1512 mxXDrawPage.clear();
1515 if ( mxXNumberingRules.is() )
1517 XIndexAccess* pNum = mxXNumberingRules.get();
1518 static_cast<SwXNumberingRulesCollection*>(pNum)->Invalidate();
1519 mxXNumberingRules.clear();
1522 if(mxXFootnotes.is())
1524 XIndexAccess* pFootnote = mxXFootnotes.get();
1525 static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1526 mxXFootnotes.clear();
1529 if(mxXEndnotes.is())
1531 XIndexAccess* pFootnote = mxXEndnotes.get();
1532 static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1533 mxXEndnotes.clear();
1536 if(mxXDocumentIndexes.is())
1538 XIndexAccess* pIdxs = mxXDocumentIndexes.get();
1539 static_cast<SwXDocumentIndexes*>(pIdxs)->Invalidate();
1540 mxXDocumentIndexes.clear();
1543 if(mxXStyleFamilies.is())
1545 XNameAccess* pStyles = mxXStyleFamilies.get();
1546 static_cast<SwXStyleFamilies*>(pStyles)->Invalidate();
1547 mxXStyleFamilies.clear();
1549 if(mxXAutoStyles.is())
1551 XNameAccess* pStyles = mxXAutoStyles.get();
1552 static_cast<SwXAutoStyles*>(pStyles)->Invalidate();
1553 mxXAutoStyles.clear();
1556 if(mxXBookmarks.is())
1558 XNameAccess* pBm = mxXBookmarks.get();
1559 static_cast<SwXBookmarks*>(pBm)->Invalidate();
1560 mxXBookmarks.clear();
1563 if(mxXChapterNumbering.is())
1565 XIndexReplace* pCh = mxXChapterNumbering.get();
1566 static_cast<SwXChapterNumbering*>(pCh)->Invalidate();
1567 mxXChapterNumbering.clear();
1570 if(mxXFootnoteSettings.is())
1572 XPropertySet* pFntSet = mxXFootnoteSettings.get();
1573 static_cast<SwXFootnoteProperties*>(pFntSet)->Invalidate();
1574 mxXFootnoteSettings.clear();
1577 if(mxXEndnoteSettings.is())
1579 XPropertySet* pEndSet = mxXEndnoteSettings.get();
1580 static_cast<SwXEndnoteProperties*>(pEndSet)->Invalidate();
1581 mxXEndnoteSettings.clear();
1584 if(mxXLineNumberingProperties.is())
1586 XPropertySet* pLine = mxXLineNumberingProperties.get();
1587 static_cast<SwXLineNumberingProperties*>(pLine)->Invalidate();
1588 mxXLineNumberingProperties.clear();
1590 if(mxXReferenceMarks.is())
1592 XNameAccess* pMarks = mxXReferenceMarks.get();
1593 static_cast<SwXReferenceMarks*>(pMarks)->Invalidate();
1594 mxXReferenceMarks.clear();
1596 if(mxLinkTargetSupplier.is())
1598 XNameAccess* pAccess = mxLinkTargetSupplier.get();
1599 static_cast<SwXLinkTargetSupplier*>(pAccess)->Invalidate();
1600 mxLinkTargetSupplier.clear();
1602 if(mxXRedlines.is())
1604 XEnumerationAccess* pMarks = mxXRedlines.get();
1605 static_cast<SwXRedlines*>(pMarks)->Invalidate();
1606 mxXRedlines.clear();
1608 if(xPropertyHelper.is())
1610 pPropertyHelper->Invalidate();
1611 xPropertyHelper = nullptr;
1612 pPropertyHelper = nullptr;
1616 css::uno::Reference<css::uno::XInterface> SwXTextDocument::create(
1617 OUString const & rServiceName,
1618 css::uno::Sequence<css::uno::Any> const * arguments)
1620 SolarMutexGuard aGuard;
1621 if (!IsValid())
1623 throw RuntimeException();
1625 const sal_uInt16 nType = SwXServiceProvider::GetProviderType(rServiceName);
1626 if (nType != SW_SERVICE_INVALID)
1628 return SwXServiceProvider::MakeInstance(nType, *pDocShell->GetDoc());
1630 if (rServiceName == "com.sun.star.drawing.DashTable")
1632 return GetPropertyHelper()->GetDrawTable(SW_CREATE_DASH_TABLE);
1634 if (rServiceName == "com.sun.star.drawing.GradientTable")
1636 return GetPropertyHelper()->GetDrawTable(SW_CREATE_GRADIENT_TABLE);
1638 if (rServiceName == "com.sun.star.drawing.HatchTable")
1640 return GetPropertyHelper()->GetDrawTable(SW_CREATE_HATCH_TABLE);
1642 if (rServiceName == "com.sun.star.drawing.BitmapTable")
1644 return GetPropertyHelper()->GetDrawTable(SW_CREATE_BITMAP_TABLE);
1646 if (rServiceName == "com.sun.star.drawing.TransparencyGradientTable")
1648 return GetPropertyHelper()->GetDrawTable(SW_CREATE_TRANSGRADIENT_TABLE);
1650 if (rServiceName == "com.sun.star.drawing.MarkerTable")
1652 return GetPropertyHelper()->GetDrawTable(SW_CREATE_MARKER_TABLE);
1654 if (rServiceName == "com.sun.star.drawing.Defaults")
1656 return GetPropertyHelper()->GetDrawTable(SW_CREATE_DRAW_DEFAULTS);
1658 if (rServiceName == "com.sun.star.document.Settings")
1660 return Reference<XInterface>(*new SwXDocumentSettings(this));
1662 if (rServiceName == "com.sun.star.document.ImportEmbeddedObjectResolver")
1664 return static_cast<cppu::OWeakObject *>(
1665 new SvXMLEmbeddedObjectHelper(
1666 *pDocShell, EMBEDDEDOBJECTHELPER_MODE_READ));
1668 if (rServiceName == "com.sun.star.text.DocumentSettings")
1670 return Reference<XInterface>(*new SwXDocumentSettings(this));
1672 if (rServiceName == "com.sun.star.chart2.data.DataProvider")
1674 return Reference<XInterface>(
1675 dynamic_cast<chart2::data::XDataProvider *>(
1676 pDocShell->getIDocumentChartDataProviderAccess().
1677 GetChartDataProvider()));
1679 if (!rServiceName.startsWith("com.sun.star.")
1680 || rServiceName.endsWith(".OLE2Shape"))
1682 // We do not want to insert OLE2 Shapes (e.g.,
1683 // "com.sun.star.drawing.OLE2Shape", ...) like this (by creating them
1684 // with the documents factory and adding the shapes to the draw page);
1685 // for inserting OLE objects the proper way is to use
1686 // "com.sun.star.text.TextEmbeddedObject":
1687 throw ServiceNotRegisteredException();
1689 // The XML import is allowed to create instances of
1690 // "com.sun.star.drawing.OLE2Shape"; thus, a temporary service name is
1691 // introduced to make this possible:
1692 OUString aTmpServiceName(rServiceName);
1693 if (rServiceName == "com.sun.star.drawing.temporaryForXMLImportOLE2Shape")
1695 aTmpServiceName = "com.sun.star.drawing.OLE2Shape";
1697 Reference<XInterface> xTmp(
1698 arguments == nullptr
1699 ? SvxFmMSFactory::createInstance(aTmpServiceName)
1700 : SvxFmMSFactory::createInstanceWithArguments(
1701 aTmpServiceName, *arguments));
1702 if (rServiceName == "com.sun.star.drawing.GroupShape"
1703 || rServiceName == "com.sun.star.drawing.Shape3DSceneObject")
1705 return *new SwXGroupShape(xTmp);
1707 if (rServiceName.startsWith("com.sun.star.drawing."))
1709 return *new SwXShape(xTmp);
1711 return xTmp;
1714 Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName)
1715 throw( Exception, RuntimeException, std::exception )
1717 return create(rServiceName, nullptr);
1720 Reference< XInterface > SwXTextDocument::createInstanceWithArguments(
1721 const OUString& ServiceSpecifier,
1722 const Sequence< Any >& Arguments)
1723 throw( Exception, RuntimeException, std::exception )
1725 return create(ServiceSpecifier, &Arguments);
1728 Sequence< OUString > SwXTextDocument::getAvailableServiceNames()
1729 throw( RuntimeException, std::exception )
1731 static Sequence< OUString > aServices;
1732 if ( aServices.getLength() == 0 )
1734 Sequence< OUString > aRet = SvxFmMSFactory::getAvailableServiceNames();
1735 OUString* pRet = aRet.getArray();
1736 for ( sal_Int32 i = 0; i < aRet.getLength(); ++i )
1738 if ( pRet[i] == "com.sun.star.drawing.OLE2Shape" )
1740 pRet[i] = pRet[aRet.getLength() - 1];
1741 aRet.realloc( aRet.getLength() - 1 ); // <pRet> no longer valid.
1742 break;
1745 Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
1746 aServices = SvxFmMSFactory::concatServiceNames(aRet, aOwn);
1749 return aServices;
1752 OUString SwXTextDocument::getImplementationName() throw( RuntimeException, std::exception )
1754 return OUString("SwXTextDocument");
1755 /* // Matching the .component information:
1756 return dynamic_cast<SwGlobalDocShell*>( pDocShell ) != nullptr
1757 ? OUString("com.sun.star.comp.Writer.GlobalDocument")
1758 : dynamic_cast<SwWebDocShell*>( pDocShell ) != nullptr
1759 ? OUString("com.sun.star.comp.Writer.WebDocument")
1760 : OUString("com.sun.star.comp.Writer.TextDocument");
1764 sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
1766 return cppu::supportsService(this, rServiceName);
1769 Sequence< OUString > SwXTextDocument::getSupportedServiceNames() throw( RuntimeException, std::exception )
1771 bool bWebDoc = (dynamic_cast<SwWebDocShell*>( pDocShell) != nullptr );
1772 bool bGlobalDoc = (dynamic_cast<SwGlobalDocShell*>( pDocShell) != nullptr );
1773 bool bTextDoc = (!bWebDoc && !bGlobalDoc);
1775 Sequence< OUString > aRet (3);
1776 OUString* pArray = aRet.getArray();
1778 pArray[0] = "com.sun.star.document.OfficeDocument";
1779 pArray[1] = "com.sun.star.text.GenericTextDocument";
1781 if (bTextDoc)
1782 pArray[2] = "com.sun.star.text.TextDocument";
1783 else if (bWebDoc)
1784 pArray[2] = "com.sun.star.text.WebDocument";
1785 else if (bGlobalDoc)
1786 pArray[2] = "com.sun.star.text.GlobalDocument";
1788 return aRet;
1791 Reference< XIndexAccess > SwXTextDocument::getDocumentIndexes() throw( RuntimeException, std::exception )
1793 SolarMutexGuard aGuard;
1794 if(!IsValid())
1795 throw RuntimeException();
1796 if(!mxXDocumentIndexes.is())
1798 mxXDocumentIndexes = new SwXDocumentIndexes(pDocShell->GetDoc());
1800 return mxXDocumentIndexes;
1803 Reference< XPropertySetInfo > SwXTextDocument::getPropertySetInfo() throw( RuntimeException, std::exception )
1805 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
1806 return xRet;
1809 void SwXTextDocument::setPropertyValue(const OUString& rPropertyName, const Any& aValue)
1810 throw (UnknownPropertyException, PropertyVetoException,
1811 IllegalArgumentException, WrappedTargetException,
1812 RuntimeException, std::exception)
1814 SolarMutexGuard aGuard;
1815 if(!IsValid())
1816 throw RuntimeException(
1817 "invalid SwXTextDocument",
1818 static_cast< cppu::OWeakObject * >(
1819 static_cast< SwXTextDocumentBaseClass * >(this)));
1820 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
1822 if(!pEntry)
1823 throw UnknownPropertyException();
1824 if(pEntry->nFlags & PropertyAttribute::READONLY)
1825 throw PropertyVetoException();
1826 switch(pEntry->nWID)
1828 case WID_DOC_CHAR_COUNT :
1829 case WID_DOC_PARA_COUNT :
1830 case WID_DOC_WORD_COUNT :
1831 throw RuntimeException(
1832 "bad WID",
1833 static_cast< cppu::OWeakObject * >(
1834 static_cast< SwXTextDocumentBaseClass * >(this)));
1835 case WID_DOC_WORD_SEPARATOR :
1837 OUString sDelim;
1838 aValue >>= sDelim;
1839 SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
1841 break;
1842 case WID_DOC_CHANGES_RECORD:
1843 case WID_DOC_CHANGES_SHOW:
1845 bool bSet = *o3tl::doAccess<bool>(aValue);
1846 sal_uInt16 eMode = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
1847 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
1849 eMode &= ~(nsRedlineMode_t::REDLINE_SHOW_INSERT | nsRedlineMode_t::REDLINE_SHOW_DELETE);
1850 eMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT;
1851 if( bSet )
1852 eMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE;
1854 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
1856 eMode = bSet ? eMode|nsRedlineMode_t::REDLINE_ON : eMode&~nsRedlineMode_t::REDLINE_ON;
1858 pDocShell->GetDoc()->getIDocumentRedlineAccess().SetRedlineMode( (RedlineMode_t)(eMode ));
1860 break;
1861 case WID_DOC_CHANGES_PASSWORD:
1863 Sequence <sal_Int8> aNew;
1864 if(aValue >>= aNew)
1866 SwDoc* pDoc = pDocShell->GetDoc();
1867 pDoc->getIDocumentRedlineAccess().SetRedlinePassword(aNew);
1868 if(aNew.getLength())
1870 sal_uInt16 eMode = pDoc->getIDocumentRedlineAccess().GetRedlineMode();
1871 eMode = eMode|nsRedlineMode_t::REDLINE_ON;
1872 pDoc->getIDocumentRedlineAccess().SetRedlineMode( (RedlineMode_t)(eMode ));
1876 break;
1877 case WID_DOC_AUTO_MARK_URL :
1879 OUString sURL;
1880 aValue >>= sURL;
1881 pDocShell->GetDoc()->SetTOIAutoMarkURL(sURL);
1883 break;
1884 case WID_DOC_HIDE_TIPS :
1885 SW_MOD()->GetModuleConfig()->SetHideFieldTips(*o3tl::doAccess<bool>(aValue));
1886 break;
1887 case WID_DOC_REDLINE_DISPLAY:
1889 sal_Int16 eRedMode = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
1890 eRedMode = eRedMode & (~nsRedlineMode_t::REDLINE_SHOW_MASK);
1891 sal_Int16 nSet = 0;
1892 aValue >>= nSet;
1893 switch(nSet)
1895 case RedlineDisplayType::NONE: break;
1896 case RedlineDisplayType::INSERTED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT; break;
1897 case RedlineDisplayType::REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_DELETE; break;
1898 case RedlineDisplayType::
1899 INSERTED_AND_REMOVED: eRedMode |= nsRedlineMode_t::REDLINE_SHOW_INSERT|nsRedlineMode_t::REDLINE_SHOW_DELETE;
1900 break;
1901 default: throw IllegalArgumentException();
1903 pDocShell->GetDoc()->getIDocumentRedlineAccess().SetRedlineMode(eRedMode);
1905 break;
1906 case WID_DOC_TWO_DIGIT_YEAR:
1908 sal_Int16 nYear = 0;
1909 aValue >>= nYear;
1910 SfxRequest aRequest ( SID_ATTR_YEAR2000, SfxCallMode::SLOT, pDocShell->GetDoc()->GetAttrPool());
1911 aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
1912 pDocShell->Execute ( aRequest );
1914 break;
1915 case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
1917 SwDrawModel * pDrawDoc;
1918 bool bAuto = *o3tl::doAccess<bool>(aValue);
1920 if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
1921 pDrawDoc->SetAutoControlFocus( bAuto );
1922 else if (bAuto)
1924 // if setting to true, and we don't have an
1925 // SdrModel, then we are changing the default and
1926 // must thus create an SdrModel, if we don't have an
1927 // SdrModel and we are leaving the default at false,
1928 // we don't need to make an SdrModel and can do nothing
1929 // #i52858# - method name changed
1930 pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
1931 pDrawDoc->SetAutoControlFocus ( bAuto );
1934 break;
1935 case WID_DOC_APPLY_FORM_DESIGN_MODE:
1937 SwDrawModel * pDrawDoc;
1938 bool bMode = *o3tl::doAccess<bool>(aValue);
1940 if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
1941 pDrawDoc->SetOpenInDesignMode( bMode );
1942 else if (!bMode)
1944 // if setting to false, and we don't have an
1945 // SdrModel, then we are changing the default and
1946 // must thus create an SdrModel, if we don't have an
1947 // SdrModel and we are leaving the default at true,
1948 // we don't need to make an SdrModel and can do
1949 // nothing
1950 // #i52858# - method name changed
1951 pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
1952 pDrawDoc->SetOpenInDesignMode ( bMode );
1955 break;
1956 // #i42634# New property to set the bInReading
1957 // flag at the document, used during binary import
1958 case WID_DOC_LOCK_UPDATES :
1960 SwDoc* pDoc = pDocShell->GetDoc();
1961 bool bBool (false);
1962 if( aValue >>= bBool )
1963 pDoc->SetInReading( bBool );
1965 break;
1966 case WID_DOC_BUILDID:
1967 aValue >>= maBuildId;
1968 break;
1970 case WID_DOC_DEFAULT_PAGE_MODE:
1972 bool bDefaultPageMode( false );
1973 aValue >>= bDefaultPageMode;
1974 pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
1976 break;
1977 case WID_DOC_INTEROP_GRAB_BAG:
1978 setGrabBagItem(aValue);
1979 break;
1981 default:
1983 const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
1984 std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
1985 pNewItem->PutValue(aValue, pEntry->nMemberId);
1986 pDocShell->GetDoc()->SetDefault(*pNewItem);
1991 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
1992 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
1994 SolarMutexGuard aGuard;
1995 if(!IsValid())
1996 throw RuntimeException();
1997 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
1999 if(!pEntry)
2000 throw UnknownPropertyException();
2001 Any aAny;
2002 switch(pEntry->nWID)
2004 case WID_DOC_ISTEMPLATEID :
2005 aAny <<= pDocShell->IsTemplate();
2006 break;
2007 case WID_DOC_CHAR_COUNT :
2008 case WID_DOC_PARA_COUNT :
2009 case WID_DOC_WORD_COUNT :
2011 const SwDocStat& rStat(pDocShell->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true ));
2012 sal_Int32 nValue;
2013 switch(pEntry->nWID)
2015 case WID_DOC_CHAR_COUNT :nValue = rStat.nChar;break;
2016 case WID_DOC_PARA_COUNT :nValue = rStat.nPara;break;
2017 case WID_DOC_WORD_COUNT :nValue = rStat.nWord;break;
2019 aAny <<= nValue;
2021 break;
2022 case WID_DOC_WORD_SEPARATOR :
2024 aAny <<= SW_MOD()->GetDocStatWordDelim();
2026 break;
2027 case WID_DOC_CHANGES_RECORD:
2028 case WID_DOC_CHANGES_SHOW:
2030 const sal_uInt16 eMode = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
2031 bool bSet = false;
2032 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2034 const sal_uInt16 nMask = nsRedlineMode_t::REDLINE_SHOW_INSERT |
2035 nsRedlineMode_t::REDLINE_SHOW_DELETE;
2036 bSet = (eMode & nMask) == nMask;
2038 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2040 bSet = (eMode& nsRedlineMode_t::REDLINE_ON) != 0;
2042 aAny <<= bSet;
2044 break;
2045 case WID_DOC_CHANGES_PASSWORD:
2047 SwDoc* pDoc = pDocShell->GetDoc();
2048 aAny <<= pDoc->getIDocumentRedlineAccess().GetRedlinePassword();
2050 break;
2051 case WID_DOC_AUTO_MARK_URL :
2052 aAny <<= pDocShell->GetDoc()->GetTOIAutoMarkURL();
2053 break;
2054 case WID_DOC_HIDE_TIPS :
2055 aAny <<= SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2056 break;
2057 case WID_DOC_REDLINE_DISPLAY:
2059 sal_Int16 eRedMode = pDocShell->GetDoc()->getIDocumentRedlineAccess().GetRedlineMode();
2060 eRedMode = eRedMode & nsRedlineMode_t::REDLINE_SHOW_MASK;
2061 sal_Int16 nRet = RedlineDisplayType::NONE;
2062 if(nsRedlineMode_t::REDLINE_SHOW_INSERT == eRedMode)
2063 nRet = RedlineDisplayType::INSERTED;
2064 else if(nsRedlineMode_t::REDLINE_SHOW_DELETE == eRedMode)
2065 nRet = RedlineDisplayType::REMOVED;
2066 else if(nsRedlineMode_t::REDLINE_SHOW_MASK == eRedMode)
2067 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2068 aAny <<= nRet;
2070 break;
2071 case WID_DOC_FORBIDDEN_CHARS:
2073 GetPropertyHelper();
2074 Reference<XForbiddenCharacters> xRet(xPropertyHelper, UNO_QUERY);
2075 aAny <<= xRet;
2077 break;
2078 case WID_DOC_TWO_DIGIT_YEAR:
2080 aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ()->GetYear2000());
2082 break;
2083 case WID_DOC_AUTOMATIC_CONTROL_FOCUS:
2085 SwDrawModel * pDrawDoc;
2086 bool bAuto;
2087 if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
2088 bAuto = pDrawDoc->GetAutoControlFocus();
2089 else
2090 bAuto = false;
2091 aAny <<= bAuto;
2093 break;
2094 case WID_DOC_APPLY_FORM_DESIGN_MODE:
2096 SwDrawModel * pDrawDoc;
2097 bool bMode;
2098 if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
2099 bMode = pDrawDoc->GetOpenInDesignMode();
2100 else
2101 bMode = true;
2102 aAny <<= bMode;
2104 break;
2105 case WID_DOC_BASIC_LIBRARIES:
2106 aAny <<= pDocShell->GetBasicContainer();
2107 break;
2108 case WID_DOC_DIALOG_LIBRARIES:
2109 aAny <<= pDocShell->GetDialogContainer();
2110 break;
2111 case WID_DOC_VBA_DOCOBJ:
2113 /* #i111553# This property provides the name of the constant that
2114 will be used to store this model in the global Basic manager.
2115 That constant will be equivalent to 'ThisComponent' but for
2116 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
2117 constant can co-exist, as required by VBA. */
2118 aAny <<= OUString( "ThisWordDoc" );
2120 break;
2121 case WID_DOC_RUNTIME_UID:
2122 aAny <<= getRuntimeUID();
2123 break;
2124 case WID_DOC_LOCK_UPDATES :
2125 aAny <<= static_cast<bool>( pDocShell->GetDoc()->IsInReading() );
2126 break;
2127 case WID_DOC_BUILDID:
2128 aAny <<= maBuildId;
2129 break;
2130 case WID_DOC_HAS_VALID_SIGNATURES:
2131 aAny <<= hasValidSignatures();
2132 break;
2133 case WID_DOC_INTEROP_GRAB_BAG:
2134 getGrabBagItem(aAny);
2135 break;
2137 default:
2139 const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2140 rItem.QueryValue(aAny, pEntry->nMemberId);
2143 return aAny;
2146 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2147 const Reference< XPropertyChangeListener > & /*aListener*/)
2148 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
2150 OSL_FAIL("not implemented");
2153 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2154 const Reference< XPropertyChangeListener > & /*aListener*/)
2155 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
2157 OSL_FAIL("not implemented");
2160 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2161 const Reference< XVetoableChangeListener > & /*aListener*/)
2162 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
2164 OSL_FAIL("not implemented");
2167 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2168 const Reference< XVetoableChangeListener > & /*aListener*/)
2169 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
2171 OSL_FAIL("not implemented");
2174 Reference< XNameAccess > SwXTextDocument::getLinks() throw( RuntimeException, std::exception )
2176 if(!mxLinkTargetSupplier.is())
2178 mxLinkTargetSupplier = new SwXLinkTargetSupplier(*this);
2180 return mxLinkTargetSupplier;
2183 Reference< XEnumerationAccess > SwXTextDocument::getRedlines( ) throw(RuntimeException, std::exception)
2185 if(!mxXRedlines.is())
2187 mxXRedlines = new SwXRedlines(pDocShell->GetDoc());
2189 return mxXRedlines;
2192 void SwXTextDocument::NotifyRefreshListeners()
2194 // why does SwBaseShell not just call refresh? maybe because it's rSh is
2195 // (sometimes) a different shell than GetWrtShell()?
2196 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
2197 m_pImpl->m_RefreshListeners.notifyEach(
2198 & util::XRefreshListener::refreshed, ev);
2201 void SwXTextDocument::refresh() throw( RuntimeException, std::exception )
2203 SolarMutexGuard aGuard;
2204 if(!IsValid())
2205 throw RuntimeException();
2206 SwViewShell *pViewShell = pDocShell->GetWrtShell();
2207 NotifyRefreshListeners();
2208 if(pViewShell)
2209 pViewShell->CalcLayout();
2212 void SAL_CALL SwXTextDocument::addRefreshListener(
2213 const Reference<util::XRefreshListener> & xListener)
2214 throw (RuntimeException, std::exception)
2216 // no need to lock here as m_pImpl is const and container threadsafe
2217 m_pImpl->m_RefreshListeners.addInterface(xListener);
2220 void SAL_CALL SwXTextDocument::removeRefreshListener(
2221 const Reference<util::XRefreshListener> & xListener)
2222 throw (RuntimeException, std::exception)
2224 // no need to lock here as m_pImpl is const and container threadsafe
2225 m_pImpl->m_RefreshListeners.removeInterface(xListener);
2228 void SwXTextDocument::updateLinks( ) throw(RuntimeException, std::exception)
2230 SolarMutexGuard aGuard;
2231 if(!IsValid())
2232 throw RuntimeException();
2233 SwDoc* pDoc = pDocShell->GetDoc();
2234 sfx2::LinkManager& rLnkMan = pDoc->getIDocumentLinksAdministration().GetLinkManager();
2235 if( !rLnkMan.GetLinks().empty() )
2237 UnoActionContext aAction(pDoc);
2238 rLnkMan.UpdateAllLinks( false, false, true );
2242 //XPropertyState
2243 PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2244 throw (UnknownPropertyException, RuntimeException, std::exception)
2246 SolarMutexGuard aGuard;
2247 PropertyState eRet = PropertyState_DIRECT_VALUE;
2248 if(!IsValid())
2249 throw RuntimeException();
2250 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2252 if(!pEntry)
2253 throw UnknownPropertyException();
2254 switch(pEntry->nWID)
2256 case 0:default:break;
2258 return eRet;
2261 Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2262 throw (UnknownPropertyException, RuntimeException, std::exception)
2264 const sal_Int32 nCount = rPropertyNames.getLength();
2265 const OUString * pNames = rPropertyNames.getConstArray();
2266 Sequence < PropertyState > aRet ( nCount );
2267 PropertyState *pState = aRet.getArray();
2269 for ( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++)
2270 pState[nIndex] = getPropertyState( pNames[nIndex] );
2272 return aRet;
2275 void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2276 throw (UnknownPropertyException, RuntimeException, std::exception)
2278 SolarMutexGuard aGuard;
2279 if(!IsValid())
2280 throw RuntimeException();
2281 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2282 if(!pEntry)
2283 throw UnknownPropertyException();
2284 switch(pEntry->nWID)
2286 case 0:default:break;
2290 Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2291 throw (UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception)
2293 SolarMutexGuard aGuard;
2294 if(!IsValid())
2295 throw RuntimeException();
2296 const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2297 if(!pEntry)
2298 throw UnknownPropertyException();
2299 Any aAny;
2300 switch(pEntry->nWID)
2302 case 0:default:break;
2304 return aAny;
2307 static VclPtr< OutputDevice > lcl_GetOutputDevice( const SwPrintUIOptions &rPrintUIOptions )
2309 VclPtr< OutputDevice > pOut;
2311 uno::Any aAny( rPrintUIOptions.getValue( "RenderDevice" ));
2312 uno::Reference< awt::XDevice > xRenderDevice;
2313 aAny >>= xRenderDevice;
2314 if (xRenderDevice.is())
2316 VCLXDevice* pDevice = VCLXDevice::GetImplementation( xRenderDevice );
2317 pOut = pDevice ? pDevice->GetOutputDevice() : VclPtr< OutputDevice >();
2320 return pOut;
2323 static bool lcl_SeqHasProperty(
2324 const uno::Sequence< beans::PropertyValue >& rOptions,
2325 const sal_Char *pPropName )
2327 bool bRes = false;
2328 const sal_Int32 nLen = rOptions.getLength();
2329 const beans::PropertyValue *pProps = rOptions.getConstArray();
2330 for (sal_Int32 i = 0; i < nLen && !bRes; ++i)
2332 if (pProps[i].Name.equalsAscii( pPropName ))
2333 bRes = true;
2335 return bRes;
2338 SfxViewShell * SwXTextDocument::GetRenderView(
2339 bool &rbIsSwSrcView,
2340 const uno::Sequence< beans::PropertyValue >& rOptions,
2341 bool bIsPDFExport )
2343 // get view shell to use
2344 SfxViewShell *pView = nullptr;
2345 if (bIsPDFExport)
2346 pView = GuessViewShell( rbIsSwSrcView );
2347 else
2349 uno::Any aTmp;
2350 const sal_Int32 nLen = rOptions.getLength();
2351 const beans::PropertyValue *pProps = rOptions.getConstArray();
2352 for (sal_Int32 i = 0; i < nLen; ++i)
2354 if ( pProps[i].Name == "View" )
2356 aTmp = pProps[i].Value;
2357 break;
2361 uno::Reference< frame::XController > xController;
2362 if (aTmp >>= xController)
2364 OSL_ENSURE( xController.is(), "controller is empty!" );
2365 pView = GuessViewShell( rbIsSwSrcView, xController );
2368 return pView;
2372 * GetRenderDoc:
2373 * returns the document to be rendered, usually this will be the 'regular'
2374 * document but in case of PDF export of (multi-)selection it will
2375 * be a temporary document that gets created if not already done.
2376 * The rpView variable will be set (if not already done) to the used
2377 * SfxViewShell.
2379 SwDoc * SwXTextDocument::GetRenderDoc(
2380 SfxViewShell *&rpView,
2381 const uno::Any& rSelection,
2382 bool bIsPDFExport )
2384 SwDoc *pDoc = nullptr;
2386 uno::Reference< frame::XModel > xModel;
2387 rSelection >>= xModel;
2388 if (xModel == pDocShell->GetModel())
2389 pDoc = pDocShell->GetDoc();
2390 else
2392 OSL_ENSURE( !xModel.is(), "unexpected model found" );
2394 if (rSelection.hasValue()) // is anything selected ?
2396 // this part should only be called when a temporary document needs to be created,
2397 // for example for PDF export or printing of (multi-)selection only.
2399 if (!rpView)
2401 bool bIsSwSrcView = false;
2402 (void) bIsPDFExport;
2403 // aside from maybe PDF export the view should always have been provided!
2404 OSL_ENSURE( bIsPDFExport, "view is missing, guessing one..." );
2406 rpView = GuessViewShell( bIsSwSrcView );
2408 OSL_ENSURE( rpView, "SwViewShell missing" );
2409 // the view shell should be SwView for documents PDF export.
2410 // for the page preview no selection should be possible
2411 // (the export dialog does not allow for this option)
2412 if (rpView && dynamic_cast< const SwView *>( rpView ) != nullptr)
2414 if (!m_pRenderData)
2416 OSL_FAIL("GetRenderDoc: no renderdata");
2417 return nullptr;
2419 SwView *const pSwView(static_cast<SwView *>(rpView));
2420 SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell());
2421 if (!xDocSh.Is())
2423 xDocSh = pSwView->CreateTmpSelectionDoc();
2424 m_pRenderData->SetTempDocShell(xDocSh);
2426 if (xDocSh.Is())
2428 pDoc = static_cast<SwDocShell*>(&xDocSh)->GetDoc();
2429 rpView = pDoc->GetDocShell()->GetView();
2432 else
2434 OSL_FAIL("unexpected SwViewShell" );
2438 return pDoc;
2441 static void lcl_SavePrintUIOptionsToDocumentPrintData(
2442 SwDoc &rDoc,
2443 const SwPrintUIOptions &rPrintUIOptions,
2444 bool bIsPDFEXport )
2446 SwPrintData aDocPrintData( rDoc.getIDocumentDeviceAccess().getPrintData() );
2448 aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2449 aDocPrintData.SetPrintTable( true ); // for now it was decided that tables should always be printed
2450 aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2451 aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2452 aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2453 aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2454 aDocPrintData.SetPrintReverse( false ); /*handled by print dialog now*/
2455 aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2456 aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2457 aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2458 aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2459 aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2460 aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2461 aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2462 // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2463 // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2464 aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2465 aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2467 rDoc.getIDocumentDeviceAccess().setPrintData( aDocPrintData );
2470 sal_Int32 SAL_CALL SwXTextDocument::getRendererCount(
2471 const uno::Any& rSelection,
2472 const uno::Sequence< beans::PropertyValue >& rxOptions )
2473 throw (IllegalArgumentException, RuntimeException,
2474 std::exception)
2476 SolarMutexGuard aGuard;
2477 if(!IsValid())
2479 throw DisposedException( OUString(),
2480 static_cast< XTextDocument* >(this) );
2483 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2484 bool bIsSwSrcView = false;
2485 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2487 if (!bIsSwSrcView && !m_pRenderData)
2488 m_pRenderData = new SwRenderData;
2489 if (!m_pPrintUIOptions)
2490 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2491 bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2493 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2494 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2495 if (!pDoc || !pView)
2496 return 0;
2498 // save current UI options from the print dialog for the next call to that dialog
2499 lcl_SavePrintUIOptionsToDocumentPrintData( *pDoc, *m_pPrintUIOptions, bIsPDFExport );
2501 sal_Int32 nRet = 0;
2502 if (bIsSwSrcView)
2504 SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2505 VclPtr< OutputDevice> pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2506 nRet = rSwSrcView.PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2508 else
2510 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2512 // TODO/mba: we really need a generic way to get the SwViewShell!
2513 SwViewShell* pViewShell = nullptr;
2514 SwView* pSwView = dynamic_cast<SwView*>( pView );
2515 if ( pSwView )
2517 pViewShell = pSwView->GetWrtShellPtr();
2519 else
2521 if ( bIsPDFExport && bFormat )
2523 //create a hidden view to be able to export as PDF also in print preview
2524 //pView and pSwView are not changed intentionally!
2525 m_pHiddenViewFrame = SfxViewFrame::LoadHiddenDocument( *pRenderDocShell, 2 );
2526 pViewShell = static_cast<SwView*>(m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2528 else
2529 pViewShell = static_cast<SwPagePreview*>(pView)->GetViewShell();
2532 if (!pViewShell || !pViewShell->GetLayout())
2533 return 0;
2535 if (bFormat)
2537 // #i38289
2538 if( pViewShell->GetViewOptions()->getBrowseMode() ||
2539 pViewShell->GetViewOptions()->IsWhitespaceHidden() )
2541 SwViewOption aOpt( *pViewShell->GetViewOptions() );
2542 aOpt.setBrowseMode( false );
2543 aOpt.SetHideWhitespaceMode( false );
2544 pViewShell->ApplyViewOptions( aOpt );
2545 if (pSwView)
2547 pSwView->RecheckBrowseMode();
2551 // reformatting the document for printing will show the changes in the view
2552 // which is likely to produce many unwanted and not nice to view actions.
2553 // We don't want that! Thus we disable updating of the view.
2554 pViewShell->StartAction();
2556 if (pSwView)
2558 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2559 m_pRenderData->ViewOptionAdjustStop();
2560 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2562 m_pRenderData->ViewOptionAdjustStart(
2563 *pViewShell, *pViewShell->GetViewOptions() );
2567 m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
2568 m_pPrintUIOptions, bIsPDFExport );
2570 if (pSwView)
2572 // PDF export should not make use of the SwPrtOptions
2573 const SwPrintData *pPrtOptions = (bIsPDFExport)
2574 ? nullptr : m_pRenderData->GetSwPrtOptions();
2575 bool setShowPlaceHoldersInPDF = false;
2576 if(bIsPDFExport)
2578 const sal_Int32 nLen = rxOptions.getLength();
2579 const beans::PropertyValue *pProps = rxOptions.getConstArray();
2580 for (sal_Int32 i = 0; i < nLen; ++i)
2582 if (pProps[i].Name == "ExportPlaceholders")
2584 pProps[i].Value >>= setShowPlaceHoldersInPDF;
2585 break;
2589 m_pRenderData->ViewOptionAdjust( pPrtOptions, setShowPlaceHoldersInPDF );
2592 // since printing now also use the API for PDF export this option
2593 // should be set for printing as well ...
2594 pViewShell->SetPDFExportOption( true );
2595 bool bOrigStatus = pRenderDocShell->IsEnableSetModified();
2596 // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2597 bool bStateChanged = false;
2598 if ( bOrigStatus && !SvtPrintWarningOptions().IsModifyDocumentOnPrintingAllowed() )
2600 pRenderDocShell->EnableSetModified( false );
2601 bStateChanged = true;
2604 // #122919# Force field update before PDF export
2605 pViewShell->SwViewShell::UpdateFields(true);
2606 if( bStateChanged )
2607 pRenderDocShell->EnableSetModified();
2609 // there is some redundancy between those two function calls, but right now
2610 // there is no time to sort this out.
2611 //TODO: check what exactly needs to be done and make just one function for that
2612 pViewShell->CalcLayout();
2613 pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2615 pViewShell->SetPDFExportOption( false );
2617 // enable view again
2618 pViewShell->EndAction();
2621 const sal_Int32 nPageCount = pViewShell->GetPageCount();
2623 // get number of pages to be rendered
2625 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2626 if (bPrintProspect)
2628 SwDoc::CalculatePagePairsForProspectPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, nPageCount );
2629 nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2631 else
2633 const SwPostItMode nPostItMode = static_cast<SwPostItMode>( m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 ) );
2634 if (nPostItMode != SwPostItMode::NONE)
2636 VclPtr< OutputDevice > pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2637 m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
2640 // get set of valid document pages (according to the current settings)
2641 // and their start frames
2642 SwDoc::CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2644 if (nPostItMode != SwPostItMode::NONE)
2646 SwDoc::UpdatePagesForPrintingWithPostItData( *m_pRenderData,
2647 *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2650 nRet = m_pRenderData->GetPagesToPrint().size();
2653 OSL_ENSURE( nRet >= 0, "negative number of pages???" );
2655 return nRet;
2658 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2659 sal_Int32 nRenderer,
2660 const uno::Any& rSelection,
2661 const uno::Sequence< beans::PropertyValue >& rxOptions )
2662 throw (IllegalArgumentException, RuntimeException,
2663 std::exception)
2665 SolarMutexGuard aGuard;
2666 if(!IsValid())
2668 throw DisposedException( OUString(),
2669 static_cast< XTextDocument* >(this) );
2672 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2673 bool bIsSwSrcView = false;
2674 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2676 // m_pRenderData should NOT be created here!
2677 // That should only be done in getRendererCount. If this function is called before
2678 // getRendererCount was called then the caller will probably just retrieve the extra UI options
2679 // and is not interested in getting valid information about the other data that would
2680 // otherwise be provided here!
2681 // if( ! m_pRenderData )
2682 // m_pRenderData = new SwRenderData;
2683 if (!m_pPrintUIOptions)
2684 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2685 m_pPrintUIOptions->processProperties( rxOptions );
2686 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2687 const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2688 const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup" );
2690 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2691 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2692 if (!pDoc || !pView)
2693 return uno::Sequence< beans::PropertyValue >();
2695 // due to #110067# (document page count changes sometimes during
2696 // PDF export/printing) we can not check for the upper bound properly.
2697 // Thus instead of throwing the exception we silently return.
2698 if (0 > nRenderer)
2699 throw IllegalArgumentException();
2701 // TODO/mba: we really need a generic way to get the SwViewShell!
2702 SwViewShell* pVwSh = nullptr;
2703 SwView* pSwView = dynamic_cast<SwView*>( pView );
2704 if ( pSwView )
2705 pVwSh = pSwView->GetWrtShellPtr();
2706 else
2707 pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2709 sal_Int32 nMaxRenderer = 0;
2710 if (!bIsSwSrcView && m_pRenderData)
2712 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2713 nMaxRenderer = bPrintProspect?
2714 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2715 m_pRenderData->GetPagesToPrint().size() - 1;
2717 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2718 // we obmit checking of the upper bound in this case.
2719 if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2720 return uno::Sequence< beans::PropertyValue >();
2722 uno::Sequence< beans::PropertyValue > aRenderer;
2723 if (m_pRenderData)
2725 // #i114210#
2726 // determine the correct page number from the renderer index
2727 // #i114875
2728 // consider brochure print
2729 const sal_Int32 nPage = bPrintProspect
2730 ? nRenderer + 1
2731 : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2733 // get paper tray to use ...
2734 sal_Int32 nPrinterPaperTray = -1;
2735 if (! bPrintPaperFromSetup)
2737 // ... from individual page style (see the page tab in Format/Page dialog)
2738 const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2739 std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2740 if (aIt != rPaperTrays.end())
2741 nPrinterPaperTray = aIt->second;
2744 awt::Size aPageSize;
2745 awt::Size aPreferredPageSize;
2746 Size aTmpSize;
2747 if (bIsSwSrcView || bPrintProspect)
2749 // for printing of HTML source code and prospect printing we should use
2750 // the printers paper size since
2751 // a) HTML source view has no page size
2752 // b) prospect printing has a different page size from the documents page
2753 // since two document pages will get rendered on one printer page
2755 // since PageIncludesNonprintableArea will be set to true we can return the
2756 // printers paper size here.
2757 // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2758 // case we won't get an OutputDevice here, but then the caller also has no need
2759 // for the correct PageSisze right now...
2760 VclPtr< Printer > pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ).get());
2761 if (pPrinter)
2763 // HTML source view and prospect adapt to the printer's paper size
2764 aTmpSize = pPrinter->GetPaperSize();
2765 aTmpSize = OutputDevice::LogicToLogic( aTmpSize,
2766 pPrinter->GetMapMode(), MapMode( MAP_100TH_MM ));
2767 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2768 #if 0
2769 // #i115048# it seems users didn't like getting double the formatted page size
2770 // revert to "old" behavior scaling to the current paper size of the printer
2771 if (bPrintProspect)
2773 // we just state what output size we would need
2774 // which may cause vcl to set that page size on the printer
2775 // (if available and not overridden by the user)
2776 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2777 aPreferredPageSize = awt::Size ( convertTwipToMm100( 2 * aTmpSize.Width() ),
2778 convertTwipToMm100( aTmpSize.Height() ));
2780 #else
2781 if( bPrintProspect )
2783 // just switch to an appropriate portrait/landscape format
2784 // FIXME: brochure printing with landscape pages puts the
2785 // pages next to each other, so landscape is currently always
2786 // the better choice
2787 if( aPageSize.Width < aPageSize.Height )
2789 aPreferredPageSize.Width = aPageSize.Height;
2790 aPreferredPageSize.Height = aPageSize.Width;
2793 #endif
2796 else
2798 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2799 aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
2800 convertTwipToMm100( aTmpSize.Height() ));
2803 sal_Int32 nLen = 2;
2804 aRenderer.realloc(2);
2805 aRenderer[0].Name = "PageSize";
2806 aRenderer[0].Value <<= aPageSize;
2807 aRenderer[1].Name = "PageIncludesNonprintableArea";
2808 aRenderer[1].Value <<= true;
2809 if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2811 ++nLen;
2812 aRenderer.realloc( nLen );
2813 aRenderer[ nLen - 1 ].Name = "PreferredPageSize";
2814 aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2816 if (nPrinterPaperTray >= 0)
2818 ++nLen;
2819 aRenderer.realloc( nLen );
2820 aRenderer[ nLen - 1 ].Name = "PrinterPaperTray";
2821 aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2825 // #i117783#
2826 if ( bApplyPagePrintSettingsFromXPagePrintable )
2828 const SwPagePreviewPrtData* pPagePrintSettings =
2829 pDocShell->GetDoc()->GetPreviewPrtData();
2830 if ( pPagePrintSettings &&
2831 ( pPagePrintSettings->GetRow() > 1 ||
2832 pPagePrintSettings->GetCol() > 1 ) )
2834 // extend render data by page print settings attributes
2835 sal_Int32 nLen = aRenderer.getLength();
2836 const sal_Int32 nRenderDataIdxStart = nLen;
2837 nLen += 9;
2838 aRenderer.realloc( nLen );
2839 // put page print settings attribute into render data
2840 const sal_Int32 nRow = pPagePrintSettings->GetRow();
2841 aRenderer[ nRenderDataIdxStart + 0 ].Name = "NUpRows";
2842 aRenderer[ nRenderDataIdxStart + 0 ].Value <<= ( nRow > 1 ? nRow : 1 );
2843 const sal_Int32 nCol = pPagePrintSettings->GetCol();
2844 aRenderer[ nRenderDataIdxStart + 1 ].Name = "NUpColumns";
2845 aRenderer[ nRenderDataIdxStart + 1 ].Value <<= ( nCol > 1 ? nCol : 1 );
2846 aRenderer[ nRenderDataIdxStart + 2 ].Name = "NUpPageMarginLeft";
2847 aRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
2848 aRenderer[ nRenderDataIdxStart + 3 ].Name = "NUpPageMarginRight";
2849 aRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
2850 aRenderer[ nRenderDataIdxStart + 4 ].Name = "NUpPageMarginTop";
2851 aRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
2852 aRenderer[ nRenderDataIdxStart + 5 ].Name = "NUpPageMarginBottom";
2853 aRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
2854 aRenderer[ nRenderDataIdxStart + 6 ].Name = "NUpHorizontalSpacing";
2855 aRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
2856 aRenderer[ nRenderDataIdxStart + 7 ].Name = "NUpVerticalSpacing";
2857 aRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
2859 Printer* pPrinter = pDocShell->GetDoc()->getIDocumentDeviceAccess().getPrinter( false );
2860 if ( pPrinter )
2862 awt::Size aNewPageSize;
2863 const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) );
2864 aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
2865 if ( ( pPagePrintSettings->GetLandscape() &&
2866 aPageSize.Width() < aPageSize.Height() ) ||
2867 ( !pPagePrintSettings->GetLandscape() &&
2868 aPageSize.Width() > aPageSize.Height() ) )
2870 aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
2872 aRenderer[ nRenderDataIdxStart + 8 ].Name = "NUpPaperSize";
2873 aRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
2878 bApplyPagePrintSettingsFromXPagePrintable = false;
2881 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2883 return aRenderer;
2886 SfxViewShell * SwXTextDocument::GuessViewShell(
2887 /* out */ bool &rbIsSwSrcView,
2888 const uno::Reference< css::frame::XController >& rController )
2890 // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2891 // must not be used (see comment from MBA)
2893 SfxViewShell *pView = nullptr;
2894 SwView *pSwView = nullptr;
2895 SwPagePreview *pSwPagePreview = nullptr;
2896 SwSrcView *pSwSrcView = nullptr;
2897 SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, false );
2899 // look for the view shell with the same controller in use,
2900 // otherwise look for a suitable view, preferably a SwView,
2901 // if that one is not found use a SwPagePreview if found.
2902 while (pFrame)
2904 pView = pFrame->GetViewShell();
2905 pSwView = dynamic_cast< SwView * >(pView);
2906 pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2907 if (!pSwPagePreview)
2908 pSwPagePreview = dynamic_cast< SwPagePreview * >(pView);
2909 if (rController.is())
2911 if (pView && pView->GetController() == rController)
2912 break;
2914 else if (pSwView || pSwSrcView)
2915 break;
2916 pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, false );
2919 OSL_ENSURE( pSwView || pSwPagePreview || pSwSrcView, "failed to get view shell" );
2920 if (pView)
2921 rbIsSwSrcView = pSwSrcView != nullptr;
2922 return pView;
2925 void SAL_CALL SwXTextDocument::render(
2926 sal_Int32 nRenderer,
2927 const uno::Any& rSelection,
2928 const uno::Sequence< beans::PropertyValue >& rxOptions )
2929 throw (IllegalArgumentException, RuntimeException,
2930 std::exception)
2932 SolarMutexGuard aGuard;
2933 if(!IsValid())
2935 throw DisposedException( OUString(),
2936 static_cast< XTextDocument* >(this) );
2939 // due to #110067# (document page count changes sometimes during
2940 // PDF export/printing) we can not check for the upper bound properly.
2941 // Thus instead of throwing the exception we silently return.
2942 if (0 > nRenderer)
2943 throw IllegalArgumentException();
2945 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2946 bool bIsSwSrcView = false;
2947 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2949 OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
2950 OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
2951 if (!bIsSwSrcView && !m_pRenderData)
2952 m_pRenderData = new SwRenderData;
2953 if (!m_pPrintUIOptions)
2954 m_pPrintUIOptions = lcl_GetPrintUIOptions( pDocShell, pView );
2955 m_pPrintUIOptions->processProperties( rxOptions );
2956 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2957 const bool bLastPage = m_pPrintUIOptions->getBoolValue( "IsLastPage" );
2959 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2960 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2961 if (pDoc && pView)
2963 sal_Int32 nMaxRenderer = 0;
2964 if (!bIsSwSrcView)
2966 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2967 nMaxRenderer = bPrintProspect?
2968 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2969 m_pRenderData->GetPagesToPrint().size() - 1;
2971 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2972 // we obmit checking of the upper bound in this case.
2973 if (bIsSwSrcView || nRenderer <= nMaxRenderer)
2975 if (bIsSwSrcView)
2977 SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2978 VclPtr< OutputDevice > pOutDev = lcl_GetOutputDevice( *m_pPrintUIOptions );
2979 rSwSrcView.PrintSource(pOutDev, nRenderer + 1, false);
2981 else
2983 // the view shell should be SwView for documents PDF export
2984 // or SwPagePreview for PDF export of the page preview
2985 //!! (check for SwView first as in GuessViewShell) !!
2986 OSL_ENSURE( pView, "!! view missing !!" );
2987 SwViewShell* pVwSh = nullptr;
2988 if (pView)
2990 // TODO/mba: we really need a generic way to get the SwViewShell!
2991 SwView* pSwView = dynamic_cast<SwView*>( pView );
2992 if ( pSwView )
2993 pVwSh = pSwView->GetWrtShellPtr();
2994 else
2995 pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2998 // get output device to use
2999 VclPtr< OutputDevice > pOut = lcl_GetOutputDevice( *m_pPrintUIOptions );
3001 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
3003 const OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange" );
3004 const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage" );
3005 bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
3007 OSL_ENSURE(( dynamic_cast< const SwView *>( pView ) != nullptr && m_pRenderData->IsViewOptionAdjust())
3008 || (dynamic_cast< const SwView *>( pView ) == nullptr && !m_pRenderData->IsViewOptionAdjust()),
3009 "SwView / SwViewOptionAdjust_Impl availability mismatch" );
3011 // since printing now also use the API for PDF export this option
3012 // should be set for printing as well ...
3013 pVwSh->SetPDFExportOption( true );
3015 // #i12836# enhanced pdf export
3017 // First, we have to export hyperlinks, notes, and outline to pdf.
3018 // During this process, additional information required for tagging
3019 // the pdf file are collected, which are evaulated during painting.
3021 SwWrtShell* pWrtShell = dynamic_cast< const SwView *>( pView ) != nullptr ?
3022 static_cast<SwView*>(pView)->GetWrtShellPtr() :
3023 nullptr;
3025 SwPrintData const& rSwPrtOptions =
3026 *m_pRenderData->GetSwPrtOptions();
3028 if (bIsPDFExport && bFirstPage && pWrtShell)
3030 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
3033 if (bPrintProspect)
3034 pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
3035 else // normal printing and PDF export
3036 pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer );
3038 // #i35176#
3040 // After printing the last page, we take care for the links coming
3041 // from the EditEngine. The links are generated during the painting
3042 // process, but the destinations are still missing.
3044 if (bIsPDFExport && bLastPage && pWrtShell)
3046 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, true, rSwPrtOptions );
3049 pVwSh->SetPDFExportOption( false );
3051 // last page to be rendered? (not necessarily the last page of the document)
3052 // -> do clean-up of data
3053 if (bLastPage)
3055 // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3056 // of the shell, which might get destroyed in lcl_DisposeView!
3057 if (m_pRenderData->IsViewOptionAdjust())
3058 m_pRenderData->ViewOptionAdjustStop();
3060 if (m_pRenderData->HasPostItData())
3061 m_pRenderData->DeletePostItData();
3062 if (m_pHiddenViewFrame)
3064 lcl_DisposeView( m_pHiddenViewFrame, pDocShell );
3065 m_pHiddenViewFrame = nullptr;
3067 // prevent crash described in #i108805
3068 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3069 SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3070 pSet->Put( SfxBoolItem( SID_HIDDEN, false ) );
3078 if( bLastPage )
3080 delete m_pRenderData; m_pRenderData = nullptr;
3081 delete m_pPrintUIOptions; m_pPrintUIOptions = nullptr;
3085 // xforms::XFormsSupplier
3086 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3087 throw( RuntimeException, std::exception )
3089 SolarMutexGuard aGuard;
3090 if ( !pDocShell )
3091 throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
3092 SwDoc* pDoc = pDocShell->GetDoc();
3093 return pDoc->getXForms();
3096 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3097 throw ( uno::RuntimeException, std::exception )
3099 SolarMutexGuard aGuard;
3100 if (!IsValid())
3102 throw DisposedException("SwXTextDocument not valid",
3103 static_cast<XTextDocument*>(this));
3106 return SwUnoCursorHelper::CreateFlatParagraphIterator(
3107 *pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
3110 uno::Reference< util::XCloneable > SwXTextDocument::createClone( ) throw (uno::RuntimeException, std::exception)
3112 SolarMutexGuard aGuard;
3113 if(!IsValid())
3114 throw RuntimeException();
3116 // create a new document - hidden - copy the storage and return it
3117 // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3118 // and thus SfxObjectShellLock is not allowed here
3119 // the model holds reference to the shell, so the shell will not destructed at the end of method
3120 SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false, false);
3121 uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3122 uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3123 uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3124 storeToStorage( xNewStorage, aTempMediaDescriptor );
3125 uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3126 xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3127 return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3130 void SwXTextDocument::paintTile( VirtualDevice &rDevice,
3131 int nOutputWidth, int nOutputHeight,
3132 int nTilePosX, int nTilePosY,
3133 long nTileWidth, long nTileHeight )
3135 SwDoc* pDoc = pDocShell->GetDoc();
3136 SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
3137 pViewShell->PaintTile(rDevice, nOutputWidth, nOutputHeight,
3138 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3141 Size SwXTextDocument::getDocumentSize()
3143 SwDoc* pDoc = pDocShell->GetDoc();
3144 SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
3145 Size aDocSize = pViewShell->GetDocSize();
3147 return Size(aDocSize.Width() + 2L * DOCUMENTBORDER,
3148 aDocSize.Height() + 2L * DOCUMENTBORDER);
3151 void SwXTextDocument::setPart(int nPart)
3153 SolarMutexGuard aGuard;
3155 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3156 if (!pWrtShell)
3157 return;
3159 pWrtShell->GotoPage(nPart + 1, true);
3162 int SwXTextDocument::getParts()
3164 SolarMutexGuard aGuard;
3166 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3167 if (!pWrtShell)
3168 return 0;
3170 return pWrtShell->GetPageCnt();
3173 OUString SwXTextDocument::getPartPageRectangles()
3175 SolarMutexGuard aGuard;
3177 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3178 if (!pWrtShell)
3179 return OUString();
3181 return pWrtShell->getPageRectangles();
3184 void SwXTextDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard)
3186 SolarMutexGuard aGuard;
3188 pDocShell->GetView()->GetEditWin().SetClipboard(xClipboard);
3191 bool SwXTextDocument::isMimeTypeSupported()
3193 SolarMutexGuard aGuard;
3195 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3196 if (!pWrtShell)
3197 return false;
3199 TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromSystemClipboard(&pWrtShell->GetView().GetEditWin()));
3200 if (SdrView* pSdrView = pWrtShell->GetDrawView())
3202 if (pSdrView->GetTextEditObject())
3203 // Editing shape text
3204 return EditEngine::HasValidData(aDataHelper.GetTransferable());
3207 return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
3210 void SwXTextDocument::setClientVisibleArea(const Rectangle& rRectangle)
3212 SwView* pView = pDocShell->GetView();
3213 if (!pView)
3214 return;
3216 // set the PgUp/PgDown offset
3217 pView->ForcePageUpDownOffset(2 * rRectangle.GetHeight() / 3);
3220 Pointer SwXTextDocument::getPointer()
3222 SolarMutexGuard aGuard;
3224 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3225 if (!pWrtShell)
3226 return Pointer();
3228 return pWrtShell->GetView().GetEditWin().GetPointer();
3231 int SwXTextDocument::getPart()
3233 SolarMutexGuard aGuard;
3235 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3236 if (!pWrtShell)
3237 return 0;
3239 sal_uInt16 nPage, nLogPage;
3240 OUString sDisplay;
3241 pWrtShell->GetPageNumber(-1, pWrtShell->IsCursorVisible(), nPage, nLogPage, sDisplay);
3243 return nPage - 1;
3246 OUString SwXTextDocument::getPartName(int nPart)
3248 SolarMutexGuard aGuard;
3250 return OUString(SW_RES(STR_PAGE)) + OUString::number(nPart + 1);
3253 OUString SwXTextDocument::getPartHash(int nPart)
3255 SolarMutexGuard aGuard;
3256 OUString sPart(OUString(SW_RES(STR_PAGE)) + OUString::number(nPart + 1));
3258 return OUString::number(sPart.hashCode());
3261 void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
3263 SolarMutexGuard aGuard;
3265 SwDoc* pDoc = pDocShell->GetDoc();
3266 SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
3268 bool bBookMode = false;
3269 sal_Int16 nColumns = 1;
3271 SwView* pView = pDocShell->GetView();
3272 if (!pView)
3273 return;
3275 pView->SetViewLayout(nColumns, bBookMode, true);
3277 // Tiled rendering defaults.
3278 SwViewOption aViewOption(*pViewShell->GetViewOptions());
3279 aViewOption.SetHardBlank(false);
3280 for (sal_Int32 i = 0; i < rArguments.getLength(); ++i)
3282 const beans::PropertyValue& rValue = rArguments[i];
3283 if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has<bool>())
3284 aViewOption.SetHideWhitespaceMode(rValue.Value.get<bool>());
3285 else if (rValue.Name == ".uno:ShowBorderShadow" && rValue.Value.has<bool>())
3286 SwViewOption::SetAppearanceFlag(ViewOptFlags::Shadow , rValue.Value.get<bool>());
3288 pViewShell->ApplyViewOptions(aViewOption);
3290 // Disable map mode, so that it's possible to send mouse event coordinates
3291 // directly in twips.
3292 SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3293 rEditWin.EnableMapMode(false);
3295 // when the "This document may contain formatting or content that cannot
3296 // be saved..." dialog appears, it is auto-cancelled with tiled rendering,
3297 // causing 'Save' being disabled; so let's always save to the original
3298 // format
3299 SvtSaveOptions().SetWarnAlienFormat(false);
3302 void SwXTextDocument::registerCallback(LibreOfficeKitCallback pCallback, void* pData)
3304 SolarMutexGuard aGuard;
3306 SwDoc* pDoc = pDocShell->GetDoc();
3307 SwViewShell* pViewShell = pDoc->getIDocumentLayoutAccess().GetCurrentViewShell();
3308 pViewShell->registerLibreOfficeKitCallback(pCallback, pData);
3311 void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
3313 SolarMutexGuard aGuard;
3315 SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3316 KeyEvent aEvent(nCharCode, nKeyCode, 0);
3318 switch (nType)
3320 case LOK_KEYEVENT_KEYINPUT:
3321 rEditWin.KeyInput(aEvent);
3322 break;
3323 case LOK_KEYEVENT_KEYUP:
3324 rEditWin.KeyUp(aEvent);
3325 break;
3326 default:
3327 assert(false);
3328 break;
3332 void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
3334 SolarMutexGuard aGuard;
3336 SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3337 Point aPos(nX , nY);
3338 MouseEvent aEvent(aPos, nCount, MouseEventModifiers::SIMPLECLICK, nButtons, nModifier);
3340 switch (nType)
3342 case LOK_MOUSEEVENT_MOUSEBUTTONDOWN:
3343 rEditWin.LogicMouseButtonDown(aEvent);
3345 if (nButtons & MOUSE_RIGHT)
3347 const CommandEvent aCEvt(aPos, CommandEventId::ContextMenu, true, nullptr);
3348 rEditWin.Command(aCEvt);
3350 break;
3351 case LOK_MOUSEEVENT_MOUSEBUTTONUP:
3352 rEditWin.LogicMouseButtonUp(aEvent);
3353 break;
3354 case LOK_MOUSEEVENT_MOUSEMOVE:
3355 rEditWin.LogicMouseMove(aEvent);
3356 break;
3357 default:
3358 assert(false);
3359 break;
3363 void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
3365 SolarMutexGuard aGuard;
3367 SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3368 switch (nType)
3370 case LOK_SETTEXTSELECTION_START:
3371 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/false, /*bClearMark=*/false);
3372 break;
3373 case LOK_SETTEXTSELECTION_END:
3374 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/false);
3375 break;
3376 case LOK_SETTEXTSELECTION_RESET:
3377 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/true);
3378 break;
3379 default:
3380 assert(false);
3381 break;
3385 OString SwXTextDocument::getTextSelection(const char* pMimeType, OString& rUsedMimeType)
3387 SolarMutexGuard aGuard;
3389 uno::Reference<datatransfer::XTransferable> xTransferable;
3391 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3392 if (SdrView* pSdrView = pWrtShell->GetDrawView())
3394 if (pSdrView->GetTextEditObject())
3396 // Editing shape text
3397 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
3398 xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3402 if (SwPostItMgr* pPostItMgr = pDocShell->GetView()->GetPostItMgr())
3404 if (sw::sidebarwindows::SwSidebarWin* pWin = pPostItMgr->GetActiveSidebarWin())
3406 // Editing postit text.
3407 EditView& rEditView = pWin->GetOutlinerView()->GetEditView();
3408 xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3412 if (!xTransferable.is())
3413 xTransferable = new SwTransferable(*pWrtShell);
3415 // Take care of UTF-8 text here.
3416 OString aMimeType(pMimeType);
3417 bool bConvert = false;
3418 sal_Int32 nIndex = 0;
3419 if (aMimeType.getToken(0, ';', nIndex) == "text/plain")
3421 if (aMimeType.getToken(0, ';', nIndex) == "charset=utf-8")
3423 aMimeType = "text/plain;charset=utf-16";
3424 bConvert = true;
3428 datatransfer::DataFlavor aFlavor;
3429 aFlavor.MimeType = OUString::fromUtf8(aMimeType.getStr());
3430 if (aMimeType == "text/plain;charset=utf-16")
3431 aFlavor.DataType = cppu::UnoType<OUString>::get();
3432 else
3433 aFlavor.DataType = cppu::UnoType< uno::Sequence<sal_Int8> >::get();
3435 if (!xTransferable->isDataFlavorSupported(aFlavor))
3436 return OString();
3438 uno::Any aAny(xTransferable->getTransferData(aFlavor));
3440 OString aRet;
3441 if (aFlavor.DataType == cppu::UnoType<OUString>::get())
3443 OUString aString;
3444 aAny >>= aString;
3445 if (bConvert)
3446 aRet = OUStringToOString(aString, RTL_TEXTENCODING_UTF8);
3447 else
3448 aRet = OString(reinterpret_cast<const sal_Char *>(aString.getStr()), aString.getLength() * sizeof(sal_Unicode));
3450 else
3452 uno::Sequence<sal_Int8> aSequence;
3453 aAny >>= aSequence;
3454 aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
3457 rUsedMimeType = pMimeType;
3458 return aRet;
3461 void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
3463 SolarMutexGuard aGuard;
3465 SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3466 switch (nType)
3468 case LOK_SETGRAPHICSELECTION_START:
3469 rEditWin.SetGraphicTwipPosition(/*bStart=*/true, Point(nX, nY));
3470 break;
3471 case LOK_SETGRAPHICSELECTION_END:
3472 rEditWin.SetGraphicTwipPosition(/*bStart=*/false, Point(nX, nY));
3473 break;
3474 default:
3475 assert(false);
3476 break;
3480 void SwXTextDocument::resetSelection()
3482 SolarMutexGuard aGuard;
3484 SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3485 pWrtShell->ResetSelect(nullptr, false);
3488 void SAL_CALL SwXTextDocument::paintTile( const ::css::uno::Any& Parent, ::sal_Int32 nOutputWidth, ::sal_Int32 nOutputHeight, ::sal_Int32 nTilePosX, ::sal_Int32 nTilePosY, ::sal_Int32 nTileWidth, ::sal_Int32 nTileHeight ) throw (::css::uno::RuntimeException, ::std::exception)
3490 SystemGraphicsData aData;
3491 aData.nSize = sizeof(SystemGraphicsData);
3492 #if defined(_WIN32)
3493 sal_Int64 nWindowHandle;
3494 Parent >>= nWindowHandle;
3495 aData.hWnd = (HWND) nWindowHandle;
3496 ScopedVclPtrInstance<VirtualDevice> xDevice(&aData, Size(1, 1), DeviceFormat::DEFAULT);
3497 paintTile(*xDevice, nOutputWidth, nOutputHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3498 #else
3499 // TODO: support other platforms
3500 (void)Parent;
3501 (void)nOutputWidth;
3502 (void)nOutputHeight;
3503 (void)nTilePosX;
3504 (void)nTilePosY;
3505 (void)nTileWidth;
3506 (void)nTileHeight;
3507 #endif
3510 void * SAL_CALL SwXTextDocument::operator new( size_t t) throw()
3512 return SwXTextDocumentBaseClass::operator new(t);
3515 void SAL_CALL SwXTextDocument::operator delete( void * p) throw()
3517 SwXTextDocumentBaseClass::operator delete(p);
3521 * retrieve languages already used in current document
3523 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3524 ::sal_Int16 nScriptTypes,
3525 ::sal_Int16 nMaxCount )
3526 throw (lang::IllegalArgumentException,
3527 uno::RuntimeException,
3528 std::exception)
3530 SolarMutexGuard aGuard;
3532 // possible canonical values for nScriptTypes
3533 // any bit wise combination is allowed
3534 const sal_Int16 nLatin = 0x001;
3535 const sal_Int16 nAsian = 0x002;
3536 const sal_Int16 nComplex = 0x004;
3538 // script types for which to get the languages
3539 const bool bLatin = 0 != (nScriptTypes & nLatin);
3540 const bool bAsian = 0 != (nScriptTypes & nAsian);
3541 const bool bComplex = 0 != (nScriptTypes & nComplex);
3543 if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3544 throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
3545 if (!pDocShell)
3546 throw DisposedException();
3547 SwDoc* pDoc = pDocShell->GetDoc();
3549 // avoid duplicate values
3550 std::set< LanguageType > aAllLangs;
3552 //USER STYLES
3554 const SwCharFormats *pFormats = pDoc->GetCharFormats();
3555 for(size_t i = 0; i < pFormats->size(); ++i)
3557 const SwAttrSet &rAttrSet = (*pFormats)[i]->GetAttrSet();
3558 LanguageType nLang = LANGUAGE_DONTKNOW;
3559 if (bLatin)
3561 nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3562 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3563 aAllLangs.insert( nLang );
3565 if (bAsian)
3567 nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3568 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3569 aAllLangs.insert( nLang );
3571 if (bComplex)
3573 nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3574 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3575 aAllLangs.insert( nLang );
3579 const SwTextFormatColls *pColls = pDoc->GetTextFormatColls();
3580 for (size_t i = 0; i < pColls->size(); ++i)
3582 const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3583 LanguageType nLang = LANGUAGE_DONTKNOW;
3584 if (bLatin)
3586 nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3587 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3588 aAllLangs.insert( nLang );
3590 if (bAsian)
3592 nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3593 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3594 aAllLangs.insert( nLang );
3596 if (bComplex)
3598 nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3599 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3600 aAllLangs.insert( nLang );
3604 //AUTO STYLES
3605 const IStyleAccess::SwAutoStyleFamily aFam[2] =
3607 IStyleAccess::AUTO_STYLE_CHAR,
3608 IStyleAccess::AUTO_STYLE_PARA
3610 for (IStyleAccess::SwAutoStyleFamily i : aFam)
3612 std::vector< std::shared_ptr<SfxItemSet> > rStyles;
3613 pDoc->GetIStyleAccess().getAllStyles(rStyles, i);
3614 while (!rStyles.empty())
3616 std::shared_ptr<SfxItemSet> pStyle = rStyles.back();
3617 rStyles.pop_back();
3618 const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
3620 LanguageType nLang = LANGUAGE_DONTKNOW;
3621 if (bLatin)
3623 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, false )).GetLanguage();
3624 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3625 aAllLangs.insert( nLang );
3627 if (bAsian)
3629 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, false )).GetLanguage();
3630 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3631 aAllLangs.insert( nLang );
3633 if (bComplex)
3635 nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, false )).GetLanguage();
3636 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3637 aAllLangs.insert( nLang );
3642 //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3643 SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
3644 SdrView *pSdrView = pWrtSh->GetDrawView();
3646 if( pSdrView )
3648 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3649 if(pOutliner)
3651 EditEngine& rEditEng = (EditEngine&)pOutliner->GetEditEngine();
3652 sal_Int32 nParCount = pOutliner->GetParagraphCount();
3653 for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
3655 //every paragraph
3656 std::vector<sal_Int32> aPortions;
3657 rEditEng.GetPortions( nPar, aPortions );
3659 for ( size_t nPos = aPortions.size(); nPos; )
3661 //every position
3662 --nPos;
3663 sal_Int32 nEnd = aPortions[ nPos ];
3664 sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
3665 ESelection aSelection( nPar, nStart, nPar, nEnd );
3666 SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3668 LanguageType nLang = LANGUAGE_DONTKNOW;
3669 if (bLatin)
3671 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, false )).GetLanguage();
3672 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3673 aAllLangs.insert( nLang );
3675 if (bAsian)
3677 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, false )).GetLanguage();
3678 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3679 aAllLangs.insert( nLang );
3681 if (bComplex)
3683 nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, false )).GetLanguage();
3684 if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3685 aAllLangs.insert( nLang );
3691 // less than nMaxCount languages
3692 if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3693 nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3695 // build return value
3696 uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3697 lang::Locale* pLanguage = aLanguages.getArray();
3698 if (nMaxCount > 0)
3700 sal_Int32 nCount = 0;
3701 for (std::set< LanguageType >::const_iterator it = aAllLangs.begin(); it != aAllLangs.end(); ++it)
3703 if (nCount >= nMaxCount)
3704 break;
3705 if (LANGUAGE_NONE != *it)
3707 pLanguage[nCount] = LanguageTag::convertToLocale( *it );
3708 pLanguage[nCount].Language = SvtLanguageTable::GetLanguageString( *it );
3709 nCount += 1;
3714 return aLanguages;
3717 SwXLinkTargetSupplier::SwXLinkTargetSupplier(SwXTextDocument& rxDoc) :
3718 pxDoc(&rxDoc)
3720 sTables = SW_RES(STR_CONTENT_TYPE_TABLE);
3721 sFrames = SW_RES(STR_CONTENT_TYPE_FRAME);
3722 sGraphics = SW_RES(STR_CONTENT_TYPE_GRAPHIC);
3723 sOLEs = SW_RES(STR_CONTENT_TYPE_OLE);
3724 sSections = SW_RES(STR_CONTENT_TYPE_REGION);
3725 sOutlines = SW_RES(STR_CONTENT_TYPE_OUTLINE);
3726 sBookmarks = SW_RES(STR_CONTENT_TYPE_BOOKMARK);
3729 SwXLinkTargetSupplier::~SwXLinkTargetSupplier()
3733 Any SwXLinkTargetSupplier::getByName(const OUString& rName)
3734 throw( NoSuchElementException, WrappedTargetException, RuntimeException, std::exception )
3736 Any aRet;
3737 if(!pxDoc)
3738 throw RuntimeException();
3739 OUString sSuffix("|");
3740 if(rName == sTables)
3742 sSuffix += "table";
3744 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3745 pxDoc->getTextTables(), rName, sSuffix );
3746 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3748 else if(rName == sFrames)
3750 sSuffix += "frame";
3751 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3752 pxDoc->getTextFrames(), rName, sSuffix );
3753 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3755 else if(rName == sSections)
3757 sSuffix += "region";
3758 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3759 pxDoc->getTextSections(), rName, sSuffix );
3760 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3762 else if(rName == sGraphics)
3764 sSuffix += "graphic";
3765 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3766 pxDoc->getGraphicObjects(), rName, sSuffix );
3767 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3769 else if(rName == sOLEs)
3771 sSuffix += "ole";
3772 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3773 pxDoc->getEmbeddedObjects(), rName, sSuffix );
3774 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3776 else if(rName == sOutlines)
3778 sSuffix += "outline";
3779 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3780 *pxDoc, rName, sSuffix );
3781 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3783 else if(rName == sBookmarks)
3785 sSuffix.clear();
3786 Reference< XNameAccess > xBkms = new SwXLinkNameAccessWrapper(
3787 pxDoc->getBookmarks(), rName, sSuffix );
3788 aRet <<= Reference< XPropertySet >(xBkms, UNO_QUERY);
3790 else
3791 throw NoSuchElementException();
3792 return aRet;
3795 Sequence< OUString > SwXLinkTargetSupplier::getElementNames()
3796 throw( RuntimeException, std::exception )
3798 Sequence< OUString > aRet(7);
3799 OUString* pNames = aRet.getArray();
3800 pNames[0] = sTables;
3801 pNames[1] = sFrames ;
3802 pNames[2] = sGraphics;
3803 pNames[3] = sOLEs ;
3804 pNames[4] = sSections;
3805 pNames[5] = sOutlines;
3806 pNames[6] = sBookmarks;
3807 return aRet;
3810 sal_Bool SwXLinkTargetSupplier::hasByName(const OUString& rName)
3811 throw( RuntimeException, std::exception )
3813 if( rName == sTables ||
3814 rName == sFrames ||
3815 rName == sGraphics||
3816 rName == sOLEs ||
3817 rName == sSections ||
3818 rName == sOutlines ||
3819 rName == sBookmarks )
3820 return true;
3821 return false;
3824 uno::Type SwXLinkTargetSupplier::getElementType()
3825 throw( RuntimeException, std::exception )
3827 return cppu::UnoType<XPropertySet>::get();
3831 sal_Bool SwXLinkTargetSupplier::hasElements() throw( RuntimeException, std::exception )
3833 return nullptr != pxDoc;
3836 OUString SwXLinkTargetSupplier::getImplementationName() throw( RuntimeException, std::exception )
3838 return OUString("SwXLinkTargetSupplier");
3841 sal_Bool SwXLinkTargetSupplier::supportsService(const OUString& rServiceName)
3842 throw( RuntimeException, std::exception )
3844 return cppu::supportsService(this, rServiceName);
3847 Sequence< OUString > SwXLinkTargetSupplier::getSupportedServiceNames()
3848 throw( RuntimeException, std::exception )
3850 Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
3851 return aRet;
3854 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(
3855 Reference< XNameAccess > xAccess, const OUString& rLinkDisplayName, const OUString& sSuffix ) :
3856 xRealAccess(xAccess),
3857 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3858 sLinkSuffix(sSuffix),
3859 sLinkDisplayName(rLinkDisplayName),
3860 pxDoc(nullptr)
3864 SwXLinkNameAccessWrapper::SwXLinkNameAccessWrapper(SwXTextDocument& rxDoc,
3865 const OUString& rLinkDisplayName, const OUString& sSuffix) :
3866 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3867 sLinkSuffix(sSuffix),
3868 sLinkDisplayName(rLinkDisplayName),
3869 pxDoc(&rxDoc)
3873 SwXLinkNameAccessWrapper::~SwXLinkNameAccessWrapper()
3877 Any SwXLinkNameAccessWrapper::getByName(const OUString& rName)
3878 throw( NoSuchElementException, WrappedTargetException, RuntimeException, std::exception )
3880 Any aRet;
3881 bool bFound = false;
3882 //cut link extension and call the real NameAccess
3883 OUString sParam = rName;
3884 OUString sSuffix(sLinkSuffix);
3885 if(sParam.getLength() > sSuffix.getLength() )
3887 OUString sCmp = sParam.copy(sParam.getLength() - sSuffix.getLength(),
3888 sSuffix.getLength());
3889 if(sCmp == sSuffix)
3891 if(pxDoc)
3893 sParam = sParam.copy(0, sParam.getLength() - sSuffix.getLength());
3894 if(!pxDoc->GetDocShell())
3895 throw RuntimeException();
3896 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3897 const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
3899 for (size_t i = 0; i < nOutlineCount && !bFound; ++i)
3901 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3902 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3903 if(sParam == lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3905 Reference< XPropertySet > xOutline = new SwXOutlineTarget(sParam);
3906 aRet <<= xOutline;
3907 bFound = true;
3911 else
3913 aRet = xRealAccess->getByName(sParam.copy(0, sParam.getLength() - sSuffix.getLength()));
3914 Reference< XInterface > xInt;
3915 if(!(aRet >>= xInt))
3916 throw RuntimeException();
3917 Reference< XPropertySet > xProp(xInt, UNO_QUERY);
3918 aRet <<= xProp;
3919 bFound = true;
3923 if(!bFound)
3924 throw NoSuchElementException();
3925 return aRet;
3928 Sequence< OUString > SwXLinkNameAccessWrapper::getElementNames()
3929 throw( RuntimeException, std::exception )
3931 Sequence< OUString > aRet;
3932 if(pxDoc)
3934 if(!pxDoc->GetDocShell())
3935 throw RuntimeException();
3937 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3938 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3939 const size_t nOutlineCount = rOutlineNodes.size();
3940 aRet.realloc(nOutlineCount);
3941 OUString* pResArr = aRet.getArray();
3942 OUString sSuffix("|outline");
3943 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3944 for (size_t i = 0; i < nOutlineCount; ++i)
3946 OUString sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule);
3947 sEntry += sSuffix;
3948 pResArr[i] = sEntry;
3951 else
3953 Sequence< OUString > aOrg = xRealAccess->getElementNames();
3954 const OUString* pOrgArr = aOrg.getConstArray();
3955 aRet.realloc(aOrg.getLength());
3956 OUString* pResArr = aRet.getArray();
3957 for(long i = 0; i < aOrg.getLength(); i++)
3959 pResArr[i] = pOrgArr[i] + sLinkSuffix;
3962 return aRet;
3965 sal_Bool SwXLinkNameAccessWrapper::hasByName(const OUString& rName)
3966 throw( RuntimeException, std::exception )
3968 bool bRet = false;
3969 OUString sParam(rName);
3970 if(sParam.getLength() > sLinkSuffix.getLength() )
3972 OUString sCmp = sParam.copy(sParam.getLength() - sLinkSuffix.getLength(),
3973 sLinkSuffix.getLength());
3974 if(sCmp == sLinkSuffix)
3976 sParam = sParam.copy(0, sParam.getLength() - sLinkSuffix.getLength());
3977 if(pxDoc)
3979 if(!pxDoc->GetDocShell())
3980 throw RuntimeException();
3981 SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3982 const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
3984 for (size_t i = 0; i < nOutlineCount && !bRet; ++i)
3986 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3987 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
3988 if(sParam ==
3989 lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
3991 bRet = true;
3995 else
3997 bRet = xRealAccess->hasByName(sParam);
4001 return bRet;
4004 uno::Type SwXLinkNameAccessWrapper::getElementType()
4005 throw( RuntimeException, std::exception )
4007 return cppu::UnoType<XPropertySet>::get();
4010 sal_Bool SwXLinkNameAccessWrapper::hasElements() throw( RuntimeException, std::exception )
4012 bool bRet = false;
4013 if(pxDoc)
4015 OSL_FAIL("not implemented");
4017 else
4019 bRet = xRealAccess->hasElements();
4021 return bRet;
4024 Reference< XPropertySetInfo > SwXLinkNameAccessWrapper::getPropertySetInfo()
4025 throw( RuntimeException, std::exception )
4027 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
4028 return xRet;
4031 void SwXLinkNameAccessWrapper::setPropertyValue(
4032 const OUString& , const Any& )
4033 throw( UnknownPropertyException,
4034 PropertyVetoException,
4035 IllegalArgumentException,
4036 WrappedTargetException,
4037 RuntimeException, std::exception)
4039 throw UnknownPropertyException();
4042 static Any lcl_GetDisplayBitmap(const OUString& _sLinkSuffix)
4044 Any aRet;
4045 OUString sLinkSuffix = _sLinkSuffix;
4046 if(!sLinkSuffix.isEmpty())
4047 sLinkSuffix = sLinkSuffix.copy(1);
4048 ContentTypeId nImgId(ContentTypeId::UNKNOWN);
4049 bool bNotFound = false;
4051 if(sLinkSuffix == "outline")
4052 nImgId = ContentTypeId::OUTLINE;
4053 else if(sLinkSuffix == "table")
4054 nImgId = ContentTypeId::TABLE;
4055 else if(sLinkSuffix == "frame")
4056 nImgId = ContentTypeId::FRAME;
4057 else if(sLinkSuffix == "graphic")
4058 nImgId = ContentTypeId::GRAPHIC;
4059 else if(sLinkSuffix == "region")
4060 nImgId = ContentTypeId::REGION;
4061 else if(sLinkSuffix == "ole")
4062 nImgId = ContentTypeId::OLE;
4063 else if(sLinkSuffix.isEmpty())
4064 nImgId = ContentTypeId::BOOKMARK;
4065 else
4066 bNotFound = true;
4067 if(!bNotFound)
4069 ImageList aEntryImages( SW_RES(IMG_NAVI_ENTRYBMP) );
4070 const Image& rImage = aEntryImages.GetImage( (int)nImgId + 2000 );
4071 Bitmap aBitmap( rImage.GetBitmapEx().GetBitmap() );
4072 aRet <<= VCLUnoHelper::CreateBitmap( aBitmap );
4074 return aRet;
4077 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
4078 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4080 Any aRet;
4081 if( rPropertyName == UNO_LINK_DISPLAY_NAME )
4083 aRet <<= OUString(sLinkDisplayName);
4085 else if( rPropertyName == UNO_LINK_DISPLAY_BITMAP )
4087 aRet = lcl_GetDisplayBitmap(sLinkSuffix);
4089 else
4090 throw UnknownPropertyException();
4091 return aRet;
4094 void SwXLinkNameAccessWrapper::addPropertyChangeListener(
4095 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4096 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4099 void SwXLinkNameAccessWrapper::removePropertyChangeListener(
4100 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4101 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4104 void SwXLinkNameAccessWrapper::addVetoableChangeListener(
4105 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4106 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4109 void SwXLinkNameAccessWrapper::removeVetoableChangeListener(
4110 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4111 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4114 Reference< XNameAccess > SwXLinkNameAccessWrapper::getLinks()
4115 throw( RuntimeException, std::exception )
4117 return this;
4120 OUString SwXLinkNameAccessWrapper::getImplementationName() throw( RuntimeException, std::exception )
4122 return OUString("SwXLinkNameAccessWrapper");
4125 sal_Bool SwXLinkNameAccessWrapper::supportsService(const OUString& rServiceName)
4126 throw( RuntimeException, std::exception )
4128 return cppu::supportsService(this, rServiceName);
4131 Sequence< OUString > SwXLinkNameAccessWrapper::getSupportedServiceNames()
4132 throw( RuntimeException, std::exception )
4134 Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
4135 return aRet;
4138 SwXOutlineTarget::SwXOutlineTarget(const OUString& rOutlineText) :
4139 pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4140 sOutlineText(rOutlineText)
4144 SwXOutlineTarget::~SwXOutlineTarget()
4148 Reference< XPropertySetInfo > SwXOutlineTarget::getPropertySetInfo() throw( RuntimeException, std::exception )
4150 static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
4151 return xRet;
4154 void SwXOutlineTarget::setPropertyValue(
4155 const OUString& /*PropertyName*/, const Any& /*aValue*/)
4156 throw( UnknownPropertyException, PropertyVetoException,
4157 IllegalArgumentException, WrappedTargetException, RuntimeException, std::exception)
4159 throw UnknownPropertyException();
4162 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
4163 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4165 Any aRet;
4166 if(rPropertyName == UNO_LINK_DISPLAY_NAME)
4167 aRet <<= OUString(sOutlineText);
4168 else
4169 throw UnknownPropertyException();
4170 return aRet;
4173 void SwXOutlineTarget::addPropertyChangeListener(
4174 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4175 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4179 void SwXOutlineTarget::removePropertyChangeListener(
4180 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4181 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4185 void SwXOutlineTarget::addVetoableChangeListener(
4186 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4187 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4191 void SwXOutlineTarget::removeVetoableChangeListener(
4192 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4193 throw( UnknownPropertyException, WrappedTargetException, RuntimeException, std::exception )
4197 OUString SwXOutlineTarget::getImplementationName() throw( RuntimeException, std::exception )
4199 return OUString("SwXOutlineTarget");
4202 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName) throw( RuntimeException, std::exception )
4204 return cppu::supportsService(this, ServiceName);
4207 Sequence< OUString > SwXOutlineTarget::getSupportedServiceNames() throw( RuntimeException, std::exception )
4209 Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4211 return aRet;
4214 SwXDocumentPropertyHelper::SwXDocumentPropertyHelper(SwDoc& rDoc) :
4215 SvxUnoForbiddenCharsTable ( rDoc.getIDocumentSettingAccess().getForbiddenCharacterTable() )
4216 ,m_pDoc(&rDoc)
4220 SwXDocumentPropertyHelper::~SwXDocumentPropertyHelper()
4224 Reference<XInterface> SwXDocumentPropertyHelper::GetDrawTable(short nWhich)
4226 Reference<XInterface> xRet;
4227 if(m_pDoc)
4229 switch(nWhich)
4231 // #i52858#
4232 // assure that Draw model is created, if it doesn't exist.
4233 case SW_CREATE_DASH_TABLE :
4234 if(!xDashTable.is())
4235 xDashTable = SvxUnoDashTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4236 xRet = xDashTable;
4237 break;
4238 case SW_CREATE_GRADIENT_TABLE :
4239 if(!xGradientTable.is())
4240 xGradientTable = SvxUnoGradientTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4241 xRet = xGradientTable;
4242 break;
4243 case SW_CREATE_HATCH_TABLE :
4244 if(!xHatchTable.is())
4245 xHatchTable = SvxUnoHatchTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4246 xRet = xHatchTable;
4247 break;
4248 case SW_CREATE_BITMAP_TABLE :
4249 if(!xBitmapTable.is())
4250 xBitmapTable = SvxUnoBitmapTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4251 xRet = xBitmapTable;
4252 break;
4253 case SW_CREATE_TRANSGRADIENT_TABLE:
4254 if(!xTransGradientTable.is())
4255 xTransGradientTable = SvxUnoTransGradientTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4256 xRet = xTransGradientTable;
4257 break;
4258 case SW_CREATE_MARKER_TABLE :
4259 if(!xMarkerTable.is())
4260 xMarkerTable = SvxUnoMarkerTable_createInstance( m_pDoc->getIDocumentDrawModelAccess().GetOrCreateDrawModel() );
4261 xRet = xMarkerTable;
4262 break;
4263 case SW_CREATE_DRAW_DEFAULTS:
4264 if(!xDrawDefaults.is())
4265 xDrawDefaults = static_cast<cppu::OWeakObject*>(new SwSvxUnoDrawPool(m_pDoc));
4266 xRet = xDrawDefaults;
4267 break;
4268 #if OSL_DEBUG_LEVEL > 0
4269 default: OSL_FAIL("which table?");
4270 #endif
4273 return xRet;
4276 void SwXDocumentPropertyHelper::Invalidate()
4278 xDashTable = nullptr;
4279 xGradientTable = nullptr;
4280 xHatchTable = nullptr;
4281 xBitmapTable = nullptr;
4282 xTransGradientTable = nullptr;
4283 xMarkerTable = nullptr;
4284 xDrawDefaults = nullptr;
4285 m_pDoc = nullptr;
4286 SvxUnoForbiddenCharsTable::mxForbiddenChars.clear();
4289 void SwXDocumentPropertyHelper::onChange()
4291 if(m_pDoc)
4292 m_pDoc->getIDocumentState().SetModified();
4295 SwViewOptionAdjust_Impl::SwViewOptionAdjust_Impl(
4296 SwViewShell& rSh, const SwViewOption &rViewOptions)
4297 : m_pShell(&rSh)
4298 , m_aOldViewOptions( rViewOptions )
4302 SwViewOptionAdjust_Impl::~SwViewOptionAdjust_Impl()
4304 if (m_pShell)
4306 m_pShell->ApplyViewOptions( m_aOldViewOptions );
4310 void
4311 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
4313 // to avoid unnecessary reformatting the view options related to the content
4314 // below should only change if necessary, that is if respective content is present
4315 const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars();
4316 const SwFieldType* pFieldType = m_pShell->GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENTXTFLD );
4317 const bool bContainsHiddenFields = pFieldType && pFieldType->HasWriterListeners();
4318 pFieldType = m_pShell->GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENPARAFLD );
4319 const bool bContainsHiddenParagraphs = pFieldType && pFieldType->HasWriterListeners();
4320 pFieldType = m_pShell->GetDoc()->getIDocumentFieldsAccess().GetSysFieldType( RES_JUMPEDITFLD );
4321 const bool bContainsPlaceHolders = pFieldType && pFieldType->HasWriterListeners();
4322 const bool bContainsFields = m_pShell->IsAnyFieldInDoc();
4324 SwViewOption aRenderViewOptions( m_aOldViewOptions );
4326 // disable anything in the view that should not be printed (or exported to PDF) by default
4327 // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4328 // in section "Display of ...")
4329 aRenderViewOptions.SetParagraph( false ); // paragraph end
4330 aRenderViewOptions.SetSoftHyph( false ); // aka custom hyphens
4331 aRenderViewOptions.SetBlank( false ); // spaces
4332 aRenderViewOptions.SetHardBlank( false ); // non-breaking spaces
4333 aRenderViewOptions.SetTab( false ); // tabs
4334 aRenderViewOptions.SetLineBreak( false ); // breaks (type 1)
4335 aRenderViewOptions.SetPageBreak( false ); // breaks (type 2)
4336 aRenderViewOptions.SetColumnBreak( false ); // breaks (type 3)
4337 bool bVal = pPrtOptions && pPrtOptions->m_bPrintHiddenText;
4338 if (bContainsHiddenChars)
4339 aRenderViewOptions.SetShowHiddenChar( bVal ); // hidden text
4340 if (bContainsHiddenFields)
4341 aRenderViewOptions.SetShowHiddenField( bVal );
4342 if (bContainsHiddenParagraphs)
4343 aRenderViewOptions.SetShowHiddenPara( bVal );
4345 if (bContainsPlaceHolders)
4347 // should always be printed in PDF export!
4348 bVal = !pPrtOptions ? setShowPlaceHoldersInPDF : pPrtOptions->m_bPrintTextPlaceholder;
4349 aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4352 if (bContainsFields)
4353 aRenderViewOptions.SetFieldName( false );
4355 // we need to set this flag in order to get to see the visible effect of
4356 // some of the above settings (needed for correct rendering)
4357 aRenderViewOptions.SetViewMetaChars( true );
4359 if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary
4361 aRenderViewOptions.SetPrinting( pPrtOptions != nullptr );
4362 m_pShell->ApplyViewOptions( aRenderViewOptions );
4366 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */