Line data Source code
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 "AccessibleChartElement.hxx"
21 : #include "CharacterProperties.hxx"
22 : #include "ObjectIdentifier.hxx"
23 : #include "ObjectNameProvider.hxx"
24 : #include "servicenames.hxx"
25 : #include "macros.hxx"
26 :
27 : #include <com/sun/star/awt/XDevice.hpp>
28 : #include <com/sun/star/chart2/XTitle.hpp>
29 : #include <com/sun/star/beans/XMultiPropertySet.hpp>
30 : #include <com/sun/star/accessibility/AccessibleStateType.hpp>
31 : #include <com/sun/star/lang/XInitialization.hpp>
32 :
33 : #include <vcl/svapp.hxx>
34 : #include <rtl/ustrbuf.hxx>
35 :
36 : using namespace ::com::sun::star;
37 : using namespace ::com::sun::star::accessibility;
38 :
39 : using ::com::sun::star::uno::UNO_QUERY;
40 : using ::com::sun::star::uno::Reference;
41 : using ::com::sun::star::uno::Sequence;
42 : using ::osl::MutexGuard;
43 : using ::osl::ClearableMutexGuard;
44 : using ::osl::ResettableMutexGuard;
45 : using ::com::sun::star::uno::RuntimeException;
46 : using ::com::sun::star::uno::Any;
47 :
48 : namespace chart
49 : {
50 :
51 0 : AccessibleChartElement::AccessibleChartElement(
52 : const AccessibleElementInfo & rAccInfo,
53 : bool bMayHaveChildren,
54 : bool bAlwaysTransparent /* default: false */ ) :
55 : impl::AccessibleChartElement_Base( rAccInfo, bMayHaveChildren, bAlwaysTransparent ),
56 0 : m_bHasText( false )
57 : {
58 0 : AddState( AccessibleStateType::TRANSIENT );
59 0 : }
60 :
61 0 : AccessibleChartElement::~AccessibleChartElement()
62 : {
63 : OSL_ASSERT( CheckDisposeState( false /* don't throw exceptions */ ) );
64 0 : }
65 :
66 : // ________ protected ________
67 :
68 0 : bool AccessibleChartElement::ImplUpdateChildren()
69 : {
70 0 : bool bResult = false;
71 : Reference< chart2::XTitle > xTitle(
72 : ObjectIdentifier::getObjectPropertySet(
73 : GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )),
74 0 : uno::UNO_QUERY );
75 0 : m_bHasText = xTitle.is();
76 :
77 0 : if( m_bHasText )
78 : {
79 0 : InitTextEdit();
80 0 : bResult = true;
81 : }
82 : else
83 0 : bResult = AccessibleBase::ImplUpdateChildren();
84 :
85 0 : return bResult;
86 : }
87 :
88 0 : void AccessibleChartElement::InitTextEdit()
89 : {
90 0 : if( ! m_xTextHelper.is())
91 : {
92 : // get hard reference
93 0 : Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
94 : // get factory from selection supplier (controller)
95 0 : Reference< lang::XMultiServiceFactory > xFact( xSelSupp, uno::UNO_QUERY );
96 0 : if( xFact.is())
97 : {
98 : m_xTextHelper.set(
99 0 : xFact->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY );
100 0 : }
101 : }
102 :
103 0 : if( m_xTextHelper.is())
104 : try
105 : {
106 0 : Reference< lang::XInitialization > xInit( m_xTextHelper, uno::UNO_QUERY_THROW );
107 0 : Sequence< uno::Any > aArgs( 3 );
108 0 : aArgs[0] <<= GetInfo().m_aOID.getObjectCID();
109 0 : aArgs[1] <<= Reference< XAccessible >( this );
110 0 : aArgs[2] <<= Reference< awt::XWindow >( GetInfo().m_xWindow );
111 0 : xInit->initialize( aArgs );
112 : }
113 0 : catch( const uno::Exception & ex )
114 : {
115 : ASSERT_EXCEPTION( ex );
116 : }
117 0 : }
118 :
119 : // Interfaces
120 :
121 : // ________ AccessibleBase::XAccessibleContext ________
122 0 : Reference< XAccessible > AccessibleChartElement::ImplGetAccessibleChildById( sal_Int32 i ) const
123 : throw (lang::IndexOutOfBoundsException, RuntimeException)
124 : {
125 0 : Reference< XAccessible > xResult;
126 :
127 0 : if( m_bHasText )
128 0 : xResult.set( m_xTextHelper->getAccessibleChild( i ));
129 : else
130 0 : xResult.set( AccessibleBase::ImplGetAccessibleChildById( i ));
131 :
132 0 : return xResult;
133 : }
134 :
135 0 : sal_Int32 AccessibleChartElement::ImplGetAccessibleChildCount() const
136 : throw (RuntimeException)
137 : {
138 0 : if( m_bHasText )
139 : {
140 0 : if( m_xTextHelper.is())
141 0 : return m_xTextHelper->getAccessibleChildCount();
142 0 : return 0;
143 : }
144 :
145 0 : return AccessibleBase::ImplGetAccessibleChildCount();
146 : }
147 :
148 : // ________ XServiceInfo ________
149 0 : OUString SAL_CALL AccessibleChartElement::getImplementationName()
150 : throw (RuntimeException, std::exception)
151 : {
152 0 : return OUString( "AccessibleChartElement" );
153 : }
154 :
155 : // ________ AccessibleChartElement::XAccessibleContext (override) ________
156 0 : OUString SAL_CALL AccessibleChartElement::getAccessibleName()
157 : throw (::com::sun::star::uno::RuntimeException, std::exception)
158 : {
159 : return ObjectNameProvider::getNameForCID(
160 0 : GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument );
161 : }
162 :
163 : // ________ AccessibleChartElement::XAccessibleContext (override) ________
164 0 : OUString SAL_CALL AccessibleChartElement::getAccessibleDescription()
165 : throw (::com::sun::star::uno::RuntimeException, std::exception)
166 : {
167 0 : return getToolTipText();
168 : }
169 :
170 : // ________ AccessibleChartElement::XAccessibleExtendedComponent ________
171 0 : Reference< awt::XFont > SAL_CALL AccessibleChartElement::getFont()
172 : throw (uno::RuntimeException, std::exception)
173 : {
174 0 : CheckDisposeState();
175 :
176 0 : Reference< awt::XFont > xFont;
177 : // using assignment for broken gcc 3.3
178 : Reference< awt::XDevice > xDevice = Reference< awt::XDevice >(
179 0 : Reference< awt::XWindow >( GetInfo().m_xWindow ), uno::UNO_QUERY );
180 :
181 0 : if( xDevice.is())
182 : {
183 : Reference< beans::XMultiPropertySet > xObjProp(
184 : ObjectIdentifier::getObjectPropertySet(
185 0 : GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )), uno::UNO_QUERY );
186 : awt::FontDescriptor aDescr(
187 0 : CharacterProperties::createFontDescriptorFromPropertySet( xObjProp ));
188 0 : xFont = xDevice->getFont( aDescr );
189 : }
190 :
191 0 : return xFont;
192 : }
193 :
194 0 : OUString SAL_CALL AccessibleChartElement::getTitledBorderText()
195 : throw (uno::RuntimeException, std::exception)
196 : {
197 0 : return OUString();
198 : }
199 :
200 0 : OUString SAL_CALL AccessibleChartElement::getToolTipText()
201 : throw (::com::sun::star::uno::RuntimeException, std::exception)
202 : {
203 0 : CheckDisposeState();
204 :
205 : return ObjectNameProvider::getHelpText(
206 0 : GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument ));
207 : }
208 :
209 : // ________ XAccessibleComponent ________
210 0 : sal_Bool SAL_CALL AccessibleChartElement::containsPoint( const awt::Point& aPoint )
211 : throw (uno::RuntimeException, std::exception)
212 : {
213 0 : return AccessibleBase::containsPoint( aPoint );
214 : }
215 :
216 0 : Reference< XAccessible > SAL_CALL AccessibleChartElement::getAccessibleAtPoint( const awt::Point& aPoint )
217 : throw (uno::RuntimeException, std::exception)
218 : {
219 0 : return AccessibleBase::getAccessibleAtPoint( aPoint );
220 : }
221 :
222 0 : awt::Rectangle SAL_CALL AccessibleChartElement::getBounds()
223 : throw (uno::RuntimeException, std::exception)
224 : {
225 0 : return AccessibleBase::getBounds();
226 : }
227 :
228 0 : awt::Point SAL_CALL AccessibleChartElement::getLocation()
229 : throw (uno::RuntimeException, std::exception)
230 : {
231 0 : return AccessibleBase::getLocation();
232 : }
233 :
234 0 : awt::Point SAL_CALL AccessibleChartElement::getLocationOnScreen()
235 : throw (uno::RuntimeException, std::exception)
236 : {
237 0 : return AccessibleBase::getLocationOnScreen();
238 : }
239 :
240 0 : awt::Size SAL_CALL AccessibleChartElement::getSize()
241 : throw (uno::RuntimeException, std::exception)
242 : {
243 0 : return AccessibleBase::getSize();
244 : }
245 :
246 0 : void SAL_CALL AccessibleChartElement::grabFocus()
247 : throw (uno::RuntimeException, std::exception)
248 : {
249 0 : return AccessibleBase::grabFocus();
250 : }
251 :
252 0 : sal_Int32 SAL_CALL AccessibleChartElement::getForeground()
253 : throw (uno::RuntimeException, std::exception)
254 : {
255 0 : return AccessibleBase::getForeground();
256 : }
257 :
258 0 : sal_Int32 SAL_CALL AccessibleChartElement::getBackground()
259 : throw (uno::RuntimeException, std::exception)
260 : {
261 0 : return AccessibleBase::getBackground();
262 : }
263 :
264 : } // namespace chart
265 :
266 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|