~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/comctl32/tests/tooltips.c

Version: ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Copyright 2005 Dmitry Timoshkov
  3  * Copyright 2008 Jason Edmeades
  4  *
  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.
  9  *
 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.
 14  *
 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
 18  */
 19 
 20 #include <assert.h>
 21 #include <windows.h>
 22 #include <commctrl.h>
 23 
 24 #include "wine/test.h"
 25 
 26 static void test_create_tooltip(void)
 27 {
 28     HWND parent, hwnd;
 29     DWORD style, exp_style;
 30 
 31     parent = CreateWindowEx(0, "static", NULL, WS_POPUP,
 32                           0, 0, 0, 0,
 33                           NULL, NULL, NULL, 0);
 34     assert(parent);
 35 
 36     hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0x7fffffff | WS_POPUP,
 37                           10, 10, 300, 100,
 38                           parent, NULL, NULL, 0);
 39     assert(hwnd);
 40 
 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);
 46 
 47     DestroyWindow(hwnd);
 48 
 49     hwnd = CreateWindowEx(0, TOOLTIPS_CLASS, NULL, 0,
 50                           10, 10, 300, 100,
 51                           parent, NULL, NULL, 0);
 52     assert(hwnd);
 53 
 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);
 58 
 59     DestroyWindow(hwnd);
 60 
 61     DestroyWindow(parent);
 62 }
 63 
 64 /* try to make sure pending X events have been processed before continuing */
 65 static void flush_events(int waitTime)
 66 {
 67     MSG msg;
 68     int diff = waitTime;
 69     DWORD time = GetTickCount() + waitTime;
 70 
 71     while (diff > 0)
 72     {
 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();
 76     }
 77 }
 78 
 79 static int CD_Stages;
 80 static LRESULT CD_Result;
 81 static HWND g_hwnd;
 82 
 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
 92 
 93 static LRESULT CALLBACK CustomDrawWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 94 {
 95     switch(msg) {
 96 
 97     case WM_DESTROY:
 98         PostQuitMessage(0);
 99         break;
100 
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);
107 
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;
119             }
120 
121             if (ttcd->nmcd.dwDrawStage == CDDS_PREPAINT) return CD_Result;
122         }
123         /* drop through */
124 
125     default:
126         return DefWindowProcA(hWnd, msg, wParam, lParam);
127     }
128 
129     return 0L;
130 }
131 
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},
141 
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}
147     };
148 
149    int       iterationNumber;
150    WNDCLASSA wc;
151    LRESULT   lResult;
152 
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);
165 
166    for (iterationNumber = 0;
167         iterationNumber < sizeof(expectedResults)/sizeof(expectedResults[0]);
168         iterationNumber++) {
169 
170        HWND parent, hwndTip;
171        TOOLINFO toolInfo = { 0 };
172 
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");
181 
182        /* Make it show */
183        ShowWindow(parent, SW_SHOWNORMAL);
184        flush_events(100);
185 
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");
193 
194        /* Set up parms for the wndproc to handle */
195        CD_Stages = 0;
196        CD_Result = expectedResults[iterationNumber].FirstReturnValue;
197        g_hwnd    = hwndTip;
198 
199        /* Make it topmost, as per the MSDN */
200        SetWindowPos(hwndTip, HWND_TOPMOST, 0, 0, 0, 0,
201              SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
202 
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");
214 
215        /* Make tooltip appear quickly */
216        SendMessage(hwndTip, TTM_SETDELAYTIME, (WPARAM)TTDT_INITIAL, (LPARAM)MAKELONG(1,0));
217 
218        /* Put cursor inside window, tooltip will appear immediately */
219        SetCursorPos(100, 100);
220        flush_events(200);
221 
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);
226 
227        /* Clean up */
228        DestroyWindow(hwndTip);
229        DestroyWindow(parent);
230    }
231 
232 
233 }
234 
235 static void test_gettext(void)
236 {
237     HWND hwnd;
238     TTTOOLINFOA toolinfoA;
239     TTTOOLINFOW toolinfoW;
240     LRESULT r;
241     char bufA[10] = "";
242     WCHAR bufW[10] = { 0 };
243 
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);
249 
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");
260 
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");
266 
267     DestroyWindow(hwnd);
268 
269     hwnd = CreateWindowExW(0, TOOLTIPS_CLASSW, NULL, 0,
270                            10, 10, 300, 100,
271                            NULL, NULL, NULL, 0);
272     assert(hwnd);
273 
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");
284 
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");
290 
291     DestroyWindow(hwnd);
292 }
293 
294 START_TEST(tooltips)
295 {
296     InitCommonControls();
297 
298     test_create_tooltip();
299     test_customdraw();
300     test_gettext();
301 }
302 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.