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 view2.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/uiview/view2.cxx

/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.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 <config_features.h>
21
22#include <com/sun/star/util/SearchAlgorithms2.hpp>
23#include <o3tl/any.hxx>
24#include <vcl/graphicfilter.hxx>
25#include <com/sun/star/sdb/DatabaseContext.hpp>
26#include <com/sun/star/ui/dialogs/XFilePicker3.hpp>
27#include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
28#include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
29#include <com/sun/star/ui/dialogs/ListboxControlActions.hpp>
30#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
31#include <com/sun/star/linguistic2/XProofreadingIterator.hpp>
32#include <com/sun/star/linguistic2/XDictionary.hpp>
33#include <SwCapObjType.hxx>
34#include <SwStyleNameMapper.hxx>
35#include <docary.hxx>
36#include <hintids.hxx>
37#include <SwRewriter.hxx>
38#include <numrule.hxx>
39#include <swundo.hxx>
40#include <svl/PasswordHelper.hxx>
41#include <svl/urihelper.hxx>
42#include <svtools/miscopt.hxx>
43#include <sfx2/passwd.hxx>
44#include <sfx2/sfxdlg.hxx>
45#include <sfx2/filedlghelper.hxx>
46#include <editeng/langitem.hxx>
47#include <svx/viewlayoutitem.hxx>
48#include <svx/zoomslideritem.hxx>
49#include <svx/linkwarn.hxx>
50#include <sfx2/htmlmode.hxx>
51#include <vcl/svapp.hxx>
52#include <sfx2/app.hxx>
53#include <sfx2/request.hxx>
54#include <sfx2/bindings.hxx>
55#include <editeng/lrspitem.hxx>
56#include <unotools/localedatawrapper.hxx>
57#include <unotools/syslocale.hxx>
58#include <editeng/unolingu.hxx>
59#include <vcl/weld.hxx>
60#include <editeng/tstpitem.hxx>
61#include <sfx2/event.hxx>
62#include <sfx2/docfile.hxx>
63#include <sfx2/docfilt.hxx>
64#include <sfx2/fcontnr.hxx>
65#include <editeng/sizeitem.hxx>
66#include <sfx2/dispatch.hxx>
67#include <svl/whiter.hxx>
68#include <svl/ptitem.hxx>
69#include <sfx2/viewfrm.hxx>
70#include <vcl/errinf.hxx>
71#include <tools/urlobj.hxx>
72#include <svx/svdview.hxx>
73#include <swtypes.hxx>
74#include <swwait.hxx>
75#include <redlndlg.hxx>
76#include <gotodlg.hxx>
77#include <view.hxx>
78#include <uivwimp.hxx>
79#include <docsh.hxx>
80#include <doc.hxx>
81#include <printdata.hxx>
82#include <IDocumentDeviceAccess.hxx>
83#include <IDocumentUndoRedo.hxx>
84#include <IDocumentSettingAccess.hxx>
85#include <IDocumentDrawModelAccess.hxx>
86#include <IDocumentStatistics.hxx>
87#include <wrtsh.hxx>
88#include <viewopt.hxx>
89#include <basesh.hxx>
90#include <swmodule.hxx>
91#include <uitool.hxx>
92#include <shellio.hxx>
93#include <fmtinfmt.hxx>
94#include <mdiexp.hxx>
95#include <drawbase.hxx>
96#include <frmatr.hxx>
97#include <frmmgr.hxx>
98#include <pagedesc.hxx>
99#include <section.hxx>
100#include <tox.hxx>
101#include <edtwin.hxx>
102#include <wview.hxx>
103#include <cmdid.h>
104#include <sfx2/strings.hrc>
105#include <sfx2/sfxresid.hxx>
106#include <strings.hrc>
107#include <swerror.h>
108#include <globals.hrc>
109#include <fmtclds.hxx>
110#include <sfx2/templatedlg.hxx>
111#include <dbconfig.hxx>
112#include <dbmgr.hxx>
113#include <reffld.hxx>
114#include <comphelper/lok.hxx>
115
116#include <PostItMgr.hxx>
117
118#include <comphelper/processfactory.hxx>
119#include <LibreOfficeKit/LibreOfficeKitEnums.h>
120
121#include <svx/svxdlg.hxx>
122#include <swabstdlg.hxx>
123#include <fmthdft.hxx>
124#include <unotextrange.hxx>
125#include <docstat.hxx>
126#include <wordcountdialog.hxx>
127#include <sfx2/sidebar/Sidebar.hxx>
128#include <sfx2/sidebar/SidebarController.hxx>
129
130#include <vcl/GraphicNativeTransform.hxx>
131#include <vcl/GraphicNativeMetadata.hxx>
132#include <vcl/settings.hxx>
133#include <i18nutil/searchopt.hxx>
134#include <paratr.hxx>
135#include <rootfrm.hxx>
136#include <frameformats.hxx>
137
138#include <viewimp.hxx>
139#include <pagefrm.hxx>
140
141#include <memory>
142#include <string_view>
143
144#include <basegfx/utils/zoomtools.hxx>
145
146const char sStatusDelim[] = " : ";
147
148using namespace sfx2;
149using namespace ::com::sun::star;
150using namespace ::com::sun::star::i18n;
151using namespace ::com::sun::star::util;
152using namespace ::com::sun::star::uno;
153using namespace ::com::sun::star::lang;
154using namespace ::com::sun::star::scanner;
155using namespace ::com::sun::star::beans;
156using namespace ::com::sun::star::container;
157using namespace ::com::sun::star::sdb;
158using namespace ::com::sun::star::ui::dialogs;
159
160static void lcl_SetAllTextToDefaultLanguage( SwWrtShell &rWrtSh, sal_uInt16 nWhichId )
161{
162 if (!(nWhichId == RES_CHRATR_LANGUAGE ||
163 nWhichId == RES_CHRATR_CJK_LANGUAGE ||
164 nWhichId == RES_CHRATR_CTL_LANGUAGE))
165 return;
166
167 rWrtSh.StartAction();
168 rWrtSh.LockView( true );
169 rWrtSh.Push();
170
171 // prepare to apply new language to all text in document
172 rWrtSh.SelAll();
173 rWrtSh.ExtendedSelectAll();
174
175 // set language attribute to default for all text
176 std::set<sal_uInt16> aAttribs;
177 aAttribs.insert( nWhichId );
178 rWrtSh.ResetAttr( aAttribs );
179
180 rWrtSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
181 rWrtSh.LockView( false );
182 rWrtSh.EndAction();
183
184}
185
186/**
187 * Create string for showing the page number in the statusbar
188 *
189 * @param nPhyNum The physical page number
190 * @param nVirtNum The logical page number (user-assigned)
191 * @param rPgStr User-defined page name (will be shown if different from logical page number)
192 *
193 * @return OUString Formatted string: Page 1 of 10 (Page 1 of 8 to print OR Page nVirtNumv/rPgStr)
194 **/
195OUString SwView::GetPageStr(sal_uInt16 nPhyNum, sal_uInt16 nVirtNum, const OUString& rPgStr)
196{
197 // Show user-defined page number in brackets if any.
198 OUString extra;
199 if (!rPgStr.isEmpty() && std::u16string_view(OUString::number(nPhyNum)) != rPgStr)
200 extra = rPgStr;
201 else if (nPhyNum != nVirtNum)
202 extra = OUString::number(nVirtNum);
203
204 sal_uInt16 nPageCount = GetWrtShell().GetPageCnt();
205 sal_uInt16 nPrintedPhyNum = nPhyNum;
206 sal_uInt16 nPrintedPageCount = nPageCount;
207 if (!GetWrtShell().getIDocumentDeviceAccess().getPrintData().IsPrintEmptyPages())
208 SwDoc::CalculateNonBlankPages(*m_pWrtShell->GetLayout(), nPrintedPageCount, nPrintedPhyNum);
209 // Show printed page numbers only, when they are different
210 OUString aStr( nPageCount != nPrintedPageCount
211 ? SwResId(STR_PAGE_COUNT_PRINTEDreinterpret_cast<char const *>("STR_PAGE_COUNT_PRINTED"
"\004" u8"Page %1 of %2 (Page %3 of %4 to print)")
)
212 : (extra.isEmpty() ? SwResId(STR_PAGE_COUNTreinterpret_cast<char const *>("STR_PAGE_COUNT" "\004" u8"Page %1 of %2"
)
) : SwResId(STR_PAGE_COUNT_CUSTOMreinterpret_cast<char const *>("STR_PAGE_COUNT_CUSTOM" "\004"
u8"Page %1 of %2 (Page %3)")
)));
213 aStr = aStr.replaceFirst("%1", OUString::number(nPhyNum));
214 aStr = aStr.replaceFirst("%2", OUString::number(nPageCount));
215 if (nPageCount != nPrintedPageCount)
216 {
217 aStr = aStr.replaceFirst("%3", OUString::number(nPrintedPhyNum));
218 aStr = aStr.replaceFirst("%4", OUString::number(nPrintedPageCount));
219 }
220 else
221 aStr = aStr.replaceFirst("%3", extra);
222
223 return aStr;
224}
225
226ErrCode SwView::InsertGraphic( const OUString &rPath, const OUString &rFilter,
227 bool bLink, GraphicFilter *pFilter )
228{
229 SwWait aWait( *GetDocShell(), true );
230
231 Graphic aGraphic;
232 ErrCode aResult = ERRCODE_NONEErrCode(0);
233 if( !pFilter )
234 {
235 pFilter = &GraphicFilter::GetGraphicFilter();
236 }
237 aResult = GraphicFilter::LoadGraphic( rPath, rFilter, aGraphic, pFilter );
238
239 if( ERRCODE_NONEErrCode(0) == aResult )
240 {
241 GraphicNativeMetadata aMetadata;
242 if ( aMetadata.read(aGraphic) )
243 {
244 const sal_uInt16 aRotation = aMetadata.getRotation();
245 if (aRotation != 0)
246 {
247 GraphicNativeTransform aTransform( aGraphic );
248 aTransform.rotate( aRotation );
249 }
250 }
251
252 SwFlyFrameAttrMgr aFrameManager( true, GetWrtShellPtr(), Frmmgr_Type::GRF, nullptr );
253 SwWrtShell& rShell = GetWrtShell();
254
255 // #i123922# determine if we really want to insert or replace the graphic at a selected object
256 const bool bReplaceMode(rShell.HasSelection() && SelectionType::Frame == rShell.GetSelectionType());
257
258 if(bReplaceMode)
259 {
260 // #i123922# Do same as in D&D, ReRead graphic and all is done
261 rShell.ReRead(
262 bLink ? rPath : OUString(),
263 bLink ? rFilter : OUString(),
264 &aGraphic);
265 }
266 else
267 {
268 rShell.StartAction();
269 if( bLink )
270 {
271 SwDocShell* pDocSh = GetDocShell();
272 INetURLObject aTemp(
273 pDocSh->HasName() ?
274 pDocSh->GetMedium()->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ) :
275 OUString());
276
277 OUString sURL = URIHelper::SmartRel2Abs(
278 aTemp, rPath, URIHelper::GetMaybeFileHdl() );
279 aGraphic.setOriginURL(sURL);
280 rShell.Insert( sURL, rFilter, aGraphic, &aFrameManager );
281 }
282 else
283 {
284 rShell.Insert( OUString(), OUString(), aGraphic, &aFrameManager );
285 }
286
287 // it is too late after "EndAction" because the Shell can already be destroyed.
288 rShell.EndAction();
289 }
290 }
291 return aResult;
292}
293
294bool SwView::InsertGraphicDlg( SfxRequest& rReq )
295{
296 bool bReturn = false;
297 SwDocShell* pDocShell = GetDocShell();
298 SwDoc* pDoc = pDocShell->GetDoc();
299
300 OUString sGraphicFormat = SwResId(STR_POOLFRM_GRAPHICreinterpret_cast<char const *>("STR_POOLFRM_GRAPHIC" "\004"
u8"Graphics")
);
301
302// No file pickers in a non-desktop (mobile app) build.
303
304#if HAVE_FEATURE_DESKTOP1
305 // when in HTML mode insert only as a link
306 const sal_uInt16 nHtmlMode = ::GetHtmlMode(pDocShell);
307 std::unique_ptr<FileDialogHelper> pFileDlg(new FileDialogHelper(
308 ui::dialogs::TemplateDescription::FILEOPEN_LINK_PREVIEW_IMAGE_TEMPLATE,
309 FileDialogFlags::Graphic, GetFrameWeld()));
310 pFileDlg->SetTitle(SwResId(STR_INSERT_GRAPHICreinterpret_cast<char const *>("STR_INSERT_GRAPHIC" "\004"
u8"Insert Image")
));
311 pFileDlg->SetContext( FileDialogHelper::SW_INSERT_GRAPHIC );
312
313 uno::Reference < XFilePicker3 > xFP = pFileDlg->GetFilePicker();
314 uno::Reference < XFilePickerControlAccess > xCtrlAcc(xFP, UNO_QUERY);
315 if(nHtmlMode & HTMLMODE_ON)
316 {
317 xCtrlAcc->setValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, makeAny(true));
318 xCtrlAcc->enableControl( ExtendedFilePickerElementIds::CHECKBOX_LINK, false);
319 }
320
321 std::vector<OUString> aFormats;
322 const size_t nArrLen = pDoc->GetFrameFormats()->size();
323 for( size_t i = 0; i < nArrLen; ++i )
324 {
325 const SwFrameFormat* pFormat = (*pDoc->GetFrameFormats())[ i ];
326 if(pFormat->IsDefault() || pFormat->IsAuto())
327 continue;
328 aFormats.push_back(pFormat->GetName());
329 }
330
331 // pool formats
332
333 const std::vector<OUString>& rFramePoolArr(
334 SwStyleNameMapper::GetFrameFormatUINameArray());
335 for(const auto & i : rFramePoolArr)
336 {
337 aFormats.push_back(i);
338 }
339
340 std::sort(aFormats.begin(), aFormats.end());
341 aFormats.erase(std::unique(aFormats.begin(), aFormats.end()), aFormats.end());
342
343 Sequence<OUString> aListBoxEntries(aFormats.size());
344 OUString* pEntries = aListBoxEntries.getArray();
345 sal_Int16 nSelect = 0;
346 for( size_t i = 0; i < aFormats.size(); ++i )
347 {
348 pEntries[i] = aFormats[i];
349 if(pEntries[i] == sGraphicFormat)
350 nSelect = i;
351 }
352 try
353 {
354 Any aTemplates(&aListBoxEntries, cppu::UnoType<decltype(aListBoxEntries)>::get());
355
356 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
357 ListboxControlActions::ADD_ITEMS , aTemplates );
358
359 Any aSelectPos(&nSelect, cppu::UnoType<decltype(nSelect)>::get());
360 xCtrlAcc->setValue( ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
361 ListboxControlActions::SET_SELECT_ITEM, aSelectPos );
362 }
363 catch (const Exception&)
364 {
365 OSL_FAIL("control access failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "365" ": "), "%s", "control access failed"); } } while (
false)
;
366 }
367#endif
368
369 const SfxStringItem* pName = rReq.GetArg<SfxStringItem>(SID_INSERT_GRAPHICTypedWhichId<SfxStringItem>( 10000 + 241 ));
370 bool bShowError = !pName;
371 if( pName
372#if HAVE_FEATURE_DESKTOP1
373 || ERRCODE_NONEErrCode(0) == pFileDlg->Execute()
374#endif
375 )
376 {
377
378 OUString aFileName, aFilterName;
379 if ( pName )
380 {
381 aFileName = pName->GetValue();
382 const SfxStringItem* pFilter = rReq.GetArg<SfxStringItem>(FN_PARAM_FILTER((20000 + 1100) + 30));
383 if ( pFilter )
384 aFilterName = pFilter->GetValue();
385 }
386#if HAVE_FEATURE_DESKTOP1
387 else
388 {
389 aFileName = pFileDlg->GetPath();
390 aFilterName = pFileDlg->GetCurrentFilter();
391 rReq.AppendItem( SfxStringItem( SID_INSERT_GRAPHICTypedWhichId<SfxStringItem>( 10000 + 241 ), aFileName ) );
392 rReq.AppendItem( SfxStringItem( FN_PARAM_FILTER((20000 + 1100) + 30), aFilterName ) );
393
394 bool bAsLink = false;
395 if(nHtmlMode & HTMLMODE_ON)
396 bAsLink = true;
397 else
398 {
399 try
400 {
401 Any aVal = xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
402 OSL_ENSURE(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found")do { if (true && (!(aVal.hasValue()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "402" ": "), "%s", "Value CBX_INSERT_AS_LINK not found")
; } } while (false)
;
403 bAsLink = !aVal.hasValue() || *o3tl::doAccess<bool>(aVal);
404 Any aTemplateValue = xCtrlAcc->getValue(
405 ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
406 ListboxControlActions::GET_SELECTED_ITEM );
407 OUString sTmpl;
408 aTemplateValue >>= sTmpl;
409 rReq.AppendItem( SfxStringItem( FN_PARAM_2((20000 + 1100)+61), sTmpl) );
410 }
411 catch (const Exception&)
412 {
413 OSL_FAIL("control access failed")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "413" ": "), "%s", "control access failed"); } } while (
false)
;
414 }
415 }
416 rReq.AppendItem( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), bAsLink ) );
417 }
418 const SfxBoolItem* pAsLink = rReq.GetArg<SfxBoolItem>(FN_PARAM_1((20000 + 1100)+60));
419 const SfxStringItem* pStyle = rReq.GetArg<SfxStringItem>(FN_PARAM_2((20000 + 1100)+61));
420#endif
421
422 bool bAsLink = false;
423
424#if HAVE_FEATURE_DESKTOP1
425 if( nHtmlMode & HTMLMODE_ON )
426 bAsLink = true;
427 else
428 {
429 if ( rReq.GetArgs() )
430 {
431 if ( pAsLink )
432 bAsLink = pAsLink->GetValue();
433 if ( pStyle && !pStyle->GetValue().isEmpty() )
434 sGraphicFormat = pStyle->GetValue();
435 }
436 else
437 {
438 Any aVal = xCtrlAcc->getValue( ExtendedFilePickerElementIds::CHECKBOX_LINK, 0);
439 OSL_ENSURE(aVal.hasValue(), "Value CBX_INSERT_AS_LINK not found")do { if (true && (!(aVal.hasValue()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "439" ": "), "%s", "Value CBX_INSERT_AS_LINK not found")
; } } while (false)
;
440 bAsLink = !aVal.hasValue() || *o3tl::doAccess<bool>(aVal);
441 Any aTemplateValue = xCtrlAcc->getValue(
442 ExtendedFilePickerElementIds::LISTBOX_IMAGE_TEMPLATE,
443 ListboxControlActions::GET_SELECTED_ITEM );
444 OUString sTmpl;
445 aTemplateValue >>= sTmpl;
446 if( !sTmpl.isEmpty() )
447 sGraphicFormat = sTmpl;
448 rReq.AppendItem( SfxStringItem( FN_PARAM_2((20000 + 1100)+61), sGraphicFormat ) );
449 rReq.AppendItem( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), bAsLink ) );
450 }
451
452 // really store as link only?
453 if( bAsLink && SvtMiscOptions().ShowLinkWarningDialog() )
454 {
455 SvxLinkWarningDialog aWarnDlg(GetFrameWeld(), pFileDlg->GetPath());
456 if (aWarnDlg.run() != RET_OK)
457 bAsLink=false; // don't store as link
458 }
459 }
460#endif
461
462 SwWrtShell& rSh = GetWrtShell();
463 rSh.LockPaint();
464 rSh.StartAction();
465
466 SwRewriter aRewriter;
467 aRewriter.AddRule(UndoArg1, SwResId(STR_GRAPHIC_DEFNAMEreinterpret_cast<char const *>("STR_GRAPHIC_DEFNAME" "\004"
u8"Image")
));
468
469 // #i123922# determine if we really want to insert or replace the graphic at a selected object
470 const bool bReplaceMode(rSh.HasSelection() && SelectionType::Frame == rSh.GetSelectionType());
471
472 rSh.StartUndo(SwUndoId::INSERT, &aRewriter);
473
474 ErrCode nError = InsertGraphic( aFileName, aFilterName, bAsLink, &GraphicFilter::GetGraphicFilter() );
475
476 // format not equal to current filter (with autodetection)
477 if( nError == ERRCODE_GRFILTER_FORMATERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 3) )
478 nError = InsertGraphic( aFileName, OUString(), bAsLink, &GraphicFilter::GetGraphicFilter() );
479
480 // #i123922# no new FrameFormat for replace mode, only when new object was created,
481 // else this would reset the current setting for the frame holding the graphic
482 if ( !bReplaceMode && rSh.IsFrameSelected() )
483 {
484 SwFrameFormat* pFormat = pDoc->FindFrameFormatByName( sGraphicFormat );
485 if(!pFormat)
486 pFormat = pDoc->MakeFrameFormat(sGraphicFormat,
487 pDocShell->GetDoc()->GetDfltFrameFormat(),
488 true, false);
489 rSh.SetFrameFormat( pFormat );
490 }
491
492 const char* pResId(nullptr);
493 if( nError == ERRCODE_GRFILTER_OPENERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 1) )
494 pResId = STR_GRFILTER_OPENERRORreinterpret_cast<char const *>("STR_GRFILTER_OPENERROR"
"\004" u8"Image file cannot be opened")
;
495 else if( nError == ERRCODE_GRFILTER_IOERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 2) )
496 pResId = STR_GRFILTER_IOERRORreinterpret_cast<char const *>("STR_GRFILTER_IOERROR" "\004"
u8"Image file cannot be read")
;
497 else if( nError ==ERRCODE_GRFILTER_FORMATERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 3) )
498 pResId = STR_GRFILTER_FORMATERRORreinterpret_cast<char const *>("STR_GRFILTER_FORMATERROR"
"\004" u8"Unknown image format")
;
499 else if( nError ==ERRCODE_GRFILTER_VERSIONERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 4) )
500 pResId = STR_GRFILTER_VERSIONERRORreinterpret_cast<char const *>("STR_GRFILTER_VERSIONERROR"
"\004" u8"This image file version is not supported")
;
501 else if( nError ==ERRCODE_GRFILTER_FILTERERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 5) )
502 pResId = STR_GRFILTER_FILTERERRORreinterpret_cast<char const *>("STR_GRFILTER_FILTERERROR"
"\004" u8"Image filter not found")
;
503 else if( nError ==ERRCODE_GRFILTER_TOOBIGErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 7) )
504 pResId = STR_GRFILTER_TOOBIGreinterpret_cast<char const *>("STR_GRFILTER_TOOBIG" "\004"
u8"Not enough memory to insert the image.")
;
505
506 rSh.EndAction();
507 rSh.UnlockPaint();
508 if (pResId)
509 {
510 if( bShowError )
511 {
512 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetFrameWeld(),
513 VclMessageType::Info, VclButtonsType::Ok,
514 SwResId(pResId)));
515 xInfoBox->run();
516 }
517 rReq.Ignore();
518 }
519 else
520 {
521 // set the specific graphic attributes to the graphic
522 bReturn = true;
523 AutoCaption( GRAPHIC_CAP );
524 rReq.Done();
525 }
526
527 rSh.EndUndo(); // due to possible change of Shell
528 }
529
530 return bReturn;
531}
532
533void SwView::Execute(SfxRequest &rReq)
534{
535 const sal_uInt16 nSlot = rReq.GetSlot();
536 const SfxItemSet* pArgs = rReq.GetArgs();
537 const SfxPoolItem* pItem;
538 bool bIgnore = false;
539 switch( nSlot )
1
Control jumps to 'case 20602:' at line 553
540 {
541 case SID_INSPECTOR_DECK((20000 + 2550) + 13):
542 {
543 OUString deckId;
544 if (nSlot == SID_INSPECTOR_DECK((20000 + 2550) + 13))
545 deckId = "InspectorDeck";
546 ::sfx2::sidebar::Sidebar::ToggleDeck(deckId, GetViewFrame());
547 }
548 break;
549 case SID_CREATE_SW_DRAWVIEW( 10000 + 860 ):
550 m_pWrtShell->getIDocumentDrawModelAccess().GetOrCreateDrawModel();
551 break;
552
553 case FN_LINE_NUMBERING_DLG((20000 + 600) + 2 ):
554 {
555 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
556 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclSwViewDialog(*this));
2
Calling constructor for 'ScopedVclPtr<VclAbstractDialog>'
9
Returning from constructor for 'ScopedVclPtr<VclAbstractDialog>'
10
Calling implicit destructor for 'VclPtr<VclAbstractDialog>'
11
Calling '~Reference'
18
Returning from '~Reference'
19
Returning from destructor for 'VclPtr<VclAbstractDialog>'
557 VclAbstractDialog::AsyncContext aContext;
558 aContext.maEndDialogFn = [](sal_Int32){};
559 pDlg->StartExecuteAsync(aContext);
20
Calling 'VclPtr::operator->'
560 break;
561 }
562 case FN_EDIT_LINK_DLG((20000 + 100) + 9 ):
563 EditLinkDlg();
564 break;
565 case FN_REFRESH_VIEW((20000 + 200) + 1):
566 GetEditWin().Invalidate();
567 break;
568 case FN_PAGEUP((20000 + 900) + 37):
569 case FN_PAGEUP_SEL(((20000) + 800) + 29):
570 case FN_PAGEDOWN((20000 + 900) + 38):
571 case FN_PAGEDOWN_SEL(((20000) + 800) + 30):
572 {
573 tools::Rectangle aVis( GetVisArea() );
574 SwEditWin& rTmpWin = GetEditWin();
575 if ( FN_PAGEUP((20000 + 900) + 37) == nSlot || FN_PAGEUP_SEL(((20000) + 800) + 29) == nSlot )
576 PageUpCursor(FN_PAGEUP_SEL(((20000) + 800) + 29) == nSlot);
577 else
578 PageDownCursor(FN_PAGEDOWN_SEL(((20000) + 800) + 30) == nSlot);
579
580 rReq.SetReturnValue(SfxBoolItem(nSlot,
581 aVis != GetVisArea()));
582 //#i42732# - notify the edit window that from now on we do not use the input language
583 rTmpWin.SetUseInputLanguage( false );
584 }
585 break;
586 case SID_ZOOM_IN(10000 + 98):
587 case SID_ZOOM_OUT(10000 + 97):
588 {
589 long nFact = m_pWrtShell->GetViewOptions()->GetZoom();
590 if (SID_ZOOM_OUT(10000 + 97) == nSlot)
591 nFact = basegfx::zoomtools::zoomIn(nFact);
592 else
593 nFact = basegfx::zoomtools::zoomOut(nFact);
594 SetZoom(SvxZoomType::PERCENT, nFact);
595 }
596 break;
597 case FN_TO_PREV_PAGE((20000 + 900) + 96):
598 case FN_TO_NEXT_PAGE((20000 + 900) + 95):
599 {
600 sal_uInt16 nPage = 0;
601 if (m_pWrtShell->IsCursorVisible())
602 nPage = m_pWrtShell->GetCursor()->GetPageNum();
603 else
604 {
605 SwFrame* pPageFrame = m_pWrtShell->Imp()->GetFirstVisPage(m_pWrtShell->GetOut());
606 if (pPageFrame)
607 nPage = pPageFrame->GetPhyPageNum();
608 }
609 if (nPage != 0)
610 {
611 sal_uInt16 nOldPage(nPage);
612 if (FN_TO_PREV_PAGE((20000 + 900) + 96) == nSlot && nPage > 1)
613 nPage--;
614 else if (FN_TO_NEXT_PAGE((20000 + 900) + 95) == nSlot && nPage < m_pWrtShell->GetPageCount())
615 nPage++;
616 if (nPage != nOldPage)
617 {
618 m_pWrtShell->LockPaint();
619 if (IsDrawMode())
620 LeaveDrawCreate();
621 m_pWrtShell->EnterStdMode();
622 m_pWrtShell->GotoPage(nPage, true);
623 // set visible area (borrowed from SwView::PhyPageUp/Down)
624 const Point aPt(m_aVisArea.Left(), m_pWrtShell->GetPagePos(nPage).Y());
625 Point aAlPt(AlignToPixel(aPt));
626 if(aPt.Y() != aAlPt.Y())
627 aAlPt.AdjustY(3 * GetEditWin().PixelToLogic(Size(0, 1)).Height());
628 SetVisArea(aAlPt);
629 m_pWrtShell->UnlockPaint();
630 }
631 }
632 }
633 break;
634 case FN_REDLINE_ON((20000 + 1800) + 25):
635 {
636 if( pArgs &&
637 SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem ))
638 {
639 IDocumentRedlineAccess& rIDRA = m_pWrtShell->getIDocumentRedlineAccess();
640 Sequence <sal_Int8> aPasswd = rIDRA.GetRedlinePassword();
641 if( aPasswd.hasElements() )
642 {
643 OSL_ENSURE( !static_cast<const SfxBoolItem*>(pItem)->GetValue(), "SwView::Execute(): password set and redlining off doesn't match!" )do { if (true && (!(!static_cast<const SfxBoolItem
*>(pItem)->GetValue()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "643" ": "), "%s", "SwView::Execute(): password set and redlining off doesn't match!"
); } } while (false)
;
644
645 // dummy password from OOXML import: only confirmation dialog
646 if (aPasswd.getLength() == 1 && aPasswd[0] == 1)
647 {
648 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(m_pWrtShell->GetView().GetFrameWeld(),
649 VclMessageType::Warning, VclButtonsType::YesNo,
650 SfxResId(RID_SVXSTR_END_REDLINING_WARNINGreinterpret_cast<char const *>("RID_SVXSTR_END_REDLINING_WARNING"
"\004" u8"This action will exit the change recording mode.\nNo information about changes will be recorded from now on.\n\nExit change recording mode?\n\n"
)
)));
651 xWarn->set_default_response(RET_NO);
652 if (xWarn->run() == RET_YES)
653 rIDRA.SetRedlinePassword(Sequence <sal_Int8> ());
654 else
655 break;
656 }
657 else
658 {
659 // xmlsec05: new password dialog
660 SfxPasswordDialog aPasswdDlg(GetFrameWeld());
661 aPasswdDlg.SetMinLen(1);
662 //#i69751# the result of Execute() can be ignored
663 (void)aPasswdDlg.run();
664 OUString sNewPasswd(aPasswdDlg.GetPassword());
665 Sequence <sal_Int8> aNewPasswd = rIDRA.GetRedlinePassword();
666 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
667 if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd))
668 rIDRA.SetRedlinePassword(Sequence <sal_Int8> ());
669 else
670 { // xmlsec05: message box for wrong password
671 break;
672 }
673 }
674 }
675
676 const RedlineFlags nOn = static_cast<const SfxBoolItem*>(pItem)->GetValue()
677 ? RedlineFlags::On : RedlineFlags::NONE;
678 const RedlineFlags nMode = m_pWrtShell->GetRedlineFlags();
679 m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn);
680
681 // Notify all view shells of this document, as the track changes mode is document-global.
682 SwDocShell* pDocShell = GetDocShell();
683 for (SfxViewFrame* pViewFrame = SfxViewFrame::GetFirst(pDocShell); pViewFrame; pViewFrame = SfxViewFrame::GetNext(*pViewFrame, pDocShell))
684 {
685 pViewFrame->GetBindings().Invalidate(FN_REDLINE_ON((20000 + 1800) + 25));
686 pViewFrame->GetBindings().Update(FN_REDLINE_ON((20000 + 1800) + 25));
687 }
688 }
689 }
690 break;
691 case FN_REDLINE_PROTECT((20000 + 1800) + 23) :
692 {
693 IDocumentRedlineAccess& rIDRA = m_pWrtShell->getIDocumentRedlineAccess();
694 Sequence <sal_Int8> aPasswd = rIDRA.GetRedlinePassword();
695 if( pArgs && SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem )
696 && static_cast<const SfxBoolItem*>(pItem)->GetValue() == aPasswd.hasElements() )
697 break;
698
699 // xmlsec05: new password dialog
700 // message box for wrong password
701 SfxPasswordDialog aPasswdDlg(GetFrameWeld());
702 aPasswdDlg.SetMinLen(1);
703 if (!aPasswd.hasElements())
704 aPasswdDlg.ShowExtras(SfxShowExtras::CONFIRM);
705 if (aPasswdDlg.run())
706 {
707 RedlineFlags nOn = RedlineFlags::On;
708 OUString sNewPasswd(aPasswdDlg.GetPassword());
709 Sequence <sal_Int8> aNewPasswd =
710 rIDRA.GetRedlinePassword();
711 SvPasswordHelper::GetHashPassword( aNewPasswd, sNewPasswd );
712 if(!aPasswd.hasElements())
713 {
714 rIDRA.SetRedlinePassword(aNewPasswd);
715 }
716 else if(SvPasswordHelper::CompareHashPassword(aPasswd, sNewPasswd))
717 {
718 rIDRA.SetRedlinePassword(Sequence <sal_Int8> ());
719 nOn = RedlineFlags::NONE;
720 }
721 const RedlineFlags nMode = rIDRA.GetRedlineFlags();
722 m_pWrtShell->SetRedlineFlagsAndCheckInsMode( (nMode & ~RedlineFlags::On) | nOn);
723 rReq.AppendItem( SfxBoolItem( FN_REDLINE_PROTECT((20000 + 1800) + 23), !(nMode&RedlineFlags::On) ) );
724 }
725 else
726 bIgnore = true;
727 }
728 break;
729 case FN_REDLINE_SHOW((20000 + 1800) + 26):
730
731 if( pArgs &&
732 SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem))
733 {
734 // tdf#125754 avoid recursive layout
735 // because all views share the layout, have to use AllAction
736 m_pWrtShell->StartAllAction();
737 m_pWrtShell->GetLayout()->SetHideRedlines(
738 !static_cast<const SfxBoolItem*>(pItem)->GetValue());
739 m_pWrtShell->EndAllAction();
740 if (m_pWrtShell->IsRedlineOn())
741 m_pWrtShell->SetInsMode();
742 }
743 break;
744 case FN_MAILMERGE_SENDMAIL_CHILDWINDOW((20000 + 1400) + 5):
745 case FN_REDLINE_ACCEPT((20000 + 1800) + 29):
746 GetViewFrame()->ToggleChildWindow(nSlot);
747 break;
748 case FN_REDLINE_ACCEPT_DIRECT((20000 + 1800) + 37):
749 case FN_REDLINE_REJECT_DIRECT((20000 + 1800) + 38):
750 case FN_REDLINE_ACCEPT_TONEXT((20000 + 1800) + 45):
751 case FN_REDLINE_REJECT_TONEXT((20000 + 1800) + 46):
752 {
753 SwDoc *pDoc = m_pWrtShell->GetDoc();
754 SwPaM *pCursor = m_pWrtShell->GetCursor();
755 const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
756 SwRedlineTable::size_type nRedline = SwRedlineTable::npos;
757 if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
758 {
759 const sal_Int64 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
760 for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
761 {
762 if (nChangeId == rRedlineTable[i]->GetId())
763 nRedline = i;
764 }
765 }
766
767 if( pCursor->HasMark() && nRedline == SwRedlineTable::npos)
768 {
769 if (FN_REDLINE_ACCEPT_DIRECT((20000 + 1800) + 37) == nSlot || FN_REDLINE_ACCEPT_TONEXT((20000 + 1800) + 45) == nSlot)
770 m_pWrtShell->AcceptRedlinesInSelection();
771 else
772 m_pWrtShell->RejectRedlinesInSelection();
773 }
774 else
775 {
776 // We check for a redline at the start of the selection/cursor, not the point.
777 // This ensures we work properly with FN_REDLINE_NEXT_CHANGE, which leaves the
778 // point at the *end* of the redline and the mark at the start (so GetRedline
779 // would return NULL if called on the point)
780 const SwRangeRedline* pRedline = nullptr;
781 if (nRedline != SwRedlineTable::npos)
782 {
783 // A redline was explicitly requested by specifying an
784 // index, don't guess based on the cursor position.
785
786 if (nRedline < rRedlineTable.size())
787 pRedline = rRedlineTable[nRedline];
788 }
789 else
790 pRedline = pDoc->getIDocumentRedlineAccess().GetRedline(*pCursor->Start(), &nRedline);
791
792 assert(pRedline != nullptr)(static_cast <bool> (pRedline != nullptr) ? void (0) : __assert_fail
("pRedline != nullptr", "/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
, 792, __extension__ __PRETTY_FUNCTION__))
;
793 if (pRedline)
794 {
795 if (FN_REDLINE_ACCEPT_DIRECT((20000 + 1800) + 37) == nSlot || FN_REDLINE_ACCEPT_TONEXT((20000 + 1800) + 45) == nSlot)
796 m_pWrtShell->AcceptRedline(nRedline);
797 else
798 m_pWrtShell->RejectRedline(nRedline);
799 }
800 }
801 if (FN_REDLINE_ACCEPT_TONEXT((20000 + 1800) + 45) == nSlot || FN_REDLINE_REJECT_TONEXT((20000 + 1800) + 46) == nSlot)
802 {
803 // Go to next change after accepting or rejecting one (tdf#101977)
804 GetViewFrame()->GetDispatcher()->Execute(FN_REDLINE_NEXT_CHANGE((20000 + 1800) + 41), SfxCallMode::ASYNCHRON);
805 }
806 }
807 break;
808
809 case FN_REDLINE_NEXT_CHANGE((20000 + 1800) + 41):
810 {
811 // If a parameter is provided, try going to the nth change, not to
812 // the next one.
813 SwDoc* pDoc = m_pWrtShell->GetDoc();
814 const SwRedlineTable& rRedlineTable = pDoc->getIDocumentRedlineAccess().GetRedlineTable();
815 SwRedlineTable::size_type nRedline = SwRedlineTable::npos;
816 if (pArgs && pArgs->GetItemState(nSlot, false, &pItem) == SfxItemState::SET)
817 {
818 const sal_uInt32 nChangeId = static_cast<const SfxUInt32Item*>(pItem)->GetValue();
819 for (SwRedlineTable::size_type i = 0; i < rRedlineTable.size(); ++i)
820 {
821 if (nChangeId == rRedlineTable[i]->GetId())
822 nRedline = i;
823 }
824 }
825
826 const SwRangeRedline *pNext = nullptr;
827 if (nRedline < rRedlineTable.size())
828 pNext = m_pWrtShell->GotoRedline(nRedline, true);
829 else
830 pNext = m_pWrtShell->SelNextRedline();
831
832 if (pNext)
833 {
834 if (comphelper::LibreOfficeKit::isActive())
835 {
836 OString aPayload(".uno:CurrentTrackedChangeId=");
837 sal_uInt32 nRedlineId = pNext->GetId();
838 aPayload += OString::number(nRedlineId);
839 libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload.getStr());
840 }
841
842 m_pWrtShell->SetInSelect();
843 }
844
845 }
846 break;
847
848 case FN_REDLINE_PREV_CHANGE((20000 + 1800) + 42):
849 {
850 const SwRangeRedline *pPrev = m_pWrtShell->SelPrevRedline();
851
852 if (pPrev)
853 {
854 if (comphelper::LibreOfficeKit::isActive())
855 {
856 OString aPayload(".uno:CurrentTrackedChangeId=");
857 sal_uInt32 nRedlineId = pPrev->GetId();
858 aPayload += OString::number(nRedlineId);
859 libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, aPayload.getStr());
860 }
861
862 m_pWrtShell->SetInSelect();
863 }
864 }
865 break;
866
867 case SID_DOCUMENT_COMPARE(5000 + 1586):
868 case SID_DOCUMENT_MERGE(5000 + 1587):
869 {
870 OUString sFileName, sFilterName;
871 sal_Int16 nVersion = 0;
872 bool bHasFileName = false;
873 m_pViewImpl->SetParam( 0 );
874 bool bNoAcceptDialog = false;
875
876 if( pArgs )
877 {
878 if( SfxItemState::SET == pArgs->GetItemState( SID_FILE_NAME(5000 + 507), false, &pItem ))
879 sFileName = static_cast<const SfxStringItem*>(pItem)->GetValue();
880 bHasFileName = !sFileName.isEmpty();
881
882 if( SfxItemState::SET == pArgs->GetItemState( SID_FILTER_NAME(5000 + 530), false, &pItem ))
883 sFilterName = static_cast<const SfxStringItem*>(pItem)->GetValue();
884
885 if( SfxItemState::SET == pArgs->GetItemState( SID_VERSION(5000 + 1583), false, &pItem ))
886 {
887 nVersion = static_cast<const SfxInt16Item *>(pItem)->GetValue();
888 m_pViewImpl->SetParam( nVersion );
889 }
890 if( SfxItemState::SET == pArgs->GetItemState( SID_NO_ACCEPT_DIALOG(5000 + 1710), false, &pItem ))
891 {
892 bNoAcceptDialog = static_cast<const SfxBoolItem *>(pItem)->GetValue();
893 }
894 }
895
896 m_pViewImpl->InitRequest( rReq );
897 long nFound = InsertDoc( nSlot, sFileName, sFilterName, nVersion );
898
899 if ( bHasFileName )
900 {
901 rReq.SetReturnValue( SfxInt32Item( nSlot, nFound ));
902
903 if (nFound > 0 && !bNoAcceptDialog) // show Redline browser
904 {
905 SfxViewFrame* pVFrame = GetViewFrame();
906 pVFrame->ShowChildWindow(FN_REDLINE_ACCEPT((20000 + 1800) + 29));
907
908 // re-initialize the Redline dialog
909 const sal_uInt16 nId = SwRedlineAcceptChild::GetChildWindowId();
910 SwRedlineAcceptChild *pRed = static_cast<SwRedlineAcceptChild*>(
911 pVFrame->GetChildWindow(nId));
912 if (pRed)
913 pRed->ReInitDlg(GetDocShell());
914 }
915 }
916 else
917 bIgnore = true;
918 }
919 break;
920 case FN_SYNC_LABELS((20000 + 1600) + 143):
921 GetViewFrame()->ShowChildWindow(nSlot);
922 break;
923 case FN_ESCAPE((20000 + 900) + 41):
924 {
925 if ( m_pWrtShell->HasDrawViewDrag() )
926 {
927 m_pWrtShell->BreakDrag();
928 m_pWrtShell->EnterSelFrameMode();
929 }
930 else if ( m_pWrtShell->IsDrawCreate() )
931 {
932 GetDrawFuncPtr()->BreakCreate();
933 AttrChangedNotify(nullptr); // shell change if needed
934 }
935 else if ( m_pWrtShell->HasSelection() || IsDrawMode() )
936 {
937 SdrView *pSdrView = m_pWrtShell->HasDrawView() ? m_pWrtShell->GetDrawView() : nullptr;
938 if(pSdrView && pSdrView->AreObjectsMarked() &&
939 pSdrView->GetHdlList().GetFocusHdl())
940 {
941 const_cast<SdrHdlList&>(pSdrView->GetHdlList()).ResetFocusHdl();
942 }
943 else
944 {
945 if(pSdrView)
946 {
947 LeaveDrawCreate();
948 Point aPt(LONG_MIN(-9223372036854775807L -1L), LONG_MIN(-9223372036854775807L -1L));
949 //go out of the frame
950 m_pWrtShell->SelectObj(aPt, SW_LEAVE_FRAME4);
951 SfxBindings& rBind = GetViewFrame()->GetBindings();
952 rBind.Invalidate( SID_ATTR_SIZETypedWhichId<SvxSizeItem>( 10000 + 224 ) );
953 }
954 m_pWrtShell->EnterStdMode();
955 AttrChangedNotify(nullptr); // shell change if necessary
956 }
957 }
958 else if ( GetEditWin().GetApplyTemplate() )
959 {
960 GetEditWin().SetApplyTemplate(SwApplyTemplate());
961 }
962 else if( static_cast<SfxObjectShell*>(GetDocShell())->IsInPlaceActive() )
963 {
964 Escape();
965 }
966 else if ( GetEditWin().IsChainMode() )
967 {
968 GetEditWin().SetChainMode( false );
969 }
970 else if( m_pWrtShell->GetFlyFrameFormat() )
971 {
972 const SwFrameFormat* pFormat = m_pWrtShell->GetFlyFrameFormat();
973 if(m_pWrtShell->GotoFly( pFormat->GetName(), FLYCNTTYPE_FRM ))
974 {
975 m_pWrtShell->HideCursor();
976 m_pWrtShell->EnterSelFrameMode();
977 }
978 }
979 else
980 {
981 SfxBoolItem aItem( SID_WIN_FULLSCREEN(5000 + 627), false );
982 GetViewFrame()->GetDispatcher()->ExecuteList(SID_WIN_FULLSCREEN(5000 + 627),
983 SfxCallMode::RECORD, { &aItem });
984 bIgnore = true;
985 }
986 }
987 break;
988 case SID_ATTR_BORDER_INNERTypedWhichId<SvxBoxInfoItem>( 10000 + 23 ):
989 case SID_ATTR_BORDER_OUTER( 10000 + 24 ):
990 case SID_ATTR_BORDER_SHADOW( 10000 + 25 ):
991 if(pArgs)
992 m_pWrtShell->SetAttrSet(*pArgs);
993 break;
994
995 case SID_ATTR_PAGETypedWhichId<SvxPageItem>( 10000 + 50 ):
996 case SID_ATTR_PAGE_SIZETypedWhichId<SvxSizeItem>( 10000 + 51 ):
997 case SID_ATTR_PAGE_MAXSIZETypedWhichId<SvxSizeItem>( 10000 + 52 ):
998 case SID_ATTR_PAGE_PAPERBINTypedWhichId<SvxPaperBinItem>( 10000 + 54 ):
999 case SID_ATTR_PAGE_EXT1( 10000 + 55 ):
1000 case FN_PARAM_FTN_INFO((20000 + 1100)+23):
1001 {
1002 if(pArgs)
1003 {
1004 const size_t nCurIdx = m_pWrtShell->GetCurPageDesc();
1005 SwPageDesc aPageDesc( m_pWrtShell->GetPageDesc( nCurIdx ) );
1006 ::ItemSetToPageDesc( *pArgs, aPageDesc );
1007 // change the descriptor of the core
1008 m_pWrtShell->ChgPageDesc( nCurIdx, aPageDesc );
1009 }
1010 }
1011 break;
1012 case FN_GOTO_PAGE((20000 + 600) + 59 ):
1013 {
1014 SwGotoPageDlg aDlg(GetViewFrame()->GetWindow().GetFrameWeld(), &GetViewFrame()->GetBindings());
1015 if (aDlg.run() == RET_OK)
1016 GetWrtShell().GotoPage(aDlg.GetPageSelection(), true);
1017 }
1018 break;
1019 case FN_EDIT_CURRENT_TOX((20000 + 1800) + 32):
1020 {
1021 GetViewFrame()->GetDispatcher()->Execute(
1022 FN_INSERT_MULTI_TOX((20000 + 1400) + 20), SfxCallMode::ASYNCHRON);
1023 }
1024 break;
1025 case FN_UPDATE_CUR_TOX((20000 + 600) + 54):
1026 {
1027 const SwTOXBase* pBase = m_pWrtShell->GetCurTOX();
1028 if(pBase)
1029 {
1030 // tdf#106374: don't jump view on the update
1031 const bool bWasLocked = m_pWrtShell->IsViewLocked();
1032 m_pWrtShell->LockView(true);
1033 m_pWrtShell->StartAction();
1034 if(TOX_INDEX == pBase->GetType())
1035 m_pWrtShell->ApplyAutoMark();
1036 m_pWrtShell->UpdateTableOf( *pBase );
1037 m_pWrtShell->EndAction();
1038 if (!bWasLocked)
1039 m_pWrtShell->LockView(false);
1040 }
1041 }
1042 break;
1043 case FN_UPDATE_TOX((20000 + 600) + 53):
1044 {
1045 m_pWrtShell->StartAction();
1046 m_pWrtShell->EnterStdMode();
1047 bool bOldCursorInReadOnly = m_pWrtShell->IsReadOnlyAvailable();
1048 m_pWrtShell->SetReadOnlyAvailable( true );
1049
1050 for( int i = 0; i < 2; ++i )
1051 {
1052 if( m_pWrtShell->GetTOXCount() == 1 )
1053 ++i;
1054
1055 while( m_pWrtShell->GotoPrevTOXBase() )
1056 ; // jump to the first "table of ..."
1057
1058 // if we are not in one, jump to next
1059 const SwTOXBase* pBase = m_pWrtShell->GetCurTOX();
1060 if( !pBase )
1061 {
1062 m_pWrtShell->GotoNextTOXBase();
1063 pBase = m_pWrtShell->GetCurTOX();
1064 }
1065
1066 bool bAutoMarkApplied = false;
1067 while( pBase )
1068 {
1069 if(TOX_INDEX == pBase->GetType() && !bAutoMarkApplied)
1070 {
1071 m_pWrtShell->ApplyAutoMark();
1072 bAutoMarkApplied = true;
1073 }
1074 // pBase is needed only for the interface. Should be changed in future! (JP 1996)
1075 m_pWrtShell->UpdateTableOf( *pBase );
1076
1077 if( m_pWrtShell->GotoNextTOXBase() )
1078 pBase = m_pWrtShell->GetCurTOX();
1079 else
1080 pBase = nullptr;
1081 }
1082 }
1083 m_pWrtShell->SetReadOnlyAvailable( bOldCursorInReadOnly );
1084 m_pWrtShell->EndAction();
1085 }
1086 break;
1087 case SID_ATTR_BRUSH( 10000 + 1 ):
1088 {
1089 if(pArgs && SfxItemState::SET == pArgs->GetItemState(RES_BACKGROUND, false, &pItem))
1090 {
1091 const size_t nCurIdx = m_pWrtShell->GetCurPageDesc();
1092 SwPageDesc aDesc( m_pWrtShell->GetPageDesc( nCurIdx ));
1093 SwFrameFormat& rMaster = aDesc.GetMaster();
1094 rMaster.SetFormatAttr(*pItem);
1095 m_pWrtShell->ChgPageDesc( nCurIdx, aDesc);
1096 }
1097 }
1098 break;
1099 case SID_CLEARHISTORY(5000 + 703):
1100 {
1101 m_pWrtShell->DelAllUndoObj();
1102 }
1103 break;
1104 case SID_UNDO(5000 + 701):
1105 {
1106 m_pShell->ExecuteSlot(rReq);
1107 }
1108 break;
1109#if defined(_WIN32) || defined UNX1
1110 case SID_TWAIN_SELECT( 10000 + 331 ):
1111 case SID_TWAIN_TRANSFER( 10000 + 332 ):
1112 GetViewImpl()->ExecuteScan( rReq );
1113 break;
1114#endif
1115
1116 case SID_ATTR_DEFTABSTOP(((((10000 + 1499) + 1) + 499) + 1) + 14):
1117 {
1118 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_DEFTABSTOP(((((10000 + 1499) + 1) + 499) + 1) + 14), false, &pItem))
1119 {
1120 SvxTabStopItem aDefTabs( 0, 0, SvxTabAdjust::Default, RES_PARATR_TABSTOP );
1121 const sal_uInt16 nTab = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1122 MakeDefTabs( nTab, aDefTabs );
1123 m_pWrtShell->SetDefault( aDefTabs );
1124 }
1125 }
1126 break;
1127 case SID_ATTR_LANGUAGE(((((10000 + 1499) + 1) + 499) + 1) + 7) :
1128 if(pArgs && SfxItemState::SET == pArgs->GetItemState(SID_ATTR_LANGUAGE(((((10000 + 1499) + 1) + 499) + 1) + 7), false, &pItem))
1129 {
1130 SvxLanguageItem aLang(static_cast<const SvxLanguageItem*>(pItem)->GetLanguage(), RES_CHRATR_LANGUAGE);
1131 m_pWrtShell->SetDefault( aLang );
1132 lcl_SetAllTextToDefaultLanguage( *m_pWrtShell, RES_CHRATR_LANGUAGE );
1133 }
1134 break;
1135 case SID_ATTR_CHAR_CTL_LANGUAGE( 10000 + 894 ):
1136 if(pArgs && SfxItemState::SET == pArgs->GetItemState(RES_CHRATR_CTL_LANGUAGE, false, &pItem))
1137 {
1138 m_pWrtShell->SetDefault( *pItem );
1139 lcl_SetAllTextToDefaultLanguage( *m_pWrtShell, RES_CHRATR_CTL_LANGUAGE );
1140 }
1141 break;
1142 case SID_ATTR_CHAR_CJK_LANGUAGE( 10000 + 889 ):
1143 if(pArgs && SfxItemState::SET == pArgs->GetItemState(RES_CHRATR_CJK_LANGUAGE, false, &pItem))
1144 {
1145 m_pWrtShell->SetDefault( *pItem );
1146 lcl_SetAllTextToDefaultLanguage( *m_pWrtShell, RES_CHRATR_CJK_LANGUAGE );
1147 }
1148 break;
1149 case FN_TOGGLE_OUTLINE_CONTENT_VISIBILITY((20000 + 200) + 64):
1150 {
1151 m_pWrtShell->EnterStdMode();
1152 size_t nPos(m_pWrtShell->GetOutlinePos());
1153 m_pWrtShell->ToggleOutlineContentVisibility(nPos);
1154 m_pWrtShell->GotoOutline(nPos);
1155 }
1156 break;
1157 case FN_NAV_ELEMENT((20000 + 200) + 55):
1158 {
1159 // nothing here on purpose - if removed only the listbox that changed is changed
1160 }
1161 break;
1162 case FN_SCROLL_PREV((20000 + 200) + 57):
1163 case FN_SCROLL_NEXT((20000 + 200) + 58):
1164 {
1165 bool *pbNext = new bool(true); // FN_SCROLL_NEXT
1166 if (nSlot == FN_SCROLL_PREV((20000 + 200) + 57))
1167 *pbNext = false;
1168 // #i75416# move the execution of the search to an asynchronously called static link
1169 Application::PostUserEvent( LINK(this, SwView, MoveNavigationHdl)::tools::detail::makeLink( ::tools::detail::castTo<SwView *
>(this), &SwView::LinkStubMoveNavigationHdl)
, pbNext );
1170 }
1171 break;
1172 case SID_JUMPTOMARK(5000 + 598):
1173 if( pArgs && SfxItemState::SET == pArgs->GetItemState(SID_JUMPTOMARK(5000 + 598), false, &pItem))
1174 JumpToSwMark( static_cast<const SfxStringItem*>(pItem)->GetValue() );
1175 break;
1176 case SID_GALLERY(5000 + 960) :
1177 // First make sure that the sidebar is visible
1178 GetViewFrame()->ShowChildWindow(SID_SIDEBAR(10000 + 336));
1179
1180 ::sfx2::sidebar::Sidebar::ShowPanel(
1181 "GalleryPanel",
1182 GetViewFrame()->GetFrame().GetFrameInterface());
1183 break;
1184 case SID_AVMEDIA_PLAYER(5000 + 1694) :
1185 GetViewFrame()->ChildWindowExecute(rReq);
1186 break;
1187 case SID_VIEW_DATA_SOURCE_BROWSER(5000 + 1660):
1188 {
1189 SfxViewFrame* pVFrame = GetViewFrame();
1190 pVFrame->ChildWindowExecute(rReq);
1191 if(pVFrame->HasChildWindow(SID_BROWSER(5000 + 1318)))
1192 {
1193 const SwDBData& rData = GetWrtShell().GetDBDesc();
1194 SwModule::ShowDBObj(*this, rData);
1195 }
1196 }
1197 break;
1198 case FN_INSERT_FIELD_DATA_ONLY((20000 + 300) + 19):
1199 {
1200 bool bShow = false;
1201 if( pArgs &&
1202 SfxItemState::SET == pArgs->GetItemState(nSlot, false, &pItem ))
1203 bShow = static_cast<const SfxBoolItem*>(pItem)->GetValue();
1204 if((bShow && m_bInMailMerge) != GetViewFrame()->HasChildWindow(nSlot))
1205 GetViewFrame()->ToggleChildWindow(nSlot);
1206 //if fields have been successfully inserted call the "real"
1207 //mail merge dialog
1208#if HAVE_FEATURE_DBCONNECTIVITY1
1209 SwWrtShell &rSh = GetWrtShell();
1210 if(m_bInMailMerge && rSh.IsAnyDatabaseFieldInDoc())
1211 {
1212 SwDBManager* pDBManager = rSh.GetDBManager();
1213 if (pDBManager)
1214 {
1215 SwDBData aData = rSh.GetDBData();
1216 rSh.EnterStdMode(); // force change in text shell; necessary for mixing DB fields
1217 AttrChangedNotify(nullptr);
1218
1219 Sequence<PropertyValue> aProperties(3);
1220 PropertyValue* pValues = aProperties.getArray();
1221 pValues[0].Name = "DataSourceName";
1222 pValues[1].Name = "Command";
1223 pValues[2].Name = "CommandType";
1224 pValues[0].Value <<= aData.sDataSource;
1225 pValues[1].Value <<= aData.sCommand;
1226 pValues[2].Value <<= aData.nCommandType;
1227 pDBManager->ExecuteFormLetter(rSh, aProperties);
1228 }
1229 }
1230#endif
1231 m_bInMailMerge &= bShow;
1232 GetViewFrame()->GetBindings().Invalidate(FN_INSERT_FIELD((20000 + 300) + 8 ));
1233 }
1234 break;
1235 case FN_QRY_MERGE((20000 + 300) + 67):
1236 {
1237 bool bUseCurrentDocument = true;
1238 bool bQuery = !pArgs || SfxItemState::SET != pArgs->GetItemState(nSlot);
1239 if(bQuery)
1240 {
1241 SfxViewFrame* pTmpFrame = GetViewFrame();
1242 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
1243 ScopedVclPtr<AbstractMailMergeCreateFromDlg> pDlg(pFact->CreateMailMergeCreateFromDlg(pTmpFrame->GetWindow().GetFrameWeld()));
1244 if (RET_OK == pDlg->Execute())
1245 bUseCurrentDocument = pDlg->IsThisDocument();
1246 else
1247 break;
1248 }
1249 GenerateFormLetter(bUseCurrentDocument);
1250 }
1251 break;
1252 case SID_RECHECK_DOCUMENT( 10000 + 1091 ):
1253 {
1254 SwDocShell* pDocShell = GetDocShell();
1255 SwDoc* pDoc = pDocShell->GetDoc();
1256 uno::Reference< linguistic2::XProofreadingIterator > xGCIterator( pDoc->GetGCIterator() );
1257 if( xGCIterator.is() )
1258 {
1259 xGCIterator->resetIgnoreRules();
1260 }
1261 // reset ignore lists
1262 pDoc->SpellItAgainSam( true, false, false );
1263 // clear ignore dictionary
1264 uno::Reference< linguistic2::XDictionary > xDictionary = LinguMgr::GetIgnoreAllList();
1265 if( xDictionary.is() )
1266 xDictionary->clear();
1267 // put cursor to the start of the document
1268 m_pWrtShell->StartOfSection();
1269 [[fallthrough]]; // call spell/grammar dialog
1270 }
1271 case FN_SPELL_GRAMMAR_DIALOG((20000 + 2200) + 105):
1272 {
1273 SfxViewFrame* pViewFrame = GetViewFrame();
1274 if (rReq.GetArgs() != nullptr)
1275 pViewFrame->SetChildWindow (FN_SPELL_GRAMMAR_DIALOG((20000 + 2200) + 105),
1276 static_cast<const SfxBoolItem&>( (rReq.GetArgs()->
1277 Get(FN_SPELL_GRAMMAR_DIALOG((20000 + 2200) + 105)))).GetValue());
1278 else
1279 pViewFrame->ToggleChildWindow(FN_SPELL_GRAMMAR_DIALOG((20000 + 2200) + 105));
1280
1281 pViewFrame->GetBindings().Invalidate(FN_SPELL_GRAMMAR_DIALOG((20000 + 2200) + 105));
1282 rReq.Ignore ();
1283 }
1284 break;
1285 case SID_ALIGN_ANY_LEFT( 10000 + 1002 ) :
1286 case SID_ALIGN_ANY_HCENTER( 10000 + 1003 ) :
1287 case SID_ALIGN_ANY_RIGHT( 10000 + 1004 ) :
1288 case SID_ALIGN_ANY_JUSTIFIED( 10000 + 1005 ):
1289 case SID_ALIGN_ANY_TOP( 10000 + 1006 ) :
1290 case SID_ALIGN_ANY_VCENTER( 10000 + 1007 ) :
1291 case SID_ALIGN_ANY_BOTTOM( 10000 + 1008 ) :
1292 case SID_ALIGN_ANY_HDEFAULT( 10000 + 1009 ) :
1293 case SID_ALIGN_ANY_VDEFAULT( 10000 + 1010 ) :
1294 {
1295 sal_uInt16 nAlias = 0;
1296 if( m_nSelectionType & (SelectionType::DrawObjectEditMode|SelectionType::Text) )
1297 {
1298 switch( nSlot )
1299 {
1300 case SID_ALIGN_ANY_LEFT( 10000 + 1002 ) : nAlias = SID_ATTR_PARA_ADJUST_LEFT( 10000 + 28 ); break;
1301 case SID_ALIGN_ANY_HCENTER( 10000 + 1003 ) : nAlias = SID_ATTR_PARA_ADJUST_CENTER( 10000 + 30 ); break;
1302 case SID_ALIGN_ANY_RIGHT( 10000 + 1004 ) : nAlias = SID_ATTR_PARA_ADJUST_RIGHT( 10000 + 29 ); break;
1303 case SID_ALIGN_ANY_JUSTIFIED( 10000 + 1005 ): nAlias = SID_ATTR_PARA_ADJUST_BLOCK( 10000 + 31 ); break;
1304 case SID_ALIGN_ANY_TOP( 10000 + 1006 ) : nAlias = SID_TABLE_VERT_NONE( 10000 + 1075 ); break;
1305 case SID_ALIGN_ANY_VCENTER( 10000 + 1007 ) : nAlias = SID_TABLE_VERT_CENTER( 10000 + 1074 ); break;
1306 case SID_ALIGN_ANY_BOTTOM( 10000 + 1008 ) : nAlias = SID_TABLE_VERT_BOTTOM( 10000 + 1073 ); break;
1307 }
1308 }
1309 else
1310 {
1311 switch( nSlot )
1312 {
1313 case SID_ALIGN_ANY_LEFT( 10000 + 1002 ) : nAlias = SID_OBJECT_ALIGN_LEFT( 10000 + 131 ) ; break;
1314 case SID_ALIGN_ANY_HCENTER( 10000 + 1003 ) : nAlias = SID_OBJECT_ALIGN_CENTER( 10000 + 132 ) ; break;
1315 case SID_ALIGN_ANY_RIGHT( 10000 + 1004 ) : nAlias = SID_OBJECT_ALIGN_RIGHT( 10000 + 133 ) ; break;
1316 case SID_ALIGN_ANY_TOP( 10000 + 1006 ) : nAlias = SID_OBJECT_ALIGN_UP( 10000 + 134 ) ; break;
1317 case SID_ALIGN_ANY_VCENTER( 10000 + 1007 ) : nAlias = SID_OBJECT_ALIGN_MIDDLE( 10000 + 135 ) ; break;
1318 case SID_ALIGN_ANY_BOTTOM( 10000 + 1008 ) : nAlias = SID_OBJECT_ALIGN_DOWN( 10000 + 136 ) ; break;
1319 }
1320 }
1321 //these slots are either re-mapped to text or object alignment
1322 if (nAlias)
1323 GetViewFrame()->GetDispatcher()->Execute(
1324 nAlias, SfxCallMode::ASYNCHRON);
1325 }
1326 break;
1327 case SID_RESTORE_EDITING_VIEW(5000 + 1663):
1328 {
1329 //#i33307# restore editing position
1330 Point aCursorPos;
1331 bool bSelectObj;
1332 if(m_pViewImpl->GetRestorePosition(aCursorPos, bSelectObj))
1333 {
1334 m_pWrtShell->SwCursorShell::SetCursor( aCursorPos, !bSelectObj );
1335 if( bSelectObj )
1336 {
1337 m_pWrtShell->SelectObj( aCursorPos );
1338 m_pWrtShell->EnterSelFrameMode( &aCursorPos );
1339 }
1340 }
1341 }
1342 break;
1343 case SID_INSERT_GRAPHICTypedWhichId<SfxStringItem>( 10000 + 241 ):
1344 {
1345 rReq.SetReturnValue(SfxBoolItem(nSlot, InsertGraphicDlg( rReq )));
1346 }
1347 break;
1348
1349 default:
1350 OSL_ENSURE(false, "wrong dispatcher")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1350" ": "), "%s", "wrong dispatcher"); } } while (false
)
;
1351 return;
1352 }
1353 if(!bIgnore)
1354 rReq.Done();
1355}
1356
1357bool SwView::IsConditionalFastCall( const SfxRequest &rReq )
1358{
1359 sal_uInt16 nId = rReq.GetSlot();
1360 bool bRet = false;
1361
1362 if (nId == FN_REDLINE_ACCEPT_DIRECT((20000 + 1800) + 37) || nId == FN_REDLINE_REJECT_DIRECT((20000 + 1800) + 38))
1363 {
1364 if (comphelper::LibreOfficeKit::isActive())
1365 bRet = true;
1366 }
1367 return bRet || SfxShell::IsConditionalFastCall(rReq);
1368
1369}
1370
1371/// invalidate page numbering field
1372void SwView::UpdatePageNums(sal_uInt16 nPhyNum, sal_uInt16 nVirtNum, const OUString& rPgStr)
1373{
1374 OUString sTemp(GetPageStr( nPhyNum, nVirtNum, rPgStr ));
1375 const SfxStringItem aTmp( FN_STAT_PAGE((20000 + 1180) + 1), sTemp );
1376 // Used to distinguish which tooltip to show
1377 const SfxBoolItem bExtendedTooltip( FN_STAT_PAGE((20000 + 1180) + 1),
1378 !rPgStr.isEmpty()
1379 && std::u16string_view(OUString::number(nPhyNum)) != rPgStr
1380 && nPhyNum != nVirtNum );
1381
1382 SfxBindings &rBnd = GetViewFrame()->GetBindings();
1383 rBnd.SetState( aTmp );
1384 rBnd.Update( FN_STAT_PAGE((20000 + 1180) + 1) );
1385 rBnd.SetState( bExtendedTooltip );
1386 rBnd.Update( FN_STAT_PAGE((20000 + 1180) + 1) );
1387}
1388
1389void SwView::UpdateDocStats()
1390{
1391 SfxBindings &rBnd = GetViewFrame()->GetBindings();
1392 rBnd.Invalidate( FN_STAT_WORDCOUNT((20000 + 1180) + 9) );
1393 rBnd.Update( FN_STAT_WORDCOUNT((20000 + 1180) + 9) );
1394}
1395
1396/// get status of the status line
1397void SwView::StateStatusLine(SfxItemSet &rSet)
1398{
1399 SwWrtShell& rShell = GetWrtShell();
1400
1401 SfxWhichIter aIter( rSet );
1402 sal_uInt16 nWhich = aIter.FirstWhich();
1403 OSL_ENSURE( nWhich, "empty set")do { if (true && (!(nWhich))) { sal_detail_logFormat(
(SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1403" ": "), "%s", "empty set"); } } while (false)
;
1404
1405 //get section change event
1406 const SwSection* CurrSect = rShell.GetCurrSection();
1407 if( CurrSect )
1408 {
1409 const OUString& sCurrentSectionName = CurrSect->GetSectionName();
1410 if(sCurrentSectionName != m_sOldSectionName)
1411 {
1412 SwCursorShell::FireSectionChangeEvent(2, 1);
1413 }
1414 m_sOldSectionName = sCurrentSectionName;
1415 }
1416 else if (!m_sOldSectionName.isEmpty())
1417 {
1418 SwCursorShell::FireSectionChangeEvent(2, 1);
1419 m_sOldSectionName= OUString();
1420 }
1421 //get column change event
1422 if(rShell.bColumnChange())
1423 {
1424 SwCursorShell::FireColumnChangeEvent(2, 1);
1425 }
1426
1427 while( nWhich )
1428 {
1429 switch( nWhich )
1430 {
1431 case FN_STAT_PAGE((20000 + 1180) + 1): {
1432 // number of pages, log. page number
1433 sal_uInt16 nPage, nLogPage;
1434 OUString sDisplay;
1435 rShell.GetPageNumber( -1, rShell.IsCursorVisible(), nPage, nLogPage, sDisplay );
1436 OUString sTemp( GetPageStr( nPage, nLogPage, sDisplay ) );
1437 const SfxStringItem aTmp( FN_STAT_PAGE((20000 + 1180) + 1), sTemp );
1438 GetViewFrame()->GetBindings().SetState( aTmp );
1439 // Used to distinguish which tooltip to show
1440 const SfxBoolItem bExtendedTooltip( FN_STAT_PAGE((20000 + 1180) + 1), !sDisplay.isEmpty() &&
1441 std::u16string_view(OUString::number( nPage ))
1442 != sDisplay &&
1443 nPage != nLogPage );
1444 GetViewFrame()->GetBindings().SetState( bExtendedTooltip );
1445 //if existing page number is not equal to old page number, send out this event.
1446 if (m_nOldPageNum != nLogPage )
1447 {
1448 if (m_nOldPageNum != 0)
1449 SwCursorShell::FirePageChangeEvent(m_nOldPageNum, nLogPage);
1450 m_nOldPageNum = nLogPage;
1451 }
1452 const sal_uInt16 nCnt = GetWrtShell().GetPageCnt();
1453 if (m_nPageCnt != nCnt) // notify Basic
1454 {
1455 m_nPageCnt = nCnt;
1456 SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwEventPageCount, SwDocShell::GetEventName(STR_SW_EVENT_PAGE_COUNT0), GetViewFrame()->GetObjectShell()), false);
1457 }
1458 }
1459 break;
1460
1461 case FN_STAT_WORDCOUNT((20000 + 1180) + 9):
1462 {
1463 SwDocStat selectionStats;
1464 SwDocStat documentStats;
1465 rShell.CountWords(selectionStats);
1466 documentStats = rShell.GetDoc()->getIDocumentStatistics().GetUpdatedDocStat( true /* complete-async */, false /* don't update fields */ );
1467
1468 sal_uLong nWord = selectionStats.nWord ? selectionStats.nWord : documentStats.nWord;
1469 sal_uLong nChar = selectionStats.nChar ? selectionStats.nChar : documentStats.nChar;
1470 const char* pResId = selectionStats.nWord ? STR_WORDCOUNTreinterpret_cast<char const *>("STR_WORDCOUNT" "\004" u8"Selected: $1, $2"
)
: STR_WORDCOUNT_NO_SELECTIONreinterpret_cast<char const *>("STR_WORDCOUNT_NO_SELECTION"
"\004" u8"$1, $2")
;
1471 const char* pWordResId = selectionStats.nWord ? STR_WORDCOUNT_WORDARGreinterpret_cast<char const *>("STR_WORDCOUNT_WORDARG" "\004"
u8"$1 word" "\004" u8"$1 words")
: STR_WORDCOUNT_WORDARG_NO_SELECTIONreinterpret_cast<char const *>("STR_WORDCOUNT_WORDARG_NO_SELECTION"
"\004" u8"$1 word" "\004" u8"$1 words")
;
1472 const char* pCharResId = selectionStats.nWord ? STR_WORDCOUNT_CHARARGreinterpret_cast<char const *>("STR_WORDCOUNT_CHARARG" "\004"
u8"$1 character" "\004" u8"$1 characters")
: STR_WORDCOUNT_CHARARG_NO_SELECTIONreinterpret_cast<char const *>("STR_WORDCOUNT_CHARARG_NO_SELECTION"
"\004" u8"$1 character" "\004" u8"$1 characters")
;
1473
1474 const LocaleDataWrapper& rLocaleData = Application::GetSettings().GetUILocaleDataWrapper();
1475 OUString aWordArg = SwResId(pWordResId, nWord).replaceAll("$1", rLocaleData.getNum(nWord, 0));
1476 OUString aCharArg = SwResId(pCharResId, nChar).replaceAll("$1", rLocaleData.getNum(nChar, 0));
1477 OUString aWordCount(SwResId(pResId));
1478 aWordCount = aWordCount.replaceAll("$1", aWordArg);
1479 aWordCount = aWordCount.replaceAll("$2", aCharArg);
1480
1481 rSet.Put( SfxStringItem( FN_STAT_WORDCOUNT((20000 + 1180) + 9), aWordCount ) );
1482
1483 SwWordCountWrapper *pWrdCnt = static_cast<SwWordCountWrapper*>(GetViewFrame()->GetChildWindow(SwWordCountWrapper::GetChildWindowId()));
1484 if (pWrdCnt)
1485 pWrdCnt->SetCounts(selectionStats, documentStats);
1486 }
1487 break;
1488
1489 case FN_STAT_TEMPLATE((20000 + 1180) + 2):
1490 {
1491 rSet.Put(SfxStringItem( FN_STAT_TEMPLATE((20000 + 1180) + 2),
1492 rShell.GetCurPageStyle()));
1493
1494 }
1495 break;
1496 case SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0):
1497 {
1498 if ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1499 {
1500 const SwViewOption* pVOpt = rShell.GetViewOptions();
1501 SvxZoomType eZoom = pVOpt->GetZoomType();
1502 SvxZoomItem aZoom(eZoom,
1503 pVOpt->GetZoom());
1504 if( pVOpt->getBrowseMode() )
1505 {
1506 aZoom.SetValueSet(
1507 SvxZoomEnableFlags::N50|
1508 SvxZoomEnableFlags::N75|
1509 SvxZoomEnableFlags::N100|
1510 SvxZoomEnableFlags::N150|
1511 SvxZoomEnableFlags::N200);
1512 }
1513 rSet.Put( aZoom );
1514 }
1515 else
1516 rSet.DisableItem( SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0) );
1517 }
1518 break;
1519 case SID_ATTR_VIEWLAYOUT( 10000 + 1064 ):
1520 {
1521 if ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1522 {
1523 const SwViewOption* pVOpt = rShell.GetViewOptions();
1524 const sal_uInt16 nColumns = pVOpt->GetViewLayoutColumns();
1525 const bool bBookMode = pVOpt->IsViewLayoutBookMode();
1526 SvxViewLayoutItem aViewLayout(nColumns, bBookMode);
1527 rSet.Put( aViewLayout );
1528 }
1529 else
1530 rSet.DisableItem( SID_ATTR_VIEWLAYOUT( 10000 + 1064 ) );
1531 }
1532 break;
1533 case SID_ATTR_ZOOMSLIDER( 10000 + 1065 ):
1534 {
1535 if ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1536 {
1537 const SwViewOption* pVOpt = rShell.GetViewOptions();
1538 const sal_uInt16 nCurrentZoom = pVOpt->GetZoom();
1539 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM20, MAXZOOM600 );
1540 aZoomSliderItem.AddSnappingPoint( 100 );
1541
1542 if ( !m_pWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) )
1543 {
1544 const sal_uInt16 nColumns = pVOpt->GetViewLayoutColumns();
1545 const bool bAutomaticViewLayout = 0 == nColumns;
1546 const SwPostItMgr* pMgr = GetPostItMgr();
1547
1548 // snapping points:
1549 // automatic mode: 1 Page, 2 Pages, 100%
1550 // n Columns mode: n Pages, 100%
1551 // n Columns book mode: nPages without gaps, 100%
1552 const SwRect aPageRect( m_pWrtShell->GetAnyCurRect( CurRectType::PageCalc ) );
1553 const SwRect aRootRect( m_pWrtShell->GetAnyCurRect( CurRectType::PagesArea ) ); // width of columns
1554 Size aPageSize( aPageRect.SSize() );
1555 aPageSize.AdjustWidth(pMgr->HasNotes() && pMgr->ShowNotes() ?
1556 pMgr->GetSidebarWidth() + pMgr->GetSidebarBorderWidth() :
1557 0 );
1558
1559 Size aRootSize( aRootRect.SSize() );
1560
1561 const MapMode aTmpMap( MapUnit::MapTwip );
1562 const Size& rEditSize = GetEditWin().GetOutputSizePixel();
1563 const Size aWindowSize( GetEditWin().PixelToLogic( rEditSize, aTmpMap ) );
1564
1565 const long nOf = pVOpt->GetDocumentBorder() * 2;
1566 long nTmpWidth = bAutomaticViewLayout ? aPageSize.Width() : aRootSize.Width();
1567 nTmpWidth += nOf;
1568 aPageSize.AdjustHeight(nOf );
1569 long nFac = aWindowSize.Width() * 100 / nTmpWidth;
1570
1571 long nVisPercent = aWindowSize.Height() * 100 / aPageSize.Height();
1572 nFac = std::min( nFac, nVisPercent );
1573
1574 if (nFac >= MINZOOM20)
1575 {
1576 aZoomSliderItem.AddSnappingPoint( nFac );
1577 }
1578
1579 if ( bAutomaticViewLayout )
1580 {
1581 nTmpWidth += aPageSize.Width() + pVOpt->GetGapBetweenPages();
1582 nFac = aWindowSize.Width() * 100 / nTmpWidth;
1583 nFac = std::min( nFac, nVisPercent );
1584 if (nFac >= MINZOOM20)
1585 {
1586 aZoomSliderItem.AddSnappingPoint( nFac );
1587 }
1588 }
1589 }
1590
1591 rSet.Put( aZoomSliderItem );
1592 }
1593 else
1594 rSet.DisableItem( SID_ATTR_ZOOMSLIDER( 10000 + 1065 ) );
1595 }
1596 break;
1597 case SID_ATTR_POSITIONTypedWhichId<SfxPointItem>( 10000 + 223 ):
1598 case SID_ATTR_SIZETypedWhichId<SvxSizeItem>( 10000 + 224 ):
1599 {
1600 if( !rShell.IsFrameSelected() && !rShell.IsObjSelected() )
1601 SwBaseShell::SetFrameMode_( FLY_DRAG_END );
1602 else
1603 {
1604 FlyMode eFrameMode = SwBaseShell::GetFrameMode();
1605 if ( eFrameMode == FLY_DRAG_START || eFrameMode == FLY_DRAG )
1606 {
1607 if ( nWhich == SID_ATTR_POSITIONTypedWhichId<SfxPointItem>( 10000 + 223 ) )
1608 rSet.Put( SfxPointItem( SID_ATTR_POSITIONTypedWhichId<SfxPointItem>( 10000 + 223 ),
1609 rShell.GetAnchorObjDiff()));
1610 else
1611 rSet.Put( SvxSizeItem( SID_ATTR_SIZETypedWhichId<SvxSizeItem>( 10000 + 224 ),
1612 rShell.GetObjSize()));
1613 }
1614 }
1615 }
1616 break;
1617 case SID_TABLE_CELL( 10000 + 225 ):
1618
1619 if( rShell.IsFrameSelected() || rShell.IsObjSelected() )
1620 {
1621 // #i39171# Don't put a SvxSizeItem into a slot which is defined as SfxStringItem.
1622 // SvxPosSizeStatusBarControl no longer resets to empty display if only one slot
1623 // has no item, so SID_TABLE_CELL can remain empty (the SvxSizeItem is supplied
1624 // in SID_ATTR_SIZE).
1625 }
1626 else
1627 {
1628 OUString sStr;
1629 if( rShell.IsCursorInTable() )
1630 {
1631 // table name + cell coordinate
1632 sStr = rShell.GetTableFormat()->GetName() + ":";
1633 sStr += rShell.GetBoxNms();
1634 }
1635 else
1636 {
1637 const SwSection* pCurrSect = rShell.GetCurrSection();
1638 if( pCurrSect )
1639 {
1640 switch( pCurrSect->GetType() )
1641 {
1642 case SectionType::ToxHeader:
1643 case SectionType::ToxContent:
1644 {
1645 const SwTOXBase* pTOX = m_pWrtShell->GetCurTOX();
1646 if( pTOX )
1647 sStr = pTOX->GetTOXName();
1648 else
1649 {
1650 OSL_ENSURE( false,do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1651" ": "), "%s", "Unknown kind of section"); } } while
(false)
1651 "Unknown kind of section" )do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1651" ": "), "%s", "Unknown kind of section"); } } while
(false)
;
1652 sStr = pCurrSect->GetSectionName();
1653 }
1654 }
1655 break;
1656 default:
1657 sStr = pCurrSect->GetSectionName();
1658 break;
1659 }
1660 }
1661 }
1662
1663 const SwNumRule* pNumRule = rShell.GetNumRuleAtCurrCursorPos();
1664 const bool bOutlineNum = pNumRule && pNumRule->IsOutlineRule();
1665
1666 if (pNumRule && !bOutlineNum ) // cursor in numbering
1667 {
1668 sal_uInt8 nNumLevel = rShell.GetNumLevel();
1669 if ( nNumLevel < MAXLEVEL )
1670 {
1671 if(!pNumRule->IsAutoRule())
1672 {
1673 SfxItemSet aSet(GetPool(),
1674 svl::Items<RES_PARATR_NUMRULE, RES_PARATR_NUMRULE>{});
1675 rShell.GetCurAttr(aSet);
1676 if(SfxItemState::DEFAULT <=
1677 aSet.GetItemState(RES_PARATR_NUMRULE))
1678 {
1679 const OUString& rNumStyle =
1680 aSet.Get(RES_PARATR_NUMRULE).GetValue();
1681 if(!rNumStyle.isEmpty())
1682 {
1683 if(!sStr.isEmpty())
1684 sStr += sStatusDelim;
1685 sStr += rNumStyle;
1686 }
1687 }
1688 }
1689 if (!sStr.isEmpty())
1690 sStr += sStatusDelim;
1691 sStr += SwResId(STR_NUM_LEVELreinterpret_cast<char const *>("STR_NUM_LEVEL" "\004" u8"Level "
)
) + OUString::number( nNumLevel + 1 );
1692
1693 }
1694 }
1695 const int nOutlineLevel = rShell.GetCurrentParaOutlineLevel();
1696 if( nOutlineLevel != 0 )
1697 {
1698 if (!sStr.isEmpty())
1699 sStr += " , ";
1700 if( bOutlineNum )
1701 {
1702 sStr += SwResId(STR_OUTLINE_NUMBERINGreinterpret_cast<char const *>("STR_OUTLINE_NUMBERING" "\004"
u8"Chapter Numbering")
) +
1703 sStatusDelim + SwResId(STR_NUM_LEVELreinterpret_cast<char const *>("STR_NUM_LEVEL" "\004" u8"Level "
)
);
1704 }
1705 else
1706 sStr += SwResId(STR_NUM_OUTLINEreinterpret_cast<char const *>("STR_NUM_OUTLINE" "\004"
u8"Outline ")
);
1707 sStr += OUString::number( nOutlineLevel);
1708 }
1709
1710 if( rShell.HasReadonlySel() )
1711 {
1712 if (!sStr.isEmpty())
1713 sStr = sStatusDelim + sStr;
1714 sStr = SwResId(SW_STR_READONLYreinterpret_cast<char const *>("SW_STR_READONLY" "\004"
u8"read-only")
) + sStr;
1715 }
1716 if (!sStr.isEmpty())
1717 rSet.Put( SfxStringItem( SID_TABLE_CELL( 10000 + 225 ), sStr ));
1718 }
1719 break;
1720 case FN_STAT_SELMODE((20000 + 1180) + 5):
1721 {
1722 if(rShell.IsStdMode())
1723 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE((20000 + 1180) + 5), 0));
1724 else if(rShell.IsAddMode())
1725 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE((20000 + 1180) + 5), 2));
1726 else if(rShell.IsBlockMode())
1727 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE((20000 + 1180) + 5), 3));
1728 else
1729 rSet.Put(SfxUInt16Item(FN_STAT_SELMODE((20000 + 1180) + 5), 1));
1730 break;
1731 }
1732 case SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ):
1733 if( rShell.IsRedlineOn() )
1734 rSet.DisableItem( nWhich );
1735 else
1736 {
1737 rSet.Put(SfxBoolItem(SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ),rShell.IsInsMode()));
1738 }
1739 break;
1740 }
1741 nWhich = aIter.NextWhich();
1742 }
1743}
1744
1745/** execute method for the status line
1746 *
1747 * @param rReq ???
1748 */
1749void SwView::ExecuteStatusLine(SfxRequest &rReq)
1750{
1751 SwWrtShell &rSh = GetWrtShell();
1752 const SfxItemSet* pArgs = rReq.GetArgs();
1753 const SfxPoolItem* pItem=nullptr;
1754 bool bUp = false;
1755 sal_uInt16 nWhich = rReq.GetSlot();
1756 switch( nWhich )
1757 {
1758 case FN_STAT_PAGE((20000 + 1180) + 1):
1759 {
1760 GetViewFrame()->GetDispatcher()->Execute( FN_GOTO_PAGE((20000 + 600) + 59 ),
1761 SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
1762 }
1763 break;
1764
1765 case FN_STAT_WORDCOUNT((20000 + 1180) + 9):
1766 {
1767 GetViewFrame()->GetDispatcher()->Execute(FN_WORDCOUNT_DIALOG((20000 + 2200) + 98),
1768 SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
1769 }
1770 break;
1771
1772 case FN_STAT_BOOKMARK((20000 + 1180) + 8):
1773 if ( pArgs )
1774 {
1775 if (SfxItemState::SET == pArgs->GetItemState( nWhich, true, &pItem))
1776 {
1777 const IDocumentMarkAccess* pMarkAccess = rSh.getIDocumentMarkAccess();
1778 const sal_Int32 nIdx = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
1779 if(nIdx < pMarkAccess->getBookmarksCount())
1780 {
1781 const IDocumentMarkAccess::const_iterator_t ppBookmark = rSh.getIDocumentMarkAccess()->getBookmarksBegin() + nIdx;
1782 rSh.EnterStdMode();
1783 rSh.GotoMark( *ppBookmark );
1784 }
1785 else
1786 OSL_FAIL("SwView::ExecuteStatusLine(..)"do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1787" ": "), "%s", "SwView::ExecuteStatusLine(..)" " - Ignoring out of range bookmark index"
); } } while (false)
1787 " - Ignoring out of range bookmark index")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "1787" ": "), "%s", "SwView::ExecuteStatusLine(..)" " - Ignoring out of range bookmark index"
); } } while (false)
;
1788 }
1789 }
1790 break;
1791
1792 case FN_STAT_TEMPLATE((20000 + 1180) + 2):
1793 {
1794 GetViewFrame()->GetDispatcher()->Execute(FN_FORMAT_PAGE_DLG((20000 + 400) + 52),
1795 SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
1796 }
1797 break;
1798 case SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0):
1799 {
1800 if ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() )
1801 {
1802 const SfxItemSet *pSet = nullptr;
1803 ScopedVclPtr<AbstractSvxZoomDialog> pDlg;
1804 if ( pArgs )
1805 pSet = pArgs;
1806 else
1807 {
1808 const SwViewOption& rViewOptions = *rSh.GetViewOptions();
1809 SfxItemSet aCoreSet(m_pShell->GetPool(), svl::Items<SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0), SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0), SID_ATTR_VIEWLAYOUT( 10000 + 1064 ), SID_ATTR_VIEWLAYOUT( 10000 + 1064 )>{} );
1810 SvxZoomItem aZoom( rViewOptions.GetZoomType(), rViewOptions.GetZoom() );
1811
1812 const bool bBrowseMode = rSh.GetViewOptions()->getBrowseMode();
1813 if( bBrowseMode )
1814 {
1815 aZoom.SetValueSet(
1816 SvxZoomEnableFlags::N50|
1817 SvxZoomEnableFlags::N75|
1818 SvxZoomEnableFlags::N100|
1819 SvxZoomEnableFlags::N150|
1820 SvxZoomEnableFlags::N200);
1821 }
1822 aCoreSet.Put( aZoom );
1823
1824 if ( !bBrowseMode )
1825 {
1826 const SvxViewLayoutItem aViewLayout( rViewOptions.GetViewLayoutColumns(), rViewOptions.IsViewLayoutBookMode() );
1827 aCoreSet.Put( aViewLayout );
1828 }
1829
1830 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
1831 pDlg.disposeAndReset(pFact->CreateSvxZoomDialog(GetViewFrame()->GetWindow().GetFrameWeld(), aCoreSet));
1832 pDlg->SetLimits( MINZOOM20, MAXZOOM600 );
1833 if( pDlg->Execute() != RET_CANCEL )
1834 pSet = pDlg->GetOutputItemSet();
1835 }
1836
1837 const SfxPoolItem* pViewLayoutItem = nullptr;
1838 if ( pSet && SfxItemState::SET == pSet->GetItemState(SID_ATTR_VIEWLAYOUT( 10000 + 1064 ), true, &pViewLayoutItem))
1839 {
1840 const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem *>(pViewLayoutItem)->GetValue();
1841 const bool bBookMode = static_cast<const SvxViewLayoutItem *>(pViewLayoutItem)->IsBookMode();
1842 SetViewLayout( nColumns, bBookMode );
1843 }
1844
1845 if ( pSet && SfxItemState::SET == pSet->GetItemState(SID_ATTR_ZOOMTypedWhichId<SvxZoomItem>(10000 + 0), true, &pItem))
1846 {
1847 SvxZoomType eType = static_cast<const SvxZoomItem *>(pItem)->GetType();
1848 SetZoom( eType, static_cast<const SvxZoomItem *>(pItem)->GetValue() );
1849 }
1850 bUp = true;
1851 if ( pItem )
1852 rReq.AppendItem( *pItem );
1853 rReq.Done();
1854 }
1855 }
1856 break;
1857
1858 case SID_ATTR_VIEWLAYOUT( 10000 + 1064 ):
1859 {
1860 if ( pArgs && !rSh.getIDocumentSettingAccess().get(DocumentSettingId::BROWSE_MODE) &&
1861 ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) )
1862 {
1863 if ( SfxItemState::SET == pArgs->GetItemState(SID_ATTR_VIEWLAYOUT( 10000 + 1064 ), true, &pItem ))
1864 {
1865 const sal_uInt16 nColumns = static_cast<const SvxViewLayoutItem *>(pItem)->GetValue();
1866 const bool bBookMode = (0 != nColumns && 0 == (nColumns % 2)) &&
1867 static_cast<const SvxViewLayoutItem *>(pItem)->IsBookMode();
1868
1869 SetViewLayout( nColumns, bBookMode );
1870 }
1871
1872 bUp = true;
1873 rReq.Done();
1874
1875 InvalidateRulerPos();
1876 }
1877 }
1878 break;
1879
1880 case SID_ATTR_ZOOMSLIDER( 10000 + 1065 ):
1881 {
1882 if ( pArgs && ( ( GetDocShell()->GetCreateMode() != SfxObjectCreateMode::EMBEDDED ) || !GetDocShell()->IsInPlaceActive() ) )
1883 {
1884 if ( SfxItemState::SET == pArgs->GetItemState(SID_ATTR_ZOOMSLIDER( 10000 + 1065 ), true, &pItem ))
1885 {
1886 const sal_uInt16 nCurrentZoom = static_cast<const SvxZoomSliderItem *>(pItem)->GetValue();
1887 SetZoom( SvxZoomType::PERCENT, nCurrentZoom );
1888 }
1889
1890 bUp = true;
1891 rReq.Done();
1892 }
1893 }
1894 break;
1895
1896 case SID_ATTR_SIZETypedWhichId<SvxSizeItem>( 10000 + 224 ):
1897 {
1898 sal_uInt16 nId = 0;
1899 if( rSh.IsCursorInTable() )
1900 nId = FN_FORMAT_TABLE_DLG((20000 + 400) + 60);
1901 else if( rSh.GetCurTOX() )
1902 nId = FN_INSERT_MULTI_TOX((20000 + 1400) + 20);
1903 else if( rSh.GetCurrSection() )
1904 nId = FN_EDIT_REGION((20000 + 100) + 65);
1905 else
1906 {
1907 const SwNumRule* pNumRule = rSh.GetNumRuleAtCurrCursorPos();
1908 if( pNumRule ) // cursor in numbering
1909 {
1910 if( pNumRule->IsAutoRule() )
1911 nId = FN_NUMBER_BULLETS((20000 + 100) + 21);
1912 else
1913 {
1914 // start dialog of the painter
1915 nId = 0;
1916 }
1917 }
1918 else if( rSh.IsFrameSelected() )
1919 nId = FN_FORMAT_FRAME_DLG((20000 + 400) + 56);
1920 else if( rSh.IsObjSelected() )
1921 nId = SID_ATTR_TRANSFORMTypedWhichId<SfxInt32Item>( 10000 + 87 );
1922 }
1923 if( nId )
1924 GetViewFrame()->GetDispatcher()->Execute(nId,
1925 SfxCallMode::SYNCHRON | SfxCallMode::RECORD );
1926 }
1927 break;
1928
1929 case FN_STAT_SELMODE((20000 + 1180) + 5):
1930 {
1931 if ( pArgs )
1932 {
1933 if (SfxItemState::SET == pArgs->GetItemState( nWhich, true, &pItem))
1934 {
1935 switch ( static_cast<const SfxUInt16Item *>(pItem)->GetValue() )
1936 {
1937 case 0: rSh.EnterStdMode(); break;
1938 case 1: rSh.EnterExtMode(); break;
1939 case 2: rSh.EnterAddMode(); break;
1940 case 3: rSh.EnterBlockMode(); break;
1941 }
1942 }
1943 }
1944 else
1945 {
1946
1947 if( !rSh.IsAddMode() && !rSh.IsExtMode() && !rSh.IsBlockMode() )
1948 rSh.ToggleExtMode();
1949 else if ( rSh.IsExtMode() )
1950 {
1951 rSh.ToggleExtMode();
1952 rSh.ToggleAddMode();
1953 }
1954 else if ( rSh.IsAddMode() )
1955 {
1956 rSh.ToggleAddMode();
1957 rSh.ToggleBlockMode();
1958 }
1959 else
1960 rSh.ToggleBlockMode();
1961 }
1962 bUp = true;
1963 break;
1964 }
1965 case FN_SET_ADD_MODE((20000 + 900) + 39):
1966 rSh.ToggleAddMode();
1967 nWhich = FN_STAT_SELMODE((20000 + 1180) + 5);
1968 bUp = true;
1969 break;
1970 case FN_SET_BLOCK_MODE((20000 + 900) + 64):
1971 rSh.ToggleBlockMode();
1972 nWhich = FN_STAT_SELMODE((20000 + 1180) + 5);
1973 bUp = true;
1974 break;
1975 case FN_SET_EXT_MODE((20000 + 900) + 40):
1976 rSh.ToggleExtMode();
1977 nWhich = FN_STAT_SELMODE((20000 + 1180) + 5);
1978 bUp = true;
1979 break;
1980 case SID_ATTR_INSERTTypedWhichId<SfxBoolItem>( 10000 + 221 ):
1981 SwPostItMgr* pMgr = GetPostItMgr();
1982 if ( pMgr && pMgr->HasActiveSidebarWin() )
1983 {
1984 pMgr->ToggleInsModeOnActiveSidebarWin();
1985 }
1986 else
1987 rSh.ToggleInsMode();
1988 bUp = true;
1989 break;
1990
1991 }
1992 if ( bUp )
1993 {
1994 SfxBindings &rBnd = GetViewFrame()->GetBindings();
1995 rBnd.Invalidate(nWhich);
1996 rBnd.Update(nWhich);
1997 }
1998}
1999
2000void SwView::InsFrameMode(sal_uInt16 nCols)
2001{
2002 if ( m_pWrtShell->HasWholeTabSelection() )
2003 {
2004 SwFlyFrameAttrMgr aMgr( true, m_pWrtShell.get(), Frmmgr_Type::TEXT, nullptr );
2005
2006 const SwFrameFormat &rPageFormat =
2007 m_pWrtShell->GetPageDesc(m_pWrtShell->GetCurPageDesc()).GetMaster();
2008 SwTwips lWidth = rPageFormat.GetFrameSize().GetWidth();
2009 const SvxLRSpaceItem &rLR = rPageFormat.GetLRSpace();
2010 lWidth -= rLR.GetLeft() + rLR.GetRight();
2011 aMgr.SetSize(Size(lWidth, aMgr.GetSize().Height()));
2012 if(nCols > 1)
2013 {
2014 SwFormatCol aCol;
2015 aCol.Init( nCols, aCol.GetGutterWidth(), aCol.GetWishWidth() );
2016 aMgr.SetCol( aCol );
2017 }
2018 aMgr.InsertFlyFrame();
2019 }
2020 else
2021 GetEditWin().InsFrame(nCols);
2022}
2023
2024/// show "edit link" dialog
2025void SwView::EditLinkDlg()
2026{
2027 bool bWeb = dynamic_cast<SwWebView*>( this ) != nullptr;
2028 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
2029 ScopedVclPtr<SfxAbstractLinksDialog> pDlg(pFact->CreateLinksDialog(GetViewFrame()->GetWindow().GetFrameWeld(), &GetWrtShell().GetLinkManager(), bWeb));
2030 pDlg->Execute();
2031}
2032
2033bool SwView::JumpToSwMark( const OUString& rMark )
2034{
2035 bool bRet = false;
2036 if( !rMark.isEmpty() )
2037 {
2038 // place bookmark at top-center
2039 bool bSaveCC = m_bCenterCursor;
2040 bool bSaveCT = m_bTopCursor;
2041 SetCursorAtTop( true );
2042
2043 // For scrolling the FrameSet, the corresponding shell needs to have the focus.
2044 bool bHasShFocus = m_pWrtShell->HasShellFocus();
2045 if( !bHasShFocus )
2046 m_pWrtShell->ShellGetFocus();
2047
2048 const SwFormatINetFormat* pINet;
2049 OUString sCmp;
2050 OUString sMark( INetURLObject::decode( rMark,
2051 INetURLObject::DecodeMechanism::WithCharset ));
2052
2053 sal_Int32 nLastPos, nPos = sMark.indexOf( cMarkSeparator );
2054 if( -1 != nPos )
2055 while( -1 != ( nLastPos = sMark.indexOf( cMarkSeparator, nPos + 1 )) )
2056 nPos = nLastPos;
2057
2058 IDocumentMarkAccess::const_iterator_t ppMark;
2059 IDocumentMarkAccess* const pMarkAccess = m_pWrtShell->getIDocumentMarkAccess();
2060 if( -1 != nPos )
2061 sCmp = sMark.copy(nPos + 1).replaceAll(" ", "");
2062
2063 if( !sCmp.isEmpty() )
2064 {
2065 OUString sName( sMark.copy( 0, nPos ) );
2066 sCmp = sCmp.toAsciiLowerCase();
2067 FlyCntType eFlyType = FLYCNTTYPE_ALL;
2068
2069 if( sCmp == "region" )
2070 {
2071 m_pWrtShell->EnterStdMode();
2072 bRet = m_pWrtShell->GotoRegion( sName );
2073 }
2074 else if( sCmp == "outline" )
2075 {
2076 m_pWrtShell->EnterStdMode();
2077 bRet = m_pWrtShell->GotoOutline( sName );
2078 }
2079 else if( sCmp == "frame" )
2080 eFlyType = FLYCNTTYPE_FRM;
2081 else if( sCmp == "graphic" )
2082 eFlyType = FLYCNTTYPE_GRF;
2083 else if( sCmp == "ole" )
2084 eFlyType = FLYCNTTYPE_OLE;
2085 else if( sCmp == "table" )
2086 {
2087 m_pWrtShell->EnterStdMode();
2088 bRet = m_pWrtShell->GotoTable( sName );
2089 }
2090 else if( sCmp == "sequence" )
2091 {
2092 m_pWrtShell->EnterStdMode();
2093 sal_Int32 nNoPos = sName.indexOf( cSequenceMarkSeparator );
2094 if ( nNoPos != -1 )
2095 {
2096 sal_uInt16 nSeqNo = sName.copy( nNoPos + 1 ).toInt32();
2097 sName = sName.copy( 0, nNoPos );
2098 bRet = m_pWrtShell->GotoRefMark(sName, REF_SEQUENCEFLD, nSeqNo);
2099 }
2100 }
2101 else if( sCmp == "text" )
2102 {
2103 // normal text search
2104 m_pWrtShell->EnterStdMode();
2105
2106 i18nutil::SearchOptions2 aSearchOpt(
2107 SearchAlgorithms_ABSOLUTE, 0,
2108 sName, OUString(),
2109 SvtSysLocale().GetLanguageTag().getLocale(),
2110 0,0,0,
2111 TransliterationFlags::IGNORE_CASE,
2112 SearchAlgorithms2::ABSOLUTE,
2113 '\\' );
2114
2115 //todo/mba: assuming that notes shouldn't be searched
2116 if( m_pWrtShell->SearchPattern( aSearchOpt, false/*bSearchInNotes*/, SwDocPositions::Start, SwDocPositions::End ))
2117 {
2118 m_pWrtShell->EnterStdMode(); // remove the selection
2119 bRet = true;
2120 }
2121 }
2122 else if( pMarkAccess->getAllMarksEnd() != (ppMark = pMarkAccess->findMark(sMark)) )
2123 {
2124 bRet = m_pWrtShell->GotoMark( *ppMark, false );
2125 }
2126 else if( nullptr != ( pINet = m_pWrtShell->FindINetAttr( sMark ) )) {
2127 m_pWrtShell->addCurrentPosition();
2128 bRet = m_pWrtShell->GotoINetAttr( *pINet->GetTextINetFormat() );
2129 }
2130
2131 // for all types of Flys
2132 if( FLYCNTTYPE_ALL != eFlyType && m_pWrtShell->GotoFly( sName, eFlyType ))
2133 {
2134 bRet = true;
2135 if( FLYCNTTYPE_FRM == eFlyType )
2136 {
2137 // TextFrames: set Cursor in the frame
2138 m_pWrtShell->UnSelectFrame();
2139 m_pWrtShell->LeaveSelFrameMode();
2140 }
2141 else
2142 {
2143 m_pWrtShell->HideCursor();
2144 m_pWrtShell->EnterSelFrameMode();
2145 }
2146 }
2147 }
2148 else if( pMarkAccess->getAllMarksEnd() != (ppMark = pMarkAccess->findMark(sMark)))
2149 {
2150 bRet = m_pWrtShell->GotoMark( *ppMark, false );
2151 }
2152 else if( nullptr != ( pINet = m_pWrtShell->FindINetAttr( sMark ) ))
2153 bRet = m_pWrtShell->GotoINetAttr( *pINet->GetTextINetFormat() );
2154
2155 // make selection visible later
2156 if ( m_aVisArea.IsEmpty() )
2157 m_bMakeSelectionVisible = true;
2158
2159 // reset ViewStatus
2160 SetCursorAtTop( bSaveCT, bSaveCC );
2161
2162 if( !bHasShFocus )
2163 m_pWrtShell->ShellLoseFocus();
2164 }
2165 return bRet;
2166}
2167
2168// #i67305# Undo after insert from file:
2169// Undo "Insert form file" crashes with documents imported from binary filter (.sdw) => disabled
2170// Undo "Insert form file" crashes with (.odt) documents crashes if these documents contains
2171// page styles with active header/footer => disabled for those documents
2172static size_t lcl_PageDescWithHeader( const SwDoc& rDoc )
2173{
2174 size_t nRet = 0;
2175 size_t nCnt = rDoc.GetPageDescCnt();
2176 for( size_t i = 0; i < nCnt; ++i )
2177 {
2178 const SwPageDesc& rPageDesc = rDoc.GetPageDesc( i );
2179 const SwFrameFormat& rMaster = rPageDesc.GetMaster();
2180 const SfxPoolItem* pItem;
2181 if( ( SfxItemState::SET == rMaster.GetAttrSet().GetItemState( RES_HEADER, false, &pItem ) &&
2182 static_cast<const SwFormatHeader*>(pItem)->IsActive() ) ||
2183 ( SfxItemState::SET == rMaster.GetAttrSet().GetItemState( RES_FOOTER, false, &pItem ) &&
2184 static_cast<const SwFormatFooter*>(pItem)->IsActive()) )
2185 ++nRet;
2186 }
2187 return nRet; // number of page styles with active header/footer
2188}
2189
2190void SwView::ExecuteInsertDoc( SfxRequest& rRequest, const SfxPoolItem* pItem )
2191{
2192 m_pViewImpl->InitRequest( rRequest );
2193 m_pViewImpl->SetParam( pItem ? 1 : 0 );
2194 const sal_uInt16 nSlot = rRequest.GetSlot();
2195
2196 if ( !pItem )
2197 {
2198 InsertDoc( nSlot, "", "" );
2199 }
2200 else
2201 {
2202 OUString sFile, sFilter;
2203 sFile = static_cast<const SfxStringItem *>( pItem )->GetValue();
2204 if ( SfxItemState::SET == rRequest.GetArgs()->GetItemState( FN_PARAM_1((20000 + 1100)+60), true, &pItem ) )
2205 sFilter = static_cast<const SfxStringItem *>(pItem )->GetValue();
2206
2207 bool bHasFileName = !sFile.isEmpty();
2208 long nFound = InsertDoc( nSlot, sFile, sFilter );
2209
2210 if ( bHasFileName )
2211 {
2212 rRequest.SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
2213 rRequest.Done();
2214 }
2215 }
2216}
2217
2218long SwView::InsertDoc( sal_uInt16 nSlotId, const OUString& rFileName, const OUString& rFilterName, sal_Int16 nVersion )
2219{
2220 std::unique_ptr<SfxMedium> pMed;
2221 SwDocShell* pDocSh = GetDocShell();
2222
2223 if( !rFileName.isEmpty() )
2224 {
2225 SfxObjectFactory& rFact = pDocSh->GetFactory();
2226 std::shared_ptr<const SfxFilter> pFilter = rFact.GetFilterContainer()->GetFilter4FilterName( rFilterName );
2227 if ( !pFilter )
2228 {
2229 pMed.reset(new SfxMedium(rFileName, StreamMode::READ, nullptr, nullptr ));
2230 SfxFilterMatcher aMatcher( rFact.GetFilterContainer()->GetName() );
2231 pMed->UseInteractionHandler( true );
2232 ErrCode nErr = aMatcher.GuessFilter(*pMed, pFilter, SfxFilterFlags::NONE);
2233 if ( nErr )
2234 pMed.reset();
2235 else
2236 pMed->SetFilter( pFilter );
2237 }
2238 else
2239 pMed.reset(new SfxMedium(rFileName, StreamMode::READ, pFilter, nullptr));
2240 }
2241 else
2242 {
2243 m_pViewImpl->StartDocumentInserter(
2244 // tdf#118578 allow inserting any Writer document except GlobalDoc
2245 SwDocShell::Factory().GetFactoryName(),
2246 LINK( this, SwView, DialogClosedHdl )::tools::detail::makeLink( ::tools::detail::castTo<SwView *
>(this), &SwView::LinkStubDialogClosedHdl)
,
2247 nSlotId
2248 );
2249 return -1;
2250 }
2251
2252 if( !pMed )
2253 return -1;
2254
2255 return InsertMedium( nSlotId, std::move(pMed), nVersion );
2256}
2257
2258long SwView::InsertMedium( sal_uInt16 nSlotId, std::unique_ptr<SfxMedium> pMedium, sal_Int16 nVersion )
2259{
2260 bool bInsert = false, bCompare = false;
2261 long nFound = 0;
2262 SwDocShell* pDocSh = GetDocShell();
2263
2264 switch( nSlotId )
2265 {
2266 case SID_DOCUMENT_MERGE(5000 + 1587): break;
2267 case SID_DOCUMENT_COMPARE(5000 + 1586): bCompare = true; break;
2268 case SID_INSERTDOC(5000 + 532): bInsert = true; break;
2269
2270 default:
2271 OSL_ENSURE( false, "unknown SlotId!" )do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/uiview/view2.cxx"
":" "2271" ": "), "%s", "unknown SlotId!"); } } while (false
)
;
2272 bInsert = true;
2273 break;
2274 }
2275
2276 if( bInsert )
2277 {
2278 uno::Reference< frame::XDispatchRecorder > xRecorder =
2279 GetViewFrame()->GetBindings().GetRecorder();
2280 if ( xRecorder.is() )
2281 {
2282 SfxRequest aRequest(GetViewFrame(), SID_INSERTDOC(5000 + 532));
2283 aRequest.AppendItem(SfxStringItem(SID_INSERTDOC(5000 + 532), pMedium->GetOrigURL()));
2284 if(pMedium->GetFilter())
2285 aRequest.AppendItem(SfxStringItem(FN_PARAM_1((20000 + 1100)+60), pMedium->GetFilter()->GetName()));
2286 aRequest.Done();
2287 }
2288
2289 SfxObjectShellRef aRef( pDocSh );
2290
2291 ErrCode nError = SfxObjectShell::HandleFilter( pMedium.get(), pDocSh );
2292 // #i16722# aborted?
2293 if(nError != ERRCODE_NONEErrCode(0))
2294 {
2295 return -1;
2296 }
2297
2298 pMedium->Download(); // start download if needed
2299 if( aRef.is() && 1 < aRef->GetRefCount() ) // still a valid ref?
2300 {
2301 SwReaderPtr pRdr;
2302 Reader *pRead = pDocSh->StartConvertFrom(*pMedium, pRdr, m_pWrtShell.get());
2303 if( pRead ||
2304 (pMedium->GetFilter()->GetFilterFlags() & SfxFilterFlags::STARONEFILTER) )
2305 {
2306 size_t nUndoCheck = 0;
2307 SwDoc *pDoc = pDocSh->GetDoc();
2308 if( pRead && pDocSh->GetDoc() )
2309 nUndoCheck = lcl_PageDescWithHeader( *pDoc );
2310 ErrCode nErrno;
2311 { //Scope for SwWait-Object, to be able to execute slots
2312 //outside this scope.
2313 SwWait aWait( *GetDocShell(), true );
2314 m_pWrtShell->StartAllAction();
2315 if ( m_pWrtShell->HasSelection() )
2316 m_pWrtShell->DelRight(); // delete selections
2317 if( pRead )
2318 {
2319 nErrno = pRdr->Read( *pRead ); // and insert document
2320 pRdr.reset();
2321 }
2322 else
2323 {
2324 ::sw::UndoGuard const ug(pDoc->GetIDocumentUndoRedo());
2325 uno::Reference<text::XTextRange> const xInsertPosition(
2326 SwXTextRange::CreateXTextRange(*pDoc,
2327 *m_pWrtShell->GetCursor()->GetPoint(), nullptr));
2328 nErrno = pDocSh->ImportFrom(*pMedium, xInsertPosition)
2329 ? ERRCODE_NONEErrCode(0) : ERR_SWG_READ_ERRORErrCode(ErrCodeArea::Sw, ErrCodeClass::Read, 2 );
2330 }
2331
2332 }
2333
2334 // update all "table of ..." sections if needed
2335 if( m_pWrtShell->IsUpdateTOX() )
2336 {
2337 SfxRequest aReq( FN_UPDATE_TOX((20000 + 600) + 53), SfxCallMode::SLOT, GetPool() );
2338 Execute( aReq );
2339 m_pWrtShell->SetUpdateTOX( false ); // reset
2340 }
2341
2342 if( pDoc )
2343 { // Disable Undo for .sdw or
2344 // if the number of page styles with header/footer has changed
2345 if( !pRead || nUndoCheck != lcl_PageDescWithHeader( *pDoc ) )
2346 {
2347 pDoc->GetIDocumentUndoRedo().DelAllUndoObj();
2348 }
2349 }
2350
2351 m_pWrtShell->EndAllAction();
2352 if( nErrno )
2353 {
2354 ErrorHandler::HandleError( nErrno );
2355 nFound = nErrno.IsError() ? -1 : 0;
2356 }
2357 else
2358 nFound = 0;
2359 }
2360 }
2361 }
2362 else
2363 {
2364 SfxObjectShellRef xDocSh;
2365 SfxObjectShellLock xLockRef;
2366
2367 const int nRet = SwFindDocShell( xDocSh, xLockRef, pMedium->GetName(), OUString(),
2368 OUString(), nVersion, pDocSh );
2369 if( nRet )
2370 {
2371 SwWait aWait( *GetDocShell(), true );
2372 m_pWrtShell->StartAllAction();
2373
2374 m_pWrtShell->EnterStdMode(); // delete selections
2375
2376 if( bCompare )
2377 nFound = m_pWrtShell->CompareDoc( *static_cast<SwDocShell*>( xDocSh.get() )->GetDoc() );
2378 else
2379 nFound = m_pWrtShell->MergeDoc( *static_cast<SwDocShell*>( xDocSh.get() )->GetDoc() );
2380
2381 m_pWrtShell->EndAllAction();
2382
2383 if (!bCompare && !nFound)
2384 {
2385 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetEditWin().GetFrameWeld(),
2386 VclMessageType::Info, VclButtonsType::Ok,
2387 SwResId(STR_NO_MERGE_ENTRYreinterpret_cast<char const *>("STR_NO_MERGE_ENTRY" "\004"
u8"Could not merge documents.")
)));
2388 xInfoBox->run();
2389 }
2390 if( nRet==2 && xDocSh.is() )
2391 xDocSh->DoClose();
2392 }
2393 }
2394
2395 return nFound;
2396}
2397
2398void SwView::EnableMailMerge()
2399{
2400 m_bInMailMerge = true;
2401 SfxBindings& rBind = GetViewFrame()->GetBindings();
2402 rBind.Invalidate(FN_INSERT_FIELD_DATA_ONLY((20000 + 300) + 19));
2403 rBind.Update(FN_INSERT_FIELD_DATA_ONLY((20000 + 300) + 19));
2404}
2405
2406#if HAVE_FEATURE_DBCONNECTIVITY1
2407
2408namespace
2409{
2410 bool lcl_NeedAdditionalDataSource( const uno::Reference< XDatabaseContext >& _rDatasourceContext )
2411 {
2412 Sequence < OUString > aNames = _rDatasourceContext->getElementNames();
2413
2414 return ( !aNames.hasElements()
2415 || ( ( 1 == aNames.getLength() )
2416 && aNames.getConstArray()[0] == SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->GetDBConfig()->GetBibliographySource().sDataSource
2417 )
2418 );
2419 }
2420}
2421
2422#endif
2423
2424void SwView::GenerateFormLetter(bool bUseCurrentDocument)
2425{
2426#if !HAVE_FEATURE_DBCONNECTIVITY1
2427 (void) bUseCurrentDocument;
2428#else
2429 if(bUseCurrentDocument)
2430 {
2431 if(!GetWrtShell().IsAnyDatabaseFieldInDoc())
2432 {
2433 //check availability of data sources (except biblio source)
2434 uno::Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
2435 uno::Reference<XDatabaseContext> xDBContext = DatabaseContext::create(xContext);
2436 bool bCallAddressPilot = false;
2437 if ( lcl_NeedAdditionalDataSource( xDBContext ) )
2438 {
2439 // no data sources are available - create a new one
2440 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/datasourcesunavailabledialog.ui"));
2441 std::unique_ptr<weld::MessageDialog> xQuery(xBuilder->weld_message_dialog("DataSourcesUnavailableDialog"));
2442 // no cancel allowed
2443 if (RET_OK != xQuery->run())
2444 return;
2445 bCallAddressPilot = true;
2446 }
2447 else
2448 {
2449 //take an existing data source or create a new one?
2450 SwAbstractDialogFactory* pFact = SwAbstractDialogFactory::Create();
2451 ScopedVclPtr<AbstractMailMergeFieldConnectionsDlg> pConnectionsDlg(pFact->CreateMailMergeFieldConnectionsDlg(GetFrameWeld()));
2452 if(RET_OK == pConnectionsDlg->Execute())
2453 bCallAddressPilot = !pConnectionsDlg->IsUseExistingConnections();
2454 else
2455 return;
2456
2457 }
2458 if(bCallAddressPilot)
2459 {
2460 GetViewFrame()->GetDispatcher()->Execute(
2461 SID_ADDRESS_DATA_SOURCE(10000 + 934), SfxCallMode::SYNCHRON);
2462 if ( lcl_NeedAdditionalDataSource( xDBContext ) )
2463 // no additional data source has been created
2464 // -> assume that the user has cancelled the pilot
2465 return;
2466 }
2467
2468 //call insert fields with database field page available, only
2469 SfxViewFrame* pVFrame = GetViewFrame();
2470 //at first hide the default field dialog if currently visible
2471 pVFrame->SetChildWindow(FN_INSERT_FIELD((20000 + 300) + 8 ), false);
2472 //enable the status of the db field dialog - it is disabled in the status method
2473 //to prevent creation of the dialog without mail merge active
2474 EnableMailMerge();
2475 //then show the "Data base only" field dialog
2476 SfxBoolItem aOn(FN_INSERT_FIELD_DATA_ONLY((20000 + 300) + 19), true);
2477 pVFrame->GetDispatcher()->ExecuteList(FN_INSERT_FIELD_DATA_ONLY((20000 + 300) + 19),
2478 SfxCallMode::SYNCHRON, { &aOn });
2479 return;
2480 }
2481 else
2482 {
2483 OUString sSource;
2484 if(!GetWrtShell().IsFieldDataSourceAvailable(sSource))
2485 {
2486 std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/warndatasourcedialog.ui"));
2487 std::unique_ptr<weld::MessageDialog> xWarning(xBuilder->weld_message_dialog("WarnDataSourceDialog"));
2488 OUString sTmp(xWarning->get_primary_text());
2489 xWarning->set_primary_text(sTmp.replaceFirst("%1", sSource));
2490 if (RET_OK == xWarning->run())
2491 {
2492 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
2493 ScopedVclPtr<VclAbstractDialog> pDlg(pFact->CreateVclDialog( nullptr, SID_OPTIONS_DATABASES( 10000 + 1060 ) ));
2494 pDlg->Execute();
2495 }
2496 return ;
2497 }
2498 }
2499 SwDBManager* pDBManager = GetWrtShell().GetDBManager();
2500
2501 SwDBData aData;
2502 SwWrtShell &rSh = GetWrtShell();
2503
2504 std::vector<OUString> aDBNameList;
2505 std::vector<OUString> aAllDBNames;
2506 rSh.GetAllUsedDB( aDBNameList, &aAllDBNames );
2507 if(!aDBNameList.empty())
2508 {
2509 OUString sDBName(aDBNameList[0]);
2510 sal_Int32 nIdx {0};
2511 aData.sDataSource = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx);
2512 aData.sCommand = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx);
2513 aData.nCommandType = sDBName.getToken(0, DB_DELIMu'\x00ff', nIdx).toInt32();
2514 }
2515 rSh.EnterStdMode(); // force change in text shell; necessary for mixing DB fields
2516 AttrChangedNotify(nullptr);
2517
2518 if (pDBManager)
2519 {
2520 Sequence<PropertyValue> aProperties(3);
2521 PropertyValue* pValues = aProperties.getArray();
2522 pValues[0].Name = "DataSourceName";
2523 pValues[1].Name = "Command";
2524 pValues[2].Name = "CommandType";
2525 pValues[0].Value <<= aData.sDataSource;
2526 pValues[1].Value <<= aData.sCommand;
2527 pValues[2].Value <<= aData.nCommandType;
2528 pDBManager->ExecuteFormLetter(GetWrtShell(), aProperties);
2529 }
2530 }
2531 else
2532 {
2533 // call documents and template dialog
2534 SfxApplication* pSfxApp = SfxGetpApp();
2535 vcl::Window* pTopWin = pSfxApp->GetTopWindow();
2536
2537 SfxTemplateManagerDlg aDocTemplDlg(GetFrameWeld());
2538 int nRet = aDocTemplDlg.run();
2539 bool bNewWin = false;
2540 if ( nRet == RET_OK )
2541 {
2542 if ( pTopWin != pSfxApp->GetTopWindow() )
2543 {
2544 // the dialogue opens a document -> a new TopWindow appears
2545 pTopWin = pSfxApp->GetTopWindow();
2546 bNewWin = true;
2547 }
2548 }
2549
2550 if ( bNewWin )
2551 // after the destruction of the dialogue its parent comes to top,
2552 // but we want that the new document is on top
2553 pTopWin->ToTop();
2554 }
2555#endif
2556}
2557
2558IMPL_LINK( SwView, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void )void SwView::LinkStubDialogClosedHdl(void * instance, sfx2::FileDialogHelper
* data) { return static_cast<SwView *>(instance)->DialogClosedHdl
(data); } void SwView::DialogClosedHdl(sfx2::FileDialogHelper
* _pFileDlg)
2559{
2560 if ( ERRCODE_NONEErrCode(0) != _pFileDlg->GetError() )
2561 return;
2562
2563 std::unique_ptr<SfxMedium> pMed = m_pViewImpl->CreateMedium();
2564 if ( !pMed )
2565 {
2566 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(GetEditWin().GetFrameWeld(),
2567 VclMessageType::Info, VclButtonsType::Ok,
2568 SwResId(RID_SVXSTR_TXTFILTER_FILTERERRORreinterpret_cast<char const *>("RID_SVXSTR_TXTFILTER_FILTERERROR"
"\004" u8"This is not a text document")
)));
2569 xInfoBox->run();
2570 return;
2571 }
2572
2573 const sal_uInt16 nSlot = m_pViewImpl->GetRequest()->GetSlot();
2574 long nFound = InsertMedium( nSlot, std::move(pMed), m_pViewImpl->GetParam() );
2575
2576 if ( SID_INSERTDOC(5000 + 532) == nSlot )
2577 {
2578 if ( m_pViewImpl->GetParam() == 0 )
2579 {
2580 m_pViewImpl->GetRequest()->SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
2581 m_pViewImpl->GetRequest()->Ignore();
2582 }
2583 else
2584 {
2585 m_pViewImpl->GetRequest()->SetReturnValue( SfxBoolItem( nSlot, nFound != -1 ) );
2586 m_pViewImpl->GetRequest()->Done();
2587 }
2588 }
2589 else if ( SID_DOCUMENT_COMPARE(5000 + 1586) == nSlot || SID_DOCUMENT_MERGE(5000 + 1587) == nSlot )
2590 {
2591 m_pViewImpl->GetRequest()->SetReturnValue( SfxInt32Item( nSlot, nFound ) );
2592
2593 if ( nFound > 0 ) // show Redline browser
2594 {
2595 SfxViewFrame* pVFrame = GetViewFrame();
2596 pVFrame->ShowChildWindow(FN_REDLINE_ACCEPT((20000 + 1800) + 29));
2597
2598 // re-initialize Redline dialog
2599 sal_uInt16 nId = SwRedlineAcceptChild::GetChildWindowId();
2600 SwRedlineAcceptChild* pRed = static_cast<SwRedlineAcceptChild*>(pVFrame->GetChildWindow( nId ));
2601 if ( pRed )
2602 pRed->ReInitDlg( GetDocShell() );
2603 }
2604 }
2605}
2606
2607void SwView::ExecuteScan( SfxRequest& rReq )
2608{
2609 if (m_pViewImpl)
2610 m_pViewImpl->ExecuteScan(rReq) ;
2611}
2612
2613const OUString& SwView::GetOldGrfCat()
2614{
2615 return GetCachedString(OldGrfCat);
2616}
2617
2618void SwView::SetOldGrfCat(const OUString& sStr)
2619{
2620 SetCachedString(OldGrfCat, sStr);
2621}
2622
2623const OUString& SwView::GetOldTabCat()
2624{
2625 return GetCachedString(OldTabCat);
2626}
2627
2628void SwView::SetOldTabCat(const OUString& sStr)
2629{
2630 SetCachedString(OldTabCat, sStr);
2631}
2632
2633const OUString& SwView::GetOldFrameCat()
2634{
2635 return GetCachedString(OldFrameCat);
2636}
2637
2638void SwView::SetOldFrameCat(const OUString& sStr)
2639{
2640 SetCachedString(OldFrameCat, sStr);
2641}
2642
2643const OUString& SwView::GetOldDrwCat()
2644{
2645 return GetCachedString(OldDrwCat);
2646}
2647
2648void SwView::SetOldDrwCat(const OUString& sStr)
2649{
2650 SwView::SetCachedString(OldDrwCat, sStr);
2651}
2652
2653
2654/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/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();
21
Calling 'Reference::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();
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)
3
Calling implicit copy constructor for 'VclPtr<VclAbstractDialog>'
4
Calling copy constructor for 'Reference<VclAbstractDialog>'
7
Returning from copy constructor for 'Reference<VclAbstractDialog>'
8
Returning from copy constructor for 'VclPtr<VclAbstractDialog>'
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: */

/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)
5
Assuming field 'm_pBody' is non-null
6
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
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
11.1
Field 'm_pBody' is non-null
)
12
Taking true branch
113 m_pBody->release();
13
Calling 'VclReferenceBase::release'
17
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;
22
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)
14
Assuming the condition is true
15
Taking true branch
40 delete this;
16
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