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