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
|
/*************************************************************************
*
* $RCSfile: AccessibleControlShape.cxx,v $
*
* $Revision: 1.3 $
*
* last change: $Author: fs $ $Date: 2002-04-29 16:51:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
*
* - GNU Lesser General Public License Version 2.1
* - Sun Industry Standards Source License Version 1.1
*
* Sun Microsystems Inc., October, 2000
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2000 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
*
* Sun Industry Standards Source License Version 1.1
* =================================================
* The contents of this file are subject to the Sun Industry Standards
* Source License Version 1.1 (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.openoffice.org/license.html.
*
* Software provided under this License is provided on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
* See the License for the specific provisions governing your rights and
* obligations concerning the Software.
*
* The Initial Developer of the Original Code is: Sun Microsystems, Inc.
*
* Copyright: 2000 by Sun Microsystems, Inc.
*
* All Rights Reserved.
*
* Contributor(s): _______________________________________
*
*
************************************************************************/
#ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_CONTROL_SHAPE_HXX
#include "AccessibleControlShape.hxx"
#endif
#ifndef _SVX_ACCESSIBILITY_DESCRIPTION_GENERATOR_HXX
#include "DescriptionGenerator.hxx"
#endif
#ifndef _COM_SUN_STAR_DRAWING_XCONTROLSHAPE_HPP_
#include <com/sun/star/drawing/XControlShape.hpp>
#endif
#include <drafts/com/sun/star/accessibility/AccessibleEventId.hpp>
#include "ShapeTypeHandler.hxx"
#include "SvxShapeTypes.hxx"
using namespace accessibility;
using namespace ::rtl;
using namespace ::com::sun::star;
using namespace ::drafts::com::sun::star::accessibility;
using ::com::sun::star::uno::Reference;
//===== internal ============================================================
AccessibleControlShape::AccessibleControlShape (const ::com::sun::star::uno::Reference<
::com::sun::star::drawing::XShape>& rxShape,
const ::com::sun::star::uno::Reference<
::drafts::com::sun::star::accessibility::XAccessible>& rxParent,
const AccessibleShapeTreeInfo& rShapeTreeInfo,
long nIndex)
: AccessibleShape (rxShape, rxParent, rShapeTreeInfo, nIndex)
, mbListeningForName( sal_False )
, mbListeningForDesc( sal_False )
{
}
AccessibleControlShape::~AccessibleControlShape (void)
{
}
//===== XAccessible =========================================================
Reference<XAccessibleContext> SAL_CALL
AccessibleControlShape::getAccessibleContext (void)
throw (::com::sun::star::uno::RuntimeException)
{
// Here will later be the control shape asked for its control and that
// for its accessibility object.
return AccessibleShape::getAccessibleContext ();
}
//===== XServiceInfo ========================================================
::rtl::OUString SAL_CALL
AccessibleControlShape::getImplementationName (void)
throw (::com::sun::star::uno::RuntimeException)
{
return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AccessibleControlShape"));
}
/// Set this object's name if is different to the current name.
::rtl::OUString
AccessibleControlShape::CreateAccessibleBaseName (void)
throw (::com::sun::star::uno::RuntimeException)
{
::rtl::OUString sName;
ShapeTypeId nShapeType = ShapeTypeHandler::Instance().GetTypeId (mxShape);
switch (nShapeType)
{
case DRAWING_CONTROL:
sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("ControlShape"));
break;
default:
sName = ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("UnknownAccessibleControlShape"));
uno::Reference<drawing::XShapeDescriptor> xDescriptor (mxShape, uno::UNO_QUERY);
if (xDescriptor.is())
sName += ::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM(": "))
+ xDescriptor->getShapeType();
}
return sName;
}
//--------------------------------------------------------------------
namespace
{
//................................................................
const ::rtl::OUString& lcl_getNamePropertyName( )
{
static ::rtl::OUString s_sNamePropertyName( RTL_CONSTASCII_USTRINGPARAM( "Name" ) );
return s_sNamePropertyName;
}
//................................................................
const ::rtl::OUString& lcl_getDescPropertyName( )
{
static ::rtl::OUString s_sDescPropertyDesc( RTL_CONSTASCII_USTRINGPARAM( "HelpText" ) );
return s_sDescPropertyDesc;
}
}
//--------------------------------------------------------------------
::rtl::OUString
AccessibleControlShape::CreateAccessibleDescription (void)
throw (::com::sun::star::uno::RuntimeException)
{
DescriptionGenerator aDG (mxShape);
ShapeTypeId nShapeType = ShapeTypeHandler::Instance().GetTypeId (mxShape);
switch (nShapeType)
{
case DRAWING_CONTROL:
{
// check if we can obtain the "Desc" property from the model
::rtl::OUString sDesc( getControlModelStringProperty( lcl_getDescPropertyName() ) );
if ( !sDesc.getLength() )
{ // no -> use the default
aDG.Initialize (OUString::createFromAscii("Control"));
aDG.AddProperty (OUString::createFromAscii ("ControlBackground"),
DescriptionGenerator::COLOR,
OUString());
aDG.AddProperty (OUString::createFromAscii ("ControlBorder"),
DescriptionGenerator::INTEGER,
OUString());
}
// ensure that we are listening to the Name property
mbListeningForDesc = ensureListeningState( mbListeningForDesc, sal_True, lcl_getDescPropertyName() );
}
break;
default:
aDG.Initialize (::rtl::OUString::createFromAscii (
"Unknown accessible control shape"));
uno::Reference<drawing::XShapeDescriptor> xDescriptor (mxShape, uno::UNO_QUERY);
if (xDescriptor.is())
{
aDG.AppendString (::rtl::OUString (RTL_CONSTASCII_USTRINGPARAM("service name=")));
aDG.AppendString (xDescriptor->getShapeType());
}
}
return aDG();
}
//--------------------------------------------------------------------
IMPLEMENT_FORWARD_XINTERFACE2( AccessibleControlShape, AccessibleShape, AccessibleControlShape_Base )
IMPLEMENT_FORWARD_XTYPEPROVIDER2( AccessibleControlShape, AccessibleShape, AccessibleControlShape_Base )
// order matters in both cases: the second argument is the base class doing the ref counting
//--------------------------------------------------------------------
void SAL_CALL AccessibleControlShape::propertyChange( const beans::PropertyChangeEvent& _rEvent ) throw (uno::RuntimeException)
{
::osl::MutexGuard aGuard( maMutex );
::rtl::OUString sNewValue;
sal_Int16 nEventId = -1;
// check if it is the name or the description
if ( _rEvent.PropertyName.equals( lcl_getNamePropertyName() ) )
{
nEventId = AccessibleEventId::ACCESSIBLE_NAME_EVENT;
sNewValue = CreateAccessibleName();
}
else if ( _rEvent.PropertyName.equals( lcl_getDescPropertyName() ) )
{
nEventId = AccessibleEventId::ACCESSIBLE_DESCRIPTION_EVENT;
sNewValue = CreateAccessibleDescription();
}
#ifdef _DEBUG
else
{
OSL_ENSURE( sal_False, "AccessibleControlShape::propertyChange: where did this come from?" );
}
#endif
if ( -1 != nEventId )
{ // notify the AccessibilityListeners
CommitChange( nEventId, uno::makeAny( sNewValue ), uno::Any() );
// TODO: check this in reality: If the name is changed from non-empty to empty, this means
// that we remove ourself as listener _while_we_are_within_the_listener_call_. Don't know
// if the common implementation in cppuhelper can correctly handle this!
}
}
//--------------------------------------------------------------------
void SAL_CALL AccessibleControlShape::disposing (const lang::EventObject& _rSource) throw (uno::RuntimeException)
{
// simply disambiguate
AccessibleShape::disposing( _rSource );
}
//--------------------------------------------------------------------
sal_Bool AccessibleControlShape::ensureListeningState(
const sal_Bool _bCurrentlyListening, const sal_Bool _bNeedNewListening,
const ::rtl::OUString& _rPropertyName )
{
if ( ( _bCurrentlyListening == _bNeedNewListening ) || !ensureControlModelAccess() )
// nothing to do
return _bCurrentlyListening;
try
{
if ( !mxModelPropsMeta.is() || mxModelPropsMeta->hasPropertyByName( _rPropertyName ) )
{
// add or revoke as listener
if ( _bNeedNewListening )
mxControlModel->addPropertyChangeListener( _rPropertyName, static_cast< beans::XPropertyChangeListener* >( this ) );
else
mxControlModel->removePropertyChangeListener( _rPropertyName, static_cast< beans::XPropertyChangeListener* >( this ) );
}
}
catch( const uno::Exception& e )
{
e; // make compiler happy
OSL_ENSURE( sal_False, "AccessibleControlShape::ensureListeningState: could not change the listening state!" );
}
return _bNeedNewListening;
}
//--------------------------------------------------------------------
::rtl::OUString AccessibleControlShape::CreateAccessibleName (void) throw (uno::RuntimeException)
{
// check if we can obtain the "Name" property from the model
::rtl::OUString sName( getControlModelStringProperty( lcl_getNamePropertyName() ) );
if ( !sName.getLength() )
{ // no -> use the default
sName = AccessibleShape::CreateAccessibleName();
}
// now that somebody first asked us for our name, ensure that we are listening to name changes on the model
mbListeningForName = ensureListeningState( mbListeningForName, sal_True, lcl_getNamePropertyName() );
return sName;
}
//--------------------------------------------------------------------
void SAL_CALL AccessibleControlShape::disposing (void)
{
// ensure we're not listening
mbListeningForName = ensureListeningState( mbListeningForName, sal_False, lcl_getNamePropertyName() );
mbListeningForDesc = ensureListeningState( mbListeningForDesc, sal_False, lcl_getDescPropertyName() );
// release the model
mxControlModel.clear();
mxModelPropsMeta.clear();
// let the base do it's stuff
AccessibleShape::dispose();
}
//--------------------------------------------------------------------
sal_Bool AccessibleControlShape::ensureControlModelAccess() const SAL_THROW(())
{
if ( mxControlModel.is() )
return sal_True;
try
{
Reference< drawing::XControlShape > xShape( mxShape, uno::UNO_QUERY );
if ( xShape.is() )
const_cast< AccessibleControlShape* >( this )->mxControlModel = mxControlModel.query( xShape->getControl() );
if ( mxControlModel.is() )
const_cast< AccessibleControlShape* >( this )->mxModelPropsMeta = mxControlModel->getPropertySetInfo();
}
catch( const uno::Exception& e )
{
e; // make compiler happy
OSL_ENSURE( sal_False, "AccessibleControlShape::ensureControlModelAccess: caught an exception!" );
}
return mxControlModel.is();
}
//--------------------------------------------------------------------
::rtl::OUString AccessibleControlShape::getControlModelStringProperty( const ::rtl::OUString& _rPropertyName ) const SAL_THROW(())
{
::rtl::OUString sReturn;
try
{
if ( ensureControlModelAccess() )
{
if ( !mxModelPropsMeta.is() || mxModelPropsMeta->hasPropertyByName( _rPropertyName ) )
// ask only if a) the control does not have a PropertySetInfo object or b) it has, and the
// property in question is available
mxControlModel->getPropertyValue( _rPropertyName ) >>= sReturn;
}
}
catch( const uno::Exception& )
{
OSL_ENSURE( sal_False, "OAccessibleControlContext::getModelStringProperty: caught an exception!" );
}
return sReturn;
}
|