tab.c 53 KB
Newer Older
1 2 3
/* Unit test suite for tab control.
 *
 * Copyright 2003 Vitaliy Margolen
4
 * Copyright 2007 Hagop Hagopian
5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * 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 22
 */

#include <windows.h>
#include <commctrl.h>
23
#include <stdio.h>
24 25

#include "wine/test.h"
26
#include "msg.h"
27

28 29 30
#define DEFAULT_MIN_TAB_WIDTH 54
#define TAB_PADDING_X 6
#define EXTRA_ICON_PADDING 3
31 32
#define MAX_TABLEN 32

33 34 35 36
#define NUM_MSG_SEQUENCES  2
#define PARENT_SEQ_INDEX   0
#define TAB_SEQ_INDEX      1

37 38 39
#define expect(expected,got) expect_(__LINE__, expected, got)
static inline void expect_(unsigned line, DWORD expected, DWORD got)
{
40
    ok_(__FILE__, line)(expected == got, "Expected %ld, got %ld\n", expected, got);
41 42
}

43 44
#define expect_str(expected, got)\
 ok ( strcmp(expected, got) == 0, "Expected '%s', got '%s'\n", expected, got)
45 46 47

#define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)

48 49 50 51 52
static HIMAGELIST (WINAPI *pImageList_Create)(INT,INT,UINT,INT,INT);
static BOOL (WINAPI *pImageList_Destroy)(HIMAGELIST);
static INT (WINAPI *pImageList_GetImageCount)(HIMAGELIST);
static INT (WINAPI *pImageList_ReplaceIcon)(HIMAGELIST,INT,HICON);

53 54 55 56
static void CheckSize(HWND hwnd, INT width, INT height, const char *msg, int line)
{
    RECT r;

57
    SendMessageA(hwnd, TCM_GETITEMRECT, 0, (LPARAM)&r);
58
    if (width >= 0 && height < 0)
59
        ok_(__FILE__,line) (width == r.right - r.left, "%s: Expected width [%d] got [%ld]\n",
60
            msg, width, r.right - r.left);
61
    else if (height >= 0 && width < 0)
62
        ok_(__FILE__,line) (height == r.bottom - r.top,  "%s: Expected height [%d] got [%ld]\n",
63
            msg, height, r.bottom - r.top);
64 65
    else
        ok_(__FILE__,line) ((width  == r.right  - r.left) && (height == r.bottom - r.top ),
66
	    "%s: Expected [%d,%d] got [%ld,%ld]\n", msg, width, height,
67 68 69 70 71 72 73 74
            r.right - r.left, r.bottom - r.top);
}

#define CHECKSIZE(hwnd,width,height,msg) CheckSize(hwnd,width,height,msg,__LINE__)

static void TabCheckSetSize(HWND hwnd, INT set_width, INT set_height, INT exp_width,
    INT exp_height, const char *msg, int line)
{
75 76
    SendMessageA(hwnd, TCM_SETITEMSIZE, 0,
            MAKELPARAM((set_width >= 0) ? set_width : 0, (set_height >= 0) ? set_height : 0));
77 78 79 80 81 82
    if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);
    CheckSize(hwnd, exp_width, exp_height, msg, line);
}

#define TABCHECKSETSIZE(hwnd,set_width,set_height,exp_width,exp_height,msg) \
    TabCheckSetSize(hwnd,set_width,set_height,exp_width,exp_height,msg,__LINE__)
83

84 85
static HFONT hFont;
static DRAWITEMSTRUCT g_drawitem;
86
static HWND parent_wnd;
87
static LRESULT tcn_selchanging_result;
88
static DWORD winevent_hook_thread_id;
89

90 91
static struct msg_sequence *sequences[NUM_MSG_SEQUENCES];

92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
static void CALLBACK msg_winevent_proc(HWINEVENTHOOK hevent,
				    DWORD event,
				    HWND hwnd,
				    LONG object_id,
				    LONG child_id,
				    DWORD thread_id,
				    DWORD event_time)
{
    struct message msg = {0};
    char class_name[256];

    ok(thread_id == winevent_hook_thread_id, "we didn't ask for events from other threads\n");

    /* ignore window and other system events */
    if (object_id != OBJID_CLIENT) return;

    /* ignore events not from a tab control */
    if (!GetClassNameA(hwnd, class_name, ARRAY_SIZE(class_name)) ||
        strcmp(class_name, WC_TABCONTROLA) != 0)
        return;

    msg.message = event;
    msg.flags = winevent_hook|wparam|lparam;
    msg.wParam = object_id;
    msg.lParam = child_id;
    add_message(sequences, TAB_SEQ_INDEX, &msg);
}

static void init_winevent_hook(void) {
    hwineventhook = SetWinEventHook(EVENT_MIN, EVENT_MAX, GetModuleHandleA(0), msg_winevent_proc,
        0, GetCurrentThreadId(), WINEVENT_INCONTEXT);
    winevent_hook_thread_id = GetCurrentThreadId();
    if (!hwineventhook)
        win_skip( "no win event hook support\n" );
}

static void uninit_winevent_hook(void) {
    if (!hwineventhook)
        return;

    UnhookWinEvent(hwineventhook);
    hwineventhook = 0;
}

136 137 138 139 140 141 142 143 144 145 146
static const struct message empty_sequence[] = {
    { 0 }
};

static const struct message get_row_count_seq[] = {
    { TCM_GETROWCOUNT, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_cur_focus_seq[] = {
    { TCM_SETCURFOCUS, sent|lparam, 0 },
147
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 5 },
148 149
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURFOCUS, sent|lparam, 0 },
150
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
151 152
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURSEL, sent|lparam, 0 },
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
    { TCM_SETCURFOCUS, sent|lparam, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_cur_focus_buttons_seq[] = {
    { TCM_SETCURFOCUS, sent|lparam, 0 },
    { TCM_GETITEMCOUNT, sent|defwinproc|optional },
    { TCM_GETITEMCOUNT, sent|defwinproc|optional },
    { EVENT_OBJECT_FOCUS, winevent_hook|wparam|lparam, OBJID_CLIENT, 5 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURFOCUS, sent|lparam, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURSEL, sent|lparam, 0 },
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
169 170 171 172 173 174 175
    { TCM_SETCURFOCUS, sent|lparam, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_cur_sel_seq[] = {
    { TCM_SETCURSEL, sent|lparam, 0 },
176
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 5 },
177
    { TCM_GETCURSEL, sent|wparam|lparam, 0, 0 },
178
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
179
    { TCM_SETCURSEL, sent|lparam, 0 },
180
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
181 182
    { TCM_GETCURSEL, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURSEL, sent|lparam, 0 },
183
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
    { TCM_SETCURSEL, sent|lparam, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_extended_style_seq[] = {
    { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
    { TCM_SETEXTENDEDSTYLE, sent },
    { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
    { TCM_SETEXTENDEDSTYLE, sent },
    { TCM_GETEXTENDEDSTYLE, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_unicode_format_seq[] = {
    { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
    { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
    { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
    { CCM_GETUNICODEFORMAT, sent|wparam|lparam, 0, 0 },
    { CCM_SETUNICODEFORMAT, sent|lparam, 0 },
    { 0 }
};

static const struct message getset_item_seq[] = {
    { TCM_SETITEMA, sent },
    { TCM_GETITEMA, sent },
    { TCM_GETITEMA, sent },
    { 0 }
};

static const struct message getset_tooltip_seq[] = {
215 216
    { WM_NOTIFYFORMAT, sent|optional },
    { WM_QUERYUISTATE, sent|wparam|lparam|optional, 0, 0 },
217
    { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
218
    { WM_NOTIFYFORMAT, sent|optional },
219 220 221 222 223 224 225 226 227 228 229 230
    { TCM_SETTOOLTIPS, sent|lparam, 0 },
    { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
    { TCM_SETTOOLTIPS, sent|lparam, 0 },
    { TCM_GETTOOLTIPS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

static const struct message getset_tooltip_parent_seq[] = {
    { WM_WINDOWPOSCHANGING, sent|wparam, 0 },
    { 0 }
};

231 232 233
static const struct message insert_focus_seq[] = {
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
234
    { TCM_INSERTITEMA, sent|wparam, 1 },
235
    { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
236 237 238
    { WM_NOTIFYFORMAT, sent|defwinproc|optional },
    { WM_QUERYUISTATE, sent|defwinproc|optional },
    { WM_PARENTNOTIFY, sent|defwinproc|optional },
239 240
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
241
    { TCM_INSERTITEMA, sent|wparam, 2 },
242
    { WM_NOTIFYFORMAT, sent|defwinproc|optional },
243
    { WM_QUERYUISTATE, sent|defwinproc|optional, },
244
    { WM_PARENTNOTIFY, sent|defwinproc|optional },
245
    { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
246 247 248
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURFOCUS, sent|wparam|lparam, -1, 0 },
249
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
250
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
251
    { TCM_INSERTITEMA, sent|wparam, 3 },
252
    { EVENT_OBJECT_CREATE, winevent_hook|wparam|lparam, OBJID_CLIENT, 3 },
253 254 255 256
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

257 258 259 260
static const struct message delete_focus_seq[] = {
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_DELETEITEM, sent|wparam|lparam, 1, 0 },
261
    { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CLIENT, 2 },
262 263 264
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_SETCURFOCUS, sent|wparam|lparam, -1, 0 },
265
    { EVENT_OBJECT_SELECTION, winevent_hook|wparam|lparam, OBJID_CLIENT, 0 },
266 267
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { TCM_DELETEITEM, sent|wparam|lparam, 0, 0 },
268
    { EVENT_OBJECT_DESTROY, winevent_hook|wparam|lparam, OBJID_CLIENT, 1 },
269 270 271 272 273
    { TCM_GETITEMCOUNT, sent|wparam|lparam, 0, 0 },
    { TCM_GETCURFOCUS, sent|wparam|lparam, 0, 0 },
    { 0 }
};

274 275 276 277 278
static const struct message rbuttonup_seq[] = {
    { WM_RBUTTONUP, sent|wparam|lparam, 0, 0 },
    { WM_CONTEXTMENU, sent|defwinproc },
    { 0 }
};
279

280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
static const struct message full_selchange_parent_seq[] = {
    { WM_NOTIFY, sent|id, 0, 0, TCN_SELCHANGING },
    { WM_NOTIFY, sent|id, 0, 0, TCN_SELCHANGE },
    { 0 }
};

static const struct message selchanging_parent_seq[] = {
    { WM_NOTIFY, sent|id, 0, 0, TCN_SELCHANGING },
    { 0 }
};

static const struct message selchange_parent_seq[] = {
    { WM_NOTIFY, sent|id, 0, 0, TCN_SELCHANGE },
    { 0 }
};

296 297 298 299 300
static const struct message setfocus_parent_seq[] = {
    { WM_NOTIFY, sent|id, 0, 0, TCN_FOCUSCHANGE },
    { 0 }
};

301
static HWND
302
create_tabcontrol (DWORD style, DWORD mask)
303 304
{
    HWND handle;
305
    TCITEMA tcNewTab;
306 307 308
    static char text1[] = "Tab 1",
    text2[] = "Wide Tab 2",
    text3[] = "T 3";
309

310 311 312
    handle = CreateWindowA(WC_TABCONTROLA, "TestTab",
            WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style, 10, 10, 300, 100, NULL,
            NULL, NULL, 0);
313
    ok(handle != NULL, "failed to create tab wnd\n");
314

315 316
    SetWindowLongA(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
    SendMessageA(handle, WM_SETFONT, 0, (LPARAM)hFont);
317

318
    tcNewTab.mask = mask;
319
    tcNewTab.pszText = text1;
320
    tcNewTab.iImage = 0;
321
    SendMessageA(handle, TCM_INSERTITEMA, 0, (LPARAM)&tcNewTab);
322
    tcNewTab.pszText = text2;
323
    tcNewTab.iImage = 1;
324
    SendMessageA(handle, TCM_INSERTITEMA, 1, (LPARAM)&tcNewTab);
325
    tcNewTab.pszText = text3;
326
    tcNewTab.iImage = 2;
327
    SendMessageA(handle, TCM_INSERTITEMA, 2, (LPARAM)&tcNewTab);
328

329 330 331 332 333 334
    if (winetest_interactive)
    {
        ShowWindow (handle, SW_SHOW);
        RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
        Sleep (1000);
    }
335 336 337 338

    return handle;
}

339
static LRESULT WINAPI parent_wnd_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
340
{
341
    static LONG defwndproc_counter = 0;
342
    struct message msg = { 0 };
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
    LRESULT ret;

    /* do not log painting messages */
    if (message != WM_PAINT &&
        message != WM_ERASEBKGND &&
        message != WM_NCPAINT &&
        message != WM_NCHITTEST &&
        message != WM_GETTEXT &&
        message != WM_GETICON &&
        message != WM_DEVICECHANGE)
    {
        msg.message = message;
        msg.flags = sent|wparam|lparam;
        if (defwndproc_counter) msg.flags |= defwinproc;
        msg.wParam = wParam;
        msg.lParam = lParam;
359 360
        if (message == WM_NOTIFY && lParam)
            msg.id = ((NMHDR*)lParam)->code;
361 362 363
        add_message(sequences, PARENT_SEQ_INDEX, &msg);
    }

364 365 366 367
    /* dump sent structure data */
    if (message == WM_DRAWITEM)
        g_drawitem = *(DRAWITEMSTRUCT*)lParam;

368 369 370 371 372 373 374
    if (message == WM_NOTIFY)
    {
        NMHDR *nmhdr = (NMHDR *)lParam;
        if (nmhdr && nmhdr->code == TCN_SELCHANGING)
            return tcn_selchanging_result;
    }

375 376 377 378 379 380 381 382 383 384 385 386
    defwndproc_counter++;
    ret = DefWindowProcA(hwnd, message, wParam, lParam);
    defwndproc_counter--;

    return ret;
}

static BOOL registerParentWindowClass(void)
{
    WNDCLASSA cls;

    cls.style = 0;
387
    cls.lpfnWndProc = parent_wnd_proc;
388 389 390 391
    cls.cbClsExtra = 0;
    cls.cbWndExtra = 0;
    cls.hInstance = GetModuleHandleA(NULL);
    cls.hIcon = 0;
392
    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
393 394 395 396 397 398 399 400 401 402 403
    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
    cls.lpszMenuName = NULL;
    cls.lpszClassName = "Tab test parent class";
    return RegisterClassA(&cls);
}

static HWND createParentWindow(void)
{
    if (!registerParentWindowClass())
        return NULL;

404 405 406
    return CreateWindowExA(0, "Tab test parent class", "Tab test parent window",
            WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_VISIBLE, 0, 0, 100, 100,
            GetDesktopWindow(), NULL, GetModuleHandleA(NULL), NULL);
407 408
}

409
static LRESULT WINAPI tab_subclass_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
410
{
411
    WNDPROC oldproc = (WNDPROC)GetWindowLongPtrA(hwnd, GWLP_USERDATA);
412
    static LONG defwndproc_counter = 0;
413
    struct message msg = { 0 };
414 415 416 417 418 419 420 421 422
    LRESULT ret;

    /* do not log painting messages */
    if (message != WM_PAINT &&
        message != WM_ERASEBKGND &&
        message != WM_NCPAINT &&
        message != WM_NCHITTEST &&
        message != WM_GETTEXT &&
        message != WM_GETICON &&
423 424
        message != WM_DEVICECHANGE &&
        message != WM_GETOBJECT)
425 426 427 428 429 430 431 432 433 434
    {
        msg.message = message;
        msg.flags = sent|wparam|lparam;
        if (defwndproc_counter) msg.flags |= defwinproc;
        msg.wParam = wParam;
        msg.lParam = lParam;
        add_message(sequences, TAB_SEQ_INDEX, &msg);
    }

    defwndproc_counter++;
435
    ret = CallWindowProcA(oldproc, hwnd, message, wParam, lParam);
436 437 438 439 440 441
    defwndproc_counter--;

    return ret;
}

static HWND createFilledTabControl(HWND parent_wnd, DWORD style, DWORD mask, INT nTabs)
442 443
{
    HWND tabHandle;
444
    TCITEMA tcNewTab;
445
    WNDPROC oldproc;
446
    RECT rect;
447 448
    INT i;

449 450
    GetClientRect(parent_wnd, &rect);

451 452 453
    tabHandle = CreateWindowA(WC_TABCONTROLA, "TestTab",
            WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style, 0, 0, rect.right,
            rect.bottom, parent_wnd, NULL, NULL, 0);
454
    ok(tabHandle != NULL, "failed to create tab wnd\n");
455

456
    oldproc = (WNDPROC)SetWindowLongPtrA(tabHandle, GWLP_WNDPROC, (LONG_PTR)tab_subclass_proc);
457
    SetWindowLongPtrA(tabHandle, GWLP_USERDATA, (LONG_PTR)oldproc);
458 459 460 461 462 463 464 465 466 467

    tcNewTab.mask = mask;

    for (i = 0; i < nTabs; i++)
    {
        char tabName[MAX_TABLEN];

        sprintf(tabName, "Tab %d", i+1);
        tcNewTab.pszText = tabName;
        tcNewTab.iImage = i;
468
        SendMessageA(tabHandle, TCM_INSERTITEMA, i, (LPARAM)&tcNewTab);
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
    }

    if (winetest_interactive)
    {
        ShowWindow (tabHandle, SW_SHOW);
        RedrawWindow (tabHandle, NULL, 0, RDW_UPDATENOW);
        Sleep (1000);
    }

    return tabHandle;
}

static HWND create_tooltip (HWND hTab, char toolTipText[])
{
    HWND hwndTT;

485 486
    TTTOOLINFOA ti;
    LPSTR lptstr = toolTipText;
487 488 489
    RECT rect;

    /* Creating a tooltip window*/
490 491 492
    hwndTT = CreateWindowExA(WS_EX_TOPMOST, TOOLTIPS_CLASSA, NULL,
            WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
            CW_USEDEFAULT, hTab, NULL, 0, NULL);
493 494 495 496 497 498 499 500 501 502

    SetWindowPos(
        hwndTT,
        HWND_TOPMOST,
        0, 0, 0, 0,
        SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);

    GetClientRect (hTab, &rect);

    /* Initialize members of toolinfo*/
503
    ti.cbSize = sizeof(TTTOOLINFOA);
504 505 506 507 508 509 510 511 512
    ti.uFlags = TTF_SUBCLASS;
    ti.hwnd = hTab;
    ti.hinst = 0;
    ti.uId = 0;
    ti.lpszText = lptstr;

    ti.rect = rect;

    /* Add toolinfo structure to the tooltip control */
513
    SendMessageA(hwndTT, TTM_ADDTOOLA, 0, (LPARAM)&ti);
514 515 516 517

    return hwndTT;
}

518
static void test_tab(INT nMinTabWidth)
519 520
{
    HWND hwTab;
521
    RECT rTab;
522
    HIMAGELIST himl = pImageList_Create(21, 21, ILC_COLOR, 3, 4);
523 524 525
    SIZE size;
    HDC hdc;
    HFONT hOldFont;
526
    INT i, dpi, exp;
527 528

    hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
529
    SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
530 531
    /* Get System default MinTabWidth */
    if (nMinTabWidth < 0)
532
        nMinTabWidth = SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
533 534

    hdc = GetDC(hwTab);
535
    dpi = GetDeviceCaps(hdc, LOGPIXELSX);
536
    hOldFont = SelectObject(hdc, (HFONT)SendMessageA(hwTab, WM_GETFONT, 0, 0));
537
    GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
538
    trace("Tab1 text size: size.cx=%ld size.cy=%ld\n", size.cx, size.cy);
539 540 541 542
    SelectObject(hdc, hOldFont);
    ReleaseDC(hwTab, hdc);

    trace ("  TCS_FIXEDWIDTH tabs no icon...\n");
543 544 545
    CHECKSIZE(hwTab, dpi, -1, "default width");
    TABCHECKSETSIZE(hwTab, 50, 20, 50, 20, "set size");
    TABCHECKSETSIZE(hwTab, 0, 1, 0, 1, "min size");
546

547
    SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
548

549
    trace ("  TCS_FIXEDWIDTH tabs with icon...\n");
550 551 552
    TABCHECKSETSIZE(hwTab, 50, 30, 50, 30, "set size > icon");
    TABCHECKSETSIZE(hwTab, 20, 20, 25, 20, "set size < icon");
    TABCHECKSETSIZE(hwTab, 0, 1, 25, 1, "min size");
553 554

    DestroyWindow (hwTab);
555

556
    hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
557
    SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
558

559 560 561
    hdc = GetDC(hwTab);
    dpi = GetDeviceCaps(hdc, LOGPIXELSX);
    ReleaseDC(hwTab, hdc);
562
    trace ("  TCS_FIXEDWIDTH buttons no icon...\n");
563 564 565 566
    CHECKSIZE(hwTab, dpi, -1, "default width");
    TABCHECKSETSIZE(hwTab, 20, 20, 20, 20, "set size 1");
    TABCHECKSETSIZE(hwTab, 10, 50, 10, 50, "set size 2");
    TABCHECKSETSIZE(hwTab, 0, 1, 0, 1, "min size");
567

568
    SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
569

570
    trace ("  TCS_FIXEDWIDTH buttons with icon...\n");
571 572 573
    TABCHECKSETSIZE(hwTab, 50, 30, 50, 30, "set size > icon");
    TABCHECKSETSIZE(hwTab, 20, 20, 25, 20, "set size < icon");
    TABCHECKSETSIZE(hwTab, 0, 1, 25, 1, "min size");
574
    SendMessageA(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4, 4));
575
    TABCHECKSETSIZE(hwTab, 0, 1, 25, 1, "set padding, min size");
576 577 578

    DestroyWindow (hwTab);

579
    hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
580
    SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
581

582 583 584
    hdc = GetDC(hwTab);
    dpi = GetDeviceCaps(hdc, LOGPIXELSX);
    ReleaseDC(hwTab, hdc);
585
    trace ("  TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
586
    CHECKSIZE(hwTab, dpi, -1, "no icon, default width");
587

588 589 590
    TABCHECKSETSIZE(hwTab, 20, 20, 20, 20, "no icon, set size 1");
    TABCHECKSETSIZE(hwTab, 10, 50, 10, 50, "no icon, set size 2");
    TABCHECKSETSIZE(hwTab, 0, 1, 0, 1, "no icon, min size");
591

592
    SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
593

594 595 596
    TABCHECKSETSIZE(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
    TABCHECKSETSIZE(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
    TABCHECKSETSIZE(hwTab, 0, 1, 25, 1, "with icon, min size");
597
    SendMessageA(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4, 4));
598
    TABCHECKSETSIZE(hwTab, 0, 1, 25, 1, "set padding, min size");
599 600 601

    DestroyWindow (hwTab);

602
    hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
603
    SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
604

605
    trace ("  non fixed width, with text...\n");
606
    exp = max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth);
607
    SendMessageA( hwTab, TCM_GETITEMRECT, 0, (LPARAM)&rTab );
608
    ok( rTab.right  - rTab.left == exp || broken(rTab.right  - rTab.left == DEFAULT_MIN_TAB_WIDTH),
609
        "no icon, default width: Expected width [%d] got [%ld]\n", exp, rTab.right - rTab.left );
610

611 612 613
    for (i=0; i<8; i++)
    {
        INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
614

615 616
        SendMessageA(hwTab, TCM_SETIMAGELIST, 0, 0);
        SendMessageA(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i, i));
617

618 619
        TABCHECKSETSIZE(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
        TABCHECKSETSIZE(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
620

621
        SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
622 623
        nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;

624 625 626
        TABCHECKSETSIZE(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
        TABCHECKSETSIZE(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
        TABCHECKSETSIZE(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
627
    }
628
    DestroyWindow (hwTab);
629

630
    hwTab = create_tabcontrol(0, TCIF_IMAGE);
631
    SendMessageA(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
632 633

    trace ("  non fixed width, no text...\n");
634
    exp = (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth;
635
    SendMessageA( hwTab, TCM_GETITEMRECT, 0, (LPARAM)&rTab );
636
    ok( rTab.right  - rTab.left == exp || broken(rTab.right  - rTab.left == DEFAULT_MIN_TAB_WIDTH),
637
        "no icon, default width: Expected width [%d] got [%ld]\n", exp, rTab.right - rTab.left );
638

639 640 641 642
    for (i=0; i<8; i++)
    {
        INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;

643 644
        SendMessageA(hwTab, TCM_SETIMAGELIST, 0, 0);
        SendMessageA(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i, i));
645

646 647
        TABCHECKSETSIZE(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
        TABCHECKSETSIZE(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
648

649
        SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
650 651 652
        if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
            nTabWidth += EXTRA_ICON_PADDING *(i-1);

653 654 655
        TABCHECKSETSIZE(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
        TABCHECKSETSIZE(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
        TABCHECKSETSIZE(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
656 657 658
    }

    DestroyWindow (hwTab);
659

660
    pImageList_Destroy(himl);
661 662
}

663
static void test_width(void)
664
{
665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
    trace ("Testing with default MinWidth\n");
    test_tab(-1);
    trace ("Testing with MinWidth set to -3\n");
    test_tab(-3);
    trace ("Testing with MinWidth set to 24\n");
    test_tab(24);
    trace ("Testing with MinWidth set to 54\n");
    test_tab(54);
    trace ("Testing with MinWidth set to 94\n");
    test_tab(94);
}

static void test_curfocus(void)
{
    const INT nTabs = 5;
680
    INT ret;
681 682 683 684 685 686 687 688
    HWND hTab;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* Testing CurFocus with largest appropriate value */
689 690 691 692
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, nTabs - 1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == nTabs - 1, "Unexpected focus index %d.\n", ret);
693 694

    /* Testing CurFocus with negative value */
695 696 697 698
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, -10, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == -1, "Unexpected focus index %d.\n", ret);
699 700

    /* Testing CurFocus with value larger than number of tabs */
701 702 703 704 705 706 707
    ret = SendMessageA(hTab, TCM_SETCURSEL, 1, 0);
    ok(ret == -1, "Unexpected focus index %d.\n", ret);

    ret = SendMessageA(hTab, TCM_SETCURFOCUS, nTabs + 1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == 1, "Unexpected focus index %d.\n", ret);
708

709 710 711 712 713 714 715 716
    ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_focus_seq, "Set focused tab sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Set focused tab parent sequence", TRUE);

    DestroyWindow(hTab);

    /* TCS_BUTTONS */
    hTab = createFilledTabControl(parent_wnd, TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");
717

718 719 720 721 722 723 724 725 726 727 728 729
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* Testing CurFocus with largest appropriate value */
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, nTabs - 1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == nTabs - 1, "Unexpected focus index %d.\n", ret);

    /* Testing CurFocus with negative value */
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, -10, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
730
    todo_wine
731 732 733 734
    ok(ret == nTabs - 1, "Unexpected focus index %d.\n", ret);

    /* Testing CurFocus with value larger than number of tabs */
    ret = SendMessageA(hTab, TCM_SETCURSEL, 1, 0);
735
    todo_wine
736 737 738 739 740
    ok(ret == 0, "Unexpected focus index %d.\n", ret);

    ret = SendMessageA(hTab, TCM_SETCURFOCUS, nTabs + 1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
741
    todo_wine
742 743
    ok(ret == nTabs - 1, "Unexpected focus index %d.\n", ret);

744
    ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_focus_buttons_seq, "TCS_BUTTONS: set focused tab sequence", FALSE);
745
    ok_sequence(sequences, PARENT_SEQ_INDEX, setfocus_parent_seq, "TCS_BUTTONS: set focused tab parent sequence", TRUE);
746 747 748 749

    DestroyWindow(hTab);
}

750
static void test_cursel(void)
751
{
752
    const INT nTabs = 5;
753 754
    INT selectionIndex;
    INT focusIndex;
755
    TCITEMA tcItem;
756 757 758 759 760 761 762 763
    HWND hTab;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* Testing CurSel with largest appropriate value */
764
    selectionIndex = SendMessageA(hTab, TCM_SETCURSEL, nTabs - 1, 0);
765
    expect(0, selectionIndex);
766
    selectionIndex = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
767 768 769
    expect(nTabs-1, selectionIndex);

    /* Focus should switch with selection */
770
    focusIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
771 772 773
    expect(nTabs-1, focusIndex);

    /* Testing CurSel with negative value */
774 775
    SendMessageA(hTab, TCM_SETCURSEL, -10, 0);
    selectionIndex = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
776 777 778
    expect(-1, selectionIndex);

    /* Testing CurSel with value larger than number of tabs */
779
    selectionIndex = SendMessageA(hTab, TCM_SETCURSEL, 1, 0);
780 781
    expect(-1, selectionIndex);

782
    selectionIndex = SendMessageA(hTab, TCM_SETCURSEL, nTabs + 1, 0);
783
    expect(-1, selectionIndex);
784
    selectionIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
785 786 787 788 789 790 791
    expect(1, selectionIndex);

    ok_sequence(sequences, TAB_SEQ_INDEX, getset_cur_sel_seq, "Getset curSel test sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset curSel test parent sequence", FALSE);

    /* selected item should have TCIS_BUTTONPRESSED state
       It doesn't depend on button state */
792
    memset(&tcItem, 0, sizeof(TCITEMA));
793 794
    tcItem.mask = TCIF_STATE;
    tcItem.dwStateMask = TCIS_BUTTONPRESSED;
795 796
    selectionIndex = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
    SendMessageA(hTab, TCM_GETITEMA, selectionIndex, (LPARAM)&tcItem);
797 798 799
    ok (tcItem.dwState & TCIS_BUTTONPRESSED || broken(tcItem.dwState == 0), /* older comctl32 */
        "Selected item should have TCIS_BUTTONPRESSED\n");

800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
    /* now deselect all and check previously selected item state */
    focusIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(focusIndex == 1, "got %d\n", focusIndex);

    selectionIndex = SendMessageA(hTab, TCM_SETCURSEL, -1, 0);
    ok(selectionIndex == 1, "got %d\n", selectionIndex);

    memset(&tcItem, 0, sizeof(TCITEMA));

    /* focus is reset too */
    focusIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(focusIndex == -1, "got %d\n", focusIndex);

    tcItem.mask = TCIF_STATE;
    tcItem.dwStateMask = TCIS_BUTTONPRESSED;
    SendMessageA(hTab, TCM_GETITEMA, selectionIndex, (LPARAM)&tcItem);
    ok(tcItem.dwState == 0, "got state %d\n", tcItem.dwState);

818 819 820
    DestroyWindow(hTab);
}

821
static void test_extendedstyle(void)
822
{
823
    const INT nTabs = 5;
824 825 826 827 828 829 830 831 832 833
    DWORD prevExtendedStyle;
    DWORD extendedStyle;
    HWND hTab;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* Testing Flat Separators */
834 835
    extendedStyle = SendMessageA(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
    prevExtendedStyle = SendMessageA(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_FLATSEPARATORS);
836 837
    expect(extendedStyle, prevExtendedStyle);

838
    extendedStyle = SendMessageA(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
839 840 841
    expect(TCS_EX_FLATSEPARATORS, extendedStyle);

    /* Testing Register Drop */
842
    prevExtendedStyle = SendMessageA(hTab, TCM_SETEXTENDEDSTYLE, 0, TCS_EX_REGISTERDROP);
843 844
    expect(extendedStyle, prevExtendedStyle);

845
    extendedStyle = SendMessageA(hTab, TCM_GETEXTENDEDSTYLE, 0, 0);
846 847 848 849 850 851 852 853 854 855
    todo_wine{
        expect(TCS_EX_REGISTERDROP, extendedStyle);
    }

    ok_sequence(sequences, TAB_SEQ_INDEX, getset_extended_style_seq, "Getset extendedStyle test sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset extendedStyle test parent sequence", FALSE);

    DestroyWindow(hTab);
}

856
static void test_unicodeformat(void)
857
{
858
    const INT nTabs = 5;
859 860 861 862 863 864 865 866
    INT unicodeFormat;
    HWND hTab;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

867
    unicodeFormat = SendMessageA(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
868 869 870
    todo_wine{
        expect(0, unicodeFormat);
    }
871
    unicodeFormat = SendMessageA(hTab, TCM_GETUNICODEFORMAT, 0, 0);
872 873
    expect(1, unicodeFormat);

874
    unicodeFormat = SendMessageA(hTab, TCM_SETUNICODEFORMAT, FALSE, 0);
875
    expect(1, unicodeFormat);
876
    unicodeFormat = SendMessageA(hTab, TCM_GETUNICODEFORMAT, 0, 0);
877 878
    expect(0, unicodeFormat);

879
    unicodeFormat = SendMessageA(hTab, TCM_SETUNICODEFORMAT, TRUE, 0);
880 881 882 883 884 885 886 887
    expect(0, unicodeFormat);

    ok_sequence(sequences, TAB_SEQ_INDEX, getset_unicode_format_seq, "Getset unicodeFormat test sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset unicodeFormat test parent sequence", FALSE);

    DestroyWindow(hTab);
}

888
static void test_getset_item(void)
889
{
890
    char szText[32] = "New Label";
891
    const INT nTabs = 5;
892
    TCITEMA tcItem;
893
    LPARAM lparam;
894 895 896
    DWORD ret;
    HWND hTab;

897 898 899 900 901 902 903 904 905 906
    hTab = CreateWindowA(
	WC_TABCONTROLA,
	"TestTab",
	WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | TCS_FIXEDWIDTH | TCS_OWNERDRAWFIXED,
        10, 10, 300, 100,
        parent_wnd, NULL, NULL, 0);

    ok(GetParent(hTab) == NULL, "got %p, expected null parent\n", GetParent(hTab));

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, sizeof(LPARAM)-1, 0);
907
    ok(ret == TRUE, "got %ld\n", ret);
908 909 910 911 912 913

    /* set some item data */
    tcItem.lParam = ~0;
    tcItem.mask = TCIF_PARAM;

    ret = SendMessageA(hTab, TCM_INSERTITEMA, 0, (LPARAM)&tcItem);
914
    ok(ret == 0, "got %ld\n", ret);
915 916 917 918 919

    /* all sizeof(LPARAM) returned anyway when using sizeof(LPARAM)-1 size */
    memset(&lparam, 0xaa, sizeof(lparam));
    tcItem.lParam = lparam;
    tcItem.mask = TCIF_PARAM;
920
    ret = SendMessageA(hTab, TCM_GETITEMA, 0, (LPARAM)&tcItem);
921 922 923
    expect(TRUE, ret);
    /* everything higher specified size is preserved */
    memset(&lparam, 0xff, sizeof(lparam)-1);
924
    ok(tcItem.lParam == lparam, "Expected 0x%Ix, got 0x%Ix\n", lparam, tcItem.lParam);
925 926 927

    DestroyWindow(hTab);

928 929 930 931 932 933 934 935 936
    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    /* passing invalid index should result in initialization to zero
       for members mentioned in mask requested */

    /* valid range here is [0,4] */
    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_PARAM;
937
    ret = SendMessageA(hTab, TCM_GETITEMA, 5, (LPARAM)&tcItem);
938
    expect(FALSE, ret);
939
    ok(tcItem.lParam == 0, "Expected zero lParam, got %Iu\n", tcItem.lParam);
940 941 942

    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_IMAGE;
943
    ret = SendMessageA(hTab, TCM_GETITEMA, 5, (LPARAM)&tcItem);
944 945 946 947 948 949 950
    expect(FALSE, ret);
    expect(0, tcItem.iImage);

    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_TEXT;
    tcItem.pszText = szText;
    szText[0] = 'a';
951
    ret = SendMessageA(hTab, TCM_GETITEMA, 5, (LPARAM)&tcItem);
952 953 954 955 956 957 958
    expect(FALSE, ret);
    expect('a', szText[0]);

    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_STATE;
    tcItem.dwStateMask = 0;
    tcItem.dwState = TCIS_BUTTONPRESSED;
959
    ret = SendMessageA(hTab, TCM_GETITEMA, 5, (LPARAM)&tcItem);
960 961 962 963 964 965 966
    expect(FALSE, ret);
    ok(tcItem.dwState == 0, "Expected zero dwState, got %u\n", tcItem.dwState);

    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_STATE;
    tcItem.dwStateMask = TCIS_BUTTONPRESSED;
    tcItem.dwState = TCIS_BUTTONPRESSED;
967
    ret = SendMessageA(hTab, TCM_GETITEMA, 5, (LPARAM)&tcItem);
968 969 970 971 972 973
    expect(FALSE, ret);
    ok(tcItem.dwState == 0, "Expected zero dwState\n");

    /* check with negative index to be sure */
    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_PARAM;
974
    ret = SendMessageA(hTab, TCM_GETITEMA, -1, (LPARAM)&tcItem);
975
    expect(FALSE, ret);
976
    ok(tcItem.lParam == 0, "Expected zero lParam, got %Iu\n", tcItem.lParam);
977 978 979

    memset(&tcItem, 0xcc, sizeof(tcItem));
    tcItem.mask = TCIF_PARAM;
980
    ret = SendMessageA(hTab, TCM_GETITEMA, -2, (LPARAM)&tcItem);
981
    expect(FALSE, ret);
982
    ok(tcItem.lParam == 0, "Expected zero lParam, got %Iu\n", tcItem.lParam);
983 984 985 986 987 988 989 990

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    tcItem.mask = TCIF_TEXT;
    tcItem.pszText = &szText[0];
    tcItem.cchTextMax = sizeof(szText);

    strcpy(szText, "New Label");
991 992
    ok(SendMessageA(hTab, TCM_SETITEMA, 0, (LPARAM)&tcItem), "Setting new item failed.\n");
    ok(SendMessageA(hTab, TCM_GETITEMA, 0, (LPARAM)&tcItem), "Getting item failed.\n");
993 994
    expect_str("New Label", tcItem.pszText);

995
    ok(SendMessageA(hTab, TCM_GETITEMA, 1, (LPARAM)&tcItem), "Getting item failed.\n");
996 997 998 999 1000 1001 1002 1003 1004 1005
    expect_str("Tab 2", tcItem.pszText);

    ok_sequence(sequences, TAB_SEQ_INDEX, getset_item_seq, "Getset item test sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Getset item test parent sequence", FALSE);

    /* TCIS_BUTTONPRESSED doesn't depend on tab style */
    memset(&tcItem, 0, sizeof(tcItem));
    tcItem.mask = TCIF_STATE;
    tcItem.dwStateMask = TCIS_BUTTONPRESSED;
    tcItem.dwState = TCIS_BUTTONPRESSED;
1006
    ok(SendMessageA(hTab, TCM_SETITEMA, 0, (LPARAM)&tcItem), "Setting new item failed.\n");
1007
    tcItem.dwState = 0;
1008
    ok(SendMessageA(hTab, TCM_GETITEMA, 0, (LPARAM)&tcItem), "Getting item failed.\n");
1009 1010 1011 1012 1013 1014 1015
    if (tcItem.dwState)
    {
        ok (tcItem.dwState == TCIS_BUTTONPRESSED, "TCIS_BUTTONPRESSED should be set.\n");
        /* next highlight item, test that dwStateMask actually masks */
        tcItem.mask = TCIF_STATE;
        tcItem.dwStateMask = TCIS_HIGHLIGHTED;
        tcItem.dwState = TCIS_HIGHLIGHTED;
1016
        ok(SendMessageA(hTab, TCM_SETITEMA, 0, (LPARAM)&tcItem), "Setting new item failed.\n");
1017
        tcItem.dwState = 0;
1018
        ok(SendMessageA(hTab, TCM_GETITEMA, 0, (LPARAM)&tcItem), "Getting item failed.\n");
1019 1020 1021 1022
        ok (tcItem.dwState == TCIS_HIGHLIGHTED, "TCIS_HIGHLIGHTED should be set.\n");
        tcItem.mask = TCIF_STATE;
        tcItem.dwStateMask = TCIS_BUTTONPRESSED;
        tcItem.dwState = 0;
1023
        ok(SendMessageA(hTab, TCM_GETITEMA, 0, (LPARAM)&tcItem), "Getting item failed.\n");
1024 1025 1026 1027 1028 1029 1030
        ok (tcItem.dwState == TCIS_BUTTONPRESSED, "TCIS_BUTTONPRESSED should be set.\n");
    }
    else win_skip( "Item state mask not supported\n" );

    DestroyWindow(hTab);
}

1031
static void test_getset_tooltips(void)
1032 1033
{
    char toolTipText[32] = "ToolTip Text Test";
1034
    HWND hTab, toolTip, hwnd;
1035
    const INT nTabs = 5;
1036
    int ret;
1037 1038 1039 1040 1041 1042 1043

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    toolTip = create_tooltip(hTab, toolTipText);
1044 1045 1046 1047
    ret = SendMessageA(hTab, TCM_SETTOOLTIPS, (WPARAM)toolTip, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    hwnd = (HWND)SendMessageA(hTab, TCM_GETTOOLTIPS, 0, 0);
    ok(toolTip == hwnd, "Unexpected tooltip window.\n");
1048

1049 1050 1051 1052 1053
    ret = SendMessageA(hTab, TCM_SETTOOLTIPS, 0, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);
    hwnd = (HWND)SendMessageA(hTab, TCM_GETTOOLTIPS, 0, 0);
    ok(hwnd == NULL, "Unexpected tooltip window.\n");
    ok(IsWindow(toolTip), "Expected tooltip window to be alive.\n");
1054 1055 1056 1057 1058

    ok_sequence(sequences, TAB_SEQ_INDEX, getset_tooltip_seq, "Getset tooltip test sequence", TRUE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, getset_tooltip_parent_seq, "Getset tooltip test parent sequence", TRUE);

    DestroyWindow(hTab);
1059
    DestroyWindow(toolTip);
1060 1061
}

1062
static void test_adjustrect(void)
1063 1064 1065 1066 1067 1068 1069 1070 1071
{
    HWND hTab;
    INT r;

    ok(parent_wnd != NULL, "no parent window!\n");

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, 0, 0);
    ok(hTab != NULL, "Failed to create tab control\n");

1072
    r = SendMessageA(hTab, TCM_ADJUSTRECT, FALSE, 0);
1073 1074
    expect(-1, r);

1075
    r = SendMessageA(hTab, TCM_ADJUSTRECT, TRUE, 0);
1076 1077
    expect(-1, r);
}
1078

1079
static void test_insert_focus(void)
1080 1081 1082 1083
{
    HWND hTab;
    INT nTabsRetrieved;
    INT r;
1084
    TCITEMA tcNewTab;
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
    DWORD mask = TCIF_TEXT|TCIF_IMAGE;
    static char tabName[] = "TAB";
    tcNewTab.mask = mask;
    tcNewTab.pszText = tabName;

    ok(parent_wnd != NULL, "no parent window!\n");

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, mask, 0);
    ok(hTab != NULL, "Failed to create tab control\n");

1095
    r = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
1096 1097
    expect(-1, r);

1098 1099
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

1100
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1101 1102
    expect(0, nTabsRetrieved);

1103
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1104 1105 1106
    expect(-1, r);

    tcNewTab.iImage = 1;
1107
    r = SendMessageA(hTab, TCM_INSERTITEMA, 1, (LPARAM)&tcNewTab);
1108 1109
    expect(0, r);

1110
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1111 1112
    expect(1, nTabsRetrieved);

1113
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1114
    expect(0, r);
1115 1116

    tcNewTab.iImage = 2;
1117
    r = SendMessageA(hTab, TCM_INSERTITEMA, 2, (LPARAM)&tcNewTab);
1118 1119
    expect(1, r);

1120
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1121 1122
    expect(2, nTabsRetrieved);

1123
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1124
    expect(0, r);
1125

1126
    r = SendMessageA(hTab, TCM_SETCURFOCUS, -1, 0);
1127 1128
    expect(0, r);

1129
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1130 1131 1132
    expect(-1, r);

    tcNewTab.iImage = 3;
1133
    r = SendMessageA(hTab, TCM_INSERTITEMA, 3, (LPARAM)&tcNewTab);
1134 1135
    expect(2, r);

1136
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1137
    expect(2, r);
1138

1139
    ok_sequence(sequences, TAB_SEQ_INDEX, insert_focus_seq, "insert_focus test sequence", FALSE);
1140
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "insert_focus parent test sequence", TRUE);
1141 1142 1143 1144

    DestroyWindow(hTab);
}

1145
static void test_delete_focus(void)
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157
{
    HWND hTab;
    INT nTabsRetrieved;
    INT r;

    ok(parent_wnd != NULL, "no parent window!\n");

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, 2);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

1158
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1159 1160
    expect(2, nTabsRetrieved);

1161
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1162
    expect(0, r);
1163

1164
    r = SendMessageA(hTab, TCM_DELETEITEM, 1, 0);
1165 1166
    expect(1, r);

1167
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1168 1169
    expect(1, nTabsRetrieved);

1170
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1171
    expect(0, r);
1172

1173
    r = SendMessageA(hTab, TCM_SETCURFOCUS, -1, 0);
1174 1175
    expect(0, r);

1176
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1177 1178
    expect(-1, r);

1179
    r = SendMessageA(hTab, TCM_DELETEITEM, 0, 0);
1180 1181
    expect(1, r);

1182
    nTabsRetrieved = SendMessageA(hTab, TCM_GETITEMCOUNT, 0, 0);
1183 1184
    expect(0, nTabsRetrieved);

1185
    r = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1186 1187 1188
    expect(-1, r);

    ok_sequence(sequences, TAB_SEQ_INDEX, delete_focus_seq, "delete_focus test sequence", FALSE);
1189
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "delete_focus parent test sequence", TRUE);
1190 1191 1192 1193

    DestroyWindow(hTab);
}

1194
static void test_removeimage(void)
1195 1196 1197 1198
{
    static const BYTE bits[32];
    HWND hwTab;
    INT i;
1199
    TCITEMA item;
1200
    HICON hicon;
1201
    HIMAGELIST himl = pImageList_Create(16, 16, ILC_COLOR, 3, 4);
1202 1203

    hicon = CreateIcon(NULL, 16, 16, 1, 1, bits, bits);
1204 1205 1206
    pImageList_ReplaceIcon(himl, -1, hicon);
    pImageList_ReplaceIcon(himl, -1, hicon);
    pImageList_ReplaceIcon(himl, -1, hicon);
1207 1208

    hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
1209
    SendMessageA(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
1210

1211
    memset(&item, 0, sizeof(TCITEMA));
1212 1213 1214
    item.mask = TCIF_IMAGE;

    for(i = 0; i < 3; i++) {
1215
        SendMessageA(hwTab, TCM_GETITEMA, i, (LPARAM)&item);
1216 1217 1218 1219
        expect(i, item.iImage);
    }

    /* remove image middle image */
1220
    SendMessageA(hwTab, TCM_REMOVEIMAGE, 1, 0);
1221 1222
    i = pImageList_GetImageCount(himl);
    ok(i == 2, "Unexpected image count %d.\n", i);
1223
    item.iImage = -1;
1224
    SendMessageA(hwTab, TCM_GETITEMA, 0, (LPARAM)&item);
1225 1226
    expect(0, item.iImage);
    item.iImage = 0;
1227
    SendMessageA(hwTab, TCM_GETITEMA, 1, (LPARAM)&item);
1228 1229
    expect(-1, item.iImage);
    item.iImage = 0;
1230
    SendMessageA(hwTab, TCM_GETITEMA, 2, (LPARAM)&item);
1231 1232
    expect(1, item.iImage);
    /* remove first image */
1233
    SendMessageA(hwTab, TCM_REMOVEIMAGE, 0, 0);
1234 1235
    i = pImageList_GetImageCount(himl);
    ok(i == 1, "Unexpected image count %d.\n", i);
1236
    item.iImage = 0;
1237
    SendMessageA(hwTab, TCM_GETITEMA, 0, (LPARAM)&item);
1238 1239
    expect(-1, item.iImage);
    item.iImage = 0;
1240
    SendMessageA(hwTab, TCM_GETITEMA, 1, (LPARAM)&item);
1241 1242
    expect(-1, item.iImage);
    item.iImage = -1;
1243
    SendMessageA(hwTab, TCM_GETITEMA, 2, (LPARAM)&item);
1244 1245
    expect(0, item.iImage);
    /* remove the last one */
1246
    SendMessageA(hwTab, TCM_REMOVEIMAGE, 0, 0);
1247 1248
    i = pImageList_GetImageCount(himl);
    ok(i == 0, "Unexpected image count %d.\n", i);
1249 1250
    for(i = 0; i < 3; i++) {
        item.iImage = 0;
1251
        SendMessageA(hwTab, TCM_GETITEMA, i, (LPARAM)&item);
1252 1253 1254 1255
        expect(-1, item.iImage);
    }

    DestroyWindow(hwTab);
1256
    pImageList_Destroy(himl);
1257 1258 1259
    DestroyIcon(hicon);
}

1260
static void test_delete_selection(void)
1261 1262
{
    HWND hTab;
1263
    INT ret;
1264 1265 1266 1267

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, 4);
    ok(hTab != NULL, "Failed to create tab control\n");

1268
    ret = SendMessageA(hTab, TCM_SETCURSEL, 3, 0);
1269
    expect(0, ret);
1270
    ret = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
1271 1272
    expect(3, ret);
    /* delete selected item - selection goes to -1 */
1273
    ret = SendMessageA(hTab, TCM_DELETEITEM, 3, 0);
1274 1275
    expect(TRUE, ret);

1276
    ret = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
1277 1278 1279 1280 1281
    expect(-1, ret);

    DestroyWindow(hTab);
}

1282
static void test_TCM_SETITEMEXTRA(void)
1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
{
    HWND hTab;
    DWORD ret;

    hTab = CreateWindowA(
	WC_TABCONTROLA,
	"TestTab",
	WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | TCS_FIXEDWIDTH,
        10, 10, 300, 100,
        parent_wnd, NULL, NULL, 0);

    /* zero is valid size too */
    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, 0, 0);
    if (ret == FALSE)
    {
        win_skip("TCM_SETITEMEXTRA not supported\n");
        DestroyWindow(hTab);
        return;
    }

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, -1, 0);
1304
    ok(ret == FALSE, "got %ld\n", ret);
1305 1306

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, 2, 0);
1307
    ok(ret == TRUE, "got %ld\n", ret);
1308 1309 1310 1311 1312 1313 1314
    DestroyWindow(hTab);

    /* it's not possible to change extra data size for control with tabs */
    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, 4);
    ok(hTab != NULL, "Failed to create tab control\n");

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, 2, 0);
1315
    ok(ret == FALSE, "got %ld\n", ret);
1316 1317 1318
    DestroyWindow(hTab);
}

1319
static void test_TCS_OWNERDRAWFIXED(void)
1320
{
1321 1322
    LPARAM lparam;
    ULONG_PTR itemdata, itemdata2;
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344
    TCITEMA item;
    HWND hTab;
    BOOL ret;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH|TCS_OWNERDRAWFIXED, TCIF_TEXT|TCIF_IMAGE, 4);
    ok(hTab != NULL, "Failed to create tab control\n");

    ok(GetParent(hTab) == NULL, "got %p, expected null parent\n", GetParent(hTab));

    /* set some item data */
    memset(&lparam, 0xde, sizeof(LPARAM));

    item.mask = TCIF_PARAM;
    item.lParam = lparam;
    ret = SendMessageA(hTab, TCM_SETITEMA, 0, (LPARAM)&item);
    ok(ret == TRUE, "got %d\n", ret);

    memset(&g_drawitem, 0, sizeof(g_drawitem));

    ShowWindow(hTab, SW_SHOW);
    RedrawWindow(hTab, NULL, 0, RDW_UPDATENOW);

1345 1346
    itemdata = 0;
    memset(&itemdata, 0xde, 4);
1347
    ok(g_drawitem.itemData == itemdata, "got 0x%Ix, expected 0x%Ix\n", g_drawitem.itemData, itemdata);
1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376

    DestroyWindow(hTab);

    /* now with custom extra data length */
    hTab = CreateWindowA(
	WC_TABCONTROLA,
	"TestTab",
	WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | TCS_FIXEDWIDTH | TCS_OWNERDRAWFIXED,
        10, 10, 300, 100,
        parent_wnd, NULL, NULL, 0);

    ok(GetParent(hTab) == NULL, "got %p, expected null parent\n", GetParent(hTab));

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, sizeof(LPARAM)+1, 0);
    ok(ret == TRUE, "got %d\n", ret);

    /* set some item data */
    memset(&lparam, 0xde, sizeof(LPARAM));
    item.mask = TCIF_PARAM;
    item.lParam = lparam;

    ret = SendMessageA(hTab, TCM_INSERTITEMA, 0, (LPARAM)&item);
    ok(ret == 0, "got %d\n", ret);

    memset(&g_drawitem, 0, sizeof(g_drawitem));

    ShowWindow(hTab, SW_SHOW);
    RedrawWindow(hTab, NULL, 0, RDW_UPDATENOW);

1377
    memset(&itemdata, 0xde, sizeof(ULONG_PTR));
1378
    ok(*(ULONG_PTR*)g_drawitem.itemData == itemdata, "got 0x%Ix, expected 0x%Ix\n", g_drawitem.itemData, itemdata);
1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406

    DestroyWindow(hTab);

    /* same thing, but size smaller than default */
    hTab = CreateWindowA(
	WC_TABCONTROLA,
	"TestTab",
	WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | TCS_FIXEDWIDTH | TCS_OWNERDRAWFIXED,
        10, 10, 300, 100,
        parent_wnd, NULL, NULL, 0);

    ok(GetParent(hTab) == NULL, "got %p, expected null parent\n", GetParent(hTab));

    ret = SendMessageA(hTab, TCM_SETITEMEXTRA, sizeof(LPARAM)-1, 0);
    ok(ret == TRUE, "got %d\n", ret);

    memset(&lparam, 0xde, sizeof(lparam));
    item.mask = TCIF_PARAM;
    item.lParam = lparam;

    ret = SendMessageA(hTab, TCM_INSERTITEMA, 0, (LPARAM)&item);
    ok(ret == 0, "got %d\n", ret);

    memset(&g_drawitem, 0, sizeof(g_drawitem));

    ShowWindow(hTab, SW_SHOW);
    RedrawWindow(hTab, NULL, 0, RDW_UPDATENOW);

1407 1408 1409 1410
    itemdata = itemdata2 = 0;
    memset(&itemdata, 0xde, 4);
    memset(&itemdata2, 0xde, sizeof(LPARAM)-1);
    ok(g_drawitem.itemData == itemdata || broken(g_drawitem.itemData == itemdata2) /* win98 */,
1411
        "got 0x%Ix, expected 0x%Ix\n", g_drawitem.itemData, itemdata);
1412 1413 1414 1415

    DestroyWindow(hTab);
}

1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
static void test_WM_CONTEXTMENU(void)
{
    HWND hTab;

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, 4);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    SendMessageA(hTab, WM_RBUTTONUP, 0, 0);

    ok_sequence(sequences, TAB_SEQ_INDEX, rbuttonup_seq, "WM_RBUTTONUP response sequence", FALSE);

    DestroyWindow(hTab);
}

1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
struct tabcreate_style {
    DWORD style;
    DWORD act_style;
};

static const struct tabcreate_style create_styles[] =
{
    { WS_CHILD|TCS_BOTTOM|TCS_VERTICAL, WS_CHILD|WS_CLIPSIBLINGS|TCS_BOTTOM|TCS_VERTICAL|TCS_MULTILINE },
    { WS_CHILD|TCS_VERTICAL,            WS_CHILD|WS_CLIPSIBLINGS|TCS_VERTICAL|TCS_MULTILINE },
    { 0 }
};

static void test_create(void)
{
    const struct tabcreate_style *ptr = create_styles;
    DWORD style;
    HWND hTab;

    while (ptr->style)
    {
        hTab = CreateWindowA(WC_TABCONTROLA, "TestTab", ptr->style,
            10, 10, 300, 100, parent_wnd, NULL, NULL, 0);
        style = GetWindowLongA(hTab, GWL_STYLE);
1455
        ok(style == ptr->act_style, "expected style 0x%08lx, got style 0x%08lx\n", ptr->act_style, style);
1456 1457 1458 1459 1460 1461

        DestroyWindow(hTab);
        ptr++;
    }
}

1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473
static void init_functions(void)
{
    HMODULE hComCtl32 = LoadLibraryA("comctl32.dll");

#define X(f) p##f = (void*)GetProcAddress(hComCtl32, #f);
    X(ImageList_Create);
    X(ImageList_Destroy);
    X(ImageList_GetImageCount);
    X(ImageList_ReplaceIcon);
#undef X
}

1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
static void test_TCN_SELCHANGING(void)
{
    const INT nTabs = 5;
    HWND hTab;
    INT ret;

    hTab = createFilledTabControl(parent_wnd, WS_CHILD|TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    /* Initially first tab is focused. */
    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == 0, "Unexpected tab focus %d.\n", ret);

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    /* Setting focus to currently focused item should do nothing. */
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, 0, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);

    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Set focus to focused tab sequence", FALSE);

    /* Allow selection change. */
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    tcn_selchanging_result = 0;
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, nTabs - 1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);

    ok_sequence(sequences, PARENT_SEQ_INDEX, full_selchange_parent_seq, "Focus change allowed sequence", FALSE);

    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == nTabs - 1, "Unexpected focused tab %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
    ok(ret == nTabs - 1, "Unexpected selected tab %d.\n", ret);

    /* Forbid selection change. */
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    tcn_selchanging_result = 1;
    ret = SendMessageA(hTab, TCM_SETCURFOCUS, 0, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);

    ok_sequence(sequences, PARENT_SEQ_INDEX, selchanging_parent_seq, "Focus change disallowed sequence", FALSE);

    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
1519
    todo_wine
1520 1521
    ok(ret == nTabs - 1, "Unexpected focused tab %d.\n", ret);
    ret = SendMessageA(hTab, TCM_GETCURSEL, 0, 0);
1522
    todo_wine
1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540
    ok(ret == nTabs - 1, "Unexpected selected tab %d.\n", ret);

    /* Removing focus sends only TCN_SELCHANGE */
    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    ret = SendMessageA(hTab, TCM_SETCURFOCUS, -1, 0);
    ok(ret == 0, "Unexpected ret value %d.\n", ret);

    ok_sequence(sequences, PARENT_SEQ_INDEX, selchange_parent_seq, "Remove focus sequence", FALSE);

    ret = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
    ok(ret == -1, "Unexpected focused tab %d.\n", ret);

    tcn_selchanging_result = 0;

    DestroyWindow(hTab);
}

1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562
static void test_TCM_GETROWCOUNT(void)
{
    const INT nTabs = 5;
    HWND hTab;
    INT count;

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    hTab = createFilledTabControl(parent_wnd, TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE, nTabs);
    ok(hTab != NULL, "Failed to create tab control\n");

    flush_sequences(sequences, NUM_MSG_SEQUENCES);

    count = SendMessageA(hTab, TCM_GETROWCOUNT, 0, 0);
    ok(count == 1, "Unexpected row count %d.\n", count);

    ok_sequence(sequences, TAB_SEQ_INDEX, get_row_count_seq, "Get rowCount test sequence", FALSE);
    ok_sequence(sequences, PARENT_SEQ_INDEX, empty_sequence, "Get rowCount test parent sequence", FALSE);

    DestroyWindow(hTab);
}

1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573
START_TEST(tab)
{
    LOGFONTA logfont;

    lstrcpyA(logfont.lfFaceName, "Arial");
    memset(&logfont, 0, sizeof(logfont));
    logfont.lfHeight = -12;
    logfont.lfWeight = FW_NORMAL;
    logfont.lfCharSet = ANSI_CHARSET;
    hFont = CreateFontIndirectA(&logfont);

1574
    init_functions();
1575

1576 1577
    init_msg_sequences(sequences, NUM_MSG_SEQUENCES);

1578 1579
    init_winevent_hook();

1580 1581 1582
    parent_wnd = createParentWindow();
    ok(parent_wnd != NULL, "Failed to create parent window!\n");

1583
    test_width();
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593
    test_curfocus();
    test_cursel();
    test_extendedstyle();
    test_unicodeformat();
    test_getset_item();
    test_getset_tooltips();
    test_adjustrect();
    test_insert_focus();
    test_delete_focus();
    test_delete_selection();
1594
    test_removeimage();
1595 1596
    test_TCM_SETITEMEXTRA();
    test_TCS_OWNERDRAWFIXED();
1597
    test_WM_CONTEXTMENU();
1598
    test_create();
1599
    test_TCN_SELCHANGING();
1600
    test_TCM_GETROWCOUNT();
1601

1602 1603
    uninit_winevent_hook();

1604
    DestroyWindow(parent_wnd);
1605
}