Bug Summary

File:home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx
Warning:line 495, column 25
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 menufloatingwindow.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 /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/glm -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/libmount -isystem /usr/include/blkid -isystem /usr/include/cairo -isystem /usr/include/glib-2.0 -isystem /usr/lib64/glib-2.0/include -isystem /usr/include/pixman-1 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/libxml2 -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -isystem /usr/include/freetype2 -isystem /usr/include/libpng16 -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 VCL_DLLIMPLEMENTATION -D DLLIMPLEMENTATION_UITEST -D CUI_DLL_NAME="libcuilo.so" -D DESKTOP_DETECTOR_DLL_NAME="libdesktop_detectorlo.so" -D TK_DLL_NAME="libtklo.so" -D SYSTEM_ZLIB -D GLM_FORCE_CTOR_INIT -D SK_USER_CONFIG_HEADER=</home/maarten/src/libreoffice/core/config_host/config_skia.h> -D SKIA_DLL -D ENABLE_CUPS -D HAVE_VALGRIND_HEADERS -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/epoxy/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/core -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/effects -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/config -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/ports -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/include/third_party/vulkan -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia/tools/gpu -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/skia -I /home/maarten/src/libreoffice/core/external/skia/inc/ -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/mdds/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/lcms2/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/workdir/UnpackedTarball/harfbuzz/src -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/graphite/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/workdir/UnpackedTarball/pdfium -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/pdfium/public -D COMPONENT_BUILD -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libpng -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/libjpeg-turbo -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/vcl/inc -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/CustomTarget/officecfg/registry -I /usr/include/freetype2 -I /usr/include/libpng16 -I /usr/include/libxml2 -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/vcl/source/window/menufloatingwindow.cxx

/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.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 "menufloatingwindow.hxx"
21#include "menuitemlist.hxx"
22#include "menubarwindow.hxx"
23#include "bufferdevice.hxx"
24
25#include <sal/log.hxx>
26#include <salframe.hxx>
27#include <svdata.hxx>
28#include <vcl/decoview.hxx>
29#include <vcl/settings.hxx>
30#include <window.h>
31
32MenuFloatingWindow::MenuFloatingWindow( Menu* pMen, vcl::Window* pParent, WinBits nStyle ) :
33 FloatingWindow( pParent, nStyle ),
34 pMenu(pMen),
35 nHighlightedItem(ITEMPOS_INVALID),
36 nMBDownPos(ITEMPOS_INVALID),
37 nScrollerHeight(0),
38 nFirstEntry(0),
39 nPosInParent(ITEMPOS_INVALID),
40 bInExecute(false),
41 bScrollMenu(false),
42 bScrollUp(false),
43 bScrollDown(false),
44 bIgnoreFirstMove(true),
45 bKeyInput(false)
46{
47 mpWindowImpl->mbMenuFloatingWindow= true;
48
49 ApplySettings(*this);
50
51 SetPopupModeEndHdl( LINK( this, MenuFloatingWindow, PopupEnd )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubPopupEnd)
);
52
53 aHighlightChangedTimer.SetInvokeHandler( LINK( this, MenuFloatingWindow, HighlightChanged )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubHighlightChanged
)
);
54 aHighlightChangedTimer.SetTimeout( GetSettings().GetMouseSettings().GetMenuDelay() );
55 aHighlightChangedTimer.SetDebugName( "vcl::MenuFloatingWindow aHighlightChangedTimer" );
56
57 aSubmenuCloseTimer.SetTimeout( GetSettings().GetMouseSettings().GetMenuDelay() );
58 aSubmenuCloseTimer.SetInvokeHandler( LINK( this, MenuFloatingWindow, SubmenuClose )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubSubmenuClose)
);
59 aSubmenuCloseTimer.SetDebugName( "vcl::MenuFloatingWindow aSubmenuCloseTimer" );
60
61 aScrollTimer.SetInvokeHandler( LINK( this, MenuFloatingWindow, AutoScroll )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubAutoScroll)
);
62 aScrollTimer.SetDebugName( "vcl::MenuFloatingWindow aScrollTimer" );
63
64 AddEventListener( LINK( this, MenuFloatingWindow, ShowHideListener )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubShowHideListener
)
);
65}
66
67void MenuFloatingWindow::doShutdown()
68{
69 if( !pMenu )
70 return;
71
72 // #105373# notify toolkit that highlight was removed
73 // otherwise the entry will not be read when the menu is opened again
74 if( nHighlightedItem != ITEMPOS_INVALID )
75 pMenu->ImplCallEventListeners( VclEventId::MenuDehighlight, nHighlightedItem );
76 if (!bKeyInput && pMenu && pMenu->pStartedFrom && !pMenu->pStartedFrom->IsMenuBar())
77 {
78 // #102461# remove highlight in parent
79 size_t i, nCount = pMenu->pStartedFrom->pItemList->size();
80 for(i = 0; i < nCount; i++)
81 {
82 MenuItemData* pData = pMenu->pStartedFrom->pItemList->GetDataFromPos( i );
83 if( pData && ( pData->pSubMenu == pMenu ) )
84 break;
85 }
86 if( i < nCount )
87 {
88 MenuFloatingWindow* pPWin = static_cast<MenuFloatingWindow*>(pMenu->pStartedFrom->ImplGetWindow());
89 if (pPWin)
90 pPWin->InvalidateItem(i);
91 }
92 }
93
94 // free the reference to the accessible component
95 SetAccessible( css::uno::Reference< css::accessibility::XAccessible >() );
96
97 aHighlightChangedTimer.Stop();
98
99 // #95056# invalidate screen area covered by system window
100 // so this can be taken into account if the commandhandler performs a scroll operation
101 if( GetParent() )
102 {
103 tools::Rectangle aInvRect( GetWindowExtentsRelative( GetParent() ) );
104 GetParent()->Invalidate( aInvRect );
105 }
106 pMenu = nullptr;
107 RemoveEventListener( LINK( this, MenuFloatingWindow, ShowHideListener )::tools::detail::makeLink( ::tools::detail::castTo<MenuFloatingWindow
*>(this), &MenuFloatingWindow::LinkStubShowHideListener
)
);
108
109 aScrollTimer.Stop();
110 aSubmenuCloseTimer.Stop();
111 aSubmenuCloseTimer.Stop();
112 aHighlightChangedTimer.Stop();
113 aHighlightChangedTimer.Stop();
114
115}
116
117MenuFloatingWindow::~MenuFloatingWindow()
118{
119 disposeOnce();
120}
121
122void MenuFloatingWindow::dispose()
123{
124 doShutdown();
125 pMenu.clear();
126 pActivePopup.clear();
127 xSaveFocusId.clear();
128 FloatingWindow::dispose();
129}
130
131void MenuFloatingWindow::Resize()
132{
133 InitMenuClipRegion(*this); // FIXME
134}
135
136void MenuFloatingWindow::ApplySettings(vcl::RenderContext& rRenderContext)
137{
138 FloatingWindow::ApplySettings(rRenderContext);
139
140 if (IsNativeControlSupported(ControlType::MenuPopup, ControlPart::MenuItem) &&
141 IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Entire))
142 {
143 AllSettings aSettings(GetSettings());
144 ImplGetFrame()->UpdateSettings(aSettings); // Update theme colors.
145 StyleSettings aStyle(aSettings.GetStyleSettings());
146 Color aHighlightTextColor = ImplGetSVData()->maNWFData.maMenuBarHighlightTextColor;
147 if (aHighlightTextColor != COL_TRANSPARENT)
148 {
149 aStyle.SetMenuHighlightTextColor(aHighlightTextColor);
150 }
151 aSettings.SetStyleSettings(aStyle);
152 OutputDevice::SetSettings(aSettings);
153 }
154
155 const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
156 SetPointFont(rRenderContext, rStyleSettings.GetMenuFont());
157
158 if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Entire))
159 {
160 rRenderContext.SetBackground(); // background will be drawn by NWF
161 }
162 else
163 rRenderContext.SetBackground(Wallpaper(rStyleSettings.GetMenuColor()));
164
165 rRenderContext.SetTextColor(rStyleSettings.GetMenuTextColor());
166 rRenderContext.SetTextFillColor();
167 rRenderContext.SetLineColor();
168}
169
170/// Get a negative pixel offset for an offset menu
171long MenuFloatingWindow::ImplGetStartY() const
172{
173 long nY = 0;
174 if( pMenu )
175 {
176 // avoid crash if somehow menu got disposed, and MenuItemList is empty (workaround for tdf#104686)
177 if ( nFirstEntry > 0 && !pMenu->GetItemList()->GetDataFromPos(nFirstEntry - 1) )
178 {
179 return 0;
180 }
181
182 for ( sal_uInt16 n = 0; n < nFirstEntry; n++ )
183 nY += pMenu->GetItemList()->GetDataFromPos( n )->aSz.Height();
184 nY -= pMenu->GetTitleHeight();
185 }
186 return -nY;
187}
188
189vcl::Region MenuFloatingWindow::ImplCalcClipRegion() const
190{
191 Size aOutSz = GetOutputSizePixel();
192 tools::Rectangle aRect( Point(), aOutSz );
193 aRect.AdjustTop(nScrollerHeight );
194 aRect.AdjustBottom( -nScrollerHeight );
195
196 vcl::Region aRegion(aRect);
197
198 return aRegion;
199}
200
201void MenuFloatingWindow::InitMenuClipRegion(vcl::RenderContext& rRenderContext)
202{
203 if (IsScrollMenu())
204 {
205 rRenderContext.SetClipRegion(ImplCalcClipRegion());
206 }
207 else
208 {
209 rRenderContext.SetClipRegion();
210 }
211}
212
213void MenuFloatingWindow::ImplHighlightItem( const MouseEvent& rMEvt, bool bMBDown )
214{
215 if( ! pMenu )
216 return;
217
218 long nY = GetInitialItemY();
219 long nMouseY = rMEvt.GetPosPixel().Y();
220 Size aOutSz = GetOutputSizePixel();
221 if ( ( nMouseY >= nY ) && ( nMouseY < aOutSz.Height() ) )
222 {
223 bool bHighlighted = false;
224 size_t nCount = pMenu->pItemList->size();
225 for ( size_t n = 0; !bHighlighted && ( n < nCount ); n++ )
226 {
227 if ( pMenu->ImplIsVisible( n ) )
228 {
229 MenuItemData* pItemData = pMenu->pItemList->GetDataFromPos( n );
230 long nOldY = nY;
231 nY += pItemData->aSz.Height();
232 if ( ( nOldY <= nMouseY ) && ( nY > nMouseY ) && pMenu->ImplIsSelectable( n ) )
233 {
234 bool bPopupArea = true;
235 if ( pItemData->nBits & MenuItemBits::POPUPSELECT )
236 {
237 // only when clicked over the arrow...
238 Size aSz = GetOutputSizePixel();
239 long nFontHeight = GetTextHeight();
240 bPopupArea = ( rMEvt.GetPosPixel().X() >= ( aSz.Width() - nFontHeight - nFontHeight/4 ) );
241 }
242
243 if ( bMBDown )
244 {
245 if ( n != nHighlightedItem )
246 {
247 ChangeHighlightItem( static_cast<sal_uInt16>(n), false );
248 }
249
250 bool bAllowNewPopup = true;
251 if ( pActivePopup )
252 {
253 MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
254 bAllowNewPopup = pData && ( pData->pSubMenu != pActivePopup );
255 if ( bAllowNewPopup )
256 KillActivePopup();
257 }
258
259 if ( bPopupArea && bAllowNewPopup )
260 {
261 HighlightChanged( nullptr );
262 }
263 }
264 else
265 {
266 if ( n != nHighlightedItem )
267 {
268 ChangeHighlightItem( static_cast<sal_uInt16>(n), true );
269 }
270 else if ( pItemData->nBits & MenuItemBits::POPUPSELECT )
271 {
272 if ( bPopupArea && ( pActivePopup != pItemData->pSubMenu ) )
273 HighlightChanged( nullptr );
274 }
275 }
276 bHighlighted = true;
277 }
278 }
279 }
280 if ( !bHighlighted )
281 ChangeHighlightItem( ITEMPOS_INVALID, true );
282 }
283 else
284 {
285 ImplScroll( rMEvt.GetPosPixel() );
286 ChangeHighlightItem( ITEMPOS_INVALID, true );
287 }
288}
289
290IMPL_LINK_NOARG(MenuFloatingWindow, PopupEnd, FloatingWindow*, void)void MenuFloatingWindow::LinkStubPopupEnd(void * instance, FloatingWindow
* data) { return static_cast<MenuFloatingWindow *>(instance
)->PopupEnd(data); } void MenuFloatingWindow::PopupEnd(__attribute__
((unused)) FloatingWindow*)
291{
292 // "this" will be deleted before the end of this method!
293 Menu* pM = pMenu;
294 if ( bInExecute )
295 {
296 End();
297 if ( pActivePopup )
298 {
299 KillActivePopup(); // should be ok to just remove it
300 //pActivePopup->bCanceled = true;
301 }
302 pMenu->bInCallback = true;
303 pMenu->Deactivate();
304 pMenu->bInCallback = false;
305 }
306 else
307 {
308 if (pMenu && pMenu->pStartedFrom)
309 pMenu->pStartedFrom->ClosePopup(pMenu);
310 }
311
312 if ( pM )
313 pM->pStartedFrom = nullptr;
314}
315
316IMPL_LINK_NOARG(MenuFloatingWindow, AutoScroll, Timer *, void)void MenuFloatingWindow::LinkStubAutoScroll(void * instance, Timer
* data) { return static_cast<MenuFloatingWindow *>(instance
)->AutoScroll(data); } void MenuFloatingWindow::AutoScroll
(__attribute__ ((unused)) Timer *)
317{
318 ImplScroll( GetPointerPosPixel() );
319}
320
321IMPL_LINK( MenuFloatingWindow, HighlightChanged, Timer*, pTimer, void )void MenuFloatingWindow::LinkStubHighlightChanged(void * instance
, Timer* data) { return static_cast<MenuFloatingWindow *>
(instance)->HighlightChanged(data); } void MenuFloatingWindow
::HighlightChanged(Timer* pTimer)
322{
323 if( ! pMenu )
324 return;
325
326 MenuItemData* pItemData = pMenu->pItemList->GetDataFromPos( nHighlightedItem );
327 if ( !pItemData )
328 return;
329
330 if ( pActivePopup && ( pActivePopup != pItemData->pSubMenu ) )
331 {
332 FloatWinPopupFlags nOldFlags = GetPopupModeFlags();
333 SetPopupModeFlags( GetPopupModeFlags() | FloatWinPopupFlags::NoAppFocusClose );
334 KillActivePopup();
335 SetPopupModeFlags( nOldFlags );
336 }
337 if ( !(pItemData->bEnabled && pItemData->pSubMenu && pItemData->pSubMenu->GetItemCount() && ( pItemData->pSubMenu != pActivePopup )) )
338 return;
339
340 pActivePopup = static_cast<PopupMenu*>(pItemData->pSubMenu.get());
341 long nY = nScrollerHeight+ImplGetStartY();
342 MenuItemData* pData = nullptr;
343 for ( sal_uLong n = 0; n < nHighlightedItem; n++ )
344 {
345 pData = pMenu->pItemList->GetDataFromPos( n );
346 nY += pData->aSz.Height();
347 }
348 pData = pMenu->pItemList->GetDataFromPos( nHighlightedItem );
349 Size MySize = GetOutputSizePixel();
350 Point aItemTopLeft( 0, nY );
351 Point aItemBottomRight( aItemTopLeft );
352 aItemBottomRight.AdjustX(MySize.Width() );
353 aItemBottomRight.AdjustY(pData->aSz.Height() );
354
355 // shift the popups a little
356 aItemTopLeft.AdjustX(2 );
357 aItemBottomRight.AdjustX( -2 );
358 if ( nHighlightedItem )
359 aItemTopLeft.AdjustY( -2 );
360 else
361 {
362 sal_Int32 nL, nT, nR, nB;
363 GetBorder( nL, nT, nR, nB );
364 aItemTopLeft.AdjustY( -nT );
365 }
366
367 // pTest: crash due to Reschedule() in call of Activate()
368 // Also it is prevented that submenus are displayed which
369 // were for long in Activate Rescheduled and which should not be
370 // displayed now.
371 Menu* pTest = pActivePopup;
372 FloatWinPopupFlags nOldFlags = GetPopupModeFlags();
373 SetPopupModeFlags( GetPopupModeFlags() | FloatWinPopupFlags::NoAppFocusClose );
374 sal_uInt16 nRet = pActivePopup->ImplExecute( this, tools::Rectangle( aItemTopLeft, aItemBottomRight ), FloatWinPopupFlags::Right, pMenu, pTimer == nullptr );
375 SetPopupModeFlags( nOldFlags );
376
377 // nRet != 0, if it was stopped during Activate()...
378 if ( !nRet && ( pActivePopup == pTest ) && pActivePopup->ImplGetWindow() )
379 pActivePopup->ImplGetFloatingWindow()->AddPopupModeWindow( this );
380}
381
382IMPL_LINK_NOARG(MenuFloatingWindow, SubmenuClose, Timer *, void)void MenuFloatingWindow::LinkStubSubmenuClose(void * instance
, Timer * data) { return static_cast<MenuFloatingWindow *>
(instance)->SubmenuClose(data); } void MenuFloatingWindow::
SubmenuClose(__attribute__ ((unused)) Timer *)
383{
384 if( pMenu && pMenu->pStartedFrom )
385 {
386 MenuFloatingWindow* pWin = static_cast<MenuFloatingWindow*>(pMenu->pStartedFrom->GetWindow());
387 if( pWin )
388 pWin->KillActivePopup();
389 }
390}
391
392IMPL_LINK( MenuFloatingWindow, ShowHideListener, VclWindowEvent&, rEvent, void )void MenuFloatingWindow::LinkStubShowHideListener(void * instance
, VclWindowEvent& data) { return static_cast<MenuFloatingWindow
*>(instance)->ShowHideListener(data); } void MenuFloatingWindow
::ShowHideListener(VclWindowEvent& rEvent)
393{
394 if( ! pMenu )
395 return;
396
397 if( rEvent.GetId() == VclEventId::WindowShow )
398 pMenu->ImplCallEventListeners( VclEventId::MenuShow, ITEMPOS_INVALID );
399 else if( rEvent.GetId() == VclEventId::WindowHide )
400 pMenu->ImplCallEventListeners( VclEventId::MenuHide, ITEMPOS_INVALID );
401}
402
403void MenuFloatingWindow::EnableScrollMenu( bool b )
404{
405 bScrollMenu = b;
406 nScrollerHeight = b ? static_cast<sal_uInt16>(GetSettings().GetStyleSettings().GetScrollBarSize()) /2 : 0;
407 bScrollDown = true;
408 InitMenuClipRegion(*this);
409}
410
411void MenuFloatingWindow::Start()
412{
413 if (bInExecute)
414 return;
415 bInExecute = true;
416 if (GetParent())
417 GetParent()->IncModalCount();
418}
419
420bool MenuFloatingWindow::MenuInHierarchyHasFocus() const
421{
422 if (HasChildPathFocus())
423 return true;
424 PopupMenu* pSub = GetActivePopup();
425 if (!pSub)
426 return false;
427 return pSub->ImplGetFloatingWindow()->HasChildPathFocus();
428}
429
430void MenuFloatingWindow::End()
431{
432 if (!bInExecute)
433 return;
434
435 if (GetParent() && !GetParent()->IsDisposed())
436 GetParent()->DecModalCount();
437
438 // restore focus to previous window if we still have the focus
439 VclPtr<vcl::Window> xFocusId(xSaveFocusId);
440 xSaveFocusId = nullptr;
441 if (xFocusId != nullptr && MenuInHierarchyHasFocus())
442 {
443 ImplGetSVData()->mpWinData->mbNoDeactivate = false;
444 Window::EndSaveFocus(xFocusId);
445 }
446
447 bInExecute = false;
448}
449
450void MenuFloatingWindow::Execute()
451{
452 ImplSVData* pSVData = ImplGetSVData();
453
454 pSVData->maAppData.mpActivePopupMenu = static_cast<PopupMenu*>(pMenu.get());
455
456 Start();
457
458 while (bInExecute)
459 Application::Yield();
460
461 pSVData->maAppData.mpActivePopupMenu = nullptr;
462}
463
464void MenuFloatingWindow::StopExecute()
465{
466 End();
467
468 ImplEndPopupMode(FloatWinPopupEndFlags::NONE, xSaveFocusId);
469
470 aHighlightChangedTimer.Stop();
471 if (pActivePopup)
4
Taking true branch
472 {
473 KillActivePopup();
5
Calling 'MenuFloatingWindow::KillActivePopup'
474 }
475 // notify parent, needed for accessibility
476 if( pMenu && pMenu->pStartedFrom )
477 pMenu->pStartedFrom->ImplCallEventListeners( VclEventId::MenuSubmenuDeactivate, nPosInParent );
478}
479
480void MenuFloatingWindow::KillActivePopup( PopupMenu* pThisOnly )
481{
482 if ( !pActivePopup || ( pThisOnly
5.1
'pThisOnly' is null
5.1
'pThisOnly' is null
5.1
'pThisOnly' is null
5.1
'pThisOnly' is null
&& ( pThisOnly != pActivePopup ) ) )
483 return;
484
485 if( pActivePopup->pWindow )
6
Taking false branch
486 if( static_cast<FloatingWindow *>(pActivePopup->pWindow.get())->IsInCleanUp() )
487 return; // kill it later
488 if ( pActivePopup->bInCallback )
7
Assuming field 'bInCallback' is false
8
Taking false branch
489 pActivePopup->bCanceled = true;
490
491 // For all actions pActivePopup = 0, if e.g.
492 // PopupModeEndHdl the popups to destroy were called synchronous
493 PopupMenu* pPopup = pActivePopup;
494 pActivePopup = nullptr;
9
Calling 'VclPtr::operator='
19
Returning; memory was released
495 pPopup->bInCallback = true;
20
Use of memory after it is freed
496 pPopup->Deactivate();
497 pPopup->bInCallback = false;
498 if ( pPopup->ImplGetWindow() )
499 {
500 pPopup->ImplGetFloatingWindow()->StopExecute();
501 pPopup->ImplGetFloatingWindow()->doShutdown();
502 pPopup->pWindow->SetParentToDefaultWindow();
503 pPopup->pWindow.disposeAndClear();
504
505 PaintImmediately();
506 }
507}
508
509void MenuFloatingWindow::EndExecute()
510{
511 Menu* pStart = pMenu ? pMenu->ImplGetStartMenu() : nullptr;
512
513 // if started elsewhere, cleanup there as well
514 MenuFloatingWindow* pCleanUpFrom = this;
515 MenuFloatingWindow* pWin = this;
516 while (pWin && !pWin->bInExecute &&
517 pWin->pMenu->pStartedFrom && !pWin->pMenu->pStartedFrom->IsMenuBar())
518 {
519 pWin = static_cast<PopupMenu*>(pWin->pMenu->pStartedFrom.get())->ImplGetFloatingWindow();
520 }
521 if ( pWin )
522 pCleanUpFrom = pWin;
523
524 // this window will be destroyed => store date locally...
525 Menu* pM = pMenu;
526 sal_uInt16 nItem = nHighlightedItem;
527
528 pCleanUpFrom->StopExecute();
529
530 if ( !(nItem != ITEMPOS_INVALID && pM) )
531 return;
532
533 MenuItemData* pItemData = pM->GetItemList()->GetDataFromPos( nItem );
534 if ( pItemData && !pItemData->bIsTemporary )
535 {
536 pM->nSelectedId = pItemData->nId;
537 pM->sSelectedIdent = pItemData->sIdent;
538 if (pStart)
539 {
540 pStart->nSelectedId = pItemData->nId;
541 pStart->sSelectedIdent = pItemData->sIdent;
542 }
543
544 pM->ImplSelect();
545 }
546}
547
548void MenuFloatingWindow::EndExecute( sal_uInt16 nId )
549{
550 size_t nPos;
551 if ( pMenu && pMenu->GetItemList()->GetData( nId, nPos ) )
552 nHighlightedItem = nPos;
553 else
554 nHighlightedItem = ITEMPOS_INVALID;
555
556 EndExecute();
557}
558
559void MenuFloatingWindow::MouseButtonDown( const MouseEvent& rMEvt )
560{
561 // TH creates a ToTop on this window, but the active popup
562 // should stay on top...
563 // due to focus change this would close all menus -> don't do it (#94123)
564 //if ( pActivePopup && pActivePopup->ImplGetWindow() && !pActivePopup->ImplGetFloatingWindow()->pActivePopup )
565 // pActivePopup->ImplGetFloatingWindow()->ToTop( ToTopFlags::NoGrabFocus );
566
567 ImplHighlightItem( rMEvt, true );
568
569 nMBDownPos = nHighlightedItem;
570}
571
572void MenuFloatingWindow::MouseButtonUp( const MouseEvent& rMEvt )
573{
574 MenuItemData* pData = pMenu ? pMenu->GetItemList()->GetDataFromPos( nHighlightedItem ) : nullptr;
575 // nMBDownPos store in local variable and reset immediately,
576 // as it will be too late after EndExecute
577 sal_uInt16 _nMBDownPos = nMBDownPos;
578 nMBDownPos = ITEMPOS_INVALID;
579 if ( !(pData && pData->bEnabled && ( pData->eType != MenuItemType::SEPARATOR )) )
580 return;
581
582 if ( !pData->pSubMenu )
583 {
584 EndExecute();
585 }
586 else if ( ( pData->nBits & MenuItemBits::POPUPSELECT ) && ( nHighlightedItem == _nMBDownPos ) && ( rMEvt.GetClicks() == 2 ) )
587 {
588 // not when clicked over the arrow...
589 Size aSz = GetOutputSizePixel();
590 long nFontHeight = GetTextHeight();
591 if ( rMEvt.GetPosPixel().X() < ( aSz.Width() - nFontHeight - nFontHeight/4 ) )
592 EndExecute();
593 }
594
595}
596
597void MenuFloatingWindow::MouseMove( const MouseEvent& rMEvt )
598{
599 if ( !IsVisible() || rMEvt.IsSynthetic() || rMEvt.IsEnterWindow() )
600 return;
601
602 if ( rMEvt.IsLeaveWindow() )
603 {
604 // #102461# do not remove highlight if a popup menu is open at this position
605 MenuItemData* pData = pMenu ? pMenu->pItemList->GetDataFromPos( nHighlightedItem ) : nullptr;
606 // close popup with some delayed if we leave somewhere else
607 if( pActivePopup && pData && pData->pSubMenu != pActivePopup )
608 pActivePopup->ImplGetFloatingWindow()->aSubmenuCloseTimer.Start();
609
610 if( !pActivePopup || (pData && pData->pSubMenu != pActivePopup ) )
611 ChangeHighlightItem( ITEMPOS_INVALID, false );
612
613 if ( IsScrollMenu() )
614 ImplScroll( rMEvt.GetPosPixel() );
615 }
616 else
617 {
618 aSubmenuCloseTimer.Stop();
619 if( bIgnoreFirstMove )
620 bIgnoreFirstMove = false;
621 else
622 ImplHighlightItem( rMEvt, false );
623 }
624}
625
626void MenuFloatingWindow::ImplScroll( bool bUp )
627{
628 KillActivePopup();
629 PaintImmediately();
630
631 if (!pMenu)
632 return;
633
634 Invalidate();
635
636 pMenu->ImplKillLayoutData();
637
638 if ( bScrollUp && bUp )
639 {
640 nFirstEntry = pMenu->ImplGetPrevVisible( nFirstEntry );
641 SAL_WARN_IF( nFirstEntry == ITEMPOS_INVALID, "vcl", "Scroll?!" )do { if (true && (nFirstEntry == ITEMPOS_INVALID)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Scroll?!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "641" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Scroll?!"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Scroll?!"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "641" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Scroll?!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "641" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Scroll?!"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Scroll?!"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "641" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
642
643 // avoid crash if somehow menu got disposed, and MenuItemList is empty (workaround for tdf#104686)
644 const auto pItemData = pMenu->GetItemList()->GetDataFromPos( nFirstEntry );
645 if ( pItemData )
646 {
647 long nScrollEntryHeight = pItemData->aSz.Height();
648
649 if ( !bScrollDown )
650 {
651 bScrollDown = true;
652 Invalidate();
653 }
654
655 if ( pMenu->ImplGetPrevVisible( nFirstEntry ) == ITEMPOS_INVALID )
656 {
657 bScrollUp = false;
658 Invalidate();
659 }
660
661 Scroll( 0, nScrollEntryHeight, ImplCalcClipRegion().GetBoundRect(), ScrollFlags::Clip );
662 }
663 }
664 else if ( bScrollDown && !bUp )
665 {
666 // avoid crash if somehow menu got disposed, and MenuItemList is empty (workaround for tdf#104686)
667 const auto pItemData = pMenu->GetItemList()->GetDataFromPos( nFirstEntry );
668 if ( pItemData )
669 {
670 long nScrollEntryHeight = pItemData->aSz.Height();
671
672 nFirstEntry = pMenu->ImplGetNextVisible( nFirstEntry );
673 SAL_WARN_IF( nFirstEntry == ITEMPOS_INVALID, "vcl", "Scroll?!" )do { if (true && (nFirstEntry == ITEMPOS_INVALID)) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Scroll?!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "673" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Scroll?!"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Scroll?!"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "673" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Scroll?!") == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN
), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "673" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Scroll?!"), 0); } else { ::std::ostringstream
sal_detail_stream; sal_detail_stream << "Scroll?!"; ::
sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "673" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
674
675 if ( !bScrollUp )
676 {
677 bScrollUp = true;
678 Invalidate();
679 }
680
681 long nHeight = GetOutputSizePixel().Height();
682 sal_uInt16 nLastVisible;
683 static_cast<PopupMenu*>(pMenu.get())->ImplCalcVisEntries( nHeight, nFirstEntry, &nLastVisible );
684 if ( pMenu->ImplGetNextVisible( nLastVisible ) == ITEMPOS_INVALID )
685 {
686 bScrollDown = false;
687 Invalidate();
688 }
689
690 Scroll( 0, -nScrollEntryHeight, ImplCalcClipRegion().GetBoundRect(), ScrollFlags::Clip );
691 }
692 }
693
694 Invalidate();
695}
696
697void MenuFloatingWindow::ImplScroll( const Point& rMousePos )
698{
699 Size aOutSz = GetOutputSizePixel();
700
701 long nY = nScrollerHeight;
702 long nMouseY = rMousePos.Y();
703 long nDelta = 0;
704
705 if ( bScrollUp && ( nMouseY < nY ) )
706 {
707 ImplScroll( true );
708 nDelta = nY - nMouseY;
709 }
710 else if ( bScrollDown && ( nMouseY > ( aOutSz.Height() - nY ) ) )
711 {
712 ImplScroll( false );
713 nDelta = nMouseY - ( aOutSz.Height() - nY );
714 }
715
716 if ( !nDelta )
717 return;
718
719 aScrollTimer.Stop(); // if scrolled through MouseMove.
720 long nTimeout;
721 if ( nDelta < 3 )
722 nTimeout = 200;
723 else if ( nDelta < 5 )
724 nTimeout = 100;
725 else if ( nDelta < 8 )
726 nTimeout = 70;
727 else if ( nDelta < 12 )
728 nTimeout = 40;
729 else
730 nTimeout = 20;
731 aScrollTimer.SetTimeout( nTimeout );
732 aScrollTimer.Start();
733}
734void MenuFloatingWindow::ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTimer )
735{
736 // #57934# if necessary, immediately close the active, as TH's backgroundstorage works.
737 // #65750# we prefer to refrain from the background storage of small lines.
738 // otherwise the menus are difficult to operate.
739 // MenuItemData* pNextData = pMenu->pItemList->GetDataFromPos( n );
740 // if ( pActivePopup && pNextData && ( pActivePopup != pNextData->pSubMenu ) )
741 // KillActivePopup();
742
743 aSubmenuCloseTimer.Stop();
744 if( ! pMenu )
745 return;
746
747 if ( nHighlightedItem != ITEMPOS_INVALID )
748 {
749 InvalidateItem(nHighlightedItem);
750 pMenu->ImplCallEventListeners( VclEventId::MenuDehighlight, nHighlightedItem );
751 }
752
753 nHighlightedItem = n;
754 SAL_WARN_IF( !pMenu->ImplIsVisible( nHighlightedItem ) && nHighlightedItem != ITEMPOS_INVALID, "vcl", "ChangeHighlightItem: Not visible!" )do { if (true && (!pMenu->ImplIsVisible( nHighlightedItem
) && nHighlightedItem != ITEMPOS_INVALID)) { switch (
sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) { case
SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ChangeHighlightItem: Not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "754" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ChangeHighlightItem: Not visible!"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ChangeHighlightItem: Not visible!"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "754" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ChangeHighlightItem: Not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "754" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ChangeHighlightItem: Not visible!"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ChangeHighlightItem: Not visible!"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "754" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
755 if( nHighlightedItem != ITEMPOS_INVALID )
756 {
757 if (pMenu->pStartedFrom && !pMenu->pStartedFrom->IsMenuBar())
758 {
759 // #102461# make sure parent entry is highlighted as well
760 size_t i, nCount = pMenu->pStartedFrom->pItemList->size();
761 for(i = 0; i < nCount; i++)
762 {
763 MenuItemData* pData = pMenu->pStartedFrom->pItemList->GetDataFromPos( i );
764 if( pData && ( pData->pSubMenu == pMenu ) )
765 break;
766 }
767 if( i < nCount )
768 {
769 MenuFloatingWindow* pPWin = static_cast<MenuFloatingWindow*>(pMenu->pStartedFrom->ImplGetWindow());
770 if( pPWin && pPWin->nHighlightedItem != i )
771 {
772 pPWin->InvalidateItem(i);
773 pPWin->nHighlightedItem = i;
774 }
775 }
776 }
777 InvalidateItem(nHighlightedItem);
778 pMenu->ImplCallHighlight( nHighlightedItem );
779 }
780 else
781 {
782 pMenu->nSelectedId = 0;
783 pMenu->sSelectedIdent.clear();
784 }
785
786 if ( bStartPopupTimer )
787 {
788 // #102438# Menu items are not selectable
789 // If a menu item is selected by an AT-tool via the XAccessibleAction, XAccessibleValue
790 // or XAccessibleSelection interface, and the parent popup menus are not executed yet,
791 // the parent popup menus must be executed SYNCHRONOUSLY, before the menu item is selected.
792 if ( GetSettings().GetMouseSettings().GetMenuDelay() )
793 aHighlightChangedTimer.Start();
794 else
795 HighlightChanged( &aHighlightChangedTimer );
796 }
797}
798
799/// Calculate the initial vertical pixel offset of the first item.
800/// May be negative for scrolled windows.
801long MenuFloatingWindow::GetInitialItemY(long *pStartY) const
802{
803 long nStartY = ImplGetStartY();
804 if (pStartY)
805 *pStartY = nStartY;
806 return nScrollerHeight + nStartY +
807 ImplGetSVData()->maNWFData.mnMenuFormatBorderY;
808}
809
810/// Emit an Invalidate just for this item's area
811void MenuFloatingWindow::InvalidateItem(sal_uInt16 nPos)
812{
813 if (!pMenu)
814 return;
815
816 long nY = GetInitialItemY();
817 size_t nCount = pMenu->pItemList->size();
818 for (size_t n = 0; n < nCount; n++)
819 {
820 MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
821 long nHeight = pData->aSz.Height();
822 if (n == nPos)
823 {
824 Size aWidth( GetSizePixel() );
825 tools::Rectangle aRect(Point(0, nY), Size(aWidth.Width(), nHeight));
826 Invalidate( aRect );
827 }
828 nY += nHeight;
829 }
830}
831
832void MenuFloatingWindow::RenderHighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos)
833{
834 if (!pMenu)
835 return;
836
837 Size aSz(GetOutputSizePixel());
838
839 long nX = 0;
840 long nStartY;
841 long nY = GetInitialItemY(&nStartY);
842
843 int nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;
844
845 size_t nCount = pMenu->pItemList->size();
846 for (size_t n = 0; n < nCount; n++)
847 {
848 MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
849 if (n == nPos)
850 {
851 SAL_WARN_IF(!pMenu->ImplIsVisible(n), "vcl", "Highlight: Item not visible!")do { if (true && (!pMenu->ImplIsVisible(n))) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Highlight: Item not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "851" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Highlight: Item not visible!"), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Highlight: Item not visible!"; ::sal::detail::log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "851" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Highlight: Item not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "851" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "Highlight: Item not visible!"), 0); }
else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "Highlight: Item not visible!"; ::sal::detail::log(
(::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "851" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
852 if (pData->eType != MenuItemType::SEPARATOR)
853 {
854 bool bRestoreLineColor = false;
855 Color oldLineColor;
856 bool bDrawItemRect = true;
857
858 tools::Rectangle aItemRect(Point(nX + nOuterSpaceX, nY), Size(aSz.Width() - 2 * nOuterSpaceX, pData->aSz.Height()));
859 if (pData->nBits & MenuItemBits::POPUPSELECT)
860 {
861 long nFontHeight = GetTextHeight();
862 aItemRect.AdjustRight( -(nFontHeight + nFontHeight / 4) );
863 }
864
865 if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Entire))
866 {
867 Size aPxSize(GetOutputSizePixel());
868 rRenderContext.Push(PushFlags::CLIPREGION);
869 rRenderContext.IntersectClipRegion(tools::Rectangle(Point(nX, nY), Size(aSz.Width(), pData->aSz.Height())));
870 tools::Rectangle aCtrlRect(Point(nX, 0), Size(aPxSize.Width()-nX, aPxSize.Height()));
871 MenupopupValue aVal(pMenu->nTextPos-GUTTERBORDER8, aItemRect);
872 rRenderContext.DrawNativeControl(ControlType::MenuPopup, ControlPart::Entire,
873 aCtrlRect, ControlState::ENABLED, aVal, OUString());
874 if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::MenuItem))
875 {
876 bDrawItemRect = false;
877 if (!rRenderContext.DrawNativeControl(ControlType::MenuPopup, ControlPart::MenuItem, aItemRect,
878 ControlState::SELECTED | (pData->bEnabled
879 ? ControlState::ENABLED
880 : ControlState::NONE),
881 aVal, OUString()))
882 {
883 bDrawItemRect = true;
884 }
885 }
886 else
887 bDrawItemRect = true;
888 rRenderContext.Pop();
889 }
890 if (bDrawItemRect)
891 {
892 if (pData->bEnabled)
893 rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuHighlightColor());
894 else
895 {
896 rRenderContext.SetFillColor();
897 oldLineColor = rRenderContext.GetLineColor();
898 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuHighlightColor());
899 bRestoreLineColor = true;
900 }
901
902 rRenderContext.DrawRect(aItemRect);
903 }
904 pMenu->ImplPaint(rRenderContext, GetOutputSizePixel(), nScrollerHeight, nStartY, pData, true/*bHighlight*/);
905 if (bRestoreLineColor)
906 rRenderContext.SetLineColor(oldLineColor);
907 }
908 return;
909 }
910
911 nY += pData->aSz.Height();
912 }
913}
914
915tools::Rectangle MenuFloatingWindow::ImplGetItemRect( sal_uInt16 nPos )
916{
917 if( ! pMenu )
918 return tools::Rectangle();
919
920 tools::Rectangle aRect;
921 Size aSz = GetOutputSizePixel();
922 long nStartY = ImplGetStartY();
923 long nY = nScrollerHeight+nStartY;
924
925 size_t nCount = pMenu->pItemList->size();
926 for ( size_t n = 0; n < nCount; n++ )
927 {
928 MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
929 if ( n == nPos )
930 {
931 SAL_WARN_IF( !pMenu->ImplIsVisible( n ), "vcl", "ImplGetItemRect: Item not visible!" )do { if (true && (!pMenu->ImplIsVisible( n ))) { switch
(sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN, "vcl")) {
case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ImplGetItemRect: Item not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "931" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ImplGetItemRect: Item not visible!"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ImplGetItemRect: Item not visible!"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "931" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "ImplGetItemRect: Item not visible!") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "931" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "ImplGetItemRect: Item not visible!"),
0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "ImplGetItemRect: Item not visible!"; ::sal::detail
::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/menufloatingwindow.cxx"
":" "931" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
932 if ( pData->eType != MenuItemType::SEPARATOR )
933 {
934 aRect = tools::Rectangle( Point( 0, nY ), Size( aSz.Width(), pData->aSz.Height() ) );
935 if ( pData->nBits & MenuItemBits::POPUPSELECT )
936 {
937 long nFontHeight = GetTextHeight();
938 aRect.AdjustRight( -(nFontHeight + nFontHeight/4) );
939 }
940 }
941 break;
942 }
943 nY += pData->aSz.Height();
944 }
945 return aRect;
946}
947
948void MenuFloatingWindow::ImplCursorUpDown( bool bUp, bool bHomeEnd )
949{
950 if( ! pMenu )
951 return;
952
953 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
954
955 sal_uInt16 n = nHighlightedItem;
956 if ( n == ITEMPOS_INVALID )
957 {
958 if ( bUp )
959 n = 0;
960 else
961 n = pMenu->GetItemCount()-1;
962 }
963
964 sal_uInt16 nLoop = n;
965
966 if( bHomeEnd )
967 {
968 // absolute positioning
969 if( bUp )
970 {
971 n = pMenu->GetItemCount();
972 nLoop = n-1;
973 }
974 else
975 {
976 n = sal_uInt16(-1);
977 nLoop = n+1;
978 }
979 }
980
981 do
982 {
983 if ( bUp )
984 {
985 if ( n )
986 n--;
987 else
988 if ( !IsScrollMenu() || ( nHighlightedItem == ITEMPOS_INVALID ) )
989 n = pMenu->GetItemCount()-1;
990 else
991 break;
992 }
993 else
994 {
995 n++;
996 if ( n >= pMenu->GetItemCount() )
997 {
998 if ( !IsScrollMenu() || ( nHighlightedItem == ITEMPOS_INVALID ) )
999 n = 0;
1000 else
1001 break;
1002 }
1003 }
1004
1005 MenuItemData* pData = pMenu->GetItemList()->GetDataFromPos( n );
1006 if ( ( pData->bEnabled || !rSettings.GetSkipDisabledInMenus() )
1007 && ( pData->eType != MenuItemType::SEPARATOR ) && pMenu->ImplIsVisible( n ) && pMenu->ImplIsSelectable( n ) )
1008 {
1009 // Is selection in visible area?
1010 if ( IsScrollMenu() )
1011 {
1012 ChangeHighlightItem( ITEMPOS_INVALID, false );
1013
1014 while ( n < nFirstEntry )
1015 ImplScroll( true );
1016
1017 Size aOutSz = GetOutputSizePixel();
1018 sal_uInt16 nLastVisible;
1019 static_cast<PopupMenu*>(pMenu.get())->ImplCalcVisEntries( aOutSz.Height(), nFirstEntry, &nLastVisible );
1020 while ( n > nLastVisible )
1021 {
1022 ImplScroll( false );
1023 static_cast<PopupMenu*>(pMenu.get())->ImplCalcVisEntries( aOutSz.Height(), nFirstEntry, &nLastVisible );
1024 }
1025 }
1026 ChangeHighlightItem( n, false );
1027 break;
1028 }
1029 } while ( n != nLoop );
1030}
1031
1032void MenuFloatingWindow::KeyInput( const KeyEvent& rKEvent )
1033{
1034 VclPtr<vcl::Window> xWindow = this;
1035
1036 bool autoacc = ImplGetSVData()->maNWFData.mbAutoAccel;
1037 sal_uInt16 nCode = rKEvent.GetKeyCode().GetCode();
1038 bKeyInput = true;
1039 switch ( nCode )
1
Control jumps to 'case 1026:' at line 1082
1040 {
1041 case KEY_UP:
1042 case KEY_DOWN:
1043 {
1044 ImplCursorUpDown( nCode == KEY_UP );
1045 }
1046 break;
1047 case KEY_END:
1048 case KEY_HOME:
1049 {
1050 ImplCursorUpDown( nCode == KEY_END, true );
1051 }
1052 break;
1053 case KEY_F6:
1054 case KEY_ESCAPE:
1055 {
1056 // Ctrl-F6 acts like ESC here, the menu bar however will then put the focus in the document
1057 if( nCode == KEY_F6 && !rKEvent.GetKeyCode().IsMod1() )
1058 break;
1059 if( pMenu )
1060 {
1061 if ( !pMenu->pStartedFrom )
1062 {
1063 StopExecute();
1064 KillActivePopup();
1065 }
1066 else if (pMenu->pStartedFrom->IsMenuBar())
1067 {
1068 pMenu->pStartedFrom->MenuBarKeyInput(rKEvent);
1069 }
1070 else
1071 {
1072 StopExecute();
1073 PopupMenu* pPopupMenu = static_cast<PopupMenu*>(pMenu->pStartedFrom.get());
1074 MenuFloatingWindow* pFloat = pPopupMenu->ImplGetFloatingWindow();
1075 pFloat->GrabFocus();
1076 pFloat->KillActivePopup();
1077 pPopupMenu->ImplCallHighlight(pFloat->nHighlightedItem);
1078 }
1079 }
1080 }
1081 break;
1082 case KEY_LEFT:
1083 {
1084 if ( pMenu && pMenu->pStartedFrom )
2
Taking true branch
1085 {
1086 StopExecute();
3
Calling 'MenuFloatingWindow::StopExecute'
1087 if (pMenu->pStartedFrom->IsMenuBar())
1088 {
1089 pMenu->pStartedFrom->MenuBarKeyInput(rKEvent);
1090 }
1091 else
1092 {
1093 MenuFloatingWindow* pFloat = static_cast<PopupMenu*>(pMenu->pStartedFrom.get())->ImplGetFloatingWindow();
1094 pFloat->GrabFocus();
1095 pFloat->KillActivePopup();
1096 sal_uInt16 highlightItem = pFloat->GetHighlightedItem();
1097 pFloat->ChangeHighlightItem(highlightItem, false);
1098 }
1099 }
1100 }
1101 break;
1102 case KEY_RIGHT:
1103 {
1104 if( pMenu )
1105 {
1106 bool bDone = false;
1107 if ( nHighlightedItem != ITEMPOS_INVALID )
1108 {
1109 MenuItemData* pData = pMenu->GetItemList()->GetDataFromPos( nHighlightedItem );
1110 if ( pData && pData->pSubMenu )
1111 {
1112 HighlightChanged( nullptr );
1113 bDone = true;
1114 }
1115 }
1116 if ( !bDone )
1117 {
1118 Menu* pStart = pMenu->ImplGetStartMenu();
1119 if (pStart && pStart->IsMenuBar())
1120 {
1121 // Forward...
1122 pStart->ImplGetWindow()->KeyInput( rKEvent );
1123 }
1124 }
1125 }
1126 }
1127 break;
1128 case KEY_RETURN:
1129 {
1130 if( pMenu )
1131 {
1132 MenuItemData* pData = pMenu->GetItemList()->GetDataFromPos( nHighlightedItem );
1133 if ( pData && pData->bEnabled )
1134 {
1135 if ( pData->pSubMenu )
1136 HighlightChanged( nullptr );
1137 else
1138 EndExecute();
1139 }
1140 else
1141 StopExecute();
1142 }
1143 }
1144 break;
1145 case KEY_MENU:
1146 {
1147 if( pMenu )
1148 {
1149 Menu* pStart = pMenu->ImplGetStartMenu();
1150 if (pStart && pStart->IsMenuBar())
1151 {
1152 // Forward...
1153 pStart->ImplGetWindow()->KeyInput( rKEvent );
1154 }
1155 }
1156 }
1157 break;
1158 default:
1159 {
1160 sal_Unicode nCharCode = rKEvent.GetCharCode();
1161 size_t nPos = 0;
1162 size_t nDuplicates = 0;
1163 MenuItemData* pData = (nCharCode && pMenu) ?
1164 pMenu->GetItemList()->SearchItem(nCharCode, rKEvent.GetKeyCode(), nPos, nDuplicates, nHighlightedItem) : nullptr;
1165 if (pData)
1166 {
1167 if ( pData->pSubMenu || nDuplicates > 1 )
1168 {
1169 ChangeHighlightItem( nPos, false );
1170 HighlightChanged( nullptr );
1171 }
1172 else
1173 {
1174 nHighlightedItem = nPos;
1175 EndExecute();
1176 }
1177 }
1178 else
1179 FloatingWindow::KeyInput( rKEvent );
1180 }
1181 }
1182
1183 if (pMenu && pMenu->pStartedFrom && pMenu->pStartedFrom->IsMenuBar())
1184 {
1185 MenuBar *pMenuBar = static_cast<MenuBar*>(pMenu->pStartedFrom.get());
1186 const bool bShowAccels = nCode != KEY_ESCAPE;
1187 if (pMenuBar->getMenuBarWindow()->GetMBWMenuKey() != bShowAccels)
1188 {
1189 pMenuBar->getMenuBarWindow()->SetMBWMenuKey(bShowAccels);
1190 pMenuBar->getMenuBarWindow()->SetMBWHideAccel(!bShowAccels);
1191 if (autoacc)
1192 Invalidate(InvalidateFlags::Update);
1193 }
1194 }
1195
1196 // #105474# check if menu window was not destroyed
1197 if ( !xWindow->IsDisposed() )
1198 {
1199 bKeyInput = false;
1200 }
1201}
1202
1203void MenuFloatingWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle &rPaintRect)
1204{
1205 if (!pMenu)
1206 return;
1207
1208 // Set the clip before the buffering starts: rPaintRect may be larger than the current clip,
1209 // this way the buffer -> render context copy happens with this clip.
1210 rRenderContext.Push(PushFlags::CLIPREGION);
1211 rRenderContext.SetClipRegion(vcl::Region(rPaintRect));
1212
1213 // Make sure that all actual rendering happens in one go to avoid flicker.
1214 vcl::BufferDevice pBuffer(this, rRenderContext);
1215
1216 if (rRenderContext.IsNativeControlSupported(ControlType::MenuPopup, ControlPart::Entire))
1217 {
1218 pBuffer->SetClipRegion();
1219 long nX = 0;
1220 Size aPxSize(GetOutputSizePixel());
1221 aPxSize.AdjustWidth( -nX );
1222 ImplControlValue aVal(pMenu->nTextPos - GUTTERBORDER8);
1223 pBuffer->DrawNativeControl(ControlType::MenuPopup, ControlPart::Entire,
1224 tools::Rectangle(Point(nX, 0), aPxSize), ControlState::ENABLED,
1225 aVal, OUString());
1226 InitMenuClipRegion(*pBuffer);
1227 }
1228 if (IsScrollMenu())
1229 {
1230 ImplDrawScroller(*pBuffer, true);
1231 ImplDrawScroller(*pBuffer, false);
1232 }
1233 pBuffer->SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuColor());
1234 pMenu->ImplPaint(*pBuffer, GetOutputSizePixel(), nScrollerHeight, ImplGetStartY());
1235 if (nHighlightedItem != ITEMPOS_INVALID)
1236 RenderHighlightItem(*pBuffer, nHighlightedItem);
1237
1238 pBuffer.Dispose();
1239 rRenderContext.Pop();
1240}
1241
1242void MenuFloatingWindow::ImplDrawScroller(vcl::RenderContext& rRenderContext, bool bUp)
1243{
1244 if (!pMenu)
1245 return;
1246
1247 rRenderContext.SetClipRegion();
1248
1249 Size aOutSz(GetOutputSizePixel());
1250 long nY = bUp ? 0 : (aOutSz.Height() - nScrollerHeight);
1251 long nX = 0;
1252 tools::Rectangle aRect(Point(nX, nY), Size(aOutSz.Width() - nX, nScrollerHeight));
1253
1254 DecorationView aDecoView(&rRenderContext);
1255 SymbolType eSymbol = bUp ? SymbolType::SPIN_UP : SymbolType::SPIN_DOWN;
1256
1257 DrawSymbolFlags nStyle = DrawSymbolFlags::NONE;
1258 if ((bUp && !bScrollUp) || (!bUp && !bScrollDown))
1259 nStyle |= DrawSymbolFlags::Disable;
1260
1261 aDecoView.DrawSymbol(aRect, eSymbol, rRenderContext.GetSettings().GetStyleSettings().GetButtonTextColor(), nStyle);
1262
1263 InitMenuClipRegion(rRenderContext);
1264}
1265
1266void MenuFloatingWindow::RequestHelp( const HelpEvent& rHEvt )
1267{
1268 sal_uInt16 nId = nHighlightedItem;
1269 Menu* pM = pMenu;
1270 vcl::Window* pW = this;
1271
1272 // #102618# Get item rect before destroying the window in EndExecute() call
1273 tools::Rectangle aHighlightRect( ImplGetItemRect( nHighlightedItem ) );
1274
1275 if ( rHEvt.GetMode() & HelpEventMode::CONTEXT )
1276 {
1277 nHighlightedItem = ITEMPOS_INVALID;
1278 EndExecute();
1279 pW = nullptr;
1280 }
1281
1282 if( !ImplHandleHelpEvent( pW, pM, nId, rHEvt, aHighlightRect ) )
1283 Window::RequestHelp( rHEvt );
1284}
1285
1286void MenuFloatingWindow::StateChanged( StateChangedType nType )
1287{
1288 FloatingWindow::StateChanged( nType );
1289
1290 if ( ( nType == StateChangedType::ControlForeground ) || ( nType == StateChangedType::ControlBackground ) )
1291 {
1292 ApplySettings(*this);
1293 Invalidate();
1294 }
1295}
1296
1297void MenuFloatingWindow::DataChanged( const DataChangedEvent& rDCEvt )
1298{
1299 FloatingWindow::DataChanged( rDCEvt );
1300
1301 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
1302 (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
1303 ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
1304 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
1305 {
1306 ApplySettings(*this);
1307 Invalidate();
1308 }
1309}
1310
1311void MenuFloatingWindow::Command( const CommandEvent& rCEvt )
1312{
1313 if ( rCEvt.GetCommand() == CommandEventId::Wheel )
1314 {
1315 const CommandWheelData* pData = rCEvt.GetWheelData();
1316 if( !pData->GetModifier() && ( pData->GetMode() == CommandWheelMode::SCROLL ) )
1317 {
1318 ImplScroll( pData->GetDelta() > 0 );
1319 MouseMove( MouseEvent( GetPointerPosPixel(), 0 ) );
1320 }
1321 }
1322}
1323
1324css::uno::Reference<css::accessibility::XAccessible> MenuFloatingWindow::CreateAccessible()
1325{
1326 css::uno::Reference<css::accessibility::XAccessible> xAcc;
1327
1328 if (pMenu && !pMenu->pStartedFrom)
1329 xAcc = pMenu->GetAccessible();
1330
1331 return xAcc;
1332}
1333
1334/* 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();
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);
10
Calling 'Reference::set'
18
Returning; memory was released
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)
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)
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)
113 m_pBody->release();
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody
10.1
'pBody' is null
10.1
'pBody' is null
10.1
'pBody' is null
10.1
'pBody' is null
)
11
Taking false branch
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld
11.1
'pOld' is non-null
11.1
'pOld' is non-null
11.1
'pOld' is non-null
11.1
'pOld' is non-null
)
12
Taking true branch
127 pOld->release();
13
Calling 'VclReferenceBase::release'
17
Returning; memory was released
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;
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