Changeset 44:c913756e6950
- Timestamp:
- 02/01/08 19:51:46
(1 year ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
Combo
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r4 |
r44 |
|
| 1 | | /******************************************************************************* |
|---|
| | 1 | /******************************************************************************* |
|---|
| 2 | 2 | * Copyright (c) 2000, 2007 IBM Corporation and others. |
|---|
| 3 | 3 | * All rights reserved. This program and the accompanying materials |
|---|
| … | … | |
| 13 | 13 | import dwt.internal.Platform; |
|---|
| 14 | 14 | |
|---|
| | 15 | static import tango.stdc.string; |
|---|
| | 16 | |
|---|
| 15 | 17 | public class C : Platform { |
|---|
| 16 | | |
|---|
| | 18 | alias tango.stdc.string.memmove MoveMemory; |
|---|
| 17 | 19 | //public static final native void free (int /*long*/ ptr); |
|---|
| 18 | 20 | //public static final native int /*long*/ getenv (byte[] wcsToMbcs); |
|---|
| r41 |
r44 |
|
| 3847 | 3847 | version(ANSI) { |
|---|
| 3848 | 3848 | alias WINAPI.AddFontResourceExA AddFontResourceEx; |
|---|
| 3849 | | alias WINAPI.CallWindowProcA CallWindowProc; |
|---|
| | 3849 | alias STDWIN.CallWindowProcA CallWindowProc; |
|---|
| 3850 | 3850 | alias WINAPI.CharLowerA CharLower; |
|---|
| 3851 | 3851 | alias WINAPI.CharUpperA CharUpper; |
|---|
| … | … | |
| 3945 | 3945 | }else{ |
|---|
| 3946 | 3946 | alias WINAPI.AddFontResourceExW AddFontResourceEx; |
|---|
| 3947 | | alias WINAPI.CallWindowProcW CallWindowProc; |
|---|
| | 3947 | alias STDWIN.CallWindowProcW CallWindowProc; |
|---|
| 3948 | 3948 | alias WINAPI.CharLowerW CharLower; |
|---|
| 3949 | 3949 | alias WINAPI.CharUpperW CharUpper; |
|---|
| r41 |
r44 |
|
| 90 | 90 | * as int like Eclispe/SWT does. and we alias int to WPARAM_I. |
|---|
| 91 | 91 | */ |
|---|
| 92 | | alias LRESULT function(HWND, int, int, int) WNDPROC_I; |
|---|
| | 92 | alias LRESULT function(HWND, uint, uint, int) WNDPROC_I; |
|---|
| 93 | 93 | alias LRESULT function(int code, int wParam, LPARAM lParam) HOOKPROC_I; |
|---|
| 94 | 94 | |
|---|
| r43 |
r44 |
|
| 101 | 101 | } |
|---|
| 102 | 102 | |
|---|
| 103 | | private static extern(Windows) int CCHookFunc (HWND hdlg, int uiMsg, int lParam, int lpData) { |
|---|
| | 103 | private static extern(Windows) int CCHookFunc (HWND hdlg, uint uiMsg, uint lParam, int lpData) { |
|---|
| 104 | 104 | ColorDialog dlg = cast(ColorDialog)cast(void*)lpData; |
|---|
| 105 | 105 | return dlg.CCHookProc( hdlg, uiMsg, lParam ); |
|---|
| 106 | 106 | } |
|---|
| 107 | 107 | |
|---|
| 108 | | int CCHookProc (HWND hdlg, int uiMsg, int lParam ) { |
|---|
| | 108 | int CCHookProc (HWND hdlg, uint uiMsg, uint lParam ) { |
|---|
| 109 | 109 | switch (uiMsg) { |
|---|
| 110 | 110 | case OS.WM_INITDIALOG: { |
|---|
| r31 |
r44 |
|
| 15 | 15 | import dwt.widgets.Composite; |
|---|
| 16 | 16 | |
|---|
| 17 | | class Combo : Composite { |
|---|
| 18 | | } |
|---|
| 19 | | /++ |
|---|
| 20 | 17 | import dwt.DWT; |
|---|
| 21 | 18 | import dwt.DWTException; |
|---|
| … | … | |
| 26 | 23 | import dwt.graphics.Font; |
|---|
| 27 | 24 | import dwt.graphics.Point; |
|---|
| 28 | | import dwt.internal.Callback; |
|---|
| 29 | | import dwt.internal.win32.COMBOBOXINFO; |
|---|
| 30 | | import dwt.internal.win32.LRESULT; |
|---|
| 31 | | import dwt.internal.win32.MONITORINFO; |
|---|
| 32 | | import dwt.internal.win32.MSG; |
|---|
| 33 | 25 | import dwt.internal.win32.OS; |
|---|
| 34 | | import dwt.internal.win32.RECT; |
|---|
| 35 | | import dwt.internal.win32.TCHAR; |
|---|
| 36 | | import dwt.internal.win32.WNDCLASS; |
|---|
| | 26 | |
|---|
| | 27 | import dwt.widgets.TypedListener; |
|---|
| | 28 | import dwt.widgets.Event; |
|---|
| | 29 | import dwt.widgets.Composite; |
|---|
| | 30 | import dwt.widgets.Shell; |
|---|
| | 31 | import dwt.widgets.Display; |
|---|
| | 32 | |
|---|
| | 33 | import dwt.dwthelper.utils; |
|---|
| 37 | 34 | |
|---|
| 38 | 35 | /** |
|---|
| … | … | |
| 72 | 69 | */ |
|---|
| 73 | 70 | |
|---|
| 74 | | public class Combo extends Composite { |
|---|
| | 71 | public class Combo : Composite { |
|---|
| | 72 | |
|---|
| | 73 | alias Composite.sendKeyEvent sendKeyEvent; |
|---|
| | 74 | |
|---|
| | 75 | alias extern(Windows) int function( HWND, uint, uint, int ) TWindowProc; |
|---|
| | 76 | private static Combo pThis; |
|---|
| 75 | 77 | bool noSelection, ignoreDefaultSelection, ignoreCharacter, ignoreModify; |
|---|
| 76 | | int cbtHook, scrollWidth, visibleCount = 5; |
|---|
| | 78 | HHOOK cbtHook; |
|---|
| | 79 | int scrollWidth, visibleCount = 5; |
|---|
| 77 | 80 | |
|---|
| 78 | 81 | /** |
|---|
| … | … | |
| 80 | 83 | * that the text field in an instance of this class can hold |
|---|
| 81 | 84 | */ |
|---|
| 82 | | public static final int LIMIT; |
|---|
| | 85 | private static int LIMIT_ = 0; |
|---|
| 83 | 86 | |
|---|
| 84 | 87 | /* |
|---|
| … | … | |
| 87 | 90 | * to stop the compiler from inlining. |
|---|
| 88 | 91 | */ |
|---|
| 89 | | static { |
|---|
| 90 | | LIMIT = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF; |
|---|
| 91 | | } |
|---|
| 92 | | |
|---|
| | 92 | public static int LIMIT(){ |
|---|
| | 93 | if( LIMIT_ is 0 ){ |
|---|
| | 94 | synchronized { |
|---|
| | 95 | LIMIT_ = OS.IsWinNT ? 0x7FFFFFFF : 0x7FFF; |
|---|
| | 96 | } |
|---|
| | 97 | } |
|---|
| | 98 | return LIMIT_; |
|---|
| | 99 | } |
|---|
| 93 | 100 | /* |
|---|
| 94 | 101 | * These are the undocumented control id's for the children of |
|---|
| … | … | |
| 97 | 104 | * been the same since Windows 3.0). |
|---|
| 98 | 105 | */ |
|---|
| 99 | | static final int CBID_LIST = 1000; |
|---|
| 100 | | static final int CBID_EDIT = 1001; |
|---|
| 101 | | static /*final*/ int EditProc, ListProc; |
|---|
| 102 | | |
|---|
| 103 | | static final int ComboProc; |
|---|
| 104 | | static final TCHAR ComboClass = new TCHAR (0, "COMBOBOX", true); |
|---|
| 105 | | static { |
|---|
| 106 | | WNDCLASS lpWndClass = new WNDCLASS (); |
|---|
| 107 | | OS.GetClassInfo (0, ComboClass, lpWndClass); |
|---|
| | 106 | static const int CBID_LIST = 1000; |
|---|
| | 107 | static const int CBID_EDIT = 1001; |
|---|
| | 108 | static /*final*/ TWindowProc EditProc, ListProc; |
|---|
| | 109 | |
|---|
| | 110 | static const TWindowProc ComboProc; |
|---|
| | 111 | static const TCHAR* ComboClass = "COMBOBOX\0"; |
|---|
| | 112 | |
|---|
| | 113 | static this() { |
|---|
| | 114 | WNDCLASS lpWndClass; |
|---|
| | 115 | OS.GetClassInfo (null, ComboClass, &lpWndClass); |
|---|
| 108 | 116 | ComboProc = lpWndClass.lpfnWndProc; |
|---|
| 109 | 117 | } |
|---|
| | 118 | |
|---|
| 110 | 119 | |
|---|
| 111 | 120 | /** |
|---|
| … | … | |
| 139 | 148 | * @see Widget#getStyle |
|---|
| 140 | 149 | */ |
|---|
| 141 | | public Combo (Composite parent, int style) { |
|---|
| | 150 | public this (Composite parent, int style) { |
|---|
| 142 | 151 | super (parent, checkStyle (style)); |
|---|
| 143 | 152 | /* This code is intentionally commented */ |
|---|
| … | … | |
| 161 | 170 | * @see #add(String,int) |
|---|
| 162 | 171 | */ |
|---|
| 163 | | public void add (String string) { |
|---|
| | 172 | public void add (char[] string) { |
|---|
| 164 | 173 | checkWidget (); |
|---|
| 165 | 174 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 166 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| 167 | | int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer); |
|---|
| | 175 | auto buffer = StrToTCHARs( string ); |
|---|
| | 176 | int result = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer.ptr ); |
|---|
| 168 | 177 | if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| 169 | 178 | if (result is OS.CB_ERRSPACE) error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| … | … | |
| 194 | 203 | * @see #add(String) |
|---|
| 195 | 204 | */ |
|---|
| 196 | | public void add (String string, int index) { |
|---|
| | 205 | public void add (char[] string, int index) { |
|---|
| 197 | 206 | checkWidget (); |
|---|
| 198 | 207 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 201 | 210 | error (DWT.ERROR_INVALID_RANGE); |
|---|
| 202 | 211 | } |
|---|
| 203 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| 204 | | int result = OS.SendMessage (handle, OS.CB_INSERTSTRING, index, buffer); |
|---|
| | 212 | auto buffer = StrToTCHARs( string ); |
|---|
| | 213 | int result = OS.SendMessage (handle, OS.CB_INSERTSTRING, index, buffer.ptr); |
|---|
| 205 | 214 | if (result is OS.CB_ERRSPACE || result is OS.CB_ERR) { |
|---|
| 206 | 215 | error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| … | … | |
| 295 | 304 | } |
|---|
| 296 | 305 | |
|---|
| 297 | | int callWindowProc (int hwnd, int msg, int wParam, int lParam) { |
|---|
| 298 | | if (handle is 0) return 0; |
|---|
| | 306 | override LRESULT callWindowProc (HWND hwnd, int msg, int wParam, int lParam) { |
|---|
| | 307 | if (handle is null) return LRESULT.ZERO; |
|---|
| 299 | 308 | if (hwnd is handle) { |
|---|
| 300 | | return OS.CallWindowProc (ComboProc, hwnd, msg, wParam, lParam); |
|---|
| 301 | | } |
|---|
| 302 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 309 | return cast(LRESULT) OS.CallWindowProc( ComboProc, hwnd, msg, wParam, lParam); |
|---|
| | 310 | } |
|---|
| | 311 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 303 | 312 | if (hwnd is hwndText) { |
|---|
| 304 | | return OS.CallWindowProc (EditProc, hwnd, msg, wParam, lParam); |
|---|
| 305 | | } |
|---|
| 306 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 313 | return cast(LRESULT) OS.CallWindowProc( EditProc, hwnd, msg, wParam, lParam); |
|---|
| | 314 | } |
|---|
| | 315 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 307 | 316 | if (hwnd is hwndList) { |
|---|
| 308 | | return OS.CallWindowProc (ListProc, hwnd, msg, wParam, lParam); |
|---|
| 309 | | } |
|---|
| 310 | | return OS.DefWindowProc (hwnd, msg, wParam, lParam); |
|---|
| | 317 | return cast(LRESULT) OS.CallWindowProc( ListProc, hwnd, msg, wParam, lParam); |
|---|
| | 318 | } |
|---|
| | 319 | return cast(LRESULT) OS.DefWindowProc (hwnd, msg, wParam, lParam); |
|---|
| | 320 | } |
|---|
| | 321 | |
|---|
| | 322 | private static extern(Windows) int CBTFunc (int nCode, int wParam, int lParam) { |
|---|
| | 323 | return pThis.CBTProc( nCode, wParam, lParam ); |
|---|
| 311 | 324 | } |
|---|
| 312 | 325 | |
|---|
| 313 | 326 | int CBTProc (int nCode, int wParam, int lParam) { |
|---|
| 314 | 327 | if (nCode is OS.HCBT_CREATEWND) { |
|---|
| 315 | | TCHAR buffer = new TCHAR (0, 128); |
|---|
| 316 | | OS.GetClassName (wParam, buffer, buffer.length ()); |
|---|
| 317 | | String className = buffer.toString (0, buffer.strlen ()); |
|---|
| 318 | | if (className.equals ("Edit") || className.equals ("EDIT")) { //$NON-NLS-1$ //$NON-NLS-2$ |
|---|
| 319 | | int bits = OS.GetWindowLong (wParam, OS.GWL_STYLE); |
|---|
| 320 | | OS.SetWindowLong (wParam, OS.GWL_STYLE, bits & ~OS.ES_NOHIDESEL); |
|---|
| | 328 | TCHAR[128] buffer = 0; |
|---|
| | 329 | OS.GetClassName (cast(HANDLE)wParam, buffer.ptr, buffer.length ); |
|---|
| | 330 | char[] className = TCHARzToStr(buffer.ptr); |
|---|
| | 331 | if (className=="Edit" || className=="EDIT") { //$NON-NLS-1$ //$NON-NLS-2$ |
|---|
| | 332 | int bits = OS.GetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE); |
|---|
| | 333 | OS.SetWindowLong (cast(HANDLE)wParam, OS.GWL_STYLE, bits & ~OS.ES_NOHIDESEL); |
|---|
| 321 | 334 | } |
|---|
| 322 | 335 | } |
|---|
| … | … | |
| 324 | 337 | } |
|---|
| 325 | 338 | |
|---|
| 326 | | bool checkHandle (int hwnd) { |
|---|
| | 339 | bool checkHandle (HWND hwnd) { |
|---|
| 327 | 340 | return hwnd is handle || hwnd is OS.GetDlgItem (handle, CBID_EDIT) || hwnd is OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 328 | 341 | } |
|---|
| … | … | |
| 386 | 399 | int width = 0, height = 0; |
|---|
| 387 | 400 | if (wHint is DWT.DEFAULT) { |
|---|
| 388 | | int newFont, oldFont = 0; |
|---|
| 389 | | int hDC = OS.GetDC (handle); |
|---|
| 390 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 391 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 401 | HFONT newFont, oldFont; |
|---|
| | 402 | auto hDC = OS.GetDC (handle); |
|---|
| | 403 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 404 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 392 | 405 | int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); |
|---|
| 393 | | RECT rect = new RECT (); |
|---|
| | 406 | RECT rect; |
|---|
| 394 | 407 | int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX; |
|---|
| 395 | 408 | if ((style & DWT.READ_ONLY) is 0) flags |= OS.DT_EDITCONTROL; |
|---|
| 396 | | int length = OS.GetWindowTextLength (handle); |
|---|
| | 409 | int length_ = OS.GetWindowTextLength (handle); |
|---|
| 397 | 410 | int cp = getCodePage (); |
|---|
| 398 | | TCHAR buffer = new TCHAR (cp, length + 1); |
|---|
| 399 | | OS.GetWindowText (handle, buffer, length + 1); |
|---|
| 400 | | OS.DrawText (hDC, buffer, length, rect, flags); |
|---|
| | 411 | TCHAR[] buffer = new TCHAR[ length_ + 1]; |
|---|
| | 412 | buffer[] = 0; |
|---|
| | 413 | OS.GetWindowText (handle, buffer.ptr, length_ + 1); |
|---|
| | 414 | OS.DrawText (hDC, buffer.ptr, length_, &rect, flags); |
|---|
| 401 | 415 | width = Math.max (width, rect.right - rect.left); |
|---|
| 402 | 416 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| … | … | |
| 404 | 418 | } else { |
|---|
| 405 | 419 | for (int i=0; i<count; i++) { |
|---|
| 406 | | length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0); |
|---|
| 407 | | if (length !is OS.CB_ERR) { |
|---|
| 408 | | if (length + 1 > buffer.length ()) buffer = new TCHAR (cp, length + 1); |
|---|
| 409 | | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, i, buffer); |
|---|
| | 420 | length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, i, 0); |
|---|
| | 421 | if (length_ !is OS.CB_ERR) { |
|---|
| | 422 | if (length_ + 1 > buffer.length ) buffer = new TCHAR[ length_ + 1 ], buffer[] =0; |
|---|
| | 423 | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, i, buffer.ptr); |
|---|
| 410 | 424 | if (result !is OS.CB_ERR) { |
|---|
| 411 | | OS.DrawText (hDC, buffer, length, rect, flags); |
|---|
| | 425 | OS.DrawText (hDC, buffer.ptr, length_, &rect, flags); |
|---|
| 412 | 426 | width = Math.max (width, rect.right - rect.left); |
|---|
| 413 | 427 | } |
|---|
| … | … | |
| 415 | 429 | } |
|---|
| 416 | 430 | } |
|---|
| 417 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 431 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 418 | 432 | OS.ReleaseDC (handle, hDC); |
|---|
| 419 | 433 | } |
|---|
| … | … | |
| 432 | 446 | width += 8; |
|---|
| 433 | 447 | } else { |
|---|
| 434 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 435 | | if (hwndText !is 0) { |
|---|
| | 448 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 449 | if (hwndText !is null) { |
|---|
| 436 | 450 | int margins = OS.SendMessage (hwndText, OS.EM_GETMARGINS, 0, 0); |
|---|
| 437 | 451 | int marginWidth = (margins & 0xFFFF) + ((margins >> 16) & 0xFFFF); |
|---|
| … | … | |
| 439 | 453 | } |
|---|
| 440 | 454 | } |
|---|
| 441 | | COMBOBOXINFO pcbi = new COMBOBOXINFO (); |
|---|
| | 455 | COMBOBOXINFO pcbi; |
|---|
| 442 | 456 | pcbi.cbSize = COMBOBOXINFO.sizeof; |
|---|
| 443 | | if (((style & DWT.SIMPLE) is 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, pcbi)) { |
|---|
| 444 | | width += pcbi.itemLeft + (pcbi.buttonRight - pcbi.buttonLeft); |
|---|
| 445 | | height = (pcbi.buttonBottom - pcbi.buttonTop) + pcbi.buttonTop * 2; |
|---|
| | 457 | if (((style & DWT.SIMPLE) is 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, &pcbi)) { |
|---|
| | 458 | width += pcbi.rcItem.left + (pcbi.rcButton.right - pcbi.rcButton.left); |
|---|
| | 459 | height = (pcbi.rcButton.bottom - pcbi.rcButton.top) + pcbi.rcButton.top * 2; |
|---|
| 446 | 460 | } else { |
|---|
| 447 | 461 | int border = OS.GetSystemMetrics (OS.SM_CXEDGE); |
|---|
| … | … | |
| 493 | 507 | } else { |
|---|
| 494 | 508 | int threadId = OS.GetCurrentThreadId (); |
|---|
| 495 | | Callback cbtCallback = new Callback (this, "CBTProc", 3); //$NON-NLS-1$ |
|---|
| 496 | | int cbtProc = cbtCallback.getAddress (); |
|---|
| 497 | | if (cbtProc is 0) error (DWT.ERROR_NO_MORE_CALLBACKS); |
|---|
| 498 | | cbtHook = OS.SetWindowsHookEx (OS.WH_CBT, cbtProc, 0, threadId); |
|---|
| | 509 | //Callback cbtCallback = new Callback (this, "CBTProc", 3); //$NON-NLS-1$ |
|---|
| | 510 | //int cbtProc = cbtCallback.getAddress (); |
|---|
| | 511 | //if (cbtProc is 0) error (DWT.ERROR_NO_MORE_CALLBACKS); |
|---|
| | 512 | pThis = this; |
|---|
| | 513 | cbtHook = OS.SetWindowsHookEx (OS.WH_CBT, &CBTFunc, null, threadId); |
|---|
| 499 | 514 | super.createHandle (); |
|---|
| 500 | | if (cbtHook !is 0) OS.UnhookWindowsHookEx (cbtHook); |
|---|
| 501 | | cbtHook = 0; |
|---|
| 502 | | cbtCallback.dispose (); |
|---|
| | 515 | if (cbtHook !is null) OS.UnhookWindowsHookEx (cbtHook); |
|---|
| | 516 | pThis = null; |
|---|
| | 517 | //cbtHook = 0; |
|---|
| | 518 | //cbtCallback.dispose (); |
|---|
| 503 | 519 | } |
|---|
| 504 | 520 | state &= ~(CANVAS | THEME_BACKGROUND); |
|---|
| 505 | 521 | |
|---|
| 506 | 522 | /* Get the text and list window procs */ |
|---|
| 507 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 508 | | if (hwndText !is 0 && EditProc is 0) { |
|---|
| 509 | | EditProc = OS.GetWindowLong (hwndText, OS.GWL_WNDPROC); |
|---|
| 510 | | } |
|---|
| 511 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 512 | | if (hwndList !is 0 && ListProc is 0) { |
|---|
| 513 | | ListProc = OS.GetWindowLong (hwndList, OS.GWL_WNDPROC); |
|---|
| | 523 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 524 | if (hwndText !is null && EditProc is null) { |
|---|
| | 525 | EditProc = cast(TWindowProc) OS.GetWindowLong (hwndText, OS.GWL_WNDPROC); |
|---|
| | 526 | } |
|---|
| | 527 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 528 | if (hwndList !is null && ListProc is null) { |
|---|
| | 529 | ListProc = cast(TWindowProc) OS.GetWindowLong (hwndList, OS.GWL_WNDPROC); |
|---|
| 514 | 530 | } |
|---|
| 515 | 531 | |
|---|
| … | … | |
| 522 | 538 | if ((style & DWT.SIMPLE) !is 0) { |
|---|
| 523 | 539 | int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE; |
|---|
| 524 | | SetWindowPos (handle, 0, 0, 0, 0x3FFF, 0x3FFF, flags); |
|---|
| 525 | | SetWindowPos (handle, 0, 0, 0, 0, 0, flags); |
|---|
| | 540 | SetWindowPos (handle, null, 0, 0, 0x3FFF, 0x3FFF, flags); |
|---|
| | 541 | SetWindowPos (handle, null, 0, 0, 0, 0, flags); |
|---|
| 526 | 542 | } |
|---|
| 527 | 543 | } |
|---|
| … | … | |
| 553 | 569 | void deregister () { |
|---|
| 554 | 570 | super.deregister (); |
|---|
| 555 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 556 | | if (hwndText !is 0) display.removeControl (hwndText); |
|---|
| 557 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 558 | | if (hwndList !is 0) display.removeControl (hwndList); |
|---|
| | 571 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 572 | if (hwndText !is null) display.removeControl (hwndText); |
|---|
| | 573 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 574 | if (hwndList !is null) display.removeControl (hwndList); |
|---|
| 559 | 575 | } |
|---|
| 560 | 576 | |
|---|
| … | … | |
| 601 | 617 | } |
|---|
| 602 | 618 | |
|---|
| 603 | | bool dragDetect (int hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { |
|---|
| | 619 | bool dragDetect (HWND hwnd, int x, int y, bool filter, bool [] detect, bool [] consume) { |
|---|
| 604 | 620 | if (filter && (style & DWT.READ_ONLY) is 0) { |
|---|
| 605 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 606 | | if (hwndText !is 0) { |
|---|
| 607 | | int [] start = new int [1], end = new int [1]; |
|---|
| 608 | | OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end); |
|---|
| 609 | | if (start [0] !is end [0]) { |
|---|
| | 621 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 622 | if (hwndText !is null) { |
|---|
| | 623 | int start, end; |
|---|
| | 624 | OS.SendMessage (handle, OS.CB_GETEDITSEL, &start, &end); |
|---|
| | 625 | if (start !is end ) { |
|---|
| 610 | 626 | int lParam = (x & 0xFFFF) | ((y << 16) & 0xFFFF0000); |
|---|
| 611 | 627 | int position = OS.SendMessage (hwndText, OS.EM_CHARFROMPOS, 0, lParam) & 0xFFFF; |
|---|
| 612 | | if (start [0] <= position && position < end [0]) { |
|---|
| | 628 | if (start <= position && position < end ) { |
|---|
| 613 | 629 | if (super.dragDetect (hwnd, x, y, filter, detect, consume)) { |
|---|
| 614 | 630 | if (consume !is null) consume [0] = true; |
|---|
| … | … | |
| 639 | 655 | * </ul> |
|---|
| 640 | 656 | */ |
|---|
| 641 | | public String getItem (int index) { |
|---|
| 642 | | checkWidget (); |
|---|
| 643 | | int length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); |
|---|
| 644 | | if (length !is OS.CB_ERR) { |
|---|
| 645 | | TCHAR buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 646 | | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer); |
|---|
| 647 | | if (result !is OS.CB_ERR) return buffer.toString (0, length); |
|---|
| | 657 | public char[] getItem (int index) { |
|---|
| | 658 | checkWidget (); |
|---|
| | 659 | int length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); |
|---|
| | 660 | if (length_ !is OS.CB_ERR) { |
|---|
| | 661 | TCHAR[] buffer = new TCHAR[ length_ + 1]; |
|---|
| | 662 | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer.ptr); |
|---|
| | 663 | if (result !is OS.CB_ERR) return TCHARzToStr( buffer.ptr ); |
|---|
| 648 | 664 | } |
|---|
| 649 | 665 | int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); |
|---|
| … | … | |
| 704 | 720 | * </ul> |
|---|
| 705 | 721 | */ |
|---|
| 706 | | public String [] getItems () { |
|---|
| | 722 | public char[] [] getItems () { |
|---|
| 707 | 723 | checkWidget (); |
|---|
| 708 | 724 | int count = getItemCount (); |
|---|
| 709 | | String [] result = new String [count]; |
|---|
| | 725 | char[] [] result = new char[] [count]; |
|---|
| 710 | 726 | for (int i=0; i<count; i++) result [i] = getItem (i); |
|---|
| 711 | 727 | return result; |
|---|
| … | … | |
| 739 | 755 | } |
|---|
| 740 | 756 | |
|---|
| 741 | | String getNameText () { |
|---|
| | 757 | char[] getNameText () { |
|---|
| 742 | 758 | return getText (); |
|---|
| 743 | 759 | } |
|---|
| … | … | |
| 784 | 800 | return new Point (0, OS.GetWindowTextLength (handle)); |
|---|
| 785 | 801 | } |
|---|
| 786 | | int [] start = new int [1], end = new int [1]; |
|---|
| 787 | | OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end); |
|---|
| | 802 | int start, end; |
|---|
| | 803 | OS.SendMessage (handle, OS.CB_GETEDITSEL, &start, &end); |
|---|
| 788 | 804 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 789 | | start [0] = mbcsToWcsPos (start [0]); |
|---|
| 790 | | end [0] = mbcsToWcsPos (end [0]); |
|---|
| 791 | | } |
|---|
| 792 | | return new Point (start [0], end [0]); |
|---|
| | 805 | start = mbcsToWcsPos (start); |
|---|
| | 806 | end = mbcsToWcsPos (end); |
|---|
| | 807 | } |
|---|
| | 808 | return new Point (start, end); |
|---|
| 793 | 809 | } |
|---|
| 794 | 810 | |
|---|
| … | … | |
| 822 | 838 | * </ul> |
|---|
| 823 | 839 | */ |
|---|
| 824 | | public String getText () { |
|---|
| 825 | | checkWidget (); |
|---|
| 826 | | int length = OS.GetWindowTextLength (handle); |
|---|
| 827 | | if (length is 0) return ""; |
|---|
| 828 | | TCHAR buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 829 | | OS.GetWindowText (handle, buffer, length + 1); |
|---|
| 830 | | return buffer.toString (0, length); |
|---|
| | 840 | public char[] getText () { |
|---|
| | 841 | checkWidget (); |
|---|
| | 842 | int length_ = OS.GetWindowTextLength (handle); |
|---|
| | 843 | if (length_ is 0) return ""; |
|---|
| | 844 | TCHAR[] buffer = new TCHAR[ length_ + 1]; |
|---|
| | 845 | OS.GetWindowText (handle, buffer.ptr, length_ + 1); |
|---|
| | 846 | return TCHARzToStr( buffer.ptr ); |
|---|
| 831 | 847 | } |
|---|
| 832 | 848 | |
|---|
| … | … | |
| 843 | 859 | public int getTextHeight () { |
|---|
| 844 | 860 | checkWidget (); |
|---|
| 845 | | COMBOBOXINFO pcbi = new COMBOBOXINFO (); |
|---|
| | 861 | COMBOBOXINFO pcbi; |
|---|
| 846 | 862 | pcbi.cbSize = COMBOBOXINFO.sizeof; |
|---|
| 847 | | if (((style & DWT.SIMPLE) is 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, pcbi)) { |
|---|
| 848 | | return (pcbi.buttonBottom - pcbi.buttonTop) + pcbi.buttonTop * 2; |
|---|
| | 863 | if (((style & DWT.SIMPLE) is 0) && !OS.IsWinCE && OS.GetComboBoxInfo (handle, &pcbi)) { |
|---|
| | 864 | return (pcbi.rcButton.bottom - pcbi.rcButton.top) + pcbi.rcButton.top * 2; |
|---|
| 849 | 865 | } |
|---|
| 850 | 866 | int result = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0); |
|---|
| … | … | |
| 870 | 886 | public int getTextLimit () { |
|---|
| 871 | 887 | checkWidget (); |
|---|
| 872 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 873 | | if (hwndText is 0) return LIMIT; |
|---|
| | 888 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 889 | if (hwndText is null) return LIMIT; |
|---|
| 874 | 890 | return OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0) & 0x7FFFFFFF; |
|---|
| 875 | 891 | } |
|---|
| … | … | |
| 898 | 914 | |
|---|
| 899 | 915 | bool hasFocus () { |
|---|
| 900 | | int hwndFocus = OS.GetFocus (); |
|---|
| | 916 | auto hwndFocus = OS.GetFocus (); |
|---|
| 901 | 917 | if (hwndFocus is handle) return true; |
|---|
| 902 | | if (hwndFocus is 0) return false; |
|---|
| 903 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 918 | if (hwndFocus is null) return false; |
|---|
| | 919 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 904 | 920 | if (hwndFocus is hwndText) return true; |
|---|
| 905 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 921 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 906 | 922 | if (hwndFocus is hwndList) return true; |
|---|
| 907 | 923 | return false; |
|---|
| … | … | |
| 925 | 941 | * </ul> |
|---|
| 926 | 942 | */ |
|---|
| 927 | | public int indexOf (String string) { |
|---|
| | 943 | public int indexOf (char[] string) { |
|---|
| 928 | 944 | return indexOf (string, 0); |
|---|
| 929 | 945 | } |
|---|
| … | … | |
| 948 | 964 | * </ul> |
|---|
| 949 | 965 | */ |
|---|
| 950 | | public int indexOf (String string, int start) { |
|---|
| | 966 | public int indexOf (char[] string, int start) { |
|---|
| 951 | 967 | checkWidget (); |
|---|
| 952 | 968 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 958 | 974 | * to search the combo, an item at a time. |
|---|
| 959 | 975 | */ |
|---|
| 960 | | if (string.length () is 0) { |
|---|
| | 976 | if (string.length is 0) { |
|---|
| 961 | 977 | int count = getItemCount (); |
|---|
| 962 | 978 | for (int i=start; i<count; i++) { |
|---|
| 963 | | if (string.equals (getItem (i))) return i; |
|---|
| | 979 | if (string==/*eq*/getItem (i)) return i; |
|---|
| 964 | 980 | } |
|---|
| 965 | 981 | return -1; |
|---|
| … | … | |
| 970 | 986 | if (!(0 <= start && start < count)) return -1; |
|---|
| 971 | 987 | int index = start - 1, last = 0; |
|---|
| 972 | | TCHAR buffer = new TCHAR (getCodePage (), string, true); |
|---|
| | 988 | TCHAR* buffer = StrToTCHARz( string ); |
|---|
| 973 | 989 | do { |
|---|
| 974 | 990 | index = OS.SendMessage (handle, OS.CB_FINDSTRINGEXACT, last = index, buffer); |
|---|
| 975 | 991 | if (index is OS.CB_ERR || index <= last) return -1; |
|---|
| 976 | | } while (!string.equals (getItem (index))); |
|---|
| | 992 | } while (string!=/*eq*/getItem (index)); |
|---|
| 977 | 993 | return index; |
|---|
| 978 | 994 | } |
|---|
| … | … | |
| 981 | 997 | if (mbcsPos <= 0) return 0; |
|---|
| 982 | 998 | if (OS.IsUnicode) return mbcsPos; |
|---|
| 983 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 984 | | if (hwndText is 0) return mbcsPos; |
|---|
| | 999 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1000 | if (hwndText is null) return mbcsPos; |
|---|
| 985 | 1001 | int mbcsSize = OS.GetWindowTextLengthA (hwndText); |
|---|
| 986 | 1002 | if (mbcsSize is 0) return 0; |
|---|
| 987 | 1003 | if (mbcsPos >= mbcsSize) return mbcsSize; |
|---|
| 988 | | byte [] buffer = new byte [mbcsSize + 1]; |
|---|
| 989 | | OS.GetWindowTextA (hwndText, buffer, mbcsSize + 1); |
|---|
| 990 | | return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer, mbcsPos, null, 0); |
|---|
| | 1004 | char [] buffer = new char [mbcsSize + 1]; |
|---|
| | 1005 | buffer[] = 0; |
|---|
| | 1006 | OS.GetWindowTextA (hwndText, buffer.ptr, mbcsSize + 1); |
|---|
| | 1007 | return OS.MultiByteToWideChar (getCodePage (), OS.MB_PRECOMPOSED, buffer.ptr, mbcsPos, null, 0); |
|---|
| 991 | 1008 | } |
|---|
| 992 | 1009 | |
|---|
| … | … | |
| 1013 | 1030 | void register () { |
|---|
| 1014 | 1031 | super.register (); |
|---|
| 1015 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 1016 | | if (hwndText !is 0) display.addControl (hwndText, this); |
|---|
| 1017 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 1018 | | if (hwndList !is 0) display.addControl (hwndList, this); |
|---|
| | 1032 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1033 | if (hwndText !is null) display.addControl (hwndText, this); |
|---|
| | 1034 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 1035 | if (hwndList !is null) display.addControl (hwndList, this); |
|---|
| 1019 | 1036 | } |
|---|
| 1020 | 1037 | |
|---|
| … | … | |
| 1039 | 1056 | |
|---|
| 1040 | 1057 | void remove (int index, bool notify) { |
|---|
| 1041 | | TCHAR buffer = null; |
|---|
| | 1058 | TCHAR[] buffer = null; |
|---|
| 1042 | 1059 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1043 | | int length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); |
|---|
| 1044 | | if (length is OS.CB_ERR) { |
|---|
| | 1060 | int length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); |
|---|
| | 1061 | if (length_ is OS.CB_ERR) { |
|---|
| 1045 | 1062 | int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); |
|---|
| 1046 | 1063 | if (0 <= index && index < count) error (DWT.ERROR_ITEM_NOT_REMOVED); |
|---|
| 1047 | 1064 | error (DWT.ERROR_INVALID_RANGE); |
|---|
| 1048 | 1065 | } |
|---|
| 1049 | | buffer = new TCHAR (getCodePage (), length + 1); |
|---|
| 1050 | | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer); |
|---|
| | 1066 | buffer = new TCHAR[ length_ + 1]; |
|---|
| | 1067 | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer.ptr); |
|---|
| 1051 | 1068 | if (result is OS.CB_ERR) { |
|---|
| 1052 | 1069 | int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); |
|---|
| … | … | |
| 1055 | 1072 | } |
|---|
| 1056 | 1073 | } |
|---|
| 1057 | | int length = OS.GetWindowTextLength (handle); |
|---|
| | 1074 | int length_ = OS.GetWindowTextLength (handle); |
|---|
| 1058 | 1075 | int code = OS.SendMessage (handle, OS.CB_DELETESTRING, index, 0); |
|---|
| 1059 | 1076 | if (code is OS.CB_ERR) { |
|---|
| … | … | |
| 1063 | 1080 | } |
|---|
| 1064 | 1081 | if ((style & DWT.H_SCROLL) !is 0) setScrollWidth (buffer, true); |
|---|
| 1065 | | if (notify && length !is OS.GetWindowTextLength (handle)) { |
|---|
| | 1082 | if (notify && length_ !is OS.GetWindowTextLength (handle)) { |
|---|
| 1066 | 1083 | sendEvent (DWT.Modify); |
|---|
| 1067 | 1084 | if (isDisposed ()) return; |
|---|
| … | … | |
| 1104 | 1121 | } |
|---|
| 1105 | 1122 | int textLength = OS.GetWindowTextLength (handle); |
|---|
| 1106 | | RECT rect = null; |
|---|
| 1107 | | int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; |
|---|
| | 1123 | RECT rect; |
|---|
| | 1124 | HDC hDC; |
|---|
| | 1125 | HFONT oldFont, newFont; |
|---|
| | 1126 | int newWidth = 0; |
|---|
| 1108 | 1127 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1109 | | rect = new RECT (); |
|---|
| | 1128 | //rect = new RECT (); |
|---|
| 1110 | 1129 | hDC = OS.GetDC (handle); |
|---|
| 1111 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 1112 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 1130 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 1131 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 1113 | 1132 | } |
|---|
| 1114 | 1133 | int cp = getCodePage (); |
|---|
| 1115 | 1134 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 1116 | 1135 | for (int i=start; i<=end; i++) { |
|---|
| 1117 | | TCHAR buffer = null; |
|---|
| | 1136 | TCHAR[] buffer = null; |
|---|
| 1118 | 1137 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1119 | | int length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, start, 0); |
|---|
| 1120 | | if (length is OS.CB_ERR) break; |
|---|
| 1121 | | buffer = new TCHAR (cp, length + 1); |
|---|
| 1122 | | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, start, buffer); |
|---|
| | 1138 | int length_ = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, start, 0); |
|---|
| | 1139 | if (length_ is OS.CB_ERR) break; |
|---|
| | 1140 | buffer = new TCHAR[ length_ + 1]; |
|---|
| | 1141 | int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, start, buffer.ptr); |
|---|
| 1123 | 1142 | if (result is OS.CB_ERR) break; |
|---|
| 1124 | 1143 | } |
|---|
| … | … | |
| 1126 | 1145 | if (result is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_REMOVED); |
|---|
| 1127 | 1146 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1128 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 1147 | OS.DrawText (hDC, buffer.ptr, -1, &rect, flags); |
|---|
| 1129 | 1148 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 1130 | 1149 | } |
|---|
| 1131 | 1150 | } |
|---|
| 1132 | 1151 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1133 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 1152 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 1134 | 1153 | OS.ReleaseDC (handle, hDC); |
|---|
| 1135 | 1154 | setScrollWidth (newWidth, false); |
|---|
| … | … | |
| 1168 | 1187 | * </ul> |
|---|
| 1169 | 1188 | */ |
|---|
| 1170 | | public void remove (String string) { |
|---|
| | 1189 | public void remove (char[] string) { |
|---|
| 1171 | 1190 | checkWidget (); |
|---|
| 1172 | 1191 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1304 | 1323 | |
|---|
| 1305 | 1324 | /* Verify the character */ |
|---|
| 1306 | | String oldText = ""; |
|---|
| 1307 | | int [] start = new int [1], end = new int [1]; |
|---|
| 1308 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 1309 | | if (hwndText is 0) return true; |
|---|
| | 1325 | char[] oldText = ""; |
|---|
| | 1326 | int start, end; |
|---|
| | 1327 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1328 | if (hwndText is null) return true; |
|---|
| 1310 | 1329 | OS.SendMessage (hwndText, OS.EM_GETSEL, start, end); |
|---|
| 1311 | 1330 | switch (key) { |
|---|
| 1312 | 1331 | case 0x08: /* Bs */ |
|---|
| 1313 | | if (start [0] is end [0]) { |
|---|
| 1314 | | if (start [0] is 0) return true; |
|---|
| 1315 | | start [0] = start [0] - 1; |
|---|
| | 1332 | if (start is end ) { |
|---|
| | 1333 | if (start is 0) return true; |
|---|
| | 1334 | start = start - 1; |
|---|
| 1316 | 1335 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 1317 | | int [] newStart = new int [1], newEnd = new int [1]; |
|---|
| 1318 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| | 1336 | int newStart, newEnd; |
|---|
| | 1337 | OS.SendMessage (hwndText, OS.EM_SETSEL, start , end ); |
|---|
| 1319 | 1338 | OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd); |
|---|
| 1320 | | if (start [0] !is newStart [0]) start [0] = start [0] - 1; |
|---|
| | 1339 | if (start !is newStart ) start = start - 1; |
|---|
| 1321 | 1340 | } |
|---|
| 1322 | | start [0] = Math.max (start [0], 0); |
|---|
| | 1341 | start = Math.max (start , 0); |
|---|
| 1323 | 1342 | } |
|---|
| 1324 | 1343 | break; |
|---|
| 1325 | 1344 | case 0x7F: /* Del */ |
|---|
| 1326 | | if (start [0] is end [0]) { |
|---|
| 1327 | | int length = OS.GetWindowTextLength (hwndText); |
|---|
| 1328 | | if (start [0] is length) return true; |
|---|
| 1329 | | end [0] = end [0] + 1; |
|---|
| | 1345 | if (start is end ) { |
|---|
| | 1346 | int length_ = OS.GetWindowTextLength (hwndText); |
|---|
| | 1347 | if (start is length_) return true; |
|---|
| | 1348 | end = end + 1; |
|---|
| 1330 | 1349 | if (!OS.IsUnicode && OS.IsDBLocale) { |
|---|
| 1331 | | int [] newStart = new int [1], newEnd = new int [1]; |
|---|
| 1332 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| | 1350 | int newStart, newEnd; |
|---|
| | 1351 | OS.SendMessage (hwndText, OS.EM_SETSEL, start , end ); |
|---|
| 1333 | 1352 | OS.SendMessage (hwndText, OS.EM_GETSEL, newStart, newEnd); |
|---|
| 1334 | | if (end [0] !is newEnd [0]) end [0] = end [0] + 1; |
|---|
| | 1353 | if (end !is newEnd ) end = end + 1; |
|---|
| 1335 | 1354 | } |
|---|
| 1336 | | end [0] = Math.min (end [0], length); |
|---|
| | 1355 | end = Math.min (end , length_); |
|---|
| 1337 | 1356 | } |
|---|
| 1338 | 1357 | break; |
|---|
| … | … | |
| 1341 | 1360 | default: /* Tab and other characters */ |
|---|
| 1342 | 1361 | if (key !is '\t' && key < 0x20) return true; |
|---|
| 1343 | | oldText = new String (new char [] {key}); |
|---|
| | 1362 | oldText = [key]; |
|---|
| 1344 | 1363 | break; |
|---|
| 1345 | 1364 | } |
|---|
| 1346 | | String newText = verifyText (oldText, start [0], end [0], event); |
|---|
| | 1365 | char[] newText = verifyText (oldText, start, end, event); |
|---|
| 1347 | 1366 | if (newText is null) return false; |
|---|
| 1348 | 1367 | if (newText is oldText) return true; |
|---|
| 1349 | | TCHAR buffer = new TCHAR (getCodePage (), newText, true); |
|---|
| 1350 | | OS.SendMessage (hwndText, OS.EM_SETSEL, start [0], end [0]); |
|---|
| | 1368 | TCHAR* buffer = StrToTCHARz( newText ); |
|---|
| | 1369 | OS.SendMessage (hwndText, OS.EM_SETSEL, start, end); |
|---|
| 1351 | 1370 | OS.SendMessage (hwndText, OS.EM_REPLACESEL, 0, buffer); |
|---|
| 1352 | 1371 | return false; |
|---|
| … | … | |
| 1378 | 1397 | } |
|---|
| 1379 | 1398 | |
|---|
| 1380 | | void setBackgroundImage (int hBitmap) { |
|---|
| | 1399 | void setBackgroundImage (HBITMAP hBitmap) { |
|---|
| 1381 | 1400 | super.setBackgroundImage (hBitmap); |
|---|
| 1382 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 1383 | | if (hwndText !is 0) OS.InvalidateRect (hwndText, null, true); |
|---|
| 1384 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 1385 | | if (hwndList !is 0) OS.InvalidateRect (hwndList, null, true); |
|---|
| | 1401 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1402 | if (hwndText !is null) OS.InvalidateRect (hwndText, null, true); |
|---|
| | 1403 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 1404 | if (hwndList !is null) OS.InvalidateRect (hwndList, null, true); |
|---|
| 1386 | 1405 | } |
|---|
| 1387 | 1406 | |
|---|
| 1388 | 1407 | void setBackgroundPixel (int pixel) { |
|---|
| 1389 | 1408 | super.setBackgroundPixel (pixel); |
|---|
| 1390 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 1391 | | if (hwndText !is 0) OS.InvalidateRect (hwndText, null, true); |
|---|
| 1392 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 1393 | | if (hwndList !is 0) OS.InvalidateRect (hwndList, null, true); |
|---|
| | 1409 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1410 | if (hwndText !is null) OS.InvalidateRect (hwndText, null, true); |
|---|
| | 1411 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 1412 | if (hwndList !is null) OS.InvalidateRect (hwndList, null, true); |
|---|
| 1394 | 1413 | } |
|---|
| 1395 | 1414 | |
|---|
| … | … | |
| 1427 | 1446 | * combo box is zero, then do not set SWP_NOSIZE. |
|---|
| 1428 | 1447 | */ |
|---|
| 1429 | | RECT rect = new RECT (); |
|---|
| 1430 | | OS.GetWindowRect (handle, rect); |
|---|
| | 1448 | RECT rect; |
|---|
| | 1449 | OS.GetWindowRect (handle, &rect); |
|---|
| 1431 | 1450 | if (rect.right - rect.left !is 0) { |
|---|
| 1432 | | if (OS.SendMessage (handle, OS.CB_GETDROPPEDCONTROLRECT, 0, rect) !is 0) { |
|---|
| | 1451 | if (OS.SendMessage (handle, OS.CB_GETDROPPEDCONTROLRECT, 0, &rect) !is 0) { |
|---|
| 1433 | 1452 | int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top; |
|---|
| 1434 | 1453 | if (oldWidth is width && oldHeight is height) flags |= OS.SWP_NOSIZE; |
|---|
| 1435 | 1454 | } |
|---|
| 1436 | 1455 | } |
|---|
| 1437 | | SetWindowPos (handle, 0, x, y, width, height, flags); |
|---|
| | 1456 | SetWindowPos (handle, null, x, y, width, height, flags); |
|---|
| 1438 | 1457 | } else { |
|---|
| 1439 | 1458 | super.setBounds (x, y, width, height, flags); |
|---|
| … | … | |
| 1449 | 1468 | void setForegroundPixel (int pixel) { |
|---|
| 1450 | 1469 | super.setForegroundPixel (pixel); |
|---|
| 1451 | | int hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| 1452 | | if (hwndText !is 0) OS.InvalidateRect (hwndText, null, true); |
|---|
| 1453 | | int hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| 1454 | | if (hwndList !is 0) OS.InvalidateRect (hwndList, null, true); |
|---|
| | 1470 | auto hwndText = OS.GetDlgItem (handle, CBID_EDIT); |
|---|
| | 1471 | if (hwndText !is null) OS.InvalidateRect (hwndText, null, true); |
|---|
| | 1472 | auto hwndList = OS.GetDlgItem (handle, CBID_LIST); |
|---|
| | 1473 | if (hwndList !is null) OS.InvalidateRect (hwndList, null, true); |
|---|
| 1455 | 1474 | } |
|---|
| 1456 | 1475 | |
|---|
| … | … | |
| 1471 | 1490 | * </ul> |
|---|
| 1472 | 1491 | */ |
|---|
| 1473 | | public void setItem (int index, String string) { |
|---|
| | 1492 | public void setItem (int index, char[] string) { |
|---|
| 1474 | 1493 | checkWidget (); |
|---|
| 1475 | 1494 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1495 | 1514 | * </ul> |
|---|
| 1496 | 1515 | */ |
|---|
| 1497 | | public void setItems (String [] items) { |
|---|
| | 1516 | public void setItems (char[] [] items) { |
|---|
| 1498 | 1517 | checkWidget (); |
|---|
| 1499 | 1518 | if (items is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| … | … | |
| 1501 | 1520 | if (items [i] is null) error (DWT.ERROR_INVALID_ARGUMENT); |
|---|
| 1502 | 1521 | } |
|---|
| 1503 | | RECT rect = null; |
|---|
| 1504 | | int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; |
|---|
| | 1522 | RECT rect; |
|---|
| | 1523 | HDC hDC; |
|---|
| | 1524 | HFONT oldFont, newFont; |
|---|
| | 1525 | int newWidth = 0; |
|---|
| 1505 | 1526 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1506 | | rect = new RECT (); |
|---|
| | 1527 | //rect = new RECT (); |
|---|
| 1507 | 1528 | hDC = OS.GetDC (handle); |
|---|
| 1508 | | newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| 1509 | | if (newFont !is 0) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| | 1529 | newFont = cast(HFONT) OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); |
|---|
| | 1530 | if (newFont !is null) oldFont = OS.SelectObject (hDC, newFont); |
|---|
| 1510 | 1531 | setScrollWidth (0); |
|---|
| 1511 | 1532 | } |
|---|
| … | … | |
| 1513 | 1534 | int codePage = getCodePage (); |
|---|
| 1514 | 1535 | for (int i=0; i<items.length; i++) { |
|---|
| 1515 | | String string = items [i]; |
|---|
| 1516 | | TCHAR buffer = new TCHAR (codePage, string, true); |
|---|
| | 1536 | char[] string = items [i]; |
|---|
| | 1537 | TCHAR* buffer = StrToTCHARz( string ); |
|---|
| 1517 | 1538 | int code = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer); |
|---|
| 1518 | 1539 | if (code is OS.CB_ERR) error (DWT.ERROR_ITEM_NOT_ADDED); |
|---|
| … | … | |
| 1520 | 1541 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1521 | 1542 | int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; |
|---|
| 1522 | | OS.DrawText (hDC, buffer, -1, rect, flags); |
|---|
| | 1543 | OS.DrawText (hDC, buffer, -1, &rect, flags); |
|---|
| 1523 | 1544 | newWidth = Math.max (newWidth, rect.right - rect.left); |
|---|
| 1524 | 1545 | } |
|---|
| 1525 | 1546 | } |
|---|
| 1526 | 1547 | if ((style & DWT.H_SCROLL) !is 0) { |
|---|
| 1527 | | if (newFont !is 0) OS.SelectObject (hDC, oldFont); |
|---|
| | 1548 | if (newFont !is null) OS.SelectObject (hDC, oldFont); |
|---|
| 1528 | 1549 | OS.ReleaseDC (handle, hDC); |
|---|
| 1529 | 1550 | setScrollWidth (newWidth + 3); |
|---|
| … | … | |
| 1587 | 1608 | } |
|---|
| 1588 | 1609 | OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits); |
|---|
| 1589 | | int hwndText = 0, hwndList = 0; |
|---|
| 1590 | | COMBOBOXINFO pcbi = new COMBOBOXINFO (); |
|---|
| | 1610 | HWND hwndText, hwndList; |
|---|
| | 1611 | COMBOBOXINFO pcbi; |
|---|
| 1591 | 1612 | pcbi.cbSize = COMBOBOXINFO.sizeof; |
|---|
| 1592 | | if (OS.GetComboBoxInfo (handle, pcbi)) { |
|---|
| | 1613 | if (OS.GetComboBoxInfo (handle, &pcbi)) { |
|---|
| 1593 | 1614 | hwndText = pcbi.hwndItem; |
|---|
| 1594 | 1615 | hwndList = pcbi.hwndList; |
|---|
| 1595 | 1616 | } |
|---|
| 1596 | | if (hwndText !is 0) { |
|---|
| | 1617 | if (hwndText !is null) { |
|---|
| 1597 | 1618 | int bits1 = OS.GetWindowLong (hwndText, OS.GWL_EXSTYLE); |
|---|
| 1598 | 1619 | int bits2 = OS.GetWindowLong (hwndText, OS.GWL_STYLE); |
|---|
| … | … | |
| 1613 | 1634 | * temporarily shrinking and then growing the width and height. |
|---|
| 1614 | 1635 | */ |
|---|
| 1615 | | RECT rect = new RECT (); |
|---|
| 1616 | | OS.GetWindowRect (hwndText, rect); |
|---|
| | 1636 | RECT rect; |
|---|
| | 1637 | OS.GetWindowRect (hwndText, &rect); |
|---|
| 1617 | 1638 | int width = rect.right - rect.left, height = rect.bottom - rect.top; |
|---|
| 1618 | | OS.GetWindowRect (handle, rect); |
|---|
| | 1639 | OS.GetWindowRect (handle, &rect); |
|---|
| 1619 | 1640 | int widthCombo = rect.right - rect.left, heightCombo = rect.bottom - rect.top; |
|---|
| 1620 | 1641 | int uFlags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE; |
|---|
| 1621 | | SetWindowPos (hwndText, 0, 0, 0, width - 1, height - 1, uFlags); |
|---|
| 1622 | | SetWindowPos (handle, 0, 0, 0, widthCombo - 1, heightCombo - 1, uFlags); |
|---|
| 1623 | | SetWindowPos (hwndText, 0, 0, 0, width, height, uFlags); |
|---|
| 1624 | | SetWindowPos (handle, 0, 0, 0, widthCombo, heightCombo, uFlags); |
|---|
| | 1642 | SetWindowPos (hwndText, null, 0, 0, width - 1, height - 1, uFlags); |
|---|
| | 1643 | SetWindowPos (handle, n |
|---|