xref: /trunk/main/svtools/source/control/valueimp.hxx (revision 2df387e6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <vos/mutex.hxx>
25 #include <tools/list.hxx>
26 #include <tools/color.hxx>
27 #include <tools/string.hxx>
28 #ifndef _IMAGE_HXX
29 #include <vcl/image.hxx>
30 #endif
31 #include <rtl/uuid.h>
32 #include <cppuhelper/implbase5.hxx>
33 #include <cppuhelper/compbase6.hxx>
34 #include <comphelper/broadcasthelper.hxx>
35 #include <com/sun/star/lang/XUnoTunnel.hpp>
36 #include <com/sun/star/accessibility/XAccessible.hpp>
37 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
38 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
39 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
40 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
41 #include <com/sun/star/lang/DisposedException.hpp>
42 
43 #include <memory>
44 #include <vector>
45 
46 // -----------
47 // - Defines -
48 // -----------
49 
50 #define ITEM_OFFSET 				4
51 #define ITEM_OFFSET_DOUBLE			6
52 #define NAME_LINE_OFF_X 			2
53 #define NAME_LINE_OFF_Y 			2
54 #define NAME_LINE_HEIGHT			2
55 #define NAME_OFFSET 				2
56 #define SCRBAR_OFFSET				1
57 #define VALUESET_ITEM_NONEITEM		0xFFFE
58 #define VALUESET_SCROLL_OFFSET		4
59 
60 // --------------------
61 // - ValueSetItemType -
62 // --------------------
63 
64 enum ValueSetItemType
65 {
66 	VALUESETITEM_NONE,
67 	VALUESETITEM_IMAGE,
68 	VALUESETITEM_COLOR,
69 	VALUESETITEM_USERDRAW,
70 	VALUESETITEM_SPACE
71 };
72 
73 // ----------------
74 // - ValueSetItem -
75 // ----------------
76 
77 class ValueSet;
78 
79 struct ValueSetItem
80 {
81 	ValueSet&           mrParent;
82     sal_uInt16				mnId;
83 	sal_uInt16				mnBits;
84 	ValueSetItemType	meType;
85 	Image				maImage;
86 	Color				maColor;
87 	XubString			maText;
88 	void*				mpData;
89 	Rectangle			maRect;
90 	sal_Bool				bSelected:1;
91 	::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >* mpxAcc;
92 
93     ValueSetItem( ValueSet& rParent );
94     ~ValueSetItem();
95 
96     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >
97                         GetAccessible( bool bIsTransientChildrenDisabled );
98      void               ClearAccessible();
99 };
100 
101 // -----------------------------------------------------------------------------
102 
103 DECLARE_LIST( ValueItemList, ValueSetItem* )
104 
105 // -----------------------------------------------------------------------------
106 
107 struct ValueSet_Impl
108 {
109     ::std::auto_ptr< ValueItemList >    mpItemList;
110     bool                                mbIsTransientChildrenDisabled;
111 	Link								maHighlightHdl;
112 
ValueSet_ImplValueSet_Impl113     ValueSet_Impl() :   mpItemList( ::std::auto_ptr< ValueItemList >( new ValueItemList() ) ),
114                         mbIsTransientChildrenDisabled( false )
115     {
116     }
117 };
118 
119 // ---------------
120 // - ValueSetAcc -
121 // ---------------
122 
123 typedef ::cppu::WeakComponentImplHelper6<
124     ::com::sun::star::accessibility::XAccessible,
125     ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
126     ::com::sun::star::accessibility::XAccessibleContext,
127     ::com::sun::star::accessibility::XAccessibleComponent,
128     ::com::sun::star::accessibility::XAccessibleSelection,
129     ::com::sun::star::lang::XUnoTunnel >
130     ValueSetAccComponentBase;
131 
132 class ValueSetAcc :
133     public ::comphelper::OBaseMutex,
134     public ValueSetAccComponentBase
135 {
136 public:
137 
138     ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled );
139     ~ValueSetAcc();
140 
141     void                FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
HasAccessibleListeners() const142     sal_Bool                HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
143 
144     static ValueSetAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
145 
146 public:
147 
148     /** Called by the corresponding ValueSet when it gets the focus.
149         Stores the new focus state and broadcasts a state change event.
150     */
151     void GetFocus (void);
152 
153     /** Called by the corresponding ValueSet when it loses the focus.
154         Stores the new focus state and broadcasts a state change event.
155     */
156     void LoseFocus (void);
157 
158 
159     // XAccessible
160     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException);
161 
162     // XAccessibleEventBroadcaster
163     using cppu::WeakComponentImplHelper6<com::sun::star::accessibility::XAccessible, com::sun::star::accessibility::XAccessibleEventBroadcaster, com::sun::star::accessibility::XAccessibleContext, com::sun::star::accessibility::XAccessibleComponent, com::sun::star::accessibility::XAccessibleSelection, com::sun::star::lang::XUnoTunnel>::addEventListener;
164     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
165     using cppu::WeakComponentImplHelper6<com::sun::star::accessibility::XAccessible, com::sun::star::accessibility::XAccessibleEventBroadcaster, com::sun::star::accessibility::XAccessibleContext, com::sun::star::accessibility::XAccessibleComponent, com::sun::star::accessibility::XAccessibleSelection, com::sun::star::lang::XUnoTunnel>::removeEventListener;
166     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
167 
168     // XAccessibleContext
169     virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
170     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);
171     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException);
172     virtual sal_Int32 SAL_CALL getAccessibleIndexInParent(  ) throw (::com::sun::star::uno::RuntimeException);
173     virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException);
174     virtual ::rtl::OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException);
175     virtual ::rtl::OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException);
176     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException);
177     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException);
178     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale(  ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
179 
180     // XAccessibleComponent
181     virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
182     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);
183     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds(  ) throw (::com::sun::star::uno::RuntimeException);
184     virtual ::com::sun::star::awt::Point SAL_CALL getLocation(  ) throw (::com::sun::star::uno::RuntimeException);
185     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen(  ) throw (::com::sun::star::uno::RuntimeException);
186     virtual ::com::sun::star::awt::Size SAL_CALL getSize(  ) throw (::com::sun::star::uno::RuntimeException);
187     virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException);
188     virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding(  ) throw (::com::sun::star::uno::RuntimeException);
189     virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException);
190     virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException);
191 
192     // XAccessibleSelection
193     virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
194     virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
195     virtual void SAL_CALL clearAccessibleSelection(  ) throw (::com::sun::star::uno::RuntimeException);
196     virtual void SAL_CALL selectAllAccessibleChildren(  ) throw (::com::sun::star::uno::RuntimeException);
197     virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
198     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);
199     virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException);
200 
201     // XUnoTunnel
202     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException );
203 
204 private:
205     //    ::vos::OMutex                                                                                                           maMutex;
206     ::std::vector< ::com::sun::star::uno::Reference<
207         ::com::sun::star::accessibility::XAccessibleEventListener > >   mxEventListeners;
208     ValueSet*                                                           mpParent;
209     bool                                                                mbIsTransientChildrenDisabled;
210     /// The current FOCUSED state.
211     bool mbIsFocused;
212 
213 	static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
214 
215     /** Tell all listeners that the object is dying.  This callback is
216         usually called from the WeakComponentImplHelper class.
217     */
218     virtual void SAL_CALL disposing (void);
219 
220     /** Return the number of items.  This takes the None-Item into account.
221     */
222     sal_uInt16 getItemCount (void) const;
223 
224     /** Return the item associated with the given index.  The None-Item is
225         taken into account which, when present, is taken to be the first
226         (with index 0) item.
227         @param nIndex
228             Index of the item to return.  The index 0 denotes the None-Item
229             when present.
230         @return
231             Returns NULL when the given index is out of range.
232     */
233     ValueSetItem* getItem (sal_uInt16 nIndex) const;
234 
235     /** Check whether or not the object has been disposed (or is in the
236         state of being disposed).  If that is the case then
237         DisposedException is thrown to inform the (indirect) caller of the
238         foul deed.
239     */
240     void ThrowIfDisposed (void)
241         throw (::com::sun::star::lang::DisposedException);
242 
243     /** Check whether or not the object has been disposed (or is in the
244         state of being disposed).
245 
246         @return sal_True, if the object is disposed or in the course
247         of being disposed. Otherwise, sal_False is returned.
248     */
249     sal_Bool IsDisposed (void);
250 
251     /** Check whether the value set has a 'none' field, i.e. a field (button)
252         that deselects any items (selects none of them).
253         @return
254             Returns <true/> if there is a 'none' field and <false/> it it is
255             missing.
256     */
257     bool HasNoneField (void) const;
258 };
259 
260 // ----------------
261 // - ValueItemAcc -
262 // ----------------
263 
264 class ValueItemAcc : public ::cppu::WeakImplHelper5< ::com::sun::star::accessibility::XAccessible,
265                                                      ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
266                                                      ::com::sun::star::accessibility::XAccessibleContext,
267                                                      ::com::sun::star::accessibility::XAccessibleComponent,
268                                                      ::com::sun::star::lang::XUnoTunnel >
269 {
270 private:
271 
272     ::std::vector< ::com::sun::star::uno::Reference<
273         ::com::sun::star::accessibility::XAccessibleEventListener > >   mxEventListeners;
274     ::vos::OMutex                                                       maMutex;
275     ValueSetItem*                                                       mpParent;
276     bool                                                                mbIsTransientChildrenDisabled;
277 
278 	static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
279 
280 public:
281 
282     ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled );
283     ~ValueItemAcc();
284 
285     void    ParentDestroyed();
286 
287     void    FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
HasAccessibleListeners() const288     sal_Bool    HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
289 
290     static ValueItemAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
291 
292 public:
293 
294     // XAccessible
295     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (::com::sun::star::uno::RuntimeException);
296 
297     // XAccessibleEventBroadcaster
298     virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
299     virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException);
300 
301     // XAccessibleContext
302     virtual sal_Int32 SAL_CALL getAccessibleChildCount(  ) throw (::com::sun::star::uno::RuntimeException);
303     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);
304     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent(  ) throw (::com::sun::star::uno::RuntimeException);
305     virtual sal_Int32 SAL_CALL getAccessibleIndexInParent(  ) throw (::com::sun::star::uno::RuntimeException);
306     virtual sal_Int16 SAL_CALL getAccessibleRole(  ) throw (::com::sun::star::uno::RuntimeException);
307     virtual ::rtl::OUString SAL_CALL getAccessibleDescription(  ) throw (::com::sun::star::uno::RuntimeException);
308     virtual ::rtl::OUString SAL_CALL getAccessibleName(  ) throw (::com::sun::star::uno::RuntimeException);
309     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet(  ) throw (::com::sun::star::uno::RuntimeException);
310     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet(  ) throw (::com::sun::star::uno::RuntimeException);
311     virtual ::com::sun::star::lang::Locale SAL_CALL getLocale(  ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException);
312 
313     // XAccessibleComponent
314     virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException);
315     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);
316     virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds(  ) throw (::com::sun::star::uno::RuntimeException);
317     virtual ::com::sun::star::awt::Point SAL_CALL getLocation(  ) throw (::com::sun::star::uno::RuntimeException);
318     virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen(  ) throw (::com::sun::star::uno::RuntimeException);
319     virtual ::com::sun::star::awt::Size SAL_CALL getSize(  ) throw (::com::sun::star::uno::RuntimeException);
320     virtual void SAL_CALL grabFocus(  ) throw (::com::sun::star::uno::RuntimeException);
321     virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding(  ) throw (::com::sun::star::uno::RuntimeException);
322     virtual sal_Int32 SAL_CALL getForeground(  ) throw (::com::sun::star::uno::RuntimeException);
323     virtual sal_Int32 SAL_CALL getBackground(  ) throw (::com::sun::star::uno::RuntimeException);
324 
325     // XUnoTunnel
326     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException );
327 };
328