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 #include "stdafx.h"
23 #include "UAccCOM2.h"
24 #include "AccHyperLink.h"
25 #include <com/sun/star/accessibility/XAccessible.hpp>
26 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
27 #include "MAccessible.h"
28 
29 using namespace com::sun::star::accessibility;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::awt;
32 
33 /**
34  * Returns the number of action.
35  *
36  * @param    nActions    the number of action.
37  */
nActions(long * nActions)38 STDMETHODIMP CAccHyperLink::nActions(/*[out,retval]*/long* nActions)
39 {
40 
41     return CAccActionBase::nActions(nActions);
42 }
43 
44 /**
45  * Performs specified action on the object.
46  *
47  * @param    actionIndex    the index of action.
48  */
doAction(long actionIndex)49 STDMETHODIMP CAccHyperLink::doAction(/* [in] */ long actionIndex)
50 {
51 
52     return CAccActionBase::doAction(actionIndex);
53 }
54 
55 /**
56  * Gets description of specified action.
57  *
58  * @param    actionIndex    the index of action.
59  * @param    description    the description string of the specified action.
60  */
get_description(long actionIndex,BSTR __RPC_FAR * description)61 STDMETHODIMP CAccHyperLink::get_description(long actionIndex,BSTR __RPC_FAR *description)
62 {
63 
64     return CAccActionBase::get_description(actionIndex, description);
65 }
66 
get_name(long actionIndex,BSTR __RPC_FAR * name)67 STDMETHODIMP CAccHyperLink::get_name( long actionIndex, BSTR __RPC_FAR *name)
68 {
69 
70     return CAccActionBase::get_name(actionIndex, name);
71 }
72 
get_localizedName(long actionIndex,BSTR __RPC_FAR * localizedName)73 STDMETHODIMP CAccHyperLink::get_localizedName( long actionIndex, BSTR __RPC_FAR *localizedName)
74 {
75 
76     return CAccActionBase::get_name(actionIndex, localizedName);
77 }
78 
79 /**
80  * Returns key binding object (if any) associated with specified action
81  * key binding is string.
82  * e.g. "alt+d" (like IAccessible::get_accKeyboardShortcut).
83  *
84  * @param    actionIndex    the index of action.
85  * @param    nMaxBinding    the max number of key binding.
86  * @param    keyBinding     the key binding array.
87  * @param    nBinding       the actual number of key binding returned.
88  */
get_keyBinding(long actionIndex,long nMaxBinding,BSTR __RPC_FAR * __RPC_FAR * keyBinding,long __RPC_FAR * nBinding)89 STDMETHODIMP CAccHyperLink::get_keyBinding(
90     /* [in] */ long actionIndex,
91     /* [in] */ long nMaxBinding,
92     /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR *__RPC_FAR *keyBinding,
93     /* [retval][out] */ long __RPC_FAR *nBinding)
94 {
95 
96     return CAccActionBase::get_keyBinding(actionIndex, nMaxBinding,	keyBinding, nBinding);
97 }
98 
99 /**
100    * get an object
101    * @param
102    * @return Result.
103 */
get_anchor(long index,VARIANT __RPC_FAR * anchor)104 STDMETHODIMP CAccHyperLink::get_anchor(/* [in] */ long index,
105         /* [retval][out] */ VARIANT __RPC_FAR *anchor)
106 {
107 
108 	CHECK_ENABLE_INF
109 
110     ENTER_PROTECTED_BLOCK
111 
112     // #CHECK#
113     if(anchor == NULL)
114     {
115         return E_INVALIDARG;
116     }
117     // #CHECK XInterface#
118     if(!pRXLink.is())
119     {
120         return E_FAIL;
121     }
122     // Get Any type value via pRXLink.
123     ::com::sun::star::uno::Any	anyVal = GetXInterface()->getAccessibleActionAnchor(index);
124     // Convert Any to VARIANT.
125     CMAccessible::ConvertAnyToVariant(anyVal, anchor);
126 
127     return S_OK;
128 
129     LEAVE_PROTECTED_BLOCK
130 }
131 
132 /**
133    * get an object
134    * @param
135    * @return Result.
136 */
get_anchorTarget(long index,VARIANT __RPC_FAR * anchorTarget)137 STDMETHODIMP CAccHyperLink::get_anchorTarget(/* [in] */ long index,
138         /* [retval][out] */ VARIANT __RPC_FAR *anchorTarget)
139 {
140 
141 
142 	CHECK_ENABLE_INF
143     ENTER_PROTECTED_BLOCK
144 
145     // #CHECK#
146     if(anchorTarget == NULL)
147     {
148         return E_INVALIDARG;
149     }
150     // #CHECK XInterface#
151     if(!pRXLink.is())
152     {
153         return E_FAIL;
154     }
155     // Get Any type value via pRXLink.
156     ::com::sun::star::uno::Any	anyVal = GetXInterface()->getAccessibleActionObject(index);
157     // Convert Any to VARIANT.
158     CMAccessible::ConvertAnyToVariant(anyVal, anchorTarget);
159 
160     return S_OK;
161 
162     LEAVE_PROTECTED_BLOCK
163 }
164 
165 
166 /**
167    * Get start index.
168    * @param index Variant to get start index.
169    * @return Result.
170 */
get_startIndex(long __RPC_FAR * index)171 STDMETHODIMP CAccHyperLink::get_startIndex(/* [retval][out] */ long __RPC_FAR *index)
172 {
173 
174 	CHECK_ENABLE_INF
175 
176     ENTER_PROTECTED_BLOCK
177 
178     // #CHECK#
179     if(index == NULL)
180     {
181         return E_INVALIDARG;
182     }
183     *index = GetXInterface()->getStartIndex();
184 
185     return S_OK;
186 
187     LEAVE_PROTECTED_BLOCK
188 }
189 
190 /**
191    * Get start index.
192    * @param index Variant to get end index.
193    * @return Result.
194 */
get_endIndex(long __RPC_FAR * index)195 STDMETHODIMP CAccHyperLink::get_endIndex(/* [retval][out] */ long __RPC_FAR *index)
196 {
197 
198 	CHECK_ENABLE_INF
199 
200     ENTER_PROTECTED_BLOCK
201 
202     // #CHECK#
203     if(index == NULL)
204     {
205         return E_INVALIDARG;
206     }
207     // #CHECK XInterface#
208     if(!pRXLink.is())
209     {
210         return E_FAIL;
211     }
212     *index = GetXInterface()->getEndIndex();
213 
214     return S_OK;
215 
216     LEAVE_PROTECTED_BLOCK
217 }
218 
219 /**
220    * Judge if the hyperlink is valid.
221    * @param valid Variant to get validity.
222    * @return Result.
223 */
get_valid(boolean __RPC_FAR * valid)224 STDMETHODIMP CAccHyperLink::get_valid(/* [retval][out] */ boolean __RPC_FAR *valid)
225 {
226 
227 	CHECK_ENABLE_INF
228 
229     ENTER_PROTECTED_BLOCK
230 
231     // #CHECK#
232     if(valid == NULL)
233     {
234         return E_INVALIDARG;
235     }
236     // #CHECK XInterface#
237     if(!pRXLink.is())
238     {
239         return E_FAIL;
240     }
241     *valid = GetXInterface()->isValid();
242 
243     return S_OK;
244 
245     LEAVE_PROTECTED_BLOCK
246 }
247 
248 /**
249    * Put UNO interface.
250    * @param pXInterface XAccessibleContext interface.
251    * @return Result.
252 */
put_XInterface(long pXInterface)253 STDMETHODIMP CAccHyperLink::put_XInterface(long pXInterface)
254 {
255 
256 	CHECK_ENABLE_INF
257 
258     ENTER_PROTECTED_BLOCK
259 
260     CAccActionBase::put_XInterface(pXInterface);
261     //special query.
262     if(pUNOInterface != NULL)
263     {
264         Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
265         if( !pRContext.is() )
266         {
267             return E_FAIL;
268         }
269         Reference<XAccessibleHyperlink> pRXI(pRContext,UNO_QUERY);
270         if( !pRXI.is() )
271         {
272             pRXLink = NULL;
273         }
274         else
275             pRXLink = pRXI.get();
276     }
277     return S_OK;
278 
279     LEAVE_PROTECTED_BLOCK
280 }
281 
282 /**
283    * Put UNO interface.
284    * @param pXSubInterface XAccessibleHyperlink interface.
285    * @return Result.
286 */
put_XSubInterface(long pXSubInterface)287 STDMETHODIMP CAccHyperLink::put_XSubInterface(long pXSubInterface)
288 {
289 
290 	CHECK_ENABLE_INF
291 
292     pRXLink = (XAccessibleHyperlink*)pXSubInterface;
293     pRXAct = (XAccessibleAction*)pXSubInterface;
294 
295     return S_OK;
296 }
297