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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_accessibility.hxx" 26 27 // includes -------------------------------------------------------------- 28 #include <accessibility/standard/vclxaccessiblemenu.hxx> 29 30 #include <com/sun/star/accessibility/AccessibleRole.hpp> 31 #include <vcl/menu.hxx> 32 33 34 using namespace ::com::sun::star; 35 using namespace ::com::sun::star::lang; 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::accessibility; 38 using namespace ::comphelper; 39 40 41 // ----------------------------------------------------------------------------- 42 // VCLXAccessibleMenu 43 // ----------------------------------------------------------------------------- 44 45 VCLXAccessibleMenu::VCLXAccessibleMenu( Menu* pParent, sal_uInt16 nItemPos, Menu* pMenu ) 46 :VCLXAccessibleMenuItem( pParent, nItemPos, pMenu ) 47 { 48 } 49 50 // ----------------------------------------------------------------------------- 51 52 VCLXAccessibleMenu::~VCLXAccessibleMenu() 53 { 54 } 55 56 // ----------------------------------------------------------------------------- 57 58 sal_Bool VCLXAccessibleMenu::IsFocused() 59 { 60 sal_Bool bFocused = sal_False; 61 62 if ( IsHighlighted() && !IsChildHighlighted() ) 63 bFocused = sal_True; 64 65 return bFocused; 66 } 67 68 // ----------------------------------------------------------------------------- 69 70 sal_Bool VCLXAccessibleMenu::IsPopupMenuOpen() 71 { 72 sal_Bool bPopupMenuOpen = sal_False; 73 74 if ( m_pParent ) 75 { 76 PopupMenu* pPopupMenu = m_pParent->GetPopupMenu( m_pParent->GetItemId( m_nItemPos ) ); 77 if ( pPopupMenu && pPopupMenu->IsMenuVisible() ) 78 bPopupMenuOpen = sal_True; 79 } 80 81 return bPopupMenuOpen; 82 } 83 84 // ----------------------------------------------------------------------------- 85 // XInterface 86 // ----------------------------------------------------------------------------- 87 88 IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE ) 89 90 // ----------------------------------------------------------------------------- 91 // XTypeProvider 92 // ----------------------------------------------------------------------------- 93 94 IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleMenu, VCLXAccessibleMenuItem, VCLXAccessibleMenu_BASE ) 95 96 // ----------------------------------------------------------------------------- 97 // XServiceInfo 98 // ----------------------------------------------------------------------------- 99 100 ::rtl::OUString VCLXAccessibleMenu::getImplementationName() throw (RuntimeException) 101 { 102 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleMenu" ); 103 } 104 105 // ----------------------------------------------------------------------------- 106 107 Sequence< ::rtl::OUString > VCLXAccessibleMenu::getSupportedServiceNames() throw (RuntimeException) 108 { 109 Sequence< ::rtl::OUString > aNames(1); 110 aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleMenu" ); 111 return aNames; 112 } 113 114 // ----------------------------------------------------------------------------- 115 // XAccessibleContext 116 // ----------------------------------------------------------------------------- 117 118 sal_Int32 VCLXAccessibleMenu::getAccessibleChildCount( ) throw (RuntimeException) 119 { 120 OExternalLockGuard aGuard( this ); 121 122 return GetChildCount(); 123 } 124 125 // ----------------------------------------------------------------------------- 126 127 Reference< XAccessible > VCLXAccessibleMenu::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException) 128 { 129 OExternalLockGuard aGuard( this ); 130 131 if ( i < 0 || i >= GetChildCount() ) 132 throw IndexOutOfBoundsException(); 133 134 return GetChild( i ); 135 } 136 137 // ----------------------------------------------------------------------------- 138 139 sal_Int16 VCLXAccessibleMenu::getAccessibleRole( ) throw (RuntimeException) 140 { 141 OExternalLockGuard aGuard( this ); 142 143 return AccessibleRole::MENU; 144 } 145 146 // ----------------------------------------------------------------------------- 147 // XAccessibleComponent 148 // ----------------------------------------------------------------------------- 149 150 Reference< XAccessible > VCLXAccessibleMenu::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException) 151 { 152 OExternalLockGuard aGuard( this ); 153 154 return GetChildAt( rPoint ); 155 } 156 157 // ----------------------------------------------------------------------------- 158 // XAccessibleSelection 159 // ----------------------------------------------------------------------------- 160 161 void VCLXAccessibleMenu::selectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 162 { 163 OExternalLockGuard aGuard( this ); 164 165 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 166 throw IndexOutOfBoundsException(); 167 168 SelectChild( nChildIndex ); 169 } 170 171 // ----------------------------------------------------------------------------- 172 173 sal_Bool VCLXAccessibleMenu::isAccessibleChildSelected( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 174 { 175 OExternalLockGuard aGuard( this ); 176 177 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 178 throw IndexOutOfBoundsException(); 179 180 return IsChildSelected( nChildIndex ); 181 } 182 183 // ----------------------------------------------------------------------------- 184 185 void VCLXAccessibleMenu::clearAccessibleSelection( ) throw (RuntimeException) 186 { 187 OExternalLockGuard aGuard( this ); 188 189 DeSelectAll(); 190 } 191 192 // ----------------------------------------------------------------------------- 193 194 void VCLXAccessibleMenu::selectAllAccessibleChildren( ) throw (RuntimeException) 195 { 196 // This method makes no sense in a menu, and so does nothing. 197 } 198 199 // ----------------------------------------------------------------------------- 200 201 sal_Int32 VCLXAccessibleMenu::getSelectedAccessibleChildCount( ) throw (RuntimeException) 202 { 203 OExternalLockGuard aGuard( this ); 204 205 sal_Int32 nRet = 0; 206 207 for ( sal_Int32 i = 0, nCount = GetChildCount(); i < nCount; i++ ) 208 { 209 if ( IsChildSelected( i ) ) 210 ++nRet; 211 } 212 213 return nRet; 214 } 215 216 // ----------------------------------------------------------------------------- 217 218 Reference< XAccessible > VCLXAccessibleMenu::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 219 { 220 OExternalLockGuard aGuard( this ); 221 222 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) 223 throw IndexOutOfBoundsException(); 224 225 Reference< XAccessible > xChild; 226 227 for ( sal_Int32 i = 0, j = 0, nCount = GetChildCount(); i < nCount; i++ ) 228 { 229 if ( IsChildSelected( i ) && ( j++ == nSelectedChildIndex ) ) 230 { 231 xChild = GetChild( i ); 232 break; 233 } 234 } 235 236 return xChild; 237 } 238 239 // ----------------------------------------------------------------------------- 240 241 void VCLXAccessibleMenu::deselectAccessibleChild( sal_Int32 nChildIndex ) throw (IndexOutOfBoundsException, RuntimeException) 242 { 243 OExternalLockGuard aGuard( this ); 244 245 if ( nChildIndex < 0 || nChildIndex >= GetChildCount() ) 246 throw IndexOutOfBoundsException(); 247 248 DeSelectAll(); 249 } 250 251 // ----------------------------------------------------------------------------- 252