2004-04-19 21:26:57 +02:00
|
|
|
/*
|
|
|
|
* AutoComplete interfaces implementation.
|
|
|
|
*
|
2008-10-18 19:20:53 +02:00
|
|
|
* Copyright 2004 Maxime Bellengé <maxime.bellenge@laposte.net>
|
2004-04-19 21:26:57 +02:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
/*
|
|
|
|
Implemented:
|
|
|
|
- ACO_AUTOAPPEND style
|
|
|
|
- ACO_AUTOSUGGEST style
|
|
|
|
- ACO_UPDOWNKEYDROPSLIST style
|
|
|
|
|
2004-04-30 06:14:33 +02:00
|
|
|
- Handle pwzsRegKeyPath and pwszQuickComplete in Init
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
TODO:
|
|
|
|
- implement ACO_SEARCH style
|
|
|
|
- implement ACO_FILTERPREFIXES style
|
|
|
|
- implement ACO_USETAB style
|
|
|
|
- implement ACO_RTLREADING style
|
2008-09-17 21:46:40 +02:00
|
|
|
- implement ResetEnumerator
|
|
|
|
- string compares should be case-insensitive, the content of the list should be sorted
|
2004-04-26 22:06:24 +02:00
|
|
|
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2004-10-07 05:06:48 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winreg.h"
|
|
|
|
#include "undocshell.h"
|
|
|
|
#include "shlwapi.h"
|
|
|
|
#include "winerror.h"
|
|
|
|
#include "objbase.h"
|
|
|
|
|
|
|
|
#include "pidl.h"
|
|
|
|
#include "shlobj.h"
|
|
|
|
#include "shldisp.h"
|
|
|
|
#include "debughlp.h"
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
#include "wine/unicode.h"
|
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(shell);
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2008-07-29 17:23:09 +02:00
|
|
|
const IAutoComplete2Vtbl *lpVtbl;
|
2008-09-17 21:42:36 +02:00
|
|
|
const IAutoCompleteDropDownVtbl *lpDropDownVtbl;
|
2005-07-03 14:03:35 +02:00
|
|
|
LONG ref;
|
2004-04-30 06:14:33 +02:00
|
|
|
BOOL enabled;
|
2004-04-26 22:06:24 +02:00
|
|
|
HWND hwndEdit;
|
|
|
|
HWND hwndListBox;
|
|
|
|
WNDPROC wpOrigEditProc;
|
|
|
|
WNDPROC wpOrigLBoxProc;
|
|
|
|
WCHAR *txtbackup;
|
2004-04-30 06:14:33 +02:00
|
|
|
WCHAR *quickComplete;
|
2004-04-26 22:06:24 +02:00
|
|
|
IEnumString *enumstr;
|
2004-04-19 21:26:57 +02:00
|
|
|
AUTOCOMPLETEOPTIONS options;
|
|
|
|
} IAutoCompleteImpl;
|
|
|
|
|
2008-07-29 17:23:09 +02:00
|
|
|
static const IAutoComplete2Vtbl acvt;
|
2008-09-17 21:42:36 +02:00
|
|
|
static const IAutoCompleteDropDownVtbl acdropdownvt;
|
2005-07-27 13:10:52 +02:00
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
/*
|
2005-03-23 14:15:18 +01:00
|
|
|
converts This to an interface pointer
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
|
|
|
#define _IUnknown_(This) (IUnknown*)&(This->lpVtbl)
|
2008-09-17 21:42:36 +02:00
|
|
|
#define _IAutoComplete2_(This) (IAutoComplete2*)&(This->lpVtbl)
|
|
|
|
#define _IAutoCompleteDropDown_(This) (IAutoCompleteDropDown*)&(This->lpDropDownVtbl)
|
|
|
|
|
|
|
|
static inline IAutoCompleteImpl *impl_from_IAutoCompleteDropDown(IAutoCompleteDropDown *iface)
|
|
|
|
{
|
|
|
|
return (IAutoCompleteImpl *)((char *)iface - FIELD_OFFSET(IAutoCompleteImpl, lpDropDownVtbl));
|
|
|
|
}
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
|
|
static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
|
|
|
|
2008-09-17 21:42:41 +02:00
|
|
|
static void create_listbox(IAutoCompleteImpl *This)
|
|
|
|
{
|
|
|
|
HWND hwndParent;
|
|
|
|
|
|
|
|
hwndParent = GetParent(This->hwndEdit);
|
|
|
|
|
|
|
|
/* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */
|
|
|
|
This->hwndListBox = CreateWindowExW(0, WC_LISTBOXW, NULL,
|
|
|
|
WS_BORDER | WS_CHILD | WS_VSCROLL | LBS_HASSTRINGS | LBS_NOTIFY | LBS_NOINTEGRALHEIGHT,
|
|
|
|
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
|
|
|
hwndParent, NULL,
|
|
|
|
(HINSTANCE)GetWindowLongPtrW( hwndParent, GWLP_HINSTANCE ), NULL);
|
|
|
|
|
|
|
|
if (This->hwndListBox) {
|
|
|
|
This->wpOrigLBoxProc = (WNDPROC) SetWindowLongPtrW( This->hwndListBox, GWLP_WNDPROC, (LONG_PTR) ACLBoxSubclassProc);
|
|
|
|
SetWindowLongPtrW( This->hwndListBox, GWLP_USERDATA, (LONG_PTR)This);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
/**************************************************************************
|
|
|
|
* IAutoComplete_Constructor
|
|
|
|
*/
|
|
|
|
HRESULT WINAPI IAutoComplete_Constructor(IUnknown * pUnkOuter, REFIID riid, LPVOID * ppv)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *lpac;
|
|
|
|
|
|
|
|
if (pUnkOuter && !IsEqualIID (riid, &IID_IUnknown))
|
|
|
|
return CLASS_E_NOAGGREGATION;
|
|
|
|
|
2005-03-21 12:25:13 +01:00
|
|
|
lpac = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IAutoCompleteImpl));
|
2004-04-19 21:26:57 +02:00
|
|
|
if (!lpac)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
lpac->ref = 1;
|
|
|
|
lpac->lpVtbl = &acvt;
|
2008-09-17 21:42:36 +02:00
|
|
|
lpac->lpDropDownVtbl = &acdropdownvt;
|
2004-04-30 06:14:33 +02:00
|
|
|
lpac->enabled = TRUE;
|
2004-04-26 22:06:24 +02:00
|
|
|
lpac->enumstr = NULL;
|
|
|
|
lpac->options = ACO_AUTOAPPEND;
|
|
|
|
lpac->wpOrigEditProc = NULL;
|
|
|
|
lpac->hwndListBox = NULL;
|
|
|
|
lpac->txtbackup = NULL;
|
2004-04-30 06:14:33 +02:00
|
|
|
lpac->quickComplete = NULL;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED (IUnknown_QueryInterface (_IUnknown_ (lpac), riid, ppv))) {
|
2004-04-19 21:26:57 +02:00
|
|
|
IUnknown_Release (_IUnknown_ (lpac));
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("-- (%p)->\n",lpac);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* AutoComplete_QueryInterface
|
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static HRESULT WINAPI IAutoComplete2_fnQueryInterface(
|
|
|
|
IAutoComplete2 * iface,
|
2004-04-19 21:26:57 +02:00
|
|
|
REFIID riid,
|
|
|
|
LPVOID *ppvObj)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
TRACE("(%p)->(\n\tIID:\t%s,%p)\n", This, shdebugstr_guid(riid), ppvObj);
|
|
|
|
*ppvObj = NULL;
|
|
|
|
|
2008-07-29 17:23:09 +02:00
|
|
|
if (IsEqualIID(riid, &IID_IUnknown) ||
|
|
|
|
IsEqualIID(riid, &IID_IAutoComplete) ||
|
|
|
|
IsEqualIID(riid, &IID_IAutoComplete2))
|
2004-04-19 21:26:57 +02:00
|
|
|
{
|
2008-07-29 17:23:09 +02:00
|
|
|
*ppvObj = (IAutoComplete2*)This;
|
2004-04-19 21:26:57 +02:00
|
|
|
}
|
2008-09-17 21:42:36 +02:00
|
|
|
else if (IsEqualIID(riid, &IID_IAutoCompleteDropDown))
|
|
|
|
{
|
|
|
|
*ppvObj = _IAutoCompleteDropDown_(This);
|
|
|
|
}
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
if (*ppvObj)
|
|
|
|
{
|
2008-07-29 17:23:09 +02:00
|
|
|
IUnknown_AddRef((IUnknown*)*ppvObj);
|
2004-04-19 21:26:57 +02:00
|
|
|
TRACE("-- Interface: (%p)->(%p)\n", ppvObj, *ppvObj);
|
|
|
|
return S_OK;
|
|
|
|
}
|
2008-09-17 21:42:36 +02:00
|
|
|
WARN("unsupported interface: %s\n", debugstr_guid(riid));
|
2004-04-19 21:26:57 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnAddRef
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static ULONG WINAPI IAutoComplete2_fnAddRef(
|
|
|
|
IAutoComplete2 * iface)
|
2004-04-19 21:26:57 +02:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedIncrement(&This->ref);
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("(%p)->(%u)\n", This, refCount - 1);
|
2005-01-14 17:02:20 +01:00
|
|
|
|
|
|
|
return refCount;
|
2004-04-19 21:26:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnRelease
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static ULONG WINAPI IAutoComplete2_fnRelease(
|
|
|
|
IAutoComplete2 * iface)
|
2004-04-19 21:26:57 +02:00
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2005-01-14 17:02:20 +01:00
|
|
|
ULONG refCount = InterlockedDecrement(&This->ref);
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("(%p)->(%u)\n", This, refCount + 1);
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2005-01-14 17:02:20 +01:00
|
|
|
if (!refCount) {
|
2004-04-19 21:26:57 +02:00
|
|
|
TRACE(" destroying IAutoComplete(%p)\n",This);
|
2004-12-23 18:06:43 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, This->quickComplete);
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->txtbackup);
|
2004-04-26 22:06:24 +02:00
|
|
|
if (This->hwndListBox)
|
|
|
|
DestroyWindow(This->hwndListBox);
|
|
|
|
if (This->enumstr)
|
|
|
|
IEnumString_Release(This->enumstr);
|
2004-04-19 21:26:57 +02:00
|
|
|
HeapFree(GetProcessHeap(), 0, This);
|
|
|
|
}
|
2005-01-14 17:02:20 +01:00
|
|
|
return refCount;
|
2004-04-19 21:26:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnEnable
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static HRESULT WINAPI IAutoComplete2_fnEnable(
|
|
|
|
IAutoComplete2 * iface,
|
2004-04-19 21:26:57 +02:00
|
|
|
BOOL fEnable)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s)\n", This, (fEnable)?"true":"false");
|
|
|
|
|
2004-04-30 06:14:33 +02:00
|
|
|
This->enabled = fEnable;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnInit
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static HRESULT WINAPI IAutoComplete2_fnInit(
|
|
|
|
IAutoComplete2 * iface,
|
2004-04-19 21:26:57 +02:00
|
|
|
HWND hwndEdit,
|
|
|
|
IUnknown *punkACL,
|
|
|
|
LPCOLESTR pwzsRegKeyPath,
|
|
|
|
LPCOLESTR pwszQuickComplete)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
TRACE("(%p)->(0x%08lx, %p, %s, %s)\n",
|
2004-04-19 21:26:57 +02:00
|
|
|
This, (long)hwndEdit, punkACL, debugstr_w(pwzsRegKeyPath), debugstr_w(pwszQuickComplete));
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
if (This->options & ACO_SEARCH) FIXME(" ACO_SEARCH not supported\n");
|
|
|
|
if (This->options & ACO_FILTERPREFIXES) FIXME(" ACO_FILTERPREFIXES not supported\n");
|
|
|
|
if (This->options & ACO_USETAB) FIXME(" ACO_USETAB not supported\n");
|
|
|
|
if (This->options & ACO_RTLREADING) FIXME(" ACO_RTLREADING not supported\n");
|
|
|
|
|
|
|
|
This->hwndEdit = hwndEdit;
|
|
|
|
|
2008-10-08 01:32:38 +02:00
|
|
|
if (FAILED (IUnknown_QueryInterface (punkACL, &IID_IEnumString, (LPVOID*)&This->enumstr))) {
|
2004-04-26 22:06:24 +02:00
|
|
|
TRACE("No IEnumString interface\n");
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
This->wpOrigEditProc = (WNDPROC) SetWindowLongPtrW( hwndEdit, GWLP_WNDPROC, (LONG_PTR) ACEditSubclassProc);
|
|
|
|
SetWindowLongPtrW( hwndEdit, GWLP_USERDATA, (LONG_PTR)This);
|
|
|
|
|
2008-09-17 21:42:41 +02:00
|
|
|
if (This->options & ACO_AUTOSUGGEST)
|
|
|
|
create_listbox(This);
|
2004-04-26 22:06:24 +02:00
|
|
|
|
2004-04-30 06:14:33 +02:00
|
|
|
if (pwzsRegKeyPath) {
|
|
|
|
WCHAR *key;
|
|
|
|
WCHAR result[MAX_PATH];
|
|
|
|
WCHAR *value;
|
|
|
|
HKEY hKey = 0;
|
|
|
|
LONG res;
|
|
|
|
LONG len;
|
|
|
|
|
|
|
|
/* pwszRegKeyPath contains the key as well as the value, so we split */
|
2005-03-21 12:25:13 +01:00
|
|
|
key = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwzsRegKeyPath)+1)*sizeof(WCHAR));
|
2004-04-30 06:14:33 +02:00
|
|
|
strcpyW(key, pwzsRegKeyPath);
|
|
|
|
value = strrchrW(key, '\\');
|
|
|
|
*value = 0;
|
|
|
|
value++;
|
|
|
|
/* Now value contains the value and buffer the key */
|
|
|
|
res = RegOpenKeyExW(HKEY_CURRENT_USER, key, 0, KEY_READ, &hKey);
|
|
|
|
if (res != ERROR_SUCCESS) {
|
|
|
|
/* if the key is not found, MSDN states we must seek in HKEY_LOCAL_MACHINE */
|
|
|
|
res = RegOpenKeyExW(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey);
|
|
|
|
}
|
|
|
|
if (res == ERROR_SUCCESS) {
|
|
|
|
res = RegQueryValueW(hKey, value, result, &len);
|
|
|
|
if (res == ERROR_SUCCESS) {
|
2005-03-21 12:25:13 +01:00
|
|
|
This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len*sizeof(WCHAR));
|
2004-04-30 06:14:33 +02:00
|
|
|
strcpyW(This->quickComplete, result);
|
|
|
|
}
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, key);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((pwszQuickComplete) && (!This->quickComplete)) {
|
2005-03-21 12:25:13 +01:00
|
|
|
This->quickComplete = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (lstrlenW(pwszQuickComplete)+1)*sizeof(WCHAR));
|
2004-04-30 06:14:33 +02:00
|
|
|
lstrcpyW(This->quickComplete, pwszQuickComplete);
|
|
|
|
}
|
2004-04-26 22:06:24 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2004-04-19 21:26:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnGetOptions
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IAutoComplete2_fnGetOptions(
|
|
|
|
IAutoComplete2 * iface,
|
|
|
|
DWORD *pdwFlag)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
2004-04-30 06:14:33 +02:00
|
|
|
|
2008-07-29 17:23:09 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
|
|
|
TRACE("(%p) -> (%p)\n", This, pdwFlag);
|
|
|
|
|
|
|
|
*pdwFlag = This->options;
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2008-07-29 17:23:09 +02:00
|
|
|
* IAutoComplete2_fnSetOptions
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IAutoComplete2_fnSetOptions(
|
|
|
|
IAutoComplete2 * iface,
|
|
|
|
DWORD dwFlag)
|
|
|
|
{
|
|
|
|
HRESULT hr = S_OK;
|
|
|
|
|
2008-07-29 17:23:09 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)iface;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2006-10-07 20:18:14 +02:00
|
|
|
TRACE("(%p) -> (0x%x)\n", This, dwFlag);
|
2004-04-26 22:06:24 +02:00
|
|
|
|
|
|
|
This->options = dwFlag;
|
2004-04-19 21:26:57 +02:00
|
|
|
|
2008-09-17 21:42:41 +02:00
|
|
|
if ((This->options & ACO_AUTOSUGGEST) && This->hwndEdit && !This->hwndListBox)
|
|
|
|
create_listbox(This);
|
|
|
|
|
2004-04-19 21:26:57 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
2008-09-17 21:42:36 +02:00
|
|
|
* IAutoCompleteDropDown_fnGetDropDownStatus
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IAutoCompleteDropDown_fnGetDropDownStatus(
|
|
|
|
IAutoCompleteDropDown *iface,
|
|
|
|
DWORD *pdwFlags,
|
|
|
|
LPWSTR *ppwszString)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
|
2008-09-17 21:42:46 +02:00
|
|
|
BOOL dropped;
|
2008-09-17 21:42:36 +02:00
|
|
|
|
2008-09-17 21:42:46 +02:00
|
|
|
TRACE("(%p) -> (%p, %p)\n", This, pdwFlags, ppwszString);
|
|
|
|
|
|
|
|
dropped = IsWindowVisible(This->hwndListBox);
|
2008-09-17 21:42:36 +02:00
|
|
|
|
|
|
|
if (pdwFlags)
|
2008-09-17 21:42:46 +02:00
|
|
|
*pdwFlags = (dropped ? ACDD_VISIBLE : 0);
|
|
|
|
|
|
|
|
if (ppwszString) {
|
|
|
|
if (dropped) {
|
|
|
|
int sel;
|
|
|
|
|
|
|
|
sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
|
|
|
|
if (sel >= 0)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
|
|
|
|
*ppwszString = CoTaskMemAlloc((len+1)*sizeof(WCHAR));
|
|
|
|
SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)*ppwszString);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppwszString = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ppwszString = NULL;
|
|
|
|
}
|
2008-09-17 21:42:36 +02:00
|
|
|
|
2008-09-17 21:42:46 +02:00
|
|
|
return S_OK;
|
2008-09-17 21:42:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IAutoCompleteDropDown_fnResetEnumarator
|
|
|
|
*/
|
|
|
|
static HRESULT WINAPI IAutoCompleteDropDown_fnResetEnumerator(
|
|
|
|
IAutoCompleteDropDown *iface)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
|
|
|
|
|
|
|
|
FIXME("(%p): stub\n", This);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IAutoComplete2 VTable
|
2004-04-19 21:26:57 +02:00
|
|
|
*/
|
2008-07-29 17:23:09 +02:00
|
|
|
static const IAutoComplete2Vtbl acvt =
|
2004-04-19 21:26:57 +02:00
|
|
|
{
|
|
|
|
IAutoComplete2_fnQueryInterface,
|
|
|
|
IAutoComplete2_fnAddRef,
|
|
|
|
IAutoComplete2_fnRelease,
|
|
|
|
IAutoComplete2_fnInit,
|
|
|
|
IAutoComplete2_fnEnable,
|
|
|
|
/* IAutoComplete2 */
|
|
|
|
IAutoComplete2_fnSetOptions,
|
|
|
|
IAutoComplete2_fnGetOptions,
|
|
|
|
};
|
2004-04-26 22:06:24 +02:00
|
|
|
|
2008-09-17 21:42:36 +02:00
|
|
|
|
|
|
|
static HRESULT WINAPI IAutoCompleteDropDown_fnQueryInterface(IAutoCompleteDropDown *iface,
|
|
|
|
REFIID riid, LPVOID *ppvObj)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
|
|
|
|
return IAutoComplete2_fnQueryInterface(_IAutoComplete2_(This), riid, ppvObj);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IAutoCompleteDropDown_fnAddRef(IAutoCompleteDropDown *iface)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
|
|
|
|
return IAutoComplete2_fnAddRef(_IAutoComplete2_(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG WINAPI IAutoCompleteDropDown_fnRelease(IAutoCompleteDropDown *iface)
|
|
|
|
{
|
|
|
|
IAutoCompleteImpl *This = impl_from_IAutoCompleteDropDown(iface);
|
|
|
|
return IAutoComplete2_fnRelease(_IAutoComplete2_(This));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
* IAutoCompleteDropDown VTable
|
|
|
|
*/
|
|
|
|
static const IAutoCompleteDropDownVtbl acdropdownvt =
|
|
|
|
{
|
|
|
|
IAutoCompleteDropDown_fnQueryInterface,
|
|
|
|
IAutoCompleteDropDown_fnAddRef,
|
|
|
|
IAutoCompleteDropDown_fnRelease,
|
|
|
|
IAutoCompleteDropDown_fnGetDropDownStatus,
|
|
|
|
IAutoCompleteDropDown_fnResetEnumerator,
|
|
|
|
};
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
/*
|
|
|
|
Window procedure for autocompletion
|
|
|
|
*/
|
|
|
|
static LRESULT APIENTRY ACEditSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
2004-04-26 22:06:24 +02:00
|
|
|
LPOLESTR strs;
|
|
|
|
HRESULT hr;
|
|
|
|
WCHAR hwndText[255];
|
2004-04-30 06:14:33 +02:00
|
|
|
WCHAR *hwndQCText;
|
2004-04-26 22:06:24 +02:00
|
|
|
RECT r;
|
2004-04-30 06:14:33 +02:00
|
|
|
BOOL control, filled, displayall = FALSE;
|
2004-04-26 22:06:24 +02:00
|
|
|
int cpt, height, sel;
|
|
|
|
|
2004-04-30 06:14:33 +02:00
|
|
|
if (!This->enabled) return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
|
2004-04-26 22:06:24 +02:00
|
|
|
switch (uMsg)
|
|
|
|
{
|
|
|
|
case CB_SHOWDROPDOWN:
|
|
|
|
ShowWindow(This->hwndListBox, SW_HIDE);
|
|
|
|
break;
|
|
|
|
case WM_KILLFOCUS:
|
2008-09-17 21:42:38 +02:00
|
|
|
if ((This->options & ACO_AUTOSUGGEST) &&
|
2004-04-26 22:06:24 +02:00
|
|
|
((HWND)wParam != This->hwndListBox))
|
|
|
|
{
|
|
|
|
ShowWindow(This->hwndListBox, SW_HIDE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_KEYUP:
|
|
|
|
|
|
|
|
GetWindowTextW( hwnd, (LPWSTR)hwndText, 255);
|
|
|
|
|
|
|
|
switch(wParam) {
|
2004-04-30 06:14:33 +02:00
|
|
|
case VK_RETURN:
|
|
|
|
/* If quickComplete is set and control is pressed, replace the string */
|
|
|
|
control = GetKeyState(VK_CONTROL) & 0x8000;
|
|
|
|
if (control && This->quickComplete) {
|
2005-03-21 12:25:13 +01:00
|
|
|
hwndQCText = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
2004-04-30 06:14:33 +02:00
|
|
|
(lstrlenW(This->quickComplete)+lstrlenW(hwndText))*sizeof(WCHAR));
|
|
|
|
sel = sprintfW(hwndQCText, This->quickComplete, hwndText);
|
|
|
|
SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)hwndQCText);
|
|
|
|
SendMessageW(hwnd, EM_SETSEL, 0, sel);
|
|
|
|
HeapFree(GetProcessHeap(), 0, hwndQCText);
|
|
|
|
}
|
|
|
|
|
|
|
|
ShowWindow(This->hwndListBox, SW_HIDE);
|
|
|
|
return 0;
|
|
|
|
case VK_LEFT:
|
|
|
|
case VK_RIGHT:
|
|
|
|
return 0;
|
2004-04-26 22:06:24 +02:00
|
|
|
case VK_UP:
|
|
|
|
case VK_DOWN:
|
|
|
|
/* Two cases here :
|
|
|
|
- if the listbox is not visible, displays it
|
|
|
|
with all the entries if the style ACO_UPDOWNKEYDROPSLIST
|
|
|
|
is present but does not select anything.
|
|
|
|
- if the listbox is visible, change the selection
|
|
|
|
*/
|
|
|
|
if ( (This->options & (ACO_AUTOSUGGEST | ACO_UPDOWNKEYDROPSLIST))
|
|
|
|
&& (!IsWindowVisible(This->hwndListBox) && (! *hwndText)) )
|
|
|
|
{
|
2008-01-16 12:20:50 +01:00
|
|
|
/* We must display all the entries */
|
2004-04-26 22:06:24 +02:00
|
|
|
displayall = TRUE;
|
|
|
|
} else {
|
2004-04-30 06:14:33 +02:00
|
|
|
if (IsWindowVisible(This->hwndListBox)) {
|
|
|
|
int count;
|
|
|
|
|
|
|
|
count = SendMessageW(This->hwndListBox, LB_GETCOUNT, 0, 0);
|
|
|
|
/* Change the selection */
|
|
|
|
sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
|
|
|
|
if (wParam == VK_UP)
|
|
|
|
sel = ((sel-1)<0)?count-1:sel-1;
|
|
|
|
else
|
|
|
|
sel = ((sel+1)>= count)?-1:sel+1;
|
|
|
|
SendMessageW(This->hwndListBox, LB_SETCURSEL, sel, 0);
|
|
|
|
if (sel != -1) {
|
|
|
|
WCHAR *msg;
|
|
|
|
int len;
|
|
|
|
|
2008-11-02 00:23:18 +01:00
|
|
|
len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
|
2005-03-21 12:25:13 +01:00
|
|
|
msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
|
2004-04-30 06:14:33 +02:00
|
|
|
SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
|
|
|
|
SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)msg);
|
|
|
|
SendMessageW(hwnd, EM_SETSEL, lstrlenW(msg), lstrlenW(msg));
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg);
|
|
|
|
} else {
|
|
|
|
SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)This->txtbackup);
|
|
|
|
SendMessageW(hwnd, EM_SETSEL, lstrlenW(This->txtbackup), lstrlenW(This->txtbackup));
|
|
|
|
}
|
|
|
|
}
|
2004-04-26 22:06:24 +02:00
|
|
|
return 0;
|
2004-04-30 06:14:33 +02:00
|
|
|
}
|
2004-04-26 22:06:24 +02:00
|
|
|
break;
|
|
|
|
case VK_BACK:
|
|
|
|
case VK_DELETE:
|
|
|
|
if ((! *hwndText) && (This->options & ACO_AUTOSUGGEST)) {
|
|
|
|
ShowWindow(This->hwndListBox, SW_HIDE);
|
|
|
|
return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
if (This->options & ACO_AUTOAPPEND) {
|
|
|
|
DWORD b;
|
2008-11-02 00:23:18 +01:00
|
|
|
SendMessageW(hwnd, EM_GETSEL, (WPARAM)&b, 0);
|
2004-04-26 22:06:24 +02:00
|
|
|
if (b>1) {
|
|
|
|
hwndText[b-1] = '\0';
|
|
|
|
} else {
|
|
|
|
hwndText[0] = '\0';
|
|
|
|
SetWindowTextW(hwnd, hwndText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageW(This->hwndListBox, LB_RESETCONTENT, 0, 0);
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, This->txtbackup);
|
2005-03-21 12:25:13 +01:00
|
|
|
This->txtbackup = HeapAlloc(GetProcessHeap(),
|
2004-07-04 02:11:07 +02:00
|
|
|
HEAP_ZERO_MEMORY, (lstrlenW(hwndText)+1)*sizeof(WCHAR));
|
2004-04-26 22:06:24 +02:00
|
|
|
lstrcpyW(This->txtbackup, hwndText);
|
|
|
|
|
|
|
|
/* Returns if there is no text to search and we doesn't want to display all the entries */
|
|
|
|
if ((!displayall) && (! *hwndText) )
|
|
|
|
break;
|
|
|
|
|
|
|
|
IEnumString_Reset(This->enumstr);
|
|
|
|
filled = FALSE;
|
|
|
|
for(cpt = 0;;) {
|
2008-07-24 11:22:48 +02:00
|
|
|
ULONG fetched;
|
|
|
|
hr = IEnumString_Next(This->enumstr, 1, &strs, &fetched);
|
2004-04-26 22:06:24 +02:00
|
|
|
if (hr != S_OK)
|
|
|
|
break;
|
|
|
|
|
2008-01-19 17:54:24 +01:00
|
|
|
if (strstrW(strs, hwndText) == strs) {
|
2008-09-17 21:42:41 +02:00
|
|
|
if (!filled && (This->options & ACO_AUTOAPPEND)) {
|
2004-04-26 22:06:24 +02:00
|
|
|
SetWindowTextW(hwnd, strs);
|
|
|
|
SendMessageW(hwnd, EM_SETSEL, lstrlenW(hwndText), lstrlenW(strs));
|
2008-09-17 21:42:41 +02:00
|
|
|
if (!(This->options & ACO_AUTOSUGGEST))
|
|
|
|
break;
|
2004-04-26 22:06:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (This->options & ACO_AUTOSUGGEST) {
|
|
|
|
SendMessageW(This->hwndListBox, LB_ADDSTRING, 0, (LPARAM)strs);
|
|
|
|
cpt++;
|
|
|
|
}
|
2008-09-17 21:42:41 +02:00
|
|
|
|
|
|
|
filled = TRUE;
|
2004-04-26 22:06:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (This->options & ACO_AUTOSUGGEST) {
|
|
|
|
if (filled) {
|
|
|
|
height = SendMessageW(This->hwndListBox, LB_GETITEMHEIGHT, 0, 0);
|
|
|
|
SendMessageW(This->hwndListBox, LB_CARETOFF, 0, 0);
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
SetParent(This->hwndListBox, HWND_DESKTOP);
|
|
|
|
/* It seems that Windows XP displays 7 lines at most
|
|
|
|
and otherwise displays a vertical scroll bar */
|
|
|
|
SetWindowPos(This->hwndListBox, HWND_TOP,
|
|
|
|
r.left, r.bottom + 1, r.right - r.left, min(height * 7, height*(cpt+1)),
|
|
|
|
SWP_SHOWWINDOW );
|
|
|
|
} else {
|
|
|
|
ShowWindow(This->hwndListBox, SW_HIDE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return CallWindowProcW(This->wpOrigEditProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2004-09-09 22:17:07 +02:00
|
|
|
IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
|
2004-04-26 22:06:24 +02:00
|
|
|
WCHAR *msg;
|
2007-03-20 23:04:36 +01:00
|
|
|
int sel, len;
|
2004-04-26 22:06:24 +02:00
|
|
|
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_MOUSEMOVE:
|
|
|
|
sel = SendMessageW(hwnd, LB_ITEMFROMPOINT, 0, lParam);
|
|
|
|
SendMessageW(hwnd, LB_SETCURSEL, (WPARAM)sel, (LPARAM)0);
|
|
|
|
break;
|
|
|
|
case WM_LBUTTONDOWN:
|
2007-03-20 23:04:36 +01:00
|
|
|
sel = SendMessageW(hwnd, LB_GETCURSEL, 0, 0);
|
|
|
|
if (sel < 0)
|
|
|
|
break;
|
|
|
|
len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0);
|
2005-03-21 12:25:13 +01:00
|
|
|
msg = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (len+1)*sizeof(WCHAR));
|
2004-04-26 22:06:24 +02:00
|
|
|
SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
|
|
|
|
SendMessageW(This->hwndEdit, WM_SETTEXT, 0, (LPARAM)msg);
|
|
|
|
SendMessageW(This->hwndEdit, EM_SETSEL, 0, lstrlenW(msg));
|
|
|
|
ShowWindow(hwnd, SW_HIDE);
|
|
|
|
HeapFree(GetProcessHeap(), 0, msg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return CallWindowProcW(This->wpOrigLBoxProc, hwnd, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|