push 01e509a9d6ecea02fa65e0980b6576cec4de2209
[wine/hacks.git] / dlls / comctl32 / tests / tooltips.c
blobc945a27f5db4b5d7b47deddf99be0c818cb59fbc
1 /*
2 * Copyright 2005 Dmitry Timoshkov
3 * Copyright 2008 Jason Edmeades
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include <assert.h>
21 #include <windows.h>
22 #include <commctrl.h>
24 #include "wine/test.h"
26 static void test_create_tooltip(void)
28 HWND parent, hwnd;
29 DWORD style, exp_style;
31 parent = CreateWindowEx(0, "static", NULL, WS_POPUP,
32 0, 0, 0, 0,
33 NULL, NULL, NULL, 0);
34 assert(parent);
36 hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0x7fffffff | WS_POPUP,
37 10, 10, 300, 100,
38 parent, NULL, NULL, 0);
39 assert(hwnd);
41 style = GetWindowLong(hwnd, GWL_STYLE);
42 trace("style = %08x\n", style);
43 exp_style = 0x7fffffff | WS_POPUP;
44 exp_style &= ~(WS_CHILD | WS_MAXIMIZE | WS_BORDER | WS_DLGFRAME);
45 ok(style == exp_style,"wrong style %08x/%08x\n", style, exp_style);
47 DestroyWindow(hwnd);
49 hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0,
50 10, 10, 300, 100,
51 parent, NULL, NULL, 0);
52 assert(hwnd);
54 style = GetWindowLong(hwnd, GWL_STYLE);
55 trace("style = %08x\n", style);
56 ok(style == (WS_POPUP | WS_CLIPSIBLINGS | WS_BORDER),
57 "wrong style %08x\n", style);
59 DestroyWindow(hwnd);
61 DestroyWindow(parent);
64 /* try to make sure pending X events have been processed before continuing */
65 static void flush_events(int waitTime)
67 MSG msg;
68 int diff = waitTime;
69 DWORD time = GetTickCount() + waitTime;
71 while (diff > 0)
73 if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min(100,diff), QS_ALLEVENTS) == WAIT_TIMEOUT) break;
74 while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
75 diff = time - GetTickCount();
79 static int CD_Stages;
80 static LRESULT CD_Result;
81 static HWND g_hwnd;
83 #define TEST_CDDS_PREPAINT 0x00000001
84 #define TEST_CDDS_POSTPAINT 0x00000002
85 #define TEST_CDDS_PREERASE 0x00000004
86 #define TEST_CDDS_POSTERASE 0x00000008
87 #define TEST_CDDS_ITEMPREPAINT 0x00000010
88 #define TEST_CDDS_ITEMPOSTPAINT 0x00000020
89 #define TEST_CDDS_ITEMPREERASE 0x00000040
90 #define TEST_CDDS_ITEMPOSTERASE 0x00000080
91 #define TEST_CDDS_SUBITEM 0x00000100
93 static LRESULT CALLBACK CustomDrawWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
95 switch(msg) {
97 case WM_DESTROY:
98 PostQuitMessage(0);
99 break;
101 case WM_NOTIFY:
102 if (((NMHDR *)lParam)->code == NM_CUSTOMDRAW) {
103 NMTTCUSTOMDRAW *ttcd = (NMTTCUSTOMDRAW*) lParam;
104 ok(ttcd->nmcd.hdr.hwndFrom == g_hwnd, "Unexpected hwnd source %x (%x)\n",
105 (int)ttcd->nmcd.hdr.hwndFrom, (int) g_hwnd);
106 ok(ttcd->nmcd.hdr.idFrom == 0x1234ABCD, "Unexpected id %x\n", (int)ttcd->nmcd.hdr.idFrom);
108 switch (ttcd->nmcd.dwDrawStage) {
109 case CDDS_PREPAINT : CD_Stages |= TEST_CDDS_PREPAINT; break;
110 case CDDS_POSTPAINT : CD_Stages |= TEST_CDDS_POSTPAINT; break;
111 case CDDS_PREERASE : CD_Stages |= TEST_CDDS_PREERASE; break;
112 case CDDS_POSTERASE : CD_Stages |= TEST_CDDS_POSTERASE; break;
113 case CDDS_ITEMPREPAINT : CD_Stages |= TEST_CDDS_ITEMPREPAINT; break;
114 case CDDS_ITEMPOSTPAINT: CD_Stages |= TEST_CDDS_ITEMPOSTPAINT; break;
115 case CDDS_ITEMPREERASE : CD_Stages |= TEST_CDDS_ITEMPREERASE; break;
116 case CDDS_ITEMPOSTERASE: CD_Stages |= TEST_CDDS_ITEMPOSTERASE; break;
117 case CDDS_SUBITEM : CD_Stages |= TEST_CDDS_SUBITEM; break;
118 default: CD_Stages = -1;
121 if (ttcd->nmcd.dwDrawStage == CDDS_PREPAINT) return CD_Result;
123 /* drop through */
125 default:
126 return DefWindowProcA(hWnd, msg, wParam, lParam);
129 return 0L;
132 static void test_customdraw(void) {
133 static struct {
134 LRESULT FirstReturnValue;
135 int ExpectedCalls;
136 } expectedResults[] = {
137 /* Valid notification responses */
138 {CDRF_DODEFAULT, TEST_CDDS_PREPAINT},
139 {CDRF_SKIPDEFAULT, TEST_CDDS_PREPAINT},
140 {CDRF_NOTIFYPOSTPAINT, TEST_CDDS_PREPAINT | TEST_CDDS_POSTPAINT},
142 /* Invalid notification responses */
143 {CDRF_NOTIFYITEMDRAW, TEST_CDDS_PREPAINT},
144 {CDRF_NOTIFYPOSTERASE, TEST_CDDS_PREPAINT},
145 {CDRF_NOTIFYSUBITEMDRAW, TEST_CDDS_PREPAINT},
146 {CDRF_NEWFONT, TEST_CDDS_PREPAINT}
149 int iterationNumber;
150 WNDCLASSA wc;
151 LRESULT lResult;
153 /* Create a class to use the custom draw wndproc */
154 wc.style = CS_HREDRAW | CS_VREDRAW;
155 wc.cbClsExtra = 0;
156 wc.cbWndExtra = 0;
157 wc.hInstance = GetModuleHandleA(NULL);
158 wc.hIcon = NULL;
159 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
160 wc.hbrBackground = GetSysColorBrush(COLOR_WINDOW);
161 wc.lpszMenuName = NULL;
162 wc.lpszClassName = "CustomDrawClass";
163 wc.lpfnWndProc = CustomDrawWndProc;
164 RegisterClass(&wc);
166 for (iterationNumber = 0;
167 iterationNumber < sizeof(expectedResults)/sizeof(expectedResults[0]);
168 iterationNumber++) {
170 HWND parent, hwndTip;
171 TOOLINFO toolInfo = { 0 };
173 /* Create a main window */
174 parent = CreateWindowEx(0, "CustomDrawClass", NULL,
175 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
176 WS_MAXIMIZEBOX | WS_VISIBLE,
177 50, 50,
178 300, 300,
179 NULL, NULL, NULL, 0);
180 ok(parent != NULL, "Creation of main window failed\n");
182 /* Make it show */
183 ShowWindow(parent, SW_SHOWNORMAL);
184 flush_events(100);
186 /* Create Tooltip */
187 hwndTip = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS,
188 NULL, TTS_NOPREFIX | TTS_ALWAYSTIP,
189 CW_USEDEFAULT, CW_USEDEFAULT,
190 CW_USEDEFAULT, CW_USEDEFAULT,
191 parent, NULL, GetModuleHandleA(NULL), 0);
192 ok(hwndTip != NULL, "Creation of tooltip window failed\n");
194 /* Set up parms for the wndproc to handle */
195 CD_Stages = 0;
196 CD_Result = expectedResults[iterationNumber].FirstReturnValue;
197 g_hwnd = hwndTip;
199 /* Make it topmost, as per the MSDN */
200 SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0,
201 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
203 /* Create a tool */
204 toolInfo.cbSize = sizeof(TOOLINFO);
205 toolInfo.hwnd = parent;
206 toolInfo.hinst = GetModuleHandleA(NULL);
207 toolInfo.uFlags = TTF_SUBCLASS;
208 toolInfo.uId = (UINT_PTR)0x1234ABCD;
209 toolInfo.lpszText = (LPSTR)"This is a test tooltip";
210 toolInfo.lParam = 0xdeadbeef;
211 GetClientRect (parent, &toolInfo.rect);
212 lResult = SendMessage(hwndTip, TTM_ADDTOOL, 0, (LPARAM)&toolInfo);
213 ok(lResult, "Adding the tool to the tooltip failed\n");
215 /* Make tooltip appear quickly */
216 SendMessage(hwndTip, TTM_SETDELAYTIME, (WPARAM)TTDT_INITIAL, (LPARAM)MAKELONG(1,0));
218 /* Put cursor inside window, tooltip will appear immediately */
219 SetCursorPos(100, 100);
220 flush_events(200);
222 /* Check CustomDraw results */
223 ok(CD_Stages == expectedResults[iterationNumber].ExpectedCalls,
224 "CustomDraw run %d stages %x, expected %x\n", iterationNumber, CD_Stages,
225 expectedResults[iterationNumber].ExpectedCalls);
227 /* Clean up */
228 DestroyWindow(hwndTip);
229 DestroyWindow(parent);
235 static void test_gettext(void)
237 HWND hwnd;
238 TTTOOLINFOA toolinfoA;
239 TTTOOLINFOW toolinfoW;
240 LRESULT r;
241 char bufA[10] = "";
242 WCHAR bufW[10] = { 0 };
244 /* For bug 14790 - lpszText is NULL */
245 hwnd = CreateWindowExA(0, TOOLTIPS_CLASSA, NULL, 0,
246 10, 10, 300, 100,
247 NULL, NULL, NULL, 0);
248 assert(hwnd);
250 toolinfoA.cbSize = sizeof(TTTOOLINFOA);
251 toolinfoA.hwnd = NULL;
252 toolinfoA.hinst = GetModuleHandleA(NULL);
253 toolinfoA.uFlags = 0;
254 toolinfoA.uId = (UINT_PTR)0x1234ABCD;
255 toolinfoA.lpszText = NULL;
256 toolinfoA.lParam = 0xdeadbeef;
257 GetClientRect(hwnd, &toolinfoA.rect);
258 r = SendMessageA(hwnd, TTM_ADDTOOL, 0, (LPARAM)&toolinfoA);
259 ok(r, "Adding the tool to the tooltip failed\n");
261 toolinfoA.hwnd = NULL;
262 toolinfoA.uId = (UINT_PTR)0x1234ABCD;
263 toolinfoA.lpszText = bufA;
264 SendMessageA(hwnd, TTM_GETTEXTA, 0, (LPARAM)&toolinfoA);
265 ok(strcmp(toolinfoA.lpszText, "") == 0, "lpszText should be an empty string\n");
267 DestroyWindow(hwnd);
269 hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
270 10, 10, 300, 100,
271 NULL, NULL, NULL, 0);
272 assert(hwnd);
274 toolinfoW.cbSize = sizeof(TTTOOLINFOW);
275 toolinfoW.hwnd = NULL;
276 toolinfoW.hinst = GetModuleHandleA(NULL);
277 toolinfoW.uFlags = 0;
278 toolinfoW.uId = (UINT_PTR)0x1234ABCD;
279 toolinfoW.lpszText = NULL;
280 toolinfoW.lParam = 0xdeadbeef;
281 GetClientRect(hwnd, &toolinfoW.rect);
282 r = SendMessageW(hwnd, TTM_ADDTOOL, 0, (LPARAM)&toolinfoW);
283 ok(r, "Adding the tool to the tooltip failed\n");
285 toolinfoW.hwnd = NULL;
286 toolinfoW.uId = (UINT_PTR)0x1234ABCD;
287 toolinfoW.lpszText = bufW;
288 SendMessageW(hwnd, TTM_GETTEXTW, 0, (LPARAM)&toolinfoW);
289 ok(toolinfoW.lpszText[0] == 0, "lpszText should be an empty string\n");
291 DestroyWindow(hwnd);
294 START_TEST(tooltips)
296 InitCommonControls();
298 test_create_tooltip();
299 test_customdraw();
300 test_gettext();