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 25 #include "precompiled_sw.hxx" 26 27 #include <SidebarWinAcc.hxx> 28 29 #include <SidebarWin.hxx> 30 #include <viewsh.hxx> 31 #include <accmap.hxx> 32 #include <toolkit/awt/vclxaccessiblecomponent.hxx> 33 34 #include <com/sun/star/accessibility/AccessibleRole.hpp> 35 36 namespace css = ::com::sun::star; 37 38 namespace sw { namespace sidebarwindows { 39 40 // ============================================================================= 41 // declaration and implementation of accessible context for <SidebarWinAccessible> instance 42 // ============================================================================= 43 class SidebarWinAccessibleContext : public VCLXAccessibleComponent 44 { 45 public: 46 explicit SidebarWinAccessibleContext( SwSidebarWin& rSidebarWin, 47 ViewShell& rViewShell, 48 const SwFrm* pAnchorFrm ) 49 : VCLXAccessibleComponent( rSidebarWin.GetWindowPeer() ) 50 , mrViewShell( rViewShell ) 51 , mpAnchorFrm( pAnchorFrm ) 52 , maMutex() 53 { 54 rSidebarWin.SetAccessibleRole( css::accessibility::AccessibleRole::COMMENT ); 55 } 56 57 virtual ~SidebarWinAccessibleContext() 58 {} 59 60 void ChangeAnchor( const SwFrm* pAnchorFrm ) 61 { 62 vos::OGuard aGuard(maMutex); 63 64 mpAnchorFrm = pAnchorFrm; 65 } 66 67 virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL 68 getAccessibleParent() throw (css::uno::RuntimeException) 69 { 70 vos::OGuard aGuard(maMutex); 71 72 css::uno::Reference< css::accessibility::XAccessible > xAccParent; 73 74 if ( mpAnchorFrm && 75 mrViewShell.GetAccessibleMap() ) 76 { 77 xAccParent = mrViewShell.GetAccessibleMap()->GetContext( mpAnchorFrm, sal_False ); 78 } 79 80 return xAccParent; 81 } 82 83 virtual sal_Int32 SAL_CALL getAccessibleIndexInParent() throw (css::uno::RuntimeException) 84 { 85 vos::OGuard aGuard(maMutex); 86 87 sal_Int32 nIndex( -1 ); 88 89 if ( mpAnchorFrm && GetWindow() && 90 mrViewShell.GetAccessibleMap() ) 91 { 92 nIndex = mrViewShell.GetAccessibleMap()->GetChildIndex( *mpAnchorFrm, 93 *GetWindow() ); 94 } 95 96 return nIndex; 97 } 98 99 private: 100 ViewShell& mrViewShell; 101 const SwFrm* mpAnchorFrm; 102 103 ::vos::OMutex maMutex; 104 }; 105 106 // ============================================================================= 107 // implementaion of accessible for <SwSidebarWin> instance 108 // ============================================================================= 109 SidebarWinAccessible::SidebarWinAccessible( SwSidebarWin& rSidebarWin, 110 ViewShell& rViewShell, 111 const SwSidebarItem& rSidebarItem ) 112 : VCLXWindow() 113 , mrSidebarWin( rSidebarWin ) 114 , mrViewShell( rViewShell ) 115 , mpAnchorFrm( rSidebarItem.maLayoutInfo.mpAnchorFrm ) 116 , bAccContextCreated( false ) 117 { 118 SetWindow( &mrSidebarWin ); 119 } 120 121 SidebarWinAccessible::~SidebarWinAccessible() 122 { 123 } 124 125 void SidebarWinAccessible::ChangeSidebarItem( const SwSidebarItem& rSidebarItem ) 126 { 127 if ( bAccContextCreated ) 128 { 129 css::uno::Reference< css::accessibility::XAccessibleContext > xAcc 130 = getAccessibleContext(); 131 if ( xAcc.is() ) 132 { 133 SidebarWinAccessibleContext* pAccContext = 134 dynamic_cast<SidebarWinAccessibleContext*>(xAcc.get()); 135 if ( pAccContext ) 136 { 137 pAccContext->ChangeAnchor( rSidebarItem.maLayoutInfo.mpAnchorFrm ); 138 } 139 } 140 } 141 } 142 143 css::uno::Reference< css::accessibility::XAccessibleContext > SidebarWinAccessible::CreateAccessibleContext() 144 { 145 SidebarWinAccessibleContext* pAccContext = 146 new SidebarWinAccessibleContext( mrSidebarWin, 147 mrViewShell, 148 mpAnchorFrm ); 149 css::uno::Reference< css::accessibility::XAccessibleContext > xAcc( pAccContext ); 150 bAccContextCreated = true; 151 return xAcc; 152 } 153 154 } } // end of namespace sw::sidebarwindows 155 156