LibreOffice Module winaccessibility (master) 1
EnumVariant.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include "stdafx.h"
21#include <UAccCOM.h>
22#include "EnumVariant.h"
23#include "MAccessible.h"
24
25#include <sal/log.hxx>
26#include <vcl/svapp.hxx>
27
28using namespace com::sun::star::uno;
29using namespace com::sun::star::accessibility;
30
31
32// CEnumVariant
33
34
42HRESULT STDMETHODCALLTYPE CEnumVariant::Next(ULONG cElements,VARIANT __RPC_FAR *pvar,ULONG __RPC_FAR *pcElementFetched)
43{
45
46 ULONG l2;
47
48 if (pvar == nullptr)
49 return E_INVALIDARG;
50
51 if (pcElementFetched != nullptr)
52 *pcElementFetched = 0;
53
54 sal_Int64 nChildCount = m_pXAccessibleSelection->getSelectedAccessibleChildCount();
55 if (nChildCount > std::numeric_limits<long>::max())
56 {
57 SAL_WARN("iacc2", "CEnumVariant::Next: Child count exceeds maximum long value, "
58 "using max long.");
59 nChildCount = std::numeric_limits<long>::max();
60 }
61
62 // Retrieve the next cElements.
63 sal_Int64 l1;
64 for (l1 = m_nCurrent, l2 = 0; l1 < nChildCount && l2 < cElements; l1++, l2++)
65 {
66 Reference< XAccessible > pRXAcc = m_pXAccessibleSelection->getSelectedAccessibleChild(l1);
67 IAccessible* pChild = nullptr;
68 bool isGet = CMAccessible::get_IAccessibleFromXAccessible(pRXAcc.get(),
69 &pChild);
70 if(isGet)
71 {
72 pvar[l2].vt = VT_DISPATCH;
73 pvar[l2].pdispVal = pChild;
74 pChild->AddRef();
75 }
76 else if(pRXAcc.is())
77 {
81 pRXAcc.get(), &pChild);
82 if(isGet)
83 {
84 pvar[l2].vt = VT_DISPATCH;
85 pvar[l2].pdispVal = pChild;
86 pChild->AddRef();
87 }
88 }
89 }
90 // Set count of elements retrieved.
91 if (pcElementFetched != nullptr)
92 *pcElementFetched = l2;
93 m_nCurrent = l1;
94
95 return (l2 < cElements) ? S_FALSE : NOERROR;
96}
97
103HRESULT STDMETHODCALLTYPE CEnumVariant::Skip(ULONG cElements)
104{
106
107 m_nCurrent += cElements;
108 sal_Int64 nChildCount = m_pXAccessibleSelection->getSelectedAccessibleChildCount();
109 if (nChildCount > std::numeric_limits<long>::max())
110 {
111 SAL_WARN("iacc2", "CEnumVariant::Skip: Child count exceeds maximum long value, "
112 "using max long.");
113 nChildCount = std::numeric_limits<long>::max();
114 }
115 if (m_nCurrent > nChildCount)
116 {
117 m_nCurrent = nChildCount;
118 return E_FAIL;
119 }
120 else
121 return NOERROR;
122}
123
124
130HRESULT STDMETHODCALLTYPE CEnumVariant::Reset()
131{
133
134 m_nCurrent = 0;
135 return NOERROR;
136}
137
138
147HRESULT STDMETHODCALLTYPE CEnumVariant::Clone(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppenum)
148{
150
151 CEnumVariant * penum = nullptr;
152 HRESULT hr;
153 if (ppenum == nullptr)
154 return E_INVALIDARG;
155
156 *ppenum = nullptr;
157
158 hr = Create(&penum);
159 if( hr == S_OK )
160 {
161 penum->PutSelection(reinterpret_cast<hyper>(pUNOInterface));
162 *ppenum = penum;
163 }
164 else
165 {
166 if (penum)
167 penum->Release();
168 }
169 return hr;
170}
171
177HRESULT STDMETHODCALLTYPE CEnumVariant::Create(CEnumVariant __RPC_FAR *__RPC_FAR *ppenum)
178{
180
181 HRESULT hr = createInstance<CEnumVariant>(IID_IEnumVariant, ppenum);
182 if (S_OK != hr)
183 {
184 return E_FAIL;
185 }
186
187 return S_OK;
188}
189
196{
198 {
199 sal_Int64 nCount = m_pXAccessibleSelection->getSelectedAccessibleChildCount();
200 if (nCount > std::numeric_limits<long>::max())
201 {
202 SAL_WARN("iacc2", "CEnumVariant::GetCountOfElements: Count exceeds maximum long value, "
203 "using max long.");
204 nCount = std::numeric_limits<long>::max();
205 }
206 return nCount;
207 }
208 return 0;
209}
210
216COM_DECLSPEC_NOTHROW STDMETHODIMP CEnumVariant::ClearEnumeration()
217{
218 // internal IEnumVariant - no mutex meeded
219
220 pUNOInterface = nullptr;
221 m_pXAccessibleSelection = nullptr;
222 m_nCurrent = 0;
223 return S_OK;
224}
225
232{
233 if( pXAcc == nullptr)
234 return nullptr;
235
236 Reference< XAccessibleContext > pRContext = pXAcc->getAccessibleContext();
237 if( !pRContext.is() )
238 return nullptr;
239
240 Reference< XAccessibleSelection > pRSelection(pRContext,UNO_QUERY);
241 if( !pRSelection.is() )
242 return nullptr;
243
244 return pRSelection;
245}
246
252STDMETHODIMP CEnumVariant::PutSelection(hyper pXSelection)
253{
254 // internal IEnumVariant - no mutex meeded
255
256 pUNOInterface = reinterpret_cast<XAccessible*>(pXSelection);
258 return S_OK;
259}
260
261/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static Reference< XAccessibleSelection > GetXAccessibleSelection(XAccessible *pXAcc)
Static method to fetch XAccessibleSelection.
virtual bool InsertAccObj(css::accessibility::XAccessible *pXAcc, css::accessibility::XAccessible *pParentXAcc, HWND hWnd=nullptr)
When a new UNO XAccessible object is found by listener, we create a corresponding com object and inse...
CEnumVariant implements IEnumVARIANT interface.
Definition: EnumVariant.h:35
HRESULT STDMETHODCALLTYPE PutSelection(hyper pXSelection) override
Put valid UNO XAccessible interface.
HRESULT STDMETHODCALLTYPE Next(ULONG cElements, VARIANT __RPC_FAR *pvar, ULONG __RPC_FAR *pcElementFetched) override
enumerate method,get next element
Definition: EnumVariant.cxx:42
HRESULT STDMETHODCALLTYPE Clone(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppenum) override
create a new IEnumVariant object, copy current enumaration container and its state to the new object ...
css::uno::Reference< css::accessibility::XAccessibleSelection > m_pXAccessibleSelection
Definition: EnumVariant.h:96
sal_Int64 m_nCurrent
Definition: EnumVariant.h:93
css::accessibility::XAccessible * pUNOInterface
Definition: EnumVariant.h:94
STDMETHOD() ClearEnumeration() override
Set member m_pXAccessibleSelection to NULL and m_nCurrent to 0.
HRESULT STDMETHODCALLTYPE Skip(ULONG cElements) override
skip the elements in the given range when enumerate elements
long GetCountOfElements()
Return count of elements in current container.
static HRESULT STDMETHODCALLTYPE Create(CEnumVariant __RPC_FAR *__RPC_FAR *ppenum)
Static public method to create a CLSID_EnumVariant com object.
HRESULT STDMETHODCALLTYPE Reset(void) override
reset the enumaration position to initial value
static bool get_IAccessibleFromXAccessible(css::accessibility::XAccessible *pXAcc, IAccessible **ppIA)
static AccObjectManagerAgent * g_pAgent
Definition: MAccessible.h:207
int nCount
#define SAL_WARN(area, stream)
return hr