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();
154 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
156 // XAccessibleEventBroadcaster
157 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
;
158 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
159 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
;
160 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
162 // XAccessibleContext
163 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
164 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
);
165 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
166 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
167 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
168 virtual ::rtl::OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
169 virtual ::rtl::OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
170 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
171 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
172 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
174 // XAccessibleComponent
175 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
176 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
);
177 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
178 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
179 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
180 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
181 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
182 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
183 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
184 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
186 // XAccessibleSelection
187 virtual void SAL_CALL
selectAccessibleChild( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
188 virtual sal_Bool SAL_CALL
isAccessibleChildSelected( sal_Int32 nChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
189 virtual void SAL_CALL
clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException
);
190 virtual void SAL_CALL
selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException
);
191 virtual sal_Int32 SAL_CALL
getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
192 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
);
193 virtual void SAL_CALL
deselectAccessibleChild( sal_Int32 nSelectedChildIndex
) throw (::com::sun::star::lang::IndexOutOfBoundsException
, ::com::sun::star::uno::RuntimeException
);
196 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
);
199 // ::vos::OMutex maMutex;
200 ::std::vector
< ::com::sun::star::uno::Reference
<
201 ::com::sun::star::accessibility::XAccessibleEventListener
> > mxEventListeners
;
203 bool mbIsTransientChildrenDisabled
;
205 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
207 /** Tell all listeners that the object is dying. This callback is
208 usually called from the WeakComponentImplHelper class.
210 virtual void SAL_CALL
disposing (void);
212 /** Return the number of items. This takes the None-Item into account.
214 USHORT
getItemCount (void) const;
216 /** Return the item associated with the given index. The None-Item is
217 taken into account which, when present, is taken to be the first
220 Index of the item to return. The index 0 denotes the None-Item
223 Returns NULL when the given index is out of range.
225 ValueSetItem
* getItem (USHORT nIndex
) const;
227 /** Check whether or not the object has been disposed (or is in the
228 state of beeing disposed). If that is the case then
229 DisposedException is thrown to inform the (indirect) caller of the
232 void ThrowIfDisposed (void)
233 throw (::com::sun::star::lang::DisposedException
);
235 /** Check whether or not the object has been disposed (or is in the
236 state of beeing disposed).
238 @return sal_True, if the object is disposed or in the course
239 of being disposed. Otherwise, sal_False is returned.
241 sal_Bool
IsDisposed (void);
243 /** Check whether the value set has a 'none' field, i.e. a field (button)
244 that deselects any items (selects none of them).
246 Returns <true/> if there is a 'none' field and <false/> it it is
249 bool HasNoneField (void) const;
256 class ValueItemAcc
: public ::cppu::WeakImplHelper5
< ::com::sun::star::accessibility::XAccessible
,
257 ::com::sun::star::accessibility::XAccessibleEventBroadcaster
,
258 ::com::sun::star::accessibility::XAccessibleContext
,
259 ::com::sun::star::accessibility::XAccessibleComponent
,
260 ::com::sun::star::lang::XUnoTunnel
>
264 ::std::vector
< ::com::sun::star::uno::Reference
<
265 ::com::sun::star::accessibility::XAccessibleEventListener
> > mxEventListeners
;
266 ::vos::OMutex maMutex
;
267 ValueSetItem
* mpParent
;
268 bool mbIsTransientChildrenDisabled
;
270 static const ::com::sun::star::uno::Sequence
< sal_Int8
>& getUnoTunnelId();
274 ValueItemAcc( ValueSetItem
* pParent
, bool bIsTransientChildrenDisabled
);
277 void ParentDestroyed();
279 void FireAccessibleEvent( short nEventId
, const ::com::sun::star::uno::Any
& rOldValue
, const ::com::sun::star::uno::Any
& rNewValue
);
280 BOOL
HasAccessibleListeners() const { return( mxEventListeners
.size() > 0 ); }
282 static ValueItemAcc
* getImplementation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& rxData
) throw();
287 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleContext
> SAL_CALL
getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException
);
289 // XAccessibleEventBroadcaster
290 virtual void SAL_CALL
addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
291 virtual void SAL_CALL
removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
);
293 // XAccessibleContext
294 virtual sal_Int32 SAL_CALL
getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException
);
295 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
);
296 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessible
> SAL_CALL
getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException
);
297 virtual sal_Int32 SAL_CALL
getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException
);
298 virtual sal_Int16 SAL_CALL
getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException
);
299 virtual ::rtl::OUString SAL_CALL
getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException
);
300 virtual ::rtl::OUString SAL_CALL
getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException
);
301 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleRelationSet
> SAL_CALL
getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException
);
302 virtual ::com::sun::star::uno::Reference
< ::com::sun::star::accessibility::XAccessibleStateSet
> SAL_CALL
getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException
);
303 virtual ::com::sun::star::lang::Locale SAL_CALL
getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException
, ::com::sun::star::uno::RuntimeException
);
305 // XAccessibleComponent
306 virtual sal_Bool SAL_CALL
containsPoint( const ::com::sun::star::awt::Point
& aPoint
) throw (::com::sun::star::uno::RuntimeException
);
307 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
);
308 virtual ::com::sun::star::awt::Rectangle SAL_CALL
getBounds( ) throw (::com::sun::star::uno::RuntimeException
);
309 virtual ::com::sun::star::awt::Point SAL_CALL
getLocation( ) throw (::com::sun::star::uno::RuntimeException
);
310 virtual ::com::sun::star::awt::Point SAL_CALL
getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException
);
311 virtual ::com::sun::star::awt::Size SAL_CALL
getSize( ) throw (::com::sun::star::uno::RuntimeException
);
312 virtual void SAL_CALL
grabFocus( ) throw (::com::sun::star::uno::RuntimeException
);
313 virtual ::com::sun::star::uno::Any SAL_CALL
getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException
);
314 virtual sal_Int32 SAL_CALL
getForeground( ) throw (::com::sun::star::uno::RuntimeException
);
315 virtual sal_Int32 SAL_CALL
getBackground( ) throw (::com::sun::star::uno::RuntimeException
);
318 virtual sal_Int64 SAL_CALL
getSomething( const ::com::sun::star::uno::Sequence
< sal_Int8
>& rId
) throw( ::com::sun::star::uno::RuntimeException
);