1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "AccessibleChartView.hxx"
21 #include "chartview/ExplicitValueProvider.hxx"
22 #include "servicenames.hxx"
24 #include "ObjectHierarchy.hxx"
25 #include "ObjectIdentifier.hxx"
27 #include "Strings.hrc"
28 #include "AccessibleViewForwarder.hxx"
30 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
32 #include <com/sun/star/accessibility/AccessibleRole.hpp>
34 #include <rtl/ustring.hxx>
35 #include <vcl/window.hxx>
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <vcl/svapp.hxx>
38 #include <osl/mutex.hxx>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::accessibility
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::WeakReference
;
46 using ::com::sun::star::uno::Any
;
47 using osl::MutexGuard
;
52 AccessibleChartView::AccessibleChartView(
53 const Reference
< uno::XComponentContext
>& xContext
, SdrView
* pView
) :
54 impl::AccessibleChartView_Base(
55 AccessibleElementInfo(), // empty for now
57 true // always transparent
59 m_xContext( xContext
),
61 m_pViewForwarder( NULL
)
63 AddState( AccessibleStateType::OPAQUE
);
66 AccessibleChartView::~AccessibleChartView()
68 delete m_pViewForwarder
;
71 awt::Rectangle
AccessibleChartView::GetWindowPosSize() const
73 Reference
< awt::XWindow
> xWindow( GetInfo().m_xWindow
);
75 return awt::Rectangle();
77 awt::Rectangle
aBBox( xWindow
->getPosSize() );
79 vcl::Window
* pWindow( VCLUnoHelper::GetWindow( GetInfo().m_xWindow
));
82 SolarMutexGuard aSolarGuard
;
83 Point
aVCLPoint( pWindow
->OutputToAbsoluteScreenPixel( Point( 0, 0 ) ));
84 aBBox
.X
= aVCLPoint
.getX();
85 aBBox
.Y
= aVCLPoint
.getY();
91 awt::Point
AccessibleChartView::GetUpperLeftOnScreen() const
93 awt::Point aParentPosition
;
95 awt::Rectangle
aBBox( GetWindowPosSize() );
96 aParentPosition
.X
= aBBox
.X
;
97 aParentPosition
.Y
= aBBox
.Y
;
99 return aParentPosition
;
102 // ________ XAccessibleContext ________
103 OUString SAL_CALL
AccessibleChartView::getAccessibleName()
104 throw (uno::RuntimeException
, std::exception
)
106 return SCH_RESSTR(STR_OBJECT_DIAGRAM
);
109 OUString SAL_CALL
AccessibleChartView::getAccessibleDescription()
110 throw (uno::RuntimeException
, std::exception
)
112 return getAccessibleName();
115 Reference
< XAccessible
> SAL_CALL
AccessibleChartView::getAccessibleParent()
116 throw (uno::RuntimeException
, std::exception
)
118 return Reference
< XAccessible
>( m_xParent
);
121 sal_Int32 SAL_CALL
AccessibleChartView::getAccessibleIndexInParent()
122 throw (uno::RuntimeException
, std::exception
)
124 // the document is always the only child of the window
128 sal_Int16 SAL_CALL
AccessibleChartView::getAccessibleRole()
129 throw (uno::RuntimeException
, std::exception
)
131 return AccessibleRole::DOCUMENT
;
134 // ________ XAccessibleComponent ________
135 awt::Rectangle SAL_CALL
AccessibleChartView::getBounds()
136 throw (uno::RuntimeException
, std::exception
)
138 awt::Rectangle
aResult( GetWindowPosSize());
139 Reference
< XAccessible
> xParent( m_xParent
);
142 Reference
< XAccessibleComponent
> xContext( xParent
->getAccessibleContext(), uno::UNO_QUERY
);
145 awt::Point aParentPosition
= xContext
->getLocationOnScreen();
146 aResult
.X
-= aParentPosition
.X
;
147 aResult
.Y
-= aParentPosition
.Y
;
153 awt::Point SAL_CALL
AccessibleChartView::getLocationOnScreen()
154 throw (uno::RuntimeException
, std::exception
)
156 awt::Rectangle
aBounds( getBounds());
158 Reference
< XAccessible
> xParent( m_xParent
);
161 Reference
< XAccessibleComponent
> xAccComp(
162 xParent
->getAccessibleContext(), uno::UNO_QUERY
);
163 aResult
= xAccComp
->getLocationOnScreen();
164 aResult
.X
+= aBounds
.X
;
165 aResult
.Y
+= aBounds
.Y
;
170 // lang::XInitialization
172 void SAL_CALL
AccessibleChartView::initialize( const Sequence
< Any
>& rArguments
)
173 throw (uno::Exception
, uno::RuntimeException
, std::exception
)
175 //0: view::XSelectionSupplier offers notifications for selection changes and access to the selection itself
176 //1: frame::XModel representing the chart model - offers access to object data
177 //2: lang::XInterface representing the normal chart view - offers access to some extra object data
179 //all arguments are only valid until next initialization
180 bool bChanged
= false;
181 bool bOldInvalid
= false;
182 bool bNewInvalid
= false;
184 Reference
< view::XSelectionSupplier
> xSelectionSupplier
;
185 Reference
< frame::XModel
> xChartModel
;
186 Reference
< uno::XInterface
> xChartView
;
187 Reference
< XAccessible
> xParent
;
188 Reference
< awt::XWindow
> xWindow
;
190 MutexGuard
aGuard( GetMutex());
191 xSelectionSupplier
.set( m_xSelectionSupplier
);
192 xChartModel
.set( m_xChartModel
);
193 xChartView
.set( m_xChartView
);
194 xParent
.set( m_xParent
);
195 xWindow
.set( m_xWindow
);
198 if( !xSelectionSupplier
.is() || !xChartModel
.is() || !xChartView
.is() )
203 if( rArguments
.getLength() > 1 )
205 Reference
< frame::XModel
> xNewChartModel
;
206 rArguments
[1] >>= xNewChartModel
;
207 if( xNewChartModel
!= xChartModel
)
209 xChartModel
= xNewChartModel
;
213 else if( xChartModel
.is() )
219 if( rArguments
.getLength() > 2 )
221 Reference
< uno::XInterface
> xNewChartView
;
222 rArguments
[2] >>= xNewChartView
;
223 if( xNewChartView
!= xChartView
)
225 xChartView
= xNewChartView
;
229 else if( xChartView
.is() )
235 if( rArguments
.getLength() > 3 )
237 Reference
< XAccessible
> xNewParent
;
238 rArguments
[3] >>= xNewParent
;
239 if( xNewParent
!= xParent
)
241 xParent
= xNewParent
;
246 if( rArguments
.getLength() > 4 )
248 Reference
< awt::XWindow
> xNewWindow
;
249 rArguments
[4] >>= xNewWindow
;
250 if( xNewWindow
!= xWindow
)
252 xWindow
.set( xNewWindow
);
257 if( rArguments
.getLength() > 0 && xChartModel
.is() && xChartView
.is() )
259 Reference
< view::XSelectionSupplier
> xNewSelectionSupplier
;
260 rArguments
[0] >>= xNewSelectionSupplier
;
261 if(xSelectionSupplier
!=xNewSelectionSupplier
)
264 if(xSelectionSupplier
.is())
265 xSelectionSupplier
->removeSelectionChangeListener(this);
266 if(xNewSelectionSupplier
.is())
267 xNewSelectionSupplier
->addSelectionChangeListener(this);
268 xSelectionSupplier
= xNewSelectionSupplier
;
271 else if( xSelectionSupplier
.is() )
274 xSelectionSupplier
->removeSelectionChangeListener(this);
275 xSelectionSupplier
= 0;
278 if( !xSelectionSupplier
.is() || !xChartModel
.is() || !xChartView
.is() )
280 if(xSelectionSupplier
.is())
281 xSelectionSupplier
->removeSelectionChangeListener(this);
282 xSelectionSupplier
= 0;
292 MutexGuard
aGuard( GetMutex());
293 m_xSelectionSupplier
= WeakReference
< view::XSelectionSupplier
>(xSelectionSupplier
);
294 m_xChartModel
= WeakReference
< frame::XModel
>(xChartModel
);
295 m_xChartView
= WeakReference
< uno::XInterface
>(xChartView
);
296 m_xParent
= WeakReference
< XAccessible
>(xParent
);
297 m_xWindow
= WeakReference
< awt::XWindow
>(xWindow
);
300 if( bOldInvalid
&& bNewInvalid
)
306 //before notification we prepare for creation of new context
307 //the old context will be deleted after notification than
308 MutexGuard
aGuard( GetMutex());
309 Reference
< chart2::XChartDocument
> xChartDoc( xChartModel
, uno::UNO_QUERY
);
311 m_spObjectHierarchy
.reset( new ObjectHierarchy( xChartDoc
, getExplicitValueProvider() ));
313 m_spObjectHierarchy
.reset();
317 AccessibleElementInfo aAccInfo
;
318 aAccInfo
.m_aOID
= ObjectIdentifier("ROOT");
319 aAccInfo
.m_xChartDocument
= uno::WeakReference
< chart2::XChartDocument
>(
320 uno::Reference
< chart2::XChartDocument
>( m_xChartModel
.get(), uno::UNO_QUERY
));
321 aAccInfo
.m_xSelectionSupplier
= m_xSelectionSupplier
;
322 aAccInfo
.m_xView
= m_xChartView
;
323 aAccInfo
.m_xWindow
= m_xWindow
;
324 aAccInfo
.m_pParent
= 0;
325 aAccInfo
.m_spObjectHierarchy
= m_spObjectHierarchy
;
326 aAccInfo
.m_pSdrView
= m_pSdrView
;
327 vcl::Window
* pWindow
= VCLUnoHelper::GetWindow( m_xWindow
);
328 if ( m_pViewForwarder
)
330 delete m_pViewForwarder
;
332 m_pViewForwarder
= new AccessibleViewForwarder( this, pWindow
);
333 aAccInfo
.m_pViewForwarder
= m_pViewForwarder
;
334 // broadcasts an INVALIDATE_ALL_CHILDREN event globally
340 ExplicitValueProvider
* AccessibleChartView::getExplicitValueProvider()
342 return ExplicitValueProvider::getExplicitValueProvider(m_xChartView
);
345 // view::XSelectionChangeListener
347 void SAL_CALL
AccessibleChartView::selectionChanged( const lang::EventObject
& /*rEvent*/ )
348 throw (uno::RuntimeException
, std::exception
)
350 Reference
< view::XSelectionSupplier
> xSelectionSupplier
;
352 MutexGuard
aGuard( GetMutex());
353 xSelectionSupplier
= Reference
< view::XSelectionSupplier
>(m_xSelectionSupplier
);
356 if( xSelectionSupplier
.is() )
358 ObjectIdentifier
aSelectedOID( xSelectionSupplier
->getSelection() );
359 if ( m_aCurrentSelectionOID
.isValid() )
361 NotifyEvent( LOST_SELECTION
, m_aCurrentSelectionOID
);
363 if( aSelectedOID
.isValid() )
365 NotifyEvent( GOT_SELECTION
, aSelectedOID
);
367 m_aCurrentSelectionOID
= aSelectedOID
;
371 // lang::XComponent::dispose()
372 void SAL_CALL
AccessibleChartView::disposing()
374 AccessibleBase::disposing();
378 void SAL_CALL
AccessibleChartView::disposing( const lang::EventObject
& /*Source*/ )
379 throw (uno::RuntimeException
, std::exception
)
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */