# HG changeset patch
# User Frank Benoit
# Date 1202119710 -3600
# Node ID 1bc7c213161703e0a6e35dec78502ebe92632e46
# Parent 0f25be5cbe6feddc9f0bf247134b0ef0eb63ab36
List
diff -r 0f25be5cbe6f -r 1bc7c2131617 dwt/internal/win32/OS.d
--- 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 ];
+}
+
+
+
diff -r 0f25be5cbe6f -r 1bc7c2131617 dwt/widgets/List.d
--- 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 @@
*
*/
-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 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 @@
* ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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 @@
* ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-public String [] getItems () {
+public char[] [] getItems () {
checkWidget ();
int count = getItemCount ();
- String [] result = new String [count];
+ char[] [] result = new char[] [count];
for (int i=0; iERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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; iERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-public int indexOf (String string) {
+public int indexOf (char[] string) {
return indexOf (string, 0);
}
@@ -655,7 +653,7 @@
* ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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; iERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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 @@
* ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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 @@
* ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
*
*/
-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 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