Bug 453883, ensure true/false marcos are available, r=joshmoz, sr=jst
[wine-gecko.git] / accessible / src / msaa / nsAccessibleRelationWrap.cpp
blob160fbc0b8152e5b39b593268f3a391efadebdff2
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=2:tabstop=2:
3 */
4 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is mozilla.org code.
19 * The Initial Developer of the Original Code is
20 * Mozilla Foundation.
21 * Portions created by the Initial Developer are Copyright (C) 2007
22 * the Initial Developer. All Rights Reserved.
24 * Contributor(s):
25 * Alexander Surkov <surkov.alexander@gmail.com> (original author)
27 * Alternatively, the contents of this file may be used under the terms of
28 * either the GNU General Public License Version 2 or later (the "GPL"), or
29 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #include "nsAccessibleRelationWrap.h"
43 #include "AccessibleRelation_i.c"
44 #include "nsAccessNodeWrap.h"
46 #include "nsArrayUtils.h"
48 nsAccessibleRelationWrap::
49 nsAccessibleRelationWrap(PRUint32 aType, nsIAccessible *aTarget) :
50 nsAccessibleRelation(aType, aTarget)
54 // ISupports
56 NS_IMPL_ISUPPORTS_INHERITED1(nsAccessibleRelationWrap, nsAccessibleRelation,
57 nsIWinAccessNode)
59 // nsIWinAccessNode
61 NS_IMETHODIMP
62 nsAccessibleRelationWrap::QueryNativeInterface(REFIID aIID, void** aInstancePtr)
64 return QueryInterface(aIID, aInstancePtr);
67 // IUnknown
69 STDMETHODIMP
70 nsAccessibleRelationWrap::QueryInterface(REFIID iid, void** ppv)
72 *ppv = NULL;
74 if (IID_IAccessibleRelation == iid || IID_IUnknown == iid) {
75 *ppv = static_cast<IAccessibleRelation*>(this);
76 (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
77 return S_OK;
80 return E_NOINTERFACE;
83 // IAccessibleRelation
85 STDMETHODIMP
86 nsAccessibleRelationWrap::get_relationType(BSTR *aRelationType)
88 __try {
89 *aRelationType = NULL;
91 PRUint32 type = 0;
92 nsresult rv = GetRelationType(&type);
93 if (NS_FAILED(rv))
94 return GetHRESULT(rv);
96 switch (type) {
97 case RELATION_CONTROLLED_BY:
98 *aRelationType = ::SysAllocString(IA2_RELATION_CONTROLLED_BY);
99 break;
100 case RELATION_CONTROLLER_FOR:
101 *aRelationType = ::SysAllocString(IA2_RELATION_CONTROLLER_FOR);
102 break;
103 case RELATION_DESCRIBED_BY:
104 *aRelationType = ::SysAllocString(IA2_RELATION_DESCRIBED_BY);
105 break;
106 case RELATION_DESCRIPTION_FOR:
107 *aRelationType = ::SysAllocString(IA2_RELATION_DESCRIPTION_FOR);
108 break;
109 case RELATION_EMBEDDED_BY:
110 *aRelationType = ::SysAllocString(IA2_RELATION_EMBEDDED_BY);
111 break;
112 case RELATION_EMBEDS:
113 *aRelationType = ::SysAllocString(IA2_RELATION_EMBEDS);
114 break;
115 case RELATION_FLOWS_FROM:
116 *aRelationType = ::SysAllocString(IA2_RELATION_FLOWS_FROM);
117 break;
118 case RELATION_FLOWS_TO:
119 *aRelationType = ::SysAllocString(IA2_RELATION_FLOWS_TO);
120 break;
121 case RELATION_LABEL_FOR:
122 *aRelationType = ::SysAllocString(IA2_RELATION_LABEL_FOR);
123 break;
124 case RELATION_LABELLED_BY:
125 *aRelationType = ::SysAllocString(IA2_RELATION_LABELED_BY);
126 break;
127 case RELATION_MEMBER_OF:
128 *aRelationType = ::SysAllocString(IA2_RELATION_MEMBER_OF);
129 break;
130 case RELATION_NODE_CHILD_OF:
131 *aRelationType = ::SysAllocString(IA2_RELATION_NODE_CHILD_OF);
132 break;
133 case RELATION_PARENT_WINDOW_OF:
134 *aRelationType = ::SysAllocString(IA2_RELATION_PARENT_WINDOW_OF);
135 break;
136 case RELATION_POPUP_FOR:
137 *aRelationType = ::SysAllocString(IA2_RELATION_POPUP_FOR);
138 break;
139 case RELATION_SUBWINDOW_OF:
140 *aRelationType = ::SysAllocString(IA2_RELATION_SUBWINDOW_OF);
141 break;
142 default:
143 return E_FAIL;
146 return *aRelationType ? S_OK : E_OUTOFMEMORY;
148 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
149 return E_FAIL;
152 STDMETHODIMP
153 nsAccessibleRelationWrap::get_localizedRelationType(BSTR *aLocalizedRelationType)
155 __try {
156 *aLocalizedRelationType = NULL;
158 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
159 return E_NOTIMPL;
162 STDMETHODIMP
163 nsAccessibleRelationWrap::get_nTargets(long *aNTargets)
165 __try {
166 *aNTargets = 0;
168 PRUint32 count = 0;
169 nsresult rv = GetTargetsCount(&count);
170 if (NS_FAILED(rv))
171 return GetHRESULT(rv);
173 *aNTargets = count;
174 return S_OK;
176 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
177 return E_FAIL;
180 STDMETHODIMP
181 nsAccessibleRelationWrap::get_target(long aTargetIndex, IUnknown **aTarget)
183 __try {
184 nsCOMPtr<nsIAccessible> accessible;
185 nsresult rv = GetTarget(aTargetIndex, getter_AddRefs(accessible));
186 if (NS_FAILED(rv))
187 return GetHRESULT(rv);
189 nsCOMPtr<nsIWinAccessNode> winAccessNode(do_QueryInterface(accessible));
190 if (!winAccessNode)
191 return E_FAIL;
193 void *instancePtr = NULL;
194 rv = winAccessNode->QueryNativeInterface(IID_IUnknown, &instancePtr);
195 if (NS_FAILED(rv))
196 return GetHRESULT(rv);
198 *aTarget = static_cast<IUnknown*>(instancePtr);
199 return S_OK;
201 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
202 return E_FAIL;
205 STDMETHODIMP
206 nsAccessibleRelationWrap::get_targets(long aMaxTargets, IUnknown **aTarget,
207 long *aNTargets)
209 __try {
210 *aNTargets = 0;
212 nsCOMPtr<nsIArray> targets;
213 nsresult rv = GetTargets(getter_AddRefs(targets));
214 if (NS_FAILED(rv))
215 return GetHRESULT(rv);
217 PRUint32 length = 0;
218 rv = targets->GetLength(&length);
219 if (NS_FAILED(rv))
220 return GetHRESULT(rv);
222 if (length == 0)
223 return S_FALSE;
225 PRUint32 count = length < PRUint32(aMaxTargets) ? length : aMaxTargets;
227 PRUint32 index = 0;
228 for (; index < count; index++) {
229 nsCOMPtr<nsIWinAccessNode> winAccessNode =
230 do_QueryElementAt(targets, index, &rv);
231 if (NS_FAILED(rv))
232 break;
234 void *instancePtr = NULL;
235 nsresult rv = winAccessNode->QueryNativeInterface(IID_IUnknown,
236 &instancePtr);
237 if (NS_FAILED(rv))
238 break;
240 aTarget[index] = static_cast<IUnknown*>(instancePtr);
243 if (NS_FAILED(rv)) {
244 for (PRUint32 index2 = 0; index2 < index; index2++) {
245 aTarget[index2]->Release();
246 aTarget[index2] = NULL;
248 return GetHRESULT(rv);
251 *aNTargets = count;
252 return S_OK;
254 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
255 return E_FAIL;