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