Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name unotxdoc.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -D BOOST_ERROR_CODE_HEADER_ONLY -D BOOST_SYSTEM_NO_DEPRECATED -D CPPU_ENV=gcc3 -D LINUX -D OSL_DEBUG_LEVEL=1 -D SAL_LOG_INFO -D SAL_LOG_WARN -D UNIX -D UNX -D X86_64 -D _PTHREADS -D _REENTRANT -D SW_DLLIMPLEMENTATION -D SWUI_DLL_NAME="libswuilo.so" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sw/source/core/inc -I /home/maarten/src/libreoffice/core/sw/source/filter/inc -I /home/maarten/src/libreoffice/core/sw/source/uibase/inc -I /home/maarten/src/libreoffice/core/sw/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sw/sdi -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/sw/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/oovbaapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sw/source/uibase/uno/unotxdoc.cxx

/home/maarten/src/libreoffice/core/sw/source/uibase/uno/unotxdoc.cxx

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

/home/maarten/src/libreoffice/core/include/rtl/ref.hxx

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#ifndef INCLUDED_RTL_REF_HXX
21#define INCLUDED_RTL_REF_HXX
22
23#include "sal/config.h"
24
25#include <cassert>
26#include <cstddef>
27#include <functional>
28#ifdef LIBO_INTERNAL_ONLY1
29#include <type_traits>
30#endif
31
32#include "sal/types.h"
33
34namespace rtl
35{
36
37/** Template reference class for reference type.
38*/
39template <class reference_type>
40class Reference
41{
42 /** The <b>reference_type</b> body pointer.
43 */
44 reference_type * m_pBody;
45
46
47public:
48 /** Constructor...
49 */
50 Reference()
51 : m_pBody (NULL__null)
52 {}
53
54
55 /** Constructor...
56 */
57 Reference (reference_type * pBody, __sal_NoAcquire)
58 : m_pBody (pBody)
59 {
60 }
61
62 /** Constructor...
63 */
64 Reference (reference_type * pBody)
65 : m_pBody (pBody)
66 {
67 if (m_pBody)
68 m_pBody->acquire();
69 }
70
71 /** Copy constructor...
72 */
73 Reference (const Reference<reference_type> & handle)
74 : m_pBody (handle.m_pBody)
75 {
76 if (m_pBody)
17
Assuming field 'm_pBody' is non-null
18
Taking true branch
77 m_pBody->acquire();
78 }
79
80#ifdef LIBO_INTERNAL_ONLY1
81 /** Move constructor...
82 */
83 Reference (Reference<reference_type> && handle) noexcept
84 : m_pBody (handle.m_pBody)
85 {
86 handle.m_pBody = nullptr;
87 }
88#endif
89
90#if defined LIBO_INTERNAL_ONLY1
91 /** Up-casting conversion constructor: Copies interface reference.
92
93 Does not work for up-casts to ambiguous bases.
94
95 @param rRef another reference
96 */
97 template< class derived_type >
98 inline Reference(
99 const Reference< derived_type > & rRef,
100 std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 )
101 : m_pBody (rRef.get())
102 {
103 if (m_pBody)
104 m_pBody->acquire();
105 }
106#endif
107
108 /** Destructor...
109 */
110 ~Reference() COVERITY_NOEXCEPT_FALSE
111 {
112 if (m_pBody
22.1
Field 'm_pBody' is non-null
22.1
Field 'm_pBody' is non-null
22.1
Field 'm_pBody' is non-null
22.1
Field 'm_pBody' is non-null
)
23
Taking true branch
113 m_pBody->release();
24
Calling 'VclReferenceBase::release'
28
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
34
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

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#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
25
Assuming the condition is true
26
Taking true branch
40 delete this;
27
Memory is released
41 }
42#ifdef DBG_UTIL
43#ifndef _WIN32
44 sal_Int32 getRefCount() const { return mnRefCnt; }
45#endif
46#endif
47
48
49private:
50 VclReferenceBase(const VclReferenceBase&) = delete;
51 VclReferenceBase& operator=(const VclReferenceBase&) = delete;
52
53 bool mbDisposed : 1;
54
55protected:
56 VclReferenceBase();
57protected:
58 virtual ~VclReferenceBase();
59
60protected:
61 virtual void dispose();
62
63public:
64 void disposeOnce();
65 bool isDisposed() const { return mbDisposed; }
66
67};
68#endif

/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx

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#ifndef INCLUDED_VCL_PTR_HXX
21#define INCLUDED_VCL_PTR_HXX
22
23#include <sal/config.h>
24
25#include <rtl/ref.hxx>
26
27#include <utility>
28#include <type_traits>
29
30#ifdef DBG_UTIL
31#ifndef _WIN32
32#include <vcl/vclmain.hxx>
33#endif
34#endif
35
36class VclReferenceBase;
37
38namespace vcl::detail {
39
40template<typename>
41constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; }
42
43template<typename T> constexpr bool isIncompleteOrDerivedFromVclReferenceBase(
44 int (*)[sizeof(T)])
45{ return std::is_base_of<VclReferenceBase, T>::value; }
46
47} // namespace vcl::detail
48
49/**
50 * A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for references to vcl::Window subclasses.
51 *
52 * For more details on the design please see vcl/README.lifecycle
53 *
54 * @param reference_type must be a subclass of vcl::Window
55 */
56template <class reference_type>
57class VclPtr
58{
59 static_assert(
60 vcl::detail::isIncompleteOrDerivedFromVclReferenceBase<reference_type>(
61 nullptr),
62 "template argument type must be derived from VclReferenceBase");
63
64 ::rtl::Reference<reference_type> m_rInnerRef;
65
66public:
67 /** Constructor...
68 */
69 VclPtr()
70 : m_rInnerRef()
71 {}
72
73 /** Constructor...
74 */
75 VclPtr (reference_type * pBody)
76 : m_rInnerRef(pBody)
77 {}
78
79 /** Constructor... that doesn't take a ref.
80 */
81 VclPtr (reference_type * pBody, __sal_NoAcquire)
82 : m_rInnerRef(pBody, SAL_NO_ACQUIRE)
83 {}
84
85 /** Up-casting conversion constructor: Copies interface reference.
86
87 Does not work for up-casts to ambiguous bases. For the special case of
88 up-casting to Reference< XInterface >, see the corresponding conversion
89 operator.
90
91 @param rRef another reference
92 */
93 template< class derived_type >
94 VclPtr(
95 const VclPtr< derived_type > & rRef,
96 typename std::enable_if<
97 std::is_base_of<reference_type, derived_type>::value, int>::type
98 = 0 )
99 : m_rInnerRef( static_cast<reference_type*>(rRef) )
100 {
101 }
102
103#if defined(DBG_UTIL) && !defined(_WIN32)
104 virtual ~VclPtr()
105 {
106 assert(m_rInnerRef.get() == nullptr || vclmain::isAlive())(static_cast <bool> (m_rInnerRef.get() == nullptr || vclmain
::isAlive()) ? void (0) : __assert_fail ("m_rInnerRef.get() == nullptr || vclmain::isAlive()"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 106, __extension__ __PRETTY_FUNCTION__))
;
107 // We can be one of the intermediate counts, but if we are the last
108 // VclPtr keeping this object alive, then something forgot to call dispose().
109 assert((!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1)(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
110 && "someone forgot to call dispose()")(static_cast <bool> ((!m_rInnerRef.get() || m_rInnerRef
->isDisposed() || m_rInnerRef->getRefCount() > 1) &&
"someone forgot to call dispose()") ? void (0) : __assert_fail
("(!m_rInnerRef.get() || m_rInnerRef->isDisposed() || m_rInnerRef->getRefCount() > 1) && \"someone forgot to call dispose()\""
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 110, __extension__ __PRETTY_FUNCTION__))
;
111 }
112 VclPtr(VclPtr const &) = default;
113 VclPtr(VclPtr &&) = default;
114 VclPtr & operator =(VclPtr const &) = default;
115 VclPtr & operator =(VclPtr &&) = default;
116#endif
117
118 /**
119 * A construction helper for VclPtr. Since VclPtr types are created
120 * with a reference-count of one - to help fit into the existing
121 * code-flow; this helps us to construct them easily.
122 *
123 * For more details on the design please see vcl/README.lifecycle
124 *
125 * @tparam reference_type must be a subclass of vcl::Window
126 */
127 template<typename... Arg> [[nodiscard]] static VclPtr< reference_type > Create(Arg &&... arg)
128 {
129 return VclPtr< reference_type >( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE );
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
33
Calling 'Reference::get'
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
310 {}
311
312 /**
313 Assignment that releases the last reference.
314 */
315 void disposeAndReset(reference_type *pBody)
316 {
317 if (pBody != this->get()) {
318 VclPtr<reference_type>::disposeAndClear();
319 VclPtr<reference_type>::set(pBody);
320 }
321 }
322
323 /**
324 Assignment that releases the last reference.
325 */
326 ScopedVclPtr<reference_type>& operator = (reference_type * pBody)
327 {
328 disposeAndReset(pBody);
329 return *this;
330 }
331
332 /** Up-casting conversion constructor: Copies interface reference.
333
334 Does not work for up-casts to ambiguous bases. For the special case of
335 up-casting to Reference< XInterface >, see the corresponding conversion
336 operator.
337
338 @param rRef another reference
339 */
340 template< class derived_type >
341 ScopedVclPtr(
342 const VclPtr< derived_type > & rRef,
343 typename std::enable_if<
344 std::is_base_of<reference_type, derived_type>::value, int>::type
345 = 0 )
346 : VclPtr<reference_type>( rRef )
347 {
348 }
349
350 /** Up-casting assignment operator.
351
352 Does not work for up-casts to ambiguous bases.
353
354 @param rRef another VclPtr
355 */
356 template<typename derived_type>
357 typename std::enable_if<
358 std::is_base_of<reference_type, derived_type>::value,
359 ScopedVclPtr &>::type
360 operator =(VclPtr<derived_type> const & rRef)
361 {
362 disposeAndReset(rRef.get());
363 return *this;
364 }
365
366 /**
367 * Override and disallow this, to prevent people accidentally calling it and actually
368 * getting VclPtr::Create and getting a naked VclPtr<> instance
369 */
370 template<typename... Arg> static ScopedVclPtr< reference_type > Create(Arg &&... ) = delete;
371
372 ~ScopedVclPtr()
373 {
374 VclPtr<reference_type>::disposeAndClear();
375 assert(VclPtr<reference_type>::get() == nullptr)(static_cast <bool> (VclPtr<reference_type>::get(
) == nullptr) ? void (0) : __assert_fail ("VclPtr<reference_type>::get() == nullptr"
, "/home/maarten/src/libreoffice/core/include/vcl/vclptr.hxx"
, 375, __extension__ __PRETTY_FUNCTION__))
; // make sure there are no lingering references
376 }
377
378private:
379 // Most likely we don't want this default copy-constructor.
380 ScopedVclPtr (const ScopedVclPtr<reference_type> &) = delete;
381 // And certainly we don't want a default assignment operator.
382 ScopedVclPtr<reference_type>& operator = (const ScopedVclPtr<reference_type> &) = delete;
383 // And disallow reset as that doesn't call disposeAndClear on the original reference
384 void reset() = delete;
385 void reset(reference_type *pBody) = delete;
386
387protected:
388 ScopedVclPtr (reference_type * pBody, __sal_NoAcquire)
389 : VclPtr<reference_type>(pBody, SAL_NO_ACQUIRE)
390 {}
391};
392
393/**
394 * A construction helper for ScopedVclPtr. Since VclPtr types are created
395 * with a reference-count of one - to help fit into the existing
396 * code-flow; this helps us to construct them easily.
397 *
398 * For more details on the design please see vcl/README.lifecycle
399 *
400 * @param reference_type must be a subclass of vcl::Window
401 */
402#if defined _MSC_VER
403#pragma warning(push)
404#pragma warning(disable: 4521) // " multiple copy constructors specified"
405#endif
406template <class reference_type>
407class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type>
408{
409public:
410 template<typename... Arg> ScopedVclPtrInstance(Arg &&... arg)
411 : ScopedVclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
412 {
413 }
414
415 /**
416 * Override and disallow this, to prevent people accidentally calling it and actually
417 * getting VclPtr::Create and getting a naked VclPtr<> instance
418 */
419 template<typename... Arg> static ScopedVclPtrInstance< reference_type > Create(Arg &&...) = delete;
420
421private:
422 // Prevent the above perfect forwarding ctor from hijacking (accidental)
423 // attempts at ScopedVclPtrInstance copy construction (where the hijacking
424 // would typically lead to somewhat obscure error messages); both non-const
425 // and const variants are needed here, as the ScopedVclPtr base class has a
426 // const--variant copy ctor, so the implicitly declared copy ctor for
427 // ScopedVclPtrInstance would also be the const variant, so non-const copy
428 // construction attempts would be hijacked by the perfect forwarding ctor;
429 // but if we only declared a non-const variant here, the const variant would
430 // no longer be implicitly declared (as there would already be an explicitly
431 // declared copy ctor), so const copy construction attempts would then be
432 // hijacked by the perfect forwarding ctor:
433 ScopedVclPtrInstance(ScopedVclPtrInstance &) = delete;
434 ScopedVclPtrInstance(ScopedVclPtrInstance const &) = delete;
435};
436#if defined _MSC_VER
437#pragma warning(pop)
438#endif
439
440#endif // INCLUDED_VCL_PTR_HXX
441
442/* vim:set shiftwidth=4 softtabstop=4 expandtab: */