comctl32/tests: Fix tab control test failures on older Windows versions.
[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_PADDING_X 6
31 #define EXTRA_ICON_PADDING 3
32 #define MAX_TABLEN 32
33
34 #define NUM_MSG_SEQUENCES  2
35 #define PARENT_SEQ_INDEX   0
36 #define TAB_SEQ_INDEX      1
37
38 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
39 #define expect_str(expected, got)\
40  ok ( strcmp(expected, got) == 0, "Expected '%s', got '%s'\n", expected, got)
41
42 #define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)
43
44 #define TabCheckSetSize(hwnd, SetWidth, SetHeight, ExpWidth, ExpHeight, Msg)\
45     SendMessage (hwnd, TCM_SETITEMSIZE, 0,\
46         (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));\
47     if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);\
48     CheckSize(hwnd, ExpWidth, ExpHeight, Msg);
49
50 #define CheckSize(hwnd,width,height,msg)\
51     SendMessage (hwnd, TCM_GETITEMRECT, 0, (LPARAM) &rTab);\
52     if ((width  >= 0) && (height < 0))\
53         ok (width  == rTab.right  - rTab.left, "%s: Expected width [%d] got [%d]\n",\
54         msg, (int)width,  rTab.right  - rTab.left);\
55     else if ((height >= 0) && (width  < 0))\
56         ok (height == rTab.bottom - rTab.top,  "%s: Expected height [%d] got [%d]\n",\
57         msg, (int)height, rTab.bottom - rTab.top);\
58     else\
59         ok ((width  == rTab.right  - rTab.left) &&\
60             (height == rTab.bottom - rTab.top ),\
61             "%s: Expected [%d,%d] got [%d,%d]\n", msg, (int)width, (int)height,\
62             rTab.right - rTab.left, rTab.bottom - rTab.top);
63
64 static HFONT hFont = 0;
65
66 static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];
67
68 static const struct message create_parent_wnd_seq[] = {
69     { WM_GETMINMAXINFO, sent },
70     { WM_NCCREATE, sent },
71     { WM_NCCALCSIZE, sent|wparam, 0 },
72     { WM_CREATE, sent },
73     { WM_SHOWWINDOW, sent|wparam, 1 },
74     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
75     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
76     { WM_ACTIVATEAPP, sent|wparam, 1 },
77     { WM_NCACTIVATE, sent|wparam, 1 },
78     { WM_ACTIVATE, sent|wparam, 1 },
79     { WM_IME_SETCONTEXT, sent|wparam|defwinproc|optional, 1 },
80     { WM_IME_NOTIFY, sent|defwinproc|optional },
81     { WM_SETFOCUS, sent|wparam|defwinproc, 0 },
82     /* Win9x adds SWP_NOZORDER below */
83     { WM_WINDOWPOSCHANGED, sent},
84     { WM_NCCALCSIZE, sent|wparam|optional, 1 },
85     { WM_SIZE, sent },
86     { WM_MOVE, sent },
87     { 0 }
88 };
89
90 static const struct message add_tab_to_parent[] = {
91     { TCM_INSERTITEMA, sent },
92     { TCM_INSERTITEMA, sent|optional },
93     { WM_NOTIFYFORMAT, sent|defwinproc },
94     { WM_QUERYUISTATE, sent|wparam|lparam|defwinproc|optional, 0, 0 },
95     { WM_PARENTNOTIFY, sent|defwinproc },
96     { TCM_INSERTITEMA, sent },
97     { TCM_INSERTITEMA, sent },
98     { TCM_INSERTITEMA, sent },
99     { TCM_INSERTITEMA, sent|optional },
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|optional, 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_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
186     { TCM_SETCURSEL, sent|lparam, 0 },
187     { TCM_GETCURSEL, sent|wparam|lparam, 0, 0 },
188     { TCM_SETCURSEL, sent|lparam, 0 },
189     { TCM_SETCURSEL, sent|lparam, 0 },
190     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
191     { 0 }
192 };
193
194 static const struct message getset_extended_style_seq[] = {
195     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
196     { TCM_SETEXTENDEDSTYLE, sent },
197     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
198     { TCM_SETEXTENDEDSTYLE, sent },
199     { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
200     { 0 }
201 };
202
203 static const struct message getset_unicode_format_seq[] = {
204     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
205     { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
206     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
207     { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
208     { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
209     { 0 }
210 };
211
212 static const struct message getset_item_seq[] = {
213     { TCM_SETITEMA, sent },
214     { TCM_GETITEMA, sent },
215     { TCM_GETITEMA, sent },
216     { 0 }
217 };
218
219 static const struct message getset_tooltip_seq[] = {
220     { WM_NOTIFYFORMAT, sent|optional },
221     { WM_QUERYUISTATE, sent|wparam|lparam|optional, 0, 0 },
222     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
223     { WM_NOTIFYFORMAT, sent|optional },
224     { TCM_SETTOOLTIPS, sent|lparam, 0 },
225     { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
226     { TCM_SETTOOLTIPS, sent|lparam, 0 },
227     { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
228     { 0 }
229 };
230
231 static const struct message getset_tooltip_parent_seq[] = {
232     { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
233     { 0 }
234 };
235
236 static const struct message insert_focus_seq[] = {
237     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
238     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
239     { TCM_INSERTITEM, sent|wparam, 1 },
240     { WM_NOTIFYFORMAT, sent|defwinproc|optional },
241     { WM_QUERYUISTATE, sent|defwinproc|optional },
242     { WM_PARENTNOTIFY, sent|defwinproc|optional },
243     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
244     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
245     { TCM_INSERTITEM, sent|wparam, 2 },
246     { WM_NOTIFYFORMAT, sent|defwinproc|optional },
247     { WM_QUERYUISTATE, sent|defwinproc|optional, },
248     { WM_PARENTNOTIFY, sent|defwinproc|optional },
249     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
250     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
251     { TCM_SETCURFOCUS, sent|wparam|lparam, -1, 0 },
252     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
253     { TCM_INSERTITEM, sent|wparam, 3 },
254     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
255     { 0 }
256 };
257
258 static const struct message delete_focus_seq[] = {
259     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
260     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
261     { TCM_DELETEITEM, sent|wparam|lparam, 1, 0 },
262     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
263     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
264     { TCM_SETCURFOCUS, sent|wparam|lparam, -1, 0 },
265     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
266     { TCM_DELETEITEM, sent|wparam|lparam, 0, 0 },
267     { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
268     { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
269     { 0 }
270 };
271
272
273 static HWND
274 create_tabcontrol (DWORD style, DWORD mask)
275 {
276     HWND handle;
277     TCITEM tcNewTab;
278     static char text1[] = "Tab 1",
279     text2[] = "Wide Tab 2",
280     text3[] = "T 3";
281
282     handle = CreateWindow (
283         WC_TABCONTROLA,
284         "TestTab",
285         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
286         10, 10, 300, 100,
287         NULL, NULL, NULL, 0);
288
289     assert (handle);
290
291     SetWindowLong(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
292     SendMessage (handle, WM_SETFONT, 0, (LPARAM) hFont);
293
294     tcNewTab.mask = mask;
295     tcNewTab.pszText = text1;
296     tcNewTab.iImage = 0;
297     SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
298     tcNewTab.pszText = text2;
299     tcNewTab.iImage = 1;
300     SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
301     tcNewTab.pszText = text3;
302     tcNewTab.iImage = 2;
303     SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
304
305     if (winetest_interactive)
306     {
307         ShowWindow (handle, SW_SHOW);
308         RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
309         Sleep (1000);
310     }
311
312     return handle;
313 }
314
315 static LRESULT WINAPI parentWindowProcess(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
316 {
317     static LONG defwndproc_counter = 0;
318     LRESULT ret;
319     struct message msg;
320
321     /* do not log painting messages */
322     if (message != WM_PAINT &&
323         message != WM_ERASEBKGND &&
324         message != WM_NCPAINT &&
325         message != WM_NCHITTEST &&
326         message != WM_GETTEXT &&
327         message != WM_GETICON &&
328         message != WM_DEVICECHANGE)
329     {
330         trace("parent: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
331
332         msg.message = message;
333         msg.flags = sent|wparam|lparam;
334         if (defwndproc_counter) msg.flags |= defwinproc;
335         msg.wParam = wParam;
336         msg.lParam = lParam;
337         add_message(sequences, PARENT_SEQ_INDEX, &msg);
338     }
339
340     defwndproc_counter++;
341     ret = DefWindowProcA(hwnd, message, wParam, lParam);
342     defwndproc_counter--;
343
344     return ret;
345 }
346
347 static BOOL registerParentWindowClass(void)
348 {
349     WNDCLASSA cls;
350
351     cls.style = 0;
352     cls.lpfnWndProc = parentWindowProcess;
353     cls.cbClsExtra = 0;
354     cls.cbWndExtra = 0;
355     cls.hInstance = GetModuleHandleA(NULL);
356     cls.hIcon = 0;
357     cls.hCursor = LoadCursorA(0, IDC_ARROW);
358     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
359     cls.lpszMenuName = NULL;
360     cls.lpszClassName = "Tab test parent class";
361     return RegisterClassA(&cls);
362 }
363
364 static HWND createParentWindow(void)
365 {
366     if (!registerParentWindowClass())
367         return NULL;
368
369     return CreateWindowEx(0, "Tab test parent class",
370                           "Tab test parent window",
371                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
372                           WS_MAXIMIZEBOX | WS_VISIBLE,
373                           0, 0, 100, 100,
374                           GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
375 }
376
377 struct subclass_info
378 {
379     WNDPROC oldproc;
380 };
381
382 static LRESULT WINAPI tabSubclassProcess(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
383 {
384     struct subclass_info *info = (struct subclass_info *)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
385     static LONG defwndproc_counter = 0;
386     LRESULT ret;
387     struct message msg;
388
389     /* do not log painting messages */
390     if (message != WM_PAINT &&
391         message != WM_ERASEBKGND &&
392         message != WM_NCPAINT &&
393         message != WM_NCHITTEST &&
394         message != WM_GETTEXT &&
395         message != WM_GETICON &&
396         message != WM_DEVICECHANGE)
397     {
398         trace("tab: %p, %04x, %08lx, %08lx\n", hwnd, message, wParam, lParam);
399
400         msg.message = message;
401         msg.flags = sent|wparam|lparam;
402         if (defwndproc_counter) msg.flags |= defwinproc;
403         msg.wParam = wParam;
404         msg.lParam = lParam;
405         add_message(sequences, TAB_SEQ_INDEX, &msg);
406     }
407
408     defwndproc_counter++;
409     ret = CallWindowProcA(info->oldproc, hwnd, message, wParam, lParam);
410     defwndproc_counter--;
411
412     return ret;
413 }
414
415 static HWND createFilledTabControl(HWND parent_wnd, DWORD style, DWORD mask, INT nTabs)
416 {
417     HWND tabHandle;
418     TCITEM tcNewTab;
419     struct subclass_info *info;
420     RECT rect;
421     INT i;
422
423     info = HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info));
424     if (!info)
425         return NULL;
426
427     GetClientRect(parent_wnd, &rect);
428
429     tabHandle = CreateWindow (
430         WC_TABCONTROLA,
431         "TestTab",
432         WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
433         0, 0, rect.right, rect.bottom,
434         parent_wnd, NULL, NULL, 0);
435
436     assert(tabHandle);
437
438     info->oldproc = (WNDPROC)SetWindowLongPtrA(tabHandle, GWLP_WNDPROC, (LONG_PTR)tabSubclassProcess);
439     SetWindowLongPtrA(tabHandle, GWLP_USERDATA, (LONG_PTR)info);
440
441     tcNewTab.mask = mask;
442
443     for (i = 0; i < nTabs; i++)
444     {
445         char tabName[MAX_TABLEN];
446
447         sprintf(tabName, "Tab %d", i+1);
448         tcNewTab.pszText = tabName;
449         tcNewTab.iImage = i;
450         SendMessage (tabHandle, TCM_INSERTITEM, i, (LPARAM) &tcNewTab);
451     }
452
453     if (winetest_interactive)
454     {
455         ShowWindow (tabHandle, SW_SHOW);
456         RedrawWindow (tabHandle, NULL, 0, RDW_UPDATENOW);
457         Sleep (1000);
458     }
459
460     return tabHandle;
461 }
462
463 static HWND create_tooltip (HWND hTab, char toolTipText[])
464 {
465     HWND hwndTT;
466
467     TOOLINFO ti;
468     LPTSTR lptstr = toolTipText;
469     RECT rect;
470
471     /* Creating a tooltip window*/
472     hwndTT = CreateWindowEx(
473         WS_EX_TOPMOST,
474         TOOLTIPS_CLASS,
475         NULL,
476         WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
477         CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
478         hTab, NULL, 0, NULL);
479
480     SetWindowPos(
481         hwndTT,
482         HWND_TOPMOST,
483         0, 0, 0, 0,
484         SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
485
486     GetClientRect (hTab, &rect);
487
488     /* Initialize members of toolinfo*/
489     ti.cbSize = sizeof(TOOLINFO);
490     ti.uFlags = TTF_SUBCLASS;
491     ti.hwnd = hTab;
492     ti.hinst = 0;
493     ti.uId = 0;
494     ti.lpszText = lptstr;
495
496     ti.rect = rect;
497
498     /* Add toolinfo structure to the tooltip control */
499     SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) &ti);
500
501     return hwndTT;
502 }
503
504 static void test_tab(INT nMinTabWidth)
505 {
506     HWND hwTab;
507     RECT rTab;
508     HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
509     SIZE size;
510     HDC hdc;
511     HFONT hOldFont;
512     INT i, dpi, exp;
513
514     hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
515     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
516     /* Get System default MinTabWidth */
517     if (nMinTabWidth < 0)
518         nMinTabWidth = SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
519
520     hdc = GetDC(hwTab);
521     dpi = GetDeviceCaps(hdc, LOGPIXELSX);
522     hOldFont = SelectObject(hdc, (HFONT)SendMessage(hwTab, WM_GETFONT, 0, 0));
523     GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
524     trace("Tab1 text size: size.cx=%d size.cy=%d\n", size.cx, size.cy);
525     SelectObject(hdc, hOldFont);
526     ReleaseDC(hwTab, hdc);
527
528     trace ("  TCS_FIXEDWIDTH tabs no icon...\n");
529     CheckSize(hwTab, dpi, -1, "default width");
530     TabCheckSetSize(hwTab, 50, 20, 50, 20, "set size");
531     TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
532
533     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
534
535     trace ("  TCS_FIXEDWIDTH tabs with icon...\n");
536     TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
537     TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
538     TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
539
540     DestroyWindow (hwTab);
541
542     hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
543     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
544
545     hdc = GetDC(hwTab);
546     dpi = GetDeviceCaps(hdc, LOGPIXELSX);
547     ReleaseDC(hwTab, hdc);
548     trace ("  TCS_FIXEDWIDTH buttons no icon...\n");
549     CheckSize(hwTab, dpi, -1, "default width");
550     TabCheckSetSize(hwTab, 20, 20, 20, 20, "set size 1");
551     TabCheckSetSize(hwTab, 10, 50, 10, 50, "set size 2");
552     TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
553
554     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
555
556     trace ("  TCS_FIXEDWIDTH buttons with icon...\n");
557     TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
558     TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
559     TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
560     SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
561     TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
562
563     DestroyWindow (hwTab);
564
565     hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
566     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
567
568     hdc = GetDC(hwTab);
569     dpi = GetDeviceCaps(hdc, LOGPIXELSX);
570     ReleaseDC(hwTab, hdc);
571     trace ("  TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
572     CheckSize(hwTab, dpi, -1, "no icon, default width");
573
574     TabCheckSetSize(hwTab, 20, 20, 20, 20, "no icon, set size 1");
575     TabCheckSetSize(hwTab, 10, 50, 10, 50, "no icon, set size 2");
576     TabCheckSetSize(hwTab, 0, 1, 0, 1, "no icon, min size");
577
578     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
579
580     TabCheckSetSize(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
581     TabCheckSetSize(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
582     TabCheckSetSize(hwTab, 0, 1, 25, 1, "with icon, min size");
583     SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
584     TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
585
586     DestroyWindow (hwTab);
587
588     hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
589     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
590
591     trace ("  non fixed width, with text...\n");
592     exp = max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth);
593     SendMessage( hwTab, TCM_GETITEMRECT, 0, (LPARAM)&rTab );
594     ok( rTab.right  - rTab.left == exp || broken(rTab.right  - rTab.left == DEFAULT_MIN_TAB_WIDTH),
595         "no icon, default width: Expected width [%d] got [%d]\n", exp, rTab.right - rTab.left );
596
597     for (i=0; i<8; i++)
598     {
599         INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
600
601         SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
602         SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
603
604         TabCheckSetSize(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
605         TabCheckSetSize(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
606
607         SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
608         nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;
609
610         TabCheckSetSize(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
611         TabCheckSetSize(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
612         TabCheckSetSize(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
613     }
614     DestroyWindow (hwTab);
615
616     hwTab = create_tabcontrol(0, TCIF_IMAGE);
617     SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
618
619     trace ("  non fixed width, no text...\n");
620     exp = (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth;
621     SendMessage( hwTab, TCM_GETITEMRECT, 0, (LPARAM)&rTab );
622     ok( rTab.right  - rTab.left == exp || broken(rTab.right  - rTab.left == DEFAULT_MIN_TAB_WIDTH),
623         "no icon, default width: Expected width [%d] got [%d]\n", exp, rTab.right - rTab.left );
624
625     for (i=0; i<8; i++)
626     {
627         INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
628
629         SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
630         SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
631
632         TabCheckSetSize(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
633         TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
634
635         SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
636         if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
637             nTabWidth += EXTRA_ICON_PADDING *(i-1);
638
639         TabCheckSetSize(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
640         TabCheckSetSize(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
641         TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
642     }
643
644     DestroyWindow (hwTab);
645
646     ImageList_Destroy(himl);
647     DeleteObject(hFont);
648 }
649
650 static void test_getters_setters(HWND parent_wnd, INT nTabs)
651 {
652     HWND hTab;
653     RECT rTab;
654     INT nTabsRetrieved;
655     INT rowCount;
656     INT dpi;
657     HDC hdc;
658
659     ok(parent_wnd != NULL, "no parent window!\n");
660     flush_sequences(sequences, NUM_MSG_SEQUENCES);
661
662     hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
663     ok(hTab != NULL, "Failed to create tab control\n");
664
665     if(!winetest_interactive)
666         ok_sequence(sequences, TAB_SEQ_INDEX, add_tab_to_parent,
667                     "Tab sequence, after adding tab control to parent", TRUE);
668     else
669         ok_sequence(sequences, TAB_SEQ_INDEX, add_tab_to_parent_interactive,
670                     "Tab sequence, after adding tab control to parent", TRUE);
671
672     if(!winetest_interactive)
673         ok_sequence(sequences, PARENT_SEQ_INDEX, add_tab_control_parent_seq,
674                     "Parent after sequence, adding tab control to parent", TRUE);
675     else
676         ok_sequence(sequences, PARENT_SEQ_INDEX, add_tab_control_parent_seq_interactive,
677                     "Parent after sequence, adding tab control to parent", TRUE);
678
679     flush_sequences(sequences, NUM_MSG_SEQUENCES);
680     ok(SendMessage(hTab, TCM_SETMINTABWIDTH, 0, -1) > 0,"TCM_SETMINTABWIDTH returned < 0\n");
681     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Set minTabWidth test parent sequence", FALSE);
682
683     /* Testing GetItemCount */
684     flush_sequences(sequences, NUM_MSG_SEQUENCES);
685     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
686     expect(nTabs, nTabsRetrieved);
687     ok_sequence(sequences, TAB_SEQ_INDEX, get_item_count_seq, "Get itemCount test sequence", FALSE);
688     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset itemCount test parent sequence", FALSE);
689
690     /* Testing GetRowCount */
691     flush_sequences(sequences, NUM_MSG_SEQUENCES);
692     rowCount = SendMessage(hTab, TCM_GETROWCOUNT, 0, 0);
693     expect(1, rowCount);
694     ok_sequence(sequences, TAB_SEQ_INDEX, get_row_count_seq, "Get rowCount test sequence", FALSE);
695     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Get rowCount test parent sequence", FALSE);
696
697     /* Testing GetItemRect */
698     flush_sequences(sequences, NUM_MSG_SEQUENCES);
699     ok(SendMessage(hTab, TCM_GETITEMRECT, 0, (LPARAM) &rTab), "GetItemRect failed.\n");
700
701     hdc = GetDC(hTab);
702     dpi = GetDeviceCaps(hdc, LOGPIXELSX);
703     ReleaseDC(hTab, hdc);
704     CheckSize(hTab, dpi, -1 , "Default Width");
705     ok_sequence(sequences, TAB_SEQ_INDEX, get_item_rect_seq, "Get itemRect test sequence", FALSE);
706     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Get itemRect test parent sequence", FALSE);
707
708     /* Testing CurFocus */
709     {
710         INT focusIndex;
711
712         flush_sequences(sequences, NUM_MSG_SEQUENCES);
713
714         /* Testing CurFocus with largest appropriate value */
715         SendMessage(hTab, TCM_SETCURFOCUS, nTabs-1, 0);
716         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
717             expect(nTabs-1, focusIndex);
718
719         /* Testing CurFocus with negative value */
720         SendMessage(hTab, TCM_SETCURFOCUS, -10, 0);
721         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
722             expect(-1, focusIndex);
723
724         /* Testing CurFocus with value larger than number of tabs */
725         focusIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
726         todo_wine{
727             expect(-1, focusIndex);
728         }
729
730         SendMessage(hTab, TCM_SETCURFOCUS, nTabs+1, 0);
731         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
732             expect(1, focusIndex);
733
734         ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_focus_seq, "Getset curFoc test sequence", FALSE);
735     }
736
737     /* Testing CurSel */
738     {
739         INT selectionIndex;
740         INT focusIndex;
741         TCITEM tcItem;
742
743         flush_sequences(sequences, NUM_MSG_SEQUENCES);
744
745         /* Testing CurSel with largest appropriate value */
746         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs-1, 0);
747             expect(1, selectionIndex);
748         selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
749             expect(nTabs-1, selectionIndex);
750
751         /* Focus should switch with selection */
752         focusIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
753             expect(nTabs-1, focusIndex);
754
755         /* Testing CurSel with negative value */
756         SendMessage(hTab, TCM_SETCURSEL, -10, 0);
757         selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
758             expect(-1, selectionIndex);
759
760         /* Testing CurSel with value larger than number of tabs */
761         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, 1, 0);
762             expect(-1, selectionIndex);
763
764         selectionIndex = SendMessage(hTab, TCM_SETCURSEL, nTabs+1, 0);
765             expect(-1, selectionIndex);
766         selectionIndex = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
767             expect(1, selectionIndex);
768
769         ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_sel_seq, "Getset curSel test sequence", FALSE);
770         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset curSel test parent sequence", FALSE);
771
772         /* selected item should have TCIS_BUTTONPRESSED state
773            It doesn't depend on button state */
774         memset(&tcItem, 0, sizeof(TCITEM));
775         tcItem.mask = TCIF_STATE;
776         tcItem.dwStateMask = TCIS_BUTTONPRESSED;
777         selectionIndex = SendMessage(hTab, TCM_GETCURSEL, 0, 0);
778         SendMessage(hTab, TCM_GETITEM, selectionIndex, (LPARAM) &tcItem);
779         ok (tcItem.dwState & TCIS_BUTTONPRESSED || broken(tcItem.dwState == 0), /* older comctl32 */
780             "Selected item should have TCIS_BUTTONPRESSED\n");
781     }
782
783     /* Testing ExtendedStyle */
784     {
785         DWORD prevExtendedStyle;
786         DWORD extendedStyle;
787
788         flush_sequences(sequences, NUM_MSG_SEQUENCES);
789
790         /* Testing Flat Separators */
791         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
792         prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_FLATSEPARATORS);
793         expect(extendedStyle, prevExtendedStyle);
794
795         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
796         expect(TCS_EX_FLATSEPARATORS, extendedStyle);
797
798         /* Testing Register Drop */
799         prevExtendedStyle = SendMessage(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_REGISTERDROP);
800             expect(extendedStyle, prevExtendedStyle);
801
802         extendedStyle = SendMessage(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
803         todo_wine{
804             expect(TCS_EX_REGISTERDROP, extendedStyle);
805         }
806
807         ok_sequence(sequences, TAB_SEQ_INDEX, getset_extended_style_seq, "Getset extendedStyle test sequence", FALSE);
808         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset extendedStyle test parent sequence", FALSE);
809     }
810
811     /* Testing UnicodeFormat */
812     {
813         INT unicodeFormat;
814
815         flush_sequences(sequences, NUM_MSG_SEQUENCES);
816
817         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
818         todo_wine{
819             expect(0, unicodeFormat);
820         }
821         unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
822             expect(1, unicodeFormat);
823
824         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, FALSE, 0);
825             expect(1, unicodeFormat);
826         unicodeFormat = SendMessage(hTab, TCM_GETUNICODEFORMAT, 0, 0);
827             expect(0, unicodeFormat);
828
829         unicodeFormat = SendMessage(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
830             expect(0, unicodeFormat);
831
832         ok_sequence(sequences, TAB_SEQ_INDEX, getset_unicode_format_seq, "Getset unicodeFormat test sequence", FALSE);
833         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset unicodeFormat test parent sequence", FALSE);
834     }
835
836     /* Testing GetSet Item */
837     {
838         TCITEM tcItem;
839         DWORD ret;
840         char szText[32] = "New Label";
841
842         /* passing invalid index should result in initialization to zero
843            for members mentioned in mask requested */
844
845         /* valid range here is [0,4] */
846         memset(&tcItem, 0xcc, sizeof(tcItem));
847         tcItem.mask = TCIF_PARAM;
848         ret = SendMessage(hTab, TCM_GETITEM, 5, (LPARAM)&tcItem);
849         expect(FALSE, ret);
850         ok(tcItem.lParam == 0, "Expected zero lParam, got %lu\n", tcItem.lParam);
851
852         memset(&tcItem, 0xcc, sizeof(tcItem));
853         tcItem.mask = TCIF_IMAGE;
854         ret = SendMessage(hTab, TCM_GETITEM, 5, (LPARAM)&tcItem);
855         expect(FALSE, ret);
856         expect(0, tcItem.iImage);
857
858         memset(&tcItem, 0xcc, sizeof(tcItem));
859         tcItem.mask = TCIF_TEXT;
860         tcItem.pszText = szText;
861         szText[0] = 'a';
862         ret = SendMessage(hTab, TCM_GETITEM, 5, (LPARAM)&tcItem);
863         expect(FALSE, ret);
864         expect('a', szText[0]);
865
866         memset(&tcItem, 0xcc, sizeof(tcItem));
867         tcItem.mask = TCIF_STATE;
868         tcItem.dwStateMask = 0;
869         tcItem.dwState = TCIS_BUTTONPRESSED;
870         ret = SendMessage(hTab, TCM_GETITEM, 5, (LPARAM)&tcItem);
871         expect(FALSE, ret);
872         ok(tcItem.dwState == 0, "Expected zero dwState, got %u\n", tcItem.dwState);
873
874         memset(&tcItem, 0xcc, sizeof(tcItem));
875         tcItem.mask = TCIF_STATE;
876         tcItem.dwStateMask = TCIS_BUTTONPRESSED;
877         tcItem.dwState = TCIS_BUTTONPRESSED;
878         ret = SendMessage(hTab, TCM_GETITEM, 5, (LPARAM)&tcItem);
879         expect(FALSE, ret);
880         ok(tcItem.dwState == 0, "Expected zero dwState\n");
881
882         /* check with negative index to be sure */
883         memset(&tcItem, 0xcc, sizeof(tcItem));
884         tcItem.mask = TCIF_PARAM;
885         ret = SendMessage(hTab, TCM_GETITEM, -1, (LPARAM)&tcItem);
886         expect(FALSE, ret);
887         ok(tcItem.lParam == 0, "Expected zero lParam, got %lu\n", tcItem.lParam);
888
889         memset(&tcItem, 0xcc, sizeof(tcItem));
890         tcItem.mask = TCIF_PARAM;
891         ret = SendMessage(hTab, TCM_GETITEM, -2, (LPARAM)&tcItem);
892         expect(FALSE, ret);
893         ok(tcItem.lParam == 0, "Expected zero lParam, got %lu\n", tcItem.lParam);
894
895         flush_sequences(sequences, NUM_MSG_SEQUENCES);
896
897         tcItem.mask = TCIF_TEXT;
898         tcItem.pszText = &szText[0];
899         tcItem.cchTextMax = sizeof(szText);
900
901         strcpy(szText, "New Label");
902         ok ( SendMessage(hTab, TCM_SETITEM, 0, (LPARAM) &tcItem), "Setting new item failed.\n");
903         ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
904         expect_str("New Label", tcItem.pszText);
905
906         ok ( SendMessage(hTab, TCM_GETITEM, 1, (LPARAM) &tcItem), "Getting item failed.\n");
907         expect_str("Tab 2", tcItem.pszText);
908
909         ok_sequence(sequences, TAB_SEQ_INDEX, getset_item_seq, "Getset item test sequence", FALSE);
910         ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset item test parent sequence", FALSE);
911
912         /* TCIS_BUTTONPRESSED doesn't depend on tab style */
913         memset(&tcItem, 0, sizeof(tcItem));
914         tcItem.mask = TCIF_STATE;
915         tcItem.dwStateMask = TCIS_BUTTONPRESSED;
916         tcItem.dwState = TCIS_BUTTONPRESSED;
917         ok ( SendMessage(hTab, TCM_SETITEM, 0, (LPARAM) &tcItem), "Setting new item failed.\n");
918         tcItem.dwState = 0;
919         ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
920         if (tcItem.dwState)
921         {
922             ok (tcItem.dwState == TCIS_BUTTONPRESSED, "TCIS_BUTTONPRESSED should be set.\n");
923             /* next highlight item, test that dwStateMask actually masks */
924             tcItem.mask = TCIF_STATE;
925             tcItem.dwStateMask = TCIS_HIGHLIGHTED;
926             tcItem.dwState = TCIS_HIGHLIGHTED;
927             ok ( SendMessage(hTab, TCM_SETITEM, 0, (LPARAM) &tcItem), "Setting new item failed.\n");
928             tcItem.dwState = 0;
929             ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
930             ok (tcItem.dwState == TCIS_HIGHLIGHTED, "TCIS_HIGHLIGHTED should be set.\n");
931             tcItem.mask = TCIF_STATE;
932             tcItem.dwStateMask = TCIS_BUTTONPRESSED;
933             tcItem.dwState = 0;
934             ok ( SendMessage(hTab, TCM_GETITEM, 0, (LPARAM) &tcItem), "Getting item failed.\n");
935             ok (tcItem.dwState == TCIS_BUTTONPRESSED, "TCIS_BUTTONPRESSED should be set.\n");
936         }
937         else win_skip( "Item state mask not supported\n" );
938     }
939
940     /* Testing GetSet ToolTip */
941     {
942         HWND toolTip;
943         char toolTipText[32] = "ToolTip Text Test";
944
945         flush_sequences(sequences, NUM_MSG_SEQUENCES);
946
947         toolTip = create_tooltip(hTab, toolTipText);
948         SendMessage(hTab, TCM_SETTOOLTIPS, (LPARAM) toolTip, 0);
949         ok (toolTip == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.\n");
950
951         SendMessage(hTab, TCM_SETTOOLTIPS, 0, 0);
952         ok (NULL  == (HWND) SendMessage(hTab,TCM_GETTOOLTIPS,0,0), "ToolTip was set incorrectly.\n");
953
954         ok_sequence(sequences, TAB_SEQ_INDEX, getset_tooltip_seq, "Getset tooltip test sequence", TRUE);
955         ok_sequence(sequences, PARENT_SEQ_INDEX, getset_tooltip_parent_seq, "Getset tooltip test parent sequence", TRUE);
956     }
957
958     DestroyWindow(hTab);
959 }
960
961 static void test_adjustrect(HWND parent_wnd)
962 {
963     HWND hTab;
964     INT r;
965
966     ok(parent_wnd != NULL, "no parent window!\n");
967
968     hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, 0, 0);
969     ok(hTab != NULL, "Failed to create tab control\n");
970
971     r = SendMessage(hTab, TCM_ADJUSTRECT, FALSE, 0);
972     expect(-1, r);
973
974     r = SendMessage(hTab, TCM_ADJUSTRECT, TRUE, 0);
975     expect(-1, r);
976 }
977 static void test_insert_focus(HWND parent_wnd)
978 {
979     HWND hTab;
980     INT nTabsRetrieved;
981     INT r;
982     TCITEM tcNewTab;
983     DWORD mask = TCIF_TEXT|TCIF_IMAGE;
984     static char tabName[] = "TAB";
985     tcNewTab.mask = mask;
986     tcNewTab.pszText = tabName;
987
988     ok(parent_wnd != NULL, "no parent window!\n");
989
990     hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, mask, 0);
991     ok(hTab != NULL, "Failed to create tab control\n");
992
993     flush_sequences(sequences, NUM_MSG_SEQUENCES);
994
995     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
996     expect(0, nTabsRetrieved);
997
998     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
999     expect(-1, r);
1000
1001     tcNewTab.iImage = 1;
1002     r = SendMessage(hTab, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
1003     expect(0, r);
1004
1005     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
1006     expect(1, nTabsRetrieved);
1007
1008     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1009     expect(0, r);
1010
1011     tcNewTab.iImage = 2;
1012     r = SendMessage(hTab, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
1013     expect(1, r);
1014
1015     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
1016     expect(2, nTabsRetrieved);
1017
1018     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1019     expect(0, r);
1020
1021     r = SendMessage(hTab, TCM_SETCURFOCUS, -1, 0);
1022     expect(0, r);
1023
1024     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1025     expect(-1, r);
1026
1027     tcNewTab.iImage = 3;
1028     r = SendMessage(hTab, TCM_INSERTITEM, 3, (LPARAM) &tcNewTab);
1029     expect(2, r);
1030
1031     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1032     expect(2, r);
1033
1034     ok_sequence(sequences, TAB_SEQ_INDEX, insert_focus_seq, "insert_focus test sequence", FALSE);
1035     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "insert_focus parent test sequence", FALSE);
1036
1037     DestroyWindow(hTab);
1038 }
1039
1040 static void test_delete_focus(HWND parent_wnd)
1041 {
1042     HWND hTab;
1043     INT nTabsRetrieved;
1044     INT r;
1045
1046     ok(parent_wnd != NULL, "no parent window!\n");
1047
1048     hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, 2);
1049     ok(hTab != NULL, "Failed to create tab control\n");
1050
1051     flush_sequences(sequences, NUM_MSG_SEQUENCES);
1052
1053     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
1054     expect(2, nTabsRetrieved);
1055
1056     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1057     expect(0, r);
1058
1059     r = SendMessage(hTab, TCM_DELETEITEM, 1, 0);
1060     expect(1, r);
1061
1062     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
1063     expect(1, nTabsRetrieved);
1064
1065     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1066     expect(0, r);
1067
1068     r = SendMessage(hTab, TCM_SETCURFOCUS, -1, 0);
1069     expect(0, r);
1070
1071     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1072     expect(-1, r);
1073
1074     r = SendMessage(hTab, TCM_DELETEITEM, 0, 0);
1075     expect(1, r);
1076
1077     nTabsRetrieved = SendMessage(hTab, TCM_GETITEMCOUNT, 0, 0);
1078     expect(0, nTabsRetrieved);
1079
1080     r = SendMessage(hTab, TCM_GETCURFOCUS, 0, 0);
1081     expect(-1, r);
1082
1083     ok_sequence(sequences, TAB_SEQ_INDEX, delete_focus_seq, "delete_focus test sequence", FALSE);
1084     ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "delete_focus parent test sequence", FALSE);
1085
1086     DestroyWindow(hTab);
1087 }
1088
1089 static void test_removeimage(HWND parent_wnd)
1090 {
1091     static const BYTE bits[32];
1092     HWND hwTab;
1093     INT i;
1094     TCITEM item;
1095     HICON hicon;
1096     HIMAGELIST himl = ImageList_Create(16, 16, ILC_COLOR, 3, 4);
1097
1098     hicon = CreateIcon(NULL, 16, 16, 1, 1, bits, bits);
1099     ImageList_AddIcon(himl, hicon);
1100     ImageList_AddIcon(himl, hicon);
1101     ImageList_AddIcon(himl, hicon);
1102
1103     hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
1104     SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
1105
1106     memset(&item, 0, sizeof(TCITEM));
1107     item.mask = TCIF_IMAGE;
1108
1109     for(i = 0; i < 3; i++) {
1110         SendMessage(hwTab, TCM_GETITEM, i, (LPARAM)&item);
1111         expect(i, item.iImage);
1112     }
1113
1114     /* remove image middle image */
1115     SendMessage(hwTab, TCM_REMOVEIMAGE, 1, 0);
1116     expect(2, ImageList_GetImageCount(himl));
1117     item.iImage = -1;
1118     SendMessage(hwTab, TCM_GETITEM, 0, (LPARAM)&item);
1119     expect(0, item.iImage);
1120     item.iImage = 0;
1121     SendMessage(hwTab, TCM_GETITEM, 1, (LPARAM)&item);
1122     expect(-1, item.iImage);
1123     item.iImage = 0;
1124     SendMessage(hwTab, TCM_GETITEM, 2, (LPARAM)&item);
1125     expect(1, item.iImage);
1126     /* remove first image */
1127     SendMessage(hwTab, TCM_REMOVEIMAGE, 0, 0);
1128     expect(1, ImageList_GetImageCount(himl));
1129     item.iImage = 0;
1130     SendMessage(hwTab, TCM_GETITEM, 0, (LPARAM)&item);
1131     expect(-1, item.iImage);
1132     item.iImage = 0;
1133     SendMessage(hwTab, TCM_GETITEM, 1, (LPARAM)&item);
1134     expect(-1, item.iImage);
1135     item.iImage = -1;
1136     SendMessage(hwTab, TCM_GETITEM, 2, (LPARAM)&item);
1137     expect(0, item.iImage);
1138     /* remove the last one */
1139     SendMessage(hwTab, TCM_REMOVEIMAGE, 0, 0);
1140     expect(0, ImageList_GetImageCount(himl));
1141     for(i = 0; i < 3; i++) {
1142         item.iImage = 0;
1143         SendMessage(hwTab, TCM_GETITEM, i, (LPARAM)&item);
1144         expect(-1, item.iImage);
1145     }
1146
1147     DestroyWindow(hwTab);
1148     ImageList_Destroy(himl);
1149     DestroyIcon(hicon);
1150 }
1151
1152 START_TEST(tab)
1153 {
1154     HWND parent_wnd;
1155     LOGFONTA logfont;
1156
1157     lstrcpyA(logfont.lfFaceName, "Arial");
1158     memset(&logfont, 0, sizeof(logfont));
1159     logfont.lfHeight = -12;
1160     logfont.lfWeight = FW_NORMAL;
1161     logfont.lfCharSet = ANSI_CHARSET;
1162     hFont = CreateFontIndirectA(&logfont);
1163
1164     InitCommonControls();
1165
1166     trace ("Testing with default MinWidth\n");
1167     test_tab(-1);
1168     trace ("Testing with MinWidth set to -3\n");
1169     test_tab(-3);
1170     trace ("Testing with MinWidth set to 24\n");
1171     test_tab(24);
1172     trace ("Testing with MinWidth set to 54\n");
1173     test_tab(54);
1174     trace ("Testing with MinWidth set to 94\n");
1175     test_tab(94);
1176
1177     init_msg_sequences(sequences, NUM_MSG_SEQUENCES);
1178
1179     parent_wnd = createParentWindow();
1180     ok(parent_wnd != NULL, "Failed to create parent window!\n");
1181
1182     /* Testing getters and setters with 5 tabs */
1183     test_getters_setters(parent_wnd, 5);
1184
1185     test_adjustrect(parent_wnd);
1186
1187     test_insert_focus(parent_wnd);
1188     test_delete_focus(parent_wnd);
1189     test_removeimage(parent_wnd);
1190
1191     DestroyWindow(parent_wnd);
1192 }