Mercurial > projects > dwt-win
changeset 55:1bc7c2131617
List
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 11:08:30 +0100 |
parents | 0f25be5cbe6f |
children | dcb2e04003ac |
files | dwt/internal/win32/OS.d dwt/widgets/List.d |
diffstat | 2 files changed, 148 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/internal/win32/OS.d Mon Feb 04 10:05:20 2008 +0100 +++ b/dwt/internal/win32/OS.d Mon Feb 04 11:08:30 2008 +0100 @@ -4802,6 +4802,9 @@ return ret; } +public wchar[] StrToWCHARs(uint codepage , char[] sc) { + return StrToWCHARs( sc ); +} public wchar[] StrToWCHARs(char[] sc) { wchar[] ret; try{ @@ -4814,6 +4817,10 @@ return ret; } +public wchar* StrToWCHARz( uint codepage, char[] sc, uint* length = null ) { + return StrToWCHARz( sc, length ); +} + public wchar* StrToWCHARz(char[] sc, uint* length = null ) { return toString16z( StrToWCHARs(sc)); } @@ -4952,5 +4959,9 @@ //alias Converter.TCHARsToStr TCHARsToStr; - - +TCHAR[] NewTCHARs( uint codepage, uint len ){ + return new TCHAR[ len ]; +} + + +
--- a/dwt/widgets/List.d Mon Feb 04 10:05:20 2008 +0100 +++ b/dwt/widgets/List.d Mon Feb 04 11:08:30 2008 +0100 @@ -12,22 +12,20 @@ *******************************************************************************/ module dwt.widgets.List; -import dwt.widgets.Scrollable; -class List : Scrollable { -} -/++ + import dwt.DWT; import dwt.DWTException; import dwt.events.SelectionEvent; import dwt.events.SelectionListener; import dwt.graphics.Font; import dwt.graphics.Point; -import dwt.internal.win32.LRESULT; import dwt.internal.win32.OS; -import dwt.internal.win32.RECT; -import dwt.internal.win32.SCROLLINFO; -import dwt.internal.win32.TCHAR; -import dwt.internal.win32.WNDCLASS; + +import dwt.widgets.Scrollable; +import dwt.widgets.Composite; +import dwt.widgets.TypedListener; + +import dwt.dwthelper.utils; /** * Instances of this class represent a selectable user interface @@ -47,17 +45,17 @@ * </p> */ -public class List extends Scrollable { +public class List : Scrollable { alias Scrollable.computeSize computeSize; alias Scrollable.windowProc windowProc; - static final int INSET = 3; - static final int ListProc; - static final TCHAR ListClass = new TCHAR (0, "LISTBOX", true); - static { - WNDCLASS lpWndClass = new WNDCLASS (); - OS.GetClassInfo (0, ListClass, lpWndClass); + static const int INSET = 3; + static const WNDPROC ListProc; + static const TCHAR[] ListClass = "LISTBOX"; + static this() { + WNDCLASS lpWndClass; + OS.GetClassInfo (null, ListClass.ptr, &lpWndClass); ListProc = lpWndClass.lpfnWndProc; } @@ -90,7 +88,7 @@ * @see Widget#checkSubclass * @see Widget#getStyle */ -public List (Composite parent, int style) { +public this (Composite parent, int style) { super (parent, checkStyle (style)); } /** @@ -108,10 +106,10 @@ * * @see #add(String,int) */ -public void add (String string) { +public void add (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz ( getCodePage (), string); int result = OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer); if (result is OS.LB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); if (result is OS.LB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); @@ -140,11 +138,11 @@ * * @see #add(String) */ -public void add (String string, int index) { +public void add (char[] string, int index) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); if (index is -1) error (DWT.ERROR_INVALID_RANGE); - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz(getCodePage (), string); int result = OS.SendMessage (handle, OS.LB_INSERTSTRING, index, buffer); if (result is OS.LB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); if (result is OS.LB_ERR) { @@ -190,9 +188,9 @@ addListener (DWT.DefaultSelection,typedListener); } -override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { - if (handle is 0) return 0; - return OS.CallWindowProc (ListProc, 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 (ListProc, hwnd, msg, wParam, lParam); } static int checkStyle (int style) { @@ -208,28 +206,28 @@ width -= INSET; } else { int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); - 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); - RECT rect = new RECT (); + 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); + RECT rect; int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; int cp = getCodePage (); - TCHAR buffer = new TCHAR (cp, 64 + 1); + TCHAR[] buffer = NewTCHARs (cp, 64 + 1); for (int i=0; i<count; i++) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0); if (length !is OS.LB_ERR) { - if (length + 1 > buffer.length ()) { - buffer = new TCHAR (cp, length + 1); + if (length + 1 > buffer.length) { + buffer = NewTCHARs (cp, length + 1); } - int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer.ptr); if (result !is OS.LB_ERR) { - OS.DrawText (hDC, buffer, length, rect, flags); + OS.DrawText (hDC, buffer.ptr, length, &rect, flags); width = Math.max (width, rect.right - rect.left); } } } - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); } } @@ -415,13 +413,13 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public String getItem (int index) { +public char[] getItem (int index) { checkWidget (); - int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); - if (length !is OS.LB_ERR) { - TCHAR buffer = new TCHAR (getCodePage (), length + 1); - int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); - if (result !is OS.LB_ERR) return buffer.toString (0, length); + int length_ = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); + if (length_ !is OS.LB_ERR) { + TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); + if (result !is OS.LB_ERR) return TCHARsToStr( buffer[0 .. length_] ); } int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (0 <= index && index < count) error (DWT.ERROR_CANNOT_GET_ITEM); @@ -480,10 +478,10 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public String [] getItems () { +public char[] [] getItems () { checkWidget (); int count = getItemCount (); - String [] result = new String [count]; + char[] [] result = new char[] [count]; for (int i=0; i<count; i++) result [i] = getItem (i); return result; } @@ -504,10 +502,10 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public String [] getSelection () { +public char[] [] getSelection () { checkWidget (); int [] indices = getSelectionIndices (); - String [] result = new String [indices.length]; + char[] [] result = new char[] [indices.length]; for (int i=0; i<indices.length; i++) { result [i] = getItem (indices [i]); } @@ -559,10 +557,10 @@ int result = OS.SendMessage (handle, OS.LB_GETSEL, index, 0); if (result is OS.LB_ERR) error (DWT.ERROR_CANNOT_GET_SELECTION); if (result !is 0) return index; - int [] buffer = new int [1]; - result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, buffer); + int buffer; + result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, &buffer); if (result !is 1) error (DWT.ERROR_CANNOT_GET_SELECTION); - return buffer [0]; + return buffer; } /** @@ -586,12 +584,12 @@ if ((style & DWT.SINGLE) !is 0) { int result = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); if (result is OS.LB_ERR) return new int [0]; - return new int [] {result}; + return [result]; } int length = OS.SendMessage (handle, OS.LB_GETSELCOUNT, 0, 0); if (length is OS.LB_ERR) error (DWT.ERROR_CANNOT_GET_SELECTION); int [] indices = new int [length]; - int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, length, indices); + int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, length, indices.ptr); if (result !is length) error (DWT.ERROR_CANNOT_GET_SELECTION); return indices; } @@ -632,7 +630,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int indexOf (String string) { +public int indexOf (char[] string) { return indexOf (string, 0); } @@ -655,7 +653,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int indexOf (String string, int start) { +public int indexOf (char[] string, int start) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); @@ -665,10 +663,10 @@ * to insert an empty string into a list. The fix is * to search the list, an item at a time. */ - if (string.length () is 0) { + if (string.length is 0) { int count = getItemCount (); for (int i=start; i<count; i++) { - if (string.equals (getItem (i))) return i; + if (string ==/*eq*/ getItem (i)) return i; } return -1; } @@ -677,11 +675,11 @@ int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (!(0 <= start && start < count)) return -1; int index = start - 1, last; - TCHAR buffer = new TCHAR (getCodePage (), string, true); + TCHAR* buffer = StrToTCHARz (getCodePage (), string ); do { index = OS.SendMessage (handle, OS.LB_FINDSTRINGEXACT, last = index, buffer); if (index is OS.LB_ERR || index <= last) return -1; - } while (!string.equals (getItem (index))); + } while (string !=/*eq*/ getItem (index)); return index; } @@ -732,32 +730,34 @@ error (DWT.ERROR_INVALID_RANGE); } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); - RECT rect = null; - int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; + RECT rect; + HDC hDC; + HFONT oldFont, newFont; + int newWidth = 0; if ((style & DWT.H_SCROLL) !is 0) { - rect = new RECT (); + //rect = new RECT (); hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); } int cp = getCodePage (); int i = 0, topCount = 0, last = -1; while (i < newIndices.length) { int index = newIndices [i]; if (index !is last) { - TCHAR buffer = null; + TCHAR[] buffer = null; if ((style & DWT.H_SCROLL) !is 0) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); if (length is OS.LB_ERR) break; - buffer = new TCHAR (cp, length + 1); - int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); + buffer = NewTCHARs (cp, length + 1); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); if (result is OS.LB_ERR) break; } int result = OS.SendMessage (handle, OS.LB_DELETESTRING, index, 0); if (result is OS.LB_ERR) break; if ((style & DWT.H_SCROLL) !is 0) { int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; - OS.DrawText (hDC, buffer, -1, rect, flags); + OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); newWidth = Math.max (newWidth, rect.right - rect.left); } if (index < topIndex) topCount++; @@ -766,7 +766,7 @@ i++; } if ((style & DWT.H_SCROLL) !is 0) { - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); setScrollWidth (newWidth, false); } @@ -793,7 +793,7 @@ */ public void remove (int index) { checkWidget (); - TCHAR buffer = null; + TCHAR[] buffer = null; if ((style & DWT.H_SCROLL) !is 0) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); if (length is OS.LB_ERR) { @@ -801,8 +801,8 @@ if (0 <= index && index < count) error (DWT.ERROR_ITEM_NOT_REMOVED); error (DWT.ERROR_INVALID_RANGE); } - buffer = new TCHAR (getCodePage (), length + 1); - int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); + buffer = NewTCHARs (getCodePage (), length + 1); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); if (result is OS.LB_ERR) { int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (0 <= index && index < count) error (DWT.ERROR_ITEM_NOT_REMOVED); @@ -816,7 +816,7 @@ if (0 <= index && index < count) error (DWT.ERROR_ITEM_NOT_REMOVED); error (DWT.ERROR_INVALID_RANGE); } - if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer, false); + if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer.ptr, false); if (index < topIndex) { OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex - 1, 0); } @@ -850,36 +850,38 @@ return; } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); - RECT rect = null; - int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; + RECT rect; + HDC hDC; + HFONT oldFont, newFont; + int newWidth = 0; if ((style & DWT.H_SCROLL) !is 0) { - rect = new RECT (); + //rect = new RECT (); hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); } int cp = getCodePage (); int index = start; int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; while (index <= end) { - TCHAR buffer = null; + TCHAR[] buffer = null; if ((style & DWT.H_SCROLL) !is 0) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, start, 0); if (length is OS.LB_ERR) break; - buffer = new TCHAR (cp, length + 1); - int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer); + buffer = NewTCHARs (cp, length + 1); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer.ptr); if (result is OS.LB_ERR) break; } int result = OS.SendMessage (handle, OS.LB_DELETESTRING, start, 0); if (result is OS.LB_ERR) break; if ((style & DWT.H_SCROLL) !is 0) { - OS.DrawText (hDC, buffer, -1, rect, flags); + OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); newWidth = Math.max (newWidth, rect.right - rect.left); } index++; } if ((style & DWT.H_SCROLL) !is 0) { - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); setScrollWidth (newWidth, false); } @@ -906,7 +908,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void remove (String string) { +public void remove (char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); int index = indexOf (string, 0); @@ -1027,8 +1029,9 @@ return; } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); - RECT itemRect = new RECT (), selectedRect = null; - OS.SendMessage (handle, OS.LB_GETITEMRECT, index, itemRect); + RECT itemRect, selectedRect; + bool selectedRectNull = true; + OS.SendMessage (handle, OS.LB_GETITEMRECT, index, &itemRect); bool redraw = drawCount is 0 && OS.IsWindowVisible (handle); if (redraw) { OS.UpdateWindow (handle); @@ -1038,8 +1041,9 @@ if ((style & DWT.SINGLE) !is 0) { int oldIndex = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); if (oldIndex !is -1) { - selectedRect = new RECT (); - OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, selectedRect); + //selectedRect = new RECT (); + selectedRectNull = false; + OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, &selectedRect); } OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0); } else { @@ -1055,9 +1059,9 @@ if (redraw) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); OS.ValidateRect (handle, null); - OS.InvalidateRect (handle, itemRect, true); - if (selectedRect !is null) { - OS.InvalidateRect (handle, selectedRect, true); + OS.InvalidateRect (handle, &itemRect, true); + if (!selectedRectNull) { + OS.InvalidateRect (handle, &selectedRect, true); } } } @@ -1156,7 +1160,7 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setItem (int index, String string) { +public void setItem (int index, char[] string) { checkWidget (); if (string is null) error (DWT.ERROR_NULL_ARGUMENT); int topIndex = getTopIndex (); @@ -1181,25 +1185,27 @@ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setItems (String [] items) { +public void setItems (char[] [] items) { checkWidget (); if (items is null) error (DWT.ERROR_NULL_ARGUMENT); for (int i=0; i<items.length; i++) { if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); } int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); - OS.SetWindowLong (handle, OS.GWL_WNDPROC, ListProc); + OS.SetWindowLong (handle, OS.GWL_WNDPROC, cast(int) ListProc); bool redraw = drawCount is 0 && OS.IsWindowVisible (handle); if (redraw) { OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); } - RECT rect = null; - int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; + RECT rect; + HDC hDC; + HFONT oldFont, newFont; + int newWidth = 0; if ((style & DWT.H_SCROLL) !is 0) { - rect = new RECT (); + //rect = new RECT (); hDC = OS.GetDC (handle); - newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); - if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); + newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); + if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0); } int length = items.length; @@ -1208,19 +1214,19 @@ int index = 0; int cp = getCodePage (); while (index < length) { - String string = items [index]; - TCHAR buffer = new TCHAR (cp, string, true); + char[] string = items [index]; + TCHAR* buffer = StrToTCHARz (cp, string); int result = OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer); if (result is OS.LB_ERR || result is OS.LB_ERRSPACE) break; if ((style & DWT.H_SCROLL) !is 0) { int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; - OS.DrawText (hDC, buffer, -1, rect, flags); + OS.DrawText (hDC, buffer, -1, &rect, flags); newWidth = Math.max (newWidth, rect.right - rect.left); } index++; } if ((style & DWT.H_SCROLL) !is 0) { - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0); } @@ -1243,39 +1249,39 @@ void setScrollWidth () { int newWidth = 0; - RECT rect = new RECT (); - 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); + RECT rect; + 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); int cp = getCodePage (); int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; for (int i=0; i<count; i++) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0); if (length !is OS.LB_ERR) { - TCHAR buffer = new TCHAR (cp, length + 1); - int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer); + TCHAR[] buffer = NewTCHARs (cp, length + 1 ); + int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer.ptr); if (result !is OS.LB_ERR) { - OS.DrawText (hDC, buffer, -1, rect, flags); + OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); newWidth = Math.max (newWidth, rect.right - rect.left); } } } - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0); } -void setScrollWidth (TCHAR buffer, bool grow) { - RECT rect = new RECT (); - 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); +void setScrollWidth (TCHAR* buffer, bool grow) { + RECT rect; + 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); int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; - OS.DrawText (hDC, buffer, -1, rect, flags); - if (newFont !is 0) OS.SelectObject (hDC, oldFont); + OS.DrawText (hDC, buffer, -1, &rect, flags); + if (newFont !is null) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); setScrollWidth (rect.right - rect.left, grow); } @@ -1348,7 +1354,7 @@ * @see List#select(int[]) * @see List#setSelection(int[]) */ -public void setSelection (String [] items) { +public void setSelection (char[] [] items) { checkWidget (); if (items is null) error (DWT.ERROR_NULL_ARGUMENT); deselectAll (); @@ -1356,7 +1362,7 @@ if (length is 0 || ((style & DWT.SINGLE) !is 0 && length > 1)) return; int focusIndex = -1; for (int i=length-1; i>=0; --i) { - String string = items [i]; + char[] string = items [i]; int index = 0; if (string !is null) { int localFocus = -1; @@ -1476,9 +1482,9 @@ if ((style & DWT.SINGLE) !is 0) { index = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); } else { - int [] indices = new int [1]; - int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, indices); - index = indices [0]; + int indices; + int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, &indices); + index = indices; if (result !is 1) index = -1; } if (index is -1) return; @@ -1486,8 +1492,8 @@ if (count is 0) return; int height = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0); forceResize (); - RECT rect = new RECT (); - OS.GetClientRect (handle, rect); + RECT rect; + OS.GetClientRect (handle, &rect); int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); int visibleCount = Math.max (rect.bottom / height, 1); int bottomIndex = Math.min (topIndex + visibleCount, count) - 1; @@ -1506,12 +1512,12 @@ return bits; } -override TCHAR windowClass () { - return ListClass; +override char[] windowClass () { + return TCHARsToStr( ListClass ); } override int windowProc () { - return ListProc; + return cast(int) ListProc; } override LRESULT WM_SIZE (int wParam, int lParam) { @@ -1530,10 +1536,10 @@ int oldIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); LRESULT result = super.WM_SIZE (wParam, lParam); if (!isDisposed ()) { - SCROLLINFO info = new SCROLLINFO (); + SCROLLINFO info; info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; - if (OS.GetScrollInfo (handle, OS.SB_HORZ, info)) { + if (OS.GetScrollInfo (handle, OS.SB_HORZ, &info)) { if (info.nPos !is 0) OS.InvalidateRect (handle, null, true); } int newIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); @@ -1558,4 +1564,3 @@ } -++/ \ No newline at end of file