Bug Summary

File:home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.cxx
Warning:line 177, column 5
Use of memory after it is freed

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name accessibledialogcontrolshape.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/basctl/inc -I /home/maarten/src/libreoffice/core/basctl/sdi -I /home/maarten/src/libreoffice/core/basctl/source/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/workdir/SdiTarget/basctl/sdi -I /home/maarten/src/libreoffice/core/workdir/CustomTarget/officecfg/registry -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/basctl/source/accessibility/accessibledialogcontrolshape.cxx

/home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.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 <accessibledialogcontrolshape.hxx>
21#include <baside3.hxx>
22#include <dlgeddef.hxx>
23#include <dlgedview.hxx>
24#include <dlgedobj.hxx>
25#include <com/sun/star/accessibility/AccessibleEventId.hpp>
26#include <com/sun/star/accessibility/AccessibleRole.hpp>
27#include <com/sun/star/accessibility/AccessibleStateType.hpp>
28#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29#include <cppuhelper/supportsservice.hxx>
30#include <unotools/accessiblestatesethelper.hxx>
31#include <unotools/accessiblerelationsethelper.hxx>
32#include <toolkit/awt/vclxfont.hxx>
33#include <toolkit/helper/convert.hxx>
34#include <toolkit/helper/vclunohelper.hxx>
35#include <tools/diagnose_ex.h>
36#include <vcl/svapp.hxx>
37#include <vcl/settings.hxx>
38#include <i18nlangtag/languagetag.hxx>
39
40namespace basctl
41{
42
43using namespace ::com::sun::star;
44using namespace ::com::sun::star::uno;
45using namespace ::com::sun::star::lang;
46using namespace ::com::sun::star::beans;
47using namespace ::com::sun::star::accessibility;
48using namespace ::comphelper;
49
50
51
52
53AccessibleDialogControlShape::AccessibleDialogControlShape (DialogWindow* pDialogWindow, DlgEdObj* pDlgEdObj)
54 :m_pDialogWindow( pDialogWindow )
55 ,m_pDlgEdObj( pDlgEdObj )
56{
57 if ( m_pDlgEdObj )
58 m_xControlModel.set( m_pDlgEdObj->GetUnoControlModel(), UNO_QUERY );
59
60 if ( m_xControlModel.is() )
61 m_xControlModel->addPropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
62
63 m_bFocused = IsFocused();
64 m_bSelected = IsSelected();
65 m_aBounds = GetBounds();
66}
67
68
69AccessibleDialogControlShape::~AccessibleDialogControlShape()
70{
71 if ( m_xControlModel.is() )
72 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
73}
74
75
76bool AccessibleDialogControlShape::IsFocused() const
77{
78 bool bFocused = false;
79 if ( m_pDialogWindow )
80 {
81 SdrView& rView = m_pDialogWindow->GetView();
82 if (rView.IsObjMarked(m_pDlgEdObj) && rView.GetMarkedObjectList().GetMarkCount() == 1)
83 bFocused = true;
84 }
85
86 return bFocused;
87}
88
89
90bool AccessibleDialogControlShape::IsSelected() const
91{
92 if ( m_pDialogWindow )
93 return m_pDialogWindow->GetView().IsObjMarked(m_pDlgEdObj);
94 return false;
95}
96
97
98void AccessibleDialogControlShape::SetFocused( bool bFocused )
99{
100 if ( m_bFocused != bFocused )
101 {
102 Any aOldValue, aNewValue;
103 if ( m_bFocused )
104 aOldValue <<= AccessibleStateType::FOCUSED;
105 else
106 aNewValue <<= AccessibleStateType::FOCUSED;
107 m_bFocused = bFocused;
108 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
109 }
110}
111
112
113void AccessibleDialogControlShape::SetSelected( bool bSelected )
114{
115 if ( m_bSelected != bSelected )
116 {
117 Any aOldValue, aNewValue;
118 if ( m_bSelected )
119 aOldValue <<= AccessibleStateType::SELECTED;
120 else
121 aNewValue <<= AccessibleStateType::SELECTED;
122 m_bSelected = bSelected;
123 NotifyAccessibleEvent( AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue );
124 }
125}
126
127
128awt::Rectangle AccessibleDialogControlShape::GetBounds() const
129{
130 awt::Rectangle aBounds( 0, 0, 0, 0 );
131 if ( m_pDlgEdObj )
132 {
133 // get the bounding box of the shape in logic units
134 tools::Rectangle aRect = m_pDlgEdObj->GetSnapRect();
135
136 if ( m_pDialogWindow )
137 {
138 // transform coordinates relative to the parent
139 MapMode aMap = m_pDialogWindow->GetMapMode();
140 Point aOrg = aMap.GetOrigin();
141 aRect.Move( aOrg.X(), aOrg.Y() );
142
143 // convert logic units to pixel
144 aRect = m_pDialogWindow->LogicToPixel( aRect, MapMode(MapUnit::Map100thMM) );
145
146 // clip the shape's bounding box with the bounding box of its parent
147 tools::Rectangle aParentRect( Point( 0, 0 ), m_pDialogWindow->GetSizePixel() );
148 aRect = aRect.GetIntersection( aParentRect );
149 aBounds = AWTRectangle( aRect );
150 }
151 }
152
153 return aBounds;
154}
155
156
157void AccessibleDialogControlShape::SetBounds( const awt::Rectangle& aBounds )
158{
159 if ( m_aBounds.X != aBounds.X || m_aBounds.Y != aBounds.Y || m_aBounds.Width != aBounds.Width || m_aBounds.Height != aBounds.Height )
160 {
161 m_aBounds = aBounds;
162 NotifyAccessibleEvent( AccessibleEventId::BOUNDRECT_CHANGED, Any(), Any() );
163 }
164}
165
166
167vcl::Window* AccessibleDialogControlShape::GetWindow() const
168{
169 vcl::Window* pWindow = nullptr;
170 if ( m_pDlgEdObj )
2
Assuming field 'm_pDlgEdObj' is non-null
3
Taking true branch
171 {
172 Reference< awt::XControl > xControl = m_pDlgEdObj->GetControl();
173 if ( xControl.is() )
4
Taking true branch
174 pWindow = VCLUnoHelper::GetWindow( xControl->getPeer() ).get();
5
Calling implicit destructor for 'VclPtr<vcl::Window>'
6
Calling '~Reference'
14
Returning from '~Reference'
15
Returning from destructor for 'VclPtr<vcl::Window>'
175 }
176
177 return pWindow;
16
Use of memory after it is freed
178}
179
180
181OUString AccessibleDialogControlShape::GetModelStringProperty( OUString const & pPropertyName )
182{
183 OUString sReturn;
184
185 try
186 {
187 if ( m_xControlModel.is() )
188 {
189 Reference< XPropertySetInfo > xInfo = m_xControlModel->getPropertySetInfo();
190 if ( xInfo.is() && xInfo->hasPropertyByName( pPropertyName ) )
191 m_xControlModel->getPropertyValue( pPropertyName ) >>= sReturn;
192 }
193 }
194 catch ( const Exception& )
195 {
196 TOOLS_WARN_EXCEPTION( "basctl", "AccessibleDialogControlShape::GetModelStringProperty" )do { css::uno::Any tools_warn_exception( DbgGetCaughtException
() ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN
, "basctl")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case
SAL_DETAIL_LOG_ACTION_LOG: if (sizeof ::sal::detail::getResult
( ::sal::detail::StreamStart() << "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"basctl"), ("/home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.cxx"
":" "196" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("basctl"
), ("/home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.cxx"
":" "196" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL
: if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart
() << "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
)) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), (
"basctl"), ("/home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.cxx"
":" "196" ": "), ::sal::detail::unwrapStream( ::sal::detail::
StreamStart() << "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
)), 0); } else { ::std::ostringstream sal_detail_stream; sal_detail_stream
<< "AccessibleDialogControlShape::GetModelStringProperty"
<< " " << exceptionToString(tools_warn_exception
); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN), ("basctl"
), ("/home/maarten/src/libreoffice/core/basctl/source/accessibility/accessibledialogcontrolshape.cxx"
":" "196" ": "), sal_detail_stream, 0); }; std::abort(); break
; } } } while (false); } while (false)
;
197 }
198
199 return sReturn;
200}
201
202
203void AccessibleDialogControlShape::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet )
204{
205 rStateSet.AddState( AccessibleStateType::ENABLED );
206
207 rStateSet.AddState( AccessibleStateType::VISIBLE );
208
209 rStateSet.AddState( AccessibleStateType::SHOWING );
210
211 rStateSet.AddState( AccessibleStateType::FOCUSABLE );
212
213 if ( IsFocused() )
214 rStateSet.AddState( AccessibleStateType::FOCUSED );
215
216 rStateSet.AddState( AccessibleStateType::SELECTABLE );
217
218 if ( IsSelected() )
219 rStateSet.AddState( AccessibleStateType::SELECTED );
220
221 rStateSet.AddState( AccessibleStateType::RESIZABLE );
222}
223
224// OCommonAccessibleComponent
225awt::Rectangle AccessibleDialogControlShape::implGetBounds()
226{
227 return GetBounds();
228}
229
230// XInterface
231IMPLEMENT_FORWARD_XINTERFACE2( AccessibleDialogControlShape, OAccessibleExtendedComponentHelper, AccessibleDialogControlShape_BASE )void AccessibleDialogControlShape::acquire() throw() { OAccessibleExtendedComponentHelper
::acquire(); } void AccessibleDialogControlShape::release() throw
() { OAccessibleExtendedComponentHelper::release(); } css::uno
::Any AccessibleDialogControlShape::queryInterface( const css
::uno::Type& _rType ) { css::uno::Any aReturn = OAccessibleExtendedComponentHelper
::queryInterface( _rType ); if ( !aReturn.hasValue() ) aReturn
= AccessibleDialogControlShape_BASE::queryInterface( _rType )
; return aReturn; }
232
233// XTypeProvider
234IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleDialogControlShape, OAccessibleExtendedComponentHelper, AccessibleDialogControlShape_BASE )css::uno::Sequence< css::uno::Type > AccessibleDialogControlShape
::getTypes( ) { return ::comphelper::concatSequences( OAccessibleExtendedComponentHelper
::getTypes(), AccessibleDialogControlShape_BASE::getTypes() )
; } css::uno::Sequence< sal_Int8 > AccessibleDialogControlShape
::getImplementationId( ) { return css::uno::Sequence<sal_Int8
>(); }
235
236// XComponent
237void AccessibleDialogControlShape::disposing()
238{
239 OAccessibleExtendedComponentHelper::disposing();
240
241 m_pDialogWindow = nullptr;
242 m_pDlgEdObj = nullptr;
243
244 if ( m_xControlModel.is() )
245 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
246 m_xControlModel.clear();
247}
248
249
250// XEventListener
251
252
253void AccessibleDialogControlShape::disposing( const lang::EventObject& )
254{
255 if ( m_xControlModel.is() )
256 m_xControlModel->removePropertyChangeListener( OUString(), static_cast< beans::XPropertyChangeListener* >( this ) );
257 m_xControlModel.clear();
258}
259
260
261// XPropertyChangeListener
262
263
264void AccessibleDialogControlShape::propertyChange( const beans::PropertyChangeEvent& rEvent )
265{
266 if ( rEvent.PropertyName == DLGED_PROP_NAME"Name" )
267 {
268 NotifyAccessibleEvent( AccessibleEventId::NAME_CHANGED, rEvent.OldValue, rEvent.NewValue );
269 }
270 else if ( rEvent.PropertyName == DLGED_PROP_POSITIONX"PositionX" ||
271 rEvent.PropertyName == DLGED_PROP_POSITIONY"PositionY" ||
272 rEvent.PropertyName == DLGED_PROP_WIDTH"Width" ||
273 rEvent.PropertyName == DLGED_PROP_HEIGHT"Height" )
274 {
275 SetBounds( GetBounds() );
276 }
277 else if ( rEvent.PropertyName == DLGED_PROP_BACKGROUNDCOLOR"BackgroundColor" ||
278 rEvent.PropertyName == DLGED_PROP_TEXTCOLOR"TextColor" ||
279 rEvent.PropertyName == DLGED_PROP_TEXTLINECOLOR"TextLineColor" )
280 {
281 NotifyAccessibleEvent( AccessibleEventId::VISIBLE_DATA_CHANGED, Any(), Any() );
282 }
283}
284
285// XServiceInfo
286OUString AccessibleDialogControlShape::getImplementationName()
287{
288 return "com.sun.star.comp.basctl.AccessibleShape";
289}
290
291sal_Bool AccessibleDialogControlShape::supportsService( const OUString& rServiceName )
292{
293 return cppu::supportsService(this, rServiceName);
294}
295
296Sequence< OUString > AccessibleDialogControlShape::getSupportedServiceNames()
297{
298 return { "com.sun.star.drawing.AccessibleShape" };
299}
300
301// XAccessible
302Reference< XAccessibleContext > AccessibleDialogControlShape::getAccessibleContext( )
303{
304 return this;
305}
306
307// XAccessibleContext
308sal_Int32 AccessibleDialogControlShape::getAccessibleChildCount()
309{
310 return 0;
311}
312
313
314Reference< XAccessible > AccessibleDialogControlShape::getAccessibleChild( sal_Int32 i )
315{
316 OExternalLockGuard aGuard( this );
317
318 if ( i < 0 || i >= getAccessibleChildCount() )
319 throw IndexOutOfBoundsException();
320
321 return Reference< XAccessible >();
322}
323
324
325Reference< XAccessible > AccessibleDialogControlShape::getAccessibleParent( )
326{
327 OExternalLockGuard aGuard( this );
328
329 Reference< XAccessible > xParent;
330 if ( m_pDialogWindow )
331 xParent = m_pDialogWindow->GetAccessible();
332
333 return xParent;
334}
335
336
337sal_Int32 AccessibleDialogControlShape::getAccessibleIndexInParent( )
338{
339 OExternalLockGuard aGuard( this );
340
341 sal_Int32 nIndexInParent = -1;
342 Reference< XAccessible > xParent( getAccessibleParent() );
343 if ( xParent.is() )
344 {
345 Reference< XAccessibleContext > xParentContext( xParent->getAccessibleContext() );
346 if ( xParentContext.is() )
347 {
348 for ( sal_Int32 i = 0, nCount = xParentContext->getAccessibleChildCount(); i < nCount; ++i )
349 {
350 Reference< XAccessible > xChild( xParentContext->getAccessibleChild( i ) );
351 if ( xChild.is() )
352 {
353 Reference< XAccessibleContext > xChildContext = xChild->getAccessibleContext();
354 if ( xChildContext == static_cast<XAccessibleContext*>(this) )
355 {
356 nIndexInParent = i;
357 break;
358 }
359 }
360 }
361 }
362 }
363
364 return nIndexInParent;
365}
366
367
368sal_Int16 AccessibleDialogControlShape::getAccessibleRole( )
369{
370 OExternalLockGuard aGuard( this );
371
372 return AccessibleRole::SHAPE;
373}
374
375
376OUString AccessibleDialogControlShape::getAccessibleDescription( )
377{
378 OExternalLockGuard aGuard( this );
379
380 return GetModelStringProperty( "HelpText" );
381}
382
383
384OUString AccessibleDialogControlShape::getAccessibleName( )
385{
386 OExternalLockGuard aGuard( this );
387
388 return GetModelStringProperty( "Name" );
389}
390
391
392Reference< XAccessibleRelationSet > AccessibleDialogControlShape::getAccessibleRelationSet( )
393{
394 OExternalLockGuard aGuard( this );
395
396 utl::AccessibleRelationSetHelper* pRelationSetHelper = new utl::AccessibleRelationSetHelper;
397 Reference< XAccessibleRelationSet > xSet = pRelationSetHelper;
398 return xSet;
399}
400
401
402Reference< XAccessibleStateSet > AccessibleDialogControlShape::getAccessibleStateSet( )
403{
404 OExternalLockGuard aGuard( this );
405
406 utl::AccessibleStateSetHelper* pStateSetHelper = new utl::AccessibleStateSetHelper;
407 Reference< XAccessibleStateSet > xSet = pStateSetHelper;
408
409 if ( !rBHelper.bDisposed && !rBHelper.bInDispose )
410 {
411 FillAccessibleStateSet( *pStateSetHelper );
412 }
413 else
414 {
415 pStateSetHelper->AddState( AccessibleStateType::DEFUNC );
416 }
417
418 return xSet;
419}
420
421
422Locale AccessibleDialogControlShape::getLocale( )
423{
424 OExternalLockGuard aGuard( this );
425
426 return Application::GetSettings().GetLanguageTag().getLocale();
427}
428
429
430// XAccessibleComponent
431
432
433Reference< XAccessible > AccessibleDialogControlShape::getAccessibleAtPoint( const awt::Point& )
434{
435 OExternalLockGuard aGuard( this );
436
437 return Reference< XAccessible >();
438}
439
440
441void AccessibleDialogControlShape::grabFocus( )
442{
443 // no focus for shapes
444}
445
446
447sal_Int32 AccessibleDialogControlShape::getForeground( )
448{
449 OExternalLockGuard aGuard( this );
450
451 Color nColor;
452 vcl::Window* pWindow = GetWindow();
453 if ( pWindow )
454 {
455 if ( pWindow->IsControlForeground() )
456 nColor = pWindow->GetControlForeground();
457 else
458 {
459 vcl::Font aFont;
460 if ( pWindow->IsControlFont() )
461 aFont = pWindow->GetControlFont();
462 else
463 aFont = pWindow->GetFont();
464 nColor = aFont.GetColor();
465 }
466 }
467
468 return sal_Int32(nColor);
469}
470
471
472sal_Int32 AccessibleDialogControlShape::getBackground( )
473{
474 OExternalLockGuard aGuard( this );
475
476 Color nColor;
477 vcl::Window* pWindow = GetWindow();
478 if ( pWindow )
479 {
480 if ( pWindow->IsControlBackground() )
481 nColor = pWindow->GetControlBackground();
482 else
483 nColor = pWindow->GetBackground().GetColor();
484 }
485
486 return sal_Int32(nColor);
487}
488
489
490// XAccessibleExtendedComponent
491
492
493Reference< awt::XFont > AccessibleDialogControlShape::getFont( )
494{
495 OExternalLockGuard aGuard( this );
496
497 Reference< awt::XFont > xFont;
498 vcl::Window* pWindow = GetWindow();
499 if ( pWindow )
500 {
501 Reference< awt::XDevice > xDev( pWindow->GetComponentInterface(), UNO_QUERY );
502 if ( xDev.is() )
503 {
504 vcl::Font aFont;
505 if ( pWindow->IsControlFont() )
506 aFont = pWindow->GetControlFont();
507 else
508 aFont = pWindow->GetFont();
509 VCLXFont* pVCLXFont = new VCLXFont;
510 pVCLXFont->Init( *xDev, aFont );
511 xFont = pVCLXFont;
512 }
513 }
514
515 return xFont;
516}
517
518
519OUString AccessibleDialogControlShape::getTitledBorderText( )
520{
521 OExternalLockGuard aGuard( this );
522
523 return OUString();
524}
525
526
527OUString AccessibleDialogControlShape::getToolTipText( )
528{
529 OExternalLockGuard aGuard( this );
530
531 OUString sText;
532 vcl::Window* pWindow = GetWindow();
1
Calling 'AccessibleDialogControlShape::GetWindow'
533 if ( pWindow )
534 sText = pWindow->GetQuickHelpText();
535
536 return sText;
537}
538
539
540} // namespace basctl
541
542/* 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)
7
Assuming field 'm_pBody' is non-null
8
Taking true branch
113 m_pBody->release();
9
Calling 'VclReferenceBase::release'
13
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;
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)
10
Assuming the condition is true
11
Taking true branch
40 delete this;
12
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