xref: /AOO41X/main/winaccessibility/source/UAccCOM/EnumVariant.cpp (revision 3a700b0a41696060114082e659787022c6e2013f)
1*3a700b0aSSteve Yin /**************************************************************
25fdc4257SSteve Yin  *
3*3a700b0aSSteve Yin  * Licensed to the Apache Software Foundation (ASF) under one
4*3a700b0aSSteve Yin  * or more contributor license agreements.  See the NOTICE file
5*3a700b0aSSteve Yin  * distributed with this work for additional information
6*3a700b0aSSteve Yin  * regarding copyright ownership.  The ASF licenses this file
7*3a700b0aSSteve Yin  * to you under the Apache License, Version 2.0 (the
8*3a700b0aSSteve Yin  * "License"); you may not use this file except in compliance
9*3a700b0aSSteve Yin  * with the License.  You may obtain a copy of the License at
105fdc4257SSteve Yin  *
11*3a700b0aSSteve Yin  *   http://www.apache.org/licenses/LICENSE-2.0
125fdc4257SSteve Yin  *
13*3a700b0aSSteve Yin  * Unless required by applicable law or agreed to in writing,
14*3a700b0aSSteve Yin  * software distributed under the License is distributed on an
15*3a700b0aSSteve Yin  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a700b0aSSteve Yin  * KIND, either express or implied.  See the License for the
17*3a700b0aSSteve Yin  * specific language governing permissions and limitations
18*3a700b0aSSteve Yin  * under the License.
195fdc4257SSteve Yin  *
20*3a700b0aSSteve Yin  *************************************************************/
215fdc4257SSteve Yin 
225fdc4257SSteve Yin #include "stdafx.h"
235fdc4257SSteve Yin #include "UAccCOM2.h"
245fdc4257SSteve Yin #include "EnumVariant.h"
255fdc4257SSteve Yin #include "MAccessible.h"
26*3a700b0aSSteve Yin 
27*3a700b0aSSteve Yin 
285fdc4257SSteve Yin /////////////////////////////////////////////////////////////////////////////
295fdc4257SSteve Yin // CEnumVariant
305fdc4257SSteve Yin 
315fdc4257SSteve Yin 
325fdc4257SSteve Yin 
335fdc4257SSteve Yin /**
345fdc4257SSteve Yin    * enumarate method,get next element
355fdc4257SSteve Yin    * @param  cElements The number of elements to be returned.
365fdc4257SSteve Yin    * @param  pvar      An array of at least size celt in which the elements are to be returned.
375fdc4257SSteve Yin    * @param  pcElementFetched Pointer to the number of elements returned in rgVar, or Null��
385fdc4257SSteve Yin    * @return Result.
395fdc4257SSteve Yin    */
405fdc4257SSteve Yin HRESULT STDMETHODCALLTYPE CEnumVariant::Next(ULONG cElements,VARIANT __RPC_FAR *pvar,ULONG __RPC_FAR *pcElementFetched)
415fdc4257SSteve Yin {
425fdc4257SSteve Yin     long l1;
435fdc4257SSteve Yin     ULONG l2;
445fdc4257SSteve Yin 
455fdc4257SSteve Yin     if (pvar == NULL)
465fdc4257SSteve Yin         return E_INVALIDARG;
475fdc4257SSteve Yin 
485fdc4257SSteve Yin 	CHECK_ENABLE_INF
495fdc4257SSteve Yin     if (pcElementFetched != NULL)
505fdc4257SSteve Yin         *pcElementFetched = 0;
515fdc4257SSteve Yin 
525fdc4257SSteve Yin     // Retrieve the next cElements.
535fdc4257SSteve Yin     for (l1=m_lCurrent, l2=0; l1<m_pXAccessibleSelection->getSelectedAccessibleChildCount() &&
545fdc4257SSteve Yin             l2<cElements; l1++, l2++)
555fdc4257SSteve Yin     {
565fdc4257SSteve Yin         Reference< XAccessible > pRXAcc = m_pXAccessibleSelection->getSelectedAccessibleChild(l1);
575fdc4257SSteve Yin         IAccessible* pChild = NULL;
585fdc4257SSteve Yin         BOOL isGet = CMAccessible::get_IAccessibleFromXAccessible((long)pRXAcc.get(),&pChild);
595fdc4257SSteve Yin         if(isGet)
605fdc4257SSteve Yin         {
615fdc4257SSteve Yin             pvar[l2].vt = VT_I4;
625fdc4257SSteve Yin             ((IMAccessible*)pChild)->Get_XAccChildID(&pvar[l2].lVal);
635fdc4257SSteve Yin         }
645fdc4257SSteve Yin         else if(pRXAcc.is())
655fdc4257SSteve Yin         {
665fdc4257SSteve Yin             if(CMAccessible::g_pAgent)
675fdc4257SSteve Yin                 CMAccessible::g_pAgent->InsertAccObj(pRXAcc.get(),pUNOInterface,NULL);
685fdc4257SSteve Yin             BOOL isGet = CMAccessible::get_IAccessibleFromXAccessible((long)pRXAcc.get(),&pChild);
695fdc4257SSteve Yin             if(isGet)
705fdc4257SSteve Yin             {
715fdc4257SSteve Yin                 pvar[l2].vt = VT_I4;
725fdc4257SSteve Yin                 ((IMAccessible*)pChild)->Get_XAccChildID(&pvar[l2].lVal);
735fdc4257SSteve Yin             }
745fdc4257SSteve Yin         }
755fdc4257SSteve Yin     }
765fdc4257SSteve Yin     // Set count of elements retrieved.
775fdc4257SSteve Yin     if (pcElementFetched != NULL)
785fdc4257SSteve Yin         *pcElementFetched = l2;
795fdc4257SSteve Yin     m_lCurrent = l1;
805fdc4257SSteve Yin 
815fdc4257SSteve Yin     return (l2 < cElements) ? S_FALSE : NOERROR;
825fdc4257SSteve Yin }
835fdc4257SSteve Yin 
845fdc4257SSteve Yin /**
855fdc4257SSteve Yin    * skip the elements in the given range when enumarate elements
865fdc4257SSteve Yin    * @param  cElements The number of elements to skip.
875fdc4257SSteve Yin    * @return Result.
885fdc4257SSteve Yin    */
895fdc4257SSteve Yin HRESULT STDMETHODCALLTYPE CEnumVariant::Skip(ULONG cElements)
905fdc4257SSteve Yin {
915fdc4257SSteve Yin 	CHECK_ENABLE_INF
925fdc4257SSteve Yin     m_lCurrent += cElements;
935fdc4257SSteve Yin     if (m_lCurrent > (long)(m_lLBound+m_pXAccessibleSelection->getSelectedAccessibleChildCount()))
945fdc4257SSteve Yin     {
955fdc4257SSteve Yin         m_lCurrent =  m_lLBound+m_pXAccessibleSelection->getSelectedAccessibleChildCount();
965fdc4257SSteve Yin         return E_FAIL;
975fdc4257SSteve Yin     }
985fdc4257SSteve Yin     else
995fdc4257SSteve Yin         return NOERROR;
1005fdc4257SSteve Yin }
1015fdc4257SSteve Yin 
1025fdc4257SSteve Yin 
1035fdc4257SSteve Yin /**
1045fdc4257SSteve Yin    * reset the enumaration position to initial value
1055fdc4257SSteve Yin    * @param
1065fdc4257SSteve Yin    * @return Result.
1075fdc4257SSteve Yin    */
1085fdc4257SSteve Yin HRESULT STDMETHODCALLTYPE CEnumVariant::Reset( void)
1095fdc4257SSteve Yin {
1105fdc4257SSteve Yin     m_lCurrent = m_lLBound;
1115fdc4257SSteve Yin     return NOERROR;
1125fdc4257SSteve Yin }
1135fdc4257SSteve Yin 
1145fdc4257SSteve Yin 
1155fdc4257SSteve Yin /**
1165fdc4257SSteve Yin    *create a new IEnumVariant object,
1175fdc4257SSteve Yin    *copy current enumaration container and its state to
1185fdc4257SSteve Yin    *the new object
1195fdc4257SSteve Yin    *AT will use the copy object to get elements
1205fdc4257SSteve Yin    * @param ppenum On return, pointer to the location of the clone enumerator��
1215fdc4257SSteve Yin    * @return Result.
1225fdc4257SSteve Yin    */
1235fdc4257SSteve Yin HRESULT STDMETHODCALLTYPE CEnumVariant::Clone(IEnumVARIANT __RPC_FAR *__RPC_FAR *ppenum)
1245fdc4257SSteve Yin {
1255fdc4257SSteve Yin     CEnumVariant * penum = NULL;
1265fdc4257SSteve Yin     HRESULT hr;
1275fdc4257SSteve Yin     if (ppenum == NULL)
1285fdc4257SSteve Yin         return E_INVALIDARG;
1295fdc4257SSteve Yin 
1305fdc4257SSteve Yin     *ppenum = NULL;
1315fdc4257SSteve Yin 
1325fdc4257SSteve Yin     hr = Create(&penum);
1335fdc4257SSteve Yin     if( hr == S_OK )
1345fdc4257SSteve Yin     {
1355fdc4257SSteve Yin         penum->PutSelection((long)pUNOInterface);
1365fdc4257SSteve Yin         *ppenum = penum;
1375fdc4257SSteve Yin     }
1385fdc4257SSteve Yin     else
1395fdc4257SSteve Yin     {
1405fdc4257SSteve Yin         if (penum)
1415fdc4257SSteve Yin             penum->Release();
1425fdc4257SSteve Yin     }
1435fdc4257SSteve Yin     return hr;
1445fdc4257SSteve Yin }
1455fdc4257SSteve Yin 
1465fdc4257SSteve Yin /**
1475fdc4257SSteve Yin    *Static public method to create a CLSID_EnumVariant com object.
1485fdc4257SSteve Yin    * @param ppenum Pointer to accept com object.
1495fdc4257SSteve Yin    * @return Result.
1505fdc4257SSteve Yin    */
1515fdc4257SSteve Yin HRESULT STDMETHODCALLTYPE CEnumVariant::Create(CEnumVariant __RPC_FAR *__RPC_FAR *ppenum)
1525fdc4257SSteve Yin {
153*3a700b0aSSteve Yin 	HRESULT hr = CoCreateInstance(CLSID_EnumVariant,NULL,
154*3a700b0aSSteve Yin                                  CLSCTX_SERVER,IID_IEnumVariant,(void **)ppenum);
155*3a700b0aSSteve Yin 	if (S_OK != hr)
1565fdc4257SSteve Yin     {
1575fdc4257SSteve Yin         return E_FAIL;
1585fdc4257SSteve Yin     }
1595fdc4257SSteve Yin 
1605fdc4257SSteve Yin     return S_OK;
1615fdc4257SSteve Yin }
1625fdc4257SSteve Yin 
1635fdc4257SSteve Yin /**
1645fdc4257SSteve Yin    *Return count of elements in current container
1655fdc4257SSteve Yin    * @param.
1665fdc4257SSteve Yin    * @return count of elements in current container.
1675fdc4257SSteve Yin    */
1685fdc4257SSteve Yin long CEnumVariant::GetCountOfElements()
1695fdc4257SSteve Yin {
1705fdc4257SSteve Yin 	CHECK_ENABLE_INF_ZERO
1715fdc4257SSteve Yin 
1725fdc4257SSteve Yin     if(m_pXAccessibleSelection.is())
1735fdc4257SSteve Yin         return m_pXAccessibleSelection->getSelectedAccessibleChildCount();
1745fdc4257SSteve Yin     return 0;
1755fdc4257SSteve Yin }
1765fdc4257SSteve Yin 
1775fdc4257SSteve Yin /**
1785fdc4257SSteve Yin    * Set memeber m_pXAccessibleSelection to NULL and m_lCurrent to m_lLBound.
1795fdc4257SSteve Yin    * @param.
1805fdc4257SSteve Yin    * @return Result
1815fdc4257SSteve Yin    */
1825fdc4257SSteve Yin STDMETHODIMP CEnumVariant::ClearEnumeration()
1835fdc4257SSteve Yin {
1845fdc4257SSteve Yin     pUNOInterface = NULL;
1855fdc4257SSteve Yin     m_pXAccessibleSelection = NULL;
1865fdc4257SSteve Yin     m_lCurrent = m_lLBound;
1875fdc4257SSteve Yin     return S_OK;
1885fdc4257SSteve Yin }
1895fdc4257SSteve Yin 
1905fdc4257SSteve Yin /**
1915fdc4257SSteve Yin    *Static method to fetch XAccessibleSelection
1925fdc4257SSteve Yin    * @param pXAcc XAccessible interface.
1935fdc4257SSteve Yin    * @return XAccessibleSelection interface.
1945fdc4257SSteve Yin    */
1955fdc4257SSteve Yin static Reference<XAccessibleSelection> GetXAccessibleSelection(XAccessible* pXAcc)
1965fdc4257SSteve Yin {
1975fdc4257SSteve Yin     XAccessibleSelection* pSelection = NULL;
1985fdc4257SSteve Yin     Reference< XAccessibleContext > pRContext;
1995fdc4257SSteve Yin 
2005fdc4257SSteve Yin     if( pXAcc == NULL)
2015fdc4257SSteve Yin         return NULL;
2025fdc4257SSteve Yin 
2035fdc4257SSteve Yin     pRContext = pXAcc->getAccessibleContext();
2045fdc4257SSteve Yin     if( !pRContext.is() )
2055fdc4257SSteve Yin         return NULL;
2065fdc4257SSteve Yin 
2075fdc4257SSteve Yin     Reference< XAccessibleSelection > pRSelection(pRContext,UNO_QUERY);
2085fdc4257SSteve Yin     if( !pRSelection.is() )
2095fdc4257SSteve Yin         return NULL;
2105fdc4257SSteve Yin 
2115fdc4257SSteve Yin     return pRSelection;
2125fdc4257SSteve Yin }
2135fdc4257SSteve Yin 
2145fdc4257SSteve Yin /**
2155fdc4257SSteve Yin    * Put valid UNO XAccessible interface.
2165fdc4257SSteve Yin    * @param pXSelection XAccessible interface.
2175fdc4257SSteve Yin    * @return Result..
2185fdc4257SSteve Yin    */
2195fdc4257SSteve Yin STDMETHODIMP CEnumVariant::PutSelection(long pXSelection)
2205fdc4257SSteve Yin {
2215fdc4257SSteve Yin     pUNOInterface = (XAccessible*)pXSelection;
2225fdc4257SSteve Yin     m_pXAccessibleSelection = GetXAccessibleSelection(pUNOInterface);
2235fdc4257SSteve Yin     return S_OK;
2245fdc4257SSteve Yin }
225