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>
123 #include <unotools/saveopt.hxx>
124 #include <swruler.hxx>
125 #include <docufld.hxx>
126 
128 #include <numrule.hxx>
129 
130 #include <editeng/langitem.hxx>
131 #include <docary.hxx>
133 #include <i18nutil/searchopt.hxx>
134 
135 #include <charfmt.hxx>
136 #include <fmtcol.hxx>
137 #include <istyleaccess.hxx>
138 
139 #include <swatrset.hxx>
140 #include <view.hxx>
141 #include <viscrs.hxx>
142 #include <srcview.hxx>
143 #include <edtwin.hxx>
144 #include <swdtflvr.hxx>
145 #include <PostItMgr.hxx>
146 
147 #include <svtools/langtab.hxx>
148 #include <map>
149 #include <set>
150 #include <vector>
151 
152 #include <editeng/eeitem.hxx>
153 #include <editeng/editeng.hxx>
154 #include <editeng/editview.hxx>
155 #include <svx/svdoutl.hxx>
156 #include <svx/svdview.hxx>
159 #include <memory>
160 #include <redline.hxx>
162 #include <xmloff/odffields.hxx>
163 #include <tools/json_writer.hxx>
164 
165 #include <svx/svdpage.hxx>
166 
167 #include <IDocumentOutlineNodes.hxx>
168 #include <SearchResultLocator.hxx>
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 public:
263  std::mutex m_Mutex; // just for OInterfaceContainerHelper4
265 };
266 
267 const Sequence< sal_Int8 > & SwXTextDocument::getUnoTunnelId()
268 {
269  static const comphelper::UnoIdInit theSwXTextDocumentUnoTunnelId;
270  return theSwXTextDocumentUnoTunnelId.getSeq();
271 }
272 
273 sal_Int64 SAL_CALL SwXTextDocument::getSomething( const Sequence< sal_Int8 >& rId )
274 {
275  if( comphelper::isUnoTunnelId<SwXTextDocument>(rId) )
276  {
277  return comphelper::getSomething_cast(this);
278  }
279  if( comphelper::isUnoTunnelId<SfxObjectShell>(rId) )
280  {
282  }
283 
284  sal_Int64 nRet = SfxBaseModel::getSomething( rId );
285  if (nRet)
286  return nRet;
287 
289  if (!m_xNumFormatAgg.is()) // may happen if not valid or no SwDoc
290  return 0;
291  Any aNumTunnel = m_xNumFormatAgg->queryAggregation(cppu::UnoType<XUnoTunnel>::get());
292  Reference<XUnoTunnel> xNumTunnel;
293  aNumTunnel >>= xNumTunnel;
294  return (xNumTunnel.is()) ? xNumTunnel->getSomething(rId) : 0;
295 }
296 
298 {
299  Any aRet = SwXTextDocumentBaseClass::queryInterface(rType);
300  if ( !aRet.hasValue() )
301  aRet = SfxBaseModel::queryInterface(rType);
302  if ( !aRet.hasValue() &&
304  {
305  Reference<lang::XMultiServiceFactory> xTmp = this;
306  aRet <<= xTmp;
307  }
308  if ( !aRet.hasValue() &&
310  {
311  Reference<tiledrendering::XTiledRenderable> xTmp = this;
312  aRet <<= xTmp;
313  }
314 
315  if ( !aRet.hasValue()
322  {
324  if(m_xNumFormatAgg.is())
325  aRet = m_xNumFormatAgg->queryAggregation(rType);
326  }
327  return aRet;
328 }
329 
330 void SAL_CALL SwXTextDocument::acquire()noexcept
331 {
333 }
334 
335 void SAL_CALL SwXTextDocument::release()noexcept
336 {
338 }
339 
340 Sequence< uno::Type > SAL_CALL SwXTextDocument::getTypes()
341 {
342  Sequence< uno::Type > aNumTypes;
344  if(m_xNumFormatAgg.is())
345  {
346  const uno::Type& rProvType = cppu::UnoType<XTypeProvider>::get();
347  Any aNumProv = m_xNumFormatAgg->queryAggregation(rProvType);
348  Reference<XTypeProvider> xNumProv;
349  if(aNumProv >>= xNumProv)
350  {
351  aNumTypes = xNumProv->getTypes();
352  }
353  }
356  SwXTextDocumentBaseClass::getTypes(),
357  aNumTypes,
358  Sequence {
361 }
362 
364  : SwXTextDocumentBaseClass(pShell)
365  , m_pImpl(new Impl)
366  ,
367  m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_DOCUMENT)),
368  m_pDocShell(pShell),
369  m_bObjectValid(pShell != nullptr),
370  m_pHiddenViewFrame(nullptr),
371  // #i117783#
372  m_bApplyPagePrintSettingsFromXPagePrintable( false )
373 {
374 }
375 
377 {
378  OSL_ENSURE(m_pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetOrCreateDrawModel(), "No SdrModel in SwDoc, should not happen");
380 }
381 
383 {
384  InitNewDoc();
385  if(m_xNumFormatAgg.is())
386  {
387  Reference< XInterface > x0;
388  m_xNumFormatAgg->setDelegator(x0);
389  m_xNumFormatAgg = nullptr;
390  }
391  m_pPrintUIOptions.reset();
392  if (m_pRenderData && m_pRenderData->IsViewOptionAdjust())
393  { // rhbz#827695: this can happen if the last page is not printed
394  // the SwViewShell has been deleted already by SwView::~SwView
395  // FIXME: replace this awful implementation of XRenderable with
396  // something less insane that has its own view
397  m_pRenderData->ViewOptionAdjustCrashPreventionKludge();
398  }
399  m_pRenderData.reset();
400 }
401 
403 {
404  if(!mxPropertyHelper.is())
405  {
407  }
408  return mxPropertyHelper.get();
409 }
410 
412 {
413  if(!IsValid())
414  return;
415 
416  if(!m_xNumFormatAgg.is())
417  {
418  if ( m_pDocShell->GetDoc() )
419  {
422  m_xNumFormatAgg = pNumFormat;
423  }
424  if(m_xNumFormatAgg.is())
425  m_xNumFormatAgg->setDelegator(static_cast<cppu::OWeakObject*>(static_cast<SwXTextDocumentBaseClass*>(this)));
426  }
427  else
428  {
429  const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
430  Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
431  Reference< XUnoTunnel > xNumTunnel;
432  aNumTunnel >>= xNumTunnel;
433  SvNumberFormatsSupplierObj* pNumFormat
434  = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
435  OSL_ENSURE(pNumFormat, "No number formatter available");
436  if (pNumFormat && !pNumFormat->GetNumberFormatter())
438  }
439 }
440 
441 Reference< XText > SwXTextDocument::getText()
442 {
443  SolarMutexGuard aGuard;
444  if(!IsValid())
445  throw DisposedException("", static_cast< XTextDocument* >(this));
446  if(!m_xBodyText.is())
447  {
449  }
450  return m_xBodyText;
451 }
452 
454 {
455  SolarMutexGuard aGuard;
456  if(!IsValid())
457  throw DisposedException("", static_cast< XTextDocument* >(this));
458 }
459 
461 {
462  SolarMutexGuard aGuard;
463  if(!IsValid())
464  throw DisposedException("", static_cast< XTextDocument* >(this));
465 
466  maActionArr.emplace_front(new UnoActionContext(m_pDocShell->GetDoc()));
467 }
468 
470 {
471  SolarMutexGuard aGuard;
472  if(maActionArr.empty())
473  throw RuntimeException("Nothing to unlock");
474 
475  maActionArr.pop_front();
476 }
477 
479 {
480  SolarMutexGuard aGuard;
481  return !maActionArr.empty();
482 }
483 
484 Reference< frame::XController > SwXTextDocument::getCurrentController()
485 {
487 }
488 
489 void SwXTextDocument::setCurrentController(const Reference< frame::XController > & xController)
490 {
492 }
493 
494 Reference< XInterface > SwXTextDocument::getCurrentSelection()
495 {
496  SolarMutexGuard aGuard;
497  Reference< XInterface > xRef;
498  if(IsValid())
499  {
500  SwView* pView = static_cast<SwView*>(SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>));
501  while(pView && pView->GetObjectShell() != m_pDocShell)
502  {
503  pView = static_cast<SwView*>(SfxViewShell::GetNext(*pView, true, checkSfxViewShell<SwView>));
504  }
505  if(pView)
506  {
507  Any aRef = pView->GetUNOObject()->getSelection();
508  aRef >>= xRef;
509  }
510  }
511  return xRef;
512 }
513 
515 {
516  return SfxBaseModel::attachResource(aURL, aArgs);
517 }
518 
520 {
521  return SfxBaseModel::getURL();
522 }
523 
525 {
526  return SfxBaseModel::getArgs();
527 }
528 
529 void SwXTextDocument::connectController(const Reference< frame::XController > & xController)
530 {
531  SfxBaseModel::connectController(xController);
532 }
533 
534 void SwXTextDocument::disconnectController(const Reference< frame::XController > & xController)
535 {
537 }
538 
540 {
541  // Delete UnoActionContexts before deleting the SwDoc, as the first has unowned pointers to the
542  // second.
543  maActionArr.clear();
544 
546 }
547 
548 void SwXTextDocument::close( sal_Bool bDeliverOwnership )
549 {
550  if(m_pDocShell)
551  {
552  uno::Sequence< uno::Any > aArgs;
554  }
555  SolarMutexGuard aGuard;
556  if(IsValid() && m_pHiddenViewFrame)
558  SfxBaseModel::close(bDeliverOwnership);
559 }
560 
561 void SwXTextDocument::addEventListener(const Reference< lang::XEventListener > & aListener)
562 {
564 }
565 
566 void SwXTextDocument::removeEventListener(const Reference< lang::XEventListener > & aListener)
567 {
569 }
570 
572 {
573  SolarMutexGuard aGuard;
574  if(!IsValid())
575  throw DisposedException("", static_cast< XTextDocument* >(this));
576 
578  {
580  }
582 }
583 
584 Reference< XIndexReplace > SwXTextDocument::getChapterNumberingRules()
585 {
586  SolarMutexGuard aGuard;
587  if(!IsValid())
588  throw DisposedException("", static_cast< XTextDocument* >(this));
589  if(!mxXChapterNumbering.is())
590  {
592  }
593  return mxXChapterNumbering;
594 }
595 
596 Reference< XIndexAccess > SwXTextDocument::getNumberingRules()
597 {
598  SolarMutexGuard aGuard;
599  if(!IsValid())
600  throw DisposedException("", static_cast< XTextDocument* >(this));
601  if(!mxXNumberingRules.is() )
602  {
604  }
605  return mxXNumberingRules;
606 }
607 
608 Reference< XIndexAccess > SwXTextDocument::getFootnotes()
609 {
610  SolarMutexGuard aGuard;
611  if(!IsValid())
612  throw DisposedException("", static_cast< XTextDocument* >(this));
613  if(!mxXFootnotes.is())
614  {
615  mxXFootnotes = new SwXFootnotes(false, m_pDocShell->GetDoc());
616  }
617  return mxXFootnotes;
618 }
619 
622 {
623  SolarMutexGuard aGuard;
624  if(!IsValid())
625  throw DisposedException("", static_cast< XTextDocument* >(this));
626  if(!mxXFootnoteSettings.is())
627  {
629  }
630  return mxXFootnoteSettings;
631 }
632 
633 Reference< XIndexAccess > SwXTextDocument::getEndnotes()
634 {
635  SolarMutexGuard aGuard;
636  if(!IsValid())
637  throw DisposedException("", static_cast< XTextDocument* >(this));
638  if(!mxXEndnotes.is())
639  {
640  mxXEndnotes = new SwXFootnotes(true, m_pDocShell->GetDoc());
641  }
642  return mxXEndnotes;
643 }
644 
646 {
647  SolarMutexGuard aGuard;
648  if(!IsValid())
649  throw DisposedException("", static_cast< XTextDocument* >(this));
650  if(!mxXEndnoteSettings.is())
651  {
653  }
654  return mxXEndnoteSettings;
655 }
656 
657 Reference< util::XReplaceDescriptor > SwXTextDocument::createReplaceDescriptor()
658 {
659  SolarMutexGuard aGuard;
660  Reference< util::XReplaceDescriptor > xRet = new SwXTextSearch;
661  return xRet;
662 }
663 
664 SwUnoCursor* SwXTextDocument::CreateCursorForSearch(Reference< XTextCursor > & xCursor)
665 {
666  getText();
667  XText *const pText = m_xBodyText.get();
668  SwXBodyText* pBText = static_cast<SwXBodyText*>(pText);
669  rtl::Reference<SwXTextCursor> pXTextCursor = pBText->CreateTextCursor(true);
670  xCursor.set( static_cast<text::XWordCursor*>(pXTextCursor.get()) );
671 
672  auto& rUnoCursor(pXTextCursor->GetCursor());
673  rUnoCursor.SetRemainInSection(false);
674  return &rUnoCursor;
675 }
676 
677 sal_Int32 SwXTextDocument::replaceAll(const Reference< util::XSearchDescriptor > & xDesc)
678 {
679  SolarMutexGuard aGuard;
680  Reference< XUnoTunnel > xDescTunnel(xDesc, UNO_QUERY_THROW);
681  SwXTextSearch* pSearch;
682  if (!IsValid() || !(pSearch = comphelper::getFromUnoTunnel<SwXTextSearch>(xDescTunnel)))
683  throw DisposedException("", static_cast< XTextDocument* >(this));
684 
685  Reference< XTextCursor > xCursor;
686  auto pUnoCursor(CreateCursorForSearch(xCursor));
688 
689  i18nutil::SearchOptions2 aSearchOpt;
690  pSearch->FillSearchOptions( aSearchOpt );
691 
694 
695  // Search should take place anywhere
696  pUnoCursor->SetRemainInSection(false);
697  sal_uInt32 nResult;
698  UnoActionContext aContext(m_pDocShell->GetDoc());
699  //try attribute search first
700  if(pSearch->HasSearchAttributes()||pSearch->HasReplaceAttributes())
701  {
705  SfxItemSetFixed<RES_CHRATR_BEGIN, RES_CHRATR_END-1,
706  RES_PARATR_BEGIN, RES_PARATR_END-1,
708  pSearch->FillSearchItemSet(aSearch);
709  pSearch->FillReplaceItemSet(aReplace);
710  bool bCancel;
711  nResult = static_cast<sal_Int32>(pUnoCursor->FindAttrs(aSearch, !pSearch->m_bStyles,
712  eStart, eEnd, bCancel,
713  static_cast<FindRanges>(eRanges),
714  !pSearch->m_sSearchText.isEmpty() ? &aSearchOpt : nullptr,
715  &aReplace ));
716  }
717  else if(pSearch->m_bStyles)
718  {
719  SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->m_sSearchText, pUnoCursor->GetDoc());
720  SwTextFormatColl *pReplaceColl = lcl_GetParaStyle(pSearch->m_sReplaceText, pUnoCursor->GetDoc());
721 
722  bool bCancel;
723  nResult = pUnoCursor->FindFormat(*pSearchColl,
724  eStart, eEnd, bCancel,
725  static_cast<FindRanges>(eRanges), pReplaceColl );
726 
727  }
728  else
729  {
730  //todo/mba: assuming that notes should be omitted
731  bool bCancel;
732  nResult = pUnoCursor->Find_Text(aSearchOpt, false/*bSearchInNotes*/,
733  eStart, eEnd, bCancel,
734  static_cast<FindRanges>(eRanges),
735  true );
736  }
737  return static_cast<sal_Int32>(nResult);
738 
739 }
740 
741 Reference< util::XSearchDescriptor > SwXTextDocument::createSearchDescriptor()
742 {
743  SolarMutexGuard aGuard;
744  Reference< util::XSearchDescriptor > xRet = new SwXTextSearch;
745  return xRet;
746 
747 }
748 
749 // Used for findAll/First/Next
750 
751 SwUnoCursor* SwXTextDocument::FindAny(const Reference< util::XSearchDescriptor > & xDesc,
752  Reference< XTextCursor > & xCursor,
753  bool bAll,
754  sal_Int32& nResult,
755  Reference< XInterface > const & xLastResult)
756 {
757  const auto pSearch = comphelper::getFromUnoTunnel<SwXTextSearch>(xDesc);
758  if(!IsValid() || !pSearch)
759  return nullptr;
760 
761  auto pUnoCursor(CreateCursorForSearch(xCursor));
762 
763  bool bParentInExtra = false;
764  if(xLastResult.is())
765  {
766  Reference<XUnoTunnel> xCursorTunnel( xLastResult, UNO_QUERY);
767  OTextCursorHelper* pPosCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
768  SwPaM* pCursor = pPosCursor ? pPosCursor->GetPaM() : nullptr;
769  if(pCursor)
770  {
771  *pUnoCursor->GetPoint() = *pCursor->End();
772  pUnoCursor->DeleteMark();
773  }
774  else
775  {
776  SwXTextRange* pRange = comphelper::getFromUnoTunnel<SwXTextRange>(xCursorTunnel);
777  if(!pRange)
778  return nullptr;
779  pRange->GetPositions(*pUnoCursor);
780  if(pUnoCursor->HasMark())
781  {
782  if(*pUnoCursor->GetPoint() < *pUnoCursor->GetMark())
783  pUnoCursor->Exchange();
784  pUnoCursor->DeleteMark();
785  }
786  }
787  const SwNode& rRangeNode = pUnoCursor->GetNode();
788  bParentInExtra = rRangeNode.FindFlyStartNode() ||
789  rRangeNode.FindFootnoteStartNode() ||
790  rRangeNode.FindHeaderStartNode() ||
791  rRangeNode.FindFooterStartNode() ;
792  }
793 
794  i18nutil::SearchOptions2 aSearchOpt;
795  pSearch->FillSearchOptions( aSearchOpt );
796 
806  if(bParentInExtra)
807  eRanges = FindRanges::InOther;
808  if(bAll) //always - everywhere?
809  eRanges = FindRanges::InSelAll;
810  SwDocPositions eStart = !bAll ? SwDocPositions::Curr : pSearch->m_bBack ? SwDocPositions::End : SwDocPositions::Start;
811  SwDocPositions eEnd = pSearch->m_bBack ? SwDocPositions::Start : SwDocPositions::End;
812 
813  nResult = 0;
814  for (int nSearchProc = 0; nSearchProc < 2; ++nSearchProc)
815  {
816  //try attribute search first
817  if(pSearch->HasSearchAttributes())
818  {
824  aSearch( m_pDocShell->GetDoc()->GetAttrPool() );
825  pSearch->FillSearchItemSet(aSearch);
826  bool bCancel;
827  nResult = static_cast<sal_Int32>(pUnoCursor->FindAttrs(aSearch, !pSearch->m_bStyles,
828  eStart, eEnd, bCancel,
829  eRanges,
830  !pSearch->m_sSearchText.isEmpty() ? &aSearchOpt : nullptr ));
831  }
832  else if(pSearch->m_bStyles)
833  {
834  SwTextFormatColl *pSearchColl = lcl_GetParaStyle(pSearch->m_sSearchText, pUnoCursor->GetDoc());
835  //pSearch->sReplaceText
836  SwTextFormatColl *pReplaceColl = nullptr;
837  bool bCancel;
838  nResult = static_cast<sal_Int32>(pUnoCursor->FindFormat(*pSearchColl,
839  eStart, eEnd, bCancel,
840  eRanges, pReplaceColl ));
841  }
842  else
843  {
844  //todo/mba: assuming that notes should be omitted
845  bool bCancel;
846  nResult = static_cast<sal_Int32>(pUnoCursor->Find_Text(aSearchOpt, false/*bSearchInNotes*/,
847  eStart, eEnd, bCancel,
848  eRanges ));
849  }
850  if(nResult || (eRanges&(FindRanges::InSelAll|FindRanges::InOther)))
851  break;
852  //second step - find in other
853  eRanges = FindRanges::InOther;
854  }
855  return pUnoCursor;
856 }
857 
858 Reference< XIndexAccess >
859  SwXTextDocument::findAll(const Reference< util::XSearchDescriptor > & xDesc)
860 {
861  SolarMutexGuard aGuard;
862  Reference< XInterface > xTmp;
863  sal_Int32 nResult = 0;
864  Reference< XTextCursor > xCursor;
865  auto pResultCursor(FindAny(xDesc, xCursor, true, nResult, xTmp));
866  if(!pResultCursor)
867  throw RuntimeException("No result cursor");
868  Reference< XIndexAccess > xRet = SwXTextRanges::Create( nResult ? &(*pResultCursor) : nullptr );
869  return xRet;
870 }
871 
872 Reference< XInterface > SwXTextDocument::findFirst(const Reference< util::XSearchDescriptor > & xDesc)
873 {
874  SolarMutexGuard aGuard;
875  Reference< XInterface > xTmp;
876  sal_Int32 nResult = 0;
877  Reference< XTextCursor > xCursor;
878  auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xTmp));
879  if(!pResultCursor)
880  throw RuntimeException("No result cursor");
881  Reference< XInterface > xRet;
882  if(nResult)
883  {
884  const uno::Reference< text::XText > xParent =
886  *pResultCursor->GetPoint());
887  xRet = *new SwXTextCursor(xParent, *pResultCursor);
888  }
889  return xRet;
890 }
891 
892 Reference< XInterface > SwXTextDocument::findNext(const Reference< XInterface > & xStartAt,
893  const Reference< util::XSearchDescriptor > & xDesc)
894 {
895  SolarMutexGuard aGuard;
896  sal_Int32 nResult = 0;
897  Reference< XTextCursor > xCursor;
898  if(!xStartAt.is())
899  throw RuntimeException("xStartAt missing");
900  auto pResultCursor(FindAny(xDesc, xCursor, false, nResult, xStartAt));
901  if(!pResultCursor)
902  throw RuntimeException("No result cursor");
903  Reference< XInterface > xRet;
904  if(nResult)
905  {
906  const uno::Reference< text::XText > xParent =
908  *pResultCursor->GetPoint());
909 
910  xRet = *new SwXTextCursor(xParent, *pResultCursor);
911  }
912  return xRet;
913 }
914 
916 {
917  SolarMutexGuard aGuard;
919  if(!IsValid())
920  throw DisposedException("", static_cast< XTextDocument* >(this));
921 
922  beans::PropertyValue* pArray = aSeq.getArray();
925  if(pData)
926  aData = *pData;
927  Any aVal;
928  aVal <<= static_cast<sal_Int16>(aData.GetRow());
929  pArray[0] = beans::PropertyValue("PageRows", -1, aVal, PropertyState_DIRECT_VALUE);
930  aVal <<= static_cast<sal_Int16>(aData.GetCol());
931  pArray[1] = beans::PropertyValue("PageColumns", -1, aVal, PropertyState_DIRECT_VALUE);
932  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetLeftSpace()));
933  pArray[2] = beans::PropertyValue("LeftMargin", -1, aVal, PropertyState_DIRECT_VALUE);
934  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetRightSpace()));
935  pArray[3] = beans::PropertyValue("RightMargin", -1, aVal, PropertyState_DIRECT_VALUE);
936  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetTopSpace()));
937  pArray[4] = beans::PropertyValue("TopMargin", -1, aVal, PropertyState_DIRECT_VALUE);
938  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetBottomSpace()));
939  pArray[5] = beans::PropertyValue("BottomMargin", -1, aVal, PropertyState_DIRECT_VALUE);
940  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetHorzSpace()));
941  pArray[6] = beans::PropertyValue("HoriMargin", -1, aVal, PropertyState_DIRECT_VALUE);
942  aVal <<= static_cast<sal_Int32>(convertTwipToMm100(aData.GetVertSpace()));
943  pArray[7] = beans::PropertyValue("VertMargin", -1, aVal, PropertyState_DIRECT_VALUE);
944  aVal <<= aData.GetLandscape();
945  pArray[8] = beans::PropertyValue("IsLandscape", -1, aVal, PropertyState_DIRECT_VALUE);
946 
947  return aSeq;
948 }
949 
950 static sal_uInt32 lcl_Any_To_ULONG(const Any& rValue, bool& bException)
951 {
952  bException = false;
953  TypeClass eType = rValue.getValueType().getTypeClass();
954 
955  sal_uInt32 nRet = 0;
956  if( eType == TypeClass_UNSIGNED_LONG )
957  rValue >>= nRet;
958  else
959  {
960  sal_Int32 nVal=0;
961  bException = !(rValue >>= nVal);
962  if( !bException )
963  nRet = static_cast<sal_uInt32>(nVal);
964  }
965 
966  return nRet;
967 }
968 
969 static OUString lcl_CreateOutlineString(const size_t nIndex, const SwDoc* pDoc)
970 {
971  OUStringBuffer sEntry;
972  const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
973  const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
974  const SwTextNode * pTextNd = rOutlineNodes[ nIndex ]->GetTextNode();
975  SwNumberTree::tNumberVector aNumVector = pTextNd->GetNumberVector();
976  if( pOutlRule && pTextNd->GetNumRule())
977  for( int nLevel = 0;
978  nLevel <= pTextNd->GetActualListLevel();
979  nLevel++ )
980  {
981  tools::Long nVal = aNumVector[nLevel];
982  nVal ++;
983  nVal -= pOutlRule->Get(nLevel).GetStart();
984  sEntry.append( nVal );
985  sEntry.append(".");
986  }
987  OUString sOutlineText = pDoc->getIDocumentOutlineNodes().getOutlineText(
988  nIndex, pDoc->GetDocShell()->GetWrtShell()->GetLayout(), false);
989  sEntry.append(sOutlineText);
990  return sEntry.makeStringAndClear();
991 }
992 
994 {
995  SolarMutexGuard aGuard;
996  if(!IsValid())
997  throw DisposedException("", static_cast< XTextDocument* >(this));
998 
1000  //if only a few properties are coming, then use the current settings
1002  if(pData)
1003  aData = *pData;
1004  for(const beans::PropertyValue& rProperty : aSettings)
1005  {
1006  OUString sName = rProperty.Name;
1007  const Any& rVal = rProperty.Value;
1008  bool bException;
1009  sal_uInt32 nVal = lcl_Any_To_ULONG(rVal, bException);
1010  if( sName == "PageRows" )
1011  {
1012  if(!nVal || nVal > 0xff)
1013  throw RuntimeException("Invalid value");
1014  aData.SetRow(static_cast<sal_uInt8>(nVal));
1015  }
1016  else if(sName == "PageColumns")
1017  {
1018  if(!nVal || nVal > 0xff)
1019  throw RuntimeException("Invalid value");
1020  aData.SetCol(static_cast<sal_uInt8>(nVal));
1021  }
1022  else if(sName == "LeftMargin")
1023  {
1025  }
1026  else if(sName == "RightMargin")
1027  {
1029  }
1030  else if(sName == "TopMargin")
1031  {
1033  }
1034  else if(sName == "BottomMargin")
1035  {
1037  }
1038  else if(sName == "HoriMargin")
1039  {
1041  }
1042  else if(sName == "VertMargin")
1043  {
1045  }
1046  else if(sName == "IsLandscape")
1047  {
1048  auto b = o3tl::tryAccess<bool>(rVal);
1049  bException = !b;
1050  if (b)
1051  {
1052  aData.SetLandscape(*b);
1053  }
1054  }
1055  else
1056  bException = true;
1057  if(bException)
1058  throw RuntimeException();
1059  }
1060  m_pDocShell->GetDoc()->SetPreviewPrtData(&aData);
1061 
1062 }
1063 
1065 {
1066  SolarMutexGuard aGuard;
1067  if(!IsValid())
1068  throw DisposedException("", static_cast< XTextDocument* >(this));
1069 
1071  SfxRequest aReq(FN_PRINT_PAGEPREVIEW, SfxCallMode::SYNCHRON,
1074 
1075  for ( const beans::PropertyValue &rProp : xOptions )
1076  {
1077  // get Property-Value from options
1078  Any aValue( rProp.Value );
1079 
1080  // FileName-Property?
1081  if ( rProp.Name == UNO_NAME_FILE_NAME )
1082  {
1083  OUString sFileURL;
1084  if ( rProp.Value >>= sFileURL )
1085  {
1086  // Convert the File URL into a system dependent path, as the SalPrinter expects
1087  OUString sSystemPath;
1088  FileBase::getSystemPathFromFileURL ( sFileURL, sSystemPath );
1089  aReq.AppendItem(SfxStringItem( SID_FILE_NAME, sSystemPath ) );
1090  }
1091  else if ( rProp.Value.getValueType() != cppu::UnoType<void>::get() )
1092  throw IllegalArgumentException();
1093  }
1094 
1095  // CopyCount-Property
1096  else if ( rProp.Name == UNO_NAME_COPY_COUNT )
1097  {
1098  sal_Int32 nCopies = 0;
1099  aValue >>= nCopies;
1100  aReq.AppendItem(SfxInt16Item( SID_PRINT_COPIES, static_cast<sal_Int16>(nCopies) ) );
1101  }
1102 
1103  // Collate-Property
1104  else if ( rProp.Name == UNO_NAME_COLLATE )
1105  {
1106  auto b = o3tl::tryAccess<bool>(rProp.Value);
1107  if ( !b )
1108  throw IllegalArgumentException();
1109  aReq.AppendItem(SfxBoolItem( SID_PRINT_COLLATE, *b ) );
1110 
1111  }
1112 
1113  // Sort-Property
1114  else if ( rProp.Name == UNO_NAME_SORT )
1115  {
1116  auto b = o3tl::tryAccess<bool>(rProp.Value);
1117  if ( !b )
1118  throw IllegalArgumentException();
1119 
1120  aReq.AppendItem(SfxBoolItem( SID_PRINT_SORT, *b ) );
1121  }
1122 
1123  // Pages-Property
1124  else if ( rProp.Name == UNO_NAME_PAGES )
1125  {
1126  OUString sTmp;
1127  if ( !(rProp.Value >>= sTmp) )
1128  throw IllegalArgumentException();
1129 
1130  aReq.AppendItem( SfxStringItem( SID_PRINT_PAGES, sTmp ) );
1131 
1132  }
1133  }
1134 
1135  // #i117783#
1137  pFrame->GetViewShell()->ExecuteSlot(aReq);
1138  // Frame close
1139  pFrame->DoClose();
1140 
1141 }
1142 
1144 {
1145  SolarMutexGuard aGuard;
1146  if(!IsValid())
1147  throw DisposedException("", static_cast< XTextDocument* >(this));
1148  if(!mxXReferenceMarks.is())
1149  {
1151  }
1152  return mxXReferenceMarks;
1153 }
1154 
1155 Reference< XEnumerationAccess > SwXTextDocument::getTextFields()
1156 {
1157  SolarMutexGuard aGuard;
1158  if(!IsValid())
1159  throw DisposedException("", static_cast< XTextDocument* >(this));
1160  if(!mxXTextFieldTypes.is())
1161  {
1163  }
1164  return mxXTextFieldTypes;
1165 }
1166 
1168 {
1169  SolarMutexGuard aGuard;
1170  if(!IsValid())
1171  throw DisposedException("", static_cast< XTextDocument* >(this));
1172  if(!mxXTextFieldMasters.is())
1173  {
1175  }
1176  return mxXTextFieldMasters;
1177 }
1178 
1180 {
1181  SolarMutexGuard aGuard;
1182  if(!IsValid())
1183  throw DisposedException("", static_cast< XTextDocument* >(this));
1184  if(!mxXEmbeddedObjects.is())
1185  {
1187  }
1188  return mxXEmbeddedObjects;
1189 }
1190 
1192 {
1193  SolarMutexGuard aGuard;
1194  if(!IsValid())
1195  throw DisposedException("", static_cast< XTextDocument* >(this));
1196  if(!mxXBookmarks.is())
1197  {
1199  }
1200  return mxXBookmarks;
1201 }
1202 
1204 {
1205  SolarMutexGuard aGuard;
1206  if(!IsValid())
1207  throw DisposedException("", static_cast< XTextDocument* >(this));
1208  if(!mxXTextSections.is())
1209  {
1211  }
1212  return mxXTextSections;
1213 }
1214 
1216 {
1217  SolarMutexGuard aGuard;
1218  if(!IsValid())
1219  throw DisposedException("", static_cast< XTextDocument* >(this));
1220  if(!mxXTextTables.is())
1221  {
1223  }
1224  return mxXTextTables;
1225 }
1226 
1228 {
1229  SolarMutexGuard aGuard;
1230  if(!IsValid())
1231  throw DisposedException("", static_cast< XTextDocument* >(this));
1232  if(!mxXGraphicObjects.is())
1233  {
1235  }
1236  return mxXGraphicObjects;
1237 }
1238 
1240 {
1241  SolarMutexGuard aGuard;
1242  if(!IsValid())
1243  throw DisposedException("", static_cast< XTextDocument* >(this));
1244  if(!mxXTextFrames.is())
1245  {
1247  }
1248  return mxXTextFrames;
1249 }
1250 
1252 {
1253  SolarMutexGuard aGuard;
1254  if(!IsValid())
1255  throw DisposedException("", static_cast< XTextDocument* >(this));
1256  if(!mxXStyleFamilies.is())
1257  {
1259  }
1260  return mxXStyleFamilies;
1261 }
1262 
1263 uno::Reference< style::XAutoStyles > SwXTextDocument::getAutoStyles( )
1264 {
1265  SolarMutexGuard aGuard;
1266  if(!IsValid())
1267  throw DisposedException("", static_cast< XTextDocument* >(this));
1268  if(!mxXAutoStyles.is())
1269  {
1271  }
1272  return mxXAutoStyles;
1273 
1274 }
1275 
1277 {
1278  SolarMutexGuard aGuard;
1279  if(!IsValid())
1280  throw DisposedException("", static_cast< XTextDocument* >(this));
1281  if(!m_xDrawPage.is())
1282  {
1284  // Create a Reference to trigger the complete initialization of the
1285  // object. Otherwise in some corner cases it would get initialized
1286  // at ::InitNewDoc -> which would get called during
1287  // close() or dispose() -> n#681746
1288  uno::Reference<lang::XComponent> xTriggerInit( static_cast<cppu::OWeakObject*>(m_xDrawPage.get()), uno::UNO_QUERY );
1289  }
1290  return m_xDrawPage;
1291 }
1292 
1293 namespace {
1294 
1295 class SwDrawPagesObj : public cppu::WeakImplHelper<
1296  css::drawing::XDrawPages,
1297  css::lang::XServiceInfo>
1298 {
1299 private:
1300  css::uno::Reference< css::drawing::XDrawPageSupplier > m_xDoc;
1301 public:
1302  SwDrawPagesObj(const css::uno::Reference< css::drawing::XDrawPageSupplier >& rxDoc) : m_xDoc(rxDoc) {}
1303 
1304  // XDrawPages
1305  virtual css::uno::Reference< css::drawing::XDrawPage > SAL_CALL
1306  insertNewByIndex(sal_Int32 /*nIndex*/) override { throw css::lang::NoSupportException(); }
1307 
1308  virtual void SAL_CALL remove(const css::uno::Reference< css::drawing::XDrawPage >& /*xPage*/) override
1309  {
1310  throw css::lang::NoSupportException();
1311  }
1312 
1313  // XIndexAccess
1314  virtual sal_Int32 SAL_CALL getCount() override { return 1; }
1315 
1316  virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
1317  {
1318  if (Index != 0)
1319  throw css::lang::IndexOutOfBoundsException("Writer documents have only one DrawPage!");
1320  return css::uno::Any(m_xDoc->getDrawPage());
1321  }
1322 
1323  // XElementAccess
1324  virtual css::uno::Type SAL_CALL getElementType() override
1325  {
1326  SolarMutexGuard aGuard;
1328  }
1329 
1330  virtual sal_Bool SAL_CALL hasElements() override { return true; }
1331 
1332  // XServiceInfo
1333  virtual OUString SAL_CALL getImplementationName() override
1334  {
1335  return "SwDrawPagesObj";
1336  }
1337 
1338  virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override
1339  {
1340  return cppu::supportsService(this, ServiceName);
1341  }
1342 
1343  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
1344  {
1345  return { "com.sun.star.drawing.DrawPages" };
1346  }
1347 };
1348 
1349 }
1350 
1351 // XDrawPagesSupplier
1352 
1353 uno::Reference<drawing::XDrawPages> SAL_CALL SwXTextDocument::getDrawPages()
1354 {
1355  SolarMutexGuard aGuard;
1356  return new SwDrawPagesObj(this);
1357 }
1358 
1360 {
1361  m_bObjectValid = false;
1362  if(m_xNumFormatAgg.is())
1363  {
1364  const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1365  Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
1366  Reference< XUnoTunnel > xNumTunnel;
1367  aNumTunnel >>= xNumTunnel;
1368  SvNumberFormatsSupplierObj* pNumFormat
1369  = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
1370  OSL_ENSURE(pNumFormat, "No number formatter available");
1371  if (pNumFormat)
1372  pNumFormat->SetNumberFormatter(nullptr);
1373  OSL_ENSURE(pNumFormat, "No number formatter available");
1374  }
1375  InitNewDoc();
1376  m_pDocShell = nullptr;
1377  lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
1378  std::unique_lock aGuard(m_pImpl->m_Mutex);
1379  m_pImpl->m_RefreshListeners.disposeAndClear(aGuard, ev);
1380 }
1381 
1383 {
1384  if(m_pDocShell && m_pDocShell != pNewDocShell)
1385  Invalidate();
1386  m_pDocShell = pNewDocShell;
1387  m_bObjectValid = true;
1388 }
1389 
1391 {
1392  // first invalidate all collections, then delete references and Set to zero
1393  if(mxXTextTables.is())
1394  {
1395  XNameAccess* pTables = mxXTextTables.get();
1396  static_cast<SwXTextTables*>(pTables)->Invalidate();
1397  mxXTextTables.clear();
1398  }
1399 
1400  if(mxXTextFrames.is())
1401  {
1402  XNameAccess* pFrames = mxXTextFrames.get();
1403  static_cast<SwXTextFrames*>(pFrames)->Invalidate();
1404  mxXTextFrames.clear();
1405  }
1406 
1407  if(mxXGraphicObjects.is())
1408  {
1409  XNameAccess* pFrames = mxXGraphicObjects.get();
1410  static_cast<SwXTextGraphicObjects*>(pFrames)->Invalidate();
1411  mxXGraphicObjects.clear();
1412  }
1413 
1414  if(mxXEmbeddedObjects.is())
1415  {
1416  XNameAccess* pOLE = mxXEmbeddedObjects.get();
1417  static_cast<SwXTextEmbeddedObjects*>(pOLE)->Invalidate();
1418  mxXEmbeddedObjects.clear();
1419  }
1420 
1421  m_xBodyText = nullptr;
1422 
1423  if(m_xNumFormatAgg.is())
1424  {
1425  const uno::Type& rTunnelType = cppu::UnoType<XUnoTunnel>::get();
1426  Any aNumTunnel = m_xNumFormatAgg->queryAggregation(rTunnelType);
1427  Reference< XUnoTunnel > xNumTunnel;
1428  aNumTunnel >>= xNumTunnel;
1429  SvNumberFormatsSupplierObj* pNumFormat
1430  = comphelper::getFromUnoTunnel<SvNumberFormatsSupplierObj>(xNumTunnel);
1431  OSL_ENSURE(pNumFormat, "No number formatter available");
1432  if (pNumFormat)
1433  pNumFormat->SetNumberFormatter(nullptr);
1434  }
1435 
1436  if(mxXTextFieldTypes.is())
1437  {
1438  XEnumerationAccess* pT = mxXTextFieldTypes.get();
1439  static_cast<SwXTextFieldTypes*>(pT)->Invalidate();
1440  mxXTextFieldTypes.clear();
1441  }
1442 
1443  if(mxXTextFieldMasters.is())
1444  {
1445  XNameAccess* pT = mxXTextFieldMasters.get();
1446  static_cast<SwXTextFieldMasters*>(pT)->Invalidate();
1447  mxXTextFieldMasters.clear();
1448  }
1449 
1450  if(mxXTextSections.is())
1451  {
1452  XNameAccess* pSect = mxXTextSections.get();
1453  static_cast<SwXTextSections*>(pSect)->Invalidate();
1454  mxXTextSections.clear();
1455  }
1456 
1457  if(m_xDrawPage.is())
1458  {
1459  // #i91798#, #i91895#
1460  // dispose XDrawPage here. We are the owner and know that it is no longer in a valid condition.
1461  Reference<XComponent>(static_cast<cppu::OWeakObject*>(m_xDrawPage.get()), UNO_QUERY_THROW)->dispose();
1462  m_xDrawPage->InvalidateSwDoc();
1463  m_xDrawPage.clear();
1464  }
1465 
1466  if ( mxXNumberingRules.is() )
1467  {
1468  XIndexAccess* pNum = mxXNumberingRules.get();
1469  static_cast<SwXNumberingRulesCollection*>(pNum)->Invalidate();
1470  mxXNumberingRules.clear();
1471  }
1472 
1473  if(mxXFootnotes.is())
1474  {
1475  XIndexAccess* pFootnote = mxXFootnotes.get();
1476  static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1477  mxXFootnotes.clear();
1478  }
1479 
1480  if(mxXEndnotes.is())
1481  {
1482  XIndexAccess* pFootnote = mxXEndnotes.get();
1483  static_cast<SwXFootnotes*>(pFootnote)->Invalidate();
1484  mxXEndnotes.clear();
1485  }
1486 
1487  if(mxXDocumentIndexes.is())
1488  {
1489  XIndexAccess* pIdxs = mxXDocumentIndexes.get();
1490  static_cast<SwXDocumentIndexes*>(pIdxs)->Invalidate();
1491  mxXDocumentIndexes.clear();
1492  }
1493 
1494  if(mxXStyleFamilies.is())
1495  {
1496  XNameAccess* pStyles = mxXStyleFamilies.get();
1497  static_cast<SwXStyleFamilies*>(pStyles)->Invalidate();
1498  mxXStyleFamilies.clear();
1499  }
1500  if(mxXAutoStyles.is())
1501  {
1502  XNameAccess* pStyles = mxXAutoStyles.get();
1503  static_cast<SwXAutoStyles*>(pStyles)->Invalidate();
1504  mxXAutoStyles.clear();
1505  }
1506 
1507  if(mxXBookmarks.is())
1508  {
1509  XNameAccess* pBm = mxXBookmarks.get();
1510  static_cast<SwXBookmarks*>(pBm)->Invalidate();
1511  mxXBookmarks.clear();
1512  }
1513 
1514  if(mxXChapterNumbering.is())
1515  {
1516  XIndexReplace* pCh = mxXChapterNumbering.get();
1517  static_cast<SwXChapterNumbering*>(pCh)->Invalidate();
1518  mxXChapterNumbering.clear();
1519  }
1520 
1521  if(mxXFootnoteSettings.is())
1522  {
1523  XPropertySet* pFntSet = mxXFootnoteSettings.get();
1524  static_cast<SwXFootnoteProperties*>(pFntSet)->Invalidate();
1525  mxXFootnoteSettings.clear();
1526  }
1527 
1528  if(mxXEndnoteSettings.is())
1529  {
1530  XPropertySet* pEndSet = mxXEndnoteSettings.get();
1531  static_cast<SwXEndnoteProperties*>(pEndSet)->Invalidate();
1532  mxXEndnoteSettings.clear();
1533  }
1534 
1536  {
1538  static_cast<SwXLineNumberingProperties*>(pLine)->Invalidate();
1540  }
1541  if(mxXReferenceMarks.is())
1542  {
1543  XNameAccess* pMarks = mxXReferenceMarks.get();
1544  static_cast<SwXReferenceMarks*>(pMarks)->Invalidate();
1545  mxXReferenceMarks.clear();
1546  }
1547  if(mxLinkTargetSupplier.is())
1548  {
1549  XNameAccess* pAccess = mxLinkTargetSupplier.get();
1550  static_cast<SwXLinkTargetSupplier*>(pAccess)->Invalidate();
1551  mxLinkTargetSupplier.clear();
1552  }
1553  if(mxXRedlines.is())
1554  {
1555  XEnumerationAccess* pMarks = mxXRedlines.get();
1556  static_cast<SwXRedlines*>(pMarks)->Invalidate();
1557  mxXRedlines.clear();
1558  }
1559  if(mxPropertyHelper.is())
1560  {
1561  mxPropertyHelper->Invalidate();
1562  mxPropertyHelper.clear();
1563  }
1564 }
1565 
1566 css::uno::Reference<css::uno::XInterface> SwXTextDocument::create(
1567  OUString const & rServiceName,
1568  css::uno::Sequence<css::uno::Any> const * arguments)
1569 {
1570  SolarMutexGuard aGuard;
1571  if (!IsValid())
1572  throw DisposedException("", static_cast< XTextDocument* >(this));
1573 
1575  if (nType != SwServiceType::Invalid)
1576  {
1578  }
1579  if (rServiceName == "com.sun.star.drawing.DashTable")
1580  {
1582  }
1583  if (rServiceName == "com.sun.star.drawing.GradientTable")
1584  {
1586  }
1587  if (rServiceName == "com.sun.star.drawing.HatchTable")
1588  {
1590  }
1591  if (rServiceName == "com.sun.star.drawing.BitmapTable")
1592  {
1594  }
1595  if (rServiceName == "com.sun.star.drawing.TransparencyGradientTable")
1596  {
1598  }
1599  if (rServiceName == "com.sun.star.drawing.MarkerTable")
1600  {
1602  }
1603  if (rServiceName == "com.sun.star.drawing.Defaults")
1604  {
1606  }
1607  if (rServiceName == "com.sun.star.document.Settings")
1608  {
1609  return Reference<XInterface>(*new SwXDocumentSettings(this));
1610  }
1611  if (rServiceName == "com.sun.star.document.ImportEmbeddedObjectResolver")
1612  {
1613  return static_cast<cppu::OWeakObject *>(
1615  *m_pDocShell, SvXMLEmbeddedObjectHelperMode::Read));
1616  }
1617  if (rServiceName == "com.sun.star.text.DocumentSettings")
1618  {
1619  return Reference<XInterface>(*new SwXDocumentSettings(this));
1620  }
1621  if (rServiceName == "com.sun.star.chart2.data.DataProvider")
1622  {
1623  return Reference<XInterface>(
1624  static_cast<chart2::data::XDataProvider *>(
1626  GetChartDataProvider()));
1627  }
1628  if (!rServiceName.startsWith("com.sun.star.")
1629  || rServiceName.endsWith(".OLE2Shape"))
1630  {
1631  // We do not want to insert OLE2 Shapes (e.g.,
1632  // "com.sun.star.drawing.OLE2Shape", ...) like this (by creating them
1633  // with the documents factory and adding the shapes to the draw page);
1634  // for inserting OLE objects the proper way is to use
1635  // "com.sun.star.text.TextEmbeddedObject":
1636  throw ServiceNotRegisteredException();
1637  }
1638  // The XML import is allowed to create instances of
1639  // "com.sun.star.drawing.OLE2Shape"; thus, a temporary service name is
1640  // introduced to make this possible:
1641  OUString aTmpServiceName(rServiceName);
1642  if (rServiceName == "com.sun.star.drawing.temporaryForXMLImportOLE2Shape")
1643  {
1644  aTmpServiceName = "com.sun.star.drawing.OLE2Shape";
1645  }
1646  Reference<XInterface> xTmp(
1647  arguments == nullptr
1648  ? SvxFmMSFactory::createInstance(aTmpServiceName)
1650  aTmpServiceName, *arguments));
1651  if (rServiceName == "com.sun.star.drawing.GroupShape"
1652  || rServiceName == "com.sun.star.drawing.Shape3DSceneObject")
1653  {
1654  return *new SwXGroupShape(xTmp, m_pDocShell->GetDoc());
1655  }
1656  if (rServiceName.startsWith("com.sun.star.drawing."))
1657  {
1658  return *new SwXShape(xTmp, m_pDocShell->GetDoc());
1659  }
1660  return xTmp;
1661 }
1662 
1663 Reference< XInterface > SwXTextDocument::createInstance(const OUString& rServiceName)
1664 {
1665  return create(rServiceName, nullptr);
1666 }
1667 
1669  const OUString& ServiceSpecifier,
1670  const Sequence< Any >& Arguments)
1671 {
1672  return create(ServiceSpecifier, &Arguments);
1673 }
1674 
1676 {
1677  static Sequence< OUString > aServices;
1678  if ( !aServices.hasElements() )
1679  {
1681  auto i = comphelper::findValue(aRet, "com.sun.star.drawing.OLE2Shape");
1682  if (i != -1)
1683  {
1684  auto nLength = aRet.getLength();
1685  aRet.getArray()[i] = aRet[nLength - 1];
1686  aRet.realloc( nLength - 1 );
1687  }
1689  aServices = comphelper::concatSequences(aRet, aOwn);
1690  }
1691 
1692  return aServices;
1693 }
1694 
1696 {
1697  return "SwXTextDocument";
1698  /* // Matching the .component information:
1699  return dynamic_cast<SwGlobalDocShell*>( pDocShell ) != nullptr
1700  ? OUString("com.sun.star.comp.Writer.GlobalDocument")
1701  : dynamic_cast<SwWebDocShell*>( pDocShell ) != nullptr
1702  ? OUString("com.sun.star.comp.Writer.WebDocument")
1703  : OUString("com.sun.star.comp.Writer.TextDocument");
1704  */
1705 }
1706 
1707 sal_Bool SwXTextDocument::supportsService(const OUString& rServiceName)
1708 {
1709  return cppu::supportsService(this, rServiceName);
1710 }
1711 
1713 {
1714  bool bWebDoc = (dynamic_cast<SwWebDocShell*>( m_pDocShell) != nullptr );
1715  bool bGlobalDoc = (dynamic_cast<SwGlobalDocShell*>( m_pDocShell) != nullptr );
1716  bool bTextDoc = (!bWebDoc && !bGlobalDoc);
1717 
1718  Sequence< OUString > aRet (3);
1719  OUString* pArray = aRet.getArray();
1720 
1721  pArray[0] = "com.sun.star.document.OfficeDocument";
1722  pArray[1] = "com.sun.star.text.GenericTextDocument";
1723 
1724  if (bTextDoc)
1725  pArray[2] = "com.sun.star.text.TextDocument";
1726  else if (bWebDoc)
1727  pArray[2] = "com.sun.star.text.WebDocument";
1728  else if (bGlobalDoc)
1729  pArray[2] = "com.sun.star.text.GlobalDocument";
1730 
1731  return aRet;
1732 }
1733 
1734 Reference< XIndexAccess > SwXTextDocument::getDocumentIndexes()
1735 {
1736  SolarMutexGuard aGuard;
1737  if(!IsValid())
1738  throw DisposedException("", static_cast< XTextDocument* >(this));
1739 
1740  if(!mxXDocumentIndexes.is())
1741  {
1743  }
1744  return mxXDocumentIndexes;
1745 }
1746 
1747 Reference< XPropertySetInfo > SwXTextDocument::getPropertySetInfo()
1748 {
1749  static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
1750  return xRet;
1751 }
1752 
1753 void SwXTextDocument::setPropertyValue(const OUString& rPropertyName, const Any& aValue)
1754 {
1755  SolarMutexGuard aGuard;
1756  if(!IsValid())
1757  throw DisposedException("", static_cast< XTextDocument* >(this));
1758 
1759  const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
1760 
1761  if(!pEntry)
1762  throw UnknownPropertyException(rPropertyName);
1763  if(pEntry->nFlags & PropertyAttribute::READONLY)
1764  throw PropertyVetoException();
1765  switch(pEntry->nWID)
1766  {
1767  case WID_DOC_CHAR_COUNT :
1768  case WID_DOC_PARA_COUNT :
1769  case WID_DOC_WORD_COUNT :
1770  throw RuntimeException(
1771  "bad WID",
1772  static_cast< cppu::OWeakObject * >(
1773  static_cast< SwXTextDocumentBaseClass * >(this)));
1774  case WID_DOC_WORD_SEPARATOR :
1775  {
1776  OUString sDelim;
1777  aValue >>= sDelim;
1778  SW_MOD()->GetModuleConfig()->SetWordDelimiter(sDelim);
1779  }
1780  break;
1782  case WID_DOC_CHANGES_SHOW:
1783  {
1784  bool bSet = *o3tl::doAccess<bool>(aValue);
1786  if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
1787  {
1789  if( !bSet )
1791  }
1792  else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
1793  {
1794  eMode = bSet ? eMode|RedlineFlags::On : eMode&~RedlineFlags::On;
1795  }
1797  }
1798  break;
1800  {
1801  Sequence <sal_Int8> aNew;
1802  if(aValue >>= aNew)
1803  {
1804  SwDoc* pDoc = m_pDocShell->GetDoc();
1806  if(aNew.hasElements())
1807  {
1809  eMode |= RedlineFlags::On;
1810  pDoc->getIDocumentRedlineAccess().SetRedlineFlags( eMode );
1811  }
1812  }
1813  }
1814  break;
1815  case WID_DOC_AUTO_MARK_URL :
1816  {
1817  OUString sURL;
1818  aValue >>= sURL;
1820  }
1821  break;
1822  case WID_DOC_HIDE_TIPS :
1823  SW_MOD()->GetModuleConfig()->SetHideFieldTips(*o3tl::doAccess<bool>(aValue));
1824  break;
1826  {
1828  eRedMode = eRedMode & (~RedlineFlags::ShowMask);
1829  sal_Int16 nSet = 0;
1830  aValue >>= nSet;
1831  switch(nSet)
1832  {
1833  case RedlineDisplayType::NONE: break;
1834  case RedlineDisplayType::INSERTED: eRedMode |= RedlineFlags::ShowInsert; break;
1835  case RedlineDisplayType::REMOVED: eRedMode |= RedlineFlags::ShowDelete; break;
1836  case RedlineDisplayType::
1837  INSERTED_AND_REMOVED: eRedMode |= RedlineFlags::ShowInsert|RedlineFlags::ShowDelete;
1838  break;
1839  default: throw IllegalArgumentException();
1840  }
1842  }
1843  break;
1845  {
1846  sal_Int16 nYear = 0;
1847  aValue >>= nYear;
1848  SfxRequest aRequest ( SID_ATTR_YEAR2000, SfxCallMode::SLOT, m_pDocShell->GetDoc()->GetAttrPool());
1849  aRequest.AppendItem(SfxUInt16Item( SID_ATTR_YEAR2000, static_cast < sal_uInt16 > ( nYear ) ) );
1850  m_pDocShell->Execute ( aRequest );
1851  }
1852  break;
1854  {
1856  bool bAuto = *o3tl::doAccess<bool>(aValue);
1857 
1858  if ( nullptr != pDrawDoc )
1859  pDrawDoc->SetAutoControlFocus( bAuto );
1860  else if (bAuto)
1861  {
1862  // if setting to true, and we don't have an
1863  // SdrModel, then we are changing the default and
1864  // must thus create an SdrModel, if we don't have an
1865  // SdrModel and we are leaving the default at false,
1866  // we don't need to make an SdrModel and can do nothing
1867  // #i52858# - method name changed
1869  pDrawDoc->SetAutoControlFocus ( bAuto );
1870  }
1871  }
1872  break;
1874  {
1876  bool bMode = *o3tl::doAccess<bool>(aValue);
1877 
1878  if ( nullptr != pDrawDoc )
1879  pDrawDoc->SetOpenInDesignMode( bMode );
1880  else if (!bMode)
1881  {
1882  // if setting to false, and we don't have an
1883  // SdrModel, then we are changing the default and
1884  // must thus create an SdrModel, if we don't have an
1885  // SdrModel and we are leaving the default at true,
1886  // we don't need to make an SdrModel and can do
1887  // nothing
1888  // #i52858# - method name changed
1890  pDrawDoc->SetOpenInDesignMode ( bMode );
1891  }
1892  }
1893  break;
1894  // #i42634# New property to set the bInReading
1895  // flag at the document, used during binary import
1896  case WID_DOC_LOCK_UPDATES :
1897  {
1898  SwDoc* pDoc = m_pDocShell->GetDoc();
1899  bool bBool (false);
1900  if( aValue >>= bBool )
1901  {
1902  pDoc->SetInReading( bBool );
1903  }
1904  }
1905  break;
1906  case WID_DOC_WRITERFILTER:
1907  {
1908  SwDoc* pDoc = m_pDocShell->GetDoc();
1909  bool bBool = {};
1910  if (aValue >>= bBool)
1911  { // HACK: writerfilter has to use API to set this :(
1912  bool bOld = pDoc->IsInWriterfilterImport();
1913  pDoc->SetInWriterfilterImport(bBool);
1914  if (bOld && !bBool)
1915  {
1916  pDoc->getIDocumentFieldsAccess().SetFieldsDirty(false, nullptr, SwNodeOffset(0));
1917  }
1918  }
1919  }
1920  break;
1921  case WID_DOC_BUILDID:
1922  aValue >>= maBuildId;
1923  break;
1924 
1926  {
1927  bool bDefaultPageMode( false );
1928  aValue >>= bDefaultPageMode;
1929  m_pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
1930  }
1931  break;
1933  setGrabBagItem(aValue);
1934  break;
1935 
1936  default:
1937  {
1938  const SfxPoolItem& rItem = m_pDocShell->GetDoc()->GetDefault(pEntry->nWID);
1939  std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
1940  pNewItem->PutValue(aValue, pEntry->nMemberId);
1941  m_pDocShell->GetDoc()->SetDefault(*pNewItem);
1942  }
1943  }
1944 }
1945 
1946 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
1947 {
1948  SolarMutexGuard aGuard;
1949  if(!IsValid())
1950  throw DisposedException("", static_cast< XTextDocument* >(this));
1951 
1952  const SfxItemPropertyMapEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName);
1953 
1954  if(!pEntry)
1955  throw UnknownPropertyException(rPropertyName);
1956  Any aAny;
1957  switch(pEntry->nWID)
1958  {
1959  case WID_DOC_ISTEMPLATEID :
1960  aAny <<= m_pDocShell->IsTemplate();
1961  break;
1962  case WID_DOC_CHAR_COUNT :
1963  case WID_DOC_PARA_COUNT :
1964  case WID_DOC_WORD_COUNT :
1965  {
1966  const SwDocStat& rStat(m_pDocShell->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true ));
1967  sal_Int32 nValue;
1968  switch(pEntry->nWID)
1969  {
1970  case WID_DOC_CHAR_COUNT :nValue = rStat.nChar;break;
1971  case WID_DOC_PARA_COUNT :nValue = rStat.nPara;break;
1972  case WID_DOC_WORD_COUNT :nValue = rStat.nWord;break;
1973  }
1974  aAny <<= nValue;
1975  }
1976  break;
1977  case WID_DOC_WORD_SEPARATOR :
1978  {
1979  aAny <<= SW_MOD()->GetDocStatWordDelim();
1980  }
1981  break;
1983  case WID_DOC_CHANGES_SHOW:
1984  {
1986  bool bSet = false;
1987  if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
1988  {
1990  }
1991  else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
1992  {
1993  bSet = bool(eMode & RedlineFlags::On);
1994  }
1995  aAny <<= bSet;
1996  }
1997  break;
1999  {
2000  SwDoc* pDoc = m_pDocShell->GetDoc();
2001  aAny <<= pDoc->getIDocumentRedlineAccess().GetRedlinePassword();
2002  }
2003  break;
2004  case WID_DOC_AUTO_MARK_URL :
2005  aAny <<= m_pDocShell->GetDoc()->GetTOIAutoMarkURL();
2006  break;
2007  case WID_DOC_HIDE_TIPS :
2008  aAny <<= SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2009  break;
2011  {
2013  eRedMode = eRedMode & RedlineFlags::ShowMask;
2014  sal_Int16 nRet = RedlineDisplayType::NONE;
2015  if(RedlineFlags::ShowInsert == eRedMode)
2017  else if(RedlineFlags::ShowDelete == eRedMode)
2018  nRet = RedlineDisplayType::REMOVED;
2019  else if(RedlineFlags::ShowMask == eRedMode)
2020  nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2021  aAny <<= nRet;
2022  }
2023  break;
2025  {
2027  Reference<XForbiddenCharacters> xRet = mxPropertyHelper;
2028  aAny <<= xRet;
2029  }
2030  break;
2032  {
2033  aAny <<= static_cast < sal_Int16 > (m_pDocShell->GetDoc()->GetNumberFormatter ()->GetYear2000());
2034  }
2035  break;
2037  {
2039  bool bAuto;
2040  if ( nullptr != pDrawDoc )
2041  bAuto = pDrawDoc->GetAutoControlFocus();
2042  else
2043  bAuto = false;
2044  aAny <<= bAuto;
2045  }
2046  break;
2048  {
2050  bool bMode;
2051  if ( nullptr != pDrawDoc )
2052  bMode = pDrawDoc->GetOpenInDesignMode();
2053  else
2054  bMode = true;
2055  aAny <<= bMode;
2056  }
2057  break;
2059  aAny <<= m_pDocShell->GetBasicContainer();
2060  break;
2062  aAny <<= m_pDocShell->GetDialogContainer();
2063  break;
2064  case WID_DOC_VBA_DOCOBJ:
2065  {
2066  /* #i111553# This property provides the name of the constant that
2067  will be used to store this model in the global Basic manager.
2068  That constant will be equivalent to 'ThisComponent' but for
2069  each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
2070  constant can co-exist, as required by VBA. */
2071  aAny <<= OUString( "ThisWordDoc" );
2072  }
2073  break;
2074  case WID_DOC_RUNTIME_UID:
2075  aAny <<= getRuntimeUID();
2076  break;
2077  case WID_DOC_LOCK_UPDATES :
2078  aAny <<= m_pDocShell->GetDoc()->IsInReading();
2079  break;
2080  case WID_DOC_BUILDID:
2081  aAny <<= maBuildId;
2082  break;
2084  aAny <<= hasValidSignatures();
2085  break;
2087  getGrabBagItem(aAny);
2088  break;
2089 
2090  default:
2091  {
2092  const SfxPoolItem& rItem = m_pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2093  rItem.QueryValue(aAny, pEntry->nMemberId);
2094  }
2095  }
2096  return aAny;
2097 }
2098 
2099 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2100  const Reference< XPropertyChangeListener > & /*aListener*/)
2101 {
2102  OSL_FAIL("not implemented");
2103 }
2104 
2105 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2106  const Reference< XPropertyChangeListener > & /*aListener*/)
2107 {
2108  OSL_FAIL("not implemented");
2109 }
2110 
2111 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2112  const Reference< XVetoableChangeListener > & /*aListener*/)
2113 {
2114  OSL_FAIL("not implemented");
2115 }
2116 
2117 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2118  const Reference< XVetoableChangeListener > & /*aListener*/)
2119 {
2120  OSL_FAIL("not implemented");
2121 }
2122 
2124 {
2125  if(!mxLinkTargetSupplier.is())
2126  {
2128  }
2129  return mxLinkTargetSupplier;
2130 }
2131 
2132 Reference< XEnumerationAccess > SwXTextDocument::getRedlines( )
2133 {
2134  if(!mxXRedlines.is())
2135  {
2137  }
2138  return mxXRedlines;
2139 }
2140 
2142 {
2143  // why does SwBaseShell not just call refresh? maybe because it's rSh is
2144  // (sometimes) a different shell than GetWrtShell()?
2145  lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
2146  std::unique_lock aGuard(m_pImpl->m_Mutex);
2147  m_pImpl->m_RefreshListeners.notifyEach(aGuard,
2148  & util::XRefreshListener::refreshed, ev);
2149 }
2150 
2152 {
2153  SolarMutexGuard aGuard;
2154  if(!IsValid())
2155  throw DisposedException("", static_cast< XTextDocument* >(this));
2156 
2157  SwViewShell *pViewShell = m_pDocShell->GetWrtShell();
2159  if(pViewShell)
2160  pViewShell->Reformat();
2161 }
2162 
2164  const Reference<util::XRefreshListener> & xListener)
2165 {
2166  if (xListener)
2167  {
2168  std::unique_lock aGuard(m_pImpl->m_Mutex);
2169  m_pImpl->m_RefreshListeners.addInterface(aGuard, xListener);
2170  }
2171 }
2172 
2174  const Reference<util::XRefreshListener> & xListener)
2175 {
2176  if (xListener)
2177  {
2178  std::unique_lock aGuard(m_pImpl->m_Mutex);
2179  m_pImpl->m_RefreshListeners.removeInterface(aGuard, xListener);
2180  }
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.getArray(),
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  // tdf#144989 the layout is complete now - prevent DoIdleJobs() from
2588  // messing it up, particulary SwDocUpdateField::MakeFieldList_() unhiding
2589  // sections
2591 
2592  return nRet;
2593 }
2594 
2595 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2596  sal_Int32 nRenderer,
2597  const uno::Any& rSelection,
2598  const uno::Sequence< beans::PropertyValue >& rxOptions )
2599 {
2600  SolarMutexGuard aGuard;
2601  if(!IsValid())
2602  {
2603  throw DisposedException("", static_cast< XTextDocument* >(this));
2604  }
2605 
2606  const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2607  bool bIsSwSrcView = false;
2608  SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2609 
2610  // m_pRenderData should NOT be created here!
2611  // That should only be done in getRendererCount. If this function is called before
2612  // getRendererCount was called then the caller will probably just retrieve the extra UI options
2613  // and is not interested in getting valid information about the other data that would
2614  // otherwise be provided here!
2615 // if( ! m_pRenderData )
2616 // m_pRenderData = new SwRenderData;
2617  if (!m_pPrintUIOptions)
2619  m_pPrintUIOptions->processProperties( rxOptions );
2620  const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2621  const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2622  const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup" );
2623 
2624  SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2625  OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2626  if (!pDoc || !pView)
2627  return uno::Sequence< beans::PropertyValue >();
2628 
2629  // due to #110067# (document page count changes sometimes during
2630  // PDF export/printing) we can not check for the upper bound properly.
2631  // Thus instead of throwing the exception we silently return.
2632  if (0 > nRenderer)
2633  throw IllegalArgumentException();
2634 
2635  // TODO/mba: we really need a generic way to get the SwViewShell!
2636  SwViewShell* pVwSh = nullptr;
2637  SwView* pSwView = dynamic_cast<SwView*>( pView );
2638  if ( pSwView )
2639  pVwSh = pSwView->GetWrtShellPtr();
2640  else
2641  pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2642 
2643  sal_Int32 nMaxRenderer = 0;
2644  if (!bIsSwSrcView && m_pRenderData)
2645  {
2646  OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2647  nMaxRenderer = bPrintProspect?
2648  m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2649  m_pRenderData->GetPagesToPrint().size() - 1;
2650  }
2651  // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2652  // we obmit checking of the upper bound in this case.
2653  if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2654  return uno::Sequence< beans::PropertyValue >();
2655 
2656  uno::Sequence< beans::PropertyValue > aRenderer;
2657  if (m_pRenderData)
2658  {
2659  // #i114210#
2660  // determine the correct page number from the renderer index
2661  // #i114875
2662  // consider brochure print
2663  const sal_Int32 nPage = bPrintProspect
2664  ? nRenderer + 1
2665  : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2666 
2667  // get paper tray to use ...
2668  sal_Int32 nPrinterPaperTray = -1;
2669  if (! bPrintPaperFromSetup)
2670  {
2671  // ... from individual page style (see the page tab in Format/Page dialog)
2672  const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2673  std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2674  if (aIt != rPaperTrays.end())
2675  nPrinterPaperTray = aIt->second;
2676  }
2677 
2678  awt::Size aPageSize;
2679  awt::Point aPagePos;
2680  awt::Size aPreferredPageSize;
2681  Size aTmpSize;
2682  if (bIsSwSrcView || bPrintProspect)
2683  {
2684  // for printing of HTML source code and prospect printing we should use
2685  // the printers paper size since
2686  // a) HTML source view has no page size
2687  // b) prospect printing has a different page size from the documents page
2688  // since two document pages will get rendered on one printer page
2689 
2690  // since PageIncludesNonprintableArea will be set to true we can return the
2691  // printers paper size here.
2692  // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2693  // case we won't get an OutputDevice here, but then the caller also has no need
2694  // for the correct PageSize right now...
2695  VclPtr< Printer > pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ).get());
2696  if (pPrinter)
2697  {
2698  // HTML source view and prospect adapt to the printer's paper size
2699  aTmpSize = pPrinter->GetPaperSize();
2700  aTmpSize = OutputDevice::LogicToLogic( aTmpSize,
2701  pPrinter->GetMapMode(), MapMode( MapUnit::Map100thMM ));
2702  aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2703  #if 0
2704  // #i115048# it seems users didn't like getting double the formatted page size
2705  // revert to "old" behavior scaling to the current paper size of the printer
2706  if (bPrintProspect)
2707  {
2708  // we just state what output size we would need
2709  // which may cause vcl to set that page size on the printer
2710  // (if available and not overridden by the user)
2711  aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2712  aPreferredPageSize = awt::Size ( convertTwipToMm100( 2 * aTmpSize.Width() ),
2713  convertTwipToMm100( aTmpSize.Height() ));
2714  }
2715  #else
2716  if( bPrintProspect )
2717  {
2718  // just switch to an appropriate portrait/landscape format
2719  // FIXME: brochure printing with landscape pages puts the
2720  // pages next to each other, so landscape is currently always
2721  // the better choice
2722  if( aPageSize.Width < aPageSize.Height )
2723  {
2724  aPreferredPageSize.Width = aPageSize.Height;
2725  aPreferredPageSize.Height = aPageSize.Width;
2726  }
2727  }
2728  #endif
2729  }
2730  }
2731  else
2732  {
2733  aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2734  aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
2735  convertTwipToMm100( aTmpSize.Height() ));
2736  Point aPoint = pVwSh->GetPagePos(nPage);
2737  aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), convertTwipToMm100(aPoint.Y()));
2738  }
2739 
2740  sal_Int32 nLen = 3;
2741  aRenderer = { comphelper::makePropertyValue("PageSize", aPageSize),
2742  comphelper::makePropertyValue("PageIncludesNonprintableArea", true),
2743  comphelper::makePropertyValue("PagePos", aPagePos) };
2744  if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2745  {
2746  ++nLen;
2747  aRenderer.realloc( nLen );
2748  auto pRenderer = aRenderer.getArray();
2749  pRenderer[ nLen - 1 ].Name = "PreferredPageSize";
2750  pRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2751  }
2752  if (nPrinterPaperTray >= 0)
2753  {
2754  ++nLen;
2755  aRenderer.realloc( nLen );
2756  auto pRenderer = aRenderer.getArray();
2757  pRenderer[ nLen - 1 ].Name = "PrinterPaperTray";
2758  pRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2759  }
2760  }
2761 
2762  // #i117783#
2764  {
2765  const SwPagePreviewPrtData* pPagePrintSettings =
2767  if ( pPagePrintSettings &&
2768  ( pPagePrintSettings->GetRow() > 1 ||
2769  pPagePrintSettings->GetCol() > 1 ) )
2770  {
2771  // extend render data by page print settings attributes
2772  sal_Int32 nLen = aRenderer.getLength();
2773  const sal_Int32 nRenderDataIdxStart = nLen;
2774  nLen += 9;
2775  aRenderer.realloc( nLen );
2776  auto pRenderer = aRenderer.getArray();
2777  // put page print settings attribute into render data
2778  const sal_Int32 nRow = pPagePrintSettings->GetRow();
2779  pRenderer[ nRenderDataIdxStart + 0 ].Name = "NUpRows";
2780  pRenderer[ nRenderDataIdxStart + 0 ].Value <<= std::max<sal_Int32>( nRow, 1);
2781  const sal_Int32 nCol = pPagePrintSettings->GetCol();
2782  pRenderer[ nRenderDataIdxStart + 1 ].Name = "NUpColumns";
2783  pRenderer[ nRenderDataIdxStart + 1 ].Value <<= std::max<sal_Int32>( nCol, 1);
2784  pRenderer[ nRenderDataIdxStart + 2 ].Name = "NUpPageMarginLeft";
2785  pRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
2786  pRenderer[ nRenderDataIdxStart + 3 ].Name = "NUpPageMarginRight";
2787  pRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
2788  pRenderer[ nRenderDataIdxStart + 4 ].Name = "NUpPageMarginTop";
2789  pRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
2790  pRenderer[ nRenderDataIdxStart + 5 ].Name = "NUpPageMarginBottom";
2791  pRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
2792  pRenderer[ nRenderDataIdxStart + 6 ].Name = "NUpHorizontalSpacing";
2793  pRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
2794  pRenderer[ nRenderDataIdxStart + 7 ].Name = "NUpVerticalSpacing";
2795  pRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
2796  {
2797  Printer* pPrinter = m_pDocShell->GetDoc()->getIDocumentDeviceAccess().getPrinter( false );
2798  if ( pPrinter )
2799  {
2800  awt::Size aNewPageSize;
2801  const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
2802  aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
2803  if ( ( pPagePrintSettings->GetLandscape() &&
2804  aPageSize.Width() < aPageSize.Height() ) ||
2805  ( !pPagePrintSettings->GetLandscape() &&
2806  aPageSize.Width() > aPageSize.Height() ) )
2807  {
2808  aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
2809  }
2810  pRenderer[ nRenderDataIdxStart + 8 ].Name = "NUpPaperSize";
2811  pRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
2812  }
2813  }
2814  }
2815 
2817  }
2818 
2819  m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2820 
2821  return aRenderer;
2822 }
2823 
2825  /* out */ bool &rbIsSwSrcView,
2826  const uno::Reference< css::frame::XController >& rController )
2827 {
2828  // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2829  // must not be used (see comment from MBA)
2830 
2831  SfxViewShell *pView = nullptr;
2832  SwView *pSwView = nullptr;
2833  SwPagePreview *pSwPagePreview = nullptr;
2834  SwSrcView *pSwSrcView = nullptr;
2835  SfxViewFrame *pFrame = SfxViewFrame::GetFirst( m_pDocShell, false );
2836 
2837  // look for the view shell with the same controller in use,
2838  // otherwise look for a suitable view, preferably a SwView,
2839  // if that one is not found use a SwPagePreview if found.
2840  while (pFrame)
2841  {
2842  pView = pFrame->GetViewShell();
2843  pSwView = dynamic_cast< SwView * >(pView);
2844  pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2845  if (!pSwPagePreview)
2846  pSwPagePreview = dynamic_cast< SwPagePreview * >(pView);
2847  if (rController.is())
2848  {
2849  if (pView && pView->GetController() == rController)
2850  break;
2851  }
2852  else if (pSwView || pSwSrcView)
2853  break;
2854  pFrame = SfxViewFrame::GetNext( *pFrame, m_pDocShell, false );
2855  }
2856 
2857  OSL_ENSURE( pSwView || pSwPagePreview || pSwSrcView, "failed to get view shell" );
2858  if (pView)
2859  rbIsSwSrcView = pSwSrcView != nullptr;
2860  return pView;
2861 }
2862 
2864  sal_Int32 nRenderer,
2865  const uno::Any& rSelection,
2866  const uno::Sequence< beans::PropertyValue >& rxOptions )
2867 {
2868  SolarMutexGuard aGuard;
2869  if(!IsValid())
2870  {
2871  throw DisposedException( OUString(),
2872  static_cast< XTextDocument* >(this) );
2873  }
2874 
2875  // due to #110067# (document page count changes sometimes during
2876  // PDF export/printing) we can not check for the upper bound properly.
2877  // Thus instead of throwing the exception we silently return.
2878  if (0 > nRenderer)
2879  throw IllegalArgumentException();
2880 
2881  // tdf#135244: prevent jumping to cursor at any temporary modification
2882  auto aLock = m_pDocShell->LockAllViews();
2883 
2884  const bool bHasPDFExtOutDevData = lcl_SeqHasProperty( rxOptions, "HasPDFExtOutDevData" );
2885  const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ) || bHasPDFExtOutDevData;
2886  bool bIsSwSrcView = false;
2887  SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2888 
2889  OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
2890  OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
2891  if (!bIsSwSrcView && !m_pRenderData)
2892  m_pRenderData.reset(new SwRenderData);
2893  if (!m_pPrintUIOptions)
2895  m_pPrintUIOptions->processProperties( rxOptions );
2896  const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2897  const bool bLastPage = m_pPrintUIOptions->getBoolValue( "IsLastPage" );
2898 
2899  SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2900  OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2901  if (pDoc && pView)
2902  {
2903  sal_Int32 nMaxRenderer = 0;
2904  if (!bIsSwSrcView)
2905  {
2906  OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2907  nMaxRenderer = bPrintProspect?
2908  m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2909  m_pRenderData->GetPagesToPrint().size() - 1;
2910  }
2911  // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2912  // we obmit checking of the upper bound in this case.
2913  if (bIsSwSrcView || nRenderer <= nMaxRenderer)
2914  {
2915  if (bIsSwSrcView)
2916  {
2917  SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2919  rSwSrcView.PrintSource(pOutDev, nRenderer + 1, false);
2920  }
2921  else
2922  {
2923  // the view shell should be SwView for documents PDF export
2924  // or SwPagePreview for PDF export of the page preview
2925  SwViewShell* pVwSh = nullptr;
2926  // TODO/mba: we really need a generic way to get the SwViewShell!
2927  const SwView* pSwView = dynamic_cast<const SwView*>(pView);
2928  if (pSwView)
2929  pVwSh = pSwView->GetWrtShellPtr();
2930  else
2931  pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2932 
2933  // get output device to use
2935 
2936  if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
2937  {
2938  const OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange" );
2939  const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage" );
2940  bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2941 
2942  OSL_ENSURE((pSwView && m_pRenderData->IsViewOptionAdjust())
2943  || (!pSwView && !m_pRenderData->IsViewOptionAdjust()),
2944  "SwView / SwViewOptionAdjust_Impl availability mismatch" );
2945 
2946  // since printing now also use the API for PDF export this option
2947  // should be set for printing as well ...
2948  pVwSh->SetPDFExportOption( true );
2949 
2950  // #i12836# enhanced pdf export
2951 
2952  // First, we have to export hyperlinks, notes, and outline to pdf.
2953  // During this process, additional information required for tagging
2954  // the pdf file are collected, which are evaluated during painting.
2955 
2956  SwWrtShell* pWrtShell = pSwView ? pSwView->GetWrtShellPtr() : nullptr;
2957 
2958  SwPrintData const& rSwPrtOptions =
2959  *m_pRenderData->GetSwPrtOptions();
2960 
2961  if (bIsPDFExport && (bFirstPage || bHasPDFExtOutDevData) && pWrtShell)
2962  {
2963  SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
2964  }
2965 
2966  if (bPrintProspect)
2967  pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
2968  else // normal printing and PDF export
2969  pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer, bIsPDFExport );
2970 
2971  // #i35176#
2972 
2973  // After printing the last page, we take care for the links coming
2974  // from the EditEngine. The links are generated during the painting
2975  // process, but the destinations are still missing.
2976 
2977  if (bIsPDFExport && bLastPage && pWrtShell)
2978  {
2979  SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, true, rSwPrtOptions );
2980  }
2981 
2982  pVwSh->SetPDFExportOption( false );
2983 
2984  // last page to be rendered? (not necessarily the last page of the document)
2985  // -> do clean-up of data
2986  if (bLastPage)
2987  {
2988  // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
2989  // of the shell, which might get destroyed in lcl_DisposeView!
2990  if (m_pRenderData->IsViewOptionAdjust())
2991  m_pRenderData->ViewOptionAdjustStop();
2992 
2993  if (m_pRenderData->HasPostItData())
2994  m_pRenderData->DeletePostItData();
2995  if (m_pHiddenViewFrame)
2996  {
2998  m_pHiddenViewFrame = nullptr;
2999 
3000  // prevent crash described in #i108805
3001  SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3002  SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3003  pSet->Put( SfxBoolItem( SID_HIDDEN, false ) );
3004 
3005  }
3006  }
3007  }
3008  }
3009  }
3010  }
3011  if( bLastPage )
3012  {
3013  // tdf#144989 enable DoIdleJobs() again after last page
3015  m_pRenderData.reset();
3016  m_pPrintUIOptions.reset();
3017  }
3018 }
3019 
3020 // xforms::XFormsSupplier
3021 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3022 {
3023  SolarMutexGuard aGuard;
3024  if ( !m_pDocShell )
3025  throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
3026  SwDoc* pDoc = m_pDocShell->GetDoc();
3027  return pDoc->getXForms();
3028 }
3029 
3030 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3031 {
3032  SolarMutexGuard aGuard;
3033  if (!IsValid())
3034  {
3035  throw DisposedException("SwXTextDocument not valid",
3036  static_cast<XTextDocument*>(this));
3037  }
3038 
3040  *m_pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
3041 }
3042 
3043 uno::Reference< util::XCloneable > SwXTextDocument::createClone( )
3044 {
3045  SolarMutexGuard aGuard;
3046  if(!IsValid())
3047  throw DisposedException("", static_cast< XTextDocument* >(this));
3048 
3049  // create a new document - hidden - copy the storage and return it
3050  // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3051  // and thus SfxObjectShellLock is not allowed here
3052  // the model holds reference to the shell, so the shell will not destructed at the end of method
3053  SfxObjectShellRef pShell = m_pDocShell->GetDoc()->CreateCopy(false, false);
3054  uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3055  uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3056  uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3057  storeToStorage( xNewStorage, aTempMediaDescriptor );
3058  uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3059  xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3060  return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3061 }
3062 
3063 void SwXTextDocument::addPasteEventListener(const uno::Reference<text::XPasteListener>& xListener)
3064 {
3065  SolarMutexGuard aGuard;
3066 
3067  if (IsValid() && xListener.is())
3069 }
3070 
3072  const uno::Reference<text::XPasteListener>& xListener)
3073 {
3074  SolarMutexGuard aGuard;
3075 
3076  if (IsValid() && xListener.is())
3078 }
3079 
3081  int nOutputWidth, int nOutputHeight,
3082  int nTilePosX, int nTilePosY,
3083  tools::Long nTileWidth, tools::Long nTileHeight )
3084 {
3085  SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3086  pViewShell->PaintTile(rDevice, nOutputWidth, nOutputHeight,
3087  nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3088 
3089  LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
3090  nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3091 }
3092 
3094 {
3095  SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3096  Size aDocSize = pViewShell->GetDocSize();
3097 
3098  return Size(aDocSize.Width() + 2 * DOCUMENTBORDER,
3099  aDocSize.Height() + 2 * DOCUMENTBORDER);
3100 }
3101 
3102 void SwXTextDocument::setPart(int nPart, bool /*bAllowChangeFocus*/)
3103 {
3104  SolarMutexGuard aGuard;
3105 
3106  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3107  if (!pWrtShell)
3108  return;
3109 
3110  pWrtShell->GotoPage(nPart + 1, true);
3111 }
3112 
3114 {
3115  SolarMutexGuard aGuard;
3116 
3117  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3118  if (!pWrtShell)
3119  return 0;
3120 
3121  return pWrtShell->GetPageCnt();
3122 }
3123 
3125 {
3126  SolarMutexGuard aGuard;
3127 
3128  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3129  if (!pWrtShell)
3130  return OUString();
3131 
3132  return pWrtShell->getPageRectangles();
3133 }
3134 
3135 void SwXTextDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard)
3136 {
3137  SolarMutexGuard aGuard;
3138 
3139  SwView* pView = m_pDocShell->GetView();
3140  if (pView)
3141  pView->GetEditWin().SetClipboard(xClipboard);
3142 }
3143 
3145 {
3146  SolarMutexGuard aGuard;
3147 
3148  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3149  if (!pWrtShell)
3150  return false;
3151 
3153  if (SdrView* pSdrView = pWrtShell->GetDrawView())
3154  {
3155  if (pSdrView->GetTextEditObject())
3156  // Editing shape text
3157  return EditEngine::HasValidData(aDataHelper.GetTransferable());
3158  }
3159 
3160  return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
3161 }
3162 
3164 {
3165  if (SwView* pView = m_pDocShell->GetView())
3166  {
3167  // set the PgUp/PgDown offset
3168  pView->ForcePageUpDownOffset(2 * rRectangle.GetHeight() / 3);
3169  }
3170 
3171  if (SwViewShell* pViewShell = m_pDocShell->GetWrtShell())
3172  {
3173  pViewShell->setLOKVisibleArea(rRectangle);
3174  }
3175 }
3176 
3177 void SwXTextDocument::setClientZoom(int nTilePixelWidth_, int /*nTilePixelHeight_*/,
3178  int nTileTwipWidth_, int /*nTileTwipHeight_*/)
3179 {
3180  // Here we set the zoom value as it has been set by the user in the client.
3181  // This value is used in postMouseEvent and setGraphicSelection methods
3182  // for in place chart editing. We assume that x and y scale is roughly
3183  // the same.
3184  SfxInPlaceClient* pIPClient = m_pDocShell->GetView()->GetIPClient();
3185  if (!pIPClient)
3186  return;
3187 
3188  SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3189  double fScale = 100.0 * nTilePixelWidth_ / nTileTwipWidth_
3191  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3192  if (aOption.GetZoom() != fScale)
3193  {
3194  aOption.SetZoom(fScale);
3195  pWrtViewShell->ApplyViewOptions(aOption);
3196 
3197  // Changing the zoom value doesn't always trigger the updating of
3198  // the client ole object area, so we call it directly.
3199  pIPClient->VisAreaChanged();
3200  }
3201 }
3202 
3204 {
3205  SolarMutexGuard aGuard;
3206 
3207  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3208  if (!pWrtShell)
3209  return PointerStyle::Arrow;
3210 
3211  return pWrtShell->GetView().GetEditWin().GetPointer();
3212 }
3213 
3215 {
3216  auto redlinesNode = rJson.startArray("redlines");
3217 
3218  // Disable since usability is very low beyond some small number of changes.
3219  static bool bDisableRedlineComments = getenv("DISABLE_REDLINE") != nullptr;
3220  if (bDisableRedlineComments)
3221  return;
3222 
3223  const SwRedlineTable& rRedlineTable
3225  for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
3226  {
3227  auto redlineNode = rJson.startStruct();
3228  rJson.put("index", rRedlineTable[i]->GetId());
3229  rJson.put("author", rRedlineTable[i]->GetAuthorString(1));
3230  rJson.put("type", SwRedlineTypeToOUString(
3231  rRedlineTable[i]->GetRedlineData().GetType()));
3232  rJson.put("comment",
3233  rRedlineTable[i]->GetRedlineData().GetComment());
3234  rJson.put("description", rRedlineTable[i]->GetDescr());
3235  OUString sDateTime = utl::toISO8601(
3236  rRedlineTable[i]->GetRedlineData().GetTimeStamp().GetUNODateTime());
3237  rJson.put("dateTime", sDateTime);
3238 
3239  SwContentNode* pContentNd = rRedlineTable[i]->GetContentNode();
3240  SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
3241  if (pView && pContentNd)
3242  {
3243  SwShellCursor aCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()));
3244  aCursor.SetMark();
3245  aCursor.GetMark()->nNode = *pContentNd;
3246  aCursor.GetMark()->nContent.Assign(pContentNd,
3247  rRedlineTable[i]->End()->nContent.GetIndex());
3248 
3249  aCursor.FillRects();
3250 
3251  SwRects* pRects(&aCursor);
3252  std::vector<OString> aRects;
3253  for (const SwRect& rNextRect : *pRects)
3254  aRects.push_back(rNextRect.SVRect().toString());
3255 
3256  const OString sRects = comphelper::string::join("; ", aRects);
3257  rJson.put("textRange", sRects);
3258  }
3259  }
3260 }
3261 
3263 {
3264  SW_MOD()->GetRedlineAuthorInfo(rJsonWriter);
3265 }
3266 
3268 {
3269  SwView* pView = m_pDocShell->GetView();
3270  dynamic_cast<SwCommentRuler&>(pView->GetHRuler()).CreateJsonNotification(rJsonWriter);
3271 }
3272 
3274 {
3275  SolarMutexGuard aGuard;
3276  auto commentsNode = rJsonWriter.startArray("comments");
3277  for (auto const& sidebarItem : *m_pDocShell->GetView()->GetPostItMgr())
3278  {
3279  sw::annotation::SwAnnotationWin* pWin = sidebarItem->mpPostIt.get();
3280 
3281  if (!pWin)
3282  {
3283  continue;
3284  }
3285 
3286  const SwPostItField* pField = pWin->GetPostItField();
3287  const SwRect& aRect = pWin->GetAnchorRect();
3288  tools::Rectangle aSVRect(aRect.Pos().getX(),
3289  aRect.Pos().getY(),
3290  aRect.Pos().getX() + aRect.SSize().Width(),
3291  aRect.Pos().getY() + aRect.SSize().Height());
3292 
3293  if (!sidebarItem->maLayoutInfo.mPositionFromCommentAnchor)
3294  {
3295  // Comments on frames: anchor position is the corner position, not the whole frame.
3296  aSVRect.SetSize(Size(0, 0));
3297  }
3298 
3299  std::vector<OString> aRects;
3300  for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
3301  {
3302  const SwRect rect(aRange.getMinX(), aRange.getMinY(), aRange.getWidth(), aRange.getHeight());
3303  aRects.push_back(rect.SVRect().toString());
3304  }
3305  const OString sRects = comphelper::string::join("; ", aRects);
3306 
3307  auto commentNode = rJsonWriter.startStruct();
3308  rJsonWriter.put("id", pField->GetPostItId());
3309  rJsonWriter.put("parent", pWin->CalcParent());
3310  rJsonWriter.put("author", pField->GetPar1());
3311  rJsonWriter.put("text", pField->GetPar2());
3312  rJsonWriter.put("resolved", pField->GetResolved() ? "true" : "false");
3313  rJsonWriter.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
3314  rJsonWriter.put("anchorPos", aSVRect.toString());
3315  rJsonWriter.put("textRange", sRects);
3316  }
3317 }
3318 
3320 {
3321  auto aIter = aArguments.find("type");
3322  if (aIter == aArguments.end() || aIter->second != "drop-down")
3323  return;
3324 
3325  aIter = aArguments.find("cmd");
3326  if (aIter == aArguments.end() || aIter->second != "selected")
3327  return;
3328 
3329  aIter = aArguments.find("data");
3330  if (aIter == aArguments.end())
3331  return;
3332 
3333  sal_Int32 nSelection = aIter->second.toInt32();
3336  if ( !pFieldBM )
3337  {
3338  --aPos.nContent;
3340  }
3341  if (pFieldBM && pFieldBM->GetFieldname() == ODF_FORMDROPDOWN)
3342  {
3343  if (nSelection >= 0)
3344  {
3345  (*pFieldBM->GetParameters())[ODF_FORMDROPDOWN_RESULT] <<= nSelection;
3346  pFieldBM->Invalidate();
3349  }
3350  }
3351 }
3352 
3353 std::vector<basegfx::B2DRange>
3355 {
3356  SwDoc* pDoc = m_pDocShell->GetDoc();
3357  if (!pDoc)
3358  return std::vector<basegfx::B2DRange>();
3359 
3360  sw::search::SearchResultLocator aLocator(pDoc);
3361  sw::search::LocationResult aResult = aLocator.findForPayload(pPayload);
3362  if (aResult.mbFound)
3363  {
3364  return aResult.maRectangles;
3365  }
3366  return std::vector<basegfx::B2DRange>();
3367 }
3368 
3370 {
3371  SolarMutexGuard aGuard;
3372 
3373  SwView* pView = m_pDocShell->GetView();
3374  if (!pView)
3375  return 0;
3376 
3377  return pView->getPart();
3378 }
3379 
3380 OUString SwXTextDocument::getPartName(int nPart)
3381 {
3382  SolarMutexGuard aGuard;
3383 
3384  return SwResId(STR_PAGE) + OUString::number(nPart + 1);
3385 }
3386 
3387 OUString SwXTextDocument::getPartHash(int nPart)
3388 {
3389  SolarMutexGuard aGuard;
3390  OUString sPart(SwResId(STR_PAGE) + OUString::number(nPart + 1));
3391 
3392  return OUString::number(sPart.hashCode());
3393 }
3394 
3396 {
3397  SolarMutexGuard aGuard;
3398  VclPtr<vcl::Window> pWindow;
3399  SwView* pView = m_pDocShell->GetView();
3400  if (pView)
3401  pWindow = &(pView->GetEditWin());
3402 
3403  LokChartHelper aChartHelper(pView);
3404  VclPtr<vcl::Window> pChartWindow = aChartHelper.GetWindow();
3405  if (pChartWindow)
3406  pWindow = pChartWindow;
3407 
3408  return pWindow;
3409 }
3410 
3411 void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
3412 {
3413  SolarMutexGuard aGuard;
3414 
3415  SwViewShell* pViewShell = m_pDocShell->GetWrtShell();
3416 
3417  SwView* pView = m_pDocShell->GetView();
3418  if (!pView)
3419  return;
3420 
3421  pView->SetViewLayout(1/*nColumns*/, false/*bBookMode*/, true);
3422 
3423  // Tiled rendering defaults.
3424  SwViewOption aViewOption(*pViewShell->GetViewOptions());
3425  aViewOption.SetHardBlank(false);
3426 
3427  // Disable field shadings: the result would depend on the cursor position.
3429 
3430  for (const beans::PropertyValue& rValue : rArguments)
3431  {
3432  if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has<bool>())
3433  aViewOption.SetHideWhitespaceMode(rValue.Value.get<bool>());
3434  else if (rValue.Name == ".uno:ShowBorderShadow" && rValue.Value.has<bool>())
3435  SwViewOption::SetAppearanceFlag(ViewOptFlags::Shadow , rValue.Value.get<bool>());
3436  else if (rValue.Name == ".uno:Author" && rValue.Value.has<OUString>())
3437  {
3438  // Store the author name in the view.
3439  pView->SetRedlineAuthor(rValue.Value.get<OUString>());
3440  // Let the actual author name pick up the value from the current
3441  // view, which would normally happen only during the next view
3442  // switch.
3443  m_pDocShell->SetView(pView);
3444  }
3445  else if (rValue.Name == ".uno:SpellOnline" && rValue.Value.has<bool>())
3446  aViewOption.SetOnlineSpell(rValue.Value.get<bool>());
3447  }
3448 
3449  // Set the initial zoom value to 1; usually it is set in setClientZoom and
3450  // SwViewShell::PaintTile; zoom value is used for chart in place
3451  // editing, see postMouseEvent and setGraphicSelection methods.
3452  aViewOption.SetZoom(1 * 100);
3453 
3454  aViewOption.SetPostIts(comphelper::LibreOfficeKit::isTiledAnnotations());
3455  pViewShell->ApplyViewOptions(aViewOption);
3456 
3457  // position the pages again after setting view options. Eg: if postit
3458  // rendering is false, then there would be no sidebar, so width of the
3459  // document needs to be adjusted
3460  pViewShell->GetLayout()->CheckViewLayout( pViewShell->GetViewOptions(), nullptr );
3461 
3462  // Disable map mode, so that it's possible to send mouse event coordinates
3463  // directly in twips.
3464  SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3465  rEditWin.EnableMapMode(false);
3466 
3467  // when the "This document may contain formatting or content that cannot
3468  // be saved..." dialog appears, it is auto-cancelled with tiled rendering,
3469  // causing 'Save' being disabled; so let's always save to the original
3470  // format
3471  auto xChanges = comphelper::ConfigurationChanges::create();
3472  officecfg::Office::Common::Save::Document::WarnAlienFormat::set(false, xChanges);
3473  xChanges->commit();
3474 
3475  // disable word auto-completion suggestions, the tooltips are not visible,
3476  // and the editeng-like auto-completion is annoying
3478 
3479  // don't change the whitespace at the beginning of paragraphs, this is
3480  // annoying when taking minutes without further formatting
3482 }
3483 
3484 void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
3485 {
3486  SolarMutexGuard aGuard;
3487  SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, nKeyCode);
3488 }
3489 
3490 void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
3491 {
3492  SolarMutexGuard aGuard;
3493 
3494  SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3495  if (!pWrtViewShell)
3496  {
3497  return;
3498  }
3499 
3500  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3501  double fScale = aOption.GetZoom() / o3tl::convert(100.0, o3tl::Length::px, o3tl::Length::twip);
3502 
3503  // check if the user hit a chart which is being edited by this view
3504  SfxViewShell* pViewShell = m_pDocShell->GetView();
3505  LokChartHelper aChartHelper(pViewShell);
3506  if (aChartHelper.postMouseEvent(nType, nX, nY,
3507  nCount, nButtons, nModifier,
3508  fScale, fScale))
3509  return;
3510 
3511  // check if the user hit a chart which is being edited by someone else
3512  // and, if so, skip current mouse event
3513  if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
3514  {
3515  if (LokChartHelper::HitAny(Point(nX, nY)))
3516  return;
3517  }
3518 
3519  SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3520  LokMouseEventData aMouseEventData(nType, Point(nX, nY), nCount,
3521  MouseEventModifiers::SIMPLECLICK,
3522  nButtons, nModifier);
3523  SfxLokHelper::postMouseEventAsync(&rEditWin, aMouseEventData);
3524 }
3525 
3526 void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
3527 {
3528  SolarMutexGuard aGuard;
3529 
3530  SfxViewShell* pViewShell = m_pDocShell->GetView();
3531  LokChartHelper aChartHelper(pViewShell);
3532  if (aChartHelper.setTextSelection(nType, nX, nY))
3533  return;
3534 
3535  SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3536  switch (nType)
3537  {
3538  case LOK_SETTEXTSELECTION_START:
3539  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/false, /*bClearMark=*/false);
3540  break;
3541  case LOK_SETTEXTSELECTION_END:
3542  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/false);
3543  break;
3544  case LOK_SETTEXTSELECTION_RESET:
3545  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/true);
3546  break;
3547  default:
3548  assert(false);
3549  break;
3550  }
3551 }
3552 
3553 uno::Reference<datatransfer::XTransferable> SwXTextDocument::getSelection()
3554 {
3555  SolarMutexGuard aGuard;
3556 
3557  uno::Reference<datatransfer::XTransferable> xTransferable;
3558 
3559  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3560  if (SdrView* pSdrView = pWrtShell ? pWrtShell->GetDrawView() : nullptr)
3561  {
3562  if (pSdrView->GetTextEditObject())
3563  {
3564  // Editing shape text
3565  EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
3566  xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3567  }
3568  }
3569 
3570  if (SwPostItMgr* pPostItMgr = m_pDocShell->GetView()->GetPostItMgr())
3571  {
3572  if (sw::annotation::SwAnnotationWin* pWin = pPostItMgr->GetActiveSidebarWin())
3573  {
3574  // Editing postit text.
3575  EditView& rEditView = pWin->GetOutlinerView()->GetEditView();
3576  xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3577  }
3578  }
3579 
3580  if (!xTransferable.is() && pWrtShell)
3581  xTransferable = new SwTransferable(*pWrtShell);
3582 
3583  return xTransferable;
3584 }
3585 
3586 void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
3587 {
3588  SolarMutexGuard aGuard;
3589 
3590  SwViewShell* pWrtViewShell = m_pDocShell->GetWrtShell();
3591  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3592  double fScale = aOption.GetZoom() / o3tl::convert(100.0, o3tl::Length::px, o3tl::Length::twip);
3593 
3594  SfxViewShell* pViewShell = m_pDocShell->GetView();
3595  LokChartHelper aChartHelper(pViewShell);
3596  if (aChartHelper.setGraphicSelection(nType, nX, nY, fScale, fScale))
3597  return;
3598 
3599  SwEditWin& rEditWin = m_pDocShell->GetView()->GetEditWin();
3600  switch (nType)
3601  {
3602  case LOK_SETGRAPHICSELECTION_START:
3603  rEditWin.SetGraphicTwipPosition(/*bStart=*/true, Point(nX, nY));
3604  break;
3605  case LOK_SETGRAPHICSELECTION_END:
3606  rEditWin.SetGraphicTwipPosition(/*bStart=*/false, Point(nX, nY));
3607  break;
3608  default:
3609  assert(false);
3610  break;
3611  }
3612 }
3613 
3615 {
3616  SolarMutexGuard aGuard;
3617 
3618  SwWrtShell* pWrtShell = m_pDocShell->GetWrtShell();
3619  pWrtShell->ResetSelect(nullptr, false);
3620 }
3621 
3622 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 )
3623 {
3625  aData.nSize = sizeof(SystemGraphicsData);
3626  #if defined(_WIN32)
3627  sal_Int64 nWindowHandle;
3628  Parent >>= nWindowHandle;
3629  aData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
3630  ScopedVclPtrInstance<VirtualDevice> xDevice(aData, Size(1, 1), DeviceFormat::DEFAULT);
3631  paintTile(*xDevice, nOutputWidth, nOutputHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3632  #else
3633  // TODO: support other platforms
3634  (void)Parent;
3635  (void)nOutputWidth;
3636  (void)nOutputHeight;
3637  (void)nTilePosX;
3638  (void)nTilePosY;
3639  (void)nTileWidth;
3640  (void)nTileHeight;
3641  #endif
3642 }
3643 
3647 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3648  ::sal_Int16 nScriptTypes,
3649  ::sal_Int16 nMaxCount )
3650 {
3651  SolarMutexGuard aGuard;
3652 
3653  // possible canonical values for nScriptTypes
3654  // any bit wise combination is allowed
3655  const sal_Int16 nLatin = 0x001;
3656  const sal_Int16 nAsian = 0x002;
3657  const sal_Int16 nComplex = 0x004;
3658 
3659  // script types for which to get the languages
3660  const bool bLatin = 0 != (nScriptTypes & nLatin);
3661  const bool bAsian = 0 != (nScriptTypes & nAsian);
3662  const bool bComplex = 0 != (nScriptTypes & nComplex);
3663 
3664  if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3665  throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
3666  if (!m_pDocShell)
3667  throw DisposedException();
3668  SwDoc* pDoc = m_pDocShell->GetDoc();
3669 
3670  // avoid duplicate values
3671  std::set< LanguageType > aAllLangs;
3672 
3673  //USER STYLES
3674 
3675  const SwCharFormats *pFormats = pDoc->GetCharFormats();
3676  for(size_t i = 0; i < pFormats->size(); ++i)
3677  {
3678  const SwAttrSet &rAttrSet = (*pFormats)[i]->GetAttrSet();
3680  if (bLatin)
3681  {
3682  nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3683  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3684  aAllLangs.insert( nLang );
3685  }
3686  if (bAsian)
3687  {
3688  nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3689  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3690  aAllLangs.insert( nLang );
3691  }
3692  if (bComplex)
3693  {
3694  nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3695  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3696  aAllLangs.insert( nLang );
3697  }
3698  }
3699 
3700  const SwTextFormatColls *pColls = pDoc->GetTextFormatColls();
3701  for (size_t i = 0; i < pColls->size(); ++i)
3702  {
3703  const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3705  if (bLatin)
3706  {
3707  nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3708  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3709  aAllLangs.insert( nLang );
3710  }
3711  if (bAsian)
3712  {
3713  nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3714  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3715  aAllLangs.insert( nLang );
3716  }
3717  if (bComplex)
3718  {
3719  nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3720  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3721  aAllLangs.insert( nLang );
3722  }
3723  }
3724 
3725  //AUTO STYLES
3726  const IStyleAccess::SwAutoStyleFamily aFam[2] =
3727  {
3730  };
3731  for (IStyleAccess::SwAutoStyleFamily i : aFam)
3732  {
3733  std::vector< std::shared_ptr<SfxItemSet> > rStyles;
3734  pDoc->GetIStyleAccess().getAllStyles(rStyles, i);
3735  while (!rStyles.empty())
3736  {
3737  std::shared_ptr<SfxItemSet> pStyle = rStyles.back();
3738  rStyles.pop_back();
3739  const SfxItemSet *pSet = pStyle.get();
3740 
3742  if (bLatin)
3743  {
3744  assert(pSet);
3745  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, false )).GetLanguage();
3746  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3747  aAllLangs.insert( nLang );
3748  }
3749  if (bAsian)
3750  {
3751  assert(pSet);
3752  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, false )).GetLanguage();
3753  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3754  aAllLangs.insert( nLang );
3755  }
3756  if (bComplex)
3757  {
3758  assert(pSet);
3759  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, false )).GetLanguage();
3760  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3761  aAllLangs.insert( nLang );
3762  }
3763  }
3764  }
3765 
3766  //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3767  SwWrtShell *pWrtSh = m_pDocShell->GetWrtShell();
3768  SdrView *pSdrView = pWrtSh->GetDrawView();
3769 
3770  if( pSdrView )
3771  {
3772  SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3773  if(pOutliner)
3774  {
3775  EditEngine& rEditEng = const_cast<EditEngine&>(pOutliner->GetEditEngine());
3776  sal_Int32 nParCount = pOutliner->GetParagraphCount();
3777  for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
3778  {
3779  //every paragraph
3780  std::vector<sal_Int32> aPortions;
3781  rEditEng.GetPortions( nPar, aPortions );
3782 
3783  for ( size_t nPos = aPortions.size(); nPos; )
3784  {
3785  //every position
3786  --nPos;
3787  sal_Int32 nEnd = aPortions[ nPos ];
3788  sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
3789  ESelection aSelection( nPar, nStart, nPar, nEnd );
3790  SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3791 
3793  if (bLatin)
3794  {
3795  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, false )).GetLanguage();
3796  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3797  aAllLangs.insert( nLang );
3798  }
3799  if (bAsian)
3800  {
3801  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, false )).GetLanguage();
3802  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3803  aAllLangs.insert( nLang );
3804  }
3805  if (bComplex)
3806  {
3807  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, false )).GetLanguage();
3808  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3809  aAllLangs.insert( nLang );
3810  }
3811  }
3812  }
3813  }
3814  }
3815  // less than nMaxCount languages
3816  if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3817  nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3818 
3819  // build return value
3820  uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3821  lang::Locale* pLanguage = aLanguages.getArray();
3822  if (nMaxCount > 0)
3823  {
3824  sal_Int32 nCount = 0;
3825  for (const auto& rLang : aAllLangs)
3826  {
3827  if (nCount >= nMaxCount)
3828  break;
3829  if (LANGUAGE_NONE != rLang)
3830  {
3831  pLanguage[nCount] = LanguageTag::convertToLocale( rLang );
3832  pLanguage[nCount].Language = SvtLanguageTable::GetLanguageString( rLang );
3833  nCount += 1;
3834  }
3835  }
3836  }
3837 
3838  return aLanguages;
3839 }
3840 
3842  m_pxDoc(&rxDoc)
3843 {
3844  m_sTables = SwResId(STR_CONTENT_TYPE_TABLE);
3845  m_sFrames = SwResId(STR_CONTENT_TYPE_FRAME);
3846  m_sGraphics = SwResId(STR_CONTENT_TYPE_GRAPHIC);
3847  m_sOLEs = SwResId(STR_CONTENT_TYPE_OLE);
3848  m_sSections = SwResId(STR_CONTENT_TYPE_REGION);
3849  m_sOutlines = SwResId(STR_CONTENT_TYPE_OUTLINE);
3850  m_sBookmarks = SwResId(STR_CONTENT_TYPE_BOOKMARK);
3851  m_sDrawingObjects = SwResId(STR_CONTENT_TYPE_DRAWOBJECT);
3852 }
3853 
3855 {
3856 }
3857 
3859 {
3860  Any aRet;
3861  if(!m_pxDoc)
3862  throw RuntimeException("No document available");
3863  OUString sSuffix("|");
3864  if(rName == m_sTables)
3865  {
3866  sSuffix += "table";
3867 
3869  m_pxDoc->getTextTables(), rName, sSuffix );
3870  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3871  }
3872  else if(rName == m_sFrames)
3873  {
3874  sSuffix += "frame";
3876  m_pxDoc->getTextFrames(), rName, sSuffix );
3877  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3878  }
3879  else if(rName == m_sSections)
3880  {
3881  sSuffix += "region";
3883  m_pxDoc->getTextSections(), rName, sSuffix );
3884  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3885  }
3886  else if(rName == m_sGraphics)
3887  {
3888  sSuffix += "graphic";
3890  m_pxDoc->getGraphicObjects(), rName, sSuffix );
3891  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3892  }
3893  else if(rName == m_sOLEs)
3894  {
3895  sSuffix += "ole";
3897  m_pxDoc->getEmbeddedObjects(), rName, sSuffix );
3898  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3899  }
3900  else if(rName == m_sOutlines)
3901  {
3902  sSuffix += "outline";
3904  *m_pxDoc, rName, sSuffix );
3905  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3906  }
3907  else if(rName == m_sBookmarks)
3908  {
3909  sSuffix.clear();
3911  m_pxDoc->getBookmarks(), rName, sSuffix );
3912  aRet <<= Reference< XPropertySet >(xBkms, UNO_QUERY);
3913  }
3914  else if(rName == m_sDrawingObjects)
3915  {
3916  sSuffix += "drawingobject";
3917  Reference<XNameAccess> xDrawingObjects = new SwXLinkNameAccessWrapper(
3918  *m_pxDoc, rName, sSuffix);
3919  aRet <<= Reference<XPropertySet>(xDrawingObjects, UNO_QUERY);
3920  }
3921  else
3922  throw NoSuchElementException();
3923  return aRet;
3924 }
3925 
3927 {
3928  return { m_sTables,
3929  m_sFrames,
3930  m_sGraphics,
3931  m_sOLEs,
3932  m_sSections,
3933  m_sOutlines,
3934  m_sBookmarks,
3936 }
3937 
3939 {
3940  if( rName == m_sTables ||
3941  rName == m_sFrames ||
3942  rName == m_sGraphics||
3943  rName == m_sOLEs ||
3944  rName == m_sSections ||
3945  rName == m_sOutlines ||
3946  rName == m_sBookmarks ||
3947  rName == m_sDrawingObjects )
3948  return true;
3949  return false;
3950 }
3951 
3953 {
3955 
3956 }
3957 
3959 {
3960  return nullptr != m_pxDoc;
3961 }
3962 
3964 {
3965  return "SwXLinkTargetSupplier";
3966 }
3967 
3969 {
3970  return cppu::supportsService(this, rServiceName);
3971 }
3972 
3974 {
3975  Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
3976  return aRet;
3977 }
3978 
3980  Reference< XNameAccess > const & xAccess, const OUString& rLinkDisplayName, const OUString& sSuffix ) :
3981  m_xRealAccess(xAccess),
3982  m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3983  m_sLinkSuffix(sSuffix),
3984  m_sLinkDisplayName(rLinkDisplayName),
3985  m_pxDoc(nullptr)
3986 {
3987 }
3988 
3990  const OUString& rLinkDisplayName, const OUString& sSuffix) :
3991  m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3992  m_sLinkSuffix(sSuffix),
3993  m_sLinkDisplayName(rLinkDisplayName),
3994  m_pxDoc(&rxDoc)
3995 {
3996 }
3997 
3999 {
4000 }
4001 
4003 {
4004  Any aRet;
4005  bool bFound = false;
4006  //cut link extension and call the real NameAccess
4007  OUString sParam = rName;
4008  OUString sSuffix(m_sLinkSuffix);
4009  if(sParam.getLength() > sSuffix.getLength() )
4010  {
4011  OUString sCmp = sParam.copy(sParam.getLength() - sSuffix.getLength(),
4012  sSuffix.getLength());
4013  if(sCmp == sSuffix)
4014  {
4015  if(m_pxDoc)
4016  {
4017  sParam = sParam.copy(0, sParam.getLength() - sSuffix.getLength());
4018  if(!m_pxDoc->GetDocShell())
4019  throw RuntimeException("No document shell available");
4020  SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4021 
4022  if (sSuffix == "|outline")
4023  {
4024  const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
4025 
4026  for (size_t i = 0; i < nOutlineCount && !bFound; ++i)
4027  {
4028  if(sParam == lcl_CreateOutlineString(i, pDoc))
4029  {
4030  OUString sOutlineText =
4032  i, pDoc->GetDocShell()->GetWrtShell()->GetLayout());
4033  sal_Int32 nOutlineLevel = pDoc->getIDocumentOutlineNodes().getOutlineLevel(i);
4034  Reference<XPropertySet> xOutline =
4035  new SwXOutlineTarget(sParam, sOutlineText, nOutlineLevel);
4036  aRet <<= xOutline;
4037  bFound = true;
4038  }
4039  }
4040  }
4041  else if (sSuffix == "|drawingobject")
4042  {
4044  if (pModel)
4045  {
4046  SdrPage* pPage = pModel->GetPage(0);
4047  for (size_t i = 0; i < pPage->GetObjCount() && !bFound; ++i)
4048  {
4049  SdrObject* pObj = pPage->GetObj(i);
4050  if (sParam == pObj->GetName())
4051  {
4052  Reference<XPropertySet> xDrawingObject = new SwXDrawingObjectTarget(sParam);
4053  aRet <<= xDrawingObject;
4054  bFound = true;
4055  }
4056  }
4057  }
4058  }
4059  }
4060  else
4061  {
4062  aRet = m_xRealAccess->getByName(sParam.copy(0, sParam.getLength() - sSuffix.getLength()));
4063  Reference< XInterface > xInt;
4064  if(!(aRet >>= xInt))
4065  throw RuntimeException("Could not retrieve property");
4066  Reference< XPropertySet > xProp(xInt, UNO_QUERY);
4067  aRet <<= xProp;
4068  bFound = true;
4069  }
4070  }
4071  }
4072  if(!bFound)
4073  throw NoSuchElementException();
4074  return aRet;
4075 }
4076 
4078 {
4079  Sequence< OUString > aRet;
4080  if(m_pxDoc)
4081  {
4082  if(!m_pxDoc->GetDocShell())
4083  throw RuntimeException("No document shell available");
4084  SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4085  if (m_sLinkSuffix == "|outline")
4086  {
4087  const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
4088  const size_t nOutlineCount = rOutlineNodes.size();
4089  aRet.realloc(nOutlineCount);
4090  OUString* pResArr = aRet.getArray();
4091  for (size_t i = 0; i < nOutlineCount; ++i)
4092  {
4093  OUString sEntry = lcl_CreateOutlineString(i, pDoc) + "|outline";
4094  pResArr[i] = sEntry;
4095  }
4096  }
4097  else if (m_sLinkSuffix == "|drawingobject")
4098  {
4100  if(pModel)
4101  {
4102  SdrPage* pPage = pModel->GetPage(0);
4103  const size_t nObjCount = pPage->GetObjCount();
4104  aRet.realloc(nObjCount);
4105  OUString* pResArr = aRet.getArray();
4106  auto j = 0;
4107  for (size_t i = 0; i < nObjCount; ++i)
4108  {
4109  SdrObject* pObj = pPage->GetObj(i);
4110  if (!pObj->GetName().isEmpty())
4111  pResArr[j++] = pObj->GetName() + "|drawingobject";
4112  }
4113  }
4114  }
4115  }
4116  else
4117  {
4118  const Sequence< OUString > aOrg = m_xRealAccess->getElementNames();
4119  aRet.realloc(aOrg.getLength());
4120  std::transform(aOrg.begin(), aOrg.end(), aRet.getArray(),
4121  [this](const OUString& rOrg) -> OUString { return rOrg + m_sLinkSuffix; });
4122  }
4123  return aRet;
4124 }
4125 
4127 {
4128  bool bRet = false;
4129  OUString sParam(rName);
4130  if(sParam.getLength() > m_sLinkSuffix.getLength() )
4131  {
4132  OUString sCmp = sParam.copy(sParam.getLength() - m_sLinkSuffix.getLength(),
4133  m_sLinkSuffix.getLength());
4134  if(sCmp == m_sLinkSuffix)
4135  {
4136  sParam = sParam.copy(0, sParam.getLength() - m_sLinkSuffix.getLength());
4137  if(m_pxDoc)
4138  {
4139  if(!m_pxDoc->GetDocShell())
4140  throw RuntimeException("No document shell available");
4141  SwDoc* pDoc = m_pxDoc->GetDocShell()->GetDoc();
4142  if (m_sLinkSuffix == "|outline")
4143  {
4144  const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
4145 
4146  for (size_t i = 0; i < nOutlineCount && !bRet; ++i)
4147  {
4148  if(sParam == lcl_CreateOutlineString(i, pDoc))
4149  {
4150  bRet = true;
4151  }
4152  }
4153  }
4154  else if (m_sLinkSuffix == "|drawingobject")
4155  {
4157  if (pModel)
4158  {
4159  SdrPage* pPage = pModel->GetPage(0);
4160  const size_t nObjCount = pPage->GetObjCount();
4161  for (size_t i = 0; i < nObjCount && !bRet; ++i)
4162  {
4163  if (sParam == pPage->GetObj(i)->GetName())
4164  bRet = true;
4165  }
4166  }
4167  }
4168  }
4169  else
4170  {
4171  bRet = m_xRealAccess->hasByName(sParam);
4172  }
4173  }
4174  }
4175  return bRet;
4176 }
4177 
4179 {
4181 }
4182 
4184 {
4185  bool bRet = false;
4186  if(m_pxDoc)
4187  {
4188  OSL_FAIL("not implemented");
4189  }
4190  else
4191  {
4192  bRet = m_xRealAccess->hasElements();
4193  }
4194  return bRet;
4195 }
4196 
4197 Reference< XPropertySetInfo > SwXLinkNameAccessWrapper::getPropertySetInfo()
4198 {
4199  static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4200  return xRet;
4201 }
4202 
4204  const OUString& rPropName, const Any& )
4205 {
4206  throw UnknownPropertyException(rPropName);
4207 }
4208 
4209 static Any lcl_GetDisplayBitmap(const OUString& _sLinkSuffix)
4210 {
4211  Any aRet;
4212  OUString sLinkSuffix = _sLinkSuffix;
4213  if(!sLinkSuffix.isEmpty())
4214  sLinkSuffix = sLinkSuffix.copy(1);
4215  OUString sImgId;
4216 
4217  if(sLinkSuffix == "outline")
4218  sImgId = RID_BMP_NAVI_OUTLINE;
4219  else if(sLinkSuffix == "table")
4220  sImgId = RID_BMP_NAVI_TABLE;
4221  else if(sLinkSuffix == "frame")
4222  sImgId = RID_BMP_NAVI_FRAME;
4223  else if(sLinkSuffix == "graphic")
4224  sImgId = RID_BMP_NAVI_GRAPHIC;
4225  else if(sLinkSuffix == "ole")
4226  sImgId = RID_BMP_NAVI_OLE;
4227  else if(sLinkSuffix.isEmpty())
4228  sImgId = RID_BMP_NAVI_BOOKMARK;
4229  else if(sLinkSuffix == "region")
4230  sImgId = RID_BMP_NAVI_REGION;
4231  else if(sLinkSuffix == "drawingobject")
4232  sImgId = RID_BMP_NAVI_DRAWOBJECT;
4233 
4234  if (!sImgId.isEmpty())
4235  {
4236  aRet <<= VCLUnoHelper::CreateBitmap(BitmapEx(sImgId));
4237  }
4238  return aRet;
4239 }
4240 
4241 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
4242 {
4243  Any aRet;
4244  if( rPropertyName == UNO_LINK_DISPLAY_NAME )
4245  {
4246  aRet <<= m_sLinkDisplayName;
4247  }
4248  else if( rPropertyName == UNO_LINK_DISPLAY_BITMAP )
4249  {
4251  }
4252  else
4253  throw UnknownPropertyException(rPropertyName);
4254  return aRet;
4255 }
4256 
4258  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4259 {}
4260 
4262  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4263 {}
4264 
4266  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4267 {}
4268 
4270  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4271 {}
4272 
4274 {
4275  return this;
4276 }
4277 
4279 {
4280  return "SwXLinkNameAccessWrapper";
4281 }
4282 
4284 {
4285  return cppu::supportsService(this, rServiceName);
4286 }
4287 
4289 {
4290  Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
4291  return aRet;
4292 }
4293 
4294 SwXOutlineTarget::SwXOutlineTarget(const OUString& rOutlineText, const OUString& rActualText,
4295  const sal_Int32 nOutlineLevel) :
4296  m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4297  m_sOutlineText(rOutlineText),
4298  m_sActualText(rActualText),
4299  m_nOutlineLevel(nOutlineLevel)
4300 {
4301 }
4302 
4304 {
4305 }
4306 
4307 Reference< XPropertySetInfo > SwXOutlineTarget::getPropertySetInfo()
4308 {
4309  static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4310  return xRet;
4311 }
4312 
4314  const OUString& rPropertyName, const Any& /*aValue*/)
4315 {
4316  throw UnknownPropertyException(rPropertyName);
4317 }
4318 
4319 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
4320 {
4321  if (rPropertyName != UNO_LINK_DISPLAY_NAME && rPropertyName != "ActualOutlineName" &&
4322  rPropertyName != "OutlineLevel")
4323  throw UnknownPropertyException(rPropertyName);
4324 
4325  if (rPropertyName == "ActualOutlineName")
4326  return Any(m_sActualText);
4327 
4328  if (rPropertyName == "OutlineLevel")
4329  return Any(m_nOutlineLevel);
4330 
4331  return Any(m_sOutlineText);
4332 }
4333 
4335  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4336 {
4337 }
4338 
4340  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4341 {
4342 }
4343 
4345  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4346 {
4347 }
4348 
4350  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4351 {
4352 }
4353 
4355 {
4356  return "SwXOutlineTarget";
4357 }
4358 
4359 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName)
4360 {
4361  return cppu::supportsService(this, ServiceName);
4362 }
4363 
4365 {
4366  Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4367 
4368  return aRet;
4369 }
4370 
4371 SwXDrawingObjectTarget::SwXDrawingObjectTarget(const OUString& rDrawingObjectText) :
4372  m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4373  m_sDrawingObjectText(rDrawingObjectText)
4374 {
4375 }
4376 
4378 {
4379 }
4380 
4381 Reference< XPropertySetInfo > SwXDrawingObjectTarget::getPropertySetInfo()
4382 {
4383  static Reference< XPropertySetInfo > xRet = m_pPropSet->getPropertySetInfo();
4384  return xRet;
4385 }
4386 
4388  const OUString& rPropertyName, const Any& /*aValue*/)
4389 {
4390  throw UnknownPropertyException(rPropertyName);
4391 }
4392 
4393 Any SwXDrawingObjectTarget::getPropertyValue(const OUString& rPropertyName)
4394 {
4395  if(rPropertyName != UNO_LINK_DISPLAY_NAME)
4396  throw UnknownPropertyException(rPropertyName);
4397 
4398  return Any(m_sDrawingObjectText);
4399 }
4400 
4402  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4403 {
4404 }
4405 
4407  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4408 {
4409 }
4410 
4412  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4413 {
4414 }
4415 
4417  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4418 {
4419 }
4420 
4422 {
4423  return "SwXDrawingObjectTarget";
4424 }
4425 
4427 {
4428  return cppu::supportsService(this, ServiceName);
4429 }
4430 
4432 {
4433  Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4434 
4435  return aRet;
4436 }
4437 
4439 SvxUnoForbiddenCharsTable ( rDoc.getIDocumentSettingAccess().getForbiddenCharacterTable() )
4440 ,m_pDoc(&rDoc)
4441 {
4442 }
4443 
4445 {
4446 }
4447 
4449 {
4450  Reference<XInterface> xRet;
4451  if(m_pDoc)
4452  {
4453  switch(nWhich)
4454  {
4455  // #i52858#
4456  // assure that Draw model is created, if it doesn't exist.
4458  if(!m_xDashTable.is())
4460  xRet = m_xDashTable;
4461  break;
4463  if(!m_xGradientTable.is())
4465  xRet = m_xGradientTable;
4466  break;
4468  if(!m_xHatchTable.is())
4470  xRet = m_xHatchTable;
4471  break;
4473  if(!m_xBitmapTable.is())
4475  xRet = m_xBitmapTable;
4476  break;
4478  if(!m_xTransGradientTable.is())
4480  xRet = m_xTransGradientTable;
4481  break;
4483  if(!m_xMarkerTable.is())
4485  xRet = m_xMarkerTable;
4486  break;
4488  if(!m_xDrawDefaults.is())
4489  m_xDrawDefaults = static_cast<cppu::OWeakObject*>(new SwSvxUnoDrawPool(*m_pDoc));
4490  xRet = m_xDrawDefaults;
4491  break;
4492 #if OSL_DEBUG_LEVEL > 0
4493  default: OSL_FAIL("which table?");
4494 #endif
4495  }
4496  }
4497  return xRet;
4498 }
4499 
4501 {
4502  m_xDashTable = nullptr;
4503  m_xGradientTable = nullptr;
4504  m_xHatchTable = nullptr;
4505  m_xBitmapTable = nullptr;
4506  m_xTransGradientTable = nullptr;
4507  m_xMarkerTable = nullptr;
4508  m_xDrawDefaults = nullptr;
4509  m_pDoc = nullptr;
4511 }
4512 
4514 {
4515  if(m_pDoc)
4517 }
4518 
4520  SwViewShell& rSh, const SwViewOption &rViewOptions)
4521  : m_pShell(&rSh)
4522  , m_aOldViewOptions( rViewOptions )
4523 {
4524 }
4525 
4527 {
4528  if (m_pShell)
4529  {
4531  }
4532 }
4533 
4534 void
4535 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
4536 {
4537  // to avoid unnecessary reformatting the view options related to the content
4538  // below should only change if necessary, that is if respective content is present
4539  const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars();
4541  const bool bContainsHiddenFields = pFieldType && pFieldType->HasWriterListeners();
4543  const bool bContainsHiddenParagraphs = pFieldType && pFieldType->HasWriterListeners();
4545  const bool bContainsPlaceHolders = pFieldType && pFieldType->HasWriterListeners();
4546  const bool bContainsFields = m_pShell->IsAnyFieldInDoc();
4547 
4548  SwViewOption aRenderViewOptions( m_aOldViewOptions );
4549 
4550  // disable anything in the view that should not be printed (or exported to PDF) by default
4551  // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4552  // in section "Display of ...")
4553  aRenderViewOptions.SetParagraph( false ); // paragraph end
4554  aRenderViewOptions.SetSoftHyph( false ); // aka custom hyphens
4555  aRenderViewOptions.SetBlank( false ); // spaces
4556  aRenderViewOptions.SetHardBlank( false ); // non-breaking spaces
4557  aRenderViewOptions.SetTab( false ); // tabs
4558  aRenderViewOptions.SetShowBookmarks( false ); // bookmarks
4559  aRenderViewOptions.SetLineBreak( false ); // breaks (type 1)
4560  aRenderViewOptions.SetPageBreak( false ); // breaks (type 2)
4561  aRenderViewOptions.SetColumnBreak( false ); // breaks (type 3)
4562  bool bVal = pPrtOptions && pPrtOptions->m_bPrintHiddenText;
4563  if (bContainsHiddenChars)
4564  aRenderViewOptions.SetShowHiddenChar( bVal ); // hidden text
4565  if (bContainsHiddenFields)
4566  aRenderViewOptions.SetShowHiddenField( bVal );
4567  if (bContainsHiddenParagraphs)
4568  aRenderViewOptions.SetShowHiddenPara( bVal );
4569 
4570  if (bContainsPlaceHolders)
4571  {
4572  // should always be printed in PDF export!
4573  bVal = !pPrtOptions ? setShowPlaceHoldersInPDF : pPrtOptions->m_bPrintTextPlaceholder;
4574  aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4575  }
4576 
4577  if (bContainsFields)
4578  aRenderViewOptions.SetFieldName( false );
4579 
4580  // we need to set this flag in order to get to see the visible effect of
4581  // some of the above settings (needed for correct rendering)
4582  aRenderViewOptions.SetViewMetaChars( true );
4583 
4584  if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary
4585  {
4586  aRenderViewOptions.SetPrinting( pPrtOptions != nullptr );
4587  m_pShell->ApplyViewOptions( aRenderViewOptions );
4588  }
4589 }
4590 
4591 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual VclPtr< vcl::Window > getDocWindow() override
Definition: unotxdoc.cxx:3395
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:4002
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:242
void SetLineBreak(bool b)
Definition: viewopt.hxx:262
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:655
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:4303
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unotxdoc.cxx:4319
bool hasValue()
const SwStartNode * FindHeaderStartNode() const
Definition: node.hxx:204
bool IsPaperFromSetup() const
Definition: printdata.hxx:191
const sal_Int32 m_nOutlineLevel
Definition: unotxdoc.hxx:563
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
static SvxAutoCorrCfg & Get()
virtual void ApplyViewOptions(const SwViewOption &rOpt)
Definition: viewsh.cxx:2208
Marks a position in the document model.
Definition: pam.hxx:36
std::map< OUString, OUString > StringMap
static bool HasValidData(const css::uno::Reference< css::datatransfer::XTransferable > &rTransferable)
const OUString & GetTOIAutoMarkURL() const
Definition: doc.hxx:951
void SetSoftHyph(bool b)
Definition: viewopt.hxx:273
virtual OUString SAL_CALL getImplementationName() override
Definition: unotxdoc.cxx:3963
static bool HitAny(const Point &aPos)
OUString m_sDrawingObjectText
Definition: unotxdoc.hxx:592
bool HasReplaceAttributes() const
Definition: unosrch.cxx:523
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:3938
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:4269
constexpr auto toTwips(N number, Length from)
#define WID_DOC_WORD_COUNT
Definition: unomap.hxx:230
void SetZoom(sal_uInt16 n)
Definition: viewopt.hxx:519
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:1297
const SwStartNode * FindFooterStartNode() const
Definition: node.hxx:206
virtual sal_Bool SAL_CALL attachResource(const OUString &aURL, const css::uno::Sequence< css::beans::PropertyValue > &aArgs) override
Definition: unotxdoc.cxx:514
virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getFootnotes() override
Definition: unotxdoc.cxx:608
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:3998
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getLinks() override
Definition: unotxdoc.cxx:4273
virtual void CalcLayout()
Definition: viewsh.cxx:1078
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:751
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:621
bool HasSearchAttributes() const
Definition: unosrch.cxx:518
virtual OUString getOutlineText(const tSortedOutlineNodeList::size_type nIdx, SwRootFrame const *pLayout, const bool bWithNumber=true, const bool bWithSpacesForLevel=false, const bool bWithFootnote=true) const =0
virtual void initializeForTiledRendering(const css::uno::Sequence< css::beans::PropertyValue > &rArguments) override
Definition: unotxdoc.cxx:3411
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:38
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:4421
#define WID_DOC_CHAR_COUNT
Definition: unomap.hxx:228
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:4381
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:2863
static bool lcl_GetBoolProperty(const uno::Sequence< beans::PropertyValue > &rOptions, const char *pPropName)
Definition: unotxdoc.cxx:2279
std::unique_ptr< sal_Int32[]> pData
View of a document.
Definition: pview.hxx:161
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
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:3614
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: unotxdoc.cxx:441
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:1373
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:561
::comphelper::OInterfaceContainerHelper4< css::util::XRefreshListener > m_RefreshListeners
Definition: unotxdoc.cxx:264
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_LANGUAGE(10)
long Long
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const SwPosition * GetMark() const
Definition: pam.hxx:210
ScopedJsonWriterArray startArray(const char *)
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unotxdoc.cxx:3926
virtual void SAL_CALL connectController(const css::uno::Reference< css::frame::XController > &xController) override
void LogicInvalidate(const tools::Rectangle *pRectangle) override
Definition: edtwin.cxx:6531
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:2824
void FillSearchOptions(i18nutil::SearchOptions2 &rSearchOpt) const
Definition: unosrch.cxx:543
css::uno::Reference< css::uno::XInterface > create(OUString const &rServiceName, css::uno::Sequence< css::uno::Any > const *arguments)
Definition: unotxdoc.cxx:1566
Find "all" in Footer/Header/Fly...
SwXDrawingObjectTarget(const OUString &rDrawingObjectText)
Definition: unotxdoc.cxx:4371
virtual void setGraphicSelection(int nType, int nX, int nY) override
Definition: unotxdoc.cxx:3586
const SvxLanguageItem & GetLanguage(bool=true) const
Definition: charatr.hxx:91
constexpr Point convert(const Point &rPoint, o3tl::Length eFrom, o3tl::Length eTo)
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unotxdoc.cxx:3858
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:714
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:3958
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:596
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:402
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unotxdoc.cxx:2117
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:2111
void AdjustViewOptions(SwPrintData const *const pPrtOptions, bool setShowPlaceHoldersInPDF)
Definition: unotxdoc.cxx:4535
::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:1064
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:4344
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: unotxdoc.cxx:2163
OUString m_sOutlineText
Definition: unotxdoc.hxx:561
std::shared_ptr< SvxForbiddenCharactersTable > mxForbiddenChars
void Pos(const Point &rNew)
Definition: swrect.hxx:171
#define WID_DOC_REDLINE_DISPLAY
Definition: unomap.hxx:236
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:1251
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
virtual OUString SAL_CALL getImplementationName() override
Definition: unotxdoc.cxx:4354
comphelper::OInterfaceContainerHelper3< css::text::XPasteListener > & GetPasteListeners()
Definition: fecopy.cxx:1207