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
24 #include "wine/test.h"
26 static void test_create_tooltip(void)
29 DWORD style, exp_style;
31 parent = CreateWindowEx(0, "static", NULL, WS_POPUP,
36 hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0x7fffffff | WS_POPUP,
38 parent, NULL, NULL, 0);
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);
49 hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0,
51 parent, NULL, NULL, 0);
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);
61 DestroyWindow(parent);
64 /* try to make sure pending X events have been processed before continuing */
65 static void flush_events(int waitTime)
69 DWORD time = GetTickCount() + waitTime;
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();
80 static LRESULT CD_Result;
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)
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;
126 return DefWindowProcA(hWnd, msg, wParam, lParam);
132 static void test_customdraw(void) {
134 LRESULT FirstReturnValue;
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}
153 /* Create a class to use the custom draw wndproc */
154 wc.style = CS_HREDRAW | CS_VREDRAW;
157 wc.hInstance = GetModuleHandleA(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;
166 for (iterationNumber = 0;
167 iterationNumber < sizeof(expectedResults)/sizeof(expectedResults[0]);
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,
179 NULL, NULL, NULL, 0);
180 ok(parent != NULL, "Creation of main window failed\n");
183 ShowWindow(parent, SW_SHOWNORMAL);
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 */
196 CD_Result = expectedResults[iterationNumber].FirstReturnValue;
199 /* Make it topmost, as per the MSDN */
200 SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0,
201 SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
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);
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);
228 DestroyWindow(hwndTip);
229 DestroyWindow(parent);
235 static void test_gettext(void)
238 TTTOOLINFOA toolinfoA;
239 TTTOOLINFOW toolinfoW;
242 WCHAR bufW[10] = { 0 };
244 /* For bug 14790 - lpszText is NULL */
245 hwnd = CreateWindowExA(0, TOOLTIPS_CLASSA, NULL, 0,
247 NULL, NULL, NULL, 0);
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");
269 SetLastError(0xdeadbeef);
270 hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
272 NULL, NULL, NULL, 0);
274 if (!hwnd && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED) {
275 win_skip("CreateWindowExW is not implemented\n");
281 toolinfoW.cbSize = sizeof(TTTOOLINFOW);
282 toolinfoW.hwnd = NULL;
283 toolinfoW.hinst = GetModuleHandleA(NULL);
284 toolinfoW.uFlags = 0;
285 toolinfoW.uId = (UINT_PTR)0x1234ABCD;
286 toolinfoW.lpszText = NULL;
287 toolinfoW.lParam = 0xdeadbeef;
288 GetClientRect(hwnd, &toolinfoW.rect);
289 r = SendMessageW(hwnd, TTM_ADDTOOL, 0, (LPARAM)&toolinfoW);
290 ok(r, "Adding the tool to the tooltip failed\n");
292 toolinfoW.hwnd = NULL;
293 toolinfoW.uId = (UINT_PTR)0x1234ABCD;
294 toolinfoW.lpszText = bufW;
295 SendMessageW(hwnd, TTM_GETTEXTW, 0, (LPARAM)&toolinfoW);
296 ok(toolinfoW.lpszText[0] == 0, "lpszText should be an empty string\n");
303 InitCommonControls();
305 test_create_tooltip();