Commit e95dc7e0 authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

shell32/autocomplete: Use LBS_NODATA for the dropdown listbox.

This eliminates the overhead of populating the listbox completely and simplifies the code. Signed-off-by: 's avatarGabriel Ivăncescu <gabrielopcode@gmail.com> Signed-off-by: 's avatarHuw Davies <huw@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 0cd95038
...@@ -399,16 +399,11 @@ static BOOL select_item_with_return_key(IAutoCompleteImpl *ac, HWND hwnd) ...@@ -399,16 +399,11 @@ static BOOL select_item_with_return_key(IAutoCompleteImpl *ac, HWND hwnd)
INT sel = SendMessageW(hwndListBox, LB_GETCURSEL, 0, 0); INT sel = SendMessageW(hwndListBox, LB_GETCURSEL, 0, 0);
if (sel >= 0) if (sel >= 0)
{ {
UINT len = SendMessageW(hwndListBox, LB_GETTEXTLEN, sel, 0); text = ac->listbox_strs[sel];
if ((text = heap_alloc((len + 1) * sizeof(WCHAR)))) set_text_and_selection(ac, hwnd, text, 0, strlenW(text));
{ hide_listbox(ac, hwndListBox, TRUE);
len = SendMessageW(hwndListBox, LB_GETTEXT, sel, (LPARAM)text); ac->no_fwd_char = '\r'; /* RETURN char */
set_text_and_selection(ac, hwnd, text, 0, len); return TRUE;
hide_listbox(ac, hwndListBox, TRUE);
ac->no_fwd_char = '\r'; /* RETURN char */
heap_free(text);
return TRUE;
}
} }
} }
hide_listbox(ac, hwndListBox, TRUE); hide_listbox(ac, hwndListBox, TRUE);
...@@ -417,6 +412,9 @@ static BOOL select_item_with_return_key(IAutoCompleteImpl *ac, HWND hwnd) ...@@ -417,6 +412,9 @@ static BOOL select_item_with_return_key(IAutoCompleteImpl *ac, HWND hwnd)
static LRESULT change_selection(IAutoCompleteImpl *ac, HWND hwnd, UINT key) static LRESULT change_selection(IAutoCompleteImpl *ac, HWND hwnd, UINT key)
{ {
WCHAR *msg;
UINT len;
INT count = SendMessageW(ac->hwndListBox, LB_GETCOUNT, 0, 0); INT count = SendMessageW(ac->hwndListBox, LB_GETCOUNT, 0, 0);
INT sel = SendMessageW(ac->hwndListBox, LB_GETCURSEL, 0, 0); INT sel = SendMessageW(ac->hwndListBox, LB_GETCURSEL, 0, 0);
if (key == VK_PRIOR || key == VK_NEXT) if (key == VK_PRIOR || key == VK_NEXT)
...@@ -457,21 +455,11 @@ static LRESULT change_selection(IAutoCompleteImpl *ac, HWND hwnd, UINT key) ...@@ -457,21 +455,11 @@ static LRESULT change_selection(IAutoCompleteImpl *ac, HWND hwnd, UINT key)
sel = ((sel + 1) >= count) ? -1 : sel + 1; sel = ((sel + 1) >= count) ? -1 : sel + 1;
SendMessageW(ac->hwndListBox, LB_SETCURSEL, sel, 0); SendMessageW(ac->hwndListBox, LB_SETCURSEL, sel, 0);
if (sel >= 0)
{ msg = (sel >= 0) ? ac->listbox_strs[sel] : ac->txtbackup;
WCHAR *msg; len = strlenW(msg);
UINT len = SendMessageW(ac->hwndListBox, LB_GETTEXTLEN, sel, 0); set_text_and_selection(ac, hwnd, msg, len, len);
if (!(msg = heap_alloc((len + 1) * sizeof(WCHAR))))
return 0;
len = SendMessageW(ac->hwndListBox, LB_GETTEXT, sel, (LPARAM)msg);
set_text_and_selection(ac, hwnd, msg, len, len);
heap_free(msg);
}
else
{
UINT len = strlenW(ac->txtbackup);
set_text_and_selection(ac, hwnd, ac->txtbackup, len, len);
}
return 0; return 0;
} }
...@@ -597,9 +585,7 @@ static BOOL display_matching_strs(IAutoCompleteImpl *ac, WCHAR *text, UINT len, ...@@ -597,9 +585,7 @@ static BOOL display_matching_strs(IAutoCompleteImpl *ac, WCHAR *text, UINT len,
SendMessageW(ac->hwndListBox, LB_RESETCONTENT, 0, 0); SendMessageW(ac->hwndListBox, LB_RESETCONTENT, 0, 0);
ac->listbox_strs = str + start; ac->listbox_strs = str + start;
SendMessageW(ac->hwndListBox, LB_INITSTORAGE, end - start, 0); SendMessageW(ac->hwndListBox, LB_SETCOUNT, end - start, 0);
for (; start < end; start++)
SendMessageW(ac->hwndListBox, LB_INSERTSTRING, -1, (LPARAM)str[start]);
show_listbox(ac); show_listbox(ac);
SendMessageW(ac->hwndListBox, WM_SETREDRAW, TRUE, 0); SendMessageW(ac->hwndListBox, WM_SETREDRAW, TRUE, 0);
...@@ -860,7 +846,7 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -860,7 +846,7 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
{ {
IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA); IAutoCompleteImpl *This = (IAutoCompleteImpl *)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
WCHAR *msg; WCHAR *msg;
int sel, len; INT sel;
switch (uMsg) { switch (uMsg) {
case WM_MOUSEACTIVATE: case WM_MOUSEACTIVATE:
...@@ -873,13 +859,9 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -873,13 +859,9 @@ static LRESULT APIENTRY ACLBoxSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
sel = SendMessageW(hwnd, LB_GETCURSEL, 0, 0); sel = SendMessageW(hwnd, LB_GETCURSEL, 0, 0);
if (sel < 0) if (sel < 0)
return 0; return 0;
len = SendMessageW(hwnd, LB_GETTEXTLEN, sel, 0); msg = This->listbox_strs[sel];
if (!(msg = heap_alloc((len + 1) * sizeof(WCHAR)))) set_text_and_selection(This, This->hwndEdit, msg, 0, strlenW(msg));
return 0;
len = SendMessageW(hwnd, LB_GETTEXT, sel, (LPARAM)msg);
set_text_and_selection(This, This->hwndEdit, msg, 0, len);
hide_listbox(This, hwnd, TRUE); hide_listbox(This, hwnd, TRUE);
heap_free(msg);
return 0; return 0;
} }
return CallWindowProcW(This->wpOrigLBoxProc, hwnd, uMsg, wParam, lParam); return CallWindowProcW(This->wpOrigLBoxProc, hwnd, uMsg, wParam, lParam);
...@@ -918,7 +900,7 @@ static void create_listbox(IAutoCompleteImpl *This) ...@@ -918,7 +900,7 @@ static void create_listbox(IAutoCompleteImpl *This)
/* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */ /* FIXME : The listbox should be resizable with the mouse. WS_THICKFRAME looks ugly */
This->hwndListBox = CreateWindowExW(WS_EX_NOACTIVATE, WC_LISTBOXW, NULL, This->hwndListBox = CreateWindowExW(WS_EX_NOACTIVATE, WC_LISTBOXW, NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_HASSTRINGS | LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT, WS_CHILD | WS_VISIBLE | WS_VSCROLL | LBS_NODATA | LBS_OWNERDRAWFIXED | LBS_NOINTEGRALHEIGHT,
0, 0, 0, 0, This->hwndListBoxOwner, NULL, shell32_hInstance, NULL); 0, 0, 0, 0, This->hwndListBoxOwner, NULL, shell32_hInstance, NULL);
if (This->hwndListBox) { if (This->hwndListBox) {
...@@ -1259,11 +1241,12 @@ static HRESULT WINAPI IAutoCompleteDropDown_fnGetDropDownStatus( ...@@ -1259,11 +1241,12 @@ static HRESULT WINAPI IAutoCompleteDropDown_fnGetDropDownStatus(
sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0); sel = SendMessageW(This->hwndListBox, LB_GETCURSEL, 0, 0);
if (sel >= 0) if (sel >= 0)
{ {
DWORD len; WCHAR *str = This->listbox_strs[sel];
size_t size = (strlenW(str) + 1) * sizeof(*str);
len = SendMessageW(This->hwndListBox, LB_GETTEXTLEN, sel, 0); if (!(*ppwszString = CoTaskMemAlloc(size)))
*ppwszString = CoTaskMemAlloc((len+1)*sizeof(WCHAR)); return E_OUTOFMEMORY;
SendMessageW(This->hwndListBox, LB_GETTEXT, sel, (LPARAM)*ppwszString); memcpy(*ppwszString, str, size);
} }
else else
*ppwszString = NULL; *ppwszString = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment