Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <osl/mutex.hxx>
30 : : #include <tools/color.hxx>
31 : : #include <tools/string.hxx>
32 : : #include <vcl/image.hxx>
33 : : #include <cppuhelper/implbase5.hxx>
34 : : #include <cppuhelper/compbase6.hxx>
35 : : #include <comphelper/broadcasthelper.hxx>
36 : : #include <com/sun/star/lang/XUnoTunnel.hpp>
37 : : #include <com/sun/star/accessibility/XAccessible.hpp>
38 : : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
39 : : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
40 : : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
41 : : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
42 : : #include <com/sun/star/lang/DisposedException.hpp>
43 : :
44 : : #include <vector>
45 : :
46 : : // -----------
47 : : // - Defines -
48 : : // -----------
49 : :
50 : : #define VALUESET_ITEM_NONEITEM 0xFFFE
51 : :
52 : : // --------------------
53 : : // - ValueSetItemType -
54 : : // --------------------
55 : :
56 : : enum ValueSetItemType
57 : : {
58 : : VALUESETITEM_NONE,
59 : : VALUESETITEM_IMAGE,
60 : : VALUESETITEM_COLOR,
61 : : VALUESETITEM_USERDRAW
62 : : };
63 : :
64 : : // ----------------
65 : : // - ValueSetItem -
66 : : // ----------------
67 : :
68 : : class ValueSet;
69 : :
70 : : struct ValueSetItem
71 : : {
72 : : ValueSet& mrParent;
73 : : sal_uInt16 mnId;
74 : : sal_uInt8 meType;
75 : : bool mbVisible;
76 : : Image maImage;
77 : : Color maColor;
78 : : XubString maText;
79 : : void* mpData;
80 : : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >* mpxAcc;
81 : :
82 : : ValueSetItem( ValueSet& rParent );
83 : : ~ValueSetItem();
84 : :
85 : : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
86 : : GetAccessible( bool bIsTransientChildrenDisabled );
87 : : };
88 : :
89 : : // ---------------
90 : : // - ValueSetAcc -
91 : : // ---------------
92 : :
93 : : typedef ::cppu::PartialWeakComponentImplHelper6<
94 : : ::com::sun::star::accessibility::XAccessible,
95 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
96 : : ::com::sun::star::accessibility::XAccessibleContext,
97 : : ::com::sun::star::accessibility::XAccessibleComponent,
98 : : ::com::sun::star::accessibility::XAccessibleSelection,
99 : : ::com::sun::star::lang::XUnoTunnel >
100 : : ValueSetAccComponentBase;
101 : :
102 : : class ValueSetAcc :
103 : : public ::comphelper::OBaseMutex,
104 : : public ValueSetAccComponentBase
105 : : {
106 : : public:
107 : :
108 : : ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled );
109 : : ~ValueSetAcc();
110 : :
111 : : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
112 : 0 : sal_Bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
113 : :
114 : : static ValueSetAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
115 : :
116 : : public:
117 : :
118 : : /** Called by the corresponding ValueSet when it gets the focus.
119 : : Stores the new focus state and broadcasts a state change event.
120 : : */
121 : : void GetFocus (void);
122 : :
123 : : /** Called by the corresponding ValueSet when it loses the focus.
124 : : Stores the new focus state and broadcasts a state change event.
125 : : */
126 : : void LoseFocus (void);
127 : :
128 : : // XComponent
129 : 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException)
130 : 0 : { WeakComponentImplHelperBase::dispose(); }
131 : 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
132 : 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
133 : 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException)
134 : 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
135 : :
136 : : // XAccessible
137 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException);
138 : :
139 : : // XAccessibleEventBroadcaster
140 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
141 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
142 : :
143 : : // XAccessibleContext
144 : : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
145 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
146 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException);
147 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException);
148 : : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException);
149 : : virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException);
150 : : virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException);
151 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException);
152 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException);
153 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
154 : :
155 : : // XAccessibleComponent
156 : : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
157 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
158 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException);
159 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException);
160 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException);
161 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException);
162 : : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException);
163 : : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
164 : : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
165 : : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
166 : :
167 : : // XAccessibleSelection
168 : : virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
169 : : virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
170 : : virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException);
171 : : virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException);
172 : : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
173 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
174 : : virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
175 : :
176 : : // XUnoTunnel
177 : : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException );
178 : :
179 : : private:
180 : : ::std::vector< ::com::sun::star::uno::Reference<
181 : : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
182 : : ValueSet* mpParent;
183 : : bool mbIsTransientChildrenDisabled;
184 : : /// The current FOCUSED state.
185 : : bool mbIsFocused;
186 : :
187 : : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
188 : :
189 : : /** Tell all listeners that the object is dying. This callback is
190 : : usually called from the WeakComponentImplHelper class.
191 : : */
192 : : virtual void SAL_CALL disposing (void);
193 : :
194 : : /** Return the number of items. This takes the None-Item into account.
195 : : */
196 : : sal_uInt16 getItemCount (void) const;
197 : :
198 : : /** Return the item associated with the given index. The None-Item is
199 : : taken into account which, when present, is taken to be the first
200 : : (with index 0) item.
201 : : @param nIndex
202 : : Index of the item to return. The index 0 denotes the None-Item
203 : : when present.
204 : : @return
205 : : Returns NULL when the given index is out of range.
206 : : */
207 : : ValueSetItem* getItem (sal_uInt16 nIndex) const;
208 : :
209 : : /** Check whether or not the object has been disposed (or is in the
210 : : state of beeing disposed). If that is the case then
211 : : DisposedException is thrown to inform the (indirect) caller of the
212 : : foul deed.
213 : : */
214 : : void ThrowIfDisposed (void)
215 : : throw (::com::sun::star::lang::DisposedException);
216 : :
217 : : /** Check whether the value set has a 'none' field, i.e. a field (button)
218 : : that deselects any items (selects none of them).
219 : : @return
220 : : Returns <true/> if there is a 'none' field and <false/> it it is
221 : : missing.
222 : : */
223 : : bool HasNoneField (void) const;
224 : : };
225 : :
226 : : // ----------------
227 : : // - ValueItemAcc -
228 : : // ----------------
229 : :
230 : : class ValueItemAcc : public ::cppu::WeakImplHelper5< ::com::sun::star::accessibility::XAccessible,
231 : : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
232 : : ::com::sun::star::accessibility::XAccessibleContext,
233 : : ::com::sun::star::accessibility::XAccessibleComponent,
234 : : ::com::sun::star::lang::XUnoTunnel >
235 : : {
236 : : private:
237 : :
238 : : ::std::vector< ::com::sun::star::uno::Reference<
239 : : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
240 : : ::osl::Mutex maMutex;
241 : : ValueSetItem* mpParent;
242 : : bool mbIsTransientChildrenDisabled;
243 : :
244 : : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
245 : :
246 : : public:
247 : :
248 : : ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled );
249 : : ~ValueItemAcc();
250 : :
251 : : void ParentDestroyed();
252 : :
253 : : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
254 : : sal_Bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
255 : :
256 : : static ValueItemAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
257 : :
258 : : public:
259 : :
260 : : // XAccessible
261 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException);
262 : :
263 : : // XAccessibleEventBroadcaster
264 : : virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
265 : : virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
266 : :
267 : : // XAccessibleContext
268 : : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException);
269 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
270 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException);
271 : : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException);
272 : : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException);
273 : : virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException);
274 : : virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException);
275 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException);
276 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException);
277 : : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
278 : :
279 : : // XAccessibleComponent
280 : : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
281 : : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
282 : : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException);
283 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException);
284 : : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException);
285 : : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException);
286 : : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException);
287 : : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
288 : : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException);
289 : : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException);
290 : :
291 : : // XUnoTunnel
292 : : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException );
293 : : };
294 : :
295 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|