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