1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: valueimp.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include <vos/mutex.hxx>
32 #include <tools/list.hxx>
33 #include <tools/color.hxx>
34 #include <tools/string.hxx>
36 #include <vcl/image.hxx>
39 #include <cppuhelper/implbase5.hxx>
40 #include <cppuhelper/compbase6.hxx>
41 #include <comphelper/broadcasthelper.hxx>
42 #include <com/sun/star/lang/XUnoTunnel.hpp>
43 #include <com/sun/star/accessibility/XAccessible.hpp>
44 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
45 #include <com/sun/star/accessibility/XAccessibleComponent.hpp>
46 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
47 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp>
48 #include <com/sun/star/lang/DisposedException.hpp>
58 #define ITEM_OFFSET_DOUBLE 6
59 #define NAME_LINE_OFF_X 2
60 #define NAME_LINE_OFF_Y 2
61 #define NAME_LINE_HEIGHT 2
63 #define SCRBAR_OFFSET 1
64 #define VALUESET_ITEM_NONEITEM 0xFFFE
65 #define VALUESET_SCROLL_OFFSET 4
67 // --------------------
68 // - ValueSetItemType -
69 // --------------------
76 VALUESETITEM_USERDRAW
,
91 ValueSetItemType meType
;
97 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>* mpxAcc
;
99 ValueSetItem( ValueSet
& rParent
);
102 ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
>
103 GetAccessible( bool bIsTransientChildrenDisabled
);
104 void ClearAccessible();
107 // -----------------------------------------------------------------------------
109 DECLARE_LIST( ValueItemList
, ValueSetItem
* )
111 // -----------------------------------------------------------------------------
115 ::std::auto_ptr
< ValueItemList
> mpItemList
;
116 bool mbIsTransientChildrenDisabled
;
118 ValueSet_Impl() : mpItemList( ::std::auto_ptr
< ValueItemList
>( new ValueItemList() ) ),
119 mbIsTransientChildrenDisabled( false )
128 typedef ::cppu::WeakComponentImplHelper6
<
129 ::com::sun::star::accessibility::XAccessible
,
130 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
131 ::com::sun::star::accessibility::XAccessibleContext
,
132 ::com::sun::star::accessibility::XAccessibleComponent
,
133 ::com::sun::star::accessibility::XAccessibleSelection
,
134 ::com::sun::star::lang::XUnoTunnel
>
135 ValueSetAccComponentBase
;
138 public ::comphelper::OBaseMutex
,
139 public ValueSetAccComponentBase
143 ValueSetAcc( ValueSet
* pParent
, bool bIsTransientChildrenDisabled
);
146 void FireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
147 BOOL
HasAccessibleListeners() const { return( mxEventListeners
.size() > 0 ); }
149 static ValueSetAcc
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxData
) throw();
153 /** Called by the corresponding ValueSet when it gets the focus.
154 Stores the new focus state and broadcasts a state change event.
156 void GetFocus (void);
158 /** Called by the corresponding ValueSet when it loses the focus.
159 Stores the new focus state and broadcasts a state change event.
161 void LoseFocus (void);
165 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
167 // XAccessibleEventBroadcaster
168 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
;
169 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
170 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
;
171 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
173 // XAccessibleContext
174 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
175 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
);
176 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
177 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
178 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
179 virtual ::rtl::OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
180 virtual ::rtl::OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
181 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
182 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
183 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
185 // XAccessibleComponent
186 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
187 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
);
188 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
189 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
190 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
191 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
192 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
193 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
194 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
195 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
197 // XAccessibleSelection
198 virtual void SAL_CALL
selectAccessibleChild( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
199 virtual sal_Bool SAL_CALL
isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
200 virtual void SAL_CALL
clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException
);
201 virtual void SAL_CALL
selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException
);
202 virtual sal_Int32 SAL_CALL
getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
203 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
);
204 virtual void SAL_CALL
deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
207 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
);
210 // ::vos::OMutex maMutex;
211 ::std::vector
< ::com::sun::star::uno::Reference
<
212 ::com::sun::star::accessibility::XAccessibleEventListener
> > mxEventListeners
;
214 bool mbIsTransientChildrenDisabled
;
215 /// The current FOCUSED state.
218 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
220 /** Tell all listeners that the object is dying. This callback is
221 usually called from the WeakComponentImplHelper class.
223 virtual void SAL_CALL
disposing (void);
225 /** Return the number of items. This takes the None-Item into account.
227 USHORT
getItemCount (void) const;
229 /** Return the item associated with the given index. The None-Item is
230 taken into account which, when present, is taken to be the first
233 Index of the item to return. The index 0 denotes the None-Item
236 Returns NULL when the given index is out of range.
238 ValueSetItem
* getItem (USHORT nIndex
) const;
240 /** Check whether or not the object has been disposed (or is in the
241 state of beeing disposed). If that is the case then
242 DisposedException is thrown to inform the (indirect) caller of the
245 void ThrowIfDisposed (void)
246 throw (::com::sun::star::lang::DisposedException
);
248 /** Check whether or not the object has been disposed (or is in the
249 state of beeing disposed).
251 @return sal_True, if the object is disposed or in the course
252 of being disposed. Otherwise, sal_False is returned.
254 sal_Bool
IsDisposed (void);
256 /** Check whether the value set has a 'none' field, i.e. a field (button)
257 that deselects any items (selects none of them).
259 Returns <true/> if there is a 'none' field and <false/> it it is
262 bool HasNoneField (void) const;
269 class ValueItemAcc
: public ::cppu::WeakImplHelper5
< ::com::sun::star::accessibility::XAccessible
,
270 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
271 ::com::sun::star::accessibility::XAccessibleContext
,
272 ::com::sun::star::accessibility::XAccessibleComponent
,
273 ::com::sun::star::lang::XUnoTunnel
>
277 ::std::vector
< ::com::sun::star::uno::Reference
<
278 ::com::sun::star::accessibility::XAccessibleEventListener
> > mxEventListeners
;
279 ::vos::OMutex maMutex
;
280 ValueSetItem
* mpParent
;
281 bool mbIsTransientChildrenDisabled
;
283 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
287 ValueItemAcc( ValueSetItem
* pParent
, bool bIsTransientChildrenDisabled
);
290 void ParentDestroyed();
292 void FireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
293 BOOL
HasAccessibleListeners() const { return( mxEventListeners
.size() > 0 ); }
295 static ValueItemAcc
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxData
) throw();
300 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
302 // XAccessibleEventBroadcaster
303 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
304 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
306 // XAccessibleContext
307 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
308 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
);
309 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
310 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
311 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
312 virtual ::rtl::OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
313 virtual ::rtl::OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
314 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
315 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
316 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
318 // XAccessibleComponent
319 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
320 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
);
321 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
322 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
323 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
324 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
325 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
326 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
327 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
328 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
331 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
);