LibreOffice Module sw (master) 1
unotxdoc.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21#include <officecfg/Office/Common.hxx>
22#include <comphelper/string.hxx>
23#include <AnnotationWin.hxx>
24#include <o3tl/any.hxx>
25#include <utility>
26#include <vcl/virdev.hxx>
27#include <vcl/sysdata.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/print.hxx>
30#include <sfx2/bindings.hxx>
31#include <sfx2/viewfrm.hxx>
32#include <sfx2/lokhelper.hxx>
34#include <sfx2/docfile.hxx>
35#include <sfx2/printer.hxx>
38#include <LibreOfficeKit/LibreOfficeKitEnums.h>
40#include <sfx2/ipclient.hxx>
41#include <editeng/svxacorr.hxx>
42#include <editeng/acorrcfg.hxx>
43#include <cmdid.h>
44#include <swtypes.hxx>
45#include <wdocsh.hxx>
46#include <wrtsh.hxx>
47#include <pview.hxx>
48#include <viewsh.hxx>
49#include <pvprtdat.hxx>
50#include <printdata.hxx>
51#include <pagefrm.hxx>
52#include <rootfrm.hxx>
53#include <svl/stritem.hxx>
54#include <unotxdoc.hxx>
55#include <svl/numformat.hxx>
56#include <svl/numuno.hxx>
57#include <fldbas.hxx>
58#include <unomap.hxx>
59#include <unotextbodyhf.hxx>
60#include <unotextrange.hxx>
61#include <unotextcursor.hxx>
62#include <unosett.hxx>
63#include <unocoll.hxx>
64#include <unoredlines.hxx>
65#include <unosrch.hxx>
66#include <sfx2/request.hxx>
67#include <sfx2/objsh.hxx>
68#include <unoprnms.hxx>
69#include <unostyle.hxx>
70#include <unodraw.hxx>
71#include <svl/eitem.hxx>
73#include <unotools/datetime.hxx>
74#include <unocrsr.hxx>
75#include <unofieldcoll.hxx>
76#include <unoidxcoll.hxx>
77#include <unocrsrhelper.hxx>
78#include <globdoc.hxx>
79#include <viewopt.hxx>
80#include <unochart.hxx>
81#include <charatr.hxx>
82#include <svx/xmleohlp.hxx>
83#include <com/sun/star/lang/ServiceNotRegisteredException.hpp>
84#include <com/sun/star/lang/DisposedException.hpp>
85#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
86#include <com/sun/star/lang/NoSupportException.hpp>
87#include <com/sun/star/beans/PropertyAttribute.hpp>
88#include <com/sun/star/beans/XFastPropertySet.hpp>
89#include <com/sun/star/beans/XPropertyAccess.hpp>
90#include <com/sun/star/document/RedlineDisplayType.hpp>
91#include <com/sun/star/document/XDocumentEventBroadcaster.hpp>
92#include <com/sun/star/frame/XController.hpp>
93#include <com/sun/star/frame/XFrame.hpp>
94#include <com/sun/star/script/XInvocation.hpp>
95#include <com/sun/star/view/XSelectionSupplier.hpp>
96#include <sfx2/linkmgr.hxx>
97#include <svx/unofill.hxx>
98#include <swmodule.hxx>
99#include <docstat.hxx>
100#include <modcfg.hxx>
101#include <ndtxt.hxx>
102#include <strings.hrc>
103#include <bitmaps.hlst>
104#include "unodefaults.hxx"
106#include <doc.hxx>
116#include <IDocumentState.hxx>
117#include <drawdoc.hxx>
118#include <SwStyleNameMapper.hxx>
119#include <osl/file.hxx>
120#include <comphelper/lok.hxx>
124#include <sfx2/dispatch.hxx>
125#include <swruler.hxx>
126#include <docufld.hxx>
127
129#include <numrule.hxx>
130
131#include <editeng/langitem.hxx>
132#include <docary.hxx>
134#include <i18nutil/searchopt.hxx>
135
136#include <charfmt.hxx>
137#include <fmtcol.hxx>
138#include <istyleaccess.hxx>
139
140#include <swatrset.hxx>
141#include <view.hxx>
142#include <viscrs.hxx>
143#include <srcview.hxx>
144#include <edtwin.hxx>
145#include <swdtflvr.hxx>
146#include <PostItMgr.hxx>
147
148#include <svtools/langtab.hxx>
149#include <map>
150#include <set>
151#include <vector>
152
153#include <editeng/eeitem.hxx>
154#include <editeng/editeng.hxx>
155#include <editeng/editview.hxx>
156#include <svx/svdoutl.hxx>
157#include <svx/svdview.hxx>
160#include <memory>
161#include <redline.hxx>
163#include <xmloff/odffields.hxx>
164#include <tools/json_writer.hxx>
166
167#include <svx/svdpage.hxx>
168#include <o3tl/string_view.hxx>
170
173#include <textcontentcontrol.hxx>
174#include <unocontentcontrol.hxx>
175
176using namespace ::com::sun::star;
177using namespace ::com::sun::star::text;
178using namespace ::com::sun::star::i18n;
179using namespace ::com::sun::star::uno;
180using namespace ::com::sun::star::beans;
181using namespace ::com::sun::star::lang;
182using namespace ::com::sun::star::container;
183using namespace ::com::sun::star::document;
184using ::osl::FileBase;
185
186static std::unique_ptr<SwPrintUIOptions> lcl_GetPrintUIOptions(
187 SwDocShell * pDocShell,
188 const SfxViewShell * pView )
189{
190 if (!pDocShell)
191 return nullptr;
192
193 const bool bWebDoc = nullptr != dynamic_cast< const SwWebDocShell * >(pDocShell);
194 const bool bSwSrcView = nullptr != dynamic_cast< const SwSrcView * >(pView);
195 const SwView * pSwView = dynamic_cast< const SwView * >(pView);
196 const bool bHasSelection = pSwView && pSwView->HasSelection( false ); // check for any selection, not just text selection
197 const bool bHasPostIts = sw_GetPostIts(pDocShell->GetDoc()->getIDocumentFieldsAccess(), nullptr);
198
199 // get default values to use in dialog from documents SwPrintData
200 const SwPrintData &rPrintData = pDocShell->GetDoc()->getIDocumentDeviceAccess().getPrintData();
201
202 // Get current page number
203 sal_uInt16 nCurrentPage = 1;
204 const SwWrtShell* pSh = pDocShell->GetWrtShell();
205 const SwRootFrame *pFrame = nullptr;
206 if (pSh)
207 {
208 SwPaM* pShellCursor = pSh->GetCursor();
209 nCurrentPage = pShellCursor->GetPageNum();
210 pFrame = pSh->GetLayout();
211 }
212 else if (!bSwSrcView)
213 {
214 const SwPagePreview* pPreview = dynamic_cast< const SwPagePreview* >(pView);
215 OSL_ENSURE(pPreview, "Unexpected type of the view shell");
216 if (pPreview)
217 {
218 nCurrentPage = pPreview->GetSelectedPage();
219 pFrame = pPreview->GetViewShell()->GetLayout();
220 }
221 }
222
223 // If blanks are skipped, account for them in initial page range value
224 if (pFrame && !rPrintData.IsPrintEmptyPages())
225 {
226 sal_uInt16 nMax = nCurrentPage;
227 const SwPageFrame *pPage = dynamic_cast<const SwPageFrame*>(pFrame->Lower());
228 while (pPage && nMax-- > 0)
229 {
230 if (pPage->getFrameArea().Height() == 0)
231 nCurrentPage--;
232 pPage = static_cast<const SwPageFrame*>(pPage->GetNext());
233 }
234 }
235 return std::make_unique<SwPrintUIOptions>( nCurrentPage, bWebDoc, bSwSrcView, bHasSelection, bHasPostIts, rPrintData );
236}
237
238static SwTextFormatColl *lcl_GetParaStyle(const OUString& rCollName, SwDoc& rDoc)
239{
240 SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( rCollName );
241 if( !pColl )
242 {
244 rCollName, SwGetPoolIdFromName::TxtColl );
245 if( USHRT_MAX != nId )
247 }
248 return pColl;
249}
250
251static void lcl_DisposeView( SfxViewFrame* pToClose, SwDocShell const * pDocShell )
252{
253 // check if the view frame still exists
254 SfxViewFrame* pFound = SfxViewFrame::GetFirst( pDocShell, false );
255 while(pFound)
256 {
257 if( pFound == pToClose)
258 {
259 pToClose->DoClose();
260 break;
261 }
262 pFound = SfxViewFrame::GetNext( *pFound, pDocShell, false );
263 }
264}
265
267{
268public:
269 std::mutex m_Mutex; // just for OInterfaceContainerHelper4
271};
272
273const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
274{
275 static const comphelper::UnoIdInit theSwXTextDocumentUnoTunnelId;
276 return theSwXTextDocumentUnoTunnelId.getSeq();
277}
278
279sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
280{
281 if( comphelper::isUnoTunnelId<SwXTextDocument>(rId) )
282 {
284 }
285 if( comphelper::isUnoTunnelId<SfxObjectShell>(rId) )
286 {
288 }
289
290 sal_Int64 nRet = SfxBaseModel::getSomething( rId );
291 if (nRet)
292 return nRet;
293
295 if (!m_xNumFormatAgg.is()) // may happen if not valid or no SwDoc
296 return 0;
297 Any aNumTunnel = m_xNumFormatAgg->queryAggregation(cppu::UnoType<XUnoTunnel>::get());
298 Reference<XUnoTunnel> xNumTunnel;
299 aNumTunnel >>= xNumTunnel;
300 return (xNumTunnel.is()) ? xNumTunnel->getSomething(rId) : 0;
301}
302
304{
305 Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
306 if ( !aRet.hasValue() )
307 aRet = SfxBaseModel::queryInterface(rType);
308 if ( !aRet.hasValue() &&
310 {
311 Reference<lang::XMultiServiceFactory> xTmp = this;
312 aRet <<= xTmp;
313 }
314 if ( !aRet.hasValue() &&
316 {
317 Reference<tiledrendering::XTiledRenderable> xTmp = this;
318 aRet <<= xTmp;
319 }
320
321 if ( !aRet.hasValue()
328 {
330 if(m_xNumFormatAgg.is())
331 aRet = m_xNumFormatAgg->queryAggregation(rType);
332 }
333 return aRet;
334}
335
336void SAL_CALL SwXTextDocument::acquire()noexcept
337{
339}
340
341void SAL_CALL SwXTextDocument::release()noexcept
342{
344}
345
346Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes()
347{
348 Sequence< uno::Type > aNumTypes;
350 if(m_xNumFormatAgg.is())
351 {
352 const uno::Type& rProvType = cppu::UnoType<XTypeProvider>::get();
353 Any aNumProv = m_xNumFormatAgg->queryAggregation(rProvType);
354 Reference<XTypeProvider> xNumProv;
355 if(aNumProv >>= xNumProv)
356 {
357 aNumTypes = xNumProv->getTypes();
358 }
359 }
362 SwXTextDocumentBaseClass::getTypes(),
363 aNumTypes,
364 Sequence {
367}
368
371 , m_pImpl(new Impl)
372 ,
373 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
374 m_pDocShell(pShell),
375 m_bObjectValid(pShell != nullptr),
376 m_pHiddenViewFrame(nullptr),
377 // #i117783#
378 m_bApplyPagePrintSettingsFromXPagePrintable( false )
379{
380}
381
383{
384 OSL_ENSURE(m_pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel(), "No SdrModel in SwDoc, should not happen");
386}
387
389{
390 InitNewDoc();
391 if(m_xNumFormatAgg.is())
392 {
393 Reference< XInterface > x0;
394 m_xNumFormatAgg->setDelegator(x0);
395 m_xNumFormatAgg = nullptr;
396 }
397 m_pPrintUIOptions.reset();
398 if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
399 { // rhbz#827695: this can happen if the last page is not printed
400 // the SwViewShell has been deleted already by SwView::~SwView
401 // FIXME: replace this awful implementation of XRenderable with
402 // something less insane that has its own view
403 m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
404 }
405 m_pRenderData.reset();
406}
407
409{
410 if(!mxPropertyHelper.is())
411 {
413 }
414 return mxPropertyHelper.get();
415}
416
418{
419 if(!IsValid())
420 return;
421
422 if(!m_xNumFormatAgg.is())
423 {
424 if ( m_pDocShell->GetDoc() )
425 {
428 m_xNumFormatAgg = pNumFormat;
429 }
430 if(m_xNumFormatAgg.is())
431 m_xNumFormatAgg->setDelegator(static_cast<cppu::OWeakObject*>(static_cast<SwXTextDocumentBaseClass*>(this)));
432 }
433 else
434 {
435 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
436 Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
437 Reference< XUnoTunnel > xNumTunnel;
438 aNumTunnel >>= xNumTunnel;
440 = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
441 OSL_ENSURE(pNumFormat, "No number formatter available");
442 if (pNumFormat && !pNumFormat->GetNumberFormatter())
444 }
445}
446
447Reference< XText > SwXTextDocument::getText()
448{
449 return getBodyText();
450}
451
453{
454 SolarMutexGuard aGuard;
455 if(!IsValid())
456 throw DisposedException("", static_cast< XTextDocument* >(this));
457 if(!m_xBodyText.is())
458 {
460 }
461 return m_xBodyText;
462}
463
465{
466 SolarMutexGuard aGuard;
467 if(!IsValid())
468 throw DisposedException("", static_cast< XTextDocument* >(this));
469}
470
472{
473 SolarMutexGuard aGuard;
474 if(!IsValid())
475 throw DisposedException("", static_cast< XTextDocument* >(this));
476
477 maActionArr.emplace_front(new UnoActionContext(m_pDocShell->GetDoc()));
478}
479
481{
482 SolarMutexGuard aGuard;
483 if(maActionArr.empty())
484 throw RuntimeException("Nothing to unlock");
485
486 maActionArr.pop_front();
487}
488
490{
491 SolarMutexGuard aGuard;
492 return !maActionArr.empty();
493}
494
495Reference< frame::XController > SwXTextDocument::getCurrentController()
496{
498}
499
500void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
501{
503}
504
506{
507 SolarMutexGuard aGuard;
508 Reference< XInterface > xRef;
509 if(IsValid())
510 {
511 SwView* pView = static_cast<SwView*>(SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>));
512 while(pView && pView->GetObjectShell() != m_pDocShell)
513 {
514 pView = static_cast<SwView*>(SfxViewShell::GetNext(*pView, true, checkSfxViewShell<SwView>));
515 }
516 if(pView)
517 {
518 Any aRef = pView->GetUNOObject()->getSelection();
519 aRef >>= xRef;
520 }
521 }
522 return xRef;
523}
524
525sal_Bool SwXTextDocument::attachResource(const OUString& aURL, const Sequence< beans::PropertyValue >& aArgs)
526{
527 return SfxBaseModel::attachResource(aURL, aArgs);
528}
529
531{
532 return SfxBaseModel::getURL();
533}
534
535Sequence< beans::PropertyValue > SwXTextDocument::getArgs()
536{
537 return SfxBaseModel::getArgs();
538}
539
540void SwXTextDocument::connectController(const Reference< frame::XController > & xController)
541{
543}
544
545void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController)
546{
548}
549
551{
552 // Delete UnoActionContexts before deleting the SwDoc, as the first has unowned pointers to the
553 // second.
554 maActionArr.clear();
555
557}
558
559void SwXTextDocument::close( sal_Bool bDeliverOwnership )
560{
561 if(m_pDocShell)
562 {
563 uno::Sequence< uno::Any > aArgs;
565 }
566 SolarMutexGuard aGuard;
569 SfxBaseModel::close(bDeliverOwnership);
570}
571
572void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener)
573{
575}
576
577void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener)
578{
580}
581
583{
584 SolarMutexGuard aGuard;
585 if(!IsValid())
586 throw DisposedException("", static_cast< XTextDocument* >(this));
587
589 {
591 }
593}
594
596{
597 SolarMutexGuard aGuard;
598 if(!IsValid())
599 throw DisposedException("", static_cast< XTextDocument* >(this));
600 if(!mxXChapterNumbering.is())
601 {
603 }
604 return mxXChapterNumbering;
605}
606
607Reference< XIndexAccess > SwXTextDocument::getNumberingRules()
608{
609 SolarMutexGuard aGuard;
610 if(!IsValid())
611 throw DisposedException("", static_cast< XTextDocument* >(this));
612 if(!mxXNumberingRules.is() )
613 {
615 }
616 return mxXNumberingRules;
617}
618
619Reference< XIndexAccess > SwXTextDocument::getFootnotes()
620{
621 SolarMutexGuard aGuard;
622 if(!IsValid())
623 throw DisposedException("", static_cast< XTextDocument* >(this));
624 if(!mxXFootnotes.is())
625 {
627 }
628 return mxXFootnotes;
629}
630
631Reference< XPropertySet > SAL_CALL
633{
634 SolarMutexGuard aGuard;
635 if(!IsValid())
636 throw DisposedException("", static_cast< XTextDocument* >(this));
637 if(!mxXFootnoteSettings.is())
638 {
640 }
641 return mxXFootnoteSettings;
642}
643
644Reference< XIndexAccess > SwXTextDocument::getEndnotes()
645{
646 SolarMutexGuard aGuard;
647 if(!IsValid())
648 throw DisposedException("", static_cast< XTextDocument* >(this));
649 if(!mxXEndnotes.is())
650 {
652 }
653 return mxXEndnotes;
654}
655
656Reference< XPropertySet > SwXTextDocument::getEndnoteSettings()
657{
658 SolarMutexGuard aGuard;
659 if(!IsValid())
660 throw DisposedException("", static_cast< XTextDocument* >(this));
661 if(!mxXEndnoteSettings.is())
662 {
664 }
665 return mxXEndnoteSettings;
666}
667
668Reference< XIndexAccess > SwXTextDocument::getContentControls()
669{
670 SolarMutexGuard aGuard;
671 if(!IsValid())
672 throw DisposedException("", static_cast< XTextDocument* >(this));
673 if(!mxXContentControls.is())
674 {
676 }
677 return mxXContentControls;
678}
679
680Reference< util::XReplaceDescriptor > SwXTextDocument::createReplaceDescriptor()
681{
682 return new SwXTextSearch;
683}
684
685SwUnoCursor* SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCursor)
686{
687 getText();
688 XText *const pText = m_xBodyText.get();
689 SwXBodyText* pBText = static_cast<SwXBodyText*>(pText);
690 rtl::Reference<SwXTextCursor> pXTextCursor = pBText->CreateTextCursor(true);
691 xCursor.set( static_cast<text::XWordCursor*>(pXTextCursor.get()) );
692
693 auto& rUnoCursor(pXTextCursor->GetCursor());
694 rUnoCursor.SetRemainInSection(false);
695 return &rUnoCursor;
696}
697
698sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
699{
700 SolarMutexGuard aGuard;
701 SwXTextSearch* pSearch;
702 if (!IsValid() || !(pSearch = dynamic_cast<SwXTextSearch*>(xDesc.get())))
703 throw DisposedException("", static_cast< XTextDocument* >(this));
704
705 Reference< XTextCursor > xCursor;
706 auto pUnoCursor(CreateCursorForSearch(xCursor));
708
709 i18nutil::SearchOptions2 aSearchOpt;
710 pSearch->FillSearchOptions( aSearchOpt );
711
714
715 // Search should take place anywhere
716 pUnoCursor->SetRemainInSection(false);
717 sal_Int32 nResult;
719 //try attribute search first
720 if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
721 {
728 pSearch->FillSearchItemSet(aSearch);
729 pSearch->FillReplaceItemSet(aReplace);
730 bool bCancel;
731 nResult = pUnoCursor->FindAttrs(aSearch, !pSearch->m_bStyles,
732 eStart, eEnd, bCancel,
733 static_cast<FindRanges>(eRanges),
734 !pSearch->m_sSearchText.isEmpty() ? &aSearchOpt : nullptr,
735 &aReplace );
736 }
737 else if(pSearch->m_bStyles)
738 {
739 SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->m_sSearchText, pUnoCursor->GetDoc());
740 SwTextFormatColl *pReplaceColl = lcl_GetParaStyle(pSearch->m_sReplaceText, pUnoCursor->GetDoc());
741
742 bool bCancel;
743 nResult = pUnoCursor->FindFormat(*pSearchColl,
744 eStart, eEnd, bCancel,
745 static_cast<FindRanges>(eRanges), pReplaceColl );
746
747 }
748 else
749 {
750 //todo/mba: assuming that notes should be omitted
751 bool bCancel;
752 nResult = pUnoCursor->Find_Text(aSearchOpt, false/*bSearchInNotes*/,
753 eStart, eEnd, bCancel,
754 static_cast<FindRanges>(eRanges),
755 true );
756 }
757 return nResult;
758
759}
760
761Reference< util::XSearchDescriptor > SwXTextDocument::createSearchDescriptor()
762{
763 return new SwXTextSearch;
764}
765
766// Used for findAll/First/Next
767
768SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
769 Reference< XTextCursor > & xCursor,
770 bool bAll,
771 sal_Int32& nResult,
772 Reference< XInterface > const & xLastResult)
773{
774 const auto pSearch = dynamic_cast<SwXTextSearch*>(xDesc.get());
775 if(!IsValid() || !pSearch)
776 return nullptr;
777
778 auto pUnoCursor(CreateCursorForSearch(xCursor));
779
780 bool bParentInExtra = false;
781 if(xLastResult.is())
782 {
783 OTextCursorHelper* pPosCursor = dynamic_cast<OTextCursorHelper*>(xLastResult.get());
784 SwPaM* pCursor = pPosCursor ? pPosCursor->GetPaM() : nullptr;
785 if(pCursor)
786 {
787 *pUnoCursor->GetPoint() = *pCursor->End();
788 pUnoCursor->DeleteMark();
789 }
790 else
791 {
792 SwXTextRange* pRange = dynamic_cast<SwXTextRange*>(xLastResult.get());
793 if(!pRange)
794 return nullptr;
795 pRange->GetPositions(*pUnoCursor);
796 if(pUnoCursor->HasMark())
797 {
798 if(*pUnoCursor->GetPoint() < *pUnoCursor->GetMark())
799 pUnoCursor->Exchange();
800 pUnoCursor->DeleteMark();
801 }
802 }
803 const SwNode& rRangeNode = pUnoCursor->GetPointNode();
804 bParentInExtra = rRangeNode.FindFlyStartNode() ||
805 rRangeNode.FindFootnoteStartNode() ||
806 rRangeNode.FindHeaderStartNode() ||
807 rRangeNode.FindFooterStartNode() ;
808 }
809
810 i18nutil::SearchOptions2 aSearchOpt;
811 pSearch->FillSearchOptions( aSearchOpt );
812
822 if(bParentInExtra)
823 eRanges = FindRanges::InOther;
824 if(bAll) //always - everywhere?
825 eRanges = FindRanges::InSelAll;
827 SwDocPositions eEnd = pSearch->m_bBack ? SwDocPositions::Start : SwDocPositions::End;
828
829 nResult = 0;
830 for (int nSearchProc = 0; nSearchProc < 2; ++nSearchProc)
831 {
832 //try attribute search first
833 if(pSearch->HasSearchAttributes())
834 {
840 aSearch( m_pDocShell->GetDoc()->GetAttrPool() );
841 pSearch->FillSearchItemSet(aSearch);
842 bool bCancel;
843 nResult = pUnoCursor->FindAttrs(aSearch, !pSearch->m_bStyles,
844 eStart, eEnd, bCancel,
845 eRanges,
846 !pSearch->m_sSearchText.isEmpty() ? &aSearchOpt : nullptr );
847 }
848 else if(pSearch->m_bStyles)
849 {
850 SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->m_sSearchText, pUnoCursor->GetDoc());
851 //pSearch->sReplaceText
852 SwTextFormatColl *pReplaceColl = nullptr;
853 bool bCancel;
854 nResult = pUnoCursor->FindFormat(*pSearchColl,
855 eStart, eEnd, bCancel,
856 eRanges, pReplaceColl );
857 }
858 else
859 {
860 //todo/mba: assuming that notes should be omitted
861 bool bCancel;
862 nResult = pUnoCursor->Find_Text(aSearchOpt, false/*bSearchInNotes*/,
863 eStart, eEnd, bCancel,
864 eRanges );
865 }
866 if(nResult || (eRanges&(FindRanges::InSelAll|FindRanges::InOther)))
867 break;
868 //second step - find in other
869 eRanges = FindRanges::InOther;
870 }
871 return pUnoCursor;
872}
873
874Reference< XIndexAccess >
875 SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
876{
877 SolarMutexGuard aGuard;
878 Reference< XInterface > xTmp;
879 sal_Int32 nResult = 0;
880 Reference< XTextCursor > xCursor;
881 auto pResultCursor(FindAny(xDesc, xCursor, true, nResult, xTmp));
882 if(!pResultCursor)
883 throw RuntimeException("No result cursor");
884 Reference< XIndexAccess > xRet = SwXTextRanges::Create( nResult ? &(*pResultCursor) : nullptr );
885 return xRet;
886}
887
888Reference< XInterface > SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
889{
890 SolarMutexGuard aGuard;
891 Reference< XInterface > xTmp;
892 sal_Int32 nResult = 0;
893 Reference< XTextCursor > xCursor;
894 auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xTmp));
895 if(!pResultCursor)
896 throw RuntimeException("No result cursor");
897 Reference< XInterface > xRet;
898 if(nResult)
899 {
900 const uno::Reference< text::XText > xParent =
902 *pResultCursor->GetPoint());
903 xRet = *new SwXTextCursor(xParent, *pResultCursor);
904 }
905 return xRet;
906}
907
908Reference< XInterface > SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
909 const Reference< util::XSearchDescriptor > & xDesc)
910{
911 SolarMutexGuard aGuard;
912 sal_Int32 nResult = 0;
913 Reference< XTextCursor > xCursor;
914 if(!xStartAt.is())
915 throw RuntimeException("xStartAt missing");
916 auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xStartAt));
917 if(!pResultCursor)
918 throw RuntimeException("No result cursor");
919 Reference< XInterface > xRet;
920 if(nResult)
921 {
922 const uno::Reference< text::XText > xParent =
924 *pResultCursor->GetPoint());
925
926 xRet = *new SwXTextCursor(xParent, *pResultCursor);
927 }
928 return xRet;
929}
930
931Sequence< beans::PropertyValue > SwXTextDocument::getPagePrintSettings()
932{
933 SolarMutexGuard aGuard;
934 Sequence< beans::PropertyValue > aSeq(9);
935 if(!IsValid())
936 throw DisposedException("", static_cast< XTextDocument* >(this));
937
938 beans::PropertyValue* pArray = aSeq.getArray();
941 if(pData)
942 aData = *pData;
943 Any aVal;
944 aVal <<= aData.GetRow();
945 pArray[0] = beans::PropertyValue("PageRows", -1, aVal, PropertyState_DIRECT_VALUE);
946 aVal <<= aData.GetCol();
947 pArray[1] = beans::PropertyValue("PageColumns", -1, aVal, PropertyState_DIRECT_VALUE);
948 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetLeftSpace()));
949 pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
950 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetRightSpace()));
951 pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
952 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetTopSpace()));
953 pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
954 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetBottomSpace()));
955 pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
956 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetHorzSpace()));
957 pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
958 aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetVertSpace()));
959 pArray[7] = beans::PropertyValue("VertMargin", -1, aVal, PropertyState_DIRECT_VALUE);
960 aVal <<= aData.GetLandscape();
961 pArray[8] = beans::PropertyValue("IsLandscape", -1, aVal, PropertyState_DIRECT_VALUE);
962
963 return aSeq;
964}
965
966static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, bool& bException)
967{
968 bException = false;
969 TypeClass eType = rValue.getValueType().getTypeClass();
970
971 sal_uInt32 nRet = 0;
972 if( eType == TypeClass_UNSIGNED_LONG )
973 rValue >>= nRet;
974 else
975 {
976 sal_Int32 nVal=0;
977 bException = !(rValue >>= nVal);
978 if( !bException )
979 nRet = static_cast<sal_uInt32>(nVal);
980 }
981
982 return nRet;
983}
984
985static OUString lcl_CreateOutlineString(const size_t nIndex, const SwDoc* pDoc)
986{
987 OUStringBuffer sEntry;
988 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
989 const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
990 const SwTextNode * pTextNd = rOutlineNodes[ nIndex ]->GetTextNode();
991 SwNumberTree::tNumberVector aNumVector = pTextNd->GetNumberVector();
992 if( pOutlRule && pTextNd->GetNumRule())
993 for( int nLevel = 0;
994 nLevel <= pTextNd->GetActualListLevel();
995 nLevel++ )
996 {
997 tools::Long nVal = aNumVector[nLevel];
998 nVal ++;
999 nVal -= pOutlRule->Get(nLevel).GetStart();
1000 sEntry.append( OUString::number(nVal) + ".");
1001 }
1002 OUString sOutlineText = pDoc->getIDocumentOutlineNodes().getOutlineText(
1003 nIndex, pDoc->GetDocShell()->GetWrtShell()->GetLayout(), false);
1004 sEntry.append(sOutlineText);
1005 return sEntry.makeStringAndClear();
1006}
1007
1008void SwXTextDocument::setPagePrintSettings(const Sequence< beans::PropertyValue >& aSettings)
1009{
1010 SolarMutexGuard aGuard;
1011 if(!IsValid())
1012 throw DisposedException("", static_cast< XTextDocument* >(this));
1013
1015 //if only a few properties are coming, then use the current settings
1017 if(pData)
1018 aData = *pData;
1019 for(const beans::PropertyValue& rProperty : aSettings)
1020 {
1021 OUString sName = rProperty.Name;
1022 const Any& rVal = rProperty.Value;
1023 bool bException;
1024 sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
1025 if( sName == "PageRows" )
1026 {
1027 if(!nVal || nVal > 0xff)
1028 throw RuntimeException("Invalid value");
1029 aData.SetRow(nVal);
1030 }
1031 else if(sName == "PageColumns")
1032 {
1033 if(!nVal || nVal > 0xff)
1034 throw RuntimeException("Invalid value");
1035 aData.SetCol(nVal);
1036 }
1037 else if(sName == "LeftMargin")
1038 {
1039 aData.SetLeftSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1040 }
1041 else if(sName == "RightMargin")
1042 {
1043 aData.SetRightSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1044 }
1045 else if(sName == "TopMargin")
1046 {
1047 aData.SetTopSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1048 }
1049 else if(sName == "BottomMargin")
1050 {
1051 aData.SetBottomSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1052 }
1053 else if(sName == "HoriMargin")
1054 {
1055 aData.SetHorzSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1056 }
1057 else if(sName == "VertMargin")
1058 {
1059 aData.SetVertSpace(o3tl::toTwips(nVal, o3tl::Length::mm100));
1060 }
1061 else if(sName == "IsLandscape")
1062 {
1063 auto b = o3tl::tryAccess<bool>(rVal);
1064 bException = !b;
1065 if (b)
1066 {
1067 aData.SetLandscape(*b);
1068 }
1069 }
1070 else
1071 bException = true;
1072 if(bException)
1073 throw RuntimeException();
1074 }
1076
1077}
1078
1079void SwXTextDocument::printPages(const Sequence< beans::PropertyValue >& xOptions)
1080{
1081 SolarMutexGuard aGuard;
1082 if(!IsValid())
1083 throw DisposedException("", static_cast< XTextDocument* >(this));
1084
1086 SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SfxCallMode::SYNCHRON,
1089
1090 for ( const beans::PropertyValue &rProp : xOptions )
1091 {
1092 // get Property-Value from options
1093 Any aValue( rProp.Value );
1094
1095 // FileName-Property?
1096 if ( rProp.Name == UNO_NAME_FILE_NAME )
1097 {
1098 OUString sFileURL;
1099 if ( rProp.Value >>= sFileURL )
1100 {
1101 // Convert the File URL into a system dependent path, as the SalPrinter expects
1102 OUString sSystemPath;
1103 FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
1104 aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
1105 }
1106 else if ( rProp.Value.getValueType() != cppu::UnoType<void>::get() )
1107 throw IllegalArgumentException();
1108 }
1109
1110 // CopyCount-Property
1111 else if ( rProp.Name == UNO_NAME_COPY_COUNT )
1112 {
1113 sal_Int32 nCopies = 0;
1114 aValue >>= nCopies;
1115 aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, static_cast<sal_Int16>(nCopies) ) );
1116 }
1117
1118 // Collate-Property
1119 else if ( rProp.Name == UNO_NAME_COLLATE )
1120 {
1121 auto b = o3tl::tryAccess<bool>(rProp.Value);
1122 if ( !b )
1123 throw IllegalArgumentException();
1124 aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *b ) );
1125
1126 }
1127
1128 // Sort-Property
1129 else if ( rProp.Name == UNO_NAME_SORT )
1130 {
1131 auto b = o3tl::tryAccess<bool>(rProp.Value);
1132 if ( !b )
1133 throw IllegalArgumentException();
1134
1135 aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *b ) );
1136 }
1137
1138 // Pages-Property
1139 else if ( rProp.Name == UNO_NAME_PAGES )
1140 {
1141 OUString sTmp;
1142 if ( !(rProp.Value >>= sTmp) )
1143 throw IllegalArgumentException();
1144
1145 aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
1146
1147 }
1148 }
1149
1150 // #i117783#
1152 pFrame->GetViewShell()->ExecuteSlot(aReq);
1153 // Frame close
1154 pFrame->DoClose();
1155
1156}
1157
1158Reference< XNameAccess > SwXTextDocument::getReferenceMarks()
1159{
1160 SolarMutexGuard aGuard;
1161 if(!IsValid())
1162 throw DisposedException("", static_cast< XTextDocument* >(this));
1163 if(!mxXReferenceMarks.is())
1164 {
1166 }
1167 return mxXReferenceMarks;
1168}
1169
1170Reference< XEnumerationAccess > SwXTextDocument::getTextFields()
1171{
1172 SolarMutexGuard aGuard;
1173 if(!IsValid())
1174 throw DisposedException("", static_cast< XTextDocument* >(this));
1175 if(!mxXTextFieldTypes.is())
1176 {
1178 }
1179 return mxXTextFieldTypes;
1180}
1181
1183{
1184 SolarMutexGuard aGuard;
1185 if(!IsValid())
1186 throw DisposedException("", static_cast< XTextDocument* >(this));
1187 if(!mxXTextFieldMasters.is())
1188 {
1190 }
1191 return mxXTextFieldMasters;
1192}
1193
1194Reference< XNameAccess > SwXTextDocument::getEmbeddedObjects()
1195{
1196 SolarMutexGuard aGuard;
1197 if(!IsValid())
1198 throw DisposedException("", static_cast< XTextDocument* >(this));
1199 if(!mxXEmbeddedObjects.is())
1200 {
1202 }
1203 return mxXEmbeddedObjects;
1204}
1205
1206Reference< XNameAccess > SwXTextDocument::getBookmarks()
1207{
1208 SolarMutexGuard aGuard;
1209 if(!IsValid())
1210 throw DisposedException("", static_cast< XTextDocument* >(this));
1211 if(!mxXBookmarks.is())
1212 {
1214 }
1215 return mxXBookmarks;
1216}
1217
1218Reference< XNameAccess > SwXTextDocument::getTextSections()
1219{
1220 SolarMutexGuard aGuard;
1221 if(!IsValid())
1222 throw DisposedException("", static_cast< XTextDocument* >(this));
1223 if(!mxXTextSections.is())
1224 {
1226 }
1227 return mxXTextSections;
1228}
1229
1230Reference< XNameAccess > SwXTextDocument::getTextTables()
1231{
1232 SolarMutexGuard aGuard;
1233 if(!IsValid())
1234 throw DisposedException("", static_cast< XTextDocument* >(this));
1235 if(!mxXTextTables.is())
1236 {
1238 }
1239 return mxXTextTables;
1240}
1241
1242Reference< XNameAccess > SwXTextDocument::getGraphicObjects()
1243{
1244 SolarMutexGuard aGuard;
1245 if(!IsValid())
1246 throw DisposedException("", static_cast< XTextDocument* >(this));
1247 if(!mxXGraphicObjects.is())
1248 {
1250 }
1251 return mxXGraphicObjects;
1252}
1253
1254Reference< XNameAccess > SwXTextDocument::getTextFrames()
1255{
1256 SolarMutexGuard aGuard;
1257 if(!IsValid())
1258 throw DisposedException("", static_cast< XTextDocument* >(this));
1259 if(!mxXTextFrames.is())
1260 {
1262 }
1263 return mxXTextFrames;
1264}
1265
1266Reference< XNameAccess > SwXTextDocument::getStyleFamilies()
1267{
1268 SolarMutexGuard aGuard;
1269 if(!IsValid())
1270 throw DisposedException("", static_cast< XTextDocument* >(this));
1271 if(!mxXStyleFamilies.is())
1272 {
1274 }
1275 return mxXStyleFamilies;
1276}
1277
1278uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles( )
1279{
1280 SolarMutexGuard aGuard;
1281 if(!IsValid())
1282 throw DisposedException("", static_cast< XTextDocument* >(this));
1283 if(!mxXAutoStyles.is())
1284 {
1286 }
1287 return mxXAutoStyles;
1288
1289}
1290
1291Reference< drawing::XDrawPage > SwXTextDocument::getDrawPage()
1292{
1293 SolarMutexGuard aGuard;
1294 if(!IsValid())
1295 throw DisposedException("", static_cast< XTextDocument* >(this));
1296 if(!m_xDrawPage.is())
1297 {
1298 SwDoc* pDoc = m_pDocShell->GetDoc();
1299 // #i52858#
1301 SdrPage* pPage = pModel->GetPage( 0 );
1302 m_xDrawPage = new SwFmDrawPage(pDoc, pPage);
1303 }
1304 return m_xDrawPage;
1305}
1306
1307namespace {
1308
1309class SwDrawPagesObj : public cppu::WeakImplHelper<
1310 css::drawing::XDrawPages,
1311 css::lang::XServiceInfo>
1312{
1313private:
1314 css::uno::Reference< css::drawing::XDrawPageSupplier > m_xDoc;
1315public:
1316 SwDrawPagesObj(css::uno::Reference< css::drawing::XDrawPageSupplier > xDoc) : m_xDoc(std::move(xDoc)) {}
1317
1318 // XDrawPages
1319 virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL
1320 insertNewByIndex(sal_Int32 /*nIndex*/) override { throw css::lang::NoSupportException(); }
1321
1322 virtual void SAL_CALL remove(const css::uno::Reference< css::drawing::XDrawPage >& /*xPage*/) override
1323 {
1324 throw css::lang::NoSupportException();
1325 }
1326
1327 // XIndexAccess
1328 virtual sal_Int32 SAL_CALL getCount() override { return 1; }
1329
1330 virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
1331 {
1332 if (Index != 0)
1333 throw css::lang::IndexOutOfBoundsException("Writer documents have only one DrawPage!");
1334 return css::uno::Any(m_xDoc->getDrawPage());
1335 }
1336
1337 // XElementAccess
1338 virtual css::uno::Type SAL_CALL getElementType() override
1339 {
1341 }
1342
1343 virtual sal_Bool SAL_CALL hasElements() override { return true; }
1344
1345 // XServiceInfo
1346 virtual OUString SAL_CALL getImplementationName() override
1347 {
1348 return "SwDrawPagesObj";
1349 }
1350
1351 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override
1352 {
1353 return cppu::supportsService(this, ServiceName);
1354 }
1355
1356 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
1357 {
1358 return { "com.sun.star.drawing.DrawPages" };
1359 }
1360};
1361
1362}
1363
1364// XDrawPagesSupplier
1365
1366uno::Reference<drawing::XDrawPages> SAL_CALL SwXTextDocument::getDrawPages()
1367{
1368 SolarMutexGuard aGuard;
1369 return new SwDrawPagesObj(this);
1370}
1371
1373{
1374 m_bObjectValid = false;
1375 if(m_xNumFormatAgg.is())
1376 {
1377 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1378 Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
1379 Reference< XUnoTunnel > xNumTunnel;
1380 aNumTunnel >>= xNumTunnel;
1381 SvNumberFormatsSupplierObj* pNumFormat
1382 = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
1383 OSL_ENSURE(pNumFormat, "No number formatter available");
1384 if (pNumFormat)
1385 pNumFormat->SetNumberFormatter(nullptr);
1386 OSL_ENSURE(pNumFormat, "No number formatter available");
1387 }
1388 InitNewDoc();
1389 m_pDocShell = nullptr;
1390 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
1391 std::unique_lock aGuard(m_pImpl->m_Mutex);
1392 m_pImpl->m_RefreshListeners.disposeAndClear(aGuard, ev);
1393}
1394
1396{
1397 if(m_pDocShell && m_pDocShell != pNewDocShell)
1398 Invalidate();
1399 m_pDocShell = pNewDocShell;
1400 m_bObjectValid = true;
1401}
1402
1404{
1405 // first invalidate all collections, then delete references and Set to zero
1406 if(mxXTextTables.is())
1407 {
1408 XNameAccess* pTables = mxXTextTables.get();
1409 static_cast<SwXTextTables*>(pTables)->Invalidate();
1410 mxXTextTables.clear();
1411 }
1412
1413 if(mxXTextFrames.is())
1414 {
1415 XNameAccess* pFrames = mxXTextFrames.get();
1416 static_cast<SwXTextFrames*>(pFrames)->Invalidate();
1417 mxXTextFrames.clear();
1418 }
1419
1420 if(mxXGraphicObjects.is())
1421 {
1422 XNameAccess* pFrames = mxXGraphicObjects.get();
1423 static_cast<SwXTextGraphicObjects*>(pFrames)->Invalidate();
1424 mxXGraphicObjects.clear();
1425 }
1426
1427 if(mxXEmbeddedObjects.is())
1428 {
1429 XNameAccess* pOLE = mxXEmbeddedObjects.get();
1430 static_cast<SwXTextEmbeddedObjects*>(pOLE)->Invalidate();
1431 mxXEmbeddedObjects.clear();
1432 }
1433
1434 m_xBodyText = nullptr;
1435
1436 if(m_xNumFormatAgg.is())
1437 {
1438 const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1439 Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
1440 Reference< XUnoTunnel > xNumTunnel;
1441 aNumTunnel >>= xNumTunnel;
1442 SvNumberFormatsSupplierObj* pNumFormat
1443 = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
1444 OSL_ENSURE(pNumFormat, "No number formatter available");
1445 if (pNumFormat)
1446 pNumFormat->SetNumberFormatter(nullptr);
1447 }
1448
1449 if(mxXTextFieldTypes.is())
1450 {
1451 XEnumerationAccess* pT = mxXTextFieldTypes.get();
1452 static_cast<SwXTextFieldTypes*>(pT)->Invalidate();
1453 mxXTextFieldTypes.clear();
1454 }
1455
1456 if(mxXTextFieldMasters.is())
1457 {
1458 XNameAccess* pT = mxXTextFieldMasters.get();
1459 static_cast<SwXTextFieldMasters*>(pT)->Invalidate();
1460 mxXTextFieldMasters.clear();
1461 }
1462
1463 if(mxXTextSections.is())
1464 {
1465 XNameAccess* pSect = mxXTextSections.get();
1466 static_cast<SwXTextSections*>(pSect)->Invalidate();
1467 mxXTextSections.clear();
1468 }
1469
1470 if(m_xDrawPage.is())
1471 {
1472 // #i91798#, #i91895#
1473 // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1474 Reference<XComponent>(static_cast<cppu::OWeakObject*>(m_xDrawPage.get()), UNO_QUERY_THROW)->dispose();
1475 m_xDrawPage->InvalidateSwDoc();
1476 m_xDrawPage.clear();
1477 }
1478
1479 if ( mxXNumberingRules.is() )
1480 {
1481 XIndexAccess* pNum = mxXNumberingRules.get();
1482 static_cast<SwXNumberingRulesCollection*>(pNum)->Invalidate();
1483 mxXNumberingRules.clear();
1484 }
1485
1486 if(mxXFootnotes.is())
1487 {
1488 XIndexAccess* pFootnote = mxXFootnotes.get();
1489 static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1490 mxXFootnotes.clear();
1491 }
1492
1493 if(mxXEndnotes.is())
1494 {
1495 XIndexAccess* pFootnote = mxXEndnotes.get();
1496 static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1497 mxXEndnotes.clear();
1498 }
1499
1500 if(mxXContentControls.is())
1501 {
1502 XIndexAccess* pContentControls = mxXContentControls.get();
1503 static_cast<SwXContentControls*>(pContentControls)->Invalidate();
1504 mxXContentControls.clear();
1505 }
1506
1507 if(mxXDocumentIndexes.is())
1508 {
1509 XIndexAccess* pIdxs = mxXDocumentIndexes.get();
1510 static_cast<SwXDocumentIndexes*>(pIdxs)->Invalidate();
1511 mxXDocumentIndexes.clear();
1512 }
1513
1514 if(mxXStyleFamilies.is())
1515 {
1516 XNameAccess* pStyles = mxXStyleFamilies.get();
1517 static_cast<SwXStyleFamilies*>(pStyles)->Invalidate();
1518 mxXStyleFamilies.clear();
1519 }
1520 if(mxXAutoStyles.is())
1521 {
1522 XNameAccess* pStyles = mxXAutoStyles.get();
1523 static_cast<SwXAutoStyles*>(pStyles)->Invalidate();
1524 mxXAutoStyles.clear();
1525 }
1526
1527 if(mxXBookmarks.is())
1528 {
1529 XNameAccess* pBm = mxXBookmarks.get();
1530 static_cast<SwXBookmarks*>(pBm)->Invalidate();
1531 mxXBookmarks.clear();
1532 }
1533
1534 if(mxXChapterNumbering.is())
1535 {
1536 XIndexReplace* pCh = mxXChapterNumbering.get();
1537 static_cast<SwXChapterNumbering*>(pCh)->Invalidate();
1538 mxXChapterNumbering.clear();
1539 }
1540
1541 if(mxXFootnoteSettings.is())
1542 {
1543 XPropertySet* pFntSet = mxXFootnoteSettings.get();
1544 static_cast<SwXFootnoteProperties*>(pFntSet)->Invalidate();
1545 mxXFootnoteSettings.clear();
1546 }
1547
1548 if(mxXEndnoteSettings.is())
1549 {
1550 XPropertySet* pEndSet = mxXEndnoteSettings.get();
1551 static_cast<SwXEndnoteProperties*>(pEndSet)->Invalidate();
1552 mxXEndnoteSettings.clear();
1553 }
1554
1556 {
1558 static_cast<SwXLineNumberingProperties*>(pLine)->Invalidate();
1560 }
1561 if(mxXReferenceMarks.is())
1562 {
1563 XNameAccess* pMarks = mxXReferenceMarks.get();
1564 static_cast<SwXReferenceMarks*>(pMarks)->Invalidate();
1565 mxXReferenceMarks.clear();
1566 }
1567 if(mxLinkTargetSupplier.is())
1568 {
1569 XNameAccess* pAccess = mxLinkTargetSupplier.get();
1570 static_cast<SwXLinkTargetSupplier*>(pAccess)->Invalidate();
1571 mxLinkTargetSupplier.clear();
1572 }
1573 if(mxXRedlines.is())
1574 {
1575 XEnumerationAccess* pMarks = mxXRedlines.get();
1576 static_cast<SwXRedlines*>(pMarks)->Invalidate();
1577 mxXRedlines.clear();
1578 }
1579 if(mxPropertyHelper.is())
1580 {
1581 mxPropertyHelper->Invalidate();
1582 mxPropertyHelper.clear();
1583 }
1584}
1585
1586css::uno::Reference<css::uno::XInterface> SwXTextDocument::create(
1587 OUString const & rServiceName,
1588 css::uno::Sequence<css::uno::Any> const * arguments)
1589{
1590 SolarMutexGuard aGuard;
1591 if (!IsValid())
1592 throw DisposedException("", static_cast< XTextDocument* >(this));
1593
1596 {
1598 }
1599 if (rServiceName == "com.sun.star.drawing.DashTable")
1600 {
1602 }
1603 if (rServiceName == "com.sun.star.drawing.GradientTable")
1604 {
1606 }
1607 if (rServiceName == "com.sun.star.drawing.HatchTable")
1608 {
1610 }
1611 if (rServiceName == "com.sun.star.drawing.BitmapTable")
1612 {
1614 }
1615 if (rServiceName == "com.sun.star.drawing.TransparencyGradientTable")
1616 {
1618 }
1619 if (rServiceName == "com.sun.star.drawing.MarkerTable")
1620 {
1622 }
1623 if (rServiceName == "com.sun.star.drawing.Defaults")
1624 {
1626 }
1627 if (rServiceName == "com.sun.star.document.Settings")
1628 {
1629 return Reference<XInterface>(*new SwXDocumentSettings(this));
1630 }
1631 if (rServiceName == "com.sun.star.document.ImportEmbeddedObjectResolver")
1632 {
1633 return static_cast<cppu::OWeakObject *>(
1635 *m_pDocShell, SvXMLEmbeddedObjectHelperMode::Read));
1636 }
1637 if (rServiceName == "com.sun.star.text.DocumentSettings")
1638 {
1639 return Reference<XInterface>(*new SwXDocumentSettings(this));
1640 }
1641 if (rServiceName == "com.sun.star.chart2.data.DataProvider")
1642 {
1643 return Reference<XInterface>(
1644 static_cast<chart2::data::XDataProvider *>(
1646 GetChartDataProvider()));
1647 }
1648 if (!rServiceName.startsWith("com.sun.star.")
1649 || rServiceName.endsWith(".OLE2Shape"))
1650 {
1651 // We do not want to insert OLE2 Shapes (e.g.,
1652 // "com.sun.star.drawing.OLE2Shape", ...) like this (by creating them
1653 // with the documents factory and adding the shapes to the draw page);
1654 // for inserting OLE objects the proper way is to use
1655 // "com.sun.star.text.TextEmbeddedObject":
1656 throw ServiceNotRegisteredException();
1657 }
1658 // The XML import is allowed to create instances of
1659 // "com.sun.star.drawing.OLE2Shape"; thus, a temporary service name is
1660 // introduced to make this possible:
1661 OUString aTmpServiceName(rServiceName);
1662 if (rServiceName == "com.sun.star.drawing.temporaryForXMLImportOLE2Shape")
1663 {
1664 aTmpServiceName = "com.sun.star.drawing.OLE2Shape";
1665 }
1666 Reference<XInterface> xTmp(
1667 arguments == nullptr
1668 ? SvxFmMSFactory::createInstance(aTmpServiceName)
1670 aTmpServiceName, *arguments));
1671 if (rServiceName == "com.sun.star.drawing.GroupShape"
1672 || rServiceName == "com.sun.star.drawing.Shape3DSceneObject")
1673 {
1674 return *new SwXGroupShape(xTmp, m_pDocShell->GetDoc());
1675 }
1676 if (rServiceName.startsWith("com.sun.star.drawing."))
1677 {
1678 return *new SwXShape(xTmp, m_pDocShell->GetDoc());
1679 }
1680 return xTmp;
1681}
1682
1683Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName)
1684{
1685 return create(rServiceName, nullptr);
1686}
1687
1689 const OUString& ServiceSpecifier,
1690 const Sequence< Any >& Arguments)
1691{
1692 return create(ServiceSpecifier, &Arguments);
1693}
1694
1696{
1697 static Sequence< OUString > aServices;
1698 if ( !aServices.hasElements() )
1699 {
1700 Sequence< OUString > aRet = SvxFmMSFactory::getAvailableServiceNames();
1701 auto i = comphelper::findValue(aRet, "com.sun.star.drawing.OLE2Shape");
1702 if (i != -1)
1703 {
1704 auto nLength = aRet.getLength();
1705 aRet.getArray()[i] = aRet[nLength - 1];
1706 aRet.realloc( nLength - 1 );
1707 }
1708 Sequence< OUString > aOwn = SwXServiceProvider::GetAllServiceNames();
1709 aServices = comphelper::concatSequences(aRet, aOwn);
1710 }
1711
1712 return aServices;
1713}
1714
1716{
1717 return "SwXTextDocument";
1718 /* // Matching the .component information:
1719 return dynamic_cast<SwGlobalDocShell*>( pDocShell ) != nullptr
1720 ? OUString("com.sun.star.comp.Writer.GlobalDocument")
1721 : dynamic_cast<SwWebDocShell*>( pDocShell ) != nullptr
1722 ? OUString("com.sun.star.comp.Writer.WebDocument")
1723 : OUString("com.sun.star.comp.Writer.TextDocument");
1724 */
1725}
1726
1727sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName)
1728{
1729 return cppu::supportsService(this, rServiceName);
1730}
1731
1733{
1734 bool bWebDoc = (dynamic_cast<SwWebDocShell*>( m_pDocShell) != nullptr );
1735 bool bGlobalDoc = (dynamic_cast<SwGlobalDocShell*>( m_pDocShell) != nullptr );
1736 bool bTextDoc = (!bWebDoc && !bGlobalDoc);
1737
1738 Sequence< OUString > aRet (3);
1739 OUString* pArray = aRet.getArray();
1740
1741 pArray[0] = "com.sun.star.document.OfficeDocument";
1742 pArray[1] = "com.sun.star.text.GenericTextDocument";
1743
1744 if (bTextDoc)
1745 pArray[2] = "com.sun.star.text.TextDocument";
1746 else if (bWebDoc)
1747 pArray[2] = "com.sun.star.text.WebDocument";
1748 else if (bGlobalDoc)
1749 pArray[2] = "com.sun.star.text.GlobalDocument";
1750
1751 return aRet;
1752}
1753
1754Reference< XIndexAccess > SwXTextDocument::getDocumentIndexes()
1755{
1756 SolarMutexGuard aGuard;
1757 if(!IsValid())
1758 throw DisposedException("", static_cast< XTextDocument* >(this));
1759
1760 if(!mxXDocumentIndexes.is())
1761 {
1763 }
1764 return mxXDocumentIndexes;
1765}
1766
1767Reference< XPropertySetInfo > SwXTextDocument::getPropertySetInfo()
1768{
1769 static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
1770 return xRet;
1771}
1772
1773void SwXTextDocument::setPropertyValue(const OUString& rPropertyName, const Any& aValue)
1774{
1775 SolarMutexGuard aGuard;
1776 if(!IsValid())
1777 throw DisposedException("", static_cast< XTextDocument* >(this));
1778
1779 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
1780
1781 if(!pEntry)
1782 throw UnknownPropertyException(rPropertyName);
1783 if(pEntry->nFlags & PropertyAttribute::READONLY)
1784 throw PropertyVetoException();
1785 switch(pEntry->nWID)
1786 {
1787 case WID_DOC_CHAR_COUNT :
1788 case WID_DOC_PARA_COUNT :
1789 case WID_DOC_WORD_COUNT :
1790 throw RuntimeException(
1791 "bad WID",
1792 static_cast< cppu::OWeakObject * >(
1793 static_cast< SwXTextDocumentBaseClass * >(this)));
1795 {
1796 OUString sDelim;
1797 aValue >>= sDelim;
1798 SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
1799 }
1800 break;
1803 {
1804 bool bSet = *o3tl::doAccess<bool>(aValue);
1806 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
1807 {
1809 if( !bSet )
1811 }
1812 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
1813 {
1815 }
1817 }
1818 break;
1820 {
1821 Sequence <sal_Int8> aNew;
1822 if(aValue >>= aNew)
1823 {
1824 SwDoc* pDoc = m_pDocShell->GetDoc();
1826 if(aNew.hasElements())
1827 {
1831 }
1832 }
1833 }
1834 break;
1836 {
1837 OUString sURL;
1838 aValue >>= sURL;
1840 }
1841 break;
1842 case WID_DOC_HIDE_TIPS :
1843 SW_MOD()->GetModuleConfig()->SetHideFieldTips(*o3tl::doAccess<bool>(aValue));
1844 break;
1846 {
1848 eRedMode = eRedMode & (~RedlineFlags::ShowMask);
1849 sal_Int16 nSet = 0;
1850 aValue >>= nSet;
1851 switch(nSet)
1852 {
1853 case RedlineDisplayType::NONE: break;
1855 case RedlineDisplayType::REMOVED: eRedMode |= RedlineFlags::ShowDelete; break;
1856 case RedlineDisplayType::
1857 INSERTED_AND_REMOVED: eRedMode |= RedlineFlags::ShowInsert|RedlineFlags::ShowDelete;
1858 break;
1859 default: throw IllegalArgumentException();
1860 }
1862 }
1863 break;
1865 {
1866 sal_Int16 nYear = 0;
1867 aValue >>= nYear;
1868 SfxRequest aRequest ( SID_ATTR_YEAR2000, SfxCallMode::SLOT, m_pDocShell->GetDoc()->GetAttrPool());
1869 aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
1870 m_pDocShell->Execute ( aRequest );
1871 }
1872 break;
1874 {
1876 bool bAuto = *o3tl::doAccess<bool>(aValue);
1877
1878 if ( nullptr != pDrawDoc )
1879 pDrawDoc->SetAutoControlFocus( bAuto );
1880 else if (bAuto)
1881 {
1882 // if setting to true, and we don't have an
1883 // SdrModel, then we are changing the default and
1884 // must thus create an SdrModel, if we don't have an
1885 // SdrModel and we are leaving the default at false,
1886 // we don't need to make an SdrModel and can do nothing
1887 // #i52858# - method name changed
1889 pDrawDoc->SetAutoControlFocus ( bAuto );
1890 }
1891 }
1892 break;
1894 {
1896 bool bMode = *o3tl::doAccess<bool>(aValue);
1897
1898 if ( nullptr != pDrawDoc )
1899 pDrawDoc->SetOpenInDesignMode( bMode );
1900 else if (!bMode)
1901 {
1902 // if setting to false, and we don't have an
1903 // SdrModel, then we are changing the default and
1904 // must thus create an SdrModel, if we don't have an
1905 // SdrModel and we are leaving the default at true,
1906 // we don't need to make an SdrModel and can do
1907 // nothing
1908 // #i52858# - method name changed
1910 pDrawDoc->SetOpenInDesignMode ( bMode );
1911 }
1912 }
1913 break;
1914 // #i42634# New property to set the bInReading
1915 // flag at the document, used during binary import
1917 {
1918 SwDoc* pDoc = m_pDocShell->GetDoc();
1919 bool bBool (false);
1920 if( aValue >>= bBool )
1921 {
1922 pDoc->SetInReading( bBool );
1923 }
1924 }
1925 break;
1927 {
1928 SwDoc* pDoc = m_pDocShell->GetDoc();
1929 bool bBool = {};
1930 if (aValue >>= bBool)
1931 { // HACK: writerfilter has to use API to set this :(
1932 bool bOld = pDoc->IsInWriterfilterImport();
1933 pDoc->SetInWriterfilterImport(bBool);
1934 if (bOld && !bBool)
1935 {
1936 pDoc->getIDocumentFieldsAccess().SetFieldsDirty(false, nullptr, SwNodeOffset(0));
1937 }
1938 }
1939 }
1940 break;
1941 case WID_DOC_BUILDID:
1942 aValue >>= maBuildId;
1943 break;
1944
1946 {
1947 bool bDefaultPageMode( false );
1948 aValue >>= bDefaultPageMode;
1949 m_pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
1950 }
1951 break;
1953 setGrabBagItem(aValue);
1954 break;
1955
1956 default:
1957 {
1958 const SfxPoolItem& rItem = m_pDocShell->GetDoc()->GetDefault(pEntry->nWID);
1959 std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
1960 pNewItem->PutValue(aValue, pEntry->nMemberId);
1961 m_pDocShell->GetDoc()->SetDefault(*pNewItem);
1962 }
1963 }
1964}
1965
1966Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
1967{
1968 SolarMutexGuard aGuard;
1969 if(!IsValid())
1970 throw DisposedException("", static_cast< XTextDocument* >(this));
1971
1972 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
1973
1974 if(!pEntry)
1975 throw UnknownPropertyException(rPropertyName);
1976 Any aAny;
1977 switch(pEntry->nWID)
1978 {
1980 aAny <<= m_pDocShell->IsTemplate();
1981 break;
1982 case WID_DOC_CHAR_COUNT :
1983 case WID_DOC_PARA_COUNT :
1984 case WID_DOC_WORD_COUNT :
1985 {
1986 const SwDocStat& rStat(m_pDocShell->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true ));
1987 sal_Int32 nValue;
1988 switch(pEntry->nWID)
1989 {
1990 case WID_DOC_CHAR_COUNT :nValue = rStat.nChar;break;
1991 case WID_DOC_PARA_COUNT :nValue = rStat.nPara;break;
1992 case WID_DOC_WORD_COUNT :nValue = rStat.nWord;break;
1993 }
1994 aAny <<= nValue;
1995 }
1996 break;
1998 {
1999 aAny <<= SW_MOD()->GetDocStatWordDelim();
2000 }
2001 break;
2004 {
2006 bool bSet = false;
2007 if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2008 {
2010 }
2011 else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2012 {
2013 bSet = bool(eMode & RedlineFlags::On);
2014 }
2015 aAny <<= bSet;
2016 }
2017 break;
2019 {
2020 SwDoc* pDoc = m_pDocShell->GetDoc();
2022 }
2023 break;
2025 aAny <<= m_pDocShell->GetDoc()->GetTOIAutoMarkURL();
2026 break;
2027 case WID_DOC_HIDE_TIPS :
2028 aAny <<= SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2029 break;
2031 {
2033 eRedMode = eRedMode & RedlineFlags::ShowMask;
2034 sal_Int16 nRet = RedlineDisplayType::NONE;
2035 if(RedlineFlags::ShowInsert == eRedMode)
2037 else if(RedlineFlags::ShowDelete == eRedMode)
2038 nRet = RedlineDisplayType::REMOVED;
2039 else if(RedlineFlags::ShowMask == eRedMode)
2040 nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2041 aAny <<= nRet;
2042 }
2043 break;
2045 {
2047 Reference<XForbiddenCharacters> xRet = mxPropertyHelper;
2048 aAny <<= xRet;
2049 }
2050 break;
2052 {
2053 aAny <<= static_cast < sal_Int16 > (m_pDocShell->GetDoc()->GetNumberFormatter ()->GetYear2000());
2054 }
2055 break;
2057 {
2059 bool bAuto;
2060 if ( nullptr != pDrawDoc )
2061 bAuto = pDrawDoc->GetAutoControlFocus();
2062 else
2063 bAuto = false;
2064 aAny <<= bAuto;
2065 }
2066 break;
2068 {
2070 bool bMode;
2071 if ( nullptr != pDrawDoc )
2072 bMode = pDrawDoc->GetOpenInDesignMode();
2073 else
2074 bMode = true;
2075 aAny <<= bMode;
2076 }
2077 break;
2079 aAny <<= m_pDocShell->GetBasicContainer();
2080 break;
2082 aAny <<= m_pDocShell->GetDialogContainer();
2083 break;
2084 case WID_DOC_VBA_DOCOBJ:
2085 {
2086 /* #i111553# This property provides the name of the constant that
2087 will be used to store this model in the global Basic manager.
2088 That constant will be equivalent to 'ThisComponent' but for
2089 each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
2090 constant can co-exist, as required by VBA. */
2091 aAny <<= OUString( "ThisWordDoc" );
2092 }
2093 break;
2095 aAny <<= getRuntimeUID();
2096 break;
2098 aAny <<= m_pDocShell->GetDoc()->IsInReading();
2099 break;
2100 case WID_DOC_BUILDID:
2101 aAny <<= maBuildId;
2102 break;
2104 aAny <<= hasValidSignatures();
2105 break;
2107 getGrabBagItem(aAny);
2108 break;
2109
2110 default:
2111 {
2112 const SfxPoolItem& rItem = m_pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2113 rItem.QueryValue(aAny, pEntry->nMemberId);
2114 }
2115 }
2116 return aAny;
2117}
2118
2119void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2120 const Reference< XPropertyChangeListener > & /*aListener*/)
2121{
2122 OSL_FAIL("not implemented");
2123}
2124
2125void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2126 const Reference< XPropertyChangeListener > & /*aListener*/)
2127{
2128 OSL_FAIL("not implemented");
2129}
2130
2131void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2132 const Reference< XVetoableChangeListener > & /*aListener*/)
2133{
2134 OSL_FAIL("not implemented");
2135}
2136
2137void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2138 const Reference< XVetoableChangeListener > & /*aListener*/)
2139{
2140 OSL_FAIL("not implemented");
2141}
2142
2143Reference< XNameAccess > SwXTextDocument::getLinks()
2144{
2145 if(!mxLinkTargetSupplier.is())
2146 {
2148 }
2149 return mxLinkTargetSupplier;
2150}
2151
2152Reference< XEnumerationAccess > SwXTextDocument::getRedlines( )
2153{
2154 if(!mxXRedlines.is())
2155 {
2157 }
2158 return mxXRedlines;
2159}
2160
2162{
2163 // why does SwBaseShell not just call refresh? maybe because it's rSh is
2164 // (sometimes) a different shell than GetWrtShell()?
2165 lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
2166 std::unique_lock aGuard(m_pImpl->m_Mutex);
2167 m_pImpl->m_RefreshListeners.notifyEach(aGuard,
2168 & util::XRefreshListener::refreshed, ev);
2169}
2170
2172{
2173 SolarMutexGuard aGuard;
2174 if(!IsValid())
2175 throw DisposedException("", static_cast< XTextDocument* >(this));
2176
2177 SwViewShell *pViewShell = m_pDocShell->GetWrtShell();
2179 if(pViewShell)
2180 pViewShell->Reformat();
2181}
2182
2184 const Reference<util::XRefreshListener> & xListener)
2185{
2186 if (xListener)
2187 {
2188 std::unique_lock aGuard(m_pImpl->m_Mutex);
2189 m_pImpl->m_RefreshListeners.addInterface(aGuard, xListener);
2190 }
2191}
2192
2194 const Reference<util::XRefreshListener> & xListener)
2195{
2196 if (xListener)
2197 {
2198 std::unique_lock aGuard(m_pImpl->m_Mutex);
2199 m_pImpl->m_RefreshListeners.removeInterface(aGuard, xListener);
2200 }
2201}
2202
2204{
2205 SolarMutexGuard aGuard;
2206 if(!IsValid())
2207 throw DisposedException("", static_cast< XTextDocument* >(this));
2208
2209 SwDoc* pDoc = m_pDocShell->GetDoc();
2211 if( !rLnkMan.GetLinks().empty() )
2212 {
2213 UnoActionContext aAction(pDoc);
2214 rLnkMan.UpdateAllLinks( false, true, nullptr );
2215 }
2216}
2217
2218//XPropertyState
2219PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2220{
2221 SolarMutexGuard aGuard;
2222 if(!IsValid())
2223 throw DisposedException("", static_cast< XTextDocument* >(this));
2224
2225 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
2226 if(!pEntry)
2227 throw UnknownPropertyException(rPropertyName);
2228 return PropertyState_DIRECT_VALUE;
2229}
2230
2231Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2232{
2233 const sal_Int32 nCount = rPropertyNames.getLength();
2234 Sequence < PropertyState > aRet ( nCount );
2235
2236 std::transform(rPropertyNames.begin(), rPropertyNames.end(), aRet.getArray(),
2237 [this](const OUString& rName) -> PropertyState { return getPropertyState(rName); });
2238
2239 return aRet;
2240}
2241
2242void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2243{
2244 SolarMutexGuard aGuard;
2245 if(!IsValid())
2246 throw DisposedException("", static_cast< XTextDocument* >(this));
2247
2248 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
2249 if(!pEntry)
2250 throw UnknownPropertyException(rPropertyName);
2251 switch(pEntry->nWID)
2252 {
2253 case 0:default:break;
2254 }
2255}
2256
2257Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2258{
2259 SolarMutexGuard aGuard;
2260 if(!IsValid())
2261 throw DisposedException("", static_cast< XTextDocument* >(this));
2262
2263 const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
2264 if(!pEntry)
2265 throw UnknownPropertyException(rPropertyName);
2266 Any aAny;
2267 switch(pEntry->nWID)
2268 {
2269 case 0:default:break;
2270 }
2271 return aAny;
2272}
2273
2275{
2277
2278 uno::Any aAny( rPrintUIOptions.getValue( "RenderDevice" ));
2279 uno::Reference< awt::XDevice > xRenderDevice;
2280 aAny >>= xRenderDevice;
2281 if (xRenderDevice.is())
2282 {
2283 VCLXDevice* pDevice = dynamic_cast<VCLXDevice*>( xRenderDevice.get() );
2284 pOut = pDevice ? pDevice->GetOutputDevice() : VclPtr< OutputDevice >();
2285 }
2286
2287 return pOut;
2288}
2289
2291 const uno::Sequence< beans::PropertyValue >& rOptions,
2292 const char *pPropName )
2293{
2294 return std::any_of(rOptions.begin(), rOptions.end(),
2295 [&pPropName](const beans::PropertyValue& rProp) {
2296 return rProp.Name.equalsAscii( pPropName ); });
2297}
2298
2300 const uno::Sequence< beans::PropertyValue >& rOptions,
2301 const char *pPropName )
2302{
2303 bool bRes = false;
2304 auto pOption = std::find_if(rOptions.begin(), rOptions.end(),
2305 [&pPropName](const beans::PropertyValue& rProp) {
2306 return rProp.Name.equalsAscii( pPropName ); });
2307 if (pOption != rOptions.end())
2308 pOption->Value >>= bRes;
2309 return bRes;
2310}
2311
2313 bool &rbIsSwSrcView,
2314 const uno::Sequence< beans::PropertyValue >& rOptions,
2315 bool bIsPDFExport )
2316{
2317 // get view shell to use
2318 SfxViewShell *pView = nullptr;
2319 if (bIsPDFExport)
2320 pView = GuessViewShell( rbIsSwSrcView );
2321 else
2322 {
2323 uno::Any aTmp;
2324 auto pOption = std::find_if(rOptions.begin(), rOptions.end(),
2325 [](const beans::PropertyValue& rProp) { return rProp.Name == "View"; });
2326 if (pOption != rOptions.end())
2327 aTmp = pOption->Value;
2328
2329 uno::Reference< frame::XController > xController;
2330 if (aTmp >>= xController)
2331 {
2332 OSL_ENSURE( xController.is(), "controller is empty!" );
2333 pView = GuessViewShell( rbIsSwSrcView, xController );
2334 }
2335 }
2336 return pView;
2337}
2338
2339/*
2340 * GetRenderDoc:
2341 * returns the document to be rendered, usually this will be the 'regular'
2342 * document but in case of PDF export of (multi-)selection it will
2343 * be a temporary document that gets created if not already done.
2344 * The rpView variable will be set (if not already done) to the used
2345 * SfxViewShell.
2346*/
2348 SfxViewShell *&rpView,
2349 const uno::Any& rSelection,
2350 bool bIsPDFExport )
2351{
2352 SwDoc *pDoc = nullptr;
2353
2354 uno::Reference< frame::XModel > xModel;
2355 rSelection >>= xModel;
2356 if (xModel == m_pDocShell->GetModel())
2357 pDoc = m_pDocShell->GetDoc();
2358 else
2359 {
2360 OSL_ENSURE( !xModel.is(), "unexpected model found" );
2361
2362 if (rSelection.hasValue()) // is anything selected ?
2363 {
2364 // this part should only be called when a temporary document needs to be created,
2365 // for example for PDF export or printing of (multi-)selection only.
2366
2367 if (!rpView)
2368 {
2369 bool bIsSwSrcView = false;
2370 // aside from maybe PDF export the view should always have been provided!
2371 OSL_ENSURE( bIsPDFExport, "view is missing, guessing one..." );
2372
2373 rpView = GuessViewShell( bIsSwSrcView );
2374 }
2375 OSL_ENSURE( rpView, "SwViewShell missing" );
2376 // the view shell should be SwView for documents PDF export.
2377 // for the page preview no selection should be possible
2378 // (the export dialog does not allow for this option)
2379 if (auto pSwView = dynamic_cast<SwView *>( rpView ))
2380 {
2381 if (!m_pRenderData)
2382 {
2383 OSL_FAIL("GetRenderDoc: no renderdata");
2384 return nullptr;
2385 }
2386 SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell());
2387 if (!xDocSh.Is())
2388 {
2389 xDocSh = pSwView->CreateTmpSelectionDoc();
2390 m_pRenderData->SetTempDocShell(xDocSh);
2391 }
2392 if (xDocSh.Is())
2393 {
2394 pDoc = static_cast<SwDocShell*>(&xDocSh)->GetDoc();
2395 rpView = pDoc->GetDocShell()->GetView();
2396 }
2397 }
2398 else
2399 {
2400 OSL_FAIL("unexpected SwViewShell" );
2401 }
2402 }
2403 }
2404 return pDoc;
2405}
2406
2408 SwDoc &rDoc,
2409 const SwPrintUIOptions &rPrintUIOptions,
2410 bool bIsPDFEXport )
2411{
2412 SwPrintData aDocPrintData( rDoc.getIDocumentDeviceAccess().getPrintData() );
2413
2414 aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2415 aDocPrintData.SetPrintTable( true ); // for now it was decided that tables should always be printed
2416 aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2417 aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2418 aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2419 aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2420 aDocPrintData.SetPrintReverse( false ); /*handled by print dialog now*/
2421 aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2422 aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2423 aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2424 aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2425 aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2426 aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2427 aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2428 // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2429 // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2430 aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2431 aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2432
2433 rDoc.getIDocumentDeviceAccess().setPrintData( aDocPrintData );
2434}
2435
2437 const uno::Any& rSelection,
2438 const uno::Sequence< beans::PropertyValue >& rxOptions )
2439{
2440 SolarMutexGuard aGuard;
2441 if(!IsValid())
2442 {
2443 throw DisposedException( OUString(),
2444 static_cast< XTextDocument* >(this) );
2445 }
2446
2447 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2448 bool bIsSwSrcView = false;
2449 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2450
2451 if (!bIsSwSrcView && !m_pRenderData)
2452 m_pRenderData.reset(new SwRenderData);
2453 if (!m_pPrintUIOptions)
2455 bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2456
2457 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2458 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2459 if (!pDoc || !pView)
2460 return 0;
2461
2462 // save current UI options from the print dialog for the next call to that dialog
2464
2465 sal_Int32 nRet = 0;
2466 if (bIsSwSrcView)
2467 {
2468 SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2470 nRet = rSwSrcView.PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2471 }
2472 else
2473 {
2474 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2475
2476 // TODO/mba: we really need a generic way to get the SwViewShell!
2477 SwViewShell* pViewShell = nullptr;
2478 SwView* pSwView = dynamic_cast<SwView*>( pView );
2479 if ( pSwView )
2480 {
2481 pViewShell = pSwView->GetWrtShellPtr();
2482 }
2483 else
2484 {
2485 if ( bIsPDFExport && bFormat )
2486 {
2487 //create a hidden view to be able to export as PDF also in print preview
2488 //pView and pSwView are not changed intentionally!
2490 pViewShell = static_cast<SwView*>(m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2491 }
2492 else
2493 pViewShell = static_cast<SwPagePreview*>(pView)->GetViewShell();
2494 }
2495
2496 if (!pViewShell || !pViewShell->GetLayout())
2497 return 0;
2498
2499 if (bFormat)
2500 {
2501 // #i38289
2502 if( pViewShell->GetViewOptions()->getBrowseMode() ||
2503 pViewShell->GetViewOptions()->IsWhitespaceHidden() )
2504 {
2505 SwViewOption aOpt( *pViewShell->GetViewOptions() );
2506 aOpt.setBrowseMode( false );
2507 aOpt.SetHideWhitespaceMode( false );
2508 pViewShell->ApplyViewOptions( aOpt );
2509 if (pSwView)
2510 {
2511 pSwView->RecheckBrowseMode();
2512 }
2513 }
2514
2515 // reformatting the document for printing will show the changes in the view
2516 // which is likely to produce many unwanted and not nice to view actions.
2517 // We don't want that! Thus we disable updating of the view.
2518 pViewShell->StartAction();
2519
2520 if (pSwView)
2521 {
2522 if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2523 m_pRenderData->ViewOptionAdjustStop();
2524 if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2525 {
2526 m_pRenderData->ViewOptionAdjustStart(
2527 *pViewShell, *pViewShell->GetViewOptions() );
2528 }
2529 }
2530
2531 m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
2532 m_pPrintUIOptions.get(), bIsPDFExport );
2533
2534 if (pSwView)
2535 {
2536 // PDF export should not make use of the SwPrtOptions
2537 const SwPrintData *pPrtOptions = bIsPDFExport
2538 ? nullptr : m_pRenderData->GetSwPrtOptions();
2539 bool setShowPlaceHoldersInPDF = false;
2540 if(bIsPDFExport)
2541 setShowPlaceHoldersInPDF = lcl_GetBoolProperty( rxOptions, "ExportPlaceholders" );
2542 m_pRenderData->ViewOptionAdjust( pPrtOptions, setShowPlaceHoldersInPDF );
2543 }
2544
2545 // since printing now also use the API for PDF export this option
2546 // should be set for printing as well ...
2547 pViewShell->SetPDFExportOption( true );
2548
2549 // there is some redundancy between those two function calls, but right now
2550 // there is no time to sort this out.
2551 //TODO: check what exactly needs to be done and make just one function for that
2552 pViewShell->CalcLayout();
2553
2554 // #122919# Force field update before PDF export, but after layout init (tdf#121962)
2555 bool bStateChanged = false;
2556 // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2558 {
2559 pRenderDocShell->EnableSetModified( false );
2560 bStateChanged = true;
2561 }
2562 pViewShell->SwViewShell::UpdateFields(true);
2563 if( bStateChanged )
2564 pRenderDocShell->EnableSetModified();
2565
2566 pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2567
2568 pViewShell->SetPDFExportOption( false );
2569
2570 // enable view again
2571 pViewShell->EndAction();
2572 }
2573
2574 const sal_Int32 nPageCount = pViewShell->GetPageCount();
2575
2576 // get number of pages to be rendered
2577
2578 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2579 if (bPrintProspect)
2580 {
2582 nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2583 }
2584 else
2585 {
2586 const SwPostItMode nPostItMode = static_cast<SwPostItMode>( m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 ) );
2587 if (nPostItMode != SwPostItMode::NONE)
2588 {
2590 m_pRenderData->CreatePostItData(*pDoc, pViewShell->GetViewOptions(), pOutDev);
2591 }
2592
2593 // get set of valid document pages (according to the current settings)
2594 // and their start frames
2595 SwDoc::CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2596
2597 if (nPostItMode != SwPostItMode::NONE)
2598 {
2600 *m_pPrintUIOptions, nPageCount );
2601 }
2602
2603 nRet = m_pRenderData->GetPagesToPrint().size();
2604 }
2605 }
2606 OSL_ENSURE( nRet >= 0, "negative number of pages???" );
2607 // tdf#144989 the layout is complete now - prevent DoIdleJobs() from
2608 // messing it up, particulary SwDocUpdateField::MakeFieldList_() unhiding
2609 // sections
2611
2612 return nRet;
2613}
2614
2615uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2616 sal_Int32 nRenderer,
2617 const uno::Any& rSelection,
2618 const uno::Sequence< beans::PropertyValue >& rxOptions )
2619{
2620 SolarMutexGuard aGuard;
2621 if(!IsValid())
2622 {
2623 throw DisposedException("", static_cast< XTextDocument* >(this));
2624 }
2625
2626 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2627 bool bIsSwSrcView = false;
2628 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2629
2630 // m_pRenderData should NOT be created here!
2631 // That should only be done in getRendererCount. If this function is called before
2632 // getRendererCount was called then the caller will probably just retrieve the extra UI options
2633 // and is not interested in getting valid information about the other data that would
2634 // otherwise be provided here!
2635// if( ! m_pRenderData )
2636// m_pRenderData = new SwRenderData;
2637 if (!m_pPrintUIOptions)
2639 m_pPrintUIOptions->processProperties( rxOptions );
2640 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2641 const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2642 const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup" );
2643
2644 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2645 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2646 if (!pDoc || !pView)
2647 return uno::Sequence< beans::PropertyValue >();
2648
2649 // due to #110067# (document page count changes sometimes during
2650 // PDF export/printing) we can not check for the upper bound properly.
2651 // Thus instead of throwing the exception we silently return.
2652 if (0 > nRenderer)
2653 throw IllegalArgumentException();
2654
2655 sal_Int32 nMaxRenderer = 0;
2656 if (!bIsSwSrcView && m_pRenderData)
2657 {
2658 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2659 nMaxRenderer = bPrintProspect?
2660 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2661 m_pRenderData->GetPagesToPrint().size() - 1;
2662 }
2663 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2664 // we obmit checking of the upper bound in this case.
2665 if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2666 return uno::Sequence< beans::PropertyValue >();
2667
2668 uno::Sequence< beans::PropertyValue > aRenderer;
2669 if (m_pRenderData)
2670 {
2671 // #i114210#
2672 // determine the correct page number from the renderer index
2673 // #i114875
2674 // consider brochure print
2675 const sal_Int32 nPage = bPrintProspect
2676 ? nRenderer + 1
2677 : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2678
2679 // get paper tray to use ...
2680 sal_Int32 nPrinterPaperTray = -1;
2681 if (! bPrintPaperFromSetup)
2682 {
2683 // ... from individual page style (see the page tab in Format/Page dialog)
2684 const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2685 std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2686 if (aIt != rPaperTrays.end())
2687 nPrinterPaperTray = aIt->second;
2688 }
2689
2690 awt::Size aPageSize;
2691 awt::Point aPagePos;
2692 awt::Size aPreferredPageSize;
2693 Size aTmpSize;
2694 if (bIsSwSrcView || bPrintProspect)
2695 {
2696 // for printing of HTML source code and prospect printing we should use
2697 // the printers paper size since
2698 // a) HTML source view has no page size
2699 // b) prospect printing has a different page size from the documents page
2700 // since two document pages will get rendered on one printer page
2701
2702 // since PageIncludesNonprintableArea will be set to true we can return the
2703 // printers paper size here.
2704 // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2705 // case we won't get an OutputDevice here, but then the caller also has no need
2706 // for the correct PageSize right now...
2707 VclPtr< Printer > pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ).get());
2708 if (pPrinter)
2709 {
2710 // HTML source view and prospect adapt to the printer's paper size
2711 aTmpSize = pPrinter->GetPaperSize();
2712 aTmpSize = OutputDevice::LogicToLogic( aTmpSize,
2713 pPrinter->GetMapMode(), MapMode( MapUnit::Map100thMM ));
2714 aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2715 #if 0
2716 // #i115048# it seems users didn't like getting double the formatted page size
2717 // revert to "old" behavior scaling to the current paper size of the printer
2718 if (bPrintProspect)
2719 {
2720 // we just state what output size we would need
2721 // which may cause vcl to set that page size on the printer
2722 // (if available and not overridden by the user)
2723 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2724 aPreferredPageSize = awt::Size ( convertTwipToMm100( 2 * aTmpSize.Width() ),
2725 convertTwipToMm100( aTmpSize.Height() ));
2726 }
2727 #else
2728 if( bPrintProspect )
2729 {
2730 // just switch to an appropriate portrait/landscape format
2731 // FIXME: brochure printing with landscape pages puts the
2732 // pages next to each other, so landscape is currently always
2733 // the better choice
2734 if( aPageSize.Width < aPageSize.Height )
2735 {
2736 aPreferredPageSize.Width = aPageSize.Height;
2737 aPreferredPageSize.Height = aPageSize.Width;
2738 }
2739 }
2740 #endif
2741 }
2742 }
2743 else
2744 {
2745 // TODO/mba: we really need a generic way to get the SwViewShell!
2746 SwViewShell* pVwSh = nullptr;
2747 SwView* pSwView = dynamic_cast<SwView*>( pView );
2748 if ( pSwView )
2749 pVwSh = pSwView->GetWrtShellPtr();
2750 else
2751 pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2752
2753 if (pVwSh)
2754 {
2755 aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2756 aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
2757 convertTwipToMm100( aTmpSize.Height() ));
2758 Point aPoint = pVwSh->GetPagePos(nPage);
2759 aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), convertTwipToMm100(aPoint.Y()));
2760 }
2761 }
2762
2763 sal_Int32 nLen = 3;
2764 aRenderer = { comphelper::makePropertyValue("PageSize", aPageSize),
2765 comphelper::makePropertyValue("PageIncludesNonprintableArea", true),
2766 comphelper::makePropertyValue("PagePos", aPagePos) };
2767 if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2768 {
2769 ++nLen;
2770 aRenderer.realloc( nLen );
2771 auto pRenderer = aRenderer.getArray();
2772 pRenderer[ nLen - 1 ].Name = "PreferredPageSize";
2773 pRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2774 }
2775 if (nPrinterPaperTray >= 0)
2776 {
2777 ++nLen;
2778 aRenderer.realloc( nLen );
2779 auto pRenderer = aRenderer.getArray();
2780 pRenderer[ nLen - 1 ].Name = "PrinterPaperTray";
2781 pRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2782 }
2783 }
2784
2785 // #i117783#
2787 {
2788 const SwPagePreviewPrtData* pPagePrintSettings =
2790 if ( pPagePrintSettings &&
2791 ( pPagePrintSettings->GetRow() > 1 ||
2792 pPagePrintSettings->GetCol() > 1 ) )
2793 {
2794 // extend render data by page print settings attributes
2795 sal_Int32 nLen = aRenderer.getLength();
2796 const sal_Int32 nRenderDataIdxStart = nLen;
2797 nLen += 9;
2798 aRenderer.realloc( nLen );
2799 auto pRenderer = aRenderer.getArray();
2800 // put page print settings attribute into render data
2801 const sal_Int32 nRow = pPagePrintSettings->GetRow();
2802 pRenderer[ nRenderDataIdxStart + 0 ].Name = "NUpRows";
2803 pRenderer[ nRenderDataIdxStart + 0 ].Value <<= std::max<sal_Int32>( nRow, 1);
2804 const sal_Int32 nCol = pPagePrintSettings->GetCol();
2805 pRenderer[ nRenderDataIdxStart + 1 ].Name = "NUpColumns";
2806 pRenderer[ nRenderDataIdxStart + 1 ].Value <<= std::max<sal_Int32>( nCol, 1);
2807 pRenderer[ nRenderDataIdxStart + 2 ].Name = "NUpPageMarginLeft";
2808 pRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
2809 pRenderer[ nRenderDataIdxStart + 3 ].Name = "NUpPageMarginRight";
2810 pRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
2811 pRenderer[ nRenderDataIdxStart + 4 ].Name = "NUpPageMarginTop";
2812 pRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
2813 pRenderer[ nRenderDataIdxStart + 5 ].Name = "NUpPageMarginBottom";
2814 pRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
2815 pRenderer[ nRenderDataIdxStart + 6 ].Name = "NUpHorizontalSpacing";
2816 pRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
2817 pRenderer[ nRenderDataIdxStart + 7 ].Name = "NUpVerticalSpacing";
2818 pRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
2819 {
2821 if ( pPrinter )
2822 {
2823 awt::Size aNewPageSize;
2824 const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
2825 aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
2826 if ( ( pPagePrintSettings->GetLandscape() &&
2827 aPageSize.Width() < aPageSize.Height() ) ||
2828 ( !pPagePrintSettings->GetLandscape() &&
2829 aPageSize.Width() > aPageSize.Height() ) )
2830 {
2831 aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
2832 }
2833 pRenderer[ nRenderDataIdxStart + 8 ].Name = "NUpPaperSize";
2834 pRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
2835 }
2836 }
2837 }
2838
2840 }
2841
2842 m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2843
2844 return aRenderer;
2845}
2846
2848 /* out */ bool &rbIsSwSrcView,
2849 const uno::Reference< css::frame::XController >& rController )
2850{
2851 // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2852 // must not be used (see comment from MBA)
2853
2854 SfxViewShell *pView = nullptr;
2855 SwView *pSwView = nullptr;
2856 SwPagePreview *pSwPagePreview = nullptr;
2857 SwSrcView *pSwSrcView = nullptr;
2859
2860 // look for the view shell with the same controller in use,
2861 // otherwise look for a suitable view, preferably a SwView,
2862 // if that one is not found use a SwPagePreview if found.
2863 while (pFrame)
2864 {
2865 pView = pFrame->GetViewShell();
2866 pSwView = dynamic_cast< SwView * >(pView);
2867 pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2868 if (!pSwPagePreview)
2869 pSwPagePreview = dynamic_cast< SwPagePreview * >(pView);
2870 if (rController.is())
2871 {
2872 if (pView && pView->GetController() == rController)
2873 break;
2874 }
2875 else if (pSwView || pSwSrcView)
2876 break;
2877 pFrame = SfxViewFrame::GetNext( *pFrame, m_pDocShell, false );
2878 }
2879
2880 OSL_ENSURE( pSwView || pSwPagePreview || pSwSrcView, "failed to get view shell" );
2881 if (pView)
2882 rbIsSwSrcView = pSwSrcView != nullptr;
2883 return pView;
2884}
2885
2887 sal_Int32 nRenderer,
2888 const uno::Any& rSelection,
2889 const uno::Sequence< beans::PropertyValue >& rxOptions )
2890{
2891 SolarMutexGuard aGuard;
2892 if(!IsValid())
2893 {
2894 throw DisposedException( OUString(),
2895 static_cast< XTextDocument* >(this) );
2896 }
2897
2898 // due to #110067# (document page count changes sometimes during
2899 // PDF export/printing) we can not check for the upper bound properly.
2900 // Thus instead of throwing the exception we silently return.
2901 if (0 > nRenderer)
2902 throw IllegalArgumentException();
2903
2904 // tdf#135244: prevent jumping to cursor at any temporary modification
2905 auto aLock = m_pDocShell->LockAllViews();
2906
2907 const bool bHasPDFExtOutDevData = lcl_SeqHasProperty( rxOptions, "HasPDFExtOutDevData" );
2908 const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ) || bHasPDFExtOutDevData;
2909 bool bIsSwSrcView = false;
2910 SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2911
2912 OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
2913 OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
2914 if (!bIsSwSrcView && !m_pRenderData)
2915 m_pRenderData.reset(new SwRenderData);
2916 if (!m_pPrintUIOptions)
2918 m_pPrintUIOptions->processProperties( rxOptions );
2919 const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2920 const bool bLastPage = m_pPrintUIOptions->getBoolValue( "IsLastPage" );
2921
2922 SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2923 OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2924 if (pDoc && pView)
2925 {
2926 sal_Int32 nMaxRenderer = 0;
2927 if (!bIsSwSrcView)
2928 {
2929 OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2930 nMaxRenderer = bPrintProspect?
2931 m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2932 m_pRenderData->GetPagesToPrint().size() - 1;
2933 }
2934 // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2935 // we obmit checking of the upper bound in this case.
2936 if (bIsSwSrcView || nRenderer <= nMaxRenderer)
2937 {
2938 if (bIsSwSrcView)
2939 {
2940 SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2942 rSwSrcView.PrintSource(pOutDev, nRenderer + 1, false);
2943 }
2944 else
2945 {
2946 // the view shell should be SwView for documents PDF export
2947 // or SwPagePreview for PDF export of the page preview
2948 SwViewShell* pVwSh = nullptr;
2949 // TODO/mba: we really need a generic way to get the SwViewShell!
2950 const SwView* pSwView = dynamic_cast<const SwView*>(pView);
2951 if (pSwView)
2952 pVwSh = pSwView->GetWrtShellPtr();
2953 else
2954 pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2955
2956 // get output device to use
2958
2959 if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
2960 {
2961 const OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange" );
2962 const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage" );
2963 bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2964
2965 OSL_ENSURE((pSwView && m_pRenderData->IsViewOptionAdjust())
2966 || (!pSwView && !m_pRenderData->IsViewOptionAdjust()),
2967 "SwView / SwViewOptionAdjust_Impl availability mismatch" );
2968
2969 // since printing now also use the API for PDF export this option
2970 // should be set for printing as well ...
2971 pVwSh->SetPDFExportOption( true );
2972
2973 // #i12836# enhanced pdf export
2974
2975 // First, we have to export hyperlinks, notes, and outline to pdf.
2976 // During this process, additional information required for tagging
2977 // the pdf file are collected, which are evaluated during painting.
2978
2979 SwWrtShell* pWrtShell = pSwView ? pSwView->GetWrtShellPtr() : nullptr;
2980
2981 SwPrintData rSwPrtOptions = *m_pRenderData->GetSwPrtOptions();
2982
2983 if (bIsPDFExport && (bFirstPage || bHasPDFExtOutDevData) && pWrtShell)
2984 {
2985 rSwPrtOptions.SetPrintPostIts(
2986 lcl_GetBoolProperty(rxOptions, "ExportNotesInMargin")
2989 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
2990 }
2991
2992 if (bPrintProspect)
2993 pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
2994 else // normal printing and PDF export
2995 pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer, bIsPDFExport );
2996
2997 // #i35176#
2998
2999 // After printing the last page, we take care for the links coming
3000 // from the EditEngine. The links are generated during the painting
3001 // process, but the destinations are still missing.
3002
3003 if (bIsPDFExport && bLastPage && pWrtShell)
3004 {
3005 SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, true, rSwPrtOptions );
3006 }
3007
3008 pVwSh->SetPDFExportOption( false );
3009
3010 // last page to be rendered? (not necessarily the last page of the document)
3011 // -> do clean-up of data
3012 if (bLastPage)
3013 {
3014 // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3015 // of the shell, which might get destroyed in lcl_DisposeView!
3016 if (m_pRenderData->IsViewOptionAdjust())
3017 m_pRenderData->ViewOptionAdjustStop();
3018
3019 if (m_pRenderData->HasPostItData())
3020 m_pRenderData->DeletePostItData();
3022 {
3024 m_pHiddenViewFrame = nullptr;
3025
3026 // prevent crash described in #i108805
3027 SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3028 SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3029 pSet->Put( SfxBoolItem( SID_HIDDEN, false ) );
3030
3031 }
3032 }
3033 }
3034 }
3035 }
3036 }
3037 if( bLastPage )
3038 {
3039 // tdf#144989 enable DoIdleJobs() again after last page
3041 m_pRenderData.reset();
3042 m_pPrintUIOptions.reset();
3043 }
3044}
3045
3046// xforms::XFormsSupplier
3047Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3048{
3049 SolarMutexGuard aGuard;
3050 if ( !m_pDocShell )
3051 throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
3052 SwDoc* pDoc = m_pDocShell->GetDoc();
3053 return pDoc->getXForms();
3054}
3055
3056uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3057{
3058 SolarMutexGuard aGuard;
3059 if (!IsValid())
3060 {
3061 throw DisposedException("SwXTextDocument not valid",
3062 static_cast<XTextDocument*>(this));
3063 }
3064
3066 *m_pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
3067}
3068
3069uno::Reference< util::XCloneable > SwXTextDocument::createClone( )
3070{
3071 SolarMutexGuard aGuard;
3072 if(!IsValid())
3073 throw DisposedException("", static_cast< XTextDocument* >(this));
3074
3075 // create a new document - hidden - copy the storage and return it
3076 // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3077 // and thus SfxObjectShellLock is not allowed here
3078 // the model holds reference to the shell, so the shell will not destructed at the end of method
3079 SfxObjectShellRef pShell = m_pDocShell->GetDoc()->CreateCopy(false, false);
3080 uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3081 uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3082 uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3083 storeToStorage( xNewStorage, aTempMediaDescriptor );
3084 uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3085 xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3086 return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3087}
3088
3089void SwXTextDocument::addPasteEventListener(const uno::Reference<text::XPasteListener>& xListener)
3090{
3091 SolarMutexGuard aGuard;
3092
3093 if (IsValid() && xListener.is())
3095}
3096
3098 const uno::Reference<text::XPasteListener>& xListener)
3099{
3100 SolarMutexGuard aGuard;
3101
3102 if (IsValid() && xListener.is())
3104}
3105
3107 int nOutputWidth, int nOutputHeight,
3108 int nTilePosX, int nTilePosY,
3109 tools::Long nTileWidth, tools::Long nTileHeight )
3110{
3111 SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3112 pViewShell->PaintTile(rDevice, nOutputWidth, nOutputHeight,
3113 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3114
3115 LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
3116 nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3117
3118 // Draw Form controls
3121 SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(0));
3122 SdrView* pDrawView = pViewShell->GetDrawView();
3123 SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3124 tools::Rectangle aTileRect(Point(nTilePosX, nTilePosY), Size(nTileWidth, nTileHeight));
3125 Size aOutputSize(nOutputWidth, nOutputHeight);
3126 LokControlHandler::paintControlTile(pPage, pDrawView, rEditWin, rDevice, aOutputSize, aTileRect);
3128}
3129
3131{
3132 SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3133 Size aDocSize = pViewShell->GetDocSize();
3134
3135 return Size(aDocSize.Width() + 2 * DOCUMENTBORDER,
3136 aDocSize.Height() + 2 * DOCUMENTBORDER);
3137}
3138
3139void SwXTextDocument::setPart(int nPart, bool /*bAllowChangeFocus*/)
3140{
3141 SolarMutexGuard aGuard;
3142
3143 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3144 if (!pWrtShell)
3145 return;
3146
3147 pWrtShell->GotoPage(nPart + 1, true);
3148}
3149
3151{
3152 SolarMutexGuard aGuard;
3153
3154 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3155 if (!pWrtShell)
3156 return 0;
3157
3158 return pWrtShell->GetPageCnt();
3159}
3160
3162{
3163 SolarMutexGuard aGuard;
3164
3165 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3166 if (!pWrtShell)
3167 return OUString();
3168
3169 return pWrtShell->getPageRectangles();
3170}
3171
3172void SwXTextDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard)
3173{
3174 SolarMutexGuard aGuard;
3175
3176 SwView* pView = m_pDocShell->GetView();
3177 if (pView)
3178 pView->GetEditWin().SetClipboard(xClipboard);
3179}
3180
3182{
3183 SolarMutexGuard aGuard;
3184
3185 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3186 if (!pWrtShell)
3187 return false;
3188
3190 if (SdrView* pSdrView = pWrtShell->GetDrawView())
3191 {
3192 if (pSdrView->GetTextEditObject())
3193 // Editing shape text
3194 return EditEngine::HasValidData(aDataHelper.GetTransferable());
3195 }
3196
3197 return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
3198}
3199
3201{
3202 if (SwView* pView = m_pDocShell->GetView())
3203 {
3204 // set the PgUp/PgDown offset
3205 pView->ForcePageUpDownOffset(2 * rRectangle.GetHeight() / 3);
3206 }
3207
3208 if (SwViewShell* pViewShell = m_pDocShell->GetWrtShell())
3209 {
3210 pViewShell->setLOKVisibleArea(rRectangle);
3211 }
3212}
3213
3214void SwXTextDocument::setClientZoom(int nTilePixelWidth_, int /*nTilePixelHeight_*/,
3215 int nTileTwipWidth_, int /*nTileTwipHeight_*/)
3216{
3217 // Here we set the zoom value as it has been set by the user in the client.
3218 // This value is used in postMouseEvent and setGraphicSelection methods
3219 // for in place chart editing. We assume that x and y scale is roughly
3220 // the same.
3222 if (!pIPClient)
3223 return;
3224
3225 SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3226 double fScale = 100.0 * nTilePixelWidth_ / nTileTwipWidth_
3228 SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3229 if (aOption.GetZoom() != fScale)
3230 {
3231 aOption.SetZoom(fScale);
3232 pWrtViewShell->ApplyViewOptions(aOption);
3233
3234 // Changing the zoom value doesn't always trigger the updating of
3235 // the client ole object area, so we call it directly.
3236 pIPClient->VisAreaChanged();
3237 }
3238}
3239
3241{
3242 SolarMutexGuard aGuard;
3243
3244 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3245 if (!pWrtShell)
3246 return PointerStyle::Arrow;
3247
3248 return pWrtShell->GetView().GetEditWin().GetPointer();
3249}
3250
3252{
3253 auto redlinesNode = rJson.startArray("redlines");
3254
3255 // Disable since usability is very low beyond some small number of changes.
3256 static bool bDisableRedlineComments = getenv("DISABLE_REDLINE") != nullptr;
3257 if (bDisableRedlineComments)
3258 return;
3259
3260 const SwRedlineTable& rRedlineTable
3262 for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
3263 {
3264 auto redlineNode = rJson.startStruct();
3265 rJson.put("index", rRedlineTable[i]->GetId());
3266 rJson.put("author", rRedlineTable[i]->GetAuthorString(1));
3267 rJson.put("type", SwRedlineTypeToOUString(
3268 rRedlineTable[i]->GetRedlineData().GetType()));
3269 rJson.put("comment",
3270 rRedlineTable[i]->GetRedlineData().GetComment());
3271 rJson.put("description", rRedlineTable[i]->GetDescr());
3272 OUString sDateTime = utl::toISO8601(
3273 rRedlineTable[i]->GetRedlineData().GetTimeStamp().GetUNODateTime());
3274 rJson.put("dateTime", sDateTime);
3275
3276 SwContentNode* pContentNd = rRedlineTable[i]->GetPointContentNode();
3277 SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
3278 if (pView && pContentNd)
3279 {
3280 SwShellCursor aCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()));
3281 aCursor.SetMark();
3282 aCursor.GetMark()->Assign(*pContentNd, rRedlineTable[i]->End()->GetContentIndex());
3283
3284 aCursor.FillRects();
3285
3286 SwRects* pRects(&aCursor);
3287 std::vector<OString> aRects;
3288 for (const SwRect& rNextRect : *pRects)
3289 aRects.push_back(rNextRect.SVRect().toString());
3290
3291 const OString sRects = comphelper::string::join("; ", aRects);
3292 rJson.put("textRange", sRects);
3293 }
3294 }
3295}
3296
3298{
3299 SW_MOD()->GetRedlineAuthorInfo(rJsonWriter);
3300}
3301
3303{
3304 SwView* pView = m_pDocShell->GetView();
3305 dynamic_cast<SwCommentRuler&>(pView->GetHRuler()).CreateJsonNotification(rJsonWriter);
3306}
3307
3309{
3310 SolarMutexGuard aGuard;
3311 auto commentsNode = rJsonWriter.startArray("comments");
3312 for (auto const& sidebarItem : *m_pDocShell->GetView()->GetPostItMgr())
3313 {
3314 sw::annotation::SwAnnotationWin* pWin = sidebarItem->mpPostIt.get();
3315
3316 if (!pWin)
3317 {
3318 continue;
3319 }
3320
3321 const SwPostItField* pField = pWin->GetPostItField();
3322 const SwRect& aRect = pWin->GetAnchorRect();
3323 tools::Rectangle aSVRect(aRect.Pos().getX(),
3324 aRect.Pos().getY(),
3325 aRect.Pos().getX() + aRect.SSize().Width(),
3326 aRect.Pos().getY() + aRect.SSize().Height());
3327
3328 if (!sidebarItem->maLayoutInfo.mPositionFromCommentAnchor)
3329 {
3330 // Comments on frames: anchor position is the corner position, not the whole frame.
3331 aSVRect.SetSize(Size(0, 0));
3332 }
3333
3334 std::vector<OString> aRects;
3335 for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
3336 {
3337 const SwRect rect(aRange.getMinX(), aRange.getMinY(), aRange.getWidth(), aRange.getHeight());
3338 aRects.push_back(rect.SVRect().toString());
3339 }
3340 const OString sRects = comphelper::string::join("; ", aRects);
3341
3342 auto commentNode = rJsonWriter.startStruct();
3343 rJsonWriter.put("id", pField->GetPostItId());
3344 rJsonWriter.put("parent", pWin->CalcParent());
3345 rJsonWriter.put("paraIdParent", pField->GetParentId());
3346 rJsonWriter.put("author", pField->GetPar1());
3347 rJsonWriter.put("text", pField->GetPar2());
3348 rJsonWriter.put("resolved", pField->GetResolved() ? "true" : "false");
3349 rJsonWriter.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
3350 rJsonWriter.put("anchorPos", aSVRect.toString());
3351 rJsonWriter.put("textRange", sRects);
3352 }
3353}
3354
3356{
3357 auto aIter = aArguments.find("type");
3358 if (aIter == aArguments.end() || aIter->second != "drop-down")
3359 return;
3360
3361 aIter = aArguments.find("cmd");
3362 if (aIter == aArguments.end() || aIter->second != "selected")
3363 return;
3364
3365 aIter = aArguments.find("data");
3366 if (aIter == aArguments.end())
3367 return;
3368
3369 sal_Int32 nSelection = aIter->second.toInt32();
3371 sw::mark::IFieldmark* pFieldBM = m_pDocShell->GetWrtShell()->getIDocumentMarkAccess()->getInnerFieldmarkFor(aPos);
3372 if ( !pFieldBM )
3373 {
3374 aPos.AdjustContent(-1);
3376 }
3377 if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN)
3378 {
3379 if (nSelection >= 0)
3380 {
3381 (*pFieldBM->GetParameters())[ODF_FORMDROPDOWN_RESULT] <<= nSelection;
3382 pFieldBM->Invalidate();
3385 }
3386 }
3387}
3388
3389std::vector<basegfx::B2DRange>
3391{
3392 SwDoc* pDoc = m_pDocShell->GetDoc();
3393 if (!pDoc)
3394 return std::vector<basegfx::B2DRange>();
3395
3396 sw::search::SearchResultLocator aLocator(pDoc);
3397 sw::search::LocationResult aResult = aLocator.findForPayload(pPayload);
3398 if (aResult.mbFound)
3399 {
3400 return aResult.maRectangles;
3401 }
3402 return std::vector<basegfx::B2DRange>();
3403}
3404
3406{
3407 OStringBuffer aState;
3408 SwView* pView = m_pDocShell->GetView();
3409 if (pView && pView->GetWrtShellPtr())
3410 {
3411 const SwViewOption* pVOpt = pView->GetWrtShell().GetViewOptions();
3412 if (pVOpt)
3413 {
3414 if (pVOpt->IsViewMetaChars())
3415 aState.append('P');
3416 if (pVOpt->IsOnlineSpell())
3417 aState.append('S');
3418 aState.append(';');
3419
3420 OString aThemeName = OUStringToOString(pVOpt->GetThemeName(), RTL_TEXTENCODING_UTF8);
3421 aState.append(aThemeName);
3422 }
3423 }
3424 return aState.makeStringAndClear();
3425}
3426
3427namespace
3428{
3429inline constexpr OUStringLiteral SELECTED_DATE_FORMAT = u"YYYY-MM-DD";
3430}
3431
3433{
3434 auto it = rArguments.find("type");
3435 if (it == rArguments.end())
3436 {
3437 return;
3438 }
3439
3440 if (it->second == "drop-down")
3441 {
3442 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3443 const SwPosition* pStart = pWrtShell->GetCursor()->Start();
3444 SwTextNode* pTextNode = pStart->GetNode().GetTextNode();
3445 if (!pTextNode)
3446 {
3447 return;
3448 }
3449
3450 SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pStart->GetContentIndex(),
3452 if (!pAttr)
3453 {
3454 return;
3455 }
3456
3457 auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr);
3458 const SwFormatContentControl& rFormatContentControl = pTextContentControl->GetContentControl();
3459 std::shared_ptr<SwContentControl> pContentControl = rFormatContentControl.GetContentControl();
3460 if (!pContentControl->GetComboBox() && !pContentControl->GetDropDown())
3461 {
3462 return;
3463 }
3464
3465 it = rArguments.find("selected");
3466 if (it == rArguments.end())
3467 {
3468 return;
3469 }
3470
3471 sal_Int32 nSelection = it->second.toInt32();
3472 pContentControl->SetSelectedListItem(nSelection);
3473 pWrtShell->GotoContentControl(rFormatContentControl);
3474 }
3475 else if (it->second == "picture")
3476 {
3477 it = rArguments.find("changed");
3478 if (it == rArguments.end())
3479 {
3480 return;
3481 }
3482
3483 SwView* pView = m_pDocShell->GetView();
3484 if (!pView)
3485 {
3486 return;
3487 }
3488
3489 // The current placeholder is selected, so this will replace, not insert.
3490 SfxStringItem aItem(SID_INSERT_GRAPHIC, it->second);
3491 pView->GetViewFrame().GetDispatcher()->ExecuteList(SID_CHANGE_PICTURE,
3492 SfxCallMode::SYNCHRON, { &aItem });
3493 }
3494 else if (it->second == "date")
3495 {
3496 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3497 const SwPosition* pStart = pWrtShell->GetCursor()->Start();
3498 SwTextNode* pTextNode = pStart->GetNode().GetTextNode();
3499 if (!pTextNode)
3500 {
3501 return;
3502 }
3503
3504 SwTextAttr* pAttr = pTextNode->GetTextAttrAt(pStart->GetContentIndex(),
3506 if (!pAttr)
3507 {
3508 return;
3509 }
3510
3511 auto pTextContentControl = static_txtattr_cast<SwTextContentControl*>(pAttr);
3512 const SwFormatContentControl& rFormatContentControl
3513 = pTextContentControl->GetContentControl();
3514 std::shared_ptr<SwContentControl> pContentControl
3515 = rFormatContentControl.GetContentControl();
3516 if (!pContentControl->GetDate())
3517 {
3518 return;
3519 }
3520
3521 it = rArguments.find("selected");
3522 if (it == rArguments.end())
3523 {
3524 return;
3525 }
3526
3527 OUString aSelectedDate = it->second.replaceAll("T00:00:00Z", "");
3528 SwDoc& rDoc = pTextNode->GetDoc();
3529 SvNumberFormatter* pNumberFormatter = rDoc.GetNumberFormatter();
3530 sal_uInt32 nFormat
3531 = pNumberFormatter->GetEntryKey(SELECTED_DATE_FORMAT, LANGUAGE_ENGLISH_US);
3532 if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
3533 {
3534 sal_Int32 nCheckPos = 0;
3536 OUString sFormat = SELECTED_DATE_FORMAT;
3537 pNumberFormatter->PutEntry(sFormat, nCheckPos, nType, nFormat, LANGUAGE_ENGLISH_US);
3538 }
3539
3540 if (nFormat == NUMBERFORMAT_ENTRY_NOT_FOUND)
3541 {
3542 return;
3543 }
3544
3545 double dCurrentDate = 0;
3546 pNumberFormatter->IsNumberFormat(aSelectedDate, nFormat, dCurrentDate);
3547 pContentControl->SetSelectedDate(dCurrentDate);
3548 pWrtShell->GotoContentControl(rFormatContentControl);
3549 }
3550}
3551
3553{
3554 SolarMutexGuard aGuard;
3555
3556 SwView* pView = m_pDocShell->GetView();
3557 if (!pView)
3558 return 0;
3559
3560 return pView->getPart();
3561}
3562
3564{
3565 return SwResId(STR_PAGE) + OUString::number(nPart + 1);
3566}
3567
3569{
3570 OUString sPart(SwResId(STR_PAGE) + OUString::number(nPart + 1));
3571
3572 return OUString::number(sPart.hashCode());
3573}
3574
3576{
3577 SolarMutexGuard aGuard;
3578 SwView* pView = m_pDocShell->GetView();
3579 if (!pView)
3580 return {};
3581
3583 return pWindow;
3584
3585 return &(pView->GetEditWin());
3586}
3587
3588void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
3589{
3590 SolarMutexGuard aGuard;
3591
3592 SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3593
3594 SwView* pView = m_pDocShell->GetView();
3595 if (!pView)
3596 return;
3597
3598 pView->SetViewLayout(1/*nColumns*/, false/*bBookMode*/, true);
3599
3600 // Tiled rendering defaults.
3601 SwViewOption aViewOption(*pViewShell->GetViewOptions());
3602 aViewOption.SetHardBlank(false);
3603
3604 // Disable field shadings: the result would depend on the cursor position.
3606 // The fancy header/footer controls don't work in tiled mode anyway, so
3607 // explicitly disable them to enable skipping invalidating the view for
3608 // the case of clicking in the header area of a document with no headers
3609 aViewOption.SetUseHeaderFooterMenu(false);
3610
3611 OUString sOrigAuthor = SW_MOD()->GetRedlineAuthor(SW_MOD()->GetRedlineAuthor());
3612 OUString sAuthor;
3613
3614 for (const beans::PropertyValue& rValue : rArguments)
3615 {
3616 if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has<bool>())
3617 aViewOption.SetHideWhitespaceMode(rValue.Value.get<bool>());
3618 else if (rValue.Name == ".uno:ShowBorderShadow" && rValue.Value.has<bool>())
3619 aViewOption.SetAppearanceFlag(ViewOptFlags::Shadow , rValue.Value.get<bool>());
3620 else if (rValue.Name == ".uno:Author" && rValue.Value.has<OUString>())
3621 {
3622 sAuthor = rValue.Value.get<OUString>();
3623 // Store the author name in the view.
3624 pView->SetRedlineAuthor(sAuthor);
3625 // Let the actual author name pick up the value from the current
3626 // view, which would normally happen only during the next view
3627 // switch.
3628 m_pDocShell->SetView(pView);
3629 }
3630 else if (rValue.Name == ".uno:SpellOnline" && rValue.Value.has<bool>())
3631 aViewOption.SetOnlineSpell(rValue.Value.get<bool>());
3632 }
3633
3634 if (!sAuthor.isEmpty() && sAuthor != sOrigAuthor)
3635 {
3636 SwView* pFirstView = static_cast<SwView*>(SfxViewShell::GetFirst());
3637 if (pFirstView && SfxViewShell::GetNext(*pFirstView) == nullptr)
3638 {
3639 if (SwEditShell* pShell = &pFirstView->GetWrtShell())
3640 {
3641 pShell->SwViewShell::UpdateFields(true);
3642 pShell->ResetModified();
3643 }
3644 }
3645 }
3646
3647 // Set the initial zoom value to 1; usually it is set in setClientZoom and
3648 // SwViewShell::PaintTile; zoom value is used for chart in place
3649 // editing, see postMouseEvent and setGraphicSelection methods.
3650 aViewOption.SetZoom(1 * 100);
3651
3653 pViewShell->ApplyViewOptions(aViewOption);
3654
3655 // position the pages again after setting view options. Eg: if postit
3656 // rendering is false, then there would be no sidebar, so width of the
3657 // document needs to be adjusted
3658 pViewShell->GetLayout()->CheckViewLayout( pViewShell->GetViewOptions(), nullptr );
3659
3660 // Disable map mode, so that it's possible to send mouse event coordinates
3661 // directly in twips.
3662 SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3663 rEditWin.EnableMapMode(false);
3664
3665 // when the "This document may contain formatting or content that cannot
3666 // be saved..." dialog appears, it is auto-cancelled with tiled rendering,
3667 // causing 'Save' being disabled; so let's always save to the original
3668 // format
3670 officecfg::Office::Common::Save::Document::WarnAlienFormat::set(false, xChanges);
3671 xChanges->commit();
3672
3673 // disable word auto-completion suggestions, the tooltips are not visible,
3674 // and the editeng-like auto-completion is annoying
3676
3677 // don't change the whitespace at the beginning of paragraphs, this is
3678 // annoying when taking minutes without further formatting
3680}
3681
3682void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
3683{
3684 SolarMutexGuard aGuard;
3685 SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, nKeyCode);
3686}
3687
3688void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
3689{
3690 SolarMutexGuard aGuard;
3691
3692 SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3693 if (!pWrtViewShell)
3694 {
3695 return;
3696 }
3697
3698 SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3699 double fScale = aOption.GetZoom() / o3tl::convert(100.0, o3tl::Length::px, o3tl::Length::twip);
3700
3702 m_pDocShell->GetView(), nType, nX, nY, nCount, nButtons, nModifier, fScale, fScale))
3703 return;
3704
3705 // try to forward mouse event to controls
3707 SdrPage* pPage = pDrawLayer->GetPage(sal_uInt16(0));
3708 SdrView* pDrawView = pWrtViewShell->GetDrawView();
3709 SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3710 Point aPointTwip(nX, nY);
3711 Point aPointHMMDraw = o3tl::convert(aPointTwip, o3tl::Length::twip, o3tl::Length::mm100);
3712 if (LokControlHandler::postMouseEvent(pPage, pDrawView, rEditWin, nType, aPointHMMDraw, nCount, nButtons, nModifier))
3713 return;
3714
3715 LokMouseEventData aMouseEventData(nType, Point(nX, nY), nCount,
3716 MouseEventModifiers::SIMPLECLICK,
3717 nButtons, nModifier);
3718 SfxLokHelper::postMouseEventAsync(&rEditWin, aMouseEventData);
3719}
3720
3721void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
3722{
3723 SolarMutexGuard aGuard;
3724
3725 SfxViewShell* pViewShell = m_pDocShell->GetView();
3726 LokChartHelper aChartHelper(pViewShell);
3727 if (aChartHelper.setTextSelection(nType, nX, nY))
3728 return;
3729
3730 SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3731 switch (nType)
3732 {
3733 case LOK_SETTEXTSELECTION_START:
3734 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/false, /*bClearMark=*/false);
3735 break;
3736 case LOK_SETTEXTSELECTION_END:
3737 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/false);
3738 break;
3739 case LOK_SETTEXTSELECTION_RESET:
3740 rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/true);
3741 break;
3742 default:
3743 assert(false);
3744 break;
3745 }
3746}
3747
3748uno::Reference<datatransfer::XTransferable> SwXTextDocument::getSelection()
3749{
3750 SolarMutexGuard aGuard;
3751
3752 uno::Reference<datatransfer::XTransferable> xTransferable;
3753
3754 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3755 if (SdrView* pSdrView = pWrtShell ? pWrtShell->GetDrawView() : nullptr)
3756 {
3757 if (pSdrView->GetTextEditObject())
3758 {
3759 // Editing shape text
3760 EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
3761 xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3762 }
3763 }
3764
3765 if (SwPostItMgr* pPostItMgr = m_pDocShell->GetView()->GetPostItMgr())
3766 {
3767 if (sw::annotation::SwAnnotationWin* pWin = pPostItMgr->GetActiveSidebarWin())
3768 {
3769 // Editing postit text.
3770 EditView& rEditView = pWin->GetOutlinerView()->GetEditView();
3771 xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3772 }
3773 }
3774
3775 if (!xTransferable.is() && pWrtShell)
3776 xTransferable = new SwTransferable(*pWrtShell);
3777
3778 return xTransferable;
3779}
3780
3781void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
3782{
3783 SolarMutexGuard aGuard;
3784
3785 SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3786 SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3787 double fScale = aOption.GetZoom() / o3tl::convert(100.0, o3tl::Length::px, o3tl::Length::twip);
3788
3789 SfxViewShell* pViewShell = m_pDocShell->GetView();
3790 LokChartHelper aChartHelper(pViewShell);
3791 if (aChartHelper.setGraphicSelection(nType, nX, nY, fScale, fScale))
3792 return;
3793
3794 SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3795 switch (nType)
3796 {
3797 case LOK_SETGRAPHICSELECTION_START:
3798 rEditWin.SetGraphicTwipPosition(/*bStart=*/true, Point(nX, nY));
3799 break;
3800 case LOK_SETGRAPHICSELECTION_END:
3801 rEditWin.SetGraphicTwipPosition(/*bStart=*/false, Point(nX, nY));
3802 break;
3803 default:
3804 assert(false);
3805 break;
3806 }
3807}
3808
3810{
3811 SolarMutexGuard aGuard;
3812
3813 SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3814 pWrtShell->ResetSelect(nullptr, false);
3815}
3816
3817void 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 )
3818{
3820 aData.nSize = sizeof(SystemGraphicsData);
3821 #if defined(_WIN32)
3822 sal_Int64 nWindowHandle;
3823 Parent >>= nWindowHandle;
3824 aData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
3825 ScopedVclPtrInstance<VirtualDevice> xDevice(aData, Size(1, 1), DeviceFormat::WITHOUT_ALPHA);
3826 paintTile(*xDevice, nOutputWidth, nOutputHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3827 #else
3828 // TODO: support other platforms
3829 (void)Parent;
3830 (void)nOutputWidth;
3831 (void)nOutputHeight;
3832 (void)nTilePosX;
3833 (void)nTilePosY;
3834 (void)nTileWidth;
3835 (void)nTileHeight;
3836 #endif
3837}
3838
3842uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3843 ::sal_Int16 nScriptTypes,
3844 ::sal_Int16 nMaxCount )
3845{
3846 SolarMutexGuard aGuard;
3847
3848 // possible canonical values for nScriptTypes
3849 // any bit wise combination is allowed
3850 const sal_Int16 nLatin = 0x001;
3851 const sal_Int16 nAsian = 0x002;
3852 const sal_Int16 nComplex = 0x004;
3853
3854 // script types for which to get the languages
3855 const bool bLatin = 0 != (nScriptTypes & nLatin);
3856 const bool bAsian = 0 != (nScriptTypes & nAsian);
3857 const bool bComplex = 0 != (nScriptTypes & nComplex);
3858
3859 if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3860 throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
3861 if (!m_pDocShell)
3862 throw DisposedException();
3863 SwDoc* pDoc = m_pDocShell->GetDoc();
3864
3865 // avoid duplicate values
3866 std::set< LanguageType > aAllLangs;
3867
3868 //USER STYLES
3869
3870 const SwCharFormats *pFormats = pDoc->GetCharFormats();
3871 for(size_t i = 0; i < pFormats->size(); ++i)
3872 {
3873 const SwAttrSet &rAttrSet = (*pFormats)[i]->GetAttrSet();
3875 if (bLatin)
3876 {
3877 nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3879 aAllLangs.insert( nLang );
3880 }
3881 if (bAsian)
3882 {
3883 nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3885 aAllLangs.insert( nLang );
3886 }
3887 if (bComplex)
3888 {
3889 nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3891 aAllLangs.insert( nLang );
3892 }
3893 }
3894
3895 const SwTextFormatColls *pColls = pDoc->GetTextFormatColls();
3896 for (size_t i = 0; i < pColls->size(); ++i)
3897 {
3898 const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3900 if (bLatin)
3901 {
3902 nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3904 aAllLangs.insert( nLang );
3905 }
3906 if (bAsian)
3907 {
3908 nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3910 aAllLangs.insert( nLang );
3911 }
3912 if (bComplex)
3913 {
3914 nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3916 aAllLangs.insert( nLang );
3917 }
3918 }
3919
3920 //AUTO STYLES
3921 const IStyleAccess::SwAutoStyleFamily aFam[2] =
3922 {
3925 };
3927 {
3928 std::vector< std::shared_ptr<SfxItemSet> > rStyles;
3929 pDoc->GetIStyleAccess().getAllStyles(rStyles, i);
3930 while (!rStyles.empty())
3931 {
3932 std::shared_ptr<SfxItemSet> pStyle = rStyles.back();
3933 rStyles.pop_back();
3934 const SfxItemSet *pSet = pStyle.get();
3935
3937 if (bLatin)
3938 {
3939 assert(pSet);
3940 nLang = pSet->Get( RES_CHRATR_LANGUAGE, false ).GetLanguage();
3942 aAllLangs.insert( nLang );
3943 }
3944 if (bAsian)
3945 {
3946 assert(pSet);
3947 nLang = pSet->Get( RES_CHRATR_CJK_LANGUAGE, false ).GetLanguage();
3949 aAllLangs.insert( nLang );
3950 }
3951 if (bComplex)
3952 {
3953 assert(pSet);
3954 nLang = pSet->Get( RES_CHRATR_CTL_LANGUAGE, false ).GetLanguage();
3956 aAllLangs.insert( nLang );
3957 }
3958 }
3959 }
3960
3961 //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3962 SwWrtShell *pWrtSh = m_pDocShell->GetWrtShell();
3963 SdrView *pSdrView = pWrtSh->GetDrawView();
3964
3965 if( pSdrView )
3966 {
3967 SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3968 if(pOutliner)
3969 {
3970 EditEngine& rEditEng = const_cast<EditEngine&>(pOutliner->GetEditEngine());
3971 sal_Int32 nParCount = pOutliner->GetParagraphCount();
3972 for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
3973 {
3974 //every paragraph
3975 std::vector<sal_Int32> aPortions;
3976 rEditEng.GetPortions( nPar, aPortions );
3977
3978 for ( size_t nPos = aPortions.size(); nPos; )
3979 {
3980 //every position
3981 --nPos;
3982 sal_Int32 nEnd = aPortions[ nPos ];
3983 sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
3984 ESelection aSelection( nPar, nStart, nPar, nEnd );
3985 SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3986
3988 if (bLatin)
3989 {
3990 nLang = aAttr.Get( EE_CHAR_LANGUAGE, false ).GetLanguage();
3992 aAllLangs.insert( nLang );
3993 }
3994 if (bAsian)
3995 {
3996 nLang = aAttr.Get( EE_CHAR_LANGUAGE_CJK, false ).GetLanguage();
3998 aAllLangs.insert( nLang );
3999 }
4000 if (bComplex)
4001 {
4002 nLang = aAttr.Get( EE_CHAR_LANGUAGE_CTL, false ).GetLanguage();
4004 aAllLangs.insert( nLang );
4005 }
4006 }
4007 }
4008 }
4009 }
4010 // less than nMaxCount languages
4011 if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
4012 nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
4013
4014 // build return value
4015 uno::Sequence< lang::Locale > aLanguages( nMaxCount );
4016 lang::Locale* pLanguage = aLanguages.getArray();
4017 if (nMaxCount > 0)
4018 {
4019 sal_Int32 nCount = 0;
4020 for (const auto& rLang : aAllLangs)
4021 {
4022 if (nCount >= nMaxCount)
4023 break;
4024 if (LANGUAGE_NONE != rLang)
4025 {
4026 pLanguage[nCount] = LanguageTag::convertToLocale( rLang );
4027 pLanguage[nCount].Language = SvtLanguageTable::GetLanguageString( rLang );
4028 nCount += 1;
4029 }
4030 }
4031 }
4032
4033 return aLanguages;
4034}
4035
4037 m_pxDoc(&rxDoc)
4038{
4039 m_sTables = SwResId(STR_CONTENT_TYPE_TABLE);
4040 m_sFrames = SwResId(STR_CONTENT_TYPE_FRAME);
4041 m_sGraphics = SwResId(STR_CONTENT_TYPE_GRAPHIC);
4042 m_sOLEs = SwResId(STR_CONTENT_TYPE_OLE);
4043 m_sSections = SwResId(STR_CONTENT_TYPE_REGION);
4044 m_sOutlines = SwResId(STR_CONTENT_TYPE_OUTLINE);
4045 m_sBookmarks = SwResId(STR_CONTENT_TYPE_BOOKMARK);
4046 m_sDrawingObjects = SwResId(STR_CONTENT_TYPE_DRAWOBJECT);
4047}
4048
4050{
4051}
4052
4054{
4055 Any aRet;
4056 if(!m_pxDoc)
4057 throw RuntimeException("No document available");
4058 OUString sSuffix("|");
4059 if(rName == m_sTables)
4060 {
4061 sSuffix += "table";
4062
4063 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4064 m_pxDoc->getTextTables(), rName, sSuffix );
4065 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4066 }
4067 else if(rName == m_sFrames)
4068 {
4069 sSuffix += "frame";
4070 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4071 m_pxDoc->getTextFrames(), rName, sSuffix );
4072 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4073 }
4074 else if(rName == m_sSections)
4075 {
4076 sSuffix += "region";
4077 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4078 m_pxDoc->getTextSections(), rName, sSuffix );
4079 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4080 }
4081 else if(rName == m_sGraphics)
4082 {
4083 sSuffix += "graphic";
4084 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4085 m_pxDoc->getGraphicObjects(), rName, sSuffix );
4086 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4087 }
4088 else if(rName == m_sOLEs)
4089 {
4090 sSuffix += "ole";
4091 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4092 m_pxDoc->getEmbeddedObjects(), rName, sSuffix );
4093 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4094 }
4095 else if(rName == m_sOutlines)
4096 {
4097 sSuffix += "outline";
4098 Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
4099 *m_pxDoc, rName, sSuffix );
4100 aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
4101 }
4102 else if(rName == m_sBookmarks)
4103 {
4104 sSuffix.clear();
4105 Reference< XNameAccess > xBkms = new SwXLinkNameAccessWrapper(
4106 m_pxDoc->getBookmarks(), rName, sSuffix );
4107 aRet <<= Reference< XPropertySet >(xBkms, UNO_QUERY);
4108 }
4109 else if(rName == m_sDrawingObjects)
4110 {
4111 sSuffix += "drawingobject";
4112 Reference<XNameAccess> xDrawingObjects = new SwXLinkNameAccessWrapper(
4113 *m_pxDoc, rName, sSuffix);
4114 aRet <<= Reference<XPropertySet>(xDrawingObjects, UNO_QUERY);
4115 }
4116 else
4117 throw NoSuchElementException();
4118 return aRet;
4119}
4120
4122{
4123 return { m_sTables,
4124 m_sFrames,
4126 m_sOLEs,
4131}
4132
4134{
4135 if( rName == m_sTables ||
4136 rName == m_sFrames ||
4137 rName == m_sGraphics||
4138 rName == m_sOLEs ||
4139 rName == m_sSections ||
4140 rName == m_sOutlines ||
4141 rName == m_sBookmarks ||
4142 rName == m_sDrawingObjects )
4143 return true;
4144 return false;
4145}
4146
4148{
4150
4151}
4152
4154{
4155 return nullptr != m_pxDoc;
4156}
4157
4159{
4160 return "SwXLinkTargetSupplier";
4161}
4162
4164{
4165 return cppu::supportsService(this, rServiceName);
4166}
4167
4169{
4170 Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
4171 return aRet;
4172}
4173
4175 Reference< XNameAccess > const & xAccess, OUString aLinkDisplayName, OUString sSuffix ) :
4176 m_xRealAccess(xAccess),
4177 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4178 m_sLinkSuffix(std::move(sSuffix)),
4179 m_sLinkDisplayName(std::move(aLinkDisplayName)),
4180 m_pxDoc(nullptr)
4181{
4182}
4183
4185 OUString aLinkDisplayName, OUString sSuffix) :
4186 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4187 m_sLinkSuffix(std::move(sSuffix)),
4188 m_sLinkDisplayName(std::move(aLinkDisplayName)),
4189 m_pxDoc(&rxDoc)
4190{
4191}
4192
4194{
4195}
4196
4198{
4199 Any aRet;
4200 bool bFound = false;
4201 //cut link extension and call the real NameAccess
4202 OUString sParam = rName;
4203 OUString sSuffix(m_sLinkSuffix);
4204 if(sParam.getLength() > sSuffix.getLength() )
4205 {
4206 std::u16string_view sCmp = sParam.subView(sParam.getLength() - sSuffix.getLength(),
4207 sSuffix.getLength());
4208 if(sCmp == sSuffix)
4209 {
4210 if(m_pxDoc)
4211 {
4212 sParam = sParam.copy(0, sParam.getLength() - sSuffix.getLength());
4213 if(!m_pxDoc->GetDocShell())
4214 throw RuntimeException("No document shell available");
4215 SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4216
4217 if (sSuffix == "|outline")
4218 {
4219 const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
4220
4221 for (size_t i = 0; i < nOutlineCount && !bFound; ++i)
4222 {
4223 if(sParam == lcl_CreateOutlineString(i, pDoc))
4224 {
4225 OUString sOutlineText =
4227 i, pDoc->GetDocShell()->GetWrtShell()->GetLayout());
4228 sal_Int32 nOutlineLevel = pDoc->getIDocumentOutlineNodes().getOutlineLevel(i);
4229 Reference<XPropertySet> xOutline =
4230 new SwXOutlineTarget(sParam, sOutlineText, nOutlineLevel);
4231 aRet <<= xOutline;
4232 bFound = true;
4233 }
4234 }
4235 }
4236 else if (sSuffix == "|drawingobject")
4237 {
4239 if (pModel)
4240 {
4241 SdrPage* pPage = pModel->GetPage(0);
4242 for (size_t i = 0; i < pPage->GetObjCount() && !bFound; ++i)
4243 {
4244 SdrObject* pObj = pPage->GetObj(i);
4245 if (sParam == pObj->GetName())
4246 {
4247 Reference<XPropertySet> xDrawingObject = new SwXDrawingObjectTarget(sParam);
4248 aRet <<= xDrawingObject;
4249 bFound = true;
4250 }
4251 }
4252 }
4253 }
4254 }
4255 else
4256 {
4257 aRet = m_xRealAccess->getByName(sParam.copy(0, sParam.getLength() - sSuffix.getLength()));
4258 Reference< XInterface > xInt;
4259 if(!(aRet >>= xInt))
4260 throw RuntimeException("Could not retrieve property");
4261 Reference< XPropertySet > xProp(xInt, UNO_QUERY);
4262 aRet <<= xProp;
4263 bFound = true;
4264 }
4265 }
4266 }
4267 if(!bFound)
4268 throw NoSuchElementException();
4269 return aRet;
4270}
4271
4273{
4274 Sequence< OUString > aRet;
4275 if(m_pxDoc)
4276 {
4277 if(!m_pxDoc->GetDocShell())
4278 throw RuntimeException("No document shell available");
4279 SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4280 if (m_sLinkSuffix == "|outline")
4281 {
4282 const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
4283 const size_t nOutlineCount = rOutlineNodes.size();
4284 aRet.realloc(nOutlineCount);
4285 OUString* pResArr = aRet.getArray();
4286 for (size_t i = 0; i < nOutlineCount; ++i)
4287 {
4288 OUString sEntry = lcl_CreateOutlineString(i, pDoc) + "|outline";
4289 pResArr[i] = sEntry;
4290 }
4291 }
4292 else if (m_sLinkSuffix == "|drawingobject")
4293 {
4295 if(pModel)
4296 {
4297 SdrPage* pPage = pModel->GetPage(0);
4298 const size_t nObjCount = pPage->GetObjCount();
4299 aRet.realloc(nObjCount);
4300 OUString* pResArr = aRet.getArray();
4301 auto j = 0;
4302 for (size_t i = 0; i < nObjCount; ++i)
4303 {
4304 SdrObject* pObj = pPage->GetObj(i);
4305 if (!pObj->GetName().isEmpty())
4306 pResArr[j++] = pObj->GetName() + "|drawingobject";
4307 }
4308 }
4309 }
4310 }
4311 else
4312 {
4313 const Sequence< OUString > aOrg = m_xRealAccess->getElementNames();
4314 aRet.realloc(aOrg.getLength());
4315 std::transform(aOrg.begin(), aOrg.end(), aRet.getArray(),
4316 [this](const OUString& rOrg) -> OUString { return rOrg + m_sLinkSuffix; });
4317 }
4318 return aRet;
4319}
4320
4322{
4323 bool bRet = false;
4324 OUString sParam(rName);
4325 if(sParam.getLength() > m_sLinkSuffix.getLength() )
4326 {
4327 std::u16string_view sCmp = sParam.subView(sParam.getLength() - m_sLinkSuffix.getLength(),
4328 m_sLinkSuffix.getLength());
4329 if(sCmp == m_sLinkSuffix)
4330 {
4331 sParam = sParam.copy(0, sParam.getLength() - m_sLinkSuffix.getLength());
4332 if(m_pxDoc)
4333 {
4334 if(!m_pxDoc->GetDocShell())
4335 throw RuntimeException("No document shell available");
4336 SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4337 if (m_sLinkSuffix == "|outline")
4338 {
4339 const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
4340
4341 for (size_t i = 0; i < nOutlineCount && !bRet; ++i)
4342 {
4343 if(sParam == lcl_CreateOutlineString(i, pDoc))
4344 {
4345 bRet = true;
4346 }
4347 }
4348 }
4349 else if (m_sLinkSuffix == "|drawingobject")
4350 {
4352 if (pModel)
4353 {
4354 SdrPage* pPage = pModel->GetPage(0);
4355 const size_t nObjCount = pPage->GetObjCount();
4356 for (size_t i = 0; i < nObjCount && !bRet; ++i)
4357 {
4358 if (sParam == pPage->GetObj(i)->GetName())
4359 bRet = true;
4360 }
4361 }
4362 }
4363 }
4364 else
4365 {
4366 bRet = m_xRealAccess->hasByName(sParam);
4367 }
4368 }
4369 }
4370 return bRet;
4371}
4372
4374{
4376}
4377
4379{
4380 bool bRet = false;
4381 if(m_pxDoc)
4382 {
4383 OSL_FAIL("not implemented");
4384 }
4385 else
4386 {
4387 bRet = m_xRealAccess->hasElements();
4388 }
4389 return bRet;
4390}
4391
4393{
4394 static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4395 return xRet;
4396}
4397
4399 const OUString& rPropName, const Any& )
4400{
4401 throw UnknownPropertyException(rPropName);
4402}
4403
4404static Any lcl_GetDisplayBitmap(std::u16string_view sLinkSuffix)
4405{
4406 Any aRet;
4407 if(!sLinkSuffix.empty())
4408 sLinkSuffix = sLinkSuffix.substr(1);
4409 OUString sImgId;
4410
4411 if(sLinkSuffix == u"outline")
4412 sImgId = RID_BMP_NAVI_OUTLINE;
4413 else if(sLinkSuffix == u"table")
4414 sImgId = RID_BMP_NAVI_TABLE;
4415 else if(sLinkSuffix == u"frame")
4416 sImgId = RID_BMP_NAVI_FRAME;
4417 else if(sLinkSuffix == u"graphic")
4418 sImgId = RID_BMP_NAVI_GRAPHIC;
4419 else if(sLinkSuffix == u"ole")
4420 sImgId = RID_BMP_NAVI_OLE;
4421 else if(sLinkSuffix.empty())
4422 sImgId = RID_BMP_NAVI_BOOKMARK;
4423 else if(sLinkSuffix == u"region")
4424 sImgId = RID_BMP_NAVI_REGION;
4425 else if(sLinkSuffix == u"drawingobject")
4426 sImgId = RID_BMP_NAVI_DRAWOBJECT;
4427
4428 if (!sImgId.isEmpty())
4429 {
4430 aRet <<= VCLUnoHelper::CreateBitmap(BitmapEx(sImgId));
4431 }
4432 return aRet;
4433}
4434
4436{
4437 Any aRet;
4438 if( rPropertyName == UNO_LINK_DISPLAY_NAME )
4439 {
4440 aRet <<= m_sLinkDisplayName;
4441 }
4442 else if( rPropertyName == UNO_LINK_DISPLAY_BITMAP )
4443 {
4445 }
4446 else
4447 throw UnknownPropertyException(rPropertyName);
4448 return aRet;
4449}
4450
4452 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4453{}
4454
4456 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4457{}
4458
4460 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4461{}
4462
4464 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4465{}
4466
4467Reference< XNameAccess > SwXLinkNameAccessWrapper::getLinks()
4468{
4469 return this;
4470}
4471
4473{
4474 return "SwXLinkNameAccessWrapper";
4475}
4476
4478{
4479 return cppu::supportsService(this, rServiceName);
4480}
4481
4483{
4484 Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
4485 return aRet;
4486}
4487
4488SwXOutlineTarget::SwXOutlineTarget(OUString aOutlineText, OUString aActualText,
4489 const sal_Int32 nOutlineLevel) :
4490 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4491 m_sOutlineText(std::move(aOutlineText)),
4492 m_sActualText(std::move(aActualText)),
4493 m_nOutlineLevel(nOutlineLevel)
4494{
4495}
4496
4498{
4499}
4500
4501Reference< XPropertySetInfo > SwXOutlineTarget::getPropertySetInfo()
4502{
4503 static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4504 return xRet;
4505}
4506
4508 const OUString& rPropertyName, const Any& /*aValue*/)
4509{
4510 throw UnknownPropertyException(rPropertyName);
4511}
4512
4513Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
4514{
4515 if (rPropertyName != UNO_LINK_DISPLAY_NAME && rPropertyName != "ActualOutlineName" &&
4516 rPropertyName != "OutlineLevel")
4517 throw UnknownPropertyException(rPropertyName);
4518
4519 if (rPropertyName == "ActualOutlineName")
4520 return Any(m_sActualText);
4521
4522 if (rPropertyName == "OutlineLevel")
4523 return Any(m_nOutlineLevel);
4524
4525 return Any(m_sOutlineText);
4526}
4527
4529 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4530{
4531}
4532
4534 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4535{
4536}
4537
4539 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4540{
4541}
4542
4544 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4545{
4546}
4547
4549{
4550 return "SwXOutlineTarget";
4551}
4552
4554{
4555 return cppu::supportsService(this, ServiceName);
4556}
4557
4559{
4560 Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4561
4562 return aRet;
4563}
4564
4566 m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4567 m_sDrawingObjectText(std::move(aDrawingObjectText))
4568{
4569}
4570
4572{
4573}
4574
4575Reference< XPropertySetInfo > SwXDrawingObjectTarget::getPropertySetInfo()
4576{
4577 static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4578 return xRet;
4579}
4580
4582 const OUString& rPropertyName, const Any& /*aValue*/)
4583{
4584 throw UnknownPropertyException(rPropertyName);
4585}
4586
4587Any SwXDrawingObjectTarget::getPropertyValue(const OUString& rPropertyName)
4588{
4589 if(rPropertyName != UNO_LINK_DISPLAY_NAME)
4590 throw UnknownPropertyException(rPropertyName);
4591
4592 return Any(m_sDrawingObjectText);
4593}
4594
4596 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4597{
4598}
4599
4601 const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4602{
4603}
4604
4606 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4607{
4608}
4609
4611 const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4612{
4613}
4614
4616{
4617 return "SwXDrawingObjectTarget";
4618}
4619
4621{
4622 return cppu::supportsService(this, ServiceName);
4623}
4624
4626{
4627 Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4628
4629 return aRet;
4630}
4631
4633SvxUnoForbiddenCharsTable ( rDoc.getIDocumentSettingAccess().getForbiddenCharacterTable() )
4634,m_pDoc(&rDoc)
4635{
4636}
4637
4639{
4640}
4641
4643{
4644 Reference<XInterface> xRet;
4645 if(m_pDoc)
4646 {
4647 switch(nWhich)
4648 {
4649 // #i52858#
4650 // assure that Draw model is created, if it doesn't exist.
4652 if(!m_xDashTable.is())
4654 xRet = m_xDashTable;
4655 break;
4657 if(!m_xGradientTable.is())
4659 xRet = m_xGradientTable;
4660 break;
4662 if(!m_xHatchTable.is())
4664 xRet = m_xHatchTable;
4665 break;
4667 if(!m_xBitmapTable.is())
4669 xRet = m_xBitmapTable;
4670 break;
4672 if(!m_xTransGradientTable.is())
4674 xRet = m_xTransGradientTable;
4675 break;
4677 if(!m_xMarkerTable.is())
4679 xRet = m_xMarkerTable;
4680 break;
4682 if(!m_xDrawDefaults.is())
4684 xRet = m_xDrawDefaults;
4685 break;
4686#if OSL_DEBUG_LEVEL > 0
4687 default: OSL_FAIL("which table?");
4688#endif
4689 }
4690 }
4691 return xRet;
4692}
4693
4695{
4696 m_xDashTable = nullptr;
4697 m_xGradientTable = nullptr;
4698 m_xHatchTable = nullptr;
4699 m_xBitmapTable = nullptr;
4700 m_xTransGradientTable = nullptr;
4701 m_xMarkerTable = nullptr;
4702 m_xDrawDefaults = nullptr;
4703 m_pDoc = nullptr;
4705}
4706
4708{
4709 if(m_pDoc)
4711}
4712
4714 SwViewShell& rSh, const SwViewOption &rViewOptions)
4715 : m_pShell(&rSh)
4716 , m_aOldViewOptions( rViewOptions )
4717{
4718}
4719
4721{
4722 if (m_pShell)
4723 {
4725 }
4726}
4727
4728void
4729SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
4730{
4731 // to avoid unnecessary reformatting the view options related to the content
4732 // below should only change if necessary, that is if respective content is present
4733 const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars();
4735 const bool bContainsHiddenFields = pFieldType && pFieldType->HasWriterListeners();
4737 const bool bContainsHiddenParagraphs = pFieldType && pFieldType->HasWriterListeners();
4739 const bool bContainsPlaceHolders = pFieldType && pFieldType->HasWriterListeners();
4740 const bool bContainsFields = m_pShell->IsAnyFieldInDoc();
4741
4742 SwViewOption aRenderViewOptions( m_aOldViewOptions );
4743
4744 // disable anything in the view that should not be printed (or exported to PDF) by default
4745 // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4746 // in section "Display of ...")
4747 aRenderViewOptions.SetParagraph( false ); // paragraph end
4748 aRenderViewOptions.SetSoftHyph( false ); // aka custom hyphens
4749 aRenderViewOptions.SetBlank( false ); // spaces
4750 aRenderViewOptions.SetHardBlank( false ); // non-breaking spaces
4751 aRenderViewOptions.SetTab( false ); // tabs
4752 aRenderViewOptions.SetShowBookmarks( false ); // bookmarks
4753 aRenderViewOptions.SetLineBreak( false ); // breaks (type 1)
4754 aRenderViewOptions.SetPageBreak( false ); // breaks (type 2)
4755 aRenderViewOptions.SetColumnBreak( false ); // breaks (type 3)
4756 bool bVal = pPrtOptions && pPrtOptions->m_bPrintHiddenText;
4757 if (bContainsHiddenChars)
4758 aRenderViewOptions.SetShowHiddenChar( bVal ); // hidden text
4759 if (bContainsHiddenFields)
4760 aRenderViewOptions.SetShowHiddenField( bVal );
4761 if (bContainsHiddenParagraphs)
4762 aRenderViewOptions.SetShowHiddenPara( bVal );
4763
4764 if (bContainsPlaceHolders)
4765 {
4766 // should always be printed in PDF export!
4767 bVal = !pPrtOptions ? setShowPlaceHoldersInPDF : pPrtOptions->m_bPrintTextPlaceholder;
4768 aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4769 }
4770
4771 if (bContainsFields)
4772 aRenderViewOptions.SetFieldName( false );
4773
4774 // we need to set this flag in order to get to see the visible effect of
4775 // some of the above settings (needed for correct rendering)
4776 aRenderViewOptions.SetViewMetaChars( true );
4777
4778 if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary
4779 {
4780 aRenderViewOptions.SetPrinting( pPrtOptions != nullptr );
4781 m_pShell->ApplyViewOptions( aRenderViewOptions );
4782 }
4783}
4784
4785/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOIndex Index
@ ShowDelete
show all deletes
@ On
RedlineFlags on.
@ ShowInsert
show all inserts
OUString SwRedlineTypeToOUString(RedlineType eType)
::std::unique_ptr< XmlIdRegistry_Impl > m_pImpl
constexpr auto convertTwipToMm100(N n)
css::util::DateTime GetUNODateTime() const
void GetPortions(sal_Int32 nPara, std::vector< sal_Int32 > &rList)
css::uno::Reference< css::datatransfer::XTransferable > CreateTransferable(const ESelection &rSelection) const
SfxItemSet GetAttribs(sal_Int32 nPara, sal_Int32 nStart, sal_Int32 nEnd, GetAttribsFlags nFlags=GetAttribsFlags::ALL) const
static bool HasValidData(const css::uno::Reference< css::datatransfer::XTransferable > &rTransferable)
ESelection GetSelection() const
EditEngine * GetEditEngine() const
bool GetAutoControlFocus() const
void SetOpenInDesignMode(bool _bOpenDesignMode)
void SetAutoControlFocus(bool _bAutoControlFocus)
bool GetOpenInDesignMode() const
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
virtual void setPrintData(const SwPrintData &rPrtData)=0
Sets the PrintData.
virtual const SwPrintData & getPrintData() const =0
Returns the PrintData.
virtual SwDrawModel * GetOrCreateDrawModel()=0
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
virtual bool SetFieldsDirty(bool b, const SwNode *pChk, SwNodeOffset nLen)=0
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
virtual sfx2::LinkManager & GetLinkManager()=0
virtual sw::mark::IFieldmark * getInnerFieldmarkFor(const SwPosition &pos) const =0
virtual OUString getOutlineText(const tSortedOutlineNodeList::size_type nIdx, SwRootFrame const *pLayout, const bool bWithNumber=true, const bool bWithSpacesForLevel=false, const bool bWithFootnote=true) const =0
virtual int getOutlineLevel(const tSortedOutlineNodeList::size_type nIdx) const =0
virtual void SetRedlinePassword(const css::uno::Sequence< sal_Int8 > &rNewPassword)=0
static bool IsShowChanges(const RedlineFlags eM)
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual void SetRedlineFlags(RedlineFlags eMode)=0
Set a new redline mode.
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual const css::uno::Sequence< sal_Int8 > & GetRedlinePassword() const =0
virtual void SetModified()=0
Must be called manually at changes of format.
virtual const SwDocStat & GetUpdatedDocStat(bool bCompleteAsync, bool bFields)=0
Updates the document statistics if the document has been modified and returns a reference to the resu...
virtual SwTextFormatColl * GetTextCollFromPool(sal_uInt16 nId, bool bRegardLanguage=true)=0
Return "Auto-Collection with ID.
virtual void BlockIdling()=0
Increment block count.
virtual void UnblockIdling()=0
Decrement block count.
virtual void getAllStyles(std::vector< std::shared_ptr< SfxItemSet > > &rStyles, SwAutoStyleFamily eFamily)=0
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
bool setGraphicSelection(int nType, int nX, int nY, double fScaleX=1.0, double fScaleY=1.0)
bool setTextSelection(int nType, int nX, int nY)
static void PaintAllChartsOnTile(VirtualDevice &rDevice, int nOutputWidth, int nOutputHeight, int nTilePosX, int nTilePosY, tools::Long nTileWidth, tools::Long nTileHeight, bool bNegativeX=false)
static void paintControlTile(const SdrPage *pPage, const SdrView *pDrawView, vcl::Window const &rMainWindow, VirtualDevice &rDevice, Size aOutputSize, tools::Rectangle const &rTileRect)
static bool postMouseEvent(const SdrPage *pPage, const SdrView *pDrawView, vcl::DocWindow &rMainWindow, int nType, Point aPointHmm, int nCount, int nButtons, int nModifier)
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
const Size & GetPaperSizePixel() const
const SdrPage * GetPage(sal_uInt16 nPgNum) const
const SdrOutliner * GetTextEditOutliner() const
SdrObject * GetObj(size_t nNum) const
size_t GetObjCount() const
virtual const OUString & GetName() const
virtual sal_Bool SAL_CALL attachResource(const OUString &sURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
virtual void SAL_CALL close(sal_Bool bDeliverOwnership) override
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual void SAL_CALL connectController(const css::uno::Reference< css::frame::XController > &xController) override
virtual void SAL_CALL setCurrentController(const css::uno::Reference< css::frame::XController > &xController) override
virtual css::uno::Reference< css::frame::XController > SAL_CALL getCurrentController() override
virtual OUString SAL_CALL getURL() override
virtual void SAL_CALL disconnectController(const css::uno::Reference< css::frame::XController > &xController) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void SAL_CALL acquire() noexcept override
virtual void SAL_CALL release() noexcept override
virtual void SAL_CALL dispose() override
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL getArgs() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
static void postKeyEventAsync(const VclPtr< vcl::Window > &xWindow, int nType, int nCharCode, int nKeyCode, int nRepeat=0)
static bool testInPlaceComponentMouseEventHit(SfxViewShell *pViewShell, int nType, int nX, int nY, int nCount, int nButtons, int nModifier, double fScaleX, double fScaleY, bool bNegativeX=false)
static VclPtr< vcl::Window > getInPlaceDocWindow(SfxViewShell *pViewShell)
static void postMouseEventAsync(const VclPtr< vcl::Window > &xWindow, LokMouseEventData const &rLokMouseEventData)
SfxItemSet * GetItemSet() const
bool Is() const
css::uno::Reference< css::script::XLibraryContainer > GetBasicContainer()
bool IsEnableSetModified() const
css::uno::Reference< css::script::XLibraryContainer > GetDialogContainer()
SfxMedium * GetMedium() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
void EnableSetModified(bool bEnable=true)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
void AppendItem(const SfxPoolItem &)
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
SfxViewShell * GetViewShell() const
bool DoClose()
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetNext(const SfxViewFrame &rPrev, const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxDispatcher * GetDispatcher()