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> xComp( 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  pDoc->SetInReading( bBool );
1966  }
1967  break;
1968  case WID_DOC_BUILDID:
1969  aValue >>= maBuildId;
1970  break;
1971 
1973  {
1974  bool bDefaultPageMode( false );
1975  aValue >>= bDefaultPageMode;
1976  pDocShell->GetDoc()->SetDefaultPageMode( bDefaultPageMode );
1977  }
1978  break;
1980  setGrabBagItem(aValue);
1981  break;
1982 
1983  default:
1984  {
1985  const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
1986  std::unique_ptr<SfxPoolItem> pNewItem(rItem.Clone());
1987  pNewItem->PutValue(aValue, pEntry->nMemberId);
1988  pDocShell->GetDoc()->SetDefault(*pNewItem);
1989  }
1990  }
1991 }
1992 
1993 Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
1994 {
1995  SolarMutexGuard aGuard;
1996  if(!IsValid())
1997  throw DisposedException("", static_cast< XTextDocument* >(this));
1998 
1999  const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2000 
2001  if(!pEntry)
2002  throw UnknownPropertyException(rPropertyName);
2003  Any aAny;
2004  switch(pEntry->nWID)
2005  {
2006  case WID_DOC_ISTEMPLATEID :
2007  aAny <<= pDocShell->IsTemplate();
2008  break;
2009  case WID_DOC_CHAR_COUNT :
2010  case WID_DOC_PARA_COUNT :
2011  case WID_DOC_WORD_COUNT :
2012  {
2013  const SwDocStat& rStat(pDocShell->GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( false, true ));
2014  sal_Int32 nValue;
2015  switch(pEntry->nWID)
2016  {
2017  case WID_DOC_CHAR_COUNT :nValue = rStat.nChar;break;
2018  case WID_DOC_PARA_COUNT :nValue = rStat.nPara;break;
2019  case WID_DOC_WORD_COUNT :nValue = rStat.nWord;break;
2020  }
2021  aAny <<= nValue;
2022  }
2023  break;
2024  case WID_DOC_WORD_SEPARATOR :
2025  {
2026  aAny <<= SW_MOD()->GetDocStatWordDelim();
2027  }
2028  break;
2030  case WID_DOC_CHANGES_SHOW:
2031  {
2033  bool bSet = false;
2034  if(WID_DOC_CHANGES_SHOW == pEntry->nWID)
2035  {
2037  }
2038  else if(WID_DOC_CHANGES_RECORD == pEntry->nWID)
2039  {
2040  bSet = bool(eMode & RedlineFlags::On);
2041  }
2042  aAny <<= bSet;
2043  }
2044  break;
2046  {
2047  SwDoc* pDoc = pDocShell->GetDoc();
2048  aAny <<= pDoc->getIDocumentRedlineAccess().GetRedlinePassword();
2049  }
2050  break;
2051  case WID_DOC_AUTO_MARK_URL :
2052  aAny <<= pDocShell->GetDoc()->GetTOIAutoMarkURL();
2053  break;
2054  case WID_DOC_HIDE_TIPS :
2055  aAny <<= SW_MOD()->GetModuleConfig()->IsHideFieldTips();
2056  break;
2058  {
2060  eRedMode = eRedMode & RedlineFlags::ShowMask;
2061  sal_Int16 nRet = RedlineDisplayType::NONE;
2062  if(RedlineFlags::ShowInsert == eRedMode)
2064  else if(RedlineFlags::ShowDelete == eRedMode)
2065  nRet = RedlineDisplayType::REMOVED;
2066  else if(RedlineFlags::ShowMask == eRedMode)
2067  nRet = RedlineDisplayType::INSERTED_AND_REMOVED;
2068  aAny <<= nRet;
2069  }
2070  break;
2072  {
2074  Reference<XForbiddenCharacters> xRet(static_cast<cppu::OWeakObject*>(mxPropertyHelper.get()), UNO_QUERY);
2075  aAny <<= xRet;
2076  }
2077  break;
2079  {
2080  aAny <<= static_cast < sal_Int16 > (pDocShell->GetDoc()->GetNumberFormatter ()->GetYear2000());
2081  }
2082  break;
2084  {
2085  SwDrawModel * pDrawDoc;
2086  bool bAuto;
2087  if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
2088  bAuto = pDrawDoc->GetAutoControlFocus();
2089  else
2090  bAuto = false;
2091  aAny <<= bAuto;
2092  }
2093  break;
2095  {
2096  SwDrawModel * pDrawDoc;
2097  bool bMode;
2098  if ( nullptr != ( pDrawDoc = pDocShell->GetDoc()->getIDocumentDrawModelAccess().GetDrawModel() ) )
2099  bMode = pDrawDoc->GetOpenInDesignMode();
2100  else
2101  bMode = true;
2102  aAny <<= bMode;
2103  }
2104  break;
2106  aAny <<= pDocShell->GetBasicContainer();
2107  break;
2109  aAny <<= pDocShell->GetDialogContainer();
2110  break;
2111  case WID_DOC_VBA_DOCOBJ:
2112  {
2113  /* #i111553# This property provides the name of the constant that
2114  will be used to store this model in the global Basic manager.
2115  That constant will be equivalent to 'ThisComponent' but for
2116  each application, so e.g. a 'ThisExcelDoc' and a 'ThisWordDoc'
2117  constant can co-exist, as required by VBA. */
2118  aAny <<= OUString( "ThisWordDoc" );
2119  }
2120  break;
2121  case WID_DOC_RUNTIME_UID:
2122  aAny <<= getRuntimeUID();
2123  break;
2124  case WID_DOC_LOCK_UPDATES :
2125  aAny <<= pDocShell->GetDoc()->IsInReading();
2126  break;
2127  case WID_DOC_BUILDID:
2128  aAny <<= maBuildId;
2129  break;
2131  aAny <<= hasValidSignatures();
2132  break;
2134  getGrabBagItem(aAny);
2135  break;
2136 
2137  default:
2138  {
2139  const SfxPoolItem& rItem = pDocShell->GetDoc()->GetDefault(pEntry->nWID);
2140  rItem.QueryValue(aAny, pEntry->nMemberId);
2141  }
2142  }
2143  return aAny;
2144 }
2145 
2146 void SwXTextDocument::addPropertyChangeListener(const OUString& /*PropertyName*/,
2147  const Reference< XPropertyChangeListener > & /*aListener*/)
2148 {
2149  OSL_FAIL("not implemented");
2150 }
2151 
2152 void SwXTextDocument::removePropertyChangeListener(const OUString& /*PropertyName*/,
2153  const Reference< XPropertyChangeListener > & /*aListener*/)
2154 {
2155  OSL_FAIL("not implemented");
2156 }
2157 
2158 void SwXTextDocument::addVetoableChangeListener(const OUString& /*PropertyName*/,
2159  const Reference< XVetoableChangeListener > & /*aListener*/)
2160 {
2161  OSL_FAIL("not implemented");
2162 }
2163 
2164 void SwXTextDocument::removeVetoableChangeListener(const OUString& /*PropertyName*/,
2165  const Reference< XVetoableChangeListener > & /*aListener*/)
2166 {
2167  OSL_FAIL("not implemented");
2168 }
2169 
2170 Reference< XNameAccess > SwXTextDocument::getLinks()
2171 {
2172  if(!mxLinkTargetSupplier.is())
2173  {
2175  }
2176  return mxLinkTargetSupplier;
2177 }
2178 
2179 Reference< XEnumerationAccess > SwXTextDocument::getRedlines( )
2180 {
2181  if(!mxXRedlines.is())
2182  {
2184  }
2185  return mxXRedlines;
2186 }
2187 
2189 {
2190  // why does SwBaseShell not just call refresh? maybe because it's rSh is
2191  // (sometimes) a different shell than GetWrtShell()?
2192  lang::EventObject const ev(static_cast<SwXTextDocumentBaseClass &>(*this));
2193  m_pImpl->m_RefreshListeners.notifyEach(
2194  & util::XRefreshListener::refreshed, ev);
2195 }
2196 
2198 {
2199  SolarMutexGuard aGuard;
2200  if(!IsValid())
2201  throw DisposedException("", static_cast< XTextDocument* >(this));
2202 
2203  SwViewShell *pViewShell = pDocShell->GetWrtShell();
2205  if(pViewShell)
2206  pViewShell->CalcLayout();
2207 }
2208 
2210  const Reference<util::XRefreshListener> & xListener)
2211 {
2212  // no need to lock here as m_pImpl is const and container threadsafe
2213  m_pImpl->m_RefreshListeners.addInterface(xListener);
2214 }
2215 
2217  const Reference<util::XRefreshListener> & xListener)
2218 {
2219  // no need to lock here as m_pImpl is const and container threadsafe
2220  m_pImpl->m_RefreshListeners.removeInterface(xListener);
2221 }
2222 
2224 {
2225  SolarMutexGuard aGuard;
2226  if(!IsValid())
2227  throw DisposedException("", static_cast< XTextDocument* >(this));
2228 
2229  SwDoc* pDoc = pDocShell->GetDoc();
2231  if( !rLnkMan.GetLinks().empty() )
2232  {
2233  UnoActionContext aAction(pDoc);
2234  rLnkMan.UpdateAllLinks( false, true, nullptr );
2235  }
2236 }
2237 
2238 //XPropertyState
2239 PropertyState SAL_CALL SwXTextDocument::getPropertyState( const OUString& rPropertyName )
2240 {
2241  SolarMutexGuard aGuard;
2242  if(!IsValid())
2243  throw DisposedException("", static_cast< XTextDocument* >(this));
2244 
2245  const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2246  if(!pEntry)
2247  throw UnknownPropertyException(rPropertyName);
2248  return PropertyState_DIRECT_VALUE;
2249 }
2250 
2251 Sequence< PropertyState > SAL_CALL SwXTextDocument::getPropertyStates( const Sequence< OUString >& rPropertyNames )
2252 {
2253  const sal_Int32 nCount = rPropertyNames.getLength();
2254  Sequence < PropertyState > aRet ( nCount );
2255 
2256  std::transform(rPropertyNames.begin(), rPropertyNames.end(), aRet.begin(),
2257  [this](const OUString& rName) -> PropertyState { return getPropertyState(rName); });
2258 
2259  return aRet;
2260 }
2261 
2262 void SAL_CALL SwXTextDocument::setPropertyToDefault( const OUString& rPropertyName )
2263 {
2264  SolarMutexGuard aGuard;
2265  if(!IsValid())
2266  throw DisposedException("", static_cast< XTextDocument* >(this));
2267 
2268  const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2269  if(!pEntry)
2270  throw UnknownPropertyException(rPropertyName);
2271  switch(pEntry->nWID)
2272  {
2273  case 0:default:break;
2274  }
2275 }
2276 
2277 Any SAL_CALL SwXTextDocument::getPropertyDefault( const OUString& rPropertyName )
2278 {
2279  SolarMutexGuard aGuard;
2280  if(!IsValid())
2281  throw DisposedException("", static_cast< XTextDocument* >(this));
2282 
2283  const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap().getByName( rPropertyName);
2284  if(!pEntry)
2285  throw UnknownPropertyException(rPropertyName);
2286  Any aAny;
2287  switch(pEntry->nWID)
2288  {
2289  case 0:default:break;
2290  }
2291  return aAny;
2292 }
2293 
2295 {
2297 
2298  uno::Any aAny( rPrintUIOptions.getValue( "RenderDevice" ));
2299  uno::Reference< awt::XDevice > xRenderDevice;
2300  aAny >>= xRenderDevice;
2301  if (xRenderDevice.is())
2302  {
2303  VCLXDevice* pDevice = comphelper::getUnoTunnelImplementation<VCLXDevice>( xRenderDevice );
2304  pOut = pDevice ? pDevice->GetOutputDevice() : VclPtr< OutputDevice >();
2305  }
2306 
2307  return pOut;
2308 }
2309 
2311  const uno::Sequence< beans::PropertyValue >& rOptions,
2312  const char *pPropName )
2313 {
2314  return std::any_of(rOptions.begin(), rOptions.end(),
2315  [&pPropName](const beans::PropertyValue& rProp) {
2316  return rProp.Name.equalsAscii( pPropName ); });
2317 }
2318 
2320  const uno::Sequence< beans::PropertyValue >& rOptions,
2321  const char *pPropName )
2322 {
2323  bool bRes = false;
2324  auto pOption = std::find_if(rOptions.begin(), rOptions.end(),
2325  [&pPropName](const beans::PropertyValue& rProp) {
2326  return rProp.Name.equalsAscii( pPropName ); });
2327  if (pOption != rOptions.end())
2328  pOption->Value >>= bRes;
2329  return bRes;
2330 }
2331 
2333  bool &rbIsSwSrcView,
2334  const uno::Sequence< beans::PropertyValue >& rOptions,
2335  bool bIsPDFExport )
2336 {
2337  // get view shell to use
2338  SfxViewShell *pView = nullptr;
2339  if (bIsPDFExport)
2340  pView = GuessViewShell( rbIsSwSrcView );
2341  else
2342  {
2343  uno::Any aTmp;
2344  auto pOption = std::find_if(rOptions.begin(), rOptions.end(),
2345  [](const beans::PropertyValue& rProp) { return rProp.Name == "View"; });
2346  if (pOption != rOptions.end())
2347  aTmp = pOption->Value;
2348 
2349  uno::Reference< frame::XController > xController;
2350  if (aTmp >>= xController)
2351  {
2352  OSL_ENSURE( xController.is(), "controller is empty!" );
2353  pView = GuessViewShell( rbIsSwSrcView, xController );
2354  }
2355  }
2356  return pView;
2357 }
2358 
2359 /*
2360  * GetRenderDoc:
2361  * returns the document to be rendered, usually this will be the 'regular'
2362  * document but in case of PDF export of (multi-)selection it will
2363  * be a temporary document that gets created if not already done.
2364  * The rpView variable will be set (if not already done) to the used
2365  * SfxViewShell.
2366 */
2368  SfxViewShell *&rpView,
2369  const uno::Any& rSelection,
2370  bool bIsPDFExport )
2371 {
2372  SwDoc *pDoc = nullptr;
2373 
2374  uno::Reference< frame::XModel > xModel;
2375  rSelection >>= xModel;
2376  if (xModel == pDocShell->GetModel())
2377  pDoc = pDocShell->GetDoc();
2378  else
2379  {
2380  OSL_ENSURE( !xModel.is(), "unexpected model found" );
2381 
2382  if (rSelection.hasValue()) // is anything selected ?
2383  {
2384  // this part should only be called when a temporary document needs to be created,
2385  // for example for PDF export or printing of (multi-)selection only.
2386 
2387  if (!rpView)
2388  {
2389  bool bIsSwSrcView = false;
2390  // aside from maybe PDF export the view should always have been provided!
2391  OSL_ENSURE( bIsPDFExport, "view is missing, guessing one..." );
2392 
2393  rpView = GuessViewShell( bIsSwSrcView );
2394  }
2395  OSL_ENSURE( rpView, "SwViewShell missing" );
2396  // the view shell should be SwView for documents PDF export.
2397  // for the page preview no selection should be possible
2398  // (the export dialog does not allow for this option)
2399  if (auto pSwView = dynamic_cast<SwView *>( rpView ))
2400  {
2401  if (!m_pRenderData)
2402  {
2403  OSL_FAIL("GetRenderDoc: no renderdata");
2404  return nullptr;
2405  }
2406  SfxObjectShellLock xDocSh(m_pRenderData->GetTempDocShell());
2407  if (!xDocSh.Is())
2408  {
2409  xDocSh = pSwView->CreateTmpSelectionDoc();
2410  m_pRenderData->SetTempDocShell(xDocSh);
2411  }
2412  if (xDocSh.Is())
2413  {
2414  pDoc = static_cast<SwDocShell*>(&xDocSh)->GetDoc();
2415  rpView = pDoc->GetDocShell()->GetView();
2416  }
2417  }
2418  else
2419  {
2420  OSL_FAIL("unexpected SwViewShell" );
2421  }
2422  }
2423  }
2424  return pDoc;
2425 }
2426 
2428  SwDoc &rDoc,
2429  const SwPrintUIOptions &rPrintUIOptions,
2430  bool bIsPDFEXport )
2431 {
2432  SwPrintData aDocPrintData( rDoc.getIDocumentDeviceAccess().getPrintData() );
2433 
2434  aDocPrintData.SetPrintGraphic( rPrintUIOptions.IsPrintGraphics() );
2435  aDocPrintData.SetPrintTable( true ); // for now it was decided that tables should always be printed
2436  aDocPrintData.SetPrintDraw( rPrintUIOptions.IsPrintDrawings() );
2437  aDocPrintData.SetPrintControl( rPrintUIOptions.IsPrintFormControls() );
2438  aDocPrintData.SetPrintLeftPage( rPrintUIOptions.IsPrintLeftPages() );
2439  aDocPrintData.SetPrintRightPage( rPrintUIOptions.IsPrintRightPages() );
2440  aDocPrintData.SetPrintReverse( false ); /*handled by print dialog now*/
2441  aDocPrintData.SetPaperFromSetup( rPrintUIOptions.IsPaperFromSetup() );
2442  aDocPrintData.SetPrintEmptyPages( rPrintUIOptions.IsPrintEmptyPages( bIsPDFEXport ) );
2443  aDocPrintData.SetPrintPostIts( rPrintUIOptions.GetPrintPostItsType() );
2444  aDocPrintData.SetPrintProspect( rPrintUIOptions.IsPrintProspect() );
2445  aDocPrintData.SetPrintProspect_RTL( rPrintUIOptions.IsPrintProspectRTL() );
2446  aDocPrintData.SetPrintPageBackground( rPrintUIOptions.IsPrintPageBackground() );
2447  aDocPrintData.SetPrintBlackFont( rPrintUIOptions.IsPrintWithBlackTextColor() );
2448  // aDocPrintData.SetPrintSingleJobs( b ); handled by File/Print dialog itself
2449  // arDocPrintData.SetFaxName( s ); n/a in File/Print dialog
2450  aDocPrintData.SetPrintHiddenText( rPrintUIOptions.IsPrintHiddenText() );
2451  aDocPrintData.SetPrintTextPlaceholder( rPrintUIOptions.IsPrintTextPlaceholders() );
2452 
2453  rDoc.getIDocumentDeviceAccess().setPrintData( aDocPrintData );
2454 }
2455 
2457  const uno::Any& rSelection,
2458  const uno::Sequence< beans::PropertyValue >& rxOptions )
2459 {
2460  SolarMutexGuard aGuard;
2461  if(!IsValid())
2462  {
2463  throw DisposedException( OUString(),
2464  static_cast< XTextDocument* >(this) );
2465  }
2466 
2467  const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2468  bool bIsSwSrcView = false;
2469  SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2470 
2471  if (!bIsSwSrcView && !m_pRenderData)
2472  m_pRenderData.reset(new SwRenderData);
2473  if (!m_pPrintUIOptions)
2475  bool bFormat = m_pPrintUIOptions->processPropertiesAndCheckFormat( rxOptions );
2476 
2477  SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2478  OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2479  if (!pDoc || !pView)
2480  return 0;
2481 
2482  // save current UI options from the print dialog for the next call to that dialog
2484 
2485  sal_Int32 nRet = 0;
2486  if (bIsSwSrcView)
2487  {
2488  SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2490  nRet = rSwSrcView.PrintSource( pOutDev, 1 /* dummy */, true /* get page count only */ );
2491  }
2492  else
2493  {
2494  SwDocShell *pRenderDocShell = pDoc->GetDocShell();
2495 
2496  // TODO/mba: we really need a generic way to get the SwViewShell!
2497  SwViewShell* pViewShell = nullptr;
2498  SwView* pSwView = dynamic_cast<SwView*>( pView );
2499  if ( pSwView )
2500  {
2501  pViewShell = pSwView->GetWrtShellPtr();
2502  }
2503  else
2504  {
2505  if ( bIsPDFExport && bFormat )
2506  {
2507  //create a hidden view to be able to export as PDF also in print preview
2508  //pView and pSwView are not changed intentionally!
2510  pViewShell = static_cast<SwView*>(m_pHiddenViewFrame->GetViewShell())->GetWrtShellPtr();
2511  }
2512  else
2513  pViewShell = static_cast<SwPagePreview*>(pView)->GetViewShell();
2514  }
2515 
2516  if (!pViewShell || !pViewShell->GetLayout())
2517  return 0;
2518 
2519  if (bFormat)
2520  {
2521  // #i38289
2522  if( pViewShell->GetViewOptions()->getBrowseMode() ||
2523  pViewShell->GetViewOptions()->IsWhitespaceHidden() )
2524  {
2525  SwViewOption aOpt( *pViewShell->GetViewOptions() );
2526  aOpt.setBrowseMode( false );
2527  aOpt.SetHideWhitespaceMode( false );
2528  pViewShell->ApplyViewOptions( aOpt );
2529  if (pSwView)
2530  {
2531  pSwView->RecheckBrowseMode();
2532  }
2533  }
2534 
2535  // reformatting the document for printing will show the changes in the view
2536  // which is likely to produce many unwanted and not nice to view actions.
2537  // We don't want that! Thus we disable updating of the view.
2538  pViewShell->StartAction();
2539 
2540  if (pSwView)
2541  {
2542  if (m_pRenderData && m_pRenderData->NeedNewViewOptionAdjust( *pViewShell ) )
2543  m_pRenderData->ViewOptionAdjustStop();
2544  if (m_pRenderData && !m_pRenderData->IsViewOptionAdjust())
2545  {
2546  m_pRenderData->ViewOptionAdjustStart(
2547  *pViewShell, *pViewShell->GetViewOptions() );
2548  }
2549  }
2550 
2551  m_pRenderData->MakeSwPrtOptions( pRenderDocShell,
2552  m_pPrintUIOptions.get(), bIsPDFExport );
2553 
2554  if (pSwView)
2555  {
2556  // PDF export should not make use of the SwPrtOptions
2557  const SwPrintData *pPrtOptions = bIsPDFExport
2558  ? nullptr : m_pRenderData->GetSwPrtOptions();
2559  bool setShowPlaceHoldersInPDF = false;
2560  if(bIsPDFExport)
2561  setShowPlaceHoldersInPDF = lcl_GetBoolProperty( rxOptions, "ExportPlaceholders" );
2562  m_pRenderData->ViewOptionAdjust( pPrtOptions, setShowPlaceHoldersInPDF );
2563  }
2564 
2565  // since printing now also use the API for PDF export this option
2566  // should be set for printing as well ...
2567  pViewShell->SetPDFExportOption( true );
2568 
2569  // there is some redundancy between those two function calls, but right now
2570  // there is no time to sort this out.
2571  //TODO: check what exactly needs to be done and make just one function for that
2572  pViewShell->CalcLayout();
2573  pViewShell->CalcPagesForPrint( pViewShell->GetPageCount() );
2574 
2575 
2576  // #122919# Force field update before PDF export, but after layout init (tdf#121962)
2577  bool bStateChanged = false;
2578  // check configuration: shall update of printing information in DocInfo set the document to "modified"?
2580  {
2581  pRenderDocShell->EnableSetModified( false );
2582  bStateChanged = true;
2583  }
2584  pViewShell->SwViewShell::UpdateFields(true);
2585  if( bStateChanged )
2586  pRenderDocShell->EnableSetModified();
2587 
2588  pViewShell->SetPDFExportOption( false );
2589 
2590  // enable view again
2591  pViewShell->EndAction();
2592  }
2593 
2594  const sal_Int32 nPageCount = pViewShell->GetPageCount();
2595 
2596  // get number of pages to be rendered
2597 
2598  const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2599  if (bPrintProspect)
2600  {
2602  nRet = m_pRenderData->GetPagePairsForProspectPrinting().size();
2603  }
2604  else
2605  {
2606  const SwPostItMode nPostItMode = static_cast<SwPostItMode>( m_pPrintUIOptions->getIntValue( "PrintAnnotationMode", 0 ) );
2607  if (nPostItMode != SwPostItMode::NONE)
2608  {
2610  m_pRenderData->CreatePostItData( pDoc, pViewShell->GetViewOptions(), pOutDev );
2611  }
2612 
2613  // get set of valid document pages (according to the current settings)
2614  // and their start frames
2615  SwDoc::CalculatePagesForPrinting( *pViewShell->GetLayout(), *m_pRenderData, *m_pPrintUIOptions, bIsPDFExport, nPageCount );
2616 
2617  if (nPostItMode != SwPostItMode::NONE)
2618  {
2620  *m_pPrintUIOptions, nPageCount );
2621  }
2622 
2623  nRet = m_pRenderData->GetPagesToPrint().size();
2624  }
2625  }
2626  OSL_ENSURE( nRet >= 0, "negative number of pages???" );
2627 
2628  return nRet;
2629 }
2630 
2631 uno::Sequence< beans::PropertyValue > SAL_CALL SwXTextDocument::getRenderer(
2632  sal_Int32 nRenderer,
2633  const uno::Any& rSelection,
2634  const uno::Sequence< beans::PropertyValue >& rxOptions )
2635 {
2636  SolarMutexGuard aGuard;
2637  if(!IsValid())
2638  {
2639  throw DisposedException("", static_cast< XTextDocument* >(this));
2640  }
2641 
2642  const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" );
2643  bool bIsSwSrcView = false;
2644  SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2645 
2646  // m_pRenderData should NOT be created here!
2647  // That should only be done in getRendererCount. If this function is called before
2648  // getRendererCount was called then the caller will probably just retrieve the extra UI options
2649  // and is not interested in getting valid information about the other data that would
2650  // otherwise be provided here!
2651 // if( ! m_pRenderData )
2652 // m_pRenderData = new SwRenderData;
2653  if (!m_pPrintUIOptions)
2655  m_pPrintUIOptions->processProperties( rxOptions );
2656  const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2657  const bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2658  const bool bPrintPaperFromSetup = m_pPrintUIOptions->getBoolValue( "PrintPaperFromSetup" );
2659 
2660  SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2661  OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2662  if (!pDoc || !pView)
2663  return uno::Sequence< beans::PropertyValue >();
2664 
2665  // due to #110067# (document page count changes sometimes during
2666  // PDF export/printing) we can not check for the upper bound properly.
2667  // Thus instead of throwing the exception we silently return.
2668  if (0 > nRenderer)
2669  throw IllegalArgumentException();
2670 
2671  // TODO/mba: we really need a generic way to get the SwViewShell!
2672  SwViewShell* pVwSh = nullptr;
2673  SwView* pSwView = dynamic_cast<SwView*>( pView );
2674  if ( pSwView )
2675  pVwSh = pSwView->GetWrtShellPtr();
2676  else
2677  pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2678 
2679  sal_Int32 nMaxRenderer = 0;
2680  if (!bIsSwSrcView && m_pRenderData)
2681  {
2682  OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2683  nMaxRenderer = bPrintProspect?
2684  m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2685  m_pRenderData->GetPagesToPrint().size() - 1;
2686  }
2687  // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2688  // we obmit checking of the upper bound in this case.
2689  if (!bIsSwSrcView && m_pRenderData && nRenderer > nMaxRenderer)
2690  return uno::Sequence< beans::PropertyValue >();
2691 
2692  uno::Sequence< beans::PropertyValue > aRenderer;
2693  if (m_pRenderData)
2694  {
2695  // #i114210#
2696  // determine the correct page number from the renderer index
2697  // #i114875
2698  // consider brochure print
2699  const sal_Int32 nPage = bPrintProspect
2700  ? nRenderer + 1
2701  : m_pRenderData->GetPagesToPrint()[ nRenderer ];
2702 
2703  // get paper tray to use ...
2704  sal_Int32 nPrinterPaperTray = -1;
2705  if (! bPrintPaperFromSetup)
2706  {
2707  // ... from individual page style (see the page tab in Format/Page dialog)
2708  const std::map< sal_Int32, sal_Int32 > &rPaperTrays = m_pRenderData->GetPrinterPaperTrays();
2709  std::map< sal_Int32, sal_Int32 >::const_iterator aIt( rPaperTrays.find( nPage ) );
2710  if (aIt != rPaperTrays.end())
2711  nPrinterPaperTray = aIt->second;
2712  }
2713 
2714  awt::Size aPageSize;
2715  awt::Point aPagePos;
2716  awt::Size aPreferredPageSize;
2717  Size aTmpSize;
2718  if (bIsSwSrcView || bPrintProspect)
2719  {
2720  // for printing of HTML source code and prospect printing we should use
2721  // the printers paper size since
2722  // a) HTML source view has no page size
2723  // b) prospect printing has a different page size from the documents page
2724  // since two document pages will get rendered on one printer page
2725 
2726  // since PageIncludesNonprintableArea will be set to true we can return the
2727  // printers paper size here.
2728  // Sometimes 'getRenderer' is only called to get "ExtraPrintUIOptions", in this
2729  // case we won't get an OutputDevice here, but then the caller also has no need
2730  // for the correct PageSisze right now...
2731  VclPtr< Printer > pPrinter = dynamic_cast< Printer * >(lcl_GetOutputDevice( *m_pPrintUIOptions ).get());
2732  if (pPrinter)
2733  {
2734  // HTML source view and prospect adapt to the printer's paper size
2735  aTmpSize = pPrinter->GetPaperSize();
2736  aTmpSize = OutputDevice::LogicToLogic( aTmpSize,
2737  pPrinter->GetMapMode(), MapMode( MapUnit::Map100thMM ));
2738  aPageSize = awt::Size( aTmpSize.Width(), aTmpSize.Height() );
2739  #if 0
2740  // #i115048# it seems users didn't like getting double the formatted page size
2741  // revert to "old" behavior scaling to the current paper size of the printer
2742  if (bPrintProspect)
2743  {
2744  // we just state what output size we would need
2745  // which may cause vcl to set that page size on the printer
2746  // (if available and not overridden by the user)
2747  aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2748  aPreferredPageSize = awt::Size ( convertTwipToMm100( 2 * aTmpSize.Width() ),
2749  convertTwipToMm100( aTmpSize.Height() ));
2750  }
2751  #else
2752  if( bPrintProspect )
2753  {
2754  // just switch to an appropriate portrait/landscape format
2755  // FIXME: brochure printing with landscape pages puts the
2756  // pages next to each other, so landscape is currently always
2757  // the better choice
2758  if( aPageSize.Width < aPageSize.Height )
2759  {
2760  aPreferredPageSize.Width = aPageSize.Height;
2761  aPreferredPageSize.Height = aPageSize.Width;
2762  }
2763  }
2764  #endif
2765  }
2766  }
2767  else
2768  {
2769  aTmpSize = pVwSh->GetPageSize( nPage, bIsSkipEmptyPages );
2770  aPageSize = awt::Size ( convertTwipToMm100( aTmpSize.Width() ),
2771  convertTwipToMm100( aTmpSize.Height() ));
2772  Point aPoint = pVwSh->GetPagePos(nPage);
2773  aPagePos = awt::Point(convertTwipToMm100(aPoint.X()), convertTwipToMm100(aPoint.Y()));
2774  }
2775 
2776  sal_Int32 nLen = 3;
2777  aRenderer.realloc(3);
2778  aRenderer[0].Name = "PageSize";
2779  aRenderer[0].Value <<= aPageSize;
2780  aRenderer[1].Name = "PageIncludesNonprintableArea";
2781  aRenderer[1].Value <<= true;
2782  aRenderer[2].Name = "PagePos";
2783  aRenderer[2].Value <<= aPagePos;
2784  if (aPreferredPageSize.Width && aPreferredPageSize.Height)
2785  {
2786  ++nLen;
2787  aRenderer.realloc( nLen );
2788  aRenderer[ nLen - 1 ].Name = "PreferredPageSize";
2789  aRenderer[ nLen - 1 ].Value <<= aPreferredPageSize;
2790  }
2791  if (nPrinterPaperTray >= 0)
2792  {
2793  ++nLen;
2794  aRenderer.realloc( nLen );
2795  aRenderer[ nLen - 1 ].Name = "PrinterPaperTray";
2796  aRenderer[ nLen - 1 ].Value <<= nPrinterPaperTray;
2797  }
2798  }
2799 
2800  // #i117783#
2802  {
2803  const SwPagePreviewPrtData* pPagePrintSettings =
2805  if ( pPagePrintSettings &&
2806  ( pPagePrintSettings->GetRow() > 1 ||
2807  pPagePrintSettings->GetCol() > 1 ) )
2808  {
2809  // extend render data by page print settings attributes
2810  sal_Int32 nLen = aRenderer.getLength();
2811  const sal_Int32 nRenderDataIdxStart = nLen;
2812  nLen += 9;
2813  aRenderer.realloc( nLen );
2814  // put page print settings attribute into render data
2815  const sal_Int32 nRow = pPagePrintSettings->GetRow();
2816  aRenderer[ nRenderDataIdxStart + 0 ].Name = "NUpRows";
2817  aRenderer[ nRenderDataIdxStart + 0 ].Value <<= std::max<sal_Int32>( nRow, 1);
2818  const sal_Int32 nCol = pPagePrintSettings->GetCol();
2819  aRenderer[ nRenderDataIdxStart + 1 ].Name = "NUpColumns";
2820  aRenderer[ nRenderDataIdxStart + 1 ].Value <<= std::max<sal_Int32>( nCol, 1);
2821  aRenderer[ nRenderDataIdxStart + 2 ].Name = "NUpPageMarginLeft";
2822  aRenderer[ nRenderDataIdxStart + 2 ].Value <<= pPagePrintSettings->GetLeftSpace();
2823  aRenderer[ nRenderDataIdxStart + 3 ].Name = "NUpPageMarginRight";
2824  aRenderer[ nRenderDataIdxStart + 3 ].Value <<= pPagePrintSettings->GetRightSpace();
2825  aRenderer[ nRenderDataIdxStart + 4 ].Name = "NUpPageMarginTop";
2826  aRenderer[ nRenderDataIdxStart + 4 ].Value <<= pPagePrintSettings->GetTopSpace();
2827  aRenderer[ nRenderDataIdxStart + 5 ].Name = "NUpPageMarginBottom";
2828  aRenderer[ nRenderDataIdxStart + 5 ].Value <<= pPagePrintSettings->GetBottomSpace();
2829  aRenderer[ nRenderDataIdxStart + 6 ].Name = "NUpHorizontalSpacing";
2830  aRenderer[ nRenderDataIdxStart + 6 ].Value <<= pPagePrintSettings->GetHorzSpace();
2831  aRenderer[ nRenderDataIdxStart + 7 ].Name = "NUpVerticalSpacing";
2832  aRenderer[ nRenderDataIdxStart + 7 ].Value <<= pPagePrintSettings->GetVertSpace();
2833  {
2834  Printer* pPrinter = pDocShell->GetDoc()->getIDocumentDeviceAccess().getPrinter( false );
2835  if ( pPrinter )
2836  {
2837  awt::Size aNewPageSize;
2838  const Size aPageSize = pPrinter->PixelToLogic( pPrinter->GetPaperSizePixel(), MapMode( MapUnit::Map100thMM ) );
2839  aNewPageSize = awt::Size( aPageSize.Width(), aPageSize.Height() );
2840  if ( ( pPagePrintSettings->GetLandscape() &&
2841  aPageSize.Width() < aPageSize.Height() ) ||
2842  ( !pPagePrintSettings->GetLandscape() &&
2843  aPageSize.Width() > aPageSize.Height() ) )
2844  {
2845  aNewPageSize = awt::Size( aPageSize.Height(), aPageSize.Width() );
2846  }
2847  aRenderer[ nRenderDataIdxStart + 8 ].Name = "NUpPaperSize";
2848  aRenderer[ nRenderDataIdxStart + 8 ].Value <<= aNewPageSize;
2849  }
2850  }
2851  }
2852 
2854  }
2855 
2856  m_pPrintUIOptions->appendPrintUIOptions( aRenderer );
2857 
2858  return aRenderer;
2859 }
2860 
2862  /* out */ bool &rbIsSwSrcView,
2863  const uno::Reference< css::frame::XController >& rController )
2864 {
2865  // #130810# SfxViewShell::Current() / SfxViewShell::GetObjectShell()
2866  // must not be used (see comment from MBA)
2867 
2868  SfxViewShell *pView = nullptr;
2869  SwView *pSwView = nullptr;
2870  SwPagePreview *pSwPagePreview = nullptr;
2871  SwSrcView *pSwSrcView = nullptr;
2872  SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pDocShell, false );
2873 
2874  // look for the view shell with the same controller in use,
2875  // otherwise look for a suitable view, preferably a SwView,
2876  // if that one is not found use a SwPagePreview if found.
2877  while (pFrame)
2878  {
2879  pView = pFrame->GetViewShell();
2880  pSwView = dynamic_cast< SwView * >(pView);
2881  pSwSrcView = dynamic_cast< SwSrcView * >(pView);
2882  if (!pSwPagePreview)
2883  pSwPagePreview = dynamic_cast< SwPagePreview * >(pView);
2884  if (rController.is())
2885  {
2886  if (pView && pView->GetController() == rController)
2887  break;
2888  }
2889  else if (pSwView || pSwSrcView)
2890  break;
2891  pFrame = SfxViewFrame::GetNext( *pFrame, pDocShell, false );
2892  }
2893 
2894  OSL_ENSURE( pSwView || pSwPagePreview || pSwSrcView, "failed to get view shell" );
2895  if (pView)
2896  rbIsSwSrcView = pSwSrcView != nullptr;
2897  return pView;
2898 }
2899 
2901  sal_Int32 nRenderer,
2902  const uno::Any& rSelection,
2903  const uno::Sequence< beans::PropertyValue >& rxOptions )
2904 {
2905  SolarMutexGuard aGuard;
2906  if(!IsValid())
2907  {
2908  throw DisposedException( OUString(),
2909  static_cast< XTextDocument* >(this) );
2910  }
2911 
2912  // due to #110067# (document page count changes sometimes during
2913  // PDF export/printing) we can not check for the upper bound properly.
2914  // Thus instead of throwing the exception we silently return.
2915  if (0 > nRenderer)
2916  throw IllegalArgumentException();
2917 
2918  const bool bHasPDFExtOutDevData = lcl_SeqHasProperty( rxOptions, "HasPDFExtOutDevData" );
2919  const bool bIsPDFExport = !lcl_SeqHasProperty( rxOptions, "IsPrinter" ) || bHasPDFExtOutDevData;
2920  bool bIsSwSrcView = false;
2921  SfxViewShell *pView = GetRenderView( bIsSwSrcView, rxOptions, bIsPDFExport );
2922 
2923  OSL_ENSURE( m_pRenderData, "data should have been created already in getRendererCount..." );
2924  OSL_ENSURE( m_pPrintUIOptions, "data should have been created already in getRendererCount..." );
2925  if (!bIsSwSrcView && !m_pRenderData)
2926  m_pRenderData.reset(new SwRenderData);
2927  if (!m_pPrintUIOptions)
2929  m_pPrintUIOptions->processProperties( rxOptions );
2930  const bool bPrintProspect = m_pPrintUIOptions->getBoolValue( "PrintProspect" );
2931  const bool bLastPage = m_pPrintUIOptions->getBoolValue( "IsLastPage" );
2932 
2933  SwDoc *pDoc = GetRenderDoc( pView, rSelection, bIsPDFExport );
2934  OSL_ENSURE( pDoc && pView, "doc or view shell missing!" );
2935  if (pDoc && pView)
2936  {
2937  sal_Int32 nMaxRenderer = 0;
2938  if (!bIsSwSrcView)
2939  {
2940  OSL_ENSURE( m_pRenderData, "m_pRenderData missing!!" );
2941  nMaxRenderer = bPrintProspect?
2942  m_pRenderData->GetPagePairsForProspectPrinting().size() - 1 :
2943  m_pRenderData->GetPagesToPrint().size() - 1;
2944  }
2945  // since SwSrcView::PrintSource is a poor implementation to get the number of pages to print
2946  // we obmit checking of the upper bound in this case.
2947  if (bIsSwSrcView || nRenderer <= nMaxRenderer)
2948  {
2949  if (bIsSwSrcView)
2950  {
2951  SwSrcView& rSwSrcView = dynamic_cast<SwSrcView&>(*pView);
2953  rSwSrcView.PrintSource(pOutDev, nRenderer + 1, false);
2954  }
2955  else
2956  {
2957  // the view shell should be SwView for documents PDF export
2958  // or SwPagePreview for PDF export of the page preview
2959  SwViewShell* pVwSh = nullptr;
2960  // TODO/mba: we really need a generic way to get the SwViewShell!
2961  const SwView* pSwView = dynamic_cast<const SwView*>(pView);
2962  if (pSwView)
2963  pVwSh = pSwView->GetWrtShellPtr();
2964  else
2965  pVwSh = static_cast<SwPagePreview*>(pView)->GetViewShell();
2966 
2967  // get output device to use
2969 
2970  if(pVwSh && pOut && m_pRenderData->HasSwPrtOptions())
2971  {
2972  const OUString aPageRange = m_pPrintUIOptions->getStringValue( "PageRange" );
2973  const bool bFirstPage = m_pPrintUIOptions->getBoolValue( "IsFirstPage" );
2974  bool bIsSkipEmptyPages = !m_pPrintUIOptions->IsPrintEmptyPages( bIsPDFExport );
2975 
2976  OSL_ENSURE((pSwView && m_pRenderData->IsViewOptionAdjust())
2977  || (!pSwView && !m_pRenderData->IsViewOptionAdjust()),
2978  "SwView / SwViewOptionAdjust_Impl availability mismatch" );
2979 
2980  // since printing now also use the API for PDF export this option
2981  // should be set for printing as well ...
2982  pVwSh->SetPDFExportOption( true );
2983 
2984  // #i12836# enhanced pdf export
2985 
2986  // First, we have to export hyperlinks, notes, and outline to pdf.
2987  // During this process, additional information required for tagging
2988  // the pdf file are collected, which are evaulated during painting.
2989 
2990  SwWrtShell* pWrtShell = pSwView ? pSwView->GetWrtShellPtr() : nullptr;
2991 
2992  SwPrintData const& rSwPrtOptions =
2993  *m_pRenderData->GetSwPrtOptions();
2994 
2995  if (bIsPDFExport && (bFirstPage || bHasPDFExtOutDevData) && pWrtShell)
2996  {
2997  SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, false, rSwPrtOptions );
2998  }
2999 
3000  if (bPrintProspect)
3001  pVwSh->PrintProspect( pOut, rSwPrtOptions, nRenderer );
3002  else // normal printing and PDF export
3003  pVwSh->PrintOrPDFExport( pOut, rSwPrtOptions, nRenderer, bIsPDFExport );
3004 
3005  // #i35176#
3006 
3007  // After printing the last page, we take care for the links coming
3008  // from the EditEngine. The links are generated during the painting
3009  // process, but the destinations are still missing.
3010 
3011  if (bIsPDFExport && bLastPage && pWrtShell)
3012  {
3013  SwEnhancedPDFExportHelper aHelper( *pWrtShell, *pOut, aPageRange, bIsSkipEmptyPages, true, rSwPrtOptions );
3014  }
3015 
3016  pVwSh->SetPDFExportOption( false );
3017 
3018  // last page to be rendered? (not necessarily the last page of the document)
3019  // -> do clean-up of data
3020  if (bLastPage)
3021  {
3022  // #i96167# haggai: delete ViewOptionsAdjust here because it makes use
3023  // of the shell, which might get destroyed in lcl_DisposeView!
3024  if (m_pRenderData->IsViewOptionAdjust())
3025  m_pRenderData->ViewOptionAdjustStop();
3026 
3027  if (m_pRenderData->HasPostItData())
3028  m_pRenderData->DeletePostItData();
3029  if (m_pHiddenViewFrame)
3030  {
3032  m_pHiddenViewFrame = nullptr;
3033 
3034  // prevent crash described in #i108805
3035  SwDocShell *pRenderDocShell = pDoc->GetDocShell();
3036  SfxItemSet *pSet = pRenderDocShell->GetMedium()->GetItemSet();
3037  pSet->Put( SfxBoolItem( SID_HIDDEN, false ) );
3038 
3039  }
3040  }
3041  }
3042  }
3043  }
3044  }
3045  if( bLastPage )
3046  {
3047  m_pRenderData.reset();
3048  m_pPrintUIOptions.reset();
3049  }
3050 }
3051 
3052 // xforms::XFormsSupplier
3053 Reference<XNameContainer> SAL_CALL SwXTextDocument::getXForms()
3054 {
3055  SolarMutexGuard aGuard;
3056  if ( !pDocShell )
3057  throw DisposedException( OUString(), static_cast< XTextDocument* >( this ) );
3058  SwDoc* pDoc = pDocShell->GetDoc();
3059  return pDoc->getXForms();
3060 }
3061 
3062 uno::Reference< text::XFlatParagraphIterator > SAL_CALL SwXTextDocument::getFlatParagraphIterator(::sal_Int32 nTextMarkupType, sal_Bool bAutomatic)
3063 {
3064  SolarMutexGuard aGuard;
3065  if (!IsValid())
3066  {
3067  throw DisposedException("SwXTextDocument not valid",
3068  static_cast<XTextDocument*>(this));
3069  }
3070 
3072  *pDocShell->GetDoc(), nTextMarkupType, bAutomatic);
3073 }
3074 
3075 uno::Reference< util::XCloneable > SwXTextDocument::createClone( )
3076 {
3077  SolarMutexGuard aGuard;
3078  if(!IsValid())
3079  throw DisposedException("", static_cast< XTextDocument* >(this));
3080 
3081  // create a new document - hidden - copy the storage and return it
3082  // SfxObjectShellRef is used here, since the model should control object lifetime after creation
3083  // and thus SfxObjectShellLock is not allowed here
3084  // the model holds reference to the shell, so the shell will not destructed at the end of method
3085  SfxObjectShellRef pShell = pDocShell->GetDoc()->CreateCopy(false, false);
3086  uno::Reference< frame::XModel > xNewModel = pShell->GetModel();
3087  uno::Reference< embed::XStorage > xNewStorage = ::comphelper::OStorageHelper::GetTemporaryStorage( );
3088  uno::Sequence< beans::PropertyValue > aTempMediaDescriptor;
3089  storeToStorage( xNewStorage, aTempMediaDescriptor );
3090  uno::Reference< document::XStorageBasedDocument > xStorageDoc( xNewModel, uno::UNO_QUERY );
3091  xStorageDoc->loadFromStorage( xNewStorage, aTempMediaDescriptor );
3092  return uno::Reference< util::XCloneable >( xNewModel, UNO_QUERY );
3093 }
3094 
3095 void SwXTextDocument::addPasteEventListener(const uno::Reference<text::XPasteListener>& xListener)
3096 {
3097  SolarMutexGuard aGuard;
3098 
3099  if (IsValid() && xListener.is())
3101 }
3102 
3104  const uno::Reference<text::XPasteListener>& xListener)
3105 {
3106  SolarMutexGuard aGuard;
3107 
3108  if (IsValid() && xListener.is())
3110 }
3111 
3113  int nOutputWidth, int nOutputHeight,
3114  int nTilePosX, int nTilePosY,
3115  long nTileWidth, long nTileHeight )
3116 {
3117  SwViewShell* pViewShell = pDocShell->GetWrtShell();
3118  pViewShell->PaintTile(rDevice, nOutputWidth, nOutputHeight,
3119  nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3120 
3121  LokChartHelper::PaintAllChartsOnTile(rDevice, nOutputWidth, nOutputHeight,
3122  nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3123 }
3124 
3126 {
3127  SwViewShell* pViewShell = pDocShell->GetWrtShell();
3128  Size aDocSize = pViewShell->GetDocSize();
3129 
3130  return Size(aDocSize.Width() + 2 * DOCUMENTBORDER,
3131  aDocSize.Height() + 2 * DOCUMENTBORDER);
3132 }
3133 
3135 {
3136  SolarMutexGuard aGuard;
3137 
3138  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3139  if (!pWrtShell)
3140  return;
3141 
3142  pWrtShell->GotoPage(nPart + 1, true);
3143 }
3144 
3146 {
3147  SolarMutexGuard aGuard;
3148 
3149  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3150  if (!pWrtShell)
3151  return 0;
3152 
3153  return pWrtShell->GetPageCnt();
3154 }
3155 
3157 {
3158  SolarMutexGuard aGuard;
3159 
3160  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3161  if (!pWrtShell)
3162  return OUString();
3163 
3164  return pWrtShell->getPageRectangles();
3165 }
3166 
3167 void SwXTextDocument::setClipboard(const uno::Reference<datatransfer::clipboard::XClipboard>& xClipboard)
3168 {
3169  SolarMutexGuard aGuard;
3170 
3171  SwView* pView = pDocShell->GetView();
3172  if (pView)
3173  pView->GetEditWin().SetClipboard(xClipboard);
3174 }
3175 
3177 {
3178  SolarMutexGuard aGuard;
3179 
3180  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3181  if (!pWrtShell)
3182  return false;
3183 
3185  if (SdrView* pSdrView = pWrtShell->GetDrawView())
3186  {
3187  if (pSdrView->GetTextEditObject())
3188  // Editing shape text
3189  return EditEngine::HasValidData(aDataHelper.GetTransferable());
3190  }
3191 
3192  return aDataHelper.GetXTransferable().is() && SwTransferable::IsPaste(*pWrtShell, aDataHelper);
3193 }
3194 
3196 {
3197  if (SwView* pView = pDocShell->GetView())
3198  {
3199  // set the PgUp/PgDown offset
3200  pView->ForcePageUpDownOffset(2 * rRectangle.GetHeight() / 3);
3201  }
3202 
3203  if (SwViewShell* pViewShell = pDocShell->GetWrtShell())
3204  {
3205  pViewShell->setLOKVisibleArea(rRectangle);
3206  }
3207 }
3208 
3209 void SwXTextDocument::setClientZoom(int nTilePixelWidth_, int /*nTilePixelHeight_*/,
3210  int nTileTwipWidth_, int /*nTileTwipHeight_*/)
3211 {
3212  // Here we set the zoom value as it has been set by the user in the client.
3213  // This value is used in postMouseEvent and setGraphicSelection methods
3214  // for in place chart editing. We assume that x and y scale is roughly
3215  // the same.
3216  SfxInPlaceClient* pIPClient = pDocShell->GetView()->GetIPClient();
3217  if (pIPClient)
3218  {
3219  SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
3220  double fScale = nTilePixelWidth_ * TWIPS_PER_PIXEL / (nTileTwipWidth_ * 1.0);
3221  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3222  if (aOption.GetZoom() != fScale * 100)
3223  {
3224  aOption.SetZoom(fScale * 100);
3225  pWrtViewShell->ApplyViewOptions(aOption);
3226 
3227  // Changing the zoom value doesn't always trigger the updating of
3228  // the client ole object area, so we call it directly.
3229  pIPClient->VisAreaChanged();
3230  }
3231  }
3232 }
3233 
3235 {
3236  SolarMutexGuard aGuard;
3237 
3238  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3239  if (!pWrtShell)
3240  return PointerStyle::Arrow;
3241 
3242  return pWrtShell->GetView().GetEditWin().GetPointer();
3243 }
3244 
3246 {
3247  boost::property_tree::ptree aTrackedChanges;
3248 
3249  // Disable since usability is very low beyond some small number of changes.
3250  static bool bDisableRedlineComments = getenv("DISABLE_REDLINE") != nullptr;
3251  if (!bDisableRedlineComments)
3252  {
3253  const SwRedlineTable& rRedlineTable
3255  for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
3256  {
3257  boost::property_tree::ptree aTrackedChange;
3258  aTrackedChange.put("index", rRedlineTable[i]->GetId());
3259  aTrackedChange.put("author", rRedlineTable[i]->GetAuthorString(1).toUtf8().getStr());
3260  aTrackedChange.put("type", SwRedlineTypeToOUString(
3261  rRedlineTable[i]->GetRedlineData().GetType())
3262  .toUtf8()
3263  .getStr());
3264  aTrackedChange.put("comment",
3265  rRedlineTable[i]->GetRedlineData().GetComment().toUtf8().getStr());
3266  aTrackedChange.put("description", rRedlineTable[i]->GetDescr().toUtf8().getStr());
3267  OUString sDateTime = utl::toISO8601(
3268  rRedlineTable[i]->GetRedlineData().GetTimeStamp().GetUNODateTime());
3269  aTrackedChange.put("dateTime", sDateTime.toUtf8().getStr());
3270 
3271  SwContentNode* pContentNd = rRedlineTable[i]->GetContentNode();
3272  SwView* pView = dynamic_cast<SwView*>(SfxViewShell::Current());
3273  if (pView && pContentNd)
3274  {
3275  SwShellCursor aCursor(pView->GetWrtShell(), *(rRedlineTable[i]->Start()));
3276  aCursor.SetMark();
3277  aCursor.GetMark()->nNode = *pContentNd;
3278  aCursor.GetMark()->nContent.Assign(pContentNd,
3279  rRedlineTable[i]->End()->nContent.GetIndex());
3280 
3281  aCursor.FillRects();
3282 
3283  SwRects* pRects(&aCursor);
3284  std::vector<OString> aRects;
3285  for (const SwRect& rNextRect : *pRects)
3286  aRects.push_back(rNextRect.SVRect().toString());
3287 
3288  const OString sRects = comphelper::string::join("; ", aRects);
3289  aTrackedChange.put("textRange", sRects.getStr());
3290  }
3291 
3292  aTrackedChanges.push_back(std::make_pair("", aTrackedChange));
3293  }
3294  }
3295 
3296  boost::property_tree::ptree aTree;
3297  aTree.add_child("redlines", aTrackedChanges);
3298  std::stringstream aStream;
3299  boost::property_tree::write_json(aStream, aTree);
3300 
3301  return OUString::fromUtf8(aStream.str().c_str());
3302 }
3303 
3305 {
3306  return SW_MOD()->GetRedlineAuthorInfo();
3307 }
3308 
3310 {
3311  SwView* pView = pDocShell->GetView();
3312  return OUString::fromUtf8(dynamic_cast<SwCommentRuler&>(pView->GetHRuler()).CreateJsonNotification().c_str());
3313 }
3314 
3316 {
3317  SolarMutexGuard aGuard;
3318  boost::property_tree::ptree aAnnotations;
3319  for (auto const& sidebarItem : *pDocShell->GetView()->GetPostItMgr())
3320  {
3321  sw::annotation::SwAnnotationWin* pWin = sidebarItem->pPostIt.get();
3322 
3323  const SwPostItField* pField = pWin->GetPostItField();
3324  const SwRect& aRect = pWin->GetAnchorRect();
3325  tools::Rectangle aSVRect(aRect.Pos().getX(),
3326  aRect.Pos().getY(),
3327  aRect.Pos().getX() + aRect.SSize().Width(),
3328  aRect.Pos().getY() + aRect.SSize().Height());
3329 
3330  if (!sidebarItem->maLayoutInfo.mPositionFromCommentAnchor)
3331  {
3332  // Comments on frames: anchor position is the corner position, not the whole frame.
3333  aSVRect.SetSize(Size(0, 0));
3334  }
3335 
3336  std::vector<OString> aRects;
3337  for (const basegfx::B2DRange& aRange : pWin->GetAnnotationTextRanges())
3338  {
3339  const SwRect rect(aRange.getMinX(), aRange.getMinY(), aRange.getWidth(), aRange.getHeight());
3340  aRects.push_back(rect.SVRect().toString());
3341  }
3342  const OString sRects = comphelper::string::join("; ", aRects);
3343 
3344  boost::property_tree::ptree aAnnotation;
3345  aAnnotation.put("id", pField->GetPostItId());
3346  aAnnotation.put("parent", pWin->CalcParent());
3347  aAnnotation.put("author", pField->GetPar1().toUtf8().getStr());
3348  aAnnotation.put("text", pField->GetPar2().toUtf8().getStr());
3349  aAnnotation.put("resolved", pField->GetResolved() ? "true" : "false");
3350  aAnnotation.put("dateTime", utl::toISO8601(pField->GetDateTime().GetUNODateTime()));
3351  aAnnotation.put("anchorPos", aSVRect.toString());
3352  aAnnotation.put("textRange", sRects.getStr());
3353 
3354  aAnnotations.push_back(std::make_pair("", aAnnotation));
3355  }
3356 
3357  boost::property_tree::ptree aTree;
3358  aTree.add_child("comments", aAnnotations);
3359  std::stringstream aStream;
3360  boost::property_tree::write_json(aStream, aTree);
3361 
3362  return OUString::fromUtf8(aStream.str().c_str());
3363 }
3364 
3366 {
3367  SolarMutexGuard aGuard;
3368 
3369  SwView* pView = pDocShell->GetView();
3370  if (!pView)
3371  return 0;
3372 
3373  return pView->getPart();
3374 }
3375 
3376 OUString SwXTextDocument::getPartName(int nPart)
3377 {
3378  SolarMutexGuard aGuard;
3379 
3380  return SwResId(STR_PAGE) + OUString::number(nPart + 1);
3381 }
3382 
3383 OUString SwXTextDocument::getPartHash(int nPart)
3384 {
3385  SolarMutexGuard aGuard;
3386  OUString sPart(SwResId(STR_PAGE) + OUString::number(nPart + 1));
3387 
3388  return OUString::number(sPart.hashCode());
3389 }
3390 
3392 {
3393  SolarMutexGuard aGuard;
3394  VclPtr<vcl::Window> pWindow;
3395  SwView* pView = pDocShell->GetView();
3396  if (pView)
3397  pWindow = &(pView->GetEditWin());
3398 
3399  LokChartHelper aChartHelper(pView);
3400  VclPtr<vcl::Window> pChartWindow = aChartHelper.GetWindow();
3401  if (pChartWindow)
3402  pWindow = pChartWindow;
3403 
3404  return pWindow;
3405 }
3406 
3407 void SwXTextDocument::initializeForTiledRendering(const css::uno::Sequence<css::beans::PropertyValue>& rArguments)
3408 {
3409  SolarMutexGuard aGuard;
3410 
3411  SwViewShell* pViewShell = pDocShell->GetWrtShell();
3412 
3413  SwView* pView = pDocShell->GetView();
3414  if (!pView)
3415  return;
3416 
3417  pView->SetViewLayout(1/*nColumns*/, false/*bBookMode*/, true);
3418 
3419  // Tiled rendering defaults.
3420  SwViewOption aViewOption(*pViewShell->GetViewOptions());
3421  aViewOption.SetHardBlank(false);
3422  for (const beans::PropertyValue& rValue : rArguments)
3423  {
3424  if (rValue.Name == ".uno:HideWhitespace" && rValue.Value.has<bool>())
3425  aViewOption.SetHideWhitespaceMode(rValue.Value.get<bool>());
3426  else if (rValue.Name == ".uno:ShowBorderShadow" && rValue.Value.has<bool>())
3427  SwViewOption::SetAppearanceFlag(ViewOptFlags::Shadow , rValue.Value.get<bool>());
3428  else if (rValue.Name == ".uno:Author" && rValue.Value.has<OUString>())
3429  {
3430  // Store the author name in the view.
3431  pView->SetRedlineAuthor(rValue.Value.get<OUString>());
3432  // Let the actual author name pick up the value from the current
3433  // view, which would normally happen only during the next view
3434  // switch.
3435  pDocShell->SetView(pView);
3436  }
3437  }
3438 
3439  // Set the initial zoom value to 1; usually it is set in setClientZoom and
3440  // SwViewShell::PaintTile; zoom value is used for chart in place
3441  // editing, see postMouseEvent and setGraphicSelection methods.
3442  aViewOption.SetZoom(1 * 100);
3443 
3444  aViewOption.SetPostIts(comphelper::LibreOfficeKit::isTiledAnnotations());
3445  pViewShell->ApplyViewOptions(aViewOption);
3446 
3447  // position the pages again after setting view options. Eg: if postit
3448  // rendering is false, then there would be no sidebar, so width of the
3449  // document needs to be adjusted
3450  pViewShell->GetLayout()->CheckViewLayout( pViewShell->GetViewOptions(), nullptr );
3451 
3452  // Disable map mode, so that it's possible to send mouse event coordinates
3453  // directly in twips.
3454  SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3455  rEditWin.EnableMapMode(false);
3456 
3457  // when the "This document may contain formatting or content that cannot
3458  // be saved..." dialog appears, it is auto-cancelled with tiled rendering,
3459  // causing 'Save' being disabled; so let's always save to the original
3460  // format
3462 
3463  // disable word auto-completion suggestions, the tooltips are not visible,
3464  // and the editeng-like auto-completion is annoying
3466 
3467  // don't change the whitespace at the beginning of paragraphs, this is
3468  // annoying when taking minutes without further formatting
3470 }
3471 
3472 void SwXTextDocument::postKeyEvent(int nType, int nCharCode, int nKeyCode)
3473 {
3474  SolarMutexGuard aGuard;
3475  SfxLokHelper::postKeyEventAsync(getDocWindow(), nType, nCharCode, nKeyCode);
3476 }
3477 
3478 void SwXTextDocument::postMouseEvent(int nType, int nX, int nY, int nCount, int nButtons, int nModifier)
3479 {
3480  SolarMutexGuard aGuard;
3481 
3482  SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
3483  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3484  double fScale = aOption.GetZoom() / (TWIPS_PER_PIXEL * 100.0);
3485 
3486  // check if the user hit a chart which is being edited by this view
3487  SfxViewShell* pViewShell = pDocShell->GetView();
3488  LokChartHelper aChartHelper(pViewShell);
3489  if (aChartHelper.postMouseEvent(nType, nX, nY,
3490  nCount, nButtons, nModifier,
3491  fScale, fScale))
3492  return;
3493 
3494  // check if the user hit a chart which is being edited by someone else
3495  // and, if so, skip current mouse event
3496  if (nType != LOK_MOUSEEVENT_MOUSEMOVE)
3497  {
3498  if (LokChartHelper::HitAny(Point(nX, nY)))
3499  return;
3500  }
3501 
3502  SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3503  SfxLokHelper::postMouseEventAsync(&rEditWin, nType,
3504  Point(nX, nY), nCount,
3505  MouseEventModifiers::SIMPLECLICK,
3506  nButtons, nModifier);
3507 }
3508 
3509 void SwXTextDocument::setTextSelection(int nType, int nX, int nY)
3510 {
3511  SolarMutexGuard aGuard;
3512 
3513  SfxViewShell* pViewShell = pDocShell->GetView();
3514  LokChartHelper aChartHelper(pViewShell);
3515  if (aChartHelper.setTextSelection(nType, nX, nY))
3516  return;
3517 
3518  SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3519  switch (nType)
3520  {
3521  case LOK_SETTEXTSELECTION_START:
3522  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/false, /*bClearMark=*/false);
3523  break;
3524  case LOK_SETTEXTSELECTION_END:
3525  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/false);
3526  break;
3527  case LOK_SETTEXTSELECTION_RESET:
3528  rEditWin.SetCursorTwipPosition(Point(nX, nY), /*bPoint=*/true, /*bClearMark=*/true);
3529  break;
3530  default:
3531  assert(false);
3532  break;
3533  }
3534 }
3535 
3536 uno::Reference<datatransfer::XTransferable> SwXTextDocument::getSelection()
3537 {
3538  SolarMutexGuard aGuard;
3539 
3540  uno::Reference<datatransfer::XTransferable> xTransferable;
3541 
3542  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3543  if (SdrView* pSdrView = pWrtShell->GetDrawView())
3544  {
3545  if (pSdrView->GetTextEditObject())
3546  {
3547  // Editing shape text
3548  EditView& rEditView = pSdrView->GetTextEditOutlinerView()->GetEditView();
3549  xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3550  }
3551  }
3552 
3553  if (SwPostItMgr* pPostItMgr = pDocShell->GetView()->GetPostItMgr())
3554  {
3555  if (sw::annotation::SwAnnotationWin* pWin = pPostItMgr->GetActiveSidebarWin())
3556  {
3557  // Editing postit text.
3558  EditView& rEditView = pWin->GetOutlinerView()->GetEditView();
3559  xTransferable = rEditView.GetEditEngine()->CreateTransferable(rEditView.GetSelection());
3560  }
3561  }
3562 
3563  if (!xTransferable.is())
3564  xTransferable = new SwTransferable(*pWrtShell);
3565 
3566  return xTransferable;
3567 }
3568 
3569 void SwXTextDocument::setGraphicSelection(int nType, int nX, int nY)
3570 {
3571  SolarMutexGuard aGuard;
3572 
3573  SwViewShell* pWrtViewShell = pDocShell->GetWrtShell();
3574  SwViewOption aOption(*(pWrtViewShell->GetViewOptions()));
3575  double fScale = aOption.GetZoom() / (TWIPS_PER_PIXEL * 100.0);
3576 
3577  SfxViewShell* pViewShell = pDocShell->GetView();
3578  LokChartHelper aChartHelper(pViewShell);
3579  if (aChartHelper.setGraphicSelection(nType, nX, nY, fScale, fScale))
3580  return;
3581 
3582  SwEditWin& rEditWin = pDocShell->GetView()->GetEditWin();
3583  switch (nType)
3584  {
3585  case LOK_SETGRAPHICSELECTION_START:
3586  rEditWin.SetGraphicTwipPosition(/*bStart=*/true, Point(nX, nY));
3587  break;
3588  case LOK_SETGRAPHICSELECTION_END:
3589  rEditWin.SetGraphicTwipPosition(/*bStart=*/false, Point(nX, nY));
3590  break;
3591  default:
3592  assert(false);
3593  break;
3594  }
3595 }
3596 
3598 {
3599  SolarMutexGuard aGuard;
3600 
3601  SwWrtShell* pWrtShell = pDocShell->GetWrtShell();
3602  pWrtShell->ResetSelect(nullptr, false);
3603 }
3604 
3605 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 )
3606 {
3608  aData.nSize = sizeof(SystemGraphicsData);
3609  #if defined(_WIN32)
3610  sal_Int64 nWindowHandle;
3611  Parent >>= nWindowHandle;
3612  aData.hWnd = reinterpret_cast<HWND>(nWindowHandle);
3613  ScopedVclPtrInstance<VirtualDevice> xDevice(aData, Size(1, 1), DeviceFormat::DEFAULT);
3614  paintTile(*xDevice, nOutputWidth, nOutputHeight, nTilePosX, nTilePosY, nTileWidth, nTileHeight);
3615  #else
3616  // TODO: support other platforms
3617  (void)Parent;
3618  (void)nOutputWidth;
3619  (void)nOutputHeight;
3620  (void)nTilePosX;
3621  (void)nTilePosY;
3622  (void)nTileWidth;
3623  (void)nTileHeight;
3624  #endif
3625 }
3626 
3630 uno::Sequence< lang::Locale > SAL_CALL SwXTextDocument::getDocumentLanguages(
3631  ::sal_Int16 nScriptTypes,
3632  ::sal_Int16 nMaxCount )
3633 {
3634  SolarMutexGuard aGuard;
3635 
3636  // possible canonical values for nScriptTypes
3637  // any bit wise combination is allowed
3638  const sal_Int16 nLatin = 0x001;
3639  const sal_Int16 nAsian = 0x002;
3640  const sal_Int16 nComplex = 0x004;
3641 
3642  // script types for which to get the languages
3643  const bool bLatin = 0 != (nScriptTypes & nLatin);
3644  const bool bAsian = 0 != (nScriptTypes & nAsian);
3645  const bool bComplex = 0 != (nScriptTypes & nComplex);
3646 
3647  if (nScriptTypes < nLatin || nScriptTypes > (nLatin | nAsian | nComplex))
3648  throw IllegalArgumentException("nScriptTypes ranges from 1 to 7!", Reference< XInterface >(), 1);
3649  if (!pDocShell)
3650  throw DisposedException();
3651  SwDoc* pDoc = pDocShell->GetDoc();
3652 
3653  // avoid duplicate values
3654  std::set< LanguageType > aAllLangs;
3655 
3656  //USER STYLES
3657 
3658  const SwCharFormats *pFormats = pDoc->GetCharFormats();
3659  for(size_t i = 0; i < pFormats->size(); ++i)
3660  {
3661  const SwAttrSet &rAttrSet = (*pFormats)[i]->GetAttrSet();
3663  if (bLatin)
3664  {
3665  nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3666  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3667  aAllLangs.insert( nLang );
3668  }
3669  if (bAsian)
3670  {
3671  nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3672  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3673  aAllLangs.insert( nLang );
3674  }
3675  if (bComplex)
3676  {
3677  nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3678  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3679  aAllLangs.insert( nLang );
3680  }
3681  }
3682 
3683  const SwTextFormatColls *pColls = pDoc->GetTextFormatColls();
3684  for (size_t i = 0; i < pColls->size(); ++i)
3685  {
3686  const SwAttrSet &rAttrSet = (*pColls)[i]->GetAttrSet();
3688  if (bLatin)
3689  {
3690  nLang = rAttrSet.GetLanguage( false ).GetLanguage();
3691  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3692  aAllLangs.insert( nLang );
3693  }
3694  if (bAsian)
3695  {
3696  nLang = rAttrSet.GetCJKLanguage( false ).GetLanguage();
3697  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3698  aAllLangs.insert( nLang );
3699  }
3700  if (bComplex)
3701  {
3702  nLang = rAttrSet.GetCTLLanguage( false ).GetLanguage();
3703  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3704  aAllLangs.insert( nLang );
3705  }
3706  }
3707 
3708  //AUTO STYLES
3709  const IStyleAccess::SwAutoStyleFamily aFam[2] =
3710  {
3713  };
3714  for (IStyleAccess::SwAutoStyleFamily i : aFam)
3715  {
3716  std::vector< std::shared_ptr<SfxItemSet> > rStyles;
3717  pDoc->GetIStyleAccess().getAllStyles(rStyles, i);
3718  while (!rStyles.empty())
3719  {
3720  std::shared_ptr<SfxItemSet> pStyle = rStyles.back();
3721  rStyles.pop_back();
3722  const SfxItemSet *pSet = dynamic_cast< const SfxItemSet * >(pStyle.get());
3723 
3725  if (bLatin)
3726  {
3727  assert(pSet);
3728  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_LANGUAGE, false )).GetLanguage();
3729  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3730  aAllLangs.insert( nLang );
3731  }
3732  if (bAsian)
3733  {
3734  assert(pSet);
3735  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CJK_LANGUAGE, false )).GetLanguage();
3736  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3737  aAllLangs.insert( nLang );
3738  }
3739  if (bComplex)
3740  {
3741  assert(pSet);
3742  nLang = dynamic_cast< const SvxLanguageItem & >(pSet->Get( RES_CHRATR_CTL_LANGUAGE, false )).GetLanguage();
3743  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3744  aAllLangs.insert( nLang );
3745  }
3746  }
3747  }
3748 
3749  //TODO/mba: it's a strange concept that a view is needed to retrieve core data
3750  SwWrtShell *pWrtSh = pDocShell->GetWrtShell();
3751  SdrView *pSdrView = pWrtSh->GetDrawView();
3752 
3753  if( pSdrView )
3754  {
3755  SdrOutliner* pOutliner = pSdrView->GetTextEditOutliner();
3756  if(pOutliner)
3757  {
3758  EditEngine& rEditEng = const_cast<EditEngine&>(pOutliner->GetEditEngine());
3759  sal_Int32 nParCount = pOutliner->GetParagraphCount();
3760  for (sal_Int32 nPar=0; nPar<nParCount; nPar++)
3761  {
3762  //every paragraph
3763  std::vector<sal_Int32> aPortions;
3764  rEditEng.GetPortions( nPar, aPortions );
3765 
3766  for ( size_t nPos = aPortions.size(); nPos; )
3767  {
3768  //every position
3769  --nPos;
3770  sal_Int32 nEnd = aPortions[ nPos ];
3771  sal_Int32 nStart = nPos ? aPortions[ nPos - 1 ] : 0;
3772  ESelection aSelection( nPar, nStart, nPar, nEnd );
3773  SfxItemSet aAttr = rEditEng.GetAttribs( aSelection );
3774 
3776  if (bLatin)
3777  {
3778  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE, false )).GetLanguage();
3779  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3780  aAllLangs.insert( nLang );
3781  }
3782  if (bAsian)
3783  {
3784  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CJK, false )).GetLanguage();
3785  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3786  aAllLangs.insert( nLang );
3787  }
3788  if (bComplex)
3789  {
3790  nLang = dynamic_cast< const SvxLanguageItem & >(aAttr.Get( EE_CHAR_LANGUAGE_CTL, false )).GetLanguage();
3791  if (nLang != LANGUAGE_DONTKNOW && nLang != LANGUAGE_SYSTEM)
3792  aAllLangs.insert( nLang );
3793  }
3794  }
3795  }
3796  }
3797  }
3798  // less than nMaxCount languages
3799  if (nMaxCount > static_cast< sal_Int16 >( aAllLangs.size() ))
3800  nMaxCount = static_cast< sal_Int16 >( aAllLangs.size() );
3801 
3802  // build return value
3803  uno::Sequence< lang::Locale > aLanguages( nMaxCount );
3804  lang::Locale* pLanguage = aLanguages.getArray();
3805  if (nMaxCount > 0)
3806  {
3807  sal_Int32 nCount = 0;
3808  for (const auto& rLang : aAllLangs)
3809  {
3810  if (nCount >= nMaxCount)
3811  break;
3812  if (LANGUAGE_NONE != rLang)
3813  {
3814  pLanguage[nCount] = LanguageTag::convertToLocale( rLang );
3815  pLanguage[nCount].Language = SvtLanguageTable::GetLanguageString( rLang );
3816  nCount += 1;
3817  }
3818  }
3819  }
3820 
3821  return aLanguages;
3822 }
3823 
3825  pxDoc(&rxDoc)
3826 {
3827  sTables = SwResId(STR_CONTENT_TYPE_TABLE);
3828  sFrames = SwResId(STR_CONTENT_TYPE_FRAME);
3829  sGraphics = SwResId(STR_CONTENT_TYPE_GRAPHIC);
3830  sOLEs = SwResId(STR_CONTENT_TYPE_OLE);
3831  sSections = SwResId(STR_CONTENT_TYPE_REGION);
3832  sOutlines = SwResId(STR_CONTENT_TYPE_OUTLINE);
3833  sBookmarks = SwResId(STR_CONTENT_TYPE_BOOKMARK);
3834 }
3835 
3837 {
3838 }
3839 
3841 {
3842  Any aRet;
3843  if(!pxDoc)
3844  throw RuntimeException("No document available");
3845  OUString sSuffix("|");
3846  if(rName == sTables)
3847  {
3848  sSuffix += "table";
3849 
3850  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3851  pxDoc->getTextTables(), rName, sSuffix );
3852  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3853  }
3854  else if(rName == sFrames)
3855  {
3856  sSuffix += "frame";
3857  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3858  pxDoc->getTextFrames(), rName, sSuffix );
3859  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3860  }
3861  else if(rName == sSections)
3862  {
3863  sSuffix += "region";
3864  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3865  pxDoc->getTextSections(), rName, sSuffix );
3866  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3867  }
3868  else if(rName == sGraphics)
3869  {
3870  sSuffix += "graphic";
3871  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3872  pxDoc->getGraphicObjects(), rName, sSuffix );
3873  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3874  }
3875  else if(rName == sOLEs)
3876  {
3877  sSuffix += "ole";
3878  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3879  pxDoc->getEmbeddedObjects(), rName, sSuffix );
3880  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3881  }
3882  else if(rName == sOutlines)
3883  {
3884  sSuffix += "outline";
3885  Reference< XNameAccess > xTables = new SwXLinkNameAccessWrapper(
3886  *pxDoc, rName, sSuffix );
3887  aRet <<= Reference< XPropertySet >(xTables, UNO_QUERY);
3888  }
3889  else if(rName == sBookmarks)
3890  {
3891  sSuffix.clear();
3892  Reference< XNameAccess > xBkms = new SwXLinkNameAccessWrapper(
3893  pxDoc->getBookmarks(), rName, sSuffix );
3894  aRet <<= Reference< XPropertySet >(xBkms, UNO_QUERY);
3895  }
3896  else
3897  throw NoSuchElementException();
3898  return aRet;
3899 }
3900 
3902 {
3903  return { sTables,
3904  sFrames,
3905  sGraphics,
3906  sOLEs,
3907  sSections,
3908  sOutlines,
3909  sBookmarks };
3910 }
3911 
3913 {
3914  if( rName == sTables ||
3915  rName == sFrames ||
3916  rName == sGraphics||
3917  rName == sOLEs ||
3918  rName == sSections ||
3919  rName == sOutlines ||
3920  rName == sBookmarks )
3921  return true;
3922  return false;
3923 }
3924 
3926 {
3928 
3929 }
3930 
3932 {
3933  return nullptr != pxDoc;
3934 }
3935 
3937 {
3938  return "SwXLinkTargetSupplier";
3939 }
3940 
3942 {
3943  return cppu::supportsService(this, rServiceName);
3944 }
3945 
3947 {
3948  Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
3949  return aRet;
3950 }
3951 
3953  Reference< XNameAccess > const & xAccess, const OUString& rLinkDisplayName, const OUString& sSuffix ) :
3954  xRealAccess(xAccess),
3955  pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3956  sLinkSuffix(sSuffix),
3957  sLinkDisplayName(rLinkDisplayName),
3958  pxDoc(nullptr)
3959 {
3960 }
3961 
3963  const OUString& rLinkDisplayName, const OUString& sSuffix) :
3964  pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
3965  sLinkSuffix(sSuffix),
3966  sLinkDisplayName(rLinkDisplayName),
3967  pxDoc(&rxDoc)
3968 {
3969 }
3970 
3972 {
3973 }
3974 
3976 {
3977  Any aRet;
3978  bool bFound = false;
3979  //cut link extension and call the real NameAccess
3980  OUString sParam = rName;
3981  OUString sSuffix(sLinkSuffix);
3982  if(sParam.getLength() > sSuffix.getLength() )
3983  {
3984  OUString sCmp = sParam.copy(sParam.getLength() - sSuffix.getLength(),
3985  sSuffix.getLength());
3986  if(sCmp == sSuffix)
3987  {
3988  if(pxDoc)
3989  {
3990  sParam = sParam.copy(0, sParam.getLength() - sSuffix.getLength());
3991  if(!pxDoc->GetDocShell())
3992  throw RuntimeException("No document shell available");
3993  SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
3994  const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
3995 
3996  for (size_t i = 0; i < nOutlineCount && !bFound; ++i)
3997  {
3998  const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
3999  const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
4000  if(sParam == lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
4001  {
4002  Reference< XPropertySet > xOutline = new SwXOutlineTarget(sParam);
4003  aRet <<= xOutline;
4004  bFound = true;
4005  }
4006  }
4007  }
4008  else
4009  {
4010  aRet = xRealAccess->getByName(sParam.copy(0, sParam.getLength() - sSuffix.getLength()));
4012  if(!(aRet >>= xInt))
4013  throw RuntimeException("Could not retrieve property");
4014  Reference< XPropertySet > xProp(xInt, UNO_QUERY);
4015  aRet <<= xProp;
4016  bFound = true;
4017  }
4018  }
4019  }
4020  if(!bFound)
4021  throw NoSuchElementException();
4022  return aRet;
4023 }
4024 
4026 {
4027  Sequence< OUString > aRet;
4028  if(pxDoc)
4029  {
4030  if(!pxDoc->GetDocShell())
4031  throw RuntimeException("No document shell available");
4032 
4033  SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
4034  const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
4035  const size_t nOutlineCount = rOutlineNodes.size();
4036  aRet.realloc(nOutlineCount);
4037  OUString* pResArr = aRet.getArray();
4038  const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
4039  for (size_t i = 0; i < nOutlineCount; ++i)
4040  {
4041  OUString sEntry = lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule) + "|outline";
4042  pResArr[i] = sEntry;
4043  }
4044  }
4045  else
4046  {
4047  Sequence< OUString > aOrg = xRealAccess->getElementNames();
4048  aRet.realloc(aOrg.getLength());
4049  std::transform(aOrg.begin(), aOrg.end(), aRet.begin(),
4050  [this](const OUString& rOrg) -> OUString { return rOrg + sLinkSuffix; });
4051  }
4052  return aRet;
4053 }
4054 
4056 {
4057  bool bRet = false;
4058  OUString sParam(rName);
4059  if(sParam.getLength() > sLinkSuffix.getLength() )
4060  {
4061  OUString sCmp = sParam.copy(sParam.getLength() - sLinkSuffix.getLength(),
4062  sLinkSuffix.getLength());
4063  if(sCmp == sLinkSuffix)
4064  {
4065  sParam = sParam.copy(0, sParam.getLength() - sLinkSuffix.getLength());
4066  if(pxDoc)
4067  {
4068  if(!pxDoc->GetDocShell())
4069  throw RuntimeException("No document shell available");
4070  SwDoc* pDoc = pxDoc->GetDocShell()->GetDoc();
4071  const size_t nOutlineCount = pDoc->GetNodes().GetOutLineNds().size();
4072 
4073  for (size_t i = 0; i < nOutlineCount && !bRet; ++i)
4074  {
4075  const SwOutlineNodes& rOutlineNodes = pDoc->GetNodes().GetOutLineNds();
4076  const SwNumRule* pOutlRule = pDoc->GetOutlineNumRule();
4077  if(sParam ==
4078  lcl_CreateOutlineString(i, rOutlineNodes, pOutlRule))
4079  {
4080  bRet = true;
4081  }
4082  }
4083  }
4084  else
4085  {
4086  bRet = xRealAccess->hasByName(sParam);
4087  }
4088  }
4089  }
4090  return bRet;
4091 }
4092 
4094 {
4096 }
4097 
4099 {
4100  bool bRet = false;
4101  if(pxDoc)
4102  {
4103  OSL_FAIL("not implemented");
4104  }
4105  else
4106  {
4107  bRet = xRealAccess->hasElements();
4108  }
4109  return bRet;
4110 }
4111 
4112 Reference< XPropertySetInfo > SwXLinkNameAccessWrapper::getPropertySetInfo()
4113 {
4114  static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
4115  return xRet;
4116 }
4117 
4119  const OUString& rPropName, const Any& )
4120 {
4121  throw UnknownPropertyException(rPropName);
4122 }
4123 
4124 static Any lcl_GetDisplayBitmap(const OUString& _sLinkSuffix)
4125 {
4126  Any aRet;
4127  OUString sLinkSuffix = _sLinkSuffix;
4128  if(!sLinkSuffix.isEmpty())
4129  sLinkSuffix = sLinkSuffix.copy(1);
4130  OUString sImgId;
4131 
4132  if(sLinkSuffix == "outline")
4133  sImgId = RID_BMP_NAVI_OUTLINE;
4134  else if(sLinkSuffix == "table")
4135  sImgId = RID_BMP_NAVI_TABLE;
4136  else if(sLinkSuffix == "frame")
4137  sImgId = RID_BMP_NAVI_FRAME;
4138  else if(sLinkSuffix == "graphic")
4139  sImgId = RID_BMP_NAVI_GRAPHIC;
4140  else if(sLinkSuffix == "ole")
4141  sImgId = RID_BMP_NAVI_OLE;
4142  else if(sLinkSuffix.isEmpty())
4143  sImgId = RID_BMP_NAVI_BOOKMARK;
4144  else if(sLinkSuffix == "region")
4145  sImgId = RID_BMP_NAVI_REGION;
4146 
4147  if (!sImgId.isEmpty())
4148  {
4149  aRet <<= VCLUnoHelper::CreateBitmap(BitmapEx(sImgId));
4150  }
4151  return aRet;
4152 }
4153 
4154 Any SwXLinkNameAccessWrapper::getPropertyValue(const OUString& rPropertyName)
4155 {
4156  Any aRet;
4157  if( rPropertyName == UNO_LINK_DISPLAY_NAME )
4158  {
4159  aRet <<= sLinkDisplayName;
4160  }
4161  else if( rPropertyName == UNO_LINK_DISPLAY_BITMAP )
4162  {
4164  }
4165  else
4166  throw UnknownPropertyException(rPropertyName);
4167  return aRet;
4168 }
4169 
4171  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4172 {}
4173 
4175  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4176 {}
4177 
4179  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4180 {}
4181 
4183  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4184 {}
4185 
4186 Reference< XNameAccess > SwXLinkNameAccessWrapper::getLinks()
4187 {
4188  return this;
4189 }
4190 
4192 {
4193  return "SwXLinkNameAccessWrapper";
4194 }
4195 
4197 {
4198  return cppu::supportsService(this, rServiceName);
4199 }
4200 
4202 {
4203  Sequence< OUString > aRet { "com.sun.star.document.LinkTargets" };
4204  return aRet;
4205 }
4206 
4207 SwXOutlineTarget::SwXOutlineTarget(const OUString& rOutlineText) :
4208  pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_LINK_TARGET)),
4209  sOutlineText(rOutlineText)
4210 {
4211 }
4212 
4214 {
4215 }
4216 
4217 Reference< XPropertySetInfo > SwXOutlineTarget::getPropertySetInfo()
4218 {
4219  static Reference< XPropertySetInfo > xRet = pPropSet->getPropertySetInfo();
4220  return xRet;
4221 }
4222 
4224  const OUString& rPropertyName, const Any& /*aValue*/)
4225 {
4226  throw UnknownPropertyException(rPropertyName);
4227 }
4228 
4229 Any SwXOutlineTarget::getPropertyValue(const OUString& rPropertyName)
4230 {
4231  if(rPropertyName != UNO_LINK_DISPLAY_NAME)
4232  throw UnknownPropertyException(rPropertyName);
4233 
4234  return Any(sOutlineText);
4235 }
4236 
4238  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4239 {
4240 }
4241 
4243  const OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
4244 {
4245 }
4246 
4248  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4249 {
4250 }
4251 
4253  const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
4254 {
4255 }
4256 
4258 {
4259  return "SwXOutlineTarget";
4260 }
4261 
4262 sal_Bool SwXOutlineTarget::supportsService(const OUString& ServiceName)
4263 {
4264  return cppu::supportsService(this, ServiceName);
4265 }
4266 
4268 {
4269  Sequence<OUString> aRet { "com.sun.star.document.LinkTarget" };
4270 
4271  return aRet;
4272 }
4273 
4275 SvxUnoForbiddenCharsTable ( rDoc.getIDocumentSettingAccess().getForbiddenCharacterTable() )
4276 ,m_pDoc(&rDoc)
4277 {
4278 }
4279 
4281 {
4282 }
4283 
4285 {
4286  Reference<XInterface> xRet;
4287  if(m_pDoc)
4288  {
4289  switch(nWhich)
4290  {
4291  // #i52858#
4292  // assure that Draw model is created, if it doesn't exist.
4294  if(!xDashTable.is())
4296  xRet = xDashTable;
4297  break;
4299  if(!xGradientTable.is())
4301  xRet = xGradientTable;
4302  break;
4304  if(!xHatchTable.is())
4306  xRet = xHatchTable;
4307  break;
4309  if(!xBitmapTable.is())
4311  xRet = xBitmapTable;
4312  break;
4314  if(!xTransGradientTable.is())
4316  xRet = xTransGradientTable;
4317  break;
4319  if(!xMarkerTable.is())
4321  xRet = xMarkerTable;
4322  break;
4324  if(!xDrawDefaults.is())
4325  xDrawDefaults = static_cast<cppu::OWeakObject*>(new SwSvxUnoDrawPool(m_pDoc));
4326  xRet = xDrawDefaults;
4327  break;
4328 #if OSL_DEBUG_LEVEL > 0
4329  default: OSL_FAIL("which table?");
4330 #endif
4331  }
4332  }
4333  return xRet;
4334 }
4335 
4337 {
4338  xDashTable = nullptr;
4339  xGradientTable = nullptr;
4340  xHatchTable = nullptr;
4341  xBitmapTable = nullptr;
4342  xTransGradientTable = nullptr;
4343  xMarkerTable = nullptr;
4344  xDrawDefaults = nullptr;
4345  m_pDoc = nullptr;
4347 }
4348 
4350 {
4351  if(m_pDoc)
4353 }
4354 
4356  SwViewShell& rSh, const SwViewOption &rViewOptions)
4357  : m_pShell(&rSh)
4358  , m_aOldViewOptions( rViewOptions )
4359 {
4360 }
4361 
4363 {
4364  if (m_pShell)
4365  {
4367  }
4368 }
4369 
4370 void
4371 SwViewOptionAdjust_Impl::AdjustViewOptions(SwPrintData const*const pPrtOptions, bool setShowPlaceHoldersInPDF)
4372 {
4373  // to avoid unnecessary reformatting the view options related to the content
4374  // below should only change if necessary, that is if respective content is present
4375  const bool bContainsHiddenChars = m_pShell->GetDoc()->ContainsHiddenChars();
4377  const bool bContainsHiddenFields = pFieldType && pFieldType->HasWriterListeners();
4379  const bool bContainsHiddenParagraphs = pFieldType && pFieldType->HasWriterListeners();
4381  const bool bContainsPlaceHolders = pFieldType && pFieldType->HasWriterListeners();
4382  const bool bContainsFields = m_pShell->IsAnyFieldInDoc();
4383 
4384  SwViewOption aRenderViewOptions( m_aOldViewOptions );
4385 
4386  // disable anything in the view that should not be printed (or exported to PDF) by default
4387  // (see also dialog "Tools/Options - StarOffice Writer - Formatting Aids"
4388  // in section "Display of ...")
4389  aRenderViewOptions.SetParagraph( false ); // paragraph end
4390  aRenderViewOptions.SetSoftHyph( false ); // aka custom hyphens
4391  aRenderViewOptions.SetBlank( false ); // spaces
4392  aRenderViewOptions.SetHardBlank( false ); // non-breaking spaces
4393  aRenderViewOptions.SetTab( false ); // tabs
4394  aRenderViewOptions.SetLineBreak( false ); // breaks (type 1)
4395  aRenderViewOptions.SetPageBreak( false ); // breaks (type 2)
4396  aRenderViewOptions.SetColumnBreak( false ); // breaks (type 3)
4397  bool bVal = pPrtOptions && pPrtOptions->m_bPrintHiddenText;
4398  if (bContainsHiddenChars)
4399  aRenderViewOptions.SetShowHiddenChar( bVal ); // hidden text
4400  if (bContainsHiddenFields)
4401  aRenderViewOptions.SetShowHiddenField( bVal );
4402  if (bContainsHiddenParagraphs)
4403  aRenderViewOptions.SetShowHiddenPara( bVal );
4404 
4405  if (bContainsPlaceHolders)
4406  {
4407  // should always be printed in PDF export!
4408  bVal = !pPrtOptions ? setShowPlaceHoldersInPDF : pPrtOptions->m_bPrintTextPlaceholder;
4409  aRenderViewOptions.SetShowPlaceHolderFields( bVal );
4410  }
4411 
4412  if (bContainsFields)
4413  aRenderViewOptions.SetFieldName( false );
4414 
4415  // we need to set this flag in order to get to see the visible effect of
4416  // some of the above settings (needed for correct rendering)
4417  aRenderViewOptions.SetViewMetaChars( true );
4418 
4419  if (m_aOldViewOptions != aRenderViewOptions) // check if reformatting is necessary
4420  {
4421  aRenderViewOptions.SetPrinting( pPrtOptions != nullptr );
4422  m_pShell->ApplyViewOptions( aRenderViewOptions );
4423  }
4424 }
4425 
4426 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual VclPtr< vcl::Window > getDocWindow() override
Definition: unotxdoc.cxx:3391
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:3975
OUString const & getRuntimeUID() const
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:234
long Width() const
css::uno::Reference< css::uno::XInterface > xDrawDefaults
Definition: unotxdoc.hxx:591
void SetLineBreak(bool b)
Definition: viewopt.hxx:238
static void UpdatePagesForPrintingWithPostItData(SwRenderData &rData, const SwPrintUIOptions &rOptions, sal_Int32 nDocPageCount)
Definition: doc.cxx:775
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:603
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)
static void postMouseEventAsync(const VclPtr< vcl::Window > &xWindow, int nType, const Point &rPos, int nCount, MouseEventModifiers aModifiers, int nButtons, int nModifier)
IDocumentStatistics const & getIDocumentStatistics() const
Definition: doc.cxx:372
bool hasValidSignatures() const
SwViewShell * GetViewShell() const
Definition: pview.hxx:235
virtual ~SwXOutlineTarget() override
Definition: unotxdoc.cxx:4213
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: unotxdoc.cxx:4229
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:2104
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:948
void SetSoftHyph(bool b)
Definition: viewopt.hxx:249
virtual OUString SAL_CALL getImplementationName() override
Definition: unotxdoc.cxx:3936
#define RES_CHRATR_CJK_LANGUAGE
Definition: hintids.hxx:186
css::uno::Reference< css::uno::XInterface > xHatchTable
Definition: unotxdoc.hxx:587
static bool HitAny(const Point &aPos)
#define EE_CHAR_LANGUAGE_CJK
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:3912
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:2310
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
Definition: unotxdoc.cxx:4182
#define WID_DOC_WORD_COUNT
Definition: unomap.hxx:231
void SetZoom(sal_uInt16 n)
Definition: viewopt.hxx:467
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:58
#define RES_CHRATR_LANGUAGE
Definition: hintids.hxx:172
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:1346
#define EE_CHAR_LANGUAGE
const SwRect & GetAnchorRect() const
static SwXTextRanges * Create(SwPaM *const pCursor)
Definition: unoobj2.cxx:1458
virtual ~SwXLinkNameAccessWrapper() override
Definition: unotxdoc.cxx:3971
SwXBodyText * pBodyText
Definition: unotxdoc.hxx:153
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getLinks() override
Definition: unotxdoc.cxx:4186
virtual void CalcLayout()
Definition: viewsh.cxx:971
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:1405
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:3407
IDocumentDeviceAccess const & getIDocumentDeviceAccess() const
Definition: doc.cxx:237
static void lcl_SavePrintUIOptionsToDocumentPrintData(SwDoc &rDoc, const SwPrintUIOptions &rPrintUIOptions, bool bIsPDFEXport)
Definition: unotxdoc.cxx:2427
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:3304
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:2900
static bool lcl_GetBoolProperty(const uno::Sequence< beans::PropertyValue > &rOptions, const char *pPropName)
Definition: unotxdoc.cxx:2319
View of a document.
Definition: pview.hxx:161
SwTextFormatColl * FindTextFormatCollByName(const OUString &rName) const
Definition: doc.hxx:796
void SetRedlineAuthor(const OUString &rAuthor)
Definition: viewprt.cxx:276
SwXOutlineTarget(const OUString &rOutlineText)
Definition: unotxdoc.cxx:4207
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:3597
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:2294
static bool IsPaste(const SwWrtShell &, const TransferableDataHelper &)
Definition: swdtflvr.cxx:1311
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
virtual void SAL_CALL release() override
Definition: unotxdoc.cxx:340
SVX_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoGradientTable_createInstance(SdrModel *pModel)
const SwPosition * GetMark() const
Definition: pam.hxx:209
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
Definition: unotxdoc.cxx:3901
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:2861
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:3569
const SvxLanguageItem & GetLanguage(bool=true) const
Definition: charatr.hxx:92
virtual css::uno::Any SAL_CALL getByName(const OUString &Name) override
Definition: unotxdoc.cxx:3840
#define RES_FRMATR_END
Definition: hintids.hxx:331
virtual void SetMark() override
Unless this is called, the getter method of Mark will return Point.
Definition: viscrs.cxx:605
void SetLandscape(bool b)
Definition: pvprtdat.hxx:64
Definition: doc.hxx:185
virtual sal_Bool SAL_CALL hasElements() override
Definition: unotxdoc.cxx:3931
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:189
comphelper::OInterfaceContainerHelper2 & GetPasteListeners()
Definition: fecopy.cxx:1174
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:2164
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:2158
void AdjustViewOptions(SwPrintData const *const pPrtOptions, bool setShowPlaceHoldersInPDF)
Definition: unotxdoc.cxx:4371
virtual void SAL_CALL acquire() override
::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:1885
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:4247
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: unotxdoc.cxx:2209
std::shared_ptr< SvxForbiddenCharactersTable > mxForbiddenChars
void Pos(const Point &rNew)
Definition: swrect.hxx:167
#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)
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:164
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:34
#define RES_TXTATR_CHARFMT
Definition: hintids.hxx:236
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
virtual OUString SAL_CALL getImplementationName() override
Definition: unotxdoc.cxx:4257
void SetHardBlank(bool b)
Definition: viewopt.hxx:226
virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getRedlines() override
Definition: unotxdoc.cxx:2179
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:286
bool HasWriterListeners() const
Definition: calbck.hxx:208
virtual ~SwXDocumentPropertyHelper() override
Definition: unotxdoc.cxx:4280
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:4088
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
void SetColumnBreak(bool b)
Definition: viewopt.hxx:244
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:2347
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:613
void SetClipboard(css::uno::Reference< css::datatransfer::clipboard::XClipboard > const &xClipboard)
#define UNO_LINK_DISPLAY_BITMAP
Definition: unoprnms.hxx:454
SVX_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoHatchTable_createInstance(SdrModel *pModel)
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:60
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:2065
size_type size() const
Definition: docary.hxx:368
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:1134
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
SVX_DLLPUBLIC css::uno::Reference< css::uno::XInterface > SvxUnoMarkerTable_createInstance(SdrModel *pModel)
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
#define RES_CHRATR_END
Definition: hintids.hxx:208
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:1409
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:2631
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:4174
void SetParagraph(bool b)
Definition: viewopt.hxx:232
const SwRect & getFrameArea() const
Definition: frame.hxx:175
void CalcPagesForPrint(sal_uInt16 nMax)
Definition: vprint.cxx:275
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const
bool getBrowseMode() const
Definition: viewopt.hxx:433
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
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:914
SwCreateDrawTable
Definition: unotxdoc.hxx:579
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: unotxdoc.cxx:4118
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:650
int nCount
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: unotxdoc.cxx:3941
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
sal_Int16 const nValue
void SetTOIAutoMarkURL(const OUString &rSet)
Definition: doc.hxx:949
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:2152
static SfxViewShell * Current()
FindRanges
Definition: cshtyp.hxx:90
void setBrowseMode(bool bSet)
Definition: viewopt.hxx:434
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
OUString const sOutlineText
Definition: unotxdoc.hxx:558
virtual void SAL_CALL refresh() override
Definition: unotxdoc.cxx:2197
Mode eMode
SvxSwAutoFormatFlags & GetSwFlags()
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getLinks() override
Definition: unotxdoc.cxx:2170
virtual void FillRects() override
Definition: viscrs.cxx:614
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
SfxViewShell * GetRenderView(bool &rbIsSwSrcView, const css::uno::Sequence< css::beans::PropertyValue > &rxOptions, bool bIsPDFExport)
Definition: unotxdoc.cxx:2332
#define RES_PARATR_BEGIN
Definition: hintids.hxx:254
virtual void SAL_CALL setCurrentController(const css::uno::Reference< css::frame::XController > &xController) override