xref: /AOO41X/main/chart2/source/controller/accessibility/AccessibleChartElement.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 
31 #include "AccessibleChartElement.hxx"
32 #include "CharacterProperties.hxx"
33 #include "ObjectIdentifier.hxx"
34 #include "ObjectNameProvider.hxx"
35 #include "servicenames.hxx"
36 #include "macros.hxx"
37 
38 #include <com/sun/star/awt/XDevice.hpp>
39 #include <com/sun/star/chart2/XTitle.hpp>
40 #include <com/sun/star/beans/XMultiPropertySet.hpp>
41 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
42 #include <com/sun/star/lang/XInitialization.hpp>
43 
44 // for SolarMutex
45 #include <vcl/svapp.hxx>
46 #include <rtl/ustrbuf.hxx>
47 
48 // #ifndef _RTL_UUID_H_
49 // #include <rtl/uuid.h>
50 // #endif
51 // #ifndef _CPPUHELPER_QUERYINTERFACE_HXX_
52 // #include <cppuhelper/queryinterface.hxx>
53 // #endif
54 // #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
55 // #include <toolkit/helper/vclunohelper.hxx>
56 // #endif
57 // #ifndef _SV_WINDOW_HXX
58 // #include <vcl/window.hxx>
59 // #endif
60 
61 // #ifndef _SVX_ACCESSILE_TEXT_HELPER_HXX_
62 // #include <svx/AccessibleTextHelper.hxx>
63 // #endif
64 
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::accessibility;
67 
68 using ::com::sun::star::uno::UNO_QUERY;
69 using ::rtl::OUString;
70 using ::rtl::OUStringBuffer;
71 using ::com::sun::star::uno::Reference;
72 using ::com::sun::star::uno::Sequence;
73 using ::osl::MutexGuard;
74 using ::osl::ClearableMutexGuard;
75 using ::osl::ResettableMutexGuard;
76 using ::com::sun::star::uno::RuntimeException;
77 using ::com::sun::star::uno::Any;
78 
79 namespace chart
80 {
81 
82 AccessibleChartElement::AccessibleChartElement(
83     const AccessibleElementInfo & rAccInfo,
84     bool bMayHaveChildren,
85     bool bAlwaysTransparent /* default: false */ ) :
86         impl::AccessibleChartElement_Base( rAccInfo, bMayHaveChildren, bAlwaysTransparent ),
87         m_bHasText( false )
88 {
89     AddState( AccessibleStateType::TRANSIENT );
90 }
91 
92 AccessibleChartElement::~AccessibleChartElement()
93 {
94     OSL_ASSERT( CheckDisposeState( false /* don't throw exceptions */ ) );
95 }
96 
97 // ________ protected ________
98 
99 bool AccessibleChartElement::ImplUpdateChildren()
100 {
101     bool bResult = false;
102     Reference< chart2::XTitle > xTitle(
103         ObjectIdentifier::getObjectPropertySet(
104             GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )),
105         uno::UNO_QUERY );
106     m_bHasText = xTitle.is();
107 
108     if( m_bHasText )
109     {
110         InitTextEdit();
111         bResult = true;
112     }
113     else
114         bResult = AccessibleBase::ImplUpdateChildren();
115 
116     return bResult;
117 }
118 
119 void AccessibleChartElement::InitTextEdit()
120 {
121     if( ! m_xTextHelper.is())
122     {
123         // get hard reference
124         Reference< view::XSelectionSupplier > xSelSupp( GetInfo().m_xSelectionSupplier );
125         // get factory from selection supplier (controller)
126         Reference< lang::XMultiServiceFactory > xFact( xSelSupp, uno::UNO_QUERY );
127         if( xFact.is())
128         {
129             m_xTextHelper.set(
130                 xFact->createInstance( CHART_ACCESSIBLE_TEXT_SERVICE_NAME ), uno::UNO_QUERY );
131         }
132     }
133 
134     if( m_xTextHelper.is())
135         try
136         {
137             Reference< lang::XInitialization > xInit( m_xTextHelper, uno::UNO_QUERY_THROW );
138             Sequence< uno::Any > aArgs( 3 );
139             aArgs[0] <<= GetInfo().m_aOID.getObjectCID();
140             aArgs[1] <<= Reference< XAccessible >( this );
141             aArgs[2] <<= Reference< awt::XWindow >( GetInfo().m_xWindow );
142             xInit->initialize( aArgs );
143         }
144         catch( const uno::Exception & ex )
145         {
146             ASSERT_EXCEPTION( ex );
147         }
148 }
149 //     OSL_ASSERT( m_pTextHelper == 0 );
150 
151 //     // /-- solar
152 //     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
153 //     Window* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow ));
154 //     if( pWindow )
155 //     {
156 //         // we need ChartController::m_pDrawViewWrapper here
157 //         SdrView * pView = 0;
158 //         if( pView )
159 //         {
160 //             SdrObject * pTextObj = m_pDrawViewWrapper->getTextEditObject();
161 //             if( pTextObj )
162 //             {
163 //                 SvxEditSource * pEditSource = new SvxEditSource( pTextObj, pView, pWindow );
164 //                 m_pTextHelper = new ::accessibility::AccessibleTextHelper(
165 //                     ::std::auto_ptr< SvxEditSource >( pEditSource ));
166 //                 if( m_pTextHelper )
167 //                     m_pTextHelper->SetEventSource( this );
168 //             }
169 //         }
170 //     }
171 //     // \-- solar
172 // }
173 
174 // ____________________________________
175 // ____________________________________
176 //
177 //             Interfaces
178 // ____________________________________
179 // ____________________________________
180 
181 // ________ AccessibleBase::XAccessibleContext ________
182 Reference< XAccessible > AccessibleChartElement::ImplGetAccessibleChildById( sal_Int32 i ) const
183     throw (lang::IndexOutOfBoundsException, RuntimeException)
184 {
185     Reference< XAccessible > xResult;
186 
187     if( m_bHasText )
188     {
189         xResult.set( m_xTextHelper->getAccessibleChild( i ));
190         // /-- solar
191 //         ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
192 //         if( m_pTextHelper )
193 //             xResult.set( m_pTextHelper->GetChild( i ) );
194         // \-- solar
195     }
196     else
197         xResult.set( AccessibleBase::ImplGetAccessibleChildById( i ));
198 
199     return xResult;
200 }
201 
202 sal_Int32 AccessibleChartElement::ImplGetAccessibleChildCount() const
203     throw (RuntimeException)
204 {
205     if( m_bHasText )
206     {
207         if( m_xTextHelper.is())
208             return m_xTextHelper->getAccessibleChildCount();
209         return 0;
210     }
211 
212     return AccessibleBase::ImplGetAccessibleChildCount();
213 }
214 
215 // ________ XServiceInfo ________
216 OUString SAL_CALL AccessibleChartElement::getImplementationName()
217     throw (RuntimeException)
218 {
219     return OUString( RTL_CONSTASCII_USTRINGPARAM( "AccessibleChartElement" ));
220 }
221 
222 // ________ AccessibleChartElement::XAccessibleContext (overloaded) ________
223 OUString SAL_CALL AccessibleChartElement::getAccessibleName()
224     throw (::com::sun::star::uno::RuntimeException)
225 {
226     return ObjectNameProvider::getNameForCID(
227         GetInfo().m_aOID.getObjectCID(), GetInfo().m_xChartDocument );
228 }
229 
230 // ________ AccessibleChartElement::XAccessibleContext (overloaded) ________
231 OUString SAL_CALL AccessibleChartElement::getAccessibleDescription()
232     throw (::com::sun::star::uno::RuntimeException)
233 {
234     return getToolTipText();
235 }
236 
237 // ________ AccessibleChartElement::XAccessibleExtendedComponent ________
238 Reference< awt::XFont > SAL_CALL AccessibleChartElement::getFont()
239     throw (uno::RuntimeException)
240 {
241     CheckDisposeState();
242 
243     Reference< awt::XFont > xFont;
244     // using assignment for broken gcc 3.3
245     Reference< awt::XDevice > xDevice = Reference< awt::XDevice >(
246         Reference< awt::XWindow >( GetInfo().m_xWindow ), uno::UNO_QUERY );
247 
248     if( xDevice.is())
249     {
250         Reference< beans::XMultiPropertySet > xObjProp(
251             ObjectIdentifier::getObjectPropertySet(
252                 GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument )), uno::UNO_QUERY );
253         awt::FontDescriptor aDescr(
254             CharacterProperties::createFontDescriptorFromPropertySet( xObjProp ));
255         xFont = xDevice->getFont( aDescr );
256     }
257 
258     return xFont;
259 }
260 
261 OUString SAL_CALL AccessibleChartElement::getTitledBorderText()
262     throw (uno::RuntimeException)
263 {
264     return OUString();
265 }
266 
267 OUString SAL_CALL AccessibleChartElement::getToolTipText()
268     throw (::com::sun::star::uno::RuntimeException)
269 {
270     CheckDisposeState();
271 
272     return ObjectNameProvider::getHelpText(
273         GetInfo().m_aOID.getObjectCID(), Reference< chart2::XChartDocument >( GetInfo().m_xChartDocument ));
274 }
275 
276 // ________ XAccessibleComponent ________
277 sal_Bool SAL_CALL AccessibleChartElement::containsPoint( const awt::Point& aPoint )
278     throw (uno::RuntimeException)
279 {
280     return AccessibleBase::containsPoint( aPoint );
281 }
282 
283 Reference< XAccessible > SAL_CALL AccessibleChartElement::getAccessibleAtPoint( const awt::Point& aPoint )
284     throw (uno::RuntimeException)
285 {
286     return AccessibleBase::getAccessibleAtPoint( aPoint );
287 }
288 
289 awt::Rectangle SAL_CALL AccessibleChartElement::getBounds()
290     throw (uno::RuntimeException)
291 {
292     return AccessibleBase::getBounds();
293 }
294 
295 awt::Point SAL_CALL AccessibleChartElement::getLocation()
296     throw (uno::RuntimeException)
297 {
298     return AccessibleBase::getLocation();
299 }
300 
301 awt::Point SAL_CALL AccessibleChartElement::getLocationOnScreen()
302     throw (uno::RuntimeException)
303 {
304     return AccessibleBase::getLocationOnScreen();
305 }
306 
307 awt::Size SAL_CALL AccessibleChartElement::getSize()
308     throw (uno::RuntimeException)
309 {
310     return AccessibleBase::getSize();
311 }
312 
313 void SAL_CALL AccessibleChartElement::grabFocus()
314     throw (uno::RuntimeException)
315 {
316     return AccessibleBase::grabFocus();
317 }
318 
319 sal_Int32 SAL_CALL AccessibleChartElement::getForeground()
320     throw (uno::RuntimeException)
321 {
322     return AccessibleBase::getForeground();
323 }
324 
325 sal_Int32 SAL_CALL AccessibleChartElement::getBackground()
326     throw (uno::RuntimeException)
327 {
328     return AccessibleBase::getBackground();
329 }
330 
331 
332 } // namespace chart
333