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 cellsh3.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 SC_DLLIMPLEMENTATION -D SC_INFO_OSVERSION="LINUX" -D SYSTEM_LIBXML -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/liborcus/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -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/clew/source/include -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/sc/source/core/inc -I /home/maarten/src/libreoffice/core/sc/source/filter/inc -I /home/maarten/src/libreoffice/core/sc/source/ui/inc -I /home/maarten/src/libreoffice/core/sc/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sc/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/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/sc/source/ui/view/cellsh3.cxx

/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.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 <scitems.hxx>
21#include <editeng/editview.hxx>
22#include <editeng/editeng.hxx>
23#include <formula/formulahelper.hxx>
24#include <sfx2/viewfrm.hxx>
25#include <sfx2/bindings.hxx>
26#include <sfx2/dispatch.hxx>
27#include <sfx2/request.hxx>
28#include <svl/stritem.hxx>
29#include <vcl/svapp.hxx>
30#include <vcl/weld.hxx>
31#include <globstr.hrc>
32#include <scresid.hxx>
33#include <scmod.hxx>
34#include <appoptio.hxx>
35#include <tabvwsh.hxx>
36#include <document.hxx>
37#include <sc.hrc>
38#include <reffact.hxx>
39#include <uiitems.hxx>
40#include <autoform.hxx>
41#include <cellsh.hxx>
42#include <inputhdl.hxx>
43#include <editable.hxx>
44#include <funcdesc.hxx>
45#include <markdata.hxx>
46#include <scabstdlg.hxx>
47#include <columnspanset.hxx>
48#include <comphelper/lok.hxx>
49#include <LibreOfficeKit/LibreOfficeKitEnums.h>
50#include <sfx2/lokhelper.hxx>
51
52#include <memory>
53
54#define IS_EDITMODE()GetViewData()->HasEditView( GetViewData()->GetActivePart
() )
GetViewData()->HasEditView( GetViewData()->GetActivePart() )
55
56using sc::HMMToTwips;
57using sc::TwipsToEvenHMM;
58
59namespace
60{
61/// Rid ourselves of unwanted " quoted json characters.
62OString escapeJSON(const OUString &aStr)
63{
64 OUString aEscaped = aStr;
65 aEscaped = aEscaped.replaceAll("\n", " ");
66 aEscaped = aEscaped.replaceAll("\"", "'");
67 return OUStringToOString(aEscaped, RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)));
68}
69
70void lcl_lokGetWholeFunctionList()
71{
72 const SfxViewShell* pViewShell = SfxViewShell::Current();
73 if (!(comphelper::LibreOfficeKit::isActive()
74 && pViewShell && pViewShell->isLOKMobilePhone()))
75 return;
76
77 const ScFunctionList* pFuncList = ScGlobal::GetStarCalcFunctionList();
78 sal_uInt32 nListCount = pFuncList->GetCount();
79 std::set<OUString> aFuncNameOrderedSet;
80 for(sal_uInt32 i = 0; i < nListCount; ++i)
81 {
82 const ScFuncDesc* pDesc = pFuncList->GetFunction( i );
83 if ( pDesc->mxFuncName )
84 {
85 aFuncNameOrderedSet.insert(*pDesc->mxFuncName);
86 }
87 }
88 ScFunctionMgr* pFuncManager = ScGlobal::GetStarCalcFunctionMgr();
89 if (!(pFuncManager && aFuncNameOrderedSet.size()))
90 return;
91
92 OStringBuffer aPayload;
93 aPayload.append("{ \"wholeList\": true, ");
94 aPayload.append("\"categories\": [ ");
95
96 formula::FormulaHelper aHelper(pFuncManager);
97 sal_uInt32 nCategoryCount = pFuncManager->getCount();
98 for (sal_uInt32 i = 0; i < nCategoryCount; ++i)
99 {
100 OUString sCategoryName = ScFunctionMgr::GetCategoryName(i);
101 aPayload.append("{");
102 aPayload.append("\"name\": \"");
103 aPayload.append(escapeJSON(sCategoryName));
104 aPayload.append("\"}, ");
105 }
106 sal_Int32 nLen = aPayload.getLength();
107 aPayload[nLen - 2] = ' ';
108 aPayload[nLen - 1] = ']';
109 aPayload.append(", ");
110
111 OUString aDescFuncNameStr;
112 aPayload.append("\"functions\": [ ");
113 sal_uInt32 nCurIndex = 0;
114 for (const OUString& aFuncNameStr : aFuncNameOrderedSet)
115 {
116 aDescFuncNameStr = aFuncNameStr + "()";
117 sal_Int32 nNextFStart = 0;
118 const formula::IFunctionDescription* ppFDesc;
119 ::std::vector< OUString > aArgs;
120 OUString eqPlusFuncName = "=" + aDescFuncNameStr;
121 if ( aHelper.GetNextFunc( eqPlusFuncName, false, nNextFStart, nullptr, &ppFDesc, &aArgs ) )
122 {
123 if ( ppFDesc && !ppFDesc->getFunctionName().isEmpty() )
124 {
125 if (ppFDesc->getCategory())
126 {
127 aPayload.append("{");
128 aPayload.append("\"index\": ");
129 aPayload.append(OString::number(nCurIndex));
130 aPayload.append(", ");
131 aPayload.append("\"category\": ");
132 aPayload.append(OString::number(ppFDesc->getCategory()->getNumber()));
133 aPayload.append(", ");
134 aPayload.append("\"signature\": \"");
135 aPayload.append(escapeJSON(ppFDesc->getSignature()));
136 aPayload.append("\", ");
137 aPayload.append("\"description\": \"");
138 aPayload.append(escapeJSON(ppFDesc->getDescription()));
139 aPayload.append("\"}, ");
140 }
141 }
142 }
143 ++nCurIndex;
144 }
145 nLen = aPayload.getLength();
146 aPayload[nLen - 2] = ' ';
147 aPayload[nLen - 1] = ']';
148 aPayload.append(" }");
149
150 OString s = aPayload.makeStringAndClear();
151 pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_CALC_FUNCTION_LIST, s.getStr());
152}
153
154} // end namespace
155
156void ScCellShell::Execute( SfxRequest& rReq )
157{
158 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell();
159 SfxBindings& rBindings = pTabViewShell->GetViewFrame()->GetBindings();
160 ScModule* pScMod = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
;
161 const SfxItemSet* pReqArgs = rReq.GetArgs();
162 sal_uInt16 nSlot = rReq.GetSlot();
163
164 if (nSlot != SID_CURRENTCELL((26000) + 41)) // this comes with MouseButtonUp
1
Assuming the condition is true
2
Taking true branch
165 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox
166
167 if ( IS_EDITMODE()GetViewData()->HasEditView( GetViewData()->GetActivePart
() )
)
3
Taking false branch
168 {
169 switch ( nSlot )
170 {
171 // when opening a reference-dialog the subshell may not be switched
172 // (on closing the dialog StopEditShell is called)
173 case SID_OPENDLG_FUNCTION((26000 + 100) + 52):
174 // inplace leads to trouble with EditShell ...
175 //! cannot always be switched ????
176 if (!pTabViewShell->GetViewFrame()->GetFrame().IsInPlace())
177 pTabViewShell->SetDontSwitch(true); // do not switch off EditShell
178 [[fallthrough]];
179
180 case FID_CELL_FORMAT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25))):
181 case SID_ENABLE_HYPHENATION((26000) + 87):
182 case SID_DATA_SELECT((((26000 + 521) + 50))+39):
183 case SID_OPENDLG_CONSOLIDATE((26000 + 100) + 50):
184 case SID_OPENDLG_SOLVE((26000 + 100) + 53):
185 case SID_OPENDLG_OPTSOLVER((26000 + 100) + 60):
186
187 pScMod->InputEnterHandler();
188 pTabViewShell->UpdateInputHandler();
189
190 pTabViewShell->SetDontSwitch(false);
191
192 break;
193
194 default:
195 break;
196 }
197 }
198
199 switch ( nSlot )
4
Control jumps to 'case 26291:' at line 816
200 {
201 case SID_STATUS_SELMODE((26000 + 100) + 16):
202 if ( pReqArgs )
203 {
204 /* 0: STD Click cancels selection
205 * 1: ER Click extends selection
206 * 2: ERG Click defines further selection
207 */
208 sal_uInt16 nMode = static_cast<const SfxUInt16Item&>(pReqArgs->Get( nSlot )).GetValue();
209
210 switch ( nMode )
211 {
212 case 1: nMode = KEY_SHIFT; break;
213 case 2: nMode = KEY_MOD1; break; // control-key
214 case 0:
215 default:
216 nMode = 0;
217 }
218
219 pTabViewShell->LockModifiers( nMode );
220 }
221 else
222 {
223 // no arguments (also executed by double click on the status bar controller):
224 // advance to next selection mode
225
226 sal_uInt16 nModifiers = pTabViewShell->GetLockedModifiers();
227 switch ( nModifiers )
228 {
229 case KEY_SHIFT: nModifiers = KEY_MOD1; break; // EXT -> ADD
230 case KEY_MOD1: nModifiers = 0; break; // ADD -> STD
231 default: nModifiers = KEY_SHIFT; break; // STD -> EXT
232 }
233 pTabViewShell->LockModifiers( nModifiers );
234 }
235
236 rBindings.Invalidate( SID_STATUS_SELMODE((26000 + 100) + 16) );
237 rReq.Done();
238 break;
239
240 // SID_STATUS_SELMODE_NORM is not used ???
241
242 case SID_STATUS_SELMODE_NORM((26000 + 100) + 24):
243 pTabViewShell->LockModifiers( 0 );
244 rBindings.Invalidate( SID_STATUS_SELMODE((26000 + 100) + 16) );
245 break;
246
247 // SID_STATUS_SELMODE_ERG / SID_STATUS_SELMODE_ERW as toggles:
248
249 case SID_STATUS_SELMODE_ERG((26000 + 100) + 22):
250 if ( pTabViewShell->GetLockedModifiers() & KEY_MOD1 )
251 pTabViewShell->LockModifiers( 0 );
252 else
253 pTabViewShell->LockModifiers( KEY_MOD1 );
254 rBindings.Invalidate( SID_STATUS_SELMODE((26000 + 100) + 16) );
255 break;
256
257 case SID_STATUS_SELMODE_ERW((26000 + 100) + 23):
258 if ( pTabViewShell->GetLockedModifiers() & KEY_SHIFT )
259 pTabViewShell->LockModifiers( 0 );
260 else
261 pTabViewShell->LockModifiers( KEY_SHIFT );
262 rBindings.Invalidate( SID_STATUS_SELMODE((26000 + 100) + 16) );
263 break;
264
265 case SID_ENTER_STRING((26000 + 100) + 37):
266 {
267 if ( pReqArgs )
268 {
269 // In the LOK case, we want to set the document modified state
270 // right away at the start of the edit, so that the content is
271 // saved even when the user leaves the document before hitting
272 // Enter
273 // NOTE: This also means we want to set the modified state
274 // regardless of the DontCommit parameter's value.
275 if (comphelper::LibreOfficeKit::isActive() && !GetViewData()->GetDocShell()->IsModified())
276 {
277 GetViewData()->GetDocShell()->SetModified();
278 rBindings.Invalidate(SID_SAVEDOC(5000 + 505));
279 rBindings.Invalidate(SID_DOC_MODIFIED(5000 + 584));
280 }
281
282 OUString aStr( static_cast<const SfxStringItem&>(pReqArgs->
283 Get( SID_ENTER_STRING((26000 + 100) + 37) )).GetValue() );
284 const SfxPoolItem* pDontCommitItem;
285 bool bCommit = true;
286 if (pReqArgs->HasItem(FN_PARAM_1((20000 + 1100)+60), &pDontCommitItem))
287 bCommit = !(static_cast<const SfxBoolItem*>(pDontCommitItem)->GetValue());
288
289 ScInputHandler* pHdl = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->GetInputHdl( pTabViewShell );
290 if (bCommit)
291 {
292 pTabViewShell->EnterData( GetViewData()->GetCurX(),
293 GetViewData()->GetCurY(),
294 GetViewData()->GetTabNo(),
295 aStr );
296 }
297 else if (pHdl)
298 {
299 SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->SetInputMode(SC_INPUT_TABLE);
300
301 EditView* pTableView = pHdl->GetActiveView();
302 pHdl->DataChanging();
303 if (pTableView)
304 pTableView->GetEditEngine()->SetText(aStr);
305 pHdl->DataChanged();
306
307 SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->SetInputMode(SC_INPUT_NONE);
308 }
309
310 if ( !pHdl || !pHdl->IsInEnterHandler() )
311 {
312 // UpdateInputHandler is needed after the cell content
313 // has changed, but if called from EnterHandler, UpdateInputHandler
314 // will be called later when moving the cursor.
315 pTabViewShell->UpdateInputHandler();
316 }
317
318 rReq.Done();
319
320 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
321 // sideview, when the input was not finished
322 // (GrabFocus is called in KillEditView)
323 }
324 }
325 break;
326
327 case SID_INSERT_MATRIX((((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20))
+ 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+20))+1
)
:
328 {
329 if ( pReqArgs )
330 {
331 OUString aStr = static_cast<const SfxStringItem&>(pReqArgs->
332 Get( SID_INSERT_MATRIX((((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20))
+ 25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+20))+1
)
)).GetValue();
333 ScDocument& rDoc = GetViewData()->GetDocument();
334 pTabViewShell->EnterMatrix( aStr, rDoc.GetGrammar() );
335 rReq.Done();
336 }
337 }
338 break;
339
340 case FID_INPUTLINE_ENTER((26000 + 100) + 1):
341 case FID_INPUTLINE_BLOCK((26000 + 100) + 29):
342 case FID_INPUTLINE_MATRIX((26000 + 100) + 11):
343 {
344 if( pReqArgs == nullptr ) //XXX temporary HACK to avoid GPF
345 break;
346
347 const ScInputStatusItem* pStatusItem
348 = static_cast<const ScInputStatusItem*>(&pReqArgs->
349 Get( FID_INPUTLINE_STATUS((26000 + 100)) ));
350
351 const ScAddress& aCursorPos = pStatusItem->GetPos();
352 const OUString& aString = pStatusItem->GetString();
353 const EditTextObject* pData = pStatusItem->GetEditData();
354
355 if (pData)
356 {
357 if (nSlot == FID_INPUTLINE_BLOCK((26000 + 100) + 29))
358 {
359 pTabViewShell->EnterBlock( aString, pData );
360 }
361 else if ( !aString.isEmpty() && ( aString[0] == '=' || aString[0] == '+' || aString[0] == '-' ) )
362 {
363 pTabViewShell->EnterData( aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aString, pData );
364 }
365 else
366 {
367 pTabViewShell->EnterData(aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), *pData);
368 }
369 }
370 else
371 {
372 if (nSlot == FID_INPUTLINE_ENTER((26000 + 100) + 1))
373 {
374 if (
375 aCursorPos.Col() == GetViewData()->GetCurX() &&
376 aCursorPos.Row() == GetViewData()->GetCurY() &&
377 aCursorPos.Tab() == GetViewData()->GetTabNo()
378 )
379 {
380 SfxStringItem aItem( SID_ENTER_STRING((26000 + 100) + 37), aString );
381
382 const SfxPoolItem* aArgs[2];
383 aArgs[0] = &aItem;
384 aArgs[1] = nullptr;
385 rBindings.Execute( SID_ENTER_STRING((26000 + 100) + 37), aArgs );
386 }
387 else
388 {
389 pTabViewShell->EnterData( aCursorPos.Col(),
390 aCursorPos.Row(),
391 aCursorPos.Tab(),
392 aString );
393 rReq.Done();
394 }
395 }
396 else if (nSlot == FID_INPUTLINE_BLOCK((26000 + 100) + 29))
397 {
398 pTabViewShell->EnterBlock( aString, nullptr );
399 rReq.Done();
400 }
401 else
402 {
403 ScDocument& rDoc = GetViewData()->GetDocument();
404 pTabViewShell->EnterMatrix( aString, rDoc.GetGrammar() );
405 rReq.Done();
406 }
407 }
408
409 pTabViewShell->SetAutoSpellData(
410 aCursorPos.Col(), aCursorPos.Row(), pStatusItem->GetMisspellRanges());
411
412 // no GrabFocus here, as otherwise on a Mac the tab jumps before the
413 // sideview, when the input was not finished
414 // (GrabFocus is called in KillEditView)
415 }
416 break;
417
418 case SID_OPENDLG_FUNCTION((26000 + 100) + 52):
419 {
420 const SfxViewShell* pViewShell = SfxViewShell::Current();
421 if (comphelper::LibreOfficeKit::isActive()
422 && pViewShell && pViewShell->isLOKMobilePhone())
423 {
424 // not set the dialog id in the mobile case or we would
425 // not be able to get cell address pasted in the edit view
426 // by just tapping on them
427 lcl_lokGetWholeFunctionList();
428 }
429 else
430 {
431 sal_uInt16 nId = SID_OPENDLG_FUNCTION((26000 + 100) + 52);
432 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
433 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
434 bool bVis = comphelper::LibreOfficeKit::isActive() || pWnd == nullptr;
435 pScMod->SetRefDialog( nId, bVis );
436 }
437 rReq.Ignore();
438 }
439 break;
440
441 case SID_OPENDLG_CONSOLIDATE((26000 + 100) + 50):
442 {
443 sal_uInt16 nId = ScConsolidateDlgWrapper::GetChildWindowId();
444 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
445 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
446
447 pScMod->SetRefDialog( nId, pWnd == nullptr );
448 }
449 break;
450
451 case FID_CELL_FORMAT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25))):
452 {
453 if ( pReqArgs != nullptr )
454 {
455
456 // set cell attribute without dialog:
457
458 std::unique_ptr<SfxItemSet> pEmptySet(
459 new SfxItemSet( *pReqArgs->GetPool(),
460 svl::Items<ATTR_PATTERN_START,
461 ATTR_PATTERN_END>{} ));
462
463 std::unique_ptr<SfxItemSet> pNewSet(
464 new SfxItemSet( *pReqArgs->GetPool(),
465 svl::Items<ATTR_PATTERN_START,
466 ATTR_PATTERN_END>{} ));
467
468 const SfxPoolItem* pAttr = nullptr;
469 sal_uInt16 nWhich = 0;
470
471 for ( nWhich=ATTR_PATTERN_START; nWhich<=ATTR_PATTERN_END; nWhich++ )
472 if ( pReqArgs->GetItemState( nWhich, true, &pAttr ) == SfxItemState::SET )
473 pNewSet->Put( *pAttr );
474
475 pTabViewShell->ApplyAttributes( pNewSet.get(), pEmptySet.get() );
476
477 pNewSet.reset();
478 pEmptySet.reset();
479
480 rReq.Done();
481 }
482 else
483 {
484 pTabViewShell->ExecuteCellFormatDlg( rReq, "" );
485 }
486 }
487 break;
488
489 case SID_ENABLE_HYPHENATION((26000) + 87):
490 pTabViewShell->ExecuteCellFormatDlg(rReq, "alignment");
491 break;
492
493 case SID_PROPERTY_PANEL_CELLTEXT_DLG((26000 + 400)+0):
494 pTabViewShell->ExecuteCellFormatDlg( rReq, "font" );
495 break;
496
497 case SID_CELL_FORMAT_BORDER( 10000 + 1132 ):
498 pTabViewShell->ExecuteCellFormatDlg( rReq, "borders" );
499 break;
500
501 case SID_CHAR_DLG_EFFECT( 10000 + 1133 ):
502 pTabViewShell->ExecuteCellFormatDlg( rReq, "fonteffects" );
503 break;
504
505 case SID_OPENDLG_SOLVE((26000 + 100) + 53):
506 {
507 sal_uInt16 nId = ScSolverDlgWrapper::GetChildWindowId();
508 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
509 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
510
511 pScMod->SetRefDialog( nId, pWnd == nullptr );
512 }
513 break;
514
515 case SID_OPENDLG_OPTSOLVER((26000 + 100) + 60):
516 {
517 sal_uInt16 nId = ScOptSolverDlgWrapper::GetChildWindowId();
518 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
519 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
520
521 pScMod->SetRefDialog( nId, pWnd == nullptr );
522 }
523 break;
524
525 case SID_OPENDLG_TABOP((26000 + 100) + 54):
526 {
527 sal_uInt16 nId = ScTabOpDlgWrapper::GetChildWindowId();
528 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame();
529 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId );
530
531 pScMod->SetRefDialog( nId, pWnd == nullptr );
532 }
533 break;
534
535 case SID_SCENARIOS((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) +
12)
:
536 {
537 ScDocument& rDoc = GetViewData()->GetDocument();
538 ScMarkData& rMark = GetViewData()->GetMarkData();
539 SCTAB nTab = GetViewData()->GetTabNo();
540
541 if ( rDoc.IsScenario(nTab) )
542 {
543 rMark.MarkToMulti();
544 if ( rMark.IsMultiMarked() )
545 {
546
547 bool bExtend = rReq.IsAPI();
548 if (!bExtend)
549 {
550 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
551 VclMessageType::Question, VclButtonsType::YesNo,
552 ScResId(STR_UPDATE_SCENARIOreinterpret_cast<char const *>("STR_UPDATE_SCENARIO" "\004"
u8"Add selected ranges to current scenario?")
)));
553 xQueryBox->set_default_response(RET_YES);
554 bExtend = xQueryBox->run() == RET_YES;
555 }
556
557 if (bExtend)
558 {
559 pTabViewShell->ExtendScenario();
560 rReq.Done();
561 }
562 }
563 else if( ! rReq.IsAPI() )
564 {
565 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(pTabViewShell->GetFrameWeld(),
566 VclMessageType::Warning, VclButtonsType::Ok,
567 ScResId(STR_NOAREASELECTEDreinterpret_cast<char const *>("STR_NOAREASELECTED" "\004"
u8"A range has not been selected.")
)));
568 xErrorBox->run();
569 }
570 }
571 else
572 {
573 rMark.MarkToMulti();
574 if ( rMark.IsMultiMarked() )
575 {
576 SCTAB i=1;
577 OUString aBaseName;
578 OUString aName;
579 Color aColor;
580 ScScenarioFlags nFlags;
581
582 OUString aTmp;
583 rDoc.GetName(nTab, aTmp);
584 aBaseName = aTmp + "_" + ScResId(STR_SCENARIOreinterpret_cast<char const *>("STR_SCENARIO" "\004" u8"Scenario"
)
) + "_";
585
586 // first test, if the prefix is recognised as valid,
587 // else avoid only doubles
588 bool bPrefix = ScDocument::ValidTabName( aBaseName );
589 OSL_ENSURE(bPrefix, "invalid sheet name")do { if (true && (!(bPrefix))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.cxx"
":" "589" ": "), "%s", "invalid sheet name"); } } while (false
)
;
590
591 while ( rDoc.IsScenario(nTab+i) )
592 i++;
593
594 bool bValid;
595 SCTAB nDummy;
596 do
597 {
598 aName = aBaseName + OUString::number( i );
599 if (bPrefix)
600 bValid = rDoc.ValidNewTabName( aName );
601 else
602 bValid = !rDoc.GetTable( aName, nDummy );
603 ++i;
604 }
605 while ( !bValid && i <= MAXTAB + 2 );
606
607 if ( pReqArgs != nullptr )
608 {
609 OUString aArgName;
610 OUString aArgComment;
611 const SfxPoolItem* pItem;
612 if ( pReqArgs->GetItemState( SID_SCENARIOS((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) +
12)
, true, &pItem ) == SfxItemState::SET )
613 aArgName = static_cast<const SfxStringItem*>(pItem)->GetValue();
614 if ( pReqArgs->GetItemState( SID_NEW_TABLENAME((((26000 + 521) + 50))+1), true, &pItem ) == SfxItemState::SET )
615 aArgComment = static_cast<const SfxStringItem*>(pItem)->GetValue();
616
617 aColor = COL_LIGHTGRAY; // Default
618 nFlags = ScScenarioFlags::NONE; // not TwoWay
619
620 pTabViewShell->MakeScenario( aArgName, aArgComment, aColor, nFlags );
621 if( ! rReq.IsAPI() )
622 rReq.Done();
623 }
624 else
625 {
626 bool bSheetProtected = rDoc.IsTabProtected(nTab);
627 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
628
629 ScopedVclPtr<AbstractScNewScenarioDlg> pNewDlg(pFact->CreateScNewScenarioDlg(pTabViewShell->GetFrameWeld(), aName, false, bSheetProtected));
630 if ( pNewDlg->Execute() == RET_OK )
631 {
632 OUString aComment;
633 pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
634 pTabViewShell->MakeScenario( aName, aComment, aColor, nFlags );
635
636 rReq.AppendItem( SfxStringItem( SID_SCENARIOS((((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 22)) +
12)
, aName ) );
637 rReq.AppendItem( SfxStringItem( SID_NEW_TABLENAME((((26000 + 521) + 50))+1), aComment ) );
638 rReq.Done();
639 }
640 }
641 }
642 else if( ! rReq.IsAPI() )
643 {
644 pTabViewShell->ErrorMessage(STR_ERR_NEWSCENARIOreinterpret_cast<char const *>("STR_ERR_NEWSCENARIO" "\004"
u8"The scenario ranges must be selected in order to be able to create a new scenario."
)
);
645 }
646 }
647 }
648 break;
649
650 case SID_SELECTALL(5000 + 723):
651 {
652 pTabViewShell->SelectAll();
653 rReq.Done();
654 }
655 break;
656
657 case FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1):
658 {
659 const SfxPoolItem* pRow;
660 const SfxPoolItem* pHeight;
661 sal_uInt16 nHeight;
662
663 if ( pReqArgs && pReqArgs->HasItem( FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1), &pHeight ) &&
664 pReqArgs->HasItem( FN_PARAM_1((20000 + 1100)+60), &pRow ) )
665 {
666 std::vector<sc::ColRowSpan> aRanges;
667 SCCOLROW nRow = static_cast<const SfxInt32Item*>(pRow)->GetValue() - 1;
668 nHeight = static_cast<const SfxUInt16Item*>(pHeight)->GetValue();
669 ScMarkData& rMark = GetViewData()->GetMarkData();
670
671 if ( rMark.IsRowMarked( static_cast<SCROW>(nRow) ) )
672 {
673 aRanges = rMark.GetMarkedRowSpans();
674 }
675 else
676 {
677 aRanges.emplace_back(nRow, nRow);
678 }
679
680 pTabViewShell->SetWidthOrHeight(false, aRanges, SC_SIZE_DIRECT, HMMToTwips(nHeight));
681 }
682 else if ( pReqArgs && pReqArgs->HasItem( FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1), &pHeight ) )
683 {
684 nHeight = static_cast<const SfxUInt16Item*>(pHeight)->GetValue();
685
686 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
687 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT,
688 sal::static_int_cast<sal_uInt16>( HMMToTwips(nHeight) ) );
689 if( ! rReq.IsAPI() )
690 rReq.Done();
691 }
692 else
693 {
694 ScViewData* pData = GetViewData();
695 FieldUnit eMetric = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->GetAppOptions().GetAppMetric();
696 sal_uInt16 nCurHeight = pData->GetDocument().
697 GetRowHeight( pData->GetCurY(),
698 pData->GetTabNo() );
699 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
700 ScopedVclPtr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
701 pTabViewShell->GetFrameWeld(), "RowHeightDialog",
702 nCurHeight, ScGlobal::nStdRowHeight,
703 eMetric, 2, MAX_ROW_HEIGHT56693));
704
705 if ( pDlg->Execute() == RET_OK )
706 {
707 long nVal = pDlg->GetInputValue();
708 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, static_cast<sal_uInt16>(nVal) );
709
710 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
711 rReq.AppendItem( SfxUInt16Item( FID_ROW_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 1), static_cast<sal_uInt16>(TwipsToEvenHMM(nVal)) ) );
712 rReq.Done();
713
714 }
715 }
716 }
717 break;
718
719 case FID_ROW_OPT_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 2):
720 {
721 if ( pReqArgs )
722 {
723 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_ROW_OPT_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 2) ));
724
725 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
726 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL,
727 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
728 ScGlobal::nLastRowHeightExtra = rUInt16Item.GetValue();
729
730 if( ! rReq.IsAPI() )
731 rReq.Done();
732 }
733 else
734 {
735 FieldUnit eMetric = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->GetAppOptions().GetAppMetric();
736
737 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
738 ScopedVclPtr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
739 pTabViewShell->GetFrameWeld(), "OptimalRowHeightDialog",
740 ScGlobal::nLastRowHeightExtra, 0, eMetric, 1, MAX_EXTRA_HEIGHT23811));
741 if ( pDlg->Execute() == RET_OK )
742 {
743 long nVal = pDlg->GetInputValue();
744 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_OPTIMAL, static_cast<sal_uInt16>(nVal) );
745 ScGlobal::nLastRowHeightExtra = nVal;
746
747 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
748 rReq.AppendItem( SfxUInt16Item( FID_ROW_OPT_HEIGHT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 2), static_cast<sal_uInt16>(TwipsToEvenHMM(nVal)) ) );
749 rReq.Done();
750
751 }
752 }
753 }
754 break;
755
756 case FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5):
757 {
758 const SfxPoolItem* pColumn;
759 const SfxPoolItem* pWidth;
760 sal_uInt16 nWidth;
761
762 if ( pReqArgs && pReqArgs->HasItem( FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5), &pWidth ) &&
763 pReqArgs->HasItem( FN_PARAM_1((20000 + 1100)+60), &pColumn ) )
764 {
765 std::vector<sc::ColRowSpan> aRanges;
766 SCCOLROW nColumn = static_cast<const SfxUInt16Item*>(pColumn)->GetValue() - 1;
767 nWidth = static_cast<const SfxUInt16Item*>(pWidth)->GetValue();
768 ScMarkData& rMark = GetViewData()->GetMarkData();
769
770 if ( rMark.IsColumnMarked( static_cast<SCCOL>(nColumn) ) )
771 {
772 aRanges = rMark.GetMarkedColSpans();
773 }
774 else
775 {
776 aRanges.emplace_back(nColumn, nColumn);
777 }
778
779 pTabViewShell->SetWidthOrHeight(true, aRanges, SC_SIZE_DIRECT, HMMToTwips(nWidth));
780 }
781 else if ( pReqArgs && pReqArgs->HasItem( FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5), &pWidth ) )
782 {
783 nWidth = static_cast<const SfxUInt16Item*>(pWidth)->GetValue();
784
785 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
786 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT,
787 sal::static_int_cast<sal_uInt16>( HMMToTwips(nWidth) ) );
788 if( ! rReq.IsAPI() )
789 rReq.Done();
790 }
791 else
792 {
793 FieldUnit eMetric = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->GetAppOptions().GetAppMetric();
794 ScViewData* pData = GetViewData();
795 sal_uInt16 nCurHeight = pData->GetDocument().
796 GetColWidth( pData->GetCurX(),
797 pData->GetTabNo() );
798 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
799 ScopedVclPtr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
800 pTabViewShell->GetFrameWeld(), "ColWidthDialog", nCurHeight,
801 STD_COL_WIDTH1280, eMetric, 2, MAX_COL_WIDTH56693));
802 if ( pDlg->Execute() == RET_OK )
803 {
804 long nVal = pDlg->GetInputValue();
805 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, static_cast<sal_uInt16>(nVal) );
806
807 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
808 rReq.AppendItem( SfxUInt16Item( FID_COL_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 5), static_cast<sal_uInt16>(TwipsToEvenHMM(nVal))) );
809 rReq.Done();
810
811 }
812 }
813 }
814 break;
815
816 case FID_COL_OPT_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 6):
817 {
818 if ( pReqArgs )
5
Assuming 'pReqArgs' is null
6
Taking false branch
819 {
820 const SfxUInt16Item& rUInt16Item = static_cast<const SfxUInt16Item&>(pReqArgs->Get( FID_COL_OPT_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 6) ));
821
822 // #101390#; the value of the macro is in HMM so use HMMToTwips to convert
823 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL,
824 sal::static_int_cast<sal_uInt16>( HMMToTwips(rUInt16Item.GetValue()) ) );
825 ScGlobal::nLastColWidthExtra = rUInt16Item.GetValue();
826
827 if( ! rReq.IsAPI() )
828 rReq.Done();
829 }
830 else
831 {
832 FieldUnit eMetric = SC_MOD()( static_cast<ScModule*>(SfxApplication::GetModule(SfxToolsModule
::Calc)) )
->GetAppOptions().GetAppMetric();
833
834 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
835 ScopedVclPtr<AbstractScMetricInputDlg> pDlg(pFact->CreateScMetricInputDlg(
7
Calling constructor for 'ScopedVclPtr<AbstractScMetricInputDlg>'
14
Returning from constructor for 'ScopedVclPtr<AbstractScMetricInputDlg>'
836 pTabViewShell->GetFrameWeld(), "OptimalColWidthDialog",
837 ScGlobal::nLastColWidthExtra, STD_EXTRA_WIDTH113, eMetric, 1, MAX_EXTRA_WIDTH23811));
15
Calling implicit destructor for 'VclPtr<AbstractScMetricInputDlg>'
16
Calling '~Reference'
23
Returning from '~Reference'
24
Returning from destructor for 'VclPtr<AbstractScMetricInputDlg>'
838 if ( pDlg->Execute() == RET_OK )
25
Calling 'VclPtr::operator->'
839 {
840 long nVal = pDlg->GetInputValue();
841 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, static_cast<sal_uInt16>(nVal) );
842 ScGlobal::nLastColWidthExtra = nVal;
843
844 // #101390#; the value of the macro should be in HMM so use TwipsToEvenHMM to convert
845 rReq.AppendItem( SfxUInt16Item( FID_COL_OPT_WIDTH((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 6), static_cast<sal_uInt16>(TwipsToEvenHMM(nVal)) ) );
846 rReq.Done();
847 }
848 }
849 }
850 break;
851
852 case FID_COL_OPT_DIRECT((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 21):
853 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_OPTIMAL, STD_EXTRA_WIDTH113 );
854 rReq.Done();
855 break;
856
857 case FID_ROW_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 3):
858 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_DIRECT, 0 );
859 rReq.Done();
860 break;
861 case FID_ROW_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 4):
862 pTabViewShell->SetMarkedWidthOrHeight( false, SC_SIZE_SHOW, 0 );
863 rReq.Done();
864 break;
865 case FID_COL_HIDE((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 7):
866 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_DIRECT, 0 );
867 rReq.Done();
868 break;
869 case FID_COL_SHOW((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 8):
870 pTabViewShell->SetMarkedWidthOrHeight( true, SC_SIZE_SHOW, 0 );
871 rReq.Done();
872 break;
873
874 case SID_CELL_FORMAT_RESET((26000) + 67):
875 {
876 pTabViewShell->DeleteContents( InsertDeleteFlags::HARDATTR | InsertDeleteFlags::EDITATTR );
877 rReq.Done();
878 }
879 break;
880
881 case FID_MERGE_ON((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 15):
882 case FID_MERGE_OFF((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 16):
883 case FID_MERGE_TOGGLE((((26000 + 521) + 50))+10):
884 {
885 if ( !GetViewData()->GetDocument().GetChangeTrack() )
886 {
887 // test whether to merge or to split
888 bool bMerge = false;
889 bool bCenter = false;
890 switch( nSlot )
891 {
892 case FID_MERGE_ON((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 15):
893 bMerge = true;
894 break;
895 case FID_MERGE_OFF((((((((((26000 + 200) + 20)) + 20)) + 20)) + 25)) + 16):
896 bMerge = false;
897 break;
898 case FID_MERGE_TOGGLE((((26000 + 521) + 50))+10):
899 {
900 bCenter = true;
901 std::unique_ptr<SfxPoolItem> pItem;
902 if( rBindings.QueryState( nSlot, pItem ) >= SfxItemState::DEFAULT )
903 bMerge = !static_cast< SfxBoolItem* >( pItem.get() )->GetValue();
904 }
905 break;
906 }
907
908 if( bMerge )
909 {
910 // merge - check if to move contents of covered cells
911 bool bMoveContents = false;
912 bool bApi = rReq.IsAPI();
913 const SfxPoolItem* pItem;
914 if ( pReqArgs &&
915 pReqArgs->GetItemState(nSlot, true, &pItem) == SfxItemState::SET )
916 {
917 OSL_ENSURE(dynamic_cast<const SfxBoolItem*>( pItem), "wrong item")do { if (true && (!(dynamic_cast<const SfxBoolItem
*>( pItem)))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN
), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.cxx"
":" "917" ": "), "%s", "wrong item"); } } while (false)
;
918 bMoveContents = static_cast<const SfxBoolItem*>(pItem)->GetValue();
919 }
920
921 if (pTabViewShell->MergeCells( bApi, bMoveContents, bCenter ))
922 {
923 if (!bApi && bMoveContents) // "yes" clicked in dialog
924 rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
925 rBindings.Invalidate( nSlot );
926 rReq.Done();
927 }
928 }
929 else
930 {
931 // split cells
932 if (pTabViewShell->RemoveMerge())
933 {
934 rBindings.Invalidate( nSlot );
935 rReq.Done();
936 }
937 }
938 break;
939 }
940 }
941 break;
942
943 case SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ):
944 {
945 weld::Window* pDlgParent = pTabViewShell->GetFrameWeld();
946 SCCOL nStartCol;
947 SCROW nStartRow;
948 SCTAB nStartTab;
949 SCCOL nEndCol;
950 SCROW nEndRow;
951 SCTAB nEndTab;
952
953 const ScMarkData& rMark = GetViewData()->GetMarkData();
954 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() )
955 pTabViewShell->MarkDataArea();
956
957 GetViewData()->GetSimpleArea( nStartCol,nStartRow,nStartTab,
958 nEndCol,nEndRow,nEndTab );
959
960 if ( ( std::abs(nEndCol-nStartCol) > 1 )
961 && ( std::abs(nEndRow-nStartRow) > 1 ) )
962 {
963 if ( pReqArgs )
964 {
965 const SfxStringItem& rNameItem = pReqArgs->Get( SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ) );
966 ScAutoFormat* pFormat = ScGlobal::GetOrCreateAutoFormat();
967 ScAutoFormat::const_iterator it = pFormat->find(rNameItem.GetValue());
968 ScAutoFormat::const_iterator itBeg = pFormat->begin();
969 size_t nIndex = std::distance(itBeg, it);
970
971 pTabViewShell->AutoFormat( nIndex );
972
973 if( ! rReq.IsAPI() )
974 rReq.Done();
975 }
976 else
977 {
978 ScGlobal::ClearAutoFormat();
979 std::unique_ptr<ScAutoFormatData> pNewEntry(pTabViewShell->CreateAutoFormatData());
980 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
981
982 ScopedVclPtr<AbstractScAutoFormatDlg> pDlg(pFact->CreateScAutoFormatDlg(pDlgParent, ScGlobal::GetOrCreateAutoFormat(), pNewEntry.get(), GetViewData()));
983
984 if ( pDlg->Execute() == RET_OK )
985 {
986 ScEditableTester aTester( pTabViewShell );
987 if ( !aTester.IsEditable() )
988 {
989 pTabViewShell->ErrorMessage(aTester.GetMessageId());
990 }
991 else
992 {
993 pTabViewShell->AutoFormat( pDlg->GetIndex() );
994
995 rReq.AppendItem( SfxStringItem( SID_AUTOFORMATTypedWhichId<SfxStringItem>( 10000 + 242 ), pDlg->GetCurrFormatName() ) );
996 rReq.Done();
997 }
998 }
999 }
1000 }
1001 else
1002 {
1003 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(pDlgParent,
1004 VclMessageType::Warning, VclButtonsType::Ok,
1005 ScResId(STR_INVALID_AFAREAreinterpret_cast<char const *>("STR_INVALID_AFAREA" "\004"
u8"To apply an AutoFormat,\na table range of at least\n3x3 cells must be selected."
)
)));
1006 xErrorBox->run();
1007 }
1008 }
1009 break;
1010
1011 case SID_CANCEL((26000 + 521) + 36):
1012 {
1013 if (GetViewData()->HasEditView(GetViewData()->GetActivePart()))
1014 pScMod->InputCancelHandler();
1015 else if (pTabViewShell->HasPaintBrush())
1016 pTabViewShell->ResetBrushDocument(); // abort format paint brush
1017 else if (pTabViewShell->HasHintWindow())
1018 pTabViewShell->RemoveHintWindow();
1019 else if( ScViewUtil::IsFullScreen( *pTabViewShell ) )
1020 ScViewUtil::SetFullScreen( *pTabViewShell, false );
1021 else
1022 {
1023 // TODO/LATER: when is this code executed?
1024 pTabViewShell->Escape();
1025 }
1026 }
1027 break;
1028
1029 case SID_DATA_SELECT((((26000 + 521) + 50))+39):
1030 pTabViewShell->StartDataSelect();
1031 break;
1032
1033 case SID_DETECTIVE_FILLMODE((((((((((((((((((((((((((26000 + 200) + 20)) + 20)) + 20)) +
25)) + 22)) + 20)) + 29)) + 20))+20))+1))+50))+20))+6)
:
1034 {
1035 bool bOldMode = pTabViewShell->IsAuditShell();
1036 pTabViewShell->SetAuditShell( !bOldMode );
1037 pTabViewShell->Invalidate( nSlot );
1038 }
1039 break;
1040
1041 case FID_INPUTLINE_STATUS((26000 + 100)):
1042 OSL_FAIL("Execute from InputLine status")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.cxx"
":" "1042" ": "), "%s", "Execute from InputLine status"); } }
while (false)
;
1043 break;
1044
1045 case SID_STATUS_DOCPOS((26000 + 100) + 14):
1046 // Launch navigator.
1047 GetViewData()->GetDispatcher().Execute(
1048 SID_NAVIGATOR(10000 + 366), SfxCallMode::SYNCHRON|SfxCallMode::RECORD );
1049 break;
1050
1051 case SID_MARKAREA((26000 + 521) + 33):
1052 // called from Basic at the hidden view to select a range in the visible view
1053 OSL_FAIL("old slot SID_MARKAREA")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.cxx"
":" "1053" ": "), "%s", "old slot SID_MARKAREA"); } } while (
false)
;
1054 break;
1055
1056 default:
1057 OSL_FAIL("ScCellShell::Execute: unknown slot")do { if (true && (((sal_Bool)1))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/ui/view/cellsh3.cxx"
":" "1057" ": "), "%s", "ScCellShell::Execute: unknown slot"
); } } while (false)
;
1058 break;
1059 }
1060}
1061
1062/* 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();
26
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)
8
Calling implicit copy constructor for 'VclPtr<AbstractScMetricInputDlg>'
9
Calling copy constructor for 'Reference<AbstractScMetricInputDlg>'
12
Returning from copy constructor for 'Reference<AbstractScMetricInputDlg>'
13
Returning from copy constructor for 'VclPtr<AbstractScMetricInputDlg>'
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)
10
Assuming field 'm_pBody' is non-null
11
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
16.1
Field 'm_pBody' is non-null
16.1
Field 'm_pBody' is non-null
16.1
Field 'm_pBody' is non-null
16.1
Field 'm_pBody' is non-null
)
17
Taking true branch
113 m_pBody->release();
18
Calling 'VclReferenceBase::release'
22
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;
27
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)
19
Assuming the condition is true
20
Taking true branch
40 delete this;
21
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