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