static CComPtr<IAccessible> FindMoreButton( IAccessible *pAcc ) { CComVariant state; CComVariant self(CHILDID_SELF); pAcc->get_accState(self,&state); if (!(state.intVal&(STATE_SYSTEM_UNAVAILABLE|STATE_SYSTEM_INVISIBLE))) { CComVariant role; pAcc->get_accRole(self,&role); if (role.intVal==ROLE_SYSTEM_PUSHBUTTON) { CComBSTR name; if (SUCCEEDED(pAcc->get_accName(self,&name)) && name && _wcsicmp(name,g_ButtonMore)==0) return pAcc; } } CComVariant children[30]; long count; AccessibleChildren(pAcc,0,_countof(children),children,&count); for (int i=0;i<count;i++) { if (children[i].vt==VT_DISPATCH) { CComQIPtr<IAccessible> pChild=children[i].pdispVal; if (pChild) { CComPtr<IAccessible> pRes=FindMoreButton(pChild); if (pRes) return pRes; } } } return NULL; }
HRESULT AccessibleObject::BuildChildren(std::vector<AccessibleChild>& children, IAccessible* acc, LPARAM param) { if (acc == nullptr) acc = acc_; if (acc == nullptr) return E_INVALIDARG; long child_count = 0; HRESULT hr = acc->get_accChildCount(&child_count); if (FAILED(hr)) return hr; if (child_count == 0) return S_FALSE; long obtained_count = 0; std::vector<VARIANT> var_array(child_count); hr = AccessibleChildren(acc, 0L, child_count, var_array.data(), &obtained_count); if (FAILED(hr)) return hr; children.resize(obtained_count); for (int i = 0; i < obtained_count; i++) { VARIANT var_child = var_array[i]; if (var_child.vt == VT_DISPATCH) { IDispatch* dispatch = var_child.pdispVal; IAccessible* child = nullptr; hr = dispatch->QueryInterface(IID_IAccessible, (void**)&child); if (hr == S_OK) { GetName(children.at(i).name, CHILDID_SELF, child); GetRole(children.at(i).role, CHILDID_SELF, child); GetValue(children.at(i).value, CHILDID_SELF, child); if (AllowChildTraverse(children.at(i), param)) BuildChildren(children.at(i).children, child, param); child->Release(); } dispatch->Release(); } else { GetName(children.at(i).name, var_child.lVal, acc); GetRole(children.at(i).role, var_child.lVal, acc); GetValue(children.at(i).value, var_child.lVal, acc); } } return S_OK; }
void CClassicCopyFile::EnumAccChildren( IAccessible *pAcc, CString *pLog ) { AddAccChild(pAcc,CComVariant(CHILDID_SELF),pLog); long count; pAcc->get_accChildCount(&count); CComVariant children[20]; AccessibleChildren(pAcc,0,count,children,&count); for (int i=0;i<count;i++) { if (children[i].vt==VT_DISPATCH) { CComQIPtr<IAccessible> pChild=children[i].pdispVal; if (pChild) EnumAccChildren(pChild,pLog); } else AddAccChild(pAcc,children[i],pLog); } }
void walk_tree(IAccessible *pAccessible, char **pColumnHeaderNames, long *pColumnHeadersCount) { HRESULT hr ; long childCount ; hr = pAccessible->get_accChildCount(&childCount) ; if (FAILED(hr) || childCount == 0) return ; VARIANT *pChildVariants = new VARIANT[childCount] ; long childrenFound ; hr = AccessibleChildren(pAccessible, 0, childCount, pChildVariants, &childrenFound) ; if (FAILED(hr)) return ; for (int i=1; i < childrenFound + 1; i++) { VARIANT vChild = pChildVariants[i] ; if (vChild.vt == VT_DISPATCH) { IDispatch *pDispatch = vChild.pdispVal ; IAccessible *pChildAccessible = NULL ; hr = pDispatch->QueryInterface(IID_IAccessible, (void**) &pChildAccessible) ; if (hr == S_OK) { walk_tree(pChildAccessible, pColumnHeaderNames, pColumnHeadersCount) ; pChildAccessible->Release() ; } pDispatch->Release() ; } else { long role ; get_role(i, pAccessible, &role) ; if (role == 0x19) { if (pColumnHeaderNames == NULL) { *pColumnHeadersCount = *pColumnHeadersCount + 1 ; } else { char *headerName = (char *)malloc(sizeof(char) * BUFFER_SIZE) ; get_name(i, pAccessible, headerName) ; pColumnHeaderNames[i - 1] = headerName ; } } } } }
static void test_AccessibleChildren(IAccessible *acc) { VARIANT children[3]; LONG count; HRESULT hr; count = -1; hr = AccessibleChildren(NULL, 0, 0, children, &count); ok(hr == E_INVALIDARG, "AccessibleChildren returned %x\n", hr); ok(count == -1, "count = %d\n", count); hr = AccessibleChildren(acc, 0, 0, NULL, &count); ok(hr == E_INVALIDARG, "AccessibleChildren returned %x\n", hr); ok(count == -1, "count = %d\n", count); hr = AccessibleChildren(acc, 0, 0, children, NULL); ok(hr == E_INVALIDARG, "AccessibleChildren returned %x\n", hr); if(acc == &Accessible) { SET_EXPECT(Accessible_QI_IEnumVARIANT); SET_EXPECT(Accessible_get_accChildCount); } hr = AccessibleChildren(acc, 0, 0, children, &count); ok(hr == S_OK, "AccessibleChildren returned %x\n", hr); if(acc == &Accessible) { CHECK_CALLED(Accessible_QI_IEnumVARIANT); CHECK_CALLED(Accessible_get_accChildCount); } ok(!count, "count = %d\n", count); count = -1; if(acc == &Accessible) { SET_EXPECT(Accessible_QI_IEnumVARIANT); SET_EXPECT(Accessible_get_accChildCount); } hr = AccessibleChildren(acc, 5, 0, children, &count); ok(hr == S_OK, "AccessibleChildren returned %x\n", hr); if(acc == &Accessible) { CHECK_CALLED(Accessible_QI_IEnumVARIANT); CHECK_CALLED(Accessible_get_accChildCount); } ok(!count, "count = %d\n", count); memset(children, 0xfe, sizeof(children)); V_VT(children) = VT_DISPATCH; if(acc == &Accessible) { SET_EXPECT(Accessible_QI_IEnumVARIANT); SET_EXPECT(Accessible_get_accChildCount); SET_EXPECT(Accessible_get_accChild); } hr = AccessibleChildren(acc, 0, 1, children, &count); ok(hr == S_OK, "AccessibleChildren returned %x\n", hr); if(acc == &Accessible) { CHECK_CALLED(Accessible_QI_IEnumVARIANT); CHECK_CALLED(Accessible_get_accChildCount); CHECK_CALLED(Accessible_get_accChild); ok(V_VT(children) == VT_I4, "V_VT(children) = %d\n", V_VT(children)); ok(V_I4(children) == 1, "V_I4(children) = %d\n", V_I4(children)); }else { ok(V_VT(children) == VT_DISPATCH, "V_VT(children) = %d\n", V_VT(children)); IDispatch_Release(V_DISPATCH(children)); } ok(count == 1, "count = %d\n", count); if(acc == &Accessible) { SET_EXPECT(Accessible_QI_IEnumVARIANT); SET_EXPECT(Accessible_get_accChildCount); SET_EXPECT(Accessible_get_accChild); } hr = AccessibleChildren(acc, 0, 3, children, &count); ok(hr == S_FALSE, "AccessibleChildren returned %x\n", hr); if(acc == &Accessible) { CHECK_CALLED(Accessible_QI_IEnumVARIANT); CHECK_CALLED(Accessible_get_accChildCount); CHECK_CALLED(Accessible_get_accChild); ok(V_VT(children) == VT_I4, "V_VT(children) = %d\n", V_VT(children)); ok(V_I4(children) == 1, "V_I4(children) = %d\n", V_I4(children)); }else { ok(V_VT(children) == VT_DISPATCH, "V_VT(children) = %d\n", V_VT(children)); IDispatch_Release(V_DISPATCH(children)); } ok(count == 1, "count = %d\n", count); ok(V_VT(children+1) == VT_EMPTY, "V_VT(children+1) = %d\n", V_VT(children+1)); ok(V_VT(children+2) == VT_EMPTY, "V_VT(children+2) = %d\n", V_VT(children+2)); }
static void DoWebAccessible(HWND w,IAccessible *pAccessible,T_SUIVI_ACCESSIBLE *ptSuivi) #endif { TRACE((TRACE_ENTER,_F_, "")); UNREFERENCED_PARAMETER(w); HRESULT hr; IAccessible *pChild=NULL; VARIANT vtChild; VARIANT vtState,vtRole; long l,lCount; long returnCount; VARIANT* pArray = NULL; #ifdef TRACES_ACTIVEES char szTab[200]; strcpy_s(szTab,sizeof(szTab),paramszTab); if (strlen(szTab)<sizeof(szTab)-5) strcat_s(szTab,sizeof(szTab)," "); #endif // si fini ou erreur, on termine la récursivité if (ptSuivi->iErreur!=0) goto end; // parcours de la suite : combien de fils ? hr=pAccessible->get_accChildCount(&lCount); if (FAILED(hr)) goto end; TRACE((TRACE_DEBUG,_F_,"%sget_accChildCount()==%ld",szTab,lCount)); // plus de fils ou lu assez de champs, on termine ! if (lCount==0) { TRACE((TRACE_INFO,_F_,"%sPas de fils",szTab)); goto end; } if (ptSuivi->iTextFieldIndex>MAX_TEXT_FIELDS) { TRACE((TRACE_INFO,_F_,"Trop de champs, on arrête la recherche dans la page (lCount=%d ptSuivi->iTextFieldIndex=%d)",lCount,ptSuivi->iTextFieldIndex)); goto end; } if (ptSuivi->iPwdIndex!=-1 && (ptSuivi->iTextFieldIndex - ptSuivi->iPwdIndex)>10) // optimisation : on ne lit pas plus de 10 champs après le mdp { TRACE((TRACE_INFO,_F_,"Fin de la recherche dans la page (ptSuivi->iTextFieldIndex=%d ptSuivi->iPwdIndex=%d)",ptSuivi->iTextFieldIndex,ptSuivi->iPwdIndex)); goto end; } pArray = new VARIANT[lCount]; hr = AccessibleChildren(pAccessible, 0L, lCount, pArray, &returnCount); if (FAILED(hr)) { TRACE((TRACE_DEBUG,_F_,"%sAccessibleChildren()=0x%08lx",szTab,hr)); } else { TRACE((TRACE_DEBUG,_F_,"%sAccessibleChildren() returnCount=%d",szTab,returnCount)); for (l=0;l<lCount;l++) { VARIANT *pVarCurrent = &pArray[l]; VariantInit(&vtRole); VariantInit(&vtState); pChild=NULL; TRACE((TRACE_DEBUG,_F_,"%s --------------------------------- l=%ld vt=%d lVal=0x%08lx",szTab,l,pVarCurrent->vt,pVarCurrent->lVal)); if (pVarCurrent->vt!=VT_DISPATCH) goto suivant; if (pVarCurrent->lVal==NULL) goto suivant; // ISSUE#80 0.96B2 ((IDispatch*)(pVarCurrent->lVal))->QueryInterface(IID_IAccessible, (void**) &pChild); if (FAILED(hr)) { TRACE((TRACE_ERROR,_F_,"%sQueryInterface(IID_IAccessible)=0x%08lx",szTab,hr)); goto suivant; } TRACE((TRACE_DEBUG,_F_,"%sQueryInterface(IID_IAccessible)=0x%08lx -> pChild=0x%08lx",szTab,hr,pChild)); vtChild.vt=VT_I4; vtChild.lVal=CHILDID_SELF; hr=pChild->get_accState(vtChild,&vtState); if (FAILED(hr)) { TRACE((TRACE_ERROR,_F_,"get_accState()=0x%08lx",hr)); goto suivant; } TRACE((TRACE_DEBUG,_F_,"%sget_accState() vtState.lVal=0x%08lx",szTab,vtState.lVal)); hr=pChild->get_accRole(vtChild,&vtRole); if (FAILED(hr)) { TRACE((TRACE_ERROR,_F_,"get_accRole()=0x%08lx",hr)); goto suivant; } TRACE((TRACE_DEBUG,_F_,"%sget_accRole() vtRole.lVal=0x%08lx",szTab,vtRole.lVal)); //hr=pChild->get_accName(vtChild,&bstrName); //if (FAILED(hr)) { TRACE((TRACE_ERROR,_F_,"get_accName()=0x%08lx",hr)); goto suivant; } //TRACE((TRACE_DEBUG,_F_,"%sget_accName() name=%S",szTab,bstrName)); // Reconnaissance du champ mot de passe : Nième champ ayant pour role et state les valeurs suivantes : // - Role = ROLE_SYSTEM_TEXT // - State = (STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED) & STATE_SYSTEM_PROTECTED // Reconnaissance du champ identifiant : Nième champ précédant le champ mot de passe et ayant pour role et state les valeurs suivantes : // - Role = ROLE_SYSTEM_TEXT // - State = (STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED) // ISSUE#279 : cas spécifique IE // TRACE((TRACE_DEBUG,_F_,"%sptSuivi->iBrowser=%d",szTab,ptSuivi->iBrowser)); if (ptSuivi->iBrowser!=BROWSER_IE) { if ((vtRole.lVal == ROLE_SYSTEM_TEXT) && ((vtState.lVal & STATE_SYSTEM_FOCUSED) || (vtState.lVal & STATE_SYSTEM_FOCUSABLE))) { // c'est un champ de saisie, s'il est protégé c'est le mdp sinon c'est un id if (vtState.lVal & STATE_SYSTEM_PROTECTED) { TRACE((TRACE_INFO,_F_,"Champ mot de passe trouve (ROLE_SYSTEM_TEXT + STATE_SYSTEM_FOCUS* + STATE_SYSTEM_PROTECTED)")); pChild->AddRef(); ptSuivi->pTextFields[ptSuivi->iTextFieldIndex]=pChild; ptSuivi->iNbPwdFound++; TRACE((TRACE_INFO,_F_,"Champ mot de passe trouve : c'est le %dieme, on attendait le %d",ptSuivi->iNbPwdFound,atoi(gptActions[ptSuivi->iAction].szPwdName))); if (ptSuivi->iNbPwdFound==atoi(gptActions[ptSuivi->iAction].szPwdName)) { ptSuivi->iPwdIndex=ptSuivi->iTextFieldIndex; } ptSuivi->iTextFieldIndex++; } else { TRACE((TRACE_INFO,_F_,"Un champ id trouve (ROLE_SYSTEM_TEXT + STATE_SYSTEM_FOCUS*)")); pChild->AddRef(); ptSuivi->pTextFields[ptSuivi->iTextFieldIndex]=pChild; ptSuivi->iTextFieldIndex++; } } else { #ifdef TRACES_ACTIVEES DoWebAccessible(szTab,NULL,pChild,ptSuivi); #else DoWebAccessible(NULL,pChild,ptSuivi); #endif } } else // ISSUE#279 : IE { if ((vtRole.lVal == ROLE_SYSTEM_TEXT) && !(vtState.lVal & STATE_SYSTEM_READONLY)) { // c'est un champ de saisie, s'il est protégé c'est le mdp sinon c'est un id if (vtState.lVal & STATE_SYSTEM_PROTECTED) { TRACE((TRACE_INFO,_F_,"Champ mot de passe trouve (ROLE_SYSTEM_TEXT + STATE_SYSTEM_FOCUS* + STATE_SYSTEM_PROTECTED)")); pChild->AddRef(); ptSuivi->pTextFields[ptSuivi->iTextFieldIndex]=pChild; ptSuivi->iNbPwdFound++; TRACE((TRACE_INFO,_F_,"Champ mot de passe trouve : c'est le %dieme, on attendait le %d",ptSuivi->iNbPwdFound,atoi(gptActions[ptSuivi->iAction].szPwdName))); if (ptSuivi->iNbPwdFound==atoi(gptActions[ptSuivi->iAction].szPwdName)) { ptSuivi->iPwdIndex=ptSuivi->iTextFieldIndex; } ptSuivi->iTextFieldIndex++; } else { TRACE((TRACE_INFO,_F_,"Un champ id trouve (ROLE_SYSTEM_TEXT + STATE_SYSTEM_FOCUS*)")); pChild->AddRef(); ptSuivi->pTextFields[ptSuivi->iTextFieldIndex]=pChild; ptSuivi->iTextFieldIndex++; } } else { #ifdef TRACES_ACTIVEES DoWebAccessible(szTab,NULL,pChild,ptSuivi); #else DoWebAccessible(NULL,pChild,ptSuivi); #endif } } suivant: if (pChild!=NULL) { pChild->Release(); pChild=NULL; } } } end: if (pArray!=NULL) delete[] pArray; TRACE((TRACE_LEAVE,_F_, "")); }
void CClassicCopyFile::GetFileInfo( IAccessible *pAcc, bool bSrc ) { long count; pAcc->get_accChildCount(&count); CComVariant children[20]; AccessibleChildren(pAcc,0,count,children,&count); wchar_t fname[_MAX_PATH]=L""; wchar_t dir[_MAX_PATH]=L""; CString size; CString date; // get the file name, directory, size and date for (int i=0;i<count;i++) { CComBSTR name; if (children[i].vt==VT_DISPATCH) { CComQIPtr<IAccessible> pChild=children[i].pdispVal; if (pChild) pChild->get_accName(CComVariant(CHILDID_SELF),&name); } else { pAcc->get_accName(children[i],&name); } switch (i) { case 2: if (wcslen(name)<_countof(fname)) wcscpy_s(fname,name); break; case 3: if (wcslen(name)<_countof(dir)) wcscpy_s(dir,name); break; case 4: size=name; break; case 5: date=name; break; } } if (bSrc) { m_FileName=fname; m_SrcSize=size; m_SrcTime=date; } else { m_DstSize=size; m_DstTime=date; } if (!fname[0] || !dir[0]) return; wchar_t fname2[_MAX_PATH]; memcpy(fname2,fname,sizeof(fname2)); *PathFindExtension(fname2)=0; int len1=Strlen(fname2); // the directory text is something like "filename (directory)". we need to parse out the real directory name int len2=Strlen(dir); if (dir[0]==0x202A) len1++; // for RTL languages the first character is some RTL marker. needs to be skipped if (len1+1>=len2 || dir[len1]!=L' ' || dir[len1+1]!=L'(' || dir[len2-1]!=L')') return; dir[len2-1]=0; // construct the full file name wchar_t path[_MAX_PATH]; _wmakepath_s(path,NULL,dir+len1+2,fname,NULL); if (!bSrc) { DWORD attrib=GetFileAttributes(path); if (attrib!=INVALID_FILE_ATTRIBUTES) { if (attrib&FILE_ATTRIBUTE_READONLY) m_bReadOnly=true; if (attrib&FILE_ATTRIBUTE_SYSTEM) m_bSystem=true; } } // get file icon HICON hIcon=NULL; PIDLIST_ABSOLUTE pidl=NULL; if (SUCCEEDED(SHParseDisplayName(path,NULL,&pidl,0,NULL)) && pidl) { int iconSize=GetSystemMetrics(SM_CXICON); HBITMAP hBitmap=NULL; CComPtr<IShellItemImageFactory> pFactory; if (SUCCEEDED(SHCreateItemFromIDList(pidl,IID_IShellItemImageFactory,(void**)&pFactory)) && pFactory) { SIZE size={iconSize,iconSize}; if (FAILED(pFactory->GetImage(size,SIIGBF_ICONONLY,&hBitmap))) hBitmap=NULL; } ILFree(pidl); if (hBitmap) { HBITMAP hMonoBitmap=CreateBitmap(iconSize,iconSize,1,1,NULL); ICONINFO info={TRUE,0,0,hMonoBitmap,hBitmap}; hIcon=CreateIconIndirect(&info); DeleteObject(hMonoBitmap); DeleteObject(hBitmap); } } if (!hIcon) return; if (bSrc) m_SrcIcon=hIcon; else m_DstIcon=hIcon; }
void MyFrame::OnQuery(wxCommandEvent& WXUNUSED(event)) { m_textCtrl->Clear(); IAccessible* accessibleFrame = NULL; if (S_OK != AccessibleObjectFromWindow((HWND) GetHWND(), OBJID_CLIENT, IID_IAccessible, (void**) & accessibleFrame)) { Log(wxT("Could not get object.")); return; } if (accessibleFrame) { //Log(wxT("Got an IAccessible for the frame.")); LogObject(0, accessibleFrame); Log(wxT("Checking children using AccessibleChildren()...")); // Now check the AccessibleChildren function works OK long childCount = 0; if (S_OK != accessibleFrame->get_accChildCount(& childCount)) { Log(wxT("Could not get number of children.")); accessibleFrame->Release(); return; } else if (childCount == 0) { Log(wxT("No children.")); accessibleFrame->Release(); return; } long obtained = 0; VARIANT *var = new VARIANT[childCount]; int i; for (i = 0; i < childCount; i++) { VariantInit(& (var[i])); var[i].vt = VT_DISPATCH; } if (S_OK == AccessibleChildren(accessibleFrame, 0, childCount, var, &obtained)) { for (i = 0; i < childCount; i++) { IAccessible* childAccessible = NULL; if (var[i].pdispVal) { if (var[i].pdispVal->QueryInterface(IID_IAccessible, (LPVOID*) & childAccessible) == S_OK) { var[i].pdispVal->Release(); wxString name, role; GetInfo(childAccessible, 0, name, role); wxString str; str.Printf(wxT("Found child %s/%s"), name.c_str(), role.c_str()); Log(str); childAccessible->Release(); } else { var[i].pdispVal->Release(); } } } } else { Log(wxT("AccessibleChildren failed.")); } delete[] var; accessibleFrame->Release(); } }