void CVocabAutoCompleteDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);

    if (!_fInited)
    {
        _fInited = true;

        ShowSizeGrip(FALSE);
        DDX_Control(pDX, IDC_WORD, m_wndEditWord);
        m_wndEditWord.SetWindowText(_strWord);

        DDX_Control(pDX, IDC_EDITAC, m_wndEdit);
        HWND hwndEdit = m_wndEdit.GetSafeHwnd();

        if (SUCCEEDED(_hrCoCreate))
        {
            IAutoComplete *pac;
            if (SUCCEEDED(CoCreateInstance(CLSID_AutoComplete, NULL, CLSCTX_INPROC_SERVER, IID_IAutoComplete, (void**)&pac)))
            {
                IUnknown *pSource;
                if (SUCCEEDED(CWordEnumString_CreateInstance(IID_IUnknown, (void**)&pSource)))
                {
                    if (SUCCEEDED(pac->Init(hwndEdit, pSource, NULL, NULL)))
                    {
                        IAutoComplete2 *pAC2;
                        if (SUCCEEDED(pac->QueryInterface(IID_IAutoComplete2, (void**)&pAC2)))
                        {
                            if (appState->_fUseAutoSuggest)
                            {
                                pAC2->SetOptions(ACO_AUTOSUGGEST);
                            }
                            pAC2->Release();
                        }
                    }
                    pSource->Release();
                }
                pac->Release();
            }
        }

        // Visuals
        DDX_Control(pDX, IDOK, m_wndOk);
        DDX_Control(pDX, IDCANCEL, m_wndCancel);
        DDX_Control(pDX, IDC_STATIC1, m_wndStatic1);
        DDX_Control(pDX, IDC_STATIC2, m_wndStatic2);
    }
}
Example #2
0
HRESULT CCommonAppUtils::EnableAutoComplete(HWND hWndEdit, LPWSTR szCurrentWorkingDirectory, AUTOCOMPLETELISTOPTIONS acloOptions, AUTOCOMPLETEOPTIONS acoOptions, REFCLSID clsid)
{
    IAutoComplete *pac;
    HRESULT hr = CoCreateInstance(CLSID_AutoComplete,
                                  NULL,
                                  CLSCTX_INPROC_SERVER,
                                  IID_PPV_ARGS(&pac));
    if (FAILED(hr))
    {
        return hr;
    }

    IUnknown *punkSource;
    hr = CoCreateInstance(clsid,
                          NULL,
                          CLSCTX_INPROC_SERVER,
                          IID_PPV_ARGS(&punkSource));
    if (FAILED(hr))
    {
        pac->Release();
        return hr;
    }

    if ((acloOptions != ACLO_NONE) || (szCurrentWorkingDirectory != NULL))
    {
        IACList2 *pal2;
        hr = punkSource->QueryInterface(IID_PPV_ARGS(&pal2));
        if (SUCCEEDED(hr))
        {
            if (acloOptions != ACLO_NONE)
            {
                hr = pal2->SetOptions(acloOptions);
            }

            if (szCurrentWorkingDirectory != NULL)
            {
                ICurrentWorkingDirectory *pcwd;
                hr = pal2->QueryInterface(IID_PPV_ARGS(&pcwd));
                if (SUCCEEDED(hr))
                {
                    hr = pcwd->SetDirectory(szCurrentWorkingDirectory);
                    pcwd->Release();
                }
            }

            pal2->Release();
        }
    }

    hr = pac->Init(hWndEdit, punkSource, NULL, NULL);

    if (acoOptions != ACO_NONE)
    {
        IAutoComplete2 *pac2;
        hr = pac->QueryInterface(IID_PPV_ARGS(&pac2));
        if (SUCCEEDED(hr))
        {
            hr = pac2->SetOptions(acoOptions);
            pac2->Release();
        }
    }

    punkSource->Release();
    pac->Release();
    return hr;
}
Example #3
0
bool wxTextEntry::AutoComplete(const wxArrayString& choices)
{
#ifdef HAS_AUTOCOMPLETE
    // if we had an old enumerator we must reuse it as IAutoComplete doesn't
    // free it if we call Init() again (see #10968) -- and it's also simpler
    if ( m_enumStrings )
    {
        m_enumStrings->ChangeStrings(choices);
        return true;
    }

    // create an object exposing IAutoComplete interface (don't go for
    // IAutoComplete2 immediately as, presumably, it might be not available on
    // older systems as otherwise why do we have both -- although in practice I
    // don't know when can this happen)
    IAutoComplete *pAutoComplete = NULL;
    HRESULT hr = CoCreateInstance
                 (
                    CLSID_AutoComplete,
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_IAutoComplete,
                    reinterpret_cast<void **>(&pAutoComplete)
                 );
    if ( FAILED(hr) )
    {
        wxLogApiError(wxT("CoCreateInstance(CLSID_AutoComplete)"), hr);
        return false;
    }

    // associate it with our strings
    m_enumStrings = new wxIEnumString(choices);
    m_enumStrings->AddRef();
    hr = pAutoComplete->Init(GetEditHwnd(), m_enumStrings, NULL, NULL);
    m_enumStrings->Release();
    if ( FAILED(hr) )
    {
        wxLogApiError(wxT("IAutoComplete::Init"), hr);
        return false;
    }

    // if IAutoComplete2 is available, set more user-friendly options
    IAutoComplete2 *pAutoComplete2 = NULL;
    hr = pAutoComplete->QueryInterface
                        (
                           IID_IAutoComplete2,
                           reinterpret_cast<void **>(&pAutoComplete2)
                        );
    if ( SUCCEEDED(hr) )
    {
        pAutoComplete2->SetOptions(ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST);
        pAutoComplete2->Release();
    }

    // the docs are unclear about when can we release it but it seems safe to
    // do it immediately, presumably the edit control itself keeps a reference
    // to the auto completer object
    pAutoComplete->Release();
    return true;
#else // !HAS_AUTOCOMPLETE
    wxUnusedVar(choices);

    return false;
#endif // HAS_AUTOCOMPLETE/!HAS_AUTOCOMPLETE
}