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