1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <toolkit/controls/accessiblecontrolcontext.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <com/sun/star/awt/XControl.hpp>
#include <com/sun/star/awt/XWindow.hpp>
#include <vcl/svapp.hxx>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/window.hxx>
//........................................................................
namespace toolkit
{
//........................................................................
using ::comphelper::OContextEntryGuard;
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::accessibility;
//====================================================================
//= OAccessibleControlContext
//====================================================================
//--------------------------------------------------------------------
OAccessibleControlContext::OAccessibleControlContext()
:OAccessibleControlContext_Base( )
{
// nothing to do here, we have a late ctor
}
//--------------------------------------------------------------------
OAccessibleControlContext::~OAccessibleControlContext()
{
ensureDisposed();
}
//--------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase )
IMPLEMENT_FORWARD_XTYPEPROVIDER3( OAccessibleControlContext, OAccessibleControlContext_Base, OAccessibleImplementationAccess, OAccessibleControlContext_IBase )
// (order matters: the first is the class name, the second is the class doing the ref counting)
//--------------------------------------------------------------------
void OAccessibleControlContext::Init( const Reference< XAccessible >& _rxCreator ) SAL_THROW( ( Exception ) )
{
OContextEntryGuard aGuard( this );
// retrieve the model of the control
OSL_ENSURE( !m_xControlModel.is(), "OAccessibleControlContext::Init: already know a control model....!???" );
Reference< awt::XControl > xControl( _rxCreator, UNO_QUERY );
if ( xControl.is() )
m_xControlModel = m_xControlModel.query( xControl->getModel() );
OSL_ENSURE( m_xControlModel.is(), "OAccessibleControlContext::Init: invalid creator (no control, or control without model!" );
if ( !m_xControlModel.is() )
throw DisposedException(); // caught by the caller (the create method)
// start listening at the model
startModelListening();
// announce the XAccessible to our base class
OAccessibleControlContext_Base::lateInit( _rxCreator );
}
//--------------------------------------------------------------------
OAccessibleControlContext* OAccessibleControlContext::create( const Reference< XAccessible >& _rxCreator ) SAL_THROW( ( ) )
{
OAccessibleControlContext* pNew = NULL;
try
{
pNew = new OAccessibleControlContext;
pNew->Init( _rxCreator );
}
catch( const Exception& )
{
OSL_FAIL( "OAccessibleControlContext::create: caught an exception from the late ctor!" );
}
return pNew;
}
//--------------------------------------------------------------------
void OAccessibleControlContext::startModelListening( ) SAL_THROW( ( Exception ) )
{
Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::startModelListening: invalid model!" );
if ( xModelComp.is() )
xModelComp->addEventListener( this );
}
//--------------------------------------------------------------------
void OAccessibleControlContext::stopModelListening( ) SAL_THROW( ( Exception ) )
{
Reference< XComponent > xModelComp( m_xControlModel, UNO_QUERY );
OSL_ENSURE( xModelComp.is(), "OAccessibleControlContext::stopModelListening: invalid model!" );
if ( xModelComp.is() )
xModelComp->removeEventListener( this );
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL OAccessibleControlContext::getAccessibleChildCount( ) throw (RuntimeException)
{
// we do not have children
return 0;
}
//--------------------------------------------------------------------
Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleChild( sal_Int32 ) throw (IndexOutOfBoundsException, RuntimeException)
{
// we do not have children
throw IndexOutOfBoundsException();
}
//--------------------------------------------------------------------
Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleParent( ) throw (RuntimeException)
{
OContextEntryGuard aGuard( this );
OSL_ENSURE( implGetForeignControlledParent().is(), "OAccessibleControlContext::getAccessibleParent: somebody forgot to set a parent!" );
// this parent of us is foreign controlled - somebody has to set it using the OAccessibleImplementationAccess
// class, before integrating our instance into an AccessibleDocumentModel
return implGetForeignControlledParent();
}
//--------------------------------------------------------------------
sal_Int16 SAL_CALL OAccessibleControlContext::getAccessibleRole( ) throw (RuntimeException)
{
return AccessibleRole::SHAPE;
}
//--------------------------------------------------------------------
::rtl::OUString SAL_CALL OAccessibleControlContext::getAccessibleDescription( ) throw (RuntimeException)
{
OContextEntryGuard aGuard( this );
return getModelStringProperty( "HelpText" );
}
//--------------------------------------------------------------------
::rtl::OUString SAL_CALL OAccessibleControlContext::getAccessibleName( ) throw (RuntimeException)
{
OContextEntryGuard aGuard( this );
return getModelStringProperty( "Name" );
}
//--------------------------------------------------------------------
Reference< XAccessibleRelationSet > SAL_CALL OAccessibleControlContext::getAccessibleRelationSet( ) throw (RuntimeException)
{
return NULL;
}
//--------------------------------------------------------------------
Reference< XAccessibleStateSet > SAL_CALL OAccessibleControlContext::getAccessibleStateSet( ) throw (RuntimeException)
{
::osl::MutexGuard aGuard( GetMutex() );
// no OContextEntryGuard here, as we do not want to throw an exception in case we're not alive anymore
::utl::AccessibleStateSetHelper* pStateSet = NULL;
if ( isAlive() )
{
// no own states, only the ones which are foreign controlled
pStateSet = new ::utl::AccessibleStateSetHelper( implGetForeignControlledStates() );
}
else
{ // only the DEFUNC state if we're already disposed
pStateSet = new ::utl::AccessibleStateSetHelper;
pStateSet->AddState( AccessibleStateType::DEFUNC );
}
return pStateSet;
}
//--------------------------------------------------------------------
void SAL_CALL OAccessibleControlContext::disposing( const EventObject&
#if OSL_DEBUG_LEVEL > 0
_rSource
#endif
) throw ( RuntimeException )
{
OSL_ENSURE( Reference< XPropertySet >( _rSource.Source, UNO_QUERY ).get() == m_xControlModel.get(),
"OAccessibleControlContext::disposing: where did this come from?" );
stopModelListening( );
m_xControlModel.clear();
m_xModelPropsInfo.clear();
OAccessibleControlContext_Base::disposing();
}
//--------------------------------------------------------------------
::rtl::OUString OAccessibleControlContext::getModelStringProperty( const sal_Char* _pPropertyName )
{
::rtl::OUString sReturn;
try
{
if ( !m_xModelPropsInfo.is() && m_xControlModel.is() )
m_xModelPropsInfo = m_xControlModel->getPropertySetInfo();
::rtl::OUString sPropertyName( ::rtl::OUString::createFromAscii( _pPropertyName ) );
if ( m_xModelPropsInfo.is() && m_xModelPropsInfo->hasPropertyByName( sPropertyName ) )
m_xControlModel->getPropertyValue( sPropertyName ) >>= sReturn;
}
catch( const Exception& )
{
OSL_FAIL( "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
}
return sReturn;
}
//--------------------------------------------------------------------
Window* OAccessibleControlContext::implGetWindow( Reference< awt::XWindow >* _pxUNOWindow ) const
{
Reference< awt::XControl > xControl( getAccessibleCreator(), UNO_QUERY );
Reference< awt::XWindow > xWindow;
if ( xControl.is() )
xWindow = xWindow.query( xControl->getPeer() );
Window* pWindow = xWindow.is() ? VCLUnoHelper::GetWindow( xWindow ) : NULL;
if ( _pxUNOWindow )
*_pxUNOWindow = xWindow;
return pWindow;
}
//--------------------------------------------------------------------
awt::Rectangle SAL_CALL OAccessibleControlContext::implGetBounds( ) throw (RuntimeException)
{
SolarMutexGuard aSolarGuard;
// want to do some VCL stuff here ...
OContextEntryGuard aGuard( this );
OSL_FAIL( "OAccessibleControlContext::implGetBounds: performance issue: forced to calc the size myself!" );
// In design mode (and this is what this class is for), the surrounding shape (if any) should handle this call
// The problem is that in design mode, our size may not be correct (in the drawing layer, controls are
// positioned/sized for painting only), and that calculation of our position is expensive
// what we know (or can obtain from somewhere):
// * the PosSize of our peer, relative to it's parent window
// * the parent window which the PosSize is relative to
// * our foreign controlled accessible parent
// from this info, we can determine the the position of our peer relative to the foreign parent
// our control
Reference< awt::XWindow > xWindow;
Window* pVCLWindow = implGetWindow( &xWindow );
awt::Rectangle aBounds( 0, 0, 0, 0 );
if ( xWindow.is() )
{
// ugly, but .... though the XWindow has a getPosSize, it is impossible to determine the
// parent which this position/size is relative to. This means we must tunnel UNO and ask the
// implementation
Window* pVCLParent = pVCLWindow ? pVCLWindow->GetParent() : NULL;
// the relative location of the window
::Point aWindowRelativePos( 0, 0);
if ( pVCLWindow )
aWindowRelativePos = pVCLWindow->GetPosPixel();
// the screnn position of the "window parent" of the control
::Point aVCLParentScreenPos( 0, 0 );
if ( pVCLParent )
aVCLParentScreenPos = pVCLParent->GetPosPixel();
// the screen position of the "accessible parent" of the control
Reference< XAccessible > xParentAcc( implGetForeignControlledParent() );
Reference< XAccessibleComponent > xParentAccComponent;
if ( xParentAcc.is() )
xParentAccComponent = xParentAccComponent.query( xParentAcc->getAccessibleContext() );
awt::Point aAccParentScreenPos( 0, 0 );
if ( xParentAccComponent.is() )
aAccParentScreenPos = xParentAccComponent->getLocationOnScreen();
// now the size of the control
aBounds = xWindow->getPosSize();
// correct the pos
aBounds.X = aWindowRelativePos.X() + aVCLParentScreenPos.X() - aAccParentScreenPos.X;
aBounds.Y = aWindowRelativePos.Y() + aVCLParentScreenPos.Y() - aAccParentScreenPos.Y;
}
return aBounds;
}
//--------------------------------------------------------------------
Reference< XAccessible > SAL_CALL OAccessibleControlContext::getAccessibleAtPoint( const awt::Point& /* _rPoint */ ) throw (RuntimeException)
{
// no children at all
return NULL;
}
//--------------------------------------------------------------------
void SAL_CALL OAccessibleControlContext::grabFocus( ) throw (RuntimeException)
{
OSL_FAIL( "OAccessibleControlContext::grabFocus: !isFocusTraversable, but grabFocus!" );
}
//--------------------------------------------------------------------
Any SAL_CALL OAccessibleControlContext::getAccessibleKeyBinding( ) throw (RuntimeException)
{
// we do not have any key bindings to activate a UNO control in design mode
return Any();
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL OAccessibleControlContext::getForeground( ) throw (::com::sun::star::uno::RuntimeException)
{
SolarMutexGuard aSolarGuard;
// want to do some VCL stuff here ...
OContextEntryGuard aGuard( this );
Window* pWindow = implGetWindow( );
sal_Int32 nColor = 0;
if ( pWindow )
{
if ( pWindow->IsControlForeground() )
nColor = pWindow->GetControlForeground().GetColor();
else
{
Font aFont;
if ( pWindow->IsControlFont() )
aFont = pWindow->GetControlFont();
else
aFont = pWindow->GetFont();
nColor = aFont.GetColor().GetColor();
}
}
return nColor;
}
//--------------------------------------------------------------------
sal_Int32 SAL_CALL OAccessibleControlContext::getBackground( ) throw (::com::sun::star::uno::RuntimeException)
{
SolarMutexGuard aSolarGuard;
// want to do some VCL stuff here ...
OContextEntryGuard aGuard( this );
Window* pWindow = implGetWindow( );
sal_Int32 nColor = 0;
if ( pWindow )
{
if ( pWindow->IsControlBackground() )
nColor = pWindow->GetControlBackground().GetColor();
else
nColor = pWindow->GetBackground().GetColor().GetColor();
}
return nColor;
}
//........................................................................
} //namespace toolkit
//........................................................................
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|