1 /* Unit test suite for tab control.
3 * Copyright 2003 Vitaliy Margolen
4 * Copyright 2007 Hagop Hagopian
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.
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.
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
26 #include "wine/test.h"
29 #define DEFAULT_MIN_TAB_WIDTH 54
30 #define TAB_DEFAULT_WIDTH 96
31 #define TAB_PADDING_X 6
32 #define EXTRA_ICON_PADDING 3
35 #define NUM_MSG_SEQUENCES 2
36 #define PARENT_SEQ_INDEX 0
37 #define TAB_SEQ_INDEX 1
39 #define expect(expected, got) ok ( expected == got, "Expected %d, got %d\n", expected, got)
40 #define expect_str(expected, got)\
41 ok ( strcmp(expected, got) == 0, "Expected '%s', got '%s'\n", expected, got)
43 #define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)
45 #define TabCheckSetSize(hwnd, SetWidth, SetHeight, ExpWidth, ExpHeight, Msg)\
46 SendMessage (hwnd, TCM_SETITEMSIZE, 0,\
47 (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));\
48 if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);\
49 CheckSize(hwnd, ExpWidth, ExpHeight, Msg);
51 #define CheckSize(hwnd,width,height,msg)\
52 SendMessage (hwnd, TCM_GETITEMRECT, 0, (LPARAM) &rTab);\
53 if ((width >= 0) && (height < 0))\
54 ok (width == rTab.right - rTab.left, "%s: Expected width [%d] got [%d]\n",\
55 msg, (int)width, rTab.right - rTab.left);\
56 else if ((height >= 0) && (width < 0))\
57 ok (height == rTab.bottom - rTab.top, "%s: Expected height [%d] got [%d]\n",\
58 msg, (int)height, rTab.bottom - rTab.top);\
60 ok ((width == rTab.right - rTab.left) &&\
61 (height == rTab.bottom - rTab.top ),\
62 "%s: Expected [%d,%d] got [%d,%d]\n", msg, (int)width, (int)height,\
63 rTab.right - rTab.left, rTab.bottom - rTab.top);
65 static HFONT hFont
= 0;
67 static struct msg_sequence
*sequences
[NUM_MSG_SEQUENCES
];
69 static const struct message create_parent_wnd_seq
[] = {
70 { WM_GETMINMAXINFO
, sent
},
71 { WM_NCCREATE
, sent
},
72 { WM_NCCALCSIZE
, sent
|wparam
, 0 },
74 { WM_SHOWWINDOW
, sent
|wparam
, 1 },
75 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
76 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
77 { WM_ACTIVATEAPP
, sent
|wparam
, 1 },
78 { WM_NCACTIVATE
, sent
|wparam
, 1 },
79 { WM_ACTIVATE
, sent
|wparam
, 1 },
80 { WM_IME_SETCONTEXT
, sent
|wparam
|defwinproc
|optional
, 1 },
81 { WM_IME_NOTIFY
, sent
|defwinproc
|optional
},
82 { WM_SETFOCUS
, sent
|wparam
|defwinproc
, 0 },
83 /* Win9x adds SWP_NOZORDER below */
84 { WM_WINDOWPOSCHANGED
, sent
},
85 { WM_NCCALCSIZE
, sent
|wparam
|optional
, 1 },
91 static const struct message add_tab_to_parent
[] = {
92 { TCM_INSERTITEMA
, sent
},
93 { TCM_INSERTITEMA
, sent
},
94 { WM_NOTIFYFORMAT
, sent
|defwinproc
},
95 { WM_QUERYUISTATE
, sent
|wparam
|lparam
|defwinproc
|optional
, 0, 0 },
96 { WM_PARENTNOTIFY
, sent
|defwinproc
},
97 { TCM_INSERTITEMA
, sent
},
98 { TCM_INSERTITEMA
, sent
},
99 { TCM_INSERTITEMA
, sent
},
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
},
126 static const struct message add_tab_control_parent_seq
[] = {
127 { WM_NOTIFYFORMAT
, sent
},
128 { WM_QUERYUISTATE
, sent
|wparam
|lparam
|optional
, 0, 0 },
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
},
145 static const struct message empty_sequence
[] = {
149 static const struct message set_min_tab_width_seq
[] = {
150 { TCM_SETMINTABWIDTH
, sent
|wparam
, 0 },
151 { TCM_SETMINTABWIDTH
, sent
|wparam
, 0 },
155 static const struct message get_item_count_seq
[] = {
156 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
160 static const struct message get_row_count_seq
[] = {
161 { TCM_GETROWCOUNT
, sent
|wparam
|lparam
, 0, 0 },
165 static const struct message get_item_rect_seq
[] = {
166 { TCM_GETITEMRECT
, sent
},
167 { TCM_GETITEMRECT
, sent
},
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 },
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 },
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 },
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 },
212 static const struct message getset_item_seq
[] = {
213 { TCM_SETITEMA
, sent
},
214 { TCM_GETITEMA
, sent
},
215 { TCM_GETITEMA
, sent
},
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 },
231 static const struct message getset_tooltip_parent_seq
[] = {
232 { WM_WINDOWPOSCHANGING
, sent
|wparam
, 0 },
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 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
241 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
242 { TCM_INSERTITEM
, sent
|wparam
, 2 },
243 { WM_NOTIFYFORMAT
, sent
|defwinproc
, },
244 { WM_QUERYUISTATE
, sent
|defwinproc
|optional
, },
245 { WM_PARENTNOTIFY
, sent
|defwinproc
, },
246 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
247 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
248 { TCM_SETCURFOCUS
, sent
|wparam
|lparam
, -1, 0 },
249 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
250 { TCM_INSERTITEM
, sent
|wparam
, 3 },
251 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
255 static const struct message delete_focus_seq
[] = {
256 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
257 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
258 { TCM_DELETEITEM
, sent
|wparam
|lparam
, 1, 0 },
259 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
260 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
261 { TCM_SETCURFOCUS
, sent
|wparam
|lparam
, -1, 0 },
262 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
263 { TCM_DELETEITEM
, sent
|wparam
|lparam
, 0, 0 },
264 { TCM_GETITEMCOUNT
, sent
|wparam
|lparam
, 0, 0 },
265 { TCM_GETCURFOCUS
, sent
|wparam
|lparam
, 0, 0 },
271 create_tabcontrol (DWORD style
, DWORD mask
)
275 static char text1
[] = "Tab 1",
276 text2
[] = "Wide Tab 2",
279 handle
= CreateWindow (
282 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| TCS_FOCUSNEVER
| style
,
284 NULL
, NULL
, NULL
, 0);
288 SetWindowLong(handle
, GWL_STYLE
, WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| TCS_FOCUSNEVER
| style
);
289 SendMessage (handle
, WM_SETFONT
, 0, (LPARAM
) hFont
);
291 tcNewTab
.mask
= mask
;
292 tcNewTab
.pszText
= text1
;
294 SendMessage (handle
, TCM_INSERTITEM
, 0, (LPARAM
) &tcNewTab
);
295 tcNewTab
.pszText
= text2
;
297 SendMessage (handle
, TCM_INSERTITEM
, 1, (LPARAM
) &tcNewTab
);
298 tcNewTab
.pszText
= text3
;
300 SendMessage (handle
, TCM_INSERTITEM
, 2, (LPARAM
) &tcNewTab
);
302 if (winetest_interactive
)
304 ShowWindow (handle
, SW_SHOW
);
305 RedrawWindow (handle
, NULL
, 0, RDW_UPDATENOW
);
312 static LRESULT WINAPI
parentWindowProcess(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
314 static long defwndproc_counter
= 0;
318 /* do not log painting messages */
319 if (message
!= WM_PAINT
&&
320 message
!= WM_ERASEBKGND
&&
321 message
!= WM_NCPAINT
&&
322 message
!= WM_NCHITTEST
&&
323 message
!= WM_GETTEXT
&&
324 message
!= WM_GETICON
&&
325 message
!= WM_DEVICECHANGE
)
327 trace("parent: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
329 msg
.message
= message
;
330 msg
.flags
= sent
|wparam
|lparam
;
331 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
334 add_message(sequences
, PARENT_SEQ_INDEX
, &msg
);
337 defwndproc_counter
++;
338 ret
= DefWindowProcA(hwnd
, message
, wParam
, lParam
);
339 defwndproc_counter
--;
344 static BOOL
registerParentWindowClass(void)
349 cls
.lpfnWndProc
= parentWindowProcess
;
352 cls
.hInstance
= GetModuleHandleA(NULL
);
354 cls
.hCursor
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
355 cls
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
356 cls
.lpszMenuName
= NULL
;
357 cls
.lpszClassName
= "Tab test parent class";
358 return RegisterClassA(&cls
);
361 static HWND
createParentWindow(void)
363 if (!registerParentWindowClass())
366 return CreateWindowEx(0, "Tab test parent class",
367 "Tab test parent window",
368 WS_CAPTION
| WS_SYSMENU
| WS_MINIMIZEBOX
|
369 WS_MAXIMIZEBOX
| WS_VISIBLE
,
371 GetDesktopWindow(), NULL
, GetModuleHandleA(NULL
), NULL
);
379 static LRESULT WINAPI
tabSubclassProcess(HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
381 struct subclass_info
*info
= (struct subclass_info
*)GetWindowLongPtrA(hwnd
, GWLP_USERDATA
);
382 static long defwndproc_counter
= 0;
386 /* do not log painting messages */
387 if (message
!= WM_PAINT
&&
388 message
!= WM_ERASEBKGND
&&
389 message
!= WM_NCPAINT
&&
390 message
!= WM_NCHITTEST
&&
391 message
!= WM_GETTEXT
&&
392 message
!= WM_GETICON
&&
393 message
!= WM_DEVICECHANGE
)
395 trace("tab: %p, %04x, %08lx, %08lx\n", hwnd
, message
, wParam
, lParam
);
397 msg
.message
= message
;
398 msg
.flags
= sent
|wparam
|lparam
;
399 if (defwndproc_counter
) msg
.flags
|= defwinproc
;
402 add_message(sequences
, TAB_SEQ_INDEX
, &msg
);
405 defwndproc_counter
++;
406 ret
= CallWindowProcA(info
->oldproc
, hwnd
, message
, wParam
, lParam
);
407 defwndproc_counter
--;
412 static HWND
createFilledTabControl(HWND parent_wnd
, DWORD style
, DWORD mask
, INT nTabs
)
416 struct subclass_info
*info
;
420 info
= HeapAlloc(GetProcessHeap(), 0, sizeof(struct subclass_info
));
424 GetClientRect(parent_wnd
, &rect
);
426 tabHandle
= CreateWindow (
429 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
| TCS_FOCUSNEVER
| style
,
430 0, 0, rect
.right
, rect
.bottom
,
431 parent_wnd
, NULL
, NULL
, 0);
435 info
->oldproc
= (WNDPROC
)SetWindowLongPtrA(tabHandle
, GWLP_WNDPROC
, (LONG_PTR
)tabSubclassProcess
);
436 SetWindowLongPtrA(tabHandle
, GWLP_USERDATA
, (LONG_PTR
)info
);
438 tcNewTab
.mask
= mask
;
440 for (i
= 0; i
< nTabs
; i
++)
442 char tabName
[MAX_TABLEN
];
444 sprintf(tabName
, "Tab %d", i
+1);
445 tcNewTab
.pszText
= tabName
;
447 SendMessage (tabHandle
, TCM_INSERTITEM
, i
, (LPARAM
) &tcNewTab
);
450 if (winetest_interactive
)
452 ShowWindow (tabHandle
, SW_SHOW
);
453 RedrawWindow (tabHandle
, NULL
, 0, RDW_UPDATENOW
);
460 static HWND
create_tooltip (HWND hTab
, char toolTipText
[])
465 LPTSTR lptstr
= toolTipText
;
468 /* Creating a tooltip window*/
469 hwndTT
= CreateWindowEx(
473 WS_POPUP
| TTS_NOPREFIX
| TTS_ALWAYSTIP
,
474 CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
, CW_USEDEFAULT
,
475 hTab
, NULL
, 0, NULL
);
481 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
);
483 GetClientRect (hTab
, &rect
);
485 /* Initialize members of toolinfo*/
486 ti
.cbSize
= sizeof(TOOLINFO
);
487 ti
.uFlags
= TTF_SUBCLASS
;
491 ti
.lpszText
= lptstr
;
495 /* Add toolinfo structure to the tooltip control */
496 SendMessage(hwndTT
, TTM_ADDTOOL
, 0, (LPARAM
) (LPTOOLINFO
) &ti
);
501 static void test_tab(INT nMinTabWidth
)
505 HIMAGELIST himl
= ImageList_Create(21, 21, ILC_COLOR
, 3, 4);
511 hwTab
= create_tabcontrol(TCS_FIXEDWIDTH
, TCIF_TEXT
|TCIF_IMAGE
);
512 SendMessage(hwTab
, TCM_SETMINTABWIDTH
, 0, nMinTabWidth
);
515 hOldFont
= SelectObject(hdc
, (HFONT
)SendMessage(hwTab
, WM_GETFONT
, 0, 0));
516 GetTextExtentPoint32A(hdc
, "Tab 1", strlen("Tab 1"), &size
);
517 trace("Tab1 text size: size.cx=%d size.cy=%d\n", size
.cx
, size
.cy
);
518 SelectObject(hdc
, hOldFont
);
519 ReleaseDC(hwTab
, hdc
);
521 trace (" TCS_FIXEDWIDTH tabs no icon...\n");
522 CheckSize(hwTab
, TAB_DEFAULT_WIDTH
, -1, "default width");
523 TabCheckSetSize(hwTab
, 50, 20, 50, 20, "set size");
524 TabCheckSetSize(hwTab
, 0, 1, 0, 1, "min size");
526 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, (LPARAM
)himl
);
528 trace (" TCS_FIXEDWIDTH tabs with icon...\n");
529 TabCheckSetSize(hwTab
, 50, 30, 50, 30, "set size > icon");
530 TabCheckSetSize(hwTab
, 20, 20, 25, 20, "set size < icon");
531 TabCheckSetSize(hwTab
, 0, 1, 25, 1, "min size");
533 DestroyWindow (hwTab
);
535 hwTab
= create_tabcontrol(TCS_FIXEDWIDTH
| TCS_BUTTONS
, TCIF_TEXT
|TCIF_IMAGE
);
536 SendMessage(hwTab
, TCM_SETMINTABWIDTH
, 0, nMinTabWidth
);
538 trace (" TCS_FIXEDWIDTH buttons no icon...\n");
539 CheckSize(hwTab
, TAB_DEFAULT_WIDTH
, -1, "default width");
540 TabCheckSetSize(hwTab
, 20, 20, 20, 20, "set size 1");
541 TabCheckSetSize(hwTab
, 10, 50, 10, 50, "set size 2");
542 TabCheckSetSize(hwTab
, 0, 1, 0, 1, "min size");
544 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, (LPARAM
)himl
);
546 trace (" TCS_FIXEDWIDTH buttons with icon...\n");
547 TabCheckSetSize(hwTab
, 50, 30, 50, 30, "set size > icon");
548 TabCheckSetSize(hwTab
, 20, 20, 25, 20, "set size < icon");
549 TabCheckSetSize(hwTab
, 0, 1, 25, 1, "min size");
550 SendMessage(hwTab
, TCM_SETPADDING
, 0, MAKELPARAM(4,4));
551 TabCheckSetSize(hwTab
, 0, 1, 25, 1, "set padding, min size");
553 DestroyWindow (hwTab
);
555 hwTab
= create_tabcontrol(TCS_FIXEDWIDTH
| TCS_BOTTOM
, TCIF_TEXT
|TCIF_IMAGE
);
556 SendMessage(hwTab
, TCM_SETMINTABWIDTH
, 0, nMinTabWidth
);
558 trace (" TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
559 CheckSize(hwTab
, TAB_DEFAULT_WIDTH
, -1, "no icon, default width");
561 TabCheckSetSize(hwTab
, 20, 20, 20, 20, "no icon, set size 1");
562 TabCheckSetSize(hwTab
, 10, 50, 10, 50, "no icon, set size 2");
563 TabCheckSetSize(hwTab
, 0, 1, 0, 1, "no icon, min size");
565 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, (LPARAM
)himl
);
567 TabCheckSetSize(hwTab
, 50, 30, 50, 30, "with icon, set size > icon");
568 TabCheckSetSize(hwTab
, 20, 20, 25, 20, "with icon, set size < icon");
569 TabCheckSetSize(hwTab
, 0, 1, 25, 1, "with icon, min size");
570 SendMessage(hwTab
, TCM_SETPADDING
, 0, MAKELPARAM(4,4));
571 TabCheckSetSize(hwTab
, 0, 1, 25, 1, "set padding, min size");
573 DestroyWindow (hwTab
);
575 hwTab
= create_tabcontrol(0, TCIF_TEXT
|TCIF_IMAGE
);
576 SendMessage(hwTab
, TCM_SETMINTABWIDTH
, 0, nMinTabWidth
);
578 trace (" non fixed width, with text...\n");
579 CheckSize(hwTab
, max(size
.cx
+TAB_PADDING_X
*2, (nMinTabWidth
< 0) ? DEFAULT_MIN_TAB_WIDTH
: nMinTabWidth
), -1,
580 "no icon, default width");
583 INT nTabWidth
= (nMinTabWidth
< 0) ? TabWidthPadded(i
, 2) : nMinTabWidth
;
585 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, 0);
586 SendMessage(hwTab
, TCM_SETPADDING
, 0, MAKELPARAM(i
,i
));
588 TabCheckSetSize(hwTab
, 50, 20, max(size
.cx
+ i
*2, nTabWidth
), 20, "no icon, set size");
589 TabCheckSetSize(hwTab
, 0, 1, max(size
.cx
+ i
*2, nTabWidth
), 1, "no icon, min size");
591 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, (LPARAM
)himl
);
592 nTabWidth
= (nMinTabWidth
< 0) ? TabWidthPadded(i
, 3) : nMinTabWidth
;
594 TabCheckSetSize(hwTab
, 50, 30, max(size
.cx
+ 21 + i
*3, nTabWidth
), 30, "with icon, set size > icon");
595 TabCheckSetSize(hwTab
, 20, 20, max(size
.cx
+ 21 + i
*3, nTabWidth
), 20, "with icon, set size < icon");
596 TabCheckSetSize(hwTab
, 0, 1, max(size
.cx
+ 21 + i
*3, nTabWidth
), 1, "with icon, min size");
598 DestroyWindow (hwTab
);
600 hwTab
= create_tabcontrol(0, TCIF_IMAGE
);
601 SendMessage(hwTab
, TCM_SETMINTABWIDTH
, 0, nMinTabWidth
);
603 trace (" non fixed width, no text...\n");
604 CheckSize(hwTab
, (nMinTabWidth
< 0) ? DEFAULT_MIN_TAB_WIDTH
: nMinTabWidth
, -1, "no icon, default width");
607 INT nTabWidth
= (nMinTabWidth
< 0) ? TabWidthPadded(i
, 2) : nMinTabWidth
;
609 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, 0);
610 SendMessage(hwTab
, TCM_SETPADDING
, 0, MAKELPARAM(i
,i
));
612 TabCheckSetSize(hwTab
, 50, 20, nTabWidth
, 20, "no icon, set size");
613 TabCheckSetSize(hwTab
, 0, 1, nTabWidth
, 1, "no icon, min size");
615 SendMessage(hwTab
, TCM_SETIMAGELIST
, 0, (LPARAM
)himl
);
616 if (i
> 1 && nMinTabWidth
> 0 && nMinTabWidth
< DEFAULT_MIN_TAB_WIDTH
)
617 nTabWidth
+= EXTRA_ICON_PADDING
*(i
-1);
619 TabCheckSetSize(hwTab
, 50, 30, nTabWidth
, 30, "with icon, set size > icon");
620 TabCheckSetSize(hwTab
, 20, 20, nTabWidth
, 20, "with icon, set size < icon");
621 TabCheckSetSize(hwTab
, 0, 1, nTabWidth
, 1, "with icon, min size");
624 DestroyWindow (hwTab
);
626 ImageList_Destroy(himl
);
630 static void test_getters_setters(HWND parent_wnd
, INT nTabs
)
637 ok(parent_wnd
!= NULL
, "no parent window!\n");
638 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
640 hTab
= createFilledTabControl(parent_wnd
, TCS_FIXEDWIDTH
, TCIF_TEXT
|TCIF_IMAGE
, nTabs
);
641 ok(hTab
!= NULL
, "Failed to create tab control\n");
643 if(!winetest_interactive
)
644 ok_sequence(sequences
, TAB_SEQ_INDEX
, add_tab_to_parent
,
645 "Tab sequence, after adding tab control to parent", TRUE
);
647 ok_sequence(sequences
, TAB_SEQ_INDEX
, add_tab_to_parent_interactive
,
648 "Tab sequence, after adding tab control to parent", TRUE
);
650 if(!winetest_interactive
)
651 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_tab_control_parent_seq
,
652 "Parent after sequence, adding tab control to parent", TRUE
);
654 ok_sequence(sequences
, PARENT_SEQ_INDEX
, add_tab_control_parent_seq_interactive
,
655 "Parent after sequence, adding tab control to parent", TRUE
);
657 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
659 expect(DEFAULT_MIN_TAB_WIDTH
, (int)SendMessage(hTab
, TCM_SETMINTABWIDTH
, 0, -1));
661 ok_sequence(sequences
, TAB_SEQ_INDEX
, set_min_tab_width_seq
, "Set minTabWidth test sequence", FALSE
);
662 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Set minTabWidth test parent sequence", FALSE
);
664 /* Testing GetItemCount */
665 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
666 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
667 expect(nTabs
, nTabsRetrieved
);
668 ok_sequence(sequences
, TAB_SEQ_INDEX
, get_item_count_seq
, "Get itemCount test sequence", FALSE
);
669 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Getset itemCount test parent sequence", FALSE
);
671 /* Testing GetRowCount */
672 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
673 rowCount
= SendMessage(hTab
, TCM_GETROWCOUNT
, 0, 0);
675 ok_sequence(sequences
, TAB_SEQ_INDEX
, get_row_count_seq
, "Get rowCount test sequence", FALSE
);
676 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Get rowCount test parent sequence", FALSE
);
678 /* Testing GetItemRect */
679 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
680 ok(SendMessage(hTab
, TCM_GETITEMRECT
, 0, (LPARAM
) &rTab
), "GetItemRect failed.\n");
681 CheckSize(hTab
, TAB_DEFAULT_WIDTH
, -1 , "Default Width");
682 ok_sequence(sequences
, TAB_SEQ_INDEX
, get_item_rect_seq
, "Get itemRect test sequence", FALSE
);
683 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Get itemRect test parent sequence", FALSE
);
685 /* Testing CurFocus */
689 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
691 /* Testing CurFocus with largest appropriate value */
692 SendMessage(hTab
, TCM_SETCURFOCUS
, nTabs
-1, 0);
693 focusIndex
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
694 expect(nTabs
-1, focusIndex
);
696 /* Testing CurFocus with negative value */
697 SendMessage(hTab
, TCM_SETCURFOCUS
, -10, 0);
698 focusIndex
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
699 expect(-1, focusIndex
);
701 /* Testing CurFocus with value larger than number of tabs */
702 focusIndex
= SendMessage(hTab
, TCM_SETCURSEL
, 1, 0);
704 expect(-1, focusIndex
);
707 SendMessage(hTab
, TCM_SETCURFOCUS
, nTabs
+1, 0);
708 focusIndex
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
709 expect(1, focusIndex
);
711 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_cur_focus_seq
, "Getset curFoc test sequence", FALSE
);
719 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
721 /* Testing CurSel with largest appropriate value */
722 selectionIndex
= SendMessage(hTab
, TCM_SETCURSEL
, nTabs
-1, 0);
723 expect(1, selectionIndex
);
724 selectionIndex
= SendMessage(hTab
, TCM_GETCURSEL
, 0, 0);
725 expect(nTabs
-1, selectionIndex
);
727 /* Focus should switch with selection */
728 focusIndex
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
729 expect(nTabs
-1, focusIndex
);
731 /* Testing CurSel with negative value */
732 SendMessage(hTab
, TCM_SETCURSEL
, -10, 0);
733 selectionIndex
= SendMessage(hTab
, TCM_GETCURSEL
, 0, 0);
734 expect(-1, selectionIndex
);
736 /* Testing CurSel with value larger than number of tabs */
737 selectionIndex
= SendMessage(hTab
, TCM_SETCURSEL
, 1, 0);
738 expect(-1, selectionIndex
);
740 selectionIndex
= SendMessage(hTab
, TCM_SETCURSEL
, nTabs
+1, 0);
741 expect(-1, selectionIndex
);
742 selectionIndex
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
743 expect(1, selectionIndex
);
745 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_cur_sel_seq
, "Getset curSel test sequence", FALSE
);
746 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Getset curSel test parent sequence", FALSE
);
749 /* Testing ExtendedStyle */
751 DWORD prevExtendedStyle
;
754 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
756 /* Testing Flat Separators */
757 extendedStyle
= SendMessage(hTab
, TCM_GETEXTENDEDSTYLE
, 0, 0);
758 prevExtendedStyle
= SendMessage(hTab
, TCM_SETEXTENDEDSTYLE
, 0, TCS_EX_FLATSEPARATORS
);
759 expect(extendedStyle
, prevExtendedStyle
);
761 extendedStyle
= SendMessage(hTab
, TCM_GETEXTENDEDSTYLE
, 0, 0);
763 expect(TCS_EX_FLATSEPARATORS
, extendedStyle
);
766 /* Testing Register Drop */
767 prevExtendedStyle
= SendMessage(hTab
, TCM_SETEXTENDEDSTYLE
, 0, TCS_EX_REGISTERDROP
);
768 expect(extendedStyle
, prevExtendedStyle
);
770 extendedStyle
= SendMessage(hTab
, TCM_GETEXTENDEDSTYLE
, 0, 0);
772 expect(TCS_EX_REGISTERDROP
, extendedStyle
);
775 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_extended_style_seq
, "Getset extendedStyle test sequence", FALSE
);
776 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Getset extendedStyle test parent sequence", FALSE
);
779 /* Testing UnicodeFormat */
783 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
785 unicodeFormat
= SendMessage(hTab
, TCM_SETUNICODEFORMAT
, TRUE
, 0);
787 expect(0, unicodeFormat
);
789 unicodeFormat
= SendMessage(hTab
, TCM_GETUNICODEFORMAT
, 0, 0);
790 expect(1, unicodeFormat
);
792 unicodeFormat
= SendMessage(hTab
, TCM_SETUNICODEFORMAT
, FALSE
, 0);
793 expect(1, unicodeFormat
);
794 unicodeFormat
= SendMessage(hTab
, TCM_GETUNICODEFORMAT
, 0, 0);
795 expect(0, unicodeFormat
);
797 unicodeFormat
= SendMessage(hTab
, TCM_SETUNICODEFORMAT
, TRUE
, 0);
798 expect(0, unicodeFormat
);
800 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_unicode_format_seq
, "Getset unicodeFormat test sequence", FALSE
);
801 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Getset unicodeFormat test parent sequence", FALSE
);
804 /* Testing GetSet Item */
807 char szText
[32] = "New Label";
809 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
811 tcItem
.mask
= TCIF_TEXT
;
812 tcItem
.pszText
= &szText
[0];
813 tcItem
.cchTextMax
= sizeof(szText
);
815 ok ( SendMessage(hTab
, TCM_SETITEM
, 0, (LPARAM
) &tcItem
), "Setting new item failed.\n");
816 ok ( SendMessage(hTab
, TCM_GETITEM
, 0, (LPARAM
) &tcItem
), "Getting item failed.\n");
817 expect_str("New Label", tcItem
.pszText
);
819 ok ( SendMessage(hTab
, TCM_GETITEM
, 1, (LPARAM
) &tcItem
), "Getting item failed.\n");
820 expect_str("Tab 2", tcItem
.pszText
);
822 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_item_seq
, "Getset item test sequence", FALSE
);
823 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "Getset item test parent sequence", FALSE
);
826 /* Testing GetSet ToolTip */
829 char toolTipText
[32] = "ToolTip Text Test";
831 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
833 toolTip
= create_tooltip(hTab
, toolTipText
);
834 SendMessage(hTab
, TCM_SETTOOLTIPS
, (LPARAM
) toolTip
, 0);
835 ok (toolTip
== (HWND
) SendMessage(hTab
,TCM_GETTOOLTIPS
,0,0), "ToolTip was set incorrectly.\n");
837 SendMessage(hTab
, TCM_SETTOOLTIPS
, (LPARAM
) NULL
, 0);
838 ok (NULL
== (HWND
) SendMessage(hTab
,TCM_GETTOOLTIPS
,0,0), "ToolTip was set incorrectly.\n");
840 ok_sequence(sequences
, TAB_SEQ_INDEX
, getset_tooltip_seq
, "Getset tooltip test sequence", TRUE
);
841 ok_sequence(sequences
, PARENT_SEQ_INDEX
, getset_tooltip_parent_seq
, "Getset tooltip test parent sequence", TRUE
);
847 static void test_insert_focus(HWND parent_wnd
)
853 DWORD mask
= TCIF_TEXT
|TCIF_IMAGE
;
854 static char tabName
[] = "TAB";
855 tcNewTab
.mask
= mask
;
856 tcNewTab
.pszText
= tabName
;
858 ok(parent_wnd
!= NULL
, "no parent window!\n");
860 hTab
= createFilledTabControl(parent_wnd
, TCS_FIXEDWIDTH
, mask
, 0);
861 ok(hTab
!= NULL
, "Failed to create tab control\n");
863 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
865 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
866 expect(0, nTabsRetrieved
);
868 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
872 r
= SendMessage(hTab
, TCM_INSERTITEM
, 1, (LPARAM
) &tcNewTab
);
875 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
876 expect(1, nTabsRetrieved
);
878 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
882 r
= SendMessage(hTab
, TCM_INSERTITEM
, 2, (LPARAM
) &tcNewTab
);
885 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
886 expect(2, nTabsRetrieved
);
888 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
891 r
= SendMessage(hTab
, TCM_SETCURFOCUS
, -1, 0);
894 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
898 r
= SendMessage(hTab
, TCM_INSERTITEM
, 3, (LPARAM
) &tcNewTab
);
901 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
904 ok_sequence(sequences
, TAB_SEQ_INDEX
, insert_focus_seq
, "insert_focus test sequence", TRUE
);
905 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "insert_focus parent test sequence", FALSE
);
910 static void test_delete_focus(HWND parent_wnd
)
916 ok(parent_wnd
!= NULL
, "no parent window!\n");
918 hTab
= createFilledTabControl(parent_wnd
, TCS_FIXEDWIDTH
, TCIF_TEXT
|TCIF_IMAGE
, 2);
919 ok(hTab
!= NULL
, "Failed to create tab control\n");
921 flush_sequences(sequences
, NUM_MSG_SEQUENCES
);
923 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
924 expect(2, nTabsRetrieved
);
926 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
929 r
= SendMessage(hTab
, TCM_DELETEITEM
, 1, 0);
932 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
933 expect(1, nTabsRetrieved
);
935 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
938 r
= SendMessage(hTab
, TCM_SETCURFOCUS
, -1, 0);
941 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
944 r
= SendMessage(hTab
, TCM_DELETEITEM
, 0, 0);
947 nTabsRetrieved
= SendMessage(hTab
, TCM_GETITEMCOUNT
, 0, 0);
948 expect(0, nTabsRetrieved
);
950 r
= SendMessage(hTab
, TCM_GETCURFOCUS
, 0, 0);
953 ok_sequence(sequences
, TAB_SEQ_INDEX
, delete_focus_seq
, "delete_focus test sequence", FALSE
);
954 ok_sequence(sequences
, PARENT_SEQ_INDEX
, empty_sequence
, "delete_focus parent test sequence", FALSE
);
964 lstrcpyA(logfont
.lfFaceName
, "Arial");
965 memset(&logfont
, 0, sizeof(logfont
));
966 logfont
.lfHeight
= -12;
967 logfont
.lfWeight
= FW_NORMAL
;
968 logfont
.lfCharSet
= ANSI_CHARSET
;
969 hFont
= CreateFontIndirectA(&logfont
);
971 InitCommonControls();
973 trace ("Testing with default MinWidth\n");
975 trace ("Testing with MinWidth set to -3\n");
977 trace ("Testing with MinWidth set to 24\n");
979 trace ("Testing with MinWidth set to 54\n");
981 trace ("Testing with MinWidth set to 94\n");
984 init_msg_sequences(sequences
, NUM_MSG_SEQUENCES
);
986 parent_wnd
= createParentWindow();
987 ok(parent_wnd
!= NULL
, "Failed to create parent window!\n");
989 /* Testing getters and setters with 5 tabs */
990 test_getters_setters(parent_wnd
, 5);
992 test_insert_focus(parent_wnd
);
993 test_delete_focus(parent_wnd
);
995 DestroyWindow(parent_wnd
);