Mercurial > projects > dwt-win
comparison dwt/widgets/Text.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | a8fed3e56433 |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
34 import dwt.dwthelper.utils; | 34 import dwt.dwthelper.utils; |
35 | 35 |
36 /** | 36 /** |
37 * Instances of this class are selectable user interface | 37 * Instances of this class are selectable user interface |
38 * objects that allow the user to enter and modify text. | 38 * objects that allow the user to enter and modify text. |
39 * Text controls can be either single or multi-line. | |
40 * When a text control is created with a border, the | |
41 * operating system includes a platform specific inset | |
42 * around the contents of the control. When created | |
43 * without a border, an effort is made to remove the | |
44 * inset such that the preferred size of the control | |
45 * is the same size as the contents. | |
39 * <p> | 46 * <p> |
40 * <dl> | 47 * <dl> |
41 * <dt><b>Styles:</b></dt> | 48 * <dt><b>Styles:</b></dt> |
42 * <dd>CANCEL, CENTER, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd> | 49 * <dd>CANCEL, CENTER, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd> |
43 * <dt><b>Events:</b></dt> | 50 * <dt><b>Events:</b></dt> |
164 super (parent, checkStyle (style)); | 171 super (parent, checkStyle (style)); |
165 } | 172 } |
166 | 173 |
167 override int callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { | 174 override int callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { |
168 if (handle is null) return 0; | 175 if (handle is null) return 0; |
169 return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); | 176 bool redraw = false; |
177 switch (msg) { | |
178 case OS.WM_ERASEBKGND: { | |
179 if (findImageControl () !is null) return 0; | |
180 break; | |
181 } | |
182 case OS.WM_HSCROLL: | |
183 case OS.WM_VSCROLL: { | |
184 redraw = findImageControl () !is null && drawCount is 0 && OS.IsWindowVisible (handle); | |
185 if (redraw) OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); | |
186 break; | |
187 } | |
188 case OS.WM_PAINT: { | |
189 if (findImageControl () !is null) { | |
190 PAINTSTRUCT ps; | |
191 auto paintDC = OS.BeginPaint (handle, &ps); | |
192 int width = ps.rcPaint.right - ps.rcPaint.left; | |
193 int height = ps.rcPaint.bottom - ps.rcPaint.top; | |
194 if (width !is 0 && height !is 0) { | |
195 auto hDC = OS.CreateCompatibleDC (paintDC); | |
196 POINT lpPoint1, lpPoint2; | |
197 OS.SetWindowOrgEx (hDC, ps.rcPaint.left, ps.rcPaint.top, &lpPoint1); | |
198 OS.SetBrushOrgEx (hDC, ps.rcPaint.left, ps.rcPaint.top, &lpPoint2); | |
199 auto hBitmap = OS.CreateCompatibleBitmap (paintDC, width, height); | |
200 auto hOldBitmap = OS.SelectObject (hDC, hBitmap); | |
201 RECT rect; | |
202 OS.SetRect (&rect, ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right, ps.rcPaint.bottom); | |
203 drawBackground (hDC, &rect); | |
204 OS.CallWindowProc ( EditProc, hwnd, OS.WM_PAINT, cast(int)hDC, lParam); | |
205 OS.SetWindowOrgEx (hDC, lpPoint1.x, lpPoint1.y, null); | |
206 OS.SetBrushOrgEx (hDC, lpPoint2.x, lpPoint2.y, null); | |
207 OS.BitBlt (paintDC, ps.rcPaint.left, ps.rcPaint.top, width, height, hDC, 0, 0, OS.SRCCOPY); | |
208 OS.SelectObject (hDC, hOldBitmap); | |
209 OS.DeleteObject (hBitmap); | |
210 OS.DeleteObject (hDC); | |
211 } | |
212 OS.EndPaint (handle, &ps); | |
213 return 0; | |
214 } | |
215 break; | |
216 } | |
217 } | |
218 int /*long*/ code = OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); | |
219 switch (msg) { | |
220 case OS.WM_HSCROLL: | |
221 case OS.WM_VSCROLL: { | |
222 if (redraw) { | |
223 OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); | |
224 OS.InvalidateRect (handle, null, true); | |
225 } | |
226 break; | |
227 } | |
228 } | |
229 return code; | |
170 } | 230 } |
171 | 231 |
172 override void createHandle () { | 232 override void createHandle () { |
173 super.createHandle (); | 233 super.createHandle (); |
174 OS.SendMessage (handle, OS.EM_LIMITTEXT, 0, 0); | 234 OS.SendMessage (handle, OS.EM_LIMITTEXT, 0, 0); |
418 * The preferred height of a single-line text widget | 478 * The preferred height of a single-line text widget |
419 * has been hand-crafted to be the same height as | 479 * has been hand-crafted to be the same height as |
420 * the single-line text widget in an editable combo | 480 * the single-line text widget in an editable combo |
421 * box. | 481 * box. |
422 */ | 482 */ |
423 int margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0); | 483 int /*long*/ margins = OS.SendMessage(handle, OS.EM_GETMARGINS, 0, 0); |
424 rect.x -= margins & 0xFFFF; | 484 rect.x -= OS.LOWORD (margins); |
425 rect.width += (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); | 485 rect.width += OS.LOWORD (margins) + OS.HIWORD (margins); |
426 if ((style & DWT.H_SCROLL) !is 0) rect.width++; | 486 if ((style & DWT.H_SCROLL) !is 0) rect.width++; |
427 if ((style & DWT.BORDER) !is 0) { | 487 if ((style & DWT.BORDER) !is 0) { |
428 rect.x -= 1; | 488 rect.x -= 1; |
429 rect.y -= 1; | 489 rect.y -= 1; |
430 rect.width += 2; | 490 rect.width += 2; |
483 override bool dragDetect (HWND hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { | 543 override bool dragDetect (HWND hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { |
484 if (filter) { | 544 if (filter) { |
485 int start, end; | 545 int start, end; |
486 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); | 546 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); |
487 if (start !is end ) { | 547 if (start !is end ) { |
488 int lParam = (x & 0xFFFF) | ((y << 16) & 0xFFFF0000); | 548 int /*long*/ lParam = OS.MAKELPARAM (x, y); |
489 int position = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF; | 549 int position = OS.LOWORD (OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam)); |
490 if (start <= position && position < end) { | 550 if (start <= position && position < end) { |
491 if (super.dragDetect (hwnd, x, y, filter, detect, consume)) { | 551 if (super.dragDetect (hwnd, x, y, filter, detect, consume)) { |
492 if (consume !is null) consume [0] = true; | 552 if (consume !is null) consume [0] = true; |
493 return true; | 553 return true; |
494 } | 554 } |
610 * be equal to the last character position in the widget. | 670 * be equal to the last character position in the widget. |
611 * If EM_POSFROMCHAR fails for any other reason, return | 671 * If EM_POSFROMCHAR fails for any other reason, return |
612 * pixel coordinates (0,0). | 672 * pixel coordinates (0,0). |
613 */ | 673 */ |
614 int position = getCaretPosition (); | 674 int position = getCaretPosition (); |
615 int caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0); | 675 int /*long*/ caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0); |
616 if (caretPos is -1) { | 676 if (caretPos is -1) { |
617 caretPos = 0; | 677 caretPos = 0; |
618 if (position >= OS.GetWindowTextLength (handle)) { | 678 if (position >= OS.GetWindowTextLength (handle)) { |
619 int cp = getCodePage (); | 679 int cp = getCodePage (); |
620 int start, end; | 680 int start, end; |
639 ignoreCharacter = ignoreModify = false; | 699 ignoreCharacter = ignoreModify = false; |
640 OS.SendMessage (handle, OS.EM_SETSEL, start , start ); | 700 OS.SendMessage (handle, OS.EM_SETSEL, start , start ); |
641 OS.SendMessage (handle, OS.EM_SETSEL, start , end ); | 701 OS.SendMessage (handle, OS.EM_SETSEL, start , end ); |
642 } | 702 } |
643 } | 703 } |
644 return new Point (cast(short) (caretPos & 0xFFFF), cast(short) (caretPos >> 16)); | 704 return new Point (OS.GET_X_LPARAM (caretPos), OS.GET_Y_LPARAM (caretPos)); |
645 } | 705 } |
646 | 706 |
647 /** | 707 /** |
648 * Returns the character position of the caret. | 708 * Returns the character position of the caret. |
649 * <p> | 709 * <p> |
900 */ | 960 */ |
901 //TODO - Javadoc | 961 //TODO - Javadoc |
902 /*public*/ int getPosition (Point point) { | 962 /*public*/ int getPosition (Point point) { |
903 checkWidget(); | 963 checkWidget(); |
904 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); | 964 if (point is null) error (DWT.ERROR_NULL_ARGUMENT); |
905 int lParam = (point.x & 0xFFFF) | ((point.y << 16) & 0xFFFF0000); | 965 int /*long*/ lParam = OS.MAKELPARAM (point.x, point.y); |
906 int position = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF; | 966 int position = OS.LOWORD (OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam)); |
907 if (!OS.IsUnicode && OS.IsDBLocale) position = mbcsToWcsPos (position); | 967 if (!OS.IsUnicode && OS.IsDBLocale) position = mbcsToWcsPos (position); |
908 return position; | 968 return position; |
909 } | 969 } |
910 | 970 |
911 /** | 971 /** |
1463 * position. | 1523 * position. |
1464 */ | 1524 */ |
1465 if ((flags & OS.SWP_NOSIZE) is 0 && width !is 0) { | 1525 if ((flags & OS.SWP_NOSIZE) is 0 && width !is 0) { |
1466 RECT rect; | 1526 RECT rect; |
1467 OS.GetWindowRect (handle, &rect); | 1527 OS.GetWindowRect (handle, &rect); |
1468 int margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0); | 1528 int /*long*/ margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0); |
1469 int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); | 1529 int marginWidth = OS.LOWORD (margins) + OS.HIWORD (margins); |
1470 if (rect.right - rect.left <= marginWidth) { | 1530 if (rect.right - rect.left <= marginWidth) { |
1471 int start, end; | 1531 int start, end; |
1472 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); | 1532 OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); |
1473 if (start !is 0 || end !is 0) { | 1533 if (start !is 0 || end !is 0) { |
1474 SetWindowPos (handle, null, x, y, width, height, flags); | 1534 SetWindowPos (handle, null, x, y, width, height, flags); |
1802 * Feature in Windows. Windows expects the tab spacing in | 1862 * Feature in Windows. Windows expects the tab spacing in |
1803 * dialog units so we must convert from space widths. Due | 1863 * dialog units so we must convert from space widths. Due |
1804 * to round off error, the tab spacing may not be the exact | 1864 * to round off error, the tab spacing may not be the exact |
1805 * number of space widths, depending on the font. | 1865 * number of space widths, depending on the font. |
1806 */ | 1866 */ |
1807 int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF); | 1867 int width = (getTabWidth (tabs) * 4) / OS.LOWORD (OS.GetDialogBaseUnits ()); |
1808 OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, &width); | 1868 OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, &width); |
1809 } | 1869 } |
1810 | 1870 |
1811 /** | 1871 /** |
1812 * Sets the contents of the receiver to the given string. If the receiver has style | 1872 * Sets the contents of the receiver to the given string. If the receiver has style |
2149 * | 2209 * |
2150 * NOTE: A read only edit control processes arrow keys | 2210 * NOTE: A read only edit control processes arrow keys |
2151 * so DLGC_WANTARROWS should not be cleared. | 2211 * so DLGC_WANTARROWS should not be cleared. |
2152 */ | 2212 */ |
2153 if ((style & DWT.READ_ONLY) !is 0) { | 2213 if ((style & DWT.READ_ONLY) !is 0) { |
2154 int code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam); | 2214 int /*long*/ code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam); |
2155 code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB); | 2215 code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB); |
2156 return new LRESULT (code); | 2216 return new LRESULT (code); |
2157 } | 2217 } |
2158 return null; | 2218 return null; |
2159 } | 2219 } |
2175 * using WM_IME_CHAR. The fix is to allow the text | 2235 * using WM_IME_CHAR. The fix is to allow the text |
2176 * widget to get the WM_CHAR's but ignore sending | 2236 * widget to get the WM_CHAR's but ignore sending |
2177 * them to the application. | 2237 * them to the application. |
2178 */ | 2238 */ |
2179 ignoreCharacter = true; | 2239 ignoreCharacter = true; |
2180 int result = callWindowProc (handle, OS.WM_IME_CHAR, wParam, lParam); | 2240 int /*long*/ result = callWindowProc (handle, OS.WM_IME_CHAR, wParam, lParam); |
2181 MSG msg; | 2241 MSG msg; |
2182 int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; | 2242 int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; |
2183 while (OS.PeekMessage (&msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) { | 2243 while (OS.PeekMessage (&msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) { |
2184 OS.TranslateMessage (&msg); | 2244 OS.TranslateMessage (&msg); |
2185 OS.DispatchMessage (&msg); | 2245 OS.DispatchMessage (&msg); |
2246 * on the text widget must keep the current text selection. As a | 2306 * on the text widget must keep the current text selection. As a |
2247 * result, the window proc is only called if the menu is not shown. | 2307 * result, the window proc is only called if the menu is not shown. |
2248 */ | 2308 */ |
2249 bool hasMenu = menu !is null && !menu.isDisposed (); | 2309 bool hasMenu = menu !is null && !menu.isDisposed (); |
2250 if (hasMenu || hooks (DWT.MenuDetect)) { | 2310 if (hasMenu || hooks (DWT.MenuDetect)) { |
2251 int x = cast(short) (lParam & 0xFFFF); | 2311 int x = OS.GET_X_LPARAM (lParam); |
2252 int y = cast(short) (lParam >> 16); | 2312 int y = OS.GET_Y_LPARAM (lParam); |
2253 SHRGINFO shrg; | 2313 SHRGINFO shrg; |
2254 shrg.cbSize = SHRGINFO.sizeof; | 2314 shrg.cbSize = SHRGINFO.sizeof; |
2255 shrg.hwndClient = handle; | 2315 shrg.hwndClient = handle; |
2256 shrg.ptDown.x = x; | 2316 shrg.ptDown.x = x; |
2257 shrg.ptDown.y = y; | 2317 shrg.ptDown.y = y; |
2285 LRESULT result = super.WM_UNDO (wParam, lParam); | 2345 LRESULT result = super.WM_UNDO (wParam, lParam); |
2286 if (result !is null) return result; | 2346 if (result !is null) return result; |
2287 return wmClipboard (OS.WM_UNDO, wParam, lParam); | 2347 return wmClipboard (OS.WM_UNDO, wParam, lParam); |
2288 } | 2348 } |
2289 | 2349 |
2290 LRESULT wmClipboard (int msg, int wParam, int lParam) { | 2350 LRESULT wmClipboard (int msg, int /*long*/ wParam, int /*long*/ lParam) { |
2291 if ((style & DWT.READ_ONLY) !is 0) return null; | 2351 if ((style & DWT.READ_ONLY) !is 0) return null; |
2292 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; | 2352 if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; |
2293 bool call = false; | 2353 bool call = false; |
2294 int start, end; | 2354 int start, end; |
2295 String newText = null; | 2355 String newText = null; |
2388 } | 2448 } |
2389 return super.wmColorChild (wParam, lParam); | 2449 return super.wmColorChild (wParam, lParam); |
2390 } | 2450 } |
2391 | 2451 |
2392 override LRESULT wmCommandChild (int wParam, int lParam) { | 2452 override LRESULT wmCommandChild (int wParam, int lParam) { |
2393 int code = wParam >> 16; | 2453 int code = OS.HIWORD (wParam); |
2394 switch (code) { | 2454 switch (code) { |
2395 case OS.EN_CHANGE: | 2455 case OS.EN_CHANGE: |
2456 if (findImageControl () !is null) { | |
2457 OS.InvalidateRect (handle, null, true); | |
2458 } | |
2396 if (ignoreModify) break; | 2459 if (ignoreModify) break; |
2397 /* | 2460 /* |
2398 * It is possible (but unlikely), that application | 2461 * It is possible (but unlikely), that application |
2399 * code could have disposed the widget in the modify | 2462 * code could have disposed the widget in the modify |
2400 * event. If this happens, end the processing of the | 2463 * event. If this happens, end the processing of the |