summaryrefslogtreecommitdiff
path: root/winaccessibility/source/UAccCOM/AccRelation.cxx
blob: 2c815c674f24ab7149bd70248a0128400116b633 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#include "stdafx.h"
#include  <UAccCOM.h>
#include "AccRelation.h"

#include <vcl/svapp.hxx>

#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/accessibility/XAccessible.hpp>
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include "MAccessible.h"

using namespace com::sun::star::accessibility;
using namespace com::sun::star::uno;

/**
   * Get relation type.
   * @param relationType Variant to get relation type.
   * @return Result.
*/
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_relationType(BSTR * relationType)
{
    SolarMutexGuard g;

    try {

    if (relationType == nullptr)
        return E_INVALIDARG;

    int type = relation.RelationType;
    SysFreeString(*relationType);

    *relationType = getRelationTypeBSTR(type);
    return S_OK;

    } catch(...) { return E_FAIL; }
}

// Gets what the type of localized relation is.
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_localizedRelationType(BSTR *)
{


    try {

    return S_OK;

    } catch(...) { return E_FAIL; }
}

/**
   * Get targets length.
   * @param nTargets Variant to get targets length.
   * @return Result.
*/
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_nTargets(long * nTargets)
{
    SolarMutexGuard g;

    try {

    if (nTargets == nullptr)
        return E_INVALIDARG;

    Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
    *nTargets = xTargets.getLength();
    return S_OK;

    } catch(...) { return E_FAIL; }
}

/**
   * Get special target.
   * @param targetIndex target index.
   * @param target      Variant to get special target.
   * @return Result.
*/
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_target(long targetIndex, IUnknown * * target)
{
    SolarMutexGuard g;

    try {

    if (target == nullptr)
        return E_FAIL;

    Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
    int nCount = xTargets.getLength();
    if( targetIndex >= nCount )
        return E_FAIL;

    Reference<XAccessible> xRAcc(xTargets[targetIndex], UNO_QUERY);
    IAccessible* pRet = CMAccessible::get_IAccessibleFromXAccessible(xRAcc.get());
    if (pRet)
    {
        *target = pRet;
        pRet->AddRef();
        return S_OK;
    }

    return E_FAIL;

    } catch(...) { return E_FAIL; }
}

/**
   * Get special targets.
   * @param maxTargets Special targets count.
   * @param target Variant to get special target.
   * @param nTargets Variant to accept actual target length.
   * @return Result.
*/
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::get_targets(long, IUnknown * * target, long * nTargets)
{
    SolarMutexGuard g;

    try {

    // #CHECK#
    if(target == nullptr)
        return E_INVALIDARG;
    if (nTargets == nullptr)
        return E_INVALIDARG;

    Sequence< Reference< XInterface > > xTargets = relation.TargetSet;
    int nCount = xTargets.getLength();

    *target = static_cast<IUnknown*>(::CoTaskMemAlloc(nCount*sizeof(IUnknown)));

    // #CHECK Memory Allocation#
    if(*target == nullptr)
    {
        return E_FAIL;
    }

    for(int i=0; i<nCount ; i++)
    {
        IUnknown* pAcc = nullptr;
        HRESULT hr = get_target(i,&pAcc);
        if(SUCCEEDED(hr))
            target[i] = pAcc;
    }

    *nTargets = nCount;
    return S_OK;

    } catch(...) { return E_FAIL; }
}

/**
   * Put UNO interface.
   * @param pXSubInterface AccessibleRelation pointer.
   * @return Result.
*/
COM_DECLSPEC_NOTHROW STDMETHODIMP CAccRelation::put_XSubInterface(hyper pXSubInterface)
{
    // internal IUNOXWrapper - no mutex meeded

    relation = *reinterpret_cast<AccessibleRelation*>(pXSubInterface);
    return S_OK;
}

/**
   * Get relation type string by type.
   * @param type Relation type.
   * @return relation type string.
*/
BSTR CAccRelation::getRelationTypeBSTR(int type)
{
    static LPCWSTR map[] =
        {
            L"INVALID",                  // AccessibleRelationType::INVALID
            IA2_RELATION_FLOWS_FROM,     // AccessibleRelationType::CONTENT_FLOWS_FROM
            IA2_RELATION_FLOWS_TO,       // AccessibleRelationType::CONTENT_FLOWS_TO
            IA2_RELATION_CONTROLLED_BY,  // AccessibleRelationType::CONTROLLED_BY
            IA2_RELATION_CONTROLLER_FOR, // AccessibleRelationType::CONTROLLER_FOR
            IA2_RELATION_LABEL_FOR,      // AccessibleRelationType::LABEL_FOR
            IA2_RELATION_LABELED_BY,     // AccessibleRelationType::LABELED_BY
            IA2_RELATION_MEMBER_OF,      // AccessibleRelationType::MEMBER_OF
            IA2_RELATION_SUBWINDOW_OF,   // AccessibleRelationType::SUB_WINDOW_OF
            IA2_RELATION_NODE_CHILD_OF,  // AccessibleRelationType::NODE_CHILD_OF
            IA2_RELATION_DESCRIBED_BY    // AccessibleRelationType::DESCRIBED_BY
        };

    return ::SysAllocString( (type >= AccessibleRelationType::INVALID && type <= AccessibleRelationType::DESCRIBED_BY)
                             ? map[type] : L"");
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */