Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / accessibility / AccessibleChartElement.cxx
blob82f55eeda53f5ea040e3cf4c2da50024ecd81a4e
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 <CharacterProperties.hxx>
22 #include <ObjectIdentifier.hxx>
23 #include <ObjectNameProvider.hxx>
24 #include <servicenames.hxx>
26 #include <com/sun/star/awt/XDevice.hpp>
27 #include <com/sun/star/chart2/XTitle.hpp>
28 #include <com/sun/star/beans/XMultiPropertySet.hpp>
29 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
30 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <vcl/svapp.hxx>
33 #include <rtl/ustrbuf.hxx>
34 #include <tools/diagnose_ex.h>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::accessibility;
39 using ::com::sun::star::uno::UNO_QUERY;
40 using ::com::sun::star::uno::Reference;
41 using ::com::sun::star::uno::Sequence;
42 using ::com::sun::star::uno::RuntimeException;
44 namespace chart
47 AccessibleChartElement::AccessibleChartElement(
48 const AccessibleElementInfo & rAccInfo,
49 bool bMayHaveChildren ) :
50 impl::AccessibleChartElement_Base( rAccInfo, bMayHaveChildren, false/*bAlwaysTransparent*/ ),
51 m_bHasText( false )
53 AddState( AccessibleStateType::TRANSIENT );
56 AccessibleChartElement::~AccessibleChartElement()
58 OSL_ASSERT( CheckDisposeState( false /* don't throw exceptions */ ) );
61 // ________ protected ________
63 bool AccessibleChartElement::ImplUpdateChildren()
65 bool bResult = false;
66 Reference< chart2::XTitle > xTitle(
67 ObjectIdentifier::getObjectPropertySet(
68 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )),
69 uno::UNO_QUERY );
70 m_bHasText = xTitle.is();
72 if( m_bHasText )
74 InitTextEdit();
75 bResult = true;
77 else
78 bResult = AccessibleBase::ImplUpdateChildren();
80 return bResult;
83 void AccessibleChartElement::InitTextEdit()
85 if( ! m_xTextHelper.is())
87 // get hard reference
88 Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
89 // get factory from selection supplier (controller)
90 Reference< lang::XMultiServiceFactory > xFact( xSelSupp, uno::UNO_QUERY );
91 if( xFact.is())
93 m_xTextHelper.set(
94 xFact->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY );
98 if( m_xTextHelper.is())
99 try
101 Reference< lang::XInitialization > xInit( m_xTextHelper, uno::UNO_QUERY_THROW );
102 Sequence< uno::Any > aArgs( 3 );
103 aArgs[0] <<= GetInfo().m_aOID.getObjectCID();
104 aArgs[1] <<= Reference< XAccessible >( this );
105 aArgs[2] <<= Reference< awt::XWindow >( GetInfo().m_xWindow );
106 xInit->initialize( aArgs );
108 catch( const uno::Exception & )
110 DBG_UNHANDLED_EXCEPTION("chart2");
114 // Interfaces
116 // ________ AccessibleBase::XAccessibleContext ________
117 Reference< XAccessible > AccessibleChartElement::ImplGetAccessibleChildById( sal_Int32 i ) const
119 Reference< XAccessible > xResult;
121 if( m_bHasText )
122 xResult.set( m_xTextHelper->getAccessibleChild( i ));
123 else
124 xResult.set( AccessibleBase::ImplGetAccessibleChildById( i ));
126 return xResult;
129 sal_Int32 AccessibleChartElement::ImplGetAccessibleChildCount() const
131 if( m_bHasText )
133 if( m_xTextHelper.is())
134 return m_xTextHelper->getAccessibleChildCount();
135 return 0;
138 return AccessibleBase::ImplGetAccessibleChildCount();
141 // ________ XServiceInfo ________
142 OUString SAL_CALL AccessibleChartElement::getImplementationName()
144 return OUString( "AccessibleChartElement" );
147 // ________ AccessibleChartElement::XAccessibleContext (override) ________
148 OUString SAL_CALL AccessibleChartElement::getAccessibleName()
150 return ObjectNameProvider::getNameForCID(
151 GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument );
154 // ________ AccessibleChartElement::XAccessibleContext (override) ________
155 OUString SAL_CALL AccessibleChartElement::getAccessibleDescription()
157 return getToolTipText();
160 // ________ AccessibleChartElement::XAccessibleExtendedComponent ________
161 Reference< awt::XFont > SAL_CALL AccessibleChartElement::getFont()
163 CheckDisposeState();
165 Reference< awt::XFont > xFont;
166 Reference< awt::XDevice > xDevice( Reference< awt::XWindow >( GetInfo().m_xWindow ), uno::UNO_QUERY );
168 if( xDevice.is())
170 Reference< beans::XMultiPropertySet > xObjProp(
171 ObjectIdentifier::getObjectPropertySet(
172 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )), uno::UNO_QUERY );
173 awt::FontDescriptor aDescr(
174 CharacterProperties::createFontDescriptorFromPropertySet( xObjProp ));
175 xFont = xDevice->getFont( aDescr );
178 return xFont;
181 OUString SAL_CALL AccessibleChartElement::getTitledBorderText()
183 return OUString();
186 OUString SAL_CALL AccessibleChartElement::getToolTipText()
188 CheckDisposeState();
190 return ObjectNameProvider::getHelpText(
191 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument ));
194 // ________ XAccessibleComponent ________
195 sal_Bool SAL_CALL AccessibleChartElement::containsPoint( const awt::Point& aPoint )
197 return AccessibleBase::containsPoint( aPoint );
200 Reference< XAccessible > SAL_CALL AccessibleChartElement::getAccessibleAtPoint( const awt::Point& aPoint )
202 return AccessibleBase::getAccessibleAtPoint( aPoint );
205 awt::Rectangle SAL_CALL AccessibleChartElement::getBounds()
207 return AccessibleBase::getBounds();
210 awt::Point SAL_CALL AccessibleChartElement::getLocation()
212 return AccessibleBase::getLocation();
215 awt::Point SAL_CALL AccessibleChartElement::getLocationOnScreen()
217 return AccessibleBase::getLocationOnScreen();
220 awt::Size SAL_CALL AccessibleChartElement::getSize()
222 return AccessibleBase::getSize();
225 void SAL_CALL AccessibleChartElement::grabFocus()
227 return AccessibleBase::grabFocus();
230 sal_Int32 SAL_CALL AccessibleChartElement::getForeground()
232 return AccessibleBase::getForeground();
235 sal_Int32 SAL_CALL AccessibleChartElement::getBackground()
237 return AccessibleBase::getBackground();
240 } // namespace chart
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */