bump product version to 5.0.4.1
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccRelation.cxx
blob81e7fed1e03716bc2bc32e6d2e32be46e1a5f21a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "stdafx.h"
21 #include "UAccCOM.h"
22 #include "AccRelation.h"
24 #include <vcl/svapp.hxx>
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
28 #include "MAccessible.h"
30 using namespace com::sun::star::accessibility;
31 using namespace com::sun::star::uno;
33 /**
34 * Get relation type.
35 * @param relationType Variant to get relation type.
36 * @return Result.
38 STDMETHODIMP CAccRelation::get_relationType(BSTR * relationType)
40 SolarMutexGuard g;
42 ENTER_PROTECTED_BLOCK
44 if (relationType == NULL)
45 return E_INVALIDARG;
47 int type = relation.RelationType;
48 SAFE_SYSFREESTRING(*relationType);
50 *relationType = getRelationTypeBSTR(type);
51 return S_OK;
53 LEAVE_PROTECTED_BLOCK
56 // Gets what the type of localized relation is.
57 STDMETHODIMP CAccRelation::get_localizedRelationType(BSTR *)
61 ENTER_PROTECTED_BLOCK
63 return S_OK;
65 LEAVE_PROTECTED_BLOCK
68 /**
69 * Get targets length.
70 * @param nTargets Variant to get targets length.
71 * @return Result.
73 STDMETHODIMP CAccRelation::get_nTargets(long * nTargets)
75 SolarMutexGuard g;
77 ENTER_PROTECTED_BLOCK
79 if (nTargets == NULL)
80 return E_INVALIDARG;
82 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
83 *nTargets = xTargets.getLength();
84 return S_OK;
86 LEAVE_PROTECTED_BLOCK
89 /**
90 * Get special target.
91 * @param targetIndex target index.
92 * @param target Variant to get special target.
93 * @return Result.
95 STDMETHODIMP CAccRelation::get_target(long targetIndex, IUnknown * * target)
97 SolarMutexGuard g;
99 ENTER_PROTECTED_BLOCK
101 if (target == NULL)
102 return E_FAIL;
104 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
105 int nCount = xTargets.getLength();
106 if( targetIndex >= nCount )
107 return E_FAIL;
109 Reference<XAccessible> xRAcc(xTargets[targetIndex], UNO_QUERY);
110 IAccessible* pRet = NULL;
112 BOOL isGet = CMAccessible::get_IAccessibleFromXAccessible(xRAcc.get(), &pRet);
113 if(isGet)
115 *target = /*(IAccessible2 *)*/(IUnknown*)pRet;
116 pRet->AddRef();
117 return S_OK;
120 return E_FAIL;
122 LEAVE_PROTECTED_BLOCK
126 * Get special targets.
127 * @param maxTargets Special targets count.
128 * @param target Variant to get special target.
129 * @param nTargets Variant to accept actual target length.
130 * @return Result.
132 STDMETHODIMP CAccRelation::get_targets(long, IUnknown * * target, long * nTargets)
134 SolarMutexGuard g;
136 ENTER_PROTECTED_BLOCK
138 // #CHECK#
139 if(target == NULL)
140 return E_INVALIDARG;
141 if (nTargets == NULL)
142 return E_INVALIDARG;
144 Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
145 int nCount = xTargets.getLength();
147 *target = (IUnknown*)::CoTaskMemAlloc(nCount*sizeof(IUnknown));
149 // #CHECK Memory Allocation#
150 if(*target == NULL)
152 return E_FAIL;
155 for(int i=0; i<nCount ; i++)
157 IUnknown* pAcc = NULL;
158 HRESULT hr = get_target(i,&pAcc);
159 if(SUCCEEDED(hr))
160 target[i] = pAcc;
163 *nTargets = nCount;
164 return S_OK;
166 LEAVE_PROTECTED_BLOCK
170 * Put UNO interface.
171 * @param pXSubInterface AccessibleRelation pointer.
172 * @return Result.
174 STDMETHODIMP CAccRelation::put_XSubInterface(hyper pXSubInterface)
176 // internal IUNOXWrapper - no mutex meeded
178 relation = *reinterpret_cast<AccessibleRelation*>(pXSubInterface);
179 return S_OK;
183 * Get relation type string by type.
184 * @param type Relation type.
185 * @return relation type string.
187 BSTR CAccRelation::getRelationTypeBSTR(int type)
189 static struct TYPE_BSTR_MAP
191 LPCTSTR string;
192 int type;
194 map[] =
196 {_T("INVALID") , 0},
197 {IA2_RELATION_FLOWS_FROM , 1},
198 {IA2_RELATION_FLOWS_TO , 2},
199 {IA2_RELATION_CONTROLLED_BY , 3},
200 {IA2_RELATION_CONTROLLER_FOR, 4},
201 {IA2_RELATION_LABEL_FOR , 5},
202 {IA2_RELATION_LABELED_BY , 6},
203 {IA2_RELATION_MEMBER_OF , 7},
204 {IA2_RELATION_SUBWINDOW_OF , 8},
205 {IA2_RELATION_NODE_CHILD_OF , 9},
206 {IA2_RELATION_DESCRIBED_BY , 10},
209 return ::SysAllocString((type >= 0 && type <= 10) ? map[type].string : _T(""));
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */