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 : explicit 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::WeakComponentImplHelper6<
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();
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();
105 :
106 : // XAccessible
107 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
108 :
109 : // XAccessibleEventBroadcaster
110 : 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;
111 : 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;
112 :
113 : // XAccessibleContext
114 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
115 : 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;
116 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
117 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
118 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
119 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
120 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
121 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
122 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
123 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
124 :
125 : // XAccessibleComponent
126 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
127 : 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;
128 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
129 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
130 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
131 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
132 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
133 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
134 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
135 :
136 : // XAccessibleSelection
137 : virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
138 : virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
139 : virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
140 : virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
141 : virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
142 : 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;
143 : virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
144 :
145 : // XUnoTunnel
146 : 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;
147 :
148 : private:
149 : ::std::vector< ::com::sun::star::uno::Reference<
150 : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
151 : VclPtr<ValueSet> mpParent;
152 : bool mbIsTransientChildrenDisabled;
153 : /// The current FOCUSED state.
154 : bool mbIsFocused;
155 :
156 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
157 :
158 : /** Tell all listeners that the object is dying. This callback is
159 : usually called from the WeakComponentImplHelper class.
160 : */
161 : virtual void SAL_CALL disposing() SAL_OVERRIDE;
162 :
163 : /** Return the number of items. This takes the None-Item into account.
164 : */
165 : sal_uInt16 getItemCount() const;
166 :
167 : /** Return the item associated with the given index. The None-Item is
168 : taken into account which, when present, is taken to be the first
169 : (with index 0) item.
170 : @param nIndex
171 : Index of the item to return. The index 0 denotes the None-Item
172 : when present.
173 : @return
174 : Returns NULL when the given index is out of range.
175 : */
176 : ValueSetItem* getItem (sal_uInt16 nIndex) const;
177 :
178 : /** Check whether or not the object has been disposed (or is in the
179 : state of being disposed). If that is the case then
180 : DisposedException is thrown to inform the (indirect) caller of the
181 : foul deed.
182 : */
183 : void ThrowIfDisposed()
184 : throw (::com::sun::star::lang::DisposedException);
185 :
186 : /** Check whether the value set has a 'none' field, i.e. a field (button)
187 : that deselects any items (selects none of them).
188 : @return
189 : Returns <true/> if there is a 'none' field and <false/> if it is
190 : missing.
191 : */
192 : bool HasNoneField() const;
193 : };
194 :
195 : class ValueItemAcc : public ::cppu::WeakImplHelper5< ::com::sun::star::accessibility::XAccessible,
196 : ::com::sun::star::accessibility::XAccessibleEventBroadcaster,
197 : ::com::sun::star::accessibility::XAccessibleContext,
198 : ::com::sun::star::accessibility::XAccessibleComponent,
199 : ::com::sun::star::lang::XUnoTunnel >
200 : {
201 : private:
202 :
203 : ::std::vector< ::com::sun::star::uno::Reference<
204 : ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners;
205 : ::osl::Mutex maMutex;
206 : ValueSetItem* mpParent;
207 : bool mbIsTransientChildrenDisabled;
208 :
209 : static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId();
210 :
211 : public:
212 :
213 : ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled );
214 : virtual ~ValueItemAcc();
215 :
216 : void ParentDestroyed();
217 :
218 : void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue );
219 : bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); }
220 :
221 : static ValueItemAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw();
222 :
223 : public:
224 :
225 : // XAccessible
226 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
227 :
228 : // XAccessibleEventBroadcaster
229 : 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;
230 : 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;
231 :
232 : // XAccessibleContext
233 : virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
234 : 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;
235 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
236 : virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
237 : virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
238 : virtual OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
239 : virtual OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
240 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
241 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
242 : virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
243 :
244 : // XAccessibleComponent
245 : virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
246 : 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;
247 : virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
248 : virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
249 : virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
250 : virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
251 : virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
252 : virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
253 : virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
254 :
255 : // XUnoTunnel
256 : 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;
257 : };
258 :
259 : #endif // INCLUDED_SVTOOLS_SOURCE_CONTROL_VALUEIMP_HXX
260 :
261 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|