Bug Summary

File:home/maarten/src/libreoffice/core/include/rtl/ref.hxx
Warning:line 192, column 9
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name slideshow.cxx -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/11.0.0 -isystem /usr/include/libxml2 -isystem /usr/include/dbus-1.0 -isystem /usr/lib64/dbus-1.0/include -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 SD_DLLIMPLEMENTATION -D SDUI_DLL_NAME="libsduilo.so" -D SYSTEM_LIBXML -D ENABLE_SDREMOTE -D ENABLE_SDREMOTE_BLUETOOTH -D EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/i18n -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/icu/source/common -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/external/bluez_bluetooth/inc -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/sd/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/inc -I /home/maarten/src/libreoffice/core/sd/source/ui/slidesorter/inc -I /home/maarten/src/libreoffice/core/workdir/SdiTarget/sd/sdi -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/oox/generated -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -I /usr/include/glib-2.0 -I /usr/lib64/glib-2.0/include -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/sd/source/ui/slideshow/slideshow.cxx

/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.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 <com/sun/star/beans/PropertyAttribute.hpp>
21#include <com/sun/star/drawing/framework/XControllerManager.hpp>
22#include <com/sun/star/frame/XDispatchProvider.hpp>
23#include <com/sun/star/util/URL.hpp>
24
25#include <cppuhelper/supportsservice.hxx>
26
27#include <sal/log.hxx>
28#include <vcl/svapp.hxx>
29#include <vcl/wrkwin.hxx>
30#include <svx/svdpool.hxx>
31#include <svx/svdlayer.hxx>
32#include <svl/itemprop.hxx>
33
34#include <sfx2/bindings.hxx>
35#include <sfx2/viewfrm.hxx>
36#include <sfx2/sfxsids.hrc>
37
38#include <framework/FrameworkHelper.hxx>
39#include <comphelper/extract.hxx>
40
41#include <FrameView.hxx>
42#include <createpresentation.hxx>
43#include <unomodel.hxx>
44#include <slideshow.hxx>
45#include "slideshowimpl.hxx"
46#include <sdattr.hrc>
47#include <sdmod.hxx>
48#include <FactoryIds.hxx>
49#include <DrawDocShell.hxx>
50#include <ViewShell.hxx>
51#include <ViewShellBase.hxx>
52#include "SlideShowRestarter.hxx"
53#include <DrawController.hxx>
54#include <PresentationViewShell.hxx>
55#include <customshowlist.hxx>
56#include <unopage.hxx>
57#include <sdpage.hxx>
58#include <cusshow.hxx>
59#include <optsitem.hxx>
60#include <strings.hrc>
61#include <sdresid.hxx>
62
63using ::com::sun::star::presentation::XSlideShowController;
64using ::sd::framework::FrameworkHelper;
65using ::com::sun::star::awt::XWindow;
66using namespace ::sd;
67using namespace ::cppu;
68using namespace ::com::sun::star;
69using namespace ::com::sun::star::uno;
70using namespace ::com::sun::star::drawing;
71using namespace ::com::sun::star::beans;
72using namespace ::com::sun::star::lang;
73using namespace ::com::sun::star::animations;
74using namespace ::com::sun::star::drawing::framework;
75
76namespace {
77 /** This local version of the work window overrides DataChanged() so that it
78 can restart the slide show when a display is added or removed.
79 */
80 class FullScreenWorkWindow : public WorkWindow
81 {
82 public:
83 FullScreenWorkWindow (
84 const ::rtl::Reference<SlideShow>& rpSlideShow,
85 ViewShellBase* pViewShellBase)
86 : WorkWindow(nullptr, WB_HIDE | WB_CLIPCHILDREN),
87 mpRestarter(std::make_shared<SlideShowRestarter>(rpSlideShow, pViewShellBase))
88 {}
89
90 void Restart(bool bForce)
91 {
92 mpRestarter->Restart(bForce);
93 }
94
95 virtual void DataChanged (const DataChangedEvent& rEvent) override
96 {
97 if (rEvent.GetType() == DataChangedEventType::DISPLAY)
98 Restart(false);
99 }
100
101 private:
102 ::std::shared_ptr<SlideShowRestarter> mpRestarter;
103 };
104}
105
106static const SfxItemPropertyMapEntry* ImplGetPresentationPropertyMap()
107{
108 // NOTE: First member must be sorted
109 static const SfxItemPropertyMapEntry aPresentationPropertyMap_Impl[] =
110 {
111 { u"AllowAnimations", ATTR_PRESENT_ANIMATION_ALLOWED27000 + 1234 + 6 + 1 + 12, cppu::UnoType<bool>::get(), 0, 0 },
112 { u"CustomShow", ATTR_PRESENT_CUSTOMSHOW27000 + 1234 + 6 + 1 + 1, ::cppu::UnoType<OUString>::get(), 0, 0 },
113 { u"Display", ATTR_PRESENT_DISPLAY27000 + 1234 + 6 + 1 + 15, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
114 { u"FirstPage", ATTR_PRESENT_DIANAME27000 + 1234 + 6 + 1 + 2, ::cppu::UnoType<OUString>::get(), 0, 0 },
115 { u"IsAlwaysOnTop", ATTR_PRESENT_ALWAYS_ON_TOP27000 + 1234 + 6 + 1 + 9, cppu::UnoType<bool>::get(), 0, 0 },
116 { u"IsAutomatic", ATTR_PRESENT_MANUEL27000 + 1234 + 6 + 1 + 4, cppu::UnoType<bool>::get(), 0, 0 },
117 { u"IsEndless", ATTR_PRESENT_ENDLESS27000 + 1234 + 6 + 1 + 3, cppu::UnoType<bool>::get(), 0, 0 },
118 { u"IsFullScreen", ATTR_PRESENT_FULLSCREEN27000 + 1234 + 6 + 1 + 10, cppu::UnoType<bool>::get(), 0, 0 },
119 { u"IsShowAll", ATTR_PRESENT_ALL27000 + 1234 + 6 + 1, cppu::UnoType<bool>::get(), 0, 0 },
120 { u"IsMouseVisible", ATTR_PRESENT_MOUSE27000 + 1234 + 6 + 1 + 5, cppu::UnoType<bool>::get(), 0, 0 },
121 { u"IsShowLogo", ATTR_PRESENT_SHOW_PAUSELOGO27000 + 1234 + 6 + 1 + 14, cppu::UnoType<bool>::get(), 0, 0 },
122 { u"IsTransitionOnClick", ATTR_PRESENT_CHANGE_PAGE27000 + 1234 + 6 + 1 + 8, cppu::UnoType<bool>::get(), 0, 0 },
123 { u"Pause", ATTR_PRESENT_PAUSE_TIMEOUT27000 + 1234 + 6 + 1 + 13, ::cppu::UnoType<sal_Int32>::get(), 0, 0 },
124 { u"StartWithNavigator", ATTR_PRESENT_NAVIGATOR27000 + 1234 + 6 + 1 + 7, cppu::UnoType<bool>::get(), 0, 0 },
125 { u"UsePen", ATTR_PRESENT_PEN27000 + 1234 + 6 + 1 + 6, cppu::UnoType<bool>::get(), 0, 0 },
126 { u"", 0, css::uno::Type(), 0, 0 }
127 };
128
129 return aPresentationPropertyMap_Impl;
130}
131
132
133SlideShow::SlideShow( SdDrawDocument* pDoc )
134: SlideshowBase( m_aMutex )
135, maPropSet(ImplGetPresentationPropertyMap(), SdrObject::GetGlobalDrawObjectItemPool())
136, mbIsInStartup(false)
137, mpDoc( pDoc )
138, mpCurrentViewShellBase( nullptr )
139, mpFullScreenViewShellBase( nullptr )
140, mpFullScreenFrameView( nullptr )
141, mnInPlaceConfigEvent( nullptr )
142{
143}
144
145void SlideShow::ThrowIfDisposed() const
146{
147 if( mpDoc == nullptr )
148 throw DisposedException();
149}
150
151/// used by the model to create a slideshow for it
152rtl::Reference< SlideShow > SlideShow::Create( SdDrawDocument* pDoc )
153{
154 return new SlideShow( pDoc );
155}
156
157rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const * pDocument )
158{
159 rtl::Reference< SlideShow > xRet;
160
161 if( pDocument )
162 xRet = GetSlideShow( *pDocument );
163
164 return xRet;
165}
166
167rtl::Reference< SlideShow > SlideShow::GetSlideShow( SdDrawDocument const & rDocument )
168{
169 return rtl::Reference< SlideShow >(
170 dynamic_cast< SlideShow* >( rDocument.getPresentation().get() ) );
171}
172
173rtl::Reference< SlideShow > SlideShow::GetSlideShow( ViewShellBase const & rBase )
174{
175 return GetSlideShow( rBase.GetDocument() );
176}
177
178css::uno::Reference< css::presentation::XSlideShowController > SlideShow::GetSlideShowController(ViewShellBase const & rBase )
179{
180 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
181
182 Reference< XSlideShowController > xRet;
183 if( xSlideShow.is() )
184 xRet = xSlideShow->getController();
185
186 return xRet;
187}
188
189bool SlideShow::StartPreview( ViewShellBase const & rBase,
190 const css::uno::Reference< css::drawing::XDrawPage >& xDrawPage,
191 const css::uno::Reference< css::animations::XAnimationNode >& xAnimationNode )
192{
193 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
194 if( !xSlideShow.is() )
195 return false;
196
197 xSlideShow->startPreview( xDrawPage, xAnimationNode );
198 return true;
199}
200
201void SlideShow::Stop( ViewShellBase const & rBase )
202{
203 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
204 if( xSlideShow.is() )
205 xSlideShow->end();
206}
207
208bool SlideShow::IsRunning( ViewShellBase const & rBase )
209{
210 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rBase ) );
211 return xSlideShow.is() && xSlideShow->isRunning();
212}
213
214bool SlideShow::IsRunning( ViewShell& rViewShell )
215{
216 rtl::Reference< SlideShow > xSlideShow( GetSlideShow( rViewShell.GetViewShellBase() ) );
217 return xSlideShow.is() && xSlideShow->isRunning() && (xSlideShow->mxController->getViewShell() == &rViewShell);
218}
219
220void SlideShow::CreateController( ViewShell* pViewSh, ::sd::View* pView, vcl::Window* pParentWindow )
221{
222 SAL_INFO_IF( !mxController.is(), "sd.slideshow", "sd::SlideShow::CreateController(), clean up old controller first!" )do { if (true && (!mxController.is())) { switch (sal_detail_log_report
(::SAL_DETAIL_LOG_LEVEL_INFO, "sd.slideshow")) { case SAL_DETAIL_LOG_ACTION_IGNORE
: break; case SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail
::getResult( ::sal::detail::StreamStart() << "sd::SlideShow::CreateController(), clean up old controller first!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.slideshow"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "222" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "sd::SlideShow::CreateController(), clean up old controller first!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "sd::SlideShow::CreateController(), clean up old controller first!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.slideshow"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "222" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "sd::SlideShow::CreateController(), clean up old controller first!"
) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.slideshow"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "222" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "sd::SlideShow::CreateController(), clean up old controller first!"
), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "sd::SlideShow::CreateController(), clean up old controller first!"
; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd.slideshow"
), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "222" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
223
224 Reference< XPresentation2 > xThis( this );
225
226 rtl::Reference<SlideshowImpl> xController (
227 new SlideshowImpl(xThis, pViewSh, pView, mpDoc, pParentWindow));
228
229 // Reset mbIsInStartup. From here mxController.is() is used to prevent
230 // multiple slide show instances for one document.
231 mxController = xController;
232 mbIsInStartup = false;
233
234}
235
236// XServiceInfo
237OUString SAL_CALL SlideShow::getImplementationName( )
238{
239 return "com.sun.star.comp.sd.SlideShow";
240}
241
242sal_Bool SAL_CALL SlideShow::supportsService( const OUString& ServiceName )
243{
244 return cppu::supportsService( this, ServiceName );
245}
246
247Sequence< OUString > SAL_CALL SlideShow::getSupportedServiceNames( )
248{
249 return { "com.sun.star.presentation.Presentation" };
250}
251
252// XPropertySet
253Reference< XPropertySetInfo > SAL_CALL SlideShow::getPropertySetInfo()
254{
255 SolarMutexGuard aGuard;
256 static Reference< XPropertySetInfo > xInfo = maPropSet.getPropertySetInfo();
257 return xInfo;
258 }
259
260void SAL_CALL SlideShow::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
261{
262 SolarMutexGuard aGuard;
263 ThrowIfDisposed();
264
265 sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
266
267 const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(aPropertyName);
268
269 if( pEntry && ((pEntry->nFlags & PropertyAttribute::READONLY) != 0) )
270 throw PropertyVetoException();
271
272 bool bValuesChanged = false;
273 bool bIllegalArgument = true;
274
275 switch( pEntry ? pEntry->nWID : -1 )
276 {
277 case ATTR_PRESENT_ALL27000 + 1234 + 6 + 1:
278 {
279 bool bVal = false;
280
281 if( aValue >>= bVal )
282 {
283 bIllegalArgument = false;
284
285 if( rPresSettings.mbAll != bVal )
286 {
287 rPresSettings.mbAll = bVal;
288 bValuesChanged = true;
289 if( bVal )
290 rPresSettings.mbCustomShow = false;
291 }
292 }
293 break;
294 }
295 case ATTR_PRESENT_CHANGE_PAGE27000 + 1234 + 6 + 1 + 8:
296 {
297 bool bVal = false;
298
299 if( aValue >>= bVal )
300 {
301 bIllegalArgument = false;
302
303 if( bVal == rPresSettings.mbLockedPages )
304 {
305 bValuesChanged = true;
306 rPresSettings.mbLockedPages = !bVal;
307 }
308 }
309 break;
310 }
311
312 case ATTR_PRESENT_ANIMATION_ALLOWED27000 + 1234 + 6 + 1 + 12:
313 {
314 bool bVal = false;
315
316 if( aValue >>= bVal )
317 {
318 bIllegalArgument = false;
319
320 if(rPresSettings.mbAnimationAllowed != bVal)
321 {
322 bValuesChanged = true;
323 rPresSettings.mbAnimationAllowed = bVal;
324 }
325 }
326 break;
327 }
328 case ATTR_PRESENT_CUSTOMSHOW27000 + 1234 + 6 + 1 + 1:
329 {
330 OUString aShowName;
331 if( aValue >>= aShowName )
332 {
333 bIllegalArgument = false;
334
335 SdCustomShowList* pCustomShowList = mpDoc->GetCustomShowList();
336 if(pCustomShowList)
337 {
338 SdCustomShow* pCustomShow;
339 for( pCustomShow = pCustomShowList->First(); pCustomShow != nullptr; pCustomShow = pCustomShowList->Next() )
340 {
341 if( pCustomShow->GetName() == aShowName )
342 break;
343 }
344
345 rPresSettings.mbCustomShow = true;
346 bValuesChanged = true;
347 }
348 }
349 break;
350 }
351 case ATTR_PRESENT_ENDLESS27000 + 1234 + 6 + 1 + 3:
352 {
353 bool bVal = false;
354
355 if( aValue >>= bVal )
356 {
357 bIllegalArgument = false;
358
359 if( rPresSettings.mbEndless != bVal)
360 {
361 bValuesChanged = true;
362 rPresSettings.mbEndless = bVal;
363 }
364 }
365 break;
366 }
367 case ATTR_PRESENT_FULLSCREEN27000 + 1234 + 6 + 1 + 10:
368 {
369 bool bVal = false;
370
371 if( aValue >>= bVal )
372 {
373 bIllegalArgument = false;
374 if( rPresSettings.mbFullScreen != bVal)
375 {
376 bValuesChanged = true;
377 rPresSettings.mbFullScreen = bVal;
378 }
379 }
380 break;
381 }
382 case ATTR_PRESENT_DIANAME27000 + 1234 + 6 + 1 + 2:
383 {
384 OUString aPresPage;
385 aValue >>= aPresPage;
386 bIllegalArgument = false;
387 if( (rPresSettings.maPresPage != aPresPage) || !rPresSettings.mbCustomShow || !rPresSettings.mbAll )
388 {
389 bValuesChanged = true;
390 rPresSettings.maPresPage = getUiNameFromPageApiNameImpl(aPresPage);
391 rPresSettings.mbCustomShow = false;
392 rPresSettings.mbAll = false;
393 }
394 break;
395 }
396 case ATTR_PRESENT_MANUEL27000 + 1234 + 6 + 1 + 4:
397 {
398 bool bVal = false;
399
400 if( aValue >>= bVal )
401 {
402 bIllegalArgument = false;
403
404 if( rPresSettings.mbManual != bVal)
405 {
406 bValuesChanged = true;
407 rPresSettings.mbManual = bVal;
408 }
409 }
410 break;
411 }
412 case ATTR_PRESENT_MOUSE27000 + 1234 + 6 + 1 + 5:
413 {
414 bool bVal = false;
415
416 if( aValue >>= bVal )
417 {
418 bIllegalArgument = false;
419 if( rPresSettings.mbMouseVisible != bVal)
420 {
421 bValuesChanged = true;
422 rPresSettings.mbMouseVisible = bVal;
423 }
424 }
425 break;
426 }
427 case ATTR_PRESENT_ALWAYS_ON_TOP27000 + 1234 + 6 + 1 + 9:
428 {
429 bool bVal = false;
430
431 if( aValue >>= bVal )
432 {
433 bIllegalArgument = false;
434
435 if( rPresSettings.mbAlwaysOnTop != bVal)
436 {
437 bValuesChanged = true;
438 rPresSettings.mbAlwaysOnTop = bVal;
439 }
440 }
441 break;
442 }
443 case ATTR_PRESENT_NAVIGATOR27000 + 1234 + 6 + 1 + 7:
444 bIllegalArgument = false;
445 //ignored, but exists in some older documents
446 break;
447 case ATTR_PRESENT_PEN27000 + 1234 + 6 + 1 + 6:
448 {
449 bool bVal = false;
450
451 if( aValue >>= bVal )
452 {
453 bIllegalArgument = false;
454
455 if(rPresSettings.mbMouseAsPen != bVal)
456 {
457 bValuesChanged = true;
458 rPresSettings.mbMouseAsPen = bVal;
459 }
460 }
461 break;
462 }
463 case ATTR_PRESENT_PAUSE_TIMEOUT27000 + 1234 + 6 + 1 + 13:
464 {
465 sal_Int32 nValue = 0;
466 if( (aValue >>= nValue) && (nValue >= 0) )
467 {
468 bIllegalArgument = false;
469 if( rPresSettings.mnPauseTimeout != nValue )
470 {
471 bValuesChanged = true;
472 rPresSettings.mnPauseTimeout = nValue;
473 }
474 }
475 break;
476 }
477 case ATTR_PRESENT_SHOW_PAUSELOGO27000 + 1234 + 6 + 1 + 14:
478 {
479 bool bVal = false;
480
481 if( aValue >>= bVal )
482 {
483 bIllegalArgument = false;
484
485 if( rPresSettings.mbShowPauseLogo != bVal )
486 {
487 bValuesChanged = true;
488 rPresSettings.mbShowPauseLogo = bVal;
489 }
490 }
491 break;
492 }
493 case ATTR_PRESENT_DISPLAY27000 + 1234 + 6 + 1 + 15:
494 {
495 sal_Int32 nDisplay = 0;
496 if( aValue >>= nDisplay )
497 {
498 bIllegalArgument = false;
499
500 SdOptions* pOptions = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule
::Draw)) )
->GetSdOptions(DocumentType::Impress);
501 pOptions->SetDisplay( nDisplay );
502
503 FullScreenWorkWindow *pWin = dynamic_cast<FullScreenWorkWindow *>(GetWorkWindow());
504 if( !pWin )
505 return;
506 pWin->Restart(true);
507 }
508 break;
509 }
510
511 default:
512 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
513 }
514
515 if( bIllegalArgument )
516 throw IllegalArgumentException();
517
518 if( bValuesChanged )
519 mpDoc->SetChanged();
520}
521
522Any SAL_CALL SlideShow::getPropertyValue( const OUString& PropertyName )
523{
524 SolarMutexGuard aGuard;
525 ThrowIfDisposed();
526
527 const sd::PresentationSettings& rPresSettings = mpDoc->getPresentationSettings();
528
529 const SfxItemPropertySimpleEntry* pEntry = maPropSet.getPropertyMapEntry(PropertyName);
530
531 switch( pEntry ? pEntry->nWID : -1 )
532 {
533 case ATTR_PRESENT_ALL27000 + 1234 + 6 + 1:
534 return Any( !rPresSettings.mbCustomShow && rPresSettings.mbAll );
535 case ATTR_PRESENT_CHANGE_PAGE27000 + 1234 + 6 + 1 + 8:
536 return Any( !rPresSettings.mbLockedPages );
537 case ATTR_PRESENT_ANIMATION_ALLOWED27000 + 1234 + 6 + 1 + 12:
538 return Any( rPresSettings.mbAnimationAllowed );
539 case ATTR_PRESENT_CUSTOMSHOW27000 + 1234 + 6 + 1 + 1:
540 {
541 SdCustomShowList* pList = mpDoc->GetCustomShowList();
542 SdCustomShow* pShow = (pList && rPresSettings.mbCustomShow) ? pList->GetCurObject() : nullptr;
543 OUString aShowName;
544
545 if(pShow)
546 aShowName = pShow->GetName();
547
548 return Any( aShowName );
549 }
550 case ATTR_PRESENT_ENDLESS27000 + 1234 + 6 + 1 + 3:
551 return Any( rPresSettings.mbEndless );
552 case ATTR_PRESENT_FULLSCREEN27000 + 1234 + 6 + 1 + 10:
553 return Any( rPresSettings.mbFullScreen );
554 case ATTR_PRESENT_DIANAME27000 + 1234 + 6 + 1 + 2:
555 {
556 OUString aSlideName;
557
558 if( !rPresSettings.mbCustomShow && !rPresSettings.mbAll )
559 aSlideName = getPageApiNameFromUiName( rPresSettings.maPresPage );
560
561 return Any( aSlideName );
562 }
563 case ATTR_PRESENT_MANUEL27000 + 1234 + 6 + 1 + 4:
564 return Any( rPresSettings.mbManual );
565 case ATTR_PRESENT_MOUSE27000 + 1234 + 6 + 1 + 5:
566 return Any( rPresSettings.mbMouseVisible );
567 case ATTR_PRESENT_ALWAYS_ON_TOP27000 + 1234 + 6 + 1 + 9:
568 return Any( rPresSettings.mbAlwaysOnTop );
569 case ATTR_PRESENT_NAVIGATOR27000 + 1234 + 6 + 1 + 7:
570 return Any( false );
571 case ATTR_PRESENT_PEN27000 + 1234 + 6 + 1 + 6:
572 return Any( rPresSettings.mbMouseAsPen );
573 case ATTR_PRESENT_PAUSE_TIMEOUT27000 + 1234 + 6 + 1 + 13:
574 return Any( rPresSettings.mnPauseTimeout );
575 case ATTR_PRESENT_SHOW_PAUSELOGO27000 + 1234 + 6 + 1 + 14:
576 return Any( rPresSettings.mbShowPauseLogo );
577 case ATTR_PRESENT_DISPLAY27000 + 1234 + 6 + 1 + 15:
578 {
579 SdOptions* pOptions = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule
::Draw)) )
->GetSdOptions(DocumentType::Impress);
580 return Any(pOptions->GetDisplay());
581 }
582
583 default:
584 throw UnknownPropertyException( OUString::number(pEntry ? pEntry->nWID : -1), static_cast<cppu::OWeakObject*>(this));
585 }
586}
587
588void SAL_CALL SlideShow::addPropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
589{
590}
591
592void SAL_CALL SlideShow::removePropertyChangeListener( const OUString& , const Reference< XPropertyChangeListener >& )
593{
594}
595
596void SAL_CALL SlideShow::addVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
597{
598}
599
600void SAL_CALL SlideShow::removeVetoableChangeListener( const OUString& , const Reference< XVetoableChangeListener >& )
601{
602}
603
604// XPresentation
605
606void SAL_CALL SlideShow::start()
607{
608 const Sequence< PropertyValue > aArguments;
609 startWithArguments( aArguments );
610}
611
612WorkWindow *SlideShow::GetWorkWindow()
613{
614 if( !mpFullScreenViewShellBase )
615 return nullptr;
616
617 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(mpFullScreenViewShellBase->GetMainViewShell().get());
618
619 if( !pShell || !pShell->GetViewFrame() )
620 return nullptr;
621
622 return dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
623}
624
625bool SlideShow::IsExitAfterPresenting() const
626{
627 SolarMutexGuard aGuard;
628 ThrowIfDisposed();
629 return mpDoc->IsExitAfterPresenting();
630}
631
632void SlideShow::SetExitAfterPresenting(bool bExit)
633{
634 SolarMutexGuard aGuard;
635 ThrowIfDisposed();
636 mpDoc->SetExitAfterPresenting(bExit);
637}
638
639void SAL_CALL SlideShow::end()
640{
641 SolarMutexGuard aGuard;
642
643 // The mbIsInStartup flag should have been reset during the start of the
644 // slide show. Reset it here just in case that something has horribly
645 // gone wrong.
646 assert(!mbIsInStartup)(static_cast <bool> (!mbIsInStartup) ? void (0) : __assert_fail
("!mbIsInStartup", "/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
, 646, __extension__ __PRETTY_FUNCTION__))
;
647
648 rtl::Reference< SlideshowImpl > xController( mxController );
649 if( !xController.is() )
650 return;
651
652 mxController.clear();
653
654 if( mpFullScreenFrameView )
655 {
656 delete mpFullScreenFrameView;
657 mpFullScreenFrameView = nullptr;
658 }
659
660 ViewShellBase* pFullScreenViewShellBase = mpFullScreenViewShellBase;
661 mpFullScreenViewShellBase = nullptr;
662
663 // dispose before fullscreen window changes screens
664 // (potentially). If this needs to be moved behind
665 // pWorkWindow->StartPresentationMode() again, read issue
666 // pWorkWindow->i94007 & implement the solution outlined
667 // there.
668 xController->dispose();
669
670 if( pFullScreenViewShellBase )
671 {
672 PresentationViewShell* pShell = dynamic_cast<PresentationViewShell*>(pFullScreenViewShellBase->GetMainViewShell().get());
673
674 if( pShell && pShell->GetViewFrame() )
675 {
676 WorkWindow* pWorkWindow = dynamic_cast<WorkWindow*>(pShell->GetViewFrame()->GetFrame().GetWindow().GetParent());
677 if( pWorkWindow )
678 {
679 pWorkWindow->StartPresentationMode( (mxController.is() && mxController->maPresSettings.mbAlwaysOnTop)
680 ? PresentationFlags::HideAllApps : PresentationFlags::NONE );
681 }
682 }
683 }
684
685 if( pFullScreenViewShellBase )
686 {
687 PresentationViewShell* pShell = nullptr;
688 {
689 // Get the shell pointer in its own scope to be sure that
690 // the shared_ptr to the shell is released before DoClose()
691 // is called.
692 ::std::shared_ptr<ViewShell> pSharedView (pFullScreenViewShellBase->GetMainViewShell());
693 pShell = dynamic_cast<PresentationViewShell*>(pSharedView.get());
694 }
695 if( pShell && pShell->GetViewFrame() )
696 pShell->GetViewFrame()->DoClose();
697 }
698 else if( mpCurrentViewShellBase )
699 {
700 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
701
702 if( pViewShell )
703 {
704 FrameView* pFrameView = pViewShell->GetFrameView();
705
706 if( pFrameView && (pFrameView->GetPresentationViewShellId() != SID_VIEWSHELL0(5000 + 630)) )
707 {
708 ViewShell::ShellType ePreviousType (pFrameView->GetPreviousViewShellType());
709 pFrameView->SetPreviousViewShellType(ViewShell::ST_NONE);
710
711 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL0(5000 + 630));
712 pFrameView->SetPreviousViewShellType(pViewShell->GetShellType());
713
714 framework::FrameworkHelper::Instance(*mpCurrentViewShellBase)->RequestView(
715 framework::FrameworkHelper::GetViewURL(ePreviousType),
716 framework::FrameworkHelper::msCenterPaneURL);
717
718 pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true );
719 }
720 }
721 }
722
723 if( mpCurrentViewShellBase )
724 {
725 if (ViewShell* const pViewShell = mpCurrentViewShellBase->GetMainViewShell().get())
726 {
727 // invalidate the view shell so the presentation slot will be re-enabled
728 // and the rehearsing will be updated
729 pViewShell->Invalidate();
730
731 if( xController->meAnimationMode ==ANIMATIONMODE_SHOW )
732 {
733 // switch to the previously visible Slide
734 DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>( pViewShell );
735 if( pDrawViewShell )
736 pDrawViewShell->SwitchPage( static_cast<sal_uInt16>(xController->getRestoreSlide()) );
737 else
738 {
739 Reference<XDrawView> xDrawView (
740 Reference<XWeak>(&mpCurrentViewShellBase->GetDrawController()), UNO_QUERY);
741 if (xDrawView.is())
742 xDrawView->setCurrentPage(
743 Reference<XDrawPage>(
744 mpDoc->GetSdPage(xController->getRestoreSlide(), PageKind::Standard)->getUnoPage(),
745 UNO_QUERY));
746 }
747 }
748
749 if( pViewShell->GetDoc()->IsExitAfterPresenting() )
750 {
751 pViewShell->GetDoc()->SetExitAfterPresenting( false );
752
753 Reference<frame::XDispatchProvider> xProvider(pViewShell->GetViewShellBase().GetController()->getFrame(),
754 UNO_QUERY);
755 if( xProvider.is() )
756 {
757 util::URL aURL;
758 aURL.Complete = ".uno:CloseFrame";
759
760 uno::Reference< frame::XDispatch > xDispatch(
761 xProvider->queryDispatch(
762 aURL, OUString(), 0));
763 if( xDispatch.is() )
764 {
765 xDispatch->dispatch(aURL,
766 uno::Sequence< beans::PropertyValue >());
767 }
768 }
769 }
770
771 // In case mbMouseAsPen was set, a new layer DrawnInSlideshow might have been generated
772 // during slideshow, which is not known to FrameView yet.
773 if (any2bool(getPropertyValue("UsePen"))
774 && pViewShell->GetDoc()->GetLayerAdmin().GetLayer("DrawnInSlideshow"))
775 {
776 SdrLayerIDSet aDocLayerIDSet;
777 pViewShell->GetDoc()->GetLayerAdmin().getVisibleLayersODF(aDocLayerIDSet);
778 if (pViewShell->GetFrameView()->GetVisibleLayers() != aDocLayerIDSet)
779 {
780 pViewShell->GetFrameView()->SetVisibleLayers(aDocLayerIDSet);
781 }
782 pViewShell->GetDoc()->GetLayerAdmin().getPrintableLayersODF(aDocLayerIDSet);
783 if (pViewShell->GetFrameView()->GetPrintableLayers() != aDocLayerIDSet)
784 {
785 pViewShell->GetFrameView()->SetPrintableLayers(aDocLayerIDSet);
786 }
787 pViewShell->GetDoc()->GetLayerAdmin().getLockedLayersODF(aDocLayerIDSet);
788 if (pViewShell->GetFrameView()->GetLockedLayers() != aDocLayerIDSet)
789 {
790 pViewShell->GetFrameView()->SetLockedLayers(aDocLayerIDSet);
791 }
792 pViewShell->InvalidateWindows();
793 }
794
795 // Fire the acc focus event when focus is switched back. The above method
796 // mpCurrentViewShellBase->GetWindow()->GrabFocus() will set focus to WorkWindow
797 // instead of the sd::window, so here call Shell's method to fire the focus event
798 pViewShell->SwitchActiveViewFireFocus();
799 }
800 }
801 mpCurrentViewShellBase = nullptr;
802}
803
804void SAL_CALL SlideShow::rehearseTimings()
805{
806 Sequence< PropertyValue > aArguments(1);
807 aArguments[0].Name = "RehearseTimings";
808 aArguments[0].Value <<= true;
809 startWithArguments( aArguments );
1
Calling 'SlideShow::startWithArguments'
810}
811
812// XPresentation2
813
814void SAL_CALL SlideShow::startWithArguments(const Sequence< PropertyValue >& rArguments)
815{
816 SolarMutexGuard aGuard;
817 ThrowIfDisposed();
818
819 // Stop a running show before starting a new one.
820 if( mxController.is() )
2
Taking false branch
821 {
822 assert(!mbIsInStartup)(static_cast <bool> (!mbIsInStartup) ? void (0) : __assert_fail
("!mbIsInStartup", "/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
, 822, __extension__ __PRETTY_FUNCTION__))
;
823 end();
824 }
825 else if (mbIsInStartup)
3
Assuming field 'mbIsInStartup' is false
4
Taking false branch
826 {
827 // We are already somewhere in process of starting a slide show but
828 // have not yet got to the point where mxController is set. There
829 // is not yet a slide show to end so return silently.
830 return;
831 }
832
833 // Prevent multiple instance of the SlideShow class for one document.
834 mbIsInStartup = true;
835
836 mxCurrentSettings = std::make_shared<PresentationSettingsEx>( mpDoc->getPresentationSettings() );
837 mxCurrentSettings->SetArguments( rArguments );
838
839 // if there is no view shell base set, use the current one or the first using this document
840 if( mpCurrentViewShellBase == nullptr )
5
Assuming the condition is false
6
Taking false branch
841 {
842 // first check current
843 ::sd::ViewShellBase* pBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::Current() );
844 if( pBase && pBase->GetDocument() == mpDoc )
845 {
846 mpCurrentViewShellBase = pBase;
847 }
848 else
849 {
850 // current is not ours, so get first from ours
851 mpCurrentViewShellBase = ::sd::ViewShellBase::GetViewShellBase( SfxViewFrame::GetFirst( mpDoc->GetDocSh() ) );
852 }
853 }
854
855 // #i118456# make sure TextEdit changes get pushed to model.
856 // mpDrawView is tested against NULL above already.
857 if(mpCurrentViewShellBase
6.1
Field 'mpCurrentViewShellBase' is non-null
6.1
Field 'mpCurrentViewShellBase' is non-null
6.1
Field 'mpCurrentViewShellBase' is non-null
6.1
Field 'mpCurrentViewShellBase' is non-null
)
7
Taking true branch
858 {
859 ViewShell* pViewShell = mpCurrentViewShellBase->GetMainViewShell().get();
860
861 if(pViewShell && pViewShell->GetView())
8
Assuming 'pViewShell' is null
862 {
863 pViewShell->GetView()->SdrEndTextEdit();
864 }
865 }
866
867 // Start either a full-screen or an in-place show.
868 if(mxCurrentSettings->mbFullScreen && !mxCurrentSettings->mbPreview)
9
Assuming field 'mbFullScreen' is true
10
Assuming field 'mbPreview' is false
11
Taking true branch
869 StartFullscreenPresentation();
12
Calling 'SlideShow::StartFullscreenPresentation'
870 else
871 StartInPlacePresentation();
872
873}
874
875sal_Bool SAL_CALL SlideShow::isRunning( )
876{
877 SolarMutexGuard aGuard;
878 return mxController.is() && mxController->isRunning();
879}
880
881Reference< XSlideShowController > SAL_CALL SlideShow::getController( )
882{
883 ThrowIfDisposed();
884
885 Reference< XSlideShowController > xController( mxController.get() );
886 return xController;
887}
888
889// XComponent
890
891void SAL_CALL SlideShow::disposing()
892{
893 SolarMutexGuard aGuard;
894
895 if( mnInPlaceConfigEvent )
896 {
897 Application::RemoveUserEvent( mnInPlaceConfigEvent );
898 mnInPlaceConfigEvent = nullptr;
899 }
900
901 if( mxController.is() )
902 {
903 mxController->dispose();
904 mxController.clear();
905 }
906
907 mpCurrentViewShellBase = nullptr;
908 mpFullScreenViewShellBase = nullptr;
909 mpDoc = nullptr;
910}
911
912void SlideShow::startPreview( const Reference< XDrawPage >& xDrawPage, const Reference< XAnimationNode >& xAnimationNode )
913{
914 Sequence< PropertyValue > aArguments(4);
915
916 aArguments[0].Name = "Preview";
917 aArguments[0].Value <<= true;
918
919 aArguments[1].Name = "FirstPage";
920 aArguments[1].Value <<= xDrawPage;
921
922 aArguments[2].Name = "AnimationNode";
923 aArguments[2].Value <<= xAnimationNode;
924
925 aArguments[3].Name = "ParentWindow";
926 aArguments[3].Value <<= Reference< XWindow >();
927
928 startWithArguments( aArguments );
929}
930
931OutputDevice* SlideShow::getShowWindow()
932{
933 return mxController.is() ? mxController->mpShowWindow.get() : nullptr;
934}
935
936int SlideShow::getAnimationMode() const
937{
938 return mxController.is() ? mxController->meAnimationMode : ANIMATIONMODE_SHOW;
939}
940
941void SlideShow::jumpToPageIndex( sal_Int32 nPageIndex )
942{
943 if( mxController.is() )
944 mxController->displaySlideIndex( nPageIndex );
945}
946
947void SlideShow::jumpToPageNumber( sal_Int32 nPageNumber )
948{
949 if( mxController.is() )
950 mxController->displaySlideNumber( nPageNumber );
951}
952
953sal_Int32 SlideShow::getCurrentPageNumber() const
954{
955 return mxController.is() ? mxController->getCurrentSlideNumber() : 0;
956}
957
958void SlideShow::jumpToBookmark( const OUString& sBookmark )
959{
960 if( mxController.is() )
961 mxController->jumpToBookmark( sBookmark );
962}
963
964bool SlideShow::isFullScreen() const
965{
966 return mxController.is() && mxController->maPresSettings.mbFullScreen;
967}
968
969void SlideShow::resize( const Size &rSize )
970{
971 if( mxController.is() )
972 mxController->resize( rSize );
973}
974
975bool SlideShow::activate( ViewShellBase& rBase )
976{
977 if( (mpFullScreenViewShellBase == &rBase) && !mxController.is() )
978 {
979 ::std::shared_ptr<PresentationViewShell> pShell = std::dynamic_pointer_cast<PresentationViewShell>(rBase.GetMainViewShell());
980 if (pShell != nullptr)
981 {
982 pShell->FinishInitialization( mpFullScreenFrameView );
983 mpFullScreenFrameView = nullptr;
984
985 CreateController( pShell.get(), pShell->GetView(), rBase.GetViewWindow() );
986
987 if (!mxController->startShow(mxCurrentSettings.get()))
988 return false;
989
990 pShell->Resize();
991 // Defer the sd::ShowWindow's GrabFocus to here. so that the accessible event can be fired correctly.
992 pShell->GetActiveWindow()->GrabFocus();
993 }
994 }
995
996 if( mxController.is() )
997 mxController->activate();
998
999 return true;
1000}
1001
1002void SlideShow::deactivate()
1003{
1004 mxController->deactivate();
1005}
1006
1007bool SlideShow::keyInput(const KeyEvent& rKEvt)
1008{
1009 return mxController.is() && mxController->keyInput(rKEvt);
1010}
1011
1012void SlideShow::paint()
1013{
1014 if( mxController.is() )
1015 mxController->paint();
1016}
1017
1018void SlideShow::pause( bool bPause )
1019{
1020 if( mxController.is() )
1021 {
1022 if( bPause )
1023 mxController->pause();
1024 else
1025 mxController->resume();
1026 }
1027}
1028
1029bool SlideShow::swipe(const CommandSwipeData& rSwipeData)
1030{
1031 return mxController.is() && mxController->swipe(rSwipeData);
1032}
1033
1034bool SlideShow::longpress(const CommandLongPressData& rLongPressData)
1035{
1036 return mxController.is() && mxController->longpress(rLongPressData);
1037}
1038
1039void SlideShow::StartInPlacePresentationConfigurationCallback()
1040{
1041 if( mnInPlaceConfigEvent != nullptr )
1042 Application::RemoveUserEvent( mnInPlaceConfigEvent );
1043
1044 mnInPlaceConfigEvent = Application::PostUserEvent( LINK( this, SlideShow, StartInPlacePresentationConfigurationHdl )::tools::detail::makeLink( ::tools::detail::castTo<SlideShow
*>(this), &SlideShow::LinkStubStartInPlacePresentationConfigurationHdl
)
);
1045}
1046
1047IMPL_LINK_NOARG(SlideShow, StartInPlacePresentationConfigurationHdl, void*, void)void SlideShow::LinkStubStartInPlacePresentationConfigurationHdl
(void * instance, void* data) { return static_cast<SlideShow
*>(instance)->StartInPlacePresentationConfigurationHdl
(data); } void SlideShow::StartInPlacePresentationConfigurationHdl
(__attribute__ ((unused)) void*)
1048{
1049 mnInPlaceConfigEvent = nullptr;
1050 StartInPlacePresentation();
1051}
1052
1053void SlideShow::StartInPlacePresentation()
1054{
1055 if( mpCurrentViewShellBase )
1056 {
1057 // Save the current view shell type so that it can be restored after the
1058 // show has ended. If there already is a saved shell type then that is
1059 // not overwritten.
1060
1061 ViewShell::ShellType eShell = ViewShell::ST_NONE;
1062
1063 ::std::shared_ptr<FrameworkHelper> pHelper(FrameworkHelper::Instance(*mpCurrentViewShellBase));
1064 ::std::shared_ptr<ViewShell> pMainViewShell(pHelper->GetViewShell(FrameworkHelper::msCenterPaneURL));
1065
1066 if( pMainViewShell )
1067 eShell = pMainViewShell->GetShellType();
1068
1069 if( eShell != ViewShell::ST_IMPRESS )
1070 {
1071 // Switch temporary to a DrawViewShell which supports the in-place presentation.
1072
1073 if( pMainViewShell )
1074 {
1075 FrameView* pFrameView = pMainViewShell->GetFrameView();
1076 pFrameView->SetPresentationViewShellId(SID_VIEWSHELL1(5000 + 631));
1077 pFrameView->SetPreviousViewShellType (pMainViewShell->GetShellType());
1078 pFrameView->SetPageKind (PageKind::Standard);
1079 }
1080
1081 pHelper->RequestView( FrameworkHelper::msImpressViewURL, FrameworkHelper::msCenterPaneURL );
1082 pHelper->RunOnConfigurationEvent(
1083 FrameworkHelper::msConfigurationUpdateEndEvent,
1084 [this] (bool const) { return this->StartInPlacePresentationConfigurationCallback(); } );
1085 return;
1086 }
1087 else
1088 {
1089 vcl::Window* pParentWindow = mxCurrentSettings->mpParentWindow;
1090 if( pParentWindow == nullptr )
1091 pParentWindow = mpCurrentViewShellBase->GetViewWindow();
1092
1093 CreateController( pMainViewShell.get(), pMainViewShell->GetView(), pParentWindow );
1094 }
1095 }
1096 else if( mxCurrentSettings->mpParentWindow )
1097 {
1098 // no current view shell, but parent window
1099 CreateController( nullptr, nullptr, mxCurrentSettings->mpParentWindow );
1100 }
1101
1102 if( !mxController.is() )
1103 return;
1104
1105 bool bSuccess = false;
1106 if( mxCurrentSettings && mxCurrentSettings->mbPreview )
1107 {
1108 bSuccess = mxController->startPreview(mxCurrentSettings->mxStartPage, mxCurrentSettings->mxAnimationNode, mxCurrentSettings->mpParentWindow );
1109 }
1110 else
1111 {
1112 bSuccess = mxController->startShow(mxCurrentSettings.get());
1113 }
1114
1115 if( !bSuccess )
1116 end();
1117 else
1118 {
1119 if( mpCurrentViewShellBase && ( !mxCurrentSettings || ( mxCurrentSettings && !mxCurrentSettings->mbPreview ) ) )
1120 mpCurrentViewShellBase->GetWindow()->GrabFocus();
1121 }
1122}
1123
1124void SlideShow::StartFullscreenPresentation( )
1125{
1126 // Create the top level window in which the PresentationViewShell(Base)
1127 // will be created. This is done here explicitly so that we can make it
1128 // fullscreen.
1129 const sal_Int32 nDisplay (GetDisplay());
1130 VclPtr<WorkWindow> pWorkWindow = VclPtr<FullScreenWorkWindow>::Create(this, mpCurrentViewShellBase);
13
Calling 'VclPtr::Create'
15
Returned allocated memory
16
Calling implicit destructor for 'VclPtr<(anonymous namespace)::FullScreenWorkWindow>'
17
Calling '~Reference'
24
Returning from '~Reference'
25
Returning from destructor for 'VclPtr<(anonymous namespace)::FullScreenWorkWindow>'
1131 pWorkWindow->SetBackground(Wallpaper(COL_BLACK));
26
Calling 'VclPtr::operator->'
1132 OUString Title(SdResId(STR_FULLSCREEN_SLIDESHOWreinterpret_cast<char const *>("STR_FULLSCREEN_SLIDESHOW"
"\004" u8"Presenting: %s")
));
1133 Title = Title.replaceFirst("%s",
1134 mpCurrentViewShellBase->GetDocShell()->GetTitle(SFX_TITLE_DETECT4));
1135 pWorkWindow->SetText(Title);
1136 pWorkWindow->StartPresentationMode( true, mpDoc->getPresentationSettings().mbAlwaysOnTop ? PresentationFlags::HideAllApps : PresentationFlags::NONE, nDisplay);
1137 // pWorkWindow->ShowFullScreenMode(sal_False, nDisplay);
1138
1139 if (!pWorkWindow->IsVisible())
1140 return;
1141
1142 // Initialize the new presentation view shell with a copy of the
1143 // frame view of the current view shell. This avoids that
1144 // changes made by the presentation have an effect on the other
1145 // view shells.
1146 FrameView* pOriginalFrameView = nullptr;
1147 ::std::shared_ptr<ViewShell> xShell(mpCurrentViewShellBase->GetMainViewShell());
1148 if (xShell)
1149 pOriginalFrameView = xShell->GetFrameView();
1150
1151 delete mpFullScreenFrameView;
1152 mpFullScreenFrameView = new FrameView(mpDoc, pOriginalFrameView);
1153
1154 // The new frame is created hidden. To make it visible and activate the
1155 // new view shell--a prerequisite to process slot calls and initialize
1156 // its panes--a GrabFocus() has to be called later on.
1157 SfxFrame* pNewFrame = SfxFrame::CreateHidden( *mpDoc->GetDocSh(), *pWorkWindow, PRESENTATION_FACTORY_ID );
1158 pNewFrame->SetPresentationMode(true);
1159
1160 mpFullScreenViewShellBase = static_cast<ViewShellBase*>(pNewFrame->GetCurrentViewFrame()->GetViewShell());
1161 if(mpFullScreenViewShellBase != nullptr)
1162 {
1163 // The following GrabFocus() is responsible for activating the
1164 // new view shell. Without it the screen remains blank (under
1165 // Windows and some Linux variants.)
1166 mpFullScreenViewShellBase->GetWindow()->GrabFocus();
1167 }
1168}
1169
1170/// convert configuration setting display concept to real screens
1171sal_Int32 SlideShow::GetDisplay()
1172{
1173 sal_Int32 nDisplay = 0;
1174
1175 SdOptions* pOptions = SD_MOD()( static_cast<SdModule*>(SfxApplication::GetModule(SfxToolsModule
::Draw)) )
->GetSdOptions(DocumentType::Impress);
1176 if( pOptions )
1177 nDisplay = pOptions->GetDisplay();
1178
1179 if( nDisplay < 0 )
1180 nDisplay = -1;
1181 else if( nDisplay == 0)
1182 nDisplay = static_cast<sal_Int32>(Application::GetDisplayExternalScreen());
1183 else
1184 nDisplay--;
1185
1186 SAL_INFO("sd", "Presenting on real screen " << nDisplay)do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_INFO
, "sd")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Presenting on real screen " << nDisplay) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd")
, ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "1186" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Presenting on real screen " <<
nDisplay), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Presenting on real screen " <<
nDisplay; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO),
("sd"), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "1186" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "Presenting on real screen " << nDisplay) ==
1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_INFO), ("sd")
, ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "1186" ": "), ::sal::detail::unwrapStream( ::sal::detail
::StreamStart() << "Presenting on real screen " <<
nDisplay), 0); } else { ::std::ostringstream sal_detail_stream
; sal_detail_stream << "Presenting on real screen " <<
nDisplay; ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_INFO),
("sd"), ("/home/maarten/src/libreoffice/core/sd/source/ui/slideshow/slideshow.cxx"
":" "1186" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false)
;
1187
1188 return nDisplay;
1189}
1190
1191bool SlideShow::dependsOn( ViewShellBase const * pViewShellBase )
1192{
1193 return mxController.is() && (pViewShellBase == mpCurrentViewShellBase) && mpFullScreenViewShellBase;
1194}
1195
1196Reference< presentation::XPresentation2 > CreatePresentation( const SdDrawDocument& rDocument )
1197{
1198 return Reference< presentation::XPresentation2 >( SlideShow::Create( const_cast< SdDrawDocument* >( &rDocument ) ).get() );
1199}
1200
1201/* 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 );
14
Memory is allocated
130 }
131
132 /** Probably most common used: handle->someBodyOp().
133 */
134 reference_type * operator->() const
135 {
136 return m_rInnerRef.get();
27
Calling 'Reference::get'
137 }
138
139 /** Get the body. Can be used instead of operator->().
140 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
141 are the same.
142 */
143 reference_type * get() const
144 {
145 return m_rInnerRef.get();
146 }
147
148 void set(reference_type *pBody)
149 {
150 m_rInnerRef.set(pBody);
151 }
152
153 void reset(reference_type *pBody)
154 {
155 m_rInnerRef.set(pBody);
156 }
157
158 /** Up-casting copy assignment operator.
159
160 Does not work for up-casts to ambiguous bases.
161
162 @param rRef another reference
163 */
164 template<typename derived_type>
165 typename std::enable_if<
166 std::is_base_of<reference_type, derived_type>::value,
167 VclPtr &>::type
168 operator =(VclPtr<derived_type> const & rRef)
169 {
170 m_rInnerRef.set(rRef.get());
171 return *this;
172 }
173
174 VclPtr & operator =(reference_type * pBody)
175 {
176 m_rInnerRef.set(pBody);
177 return *this;
178 }
179
180 operator reference_type * () const
181 {
182 return m_rInnerRef.get();
183 }
184
185 explicit operator bool () const
186 {
187 return m_rInnerRef.get() != nullptr;
188 }
189
190 void clear()
191 {
192 m_rInnerRef.clear();
193 }
194
195 void reset()
196 {
197 m_rInnerRef.clear();
198 }
199
200 void disposeAndClear()
201 {
202 // hold it alive for the lifetime of this method
203 ::rtl::Reference<reference_type> aTmp(m_rInnerRef);
204 m_rInnerRef.clear(); // we should use some 'swap' method ideally ;-)
205 if (aTmp.get()) {
206 aTmp->disposeOnce();
207 }
208 }
209
210 /** Needed to place VclPtr's into STL collection.
211 */
212 bool operator< (const VclPtr<reference_type> & handle) const
213 {
214 return (m_rInnerRef < handle.m_rInnerRef);
215 }
216}; // class VclPtr
217
218template<typename T1, typename T2>
219inline bool operator ==(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
220 return p1.get() == p2.get();
221}
222
223template<typename T> inline bool operator ==(VclPtr<T> const & p1, T const * p2)
224{
225 return p1.get() == p2;
226}
227
228template<typename T> inline bool operator ==(VclPtr<T> const & p1, T * p2) {
229 return p1.get() == p2;
230}
231
232template<typename T> inline bool operator ==(T const * p1, VclPtr<T> const & p2)
233{
234 return p1 == p2.get();
235}
236
237template<typename T> inline bool operator ==(T * p1, VclPtr<T> const & p2) {
238 return p1 == p2.get();
239}
240
241template<typename T1, typename T2>
242inline bool operator !=(VclPtr<T1> const & p1, VclPtr<T2> const & p2) {
243 return !(p1 == p2);
244}
245
246template<typename T> inline bool operator !=(VclPtr<T> const & p1, T const * p2)
247{
248 return !(p1 == p2);
249}
250
251template<typename T> inline bool operator !=(VclPtr<T> const & p1, T * p2) {
252 return !(p1 == p2);
253}
254
255template<typename T> inline bool operator !=(T const * p1, VclPtr<T> const & p2)
256{
257 return !(p1 == p2);
258}
259
260template<typename T> inline bool operator !=(T * p1, VclPtr<T> const & p2) {
261 return !(p1 == p2);
262}
263
264/**
265 * A construction helper for a temporary VclPtr. Since VclPtr types
266 * are created with a reference-count of one - to help fit into
267 * the existing code-flow; this helps us to construct them easily.
268 * see also VclPtr::Create and ScopedVclPtr
269 *
270 * For more details on the design please see vcl/README.lifecycle
271 *
272 * @param reference_type must be a subclass of vcl::Window
273 */
274template <class reference_type>
275class SAL_WARN_UNUSED__attribute__((warn_unused)) VclPtrInstance final : public VclPtr<reference_type>
276{
277public:
278 template<typename... Arg> VclPtrInstance(Arg &&... arg)
279 : VclPtr<reference_type>( new reference_type(std::forward<Arg>(arg)...), SAL_NO_ACQUIRE )
280 {
281 }
282
283 /**
284 * Override and disallow this, to prevent people accidentally calling it and actually
285 * getting VclPtr::Create and getting a naked VclPtr<> instance
286 */
287 template<typename... Arg> static VclPtrInstance< reference_type > Create(Arg &&... ) = delete;
288};
289
290template <class reference_type>
291class ScopedVclPtr : public VclPtr<reference_type>
292{
293public:
294 /** Constructor...
295 */
296 ScopedVclPtr()
297 : VclPtr<reference_type>()
298 {}
299
300 /** Constructor
301 */
302 ScopedVclPtr (reference_type * pBody)
303 : VclPtr<reference_type>(pBody)
304 {}
305
306 /** Copy constructor...
307 */
308 ScopedVclPtr (const VclPtr<reference_type> & handle)
309 : VclPtr<reference_type>(handle)
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
17.1
Field 'm_pBody' is non-null
17.1
Field 'm_pBody' is non-null
17.1
Field 'm_pBody' is non-null
17.1
Field 'm_pBody' is non-null
)
18
Taking true branch
113 m_pBody->release();
19
Calling 'VclReferenceBase::release'
23
Returning; memory was released
114 }
115
116 /** Set...
117 Similar to assignment.
118 */
119 Reference<reference_type> &
120 SAL_CALL set (reference_type * pBody)
121 {
122 if (pBody)
123 pBody->acquire();
124 reference_type * const pOld = m_pBody;
125 m_pBody = pBody;
126 if (pOld)
127 pOld->release();
128 return *this;
129 }
130
131 /** Assignment.
132 Unbinds this instance from its body (if bound) and
133 bind it to the body represented by the handle.
134 */
135 Reference<reference_type> &
136 SAL_CALL operator= (const Reference<reference_type> & handle)
137 {
138 return set( handle.m_pBody );
139 }
140
141#ifdef LIBO_INTERNAL_ONLY1
142 /** Assignment.
143 * Unbinds this instance from its body (if bound),
144 * bind it to the body represented by the handle, and
145 * set the body represented by the handle to nullptr.
146 */
147 Reference<reference_type> &
148 operator= (Reference<reference_type> && handle)
149 {
150 // self-movement guts ourself
151 if (m_pBody)
152 m_pBody->release();
153 m_pBody = handle.m_pBody;
154 handle.m_pBody = nullptr;
155 return *this;
156 }
157#endif
158
159 /** Assignment...
160 */
161 Reference<reference_type> &
162 SAL_CALL operator= (reference_type * pBody)
163 {
164 return set( pBody );
165 }
166
167 /** Unbind the body from this handle.
168 Note that for a handle representing a large body,
169 "handle.clear().set(new body());" _might_
170 perform a little bit better than "handle.set(new body());",
171 since in the second case two large objects exist in memory
172 (the old body and the new body).
173 */
174 Reference<reference_type> & SAL_CALL clear()
175 {
176 if (m_pBody)
177 {
178 reference_type * const pOld = m_pBody;
179 m_pBody = NULL__null;
180 pOld->release();
181 }
182 return *this;
183 }
184
185
186 /** Get the body. Can be used instead of operator->().
187 I.e. handle->someBodyOp() and handle.get()->someBodyOp()
188 are the same.
189 */
190 reference_type * SAL_CALL get() const
191 {
192 return m_pBody;
28
Use of memory after it is freed
193 }
194
195
196 /** Probably most common used: handle->someBodyOp().
197 */
198 reference_type * SAL_CALL operator->() const
199 {
200 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 200, __extension__ __PRETTY_FUNCTION__))
;
201 return m_pBody;
202 }
203
204
205 /** Allows (*handle).someBodyOp().
206 */
207 reference_type & SAL_CALL operator*() const
208 {
209 assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail
("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx"
, 209, __extension__ __PRETTY_FUNCTION__))
;
210 return *m_pBody;
211 }
212
213
214 /** Returns True if the handle does point to a valid body.
215 */
216 bool SAL_CALL is() const
217 {
218 return (m_pBody != NULL__null);
219 }
220
221#if defined LIBO_INTERNAL_ONLY1
222 /** Returns True if the handle does point to a valid body.
223 */
224 explicit operator bool() const
225 {
226 return is();
227 }
228#endif
229
230 /** Returns True if this points to pBody.
231 */
232 bool SAL_CALL operator== (const reference_type * pBody) const
233 {
234 return (m_pBody == pBody);
235 }
236
237
238 /** Returns True if handle points to the same body.
239 */
240 bool
241 SAL_CALL operator== (const Reference<reference_type> & handle) const
242 {
243 return (m_pBody == handle.m_pBody);
244 }
245
246
247 /** Needed to place References into STL collection.
248 */
249 bool
250 SAL_CALL operator!= (const Reference<reference_type> & handle) const
251 {
252 return (m_pBody != handle.m_pBody);
253 }
254
255
256 /** Needed to place References into STL collection.
257 */
258 bool
259 SAL_CALL operator< (const Reference<reference_type> & handle) const
260 {
261 return (m_pBody < handle.m_pBody);
262 }
263
264
265 /** Needed to place References into STL collection.
266 */
267 bool
268 SAL_CALL operator> (const Reference<reference_type> & handle) const
269 {
270 return (m_pBody > handle.m_pBody);
271 }
272};
273
274} // namespace rtl
275
276#if defined LIBO_INTERNAL_ONLY1
277namespace std
278{
279
280/// @cond INTERNAL
281/**
282 Make rtl::Reference hashable by default for use in STL containers.
283
284 @since LibreOffice 6.3
285*/
286template<typename T>
287struct hash<::rtl::Reference<T>>
288{
289 std::size_t operator()(::rtl::Reference<T> const & s) const
290 { return std::size_t(s.get()); }
291};
292/// @endcond
293
294}
295
296#endif
297
298#endif /* ! INCLUDED_RTL_REF_HXX */
299
300/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/vcl/vclreferencebase.hxx

1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#ifndef INCLUDED_VCL_Reference_HXX
20#define INCLUDED_VCL_Reference_HXX
21
22#include <vcl/dllapi.h>
23#include <osl/interlck.h>
24
25class VCL_DLLPUBLIC__attribute__ ((visibility("default"))) VclReferenceBase
26{
27 mutable oslInterlockedCount mnRefCnt;
28
29 template<typename T> friend class VclPtr;
30
31public:
32 void acquire() const
33 {
34 osl_atomic_increment(&mnRefCnt)__sync_add_and_fetch((&mnRefCnt), 1);
35 }
36
37 void release() const
38 {
39 if (osl_atomic_decrement(&mnRefCnt)__sync_sub_and_fetch((&mnRefCnt), 1) == 0)
20
Assuming the condition is true
21
Taking true branch
40 delete this;
22
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