1*c82f2877SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c82f2877SAndrew Rist * distributed with this work for additional information 6*c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c82f2877SAndrew Rist * "License"); you may not use this file except in compliance 9*c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c82f2877SAndrew Rist * software distributed under the License is distributed on an 15*c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c82f2877SAndrew Rist * KIND, either express or implied. See the License for the 17*c82f2877SAndrew Rist * specific language governing permissions and limitations 18*c82f2877SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*c82f2877SAndrew Rist *************************************************************/ 21*c82f2877SAndrew Rist 22*c82f2877SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_accessibility.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // includes -------------------------------------------------------------- 28cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblescrollbar.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <toolkit/awt/vclxwindows.hxx> 31cdf0e10cSrcweir #include <accessibility/helper/accresmgr.hxx> 32cdf0e10cSrcweir #include <accessibility/helper/accessiblestrings.hrc> 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx> 35cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp> 36cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp> 37cdf0e10cSrcweir #include <com/sun/star/awt/ScrollBarOrientation.hpp> 38cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx> 39cdf0e10cSrcweir #include <comphelper/sequence.hxx> 40cdf0e10cSrcweir #include <vcl/scrbar.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace ::com::sun::star; 43cdf0e10cSrcweir using namespace ::com::sun::star::uno; 44cdf0e10cSrcweir using namespace ::com::sun::star::awt; 45cdf0e10cSrcweir using namespace ::com::sun::star::lang; 46cdf0e10cSrcweir using namespace ::com::sun::star::beans; 47cdf0e10cSrcweir using namespace ::com::sun::star::accessibility; 48cdf0e10cSrcweir using namespace ::comphelper; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir // ----------------------------------------------------------------------------- 52cdf0e10cSrcweir // VCLXAccessibleScrollBar 53cdf0e10cSrcweir // ----------------------------------------------------------------------------- 54cdf0e10cSrcweir 55cdf0e10cSrcweir VCLXAccessibleScrollBar::VCLXAccessibleScrollBar( VCLXWindow* pVCLWindow ) 56cdf0e10cSrcweir :VCLXAccessibleComponent( pVCLWindow ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir } 59cdf0e10cSrcweir 60cdf0e10cSrcweir // ----------------------------------------------------------------------------- 61cdf0e10cSrcweir 62cdf0e10cSrcweir VCLXAccessibleScrollBar::~VCLXAccessibleScrollBar() 63cdf0e10cSrcweir { 64cdf0e10cSrcweir } 65cdf0e10cSrcweir 66cdf0e10cSrcweir // ----------------------------------------------------------------------------- 67cdf0e10cSrcweir 68cdf0e10cSrcweir void VCLXAccessibleScrollBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir case VCLEVENT_SCROLLBAR_SCROLL: 73cdf0e10cSrcweir { 74cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::VALUE_CHANGED, Any(), Any() ); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir break; 77cdf0e10cSrcweir default: 78cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent ); 79cdf0e10cSrcweir } 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir // ----------------------------------------------------------------------------- 83cdf0e10cSrcweir 84cdf0e10cSrcweir void VCLXAccessibleScrollBar::FillAccessibleStateSet( utl::AccessibleStateSetHelper& rStateSet ) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() ); 89cdf0e10cSrcweir if ( pVCLXScrollBar ) 90cdf0e10cSrcweir { 91cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::FOCUSABLE ); 92cdf0e10cSrcweir if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::HORIZONTAL ) 93cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::HORIZONTAL ); 94cdf0e10cSrcweir else if ( pVCLXScrollBar->getOrientation() == ScrollBarOrientation::VERTICAL ) 95cdf0e10cSrcweir rStateSet.AddState( AccessibleStateType::VERTICAL ); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir // ----------------------------------------------------------------------------- 100cdf0e10cSrcweir // XInterface 101cdf0e10cSrcweir // ----------------------------------------------------------------------------- 102cdf0e10cSrcweir 103cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE ) 104cdf0e10cSrcweir 105cdf0e10cSrcweir // ----------------------------------------------------------------------------- 106cdf0e10cSrcweir // XTypeProvider 107cdf0e10cSrcweir // ----------------------------------------------------------------------------- 108cdf0e10cSrcweir 109cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( VCLXAccessibleScrollBar, VCLXAccessibleComponent, VCLXAccessibleScrollBar_BASE ) 110cdf0e10cSrcweir 111cdf0e10cSrcweir // ----------------------------------------------------------------------------- 112cdf0e10cSrcweir // XServiceInfo 113cdf0e10cSrcweir // ----------------------------------------------------------------------------- 114cdf0e10cSrcweir 115cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleScrollBar::getImplementationName() throw (RuntimeException) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleScrollBar" ); 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir // ----------------------------------------------------------------------------- 121cdf0e10cSrcweir 122cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleScrollBar::getSupportedServiceNames() throw (RuntimeException) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1); 125cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleScrollBar" ); 126cdf0e10cSrcweir return aNames; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir // ----------------------------------------------------------------------------- 130cdf0e10cSrcweir // XAccessibleAction 131cdf0e10cSrcweir // ----------------------------------------------------------------------------- 132cdf0e10cSrcweir 133cdf0e10cSrcweir sal_Int32 VCLXAccessibleScrollBar::getAccessibleActionCount( ) throw (RuntimeException) 134cdf0e10cSrcweir { 135cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 136cdf0e10cSrcweir 137cdf0e10cSrcweir return 4; 138cdf0e10cSrcweir } 139cdf0e10cSrcweir 140cdf0e10cSrcweir // ----------------------------------------------------------------------------- 141cdf0e10cSrcweir 142cdf0e10cSrcweir sal_Bool VCLXAccessibleScrollBar::doAccessibleAction ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 147cdf0e10cSrcweir throw IndexOutOfBoundsException(); 148cdf0e10cSrcweir 149cdf0e10cSrcweir sal_Bool bReturn = sal_False; 150cdf0e10cSrcweir ScrollBar* pScrollBar = static_cast< ScrollBar* >( GetWindow() ); 151cdf0e10cSrcweir if ( pScrollBar ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir ScrollType eScrollType; 154cdf0e10cSrcweir switch ( nIndex ) 155cdf0e10cSrcweir { 156cdf0e10cSrcweir case 0: eScrollType = SCROLL_LINEUP; break; 157cdf0e10cSrcweir case 1: eScrollType = SCROLL_LINEDOWN; break; 158cdf0e10cSrcweir case 2: eScrollType = SCROLL_PAGEUP; break; 159cdf0e10cSrcweir case 3: eScrollType = SCROLL_PAGEDOWN; break; 160cdf0e10cSrcweir default: eScrollType = SCROLL_DONTKNOW; break; 161cdf0e10cSrcweir } 162cdf0e10cSrcweir if ( pScrollBar->DoScrollAction( eScrollType ) ) 163cdf0e10cSrcweir bReturn = sal_True; 164cdf0e10cSrcweir } 165cdf0e10cSrcweir 166cdf0e10cSrcweir return bReturn; 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir // ----------------------------------------------------------------------------- 170cdf0e10cSrcweir 171cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleScrollBar::getAccessibleActionDescription ( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 176cdf0e10cSrcweir throw IndexOutOfBoundsException(); 177cdf0e10cSrcweir 178cdf0e10cSrcweir ::rtl::OUString sDescription; 179cdf0e10cSrcweir 180cdf0e10cSrcweir switch ( nIndex ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir case 0: sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECLINE ) ); break; 183cdf0e10cSrcweir case 1: sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCLINE ) ); break; 184cdf0e10cSrcweir case 2: sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_DECBLOCK ) ); break; 185cdf0e10cSrcweir case 3: sDescription = ::rtl::OUString( TK_RES_STRING( RID_STR_ACC_ACTION_INCBLOCK ) ); break; 186cdf0e10cSrcweir default: break; 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir return sDescription; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir // ----------------------------------------------------------------------------- 193cdf0e10cSrcweir 194cdf0e10cSrcweir Reference< XAccessibleKeyBinding > VCLXAccessibleScrollBar::getAccessibleActionKeyBinding( sal_Int32 nIndex ) throw (IndexOutOfBoundsException, RuntimeException) 195cdf0e10cSrcweir { 196cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 197cdf0e10cSrcweir 198cdf0e10cSrcweir if ( nIndex < 0 || nIndex >= getAccessibleActionCount() ) 199cdf0e10cSrcweir throw IndexOutOfBoundsException(); 200cdf0e10cSrcweir 201cdf0e10cSrcweir return Reference< XAccessibleKeyBinding >(); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir // ----------------------------------------------------------------------------- 205cdf0e10cSrcweir // XAccessibleValue 206cdf0e10cSrcweir // ----------------------------------------------------------------------------- 207cdf0e10cSrcweir 208cdf0e10cSrcweir Any VCLXAccessibleScrollBar::getCurrentValue( ) throw (RuntimeException) 209cdf0e10cSrcweir { 210cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 211cdf0e10cSrcweir 212cdf0e10cSrcweir Any aValue; 213cdf0e10cSrcweir 214cdf0e10cSrcweir VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() ); 215cdf0e10cSrcweir if ( pVCLXScrollBar ) 216cdf0e10cSrcweir aValue <<= (sal_Int32) pVCLXScrollBar->getValue(); 217cdf0e10cSrcweir 218cdf0e10cSrcweir return aValue; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir // ----------------------------------------------------------------------------- 222cdf0e10cSrcweir 223cdf0e10cSrcweir sal_Bool VCLXAccessibleScrollBar::setCurrentValue( const Any& aNumber ) throw (RuntimeException) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 226cdf0e10cSrcweir 227cdf0e10cSrcweir sal_Bool bReturn = sal_False; 228cdf0e10cSrcweir 229cdf0e10cSrcweir VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() ); 230cdf0e10cSrcweir if ( pVCLXScrollBar ) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir sal_Int32 nValue = 0, nValueMin = 0, nValueMax = 0; 233cdf0e10cSrcweir OSL_VERIFY( aNumber >>= nValue ); 234cdf0e10cSrcweir OSL_VERIFY( getMinimumValue() >>= nValueMin ); 235cdf0e10cSrcweir OSL_VERIFY( getMaximumValue() >>= nValueMax ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir if ( nValue < nValueMin ) 238cdf0e10cSrcweir nValue = nValueMin; 239cdf0e10cSrcweir else if ( nValue > nValueMax ) 240cdf0e10cSrcweir nValue = nValueMax; 241cdf0e10cSrcweir 242cdf0e10cSrcweir pVCLXScrollBar->setValue( nValue ); 243cdf0e10cSrcweir bReturn = sal_True; 244cdf0e10cSrcweir } 245cdf0e10cSrcweir 246cdf0e10cSrcweir return bReturn; 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir // ----------------------------------------------------------------------------- 250cdf0e10cSrcweir 251cdf0e10cSrcweir Any VCLXAccessibleScrollBar::getMaximumValue( ) throw (RuntimeException) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 254cdf0e10cSrcweir 255cdf0e10cSrcweir Any aValue; 256cdf0e10cSrcweir 257cdf0e10cSrcweir VCLXScrollBar* pVCLXScrollBar = static_cast< VCLXScrollBar* >( GetVCLXWindow() ); 258cdf0e10cSrcweir if ( pVCLXScrollBar ) 259cdf0e10cSrcweir aValue <<= (sal_Int32) pVCLXScrollBar->getMaximum(); 260cdf0e10cSrcweir 261cdf0e10cSrcweir return aValue; 262cdf0e10cSrcweir } 263cdf0e10cSrcweir 264cdf0e10cSrcweir // ----------------------------------------------------------------------------- 265cdf0e10cSrcweir 266cdf0e10cSrcweir Any VCLXAccessibleScrollBar::getMinimumValue( ) throw (RuntimeException) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir OExternalLockGuard aGuard( this ); 269cdf0e10cSrcweir 270cdf0e10cSrcweir Any aValue; 271cdf0e10cSrcweir aValue <<= (sal_Int32) 0; 272cdf0e10cSrcweir 273cdf0e10cSrcweir return aValue; 274cdf0e10cSrcweir } 275cdf0e10cSrcweir 276cdf0e10cSrcweir // ----------------------------------------------------------------------------- 277