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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_sw.hxx" 24 25 #include <comphelper/accessiblekeybindinghelper.hxx> 26 #include <swurl.hxx> 27 #include <vos/mutex.hxx> 28 #include <vcl/svapp.hxx> 29 #include <ndtxt.hxx> 30 #include <txtinet.hxx> 31 #include <frmfmt.hxx> 32 33 #include <accnotexthyperlink.hxx> 34 35 #include <fmturl.hxx> 36 37 #include <svtools/imap.hxx> 38 #include <svtools/imapobj.hxx> 39 40 #include <accmap.hxx> 41 using namespace ::com::sun::star::lang; 42 using namespace ::com::sun::star::uno; 43 using namespace ::com::sun::star::accessibility; 44 //using namespace ::rtl; 45 46 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame *p, const SwFrm *aFrm, sal_uInt16 nIndex) : 47 xFrame( p ), 48 mpFrm( aFrm ), 49 mnIndex(nIndex) 50 { 51 } 52 53 // XAccessibleAction 54 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionCount() 55 { 56 SwFmtURL aURL( GetFmt()->GetURL() ); 57 ImageMap* pMap = aURL.GetMap(); 58 if( pMap != NULL ) 59 { 60 return pMap->GetIMapObjectCount(); 61 }else if( aURL.GetURL().Len() ) 62 { 63 return 1; 64 } 65 66 return 0; 67 } 68 69 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex ) 70 { 71 vos::OGuard aGuard(Application::GetSolarMutex()); 72 73 if(nIndex < 0 || nIndex >= getAccessibleActionCount()) 74 throw new IndexOutOfBoundsException; 75 76 sal_Bool bRet = sal_False; 77 SwFmtURL aURL( GetFmt()->GetURL() ); 78 ImageMap* pMap = aURL.GetMap(); 79 if( pMap != NULL ) 80 { 81 IMapObject* pMapObj = pMap->GetIMapObject(nIndex); 82 if(pMapObj->GetURL().Len()) 83 { 84 ViewShell *pVSh = xFrame->GetShell(); 85 if( pVSh ) 86 { 87 LoadURL( pMapObj->GetURL(), pVSh, URLLOAD_NOFILTER, 88 &pMapObj->GetTarget() ); 89 bRet = sal_True; 90 } 91 } 92 } 93 else if( aURL.GetURL().Len() ) 94 { 95 ViewShell *pVSh = xFrame->GetShell(); 96 if( pVSh ) 97 { 98 LoadURL( aURL.GetURL(), pVSh, URLLOAD_NOFILTER, 99 &aURL.GetTargetFrameName() ); 100 bRet = sal_True; 101 } 102 } 103 104 return bRet; 105 } 106 107 rtl::OUString SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionDescription( 108 sal_Int32 nIndex ) 109 { 110 rtl::OUString sDesc; 111 112 if(nIndex < 0 || nIndex >= getAccessibleActionCount()) 113 throw new IndexOutOfBoundsException; 114 115 SwFmtURL aURL( GetFmt()->GetURL() ); 116 ImageMap* pMap = aURL.GetMap(); 117 if( pMap != NULL ) 118 { 119 IMapObject* pMapObj = pMap->GetIMapObject(nIndex); 120 if(pMapObj->GetDesc().Len()) 121 sDesc = rtl::OUString( pMapObj->GetDesc() ); 122 else if(pMapObj->GetURL().Len()) 123 sDesc = rtl::OUString( pMapObj->GetURL() ); 124 } 125 else if( aURL.GetURL().Len() ) 126 sDesc = rtl::OUString( aURL.GetName() ); 127 //sDesc = rtl::OUString( aURL.GetName() ); 128 129 return sDesc; 130 } 131 132 Reference< XAccessibleKeyBinding > SAL_CALL 133 SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex ) 134 { 135 Reference< XAccessibleKeyBinding > xKeyBinding; 136 137 if(nIndex < 0 || nIndex >= getAccessibleActionCount()) 138 throw new IndexOutOfBoundsException; 139 140 bool bIsValid = sal_False; 141 SwFmtURL aURL( GetFmt()->GetURL() ); 142 ImageMap* pMap = aURL.GetMap(); 143 if( pMap != NULL ) 144 { 145 IMapObject* pMapObj = pMap->GetIMapObject(nIndex); 146 if(pMapObj->GetURL().Len()) 147 bIsValid = sal_True; 148 }else if( aURL.GetURL().Len() ) 149 bIsValid = sal_True; 150 151 if(bIsValid) 152 { 153 ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper = 154 new ::comphelper::OAccessibleKeyBindingHelper(); 155 xKeyBinding = pKeyBindingHelper; 156 157 ::com::sun::star::awt::KeyStroke aKeyStroke; 158 aKeyStroke.Modifiers = 0; 159 aKeyStroke.KeyCode = KEY_RETURN; 160 aKeyStroke.KeyChar = 0; 161 aKeyStroke.KeyFunc = 0; 162 pKeyBindingHelper->AddKeyBinding( aKeyStroke ); 163 } 164 165 return xKeyBinding; 166 } 167 168 // XAccessibleHyperlink 169 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionAnchor( 170 sal_Int32 nIndex ) 171 { 172 if(nIndex < 0 || nIndex >= getAccessibleActionCount()) 173 throw new IndexOutOfBoundsException; 174 175 Any aRet; 176 //SwFrm* pAnchor = ((SwFlyFrm*)mpFrm)->GetAnchor(); 177 Reference< XAccessible > xAnchor = xFrame->GetAccessibleMap()->GetContext(mpFrm, sal_True); 178 //SwAccessibleNoTextFrame* pFrame = xFrame.get(); 179 //Reference< XAccessible > xAnchor = (XAccessible*)pFrame; 180 aRet <<= xAnchor; 181 return aRet; 182 } 183 184 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionObject( 185 sal_Int32 nIndex ) 186 { 187 if(nIndex < 0 || nIndex >= getAccessibleActionCount()) 188 throw new IndexOutOfBoundsException; 189 190 SwFmtURL aURL( GetFmt()->GetURL() ); 191 ::rtl::OUString retText; 192 ImageMap* pMap = aURL.GetMap(); 193 if( pMap != NULL ) 194 { 195 IMapObject* pMapObj = pMap->GetIMapObject(nIndex); 196 if(pMapObj->GetURL().Len()) 197 retText = rtl::OUString( pMapObj->GetURL() ); 198 }else if( aURL.GetURL().Len() ) 199 retText = rtl::OUString( aURL.GetURL() ); 200 201 Any aRet; 202 aRet <<= retText; 203 return aRet; 204 } 205 206 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getStartIndex() 207 { 208 return 0; 209 } 210 211 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getEndIndex() 212 { 213 return 0; 214 } 215 216 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::isValid( ) 217 { 218 SwFmtURL aURL( GetFmt()->GetURL() ); 219 220 if( aURL.GetMap() || aURL.GetURL().Len() ) 221 return sal_True; 222 return sal_False; 223 } 224