Bug Summary

File:home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.cxx
Warning:line 362, column 18
Forming reference to null pointer

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 PresenterController.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 -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 EXCEPTIONS_ON -D LIBO_INTERNAL_ONLY -I /home/maarten/src/libreoffice/core/external/boost/include -I /home/maarten/src/libreoffice/core/workdir/UnpackedTarball/boost -I /home/maarten/src/libreoffice/core/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include -I /usr/lib/jvm/java-11-openjdk-11.0.9.10-0.0.ea.fc33.x86_64/include/linux -I /home/maarten/src/libreoffice/core/config_host -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/udkapi/normal -I /home/maarten/src/libreoffice/core/workdir/UnoApiHeadersTarget/offapi/normal -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10 -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/x86_64-redhat-linux -internal-isystem /usr/bin/../lib/gcc/x86_64-redhat-linux/10/../../../../include/c++/10/backward -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/11.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -Wno-missing-braces -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/maarten/src/libreoffice/core -ferror-limit 19 -fvisibility hidden -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -debug-info-kind=constructor -analyzer-output=html -faddrsig -o /home/maarten/tmp/wis/scan-build-libreoffice/output/report/2020-10-07-141433-9725-1 -x c++ /home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.cxx

/home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.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 <sal/config.h>
21
22#include <string_view>
23
24#include "PresenterController.hxx"
25
26#include "PresenterAccessibility.hxx"
27#include "PresenterCanvasHelper.hxx"
28#include "PresenterCurrentSlideObserver.hxx"
29#include "PresenterScreen.hxx"
30#include "PresenterPaintManager.hxx"
31#include "PresenterPaneBase.hxx"
32#include "PresenterPaneContainer.hxx"
33#include "PresenterPaneBorderPainter.hxx"
34#include "PresenterTheme.hxx"
35#include "PresenterViewFactory.hxx"
36#include "PresenterWindowManager.hxx"
37
38#include <com/sun/star/awt/Key.hpp>
39#include <com/sun/star/awt/KeyModifier.hpp>
40#include <com/sun/star/awt/MouseButton.hpp>
41#include <com/sun/star/container/XNamed.hpp>
42#include <com/sun/star/drawing/XDrawView.hpp>
43#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
44#include <com/sun/star/drawing/framework/ResourceActivationMode.hpp>
45#include <com/sun/star/drawing/framework/ResourceId.hpp>
46#include <com/sun/star/drawing/framework/XControllerManager.hpp>
47#include <com/sun/star/frame/FrameSearchFlag.hpp>
48#include <com/sun/star/frame/XDispatchProvider.hpp>
49#include <com/sun/star/presentation/AnimationEffect.hpp>
50#include <com/sun/star/presentation/XPresentation.hpp>
51#include <com/sun/star/presentation/XPresentationSupplier.hpp>
52#include <com/sun/star/rendering/TextDirection.hpp>
53#include <com/sun/star/util/URLTransformer.hpp>
54
55#include <rtl/ustrbuf.hxx>
56
57using namespace ::com::sun::star;
58using namespace ::com::sun::star::uno;
59using namespace ::com::sun::star::presentation;
60using namespace ::com::sun::star::drawing::framework;
61
62namespace {
63 const sal_Int32 ResourceActivationEventType = 0;
64 const sal_Int32 ResourceDeactivationEventType = 1;
65 const sal_Int32 ConfigurationUpdateEndEventType = 2;
66}
67
68namespace sdext::presenter {
69
70IPresentationTime::~IPresentationTime()
71{
72}
73
74PresenterController::InstanceContainer PresenterController::maInstances;
75
76::rtl::Reference<PresenterController> PresenterController::Instance (
77 const css::uno::Reference<css::frame::XFrame>& rxFrame)
78{
79 InstanceContainer::const_iterator iInstance (maInstances.find(rxFrame));
80 if (iInstance != maInstances.end())
81 return iInstance->second;
82 else
83 return ::rtl::Reference<PresenterController>();
84}
85
86PresenterController::PresenterController (
87 const css::uno::WeakReference<css::lang::XEventListener> &rxScreen,
88 const Reference<XComponentContext>& rxContext,
89 const Reference<frame::XController>& rxController,
90 const Reference<presentation::XSlideShowController>& rxSlideShowController,
91 const rtl::Reference<PresenterPaneContainer>& rpPaneContainer,
92 const Reference<XResourceId>& rxMainPaneId)
93 : PresenterControllerInterfaceBase(m_aMutex),
94 mxScreen(rxScreen),
95 mxComponentContext(rxContext),
96 mxController(rxController),
97 mxConfigurationController(),
98 mxSlideShowController(rxSlideShowController),
99 mxMainPaneId(rxMainPaneId),
100 mpPaneContainer(rpPaneContainer),
101 mnCurrentSlideIndex(-1),
102 mxCurrentSlide(),
103 mxNextSlide(),
104 mpWindowManager(new PresenterWindowManager(rxContext,mpPaneContainer,this)),
105 mpTheme(),
106 mxMainWindow(),
107 mpPaneBorderPainter(),
108 mpCanvasHelper(std::make_shared<PresenterCanvasHelper>()),
109 mxPresenterHelper(),
110 mpPaintManager(),
111 mnPendingSlideNumber(-1),
112 mxUrlTransformer(),
113 mpAccessibleObject(),
114 mbIsAccessibilityActive(false)
115{
116 OSL_ASSERT(mxController.is())do { if (true && (!(mxController.is()))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.cxx"
":" "116" ": "), "OSL_ASSERT: %s", "mxController.is()"); } }
while (false)
;
117
118 if ( ! mxSlideShowController.is())
119 throw lang::IllegalArgumentException(
120 "missing slide show controller",
121 static_cast<XWeak*>(this),
122 2);
123
124 new PresenterCurrentSlideObserver(this,rxSlideShowController);
125
126 // Listen for configuration changes.
127 Reference<XControllerManager> xCM (mxController, UNO_QUERY_THROW);
128 mxConfigurationController = xCM->getConfigurationController();
129 if (mxConfigurationController.is())
130 {
131 mxConfigurationController->addConfigurationChangeListener(
132 this,
133 "ResourceActivation",
134 Any(ResourceActivationEventType));
135 mxConfigurationController->addConfigurationChangeListener(
136 this,
137 "ResourceDeactivation",
138 Any(ResourceDeactivationEventType));
139 mxConfigurationController->addConfigurationChangeListener(
140 this,
141 "ConfigurationUpdateEnd",
142 Any(ConfigurationUpdateEndEventType));
143 }
144
145 // Listen for the frame being activated.
146 Reference<frame::XFrame> xFrame (mxController->getFrame());
147 if (xFrame.is())
148 xFrame->addFrameActionListener(this);
149
150 // Create the border painter.
151 mpPaneBorderPainter = new PresenterPaneBorderPainter(rxContext);
152 mpWindowManager->SetPaneBorderPainter(mpPaneBorderPainter);
153
154 // Create an object that is able to load the bitmaps in a format that is
155 // supported by the canvas.
156 Reference<lang::XMultiComponentFactory> xFactory =
157 rxContext->getServiceManager();
158 if ( ! xFactory.is())
159 return;
160 mxPresenterHelper.set(
161 xFactory->createInstanceWithContext(
162 "com.sun.star.drawing.PresenterHelper",
163 rxContext),
164 UNO_QUERY_THROW);
165
166 if (mxSlideShowController.is())
167 {
168 mxSlideShowController->activate();
169 Reference<beans::XPropertySet> xProperties (mxSlideShowController, UNO_QUERY);
170 if (xProperties.is())
171 {
172 Reference<awt::XWindow> xWindow (
173 xProperties->getPropertyValue("ParentWindow"), UNO_QUERY);
174 if (xWindow.is())
175 xWindow->addKeyListener(this);
176 }
177 }
178
179 UpdateCurrentSlide(0);
180
181 maInstances[mxController->getFrame()] = this;
182
183 // Create a URLTransformer.
184 if (xFactory.is())
185 {
186 mxUrlTransformer.set(util::URLTransformer::create(mxComponentContext));
187 }
188}
189
190PresenterController::~PresenterController()
191{
192}
193
194void PresenterController::disposing()
195{
196 maInstances.erase(mxController->getFrame());
197
198 if (mxMainWindow.is())
199 {
200 mxMainWindow->removeKeyListener(this);
201 mxMainWindow->removeMouseListener(this);
202 mxMainWindow = nullptr;
203 }
204 if (mxConfigurationController.is())
205 mxConfigurationController->removeConfigurationChangeListener(this);
206
207 Reference<XComponent> xWindowManagerComponent (
208 static_cast<XWeak*>(mpWindowManager.get()), UNO_QUERY);
209 mpWindowManager = nullptr;
210 if (xWindowManagerComponent.is())
211 xWindowManagerComponent->dispose();
212
213 if (mxController.is())
214 {
215 Reference<frame::XFrame> xFrame (mxController->getFrame());
216 if (xFrame.is())
217 xFrame->removeFrameActionListener(this);
218 mxController = nullptr;
219 }
220
221 mxComponentContext = nullptr;
222 mxConfigurationController = nullptr;
223 mxSlideShowController = nullptr;
224 mxMainPaneId = nullptr;
225 mpPaneContainer = nullptr;
226 mnCurrentSlideIndex = -1;
227 mxCurrentSlide = nullptr;
228 mxNextSlide = nullptr;
229 mpTheme.reset();
230 {
231 Reference<lang::XComponent> xComponent (
232 static_cast<XWeak*>(mpPaneBorderPainter.get()), UNO_QUERY);
233 mpPaneBorderPainter = nullptr;
234 if (xComponent.is())
235 xComponent->dispose();
236 }
237 mpCanvasHelper.reset();
238 {
239 Reference<lang::XComponent> xComponent (mxPresenterHelper, UNO_QUERY);
240 mxPresenterHelper = nullptr;
241 if (xComponent.is())
242 xComponent->dispose();
243 }
244 mpPaintManager.reset();
245 mnPendingSlideNumber = -1;
246 {
247 Reference<lang::XComponent> xComponent (mxUrlTransformer, UNO_QUERY);
248 mxUrlTransformer = nullptr;
249 if (xComponent.is())
250 xComponent->dispose();
251 }
252}
253
254void PresenterController::UpdateCurrentSlide (const sal_Int32 nOffset)
255{
256 // std::cerr << "Updating current Slide to " << nOffset << std::endl;
257 GetSlides(nOffset);
258 UpdatePaneTitles();
259 UpdateViews();
260
261 // Update the accessibility object.
262 if (IsAccessibilityActive())
263 {
264 mpAccessibleObject->NotifyCurrentSlideChange();
265 }
266}
267
268void PresenterController::GetSlides (const sal_Int32 nOffset)
269{
270 if ( ! mxSlideShowController.is())
271 return;
272
273 // Get the current slide from the slide show controller.
274 mxCurrentSlide = nullptr;
275 Reference<container::XIndexAccess> xIndexAccess(mxSlideShowController, UNO_QUERY);
276 try
277 {
278 sal_Int32 nSlideIndex = mxSlideShowController->getCurrentSlideIndex() + nOffset;
279 if (mxSlideShowController->isPaused())
280 nSlideIndex = -1;
281
282 if (xIndexAccess.is() && nSlideIndex>=0)
283 {
284 if (nSlideIndex < xIndexAccess->getCount())
285 {
286 mnCurrentSlideIndex = nSlideIndex;
287 mxCurrentSlide.set( xIndexAccess->getByIndex(nSlideIndex), UNO_QUERY);
288 }
289 }
290 }
291 catch (RuntimeException&)
292 {
293 }
294
295 // Get the next slide.
296 mxNextSlide = nullptr;
297 try
298 {
299 const sal_Int32 nNextSlideIndex (mxSlideShowController->getNextSlideIndex()+nOffset);
300 if (nNextSlideIndex >= 0)
301 {
302 if (xIndexAccess.is())
303 {
304 if (nNextSlideIndex < xIndexAccess->getCount())
305 mxNextSlide.set( xIndexAccess->getByIndex(nNextSlideIndex), UNO_QUERY);
306 }
307 }
308 }
309 catch (RuntimeException&)
310 {
311 }
312}
313
314void PresenterController::UpdatePaneTitles()
315{
316 if ( ! mxSlideShowController.is())
4
Calling 'BaseReference::is'
7
Returning from 'BaseReference::is'
8
Taking false branch
317 return;
318
319 // Get placeholders and their values.
320 const OUString sCurrentSlideNumberPlaceholder ("CURRENT_SLIDE_NUMBER");
321 const OUString sCurrentSlideNamePlaceholder ("CURRENT_SLIDE_NAME");
322 const OUString sSlideCountPlaceholder ("SLIDE_COUNT");
323
324 // Get string for slide count.
325 OUString sSlideCount ("---");
326 Reference<container::XIndexAccess> xIndexAccess(mxSlideShowController, UNO_QUERY);
327 if (xIndexAccess.is())
9
Taking false branch
328 sSlideCount = OUString::number(xIndexAccess->getCount());
329
330 // Get string for current slide index.
331 OUString sCurrentSlideNumber (OUString::number(mnCurrentSlideIndex + 1));
332
333 // Get name of the current slide.
334 OUString sCurrentSlideName;
335 Reference<container::XNamed> xNamedSlide (mxCurrentSlide, UNO_QUERY);
336 if (xNamedSlide.is())
10
Taking false branch
337 sCurrentSlideName = xNamedSlide->getName();
338 Reference<beans::XPropertySet> xSlideProperties (mxCurrentSlide, UNO_QUERY);
339 if (xSlideProperties.is())
11
Taking false branch
340 {
341 try
342 {
343 OUString sName;
344 if (xSlideProperties->getPropertyValue("LinkDisplayName") >>= sName)
345 {
346 // Find out whether the name of the current slide has been
347 // automatically created or has been set by the user.
348 if (sName != sCurrentSlideName)
349 sCurrentSlideName = sName;
350 }
351 }
352 catch (const beans::UnknownPropertyException&)
353 {
354 }
355 }
356
357 // Replace the placeholders with their current values.
358 for (auto& rxPane : mpPaneContainer->maPanes)
359 {
360 OSL_ASSERT(rxPane != nullptr)do { if (true && (!(rxPane != nullptr))) { sal_detail_logFormat
((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.cxx"
":" "360" ": "), "OSL_ASSERT: %s", "rxPane != nullptr"); } }
while (false)
;
12
Taking true branch
13
Loop condition is false. Exiting loop
361
362 OUString sTemplate (IsAccessibilityActive()
14
Assuming the condition is false
15
'?' condition is false
16
Forming reference to null pointer
363 ? rxPane->msAccessibleTitleTemplate
364 : rxPane->msTitleTemplate);
365 if (sTemplate.isEmpty())
366 continue;
367
368 OUStringBuffer sResult;
369 sResult.ensureCapacity(sTemplate.getLength());
370
371 sal_Int32 nIndex (0);
372 while (true)
373 {
374 sal_Int32 nStartIndex = sTemplate.indexOf('%', nIndex);
375 if (nStartIndex < 0)
376 {
377 // Add the remaining part of the string.
378 sResult.append(std::u16string_view(sTemplate).substr(nIndex));
379 break;
380 }
381 else
382 {
383 // Add the part preceding the next %.
384 sResult.append(std::u16string_view(sTemplate).substr(nIndex, nStartIndex-nIndex));
385
386 // Get the placeholder
387 ++nStartIndex;
388 const sal_Int32 nEndIndex (sTemplate.indexOf('%', nStartIndex+1));
389 const OUString sPlaceholder (sTemplate.copy(nStartIndex, nEndIndex-nStartIndex));
390 nIndex = nEndIndex+1;
391
392 // Replace the placeholder with its current value.
393 if (sPlaceholder == sCurrentSlideNumberPlaceholder)
394 sResult.append(sCurrentSlideNumber);
395 else if (sPlaceholder == sCurrentSlideNamePlaceholder)
396 sResult.append(sCurrentSlideName);
397 else if (sPlaceholder == sSlideCountPlaceholder)
398 sResult.append(sSlideCount);
399 }
400 }
401
402 rxPane->msTitle = sResult.makeStringAndClear();
403 if (rxPane->mxPane.is())
404 rxPane->mxPane->SetTitle(rxPane->msTitle);
405 }
406}
407
408void PresenterController::UpdateViews()
409{
410 // Tell all views about the slides they should display.
411 for (const auto& rxPane : mpPaneContainer->maPanes)
412 {
413 Reference<drawing::XDrawView> xDrawView (rxPane->mxView, UNO_QUERY);
414 if (xDrawView.is())
415 xDrawView->setCurrentPage(mxCurrentSlide);
416 }
417}
418
419SharedBitmapDescriptor
420 PresenterController::GetViewBackground (const OUString& rsViewURL) const
421{
422 if (mpTheme != nullptr)
423 {
424 const OUString sStyleName (mpTheme->GetStyleName(rsViewURL));
425 return mpTheme->GetBitmap(sStyleName, "Background");
426 }
427 return SharedBitmapDescriptor();
428}
429
430PresenterTheme::SharedFontDescriptor
431 PresenterController::GetViewFont (const OUString& rsViewURL) const
432{
433 if (mpTheme != nullptr)
434 {
435 const OUString sStyleName (mpTheme->GetStyleName(rsViewURL));
436 return mpTheme->GetFont(sStyleName);
437 }
438 return PresenterTheme::SharedFontDescriptor();
439}
440
441const std::shared_ptr<PresenterTheme>& PresenterController::GetTheme() const
442{
443 return mpTheme;
444}
445
446const ::rtl::Reference<PresenterWindowManager>& PresenterController::GetWindowManager() const
447{
448 return mpWindowManager;
449}
450
451const Reference<presentation::XSlideShowController>&
452 PresenterController::GetSlideShowController() const
453{
454 return mxSlideShowController;
455}
456
457const rtl::Reference<PresenterPaneContainer>& PresenterController::GetPaneContainer() const
458{
459 return mpPaneContainer;
460}
461
462const ::rtl::Reference<PresenterPaneBorderPainter>& PresenterController::GetPaneBorderPainter() const
463{
464 return mpPaneBorderPainter;
465}
466
467const std::shared_ptr<PresenterCanvasHelper>& PresenterController::GetCanvasHelper() const
468{
469 return mpCanvasHelper;
470}
471
472const Reference<drawing::XPresenterHelper>& PresenterController::GetPresenterHelper() const
473{
474 return mxPresenterHelper;
475}
476
477const std::shared_ptr<PresenterPaintManager>& PresenterController::GetPaintManager() const
478{
479 return mpPaintManager;
480}
481
482void PresenterController::ShowView (const OUString& rsViewURL)
483{
484 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
485 mpPaneContainer->FindViewURL(rsViewURL));
486 if (!pDescriptor)
487 return;
488
489 pDescriptor->mbIsActive = true;
490 mxConfigurationController->requestResourceActivation(
491 pDescriptor->mxPaneId,
492 ResourceActivationMode_ADD);
493 mxConfigurationController->requestResourceActivation(
494 ResourceId::createWithAnchor(
495 mxComponentContext,
496 rsViewURL,
497 pDescriptor->mxPaneId),
498 ResourceActivationMode_REPLACE);
499}
500
501void PresenterController::HideView (const OUString& rsViewURL)
502{
503 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
504 mpPaneContainer->FindViewURL(rsViewURL));
505 if (pDescriptor)
506 {
507 mxConfigurationController->requestResourceDeactivation(
508 ResourceId::createWithAnchor(
509 mxComponentContext,
510 rsViewURL,
511 pDescriptor->mxPaneId));
512 }
513}
514
515void PresenterController::DispatchUnoCommand (const OUString& rsCommand) const
516{
517 if ( ! mxUrlTransformer.is())
518 return;
519
520 util::URL aURL;
521 aURL.Complete = rsCommand;
522 mxUrlTransformer->parseStrict(aURL);
523
524 Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
525 if ( ! xDispatch.is())
526 return;
527
528 xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>());
529}
530
531Reference<css::frame::XDispatch> PresenterController::GetDispatch (const util::URL& rURL) const
532{
533 if ( ! mxController.is())
534 return nullptr;
535
536 Reference<frame::XDispatchProvider> xDispatchProvider (mxController->getFrame(), UNO_QUERY);
537 if ( ! xDispatchProvider.is())
538 return nullptr;
539
540 return xDispatchProvider->queryDispatch(
541 rURL,
542 OUString(),
543 frame::FrameSearchFlag::SELF);
544}
545
546util::URL PresenterController::CreateURLFromString (const OUString& rsURL) const
547{
548 util::URL aURL;
549
550 if (mxUrlTransformer.is())
551 {
552 aURL.Complete = rsURL;
553 mxUrlTransformer->parseStrict(aURL);
554 }
555
556 return aURL;
557}
558
559const Reference<drawing::framework::XConfigurationController>&
560 PresenterController::GetConfigurationController() const
561{
562 return mxConfigurationController;
563}
564
565const Reference<drawing::XDrawPage>& PresenterController::GetCurrentSlide() const
566{
567 return mxCurrentSlide;
568}
569
570bool PresenterController::HasTransition (Reference<drawing::XDrawPage> const & rxPage)
571{
572 bool bTransition = false;
573 if( rxPage.is() )
574 {
575 Reference<beans::XPropertySet> xSlidePropertySet (rxPage, UNO_QUERY);
576 try
577 {
578 sal_uInt16 aTransitionType = 0;
579 xSlidePropertySet->getPropertyValue("TransitionType") >>= aTransitionType;
580 if (aTransitionType > 0)
581 {
582 bTransition = true;
583 }
584 }
585 catch (const beans::UnknownPropertyException&)
586 {
587 }
588 }
589 return bTransition;
590}
591
592bool PresenterController::HasCustomAnimation (Reference<drawing::XDrawPage> const & rxPage)
593{
594 bool bCustomAnimation = false;
595 if( rxPage.is() )
596 {
597 sal_uInt32 i, nCount = rxPage->getCount();
598 for ( i = 0; i < nCount; i++ )
599 {
600 Reference<drawing::XShape> xShape(rxPage->getByIndex(i), UNO_QUERY);
601 Reference<beans::XPropertySet> xShapePropertySet(xShape, UNO_QUERY);
602 presentation::AnimationEffect aEffect = presentation::AnimationEffect_NONE;
603 presentation::AnimationEffect aTextEffect = presentation::AnimationEffect_NONE;
604 try
605 {
606 xShapePropertySet->getPropertyValue("Effect") >>= aEffect;
607 xShapePropertySet->getPropertyValue("TextEffect") >>= aTextEffect;
608 }
609 catch (const beans::UnknownPropertyException&)
610 {
611 }
612 if( aEffect != presentation::AnimationEffect_NONE ||
613 aTextEffect != presentation::AnimationEffect_NONE )
614 {
615 bCustomAnimation = true;
616 break;
617 }
618 }
619 }
620 return bCustomAnimation;
621}
622
623void PresenterController::SetAccessibilityActiveState (const bool bIsActive)
624{
625 if ( mbIsAccessibilityActive != bIsActive)
1
Assuming 'bIsActive' is not equal to field 'mbIsAccessibilityActive'
2
Taking true branch
626 {
627 mbIsAccessibilityActive = bIsActive;
628 UpdatePaneTitles();
3
Calling 'PresenterController::UpdatePaneTitles'
629 }
630}
631
632
633void PresenterController::HandleMouseClick (const awt::MouseEvent& rEvent)
634{
635 if (!mxSlideShowController.is())
636 return;
637
638 switch (rEvent.Buttons)
639 {
640 case awt::MouseButton::LEFT:
641 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
642 mxSlideShowController->gotoNextSlide();
643 else
644 mxSlideShowController->gotoNextEffect();
645 break;
646
647 case awt::MouseButton::RIGHT:
648 mxSlideShowController->gotoPreviousSlide();
649 break;
650
651 default:
652 // Other or multiple buttons.
653 break;
654 }
655}
656
657void PresenterController::RequestViews (
658 const bool bIsSlideSorterActive,
659 const bool bIsNotesViewActive,
660 const bool bIsHelpViewActive)
661{
662 for (const auto& rxPane : mpPaneContainer->maPanes)
663 {
664 bool bActivate (true);
665 const OUString sViewURL (rxPane->msViewURL);
666 if (sViewURL == PresenterViewFactory::msNotesViewURL)
667 {
668 bActivate = bIsNotesViewActive && !bIsSlideSorterActive && !bIsHelpViewActive;
669 }
670 else if (sViewURL == PresenterViewFactory::msSlideSorterURL)
671 {
672 bActivate = bIsSlideSorterActive;
673 }
674 else if (sViewURL == PresenterViewFactory::msCurrentSlidePreviewViewURL
675 || sViewURL == PresenterViewFactory::msNextSlidePreviewViewURL)
676 {
677 bActivate = !bIsSlideSorterActive && ! bIsHelpViewActive;
678 }
679 else if (sViewURL == PresenterViewFactory::msToolBarViewURL)
680 {
681 bActivate = true;
682 }
683 else if (sViewURL == PresenterViewFactory::msHelpViewURL)
684 {
685 bActivate = bIsHelpViewActive;
686 }
687
688 if (bActivate)
689 ShowView(sViewURL);
690 else
691 HideView(sViewURL);
692 }
693}
694
695void PresenterController::SetPresentationTime(IPresentationTime* pPresentationTime)
696{
697 mpPresentationTime = pPresentationTime;
698}
699
700IPresentationTime* PresenterController::GetPresentationTime()
701{
702 return mpPresentationTime;
703}
704
705//----- XConfigurationChangeListener ------------------------------------------
706
707void SAL_CALL PresenterController::notifyConfigurationChange (
708 const ConfigurationChangeEvent& rEvent)
709{
710 if (rBHelper.bDisposed || rBHelper.bInDispose)
711 {
712 throw lang::DisposedException (
713 "PresenterController object has already been disposed",
714 static_cast<uno::XWeak*>(this));
715 }
716
717 sal_Int32 nType (0);
718 if ( ! (rEvent.UserData >>= nType))
719 return;
720
721 switch (nType)
722 {
723 case ResourceActivationEventType:
724 if (rEvent.ResourceId->compareTo(mxMainPaneId) == 0)
725 {
726 InitializeMainPane(Reference<XPane>(rEvent.ResourceObject,UNO_QUERY));
727 }
728 else if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_DIRECT))
729 {
730 // A pane bound to the main pane has been created and is
731 // stored in the pane container.
732 Reference<XPane> xPane (rEvent.ResourceObject,UNO_QUERY);
733 if (xPane.is())
734 {
735 mpPaneContainer->FindPaneId(xPane->getResourceId());
736 }
737 }
738 else if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_INDIRECT))
739 {
740 // A view bound to one of the panes has been created and is
741 // stored in the pane container along with its pane.
742 Reference<XView> xView (rEvent.ResourceObject,UNO_QUERY);
743 if (xView.is())
744 {
745 mpPaneContainer->StoreView(xView);
746 UpdateViews();
747 mpWindowManager->NotifyViewCreation(xView);
748 }
749 }
750 break;
751
752 case ResourceDeactivationEventType:
753 if (rEvent.ResourceId->isBoundTo(mxMainPaneId,AnchorBindingMode_INDIRECT))
754 {
755 // If this is a view then remove it from the pane container.
756 Reference<XView> xView (rEvent.ResourceObject,UNO_QUERY);
757 if (xView.is())
758 {
759 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
760 mpPaneContainer->RemoveView(xView));
761
762 // A possibly opaque view has been removed. Update()
763 // updates the clip polygon.
764 mpWindowManager->Update();
765 // Request the repainting of the area previously
766 // occupied by the view.
767 if (pDescriptor)
768 GetPaintManager()->Invalidate(pDescriptor->mxBorderWindow);
769 }
770 }
771 break;
772
773 case ConfigurationUpdateEndEventType:
774 if (IsAccessibilityActive())
775 {
776 mpAccessibleObject->UpdateAccessibilityHierarchy();
777 UpdateCurrentSlide(0);
778 }
779 break;
780 }
781}
782
783//----- XEventListener --------------------------------------------------------
784
785void SAL_CALL PresenterController::disposing (
786 const lang::EventObject& rEvent)
787{
788 if (rEvent.Source == mxController)
789 mxController = nullptr;
790 else if (rEvent.Source == mxConfigurationController)
791 mxConfigurationController = nullptr;
792 else if (rEvent.Source == mxSlideShowController)
793 mxSlideShowController = nullptr;
794 else if (rEvent.Source == mxMainWindow)
795 mxMainWindow = nullptr;
796}
797
798//----- XFrameActionListener --------------------------------------------------
799
800void SAL_CALL PresenterController::frameAction (
801 const frame::FrameActionEvent& rEvent)
802{
803 if (rEvent.Action == frame::FrameAction_FRAME_ACTIVATED)
804 {
805 if (mxSlideShowController.is())
806 mxSlideShowController->activate();
807 }
808}
809
810//----- XKeyListener ----------------------------------------------------------
811
812void SAL_CALL PresenterController::keyPressed (const awt::KeyEvent& rEvent)
813{
814 // Tell all views about the unhandled key event.
815 for (const auto& rxPane : mpPaneContainer->maPanes)
816 {
817 if ( ! rxPane->mbIsActive)
818 continue;
819
820 Reference<awt::XKeyListener> xKeyListener (rxPane->mxView, UNO_QUERY);
821 if (xKeyListener.is())
822 xKeyListener->keyPressed(rEvent);
823 }
824}
825
826void SAL_CALL PresenterController::keyReleased (const awt::KeyEvent& rEvent)
827{
828 if (rEvent.Source != mxMainWindow)
829 return;
830
831 switch (rEvent.KeyCode)
832 {
833 case awt::Key::ESCAPE:
834 case awt::Key::SUBTRACT:
835 {
836 if( mxController.is() )
837 {
838 Reference< XPresentationSupplier > xPS( mxController->getModel(), UNO_QUERY );
839 if( xPS.is() )
840 {
841 Reference< XPresentation > xP( xPS->getPresentation() );
842 if( xP.is() )
843 xP->end();
844 }
845 }
846 }
847 break;
848
849 case awt::Key::PAGEDOWN:
850 if (mxSlideShowController.is())
851 {
852 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
853 mxSlideShowController->gotoNextSlide();
854 else
855 mxSlideShowController->gotoNextEffect();
856 }
857 break;
858
859 case awt::Key::RIGHT:
860 case awt::Key::SPACE:
861 case awt::Key::DOWN:
862 case awt::Key::N:
863 if (mxSlideShowController.is())
864 {
865 mxSlideShowController->gotoNextEffect();
866 }
867 break;
868
869 case awt::Key::PAGEUP:
870 if (mxSlideShowController.is())
871 {
872 if (rEvent.Modifiers == awt::KeyModifier::MOD2)
873 mxSlideShowController->gotoPreviousSlide();
874 else
875 mxSlideShowController->gotoPreviousEffect();
876 }
877 break;
878
879 case awt::Key::LEFT:
880 case awt::Key::UP:
881 case awt::Key::P:
882 case awt::Key::BACKSPACE:
883 if (mxSlideShowController.is())
884 {
885 mxSlideShowController->gotoPreviousEffect();
886 }
887 break;
888
889 case awt::Key::HOME:
890 if (mxSlideShowController.is())
891 {
892 mxSlideShowController->gotoFirstSlide();
893 }
894 break;
895
896 case awt::Key::END:
897 if (mxSlideShowController.is())
898 {
899 mxSlideShowController->gotoLastSlide();
900 }
901 break;
902
903 case awt::Key::W:
904 case awt::Key::COMMA:
905 if (mxSlideShowController.is())
906 {
907 if (mxSlideShowController->isPaused())
908 mxSlideShowController->resume();
909 else
910 mxSlideShowController->blankScreen(0x00ffffff);
911 }
912 break;
913
914 case awt::Key::B:
915 case awt::Key::POINT:
916 if (mxSlideShowController.is())
917 {
918 if (mxSlideShowController->isPaused())
919 mxSlideShowController->resume();
920 else
921 mxSlideShowController->blankScreen(0x00000000);
922 }
923 break;
924
925 case awt::Key::NUM0:
926 case awt::Key::NUM1:
927 case awt::Key::NUM2:
928 case awt::Key::NUM3:
929 case awt::Key::NUM4:
930 case awt::Key::NUM5:
931 case awt::Key::NUM6:
932 case awt::Key::NUM7:
933 case awt::Key::NUM8:
934 case awt::Key::NUM9:
935 HandleNumericKeyPress(rEvent.KeyCode-awt::Key::NUM0, rEvent.Modifiers);
936 break;
937
938 case awt::Key::RETURN:
939 if (mnPendingSlideNumber > 0)
940 {
941 if (mxSlideShowController.is())
942 mxSlideShowController->gotoSlideIndex(mnPendingSlideNumber - 1);
943 mnPendingSlideNumber = -1;
944 }
945 else
946 {
947 if (mxSlideShowController.is())
948 mxSlideShowController->gotoNextEffect();
949 }
950
951 break;
952
953 case awt::Key::F1:
954 // Toggle the help view.
955 if (mpWindowManager)
956 {
957 if (mpWindowManager->GetViewMode() != PresenterWindowManager::VM_Help)
958 mpWindowManager->SetViewMode(PresenterWindowManager::VM_Help);
959 else
960 mpWindowManager->SetHelpViewState(false);
961 }
962
963 break;
964
965 default:
966 // Tell all views about the unhandled key event.
967 for (const auto& rxPane : mpPaneContainer->maPanes)
968 {
969 if ( ! rxPane->mbIsActive)
970 continue;
971
972 Reference<awt::XKeyListener> xKeyListener (rxPane->mxView, UNO_QUERY);
973 if (xKeyListener.is())
974 xKeyListener->keyReleased(rEvent);
975 }
976 break;
977 }
978}
979
980void PresenterController::HandleNumericKeyPress (
981 const sal_Int32 nKey,
982 const sal_Int32 nModifiers)
983{
984 switch (nModifiers)
985 {
986 case 0:
987 if (mnPendingSlideNumber == -1)
988 mnPendingSlideNumber = 0;
989 UpdatePendingSlideNumber(mnPendingSlideNumber * 10 + nKey);
990 break;
991
992 case awt::KeyModifier::MOD1:
993 // Ctrl-1, Ctrl-2, and Ctrl-3 are used to switch between views
994 // (slide view, notes view, normal). Ctrl-4 switches monitors
995 mnPendingSlideNumber = -1;
996 if (!mpWindowManager)
997 return;
998 switch(nKey)
999 {
1000 case 1:
1001 mpWindowManager->SetViewMode(PresenterWindowManager::VM_Standard);
1002 break;
1003 case 2:
1004 mpWindowManager->SetViewMode(PresenterWindowManager::VM_Notes);
1005 break;
1006 case 3:
1007 mpWindowManager->SetViewMode(PresenterWindowManager::VM_SlideOverview);
1008 break;
1009 case 4:
1010 SwitchMonitors();
1011 break;
1012 default:
1013 // Ignore unsupported key.
1014 break;
1015 }
1016 break;
1017
1018 default:
1019 // Ignore unsupported modifiers.
1020 break;
1021 }
1022}
1023
1024//----- XMouseListener --------------------------------------------------------
1025
1026void SAL_CALL PresenterController::mousePressed (const css::awt::MouseEvent&)
1027{
1028 if (mxMainWindow.is())
1029 mxMainWindow->setFocus();
1030}
1031
1032void SAL_CALL PresenterController::mouseReleased (const css::awt::MouseEvent&) {}
1033
1034void SAL_CALL PresenterController::mouseEntered (const css::awt::MouseEvent&) {}
1035
1036void SAL_CALL PresenterController::mouseExited (const css::awt::MouseEvent&) {}
1037
1038void PresenterController::InitializeMainPane (const Reference<XPane>& rxPane)
1039{
1040 if ( ! rxPane.is())
1041 return;
1042
1043 mpAccessibleObject = new PresenterAccessible(
1044 mxComponentContext,
1045 this,
1046 rxPane);
1047
1048 LoadTheme(rxPane);
1049
1050 // Main pane has been created and is now observed by the window
1051 // manager.
1052 mpWindowManager->SetParentPane(rxPane);
1053 mpWindowManager->SetTheme(mpTheme);
1054
1055 if (mpPaneBorderPainter)
1056 mpPaneBorderPainter->SetTheme(mpTheme);
1057
1058 // Add key listener
1059 mxMainWindow = rxPane->getWindow();
1060 if (mxMainWindow.is())
1061 {
1062 mxMainWindow->addKeyListener(this);
1063 mxMainWindow->addMouseListener(this);
1064 }
1065 Reference<XPane2> xPane2 (rxPane, UNO_QUERY);
1066 if (xPane2.is())
1067 xPane2->setVisible(true);
1068
1069 mpPaintManager = std::make_shared<PresenterPaintManager>(mxMainWindow, mxPresenterHelper, mpPaneContainer);
1070
1071 mxCanvas.set(rxPane->getCanvas(), UNO_QUERY);
1072
1073 if (mxSlideShowController.is())
1074 mxSlideShowController->activate();
1075
1076 UpdateCurrentSlide(0);
1077}
1078
1079void PresenterController::LoadTheme (const Reference<XPane>& rxPane)
1080{
1081 // Create (load) the current theme.
1082 if (rxPane.is())
1083 mpTheme = std::make_shared<PresenterTheme>(mxComponentContext, rxPane->getCanvas());
1084}
1085
1086double PresenterController::GetSlideAspectRatio() const
1087{
1088 double nSlideAspectRatio (28.0/21.0);
1089
1090 try
1091 {
1092 if (mxController.is())
1093 {
1094 Reference<drawing::XDrawPagesSupplier> xSlideSupplier (
1095 mxController->getModel(), UNO_QUERY_THROW);
1096 Reference<drawing::XDrawPages> xSlides (xSlideSupplier->getDrawPages());
1097 if (xSlides.is() && xSlides->getCount()>0)
1098 {
1099 Reference<beans::XPropertySet> xProperties(xSlides->getByIndex(0),UNO_QUERY_THROW);
1100 sal_Int32 nWidth (28000);
1101 sal_Int32 nHeight (21000);
1102 if ((xProperties->getPropertyValue("Width") >>= nWidth)
1103 && (xProperties->getPropertyValue("Height") >>= nHeight)
1104 && nHeight > 0)
1105 {
1106 nSlideAspectRatio = double(nWidth) / double(nHeight);
1107 }
1108 }
1109 }
1110 }
1111 catch (RuntimeException&)
1112 {
1113 OSL_ASSERT(false)do { if (true && (!(false))) { sal_detail_logFormat((
SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sdext/source/presenter/PresenterController.cxx"
":" "1113" ": "), "OSL_ASSERT: %s", "false"); } } while (false
)
;
1114 }
1115
1116 return nSlideAspectRatio;
1117}
1118
1119void PresenterController::UpdatePendingSlideNumber (const sal_Int32 nPendingSlideNumber)
1120{
1121 mnPendingSlideNumber = nPendingSlideNumber;
1122
1123 if (mpTheme == nullptr)
1124 return;
1125
1126 if ( ! mxMainWindow.is())
1127 return;
1128
1129 PresenterTheme::SharedFontDescriptor pFont (
1130 mpTheme->GetFont("PendingSlideNumberFont"));
1131 if (!pFont)
1132 return;
1133
1134 pFont->PrepareFont(mxCanvas);
1135 if ( ! pFont->mxFont.is())
1136 return;
1137
1138 const OUString sText (OUString::number(mnPendingSlideNumber));
1139 rendering::StringContext aContext (sText, 0, sText.getLength());
1140 pFont->mxFont->createTextLayout(
1141 aContext,
1142 rendering::TextDirection::WEAK_LEFT_TO_RIGHT,
1143 0);
1144}
1145
1146void PresenterController::SwitchMonitors()
1147{
1148 Reference<lang::XEventListener> xScreen( mxScreen );
1149 if (!xScreen.is())
1150 return;
1151
1152 PresenterScreen *pScreen = dynamic_cast<PresenterScreen *>(xScreen.get());
1153 if (!pScreen)
1154 return;
1155
1156 pScreen->SwitchMonitors();
1157}
1158
1159void PresenterController::ExitPresenter()
1160{
1161 if( mxController.is() )
1162 {
1163 Reference< XPresentationSupplier > xPS( mxController->getModel(), UNO_QUERY );
1164 if( xPS.is() )
1165 {
1166 Reference< XPresentation > xP( xPS->getPresentation() );
1167 if( xP.is() )
1168 xP->end();
1169 }
1170 }
1171}
1172
1173} // end of namespace ::sdext::presenter
1174
1175/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h

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_COM_SUN_STAR_UNO_REFERENCE_H
20#define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H
21
22#include "sal/config.h"
23
24#include <cassert>
25#include <cstddef>
26
27#if defined LIBO_INTERNAL_ONLY1
28#include <type_traits>
29#endif
30
31#include "rtl/alloc.h"
32
33namespace com
34{
35namespace sun
36{
37namespace star
38{
39namespace uno
40{
41
42class RuntimeException;
43class XInterface;
44class Type;
45class Any;
46
47/** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface.
48 Deprecated, please use SAL_NO_ACQUIRE.
49 @deprecated
50*/
51enum UnoReference_NoAcquire
52{
53 /** This enum value can be used for creating a reference granting a given interface,
54 i.e. transferring ownership to it.
55 */
56 UNO_REF_NO_ACQUIRE
57};
58
59/** This base class serves as a base class for all template reference classes and
60 has been introduced due to compiler problems with templated operators ==, =!.
61*/
62class BaseReference
63{
64protected:
65 /** the interface pointer
66 */
67 XInterface * _pInterface;
68
69 /** Queries given interface for type rType.
70
71 @param pInterface interface pointer
72 @param rType interface type
73 @return interface of demanded type (may be null)
74 */
75 inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType );
76 /** Queries given interface for type rType.
77 Throws a RuntimeException if the demanded interface cannot be queried.
78
79 @param pInterface interface pointer
80 @param rType interface type
81 @return interface of demanded type
82 */
83 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType );
84
85public:
86 /** Gets interface pointer. This call does not acquire the interface.
87
88 @return UNacquired interface pointer
89 */
90 XInterface * SAL_CALL get() const
91 { return _pInterface; }
92
93 /** Checks if reference is null.
94
95 @return true if reference acquires an interface, i.e. true if it is not null
96 */
97 bool SAL_CALL is() const
98 { return (NULL__null != _pInterface); }
5
Assuming NULL is not equal to field '_pInterface'
6
Returning the value 1, which participates in a condition later
99
100#if defined LIBO_INTERNAL_ONLY1
101 /** Checks if reference is null.
102
103 @return true if reference acquires an interface, i.e. true if it is not null
104 */
105 explicit operator bool() const
106 { return is(); }
107#endif
108
109 /** Equality operator: compares two interfaces
110 Checks if both references are null or refer to the same object.
111
112 @param pInterface another interface
113 @return true if both references are null or refer to the same object, false otherwise
114 */
115 inline bool SAL_CALL operator == ( XInterface * pInterface ) const;
116 /** Inequality operator: compares two interfaces
117 Checks if both references are null or refer to the same object.
118
119 @param pInterface another interface
120 @return false if both references are null or refer to the same object, true otherwise
121 */
122 inline bool SAL_CALL operator != ( XInterface * pInterface ) const;
123
124 /** Equality operator: compares two interfaces
125 Checks if both references are null or refer to the same object.
126
127 @param rRef another reference
128 @return true if both references are null or refer to the same object, false otherwise
129 */
130 inline bool SAL_CALL operator == ( const BaseReference & rRef ) const;
131 /** Inequality operator: compares two interfaces
132 Checks if both references are null or refer to the same object.
133
134 @param rRef another reference
135 @return false if both references are null or refer to the same object, true otherwise
136 */
137 inline bool SAL_CALL operator != ( const BaseReference & rRef ) const;
138
139 /** Needed by some STL containers.
140
141 @param rRef another reference
142 @return true, if this reference is less than rRef
143 */
144 inline bool SAL_CALL operator < ( const BaseReference & rRef ) const;
145};
146
147/** Enum defining UNO_QUERY for implicit interface query.
148*/
149enum UnoReference_Query
150{
151 /** This enum value can be used for implicit interface query.
152 */
153 UNO_QUERY
154};
155/** Enum defining UNO_QUERY_THROW for implicit interface query.
156 If the demanded interface is unavailable, then a RuntimeException is thrown.
157*/
158enum UnoReference_QueryThrow
159{
160 /** This enum value can be used for implicit interface query.
161 */
162 UNO_QUERY_THROW
163};
164/** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null
165 interface
166
167 @since UDK 3.2.8
168*/
169enum UnoReference_SetThrow
170{
171 UNO_SET_THROW
172};
173
174/** Template reference class for interface type derived from BaseReference.
175 A special constructor given the UNO_QUERY identifier queries interfaces
176 for reference type.
177*/
178template< class interface_type >
179class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) Reference : public BaseReference
180{
181 /** Queries given interface for type interface_type.
182
183 @param pInterface interface pointer
184 @return interface of demanded type (may be null)
185 */
186 inline static XInterface * SAL_CALL iquery( XInterface * pInterface );
187 /** Queries given interface for type interface_type.
188 Throws a RuntimeException if the demanded interface cannot be queried.
189
190 @param pInterface interface pointer
191 @return interface of demanded type
192 */
193 inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface );
194 /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise.
195
196 @param pInterface interface pointer
197 @return pInterface
198 */
199 inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface );
200
201 /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a
202 pointer to this interface_type.
203
204 To work around ambiguities in the case of multiple-inheritance interface
205 types (which inherit XInterface more than once), use reinterpret_cast
206 (resp. a sequence of two static_casts, to avoid warnings about
207 reinterpret_cast used between related classes) to switch from a pointer
208 to XInterface to a pointer to this derived interface_type. In
209 principle, this is not guaranteed to work. In practice, it seems to
210 work on all supported platforms.
211 */
212 static interface_type * castFromXInterface(XInterface * p) {
213 return static_cast< interface_type * >(static_cast< void * >(p));
214 }
215
216 /** Cast from a pointer to this interface_type to an "interface pointer"
217 (e.g., BaseReference::_pInterface).
218
219 To work around ambiguities in the case of multiple-inheritance interface
220 types (which inherit XInterface more than once), use reinterpret_cast
221 (resp. a sequence of two static_casts, to avoid warnings about
222 reinterpret_cast used between related classes) to switch from a pointer
223 to this derived interface_type to a pointer to XInterface. In
224 principle, this is not guaranteed to work. In practice, it seems to
225 work on all supported platforms.
226 */
227 static XInterface * castToXInterface(interface_type * p) {
228 return static_cast< XInterface * >(static_cast< void * >(p));
229 }
230
231public:
232 /// @cond INTERNAL
233 // these are here to force memory de/allocation to sal lib.
234 static void * SAL_CALL operator new ( ::size_t nSize )
235 { return ::rtl_allocateMemory( nSize ); }
236 static void SAL_CALL operator delete ( void * pMem )
237 { ::rtl_freeMemory( pMem ); }
238 static void * SAL_CALL operator new ( ::size_t, void * pMem )
239 { return pMem; }
240 static void SAL_CALL operator delete ( void *, void * )
241 {}
242 /// @endcond
243
244 /** Destructor: Releases interface if set.
245 */
246 inline ~Reference() COVERITY_NOEXCEPT_FALSE;
247
248 /** Default Constructor: Sets null reference.
249 */
250 inline Reference();
251
252 /** Copy constructor: Copies interface reference.
253
254 @param rRef another reference
255 */
256 inline Reference( const Reference< interface_type > & rRef );
257
258#if defined LIBO_INTERNAL_ONLY1
259 /** Move constructor
260
261 @param rRef another reference
262 */
263 inline Reference( Reference< interface_type > && rRef ) noexcept;
264
265 /** Up-casting conversion constructor: Copies interface reference.
266
267 Does not work for up-casts to ambiguous bases. For the special case of
268 up-casting to Reference< XInterface >, see the corresponding conversion
269 operator.
270
271 @param rRef another reference
272 */
273 template< class derived_type >
274 inline Reference(
275 const Reference< derived_type > & rRef,
276 std::enable_if_t<
277 std::is_base_of_v<interface_type, derived_type>
278 && !std::is_same_v<interface_type, XInterface>, void *> = nullptr);
279#endif
280
281 /** Constructor: Sets given interface pointer.
282
283 @param pInterface an interface pointer
284 */
285 inline Reference( interface_type * pInterface );
286
287 /** Constructor: Sets given interface pointer without acquiring it.
288
289 @param pInterface another reference
290 @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors
291 */
292 inline Reference( interface_type * pInterface, __sal_NoAcquire dummy);
293 /** Constructor: Sets given interface pointer without acquiring it.
294 Deprecated, please use SAL_NO_ACQUIRE version.
295
296 @deprecated
297 @param pInterface another reference
298 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors
299 */
300 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) Reference( interface_type * pInterface, UnoReference_NoAcquire dummy );
301
302 /** Constructor: Queries given interface for reference interface type (interface_type).
303
304 @param rRef another reference
305 @param dummy UNO_QUERY to force obvious distinction to other constructors
306 */
307 inline Reference( const BaseReference & rRef, UnoReference_Query dummy );
308 /** Constructor: Queries given interface for reference interface type (interface_type).
309
310 @param pInterface an interface pointer
311 @param dummy UNO_QUERY to force obvious distinction to other constructors
312 */
313 inline Reference( XInterface * pInterface, UnoReference_Query dummy);
314 /** Constructor: Queries given any for reference interface type (interface_type).
315
316 @param rAny an any
317 @param dummy UNO_QUERY to force obvious distinction to other constructors
318 */
319 inline Reference( const Any & rAny, UnoReference_Query dummy);
320 /** Constructor: Queries given interface for reference interface type (interface_type).
321 Throws a RuntimeException if the demanded interface cannot be queried.
322
323 @param rRef another reference
324 @param dummy UNO_QUERY_THROW to force obvious distinction
325 to other constructors
326 */
327 inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy );
328#ifdef LIBO_INTERNAL_ONLY1
329 /**
330 Prevent code from calling the QUERY_THROW constructor, when they meant to use the SET_THROW constructor.
331 */
332 Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
333#endif
334 /** Constructor: Queries given interface for reference interface type (interface_type).
335 Throws a RuntimeException if the demanded interface cannot be queried.
336
337 @param pInterface an interface pointer
338 @param dummy UNO_QUERY_THROW to force obvious distinction
339 to other constructors
340 */
341 inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy );
342 /** Constructor: Queries given any for reference interface type (interface_type).
343 Throws a RuntimeException if the demanded interface cannot be queried.
344
345 @param rAny an any
346 @param dummy UNO_QUERY_THROW to force obvious distinction
347 to other constructors
348 */
349 inline Reference( const Any & rAny, UnoReference_QueryThrow dummy );
350 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
351 if the source interface is NULL.
352
353 @param rRef another interface reference of the same type
354 @param dummy UNO_SET_THROW to distinguish from default copy constructor
355
356 @since UDK 3.2.8
357 */
358 inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy );
359 /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException
360 if the source interface is NULL.
361
362 @param pInterface an interface pointer
363 @param dummy UNO_SET_THROW to distinguish from default assignment constructor
364
365 @since UDK 3.2.8
366 */
367 inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy );
368
369 /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and
370 any interface must be derived from com.sun.star.uno.XInterface.
371 This a useful direct cast possibility.
372 */
373 SAL_CALL operator const Reference< XInterface > & () const
374 { return * reinterpret_cast< const Reference< XInterface > * >( this ); }
375
376 /** Dereference operator: Used to call interface methods.
377
378 @return UNacquired interface pointer
379 */
380 interface_type * SAL_CALL operator -> () const {
381 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 381, __extension__ __PRETTY_FUNCTION__))
;
382 return castFromXInterface(_pInterface);
383 }
384
385 /** Indirection operator.
386
387 @since LibreOffice 6.3
388 @return UNacquired interface reference
389 */
390 interface_type & SAL_CALL operator * () const {
391 assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) :
__assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h"
, 391, __extension__ __PRETTY_FUNCTION__))
;
392 return *castFromXInterface(_pInterface);
393 }
394
395 /** Gets interface pointer. This call does not acquire the interface.
396
397 @return UNacquired interface pointer
398 */
399 interface_type * SAL_CALL get() const
400 { return castFromXInterface(_pInterface); }
401
402 /** Clears reference, i.e. releases interface. Reference is null after clear() call.
403 */
404 inline void SAL_CALL clear();
405
406 /** Sets the given interface. An interface already set will be released.
407
408 @param rRef another reference
409 @return true, if non-null interface was set
410 */
411 inline bool SAL_CALL set( const Reference< interface_type > & rRef );
412 /** Sets the given interface. An interface already set will be released.
413
414 @param pInterface another interface
415 @return true, if non-null interface was set
416 */
417 inline bool SAL_CALL set( interface_type * pInterface );
418
419 /** Sets interface pointer without acquiring it. An interface already set will be released.
420
421 @param pInterface an interface pointer
422 @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods
423 @return true, if non-null interface was set
424 */
425 inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy);
426 /** Sets interface pointer without acquiring it. An interface already set will be released.
427 Deprecated, please use SAL_NO_ACQUIRE version.
428
429 @deprecated
430 @param pInterface an interface pointer
431 @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods
432 @return true, if non-null interface was set
433 */
434 inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy);
435
436 /** Queries given interface for reference interface type (interface_type) and sets it.
437 An interface already set will be released.
438
439 @param pInterface an interface pointer
440 @param dummy UNO_QUERY to force obvious distinction to set methods
441 @return true, if non-null interface was set
442 */
443 inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy );
444 /** Queries given interface for reference interface type (interface_type) and sets it.
445 An interface already set will be released.
446
447 @param rRef another reference
448 @param dummy UNO_QUERY to force obvious distinction to set methods
449 @return true, if non-null interface was set
450 */
451 inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy);
452
453 /** Queries given any for reference interface type (interface_type)
454 and sets it. An interface already set will be released.
455
456 @param rAny
457 an Any containing an interface
458 @param dummy
459 UNO_QUERY to force obvious distinction
460 to set methods
461 @return
462 true, if non-null interface was set
463 */
464 inline bool set( Any const & rAny, UnoReference_Query dummy );
465
466 /** Queries given interface for reference interface type (interface_type) and sets it.
467 An interface already set will be released.
468 Throws a RuntimeException if the demanded interface cannot be set.
469
470 @param pInterface an interface pointer
471 @param dummy UNO_QUERY_THROW to force obvious distinction
472 to set methods
473 */
474 inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy );
475 /** Queries given interface for reference interface type (interface_type) and sets it.
476 An interface already set will be released.
477 Throws a RuntimeException if the demanded interface cannot be set.
478
479 @param rRef another reference
480 @param dummy UNO_QUERY_THROW to force obvious distinction
481 to set methods
482 */
483 inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy );
484#ifdef LIBO_INTERNAL_ONLY1
485 /**
486 Prevent code from calling the QUERY_THROW version, when they meant to use the SET_THROW version.
487 */
488 void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete;
489#endif
490
491 /** Queries given any for reference interface type (interface_type) and
492 sets it. An interface already set will be released.
493 Throws a RuntimeException if the demanded interface cannot be set.
494
495 @param rAny
496 an Any containing an interface
497 @param dummy
498 UNO_QUERY_THROW to force obvious distinction to set methods
499 */
500 inline void set( Any const & rAny, UnoReference_QueryThrow dummy);
501 /** sets the given interface
502 An interface already set will be released.
503 Throws a RuntimeException if the source interface is @b NULL.
504
505 @param pInterface an interface pointer
506 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
507
508 @since UDK 3.2.8
509 */
510 inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy);
511 /** sets the given interface
512 An interface already set will be released.
513 Throws a RuntimeException if the source interface is @b NULL.
514
515 @param rRef an interface reference
516 @param dummy UNO_SET_THROW to force obvious distinction to other set methods
517
518 @since UDK 3.2.8
519 */
520 inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy);
521
522
523 /** Assignment operator: Acquires given interface pointer and sets reference.
524 An interface already set will be released.
525
526 @param pInterface an interface pointer
527 @return this reference
528 */
529 inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface );
530 /** Assignment operator: Acquires given interface reference and sets reference.
531 An interface already set will be released.
532
533 @param rRef an interface reference
534 @return this reference
535 */
536 inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef );
537#if defined LIBO_INTERNAL_ONLY1
538 /** Assignment move operator: Acquires given interface reference and sets reference.
539 An interface already set will be released.
540
541 @param rRef an interface reference
542 @return this reference
543 */
544 inline Reference< interface_type > & SAL_CALL operator = ( Reference< interface_type > && rRef ) noexcept;
545#endif
546 /** Queries given interface reference for type interface_type.
547
548 @param rRef interface reference
549 @return interface reference of demanded type (may be null)
550 */
551 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef );
552 /** Queries given interface for type interface_type.
553
554 @param pInterface interface pointer
555 @return interface reference of demanded type (may be null)
556 */
557 SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface );
558};
559
560}
561}
562}
563}
564
565#endif
566
567/* vim:set shiftwidth=4 softtabstop=4 expandtab: */