Bug Summary

File:home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx
Warning:line 364, column 5
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 dockwin.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/dockwin.cxx

/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.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 <tools/time.hxx>
21#include <sal/log.hxx>
22#include <vcl/accel.hxx>
23#include <vcl/event.hxx>
24#include <vcl/floatwin.hxx>
25#include <vcl/dockwin.hxx>
26#include <vcl/layout.hxx>
27#include <vcl/svapp.hxx>
28#include <vcl/timer.hxx>
29#include <vcl/idle.hxx>
30#include <vcl/settings.hxx>
31
32#include <svdata.hxx>
33#include <window.h>
34#include <brdwin.hxx>
35
36#define DOCKWIN_FLOATSTYLES(WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE
)
(WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE )
37
38class DockingWindow::ImplData
39{
40public:
41 ImplData();
42
43 VclPtr<vcl::Window> mpParent;
44 Size maMaxOutSize;
45};
46
47DockingWindow::ImplData::ImplData()
48{
49 mpParent = nullptr;
50 maMaxOutSize = Size( SHRT_MAX32767, SHRT_MAX32767 );
51}
52
53namespace {
54
55class ImplDockFloatWin : public FloatingWindow
56{
57private:
58 VclPtr<DockingWindow> mpDockWin;
59 sal_uInt64 mnLastTicks;
60 Idle maDockIdle;
61 Point maDockPos;
62 tools::Rectangle maDockRect;
63 bool mbInMove;
64 ImplSVEvent * mnLastUserEvent;
65
66 DECL_LINK(DockingHdl, void *, void)static void LinkStubDockingHdl(void *, void *); void DockingHdl
(void *)
;
67 DECL_LINK(DockTimerHdl, Timer *, void)static void LinkStubDockTimerHdl(void *, Timer *); void DockTimerHdl
(Timer *)
;
68public:
69 ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits,
70 DockingWindow* pDockingWin );
71 virtual ~ImplDockFloatWin() override;
72 virtual void dispose() override;
73
74 virtual void Move() override;
75 virtual void Resize() override;
76 virtual void Resizing( Size& rSize ) override;
77 virtual bool Close() override;
78};
79
80}
81
82ImplDockFloatWin::ImplDockFloatWin( vcl::Window* pParent, WinBits nWinBits,
83 DockingWindow* pDockingWin ) :
84 FloatingWindow( pParent, nWinBits ),
85 mpDockWin( pDockingWin ),
86 mnLastTicks( tools::Time::GetSystemTicks() ),
87 mbInMove( false ),
88 mnLastUserEvent( nullptr )
89{
90 // copy settings of DockingWindow
91 if ( pDockingWin )
92 {
93 SetSettings( pDockingWin->GetSettings() );
94 Enable( pDockingWin->IsEnabled(), false );
95 EnableInput( pDockingWin->IsInputEnabled(), false );
96 AlwaysEnableInput( pDockingWin->IsAlwaysEnableInput(), false );
97 EnableAlwaysOnTop( pDockingWin->IsAlwaysOnTopEnabled() );
98 SetActivateMode( pDockingWin->GetActivateMode() );
99 }
100
101 SetBackground();
102
103 maDockIdle.SetInvokeHandler( LINK( this, ImplDockFloatWin, DockTimerHdl )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockFloatWin
*>(this), &ImplDockFloatWin::LinkStubDockTimerHdl)
);
104 maDockIdle.SetPriority( TaskPriority::HIGH_IDLE );
105 maDockIdle.SetDebugName( "vcl::ImplDockFloatWin maDockIdle" );
106}
107
108ImplDockFloatWin::~ImplDockFloatWin()
109{
110 disposeOnce();
111}
112
113void ImplDockFloatWin::dispose()
114{
115 if( mnLastUserEvent )
116 Application::RemoveUserEvent( mnLastUserEvent );
117
118 disposeBuilder();
119
120 mpDockWin.clear();
121 FloatingWindow::dispose();
122}
123
124IMPL_LINK_NOARG(ImplDockFloatWin, DockTimerHdl, Timer *, void)void ImplDockFloatWin::LinkStubDockTimerHdl(void * instance, Timer
* data) { return static_cast<ImplDockFloatWin *>(instance
)->DockTimerHdl(data); } void ImplDockFloatWin::DockTimerHdl
(__attribute__ ((unused)) Timer *)
125{
126 SAL_WARN_IF( !mpDockWin->IsFloatingMode(), "vcl", "docktimer called but not floating" )do { if (true && (!mpDockWin->IsFloatingMode())) {
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
() << "docktimer called but not floating") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "126" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "docktimer called but not floating"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "docktimer called but not floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "126" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "docktimer called but not floating") == 1) { ::sal_detail_log
( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "126" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "docktimer called but not floating"), 0
); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "docktimer called but not floating"; ::sal::detail::
log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "126" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
127
128 maDockIdle.Stop();
129 PointerState aState = GetPointerState();
130
131 if( aState.mnState & KEY_MOD1 )
132 {
133 // i43499 CTRL disables docking now
134 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
135 mpDockWin->EndDocking( maDockRect, true );
136 if( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) )
137 maDockIdle.Start();
138 }
139 else if( ! ( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) )
140 {
141 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
142 mpDockWin->EndDocking( maDockRect, false );
143 }
144 else
145 {
146 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Big | ShowTrackFlags::TrackWindow );
147 maDockIdle.Start();
148 }
149}
150
151IMPL_LINK_NOARG(ImplDockFloatWin, DockingHdl, void*, void)void ImplDockFloatWin::LinkStubDockingHdl(void * instance, void
* data) { return static_cast<ImplDockFloatWin *>(instance
)->DockingHdl(data); } void ImplDockFloatWin::DockingHdl(__attribute__
((unused)) void*)
152{
153 PointerState aState = mpDockWin->GetParent()->GetPointerState();
154
155 mnLastUserEvent = nullptr;
156 if( mpDockWin->IsDockable() &&
157 (tools::Time::GetSystemTicks() - mnLastTicks > 500) &&
158 ( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) &&
159 !(aState.mnState & KEY_MOD1) ) // i43499 CTRL disables docking now
160 {
161 maDockPos = mpDockWin->GetParent()->AbsoluteScreenToOutputPixel( OutputToAbsoluteScreenPixel( Point() ) );
162 maDockPos = mpDockWin->GetParent()->OutputToScreenPixel( maDockPos ); // sfx expects screen coordinates
163
164 if( ! mpDockWin->IsDocking() )
165 mpDockWin->StartDocking();
166 maDockRect = tools::Rectangle( maDockPos, mpDockWin->GetSizePixel() );
167
168 // mouse pos also in screen pixels
169 Point aMousePos = mpDockWin->GetParent()->OutputToScreenPixel( aState.maPos );
170
171 bool bFloatMode = mpDockWin->Docking( aMousePos, maDockRect );
172 if( ! bFloatMode )
173 {
174 mpDockWin->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Object | ShowTrackFlags::TrackWindow );
175 DockTimerHdl( nullptr );
176 }
177 else
178 {
179 mpDockWin->GetParent()->ImplGetFrameWindow()->HideTracking();
180 maDockIdle.Stop();
181 mpDockWin->EndDocking( maDockRect, true );
182 }
183 }
184 mbInMove = false;
185}
186
187void ImplDockFloatWin::Move()
188{
189 if( mbInMove )
190 return;
191
192 mbInMove = true;
193 FloatingWindow::Move();
194 mpDockWin->Move();
195
196 /*
197 * note: the window should only dock if
198 * the user releases all mouse buttons. The real problem here
199 * is that we don't get mouse events (at least not on X)
200 * if the mouse is on the decoration. So we have to start an
201 * awkward timer based process that polls the modifier/buttons
202 * to see whether they are in the right condition shortly after the
203 * last Move message.
204 */
205 if( ! mnLastUserEvent )
206 mnLastUserEvent = Application::PostUserEvent( LINK( this, ImplDockFloatWin, DockingHdl )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockFloatWin
*>(this), &ImplDockFloatWin::LinkStubDockingHdl)
, nullptr, true );
207}
208
209void ImplDockFloatWin::Resize()
210{
211 FloatingWindow::Resize();
212 Size aSize( GetSizePixel() );
213 mpDockWin->ImplPosSizeWindow( 0, 0, aSize.Width(), aSize.Height(), PosSizeFlags::PosSize );
214}
215
216void ImplDockFloatWin::Resizing( Size& rSize )
217{
218 FloatingWindow::Resizing( rSize );
219 mpDockWin->Resizing( rSize );
220}
221
222bool ImplDockFloatWin::Close()
223{
224 return mpDockWin->Close();
225}
226
227void DockingWindow::ImplStartDocking( const Point& rPos )
228{
229 if ( !mbDockable )
230 return;
231
232 maMouseOff = rPos;
233 mbDocking = true;
234 mbLastFloatMode = IsFloatingMode();
235 mbStartFloat = mbLastFloatMode;
236
237 // calculate FloatingBorder
238 VclPtr<FloatingWindow> pWin;
239 if ( mpFloatWin )
240 pWin = mpFloatWin;
241 else
242 pWin = VclPtr<ImplDockFloatWin>::Create( mpImplData->mpParent, mnFloatBits, nullptr );
243 pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom );
244 if ( !mpFloatWin )
245 pWin.disposeAndClear();
246
247 Point aPos = ImplOutputToFrame( Point() );
248 Size aSize = Window::GetOutputSizePixel();
249 mnTrackX = aPos.X();
250 mnTrackY = aPos.Y();
251 mnTrackWidth = aSize.Width();
252 mnTrackHeight = aSize.Height();
253
254 if ( mbLastFloatMode )
255 {
256 maMouseOff.AdjustX(mnDockLeft );
257 maMouseOff.AdjustY(mnDockTop );
258 mnTrackX -= mnDockLeft;
259 mnTrackY -= mnDockTop;
260 mnTrackWidth += mnDockLeft+mnDockRight;
261 mnTrackHeight += mnDockTop+mnDockBottom;
262 }
263
264 if ( GetSettings().GetStyleSettings().GetDragFullOptions() & DragFullOptions::Docking &&
265 !( mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ) ) // no full drag when migrating to system window
266 mbDragFull = true;
267 else
268 {
269 StartDocking();
270 mbDragFull = false;
271 ImplUpdateAll();
272 ImplGetFrameWindow()->ImplUpdateAll();
273 }
274
275 StartTracking( StartTrackingFlags::KeyMod );
276}
277
278void DockingWindow::ImplInitDockingWindowData()
279{
280 mpWindowImpl->mbDockWin = true;
281 mpFloatWin = nullptr;
282 mpOldBorderWin = nullptr;
283 mpImplData.reset(new ImplData);
284 mnTrackX = 0;
285 mnTrackY = 0;
286 mnTrackWidth = 0;
287 mnTrackHeight = 0;
288 mnDockLeft = 0;
289 mnDockTop = 0;
290 mnDockRight = 0;
291 mnDockBottom = 0;
292 mnFloatBits = 0;
293 mbDockCanceled = false;
294 mbDockable = false;
295 mbDocking = false;
296 mbDragFull = false;
297 mbLastFloatMode = false;
298 mbStartFloat = false;
299 mbRollUp = false;
300 mbDockBtn = false;
301 mbHideBtn = false;
302 mbIsDeferredInit = false;
303 mbIsCalculatingInitialLayoutSize = false;
304 mpDialogParent = nullptr;
305
306 //To-Do, reuse maResizeTimer
307 maLayoutIdle.SetPriority(TaskPriority::RESIZE);
308 maLayoutIdle.SetInvokeHandler( LINK( this, DockingWindow, ImplHandleLayoutTimerHdl )::tools::detail::makeLink( ::tools::detail::castTo<DockingWindow
*>(this), &DockingWindow::LinkStubImplHandleLayoutTimerHdl
)
);
309 maLayoutIdle.SetDebugName( "vcl::DockingWindow maLayoutIdle" );
310}
311
312void DockingWindow::ImplInit( vcl::Window* pParent, WinBits nStyle )
313{
314 if ( !(nStyle & WB_NODIALOGCONTROL) )
315 nStyle |= WB_DIALOGCONTROL;
316
317 mpImplData->mpParent = pParent;
318 mbDockable = (nStyle & WB_DOCKABLE) != 0;
319 mnFloatBits = WB_BORDER | (nStyle & DOCKWIN_FLOATSTYLES(WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE
)
);
320 nStyle &= ~(DOCKWIN_FLOATSTYLES(WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE
)
| WB_BORDER);
321
322 Window::ImplInit( pParent, nStyle, nullptr );
323
324 ImplInitSettings();
325}
326
327void DockingWindow::ImplInitSettings()
328{
329 // Hack: to be able to build DockingWindows w/o background before switching
330 // TODO: Hack
331 if ( !IsBackground() )
332 return;
333
334 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
335
336 Color aColor;
337 if ( IsControlBackground() )
338 aColor = GetControlBackground();
339 else if ( Window::GetStyle() & WB_3DLOOK )
340 aColor = rStyleSettings.GetFaceColor();
341 else
342 aColor = rStyleSettings.GetWindowColor();
343 SetBackground( aColor );
344}
345
346DockingWindow::DockingWindow( WindowType nType ) :
347 Window(nType)
348{
349 ImplInitDockingWindowData();
350}
351
352DockingWindow::DockingWindow( vcl::Window* pParent, WinBits nStyle ) :
353 Window( WindowType::DOCKINGWINDOW )
354{
355 ImplInitDockingWindowData();
356 ImplInit( pParent, nStyle );
357}
358
359//Find the real parent stashed in mpDialogParent.
360void DockingWindow::doDeferredInit(WinBits nBits)
361{
362 vcl::Window *pParent = mpDialogParent;
363 mpDialogParent = nullptr;
1
Calling 'VclPtr::operator='
12
Returning; memory was released
364 ImplInit(pParent, nBits);
13
Use of memory after it is freed
365 mbIsDeferredInit = false;
366}
367
368void DockingWindow::loadUI(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
369 const css::uno::Reference<css::frame::XFrame> &rFrame)
370{
371 mbIsDeferredInit = true;
372 mpDialogParent = pParent; //should be unset in doDeferredInit
373 m_pUIBuilder.reset( new VclBuilder(this, AllSettings::GetUIRootDir(), rUIXMLDescription, rID, rFrame) );
374}
375
376DockingWindow::DockingWindow(vcl::Window* pParent, const OString& rID,
377 const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame> &rFrame)
378 : Window(WindowType::DOCKINGWINDOW)
379{
380 ImplInitDockingWindowData();
381
382 loadUI(pParent, rID, rUIXMLDescription, rFrame);
383}
384
385DockingWindow::~DockingWindow()
386{
387 disposeOnce();
388}
389
390void DockingWindow::dispose()
391{
392 if ( IsFloatingMode() )
393 {
394 Show( false, ShowFlags::NoFocusChange );
395 SetFloatingMode(false);
396 }
397 mpImplData.reset();
398 mpFloatWin.clear();
399 mpOldBorderWin.clear();
400 mpDialogParent.clear();
401 disposeBuilder();
402 Window::dispose();
403}
404
405void DockingWindow::Tracking( const TrackingEvent& rTEvt )
406{
407 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
408 return Window::Tracking( rTEvt );
409
410 if ( !mbDocking )
411 return;
412
413 if ( rTEvt.IsTrackingEnded() )
414 {
415 mbDocking = false;
416 if ( mbDragFull )
417 {
418 // reset old state on Cancel
419 if ( rTEvt.IsTrackingCanceled() )
420 {
421 StartDocking();
422 tools::Rectangle aRect( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) );
423 EndDocking( aRect, mbStartFloat );
424 }
425 }
426 else
427 {
428 HideTracking();
429 if ( rTEvt.IsTrackingCanceled() )
430 {
431 mbDockCanceled = true;
432 EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
433 mbDockCanceled = false;
434 }
435 else
436 EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode );
437 }
438 }
439 // dock only for non-synthetic MouseEvents
440 else if ( !rTEvt.GetMouseEvent().IsSynthetic() || rTEvt.GetMouseEvent().IsModifierChanged() )
441 {
442 Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel();
443 Point aFrameMousePos = ImplOutputToFrame( aMousePos );
444 Size aFrameSize = mpWindowImpl->mpFrameWindow->GetOutputSizePixel();
445 if ( aFrameMousePos.X() < 0 )
446 aFrameMousePos.setX( 0 );
447 if ( aFrameMousePos.Y() < 0 )
448 aFrameMousePos.setY( 0 );
449 if ( aFrameMousePos.X() > aFrameSize.Width()-1 )
450 aFrameMousePos.setX( aFrameSize.Width()-1 );
451 if ( aFrameMousePos.Y() > aFrameSize.Height()-1 )
452 aFrameMousePos.setY( aFrameSize.Height()-1 );
453 aMousePos = ImplFrameToOutput( aFrameMousePos );
454 aMousePos.AdjustX( -(maMouseOff.X()) );
455 aMousePos.AdjustY( -(maMouseOff.Y()) );
456 Point aFramePos = ImplOutputToFrame( aMousePos );
457 tools::Rectangle aTrackRect( aFramePos, Size( mnTrackWidth, mnTrackHeight ) );
458 tools::Rectangle aCompRect = aTrackRect;
459 aFramePos.AdjustX(maMouseOff.X() );
460 aFramePos.AdjustY(maMouseOff.Y() );
461 if ( mbDragFull )
462 StartDocking();
463 bool bFloatMode = Docking( aFramePos, aTrackRect );
464 if ( mbLastFloatMode != bFloatMode )
465 {
466 if ( bFloatMode )
467 {
468 aTrackRect.AdjustLeft( -mnDockLeft );
469 aTrackRect.AdjustTop( -mnDockTop );
470 aTrackRect.AdjustRight(mnDockRight );
471 aTrackRect.AdjustBottom(mnDockBottom );
472 }
473 else
474 {
475 if ( aCompRect == aTrackRect )
476 {
477 aTrackRect.AdjustLeft(mnDockLeft );
478 aTrackRect.AdjustTop(mnDockTop );
479 aTrackRect.AdjustRight( -mnDockRight );
480 aTrackRect.AdjustBottom( -mnDockBottom );
481 }
482 }
483 mbLastFloatMode = bFloatMode;
484 }
485 if ( mbDragFull )
486 {
487 Point aOldPos = OutputToScreenPixel( Point() );
488 EndDocking( aTrackRect, mbLastFloatMode );
489 // repaint if state or position has changed
490 if ( aOldPos != OutputToScreenPixel( Point() ) )
491 {
492 ImplUpdateAll();
493 ImplGetFrameWindow()->ImplUpdateAll();
494 }
495// EndDocking( aTrackRect, mbLastFloatMode );
496 }
497 else
498 {
499 ShowTrackFlags nTrackStyle;
500 if ( bFloatMode )
501 nTrackStyle = ShowTrackFlags::Big;
502 else
503 nTrackStyle = ShowTrackFlags::Object;
504 tools::Rectangle aShowTrackRect = aTrackRect;
505 aShowTrackRect.SetPos( ImplFrameToOutput( aShowTrackRect.TopLeft() ) );
506 ShowTracking( aShowTrackRect, nTrackStyle );
507
508 // recalculate mouse offset, as the rectangle was changed
509 maMouseOff.setX( aFramePos.X() - aTrackRect.Left() );
510 maMouseOff.setY( aFramePos.Y() - aTrackRect.Top() );
511 }
512
513 mnTrackX = aTrackRect.Left();
514 mnTrackY = aTrackRect.Top();
515 mnTrackWidth = aTrackRect.GetWidth();
516 mnTrackHeight = aTrackRect.GetHeight();
517 }
518}
519
520bool DockingWindow::EventNotify( NotifyEvent& rNEvt )
521{
522 if( GetDockingManager()->IsDockable( this ) ) // new docking interface
523 return Window::EventNotify( rNEvt );
524
525 if ( mbDockable )
526 {
527 const bool bDockingSupportCrippled = !StyleSettings::GetDockingFloatsSupported();
528
529 if ( rNEvt.GetType() == MouseNotifyEvent::MOUSEBUTTONDOWN )
530 {
531 const MouseEvent* pMEvt = rNEvt.GetMouseEvent();
532 if ( pMEvt->IsLeft() )
533 {
534 if (!bDockingSupportCrippled && pMEvt->IsMod1() && (pMEvt->GetClicks() == 2) )
535 {
536 SetFloatingMode( !IsFloatingMode() );
537 if ( IsFloatingMode() )
538 ToTop( ToTopFlags::GrabFocusOnly );
539 return true;
540 }
541 else if ( pMEvt->GetClicks() == 1 )
542 {
543 // check if window is floating standalone (IsFloating())
544 // or only partially floating and still docked with one border
545 // ( !mpWindowImpl->mbFrame)
546 if( ! IsFloatingMode() || ! mpFloatWin->mpWindowImpl->mbFrame )
547 {
548 Point aPos = pMEvt->GetPosPixel();
549 vcl::Window* pWindow = rNEvt.GetWindow();
550 if ( pWindow != this )
551 {
552 aPos = pWindow->OutputToScreenPixel( aPos );
553 aPos = ScreenToOutputPixel( aPos );
554 }
555 ImplStartDocking( aPos );
556 }
557 return true;
558 }
559 }
560 }
561 else if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
562 {
563 const vcl::KeyCode& rKey = rNEvt.GetKeyEvent()->GetKeyCode();
564 if( rKey.GetCode() == KEY_F10 && rKey.GetModifier() &&
565 rKey.IsShift() && rKey.IsMod1() && !bDockingSupportCrippled )
566 {
567 SetFloatingMode( !IsFloatingMode() );
568 if ( IsFloatingMode() )
569 ToTop( ToTopFlags::GrabFocusOnly );
570 return true;
571 }
572 }
573 }
574
575 return Window::EventNotify( rNEvt );
576}
577
578void DockingWindow::StartDocking()
579{
580 mbDocking = true;
581}
582
583bool DockingWindow::Docking( const Point&, tools::Rectangle& )
584{
585 return IsFloatingMode();
586}
587
588void DockingWindow::EndDocking( const tools::Rectangle& rRect, bool bFloatMode )
589{
590 bool bOrigDockCanceled = mbDockCanceled;
591 if (bFloatMode && !StyleSettings::GetDockingFloatsSupported())
592 mbDockCanceled = true;
593
594 if ( !IsDockingCanceled() )
595 {
596 if ( bFloatMode != IsFloatingMode() )
597 {
598 SetFloatingMode( bFloatMode );
599 if ( IsFloatingMode() )
600 ToTop( ToTopFlags::GrabFocusOnly );
601 if ( bFloatMode && mpFloatWin )
602 mpFloatWin->SetPosSizePixel( rRect.TopLeft(), rRect.GetSize() );
603 }
604 if ( !bFloatMode )
605 {
606 Point aPos = rRect.TopLeft();
607 aPos = GetParent()->ScreenToOutputPixel( aPos );
608 Window::SetPosSizePixel( aPos, rRect.GetSize() );
609 }
610 }
611 mbDocking = false;
612 mbDockCanceled = bOrigDockCanceled;
613}
614
615bool DockingWindow::PrepareToggleFloatingMode()
616{
617 return true;
618}
619
620bool DockingWindow::Close()
621{
622 VclPtr<vcl::Window> xWindow = this;
623 CallEventListeners( VclEventId::WindowClose );
624 if ( xWindow->IsDisposed() )
625 return false;
626
627 if ( mpWindowImpl->mxWindowPeer.is() && IsCreatedWithToolkit() )
628 return false;
629
630 Show( false, ShowFlags::NoFocusChange );
631 return true;
632}
633
634void DockingWindow::ToggleFloatingMode()
635{
636}
637
638void DockingWindow::Resizing( Size& )
639{
640}
641
642void DockingWindow::DoInitialLayout()
643{
644 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
645 Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
646
647 if (isLayoutEnabled())
648 {
649 mbIsCalculatingInitialLayoutSize = true;
650 setDeferredProperties();
651 if (IsFloatingMode())
652 setOptimalLayoutSize();
653 mbIsCalculatingInitialLayoutSize = false;
654 }
655}
656
657void DockingWindow::StateChanged( StateChangedType nType )
658{
659 switch(nType)
660 {
661 case StateChangedType::InitShow:
662 DoInitialLayout();
663 break;
664
665 case StateChangedType::ControlBackground:
666 ImplInitSettings();
667 Invalidate();
668 break;
669
670 case StateChangedType::Style:
671 mbDockable = (GetStyle() & WB_DOCKABLE) != 0;
672 break;
673
674 default:
675 break;
676 }
677
678 Window::StateChanged( nType );
679}
680
681void DockingWindow::DataChanged( const DataChangedEvent& rDCEvt )
682{
683 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
684 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
685 {
686 ImplInitSettings();
687 Invalidate();
688 }
689 else
690 Window::DataChanged( rDCEvt );
691}
692
693void DockingWindow::SetFloatingMode( bool bFloatMode )
694{
695 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
696 if( pWrapper )
697 {
698 pWrapper->SetFloatingMode( bFloatMode );
699 return;
700 }
701 if ( IsFloatingMode() == bFloatMode )
702 return;
703
704 if ( !PrepareToggleFloatingMode() ) // changes to floating mode can be vetoed
705 return;
706
707 bool bVisible = IsVisible();
708
709 if ( bFloatMode )
710 {
711 // set deferred properties early, so border width will end up
712 // in our mpWindowImpl->mnBorderWidth, not in mpBorderWindow.
713 // (see its usage in setPosSizeOnContainee and GetOptimalSize.)
714 setDeferredProperties();
715
716 Show( false, ShowFlags::NoFocusChange );
717
718 maDockPos = Window::GetPosPixel();
719
720 vcl::Window* pRealParent = mpWindowImpl->mpRealParent;
721 mpOldBorderWin = mpWindowImpl->mpBorderWindow;
722
723 VclPtrInstance<ImplDockFloatWin> pWin(
724 mpImplData->mpParent,
725 mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? mnFloatBits | WB_SYSTEMWINDOW : mnFloatBits,
726 this );
727 mpFloatWin = pWin;
728 mpWindowImpl->mpBorderWindow = nullptr;
729 mpWindowImpl->mnLeftBorder = 0;
730 mpWindowImpl->mnTopBorder = 0;
731 mpWindowImpl->mnRightBorder = 0;
732 mpWindowImpl->mnBottomBorder = 0;
733 // if the parent gets destroyed, we also have to reset the parent of the BorderWindow
734 if ( mpOldBorderWin )
735 mpOldBorderWin->SetParent( pWin );
736
737 // #i123765# reset the buffered DropTargets when undocking, else it may not
738 // be correctly initialized
739 mpWindowImpl->mxDNDListenerContainer.clear();
740
741 SetParent( pWin );
742 SetPosPixel( Point() );
743 mpWindowImpl->mpBorderWindow = pWin;
744 pWin->mpWindowImpl->mpClientWindow = this;
745 mpWindowImpl->mpRealParent = pRealParent;
746 pWin->SetText( Window::GetText() );
747 Size aSize(Window::GetSizePixel());
748 pWin->SetOutputSizePixel(aSize);
749 pWin->SetPosPixel( maFloatPos );
750 // pass on DockingData to FloatingWindow
751 pWin->ShowTitleButton( TitleButton::Docking, mbDockBtn );
752 pWin->ShowTitleButton( TitleButton::Hide, mbHideBtn );
753 if ( mbRollUp )
754 pWin->RollUp();
755 else
756 pWin->RollDown();
757 pWin->SetRollUpOutputSizePixel( maRollUpOutSize );
758 pWin->SetMinOutputSizePixel( maMinOutSize );
759
760 pWin->SetMaxOutputSizePixel( mpImplData->maMaxOutSize );
761
762 ToggleFloatingMode();
763
764 if ( bVisible )
765 Show();
766 }
767 else
768 {
769 Show( false, ShowFlags::NoFocusChange );
770
771 // store FloatingData in FloatingWindow
772 maFloatPos = mpFloatWin->GetPosPixel();
773 mbDockBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Docking );
774 mbHideBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Hide );
775 mbRollUp = mpFloatWin->IsRollUp();
776 maRollUpOutSize = mpFloatWin->GetRollUpOutputSizePixel();
777 maMinOutSize = mpFloatWin->GetMinOutputSizePixel();
778 mpImplData->maMaxOutSize = mpFloatWin->GetMaxOutputSizePixel();
779
780 vcl::Window* pRealParent = mpWindowImpl->mpRealParent;
781 mpWindowImpl->mpBorderWindow = nullptr;
782 if ( mpOldBorderWin )
783 {
784 SetParent( mpOldBorderWin );
785 static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( mpWindowImpl->mnLeftBorder, mpWindowImpl->mnTopBorder, mpWindowImpl->mnRightBorder, mpWindowImpl->mnBottomBorder );
786 mpOldBorderWin->Resize();
787 }
788 mpWindowImpl->mpBorderWindow = mpOldBorderWin;
789 SetParent( pRealParent );
790 mpWindowImpl->mpRealParent = pRealParent;
791 mpFloatWin.disposeAndClear();
792 SetPosPixel( maDockPos );
793
794 ToggleFloatingMode();
795
796 if ( bVisible )
797 Show();
798 }
799}
800
801void DockingWindow::SetFloatStyle( WinBits nStyle )
802{
803 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
804 if( pWrapper )
805 {
806 pWrapper->SetFloatStyle( nStyle );
807 return;
808 }
809
810 mnFloatBits = nStyle;
811}
812
813WinBits DockingWindow::GetFloatStyle() const
814{
815 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
816 if( pWrapper )
817 {
818 return pWrapper->GetFloatStyle();
819 }
820
821 return mnFloatBits;
822}
823
824void DockingWindow::setPosSizePixel( long nX, long nY,
825 long nWidth, long nHeight,
826 PosSizeFlags nFlags )
827{
828 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
829 if (pWrapper)
830 {
831 if (!pWrapper->mpFloatWin)
832 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
833 }
834 else
835 {
836 if (!mpFloatWin)
837 Window::setPosSizePixel( nX, nY, nWidth, nHeight, nFlags );
838 else
839 {
840 mpFloatWin->SetOutputSizePixel(Size(nWidth, nHeight));
841 mpFloatWin->SetPosPixel(Point(nX, nY));
842 }
843 }
844
845 if (::isLayoutEnabled(this))
846 setPosSizeOnContainee();
847}
848
849Point DockingWindow::GetPosPixel() const
850{
851 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
852 if( pWrapper )
853 {
854 if ( pWrapper->mpFloatWin )
855 return pWrapper->mpFloatWin->GetPosPixel();
856 else
857 return Window::GetPosPixel();
858 }
859
860 if ( mpFloatWin )
861 return mpFloatWin->GetPosPixel();
862 else
863 return Window::GetPosPixel();
864}
865
866Size DockingWindow::GetSizePixel() const
867{
868 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
869 if( pWrapper )
870 {
871 if ( pWrapper->mpFloatWin )
872 return pWrapper->mpFloatWin->GetSizePixel();
873 else
874 return Window::GetSizePixel();
875 }
876
877 if ( mpFloatWin )
878 return mpFloatWin->GetSizePixel();
879 else
880 return Window::GetSizePixel();
881}
882
883void DockingWindow::SetOutputSizePixel( const Size& rNewSize )
884{
885 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
886 if( pWrapper )
887 {
888 if ( pWrapper->mpFloatWin )
889 pWrapper->mpFloatWin->SetOutputSizePixel( rNewSize );
890 else
891 Window::SetOutputSizePixel( rNewSize );
892 return;
893 }
894
895 if ( mpFloatWin )
896 mpFloatWin->SetOutputSizePixel( rNewSize );
897 else
898 Window::SetOutputSizePixel( rNewSize );
899}
900
901Size DockingWindow::GetOutputSizePixel() const
902{
903 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
904 if( pWrapper )
905 {
906 if ( pWrapper->mpFloatWin )
907 return pWrapper->mpFloatWin->GetOutputSizePixel();
908 else
909 return Window::GetOutputSizePixel();
910 }
911
912 if ( mpFloatWin )
913 return mpFloatWin->GetOutputSizePixel();
914 else
915 return Window::GetOutputSizePixel();
916}
917
918Point DockingWindow::GetFloatingPos() const
919{
920 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
921 if( pWrapper )
922 {
923 if ( pWrapper->mpFloatWin )
924 {
925 WindowStateData aData;
926 aData.SetMask( WindowStateMask::Pos );
927 pWrapper->mpFloatWin->GetWindowStateData( aData );
928 Point aPos( aData.GetX(), aData.GetY() );
929 aPos = pWrapper->mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
930 return aPos;
931 }
932 else
933 return maFloatPos;
934 }
935
936 if ( mpFloatWin )
937 {
938 WindowStateData aData;
939 aData.SetMask( WindowStateMask::Pos );
940 mpFloatWin->GetWindowStateData( aData );
941 Point aPos( aData.GetX(), aData.GetY() );
942 aPos = mpFloatWin->GetParent()->ImplGetFrameWindow()->AbsoluteScreenToOutputPixel( aPos );
943 return aPos;
944 }
945 else
946 return maFloatPos;
947}
948
949bool DockingWindow::IsFloatingMode() const
950{
951 ImplDockingWindowWrapper *pWrapper = ImplGetDockingManager()->GetDockingWindowWrapper( this );
952 if( pWrapper )
953 return pWrapper->IsFloatingMode();
954 else
955 return (mpFloatWin != nullptr);
956}
957
958void DockingWindow::SetMaxOutputSizePixel( const Size& rSize )
959{
960 if ( mpFloatWin )
961 mpFloatWin->SetMaxOutputSizePixel( rSize );
962 mpImplData->maMaxOutSize = rSize;
963}
964
965void DockingWindow::SetText(const OUString& rStr)
966{
967 setDeferredProperties();
968 Window::SetText(rStr);
969}
970
971OUString DockingWindow::GetText() const
972{
973 const_cast<DockingWindow*>(this)->setDeferredProperties();
974 return Window::GetText();
975}
976
977bool DockingWindow::isLayoutEnabled() const
978{
979 //pre dtor called, and single child is a container => we're layout enabled
980 return mpImplData && ::isLayoutEnabled(this);
981}
982
983void DockingWindow::setOptimalLayoutSize()
984{
985 maLayoutIdle.Stop();
986
987 //resize DockingWindow to fit requisition on initial show
988 Size aSize = get_preferred_size();
989
990 Size aMax(bestmaxFrameSizeForScreenSize(GetDesktopRectPixel().GetSize()));
991
992 aSize.setWidth( std::min(aMax.Width(), aSize.Width()) );
993 aSize.setHeight( std::min(aMax.Height(), aSize.Height()) );
994
995 SetMinOutputSizePixel(aSize);
996 setPosSizeOnContainee();
997}
998
999void DockingWindow::setPosSizeOnContainee()
1000{
1001 Size aSize = GetOutputSizePixel();
1002
1003 // Don't make the border width accessible via get_border_width(),
1004 // otherwise the floating window will handle the border as well.
1005 sal_Int32 nBorderWidth = mpWindowImpl->mnBorderWidth;
1006
1007 aSize.AdjustWidth( -(2 * nBorderWidth) );
1008 aSize.AdjustHeight( -(2 * nBorderWidth) );
1009
1010 Window* pBox = GetWindow(GetWindowType::FirstChild);
1011 assert(pBox)(static_cast <bool> (pBox) ? void (0) : __assert_fail (
"pBox", "/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
, 1011, __extension__ __PRETTY_FUNCTION__))
;
1012 VclContainer::setLayoutAllocation(*pBox, Point(nBorderWidth, nBorderWidth), aSize);
1013}
1014
1015Size DockingWindow::GetOptimalSize() const
1016{
1017 if (!isLayoutEnabled())
1018 return Window::GetOptimalSize();
1019
1020 Size aSize = VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
1021
1022 // Don't make the border width accessible via get_border_width(),
1023 // otherwise the floating window will handle the border as well.
1024 sal_Int32 nBorderWidth = mpWindowImpl->mnBorderWidth;
1025
1026 aSize.AdjustHeight(2 * nBorderWidth );
1027 aSize.AdjustWidth(2 * nBorderWidth );
1028
1029 return aSize;
1030}
1031
1032void DockingWindow::queue_resize(StateChangedType eReason)
1033{
1034 bool bTriggerLayout = true;
1035 if (maLayoutIdle.IsActive() || mbIsCalculatingInitialLayoutSize)
1036 {
1037 bTriggerLayout = false;
1038 }
1039 if (!isLayoutEnabled())
1040 {
1041 bTriggerLayout = false;
1042 }
1043 if (bTriggerLayout)
1044 {
1045 InvalidateSizeCache();
1046 maLayoutIdle.Start();
1047 }
1048 vcl::Window::queue_resize(eReason);
1049}
1050
1051IMPL_LINK_NOARG(DockingWindow, ImplHandleLayoutTimerHdl, Timer*, void)void DockingWindow::LinkStubImplHandleLayoutTimerHdl(void * instance
, Timer* data) { return static_cast<DockingWindow *>(instance
)->ImplHandleLayoutTimerHdl(data); } void DockingWindow::ImplHandleLayoutTimerHdl
(__attribute__ ((unused)) Timer*)
1052{
1053 if (!isLayoutEnabled())
1054 {
1055 SAL_WARN_IF(GetWindow(GetWindowType::FirstChild), "vcl.layout", "DockingWindow has become non-layout because extra children have been added directly to it.")do { if (true && (GetWindow(GetWindowType::FirstChild
))) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "vcl.layout")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "DockingWindow has become non-layout because extra children have been added directly to it."
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "1055" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "DockingWindow has become non-layout because extra children have been added directly to it."
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "DockingWindow has become non-layout because extra children have been added directly to it."
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "1055" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "DockingWindow has become non-layout because extra children have been added directly to it."
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "1055" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "DockingWindow has become non-layout because extra children have been added directly to it."
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "DockingWindow has become non-layout because extra children have been added directly to it."
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl.layout"
), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockwin.cxx"
":" "1055" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1056 return;
1057 }
1058 setPosSizeOnContainee();
1059}
1060
1061/* 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);
2
Calling 'Reference::set'
11
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
2.1
'pBody' is null
2.1
'pBody' is null
2.1
'pBody' is null
2.1
'pBody' is null
)
3
Taking false branch
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
4
Assuming 'pOld' is non-null
5
Taking true branch
127 pOld->release();
6
Calling 'VclReferenceBase::release'
10
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)
7
Assuming the condition is true
8
Taking true branch
40 delete this;
9
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