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