1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "EnumVariant.h"
22 #include "MAccessible.h"
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wnon-virtual-dtor"
30 #pragma clang diagnostic pop
33 #include <vcl/svapp.hxx>
35 using namespace com::sun::star::uno
;
36 using namespace com::sun::star::accessibility
;
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
49 HRESULT STDMETHODCALLTYPE
CEnumVariant::Next(ULONG cElements
,VARIANT __RPC_FAR
*pvar
,ULONG __RPC_FAR
*pcElementFetched
)
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(),
73 static_cast<IMAccessible
*>(pChild
)->Get_XAccChildID(&pvar
[l2
].lVal
);
77 if(CMAccessible::g_pAgent
)
78 CMAccessible::g_pAgent
->InsertAccObj(pRXAcc
.get(),pUNOInterface
);
79 isGet
= CMAccessible::get_IAccessibleFromXAccessible(
80 pRXAcc
.get(), &pChild
);
84 static_cast<IMAccessible
*>(pChild
)->Get_XAccChildID(&pvar
[l2
].lVal
);
88 // Set count of elements retrieved.
89 if (pcElementFetched
!= nullptr)
90 *pcElementFetched
= l2
;
93 return (l2
< cElements
) ? S_FALSE
: NOERROR
;
97 * skip the elements in the given range when enumerate elements
98 * @param cElements The number of elements to skip.
101 HRESULT STDMETHODCALLTYPE
CEnumVariant::Skip(ULONG cElements
)
105 m_lCurrent
+= cElements
;
106 if (m_lCurrent
> static_cast<long>(m_lLBound
+m_pXAccessibleSelection
->getSelectedAccessibleChildCount()))
108 m_lCurrent
= m_lLBound
+m_pXAccessibleSelection
->getSelectedAccessibleChildCount();
117 * reset the enumaration position to initial value
121 HRESULT STDMETHODCALLTYPE
CEnumVariant::Reset()
125 m_lCurrent
= m_lLBound
;
131 *create a new IEnumVariant object,
132 *copy current enumaration container and its state to
134 *AT will use the copy object to get elements
135 * @param ppenum On return, pointer to the location of the clone enumerator
138 HRESULT STDMETHODCALLTYPE
CEnumVariant::Clone(IEnumVARIANT __RPC_FAR
*__RPC_FAR
*ppenum
)
142 CEnumVariant
* penum
= nullptr;
144 if (ppenum
== nullptr)
152 penum
->PutSelection(reinterpret_cast<hyper
>(pUNOInterface
));
164 *Static public method to create a CLSID_EnumVariant com object.
165 * @param ppenum Pointer to accept com object.
168 HRESULT STDMETHODCALLTYPE
CEnumVariant::Create(CEnumVariant __RPC_FAR
*__RPC_FAR
*ppenum
)
172 HRESULT hr
= createInstance
<CEnumVariant
>(IID_IEnumVariant
, ppenum
);
182 *Return count of elements in current container
184 * @return count of elements in current container.
186 long CEnumVariant::GetCountOfElements()
188 if(m_pXAccessibleSelection
.is())
189 return m_pXAccessibleSelection
->getSelectedAccessibleChildCount();
194 * Set member m_pXAccessibleSelection to NULL and m_lCurrent to m_lLBound.
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
;
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)
218 Reference
< XAccessibleContext
> pRContext
= pXAcc
->getAccessibleContext();
219 if( !pRContext
.is() )
222 Reference
< XAccessibleSelection
> pRSelection(pRContext
,UNO_QUERY
);
223 if( !pRSelection
.is() )
230 * Put valid UNO XAccessible interface.
231 * @param pXSelection XAccessible interface.
234 STDMETHODIMP
CEnumVariant::PutSelection(hyper pXSelection
)
236 // internal IEnumVariant - no mutex meeded
238 pUNOInterface
= reinterpret_cast<XAccessible
*>(pXSelection
);
239 m_pXAccessibleSelection
= GetXAccessibleSelection(pUNOInterface
);
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */