⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 access.cpp

📁 Wxpython Implemented on Windows CE, Source code
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        else
        {
            wxIAccessible* childIA = childObject->GetIAccessible();
            if (!childIA)
                return E_NOTIMPL;

            if (childIA->QueryInterface(IID_IDispatch, (LPVOID*) & pVarID->pdispVal) != S_OK)
                return E_FAIL;

            pVarID->vt = VT_DISPATCH;
            return S_OK;
        }
    }
    else if (childId > 0)
    {
        pVarID->vt = VT_I4;
        pVarID->lVal = childId;
        return S_OK;
    }
    else
    {
        pVarID->vt = VT_EMPTY;
        return S_FALSE;
    }

    #if 0
    // all cases above already cause some return action so below line
    // is unreachable and cause unnecessary warning
    return E_NOTIMPL;
    #endif
}

// Retrieves the specified object's current screen location. All visual objects must
// support this method; sound objects do not support it.

STDMETHODIMP wxIAccessible::accLocation ( long* pxLeft, long* pyTop, long* pcxWidth, long* pcyHeight, VARIANT varID)
{
    wxLogTrace(wxT("access"), wxT("accLocation"));
    wxASSERT (m_pAccessible != NULL);
    if (!m_pAccessible)
        return E_FAIL;

    wxRect rect;

    wxAccStatus status = m_pAccessible->GetLocation(rect, varID.lVal);
    if (status == wxACC_FAIL)
        return E_FAIL;

    if (status == wxACC_NOT_IMPLEMENTED)
    {
        // Try to use child object directly.
        if (varID.lVal > 0)
        {
            IAccessible* childAccessible = GetChildAccessible(varID.lVal);
            if (childAccessible)
            {
                varID.lVal = 0;
                HRESULT hResult = childAccessible->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varID);
                childAccessible->Release();
                return hResult;
            }
            else if (m_pAccessible->GetIAccessibleStd())
                return ((IAccessible*) m_pAccessible->GetIAccessibleStd())->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varID);
        }
        else if (m_pAccessible->GetIAccessibleStd())
            return ((IAccessible*) m_pAccessible->GetIAccessibleStd())->accLocation(pxLeft, pyTop, pcxWidth, pcyHeight, varID);
    }
    else
    {
        *pxLeft = rect.x;
        *pyTop = rect.y;
        *pcxWidth = rect.width;
        *pcyHeight = rect.height;
        return S_OK;
    }

    return E_NOTIMPL;
}

// Traverses to another user interface element within a container and retrieves the object.
// All visual objects must support this method.

STDMETHODIMP wxIAccessible::accNavigate ( long navDir, VARIANT varStart, VARIANT* pVarEnd)
{
    wxASSERT (m_pAccessible != NULL);
    if (!m_pAccessible)
        return E_FAIL;
    wxLogTrace(wxT("access"), wxString(wxT("accNavigate for ")) + m_pAccessible->GetWindow()->GetClassInfo()->GetClassName());

    if ((varStart.vt != VT_I4 && varStart.vt != VT_EMPTY)
                                                          #if 0
                                                          // according to MSDN and sources varStart.vt is unsigned
                                                          // so below line cause warning "Condition is always false"
                                                          || varStart.vt < 0
                                                          #endif
                                                          )
    {
        wxLogTrace(wxT("access"), wxT("Invalid arg for accNavigate"));
        return E_INVALIDARG;
    }

    wxAccessible* elementObject = NULL;
    int elementId = 0;
    VariantInit(pVarEnd);
    wxNavDir navDirWX = wxNAVDIR_FIRSTCHILD;

    wxString navStr;

    switch (navDir)
    {
    case NAVDIR_DOWN:
        navDirWX = wxNAVDIR_DOWN;
        navStr = wxT("wxNAVDIR_DOWN");
        break;

    case NAVDIR_FIRSTCHILD:
        navDirWX = wxNAVDIR_FIRSTCHILD;
        navStr = wxT("wxNAVDIR_FIRSTCHILD");
        break;

    case NAVDIR_LASTCHILD:
        navDirWX = wxNAVDIR_LASTCHILD;
        navStr = wxT("wxNAVDIR_LASTCHILD");
        break;

    case NAVDIR_LEFT:
        navDirWX = wxNAVDIR_LEFT;
        navStr = wxT("wxNAVDIR_LEFT");
        break;

    case NAVDIR_NEXT:
        navDirWX = wxNAVDIR_NEXT;
        navStr = wxT("wxNAVDIR_NEXT");
        break;

    case NAVDIR_PREVIOUS:
        navDirWX = wxNAVDIR_PREVIOUS;
        navStr = wxT("wxNAVDIR_PREVIOUS");
        break;

    case NAVDIR_RIGHT:
        navDirWX = wxNAVDIR_RIGHT;
        navStr = wxT("wxNAVDIR_RIGHT");
        break;

    case NAVDIR_UP:
        navDirWX = wxNAVDIR_UP;
        navStr = wxT("wxNAVDIR_UP");
        break;
    default:
        {
            wxLogTrace(wxT("access"), wxT("Unknown NAVDIR symbol"));
            break;
        }
    }
    wxLogTrace(wxT("access"), navStr);

    wxAccStatus status = m_pAccessible->Navigate(navDirWX, varStart.lVal, & elementId,
        & elementObject);

    if (status == wxACC_FAIL)
    {
        wxLogTrace(wxT("access"), wxT("wxAccessible::Navigate failed"));
        return E_FAIL;
    }

    if (status == wxACC_FALSE)
    {
        wxLogTrace(wxT("access"), wxT("wxAccessible::Navigate found no object in this direction"));
        return S_FALSE;
    }

    if (status == wxACC_NOT_IMPLEMENTED)
    {
        wxLogTrace(wxT("access"), wxT("Navigate not implemented"));

        // Try to use child object directly.
        if (varStart.vt == VT_I4 && varStart.lVal > 0)
        {
            IAccessible* childAccessible = GetChildAccessible(varStart.lVal);
            if (childAccessible)
            {
                varStart.lVal = 0;
                HRESULT hResult = childAccessible->accNavigate(navDir, varStart, pVarEnd);
                childAccessible->Release();
                return hResult;
            }
            else if (m_pAccessible->GetIAccessibleStd())
                return ((IAccessible*) m_pAccessible->GetIAccessibleStd())->accNavigate(navDir, varStart, pVarEnd);
        }
        else if (m_pAccessible->GetIAccessibleStd())
            return ((IAccessible*) m_pAccessible->GetIAccessibleStd())->accNavigate(navDir, varStart, pVarEnd);
    }
    else
    {
        if (elementObject)
        {
            wxLogTrace(wxT("access"), wxT("Getting wxIAccessible and calling QueryInterface for Navigate"));
            wxIAccessible* objectIA = elementObject->GetIAccessible();
            if (!objectIA)
            {
                wxLogTrace(wxT("access"), wxT("No wxIAccessible"));
                return E_FAIL;
            }

            HRESULT hResult = objectIA->QueryInterface(IID_IDispatch, (LPVOID*) & pVarEnd->pdispVal);
            if (hResult != S_OK)
            {
                wxLogTrace(wxT("access"), wxT("QueryInterface failed"));
                return E_FAIL;
            }

            wxLogTrace(wxT("access"), wxT("Called QueryInterface for Navigate"));
            pVarEnd->vt = VT_DISPATCH;
            return S_OK;
        }
        else if (elementId > 0)
        {
            wxLogTrace(wxT("access"), wxT("Returning element id from Navigate"));
            pVarEnd->vt = VT_I4;
            pVarEnd->lVal = elementId;
            return S_OK;
        }
        else
        {
            wxLogTrace(wxT("access"), wxT("No object in accNavigate"));
            pVarEnd->vt = VT_EMPTY;
            return S_FALSE;
        }
    }

    wxLogTrace(wxT("access"), wxT("Failing Navigate"));
    return E_NOTIMPL;
}

// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.

STDMETHODIMP wxIAccessible::get_accChild ( VARIANT varChildID, IDispatch** ppDispChild)
{
    wxLogTrace(wxT("access"), wxT("get_accChild"));
    wxASSERT (m_pAccessible != NULL);
    if (!m_pAccessible)
        return E_FAIL;

    if (varChildID.vt != VT_I4)
    {
        wxLogTrace(wxT("access"), wxT("Invalid arg for get_accChild"));
        return E_INVALIDARG;
    }

    if (varChildID.lVal == CHILDID_SELF)
    {
        *ppDispChild = this;
        AddRef();
        return S_OK;
    }

    wxAccessible* child = NULL;

    wxAccStatus status = m_pAccessible->GetChild(varChildID.lVal, & child);
    if (status == wxACC_FAIL)
    {
        wxLogTrace(wxT("access"), wxT("GetChild failed"));
        return E_FAIL;
    }

    if (status == wxACC_NOT_IMPLEMENTED)
    {
        // Use standard interface instead.
        IAccessible* stdInterface = (IAccessible*)m_pAccessible->GetIAccessibleStd();
        if (!stdInterface)
            return E_NOTIMPL;
        else
        {
            wxLogTrace(wxT("access"), wxT("Using standard interface for get_accChild"));
            return stdInterface->get_accChild (varChildID, ppDispChild);
        }
    }
    else
    {
        if (child)
        {
            wxIAccessible* objectIA = child->GetIAccessible();
            if (!objectIA)
                return E_NOTIMPL;

            if (objectIA->QueryInterface(IID_IDispatch, (LPVOID*) ppDispChild) != S_OK)
            {
                wxLogTrace(wxT("access"), wxT("QueryInterface failed in get_accChild"));
                return E_FAIL;
            }

            return S_OK;
        }
        else
        {
            wxLogTrace(wxT("access"), wxT("Not an accessible object"));
            return S_FALSE; // Indicates it's not an accessible object
        }
    }

    #if 0
    // all cases above already cause some return action so below line
    // is unreachable and cause unnecessary warning
    return E_NOTIMPL;
    #endif
}

// Retrieves the number of children that belong to this object.
// All objects must support this property.

STDMETHODIMP wxIAccessible::get_accChildCount ( long* pCountChildren)
{
    wxLogTrace(wxT("access"), wxT("get_accChildCount"));
    wxASSERT (m_pAccessible != NULL);
    if (!m_pAccessible)
        return E_FAIL;

    int childCount = 0;
    wxAccStatus status = m_pAccessible->GetChildCount(& childCount);
    if (status == wxACC_FAIL)
        return E_FAIL;

    if (status == wxACC_NOT_IMPLEMENTED)
    {
        // Use standard interface instead.
        IAccessible* stdInterface = (IAccessible*)m_pAccessible->GetIAccessibleStd();
        if (!stdInterface)
            return E_NOTIMPL;
        else
        {
            wxLogTrace(wxT("access"), wxT("Using standard interface for get_accChildCount"));
            HRESULT res = stdInterface->get_accChildCount (pCountChildren);
            wxString str;
            str.Printf(wxT("Number of children was %d"), (int) (*pCountChildren));
            wxLogTrace(wxT("access"), str);
            return res;
        }
    }
    else
    {
        * pCountChildren = (long) childCount;
        return S_OK;
    }

    #if 0
    // all cases above already cause some return action so below line
    // is unreachable and cause unnecessary warning
    return E_NOTIMPL;
    #endif
}

// Retrieves the IDispatch interface of the object's parent.
// All objects support this property.

STDMETHODIMP wxIAccessible::get_accParent ( IDispatch** ppDispParent)
{
    wxLogTrace(wxT("access"), wxT("get_accParent"));
    wxASSERT (m_pAccessible != NULL);
    if (!m_pAccessible)
        return E_FAIL;

    wxAccessible* parent = NULL;
    wxAccStatus status = m_pAccessible->GetParent(& parent);

    if (status == wxACC_FAIL)
        return E_FAIL;

    // It doesn't seem acceptable to return S_FALSE with a NULL
    // ppDispParent, so if we have no wxWidgets parent, we leave
    // it to the standard interface.
    if (status == wxACC_NOT_IMPLEMENTED || !parent)
    {
        wxLogTrace(wxT("access"), wxT("Using standard interface to get the parent."));
        // Use standard interface instead.
        IAccessible* stdInterface = (IAccessible*)m_pAccessible->GetIAccessibleStd();
        if (!stdInterface)
            return E_NOTIMPL;
        else
            return stdInterface->get_accParent (ppDispParent);
    }
    else
    {
        if (parent)
        {
            wxIAccessible* objectIA = parent->GetIAccessible();
            if (!objectIA)
                return E_FAIL;

            wxLogTrace(wxT("access"), wxT("About to call QueryInterface"));
            if (objectIA->QueryInterface(IID_IDispatch, (LPVOID*) ppDispParent) != S_OK)
            {
                wxLogTrace(wxT("access"), wxT("Failed QueryInterface"));
                return E_FAIL;
            }

            wxLogTrace(wxT("access"), wxT("Returning S_OK for get_accParent"));
            return S_OK;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -