mcicda: Exclude unused headers.
[wine] / dlls / comctl32 / tests / tab.c
1 /* Unit test suite for tab control.
2  *
3  * Copyright 2003 Vitaliy Margolen
4  * Copyright 2007 Hagop Hagopian
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20
21 #include <assert.h>
22 #include <windows.h>
23 #include <commctrl.h>
24 #include <stdio.h>
25
26 #include "wine/test.h"
27 #include "msg.h"
28
29 #define DEFAULT_MIN_TAB_WIDTH 54
30 #define TAB_DEFAULT_WIDTH 96
31 #define TAB_PADDING_X 6
32 #define EXTRA_ICON_PADDING 3
33 #define MAX_TABLEN 32
34
35 #define NUM_MSG_SEQUENCES  2
36 #define PARENT_SEQ_INDEX   0
37 #define TAB_SEQ_INDEX      1
38
39 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
40 #define expect_str(expected, got)\
41  ok ( strcmp(expected, got) == 0, "Expected '%s', got '%s'\n", expected, got)
42
43 #define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)
44
45 #define TabCheckSetSize(hwnd, SetWidth, SetHeight, ExpWidth, ExpHeight, Msg)\
46     SendMessage (hwnd, TCM_SETITEMSIZE, 0,\
47         (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));\
48     if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);\
49     CheckSize(hwnd, ExpWidth, ExpHeight, Msg);
50
51 #define CheckSize(hwnd,width,height,msg)\
52     SendMessage (hwnd, TCM_GETITEMRECT, 0, (LPARAM) &rTab);\
53     if ((width  >= 0) && (height < 0))\
54         ok (width  == rTab.right  - rTab.left, "%s: Expected width [%d] got [%d]\n",\
55         msg, (int)width,  rTab.right  - rTab.left);\
56     else if ((height >= 0) && (width  < 0))\
57         ok (height == rTab.bottom - rTab.top,  "%s: Expected height [%d] got [%d]\n",\
58         msg, (int)height, rTab.bottom - rTab.top);\
59     else\
60         ok ((width  == rTab.right  - rTab.left) &&\
61             (height == rTab.bottom - rTab.top ),\
62             "%s: Expected [%d,%d] got [%d,%d]\n", msg, (int)width, (int)height,\
63             rTab.right - rTab.left, rTab.bottom - rTab.top);
64
65 static HFONT hFont = 0;
66
67 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
68
69 static const struct message create_parent_wnd_seq[] = {
70     { WM_GETMINMAXINFO, sent },
71     { WM_NCCREATE, sent },
72     { WM_NCCALCSIZE, sent|wparam, 0 },
73     { WM_CREATE, sent },
74     { WM_SHOWWINDOW, sent|wparam, 1 },
75     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
76     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
77     { WM_ACTIVATEAPP, sent|wparam, 1 },
78     { WM_NCACTIVATE, sent|wparam, 1 },
79     { WM_ACTIVATE, sent|wparam, 1 },
80     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
81     { WM_IME_NOTIFY, sent|defwinproc|optional },
82     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
83     /* Win9x adds SWP_NOZORDER below */
84     { WM_WINDOWPOSCHANGED, sent},
85     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
86     { WM_SIZE, sent },
87     { WM_MOVE, sent },
88     { 0 }
89 };
90
91 static const struct message add_tab_to_parent[] = {
92     { TCM_INSERTITEMA, sent },
93     { TCM_INSERTITEMA, sent },
94     { WM_NOTIFYFORMAT, sent|defwinproc },
95     { WM_QUERYUISTATE, sent|wparam|lparam|defwinproc, 0, 0 },
96     { WM_PARENTNOTIFY, sent|defwinproc },
97     { TCM_INSERTITEMA, sent },
98     { TCM_INSERTITEMA, sent },
99     { TCM_INSERTITEMA, sent },
100     { 0 }
101 };
102
103 static const struct message add_tab_to_parent_interactive[] = {
104     { TCM_INSERTITEMA, sent },
105     { TCM_INSERTITEMA, sent },
106     { WM_NOTIFYFORMAT, sent|defwinproc },
107     { WM_QUERYUISTATE, sent|wparam|lparam|defwinproc, 0, 0 },
108     { WM_PARENTNOTIFY, sent|defwinproc },
109     { TCM_INSERTITEMA, sent },
110     { TCM_INSERTITEMA, sent },
111     { TCM_INSERTITEMA, sent },
112     { WM_SHOWWINDOW, sent},
113     { WM_WINDOWPOSCHANGING, sent},
114     { WM_WINDOWPOSCHANGING, sent},
115     { WM_NCACTIVATE, sent},
116     { WM_ACTIVATE, sent},
117     { WM_IME_SETCONTEXT, sent|defwinproc|optional},
118     { WM_IME_NOTIFY, sent|defwinproc|optional},
119     { WM_SETFOCUS, sent|defwinproc},
120     { WM_WINDOWPOSCHANGED, sent},
121     { WM_SIZE, sent},
122     { WM_MOVE, sent},
123     { 0 }
124 };
125
126 static const struct message add_tab_control_parent_seq[] = {
127     { WM_NOTIFYFORMAT, sent },
128     { WM_QUERYUISTATE, sent|wparam|lparam, 0, 0 },
129     { 0 }
130 };
131
132 static const struct message add_tab_control_parent_seq_interactive[] = {
133     { WM_NOTIFYFORMAT, sent },
134     { WM_QUERYUISTATE, sent|wparam|lparam, 0, 0 },
135     { WM_WINDOWPOSCHANGING, sent|optional},
136     { WM_NCACTIVATE, sent},
137     { WM_ACTIVATE, sent},
138     { WM_WINDOWPOSCHANGING, sent|optional},
139     { WM_KILLFOCUS, sent},
140     { WM_IME_SETCONTEXT, sent|optional},
141     { WM_IME_NOTIFY, sent|optional},
142     { 0 }
143 };
144
145 static const struct message empty_sequence[] = {
146     { 0 }
147 };
148
149 static const struct message set_min_tab_width_seq[] = {
150     { TCM_SETMINTABWIDTH, sent|wparam, 0 },
151     { TCM_SETMINTABWIDTH, sent|wparam, 0 },
152     { 0 }
153 };
154
155 static const struct message get_item_count_seq[] = {
156     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
157     { 0 }
158 };
159
160 static const struct message get_row_count_seq[] = {
161     { TCM_GETROWCOUNT, sent|wparam|lparam, 0, 0 },
162     { 0 }
163 };
164
165 static const struct message get_item_rect_seq[] = {
166     { TCM_GETITEMRECT, sent },
167     { TCM_GETITEMRECT, sent },
168     { 0 }
169 };
170
171 static const struct message getset_cur_focus_seq[] = {
172     { TCM_SETCURFOCUS, sent|lparam, 0 },
173     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
174     { TCM_SETCURFOCUS, sent|lparam, 0 },
175     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
176     { TCM_SETCURSEL, sent|lparam, 0 },
177     { TCM_SETCURFOCUS, sent|lparam, 0 },
178     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
179     { 0 }
180 };
181
182 static const struct message getset_cur_sel_seq[] = {
183     { TCM_SETCURSEL, sent|lparam, 0 },
184     { TCM_GETCURSEL, sent|wparam|lparam, 0, 0 },
185     { TCM_SETCURSEL, sent|lparam, 0 },
186     { TCM_GETCURSEL, sent|wparam|lparam, 0, 0 },
187     { TCM_SETCURSEL, sent|lparam, 0 },
188     { TCM_SETCURSEL, sent|lparam, 0 },
189     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
190     { 0 }
191 };
192
193 static const struct message getset_extended_style_seq[] = {
194     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
195     { TCM_SETEXTENDEDSTYLE, sent },
196     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
197     { TCM_SETEXTENDEDSTYLE, sent },
198     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
199     { 0 }
200 };
201
202 static const struct message getset_unicode_format_seq[] = {
203     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
204     { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
205     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
206     { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
207     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
208     { 0 }
209 };
210
211 static const struct message getset_item_seq[] = {
212     { TCM_SETITEMA, sent },
213     { TCM_GETITEMA, sent },
214     { TCM_GETITEMA, sent },
215     { 0 }
216 };
217
218 static const struct message getset_tooltip_seq[] = {
219     { WM_NOTIFYFORMAT, sent },
220     { WM_QUERYUISTATE, sent|wparam|lparam, 0, 0 },
221     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
222     { WM_NOTIFYFORMAT, sent },
223     { TCM_SETTOOLTIPS, sent|lparam, 0 },
224     { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
225     { TCM_SETTOOLTIPS, sent|lparam, 0 },
226     { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
227     { 0 }
228 };
229
230 static const struct message getset_tooltip_parent_seq[] = {
231     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
232     { 0 }
233 };
234
235 static HWND
236 create_tabcontrol (DWORD style, DWORD mask)
237 {
238     HWND handle;
239     TCITEM tcNewTab;
240     static char text1[] = "Tab 1",
241     text2[] = "Wide Tab 2",
242     text3[] = "T 3";
243
244     handle = CreateWindow (
245         WC_TABCONTROLA,
246         "TestTab",
247         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
248         10, 10, 300, 100,
249         NULL, NULL, NULL, 0);
250
251     assert (handle);
252
253     SetWindowLong(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
254     SendMessage (handle, WM_SETFONT, 0, (LPARAM) hFont);
255
256     tcNewTab.mask = mask;
257     tcNewTab.pszText = text1;
258     tcNewTab.iImage = 0;
259     SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
260     tcNewTab.pszText = text2;
261     tcNewTab.iImage = 1;
262     SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
263     tcNewTab.pszText = text3;
264     tcNewTab.iImage = 2;
265     SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
266
267     if (winetest_interactive)
268     {
269         ShowWindow (handle, SW_SHOW);
270         RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
271         Sleep (1000);
272     }
273
274     return handle;
275 }
276
277 static LRESULT WINAPI parentWindowProcess(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
278 {
279     static long defwndproc_counter = 0;
280     LRESULT ret;
281     struct message msg;
282
283     /* do not log painting messages */
284     if (message != WM_PAINT &&
285         message != WM_ERASEBKGND &&
286         message != WM_NCPAINT &&
287         message != WM_NCHITTEST &&
288         message != WM_GETTEXT &&
289         message != WM_GETICON &&
290         message != WM_DEVICECHANGE)
291     {
292         trace("parent: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
293
294         msg.message = message;
295         msg.flags = sent|wparam|lparam;
296         if (defwndproc_counter) msg.flags |= defwinproc;
297         msg.wParam = wParam;
298         msg.lParam = lParam;
299         add_message(sequences, PARENT_SEQ_INDEX, &msg);
300     }
301
302     defwndproc_counter++;
303     ret = DefWindowProcA(hwnd, message, wParam, lParam);
304     defwndproc_counter--;
305
306     return ret;
307 }
308
309 static BOOL registerParentWindowClass(void)
310 {
311     WNDCLASSA cls;
312
313     cls.style = 0;
314     cls.lpfnWndProc = parentWindowProcess;
315     cls.cbClsExtra = 0;
316     cls.cbWndExtra = 0;
317     cls.hInstance = GetModuleHandleA(NULL);
318     cls.hIcon = 0;
319     cls.hCursor = LoadCursorA(0, (LPSTR)IDC_ARROW);
320     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
321     cls.lpszMenuName = NULL;
322     cls.lpszClassName = "Tab test parent class";
323     return RegisterClassA(&cls);
324 }
325
326 static HWND createParentWindow(void)
327 {
328     if (!registerParentWindowClass())
329         return NULL;
330
331     return CreateWindowEx(0, "Tab test parent class",
332                           "Tab test parent window",
333                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
334                           WS_MAXIMIZEBOX | WS_VISIBLE,
335                           0, 0, 100, 100,
336                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
337 }
338
339 struct subclass_info
340 {
341     WNDPROC oldproc;
342 };
343
344 static LRESULT WINAPI tabSubclassProcess(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
345 {
346     struct subclass_info *info = (struct subclass_info *)GetWindowLongA(hwnd, GWL_USERDATA);
347     static long defwndproc_counter = 0;
348     LRESULT ret;
349     struct message msg;
350
351     /* do not log painting messages */
352     if (message != WM_PAINT &&
353         message != WM_ERASEBKGND &&
354         message != WM_NCPAINT &&
355         message != WM_NCHITTEST &&
356         message != WM_GETTEXT &&
357         message != WM_GETICON &&
358         message != WM_DEVICECHANGE)
359     {
360         trace("tab: %p, %04x, %08x, %08lx\n", hwnd, message, wParam, lParam);
361
362         msg.message = message;
363         msg.flags = sent|wparam|lparam;
364         if (defwndproc_counter) msg.flags |= defwinproc;
365         msg.wParam = wParam;
366         msg.lParam = lParam;
367         add_message(sequences, TAB_SEQ_INDEX, &msg);
368     }
369
370     defwndproc_counter++;
371     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
372     defwndproc_counter--;
373
374     return ret;
375 }
376
377 static HWND createFilledTabControl(HWND parent_wnd, DWORD style, DWORD mask, INT nTabs)
378 {
379     HWND tabHandle;
380     TCITEM tcNewTab;
381     struct subclass_info *info;
382     RECT rect;
383     INT i;
384
385     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
386     if (!info)
387         return NULL;
388
389     GetClientRect(parent_wnd, &rect);
390
391     tabHandle = CreateWindow (
392         WC_TABCONTROLA,
393         "TestTab",
394         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
395         0, 0, rect.right, rect.bottom,
396         parent_wnd, NULL, NULL, 0);
397
398     assert(tabHandle);
399
400     info->oldproc = (WNDPROC)SetWindowLongA(tabHandle, GWL_WNDPROC, (LONG)tabSubclassProcess);
401     SetWindowLongA(tabHandle, GWL_USERDATA, (LONG)info);
402
403     tcNewTab.mask = mask;
404
405     for (i = 0; i < nTabs; i++)
406     {
407         char tabName[MAX_TABLEN];
408
409         sprintf(tabName, "Tab %d", i+1);
410         tcNewTab.pszText = tabName;
411         tcNewTab.iImage = i;
412         SendMessage (tabHandle, TCM_INSERTITEM, i, (LPARAM) &tcNewTab);
413     }
414
415     if (winetest_interactive)
416     {
417         ShowWindow (tabHandle, SW_SHOW);
418         RedrawWindow (tabHandle, NULL, 0, RDW_UPDATENOW);
419         Sleep (1000);
420     }
421
422     return tabHandle;
423 }
424
425 static HWND create_tooltip (HWND hTab, char toolTipText[])
426 {
427     HWND hwndTT;
428
429     TOOLINFO ti;
430     LPTSTR lptstr = toolTipText;
431     RECT rect;
432
433     /* Creating a tooltip window*/
434     hwndTT = CreateWindowEx(
435         WS_EX_TOPMOST,
436         TOOLTIPS_CLASS,
437         NULL,
438         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
439         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
440         hTab, NULL, 0, NULL);
441
442     SetWindowPos(
443         hwndTT,
444         HWND_TOPMOST,
445         0, 0, 0, 0,
446         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
447
448     GetClientRect (hTab, &rect);
449
450     /* Initialize members of toolinfo*/
451     ti.cbSize = sizeof(TOOLINFO);
452     ti.uFlags = TTF_SUBCLASS;
453     ti.hwnd = hTab;
454     ti.hinst = 0;
455     ti.uId = 0;
456     ti.lpszText = lptstr;
457
458     ti.rect = rect;
459
460     /* Add toolinfo structure to the tooltip control */
461     SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti);
462
463     return hwndTT;
464 }
465
466 static void test_tab(INT nMinTabWidth)
467 {
468     HWND hwTab;
469     RECT rTab;
470     HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
471     SIZE size;
472     HDC hdc;
473     HFONT hOldFont;
474     INT i;
475
476     hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
477     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
478
479     hdc = GetDC(hwTab);
480     hOldFont = SelectObject(hdc, (HFONT)SendMessage(hwTab, WM_GETFONT, 0, 0));
481     GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
482     trace("Tab1 text size: size.cx=%d size.cy=%d\n", size.cx, size.cy);
483     SelectObject(hdc, hOldFont);
484     ReleaseDC(hwTab, hdc);
485
486     trace ("  TCS_FIXEDWIDTH tabs no icon...\n");
487     CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
488     TabCheckSetSize(hwTab, 50, 20, 50, 20, "set size");
489     TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
490
491     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
492
493     trace ("  TCS_FIXEDWIDTH tabs with icon...\n");
494     TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
495     TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
496     TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
497
498     DestroyWindow (hwTab);
499
500     hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
501     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
502
503     trace ("  TCS_FIXEDWIDTH buttons no icon...\n");
504     CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
505     TabCheckSetSize(hwTab, 20, 20, 20, 20, "set size 1");
506     TabCheckSetSize(hwTab, 10, 50, 10, 50, "set size 2");
507     TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
508
509     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
510
511     trace ("  TCS_FIXEDWIDTH buttons with icon...\n");
512     TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
513     TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
514     TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
515     SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
516     TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
517
518     DestroyWindow (hwTab);
519
520     hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
521     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
522
523     trace ("  TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
524     CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "no icon, default width");
525
526     TabCheckSetSize(hwTab, 20, 20, 20, 20, "no icon, set size 1");
527     TabCheckSetSize(hwTab, 10, 50, 10, 50, "no icon, set size 2");
528     TabCheckSetSize(hwTab, 0, 1, 0, 1, "no icon, min size");
529
530     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
531
532     TabCheckSetSize(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
533     TabCheckSetSize(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
534     TabCheckSetSize(hwTab, 0, 1, 25, 1, "with icon, min size");
535     SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
536     TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
537
538     DestroyWindow (hwTab);
539
540     hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
541     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
542
543     trace ("  non fixed width, with text...\n");
544     CheckSize(hwTab, max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth), -1,
545               "no icon, default width");
546     for (i=0; i<8; i++)
547     {
548         INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
549
550         SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
551         SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
552
553         TabCheckSetSize(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
554         TabCheckSetSize(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
555
556         SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
557         nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;
558
559         TabCheckSetSize(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
560         TabCheckSetSize(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
561         TabCheckSetSize(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
562     }
563     DestroyWindow (hwTab);
564
565     hwTab = create_tabcontrol(0, TCIF_IMAGE);
566     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
567
568     trace ("  non fixed width, no text...\n");
569     CheckSize(hwTab, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth, -1, "no icon, default width");
570     for (i=0; i<8; i++)
571     {
572         INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
573
574         SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
575         SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
576
577         TabCheckSetSize(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
578         TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
579
580         SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
581         if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
582             nTabWidth += EXTRA_ICON_PADDING *(i-1);
583
584         TabCheckSetSize(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
585         TabCheckSetSize(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
586         TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
587     }
588
589     DestroyWindow (hwTab);
590
591     ImageList_Destroy(himl);
592     DeleteObject(hFont);
593 }
594
595 static void test_getters_setters(INT nTabs)
596 {
597     HWND hTab;
598     HWND parent_wnd;
599     RECT rTab;
600     INT nTabsRetrieved;
601     INT rowCount;
602
603     parent_wnd = createParentWindow();
604     ok(parent_wnd != NULL, "Failed to create parent window!\n");
605     flush_sequences(sequences, NUM_MSG_SEQUENCES);
606
607     hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
608     ok(hTab != NULL, "Failed to create tab control\n");
609
610     if(!winetest_interactive)
611         ok_sequence(sequences, TAB_SEQ_INDEX, add_tab_to_parent,
612                     "Tab sequence, after adding tab control to parent", TRUE);
613     else
614         ok_sequence(sequences, TAB_SEQ_INDEX, add_tab_to_parent_interactive,
615                     "Tab sequence, after adding tab control to parent", TRUE);
616
617     if(!winetest_interactive)
618         ok_sequence(sequences, PARENT_SEQ_INDEX, add_tab_control_parent_seq,
619                     "Parent after sequence, adding tab control to parent", TRUE);
620     else
621         ok_sequence(sequences, PARENT_SEQ_INDEX, add_tab_control_parent_seq_interactive,
622                     "Parent after sequence, adding tab control to parent", TRUE);
623
624     flush_sequences(sequences, NUM_MSG_SEQUENCES);
625     todo_wine{
626         expect(DEFAULT_MIN_TAB_WIDTH, (int)SendMessage(hTab, TCM_SETMINTABWIDTH, 0, -1));
627     }
628     ok_sequence(sequences, TAB_SEQ_INDEX, set_min_tab_width_seq, "Set minTabWidth test sequence", FALSE);
629     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Set minTabWidth test parent sequence", FALSE);
630
631     /* Testing GetItemCount */
632     flush_sequences(sequences, NUM_MSG_SEQUENCES);
633     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
634     expect(nTabs, nTabsRetrieved);
635     ok_sequence(sequences, TAB_SEQ_INDEX, get_item_count_seq, "Get itemCount test sequence", FALSE);
636     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset itemCount test parent sequence", FALSE);
637
638     /* Testing GetRowCount */
639     flush_sequences(sequences, NUM_MSG_SEQUENCES);
640     rowCount = SendMessage(hTab, TCM_GETROWCOUNT, 0, 0);
641     expect(1, rowCount);
642     ok_sequence(sequences, TAB_SEQ_INDEX, get_row_count_seq, "Get rowCount test sequence", FALSE);
643     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Get rowCount test parent sequence", FALSE);
644
645     /* Testing GetItemRect */
646     flush_sequences(sequences, NUM_MSG_SEQUENCES);
647     ok(SendMessage(hTab, TCM_GETITEMRECT, 0, (LPARAM) &rTab), "GetItemRect failed.\n");
648     CheckSize(hTab, TAB_DEFAULT_WIDTH, -1 , "Default Width");
649     ok_sequence(sequences, TAB_SEQ_INDEX, get_item_rect_seq, "Get itemRect test sequence", FALSE);
650     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Get itemRect test parent sequence", FALSE);
651
652     /* Testing CurFocus */
653     {
654         INT focusIndex;
655
656         flush_sequences(sequences, NUM_MSG_SEQUENCES);
657
658         /* Testing CurFocus with largest appropriate value */
659         SendMessage(hTab, TCM_SETCURFOCUS, nTabs-1, 0);
660         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
661             expect(nTabs-1, focusIndex);
662
663         /* Testing CurFocus with negative value */
664         SendMessage(hTab, TCM_SETCURFOCUS, -10, 0);
665         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
666             expect(-1, focusIndex);
667
668         /* Testing CurFocus with value larger than number of tabs */
669         focusIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
670         todo_wine{
671             expect(-1, focusIndex);
672         }
673
674         SendMessage(hTab, TCM_SETCURFOCUS, nTabs+1, 0);
675         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
676         todo_wine{
677             expect(1, focusIndex);
678         }
679
680         ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_focus_seq, "Getset curFoc test sequence", FALSE);
681     }
682
683     /* Testing CurSel */
684     {
685         INT selectionIndex;
686
687         flush_sequences(sequences, NUM_MSG_SEQUENCES);
688
689         /* Testing CurSel with largest appropriate value */
690         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs-1, 0);
691             expect(1, selectionIndex);
692         selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
693             expect(nTabs-1, selectionIndex);
694
695         /* Testing CurSel with negative value */
696         SendMessage(hTab, TCM_SETCURSEL, -10, 0);
697         selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
698             expect(-1, selectionIndex);
699
700         /* Testing CurSel with value larger than number of tabs */
701         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
702             expect(-1, selectionIndex);
703
704         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs+1, 0);
705             expect(-1, selectionIndex);
706         selectionIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
707         todo_wine{
708             expect(1, selectionIndex);
709         }
710
711         ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_sel_seq, "Getset curSel test sequence", FALSE);
712         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset curSel test parent sequence", FALSE);
713     }
714
715     /* Testing ExtendedStyle */
716     {
717         DWORD prevExtendedStyle;
718         DWORD extendedStyle;
719
720         flush_sequences(sequences, NUM_MSG_SEQUENCES);
721
722         /* Testing Flat Separators */
723         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
724         prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_FLATSEPARATORS);
725             expect(extendedStyle, prevExtendedStyle);
726
727         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
728         todo_wine{
729             expect(TCS_EX_FLATSEPARATORS, extendedStyle);
730         }
731
732         /* Testing Register Drop */
733         prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_REGISTERDROP);
734             expect(extendedStyle, prevExtendedStyle);
735
736         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
737         todo_wine{
738             expect(TCS_EX_REGISTERDROP, extendedStyle);
739         }
740
741         ok_sequence(sequences, TAB_SEQ_INDEX, getset_extended_style_seq, "Getset extendedStyle test sequence", FALSE);
742         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset extendedStyle test parent sequence", FALSE);
743     }
744
745     /* Testing UnicodeFormat */
746     {
747         INT unicodeFormat;
748
749         flush_sequences(sequences, NUM_MSG_SEQUENCES);
750
751         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
752         todo_wine{
753             expect(0, unicodeFormat);
754         }
755         unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
756             expect(1, unicodeFormat);
757
758         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, FALSE, 0);
759             expect(1, unicodeFormat);
760         unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
761             expect(0, unicodeFormat);
762
763         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
764             expect(0, unicodeFormat);
765
766         ok_sequence(sequences, TAB_SEQ_INDEX, getset_unicode_format_seq, "Getset unicodeFormat test sequence", FALSE);
767         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset unicodeFormat test parent sequence", FALSE);
768     }
769
770     /* Testing GetSet Item */
771     {
772         TCITEM tcItem;
773         char szText[32] = "New Label";
774
775         flush_sequences(sequences, NUM_MSG_SEQUENCES);
776
777         tcItem.mask = TCIF_TEXT;
778         tcItem.pszText = &szText[0];
779         tcItem.cchTextMax = sizeof(szText);
780
781         ok ( SendMessage(hTab, TCM_SETITEM, 0, (LPARAM) &tcItem), "Setting new item failed.\n");
782         ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
783         expect_str("New Label", tcItem.pszText);
784
785         ok ( SendMessage(hTab, TCM_GETITEM, 1, (LPARAM) &tcItem), "Getting item failed.\n");
786         expect_str("Tab 2", tcItem.pszText);
787
788         ok_sequence(sequences, TAB_SEQ_INDEX, getset_item_seq, "Getset item test sequence", FALSE);
789         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset item test parent sequence", FALSE);
790     }
791
792     /* Testing GetSet ToolTip */
793     {
794         HWND toolTip;
795         char toolTipText[32] = "ToolTip Text Test";
796
797         flush_sequences(sequences, NUM_MSG_SEQUENCES);
798
799         toolTip = create_tooltip(hTab, toolTipText);
800         SendMessage(hTab, TCM_SETTOOLTIPS, (LPARAM) toolTip, 0);
801         ok (toolTip == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.\n");
802
803         SendMessage(hTab, TCM_SETTOOLTIPS, (LPARAM) NULL, 0);
804         ok (NULL  == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.\n");
805
806         ok_sequence(sequences, TAB_SEQ_INDEX, getset_tooltip_seq, "Getset tooltip test sequence", TRUE);
807         ok_sequence(sequences, PARENT_SEQ_INDEX, getset_tooltip_parent_seq, "Getset tooltip test parent sequence", TRUE);
808     }
809
810     DestroyWindow(hTab);
811     DestroyWindow(parent_wnd);
812 }
813
814 START_TEST(tab)
815 {
816     LOGFONTA logfont;
817
818     lstrcpyA(logfont.lfFaceName, "Arial");
819     memset(&logfont, 0, sizeof(logfont));
820     logfont.lfHeight = -12;
821     logfont.lfWeight = FW_NORMAL;
822     logfont.lfCharSet = ANSI_CHARSET;
823     hFont = CreateFontIndirectA(&logfont);
824
825     InitCommonControls();
826
827     trace ("Testing with default MinWidth\n");
828     test_tab(-1);
829     trace ("Testing with MinWidth set to -3\n");
830     test_tab(-3);
831     trace ("Testing with MinWidth set to 24\n");
832     test_tab(24);
833     trace ("Testing with MinWidth set to 54\n");
834     test_tab(54);
835     trace ("Testing with MinWidth set to 94\n");
836     test_tab(94);
837
838     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
839
840     /* Testing getters and setters with 5 tabs */
841     test_getters_setters(5);
842 }