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 //IAccessibility2 Implementation 2009----- 91 sal_Bool bSelected:1; 92 //-----IAccessibility2 Implementation 2009 93 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >* mpxAcc; 94 95 ValueSetItem( ValueSet& rParent ); 96 ~ValueSetItem(); 97 98 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > 99 GetAccessible( bool bIsTransientChildrenDisabled ); 100 void ClearAccessible(); 101 }; 102 103 // ----------------------------------------------------------------------------- 104 105 DECLARE_LIST( ValueItemList, ValueSetItem* ) 106 107 // ----------------------------------------------------------------------------- 108 109 struct ValueSet_Impl 110 { 111 ::std::auto_ptr< ValueItemList > mpItemList; 112 bool mbIsTransientChildrenDisabled; 113 Link maHighlightHdl; 114 115 ValueSet_Impl() : mpItemList( ::std::auto_ptr< ValueItemList >( new ValueItemList() ) ), 116 mbIsTransientChildrenDisabled( false ) 117 { 118 } 119 }; 120 121 // --------------- 122 // - ValueSetAcc - 123 // --------------- 124 125 typedef ::cppu::WeakComponentImplHelper6< 126 ::com::sun::star::accessibility::XAccessible, 127 ::com::sun::star::accessibility::XAccessibleEventBroadcaster, 128 ::com::sun::star::accessibility::XAccessibleContext, 129 ::com::sun::star::accessibility::XAccessibleComponent, 130 ::com::sun::star::accessibility::XAccessibleSelection, 131 ::com::sun::star::lang::XUnoTunnel > 132 ValueSetAccComponentBase; 133 134 class ValueSetAcc : 135 public ::comphelper::OBaseMutex, 136 public ValueSetAccComponentBase 137 { 138 public: 139 140 ValueSetAcc( ValueSet* pParent, bool bIsTransientChildrenDisabled ); 141 ~ValueSetAcc(); 142 143 void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue ); 144 sal_Bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); } 145 146 static ValueSetAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw(); 147 148 public: 149 150 /** Called by the corresponding ValueSet when it gets the focus. 151 Stores the new focus state and broadcasts a state change event. 152 */ 153 void GetFocus (void); 154 155 /** Called by the corresponding ValueSet when it loses the focus. 156 Stores the new focus state and broadcasts a state change event. 157 */ 158 void LoseFocus (void); 159 160 161 // XAccessible 162 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException); 163 164 // XAccessibleEventBroadcaster 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>::addEventListener; 166 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 167 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; 168 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 169 170 // XAccessibleContext 171 virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); 172 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); 173 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException); 174 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException); 175 virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException); 176 virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException); 177 virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException); 178 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException); 179 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException); 180 virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException); 181 182 // XAccessibleComponent 183 virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException); 184 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); 185 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException); 186 virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException); 187 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException); 188 virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); 189 virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException); 190 virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException); 191 virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException); 192 virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException); 193 194 // XAccessibleSelection 195 virtual void SAL_CALL selectAccessibleChild( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 196 virtual sal_Bool SAL_CALL isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 197 virtual void SAL_CALL clearAccessibleSelection( ) throw (::com::sun::star::uno::RuntimeException); 198 virtual void SAL_CALL selectAllAccessibleChildren( ) throw (::com::sun::star::uno::RuntimeException); 199 virtual sal_Int32 SAL_CALL getSelectedAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); 200 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); 201 virtual void SAL_CALL deselectAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 202 203 // XUnoTunnel 204 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException ); 205 206 private: 207 // ::vos::OMutex maMutex; 208 ::std::vector< ::com::sun::star::uno::Reference< 209 ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners; 210 ValueSet* mpParent; 211 bool mbIsTransientChildrenDisabled; 212 /// The current FOCUSED state. 213 bool mbIsFocused; 214 215 static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId(); 216 217 /** Tell all listeners that the object is dying. This callback is 218 usually called from the WeakComponentImplHelper class. 219 */ 220 virtual void SAL_CALL disposing (void); 221 222 /** Return the number of items. This takes the None-Item into account. 223 */ 224 sal_uInt16 getItemCount (void) const; 225 226 /** Return the item associated with the given index. The None-Item is 227 taken into account which, when present, is taken to be the first 228 (with index 0) item. 229 @param nIndex 230 Index of the item to return. The index 0 denotes the None-Item 231 when present. 232 @return 233 Returns NULL when the given index is out of range. 234 */ 235 ValueSetItem* getItem (sal_uInt16 nIndex) const; 236 237 /** Check whether or not the object has been disposed (or is in the 238 state of beeing disposed). If that is the case then 239 DisposedException is thrown to inform the (indirect) caller of the 240 foul deed. 241 */ 242 void ThrowIfDisposed (void) 243 throw (::com::sun::star::lang::DisposedException); 244 245 /** Check whether or not the object has been disposed (or is in the 246 state of beeing disposed). 247 248 @return sal_True, if the object is disposed or in the course 249 of being disposed. Otherwise, sal_False is returned. 250 */ 251 sal_Bool IsDisposed (void); 252 253 /** Check whether the value set has a 'none' field, i.e. a field (button) 254 that deselects any items (selects none of them). 255 @return 256 Returns <true/> if there is a 'none' field and <false/> it it is 257 missing. 258 */ 259 bool HasNoneField (void) const; 260 }; 261 262 // ---------------- 263 // - ValueItemAcc - 264 // ---------------- 265 266 class ValueItemAcc : public ::cppu::WeakImplHelper5< ::com::sun::star::accessibility::XAccessible, 267 ::com::sun::star::accessibility::XAccessibleEventBroadcaster, 268 ::com::sun::star::accessibility::XAccessibleContext, 269 ::com::sun::star::accessibility::XAccessibleComponent, 270 ::com::sun::star::lang::XUnoTunnel > 271 { 272 private: 273 274 ::std::vector< ::com::sun::star::uno::Reference< 275 ::com::sun::star::accessibility::XAccessibleEventListener > > mxEventListeners; 276 ::vos::OMutex maMutex; 277 ValueSetItem* mpParent; 278 bool mbIsTransientChildrenDisabled; 279 280 static const ::com::sun::star::uno::Sequence< sal_Int8 >& getUnoTunnelId(); 281 282 public: 283 284 ValueItemAcc( ValueSetItem* pParent, bool bIsTransientChildrenDisabled ); 285 ~ValueItemAcc(); 286 287 void ParentDestroyed(); 288 289 void FireAccessibleEvent( short nEventId, const ::com::sun::star::uno::Any& rOldValue, const ::com::sun::star::uno::Any& rNewValue ); 290 sal_Bool HasAccessibleListeners() const { return( mxEventListeners.size() > 0 ); } 291 292 static ValueItemAcc* getImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxData ) throw(); 293 294 public: 295 296 // XAccessible 297 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext( ) throw (::com::sun::star::uno::RuntimeException); 298 299 // XAccessibleEventBroadcaster 300 virtual void SAL_CALL addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 301 virtual void SAL_CALL removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException); 302 303 // XAccessibleContext 304 virtual sal_Int32 SAL_CALL getAccessibleChildCount( ) throw (::com::sun::star::uno::RuntimeException); 305 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); 306 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleParent( ) throw (::com::sun::star::uno::RuntimeException); 307 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent( ) throw (::com::sun::star::uno::RuntimeException); 308 virtual sal_Int16 SAL_CALL getAccessibleRole( ) throw (::com::sun::star::uno::RuntimeException); 309 virtual ::rtl::OUString SAL_CALL getAccessibleDescription( ) throw (::com::sun::star::uno::RuntimeException); 310 virtual ::rtl::OUString SAL_CALL getAccessibleName( ) throw (::com::sun::star::uno::RuntimeException); 311 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleRelationSet > SAL_CALL getAccessibleRelationSet( ) throw (::com::sun::star::uno::RuntimeException); 312 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleStateSet > SAL_CALL getAccessibleStateSet( ) throw (::com::sun::star::uno::RuntimeException); 313 virtual ::com::sun::star::lang::Locale SAL_CALL getLocale( ) throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException); 314 315 // XAccessibleComponent 316 virtual sal_Bool SAL_CALL containsPoint( const ::com::sun::star::awt::Point& aPoint ) throw (::com::sun::star::uno::RuntimeException); 317 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); 318 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) throw (::com::sun::star::uno::RuntimeException); 319 virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) throw (::com::sun::star::uno::RuntimeException); 320 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) throw (::com::sun::star::uno::RuntimeException); 321 virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) throw (::com::sun::star::uno::RuntimeException); 322 virtual void SAL_CALL grabFocus( ) throw (::com::sun::star::uno::RuntimeException); 323 virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding( ) throw (::com::sun::star::uno::RuntimeException); 324 virtual sal_Int32 SAL_CALL getForeground( ) throw (::com::sun::star::uno::RuntimeException); 325 virtual sal_Int32 SAL_CALL getBackground( ) throw (::com::sun::star::uno::RuntimeException); 326 327 // XUnoTunnel 328 virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rId ) throw( ::com::sun::star::uno::RuntimeException ); 329 }; 330