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