2007-03-26 11:25:21 +02:00
|
|
|
/* Unit test suite for combo boxes.
|
|
|
|
*
|
|
|
|
* Copyright 2007 Mikolaj Zalewski
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2015-12-31 14:00:20 +01:00
|
|
|
#include <limits.h>
|
2007-03-26 11:25:21 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2007-08-09 11:34:23 +02:00
|
|
|
#define STRICT
|
2007-03-26 11:25:21 +02:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
#include "wine/test.h"
|
|
|
|
|
2007-08-09 11:34:23 +02:00
|
|
|
#define COMBO_ID 1995
|
|
|
|
|
2017-08-17 18:24:57 +02:00
|
|
|
#define COMBO_YBORDERSIZE() 2
|
|
|
|
|
2007-08-09 11:34:23 +02:00
|
|
|
static HWND hMainWnd;
|
2007-03-26 11:25:21 +02:00
|
|
|
|
|
|
|
#define expect_eq(expr, value, type, fmt); { type val = expr; ok(val == (value), #expr " expected " #fmt " got " #fmt "\n", (value), val); }
|
|
|
|
#define expect_rect(r, _left, _top, _right, _bottom) ok(r.left == _left && r.top == _top && \
|
2016-09-27 09:57:04 +02:00
|
|
|
r.bottom == _bottom && r.right == _right, "Invalid rect %s vs (%d,%d)-(%d,%d)\n", \
|
|
|
|
wine_dbgstr_rect(&r), _left, _top, _right, _bottom);
|
2007-03-26 11:25:21 +02:00
|
|
|
|
|
|
|
static HWND build_combo(DWORD style)
|
|
|
|
{
|
2013-10-23 07:53:22 +02:00
|
|
|
return CreateWindowA("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|style, 5, 5, 100, 100, hMainWnd, (HMENU)COMBO_ID, NULL, 0);
|
2007-03-26 11:25:21 +02:00
|
|
|
}
|
|
|
|
|
2019-11-27 09:31:05 +01:00
|
|
|
static int get_font_height(HFONT hFont)
|
2007-03-26 11:25:21 +02:00
|
|
|
{
|
2013-10-23 07:53:22 +02:00
|
|
|
TEXTMETRICA tm;
|
2007-03-26 11:25:21 +02:00
|
|
|
HFONT hFontOld;
|
|
|
|
HDC hDC;
|
|
|
|
|
|
|
|
hDC = CreateCompatibleDC(NULL);
|
|
|
|
hFontOld = SelectObject(hDC, hFont);
|
2013-10-23 07:53:22 +02:00
|
|
|
GetTextMetricsA(hDC, &tm);
|
2007-03-26 11:25:21 +02:00
|
|
|
SelectObject(hDC, hFontOld);
|
|
|
|
DeleteDC(hDC);
|
|
|
|
|
|
|
|
return tm.tmHeight;
|
|
|
|
}
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
static INT CALLBACK is_font_installed_proc(const LOGFONTA *elf, const TEXTMETRICA *tm, DWORD type, LPARAM lParam)
|
2007-03-26 11:25:21 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-11-05 01:05:01 +01:00
|
|
|
static BOOL is_font_installed(const char *name)
|
2007-03-26 11:25:21 +02:00
|
|
|
{
|
|
|
|
HDC hdc = GetDC(NULL);
|
2013-10-23 07:53:22 +02:00
|
|
|
BOOL ret = !EnumFontFamiliesA(hdc, name, is_font_installed_proc, 0);
|
2007-03-26 11:25:21 +02:00
|
|
|
ReleaseDC(NULL, hdc);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-08-30 20:45:51 +02:00
|
|
|
static void test_setitemheight(DWORD style)
|
|
|
|
{
|
|
|
|
HWND hCombo = build_combo(style);
|
2019-11-27 09:31:05 +01:00
|
|
|
int i, font_height, height;
|
|
|
|
HFONT hFont;
|
2007-08-30 20:45:51 +02:00
|
|
|
RECT r;
|
|
|
|
|
|
|
|
trace("Style %x\n", style);
|
|
|
|
GetClientRect(hCombo, &r);
|
2019-11-27 09:31:05 +01:00
|
|
|
expect_rect(r, 0, 0, 100, get_font_height(GetStockObject(SYSTEM_FONT)) + 8);
|
2007-08-30 20:45:51 +02:00
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
|
|
|
|
todo_wine expect_rect(r, 5, 5, 105, 105);
|
|
|
|
|
|
|
|
for (i = 1; i < 30; i++)
|
|
|
|
{
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_SETITEMHEIGHT, -1, i);
|
2007-08-30 20:45:51 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
|
|
|
expect_eq(r.bottom - r.top, i + 6, int, "%d");
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
2019-11-27 09:31:05 +01:00
|
|
|
|
|
|
|
/* Set item height below text height, force resize. */
|
|
|
|
hCombo = build_combo(style);
|
|
|
|
|
|
|
|
hFont = (HFONT)SendMessageA(hCombo, WM_GETFONT, 0, 0);
|
|
|
|
font_height = get_font_height(hFont);
|
|
|
|
SendMessageA(hCombo, CB_SETITEMHEIGHT, -1, font_height / 2);
|
|
|
|
height = SendMessageA(hCombo, CB_GETITEMHEIGHT, -1, 0);
|
|
|
|
todo_wine
|
|
|
|
ok(height == font_height / 2, "Unexpected item height %d, expected %d.\n", height, font_height / 2);
|
|
|
|
|
|
|
|
SetWindowPos(hCombo, NULL, 10, 10, 150, 5 * font_height, SWP_SHOWWINDOW);
|
|
|
|
height = SendMessageA(hCombo, CB_GETITEMHEIGHT, -1, 0);
|
|
|
|
ok(height > font_height, "Unexpected item height %d, font height %d.\n", height, font_height);
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
2007-08-30 20:45:51 +02:00
|
|
|
}
|
|
|
|
|
2007-03-26 11:25:21 +02:00
|
|
|
static void test_setfont(DWORD style)
|
|
|
|
{
|
2009-08-05 04:03:39 +02:00
|
|
|
HWND hCombo;
|
|
|
|
HFONT hFont1, hFont2;
|
2007-03-26 11:25:21 +02:00
|
|
|
RECT r;
|
|
|
|
int i;
|
|
|
|
|
2009-08-05 04:03:39 +02:00
|
|
|
if (!is_font_installed("Marlett"))
|
|
|
|
{
|
|
|
|
skip("Marlett font not available\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-26 11:25:21 +02:00
|
|
|
trace("Style %x\n", style);
|
2009-08-05 04:03:39 +02:00
|
|
|
|
|
|
|
hCombo = build_combo(style);
|
2013-10-23 07:53:22 +02:00
|
|
|
hFont1 = CreateFontA(10, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
|
|
|
|
hFont2 = CreateFontA(8, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
|
2009-08-05 04:03:39 +02:00
|
|
|
|
2007-03-26 11:25:21 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
2019-11-27 09:31:05 +01:00
|
|
|
expect_rect(r, 0, 0, 100, get_font_height(GetStockObject(SYSTEM_FONT)) + 8);
|
2007-03-26 11:25:21 +02:00
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
|
|
|
|
todo_wine expect_rect(r, 5, 5, 105, 105);
|
|
|
|
|
2010-10-26 06:45:12 +02:00
|
|
|
/* The size of the dropped control is initially equal to the size
|
|
|
|
of the window when it was created. The size of the calculated
|
|
|
|
dropped area changes only by how much the selection area
|
|
|
|
changes, not by how much the list area changes. */
|
2019-11-27 09:31:05 +01:00
|
|
|
if (get_font_height(hFont1) == 10 && get_font_height(hFont2) == 8)
|
2007-03-26 11:25:21 +02:00
|
|
|
{
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
|
2007-03-26 11:25:21 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
|
|
|
expect_rect(r, 0, 0, 100, 18);
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
|
2019-11-27 09:31:05 +01:00
|
|
|
todo_wine expect_rect(r, 5, 5, 105, 105 - (get_font_height(GetStockObject(SYSTEM_FONT)) - get_font_height(hFont1)));
|
2007-03-26 11:25:21 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont2, FALSE);
|
2007-03-26 11:25:21 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
|
|
|
expect_rect(r, 0, 0, 100, 16);
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
|
2019-11-27 09:31:05 +01:00
|
|
|
todo_wine expect_rect(r, 5, 5, 105, 105 - (get_font_height(GetStockObject(SYSTEM_FONT)) - get_font_height(hFont2)));
|
2007-03-26 11:25:21 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont1, FALSE);
|
2007-03-26 11:25:21 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
|
|
|
expect_rect(r, 0, 0, 100, 18);
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&r);
|
|
|
|
MapWindowPoints(HWND_DESKTOP, hMainWnd, (LPPOINT)&r, 2);
|
2019-11-27 09:31:05 +01:00
|
|
|
todo_wine expect_rect(r, 5, 5, 105, 105 - (get_font_height(GetStockObject(SYSTEM_FONT)) - get_font_height(hFont1)));
|
2007-03-26 11:25:21 +02:00
|
|
|
}
|
|
|
|
else
|
2009-08-05 04:03:39 +02:00
|
|
|
{
|
|
|
|
ok(0, "Expected Marlett font heights 10/8, got %d/%d\n",
|
2019-11-27 09:31:05 +01:00
|
|
|
get_font_height(hFont1), get_font_height(hFont2));
|
2009-08-05 04:03:39 +02:00
|
|
|
}
|
2007-03-26 11:25:21 +02:00
|
|
|
|
|
|
|
for (i = 1; i < 30; i++)
|
|
|
|
{
|
2013-10-23 07:53:22 +02:00
|
|
|
HFONT hFont = CreateFontA(i, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, SYMBOL_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Marlett");
|
2019-11-27 09:31:05 +01:00
|
|
|
int height = get_font_height(hFont);
|
2007-03-26 11:25:21 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFONT, (WPARAM)hFont, FALSE);
|
2007-03-26 11:25:21 +02:00
|
|
|
GetClientRect(hCombo, &r);
|
|
|
|
expect_eq(r.bottom - r.top, height + 8, int, "%d");
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFONT, 0, FALSE);
|
2007-03-26 11:25:21 +02:00
|
|
|
DeleteObject(hFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
DeleteObject(hFont1);
|
|
|
|
DeleteObject(hFont2);
|
|
|
|
}
|
|
|
|
|
2007-08-09 11:34:23 +02:00
|
|
|
static LRESULT (CALLBACK *old_parent_proc)(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam);
|
|
|
|
static LPCSTR expected_edit_text;
|
|
|
|
static LPCSTR expected_list_text;
|
2008-02-10 20:00:02 +01:00
|
|
|
static BOOL selchange_fired;
|
2019-11-04 08:30:27 +01:00
|
|
|
static HWND lparam_for_WM_CTLCOLOR;
|
|
|
|
static HBRUSH brush_red;
|
2007-08-09 11:34:23 +02:00
|
|
|
|
|
|
|
static LRESULT CALLBACK parent_wnd_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (wparam)
|
|
|
|
{
|
|
|
|
case MAKEWPARAM(COMBO_ID, CBN_SELCHANGE):
|
|
|
|
{
|
|
|
|
HWND hCombo = (HWND)lparam;
|
|
|
|
int idx;
|
|
|
|
char list[20], edit[20];
|
|
|
|
|
|
|
|
memset(list, 0, sizeof(list));
|
|
|
|
memset(edit, 0, sizeof(edit));
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
idx = SendMessageA(hCombo, CB_GETCURSEL, 0, 0);
|
|
|
|
SendMessageA(hCombo, CB_GETLBTEXT, idx, (LPARAM)list);
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
|
2007-08-09 11:34:23 +02:00
|
|
|
|
|
|
|
ok(!strcmp(edit, expected_edit_text), "edit: got %s, expected %s\n",
|
|
|
|
edit, expected_edit_text);
|
|
|
|
ok(!strcmp(list, expected_list_text), "list: got %s, expected %s\n",
|
|
|
|
list, expected_list_text);
|
2008-02-10 20:00:02 +01:00
|
|
|
|
|
|
|
selchange_fired = TRUE;
|
2007-08-09 11:34:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-04 08:30:27 +01:00
|
|
|
case WM_CTLCOLOR:
|
|
|
|
case WM_CTLCOLORMSGBOX:
|
|
|
|
case WM_CTLCOLOREDIT:
|
|
|
|
case WM_CTLCOLORLISTBOX:
|
|
|
|
case WM_CTLCOLORBTN:
|
|
|
|
case WM_CTLCOLORDLG:
|
|
|
|
case WM_CTLCOLORSCROLLBAR:
|
|
|
|
case WM_CTLCOLORSTATIC:
|
|
|
|
if (lparam_for_WM_CTLCOLOR)
|
|
|
|
{
|
|
|
|
ok(lparam_for_WM_CTLCOLOR == (HWND)lparam, "Expected %p, got %p\n", lparam_for_WM_CTLCOLOR, (HWND)lparam);
|
|
|
|
return (LRESULT) brush_red;
|
|
|
|
}
|
|
|
|
break;
|
2007-08-09 11:34:23 +02:00
|
|
|
}
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
return CallWindowProcA(old_parent_proc, hwnd, msg, wparam, lparam);
|
2007-08-09 11:34:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_selection(DWORD style, const char * const text[],
|
|
|
|
const int *edit, const int *list)
|
|
|
|
{
|
|
|
|
INT idx;
|
|
|
|
HWND hCombo;
|
|
|
|
|
|
|
|
hCombo = build_combo(style);
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)text[0]);
|
|
|
|
SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)text[1]);
|
|
|
|
SendMessageA(hCombo, CB_SETCURSEL, -1, 0);
|
2007-08-09 11:34:23 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
old_parent_proc = (void *)SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)parent_wnd_proc);
|
2007-08-09 11:34:23 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
idx = SendMessageA(hCombo, CB_GETCURSEL, 0, 0);
|
2007-08-09 11:34:23 +02:00
|
|
|
ok(idx == -1, "expected selection -1, got %d\n", idx);
|
|
|
|
|
2008-02-10 20:00:02 +01:00
|
|
|
/* keyboard navigation */
|
|
|
|
|
2007-08-09 11:34:23 +02:00
|
|
|
expected_list_text = text[list[0]];
|
|
|
|
expected_edit_text = text[edit[0]];
|
2008-02-10 20:00:02 +01:00
|
|
|
selchange_fired = FALSE;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_KEYDOWN, VK_DOWN, 0);
|
2008-02-10 20:00:02 +01:00
|
|
|
ok(selchange_fired, "CBN_SELCHANGE not sent!\n");
|
2007-08-09 11:34:23 +02:00
|
|
|
|
|
|
|
expected_list_text = text[list[1]];
|
|
|
|
expected_edit_text = text[edit[1]];
|
2008-02-10 20:00:02 +01:00
|
|
|
selchange_fired = FALSE;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_KEYDOWN, VK_DOWN, 0);
|
2008-02-10 20:00:02 +01:00
|
|
|
ok(selchange_fired, "CBN_SELCHANGE not sent!\n");
|
2007-08-09 11:34:23 +02:00
|
|
|
|
|
|
|
expected_list_text = text[list[2]];
|
|
|
|
expected_edit_text = text[edit[2]];
|
2008-02-10 20:00:02 +01:00
|
|
|
selchange_fired = FALSE;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_KEYDOWN, VK_UP, 0);
|
2008-02-10 20:00:02 +01:00
|
|
|
ok(selchange_fired, "CBN_SELCHANGE not sent!\n");
|
|
|
|
|
2008-04-22 08:18:14 +02:00
|
|
|
/* programmatic navigation */
|
2008-02-10 20:00:02 +01:00
|
|
|
|
|
|
|
expected_list_text = text[list[3]];
|
|
|
|
expected_edit_text = text[edit[3]];
|
|
|
|
selchange_fired = FALSE;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_SETCURSEL, list[3], 0);
|
2008-02-10 20:00:02 +01:00
|
|
|
ok(!selchange_fired, "CBN_SELCHANGE sent!\n");
|
|
|
|
|
|
|
|
expected_list_text = text[list[4]];
|
|
|
|
expected_edit_text = text[edit[4]];
|
|
|
|
selchange_fired = FALSE;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_SETCURSEL, list[4], 0);
|
2008-02-10 20:00:02 +01:00
|
|
|
ok(!selchange_fired, "CBN_SELCHANGE sent!\n");
|
2007-08-09 11:34:23 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)old_parent_proc);
|
2007-08-09 11:34:23 +02:00
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_CBN_SELCHANGE(void)
|
|
|
|
{
|
|
|
|
static const char * const text[] = { "alpha", "beta", "" };
|
2008-02-10 20:00:02 +01:00
|
|
|
static const int sel_1[] = { 2, 0, 1, 0, 1 };
|
|
|
|
static const int sel_2[] = { 0, 1, 0, 0, 1 };
|
2007-08-09 11:34:23 +02:00
|
|
|
|
|
|
|
test_selection(CBS_SIMPLE, text, sel_1, sel_2);
|
|
|
|
test_selection(CBS_DROPDOWN, text, sel_1, sel_2);
|
|
|
|
test_selection(CBS_DROPDOWNLIST, text, sel_2, sel_2);
|
|
|
|
}
|
|
|
|
|
2008-07-03 17:37:10 +02:00
|
|
|
static void test_WM_LBUTTONDOWN(void)
|
|
|
|
{
|
|
|
|
HWND hCombo, hEdit, hList;
|
|
|
|
COMBOBOXINFO cbInfo;
|
|
|
|
UINT x, y, item_height;
|
|
|
|
LRESULT result;
|
|
|
|
int i, idx;
|
|
|
|
RECT rect;
|
2008-10-07 07:54:52 +02:00
|
|
|
CHAR buffer[3];
|
2008-07-03 17:37:10 +02:00
|
|
|
static const UINT choices[] = {8,9,10,11,12,14,16,18,20,22,24,26,28,36,48,72};
|
2008-10-07 07:54:52 +02:00
|
|
|
static const CHAR stringFormat[] = "%2d";
|
|
|
|
BOOL ret;
|
2008-07-03 17:37:10 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
hCombo = CreateWindowA("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|CBS_DROPDOWN,
|
2008-07-03 17:37:10 +02:00
|
|
|
0, 0, 200, 150, hMainWnd, (HMENU)COMBO_ID, NULL, 0);
|
|
|
|
|
2018-06-28 18:17:01 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(choices); i++){
|
2008-10-07 07:54:52 +02:00
|
|
|
sprintf(buffer, stringFormat, choices[i]);
|
|
|
|
result = SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
|
|
ok(result == i,
|
2008-07-03 17:37:10 +02:00
|
|
|
"Failed to add item %d\n", i);
|
|
|
|
}
|
|
|
|
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
2008-10-07 07:54:52 +02:00
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &cbInfo);
|
2008-10-07 07:54:52 +02:00
|
|
|
ok(ret, "Failed to get combobox info structure. LastError=%d\n",
|
2008-07-03 17:37:10 +02:00
|
|
|
GetLastError());
|
|
|
|
hEdit = cbInfo.hwndItem;
|
|
|
|
hList = cbInfo.hwndList;
|
|
|
|
|
2009-01-03 20:16:33 +01:00
|
|
|
trace("hMainWnd=%p, hCombo=%p, hList=%p, hEdit=%p\n", hMainWnd, hCombo, hList, hEdit);
|
|
|
|
ok(GetFocus() == hMainWnd, "Focus not on Main Window, instead on %p\n", GetFocus());
|
2008-07-03 17:37:10 +02:00
|
|
|
|
|
|
|
/* Click on the button to drop down the list */
|
|
|
|
x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2;
|
|
|
|
y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2;
|
2013-10-23 07:53:22 +02:00
|
|
|
result = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
2013-10-23 07:53:22 +02:00
|
|
|
ok(SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0),
|
2008-07-03 17:37:10 +02:00
|
|
|
"The dropdown list should have appeared after clicking the button.\n");
|
|
|
|
|
|
|
|
ok(GetFocus() == hEdit,
|
2009-01-03 20:16:33 +01:00
|
|
|
"Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
|
2013-10-23 07:53:22 +02:00
|
|
|
result = SendMessageA(hCombo, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(result, "WM_LBUTTONUP was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(GetFocus() == hEdit,
|
2009-01-03 20:16:33 +01:00
|
|
|
"Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
|
2008-07-03 17:37:10 +02:00
|
|
|
|
|
|
|
/* Click on the 5th item in the list */
|
2013-10-23 07:53:22 +02:00
|
|
|
item_height = SendMessageA(hCombo, CB_GETITEMHEIGHT, 0, 0);
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(GetClientRect(hList, &rect), "Failed to get list's client rect.\n");
|
|
|
|
x = rect.left + (rect.right-rect.left)/2;
|
|
|
|
y = item_height/2 + item_height*4;
|
2013-10-23 07:53:22 +02:00
|
|
|
result = SendMessageA(hList, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(!result, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(GetFocus() == hEdit,
|
2009-01-03 20:16:33 +01:00
|
|
|
"Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
|
2008-07-03 17:37:10 +02:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
result = SendMessageA(hList, WM_MOUSEMOVE, 0, MAKELPARAM(x, y));
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(!result, "WM_MOUSEMOVE was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(GetFocus() == hEdit,
|
2009-01-03 20:16:33 +01:00
|
|
|
"Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
|
2013-10-23 07:53:22 +02:00
|
|
|
ok(SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0),
|
2008-07-03 17:37:10 +02:00
|
|
|
"The dropdown list should still be visible.\n");
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
result = SendMessageA(hList, WM_LBUTTONUP, 0, MAKELPARAM(x, y));
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(!result, "WM_LBUTTONUP was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(GetFocus() == hEdit,
|
2009-01-03 20:16:33 +01:00
|
|
|
"Focus not on ComboBox's Edit Control, instead on %p\n", GetFocus());
|
2013-10-23 07:53:22 +02:00
|
|
|
ok(!SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0),
|
2008-07-03 17:37:10 +02:00
|
|
|
"The dropdown list should have been rolled up.\n");
|
2013-10-23 07:53:22 +02:00
|
|
|
idx = SendMessageA(hCombo, CB_GETCURSEL, 0, 0);
|
2008-07-03 17:37:10 +02:00
|
|
|
ok(idx, "Current Selection: expected %d, got %d\n", 4, idx);
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
2009-04-03 07:49:34 +02:00
|
|
|
static void test_changesize( DWORD style)
|
|
|
|
{
|
|
|
|
HWND hCombo = build_combo(style);
|
|
|
|
RECT rc;
|
|
|
|
INT ddheight, clheight, ddwidth, clwidth;
|
|
|
|
/* get initial measurements */
|
|
|
|
GetClientRect( hCombo, &rc);
|
|
|
|
clheight = rc.bottom - rc.top;
|
|
|
|
clwidth = rc.right - rc.left;
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&rc);
|
|
|
|
ddheight = rc.bottom - rc.top;
|
|
|
|
ddwidth = rc.right - rc.left;
|
|
|
|
/* use MoveWindow to move & resize the combo */
|
|
|
|
/* first make it slightly smaller */
|
|
|
|
MoveWindow( hCombo, 10, 10, clwidth - 2, clheight - 2, TRUE);
|
|
|
|
GetClientRect( hCombo, &rc);
|
2015-11-26 23:23:09 +01:00
|
|
|
ok( rc.right - rc.left == clwidth - 2, "clientrect width is %d vs %d\n",
|
2009-04-03 07:49:34 +02:00
|
|
|
rc.right - rc.left, clwidth - 2);
|
|
|
|
ok( rc.bottom - rc.top == clheight, "clientrect height is %d vs %d\n",
|
|
|
|
rc.bottom - rc.top, clheight);
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&rc);
|
2015-11-26 23:23:09 +01:00
|
|
|
ok( rc.right - rc.left == clwidth - 2, "drop-down rect width is %d vs %d\n",
|
2009-04-03 07:49:34 +02:00
|
|
|
rc.right - rc.left, clwidth - 2);
|
|
|
|
ok( rc.bottom - rc.top == ddheight, "drop-down rect height is %d vs %d\n",
|
|
|
|
rc.bottom - rc.top, ddheight);
|
2010-05-22 09:25:13 +02:00
|
|
|
ok( rc.right - rc.left == ddwidth -2, "drop-down rect width is %d vs %d\n",
|
|
|
|
rc.right - rc.left, ddwidth - 2);
|
2009-04-20 14:47:23 +02:00
|
|
|
/* new cx, cy is slightly bigger than the initial values */
|
2009-04-03 07:49:34 +02:00
|
|
|
MoveWindow( hCombo, 10, 10, clwidth + 2, clheight + 2, TRUE);
|
|
|
|
GetClientRect( hCombo, &rc);
|
2015-11-26 23:23:09 +01:00
|
|
|
ok( rc.right - rc.left == clwidth + 2, "clientrect width is %d vs %d\n",
|
2009-04-03 07:49:34 +02:00
|
|
|
rc.right - rc.left, clwidth + 2);
|
|
|
|
ok( rc.bottom - rc.top == clheight, "clientrect height is %d vs %d\n",
|
|
|
|
rc.bottom - rc.top, clheight);
|
|
|
|
SendMessageA(hCombo, CB_GETDROPPEDCONTROLRECT, 0, (LPARAM)&rc);
|
2015-11-26 23:23:09 +01:00
|
|
|
ok( rc.right - rc.left == clwidth + 2, "drop-down rect width is %d vs %d\n",
|
2009-04-03 07:49:34 +02:00
|
|
|
rc.right - rc.left, clwidth + 2);
|
|
|
|
todo_wine {
|
|
|
|
ok( rc.bottom - rc.top == clheight + 2, "drop-down rect height is %d vs %d\n",
|
|
|
|
rc.bottom - rc.top, clheight + 2);
|
|
|
|
}
|
2011-08-22 03:23:06 +02:00
|
|
|
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, -1, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
2011-08-22 03:23:06 +02:00
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
2011-08-22 03:23:06 +02:00
|
|
|
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, 0, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
2011-08-22 03:23:06 +02:00
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
|
|
|
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, clwidth - 1, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
2011-08-22 03:23:06 +02:00
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
2011-08-22 03:23:06 +02:00
|
|
|
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, clwidth << 1, 0);
|
2011-09-01 07:30:50 +02:00
|
|
|
ok( ddwidth == (clwidth << 1), "drop-width is %d vs %d\n", ddwidth, clwidth << 1);
|
2011-08-22 03:23:06 +02:00
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
|
|
|
ok( ddwidth == (clwidth << 1), "drop-width is %d vs %d\n", ddwidth, clwidth << 1);
|
|
|
|
|
2011-09-01 07:30:50 +02:00
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, 0, 0);
|
|
|
|
ok( ddwidth == (clwidth << 1), "drop-width is %d vs %d\n", ddwidth, clwidth << 1);
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
|
|
|
ok( ddwidth == (clwidth << 1), "drop-width is %d vs %d\n", ddwidth, clwidth << 1);
|
|
|
|
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_SETDROPPEDWIDTH, 1, 0);
|
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
|
|
|
ddwidth = SendMessageA(hCombo, CB_GETDROPPEDWIDTH, 0, 0);
|
|
|
|
ok( ddwidth == clwidth + 2, "drop-width is %d vs %d\n", ddwidth, clwidth + 2);
|
|
|
|
|
2009-04-03 07:49:34 +02:00
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
2010-01-24 21:37:59 +01:00
|
|
|
static void test_editselection(void)
|
|
|
|
{
|
|
|
|
HWND hCombo;
|
|
|
|
INT start,end;
|
|
|
|
HWND hEdit;
|
|
|
|
COMBOBOXINFO cbInfo;
|
|
|
|
BOOL ret;
|
|
|
|
DWORD len;
|
|
|
|
char edit[20];
|
|
|
|
|
|
|
|
/* Build a combo */
|
|
|
|
hCombo = build_combo(CBS_SIMPLE);
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &cbInfo);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(ret, "Failed to get combobox info structure. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
hEdit = cbInfo.hwndItem;
|
|
|
|
|
|
|
|
/* Initially combo selection is empty*/
|
2013-10-23 07:53:22 +02:00
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
|
|
|
|
ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
|
|
|
|
|
|
|
|
/* Set some text, and press a key to replace it */
|
|
|
|
edit[0] = 0x00;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason1");
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(strcmp(edit, "Jason1")==0, "Unexpected text retrieved %s\n", edit);
|
|
|
|
|
|
|
|
/* Now what is the selection - still empty */
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
|
2016-01-14 10:05:01 +01:00
|
|
|
ok(start==0, "Unexpected start position for selection %d\n", start);
|
|
|
|
ok(end==0, "Unexpected end position for selection %d\n", end);
|
2013-10-23 07:53:22 +02:00
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
|
|
|
|
ok(HIWORD(len)==0, "Unexpected end position for selection %d\n", HIWORD(len));
|
|
|
|
|
|
|
|
/* Give it focus, and it gets selected */
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
|
|
|
|
SendMessageA(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
|
2016-01-14 10:05:01 +01:00
|
|
|
ok(start==0, "Unexpected start position for selection %d\n", start);
|
|
|
|
ok(end==6, "Unexpected end position for selection %d\n", end);
|
2013-10-23 07:53:22 +02:00
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
|
2010-01-24 21:56:11 +01:00
|
|
|
ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
|
2010-01-24 21:37:59 +01:00
|
|
|
|
|
|
|
/* Now emulate a key press */
|
|
|
|
edit[0] = 0x00;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_CHAR, 'A', 0x1c0001);
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
|
2010-01-24 21:56:11 +01:00
|
|
|
ok(strcmp(edit, "A")==0, "Unexpected text retrieved %s\n", edit);
|
2010-01-24 21:37:59 +01:00
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len));
|
|
|
|
ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len));
|
|
|
|
|
2010-03-20 15:24:53 +01:00
|
|
|
/* Now what happens when it gets more focus a second time - it doesn't reselect */
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
|
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==1, "Unexpected start position for selection %d\n", LOWORD(len));
|
|
|
|
ok(HIWORD(len)==1, "Unexpected end position for selection %d\n", HIWORD(len));
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
|
|
|
|
/* Start again - Build a combo */
|
|
|
|
hCombo = build_combo(CBS_SIMPLE);
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &cbInfo);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(ret, "Failed to get combobox info structure. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
hEdit = cbInfo.hwndItem;
|
|
|
|
|
|
|
|
/* Set some text and give focus so it gets selected */
|
|
|
|
edit[0] = 0x00;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETTEXT, 0, (LPARAM)"Jason2");
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(strcmp(edit, "Jason2")==0, "Unexpected text retrieved %s\n", edit);
|
|
|
|
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
|
2010-01-24 21:37:59 +01:00
|
|
|
|
|
|
|
/* Now what is the selection */
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_GETEDITSEL, (WPARAM)&start, (WPARAM)&end);
|
2016-01-14 10:05:01 +01:00
|
|
|
ok(start==0, "Unexpected start position for selection %d\n", start);
|
|
|
|
ok(end==6, "Unexpected end position for selection %d\n", end);
|
2013-10-23 07:53:22 +02:00
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0,0);
|
2010-01-24 21:37:59 +01:00
|
|
|
ok(LOWORD(len)==0, "Unexpected start position for selection %d\n", LOWORD(len));
|
2010-01-24 21:56:11 +01:00
|
|
|
ok(HIWORD(len)==6, "Unexpected end position for selection %d\n", HIWORD(len));
|
2010-01-24 21:37:59 +01:00
|
|
|
|
|
|
|
/* Now change the selection to the apparently invalid start -1, end -1 and
|
|
|
|
show it means no selection (ie start -1) but cursor at end */
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, CB_SETEDITSEL, 0, -1);
|
2010-01-24 21:37:59 +01:00
|
|
|
edit[0] = 0x00;
|
2013-10-23 07:53:22 +02:00
|
|
|
SendMessageA(hCombo, WM_CHAR, 'A', 0x1c0001);
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(edit), (LPARAM)edit);
|
2010-01-24 21:56:11 +01:00
|
|
|
ok(strcmp(edit, "Jason2A")==0, "Unexpected text retrieved %s\n", edit);
|
2010-01-24 21:37:59 +01:00
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
2015-12-31 14:00:20 +01:00
|
|
|
static WNDPROC edit_window_proc;
|
|
|
|
static long setsel_start = 1, setsel_end = 1;
|
|
|
|
static HWND hCBN_SetFocus, hCBN_KillFocus;
|
|
|
|
|
|
|
|
static LRESULT CALLBACK combobox_subclass_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
if (msg == EM_SETSEL)
|
|
|
|
{
|
|
|
|
setsel_start = wParam;
|
|
|
|
setsel_end = lParam;
|
|
|
|
}
|
|
|
|
return CallWindowProcA(edit_window_proc, hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
static LRESULT CALLBACK test_window_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (msg)
|
|
|
|
{
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (HIWORD(wParam))
|
|
|
|
{
|
|
|
|
case CBN_SETFOCUS:
|
|
|
|
hCBN_SetFocus = (HWND)lParam;
|
|
|
|
break;
|
|
|
|
case CBN_KILLFOCUS:
|
|
|
|
hCBN_KillFocus = (HWND)lParam;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_NEXTDLGCTL:
|
|
|
|
SetFocus((HWND)wParam);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return CallWindowProcA(old_parent_proc, hwnd, msg, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void test_editselection_focus(DWORD style)
|
|
|
|
{
|
|
|
|
HWND hCombo, hEdit, hButton;
|
|
|
|
COMBOBOXINFO cbInfo;
|
|
|
|
BOOL ret;
|
|
|
|
const char wine_test[] = "Wine Test";
|
|
|
|
char buffer[16] = {0};
|
|
|
|
DWORD len;
|
|
|
|
|
|
|
|
hCombo = build_combo(style);
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &cbInfo);
|
2015-12-31 14:00:20 +01:00
|
|
|
ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
|
|
|
|
hEdit = cbInfo.hwndItem;
|
|
|
|
|
|
|
|
hButton = CreateWindowA("Button", "OK", WS_VISIBLE|WS_CHILD|BS_DEFPUSHBUTTON,
|
|
|
|
5, 50, 100, 20, hMainWnd, NULL,
|
|
|
|
(HINSTANCE)GetWindowLongPtrA(hMainWnd, GWLP_HINSTANCE), NULL);
|
|
|
|
|
|
|
|
old_parent_proc = (WNDPROC)SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)test_window_proc);
|
|
|
|
edit_window_proc = (WNDPROC)SetWindowLongPtrA(hEdit, GWLP_WNDPROC, (ULONG_PTR)combobox_subclass_proc);
|
|
|
|
|
|
|
|
SendMessageA(hCombo, WM_SETFOCUS, 0, (LPARAM)hEdit);
|
|
|
|
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
|
|
|
|
todo_wine ok(setsel_end == INT_MAX, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
|
|
|
|
ok(hCBN_SetFocus == hCombo, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus);
|
|
|
|
ok(GetFocus() == hEdit, "hEdit should have keyboard focus\n");
|
|
|
|
|
|
|
|
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hButton, TRUE);
|
|
|
|
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
|
|
|
|
todo_wine ok(setsel_end == 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
|
|
|
|
ok(hCBN_KillFocus == hCombo, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus);
|
|
|
|
ok(GetFocus() == hButton, "hButton should have keyboard focus\n");
|
|
|
|
|
|
|
|
SendMessageA(hCombo, WM_SETTEXT, 0, (LPARAM)wine_test);
|
|
|
|
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hCombo, TRUE);
|
|
|
|
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
|
|
|
|
todo_wine ok(setsel_end == INT_MAX, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
|
|
|
|
ok(hCBN_SetFocus == hCombo, "Wrong handle set by CBN_SETFOCUS; got %p\n", hCBN_SetFocus);
|
|
|
|
ok(GetFocus() == hEdit, "hEdit should have keyboard focus\n");
|
|
|
|
SendMessageA(hCombo, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
|
|
|
|
ok(!strcmp(buffer, wine_test), "Unexpected text in edit control; got '%s'\n", buffer);
|
|
|
|
|
|
|
|
SendMessageA(hMainWnd, WM_NEXTDLGCTL, (WPARAM)hButton, TRUE);
|
|
|
|
ok(setsel_start == 0, "Unexpected EM_SETSEL start value; got %ld\n", setsel_start);
|
|
|
|
todo_wine ok(setsel_end == 0, "Unexpected EM_SETSEL end value; got %ld\n", setsel_end);
|
|
|
|
ok(hCBN_KillFocus == hCombo, "Wrong handle set by CBN_KILLFOCUS; got %p\n", hCBN_KillFocus);
|
|
|
|
ok(GetFocus() == hButton, "hButton should have keyboard focus\n");
|
|
|
|
len = SendMessageA(hCombo, CB_GETEDITSEL, 0, 0);
|
|
|
|
ok(len == 0, "Unexpected text selection; start: %u, end: %u\n", LOWORD(len), HIWORD(len));
|
|
|
|
|
|
|
|
SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)old_parent_proc);
|
|
|
|
DestroyWindow(hButton);
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
2014-11-07 17:48:49 +01:00
|
|
|
static void test_listbox_styles(DWORD cb_style)
|
|
|
|
{
|
|
|
|
HWND combo;
|
|
|
|
COMBOBOXINFO info;
|
|
|
|
DWORD style, exstyle, expect_style, expect_exstyle;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
expect_style = WS_CHILD|WS_CLIPSIBLINGS|LBS_COMBOBOX|LBS_HASSTRINGS|LBS_NOTIFY;
|
|
|
|
if (cb_style == CBS_SIMPLE)
|
|
|
|
{
|
|
|
|
expect_style |= WS_VISIBLE;
|
|
|
|
expect_exstyle = WS_EX_CLIENTEDGE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
expect_style |= WS_BORDER;
|
|
|
|
expect_exstyle = WS_EX_TOOLWINDOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
combo = build_combo(cb_style);
|
|
|
|
info.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(combo, &info);
|
2014-11-07 17:48:49 +01:00
|
|
|
ok(ret, "Failed to get combobox info structure.\n");
|
|
|
|
|
|
|
|
style = GetWindowLongW( info.hwndList, GWL_STYLE );
|
|
|
|
exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE );
|
|
|
|
ok(style == expect_style, "%08x: got %08x\n", cb_style, style);
|
|
|
|
ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle);
|
|
|
|
|
|
|
|
if (cb_style != CBS_SIMPLE)
|
|
|
|
expect_exstyle |= WS_EX_TOPMOST;
|
|
|
|
|
|
|
|
SendMessageW(combo, CB_SHOWDROPDOWN, TRUE, 0 );
|
|
|
|
style = GetWindowLongW( info.hwndList, GWL_STYLE );
|
|
|
|
exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE );
|
|
|
|
ok(style == (expect_style | WS_VISIBLE), "%08x: got %08x\n", cb_style, style);
|
|
|
|
ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle);
|
|
|
|
|
|
|
|
SendMessageW(combo, CB_SHOWDROPDOWN, FALSE, 0 );
|
|
|
|
style = GetWindowLongW( info.hwndList, GWL_STYLE );
|
|
|
|
exstyle = GetWindowLongW( info.hwndList, GWL_EXSTYLE );
|
|
|
|
ok(style == expect_style, "%08x: got %08x\n", cb_style, style);
|
|
|
|
ok(exstyle == expect_exstyle, "%08x: got %08x\n", cb_style, exstyle);
|
|
|
|
|
|
|
|
DestroyWindow(combo);
|
|
|
|
}
|
|
|
|
|
2017-08-17 18:24:57 +02:00
|
|
|
static void test_listbox_size(DWORD style)
|
|
|
|
{
|
|
|
|
HWND hCombo, hList;
|
|
|
|
COMBOBOXINFO cbInfo;
|
|
|
|
UINT x, y;
|
|
|
|
BOOL ret;
|
|
|
|
int i, test;
|
|
|
|
const char wine_test[] = "Wine Test";
|
|
|
|
|
|
|
|
static const struct list_size_info
|
|
|
|
{
|
|
|
|
int num_items;
|
|
|
|
int height_combo;
|
|
|
|
BOOL todo;
|
|
|
|
} info_height[] = {
|
2018-08-19 21:03:54 +02:00
|
|
|
{2, 24, FALSE},
|
2017-08-17 18:24:57 +02:00
|
|
|
{2, 41, TRUE},
|
2018-08-19 21:03:54 +02:00
|
|
|
{2, 42, FALSE},
|
|
|
|
{2, 50, FALSE},
|
2017-08-17 18:24:57 +02:00
|
|
|
{2, 60},
|
|
|
|
{2, 80},
|
|
|
|
{2, 89},
|
|
|
|
{2, 90},
|
|
|
|
{2, 100},
|
|
|
|
|
2018-08-19 21:03:54 +02:00
|
|
|
{10, 24, FALSE},
|
2017-08-17 18:24:57 +02:00
|
|
|
{10, 41, TRUE},
|
2018-08-19 21:03:54 +02:00
|
|
|
{10, 42, FALSE},
|
|
|
|
{10, 50, FALSE},
|
|
|
|
{10, 60, FALSE},
|
|
|
|
{10, 80, FALSE},
|
2017-08-17 18:24:57 +02:00
|
|
|
{10, 89, TRUE},
|
2018-08-19 21:03:54 +02:00
|
|
|
{10, 90, FALSE},
|
|
|
|
{10, 100, FALSE},
|
2017-08-17 18:24:57 +02:00
|
|
|
};
|
|
|
|
|
2018-06-28 18:17:01 +02:00
|
|
|
for(test = 0; test < ARRAY_SIZE(info_height); test++)
|
2017-08-17 18:24:57 +02:00
|
|
|
{
|
|
|
|
const struct list_size_info *info_test = &info_height[test];
|
|
|
|
int height_item; /* Height of a list item */
|
|
|
|
int height_list; /* Height of the list we got */
|
|
|
|
int expected_count_list;
|
|
|
|
int expected_height_list;
|
|
|
|
int list_height_nonclient;
|
|
|
|
int list_height_calculated;
|
|
|
|
RECT rect_list_client, rect_list_complete;
|
|
|
|
|
|
|
|
hCombo = CreateWindowA("ComboBox", "Combo", WS_VISIBLE|WS_CHILD|style, 5, 5, 100,
|
|
|
|
info_test->height_combo, hMainWnd, (HMENU)COMBO_ID, NULL, 0);
|
|
|
|
|
|
|
|
cbInfo.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &cbInfo);
|
2017-08-17 18:24:57 +02:00
|
|
|
ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
|
|
|
|
|
|
|
|
hList = cbInfo.hwndList;
|
|
|
|
for (i = 0; i < info_test->num_items; i++)
|
|
|
|
SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM) wine_test);
|
|
|
|
|
|
|
|
/* Click on the button to drop down the list */
|
|
|
|
x = cbInfo.rcButton.left + (cbInfo.rcButton.right-cbInfo.rcButton.left)/2;
|
|
|
|
y = cbInfo.rcButton.top + (cbInfo.rcButton.bottom-cbInfo.rcButton.top)/2;
|
|
|
|
ret = SendMessageA(hCombo, WM_LBUTTONDOWN, 0, MAKELPARAM(x, y));
|
|
|
|
ok(ret, "WM_LBUTTONDOWN was not processed. LastError=%d\n",
|
|
|
|
GetLastError());
|
|
|
|
ok(SendMessageA(hCombo, CB_GETDROPPEDSTATE, 0, 0),
|
|
|
|
"The dropdown list should have appeared after clicking the button.\n");
|
|
|
|
|
|
|
|
GetClientRect(hList, &rect_list_client);
|
|
|
|
GetWindowRect(hList, &rect_list_complete);
|
|
|
|
height_list = rect_list_client.bottom - rect_list_client.top;
|
|
|
|
height_item = (int)SendMessageA(hList, LB_GETITEMHEIGHT, 0, 0);
|
|
|
|
|
|
|
|
list_height_nonclient = (rect_list_complete.bottom - rect_list_complete.top)
|
|
|
|
- (rect_list_client.bottom - rect_list_client.top);
|
|
|
|
|
|
|
|
/* Calculate the expected client size of the listbox popup from the size of the combobox. */
|
|
|
|
list_height_calculated = info_test->height_combo
|
|
|
|
- (cbInfo.rcItem.bottom + COMBO_YBORDERSIZE())
|
|
|
|
- list_height_nonclient
|
|
|
|
- 1;
|
|
|
|
|
|
|
|
expected_count_list = list_height_calculated / height_item;
|
|
|
|
if(expected_count_list < 0)
|
|
|
|
expected_count_list = 0;
|
|
|
|
expected_count_list = min(expected_count_list, info_test->num_items);
|
|
|
|
expected_height_list = expected_count_list * height_item;
|
|
|
|
|
|
|
|
todo_wine_if(info_test->todo)
|
|
|
|
ok(expected_height_list == height_list,
|
|
|
|
"Test %d, expected list height to be %d, got %d\n", test, expected_height_list, height_list);
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-04 15:54:46 +01:00
|
|
|
static void test_WS_VSCROLL(void)
|
2017-11-11 21:56:40 +01:00
|
|
|
{
|
|
|
|
HWND hCombo, hList;
|
|
|
|
COMBOBOXINFO info;
|
|
|
|
DWORD style;
|
|
|
|
BOOL ret;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
info.cbSize = sizeof(info);
|
|
|
|
hCombo = build_combo(CBS_DROPDOWNLIST);
|
|
|
|
|
|
|
|
SetLastError(0xdeadbeef);
|
2018-02-08 12:12:27 +01:00
|
|
|
ret = GetComboBoxInfo(hCombo, &info);
|
2017-11-11 21:56:40 +01:00
|
|
|
ok(ret, "Failed to get COMBOBOXINFO structure; LastError: %u\n", GetLastError());
|
|
|
|
hList = info.hwndList;
|
|
|
|
|
|
|
|
for(i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
char buffer[2];
|
|
|
|
sprintf(buffer, "%d", i);
|
|
|
|
SendMessageA(hCombo, CB_ADDSTRING, 0, (LPARAM)buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
style = GetWindowLongA(info.hwndList, GWL_STYLE);
|
|
|
|
SetWindowLongA(hList, GWL_STYLE, style | WS_VSCROLL);
|
|
|
|
|
|
|
|
SendMessageA(hCombo, CB_SHOWDROPDOWN, TRUE, 0);
|
|
|
|
SendMessageA(hCombo, CB_SHOWDROPDOWN, FALSE, 0);
|
|
|
|
|
|
|
|
style = GetWindowLongA(hList, GWL_STYLE);
|
|
|
|
ok((style & WS_VSCROLL) != 0, "Style does not include WS_VSCROLL\n");
|
|
|
|
|
|
|
|
DestroyWindow(hCombo);
|
|
|
|
}
|
|
|
|
|
2019-11-04 08:30:27 +01:00
|
|
|
static void test_combo_ctlcolor(void)
|
|
|
|
{
|
|
|
|
static const int messages[] =
|
|
|
|
{
|
|
|
|
WM_CTLCOLOR,
|
|
|
|
WM_CTLCOLORMSGBOX,
|
|
|
|
WM_CTLCOLOREDIT,
|
|
|
|
WM_CTLCOLORLISTBOX,
|
|
|
|
WM_CTLCOLORBTN,
|
|
|
|
WM_CTLCOLORDLG,
|
|
|
|
WM_CTLCOLORSCROLLBAR,
|
|
|
|
WM_CTLCOLORSTATIC,
|
|
|
|
};
|
|
|
|
|
|
|
|
HBRUSH brush, global_brush;
|
|
|
|
unsigned int i, ret;
|
|
|
|
COMBOBOXINFO info;
|
|
|
|
HWND combo;
|
|
|
|
|
|
|
|
combo = build_combo(CBS_DROPDOWN);
|
|
|
|
ok(!!combo, "Failed to create combo window.\n");
|
|
|
|
|
|
|
|
old_parent_proc = (void *)SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)parent_wnd_proc);
|
|
|
|
|
|
|
|
info.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
ret = GetComboBoxInfo(combo, &info);
|
|
|
|
ok(ret, "Failed to get combobox info structure.\n");
|
|
|
|
|
|
|
|
lparam_for_WM_CTLCOLOR = info.hwndItem;
|
|
|
|
|
|
|
|
/* Parent returns valid brush handle. */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(messages); ++i)
|
|
|
|
{
|
|
|
|
brush = (HBRUSH)SendMessageA(combo, messages[i], 0, (LPARAM)info.hwndItem);
|
|
|
|
ok(brush == brush_red, "%u: unexpected brush %p, expected got %p.\n", i, brush, brush_red);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Parent returns NULL brush. */
|
|
|
|
global_brush = brush_red;
|
|
|
|
brush_red = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(messages); ++i)
|
|
|
|
{
|
|
|
|
brush = (HBRUSH)SendMessageA(combo, messages[i], 0, (LPARAM)info.hwndItem);
|
|
|
|
ok(!brush, "%u: unexpected brush %p.\n", i, brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
brush_red = global_brush;
|
|
|
|
|
|
|
|
lparam_for_WM_CTLCOLOR = 0;
|
|
|
|
|
|
|
|
/* Parent does default processing. */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(messages); ++i)
|
|
|
|
{
|
|
|
|
brush = (HBRUSH)SendMessageA(combo, messages[i], 0, (LPARAM)info.hwndItem);
|
|
|
|
ok(!!brush && brush != brush_red, "%u: unexpected brush %p.\n", i, brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetWindowLongPtrA(hMainWnd, GWLP_WNDPROC, (ULONG_PTR)old_parent_proc);
|
|
|
|
DestroyWindow(combo);
|
|
|
|
|
|
|
|
/* Combo without a parent. */
|
|
|
|
combo = CreateWindowA("ComboBox", "Combo", CBS_DROPDOWN, 5, 5, 100, 100, NULL, NULL, NULL, 0);
|
|
|
|
ok(!!combo, "Failed to create combo window.\n");
|
|
|
|
|
|
|
|
info.cbSize = sizeof(COMBOBOXINFO);
|
|
|
|
ret = GetComboBoxInfo(combo, &info);
|
|
|
|
ok(ret, "Failed to get combobox info structure.\n");
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(messages); ++i)
|
|
|
|
{
|
|
|
|
brush = (HBRUSH)SendMessageA(combo, messages[i], 0, (LPARAM)info.hwndItem);
|
|
|
|
ok(!!brush && brush != brush_red, "%u: unexpected brush %p.\n", i, brush);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(combo);
|
|
|
|
}
|
|
|
|
|
2007-03-26 11:25:21 +02:00
|
|
|
START_TEST(combo)
|
|
|
|
{
|
2019-11-04 08:30:27 +01:00
|
|
|
brush_red = CreateSolidBrush(RGB(255, 0, 0));
|
2013-10-23 07:53:22 +02:00
|
|
|
hMainWnd = CreateWindowA("static", "Test", WS_OVERLAPPEDWINDOW, 10, 10, 300, 300, NULL, NULL, NULL, 0);
|
2007-03-26 11:25:21 +02:00
|
|
|
ShowWindow(hMainWnd, SW_SHOW);
|
|
|
|
|
2017-11-11 21:56:40 +01:00
|
|
|
test_WS_VSCROLL();
|
2007-03-26 11:25:21 +02:00
|
|
|
test_setfont(CBS_DROPDOWN);
|
|
|
|
test_setfont(CBS_DROPDOWNLIST);
|
2007-08-30 20:45:51 +02:00
|
|
|
test_setitemheight(CBS_DROPDOWN);
|
|
|
|
test_setitemheight(CBS_DROPDOWNLIST);
|
2007-08-09 11:34:23 +02:00
|
|
|
test_CBN_SELCHANGE();
|
2008-07-03 17:37:10 +02:00
|
|
|
test_WM_LBUTTONDOWN();
|
2009-04-03 07:49:34 +02:00
|
|
|
test_changesize(CBS_DROPDOWN);
|
|
|
|
test_changesize(CBS_DROPDOWNLIST);
|
2010-01-24 21:37:59 +01:00
|
|
|
test_editselection();
|
2015-12-31 14:00:20 +01:00
|
|
|
test_editselection_focus(CBS_SIMPLE);
|
|
|
|
test_editselection_focus(CBS_DROPDOWN);
|
2014-11-07 17:48:49 +01:00
|
|
|
test_listbox_styles(CBS_SIMPLE);
|
|
|
|
test_listbox_styles(CBS_DROPDOWN);
|
|
|
|
test_listbox_styles(CBS_DROPDOWNLIST);
|
2017-08-17 18:24:57 +02:00
|
|
|
test_listbox_size(CBS_DROPDOWN);
|
2019-11-04 08:30:27 +01:00
|
|
|
test_combo_ctlcolor();
|
2007-08-09 11:34:23 +02:00
|
|
|
|
2007-03-26 11:25:21 +02:00
|
|
|
DestroyWindow(hMainWnd);
|
2019-11-04 08:30:27 +01:00
|
|
|
DeleteObject(brush_red);
|
2007-03-26 11:25:21 +02:00
|
|
|
}
|