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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 [%ld]\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 [%ld]\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 [%ld,%ld]\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)
61 handle = CreateWindow (
64 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style,
70 SetWindowLong(handle, GWL_STYLE, WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TCS_FOCUSNEVER | style);
71 SendMessage (handle, WM_SETFONT, 0, (LPARAM) hFont);
74 tcNewTab.pszText = "Tab 1";
76 SendMessage (handle, TCM_INSERTITEM, 0, (LPARAM) &tcNewTab);
77 tcNewTab.pszText = "Wide Tab 2";
79 SendMessage (handle, TCM_INSERTITEM, 1, (LPARAM) &tcNewTab);
80 tcNewTab.pszText = "T 3";
82 SendMessage (handle, TCM_INSERTITEM, 2, (LPARAM) &tcNewTab);
84 if (winetest_interactive)
86 ShowWindow (handle, SW_SHOW);
87 RedrawWindow (handle, NULL, 0, RDW_UPDATENOW);
94 static void test_tab(INT nMinTabWidth)
98 HIMAGELIST himl = ImageList_Create(21, 21, ILC_COLOR, 3, 4);
104 hwTab = create_tabcontrol(TCS_FIXEDWIDTH, TCIF_TEXT|TCIF_IMAGE);
105 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
108 hOldFont = SelectObject(hdc, (HFONT)SendMessage(hwTab, WM_GETFONT, 0, 0));
109 GetTextExtentPoint32A(hdc, "Tab 1", strlen("Tab 1"), &size);
110 trace("Tab1 text size: size.cx=%ld size.cy=%ld\n", size.cx, size.cy);
111 SelectObject(hdc, hOldFont);
112 ReleaseDC(hwTab, hdc);
114 trace (" TCS_FIXEDWIDTH tabs no icon...\n");
115 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
116 TabCheckSetSize(hwTab, 50, 20, 50, 20, "set size");
117 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
119 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
121 trace (" TCS_FIXEDWIDTH tabs with icon...\n");
122 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
123 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
124 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
126 DestroyWindow (hwTab);
128 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BUTTONS, TCIF_TEXT|TCIF_IMAGE);
129 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
131 trace (" TCS_FIXEDWIDTH buttons no icon...\n");
132 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "default width");
133 TabCheckSetSize(hwTab, 20, 20, 20, 20, "set size 1");
134 TabCheckSetSize(hwTab, 10, 50, 10, 50, "set size 2");
135 TabCheckSetSize(hwTab, 0, 1, 0, 1, "min size");
137 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
139 trace (" TCS_FIXEDWIDTH buttons with icon...\n");
140 TabCheckSetSize(hwTab, 50, 30, 50, 30, "set size > icon");
141 TabCheckSetSize(hwTab, 20, 20, 25, 20, "set size < icon");
142 TabCheckSetSize(hwTab, 0, 1, 25, 1, "min size");
143 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
144 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
146 DestroyWindow (hwTab);
148 hwTab = create_tabcontrol(TCS_FIXEDWIDTH | TCS_BOTTOM, TCIF_TEXT|TCIF_IMAGE);
149 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
151 trace (" TCS_FIXEDWIDTH | TCS_BOTTOM tabs...\n");
152 CheckSize(hwTab, TAB_DEFAULT_WIDTH, -1, "no icon, default width");
154 TabCheckSetSize(hwTab, 20, 20, 20, 20, "no icon, set size 1");
155 TabCheckSetSize(hwTab, 10, 50, 10, 50, "no icon, set size 2");
156 TabCheckSetSize(hwTab, 0, 1, 0, 1, "no icon, min size");
158 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
160 TabCheckSetSize(hwTab, 50, 30, 50, 30, "with icon, set size > icon");
161 TabCheckSetSize(hwTab, 20, 20, 25, 20, "with icon, set size < icon");
162 TabCheckSetSize(hwTab, 0, 1, 25, 1, "with icon, min size");
163 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(4,4));
164 TabCheckSetSize(hwTab, 0, 1, 25, 1, "set padding, min size");
166 DestroyWindow (hwTab);
168 hwTab = create_tabcontrol(0, TCIF_TEXT|TCIF_IMAGE);
169 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
171 trace (" non fixed width, with text...\n");
172 CheckSize(hwTab, max(size.cx +TAB_PADDING_X*2, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth), -1,
173 "no icon, default width");
176 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
178 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
179 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
181 TabCheckSetSize(hwTab, 50, 20, max(size.cx + i*2, nTabWidth), 20, "no icon, set size");
182 TabCheckSetSize(hwTab, 0, 1, max(size.cx + i*2, nTabWidth), 1, "no icon, min size");
184 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
185 nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 3) : nMinTabWidth;
187 TabCheckSetSize(hwTab, 50, 30, max(size.cx + 21 + i*3, nTabWidth), 30, "with icon, set size > icon");
188 TabCheckSetSize(hwTab, 20, 20, max(size.cx + 21 + i*3, nTabWidth), 20, "with icon, set size < icon");
189 TabCheckSetSize(hwTab, 0, 1, max(size.cx + 21 + i*3, nTabWidth), 1, "with icon, min size");
191 DestroyWindow (hwTab);
193 hwTab = create_tabcontrol(0, TCIF_IMAGE);
194 SendMessage(hwTab, TCM_SETMINTABWIDTH, 0, nMinTabWidth);
196 trace (" non fixed width, no text...\n");
197 CheckSize(hwTab, (nMinTabWidth < 0) ? DEFAULT_MIN_TAB_WIDTH : nMinTabWidth, -1, "no icon, default width");
200 INT nTabWidth = (nMinTabWidth < 0) ? TabWidthPadded(i, 2) : nMinTabWidth;
202 SendMessage(hwTab, TCM_SETIMAGELIST, 0, 0);
203 SendMessage(hwTab, TCM_SETPADDING, 0, MAKELPARAM(i,i));
205 TabCheckSetSize(hwTab, 50, 20, nTabWidth, 20, "no icon, set size");
206 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "no icon, min size");
208 SendMessage(hwTab, TCM_SETIMAGELIST, 0, (LPARAM)himl);
209 if (i > 1 && nMinTabWidth > 0 && nMinTabWidth < DEFAULT_MIN_TAB_WIDTH)
210 nTabWidth += EXTRA_ICON_PADDING *(i-1);
212 TabCheckSetSize(hwTab, 50, 30, nTabWidth, 30, "with icon, set size > icon");
213 TabCheckSetSize(hwTab, 20, 20, nTabWidth, 20, "with icon, set size < icon");
214 TabCheckSetSize(hwTab, 0, 1, nTabWidth, 1, "with icon, min size");
217 DestroyWindow (hwTab);
219 ImageList_Destroy(himl);
227 lstrcpyA(logfont.lfFaceName, "Arial");
228 memset(&logfont, 0, sizeof(logfont));
229 logfont.lfHeight = -12;
230 logfont.lfWeight = FW_NORMAL;
231 logfont.lfCharSet = ANSI_CHARSET;
232 hFont = CreateFontIndirectA(&logfont);
234 InitCommonControls();
236 trace ("Testing with default MinWidth\n");
238 trace ("Testing with MinWidth set to -3\n");
240 trace ("Testing with MinWidth set to 24\n");
242 trace ("Testing with MinWidth set to 54\n");
244 trace ("Testing with MinWidth set to 94\n");