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 drwtxtsh.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/shells/drwtxtsh.cxx

/home/maarten/src/libreoffice/core/sw/source/uibase/shells/drwtxtsh.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 <hintids.hxx>
21#include <i18nlangtag/lang.h>
22#include <i18nutil/transliteration.hxx>
23#include <rtl/ustrbuf.hxx>
24#include <svl/slstitm.hxx>
25#include <svl/stritem.hxx>
26#include <editeng/fontitem.hxx>
27#include <svx/svdview.hxx>
28#include <sfx2/viewfrm.hxx>
29#include <sfx2/objface.hxx>
30#include <svx/svdotext.hxx>
31#include <svx/sdooitm.hxx>
32#include <editeng/editeng.hxx>
33#include <editeng/editview.hxx>
34#include <editeng/eeitem.hxx>
35#include <editeng/scripttypeitem.hxx>
36#include <sfx2/bindings.hxx>
37#include <svx/fontwork.hxx>
38#include <sfx2/request.hxx>
39#include <vcl/EnumContext.hxx>
40#include <svl/whiter.hxx>
41#include <editeng/outliner.hxx>
42#include <editeng/editstat.hxx>
43#include <svx/svdoutl.hxx>
44#include <com/sun/star/i18n/TextConversionOption.hpp>
45#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
46#include <com/sun/star/lang/XInitialization.hpp>
47#include <com/sun/star/beans/XPropertySet.hpp>
48#include <com/sun/star/awt/XWindow.hpp>
49#include <com/sun/star/uno/XComponentContext.hpp>
50#include <comphelper/propertysequence.hxx>
51#include <swtypes.hxx>
52#include <view.hxx>
53#include <wrtsh.hxx>
54#include <viewopt.hxx>
55#include <drwtxtsh.hxx>
56#include <breakit.hxx>
57
58#include <cmdid.h>
59
60#define ShellClass_SwDrawTextShell
61#include <sfx2/msg.hxx>
62#include <swslots.hxx>
63#include <uitool.hxx>
64#include <wview.hxx>
65#include <swmodule.hxx>
66#include <svx/svdoashp.hxx>
67#include <svx/svxdlg.hxx>
68#include <comphelper/processfactory.hxx>
69#include <IDocumentUndoRedo.hxx>
70#include <memory>
71
72using namespace ::com::sun::star;
73using namespace ::com::sun::star::uno;
74using namespace ::com::sun::star::beans;
75using namespace ::com::sun::star::i18n;
76
77SFX_IMPL_INTERFACE(SwDrawTextShell, SfxShell)SfxInterface* SwDrawTextShell::pInterface = nullptr; SfxInterface
* SwDrawTextShell::GetStaticInterface() { if ( !pInterface ) {
pInterface = new SfxInterface( "SwDrawTextShell", false, GetInterfaceId
(), SfxShell::GetStaticInterface(), aSwDrawTextShellSlots_Impl
[0], sal_uInt16(sizeof(aSwDrawTextShellSlots_Impl) / sizeof(SfxSlot
) ) ); InitInterface_Impl(); } return pInterface; } SfxInterface
* SwDrawTextShell::GetInterface() const { return GetStaticInterface
(); } void SwDrawTextShell::RegisterInterface(const SfxModule
* pMod) { GetStaticInterface()->Register(pMod); }
78
79void SwDrawTextShell::InitInterface_Impl()
80{
81 GetStaticInterface()->RegisterPopupMenu("drawtext");
82
83 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT1, SfxVisibilityFlags::Invisible, ToolbarId::Draw_Text_Toolbox_Sw);
84
85 GetStaticInterface()->RegisterChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
86}
87
88
89void SwDrawTextShell::Init()
90{
91 SwWrtShell &rSh = GetShell();
92 pSdrView = rSh.GetDrawView();
93 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
94 //#97471# mouse click _and_ key input at the same time
95 if( !pOutliner )
96 return ;
97 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
98 EEControlBits nCtrl = pOutliner->GetControlWord();
99 nCtrl |= EEControlBits::AUTOCORRECT;
100
101 SetUndoManager(&pOutliner->GetUndoManager());
102
103 // Now let's try an AutoSpell.
104
105 const SwViewOption* pVOpt = rSh.GetViewOptions();
106 if(pVOpt->IsOnlineSpell())
107 {
108 nCtrl |= EEControlBits::ONLINESPELLING|EEControlBits::ALLOWBIGOBJS;
109 }
110 else
111 nCtrl &= ~EEControlBits::ONLINESPELLING;
112
113 pOutliner->SetControlWord(nCtrl);
114 pOLV->ShowCursor();
115}
116
117SwDrawTextShell::SwDrawTextShell(SwView &rV) :
118 SfxShell(&rV),
119 rView(rV)
120{
121 SwWrtShell &rSh = GetShell();
122 SetPool(rSh.GetAttrPool().GetSecondaryPool());
123
124 // Initialize and show cursor to start editing.
125 Init();
126
127 SetName("ObjectText");
128 SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::DrawText));
129}
130
131SwDrawTextShell::~SwDrawTextShell()
132{
133 if ( GetView().GetCurShell() == this )
134 rView.ResetSubShell();
135}
136
137SwWrtShell& SwDrawTextShell::GetShell()
138{
139 return rView.GetWrtShell();
140}
141
142// Disable slots with this status method
143
144void SwDrawTextShell::StateDisableItems( SfxItemSet &rSet )
145{
146 SfxWhichIter aIter(rSet);
147 sal_uInt16 nWhich = aIter.FirstWhich();
148
149 while (nWhich)
150 {
151 rSet.DisableItem( nWhich );
152 nWhich = aIter.NextWhich();
153 }
154}
155
156void SwDrawTextShell::SetAttrToMarked(const SfxItemSet& rAttr)
157{
158 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
159 tools::Rectangle aOutRect = pOLV->GetOutputArea();
160
161 if (tools::Rectangle() != aOutRect)
162 {
163 GetShell().GetDrawView()->SetAttributes(rAttr);
164 }
165}
166
167bool SwDrawTextShell::IsTextEdit() const
168{
169 return pSdrView->IsTextEdit();
170}
171
172void SwDrawTextShell::ExecFontWork(SfxRequest const & rReq)
173{
174 SwWrtShell &rSh = GetShell();
175 FieldUnit eMetric = ::GetDfltMetric( dynamic_cast<SwWebView*>( &rSh.GetView()) != nullptr );
176 SW_MOD()( static_cast<SwModule*>(SfxApplication::GetModule(SfxToolsModule
::Writer)))
->PutItem(SfxUInt16Item(SID_ATTR_METRICTypedWhichId<SfxUInt16Item>(((((10000 + 1499) + 1) + 499
) + 1) + 8)
, static_cast< sal_uInt16 >(eMetric)) );
177 SfxViewFrame* pVFrame = GetView().GetViewFrame();
178 if ( rReq.GetArgs() )
179 {
180 pVFrame->SetChildWindow(SvxFontWorkChildWindow::GetChildWindowId(),
181 static_cast<const SfxBoolItem&>( (rReq.GetArgs()->
182 Get(SID_FONTWORK( 10000 + 256 )))).GetValue());
183 }
184 else
185 pVFrame->ToggleChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
186
187 pVFrame->GetBindings().Invalidate(SID_FONTWORK( 10000 + 256 ));
188}
189
190void SwDrawTextShell::StateFontWork(SfxItemSet& rSet)
191{
192 const sal_uInt16 nId = SvxFontWorkChildWindow::GetChildWindowId();
193 rSet.Put(SfxBoolItem(SID_FONTWORK( 10000 + 256 ), GetView().GetViewFrame()->HasChildWindow(nId)));
194}
195
196// Edit SfxRequests for FontWork
197
198void SwDrawTextShell::ExecFormText(SfxRequest const & rReq)
199{
200 SwWrtShell &rSh = GetShell();
201 SdrView* pDrView = rSh.GetDrawView();
202
203 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
204
205 if ( !(rMarkList.GetMarkCount() == 1 && rReq.GetArgs()) )
206 return;
207
208 const SfxItemSet& rSet = *rReq.GetArgs();
209
210 if ( pDrView->IsTextEdit() )
211 {
212 //#111733# Sometimes SdrEndTextEdit() initiates the change in selection and
213 // 'this' is not valid anymore
214 SwView& rTempView = GetView();
215 pDrView->SdrEndTextEdit(true);
216 //this removes the current shell from the dispatcher stack!!
217 rTempView.AttrChangedNotify(nullptr);
218 }
219
220 pDrView->SetAttributes(rSet);
221
222}
223
224// Return Status values back to FontWork
225
226void SwDrawTextShell::GetFormTextState(SfxItemSet& rSet)
227{
228 SwWrtShell &rSh = GetShell();
229 SdrView* pDrView = rSh.GetDrawView();
230 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
231 const SdrObject* pObj = nullptr;
232
233 if ( rMarkList.GetMarkCount() == 1 )
234 pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
235
236 const SdrTextObj* pTextObj = dynamic_cast< const SdrTextObj* >(pObj);
237 const bool bDeactivate(
238 !pObj ||
239 !pTextObj ||
240 !pTextObj->HasText() ||
241 dynamic_cast< const SdrObjCustomShape* >(pObj)); // #121538# no FontWork for CustomShapes
242
243 if (bDeactivate)
244 {
245 rSet.DisableItem(XATTR_FORMTXTSTYLE);
246 rSet.DisableItem(XATTR_FORMTXTADJUST);
247 rSet.DisableItem(XATTR_FORMTXTDISTANCE);
248 rSet.DisableItem(XATTR_FORMTXTSTART);
249 rSet.DisableItem(XATTR_FORMTXTMIRROR);
250 rSet.DisableItem(XATTR_FORMTXTHIDEFORM);
251 rSet.DisableItem(XATTR_FORMTXTOUTLINE);
252 rSet.DisableItem(XATTR_FORMTXTSHADOW);
253 rSet.DisableItem(XATTR_FORMTXTSHDWCOLOR);
254 rSet.DisableItem(XATTR_FORMTXTSHDWXVAL);
255 rSet.DisableItem(XATTR_FORMTXTSHDWYVAL);
256 }
257 else
258 {
259 pDrView->GetAttributes( rSet );
260 }
261}
262
263void SwDrawTextShell::ExecDrawLingu(SfxRequest const &rReq)
264{
265 SwWrtShell &rSh = GetShell();
266 OutlinerView* pOutlinerView = pSdrView->GetTextEditOutlinerView();
267 if( !rSh.GetDrawView()->GetMarkedObjectList().GetMarkCount() )
268 return;
269
270 switch(rReq.GetSlot())
271 {
272 case SID_THESAURUS( 10000 + 245 ):
273 pOutlinerView->StartThesaurus();
274 break;
275
276 case SID_HANGUL_HANJA_CONVERSION( 10000 + 959 ):
277 pOutlinerView->StartTextConversion(LANGUAGE_KOREANLanguageType(0x0412), LANGUAGE_KOREANLanguageType(0x0412), nullptr,
278 i18n::TextConversionOption::CHARACTER_BY_CHARACTER, true, false);
279 break;
280
281 case SID_CHINESE_CONVERSION( 10000 + 1016 ):
282 {
283 //open ChineseTranslationDialog
284 Reference<XComponentContext> xContext = comphelper::getProcessComponentContext();
285 if (!xContext.is())
286 return;
287
288 Reference<lang::XMultiComponentFactory> xMCF(xContext->getServiceManager());
289 if (!xMCF.is())
290 return;
291
292 Reference<ui::dialogs::XExecutableDialog> xDialog(
293 xMCF->createInstanceWithContext("com.sun.star.linguistic2.ChineseTranslationDialog", xContext), UNO_QUERY);
294
295 Reference<lang::XInitialization> xInit(xDialog, UNO_QUERY);
296
297 if (!xInit.is())
298 return;
299
300 // initialize dialog
301 uno::Sequence<uno::Any> aSequence(comphelper::InitAnyPropertySequence(
302 {
303 {"ParentWindow", uno::Any(Reference<awt::XWindow>())}
304 }));
305 xInit->initialize( aSequence );
306
307 //execute dialog
308 sal_Int16 nDialogRet = xDialog->execute();
309 if(RET_OK == nDialogRet)
310 {
311 //get some parameters from the dialog
312 bool bToSimplified = true;
313 bool bUseVariants = true;
314 bool bCommonTerms = true;
315 Reference<beans::XPropertySet> xPropertySet(xDialog, UNO_QUERY);
316 if (xPropertySet.is())
317 {
318 try
319 {
320 xPropertySet->getPropertyValue("IsDirectionToSimplified") >>= bToSimplified;
321 xPropertySet->getPropertyValue("IsUseCharacterVariants") >>= bUseVariants;
322 xPropertySet->getPropertyValue("IsTranslateCommonTerms") >>= bCommonTerms;
323 }
324 catch (const Exception&)
325 {
326 }
327 }
328
329 //execute translation
330 LanguageType nSourceLang = bToSimplified ? LANGUAGE_CHINESE_TRADITIONALLanguageType(0x0404) : LANGUAGE_CHINESE_SIMPLIFIEDLanguageType(0x0804);
331 LanguageType nTargetLang = bToSimplified ? LANGUAGE_CHINESE_SIMPLIFIEDLanguageType(0x0804) : LANGUAGE_CHINESE_TRADITIONALLanguageType(0x0404);
332 sal_Int32 nOptions = bUseVariants ? i18n::TextConversionOption::USE_CHARACTER_VARIANTS : 0;
333 if(!bCommonTerms)
334 nOptions = nOptions | i18n::TextConversionOption::CHARACTER_BY_CHARACTER;
335
336 vcl::Font aTargetFont = OutputDevice::GetDefaultFont(DefaultFontType::CJK_TEXT, nTargetLang, GetDefaultFontFlags::OnlyOne);
337
338 pOutlinerView->StartTextConversion(nSourceLang, nTargetLang, &aTargetFont, nOptions, false, false);
339 }
340
341 Reference<lang::XComponent> xComponent(xDialog, UNO_QUERY);
342 if (xComponent.is())
343 xComponent->dispose();
344 }
345 break;
346
347 default:
348 OSL_ENSURE(false, "unexpected slot-id")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/drwtxtsh.cxx"
":" "348" ": "), "%s", "unexpected slot-id"); } } while (false
)
;
349 }
350}
351
352void SwDrawTextShell::ExecDraw(SfxRequest &rReq)
353{
354 SwWrtShell &rSh = GetShell();
355 pSdrView = rSh.GetDrawView();
356 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
357
358 switch (rReq.GetSlot())
1
Control jumps to 'case 20376:' at line 434
359 {
360 case FN_INSERT_SOFT_HYPHEN((20000 + 300) + 43):
361 case FN_INSERT_HARDHYPHEN((20000 + 300) + 85):
362 case FN_INSERT_HARD_SPACE((20000 + 300) + 44):
363 case FN_INSERT_NNBSP((20000 + 300) + 45):
364 case SID_INSERT_RLM( 10000 + 1056 ) :
365 case SID_INSERT_LRM( 10000 + 1057 ) :
366 case SID_INSERT_ZWNBSP( 10000 + 1059 ) :
367 case SID_INSERT_ZWSP( 10000 + 1058 ):
368 {
369 sal_Unicode cIns = 0;
370 switch(rReq.GetSlot())
371 {
372 case FN_INSERT_SOFT_HYPHEN((20000 + 300) + 43): cIns = CHAR_SOFTHYPHENu'\x00AD'; break;
373 case FN_INSERT_HARDHYPHEN((20000 + 300) + 85): cIns = CHAR_HARDHYPHENu'\x2011'; break;
374 case FN_INSERT_HARD_SPACE((20000 + 300) + 44): cIns = CHAR_HARDBLANKu'\x00A0'; break;
375 case FN_INSERT_NNBSP((20000 + 300) + 45): cIns = CHAR_NNBSPu'\x202F'; break;
376 case SID_INSERT_RLM( 10000 + 1056 ) : cIns = CHAR_RLMu'\x200F' ; break;
377 case SID_INSERT_LRM( 10000 + 1057 ) : cIns = CHAR_LRMu'\x200E' ; break;
378 case SID_INSERT_ZWSP( 10000 + 1058 ) : cIns = CHAR_ZWSPu'\x200B' ; break;
379 case SID_INSERT_ZWNBSP( 10000 + 1059 ): cIns = CHAR_ZWNBSPu'\x2060'; break;
380 }
381 pOLV->InsertText( OUString(cIns));
382 rReq.Done();
383 }
384 break;
385 case SID_CHARMAP((10000 + 500) + 3):
386 { // Insert special character
387 InsertSymbol(rReq);
388 break;
389 }
390 case FN_INSERT_STRING((20000 + 300)+31):
391 {
392 const SfxItemSet *pNewAttrs = rReq.GetArgs();
393 sal_uInt16 nSlot = rReq.GetSlot();
394 const SfxPoolItem* pItem = nullptr;
395 if(pNewAttrs)
396 {
397 pNewAttrs->GetItemState(nSlot, false, &pItem );
398 pOLV->InsertText(static_cast<const SfxStringItem *>(pItem)->GetValue());
399 }
400 break;
401 }
402
403 case SID_SELECTALL(5000 + 723):
404 {
405 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
406 if(pOutliner)
407 {
408 sal_Int32 nParaCount = pOutliner->GetParagraphCount();
409 if (nParaCount > 0)
410 pOLV->SelectRange(0, nParaCount );
411 }
412 }
413 break;
414
415 case FN_FORMAT_RESET((20000 + 400) + 69): // delete hard text attributes
416 {
417 pOLV->RemoveAttribsKeepLanguages( true );
418 pOLV->GetEditView().GetEditEngine()->RemoveFields();
419 rReq.Done();
420 }
421 break;
422
423 case FN_ESCAPE((20000 + 900) + 41):
424 if (pSdrView->IsTextEdit())
425 {
426 // Shell switch!
427 rSh.EndTextEdit();
428 SwView& rTempView = rSh.GetView();
429 rTempView.ExitDraw();
430 rSh.Edit();
431 return;
432 }
433 break;
434 case FN_DRAWTEXT_ATTR_DLG((20000 + 300) + 76):
435 {
436 SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool() );
437 pSdrView->GetAttributes( aNewAttr );
438 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
439 ScopedVclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog(
2
Calling constructor for 'ScopedVclPtr<SfxAbstractTabDialog>'
9
Returning from constructor for 'ScopedVclPtr<SfxAbstractTabDialog>'
440 GetView().GetFrameWeld(),
441 &aNewAttr, pSdrView ));
10
Calling implicit destructor for 'VclPtr<SfxAbstractTabDialog>'
11
Calling '~Reference'
18
Returning from '~Reference'
19
Returning from destructor for 'VclPtr<SfxAbstractTabDialog>'
442 sal_uInt16 nResult = pDlg->Execute();
20
Calling 'VclPtr::operator->'
443
444 if (nResult == RET_OK)
445 {
446 if (pSdrView->AreObjectsMarked())
447 {
448 pSdrView->SetAttributes(*pDlg->GetOutputItemSet());
449 rReq.Done(*(pDlg->GetOutputItemSet()));
450 }
451 }
452 }
453 break;
454 case SID_TABLE_VERT_NONE( 10000 + 1075 ):
455 case SID_TABLE_VERT_CENTER( 10000 + 1074 ):
456 case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ):
457 {
458 sal_uInt16 nSId = rReq.GetSlot();
459 if (pSdrView->AreObjectsMarked())
460 {
461 SdrTextVertAdjust eTVA = SDRTEXTVERTADJUST_TOP;
462 if (nSId == SID_TABLE_VERT_CENTER( 10000 + 1074 ))
463 eTVA = SDRTEXTVERTADJUST_CENTER;
464 else if (nSId == SID_TABLE_VERT_BOTTOM( 10000 + 1073 ))
465 eTVA = SDRTEXTVERTADJUST_BOTTOM;
466
467 SfxItemSet aNewAttr( pSdrView->GetModel()->GetItemPool() );
468 pSdrView->GetAttributes( aNewAttr );
469 aNewAttr.Put(SdrTextVertAdjustItem(eTVA));
470 pSdrView->SetAttributes(aNewAttr);
471 rReq.Done();
472 }
473
474 }
475 break;
476
477 default:
478 OSL_ENSURE(false, "unexpected slot-id")do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sw/source/uibase/shells/drwtxtsh.cxx"
":" "478" ": "), "%s", "unexpected slot-id"); } } while (false
)
;
479 return;
480 }
481
482 GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
483
484 if (IsTextEdit() && pOLV->GetOutliner()->IsModified())
485 rSh.SetModified();
486}
487
488// Execute undo
489
490void SwDrawTextShell::ExecUndo(SfxRequest &rReq)
491{
492 if( !IsTextEdit() )
493 return;
494
495 bool bCallBase = true;
496 const SfxItemSet* pArgs = rReq.GetArgs();
497 if( pArgs )
498 {
499 sal_uInt16 nId = rReq.GetSlot(), nCnt = 1;
500 const SfxPoolItem* pItem;
501 switch( nId )
502 {
503 case SID_UNDO(5000 + 701):
504 case SID_REDO(5000 + 700):
505 if( SfxItemState::SET == pArgs->GetItemState( nId, false, &pItem ) &&
506 1 < (nCnt = static_cast<const SfxUInt16Item*>(pItem)->GetValue()) )
507 {
508 // then we make by ourself.
509 SfxUndoManager* pUndoManager = GetUndoManager();
510 if( pUndoManager )
511 {
512 if( SID_UNDO(5000 + 701) == nId )
513 while( nCnt-- )
514 pUndoManager->Undo();
515 else
516 while( nCnt-- )
517 pUndoManager->Redo();
518 }
519 bCallBase = false;
520 GetView().GetViewFrame()->GetBindings().InvalidateAll(false);
521 }
522 break;
523 }
524 }
525 if( bCallBase )
526 {
527 SfxViewFrame *pSfxViewFrame = GetView().GetViewFrame();
528 pSfxViewFrame->ExecuteSlot(rReq, pSfxViewFrame->GetInterface());
529 }
530}
531
532// State of undo
533
534void SwDrawTextShell::StateUndo(SfxItemSet &rSet)
535{
536 if ( !IsTextEdit() )
537 return;
538
539 SfxViewFrame *pSfxViewFrame = GetView().GetViewFrame();
540 SfxWhichIter aIter(rSet);
541 sal_uInt16 nWhich = aIter.FirstWhich();
542 while( nWhich )
543 {
544 switch ( nWhich )
545 {
546 case SID_GETUNDOSTRINGS( 10000 + 923 ):
547 case SID_GETREDOSTRINGS( 10000 + 924 ):
548 {
549 SfxUndoManager* pUndoManager = GetUndoManager();
550 if( pUndoManager )
551 {
552 OUString (SfxUndoManager::*fnGetComment)( size_t, bool const ) const;
553
554 sal_uInt16 nCount;
555 if( SID_GETUNDOSTRINGS( 10000 + 923 ) == nWhich )
556 {
557 nCount = pUndoManager->GetUndoActionCount();
558 fnGetComment = &SfxUndoManager::GetUndoActionComment;
559 }
560 else
561 {
562 nCount = pUndoManager->GetRedoActionCount();
563 fnGetComment = &SfxUndoManager::GetRedoActionComment;
564 }
565 if( nCount )
566 {
567 OUStringBuffer sList;
568 for( sal_uInt16 n = 0; n < nCount; ++n )
569 sList.append( (pUndoManager->*fnGetComment)( n, SfxUndoManager::TopLevel ) ).append("\n");
570
571 SfxStringListItem aItem( nWhich );
572 aItem.SetString( sList.makeStringAndClear() );
573 rSet.Put( aItem );
574 }
575 }
576 else
577 rSet.DisableItem( nWhich );
578 }
579 break;
580
581 default:
582 {
583 auto* pUndoManager = dynamic_cast<IDocumentUndoRedo*>(GetUndoManager());
584 if (pUndoManager)
585 pUndoManager->SetView(&GetView());
586 pSfxViewFrame->GetSlotState(nWhich, pSfxViewFrame->GetInterface(), &rSet);
587 if (pUndoManager)
588 pUndoManager->SetView(nullptr);
589 }
590 }
591
592 nWhich = aIter.NextWhich();
593 }
594}
595
596void SwDrawTextShell::ExecTransliteration( SfxRequest const & rReq )
597{
598 if (!pSdrView)
599 return;
600
601 using namespace i18n;
602
603 TransliterationFlags nMode = TransliterationFlags::NONE;
604
605 switch( rReq.GetSlot() )
606 {
607 case SID_TRANSLITERATE_SENTENCE_CASE( 10000 + 1102 ):
608 nMode = TransliterationFlags::SENTENCE_CASE;
609 break;
610 case SID_TRANSLITERATE_TITLE_CASE( 10000 + 1103 ):
611 nMode = TransliterationFlags::TITLE_CASE;
612 break;
613 case SID_TRANSLITERATE_TOGGLE_CASE( 10000 + 1104 ):
614 nMode = TransliterationFlags::TOGGLE_CASE;
615 break;
616 case SID_TRANSLITERATE_UPPER( 10000 + 912 ):
617 nMode = TransliterationFlags::LOWERCASE_UPPERCASE;
618 break;
619 case SID_TRANSLITERATE_LOWER( 10000 + 913 ):
620 nMode = TransliterationFlags::UPPERCASE_LOWERCASE;
621 break;
622
623 case SID_TRANSLITERATE_HALFWIDTH( 10000 + 914 ):
624 nMode = TransliterationFlags::FULLWIDTH_HALFWIDTH;
625 break;
626 case SID_TRANSLITERATE_FULLWIDTH( 10000 + 915 ):
627 nMode = TransliterationFlags::HALFWIDTH_FULLWIDTH;
628 break;
629
630 case SID_TRANSLITERATE_HIRAGANA( 10000 + 916 ):
631 nMode = TransliterationFlags::KATAKANA_HIRAGANA;
632 break;
633 case SID_TRANSLITERATE_KATAKANA( 10000 + 917 ):
634 nMode = TransliterationFlags::HIRAGANA_KATAKANA;
635 break;
636
637 default:
638 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/shells/drwtxtsh.cxx"
":" "638" ": "), "%s", "wrong dispatcher"); } } while (false
)
;
639 }
640
641 if( nMode != TransliterationFlags::NONE )
642 {
643 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
644
645 if (!pOLV)
646 return;
647
648 pOLV->TransliterateText( nMode );
649 }
650}
651
652void SwDrawTextShell::ExecRotateTransliteration( SfxRequest const & rReq )
653{
654 if( rReq.GetSlot() == SID_TRANSLITERATE_ROTATE_CASE( 10000 + 1105 ) )
655 {
656 if (!pSdrView)
657 return;
658
659 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
660
661 if (!pOLV)
662 return;
663
664 pOLV->TransliterateText( m_aRotateCase.getNextMode() );
665 }
666}
667
668// Insert special character (see SDraw: FUBULLET.CXX)
669
670void SwDrawTextShell::InsertSymbol(SfxRequest& rReq)
671{
672 OutlinerView* pOLV = pSdrView->GetTextEditOutlinerView();
673 if(!pOLV)
674 return;
675 const SfxItemSet *pArgs = rReq.GetArgs();
676 const SfxPoolItem* pItem = nullptr;
677 if( pArgs )
678 pArgs->GetItemState(GetPool().GetWhich(SID_CHARMAP((10000 + 500) + 3)), false, &pItem);
679
680 OUString sSym;
681 OUString sFontName;
682 if ( pItem )
683 {
684 sSym = static_cast<const SfxStringItem*>(pItem)->GetValue();
685 const SfxPoolItem* pFtItem = nullptr;
686 pArgs->GetItemState( GetPool().GetWhich(SID_ATTR_SPECIALCHAR( 10000 + 1120 )), false, &pFtItem);
687 const SfxStringItem* pFontItem = dynamic_cast<const SfxStringItem*>( pFtItem );
688 if ( pFontItem )
689 sFontName = pFontItem->GetValue();
690 }
691
692 SfxItemSet aSet(pOLV->GetAttribs());
693 SvtScriptType nScript = pOLV->GetSelectedScriptType();
694 std::shared_ptr<SvxFontItem> aSetDlgFont(std::make_shared<SvxFontItem>(RES_CHRATR_FONT));
695 {
696 SvxScriptSetItem aSetItem( SID_ATTR_CHAR_FONT( 10000 + 7 ), *aSet.GetPool() );
697 aSetItem.GetItemSet().Put( aSet, false );
698 const SfxPoolItem* pI = aSetItem.GetItemOfScript( nScript );
699 if( pI )
700 aSetDlgFont.reset(static_cast<SvxFontItem*>(pI->Clone()));
701 else
702 aSetDlgFont.reset(static_cast<SvxFontItem*>(aSet.Get( GetWhichOfScript(
703 SID_ATTR_CHAR_FONT( 10000 + 7 ),
704 SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() ) )).Clone()));
705 if (sFontName.isEmpty())
706 sFontName = aSetDlgFont->GetFamilyName();
707 }
708
709 vcl::Font aFont(sFontName, Size(1,1));
710 if(sSym.isEmpty())
711 {
712 SfxAllItemSet aAllSet( GetPool() );
713 aAllSet.Put( SfxBoolItem( FN_PARAM_1((20000 + 1100)+60), false ) );
714
715 SwViewOption aOpt(*rView.GetWrtShell().GetViewOptions());
716 const OUString& sSymbolFont = aOpt.GetSymbolFont();
717 if( !sSymbolFont.isEmpty() )
718 aAllSet.Put( SfxStringItem( SID_FONT_NAME(5000 + 1716), sSymbolFont ) );
719 else
720 aAllSet.Put( SfxStringItem( SID_FONT_NAME(5000 + 1716), aSetDlgFont->GetFamilyName() ) );
721
722 // If character is selected, it can be shown
723 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
724 auto xFrame = rView.GetViewFrame()->GetFrame().GetFrameInterface();
725 ScopedVclPtr<SfxAbstractDialog> pDlg(pFact->CreateCharMapDialog(rView.GetFrameWeld(), aAllSet, xFrame));
726 pDlg->Execute();
727 return;
728 }
729
730 // do not flicker
731 pOLV->HideCursor();
732 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
733 pOutliner->SetUpdateMode(false);
734
735 SfxItemSet aOldSet( pOLV->GetAttribs() );
736 SfxItemSet aFontSet(
737 *aOldSet.GetPool(),
738 svl::Items<
739 EE_CHAR_FONTINFO, EE_CHAR_FONTINFO,
740 EE_CHAR_FONTINFO_CJK, EE_CHAR_FONTINFO_CTL>{});
741 aFontSet.Set( aOldSet );
742
743 // Insert string
744 pOLV->InsertText( sSym );
745
746 // assign attributes (Set font)
747 SfxItemSet aFontAttribSet( *aFontSet.GetPool(), aFontSet.GetRanges() );
748 SvxFontItem aFontItem (aFont.GetFamilyType(), aFont.GetFamilyName(),
749 aFont.GetStyleName(), aFont.GetPitch(),
750 aFont.GetCharSet(),
751 EE_CHAR_FONTINFO );
752 nScript = g_pBreakIt->GetAllScriptsOfText( sSym );
753 if( SvtScriptType::LATIN & nScript )
754 aFontAttribSet.Put( aFontItem );
755 if( SvtScriptType::ASIAN & nScript )
756 {
757 aFontItem.SetWhich(EE_CHAR_FONTINFO_CJK);
758 aFontAttribSet.Put( aFontItem );
759 }
760 if( SvtScriptType::COMPLEX & nScript )
761 {
762 aFontItem.SetWhich(EE_CHAR_FONTINFO_CTL);
763 aFontAttribSet.Put( aFontItem );
764 }
765 pOLV->SetAttribs(aFontAttribSet);
766
767 // Remove selection
768 ESelection aSel(pOLV->GetSelection());
769 aSel.nStartPara = aSel.nEndPara;
770 aSel.nStartPos = aSel.nEndPos;
771 pOLV->SetSelection(aSel);
772
773 // Restore old font
774 pOLV->SetAttribs( aFontSet );
775
776 // From now on show again
777 pOutliner->SetUpdateMode(true);
778 pOLV->ShowCursor();
779
780 rReq.AppendItem( SfxStringItem( GetPool().GetWhich(SID_CHARMAP((10000 + 500) + 3)), sSym ) );
781 if(!aFont.GetFamilyName().isEmpty())
782 rReq.AppendItem( SfxStringItem( SID_ATTR_SPECIALCHAR( 10000 + 1120 ), aFont.GetFamilyName() ) );
783 rReq.Done();
784
785}
786
787SfxUndoManager* SwDrawTextShell::GetUndoManager()
788{
789 SwWrtShell &rSh = GetShell();
790 pSdrView = rSh.GetDrawView();
791 SdrOutliner * pOutliner = pSdrView->GetTextEditOutliner();
792 return &pOutliner->GetUndoManager();
793}
794
795void SwDrawTextShell::GetStatePropPanelAttr(SfxItemSet &rSet)
796{
797 SfxWhichIter aIter( rSet );
798 sal_uInt16 nWhich = aIter.FirstWhich();
799
800 SwWrtShell &rSh = GetShell();
801 pSdrView = rSh.GetDrawView();
802
803 SfxItemSet aAttrs( pSdrView->GetModel()->GetItemPool() );
804 pSdrView->GetAttributes( aAttrs );
805
806 while ( nWhich )
807 {
808 sal_uInt16 nSlotId = SfxItemPool::IsWhich(nWhich)
809 ? GetPool().GetSlotId(nWhich)
810 : nWhich;
811 switch ( nSlotId )
812 {
813 case SID_TABLE_VERT_NONE( 10000 + 1075 ):
814 case SID_TABLE_VERT_CENTER( 10000 + 1074 ):
815 case SID_TABLE_VERT_BOTTOM( 10000 + 1073 ):
816 bool bContour = false;
817 SfxItemState eConState = aAttrs.GetItemState( SDRATTR_TEXT_CONTOURFRAME );
818 if( eConState != SfxItemState::DONTCARE )
819 {
820 bContour = aAttrs.Get( SDRATTR_TEXT_CONTOURFRAME ).GetValue();
821 }
822 if (bContour) break;
823
824 SfxItemState eVState = aAttrs.GetItemState( SDRATTR_TEXT_VERTADJUST );
825 //SfxItemState eHState = aAttrs.GetItemState( SDRATTR_TEXT_HORZADJUST );
826
827 //if(SfxItemState::DONTCARE != eVState && SfxItemState::DONTCARE != eHState)
828 if(SfxItemState::DONTCARE != eVState)
829 {
830 SdrTextVertAdjust eTVA = aAttrs.Get(SDRATTR_TEXT_VERTADJUST).GetValue();
831 bool bSet = (nSlotId == SID_TABLE_VERT_NONE( 10000 + 1075 ) && eTVA == SDRTEXTVERTADJUST_TOP) ||
832 (nSlotId == SID_TABLE_VERT_CENTER( 10000 + 1074 ) && eTVA == SDRTEXTVERTADJUST_CENTER) ||
833 (nSlotId == SID_TABLE_VERT_BOTTOM( 10000 + 1073 ) && eTVA == SDRTEXTVERTADJUST_BOTTOM);
834 rSet.Put(SfxBoolItem(nSlotId, bSet));
835 }
836 else
837 {
838 rSet.Put(SfxBoolItem(nSlotId, false));
839 }
840 break;
841 }
842 nWhich = aIter.NextWhich();
843 }
844}
845
846/* 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<SfxAbstractTabDialog>'
4
Calling copy constructor for 'Reference<SfxAbstractTabDialog>'
7
Returning from copy constructor for 'Reference<SfxAbstractTabDialog>'
8
Returning from copy constructor for 'VclPtr<SfxAbstractTabDialog>'
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