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