1 /* Unit test suite for tab control.
3 * Copyright 2003 Vitaliy Margolen
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/test.h"
26 #define DEFAULT_MIN_TAB_WIDTH 54
27 #define TAB_DEFAULT_WIDTH 96
28 #define TAB_PADDING_X 6
29 #define EXTRA_ICON_PADDING 3
31 #define TabWidthPadded(padd_x, num) (DEFAULT_MIN_TAB_WIDTH - (TAB_PADDING_X - (padd_x)) * num)
33 #define TabCheckSetSize(hwnd, SetWidth, SetHeight, ExpWidth, ExpHeight, Msg)\
34 SendMessage (hwnd, TCM_SETITEMSIZE, 0,\
35 (LPARAM) MAKELPARAM((SetWidth >= 0) ? SetWidth:0, (SetHeight >= 0) ? SetHeight:0));\
36 if (winetest_interactive) RedrawWindow (hwnd, NULL, 0, RDW_UPDATENOW);\
37 CheckSize(hwnd, ExpWidth, ExpHeight, Msg);
39 #define CheckSize(hwnd,width,height,msg)\
40 SendMessage (hwnd, TCM_GETITEMRECT, 0, (LPARAM) &rTab);\
41 if ((width >= 0) && (height < 0))\
42 ok (width == rTab.right - rTab.left, "%s: Expected width [%d] got [%d]\n",\
43 msg, (int)width, rTab.right - rTab.left);\
44 else if ((height >= 0) && (width < 0))\
45 ok (height == rTab.bottom - rTab.top, "%s: Expected height [%d] got [%d]\n",\
46 msg, (int)height, rTab.bottom - rTab.top);\
48 ok ((width == rTab.right - rTab.left) &&\
49 (height == rTab.bottom - rTab.top ),\
50 "%s: Expected [%d,%d] got [%d,%d]\n", msg, (int)width, (int)height,\
51 rTab.right - rTab.left, rTab.bottom - rTab.top);
53 static HFONT hFont = 0;
56 create_tabcontrol (DWORD style, DWORD mask)
60 static char text1[] = "Tab 1",
61 text2[] = "Wide Tab 2",
64 handle = CreateWindow (
67 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
73 SetWindowLong(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
74 SendMessage (handle, WM_SETFONT, 0, (LPARAM) hFont);
77 tcNewTab.pszText = text1;
79 SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
80 tcNewTab.pszText = text2;
82 SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
83 tcNewTab.pszText = text3;
85 SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
87 if (winetest_interactive)
89 ShowWindow (handle, SW_SHOW);
90 RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
97 static void test_tab(INT nMinTabWidth)
101 HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
107 hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
108 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
111 hOldFont = SelectObject(hdc, (HFONT)SendMessage(hwTab, WM_GETFONT, 0, 0));
112 GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
113 trace("Tab1 text size: size.cx=%d size.cy=%d\n", size.cx, size.cy);
114 SelectObject(hdc, hOldFont);
115 ReleaseDC(hwTab, hdc);
117 trace (" TCS_FIXEDWIDTH tabs no icon...\n");
118 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
119 TabCheckSetSize(hwTab, 50, 20, 50, 20, "set size");
120 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
122 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
124 trace (" TCS_FIXEDWIDTH tabs with icon...\n");
125 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
126 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
127 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
129 DestroyWindow (hwTab);
131 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
132 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
134 trace (" TCS_FIXEDWIDTH buttons no icon...\n");
135 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
136 TabCheckSetSize(hwTab, 20, 20, 20, 20, "set size 1");
137 TabCheckSetSize(hwTab, 10, 50, 10, 50, "set size 2");
138 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
140 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
142 trace (" TCS_FIXEDWIDTH buttons with icon...\n");
143 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
144 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
145 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
146 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
147 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
149 DestroyWindow (hwTab);
151 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
152 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
154 trace (" TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
155 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "no icon, default width");
157 TabCheckSetSize(hwTab, 20, 20, 20, 20, "no icon, set size 1");
158 TabCheckSetSize(hwTab, 10, 50, 10, 50, "no icon, set size 2");
159 TabCheckSetSize(hwTab, 0, 1, 0, 1, "no icon, min size");
161 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
163 TabCheckSetSize(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
164 TabCheckSetSize(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
165 TabCheckSetSize(hwTab, 0, 1, 25, 1, "with icon, min size");
166 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
167 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
169 DestroyWindow (hwTab);
171 hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
172 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
174 trace (" non fixed width, with text...\n");
175 CheckSize(hwTab, max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth), -1,
176 "no icon, default width");
179 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
181 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
182 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
184 TabCheckSetSize(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
185 TabCheckSetSize(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
187 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
188 nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;
190 TabCheckSetSize(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
191 TabCheckSetSize(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
192 TabCheckSetSize(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
194 DestroyWindow (hwTab);
196 hwTab = create_tabcontrol(0, TCIF_IMAGE);
197 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
199 trace (" non fixed width, no text...\n");
200 CheckSize(hwTab, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth, -1, "no icon, default width");
203 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
205 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
206 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
208 TabCheckSetSize(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
209 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
211 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
212 if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
213 nTabWidth += EXTRA_ICON_PADDING *(i-1);
215 TabCheckSetSize(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
216 TabCheckSetSize(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
217 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
220 DestroyWindow (hwTab);
222 ImageList_Destroy(himl);
230 lstrcpyA(logfont.lfFaceName, "Arial");
231 memset(&logfont, 0, sizeof(logfont));
232 logfont.lfHeight = -12;
233 logfont.lfWeight = FW_NORMAL;
234 logfont.lfCharSet = ANSI_CHARSET;
235 hFont = CreateFontIndirectA(&logfont);
237 InitCommonControls();
239 trace ("Testing with default MinWidth\n");
241 trace ("Testing with MinWidth set to -3\n");
243 trace ("Testing with MinWidth set to 24\n");
245 trace ("Testing with MinWidth set to 54\n");
247 trace ("Testing with MinWidth set to 94\n");