Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVTOOLS_SOURCE_CONTROL_VALUEIMP_HXX
21 : #define INCLUDED_SVTOOLS_SOURCE_CONTROL_VALUEIMP_HXX
22 :
23 : #include <osl/mutex.hxx>
24 : #include <tools/color.hxx>
25 : #include <vcl/image.hxx>
26 : #include <cppuhelper/implbase5.hxx>
27 : #include <cppuhelper/compbase6.hxx>
28 : #include <comphelper/broadcasthelper.hxx>
29 : #include <com/sun/star/lang/XUnoTunnel.hpp>
30 : #include <com/sun/star/accessibility/XAccessible.hpp>
31 : #include <com/sun/star/accessibility/XAccessibleContext.hpp>
32 : #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
33 : #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
34 : #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
35 : #include <com/sun/star/lang/DisposedException.hpp>
36 :
37 : #include <vector>
38 :
39 : #define VALUESET_ITEM_NONEITEM 0xFFFE
40 :
41 : enum ValueSetItemType
42 : {
43 : VALUESETITEM_NONE,
44 : VALUESETITEM_IMAGE,
45 : VALUESETITEM_COLOR,
46 : VALUESETITEM_USERDRAW
47 : };
48 :
49 : class ValueSet;
50 :
51 : struct ValueSetItem
52 : {
53 : ValueSet& mrParent;
54 : sal_uInt16 mnId;
55 : sal_uInt8 meType;
56 : bool mbVisible;
57 : Image maImage;
58 : Color maColor;
59 : OUString maText;
60 : void* mpData;
61 : bool mbSelected;
62 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >* mpxAcc;
63 :
64 : ValueSetItem( ValueSet& rParent );
65 : ~ValueSetItem();
66 :
67 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
68 : GetAccessible( bool bIsTransientChildrenDisabled );
69 : };
70 :
71 : typedef ::cppu::PartialWeakComponentImplHelper6<
72 : ::com::sun::star::accessibility::XAccessible,
73 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
74 : ::com::sun::star::accessibility::XAccessibleContext,
75 : ::com::sun::star::accessibility::XAccessibleComponent,
76 : ::com::sun::star::accessibility::XAccessibleSelection,
77 : ::com::sun::star::lang::XUnoTunnel >
78 : ValueSetAccComponentBase;
79 :
80 : class ValueSetAcc :
81 : public ::comphelper::OBaseMutex,
82 : public ValueSetAccComponentBase
83 : {
84 : public:
85 :
86 : ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled );
87 : virtual ~ValueSetAcc();
88 :
89 : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
90 0 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
91 :
92 : static ValueSetAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
93 :
94 : public:
95 :
96 : /** Called by the corresponding ValueSet when it gets the focus.
97 : Stores the new focus state and broadcasts a state change event.
98 : */
99 : void GetFocus (void);
100 :
101 : /** Called by the corresponding ValueSet when it loses the focus.
102 : Stores the new focus state and broadcasts a state change event.
103 : */
104 : void LoseFocus (void);
105 :
106 : // XComponent
107 0 : virtual void SAL_CALL dispose()throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
108 0 : { WeakComponentImplHelperBase::dispose(); }
109 0 : virtual void SAL_CALL addEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
110 0 : { WeakComponentImplHelperBase::addEventListener(xListener); }
111 0 : virtual void SAL_CALL removeEventListener(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > & xListener)throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE
112 0 : { WeakComponentImplHelperBase::removeEventListener(xListener); }
113 :
114 : // XAccessible
115 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
116 :
117 : // XAccessibleEventBroadcaster
118 : virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 : virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 :
121 : // XAccessibleContext
122 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 : 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, std::exception) SAL_OVERRIDE;
124 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
125 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
126 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
128 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 :
133 : // XAccessibleComponent
134 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 : 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, std::exception) SAL_OVERRIDE;
136 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
137 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
142 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
143 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 :
145 : // XAccessibleSelection
146 : virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 : virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
148 : virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 : virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
150 : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
151 : 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, std::exception) SAL_OVERRIDE;
152 : virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
153 :
154 : // XUnoTunnel
155 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
156 :
157 : private:
158 : ::std::vector< ::com::sun::star::uno::Reference<
159 : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
160 : ValueSet* mpParent;
161 : bool mbIsTransientChildrenDisabled;
162 : /// The current FOCUSED state.
163 : bool mbIsFocused;
164 :
165 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
166 :
167 : /** Tell all listeners that the object is dying. This callback is
168 : usually called from the WeakComponentImplHelper class.
169 : */
170 : virtual void SAL_CALL disposing (void) SAL_OVERRIDE;
171 :
172 : /** Return the number of items. This takes the None-Item into account.
173 : */
174 : sal_uInt16 getItemCount (void) const;
175 :
176 : /** Return the item associated with the given index. The None-Item is
177 : taken into account which, when present, is taken to be the first
178 : (with index 0) item.
179 : @param nIndex
180 : Index of the item to return. The index 0 denotes the None-Item
181 : when present.
182 : @return
183 : Returns NULL when the given index is out of range.
184 : */
185 : ValueSetItem* getItem (sal_uInt16 nIndex) const;
186 :
187 : /** Check whether or not the object has been disposed (or is in the
188 : state of being disposed). If that is the case then
189 : DisposedException is thrown to inform the (indirect) caller of the
190 : foul deed.
191 : */
192 : void ThrowIfDisposed (void)
193 : throw (::com::sun::star::lang::DisposedException);
194 :
195 : /** Check whether the value set has a 'none' field, i.e. a field (button)
196 : that deselects any items (selects none of them).
197 : @return
198 : Returns <true/> if there is a 'none' field and <false/> it it is
199 : missing.
200 : */
201 : bool HasNoneField (void) const;
202 : };
203 :
204 : class ValueItemAcc : public ::cppu::WeakImplHelper5< ::com::sun::star::accessibility::XAccessible,
205 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
206 : ::com::sun::star::accessibility::XAccessibleContext,
207 : ::com::sun::star::accessibility::XAccessibleComponent,
208 : ::com::sun::star::lang::XUnoTunnel >
209 : {
210 : private:
211 :
212 : ::std::vector< ::com::sun::star::uno::Reference<
213 : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
214 : ::osl::Mutex maMutex;
215 : ValueSetItem* mpParent;
216 : bool mbIsTransientChildrenDisabled;
217 :
218 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
219 :
220 : public:
221 :
222 : ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled );
223 : virtual ~ValueItemAcc();
224 :
225 : void ParentDestroyed();
226 :
227 : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
228 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
229 :
230 : static ValueItemAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
231 :
232 : public:
233 :
234 : // XAccessible
235 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
236 :
237 : // XAccessibleEventBroadcaster
238 : virtual void SAL_CALL addAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 : virtual void SAL_CALL removeAccessibleEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
240 :
241 : // XAccessibleContext
242 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
243 : 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, std::exception) SAL_OVERRIDE;
244 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
245 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
246 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
247 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
249 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
250 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 :
253 : // XAccessibleComponent
254 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
255 : 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, std::exception) SAL_OVERRIDE;
256 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
257 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
258 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
259 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
260 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
261 : virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException);
262 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 :
265 : // XUnoTunnel
266 : virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
267 : };
268 :
269 : #endif // INCLUDED_SVTOOLS_SOURCE_CONTROL_VALUEIMP_HXX
270 :
271 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|