Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / winaccessibility / source / UAccCOM / EnumVariant.cxx
blob1cbb4513d73fa5418e55dddf2cf4b9dc00182753
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 "EnumVariant.h"
22 #include "MAccessible.h"
24 #if defined __clang__
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
27 #endif
28 #include <UAccCOM.h>
29 #if defined __clang__
30 #pragma clang diagnostic pop
31 #endif
33 #include <vcl/svapp.hxx>
35 using namespace com::sun::star::uno;
36 using namespace com::sun::star::accessibility;
39 // CEnumVariant
42 /**
43 * enumerate method,get next element
44 * @param cElements The number of elements to be returned.
45 * @param pvar An array of at least size celt in which the elements are to be returned.
46 * @param pcElementFetched Pointer to the number of elements returned in rgVar, or Null
47 * @return Result.
49 HRESULT STDMETHODCALLTYPE CEnumVariant::Next(ULONG cElements,VARIANT __RPC_FAR *pvar,ULONG __RPC_FAR *pcElementFetched)
51 SolarMutexGuard g;
53 long l1;
54 ULONG l2;
56 if (pvar == nullptr)
57 return E_INVALIDARG;
59 if (pcElementFetched != nullptr)
60 *pcElementFetched = 0;
62 // Retrieve the next cElements.
63 for (l1=m_lCurrent, l2=0; l1<m_pXAccessibleSelection->getSelectedAccessibleChildCount() &&
64 l2<cElements; l1++, l2++)
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)
72 pvar[l2].vt = VT_I4;
73 static_cast<IMAccessible*>(pChild)->Get_XAccChildID(&pvar[l2].lVal);
75 else if(pRXAcc.is())
77 if(CMAccessible::g_pAgent)
78 CMAccessible::g_pAgent->InsertAccObj(pRXAcc.get(),pUNOInterface);
79 isGet = CMAccessible::get_IAccessibleFromXAccessible(
80 pRXAcc.get(), &pChild);
81 if(isGet)
83 pvar[l2].vt = VT_I4;
84 static_cast<IMAccessible*>(pChild)->Get_XAccChildID(&pvar[l2].lVal);
88 // Set count of elements retrieved.
89 if (pcElementFetched != nullptr)
90 *pcElementFetched = l2;
91 m_lCurrent = l1;
93 return (l2 < cElements) ? S_FALSE : NOERROR;
96 /**
97 * skip the elements in the given range when enumerate elements
98 * @param cElements The number of elements to skip.
99 * @return Result.
101 HRESULT STDMETHODCALLTYPE CEnumVariant::Skip(ULONG cElements)
103 SolarMutexGuard g;
105 m_lCurrent += cElements;
106 if (m_lCurrent > static_cast<long>(m_lLBound+m_pXAccessibleSelection->getSelectedAccessibleChildCount()))
108 m_lCurrent = m_lLBound+m_pXAccessibleSelection->getSelectedAccessibleChildCount();
109 return E_FAIL;
111 else
112 return NOERROR;
117 * reset the enumaration position to initial value
118 * @param
119 * @return Result.
121 HRESULT STDMETHODCALLTYPE CEnumVariant::Reset()
123 SolarMutexGuard g;
125 m_lCurrent = m_lLBound;
126 return NOERROR;
131 *create a new IEnumVariant object,
132 *copy current enumaration container and its state to
133 *the new object
134 *AT will use the copy object to get elements
135 * @param ppenum On return, pointer to the location of the clone enumerator
136 * @return Result.
138 HRESULT STDMETHODCALLTYPE CEnumVariant::Clone(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppenum)
140 SolarMutexGuard g;
142 CEnumVariant * penum = nullptr;
143 HRESULT hr;
144 if (ppenum == nullptr)
145 return E_INVALIDARG;
147 *ppenum = nullptr;
149 hr = Create(&penum);
150 if( hr == S_OK )
152 penum->PutSelection(reinterpret_cast<hyper>(pUNOInterface));
153 *ppenum = penum;
155 else
157 if (penum)
158 penum->Release();
160 return hr;
164 *Static public method to create a CLSID_EnumVariant com object.
165 * @param ppenum Pointer to accept com object.
166 * @return Result.
168 HRESULT STDMETHODCALLTYPE CEnumVariant::Create(CEnumVariant __RPC_FAR *__RPC_FAR *ppenum)
170 SolarMutexGuard g;
172 HRESULT hr = createInstance<CEnumVariant>(IID_IEnumVariant, ppenum);
173 if (S_OK != hr)
175 return E_FAIL;
178 return S_OK;
182 *Return count of elements in current container
183 * @param.
184 * @return count of elements in current container.
186 long CEnumVariant::GetCountOfElements()
188 if(m_pXAccessibleSelection.is())
189 return m_pXAccessibleSelection->getSelectedAccessibleChildCount();
190 return 0;
194 * Set member m_pXAccessibleSelection to NULL and m_lCurrent to m_lLBound.
195 * @param.
196 * @return Result
198 COM_DECLSPEC_NOTHROW STDMETHODIMP CEnumVariant::ClearEnumeration()
200 // internal IEnumVariant - no mutex meeded
202 pUNOInterface = nullptr;
203 m_pXAccessibleSelection = nullptr;
204 m_lCurrent = m_lLBound;
205 return S_OK;
209 *Static method to fetch XAccessibleSelection
210 * @param pXAcc XAccessible interface.
211 * @return XAccessibleSelection interface.
213 static Reference<XAccessibleSelection> GetXAccessibleSelection(XAccessible* pXAcc)
215 if( pXAcc == nullptr)
216 return nullptr;
218 Reference< XAccessibleContext > pRContext = pXAcc->getAccessibleContext();
219 if( !pRContext.is() )
220 return nullptr;
222 Reference< XAccessibleSelection > pRSelection(pRContext,UNO_QUERY);
223 if( !pRSelection.is() )
224 return nullptr;
226 return pRSelection;
230 * Put valid UNO XAccessible interface.
231 * @param pXSelection XAccessible interface.
232 * @return Result...
234 STDMETHODIMP CEnumVariant::PutSelection(hyper pXSelection)
236 // internal IEnumVariant - no mutex meeded
238 pUNOInterface = reinterpret_cast<XAccessible*>(pXSelection);
239 m_pXAccessibleSelection = GetXAccessibleSelection(pUNOInterface);
240 return S_OK;
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */