File: | home/maarten/src/libreoffice/core/include/rtl/ref.hxx |
Warning: | line 192, column 9 Use of memory after it is freed |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <o3tl/deleter.hxx> | |||
23 | ||||
24 | #include <brdwin.hxx> | |||
25 | #include <svdata.hxx> | |||
26 | #include <window.h> | |||
27 | ||||
28 | #include <vcl/event.hxx> | |||
29 | #include <vcl/floatwin.hxx> | |||
30 | #include <vcl/dockwin.hxx> | |||
31 | #include <vcl/toolbox.hxx> | |||
32 | #include <vcl/svapp.hxx> | |||
33 | #include <vcl/timer.hxx> | |||
34 | #include <vcl/settings.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 | ||||
38 | namespace { | |||
39 | ||||
40 | class ImplDockFloatWin2 : public FloatingWindow | |||
41 | { | |||
42 | private: | |||
43 | ImplDockingWindowWrapper* mpDockWin; | |||
44 | sal_uInt64 mnLastTicks; | |||
45 | Timer m_aDockTimer; | |||
46 | Timer m_aEndDockTimer; | |||
47 | Point maDockPos; | |||
48 | tools::Rectangle maDockRect; | |||
49 | bool mbInMove; | |||
50 | ImplSVEvent * mnLastUserEvent; | |||
51 | ||||
52 | DECL_LINK(DockingHdl, void *, void)static void LinkStubDockingHdl(void *, void *); void DockingHdl (void *); | |||
53 | DECL_LINK(DockTimerHdl, Timer *, void)static void LinkStubDockTimerHdl(void *, Timer *); void DockTimerHdl (Timer *); | |||
54 | DECL_LINK(EndDockTimerHdl, Timer *, void)static void LinkStubEndDockTimerHdl(void *, Timer *); void EndDockTimerHdl (Timer *); | |||
55 | public: | |||
56 | ImplDockFloatWin2( vcl::Window* pParent, WinBits nWinBits, | |||
57 | ImplDockingWindowWrapper* pDockingWin ); | |||
58 | virtual ~ImplDockFloatWin2() override; | |||
59 | virtual void dispose() override; | |||
60 | ||||
61 | virtual void Move() override; | |||
62 | virtual void Resize() override; | |||
63 | virtual void TitleButtonClick( TitleButton nButton ) override; | |||
64 | virtual void Resizing( Size& rSize ) override; | |||
65 | virtual bool Close() override; | |||
66 | }; | |||
67 | ||||
68 | } | |||
69 | ||||
70 | ImplDockFloatWin2::ImplDockFloatWin2( vcl::Window* pParent, WinBits nWinBits, | |||
71 | ImplDockingWindowWrapper* pDockingWin ) : | |||
72 | FloatingWindow( pParent, nWinBits ), | |||
73 | mpDockWin( pDockingWin ), | |||
74 | mnLastTicks( tools::Time::GetSystemTicks() ), | |||
75 | mbInMove( false ), | |||
76 | mnLastUserEvent( nullptr ) | |||
77 | { | |||
78 | // copy state of DockingWindow | |||
79 | if ( pDockingWin ) | |||
80 | { | |||
81 | SetSettings( pDockingWin->GetWindow()->GetSettings() ); | |||
82 | Enable( pDockingWin->GetWindow()->IsEnabled(), false ); | |||
83 | EnableInput( pDockingWin->GetWindow()->IsInputEnabled(), false ); | |||
84 | AlwaysEnableInput( pDockingWin->GetWindow()->IsAlwaysEnableInput(), false ); | |||
85 | EnableAlwaysOnTop( pDockingWin->GetWindow()->IsAlwaysOnTopEnabled() ); | |||
86 | SetActivateMode( pDockingWin->GetWindow()->GetActivateMode() ); | |||
87 | } | |||
88 | ||||
89 | SetBackground( GetSettings().GetStyleSettings().GetFaceColor() ); | |||
90 | ||||
91 | m_aDockTimer.SetInvokeHandler( LINK( this, ImplDockFloatWin2, DockTimerHdl )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockFloatWin2 *>(this), &ImplDockFloatWin2::LinkStubDockTimerHdl) ); | |||
92 | m_aDockTimer.SetPriority( TaskPriority::HIGH_IDLE ); | |||
93 | m_aDockTimer.SetTimeout( 50 ); | |||
94 | m_aDockTimer.SetDebugName( "vcl::ImplDockFloatWin2 m_aDockTimer" ); | |||
95 | ||||
96 | m_aEndDockTimer.SetInvokeHandler( LINK( this, ImplDockFloatWin2, EndDockTimerHdl )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockFloatWin2 *>(this), &ImplDockFloatWin2::LinkStubEndDockTimerHdl ) ); | |||
97 | m_aEndDockTimer.SetPriority( TaskPriority::HIGH_IDLE ); | |||
98 | m_aEndDockTimer.SetTimeout( 50 ); | |||
99 | m_aEndDockTimer.SetDebugName( "vcl::ImplDockFloatWin2 m_aEndDockTimer" ); | |||
100 | } | |||
101 | ||||
102 | ImplDockFloatWin2::~ImplDockFloatWin2() | |||
103 | { | |||
104 | disposeOnce(); | |||
105 | } | |||
106 | ||||
107 | void ImplDockFloatWin2::dispose() | |||
108 | { | |||
109 | if( mnLastUserEvent ) | |||
110 | Application::RemoveUserEvent( mnLastUserEvent ); | |||
111 | FloatingWindow::dispose(); | |||
112 | } | |||
113 | ||||
114 | IMPL_LINK_NOARG(ImplDockFloatWin2, DockTimerHdl, Timer *, void)void ImplDockFloatWin2::LinkStubDockTimerHdl(void * instance, Timer * data) { return static_cast<ImplDockFloatWin2 *> (instance)->DockTimerHdl(data); } void ImplDockFloatWin2:: DockTimerHdl(__attribute__ ((unused)) Timer *) | |||
115 | { | |||
116 | 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/dockmgr.cxx" ":" "116" ": "), ::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/dockmgr.cxx" ":" "116" ": "), 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/dockmgr.cxx" ":" "116" ": "), ::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/dockmgr.cxx" ":" "116" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
117 | ||||
118 | PointerState aState = GetPointerState(); | |||
119 | ||||
120 | if( aState.mnState & KEY_MOD1 ) | |||
121 | { | |||
122 | // i43499 CTRL disables docking now | |||
123 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->HideTracking(); | |||
124 | if( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) | |||
125 | m_aDockTimer.Start(); | |||
126 | } | |||
127 | else if( ! ( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) ) | |||
128 | { | |||
129 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->HideTracking(); | |||
130 | mpDockWin->EndDocking( maDockRect, false ); | |||
131 | } | |||
132 | else | |||
133 | { | |||
134 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Big | ShowTrackFlags::TrackWindow ); | |||
135 | m_aDockTimer.Start(); | |||
136 | } | |||
137 | } | |||
138 | ||||
139 | IMPL_LINK_NOARG(ImplDockFloatWin2, EndDockTimerHdl, Timer *, void)void ImplDockFloatWin2::LinkStubEndDockTimerHdl(void * instance , Timer * data) { return static_cast<ImplDockFloatWin2 *> (instance)->EndDockTimerHdl(data); } void ImplDockFloatWin2 ::EndDockTimerHdl(__attribute__ ((unused)) Timer *) | |||
140 | { | |||
141 | SAL_WARN_IF( !mpDockWin->IsFloatingMode(), "vcl", "enddocktimer 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 () << "enddocktimer called but not floating") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockmgr.cxx" ":" "141" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "enddocktimer called but not floating" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "enddocktimer called but not floating"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockmgr.cxx" ":" "141" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "enddocktimer called but not floating") == 1) { :: sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockmgr.cxx" ":" "141" ": "), ::sal::detail::unwrapStream( ::sal::detail:: StreamStart() << "enddocktimer called but not floating" ), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream << "enddocktimer called but not floating"; ::sal::detail ::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("vcl"), ("/home/maarten/src/libreoffice/core/vcl/source/window/dockmgr.cxx" ":" "141" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); | |||
142 | ||||
143 | PointerState aState = GetPointerState(); | |||
144 | if( ! ( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) ) | |||
145 | { | |||
146 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->HideTracking(); | |||
147 | mpDockWin->EndDocking( maDockRect, true ); | |||
148 | } | |||
149 | else | |||
150 | m_aEndDockTimer.Start(); | |||
151 | } | |||
152 | ||||
153 | IMPL_LINK_NOARG(ImplDockFloatWin2, DockingHdl, void*, void)void ImplDockFloatWin2::LinkStubDockingHdl(void * instance, void * data) { return static_cast<ImplDockFloatWin2 *>(instance )->DockingHdl(data); } void ImplDockFloatWin2::DockingHdl( __attribute__ ((unused)) void*) | |||
154 | { | |||
155 | // called during move of a floating window | |||
156 | mnLastUserEvent = nullptr; | |||
157 | ||||
158 | vcl::Window *pDockingArea = mpDockWin->GetWindow()->GetParent(); | |||
159 | PointerState aState = pDockingArea->GetPointerState(); | |||
160 | ||||
161 | bool bRealMove = true; | |||
162 | if( GetStyle() & WB_OWNERDRAWDECORATION ) | |||
163 | { | |||
164 | // for windows with ownerdraw decoration | |||
165 | // we allow docking only when the window was moved | |||
166 | // by dragging its caption | |||
167 | // and ignore move request due to resizing | |||
168 | vcl::Window *pBorder = GetWindow( GetWindowType::Border ); | |||
169 | if( pBorder != this ) | |||
170 | { | |||
171 | tools::Rectangle aBorderRect( Point(), pBorder->GetSizePixel() ); | |||
172 | sal_Int32 nLeft, nTop, nRight, nBottom; | |||
173 | GetBorder( nLeft, nTop, nRight, nBottom ); | |||
174 | // limit borderrect to the caption part only and without the resizing borders | |||
175 | aBorderRect.SetBottom( aBorderRect.Top() + nTop ); | |||
176 | aBorderRect.AdjustLeft(nLeft ); | |||
177 | aBorderRect.AdjustRight( -nRight ); | |||
178 | ||||
179 | PointerState aBorderState = pBorder->GetPointerState(); | |||
180 | bRealMove = aBorderRect.IsInside( aBorderState.maPos ); | |||
181 | } | |||
182 | } | |||
183 | ||||
184 | if( mpDockWin->GetWindow()->IsVisible() && | |||
185 | (tools::Time::GetSystemTicks() - mnLastTicks > 500) && | |||
186 | ( aState.mnState & ( MOUSE_LEFT(sal_uInt16(0x0001)) | MOUSE_MIDDLE(sal_uInt16(0x0002)) | MOUSE_RIGHT(sal_uInt16(0x0004)) ) ) && | |||
187 | !(aState.mnState & KEY_MOD1) && // i43499 CTRL disables docking now | |||
188 | bRealMove ) | |||
189 | { | |||
190 | maDockPos = pDockingArea->OutputToScreenPixel( pDockingArea->AbsoluteScreenToOutputPixel( OutputToAbsoluteScreenPixel( Point() ) ) ); | |||
191 | maDockRect = tools::Rectangle( maDockPos, mpDockWin->GetSizePixel() ); | |||
192 | ||||
193 | // mouse pos in screen pixels | |||
194 | Point aMousePos = pDockingArea->OutputToScreenPixel( aState.maPos ); | |||
195 | ||||
196 | if( ! mpDockWin->IsDocking() ) | |||
197 | mpDockWin->StartDocking( aMousePos, maDockRect ); | |||
198 | ||||
199 | bool bFloatMode = mpDockWin->Docking( aMousePos, maDockRect ); | |||
200 | ||||
201 | if( ! bFloatMode ) | |||
202 | { | |||
203 | // indicates that the window could be docked at maDockRect | |||
204 | maDockRect.SetPos( mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->ScreenToOutputPixel( | |||
205 | maDockRect.TopLeft() ) ); | |||
206 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->ShowTracking( maDockRect, ShowTrackFlags::Big | ShowTrackFlags::TrackWindow ); | |||
207 | m_aEndDockTimer.Stop(); | |||
208 | m_aDockTimer.Invoke(); | |||
209 | } | |||
210 | else | |||
211 | { | |||
212 | mpDockWin->GetWindow()->GetParent()->ImplGetFrameWindow()->HideTracking(); | |||
213 | m_aDockTimer.Stop(); | |||
214 | m_aEndDockTimer.Invoke(); | |||
215 | } | |||
216 | } | |||
217 | mbInMove = false; | |||
218 | } | |||
219 | ||||
220 | void ImplDockFloatWin2::Move() | |||
221 | { | |||
222 | if( mbInMove ) | |||
223 | return; | |||
224 | ||||
225 | mbInMove = true; | |||
226 | FloatingWindow::Move(); | |||
227 | mpDockWin->GetWindow()->Move(); | |||
228 | ||||
229 | /* | |||
230 | * note: the window should only dock if KEY_MOD1 is pressed | |||
231 | * and the user releases all mouse buttons. The real problem here | |||
232 | * is that we don't get mouse events (at least not on X) | |||
233 | * if the mouse is on the decoration. So we have to start an | |||
234 | * awkward timer based process that polls the modifier/buttons | |||
235 | * to see whether they are in the right condition shortly after the | |||
236 | * last Move message. | |||
237 | */ | |||
238 | if( ! mnLastUserEvent ) | |||
239 | mnLastUserEvent = Application::PostUserEvent( LINK( this, ImplDockFloatWin2, DockingHdl )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockFloatWin2 *>(this), &ImplDockFloatWin2::LinkStubDockingHdl), nullptr, true ); | |||
240 | } | |||
241 | ||||
242 | void ImplDockFloatWin2::Resize() | |||
243 | { | |||
244 | // forwarding of resize only required if we have no borderwindow ( GetWindow() then returns 'this' ) | |||
245 | if( GetWindow( GetWindowType::Border ) == this ) | |||
246 | { | |||
247 | FloatingWindow::Resize(); | |||
248 | Size aSize( GetSizePixel() ); | |||
249 | mpDockWin->GetWindow()->ImplPosSizeWindow( 0, 0, aSize.Width(), aSize.Height(), PosSizeFlags::PosSize ); // TODO: is this needed ??? | |||
250 | } | |||
251 | } | |||
252 | ||||
253 | void ImplDockFloatWin2::TitleButtonClick( TitleButton nButton ) | |||
254 | { | |||
255 | FloatingWindow::TitleButtonClick( nButton ); | |||
256 | mpDockWin->TitleButtonClick( nButton ); | |||
257 | } | |||
258 | ||||
259 | void ImplDockFloatWin2::Resizing( Size& rSize ) | |||
260 | { | |||
261 | FloatingWindow::Resizing( rSize ); | |||
262 | mpDockWin->Resizing( rSize ); | |||
263 | } | |||
264 | ||||
265 | bool ImplDockFloatWin2::Close() | |||
266 | { | |||
267 | return true; | |||
268 | } | |||
269 | ||||
270 | DockingManager::DockingManager() | |||
271 | { | |||
272 | } | |||
273 | ||||
274 | DockingManager::~DockingManager() | |||
275 | { | |||
276 | } | |||
277 | ||||
278 | ImplDockingWindowWrapper* DockingManager::GetDockingWindowWrapper( const vcl::Window *pWindow ) | |||
279 | { | |||
280 | for( const auto& xWrapper : mvDockingWindows ) | |||
281 | { | |||
282 | if (xWrapper && xWrapper->mpDockingWindow == pWindow) | |||
283 | return xWrapper.get(); | |||
284 | } | |||
285 | return nullptr; | |||
286 | } | |||
287 | ||||
288 | bool DockingManager::IsDockable( const vcl::Window *pWindow ) | |||
289 | { | |||
290 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
291 | ||||
292 | /* | |||
293 | if( pWindow->HasDockingHandler() ) | |||
294 | return true; | |||
295 | */ | |||
296 | return (pWrapper != nullptr); | |||
297 | } | |||
298 | ||||
299 | bool DockingManager::IsFloating( const vcl::Window *pWindow ) | |||
300 | { | |||
301 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
302 | if( pWrapper ) | |||
303 | return pWrapper->IsFloatingMode(); | |||
304 | else | |||
305 | return false; | |||
306 | } | |||
307 | ||||
308 | bool DockingManager::IsLocked( const vcl::Window *pWindow ) | |||
309 | { | |||
310 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
311 | return pWrapper && pWrapper->IsLocked(); | |||
312 | } | |||
313 | ||||
314 | void DockingManager::Lock( const vcl::Window *pWindow ) | |||
315 | { | |||
316 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
317 | if( pWrapper ) | |||
318 | pWrapper->Lock(); | |||
319 | } | |||
320 | ||||
321 | void DockingManager::Unlock( const vcl::Window *pWindow ) | |||
322 | { | |||
323 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
324 | if( pWrapper ) | |||
325 | pWrapper->Unlock(); | |||
326 | } | |||
327 | ||||
328 | void DockingManager::SetFloatingMode( const vcl::Window *pWindow, bool bFloating ) | |||
329 | { | |||
330 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
331 | if( pWrapper ) | |||
332 | pWrapper->SetFloatingMode( bFloating ); | |||
333 | } | |||
334 | ||||
335 | void DockingManager::StartPopupMode( const vcl::Window *pWindow, const tools::Rectangle& rRect, FloatWinPopupFlags nFlags ) | |||
336 | { | |||
337 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
338 | if( pWrapper ) | |||
339 | pWrapper->StartPopupMode( rRect, nFlags ); | |||
340 | } | |||
341 | ||||
342 | void DockingManager::StartPopupMode( ToolBox *pParentToolBox, const vcl::Window *pWindow, FloatWinPopupFlags nFlags ) | |||
343 | { | |||
344 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
345 | if( pWrapper ) | |||
346 | pWrapper->StartPopupMode( pParentToolBox, nFlags ); | |||
347 | } | |||
348 | ||||
349 | void DockingManager::StartPopupMode( ToolBox *pParentToolBox, const vcl::Window *pWindow ) | |||
350 | { | |||
351 | StartPopupMode( pParentToolBox, pWindow, FloatWinPopupFlags::AllowTearOff | | |||
352 | FloatWinPopupFlags::AllMouseButtonClose | | |||
353 | FloatWinPopupFlags::NoMouseUpClose ); | |||
354 | } | |||
355 | ||||
356 | bool DockingManager::IsInPopupMode( const vcl::Window *pWindow ) | |||
357 | { | |||
358 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
359 | return pWrapper && pWrapper->IsInPopupMode(); | |||
360 | } | |||
361 | ||||
362 | void DockingManager::EndPopupMode( const vcl::Window *pWin ) | |||
363 | { | |||
364 | ImplDockingWindowWrapper *pWrapper = GetDockingWindowWrapper( pWin ); | |||
365 | if( pWrapper && pWrapper->GetFloatingWindow() && pWrapper->GetFloatingWindow()->IsInPopupMode() ) | |||
366 | pWrapper->GetFloatingWindow()->EndPopupMode(); | |||
367 | } | |||
368 | ||||
369 | void DockingManager::SetPopupModeEndHdl( const vcl::Window *pWindow, const Link<FloatingWindow*,void>& rLink ) | |||
370 | { | |||
371 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
372 | if( pWrapper ) | |||
373 | pWrapper->SetPopupModeEndHdl(rLink); | |||
374 | } | |||
375 | ||||
376 | void DockingManager::AddWindow( const vcl::Window *pWindow ) | |||
377 | { | |||
378 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
379 | if( pWrapper ) | |||
380 | return; | |||
381 | mvDockingWindows.emplace_back( new ImplDockingWindowWrapper( pWindow ) ); | |||
382 | } | |||
383 | ||||
384 | void DockingManager::RemoveWindow( const vcl::Window *pWindow ) | |||
385 | { | |||
386 | for( auto it = mvDockingWindows.begin(); it != mvDockingWindows.end(); ++it ) | |||
387 | { | |||
388 | const auto& xWrapper = *it; | |||
389 | if (xWrapper && xWrapper->mpDockingWindow == pWindow) | |||
390 | { | |||
391 | mvDockingWindows.erase( it ); | |||
392 | break; | |||
393 | } | |||
394 | } | |||
395 | } | |||
396 | ||||
397 | void DockingManager::SetPosSizePixel( vcl::Window const *pWindow, long nX, long nY, | |||
398 | long nWidth, long nHeight, | |||
399 | PosSizeFlags nFlags ) | |||
400 | { | |||
401 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
402 | if( pWrapper ) | |||
403 | pWrapper->setPosSizePixel( nX, nY, nWidth, nHeight, nFlags ); | |||
404 | } | |||
405 | ||||
406 | tools::Rectangle DockingManager::GetPosSizePixel( const vcl::Window *pWindow ) | |||
407 | { | |||
408 | tools::Rectangle aRect; | |||
409 | ImplDockingWindowWrapper* pWrapper = GetDockingWindowWrapper( pWindow ); | |||
410 | if( pWrapper ) | |||
411 | aRect = tools::Rectangle( pWrapper->GetPosPixel(), pWrapper->GetSizePixel() ); | |||
412 | ||||
413 | return aRect; | |||
414 | } | |||
415 | ||||
416 | class ImplPopupFloatWin : public FloatingWindow | |||
417 | { | |||
418 | private: | |||
419 | bool mbToolBox; | |||
420 | ||||
421 | public: | |||
422 | ImplPopupFloatWin( vcl::Window* pParent, bool bToolBox ); | |||
423 | virtual ~ImplPopupFloatWin() override; | |||
424 | virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible() override; | |||
425 | }; | |||
426 | ||||
427 | ImplPopupFloatWin::ImplPopupFloatWin( vcl::Window* pParent, bool bToolBox ) : | |||
428 | FloatingWindow( pParent, bToolBox ? WB_BORDER | WB_POPUP | WB_SYSTEMWINDOW | WB_NOSHADOW : WB_STDPOPUP ), | |||
429 | mbToolBox( bToolBox ) | |||
430 | { | |||
431 | if ( bToolBox ) | |||
432 | { | |||
433 | // indicate window type, required for accessibility | |||
434 | // which should not see this window as a toplevel window | |||
435 | mpWindowImpl->mbToolbarFloatingWindow = true; | |||
436 | } | |||
437 | } | |||
438 | ||||
439 | ImplPopupFloatWin::~ImplPopupFloatWin() | |||
440 | { | |||
441 | disposeOnce(); | |||
442 | } | |||
443 | ||||
444 | css::uno::Reference< css::accessibility::XAccessible > ImplPopupFloatWin::CreateAccessible() | |||
445 | { | |||
446 | if ( !mbToolBox ) | |||
447 | return FloatingWindow::CreateAccessible(); | |||
448 | ||||
449 | // switch off direct accessibility support for this window | |||
450 | ||||
451 | // this is to avoid appearance of this window as standalone window in the accessibility hierarchy | |||
452 | // as this window is only used as a helper for subtoolbars that are not teared-off, the parent toolbar | |||
453 | // has to provide accessibility support (as implemented in the toolkit) | |||
454 | // so the contained toolbar should appear as child of the corresponding toolbar item of the parent toolbar | |||
455 | return css::uno::Reference< css::accessibility::XAccessible >(); | |||
456 | } | |||
457 | ||||
458 | ImplDockingWindowWrapper::ImplDockingWindowWrapper( const vcl::Window *pWindow ) | |||
459 | : mpDockingWindow(const_cast<vcl::Window*>(pWindow)) | |||
460 | , mpFloatWin(nullptr) | |||
461 | , mpOldBorderWin(nullptr) | |||
462 | , mpParent(pWindow->GetParent()) | |||
463 | , maMaxOutSize( SHRT_MAX32767, SHRT_MAX32767 ) | |||
464 | , mnTrackX(0) | |||
465 | , mnTrackY(0) | |||
466 | , mnTrackWidth(0) | |||
467 | , mnTrackHeight(0) | |||
468 | , mnDockLeft(0) | |||
469 | , mnDockTop(0) | |||
470 | , mnDockRight(0) | |||
471 | , mnDockBottom(0) | |||
472 | , mnFloatBits(WB_BORDER | WB_CLOSEABLE | WB_SIZEABLE | (pWindow->GetStyle() & DOCKWIN_FLOATSTYLES(WB_SIZEABLE | WB_MOVEABLE | WB_CLOSEABLE | WB_STANDALONE | WB_ROLLABLE ))) | |||
473 | , mbDockCanceled(false) | |||
474 | , mbDocking(false) | |||
475 | , mbLastFloatMode(false) | |||
476 | , mbRollUp(false) | |||
477 | , mbDockBtn(false) | |||
478 | , mbHideBtn(false) | |||
479 | // must be enabled in Window::Notify to prevent permanent docking during mouse move | |||
480 | , mbStartDockingEnabled(false) | |||
481 | , mbLocked(false) | |||
482 | { | |||
483 | assert(mpDockingWindow)(static_cast <bool> (mpDockingWindow) ? void (0) : __assert_fail ("mpDockingWindow", "/home/maarten/src/libreoffice/core/vcl/source/window/dockmgr.cxx" , 483, __extension__ __PRETTY_FUNCTION__)); | |||
484 | DockingWindow *pDockWin = dynamic_cast< DockingWindow* > ( mpDockingWindow.get() ); | |||
485 | if( pDockWin ) | |||
486 | mnFloatBits = pDockWin->GetFloatStyle(); | |||
487 | } | |||
488 | ||||
489 | ImplDockingWindowWrapper::~ImplDockingWindowWrapper() | |||
490 | { | |||
491 | if ( IsFloatingMode() ) | |||
492 | { | |||
493 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
494 | SetFloatingMode(false); | |||
495 | } | |||
496 | } | |||
497 | ||||
498 | void ImplDockingWindowWrapper::ImplStartDocking( const Point& rPos ) | |||
499 | { | |||
500 | if( !mbStartDockingEnabled ) | |||
501 | return; | |||
502 | ||||
503 | maMouseOff = rPos; | |||
504 | mbDocking = true; | |||
505 | mbLastFloatMode = IsFloatingMode(); | |||
506 | ||||
507 | // calculate FloatingBorder | |||
508 | VclPtr<FloatingWindow> pWin; | |||
509 | if ( mpFloatWin ) | |||
510 | pWin = mpFloatWin; | |||
511 | else | |||
512 | pWin = VclPtr<ImplDockFloatWin2>::Create( mpParent, mnFloatBits, nullptr ); | |||
513 | pWin->GetBorder( mnDockLeft, mnDockTop, mnDockRight, mnDockBottom ); | |||
514 | if ( !mpFloatWin ) | |||
515 | pWin.disposeAndClear(); | |||
516 | ||||
517 | Point aPos = GetWindow()->ImplOutputToFrame( Point() ); | |||
518 | Size aSize = GetWindow()->GetOutputSizePixel(); | |||
519 | mnTrackX = aPos.X(); | |||
520 | mnTrackY = aPos.Y(); | |||
521 | mnTrackWidth = aSize.Width(); | |||
522 | mnTrackHeight = aSize.Height(); | |||
523 | ||||
524 | if ( mbLastFloatMode ) | |||
525 | { | |||
526 | maMouseOff.AdjustX(mnDockLeft ); | |||
527 | maMouseOff.AdjustY(mnDockTop ); | |||
528 | mnTrackX -= mnDockLeft; | |||
529 | mnTrackY -= mnDockTop; | |||
530 | mnTrackWidth += mnDockLeft+mnDockRight; | |||
531 | mnTrackHeight += mnDockTop+mnDockBottom; | |||
532 | } | |||
533 | ||||
534 | vcl::Window *pDockingArea = GetWindow()->GetParent(); | |||
535 | vcl::Window::PointerState aState = pDockingArea->GetPointerState(); | |||
536 | ||||
537 | // mouse pos in screen pixels | |||
538 | Point aMousePos = pDockingArea->OutputToScreenPixel( aState.maPos ); | |||
539 | Point aDockPos = pDockingArea->AbsoluteScreenToOutputPixel( GetWindow()->OutputToAbsoluteScreenPixel( GetWindow()->GetPosPixel() ) ); | |||
540 | tools::Rectangle aDockRect( aDockPos, GetWindow()->GetSizePixel() ); | |||
541 | StartDocking( aMousePos, aDockRect ); | |||
542 | ||||
543 | GetWindow()->ImplUpdateAll(); | |||
544 | GetWindow()->ImplGetFrameWindow()->ImplUpdateAll(); | |||
545 | ||||
546 | GetWindow()->StartTracking( StartTrackingFlags::KeyMod ); | |||
547 | } | |||
548 | ||||
549 | void ImplDockingWindowWrapper::Tracking( const TrackingEvent& rTEvt ) | |||
550 | { | |||
551 | // used during docking of a currently docked window | |||
552 | if ( !mbDocking ) | |||
553 | return; | |||
554 | ||||
555 | if ( rTEvt.IsTrackingEnded() ) | |||
556 | { | |||
557 | mbDocking = false; | |||
558 | GetWindow()->HideTracking(); | |||
559 | if ( rTEvt.IsTrackingCanceled() ) | |||
560 | { | |||
561 | mbDockCanceled = true; | |||
562 | EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode ); | |||
563 | mbDockCanceled = false; | |||
564 | } | |||
565 | else | |||
566 | EndDocking( tools::Rectangle( Point( mnTrackX, mnTrackY ), Size( mnTrackWidth, mnTrackHeight ) ), mbLastFloatMode ); | |||
567 | } | |||
568 | // Docking only upon non-synthetic MouseEvents | |||
569 | else if ( !rTEvt.GetMouseEvent().IsSynthetic() || rTEvt.GetMouseEvent().IsModifierChanged() ) | |||
570 | { | |||
571 | Point aMousePos = rTEvt.GetMouseEvent().GetPosPixel(); | |||
572 | Point aFrameMousePos = GetWindow()->ImplOutputToFrame( aMousePos ); | |||
573 | Size aFrameSize = GetWindow()->ImplGetFrameWindow()->GetOutputSizePixel(); | |||
574 | if ( aFrameMousePos.X() < 0 ) | |||
575 | aFrameMousePos.setX( 0 ); | |||
576 | if ( aFrameMousePos.Y() < 0 ) | |||
577 | aFrameMousePos.setY( 0 ); | |||
578 | if ( aFrameMousePos.X() > aFrameSize.Width()-1 ) | |||
579 | aFrameMousePos.setX( aFrameSize.Width()-1 ); | |||
580 | if ( aFrameMousePos.Y() > aFrameSize.Height()-1 ) | |||
581 | aFrameMousePos.setY( aFrameSize.Height()-1 ); | |||
582 | aMousePos = GetWindow()->ImplFrameToOutput( aFrameMousePos ); | |||
583 | aMousePos.AdjustX( -(maMouseOff.X()) ); | |||
584 | aMousePos.AdjustY( -(maMouseOff.Y()) ); | |||
585 | Point aPos = GetWindow()->ImplOutputToFrame( aMousePos ); | |||
586 | tools::Rectangle aTrackRect( aPos, Size( mnTrackWidth, mnTrackHeight ) ); | |||
587 | tools::Rectangle aCompRect = aTrackRect; | |||
588 | aPos.AdjustX(maMouseOff.X() ); | |||
589 | aPos.AdjustY(maMouseOff.Y() ); | |||
590 | ||||
591 | bool bFloatMode = Docking( aPos, aTrackRect ); | |||
592 | ||||
593 | if ( mbLastFloatMode != bFloatMode ) | |||
594 | { | |||
595 | if ( bFloatMode ) | |||
596 | { | |||
597 | aTrackRect.AdjustLeft( -mnDockLeft ); | |||
598 | aTrackRect.AdjustTop( -mnDockTop ); | |||
599 | aTrackRect.AdjustRight(mnDockRight ); | |||
600 | aTrackRect.AdjustBottom(mnDockBottom ); | |||
601 | } | |||
602 | else | |||
603 | { | |||
604 | if ( aCompRect == aTrackRect ) | |||
605 | { | |||
606 | aTrackRect.AdjustLeft(mnDockLeft ); | |||
607 | aTrackRect.AdjustTop(mnDockTop ); | |||
608 | aTrackRect.AdjustRight( -mnDockRight ); | |||
609 | aTrackRect.AdjustBottom( -mnDockBottom ); | |||
610 | } | |||
611 | } | |||
612 | mbLastFloatMode = bFloatMode; | |||
613 | } | |||
614 | ||||
615 | ShowTrackFlags nTrackStyle; | |||
616 | if ( bFloatMode ) | |||
617 | nTrackStyle = ShowTrackFlags::Object; | |||
618 | else | |||
619 | nTrackStyle = ShowTrackFlags::Big; | |||
620 | tools::Rectangle aShowTrackRect = aTrackRect; | |||
621 | aShowTrackRect.SetPos( GetWindow()->ImplFrameToOutput( aShowTrackRect.TopLeft() ) ); | |||
622 | ||||
623 | GetWindow()->ShowTracking( aShowTrackRect, nTrackStyle ); | |||
624 | ||||
625 | // calculate mouse offset again, as the rectangle was changed | |||
626 | maMouseOff.setX( aPos.X() - aTrackRect.Left() ); | |||
627 | maMouseOff.setY( aPos.Y() - aTrackRect.Top() ); | |||
628 | ||||
629 | mnTrackX = aTrackRect.Left(); | |||
630 | mnTrackY = aTrackRect.Top(); | |||
631 | mnTrackWidth = aTrackRect.GetWidth(); | |||
632 | mnTrackHeight = aTrackRect.GetHeight(); | |||
633 | } | |||
634 | } | |||
635 | ||||
636 | void ImplDockingWindowWrapper::StartDocking( const Point& rPoint, tools::Rectangle const & rRect ) | |||
637 | { | |||
638 | DockingData data( rPoint, rRect, IsFloatingMode() ); | |||
639 | ||||
640 | GetWindow()->CallEventListeners( VclEventId::WindowStartDocking, &data ); | |||
641 | mbDocking = true; | |||
642 | } | |||
643 | ||||
644 | bool ImplDockingWindowWrapper::Docking( const Point& rPoint, tools::Rectangle& rRect ) | |||
645 | { | |||
646 | DockingData data( rPoint, rRect, IsFloatingMode() ); | |||
647 | ||||
648 | GetWindow()->CallEventListeners( VclEventId::WindowDocking, &data ); | |||
649 | rRect = data.maTrackRect; | |||
650 | return data.mbFloating; | |||
651 | } | |||
652 | ||||
653 | void ImplDockingWindowWrapper::EndDocking( const tools::Rectangle& rRect, bool bFloatMode ) | |||
654 | { | |||
655 | tools::Rectangle aRect( rRect ); | |||
656 | ||||
657 | bool bOrigDockCanceled = mbDockCanceled; | |||
658 | if (bFloatMode && !StyleSettings::GetDockingFloatsSupported()) | |||
659 | mbDockCanceled = true; | |||
660 | ||||
661 | if ( !IsDockingCanceled() ) | |||
662 | { | |||
663 | bool bShow = false; | |||
664 | if ( bFloatMode != IsFloatingMode() ) | |||
665 | { | |||
666 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
667 | SetFloatingMode( bFloatMode ); | |||
668 | bShow = true; | |||
669 | if ( bFloatMode ) | |||
670 | { | |||
671 | // #i44800# always use outputsize - as in all other places | |||
672 | mpFloatWin->SetOutputSizePixel( aRect.GetSize() ); | |||
673 | mpFloatWin->SetPosPixel( aRect.TopLeft() ); | |||
674 | } | |||
675 | } | |||
676 | if ( !bFloatMode ) | |||
677 | { | |||
678 | Point aPos = aRect.TopLeft(); | |||
679 | aPos = GetWindow()->GetParent()->ScreenToOutputPixel( aPos ); | |||
680 | GetWindow()->SetPosSizePixel( aPos, aRect.GetSize() ); | |||
681 | } | |||
682 | ||||
683 | if ( bShow ) | |||
684 | GetWindow()->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate ); | |||
685 | } | |||
686 | ||||
687 | EndDockingData data( aRect, IsFloatingMode(), IsDockingCanceled() ); | |||
688 | GetWindow()->CallEventListeners( VclEventId::WindowEndDocking, &data ); | |||
689 | ||||
690 | mbDocking = false; | |||
691 | ||||
692 | // must be enabled in Window::Notify to prevent permanent docking during mouse move | |||
693 | mbStartDockingEnabled = false; | |||
694 | ||||
695 | mbDockCanceled = bOrigDockCanceled; | |||
696 | } | |||
697 | ||||
698 | bool ImplDockingWindowWrapper::PrepareToggleFloatingMode() | |||
699 | { | |||
700 | bool bFloating = true; | |||
701 | GetWindow()->CallEventListeners( VclEventId::WindowPrepareToggleFloating, &bFloating ); | |||
702 | return bFloating; | |||
703 | } | |||
704 | ||||
705 | void ImplDockingWindowWrapper::ToggleFloatingMode() | |||
706 | { | |||
707 | // notify dockingwindow/toolbox | |||
708 | // note: this must be done *before* notifying the | |||
709 | // listeners to have the toolbox in the proper state | |||
710 | if( GetWindow()->IsDockingWindow() ) | |||
711 | static_cast<DockingWindow*>(GetWindow())->ToggleFloatingMode(); | |||
712 | ||||
713 | // now notify listeners | |||
714 | GetWindow()->CallEventListeners( VclEventId::WindowToggleFloating ); | |||
715 | ||||
716 | // must be enabled in Window::Notify to prevent permanent docking during mouse move | |||
717 | mbStartDockingEnabled = false; | |||
718 | } | |||
719 | ||||
720 | void ImplDockingWindowWrapper::TitleButtonClick( TitleButton nType ) | |||
721 | { | |||
722 | if( nType == TitleButton::Menu ) | |||
723 | { | |||
724 | ToolBox *pToolBox = dynamic_cast< ToolBox* >( GetWindow() ); | |||
725 | if( pToolBox ) | |||
726 | { | |||
727 | pToolBox->ExecuteCustomMenu(); | |||
728 | } | |||
729 | } | |||
730 | if( nType == TitleButton::Docking ) | |||
731 | { | |||
732 | SetFloatingMode( !IsFloatingMode() ); | |||
733 | } | |||
734 | } | |||
735 | ||||
736 | void ImplDockingWindowWrapper::Resizing( Size& rSize ) | |||
737 | { | |||
738 | // TODO: add virtual Resizing() to class Window, so we can get rid of class DockingWindow | |||
739 | DockingWindow *pDockingWindow = dynamic_cast< DockingWindow* >( GetWindow() ); | |||
740 | if( pDockingWindow ) | |||
741 | pDockingWindow->Resizing( rSize ); | |||
742 | } | |||
743 | ||||
744 | void ImplDockingWindowWrapper::ShowTitleButton( TitleButton nButton, bool bVisible ) | |||
745 | { | |||
746 | if ( mpFloatWin ) | |||
747 | mpFloatWin->ShowTitleButton( nButton, bVisible ); | |||
748 | else | |||
749 | { | |||
750 | if ( nButton == TitleButton::Docking ) | |||
751 | mbDockBtn = bVisible; | |||
752 | else // if ( nButton == TitleButton::Hide ) | |||
753 | mbHideBtn = bVisible; | |||
754 | } | |||
755 | } | |||
756 | ||||
757 | void ImplDockingWindowWrapper::ImplPreparePopupMode() | |||
758 | { | |||
759 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
760 | ||||
761 | // prepare reparenting | |||
762 | vcl::Window* pRealParent = GetWindow()->GetWindow( GetWindowType::Parent ); | |||
763 | mpOldBorderWin = GetWindow()->GetWindow( GetWindowType::Border ); | |||
764 | if( mpOldBorderWin.get() == GetWindow() ) | |||
765 | mpOldBorderWin = nullptr; // no border window found | |||
766 | ||||
767 | // the new parent for popup mode | |||
768 | VclPtrInstance<ImplPopupFloatWin> pWin( mpParent, GetWindow()->GetType() == WindowType::TOOLBOX ); | |||
769 | pWin->SetPopupModeEndHdl( LINK( this, ImplDockingWindowWrapper, PopupModeEnd )::tools::detail::makeLink( ::tools::detail::castTo<ImplDockingWindowWrapper *>(this), &ImplDockingWindowWrapper::LinkStubPopupModeEnd ) ); | |||
770 | ||||
771 | // At least for DockingWindow, GetText() has a side effect of setting deferred | |||
772 | // properties. This must be done before setting the border window (see below), | |||
773 | // so that the border width will end up in mpWindowImpl->mnBorderWidth, not in | |||
774 | // the border window (See DockingWindow::setPosSizeOnContainee() and | |||
775 | // DockingWindow::GetOptimalSize()). | |||
776 | pWin->SetText( GetWindow()->GetText() ); | |||
777 | pWin->SetOutputSizePixel( GetWindow()->GetSizePixel() ); | |||
778 | ||||
779 | GetWindow()->mpWindowImpl->mpBorderWindow = nullptr; | |||
780 | GetWindow()->mpWindowImpl->mnLeftBorder = 0; | |||
781 | GetWindow()->mpWindowImpl->mnTopBorder = 0; | |||
782 | GetWindow()->mpWindowImpl->mnRightBorder = 0; | |||
783 | GetWindow()->mpWindowImpl->mnBottomBorder = 0; | |||
784 | ||||
785 | // reparent borderwindow and window | |||
786 | if ( mpOldBorderWin ) | |||
787 | mpOldBorderWin->SetParent( pWin ); | |||
788 | GetWindow()->SetParent( pWin ); | |||
789 | ||||
790 | // correct border window pointers | |||
791 | GetWindow()->mpWindowImpl->mpBorderWindow = pWin; | |||
792 | pWin->mpWindowImpl->mpClientWindow = GetWindow(); | |||
793 | GetWindow()->mpWindowImpl->mpRealParent = pRealParent; | |||
794 | ||||
795 | // set mpFloatWin not until all window positioning is done !!! | |||
796 | // (SetPosPixel etc. check for valid mpFloatWin pointer) | |||
797 | mpFloatWin = pWin; | |||
798 | } | |||
799 | ||||
800 | void ImplDockingWindowWrapper::StartPopupMode( ToolBox *pParentToolBox, FloatWinPopupFlags nFlags ) | |||
801 | { | |||
802 | // do nothing if window is floating | |||
803 | if( IsFloatingMode() ) | |||
804 | return; | |||
805 | ||||
806 | ImplPreparePopupMode(); | |||
807 | ||||
808 | // don't allow tearoff, if globally disabled | |||
809 | if( !StyleSettings::GetDockingFloatsSupported() || | |||
810 | ( GetWindow()->GetType() == WindowType::TOOLBOX && ToolBox::AlwaysLocked() ) ) | |||
811 | nFlags &= ~FloatWinPopupFlags::AllowTearOff; | |||
812 | ||||
813 | // if the subtoolbar was opened via keyboard make sure that key events | |||
814 | // will go into subtoolbar | |||
815 | if( pParentToolBox->IsKeyEvent() ) | |||
816 | nFlags |= FloatWinPopupFlags::GrabFocus; | |||
817 | ||||
818 | mpFloatWin->StartPopupMode( pParentToolBox, nFlags ); | |||
819 | GetWindow()->Show(); | |||
820 | ||||
821 | if( pParentToolBox->IsKeyEvent() ) | |||
822 | { | |||
823 | // send HOME key to subtoolbar in order to select first item | |||
824 | KeyEvent aEvent( 0, vcl::KeyCode( KEY_HOME ) ); | |||
825 | GetWindow()->KeyInput(aEvent); | |||
826 | } | |||
827 | } | |||
828 | ||||
829 | void ImplDockingWindowWrapper::StartPopupMode( const tools::Rectangle& rRect, FloatWinPopupFlags nFlags ) | |||
830 | { | |||
831 | // do nothing if window is floating | |||
832 | if( IsFloatingMode() ) | |||
833 | return; | |||
834 | ||||
835 | ImplPreparePopupMode(); | |||
836 | mpFloatWin->StartPopupMode( rRect, nFlags ); | |||
837 | GetWindow()->Show(); | |||
838 | } | |||
839 | ||||
840 | IMPL_LINK_NOARG(ImplDockingWindowWrapper, PopupModeEnd, FloatingWindow*, void)void ImplDockingWindowWrapper::LinkStubPopupModeEnd(void * instance , FloatingWindow* data) { return static_cast<ImplDockingWindowWrapper *>(instance)->PopupModeEnd(data); } void ImplDockingWindowWrapper ::PopupModeEnd(__attribute__ ((unused)) FloatingWindow*) | |||
| ||||
841 | { | |||
842 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
843 | ||||
844 | // set parameter for handler before destroying floating window | |||
845 | EndPopupModeData aData( mpFloatWin->GetWindow( GetWindowType::Border )->GetPosPixel(), mpFloatWin->IsPopupModeTearOff() ); | |||
846 | ||||
847 | // before deleting change parent back, so we can delete the floating window alone | |||
848 | vcl::Window* pRealParent = GetWindow()->GetWindow( GetWindowType::Parent ); | |||
849 | GetWindow()->mpWindowImpl->mpBorderWindow = nullptr; | |||
850 | if ( mpOldBorderWin ) | |||
851 | { | |||
852 | GetWindow()->SetParent( mpOldBorderWin ); | |||
853 | static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( | |||
854 | GetWindow()->mpWindowImpl->mnLeftBorder, GetWindow()->mpWindowImpl->mnTopBorder, | |||
855 | GetWindow()->mpWindowImpl->mnRightBorder, GetWindow()->mpWindowImpl->mnBottomBorder ); | |||
856 | mpOldBorderWin->Resize(); | |||
857 | } | |||
858 | GetWindow()->mpWindowImpl->mpBorderWindow = mpOldBorderWin; | |||
859 | GetWindow()->SetParent( pRealParent ); | |||
860 | GetWindow()->mpWindowImpl->mpRealParent = pRealParent; | |||
861 | ||||
862 | maPopupModeEndHdl.Call(mpFloatWin); | |||
863 | mpFloatWin.disposeAndClear(); | |||
864 | ||||
865 | // call handler - which will destroy the window and thus the wrapper as well ! | |||
866 | GetWindow()->CallEventListeners( VclEventId::WindowEndPopupMode, &aData ); | |||
867 | } | |||
868 | ||||
869 | bool ImplDockingWindowWrapper::IsInPopupMode() const | |||
870 | { | |||
871 | if( GetFloatingWindow() ) | |||
872 | return GetFloatingWindow()->IsInPopupMode(); | |||
873 | else | |||
874 | return false; | |||
875 | } | |||
876 | ||||
877 | void ImplDockingWindowWrapper::SetFloatingMode( bool bFloatMode ) | |||
878 | { | |||
879 | // do nothing if window is docked and locked | |||
880 | if( !IsFloatingMode() && IsLocked() ) | |||
881 | return; | |||
882 | ||||
883 | if ( IsFloatingMode() == bFloatMode ) | |||
884 | return; | |||
885 | ||||
886 | if ( !PrepareToggleFloatingMode() ) | |||
887 | return; | |||
888 | ||||
889 | bool bVisible = GetWindow()->IsVisible(); | |||
890 | ||||
891 | if ( bFloatMode ) | |||
892 | { | |||
893 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
894 | ||||
895 | maDockPos = GetWindow()->GetPosPixel(); | |||
896 | ||||
897 | vcl::Window* pRealParent = GetWindow()->GetWindow( GetWindowType::Parent ); | |||
898 | mpOldBorderWin = GetWindow()->GetWindow( GetWindowType::Border ); | |||
899 | if( mpOldBorderWin == mpDockingWindow ) | |||
900 | mpOldBorderWin = nullptr; // no border window found | |||
901 | ||||
902 | VclPtrInstance<ImplDockFloatWin2> pWin( | |||
903 | mpParent, | |||
904 | mnFloatBits & ( WB_MOVEABLE | WB_SIZEABLE | WB_CLOSEABLE ) ? | |||
905 | mnFloatBits | WB_SYSTEMWINDOW | |||
906 | | WB_OWNERDRAWDECORATION | |||
907 | : mnFloatBits, | |||
908 | this ); | |||
909 | ||||
910 | // At least for DockingWindow, GetText() has a side effect of setting deferred | |||
911 | // properties. This must be done before setting the border window (see below), | |||
912 | // so that the border width will end up in mpWindowImpl->mnBorderWidth, not in | |||
913 | // the border window (See DockingWindow::setPosSizeOnContainee() and | |||
914 | // DockingWindow::GetOptimalSize()). | |||
915 | pWin->SetText( GetWindow()->GetText() ); | |||
916 | ||||
917 | GetWindow()->mpWindowImpl->mpBorderWindow = nullptr; | |||
918 | GetWindow()->mpWindowImpl->mnLeftBorder = 0; | |||
919 | GetWindow()->mpWindowImpl->mnTopBorder = 0; | |||
920 | GetWindow()->mpWindowImpl->mnRightBorder = 0; | |||
921 | GetWindow()->mpWindowImpl->mnBottomBorder = 0; | |||
922 | ||||
923 | // if the parent gets destroyed, we also have to reset the parent of the BorderWindow | |||
924 | if ( mpOldBorderWin ) | |||
925 | mpOldBorderWin->SetParent( pWin ); | |||
926 | GetWindow()->SetParent( pWin ); | |||
927 | pWin->SetPosPixel( Point() ); | |||
928 | ||||
929 | GetWindow()->mpWindowImpl->mpBorderWindow = pWin; | |||
930 | pWin->mpWindowImpl->mpClientWindow = mpDockingWindow; | |||
931 | GetWindow()->mpWindowImpl->mpRealParent = pRealParent; | |||
932 | ||||
933 | pWin->SetOutputSizePixel( GetWindow()->GetSizePixel() ); | |||
934 | pWin->SetPosPixel( maFloatPos ); | |||
935 | // pass on DockingData to FloatingWindow | |||
936 | pWin->ShowTitleButton( TitleButton::Docking, mbDockBtn ); | |||
937 | pWin->ShowTitleButton( TitleButton::Hide, mbHideBtn ); | |||
938 | if ( mbRollUp ) | |||
939 | pWin->RollUp(); | |||
940 | else | |||
941 | pWin->RollDown(); | |||
942 | pWin->SetRollUpOutputSizePixel( maRollUpOutSize ); | |||
943 | pWin->SetMinOutputSizePixel( maMinOutSize ); | |||
944 | pWin->SetMaxOutputSizePixel( maMaxOutSize ); | |||
945 | ||||
946 | mpFloatWin = pWin; | |||
947 | ||||
948 | if ( bVisible ) | |||
949 | GetWindow()->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate ); | |||
950 | ||||
951 | ToggleFloatingMode(); | |||
952 | } | |||
953 | else | |||
954 | { | |||
955 | GetWindow()->Show( false, ShowFlags::NoFocusChange ); | |||
956 | ||||
957 | // store FloatingData in FloatingWindow | |||
958 | maFloatPos = mpFloatWin->GetPosPixel(); | |||
959 | mbDockBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Docking ); | |||
960 | mbHideBtn = mpFloatWin->IsTitleButtonVisible( TitleButton::Hide ); | |||
961 | mbRollUp = mpFloatWin->IsRollUp(); | |||
962 | maRollUpOutSize = mpFloatWin->GetRollUpOutputSizePixel(); | |||
963 | maMinOutSize = mpFloatWin->GetMinOutputSizePixel(); | |||
964 | maMaxOutSize = mpFloatWin->GetMaxOutputSizePixel(); | |||
965 | ||||
966 | vcl::Window* pRealParent = GetWindow()->GetWindow( GetWindowType::Parent ); //mpWindowImpl->mpRealParent; | |||
967 | GetWindow()->mpWindowImpl->mpBorderWindow = nullptr; | |||
968 | if ( mpOldBorderWin ) | |||
969 | { | |||
970 | GetWindow()->SetParent( mpOldBorderWin ); | |||
971 | static_cast<ImplBorderWindow*>(mpOldBorderWin.get())->GetBorder( | |||
972 | GetWindow()->mpWindowImpl->mnLeftBorder, GetWindow()->mpWindowImpl->mnTopBorder, | |||
973 | GetWindow()->mpWindowImpl->mnRightBorder, GetWindow()->mpWindowImpl->mnBottomBorder ); | |||
974 | mpOldBorderWin->Resize(); | |||
975 | } | |||
976 | GetWindow()->mpWindowImpl->mpBorderWindow = mpOldBorderWin; | |||
977 | GetWindow()->SetParent( pRealParent ); | |||
978 | GetWindow()->mpWindowImpl->mpRealParent = pRealParent; | |||
979 | ||||
980 | mpFloatWin.disposeAndClear(); | |||
981 | GetWindow()->SetPosPixel( maDockPos ); | |||
982 | ||||
983 | if ( bVisible ) | |||
984 | GetWindow()->Show(); | |||
985 | ||||
986 | ToggleFloatingMode(); | |||
987 | ||||
988 | } | |||
989 | } | |||
990 | ||||
991 | void ImplDockingWindowWrapper::SetFloatStyle( WinBits nStyle ) | |||
992 | { | |||
993 | mnFloatBits = nStyle; | |||
994 | } | |||
995 | ||||
996 | ||||
997 | void ImplDockingWindowWrapper::setPosSizePixel( long nX, long nY, | |||
998 | long nWidth, long nHeight, | |||
999 | PosSizeFlags nFlags ) | |||
1000 | { | |||
1001 | if ( mpFloatWin ) | |||
1002 | mpFloatWin->setPosSizePixel( nX, nY, nWidth, nHeight, nFlags ); | |||
1003 | else | |||
1004 | GetWindow()->setPosSizePixel( nX, nY, nWidth, nHeight, nFlags ); | |||
1005 | } | |||
1006 | ||||
1007 | Point ImplDockingWindowWrapper::GetPosPixel() const | |||
1008 | { | |||
1009 | if ( mpFloatWin ) | |||
1010 | return mpFloatWin->GetPosPixel(); | |||
1011 | else | |||
1012 | return mpDockingWindow->GetPosPixel(); | |||
1013 | } | |||
1014 | ||||
1015 | Size ImplDockingWindowWrapper::GetSizePixel() const | |||
1016 | { | |||
1017 | if ( mpFloatWin ) | |||
1018 | return mpFloatWin->GetSizePixel(); | |||
1019 | else | |||
1020 | return mpDockingWindow->GetSizePixel(); | |||
1021 | } | |||
1022 | ||||
1023 | // old inlines from DockingWindow | |||
1024 | ||||
1025 | void ImplDockingWindowWrapper::SetMinOutputSizePixel( const Size& rSize ) | |||
1026 | { | |||
1027 | if ( mpFloatWin ) | |||
1028 | mpFloatWin->SetMinOutputSizePixel( rSize ); | |||
1029 | maMinOutSize = rSize; | |||
1030 | } | |||
1031 | ||||
1032 | void ImplDockingWindowWrapper::SetMaxOutputSizePixel( const Size& rSize ) | |||
1033 | { | |||
1034 | if ( mpFloatWin ) | |||
1035 | mpFloatWin->SetMaxOutputSizePixel( rSize ); | |||
1036 | maMaxOutSize = rSize; | |||
1037 | } | |||
1038 | ||||
1039 | bool ImplDockingWindowWrapper::IsFloatingMode() const | |||
1040 | { | |||
1041 | return (mpFloatWin != nullptr); | |||
1042 | } | |||
1043 | ||||
1044 | void ImplDockingWindowWrapper::SetDragArea( const tools::Rectangle& rRect ) | |||
1045 | { | |||
1046 | maDragArea = rRect; | |||
1047 | } | |||
1048 | ||||
1049 | ||||
1050 | void ImplDockingWindowWrapper::Lock() | |||
1051 | { | |||
1052 | mbLocked = true; | |||
1053 | // only toolbars support locking | |||
1054 | ToolBox *pToolBox = dynamic_cast< ToolBox * >( GetWindow() ); | |||
1055 | if( pToolBox ) | |||
1056 | pToolBox->Lock( mbLocked ); | |||
1057 | } | |||
1058 | ||||
1059 | void ImplDockingWindowWrapper::Unlock() | |||
1060 | { | |||
1061 | mbLocked = false; | |||
1062 | // only toolbars support locking | |||
1063 | ToolBox *pToolBox = dynamic_cast< ToolBox * >( GetWindow() ); | |||
1064 | if( pToolBox ) | |||
1065 | pToolBox->Lock( mbLocked ); | |||
1066 | } | |||
1067 | ||||
1068 | ||||
1069 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | |
36 | class VclReferenceBase; |
37 | |
38 | namespace vcl::detail { |
39 | |
40 | template<typename> |
41 | constexpr bool isIncompleteOrDerivedFromVclReferenceBase(...) { return true; } |
42 | |
43 | template<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 | */ |
56 | template <class reference_type> |
57 | class 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 | |
66 | public: |
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); |
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 | |
218 | template<typename T1, typename T2> |
219 | inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
220 | return p1.get() == p2.get(); |
221 | } |
222 | |
223 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2) |
224 | { |
225 | return p1.get() == p2; |
226 | } |
227 | |
228 | template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) { |
229 | return p1.get() == p2; |
230 | } |
231 | |
232 | template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2) |
233 | { |
234 | return p1 == p2.get(); |
235 | } |
236 | |
237 | template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) { |
238 | return p1 == p2.get(); |
239 | } |
240 | |
241 | template<typename T1, typename T2> |
242 | inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) { |
243 | return !(p1 == p2); |
244 | } |
245 | |
246 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2) |
247 | { |
248 | return !(p1 == p2); |
249 | } |
250 | |
251 | template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) { |
252 | return !(p1 == p2); |
253 | } |
254 | |
255 | template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2) |
256 | { |
257 | return !(p1 == p2); |
258 | } |
259 | |
260 | template<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 | */ |
274 | template <class reference_type> |
275 | class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type> |
276 | { |
277 | public: |
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 | |
290 | template <class reference_type> |
291 | class ScopedVclPtr : public VclPtr<reference_type> |
292 | { |
293 | public: |
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 | |
378 | private: |
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 | |
387 | protected: |
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 |
406 | template <class reference_type> |
407 | class SAL_WARN_UNUSED__attribute__((warn_unused)) ScopedVclPtrInstance final : public ScopedVclPtr<reference_type> |
408 | { |
409 | public: |
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 | |
421 | private: |
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: */ |
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 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
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) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody
| ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
| |||||||||
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 | ||||||||
277 | namespace 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 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct 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: */ |
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 | |
25 | class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase |
26 | { |
27 | mutable oslInterlockedCount mnRefCnt; |
28 | |
29 | template<typename T> friend class VclPtr; |
30 | |
31 | public: |
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) |
40 | delete this; |
41 | } |
42 | #ifdef DBG_UTIL |
43 | #ifndef _WIN32 |
44 | sal_Int32 getRefCount() const { return mnRefCnt; } |
45 | #endif |
46 | #endif |
47 | |
48 | |
49 | private: |
50 | VclReferenceBase(const VclReferenceBase&) = delete; |
51 | VclReferenceBase& operator=(const VclReferenceBase&) = delete; |
52 | |
53 | bool mbDisposed : 1; |
54 | |
55 | protected: |
56 | VclReferenceBase(); |
57 | protected: |
58 | virtual ~VclReferenceBase(); |
59 | |
60 | protected: |
61 | virtual void dispose(); |
62 | |
63 | public: |
64 | void disposeOnce(); |
65 | bool isDisposed() const { return mbDisposed; } |
66 | |
67 | }; |
68 | #endif |