Changeset 55:1bc7c2131617
- Timestamp:
- 02/04/08 05:08:30
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
List
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r52 |
r55 |
|
| 4803 | 4803 | } |
|---|
| 4804 | 4804 | |
|---|
| | 4805 | public wchar[] StrToWCHARs(uint codepage , char[] sc) { |
|---|
| | 4806 | return StrToWCHARs( sc ); |
|---|
| | 4807 | } |
|---|
| 4805 | 4808 | public wchar[] StrToWCHARs(char[] sc) { |
|---|
| 4806 | 4809 | wchar[] ret; |
|---|
| … | … | |
| 4813 | 4816 | |
|---|
| 4814 | 4817 | return ret; |
|---|
| | 4818 | } |
|---|
| | 4819 | |
|---|
| | 4820 | public wchar* StrToWCHARz( uint codepage, char[] sc, uint* length = null ) { |
|---|
| | 4821 | return StrToWCHARz( sc, length ); |
|---|
| 4815 | 4822 | } |
|---|
| 4816 | 4823 | |
|---|
| … | … | |
| 4953 | 4960 | |
|---|
| 4954 | 4961 | |
|---|
| 4955 | | |
|---|
| 4956 | | |
|---|
| | 4962 | TCHAR[] NewTCHARs( uint codepage, uint len ){ |
|---|
| | 4963 | return new TCHAR[ len ]; |
|---|
| | 4964 | } |
|---|
| | 4965 | |
|---|
| | 4966 | |
|---|
| | 4967 | |
|---|
| r54 |
r55 |
|
| 13 | 13 | module dwt.widgets.List; |
|---|
| 14 | 14 | |
|---|
| 15 | | import dwt.widgets.Scrollable; |
|---|
| 16 | | class List : Scrollable { |
|---|
| 17 | | } |
|---|
| 18 | | /++ |
|---|
| | 15 | |
|---|
| 19 | 16 | import dwt.DWT; |
|---|
| 20 | 17 | import dwt.DWTException; |
|---|
| … | … | |
| 23 | 20 | import dwt.graphics.Font; |
|---|
| 24 | 21 | import dwt.graphics.Point; |
|---|
| 25 | | import dwt.internal.win32.LRESULT; |
|---|
| 26 | 22 | import dwt.internal.win32.OS; |
|---|
| 27 | | import dwt.internal.win32.RECT; |
|---|
| 28 | | import dwt.internal.win32.SCROLLINFO; |
|---|
| 29 | | import dwt.internal.win32.TCHAR; |
|---|
| 30 | | import dwt.internal.win32.WNDCLASS; |
|---|
| | 23 | |
|---|
| | 24 | import dwt.widgets.Scrollable; |
|---|
| | 25 | import dwt.widgets.Composite; |
|---|
| | 26 | import dwt.widgets.TypedListener; |
|---|
| | 27 | |
|---|
| | 28 | import dwt.dwthelper.utils; |
|---|
| 31 | 29 | |
|---|
| 32 | 30 | /** |
|---|
| … | … | |
| 48 | 46 | */ |
|---|
| 49 | 47 | |
|---|
| 50 | | public class List extends Scrollable { |
|---|
| | 48 | public class List : Scrollable { |
|---|
| 51 | 49 | |
|---|
| 52 | 50 | alias Scrollable.computeSize computeSize; |
|---|
| 53 | 51 | alias Scrollable.windowProc windowProc; |
|---|
| 54 | 52 | |
|---|
| 55 | | static final int INSET = 3; |
|---|
| 56 | | static final int ListProc; |
|---|
| 57 | | static final TCHAR ListClass = new TCHAR (0, "LISTBOX", true); |
|---|
| 58 | | static { |
|---|
| 59 | | WNDCLASS lpWndClass = new WNDCLASS (); |
|---|
| 60 | | OS.GetClassInfo (0, ListClass, lpWndClass); |
|---|
| | 53 | static const int INSET = 3; |
|---|
| | 54 | static const WNDPROC ListProc; |
|---|
| | 55 | static const TCHAR[] ListClass = "LISTBOX"; |
|---|
| | 56 | static this() { |
|---|
| | 57 | WNDCLASS lpWndClass; |
|---|
| | 58 | OS.GetClassInfo (null, ListClass.ptr, &lpWndClass); |
|---|
| 61 | 59 | ListProc = lpWndClass.lpfnWndProc; |
|---|
| 62 | 60 | } |
|---|
| … | … | |
| 91 | 89 | * @see Widget#getStyle |
|---|
| 92 | 90 | */ |
|---|
| 93 | | public List (Composite parent, int style) { |
|---|
| | 91 | public this (Composite parent, int style) { |
|---|
| 94 | 92 | super (parent, checkStyle (style)); |
|---|
| 95 | 93 | } |
|---|
| … | … | |
| 109 | 107 | * @see #add(String,int) |
|---|
| 110 | 108 | */ |
|---|
| 111 | | public void add (String string) { |
|---|
| | 109 | public void add (char[] string) { |
|---|
| 112 | 110 | checkWidget (); |
|---|
| 113 | 111 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 114 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 112 | TCHAR* buffer = StrToTCHARz ( getCodePage (), string); |
|---|
| 115 | 113 | int result = OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer); |
|---|
| 116 | 114 | if (result is OS.LB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| … | … | |
| 141 | 139 | * @see #add(String) |
|---|
| 142 | 140 | */ |
|---|
| 143 | | public void add (String string, int index) { |
|---|
| | 141 | public void add (char[] string, int index) { |
|---|
| 144 | 142 | checkWidget (); |
|---|
| 145 | 143 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 146 | 144 | if (index is -1) error (DWT.ERROR_INVALID_RANGE); |
|---|
| 147 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 145 | TCHAR* buffer = StrToTCHARz(getCodePage (), string); |
|---|
| 148 | 146 | int result = OS.SendMessage (handle, OS.LB_INSERTSTRING, index, buffer); |
|---|
| 149 | 147 | if (result is OS.LB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| … | … | |
| 191 | 189 | } |
|---|
| 192 | 190 | |
|---|
| 193 | | override int callWindowProc (int hwnd, int msg, int wParam, int lParam) { |
|---|
| 194 | | if (handle is 0) return 0; |
|---|
| 195 | | return OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam); |
|---|
| | 191 | override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { |
|---|
| | 192 | if (handle is null) return LRESULT.ZERO; |
|---|
| | 193 | return cast(LRESULT) OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam); |
|---|
| 196 | 194 | } |
|---|
| 197 | 195 | |
|---|
| … | … | |
| 209 | 207 | } else { |
|---|
| 210 | 208 | int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); |
|---|
| 211 | | int newFont, oldFont = 0; |
|---|
| 212 | | int hDC = OS.GetDC (handle); |
|---|
| 213 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 214 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 215 | | RECT rect = new RECT (); |
|---|
| | 209 | HFONT newFont, oldFont; |
|---|
| | 210 | auto hDC = OS.GetDC (handle); |
|---|
| | 211 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 212 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 213 | RECT rect; |
|---|
| 216 | 214 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 217 | 215 | int cp = getCodePage (); |
|---|
| 218 | | TCHAR buffer = new TCHAR (cp, 64 + 1); |
|---|
| | 216 | TCHAR[] buffer = NewTCHARs (cp, 64 + 1); |
|---|
| 219 | 217 | for (int i=0; i<count; i++) { |
|---|
| 220 | 218 | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0); |
|---|
| 221 | 219 | if (length !is OS.LB_ERR) { |
|---|
| 222 | | if (length + 1 > buffer.length ()) { |
|---|
| 223 | | buffer = new TCHAR (cp, length + 1); |
|---|
| | 220 | if (length + 1 > buffer.length) { |
|---|
| | 221 | buffer = NewTCHARs (cp, length + 1); |
|---|
| 224 | 222 | } |
|---|
| 225 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer); |
|---|
| | 223 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer.ptr); |
|---|
| 226 | 224 | if (result !is OS.LB_ERR) { |
|---|
| 227 | | OS.DrawText (hDC, buffer, length, rect, flags); |
|---|
| | 225 | OS.DrawText (hDC, buffer.ptr, length, &rect, flags); |
|---|
| 228 | 226 | width = Math.max (width, rect.right - rect.left); |
|---|
| 229 | 227 | } |
|---|
| 230 | 228 | } |
|---|
| 231 | 229 | } |
|---|
| 232 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 230 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 233 | 231 | OS.ReleaseDC (handle, hDC); |
|---|
| 234 | 232 | } |
|---|
| … | … | |
| 416 | 414 | * </ul> |
|---|
| 417 | 415 | */ |
|---|
| 418 | | public String getItem (int index) { |
|---|
| 419 | | checkWidget (); |
|---|
| 420 | | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); |
|---|
| 421 | | if (length !is OS.LB_ERR) { |
|---|
| 422 | | TCHAR buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 423 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); |
|---|
| 424 | | if (result !is OS.LB_ERR) return buffer.toString (0, length); |
|---|
| | 416 | public char[] getItem (int index) { |
|---|
| | 417 | checkWidget (); |
|---|
| | 418 | int length_ = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); |
|---|
| | 419 | if (length_ !is OS.LB_ERR) { |
|---|
| | 420 | TCHAR[] buffer = NewTCHARs (getCodePage (), length_ + 1); |
|---|
| | 421 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); |
|---|
| | 422 | if (result !is OS.LB_ERR) return TCHARsToStr( buffer[0 .. length_] ); |
|---|
| 425 | 423 | } |
|---|
| 426 | 424 | int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); |
|---|
| … | … | |
| 481 | 479 | * </ul> |
|---|
| 482 | 480 | */ |
|---|
| 483 | | public String [] getItems () { |
|---|
| | 481 | public char[] [] getItems () { |
|---|
| 484 | 482 | checkWidget (); |
|---|
| 485 | 483 | int count = getItemCount (); |
|---|
| 486 | | String [] result = new String [count]; |
|---|
| | 484 | char[] [] result = new char[] [count]; |
|---|
| 487 | 485 | for (int i=0; i<count; i++) result [i] = getItem (i); |
|---|
| 488 | 486 | return result; |
|---|
| … | … | |
| 505 | 503 | * </ul> |
|---|
| 506 | 504 | */ |
|---|
| 507 | | public String [] getSelection () { |
|---|
| | 505 | public char[] [] getSelection () { |
|---|
| 508 | 506 | checkWidget (); |
|---|
| 509 | 507 | int [] indices = getSelectionIndices (); |
|---|
| 510 | | String [] result = new String [indices.length]; |
|---|
| | 508 | char[] [] result = new char[] [indices.length]; |
|---|
| 511 | 509 | for (int i=0; i<indices.length; i++) { |
|---|
| 512 | 510 | result [i] = getItem (indices [i]); |
|---|
| … | … | |
| 560 | 558 | if (result is OS.LB_ERR) error (DWT.ERROR_CANNOT_GET_SELECTION); |
|---|
| 561 | 559 | if (result !is 0) return index; |
|---|
| 562 | | int [] buffer = new int [1]; |
|---|
| 563 | | result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, buffer); |
|---|
| | 560 | int buffer; |
|---|
| | 561 | result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, &buffer); |
|---|
| 564 | 562 | if (result !is 1) error (DWT.ERROR_CANNOT_GET_SELECTION); |
|---|
| 565 | | return buffer [0]; |
|---|
| | 563 | return buffer; |
|---|
| 566 | 564 | } |
|---|
| 567 | 565 | |
|---|
| … | … | |
| 587 | 585 | int result = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); |
|---|
| 588 | 586 | if (result is OS.LB_ERR) return new int [0]; |
|---|
| 589 | | return new int [] {result}; |
|---|
| | 587 | return [result]; |
|---|
| 590 | 588 | } |
|---|
| 591 | 589 | int length = OS.SendMessage (handle, OS.LB_GETSELCOUNT, 0, 0); |
|---|
| 592 | 590 | if (length is OS.LB_ERR) error (DWT.ERROR_CANNOT_GET_SELECTION); |
|---|
| 593 | 591 | int [] indices = new int [length]; |
|---|
| 594 | | int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, length, indices); |
|---|
| | 592 | int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, length, indices.ptr); |
|---|
| 595 | 593 | if (result !is length) error (DWT.ERROR_CANNOT_GET_SELECTION); |
|---|
| 596 | 594 | return indices; |
|---|
| … | … | |
| 633 | 631 | * </ul> |
|---|
| 634 | 632 | */ |
|---|
| 635 | | public int indexOf (String string) { |
|---|
| | 633 | public int indexOf (char[] string) { |
|---|
| 636 | 634 | return indexOf (string, 0); |
|---|
| 637 | 635 | } |
|---|
| … | … | |
| 656 | 654 | * </ul> |
|---|
| 657 | 655 | */ |
|---|
| 658 | | public int indexOf (String string, int start) { |
|---|
| | 656 | public int indexOf (char[] string, int start) { |
|---|
| 659 | 657 | checkWidget (); |
|---|
| 660 | 658 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 666 | 664 | * to search the list, an item at a time. |
|---|
| 667 | 665 | */ |
|---|
| 668 | | if (string.length () is 0) { |
|---|
| | 666 | if (string.length is 0) { |
|---|
| 669 | 667 | int count = getItemCount (); |
|---|
| 670 | 668 | for (int i=start; i<count; i++) { |
|---|
| 671 | | if (string.equals (getItem (i))) return i; |
|---|
| | 669 | if (string ==/*eq*/ getItem (i)) return i; |
|---|
| 672 | 670 | } |
|---|
| 673 | 671 | return -1; |
|---|
| … | … | |
| 678 | 676 | if (!(0 <= start && start < count)) return -1; |
|---|
| 679 | 677 | int index = start - 1, last; |
|---|
| 680 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 678 | TCHAR* buffer = StrToTCHARz (getCodePage (), string ); |
|---|
| 681 | 679 | do { |
|---|
| 682 | 680 | index = OS.SendMessage (handle, OS.LB_FINDSTRINGEXACT, last = index, buffer); |
|---|
| 683 | 681 | if (index is OS.LB_ERR || index <= last) return -1; |
|---|
| 684 | | } while (!string.equals (getItem (index))); |
|---|
| | 682 | } while (string !=/*eq*/ getItem (index)); |
|---|
| 685 | 683 | return index; |
|---|
| 686 | 684 | } |
|---|
| … | … | |
| 733 | 731 | } |
|---|
| 734 | 732 | int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); |
|---|
| 735 | | RECT rect = null; |
|---|
| 736 | | int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; |
|---|
| | 733 | RECT rect; |
|---|
| | 734 | HDC hDC; |
|---|
| | 735 | HFONT oldFont, newFont; |
|---|
| | 736 | int newWidth = 0; |
|---|
| 737 | 737 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 738 | | rect = new RECT (); |
|---|
| | 738 | //rect = new RECT (); |
|---|
| 739 | 739 | hDC = OS.GetDC (handle); |
|---|
| 740 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 741 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 740 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 741 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 742 | 742 | } |
|---|
| 743 | 743 | int cp = getCodePage (); |
|---|
| … | … | |
| 746 | 746 | int index = newIndices [i]; |
|---|
| 747 | 747 | if (index !is last) { |
|---|
| 748 | | TCHAR buffer = null; |
|---|
| | 748 | TCHAR[] buffer = null; |
|---|
| 749 | 749 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 750 | 750 | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); |
|---|
| 751 | 751 | if (length is OS.LB_ERR) break; |
|---|
| 752 | | buffer = new TCHAR (cp, length + 1); |
|---|
| 753 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); |
|---|
| | 752 | buffer = NewTCHARs (cp, length + 1); |
|---|
| | 753 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); |
|---|
| 754 | 754 | if (result is OS.LB_ERR) break; |
|---|
| 755 | 755 | } |
|---|
| … | … | |
| 758 | 758 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 759 | 759 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 760 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 760 | OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); |
|---|
| 761 | 761 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 762 | 762 | } |
|---|
| … | … | |
| 767 | 767 | } |
|---|
| 768 | 768 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 769 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 769 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 770 | 770 | OS.ReleaseDC (handle, hDC); |
|---|
| 771 | 771 | setScrollWidth (newWidth, false); |
|---|
| … | … | |
| 794 | 794 | public void remove (int index) { |
|---|
| 795 | 795 | checkWidget (); |
|---|
| 796 | | TCHAR buffer = null; |
|---|
| | 796 | TCHAR[] buffer = null; |
|---|
| 797 | 797 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 798 | 798 | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); |
|---|
| … | … | |
| 802 | 802 | error (DWT.ERROR_INVALID_RANGE); |
|---|
| 803 | 803 | } |
|---|
| 804 | | buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 805 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); |
|---|
| | 804 | buffer = NewTCHARs (getCodePage (), length + 1); |
|---|
| | 805 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer.ptr); |
|---|
| 806 | 806 | if (result is OS.LB_ERR) { |
|---|
| 807 | 807 | int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); |
|---|
| … | … | |
| 817 | 817 | error (DWT.ERROR_INVALID_RANGE); |
|---|
| 818 | 818 | } |
|---|
| 819 | | if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer, false); |
|---|
| | 819 | if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer.ptr, false); |
|---|
| 820 | 820 | if (index < topIndex) { |
|---|
| 821 | 821 | OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex - 1, 0); |
|---|
| … | … | |
| 851 | 851 | } |
|---|
| 852 | 852 | int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); |
|---|
| 853 | | RECT rect = null; |
|---|
| 854 | | int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; |
|---|
| | 853 | RECT rect; |
|---|
| | 854 | HDC hDC; |
|---|
| | 855 | HFONT oldFont, newFont; |
|---|
| | 856 | int newWidth = 0; |
|---|
| 855 | 857 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 856 | | rect = new RECT (); |
|---|
| | 858 | //rect = new RECT (); |
|---|
| 857 | 859 | hDC = OS.GetDC (handle); |
|---|
| 858 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 859 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 860 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 861 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 860 | 862 | } |
|---|
| 861 | 863 | int cp = getCodePage (); |
|---|
| … | … | |
| 863 | 865 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 864 | 866 | while (index <= end) { |
|---|
| 865 | | TCHAR buffer = null; |
|---|
| | 867 | TCHAR[] buffer = null; |
|---|
| 866 | 868 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 867 | 869 | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, start, 0); |
|---|
| 868 | 870 | if (length is OS.LB_ERR) break; |
|---|
| 869 | | buffer = new TCHAR (cp, length + 1); |
|---|
| 870 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer); |
|---|
| | 871 | buffer = NewTCHARs (cp, length + 1); |
|---|
| | 872 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer.ptr); |
|---|
| 871 | 873 | if (result is OS.LB_ERR) break; |
|---|
| 872 | 874 | } |
|---|
| … | … | |
| 874 | 876 | if (result is OS.LB_ERR) break; |
|---|
| 875 | 877 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 876 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 878 | OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); |
|---|
| 877 | 879 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 878 | 880 | } |
|---|
| … | … | |
| 880 | 882 | } |
|---|
| 881 | 883 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 882 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 884 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 883 | 885 | OS.ReleaseDC (handle, hDC); |
|---|
| 884 | 886 | setScrollWidth (newWidth, false); |
|---|
| … | … | |
| 907 | 909 | * </ul> |
|---|
| 908 | 910 | */ |
|---|
| 909 | | public void remove (String string) { |
|---|
| | 911 | public void remove (char[] string) { |
|---|
| 910 | 912 | checkWidget (); |
|---|
| 911 | 913 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1028 | 1030 | } |
|---|
| 1029 | 1031 | int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); |
|---|
| 1030 | | RECT itemRect = new RECT (), selectedRect = null; |
|---|
| 1031 | | OS.SendMessage (handle, OS.LB_GETITEMRECT, index, itemRect); |
|---|
| | 1032 | RECT itemRect, selectedRect; |
|---|
| | 1033 | bool selectedRectNull = true; |
|---|
| | 1034 | OS.SendMessage (handle, OS.LB_GETITEMRECT, index, &itemRect); |
|---|
| 1032 | 1035 | bool redraw = drawCount is 0 && OS.IsWindowVisible (handle); |
|---|
| 1033 | 1036 | if (redraw) { |
|---|
| … | … | |
| 1039 | 1042 | int oldIndex = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); |
|---|
| 1040 | 1043 | if (oldIndex !is -1) { |
|---|
| 1041 | | selectedRect = new RECT (); |
|---|
| 1042 | | OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, selectedRect); |
|---|
| | 1044 | //selectedRect = new RECT (); |
|---|
| | 1045 | selectedRectNull = false; |
|---|
| | 1046 | OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, &selectedRect); |
|---|
| 1043 | 1047 | } |
|---|
| 1044 | 1048 | OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0); |
|---|
| … | … | |
| 1056 | 1060 | OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); |
|---|
| 1057 | 1061 | OS.ValidateRect (handle, null); |
|---|
| 1058 | | OS.InvalidateRect (handle, itemRect, true); |
|---|
| 1059 | | if (selectedRect !is null) { |
|---|
| 1060 | | OS.InvalidateRect (handle, selectedRect, true); |
|---|
| | 1062 | OS.InvalidateRect (handle, &itemRect, true); |
|---|
| | 1063 | if (!selectedRectNull) { |
|---|
| | 1064 | OS.InvalidateRect (handle, &selectedRect, true); |
|---|
| 1061 | 1065 | } |
|---|
| 1062 | 1066 | } |
|---|
| … | … | |
| 1157 | 1161 | * </ul> |
|---|
| 1158 | 1162 | */ |
|---|
| 1159 | | public void setItem (int index, String string) { |
|---|
| | 1163 | public void setItem (int index, char[] string) { |
|---|
| 1160 | 1164 | checkWidget (); |
|---|
| 1161 | 1165 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1182 | 1186 | * </ul> |
|---|
| 1183 | 1187 | */ |
|---|
| 1184 | | public void setItems (String [] items) { |
|---|
| | 1188 | public void setItems (char[] [] items) { |
|---|
| 1185 | 1189 | checkWidget (); |
|---|
| 1186 | 1190 | if (items is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1189 | 1193 | } |
|---|
| 1190 | 1194 | int oldProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); |
|---|
| 1191 | | OS.SetWindowLong (handle, OS.GWL_WNDPROC, ListProc); |
|---|
| | 1195 | OS.SetWindowLong (handle, OS.GWL_WNDPROC, cast(int) ListProc); |
|---|
| 1192 | 1196 | bool redraw = drawCount is 0 && OS.IsWindowVisible (handle); |
|---|
| 1193 | 1197 | if (redraw) { |
|---|
| 1194 | 1198 | OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); |
|---|
| 1195 | 1199 | } |
|---|
| 1196 | | RECT rect = null; |
|---|
| 1197 | | int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; |
|---|
| | 1200 | RECT rect; |
|---|
| | 1201 | HDC hDC; |
|---|
| | 1202 | HFONT oldFont, newFont; |
|---|
| | 1203 | int newWidth = 0; |
|---|
| 1198 | 1204 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1199 | | rect = new RECT (); |
|---|
| | 1205 | //rect = new RECT (); |
|---|
| 1200 | 1206 | hDC = OS.GetDC (handle); |
|---|
| 1201 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 1202 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 1207 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 1208 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 1203 | 1209 | OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0); |
|---|
| 1204 | 1210 | } |
|---|
| … | … | |
| 1209 | 1215 | int cp = getCodePage (); |
|---|
| 1210 | 1216 | while (index < length) { |
|---|
| 1211 | | String string = items [index]; |
|---|
| 1212 | | TCHAR buffer = new TCHAR (cp, string, true); |
|---|
| | 1217 | char[] string = items [index]; |
|---|
| | 1218 | TCHAR* buffer = StrToTCHARz (cp, string); |
|---|
| 1213 | 1219 | int result = OS.SendMessage (handle, OS.LB_ADDSTRING, 0, buffer); |
|---|
| 1214 | 1220 | if (result is OS.LB_ERR || result is OS.LB_ERRSPACE) break; |
|---|
| 1215 | 1221 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1216 | 1222 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 1217 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 1223 | OS.DrawText (hDC, buffer, -1, &rect, flags); |
|---|
| 1218 | 1224 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 1219 | 1225 | } |
|---|
| … | … | |
| 1221 | 1227 | } |
|---|
| 1222 | 1228 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1223 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 1229 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 1224 | 1230 | OS.ReleaseDC (handle, hDC); |
|---|
| 1225 | 1231 | OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0); |
|---|
| … | … | |
| 1244 | 1250 | void setScrollWidth () { |
|---|
| 1245 | 1251 | int newWidth = 0; |
|---|
| 1246 | | RECT rect = new RECT (); |
|---|
| 1247 | | int newFont, oldFont = 0; |
|---|
| 1248 | | int hDC = OS.GetDC (handle); |
|---|
| 1249 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 1250 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 1252 | RECT rect; |
|---|
| | 1253 | HFONT newFont, oldFont; |
|---|
| | 1254 | auto hDC = OS.GetDC (handle); |
|---|
| | 1255 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 1256 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 1251 | 1257 | int cp = getCodePage (); |
|---|
| 1252 | 1258 | int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); |
|---|
| … | … | |
| 1255 | 1261 | int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, i, 0); |
|---|
| 1256 | 1262 | if (length !is OS.LB_ERR) { |
|---|
| 1257 | | TCHAR buffer = new TCHAR (cp, length + 1); |
|---|
| 1258 | | int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer); |
|---|
| | 1263 | TCHAR[] buffer = NewTCHARs (cp, length + 1 ); |
|---|
| | 1264 | int result = OS.SendMessage (handle, OS.LB_GETTEXT, i, buffer.ptr); |
|---|
| 1259 | 1265 | if (result !is OS.LB_ERR) { |
|---|
| 1260 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 1266 | OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); |
|---|
| 1261 | 1267 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 1262 | 1268 | } |
|---|
| 1263 | 1269 | } |
|---|
| 1264 | 1270 | } |
|---|
| 1265 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 1271 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 1266 | 1272 | OS.ReleaseDC (handle, hDC); |
|---|
| 1267 | 1273 | OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, newWidth + INSET, 0); |
|---|
| 1268 | 1274 | } |
|---|
| 1269 | 1275 | |
|---|
| 1270 | | void setScrollWidth (TCHAR buffer, bool grow) { |
|---|
| 1271 | | RECT rect = new RECT (); |
|---|
| 1272 | | int newFont, oldFont = 0; |
|---|
| 1273 | | int hDC = OS.GetDC (handle); |
|---|
| 1274 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 1275 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 1276 | void setScrollWidth (TCHAR* buffer, bool grow) { |
|---|
| | 1277 | RECT rect; |
|---|
| | 1278 | HFONT newFont, oldFont; |
|---|
| | 1279 | auto hDC = OS.GetDC (handle); |
|---|
| | 1280 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 1281 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 1276 | 1282 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 1277 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| 1278 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 1283 | OS.DrawText (hDC, buffer, -1, &rect, flags); |
|---|
| | 1284 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 1279 | 1285 | OS.ReleaseDC (handle, hDC); |
|---|
| 1280 | 1286 | setScrollWidth (rect.right - rect.left, grow); |
|---|
| … | … | |
| 1349 | 1355 | * @see List#setSelection(int[]) |
|---|
| 1350 | 1356 | */ |
|---|
| 1351 | | public void setSelection (String [] items) { |
|---|
| | 1357 | public void setSelection (char[] [] items) { |
|---|
| 1352 | 1358 | checkWidget (); |
|---|
| 1353 | 1359 | if (items is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1357 | 1363 | int focusIndex = -1; |
|---|
| 1358 | 1364 | for (int i=length-1; i>=0; --i) { |
|---|
| 1359 | | String string = items [i]; |
|---|
| | 1365 | char[] string = items [i]; |
|---|
| 1360 | 1366 | int index = 0; |
|---|
| 1361 | 1367 | if (string !is null) { |
|---|
| … | … | |
| 1477 | 1483 | index = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); |
|---|
| 1478 | 1484 | } else { |
|---|
| 1479 | | int [] indices = new int [1]; |
|---|
| 1480 | | int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, indices); |
|---|
| 1481 | | index = indices [0]; |
|---|
| | 1485 | int indices; |
|---|
| | 1486 | int result = OS.SendMessage (handle, OS.LB_GETSELITEMS, 1, &indices); |
|---|
| | 1487 | index = indices; |
|---|
| 1482 | 1488 | if (result !is 1) index = -1; |
|---|
| 1483 | 1489 | } |
|---|
| … | … | |
| 1487 | 1493 | int height = OS.SendMessage (handle, OS.LB_GETITEMHEIGHT, 0, 0); |
|---|
| 1488 | 1494 | forceResize (); |
|---|
| 1489 | | RECT rect = new RECT (); |
|---|
| 1490 | | OS.GetClientRect (handle, rect); |
|---|
| | 1495 | RECT rect; |
|---|
| | 1496 | OS.GetClientRect (handle, &rect); |
|---|
| 1491 | 1497 | int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); |
|---|
| 1492 | 1498 | int visibleCount = Math.max (rect.bottom / height, 1); |
|---|
| … | … | |
| 1507 | 1513 | } |
|---|
| 1508 | 1514 | |
|---|
| 1509 | | override TCHAR windowClass () { |
|---|
| 1510 | | return ListClass; |
|---|
| | 1515 | override char[] windowClass () { |
|---|
| | 1516 | return TCHARsToStr( ListClass ); |
|---|
| 1511 | 1517 | } |
|---|
| 1512 | 1518 | |
|---|
| 1513 | 1519 | override int windowProc () { |
|---|
| 1514 | | return ListProc; |
|---|
| | 1520 | return cast(int) ListProc; |
|---|
| 1515 | 1521 | } |
|---|
| 1516 | 1522 | |
|---|
| … | … | |
| 1531 | 1537 | LRESULT result = super.WM_SIZE (wParam, lParam); |
|---|
| 1532 | 1538 | if (!isDisposed ()) { |
|---|
| 1533 | | SCROLLINFO info = new SCROLLINFO (); |
|---|
| | 1539 | SCROLLINFO info; |
|---|
| 1534 | 1540 | info.cbSize = SCROLLINFO.sizeof; |
|---|
| 1535 | 1541 | info.fMask = OS.SIF_POS; |
|---|
| 1536 | | if (OS.GetScrollInfo (handle, OS.SB_HORZ, info)) { |
|---|
| | 1542 | if (OS.GetScrollInfo (handle, OS.SB_HORZ, &info)) { |
|---|
| 1537 | 1543 | if (info.nPos !is 0) OS.InvalidateRect (handle, null, true); |
|---|
| 1538 | 1544 | } |
|---|
| … | … | |
| 1559 | 1565 | |
|---|
| 1560 | 1566 | } |
|---|
| 1561 | | ++/ |
|---|