Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / accessibility / AccessibleChartElement.cxx
blob209d282c2c77890e421fbf6cc1a36f2b72c9db08
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "AccessibleChartElement.hxx"
21 #include <AccessibleTextHelper.hxx>
22 #include <CharacterProperties.hxx>
23 #include <ChartModel.hxx>
24 #include <ChartController.hxx>
25 #include <ObjectIdentifier.hxx>
26 #include <ObjectNameProvider.hxx>
27 #include <servicenames.hxx>
29 #include <com/sun/star/awt/XDevice.hpp>
30 #include <com/sun/star/chart2/XTitle.hpp>
31 #include <com/sun/star/beans/XMultiPropertySet.hpp>
32 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/view/XSelectionSupplier.hpp>
37 #include <comphelper/diagnose_ex.hxx>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
42 using ::com::sun::star::uno::UNO_QUERY;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Sequence;
46 namespace chart
49 AccessibleChartElement::AccessibleChartElement(
50 const AccessibleElementInfo & rAccInfo,
51 bool bMayHaveChildren ) :
52 impl::AccessibleChartElement_Base( rAccInfo, bMayHaveChildren, false/*bAlwaysTransparent*/ ),
53 m_bHasText( false )
55 AddState( AccessibleStateType::TRANSIENT );
58 AccessibleChartElement::~AccessibleChartElement()
60 OSL_ASSERT( CheckDisposeState( false /* don't throw exceptions */ ) );
63 // ________ protected ________
65 bool AccessibleChartElement::ImplUpdateChildren()
67 bool bResult = false;
68 Reference< chart2::XTitle > xTitle(
69 ObjectIdentifier::getObjectPropertySet(
70 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument ),
71 uno::UNO_QUERY );
72 m_bHasText = xTitle.is();
74 if( m_bHasText )
76 InitTextEdit();
77 bResult = true;
79 else
80 bResult = AccessibleBase::ImplUpdateChildren();
82 return bResult;
85 void AccessibleChartElement::InitTextEdit()
87 if( ! m_xTextHelper.is())
89 // get hard reference
90 rtl::Reference< ::chart::ChartController > xChartController( GetInfo().m_xChartController );
91 if( xChartController.is())
92 m_xTextHelper = xChartController->createAccessibleTextContext();
95 if( !m_xTextHelper.is())
96 return;
98 m_xTextHelper->initialize( GetInfo().m_aOID.getObjectCID(), this, GetInfo().m_xWindow );
101 // Interfaces
103 // ________ AccessibleBase::XAccessibleContext ________
104 Reference< XAccessible > AccessibleChartElement::ImplGetAccessibleChildById( sal_Int64 i ) const
106 Reference< XAccessible > xResult;
108 if( m_bHasText )
109 xResult.set( m_xTextHelper->getAccessibleChild( i ));
110 else
111 xResult.set( AccessibleBase::ImplGetAccessibleChildById( i ));
113 return xResult;
116 sal_Int64 AccessibleChartElement::ImplGetAccessibleChildCount() const
118 if( m_bHasText )
120 if( m_xTextHelper.is())
121 return m_xTextHelper->getAccessibleChildCount();
122 return 0;
125 return AccessibleBase::ImplGetAccessibleChildCount();
128 // ________ XServiceInfo ________
129 OUString SAL_CALL AccessibleChartElement::getImplementationName()
131 return "AccessibleChartElement";
134 // ________ AccessibleChartElement::XAccessibleContext (override) ________
135 OUString SAL_CALL AccessibleChartElement::getAccessibleName()
137 return ObjectNameProvider::getNameForCID(
138 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument );
141 // ________ AccessibleChartElement::XAccessibleContext (override) ________
142 OUString SAL_CALL AccessibleChartElement::getAccessibleDescription()
144 return getToolTipText();
147 // ________ AccessibleChartElement::XAccessibleExtendedComponent ________
148 Reference< awt::XFont > SAL_CALL AccessibleChartElement::getFont()
150 CheckDisposeState();
152 Reference< awt::XFont > xFont;
153 Reference< awt::XDevice > xDevice( Reference< awt::XWindow >( GetInfo().m_xWindow ), uno::UNO_QUERY );
155 if( xDevice.is())
157 Reference< beans::XMultiPropertySet > xObjProp(
158 ObjectIdentifier::getObjectPropertySet(
159 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument ), uno::UNO_QUERY );
160 awt::FontDescriptor aDescr(
161 CharacterProperties::createFontDescriptorFromPropertySet( xObjProp ));
162 xFont = xDevice->getFont( aDescr );
165 return xFont;
168 OUString SAL_CALL AccessibleChartElement::getTitledBorderText()
170 return OUString();
173 OUString SAL_CALL AccessibleChartElement::getToolTipText()
175 CheckDisposeState();
177 return ObjectNameProvider::getHelpText(
178 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument );
181 // ________ XAccessibleComponent ________
182 sal_Bool SAL_CALL AccessibleChartElement::containsPoint( const awt::Point& aPoint )
184 return AccessibleBase::containsPoint( aPoint );
187 Reference< XAccessible > SAL_CALL AccessibleChartElement::getAccessibleAtPoint( const awt::Point& aPoint )
189 return AccessibleBase::getAccessibleAtPoint( aPoint );
192 awt::Rectangle SAL_CALL AccessibleChartElement::getBounds()
194 return AccessibleBase::getBounds();
197 awt::Point SAL_CALL AccessibleChartElement::getLocation()
199 return AccessibleBase::getLocation();
202 awt::Point SAL_CALL AccessibleChartElement::getLocationOnScreen()
204 return AccessibleBase::getLocationOnScreen();
207 awt::Size SAL_CALL AccessibleChartElement::getSize()
209 return AccessibleBase::getSize();
212 void SAL_CALL AccessibleChartElement::grabFocus()
214 return AccessibleBase::grabFocus();
217 sal_Int32 SAL_CALL AccessibleChartElement::getForeground()
219 return AccessibleBase::getForeground();
222 sal_Int32 SAL_CALL AccessibleChartElement::getBackground()
224 return AccessibleBase::getBackground();
227 } // namespace chart
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */