1 /* Unit test suite for edit control.
3 * Copyright 2004 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"
27 #define ES_COMBO 0x200
31 HWND create_editcontrol (DWORD style, DWORD exstyle)
35 handle = CreateWindowEx(exstyle,
38 ES_AUTOHSCROLL | ES_AUTOVSCROLL | style,
40 NULL, NULL, NULL, NULL);
42 if (winetest_interactive)
43 ShowWindow (handle, SW_SHOW);
47 static LONG get_edit_style (HWND hwnd)
49 return GetWindowLongA( hwnd, GWL_STYLE ) & (
51 /* FIXME: not implemented
70 static void set_client_height(HWND Wnd, unsigned Height)
72 RECT ClientRect, WindowRect;
74 GetWindowRect(Wnd, &WindowRect);
75 GetClientRect(Wnd, &ClientRect);
76 SetWindowPos(Wnd, NULL, WindowRect.left, WindowRect.top,
77 WindowRect.right - WindowRect.left,
78 Height + (WindowRect.bottom - WindowRect.top) - (ClientRect.bottom - ClientRect.top),
79 SWP_NOMOVE | SWP_NOZORDER);
82 static void test_edit_control(void)
93 msMessage.message = WM_KEYDOWN;
95 trace("EDIT: Single line\n");
96 hwEdit = create_editcontrol(0, 0);
97 r = get_edit_style(hwEdit);
98 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%lx\n", r);
101 msMessage.wParam = i;
102 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
103 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
104 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
106 DestroyWindow (hwEdit);
108 trace("EDIT: Single line want returns\n");
109 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
110 r = get_edit_style(hwEdit);
111 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%lx\n", r);
112 for (i=0;i<65535;i++)
114 msMessage.wParam = i;
115 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
116 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
117 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
119 DestroyWindow (hwEdit);
121 trace("EDIT: Multiline line\n");
122 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL, 0);
123 r = get_edit_style(hwEdit);
124 ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%lx\n", r);
125 for (i=0;i<65535;i++)
127 msMessage.wParam = i;
128 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
129 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
130 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
132 DestroyWindow (hwEdit);
134 trace("EDIT: Multi line want returns\n");
135 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_WANTRETURN, 0);
136 r = get_edit_style(hwEdit);
137 ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%lx\n", r);
138 for (i=0;i<65535;i++)
140 msMessage.wParam = i;
141 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
142 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
143 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
145 DestroyWindow (hwEdit);
147 /* Get a stock font for which we can determine the metrics */
148 Font = GetStockObject(SYSTEM_FONT);
149 assert(NULL != Font);
152 OldFont = SelectObject(Dc, Font);
153 assert(NULL != OldFont);
154 if (! GetTextMetrics(Dc, &Metrics))
158 SelectObject(Dc, OldFont);
161 trace("EDIT: vertical text position\n");
162 hwEdit = create_editcontrol(WS_POPUP, 0);
163 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
164 set_client_height(hwEdit, Metrics.tmHeight - 1);
165 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
166 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
167 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
168 set_client_height(hwEdit, Metrics.tmHeight);
169 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
170 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
171 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
172 set_client_height(hwEdit, Metrics.tmHeight + 1);
173 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
174 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
175 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
176 set_client_height(hwEdit, Metrics.tmHeight + 2);
177 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
178 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
179 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
180 set_client_height(hwEdit, Metrics.tmHeight + 10);
181 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
182 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
183 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
184 DestroyWindow(hwEdit);
186 hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, 0);
187 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
188 set_client_height(hwEdit, Metrics.tmHeight - 1);
189 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
190 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
191 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
192 set_client_height(hwEdit, Metrics.tmHeight);
193 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
194 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
195 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
196 set_client_height(hwEdit, Metrics.tmHeight + 2);
197 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
198 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
199 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
200 set_client_height(hwEdit, Metrics.tmHeight + 3);
201 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
202 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
203 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
204 set_client_height(hwEdit, Metrics.tmHeight + 4);
205 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
206 ok(2 == FormatRect.top, "wrong vertical position expected 2 got %ld\n", FormatRect.top);
207 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
208 set_client_height(hwEdit, Metrics.tmHeight + 10);
209 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
210 ok(2 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
211 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
212 DestroyWindow(hwEdit);
214 hwEdit = create_editcontrol(WS_POPUP, WS_EX_CLIENTEDGE);
215 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
216 set_client_height(hwEdit, Metrics.tmHeight - 1);
217 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
218 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
219 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
220 set_client_height(hwEdit, Metrics.tmHeight);
221 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
222 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
223 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
224 set_client_height(hwEdit, Metrics.tmHeight + 1);
225 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
226 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
227 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
228 set_client_height(hwEdit, Metrics.tmHeight + 2);
229 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
230 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
231 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
232 set_client_height(hwEdit, Metrics.tmHeight + 4);
233 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
234 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
235 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
236 set_client_height(hwEdit, Metrics.tmHeight + 10);
237 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
238 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
239 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
240 DestroyWindow(hwEdit);
242 hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
243 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
244 set_client_height(hwEdit, Metrics.tmHeight - 1);
245 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
246 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
247 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
248 set_client_height(hwEdit, Metrics.tmHeight);
249 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
250 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
251 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
252 set_client_height(hwEdit, Metrics.tmHeight + 1);
253 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
254 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
255 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
256 set_client_height(hwEdit, Metrics.tmHeight + 2);
257 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
258 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
259 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
260 set_client_height(hwEdit, Metrics.tmHeight + 4);
261 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
262 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
263 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
264 set_client_height(hwEdit, Metrics.tmHeight + 10);
265 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
266 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
267 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
268 DestroyWindow(hwEdit);