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 "AccRelation.h"
25 #include <com/sun/star/accessibility/XAccessible.hpp>
26 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
27 #include "MAccessible.h"
28
29 using namespace com::sun::star::accessibility;
30 using namespace com::sun::star::uno;
31
32 /**
33 * Get relation type.
34 * @param relationType Variant to get relation type.
35 * @return Result.
36 */
get_relationType(BSTR * relationType)37 STDMETHODIMP CAccRelation::get_relationType(BSTR * relationType)
38 {
39
40 CHECK_ENABLE_INF
41
42 ENTER_PROTECTED_BLOCK
43
44 if (relationType == NULL)
45 return E_INVALIDARG;
46
47 int type = relation.RelationType;
48 SAFE_SYSFREESTRING(*relationType);
49
50 *relationType = getRelationTypeBSTR(type);
51 return S_OK;
52
53 LEAVE_PROTECTED_BLOCK
54 }
55
56 // Gets what the type of localized relation is.
get_localizedRelationType(BSTR *)57 STDMETHODIMP CAccRelation::get_localizedRelationType(BSTR *)
58 {
59
60
61 ENTER_PROTECTED_BLOCK
62
63 return S_OK;
64
65 LEAVE_PROTECTED_BLOCK
66 }
67
68 /**
69 * Get targets length.
70 * @param nTargets Variant to get targets length.
71 * @return Result.
72 */
get_nTargets(long * nTargets)73 STDMETHODIMP CAccRelation::get_nTargets(long * nTargets)
74 {
75
76
77 ENTER_PROTECTED_BLOCK
78
79 CHECK_ENABLE_INF
80 if (nTargets == NULL)
81 return E_INVALIDARG;
82
83 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
84 *nTargets = xTargets.getLength();
85 return S_OK;
86
87 LEAVE_PROTECTED_BLOCK
88 }
89
90 /**
91 * Get special target.
92 * @param targetIndex target index.
93 * @param target Variant to get special target.
94 * @return Result.
95 */
get_target(long targetIndex,IUnknown ** target)96 STDMETHODIMP CAccRelation::get_target(long targetIndex, IUnknown * * target)
97 {
98
99 CHECK_ENABLE_INF
100
101 ENTER_PROTECTED_BLOCK
102
103 if (target == NULL)
104 return E_FAIL;
105
106 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
107 int nCount = xTargets.getLength();
108 if( targetIndex >= nCount )
109 return E_FAIL;
110
111 Reference<XInterface> pRAcc = xTargets[targetIndex];
112 IAccessible* pRet = NULL;
113
114 BOOL isGet = CMAccessible::get_IAccessibleFromXAccessible((long)pRAcc.get(),&pRet);
115 if(isGet)
116 {
117 *target = /*(IAccessible2 *)*/(IUnknown*)pRet;
118 pRet->AddRef();
119 return S_OK;
120 }
121
122 return E_FAIL;
123
124 LEAVE_PROTECTED_BLOCK
125 }
126
127 /**
128 * Get special targets.
129 * @param maxTargets Special targets count.
130 * @param target Variant to get special target.
131 * @param nTargets Variant to accept actual target length.
132 * @return Result.
133 */
get_targets(long,IUnknown ** target,long * nTargets)134 STDMETHODIMP CAccRelation::get_targets(long, IUnknown * * target, long * nTargets)
135 {
136
137 CHECK_ENABLE_INF
138
139 ENTER_PROTECTED_BLOCK
140
141 // #CHECK#
142 if(target == NULL)
143 return E_INVALIDARG;
144 if (nTargets == NULL)
145 return E_INVALIDARG;
146
147 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
148 int nCount = xTargets.getLength();
149
150 *target = (IUnknown*)::CoTaskMemAlloc(nCount*sizeof(IUnknown));
151
152 // #CHECK Memory Allocation#
153 if(*target == NULL)
154 {
155 return E_FAIL;
156 }
157
158 for(int i=0; i<nCount ; i++)
159 {
160 IUnknown* pAcc = NULL;
161 HRESULT hr = get_target(i,&pAcc);
162 if(SUCCEEDED(hr))
163 target[i] = pAcc;
164 }
165
166 *nTargets = nCount;
167 return S_OK;
168
169 LEAVE_PROTECTED_BLOCK
170 }
171
172 /**
173 * Put UNO interface.
174 * @param pXSubInterface AccessibleRelation pointer.
175 * @return Result.
176 */
put_XSubInterface(long pXSubInterface)177 STDMETHODIMP CAccRelation::put_XSubInterface(long pXSubInterface)
178 {
179
180 relation = *((AccessibleRelation*)pXSubInterface);
181 return S_OK;
182 }
183
184 /**
185 * Get relation type string by type.
186 * @param type Relation type.
187 * @return relation type string.
188 */
getRelationTypeBSTR(int type)189 BSTR CAccRelation::getRelationTypeBSTR(int type)
190 {
191 static struct TYPE_BSTR_MAP
192 {
193 LPCTSTR string;
194 int type;
195 }
196 map[] =
197 {
198 {_T("INVALID") , 0},
199 {IA2_RELATION_FLOWS_FROM , 1},
200 {IA2_RELATION_FLOWS_TO , 2},
201 {IA2_RELATION_CONTROLLED_BY , 3},
202 {IA2_RELATION_CONTROLLER_FOR, 4},
203 {IA2_RELATION_LABEL_FOR , 5},
204 {IA2_RELATION_LABELED_BY , 6},
205 {IA2_RELATION_MEMBER_OF , 7},
206 {IA2_RELATION_SUBWINDOW_OF , 8},
207 {IA2_RELATION_NODE_CHILD_OF, 9},
208 {IA2_RELATION_DESCRIBED_BY , 10},
209 };
210
211 USES_CONVERSION;
212
213 return (type >= 0 && type <= 10) ? T2BSTR(map[type].string) : _T("");
214 }
215