# HG changeset patch # User Frank Benoit # Date 1202154784 -3600 # Node ID 5c549a70cf43f0f61df28973259caac0aac7678c # Parent 3f4e6a4ecc093b97505f50672c0e17915887045d Text diff -r 3f4e6a4ecc09 -r 5c549a70cf43 dwt/widgets/Text.d --- a/dwt/widgets/Text.d Mon Feb 04 20:01:30 2008 +0100 +++ b/dwt/widgets/Text.d Mon Feb 04 20:53:04 2008 +0100 @@ -10,10 +10,7 @@ *******************************************************************************/ module dwt.widgets.Text; -import dwt.widgets.Scrollable; -class Text : Scrollable { -} -/++ + import dwt.DWT; import dwt.DWTException; import dwt.events.ModifyListener; @@ -23,18 +20,16 @@ import dwt.graphics.Font; import dwt.graphics.Point; import dwt.graphics.Rectangle; -import dwt.internal.win32.GUITHREADINFO; -import dwt.internal.win32.LRESULT; -import dwt.internal.win32.MSG; import dwt.internal.win32.OS; -import dwt.internal.win32.POINT; -import dwt.internal.win32.RECT; -import dwt.internal.win32.SHRGINFO; -import dwt.internal.win32.TCHAR; -import dwt.internal.win32.TEXTMETRIC; -import dwt.internal.win32.TEXTMETRICA; -import dwt.internal.win32.TEXTMETRICW; -import dwt.internal.win32.WNDCLASS; + +import dwt.widgets.Scrollable; +import dwt.widgets.TypedListener; +import dwt.widgets.Event; +import dwt.widgets.Composite; +import dwt.widgets.Display; +import dwt.widgets.Control; + +import dwt.dwthelper.utils; /** * Instances of this class are selectable user interface @@ -53,7 +48,7 @@ * IMPORTANT: This class is not intended to be subclassed. *

*/ -public class Text extends Scrollable { +public class Text : Scrollable { alias Scrollable.computeSize computeSize; alias Scrollable.dragDetect dragDetect; @@ -62,7 +57,7 @@ int tabs, oldStart, oldEnd; bool doubleClick, ignoreModify, ignoreVerify, ignoreCharacter; - String message; + char[] message; /** * The maximum number of characters that can be entered @@ -72,14 +67,14 @@ * the native widget implementation. *

*/ - public static final int LIMIT; + public static const int LIMIT; /** * The delimiter used by multi-line text widgets. When text * is queried and from the widget, it will be delimited using * this delimiter. */ - public static final String DELIMITER; + public static const char[] DELIMITER; /* * This code is intentionally commented. @@ -91,16 +86,14 @@ * Therefore they are not initialized in the declaration * to stop the compiler from inlining. */ - static { + + static const WNDPROC EditProc; + static const TCHAR[] EditClass = "EDIT\0"; + static this() { LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF; DELIMITER = "\r\n"; - } - - static final int EditProc; - static final TCHAR EditClass = new TCHAR (0, "EDIT", true); - static { - WNDCLASS lpWndClass = new WNDCLASS (); - OS.GetClassInfo (0, EditClass, lpWndClass); + WNDCLASS lpWndClass; + OS.GetClassInfo (null, EditClass.ptr, &lpWndClass); EditProc = lpWndClass.lpfnWndProc; /* * This code is intentionally commented. @@ -150,13 +143,13 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public Text (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; - return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); +override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { + if (handle is null) return LRESULT.ZERO; + return cast(LRESULT) OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); } override void createHandle () { @@ -272,7 +265,7 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public void append (String string) { +public void append (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); string = Display.withCrLf (string); @@ -282,7 +275,7 @@ if (string is null) return; } OS.SendMessage (handle, OS.EM_SETSEL, length, length); - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz (getCodePage (), string); /* * Feature in Windows. When an edit control with ES_MULTILINE * style that does not have the WS_VSCROLL style is full (i.e. @@ -331,7 +324,7 @@ */ public void clearSelection () { checkWidget (); - if (OS.IsWinCE) { + static if (OS.IsWinCE) { /* * Bug in WinCE. Calling EM_SETSEL with -1 and 0 is equivalent * to calling EM_SETSEL with 0 and -1. It causes the entire @@ -339,9 +332,9 @@ * fix is to set the start of the selection to the end of the * current selection. */ - int [] end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, (int []) null, end); - OS.SendMessage (handle, OS.EM_SETSEL, end [0], end [0]); + int end; + OS.SendMessage (handle, OS.EM_GETSEL, null, &end); + OS.SendMessage (handle, OS.EM_SETSEL, end , end ); } else { OS.SendMessage (handle, OS.EM_SETSEL, -1, 0); } @@ -351,15 +344,15 @@ checkWidget (); int height = 0, width = 0; if (wHint is DWT.DEFAULT || hHint is DWT.DEFAULT) { - int newFont, oldFont = 0; - int hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); - OS.GetTextMetrics (hDC, tm); + HFONT newFont, oldFont; + auto hDC = OS.GetDC (handle); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + TEXTMETRIC tm; + OS.GetTextMetrics (hDC, &tm); int count = (style & DWT.SINGLE) !is 0 ? 1 : OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0); height = count * tm.tmHeight; - RECT rect = new RECT (); + RECT rect; int flags = OS.DT_CALCRECT | OS.DT_EDITCONTROL | OS.DT_NOPREFIX; bool wrap = (style & DWT.MULTI) !is 0 && (style & DWT.WRAP) !is 0; if (wrap && wHint !is DWT.DEFAULT) { @@ -368,9 +361,9 @@ } int length = OS.GetWindowTextLength (handle); if (length !is 0) { - TCHAR buffer = new TCHAR (getCodePage (), length + 1); - OS.GetWindowText (handle, buffer, length + 1); - OS.DrawText (hDC, buffer, length, rect, flags); + TCHAR[] buffer = NewTCHARs (getCodePage (), length + 1); + OS.GetWindowText (handle, buffer.ptr, length + 1); + OS.DrawText (hDC, buffer.ptr, length, &rect, flags); width = rect.right - rect.left; } //This code is intentionally commented @@ -390,7 +383,7 @@ int newHeight = rect.bottom - rect.top; if (newHeight !is 0) height = newHeight; } - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); } if (width is 0) width = DEFAULT_WIDTH; @@ -470,14 +463,14 @@ return OS.GetSysColor ((bits & OS.ES_READONLY) !is 0 ? OS.COLOR_3DFACE : OS.COLOR_WINDOW); } -override bool dragDetect (int hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { +override bool dragDetect (HWND hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { if (filter) { - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - if (start [0] !is end [0]) { + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + if (start !is end ) { int lParam = (x & 0xFFFF) | ((y << 16) & 0xFFFF0000); int position = OS.SendMessage (handle, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF; - if (start [0] <= position && position < end [0]) { + if (start <= position && position < end) { if (super.dragDetect (hwnd, x, y, filter, detect, consume)) { if (consume !is null) consume [0] = true; return true; @@ -607,8 +600,8 @@ caretPos = 0; if (position >= OS.GetWindowTextLength (handle)) { int cp = getCodePage (); - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); OS.SendMessage (handle, OS.EM_SETSEL, position, position); /* * Feature in Windows. When an edit control with ES_MULTILINE @@ -622,16 +615,16 @@ * handler from WM_CHAR. */ ignoreCharacter = ignoreModify = true; - OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true)); + OS.SendMessage (handle, OS.EM_REPLACESEL, 0, StrToTCHARz (cp, " ")); caretPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, position, 0); OS.SendMessage (handle, OS.EM_SETSEL, position, position + 1); - OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true)); + OS.SendMessage (handle, OS.EM_REPLACESEL, 0, StrToTCHARz (cp, "")); ignoreCharacter = ignoreModify = false; - OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0]); - OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); + OS.SendMessage (handle, OS.EM_SETSEL, start , start ); + OS.SendMessage (handle, OS.EM_SETSEL, start , end ); } } - return new Point ((short) (caretPos & 0xFFFF), (short) (caretPos >> 16)); + return new Point (cast(short) (caretPos & 0xFFFF), cast(short) (caretPos >> 16)); } /** @@ -649,8 +642,8 @@ */ public int getCaretPosition () { checkWidget (); - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); /* * In Windows, there is no API to get the position of the caret * when the selection is not an i-beam. The best that can be done @@ -661,27 +654,27 @@ * control. In this case, guess that the i-beam is at the start * of the selection. */ - int caret = start [0]; - if (start [0] !is end [0]) { - int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0); - int endLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0); + int caret = start ; + if (start !is end ) { + int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start, 0); + int endLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end, 0); if (startLine is endLine) { - if (!OS.IsWinCE) { + static if (!OS.IsWinCE) { int idThread = OS.GetWindowThreadProcessId (handle, null); - GUITHREADINFO lpgui = new GUITHREADINFO (); + GUITHREADINFO lpgui; lpgui.cbSize = GUITHREADINFO.sizeof; - if (OS.GetGUIThreadInfo (idThread, lpgui)) { - if (lpgui.hwndCaret is handle || lpgui.hwndCaret is 0) { - POINT ptCurrentPos = new POINT (); - if (OS.GetCaretPos (ptCurrentPos)) { - int endPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, end [0], 0); + if (OS.GetGUIThreadInfo (idThread, &lpgui)) { + if (lpgui.hwndCaret is handle || lpgui.hwndCaret is null) { + POINT ptCurrentPos; + if (OS.GetCaretPos (&ptCurrentPos)) { + int endPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, end, 0); if (endPos is -1) { - int startPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0); - int startX = (short) (startPos & 0xFFFF); - if (ptCurrentPos.x > startX) caret = end [0]; + int startPos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start, 0); + int startX = cast(short) (startPos & 0xFFFF); + if (ptCurrentPos.x > startX) caret = end; } else { - int endX = (short) (endPos & 0xFFFF); - if (ptCurrentPos.x >= endX) caret = end [0]; + int endX = cast(short) (endPos & 0xFFFF); + if (ptCurrentPos.x >= endX) caret = end; } } } @@ -690,7 +683,7 @@ } else { int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0); int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0); - if (caretLine is endLine) caret = end [0]; + if (caretLine is endLine) caret = end; } } if (!OS.IsUnicode && OS.IsDBLocale) caret = mbcsToWcsPos (caret); @@ -753,7 +746,7 @@ */ public char getEchoChar () { checkWidget (); - char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0); + wchar echo = cast(wchar) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0); if (echo !is 0 && (echo = Display.mbcsToWcs (echo, getCodePage ())) is 0) echo = '*'; return echo; } @@ -801,7 +794,7 @@ * * @see #DELIMITER */ -public String getLineDelimiter () { +public char[] getLineDelimiter () { checkWidget (); return DELIMITER; } @@ -818,13 +811,13 @@ */ public int getLineHeight () { checkWidget (); - int newFont, oldFont = 0; - int hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); - TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA (); - OS.GetTextMetrics (hDC, tm); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + HFONT newFont, oldFont; + auto hDC = OS.GetDC (handle); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); + TEXTMETRIC tm; + OS.GetTextMetrics (hDC, &tm); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); return tm.tmHeight; } @@ -866,7 +859,7 @@ * * @since 3.3 */ -public String getMessage () { +public char[] getMessage () { checkWidget (); return message; } @@ -918,13 +911,13 @@ */ public Point getSelection () { checkWidget (); - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); if (!OS.IsUnicode && OS.IsDBLocale) { - start [0] = mbcsToWcsPos (start [0]); - end [0] = mbcsToWcsPos (end [0]); + start = mbcsToWcsPos (start); + end = mbcsToWcsPos (end); } - return new Point (start [0], end [0]); + return new Point (start, end); } /** @@ -953,16 +946,16 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public String getSelectionText () { +public char[] getSelectionText () { checkWidget (); int length = OS.GetWindowTextLength (handle); if (length is 0) return ""; - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - if (start [0] is end [0]) return ""; - TCHAR buffer = new TCHAR (getCodePage (), length + 1); - OS.GetWindowText (handle, buffer, length + 1); - return buffer.toString (start [0], end [0] - start [0]); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + if (start is end ) return ""; + TCHAR[] buffer = NewTCHARs (getCodePage (), length + 1); + OS.GetWindowText (handle, buffer.ptr, length + 1); + return TCHARsToStr( buffer[ start .. end - start ] ); } /** @@ -986,15 +979,15 @@ } int getTabWidth (int tabs) { - int oldFont = 0; - RECT rect = new RECT (); - int hDC = OS.GetDC (handle); - int newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); + HFONT oldFont; + RECT rect; + auto hDC = OS.GetDC (handle); + HFONT newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; - TCHAR SPACE = new TCHAR (getCodePage (), " ", false); - OS.DrawText (hDC, SPACE, SPACE.length (), rect, flags); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + TCHAR[] SPACE = StrToTCHARs (getCodePage (), " ", false); + OS.DrawText (hDC, SPACE.ptr, SPACE.length, &rect, flags); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); return (rect.right - rect.left) * tabs; } @@ -1013,13 +1006,13 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public String getText () { +public char[] getText () { checkWidget (); - int length = OS.GetWindowTextLength (handle); - if (length is 0) return ""; - TCHAR buffer = new TCHAR (getCodePage (), length + 1); - OS.GetWindowText (handle, buffer, length + 1); - return buffer.toString (0, length); + int length_ = OS.GetWindowTextLength (handle); + if (length_ is 0) return ""; + TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); + OS.GetWindowText (handle, buffer.ptr, length_ + 1); + return TCHARsToStr( buffer[0 .. length_] ); } /** @@ -1040,7 +1033,7 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public String getText (int start, int end) { +public char[] getText (int start, int end) { checkWidget (); if (!(start <= end && 0 <= end)) return ""; int length = OS.GetWindowTextLength (handle); @@ -1123,8 +1116,8 @@ * and greater. The plain text widget and previous versions * of Rich Edit return zero. */ - int [] buffer = new int [2]; - int code = OS.SendMessage (handle, OS.EM_GETSCROLLPOS, 0, buffer); + int [2] buffer; + int code = OS.SendMessage (handle, OS.EM_GETSCROLLPOS, 0, buffer.ptr); if (code is 1) return buffer [1]; return getTopIndex () * getLineHeight (); } @@ -1145,17 +1138,17 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public void insert (String string) { +public void insert (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); string = Display.withCrLf (string); if (hooks (DWT.Verify) || filters (DWT.Verify)) { - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - string = verifyText (string, start [0], end [0], null); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + string = verifyText (string, start, end, null); if (string is null) return; } - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz (getCodePage (), string ); /* * Feature in Windows. When an edit control with ES_MULTILINE * style that does not have the WS_VSCROLL style is full (i.e. @@ -1177,9 +1170,9 @@ if (OS.IsUnicode) return mbcsPos; int cp = getCodePage (); int wcsTotal = 0, mbcsTotal = 0; - byte [] buffer = new byte [128]; - String delimiter = getLineDelimiter(); - int delimiterSize = delimiter.length (); + char [] buffer = new char [128]; + char[] delimiter = getLineDelimiter(); + int delimiterSize = delimiter.length; int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); for (int line=0; line buffer.length) { - buffer = new byte [mbcsSize + delimiterSize]; + buffer = new char [mbcsSize + delimiterSize]; } //ENDIAN - buffer [0] = (byte) (mbcsSize & 0xFF); - buffer [1] = (byte) (mbcsSize >> 8); - mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer); - wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0); + buffer [0] = cast(char) (mbcsSize & 0xFF); + buffer [1] = cast(char) (mbcsSize >> 8); + mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer.ptr); + wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer.ptr, mbcsSize, null, 0); } if (line - 1 !is count) { for (int i=0; i= mbcsPos) { int bufferSize = mbcsPos - mbcsTotal; - wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, bufferSize, null, 0); + wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer.ptr, bufferSize, null, 0); return wcsTotal + wcsSize; } wcsTotal += wcsSize; @@ -1361,46 +1354,46 @@ } /* Verify the character */ - String oldText = ""; - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + char[] oldText = ""; + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); switch (key) { case 0x08: /* Bs */ - if (start [0] is end [0]) { - if (start [0] is 0) return true; + if (start is end ) { + if (start is 0) return true; int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0); - if (start [0] is lineStart) { - start [0] = start [0] - DELIMITER.length (); + if (start is lineStart) { + start = start - DELIMITER.length; } else { - start [0] = start [0] - 1; + start = start - 1; if (!OS.IsUnicode && OS.IsDBLocale) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); - OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd); - if (start [0] !is newStart [0]) start [0] = start [0] - 1; + int newStart, newEnd; + OS.SendMessage (handle, OS.EM_SETSEL, start, end); + OS.SendMessage (handle, OS.EM_GETSEL, &newStart, &newEnd); + if (start !is newStart) start = start - 1; } } - start [0] = Math.max (start [0], 0); + start = Math.max (start, 0); } break; case 0x7F: /* Del */ - if (start [0] is end [0]) { + if (start is end) { int length = OS.GetWindowTextLength (handle); - if (start [0] is length) return true; - int line = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end [0], 0); + if (start is length) return true; + int line = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, end, 0); int lineStart = OS.SendMessage (handle, OS.EM_LINEINDEX, line + 1, 0); - if (end [0] is lineStart - DELIMITER.length ()) { - end [0] = end [0] + DELIMITER.length (); + if (end is lineStart - DELIMITER.length) { + end = end + DELIMITER.length; } else { - end [0] = end [0] + 1; + end = end + 1; if (!OS.IsUnicode && OS.IsDBLocale) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); - OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd); - if (end [0] !is newEnd [0]) end [0] = end [0] + 1; + int newStart, newEnd; + OS.SendMessage (handle, OS.EM_SETSEL, start, end); + OS.SendMessage (handle, OS.EM_GETSEL, &newStart, &newEnd); + if (end !is newEnd) end = end + 1; } } - end [0] = Math.min (end [0], length); + end = Math.min (end, length); } break; case '\r': /* Return */ @@ -1409,15 +1402,15 @@ break; default: /* Tab and other characters */ if (key !is '\t' && key < 0x20) return true; - oldText = new String (new char [] {key}); + oldText = [key]; break; } - String newText = verifyText (oldText, start [0], end [0], event); + char[] newText = verifyText (oldText, start, end, event); if (newText is null) return false; if (newText is oldText) return true; newText = Display.withCrLf (newText); - TCHAR buffer = new TCHAR (getCodePage (), newText, true); - OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); + TCHAR* buffer = StrToTCHARz (getCodePage (), newText); + OS.SendMessage (handle, OS.EM_SETSEL, start, end); /* * Feature in Windows. When an edit control with ES_MULTILINE * style that does not have the WS_VSCROLL style is full (i.e. @@ -1452,17 +1445,17 @@ * position. */ if ((flags & OS.SWP_NOSIZE) is 0 && width !is 0) { - RECT rect = new RECT (); - OS.GetWindowRect (handle, rect); + RECT rect; + OS.GetWindowRect (handle, &rect); int margins = OS.SendMessage (handle, OS.EM_GETMARGINS, 0, 0); int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); if (rect.right - rect.left <= marginWidth) { - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - if (start [0] !is 0 || end [0] !is 0) { - SetWindowPos (handle, 0, x, y, width, height, flags); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + if (start !is 0 || end !is 0) { + SetWindowPos (handle, null, x, y, width, height, flags); OS.SendMessage (handle, OS.EM_SETSEL, 0, 0); - OS.SendMessage (handle, OS.EM_SETSEL, start [0], end [0]); + OS.SendMessage (handle, OS.EM_SETSEL, start, end); return; } } @@ -1523,7 +1516,7 @@ checkWidget (); if ((style & DWT.MULTI) !is 0) return; if (echo !is 0) { - if ((echo = (char) Display.wcsToMbcs (echo, getCodePage ())) is 0) echo = '*'; + if ((echo = cast(char) Display.wcsToMbcs (echo, getCodePage ())) is 0) echo = '*'; } OS.SendMessage (handle, OS.EM_SETPASSWORDCHAR, echo, 0); /* @@ -1594,7 +1587,7 @@ * * @since 3.3 */ -public void setMessage (String message) { +public void setMessage (char[] message) { checkWidget (); if (message is null) error (DWT.ERROR_NULL_ARGUMENT); this.message = message; @@ -1602,10 +1595,7 @@ if ((style & DWT.SEARCH) !is 0) { int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); if ((bits & OS.ES_MULTILINE) is 0) { - int length = message.length (); - char [] chars = new char [length + 1]; - message.getChars(0, length, chars, 0); - OS.SendMessage (handle, OS.EM_SETCUEBANNER, 0, chars); + OS.SendMessage (handle, OS.EM_SETCUEBANNER, 0, StrToTCHARz( 0, message )); } } } @@ -1722,12 +1712,12 @@ * when redraw is restored. */ if (drawCount !is 0) return; - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); if (!redraw) { - oldStart = start [0]; oldEnd = end [0]; + oldStart = start; oldEnd = end; } else { - if (oldStart is start [0] && oldEnd is end [0]) return; + if (oldStart is start && oldEnd is end) return; OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); } } @@ -1797,7 +1787,7 @@ * number of space widths, depending on the font. */ int width = (getTabWidth (tabs) * 4) / (OS.GetDialogBaseUnits () & 0xFFFF); - OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, new int [] {width}); + OS.SendMessage (handle, OS.EM_SETTABSTOPS, 1, &width); } /** @@ -1815,7 +1805,7 @@ *
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  • * */ -public void setText (String string) { +public void setText (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); string = Display.withCrLf (string); @@ -1825,8 +1815,8 @@ if (string is null) return; } int limit = OS.SendMessage (handle, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF; - if (string.length () > limit) string = string.substring (0, limit); - TCHAR buffer = new TCHAR (getCodePage (), string, true); + if (string.length > limit) string = string.substring (0, limit); + TCHAR* buffer = StrToTCHARz (getCodePage (), string); OS.SetWindowText (handle, buffer); /* * Bug in Windows. When the widget is multi line @@ -1911,7 +1901,7 @@ OS.SendMessage (handle, OS.EM_SCROLLCARET, 0, 0); } -String verifyText (String string, int start, int end, Event keyEvent) { +char[] verifyText (char[] string, int start, int end, Event keyEvent) { if (ignoreVerify) return string; Event event = new Event (); event.text = string; @@ -1942,9 +1932,9 @@ if (OS.IsUnicode) return wcsPos; int cp = getCodePage (); int wcsTotal = 0, mbcsTotal = 0; - byte [] buffer = new byte [128]; - String delimiter = getLineDelimiter (); - int delimiterSize = delimiter.length (); + char [] buffer = new char [128]; + char[] delimiter = getLineDelimiter (); + int delimiterSize = delimiter.length; int count = OS.SendMessageA (handle, OS.EM_GETLINECOUNT, 0, 0); for (int line=0; line buffer.length) { - buffer = new byte [mbcsSize + delimiterSize]; + buffer = new char [mbcsSize + delimiterSize]; } //ENDIAN - buffer [0] = (byte) (mbcsSize & 0xFF); - buffer [1] = (byte) (mbcsSize >> 8); - mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer); - wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer, mbcsSize, null, 0); + buffer [0] = cast(char) (mbcsSize & 0xFF); + buffer [1] = cast(char) (mbcsSize >> 8); + mbcsSize = OS.SendMessageA (handle, OS.EM_GETLINE, line, buffer.ptr); + wcsSize = OS.MultiByteToWideChar (cp, OS.MB_PRECOMPOSED, buffer.ptr, mbcsSize, null, 0); } if (line - 1 !is count) { for (int i=0; i= 6 && OS.IsAppThemed ()) { control = findThemeControl (); if (control !is null) { - RECT rect = new RECT (); - OS.GetClientRect (handle, rect); - fillThemeBackground (wParam, control, rect); + RECT rect; + OS.GetClientRect (handle, &rect); + fillThemeBackground (cast(HANDLE)wParam, control, &rect); return LRESULT.ONE; } } @@ -2117,7 +2107,7 @@ override LRESULT WM_GETDLGCODE (int wParam, int lParam) { LRESULT result = super.WM_GETDLGCODE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; /* * Bug in WinCE PPC. For some reason, sending WM_GETDLGCODE @@ -2125,9 +2115,9 @@ * tab keys. The fix is to return the value which is normally * returned by the text window proc on other versions of Windows. */ - if (OS.IsPPC) { + if (OS.IsPPC_) { if ((style & DWT.MULTI) !is 0 && (style & DWT.READ_ONLY) is 0 && lParam is 0) { - return new LRESULT (OS.DLGC_HASSETSEL | OS.DLGC_WANTALLKEYS | OS.DLGC_WANTCHARS); + return cast(LRESULT) (OS.DLGC_HASSETSEL | OS.DLGC_WANTALLKEYS | OS.DLGC_WANTCHARS); } } @@ -2143,9 +2133,9 @@ if ((style & DWT.READ_ONLY) !is 0) { int code = callWindowProc (handle, OS.WM_GETDLGCODE, wParam, lParam); code &= ~(OS.DLGC_WANTALLKEYS | OS.DLGC_WANTTAB); - return new LRESULT (code); + return cast(LRESULT) (code); } - return null; + return LRESULT.NULL; } override LRESULT WM_IME_CHAR (int wParam, int lParam) { @@ -2168,18 +2158,18 @@ */ ignoreCharacter = true; int result = callWindowProc (handle, OS.WM_IME_CHAR, wParam, lParam); - MSG msg = new MSG (); + MSG msg; int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE; - while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) { - OS.TranslateMessage (msg); - OS.DispatchMessage (msg); + while (OS.PeekMessage (&msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) { + OS.TranslateMessage (&msg); + OS.DispatchMessage (&msg); } ignoreCharacter = false; sendKeyEvent (DWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam); // widget could be disposed at this point display.lastKey = display.lastAscii = 0; - return new LRESULT (result); + return cast(LRESULT) (result); } override LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) { @@ -2188,7 +2178,7 @@ * when double clicking behavior is disabled by not * calling the window proc. */ - LRESULT result = null; + LRESULT result = LRESULT.NULL; sendMouseEvent (DWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam); if (!sendMouseEvent (DWT.MouseDoubleClick, 1, handle, OS.WM_LBUTTONDBLCLK, wParam, lParam)) { result = LRESULT.ZERO; @@ -2208,11 +2198,11 @@ * text in the widget. The fix is to detect this case * and avoid calling the window proc. */ - int [] start = new int [1], end = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - if (start [0] is end [0]) { + int start, end; + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + if (start is end ) { int length = OS.GetWindowTextLength (handle); - if (length is start [0]) { + if (length is start) { int code = OS.SendMessage (handle, OS.EM_LINELENGTH, length, 0); if (code is 0) return LRESULT.ZERO; } @@ -2221,8 +2211,9 @@ } override LRESULT WM_LBUTTONDOWN (int wParam, int lParam) { - if (OS.IsPPC) { - LRESULT result = null; + static if( OS.IsWinCE ) + if (OS.IsPPC_) { + LRESULT result = LRESULT.NULL; Display display = this.display; display.captureChanged = false; bool dispatch = sendMouseEvent (DWT.MouseDown, 1, handle, OS.WM_LBUTTONDOWN, wParam, lParam); @@ -2237,22 +2228,22 @@ */ bool hasMenu = menu !is null && !menu.isDisposed (); if (hasMenu || hooks (DWT.MenuDetect)) { - int x = (short) (lParam & 0xFFFF); - int y = (short) (lParam >> 16); - SHRGINFO shrg = new SHRGINFO (); + int x = cast(short) (lParam & 0xFFFF); + int y = cast(short) (lParam >> 16); + SHRGINFO shrg; shrg.cbSize = SHRGINFO.sizeof; shrg.hwndClient = handle; - shrg.ptDown_x = x; - shrg.ptDown_y = y; + shrg.ptDown.x = x; + shrg.ptDown.y = y; shrg.dwFlags = OS.SHRG_RETURNCMD; - int type = OS.SHRecognizeGesture (shrg); + int type = OS.SHRecognizeGesture (&shrg); if (type is OS.GN_CONTEXTMENU) { showMenu (x, y); return LRESULT.ONE; } } if (dispatch) { - result = new LRESULT (callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam)); + result = cast(LRESULT) (callWindowProc (handle, OS.WM_LBUTTONDOWN, wParam, lParam)); } else { result = LRESULT.ZERO; } @@ -2261,32 +2252,32 @@ } return result; } - return super.WM_LBUTTONDOWN (wParam, lParam); + return super.WM_LBUTTONDOWN (wParam, lParam); } override LRESULT WM_PASTE (int wParam, int lParam) { LRESULT result = super.WM_PASTE (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; return wmClipboard (OS.WM_PASTE, wParam, lParam); } override LRESULT WM_UNDO (int wParam, int lParam) { LRESULT result = super.WM_UNDO (wParam, lParam); - if (result !is null) return result; + if (result !is LRESULT.NULL) return result; return wmClipboard (OS.WM_UNDO, wParam, lParam); } LRESULT wmClipboard (int msg, int wParam, int lParam) { - if ((style & DWT.READ_ONLY) !is 0) return null; - if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return null; + if ((style & DWT.READ_ONLY) !is 0) return LRESULT.NULL; + if (!hooks (DWT.Verify) && !filters (DWT.Verify)) return LRESULT.NULL; bool call = false; - int [] start = new int [1], end = new int [1]; - String newText = null; + int start, end; + char[] newText = null; switch (msg) { case OS.WM_CLEAR: case OS.WM_CUT: - OS.SendMessage (handle, OS.EM_GETSEL, start, end); - if (start [0] !is end [0]) { + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); + if (start !is end ) { newText = ""; call = true; } @@ -2299,15 +2290,15 @@ case OS.WM_UNDO: if (OS.SendMessage (handle, OS.EM_CANUNDO, 0, 0) !is 0) { ignoreModify = ignoreCharacter = true; - OS.SendMessage (handle, OS.EM_GETSEL, start, end); + OS.SendMessage (handle, OS.EM_GETSEL, &start, &end); callWindowProc (handle, msg, wParam, lParam); int length = OS.GetWindowTextLength (handle); - int [] newStart = new int [1], newEnd = new int [1]; - OS.SendMessage (handle, OS.EM_GETSEL, newStart, newEnd); - if (length !is 0 && newStart [0] !is newEnd [0]) { - TCHAR buffer = new TCHAR (getCodePage (), length + 1); - OS.GetWindowText (handle, buffer, length + 1); - newText = buffer.toString (newStart [0], newEnd [0] - newStart [0]); + int newStart, newEnd; + OS.SendMessage (handle, OS.EM_GETSEL, &newStart, &newEnd); + if (length !is 0 && newStart !is newEnd) { + TCHAR[] buffer = NewTCHARs (getCodePage (), length + 1); + OS.GetWindowText (handle, buffer.ptr, length + 1); + newText = TCHARsToStr( buffer[ newStart .. newEnd - newStart] ); } else { newText = ""; } @@ -2317,15 +2308,15 @@ break; } if (newText !is null) { - String oldText = newText; - newText = verifyText (newText, start [0], end [0], null); + char[] oldText = newText; + newText = verifyText (newText, start, end, null); if (newText is null) return LRESULT.ZERO; - if (!newText.equals (oldText)) { + if (newText !=/*eq*/oldText) { if (call) { callWindowProc (handle, msg, wParam, lParam); } newText = Display.withCrLf (newText); - TCHAR buffer = new TCHAR (getCodePage (), newText, true); + TCHAR* buffer = StrToTCHARz(getCodePage (), newText); /* * Feature in Windows. When an edit control with ES_MULTILINE * style that does not have the WS_VSCROLL style is full (i.e. @@ -2349,7 +2340,7 @@ ignoreVerify = ignoreCharacter = false; return LRESULT.ONE; } - return null; + return LRESULT.NULL; } override LRESULT wmColorChild (int wParam, int lParam) { @@ -2363,10 +2354,10 @@ if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { control = findThemeControl (); if (control !is null) { - OS.SetTextColor (wParam, getForegroundPixel ()); - OS.SetBkColor (wParam, getBackgroundPixel ()); - OS.SetBkMode (wParam, OS.TRANSPARENT); - return new LRESULT (OS.GetStockObject (OS.NULL_BRUSH)); + OS.SetTextColor (cast(HANDLE) wParam, getForegroundPixel ()); + OS.SetBkColor (cast(HANDLE) wParam, getBackgroundPixel ()); + OS.SetBkMode (cast(HANDLE) wParam, OS.TRANSPARENT); + return cast(LRESULT) (OS.GetStockObject (OS.NULL_BRUSH)); } } } @@ -2407,4 +2398,4 @@ } } -++/ +