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"
26 HWND create_editcontrol (DWORD style, DWORD exstyle)
30 handle = CreateWindowEx(exstyle,
33 ES_AUTOHSCROLL | ES_AUTOVSCROLL | style,
35 NULL, NULL, NULL, NULL);
37 if (winetest_interactive)
38 ShowWindow (handle, SW_SHOW);
42 static LONG get_edit_style (HWND hwnd)
44 return GetWindowLongA( hwnd, GWL_STYLE ) & (
46 /* FIXME: not implemented
65 static void set_client_height(HWND Wnd, unsigned Height)
67 RECT ClientRect, WindowRect;
69 GetWindowRect(Wnd, &WindowRect);
70 GetClientRect(Wnd, &ClientRect);
71 SetWindowPos(Wnd, NULL, WindowRect.left, WindowRect.top,
72 WindowRect.right - WindowRect.left,
73 Height + (WindowRect.bottom - WindowRect.top) - (ClientRect.bottom - ClientRect.top),
74 SWP_NOMOVE | SWP_NOZORDER);
77 static void test_edit_control(void)
88 msMessage.message = WM_KEYDOWN;
90 trace("EDIT: Single line\n");
91 hwEdit = create_editcontrol(0, 0);
92 r = get_edit_style(hwEdit);
93 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL), "Wrong style expected 0xc0 got: 0x%lx\n", r);
97 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
98 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
99 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
101 DestroyWindow (hwEdit);
103 trace("EDIT: Single line want returns\n");
104 hwEdit = create_editcontrol(ES_WANTRETURN, 0);
105 r = get_edit_style(hwEdit);
106 ok(r == (ES_AUTOVSCROLL | ES_AUTOHSCROLL | ES_WANTRETURN), "Wrong style expected 0x10c0 got: 0x%lx\n", r);
107 for (i=0;i<65535;i++)
109 msMessage.wParam = i;
110 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
111 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS),
112 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTARROWS got %lx\n", r);
114 DestroyWindow (hwEdit);
116 trace("EDIT: Multiline line\n");
117 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL, 0);
118 r = get_edit_style(hwEdit);
119 ok(r == (ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0xc4 got: 0x%lx\n", r);
120 for (i=0;i<65535;i++)
122 msMessage.wParam = i;
123 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
124 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
125 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
127 DestroyWindow (hwEdit);
129 trace("EDIT: Multi line want returns\n");
130 hwEdit = create_editcontrol(ES_MULTILINE | WS_VSCROLL | ES_AUTOVSCROLL | ES_WANTRETURN, 0);
131 r = get_edit_style(hwEdit);
132 ok(r == (ES_WANTRETURN | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE), "Wrong style expected 0x10c4 got: 0x%lx\n", r);
133 for (i=0;i<65535;i++)
135 msMessage.wParam = i;
136 r = SendMessage(hwEdit, WM_GETDLGCODE, 0, (LPARAM) &msMessage);
137 ok(r == (DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS),
138 "Expected DLGC_WANTCHARS | DLGC_HASSETSEL | DLGC_WANTALLKEYS | DLGC_WANTARROWS got %lx\n", r);
140 DestroyWindow (hwEdit);
142 /* Get a stock font for which we can determine the metrics */
143 Font = GetStockObject(SYSTEM_FONT);
144 assert(NULL != Font);
147 OldFont = SelectObject(Dc, Font);
148 assert(NULL != OldFont);
149 if (! GetTextMetrics(Dc, &Metrics))
153 SelectObject(Dc, OldFont);
156 trace("EDIT: vertical text position\n");
157 hwEdit = create_editcontrol(WS_POPUP, 0);
158 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
159 set_client_height(hwEdit, Metrics.tmHeight - 1);
160 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
161 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
162 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
163 set_client_height(hwEdit, Metrics.tmHeight);
164 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
165 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
166 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
167 set_client_height(hwEdit, Metrics.tmHeight + 1);
168 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
169 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
170 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
171 set_client_height(hwEdit, Metrics.tmHeight + 2);
172 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
173 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
174 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
175 set_client_height(hwEdit, Metrics.tmHeight + 10);
176 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
177 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
178 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
179 DestroyWindow(hwEdit);
181 hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, 0);
182 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
183 set_client_height(hwEdit, Metrics.tmHeight - 1);
184 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
185 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
186 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
187 set_client_height(hwEdit, Metrics.tmHeight);
188 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
189 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
190 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
191 set_client_height(hwEdit, Metrics.tmHeight + 2);
192 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
193 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
194 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
195 set_client_height(hwEdit, Metrics.tmHeight + 3);
196 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
197 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
198 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
199 set_client_height(hwEdit, Metrics.tmHeight + 4);
200 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
201 ok(2 == FormatRect.top, "wrong vertical position expected 2 got %ld\n", FormatRect.top);
202 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
203 set_client_height(hwEdit, Metrics.tmHeight + 10);
204 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
205 ok(2 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
206 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
207 DestroyWindow(hwEdit);
209 hwEdit = create_editcontrol(WS_POPUP, WS_EX_CLIENTEDGE);
210 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
211 set_client_height(hwEdit, Metrics.tmHeight - 1);
212 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
213 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
214 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
215 set_client_height(hwEdit, Metrics.tmHeight);
216 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
217 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
218 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
219 set_client_height(hwEdit, Metrics.tmHeight + 1);
220 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
221 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
222 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
223 set_client_height(hwEdit, Metrics.tmHeight + 2);
224 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
225 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
226 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
227 set_client_height(hwEdit, Metrics.tmHeight + 4);
228 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
229 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
230 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
231 set_client_height(hwEdit, Metrics.tmHeight + 10);
232 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
233 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
234 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
235 DestroyWindow(hwEdit);
237 hwEdit = create_editcontrol(WS_POPUP | WS_BORDER, WS_EX_CLIENTEDGE);
238 SendMessage(hwEdit, WM_SETFONT, (WPARAM) Font, (LPARAM) FALSE);
239 set_client_height(hwEdit, Metrics.tmHeight - 1);
240 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
241 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
242 ok(Metrics.tmHeight - 1 == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight - 1, FormatRect.bottom - FormatRect.top);
243 set_client_height(hwEdit, Metrics.tmHeight);
244 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
245 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
246 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
247 set_client_height(hwEdit, Metrics.tmHeight + 1);
248 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
249 ok(0 == FormatRect.top, "wrong vertical position expected 0 got %ld\n", FormatRect.top);
250 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
251 set_client_height(hwEdit, Metrics.tmHeight + 2);
252 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
253 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
254 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
255 set_client_height(hwEdit, Metrics.tmHeight + 4);
256 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
257 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
258 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
259 set_client_height(hwEdit, Metrics.tmHeight + 10);
260 SendMessage(hwEdit, EM_GETRECT, 0, (LPARAM) &FormatRect);
261 ok(1 == FormatRect.top, "wrong vertical position expected 1 got %ld\n", FormatRect.top);
262 ok(Metrics.tmHeight == FormatRect.bottom - FormatRect.top, "wrong height expected %ld got %ld\n", Metrics.tmHeight, FormatRect.bottom - FormatRect.top);
263 DestroyWindow(hwEdit);