1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
21
22 #include <comphelper/accessiblekeybindinghelper.hxx>
23 #include <swurl.hxx>
24 #include <vcl/svapp.hxx>
25 #include <frmfmt.hxx>
26
27 #include "accnotexthyperlink.hxx"
28
29 #include <fmturl.hxx>
30
31 #include <vcl/imap.hxx>
32 #include <vcl/imapobj.hxx>
33 #include <vcl/keycodes.hxx>
34
35 #include <accmap.hxx>
36
37 using namespace css;
38 using namespace css::lang;
39 using namespace css::uno;
40 using namespace css::accessibility;
41
SwAccessibleNoTextHyperlink(SwAccessibleNoTextFrame * p,const SwFrame * aFrame)42 SwAccessibleNoTextHyperlink::SwAccessibleNoTextHyperlink( SwAccessibleNoTextFrame *p, const SwFrame *aFrame ) :
43 mxFrame( p ),
44 mpFrame( aFrame )
45 {
46 }
47
48 // XAccessibleAction
getAccessibleActionCount()49 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionCount()
50 {
51 SolarMutexGuard g;
52
53 SwFormatURL aURL( GetFormat()->GetURL() );
54 ImageMap* pMap = aURL.GetMap();
55 if( pMap != nullptr )
56 {
57 return pMap->GetIMapObjectCount();
58 }
59 else if( !aURL.GetURL().isEmpty() )
60 {
61 return 1;
62 }
63
64 return 0;
65 }
66
doAccessibleAction(sal_Int32 nIndex)67 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::doAccessibleAction( sal_Int32 nIndex )
68 {
69 SolarMutexGuard aGuard;
70
71 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
72 throw lang::IndexOutOfBoundsException();
73
74 bool bRet = false;
75 SwFormatURL aURL( GetFormat()->GetURL() );
76 ImageMap* pMap = aURL.GetMap();
77 if( pMap != nullptr )
78 {
79 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
80 if (!pMapObj->GetURL().isEmpty())
81 {
82 SwViewShell *pVSh = mxFrame->GetShell();
83 if( pVSh )
84 {
85 LoadURL( *pVSh, pMapObj->GetURL(), LoadUrlFlags::NONE,
86 pMapObj->GetTarget() );
87 bRet = true;
88 }
89 }
90 }
91 else if (!aURL.GetURL().isEmpty())
92 {
93 SwViewShell *pVSh = mxFrame->GetShell();
94 if( pVSh )
95 {
96 LoadURL( *pVSh, aURL.GetURL(), LoadUrlFlags::NONE,
97 aURL.GetTargetFrameName() );
98 bRet = true;
99 }
100 }
101
102 return bRet;
103 }
104
getAccessibleActionDescription(sal_Int32 nIndex)105 OUString SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionDescription(
106 sal_Int32 nIndex )
107 {
108 SolarMutexGuard g;
109
110 OUString sDesc;
111
112 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
113 throw lang::IndexOutOfBoundsException();
114
115 SwFormatURL aURL( GetFormat()->GetURL() );
116 ImageMap* pMap = aURL.GetMap();
117 if( pMap != nullptr )
118 {
119 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
120 if (!pMapObj->GetDesc().isEmpty())
121 sDesc = pMapObj->GetDesc();
122 else if (!pMapObj->GetURL().isEmpty())
123 sDesc = pMapObj->GetURL();
124 }
125 else if( !aURL.GetURL().isEmpty() )
126 sDesc = aURL.GetName();
127
128 return sDesc;
129 }
130
131 Reference< XAccessibleKeyBinding > SAL_CALL
getAccessibleActionKeyBinding(sal_Int32 nIndex)132 SwAccessibleNoTextHyperlink::getAccessibleActionKeyBinding( sal_Int32 nIndex )
133 {
134 SolarMutexGuard g;
135
136 Reference< XAccessibleKeyBinding > xKeyBinding;
137
138 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
139 throw lang::IndexOutOfBoundsException();
140
141 bool bIsValid = false;
142 SwFormatURL aURL( GetFormat()->GetURL() );
143 ImageMap* pMap = aURL.GetMap();
144 if( pMap != nullptr )
145 {
146 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
147 if (!pMapObj->GetURL().isEmpty())
148 bIsValid = true;
149 }
150 else if (!aURL.GetURL().isEmpty())
151 bIsValid = true;
152
153 if(bIsValid)
154 {
155 ::comphelper::OAccessibleKeyBindingHelper* pKeyBindingHelper =
156 new ::comphelper::OAccessibleKeyBindingHelper();
157 xKeyBinding = pKeyBindingHelper;
158
159 css::awt::KeyStroke aKeyStroke;
160 aKeyStroke.Modifiers = 0;
161 aKeyStroke.KeyCode = KEY_RETURN;
162 aKeyStroke.KeyChar = 0;
163 aKeyStroke.KeyFunc = 0;
164 pKeyBindingHelper->AddKeyBinding( aKeyStroke );
165 }
166
167 return xKeyBinding;
168 }
169
170 // XAccessibleHyperlink
getAccessibleActionAnchor(sal_Int32 nIndex)171 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionAnchor(
172 sal_Int32 nIndex )
173 {
174 SolarMutexGuard g;
175
176 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
177 throw lang::IndexOutOfBoundsException();
178
179 Any aRet;
180 //SwFrame* pAnchor = static_cast<SwFlyFrame*>(mpFrame)->GetAnchor();
181 Reference< XAccessible > xAnchor = mxFrame->GetAccessibleMap()->GetContext(mpFrame);
182 //SwAccessibleNoTextFrame* pFrame = xFrame.get();
183 //Reference< XAccessible > xAnchor = (XAccessible*)pFrame;
184 aRet <<= xAnchor;
185 return aRet;
186 }
187
getAccessibleActionObject(sal_Int32 nIndex)188 Any SAL_CALL SwAccessibleNoTextHyperlink::getAccessibleActionObject(
189 sal_Int32 nIndex )
190 {
191 SolarMutexGuard g;
192
193 if(nIndex < 0 || nIndex >= getAccessibleActionCount())
194 throw lang::IndexOutOfBoundsException();
195
196 SwFormatURL aURL( GetFormat()->GetURL() );
197 OUString retText;
198 ImageMap* pMap = aURL.GetMap();
199 if( pMap != nullptr )
200 {
201 IMapObject* pMapObj = pMap->GetIMapObject(nIndex);
202 if (!pMapObj->GetURL().isEmpty())
203 retText = pMapObj->GetURL();
204 }
205 else if ( !aURL.GetURL().isEmpty() )
206 retText = aURL.GetURL();
207
208 Any aRet;
209 aRet <<= retText;
210 return aRet;
211 }
212
getStartIndex()213 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getStartIndex()
214 {
215 return 0;
216 }
217
getEndIndex()218 sal_Int32 SAL_CALL SwAccessibleNoTextHyperlink::getEndIndex()
219 {
220 return 0;
221 }
222
isValid()223 sal_Bool SAL_CALL SwAccessibleNoTextHyperlink::isValid( )
224 {
225 SolarMutexGuard g;
226
227 SwFormatURL aURL( GetFormat()->GetURL() );
228
229 if( aURL.GetMap() || !aURL.GetURL().isEmpty() )
230 return true;
231 return false;
232 }
233
234 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
235