Changeset 59:dc7db4338dbe
- Timestamp:
- 02/04/08 07:39:10
(10 months ago)
- Author:
- Frank Benoit <benoit@tionex.de>
- branch:
- default
- Message:
MenuItem?
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r57 |
r59 |
|
| 144 | 144 | public void printStackTrace () { |
|---|
| 145 | 145 | Stderr.formatln( "stacktrace follows (if feature compiled in)" ); |
|---|
| 146 | | foreach( msg; this ){ |
|---|
| | 146 | foreach( msg; info ){ |
|---|
| 147 | 147 | Stderr.formatln( "{}", msg ); |
|---|
| 148 | 148 | } |
|---|
| 149 | 149 | if ( throwable !is null) { |
|---|
| 150 | 150 | Stderr.formatln ("*** Stack trace of contained error ***"); //$NON-NLS-1$ |
|---|
| 151 | | foreach( msg; throwable ){ |
|---|
| | 151 | foreach( msg; throwable.info ){ |
|---|
| 152 | 152 | Stderr.formatln( "{}", msg ); |
|---|
| 153 | 153 | } |
|---|
| r57 |
r59 |
|
| 135 | 135 | public void printStackTrace () { |
|---|
| 136 | 136 | Stderr.formatln( "stacktrace follows (if feature compiled in)" ); |
|---|
| 137 | | foreach( msg; this ){ |
|---|
| | 137 | foreach( msg; info ){ |
|---|
| 138 | 138 | Stderr.formatln( "{}", msg ); |
|---|
| 139 | 139 | } |
|---|
| 140 | 140 | if ( throwable !is null) { |
|---|
| 141 | 141 | Stderr.formatln ("*** Stack trace of contained exception ***"); //$NON-NLS-1$ |
|---|
| 142 | | foreach( msg; throwable ){ |
|---|
| | 142 | foreach( msg; throwable.info ){ |
|---|
| 143 | 143 | Stderr.formatln( "{}", msg ); |
|---|
| 144 | 144 | } |
|---|
| r53 |
r59 |
|
| 201 | 201 | void breakRun(StyleItem run) { |
|---|
| 202 | 202 | if (run.psla !is null) return; |
|---|
| 203 | | wchar[] chars = StrToWCHARs( segmentsText[ run.start .. run.start + run.length ] ); |
|---|
| | 203 | wchar[] chars = StrToWCHARs( 0, segmentsText[ run.start .. run.start + run.length ] ); |
|---|
| 204 | 204 | auto hHeap = OS.GetProcessHeap(); |
|---|
| 205 | 205 | run.psla = cast(SCRIPT_LOGATTR*)OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, SCRIPT_LOGATTR.sizeof * chars.length); |
|---|
| r56 |
r59 |
|
| 4804 | 4804 | } |
|---|
| 4805 | 4805 | |
|---|
| 4806 | | public wchar[] StrToWCHARs(uint codepage , char[] sc) { |
|---|
| 4807 | | return StrToWCHARs( sc ); |
|---|
| 4808 | | } |
|---|
| 4809 | | public wchar[] StrToWCHARs(char[] sc) { |
|---|
| | 4806 | public wchar[] StrToWCHARs(uint codepage , char[] sc, bool terminated = false ) { |
|---|
| | 4807 | return StrToWCHARs( sc, terminated ); |
|---|
| | 4808 | } |
|---|
| | 4809 | public wchar[] StrToWCHARs(char[] sc, bool terminated = false ) { |
|---|
| 4810 | 4810 | wchar[] ret; |
|---|
| 4811 | 4811 | try{ |
|---|
| … | … | |
| 4815 | 4815 | ret = ""; |
|---|
| 4816 | 4816 | } |
|---|
| 4817 | | |
|---|
| | 4817 | if( terminated ){ |
|---|
| | 4818 | ret ~= \0; |
|---|
| | 4819 | } |
|---|
| 4818 | 4820 | return ret; |
|---|
| 4819 | 4821 | } |
|---|
| … | … | |
| 4824 | 4826 | |
|---|
| 4825 | 4827 | public wchar* StrToWCHARz(char[] sc, uint* length = null ) { |
|---|
| 4826 | | return toString16z( StrToWCHARs(sc)); |
|---|
| | 4828 | return StrToWCHARs(sc, true ).ptr; |
|---|
| 4827 | 4829 | } |
|---|
| 4828 | 4830 | |
|---|
| r56 |
r59 |
|
| 13 | 13 | module dwt.widgets.MenuItem; |
|---|
| 14 | 14 | |
|---|
| 15 | | import dwt.widgets.Item; |
|---|
| 16 | | import dwt.widgets.Widget; |
|---|
| 17 | | import dwt.widgets.Menu; |
|---|
| 18 | | import dwt.widgets.Decorations; |
|---|
| 19 | | import dwt.internal.win32.OS; |
|---|
| 20 | | |
|---|
| 21 | | class MenuItem : Item { |
|---|
| 22 | | Menu parent, menu; |
|---|
| 23 | | HBITMAP hBitmap; |
|---|
| 24 | | int accelerator; |
|---|
| 25 | | int id; |
|---|
| 26 | | public this (Widget parent, int style) { |
|---|
| 27 | | super (parent, style); |
|---|
| 28 | | } |
|---|
| 29 | | public bool getEnabled () ; |
|---|
| 30 | | public bool isEnabled () ; |
|---|
| 31 | | LRESULT wmCommandChild (int wParam, int lParam) ; |
|---|
| 32 | | LRESULT wmDrawChild (int wParam, int lParam) ; |
|---|
| 33 | | LRESULT wmMeasureChild (int wParam, int lParam) ; |
|---|
| 34 | | void fillAccel (ACCEL* accel) ; |
|---|
| 35 | | int widgetStyle () ; |
|---|
| 36 | | void fixMenus (Decorations newParent) ; |
|---|
| 37 | | void releaseMenu () ; |
|---|
| 38 | | } |
|---|
| 39 | | /++ |
|---|
| 40 | 15 | import dwt.DWT; |
|---|
| 41 | 16 | import dwt.DWTException; |
|---|
| … | … | |
| 48 | 23 | import dwt.graphics.Image; |
|---|
| 49 | 24 | import dwt.graphics.Rectangle; |
|---|
| 50 | | import dwt.internal.win32.ACCEL; |
|---|
| 51 | | import dwt.internal.win32.DRAWITEMSTRUCT; |
|---|
| 52 | | import dwt.internal.win32.LRESULT; |
|---|
| 53 | | import dwt.internal.win32.MEASUREITEMSTRUCT; |
|---|
| 54 | | import dwt.internal.win32.MENUBARINFO; |
|---|
| 55 | | import dwt.internal.win32.MENUINFO; |
|---|
| 56 | | import dwt.internal.win32.MENUITEMINFO; |
|---|
| 57 | 25 | import dwt.internal.win32.OS; |
|---|
| 58 | | import dwt.internal.win32.RECT; |
|---|
| 59 | | import dwt.internal.win32.TBBUTTONINFO; |
|---|
| 60 | | import dwt.internal.win32.TCHAR; |
|---|
| | 26 | |
|---|
| | 27 | import dwt.widgets.Item; |
|---|
| | 28 | import dwt.widgets.Widget; |
|---|
| | 29 | import dwt.widgets.Menu; |
|---|
| | 30 | import dwt.widgets.Decorations; |
|---|
| | 31 | import dwt.widgets.TypedListener; |
|---|
| | 32 | import dwt.widgets.Display; |
|---|
| | 33 | import dwt.widgets.Event; |
|---|
| | 34 | |
|---|
| | 35 | import dwt.dwthelper.utils; |
|---|
| 61 | 36 | |
|---|
| 62 | 37 | /** |
|---|
| … | … | |
| 77 | 52 | */ |
|---|
| 78 | 53 | |
|---|
| 79 | | public class MenuItem extends Item { |
|---|
| | 54 | public class MenuItem : Item { |
|---|
| 80 | 55 | Menu parent, menu; |
|---|
| 81 | | int hBitmap, id, accelerator; |
|---|
| | 56 | HBITMAP hBitmap; |
|---|
| | 57 | int id, accelerator; |
|---|
| 82 | 58 | /* |
|---|
| 83 | 59 | * Feature in Windows. On Windows 98, it is necessary |
|---|
| … | … | |
| 88 | 64 | * everywhere but on Windows 98. |
|---|
| 89 | 65 | */ |
|---|
| 90 | | final static int MARGIN_WIDTH = OS.IsWin95 ? 2 : 1; |
|---|
| 91 | | final static int MARGIN_HEIGHT = OS.IsWin95 ? 2 : 1; |
|---|
| | 66 | const static int MARGIN_WIDTH; |
|---|
| | 67 | const static int MARGIN_HEIGHT; |
|---|
| | 68 | static this() { |
|---|
| | 69 | MARGIN_WIDTH = OS.IsWin95 ? 2 : 1; |
|---|
| | 70 | MARGIN_HEIGHT = OS.IsWin95 ? 2 : 1; |
|---|
| | 71 | } |
|---|
| 92 | 72 | |
|---|
| 93 | 73 | /** |
|---|
| … | … | |
| 125 | 105 | * @see Widget#getStyle |
|---|
| 126 | 106 | */ |
|---|
| 127 | | public MenuItem (Menu parent, int style) { |
|---|
| | 107 | public this (Menu parent, int style) { |
|---|
| 128 | 108 | super (parent, checkStyle (style)); |
|---|
| 129 | 109 | this.parent = parent; |
|---|
| … | … | |
| 167 | 147 | * @see Widget#getStyle |
|---|
| 168 | 148 | */ |
|---|
| 169 | | public MenuItem (Menu parent, int style, int index) { |
|---|
| | 149 | public this (Menu parent, int style, int index) { |
|---|
| 170 | 150 | super (parent, checkStyle (style)); |
|---|
| 171 | 151 | this.parent = parent; |
|---|
| … | … | |
| 173 | 153 | } |
|---|
| 174 | 154 | |
|---|
| 175 | | MenuItem (Menu parent, Menu menu, int style, int index) { |
|---|
| | 155 | this (Menu parent, Menu menu, int style, int index) { |
|---|
| 176 | 156 | super (parent, checkStyle (style)); |
|---|
| 177 | 157 | this.parent = parent; |
|---|
| … | … | |
| 284 | 264 | int fVirt = OS.FVIRTKEY; |
|---|
| 285 | 265 | int key = accelerator & DWT.KEY_MASK; |
|---|
| 286 | | int vKey = Display.untranslateKey (key); |
|---|
| | 266 | auto vKey = Display.untranslateKey (key); |
|---|
| 287 | 267 | if (vKey !is 0) { |
|---|
| 288 | 268 | key = vKey; |
|---|
| … | … | |
| 298 | 278 | case 127: key = OS.VK_DELETE; break; |
|---|
| 299 | 279 | default: { |
|---|
| 300 | | key = Display.wcsToMbcs ((char) key); |
|---|
| | 280 | key = Display.wcsToMbcs (cast(char) key); |
|---|
| 301 | 281 | if (key is 0) return; |
|---|
| 302 | | if (OS.IsWinCE) { |
|---|
| 303 | | key = OS.CharUpper ((short) key); |
|---|
| | 282 | static if (OS.IsWinCE) { |
|---|
| | 283 | key = cast(int) OS.CharUpper (cast(TCHAR*) key); |
|---|
| 304 | 284 | } else { |
|---|
| 305 | | vKey = OS.VkKeyScan ((short) key) & 0xFF; |
|---|
| | 285 | vKey = OS.VkKeyScan (cast(TCHAR) key) & 0xFF; |
|---|
| 306 | 286 | if (vKey is -1) { |
|---|
| 307 | 287 | fVirt = 0; |
|---|
| … | … | |
| 313 | 293 | } |
|---|
| 314 | 294 | } |
|---|
| 315 | | accel.key = (short) key; |
|---|
| 316 | | accel.cmd = (short) id; |
|---|
| 317 | | accel.fVirt = (byte) fVirt; |
|---|
| | 295 | accel.key = cast(short) key; |
|---|
| | 296 | accel.cmd = cast(short) id; |
|---|
| | 297 | accel.fVirt = cast(byte) fVirt; |
|---|
| 318 | 298 | if ((accelerator & DWT.ALT) !is 0) accel.fVirt |= OS.FALT; |
|---|
| 319 | 299 | if ((accelerator & DWT.SHIFT) !is 0) accel.fVirt |= OS.FSHIFT; |
|---|
| … | … | |
| 368 | 348 | return new Rectangle (0, 0, 0, 0); |
|---|
| 369 | 349 | } |
|---|
| 370 | | int hwndShell = shell.handle; |
|---|
| 371 | | MENUBARINFO info1 = new MENUBARINFO (); |
|---|
| | 350 | auto hwndShell = shell.handle; |
|---|
| | 351 | MENUBARINFO info1; |
|---|
| 372 | 352 | info1.cbSize = MENUBARINFO.sizeof; |
|---|
| 373 | | if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, 1, info1)) { |
|---|
| | 353 | if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, 1, &info1)) { |
|---|
| 374 | 354 | return new Rectangle (0, 0, 0, 0); |
|---|
| 375 | 355 | } |
|---|
| 376 | | MENUBARINFO info2 = new MENUBARINFO (); |
|---|
| | 356 | MENUBARINFO info2; |
|---|
| 377 | 357 | info2.cbSize = MENUBARINFO.sizeof; |
|---|
| 378 | | if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, index + 1, info2)) { |
|---|
| | 358 | if (!OS.GetMenuBarInfo (hwndShell, OS.OBJID_MENU, index + 1, &info2)) { |
|---|
| 379 | 359 | return new Rectangle (0, 0, 0, 0); |
|---|
| 380 | 360 | } |
|---|
| 381 | | int x = info2.left - info1.left; |
|---|
| 382 | | int y = info2.top - info1.top; |
|---|
| 383 | | int width = info2.right - info2.left; |
|---|
| 384 | | int height = info2.bottom - info2.top; |
|---|
| | 361 | int x = info2.rcBar.left - info1.rcBar.left; |
|---|
| | 362 | int y = info2.rcBar.top - info1.rcBar.top; |
|---|
| | 363 | int width = info2.rcBar.right - info2.rcBar.left; |
|---|
| | 364 | int height = info2.rcBar.bottom - info2.rcBar.top; |
|---|
| 385 | 365 | return new Rectangle (x, y, width, height); |
|---|
| 386 | 366 | } else { |
|---|
| 387 | | int hMenu = parent.handle; |
|---|
| 388 | | RECT rect1 = new RECT (); |
|---|
| 389 | | if (!OS.GetMenuItemRect (0, hMenu, 0, rect1)) { |
|---|
| | 367 | auto hMenu = parent.handle; |
|---|
| | 368 | RECT rect1; |
|---|
| | 369 | if (!OS.GetMenuItemRect (null, hMenu, 0, &rect1)) { |
|---|
| 390 | 370 | return new Rectangle (0, 0, 0, 0); |
|---|
| 391 | 371 | } |
|---|
| 392 | | RECT rect2 = new RECT (); |
|---|
| 393 | | if (!OS.GetMenuItemRect (0, hMenu, index, rect2)) { |
|---|
| | 372 | RECT rect2; |
|---|
| | 373 | if (!OS.GetMenuItemRect (null, hMenu, index, &rect2)) { |
|---|
| 394 | 374 | return new Rectangle (0, 0, 0, 0); |
|---|
| 395 | 375 | } |
|---|
| … | … | |
| 419 | 399 | public bool getEnabled () { |
|---|
| 420 | 400 | checkWidget (); |
|---|
| 421 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) { |
|---|
| 422 | | int hwndCB = parent.hwndCB; |
|---|
| 423 | | TBBUTTONINFO info = new TBBUTTONINFO (); |
|---|
| | 401 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) { |
|---|
| | 402 | auto hwndCB = parent.hwndCB; |
|---|
| | 403 | TBBUTTONINFO info; |
|---|
| 424 | 404 | info.cbSize = TBBUTTONINFO.sizeof; |
|---|
| 425 | 405 | info.dwMask = OS.TBIF_STATE; |
|---|
| 426 | | OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, info); |
|---|
| | 406 | OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, &info); |
|---|
| 427 | 407 | return (info.fsState & OS.TBSTATE_ENABLED) !is 0; |
|---|
| 428 | 408 | } |
|---|
| 429 | | int hMenu = parent.handle; |
|---|
| 430 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 409 | auto hMenu = parent.handle; |
|---|
| | 410 | MENUITEMINFO info; |
|---|
| 431 | 411 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 432 | 412 | info.fMask = OS.MIIM_STATE; |
|---|
| … | … | |
| 435 | 415 | int index = parent.indexOf (this); |
|---|
| 436 | 416 | if (index is -1) error (DWT.ERROR_CANNOT_GET_ENABLED); |
|---|
| 437 | | success = OS.GetMenuItemInfo (hMenu, index, true, info); |
|---|
| | 417 | success = cast(bool) OS.GetMenuItemInfo (hMenu, index, true, &info); |
|---|
| 438 | 418 | } else { |
|---|
| 439 | | success = OS.GetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 419 | success = cast(bool) OS.GetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 440 | 420 | } |
|---|
| 441 | 421 | if (!success) error (DWT.ERROR_CANNOT_GET_ENABLED); |
|---|
| … | … | |
| 462 | 442 | } |
|---|
| 463 | 443 | |
|---|
| 464 | | override String getNameText () { |
|---|
| | 444 | override char[] getNameText () { |
|---|
| 465 | 445 | if ((style & DWT.SEPARATOR) !is 0) return "|"; |
|---|
| 466 | 446 | return super.getNameText (); |
|---|
| … | … | |
| 499 | 479 | checkWidget (); |
|---|
| 500 | 480 | if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return false; |
|---|
| 501 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) return false; |
|---|
| 502 | | int hMenu = parent.handle; |
|---|
| 503 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 481 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) return false; |
|---|
| | 482 | auto hMenu = parent.handle; |
|---|
| | 483 | MENUITEMINFO info; |
|---|
| 504 | 484 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 505 | 485 | info.fMask = OS.MIIM_STATE; |
|---|
| 506 | | bool success = OS.GetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 486 | bool success = cast(bool) OS.GetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 507 | 487 | if (!success) error (DWT.ERROR_CANNOT_GET_SELECTION); |
|---|
| 508 | | return (info.fState & OS.MFS_CHECKED) !is0; |
|---|
| | 488 | return (info.fState & OS.MFS_CHECKED) !is 0; |
|---|
| 509 | 489 | } |
|---|
| 510 | 490 | |
|---|
| … | … | |
| 543 | 523 | |
|---|
| 544 | 524 | void releaseMenu () { |
|---|
| 545 | | if (!OS.IsSP) setMenu (null); |
|---|
| | 525 | if (!OS.IsSP_) setMenu (null); |
|---|
| 546 | 526 | menu = null; |
|---|
| 547 | 527 | } |
|---|
| … | … | |
| 555 | 535 | override void releaseWidget () { |
|---|
| 556 | 536 | super.releaseWidget (); |
|---|
| 557 | | if (hBitmap !is 0) OS.DeleteObject (hBitmap); |
|---|
| 558 | | hBitmap = 0; |
|---|
| | 537 | if (hBitmap !is null) OS.DeleteObject (hBitmap); |
|---|
| | 538 | hBitmap = null; |
|---|
| 559 | 539 | if (accelerator !is 0) { |
|---|
| 560 | 540 | parent.destroyAccelerators (); |
|---|
| … | … | |
| 684 | 664 | public void setEnabled (bool enabled) { |
|---|
| 685 | 665 | checkWidget (); |
|---|
| 686 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) { |
|---|
| 687 | | int hwndCB = parent.hwndCB; |
|---|
| 688 | | TBBUTTONINFO info = new TBBUTTONINFO (); |
|---|
| | 666 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) { |
|---|
| | 667 | auto hwndCB = parent.hwndCB; |
|---|
| | 668 | TBBUTTONINFO info; |
|---|
| 689 | 669 | info.cbSize = TBBUTTONINFO.sizeof; |
|---|
| 690 | 670 | info.dwMask = OS.TBIF_STATE; |
|---|
| 691 | | OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, info); |
|---|
| | 671 | OS.SendMessage (hwndCB, OS.TB_GETBUTTONINFO, id, &info); |
|---|
| 692 | 672 | info.fsState &= ~OS.TBSTATE_ENABLED; |
|---|
| 693 | 673 | if (enabled) info.fsState |= OS.TBSTATE_ENABLED; |
|---|
| 694 | | OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info); |
|---|
| | 674 | OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, &info); |
|---|
| 695 | 675 | } else { |
|---|
| 696 | | int hMenu = parent.handle; |
|---|
| 697 | | if (OS.IsWinCE) { |
|---|
| | 676 | auto hMenu = parent.handle; |
|---|
| | 677 | static if (OS.IsWinCE) { |
|---|
| 698 | 678 | int index = parent.indexOf (this); |
|---|
| 699 | 679 | if (index is -1) return; |
|---|
| … | … | |
| 701 | 681 | OS.EnableMenuItem (hMenu, index, uEnable); |
|---|
| 702 | 682 | } else { |
|---|
| 703 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 683 | MENUITEMINFO info; |
|---|
| 704 | 684 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 705 | 685 | info.fMask = OS.MIIM_STATE; |
|---|
| 706 | | bool success = OS.GetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 686 | bool success = cast(bool) OS.GetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 707 | 687 | if (!success) error (DWT.ERROR_CANNOT_SET_ENABLED); |
|---|
| 708 | 688 | int bits = OS.MFS_DISABLED | OS.MFS_GRAYED; |
|---|
| … | … | |
| 714 | 694 | info.fState |= bits; |
|---|
| 715 | 695 | } |
|---|
| 716 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 696 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 717 | 697 | if (!success) { |
|---|
| 718 | 698 | /* |
|---|
| … | … | |
| 753 | 733 | if ((style & DWT.SEPARATOR) !is 0) return; |
|---|
| 754 | 734 | super.setImage (image); |
|---|
| 755 | | if (OS.IsWinCE) { |
|---|
| 756 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) { |
|---|
| | 735 | static if (OS.IsWinCE) { |
|---|
| | 736 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) { |
|---|
| 757 | 737 | int hwndCB = parent.hwndCB; |
|---|
| 758 | | TBBUTTONINFO info = new TBBUTTONINFO (); |
|---|
| | 738 | TBBUTTONINFO info; |
|---|
| 759 | 739 | info.cbSize = TBBUTTONINFO.sizeof; |
|---|
| 760 | 740 | info.dwMask = OS.TBIF_IMAGE; |
|---|
| 761 | 741 | info.iImage = parent.imageIndex (image); |
|---|
| 762 | | OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info); |
|---|
| | 742 | OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, &info); |
|---|
| 763 | 743 | } |
|---|
| 764 | 744 | return; |
|---|
| 765 | 745 | } |
|---|
| 766 | 746 | if (OS.WIN32_VERSION < OS.VERSION (4, 10)) return; |
|---|
| 767 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 747 | MENUITEMINFO info; |
|---|
| 768 | 748 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 769 | 749 | info.fMask = OS.MIIM_BITMAP; |
|---|
| … | … | |
| 772 | 752 | } else { |
|---|
| 773 | 753 | if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { |
|---|
| 774 | | if (hBitmap !is 0) OS.DeleteObject (hBitmap); |
|---|
| 775 | | info.hbmpItem = hBitmap = image !is null ? Display.create32bitDIB (image) : 0; |
|---|
| | 754 | if (hBitmap !is null) OS.DeleteObject (hBitmap); |
|---|
| | 755 | info.hbmpItem = hBitmap = image !is null ? Display.create32bitDIB (image) : null; |
|---|
| 776 | 756 | } else { |
|---|
| 777 | 757 | info.hbmpItem = OS.HBMMENU_CALLBACK; |
|---|
| 778 | 758 | } |
|---|
| 779 | 759 | } |
|---|
| 780 | | int hMenu = parent.handle; |
|---|
| 781 | | OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 760 | auto hMenu = parent.handle; |
|---|
| | 761 | OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 782 | 762 | parent.redraw (); |
|---|
| 783 | 763 | } |
|---|
| … | … | |
| 832 | 812 | |
|---|
| 833 | 813 | /* Assign the new menu in the OS */ |
|---|
| 834 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) { |
|---|
| 835 | | if (OS.IsPPC) { |
|---|
| 836 | | int hwndCB = parent.hwndCB; |
|---|
| 837 | | int hMenu = menu is null ? 0 : menu.handle; |
|---|
| | 814 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) { |
|---|
| | 815 | if (OS.IsPPC_) { |
|---|
| | 816 | HWND hwndCB = parent.hwndCB; |
|---|
| | 817 | HMENU hMenu = menu is null ? null : menu.handle; |
|---|
| 838 | 818 | OS.SendMessage (hwndCB, OS.SHCMBM_SETSUBMENU, id, hMenu); |
|---|
| 839 | 819 | } |
|---|
| 840 | | if (OS.IsSP) error (DWT.ERROR_CANNOT_SET_MENU); |
|---|
| | 820 | if (OS.IsSP_) error (DWT.ERROR_CANNOT_SET_MENU); |
|---|
| 841 | 821 | } else { |
|---|
| 842 | 822 | /* |
|---|
| … | … | |
| 848 | 828 | * the submenu and then insert the item with InsertMenuItem (). |
|---|
| 849 | 829 | */ |
|---|
| 850 | | int hMenu = parent.handle; |
|---|
| 851 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 830 | HMENU hMenu = parent.handle; |
|---|
| | 831 | MENUITEMINFO info; |
|---|
| 852 | 832 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 853 | 833 | info.fMask = OS.MIIM_DATA; |
|---|
| 854 | 834 | int index = 0; |
|---|
| 855 | | while (OS.GetMenuItemInfo (hMenu, index, true, info)) { |
|---|
| | 835 | while (OS.GetMenuItemInfo (hMenu, index, true, &info)) { |
|---|
| 856 | 836 | if (info.dwItemData is id) break; |
|---|
| 857 | 837 | index++; |
|---|
| … | … | |
| 870 | 850 | if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) { |
|---|
| 871 | 851 | info.fMask = OS.MIIM_BITMAP; |
|---|
| 872 | | OS.GetMenuItemInfo (hMenu, index, true, info); |
|---|
| 873 | | restoreBitmap = info.hbmpItem !is 0 || parent.foreground !is -1; |
|---|
| | 852 | OS.GetMenuItemInfo (hMenu, index, true, &info); |
|---|
| | 853 | restoreBitmap = info.hbmpItem !is null || parent.foreground !is -1; |
|---|
| 874 | 854 | if (restoreBitmap) { |
|---|
| 875 | | info.hbmpItem = 0; |
|---|
| 876 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 855 | info.hbmpItem = null; |
|---|
| | 856 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 877 | 857 | } |
|---|
| 878 | 858 | } |
|---|
| 879 | 859 | |
|---|
| 880 | 860 | int cch = 128; |
|---|
| 881 | | int hHeap = OS.GetProcessHeap (); |
|---|
| | 861 | auto hHeap = OS.GetProcessHeap (); |
|---|
| 882 | 862 | int byteCount = cch * TCHAR.sizeof; |
|---|
| 883 | | int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| | 863 | auto pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| 884 | 864 | info.fMask = OS.MIIM_STATE | OS.MIIM_ID | OS.MIIM_TYPE | OS.MIIM_DATA; |
|---|
| 885 | 865 | info.dwTypeData = pszText; |
|---|
| 886 | 866 | info.cch = cch; |
|---|
| 887 | | success = OS.GetMenuItemInfo (hMenu, index, true, info); |
|---|
| | 867 | success = cast(bool) OS.GetMenuItemInfo (hMenu, index, true, &info); |
|---|
| 888 | 868 | if (menu !is null) { |
|---|
| 889 | 869 | menu.cascade = this; |
|---|
| … | … | |
| 892 | 872 | } |
|---|
| 893 | 873 | OS.RemoveMenu (hMenu, index, OS.MF_BYPOSITION); |
|---|
| 894 | | if (OS.IsWinCE) { |
|---|
| | 874 | static if (OS.IsWinCE) { |
|---|
| 895 | 875 | /* |
|---|
| 896 | 876 | * On WinCE, InsertMenuItem() is not available. The fix is to |
|---|
| … | … | |
| 919 | 899 | } |
|---|
| 920 | 900 | } else { |
|---|
| 921 | | success = OS.InsertMenuItem (hMenu, index, true, info); |
|---|
| | 901 | success = cast(bool) OS.InsertMenuItem (hMenu, index, true, &info); |
|---|
| 922 | 902 | /* |
|---|
| 923 | 903 | * Restore the bitmap that was removed to work around a problem |
|---|
| … | … | |
| 937 | 917 | } |
|---|
| 938 | 918 | } |
|---|
| 939 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 919 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 940 | 920 | } |
|---|
| 941 | 921 | } |
|---|
| 942 | 922 | } |
|---|
| 943 | | if (pszText !is 0) OS.HeapFree (hHeap, 0, pszText); |
|---|
| | 923 | if (pszText !is null ) OS.HeapFree (hHeap, 0, pszText); |
|---|
| 944 | 924 | if (!success) error (DWT.ERROR_CANNOT_SET_MENU); |
|---|
| 945 | 925 | } |
|---|
| … | … | |
| 972 | 952 | checkWidget (); |
|---|
| 973 | 953 | if ((style & (DWT.CHECK | DWT.RADIO)) is 0) return; |
|---|
| 974 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) return; |
|---|
| 975 | | int hMenu = parent.handle; |
|---|
| | 954 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) return; |
|---|
| | 955 | auto hMenu = parent.handle; |
|---|
| 976 | 956 | if (OS.IsWinCE) { |
|---|
| 977 | 957 | int index = parent.indexOf (this); |
|---|
| … | … | |
| 980 | 960 | OS.CheckMenuItem (hMenu, index, uCheck); |
|---|
| 981 | 961 | } else { |
|---|
| 982 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 962 | MENUITEMINFO info; |
|---|
| 983 | 963 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 984 | 964 | info.fMask = OS.MIIM_STATE; |
|---|
| 985 | | bool success = OS.GetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 965 | bool success = cast(bool) OS.GetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 986 | 966 | if (!success) error (DWT.ERROR_CANNOT_SET_SELECTION); |
|---|
| 987 | 967 | info.fState &= ~OS.MFS_CHECKED; |
|---|
| 988 | 968 | if (selected) info.fState |= OS.MFS_CHECKED; |
|---|
| 989 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 969 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 990 | 970 | if (!success) { |
|---|
| 991 | 971 | /* |
|---|
| … | … | |
| 1042 | 1022 | * @see #setAccelerator |
|---|
| 1043 | 1023 | */ |
|---|
| 1044 | | override public void setText (String string) { |
|---|
| | 1024 | override public void setText (char[] string) { |
|---|
| 1045 | 1025 | checkWidget (); |
|---|
| 1046 | 1026 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 1047 | 1027 | if ((style & DWT.SEPARATOR) !is 0) return; |
|---|
| 1048 | | if (text.equals (string)) return; |
|---|
| | 1028 | if (text==/*eq*/string ) return; |
|---|
| 1049 | 1029 | super.setText (string); |
|---|
| 1050 | | int hHeap = OS.GetProcessHeap (); |
|---|
| 1051 | | int pszText = 0; |
|---|
| | 1030 | auto hHeap = OS.GetProcessHeap (); |
|---|
| | 1031 | TCHAR* pszText; |
|---|
| 1052 | 1032 | bool success = false; |
|---|
| 1053 | | if ((OS.IsPPC || OS.IsSP) && parent.hwndCB !is 0) { |
|---|
| | 1033 | if ((OS.IsPPC_ || OS.IsSP_) && parent.hwndCB !is null) { |
|---|
| 1054 | 1034 | /* |
|---|
| 1055 | 1035 | * Bug in WinCE PPC. Tool items on the menubar don't resize |
|---|
| … | … | |
| 1059 | 1039 | */ |
|---|
| 1060 | 1040 | if (string.indexOf ('&') !is -1) { |
|---|
| 1061 | | int length = string.length (); |
|---|
| 1062 | | char[] text = new char [length]; |
|---|
| 1063 | | string.getChars( 0, length, text, 0); |
|---|
| | 1041 | int length_ = string.length; |
|---|
| | 1042 | char[] text = new char [length_]; |
|---|
| | 1043 | string.getChars( 0, length_, text, 0); |
|---|
| 1064 | 1044 | int i = 0, j = 0; |
|---|
| 1065 | | for (i=0; i<length; i++) { |
|---|
| | 1045 | for (i=0; i<length_; i++) { |
|---|
| 1066 | 1046 | if (text[i] !is '&') text [j++] = text [i]; |
|---|
| 1067 | 1047 | } |
|---|
| 1068 | | if (j < i) string = new String (text, 0, j); |
|---|
| | 1048 | if (j < i) string = text[ 0 .. j ].dup; |
|---|
| 1069 | 1049 | } |
|---|
| 1070 | 1050 | /* Use the character encoding for the default locale */ |
|---|
| 1071 | | TCHAR buffer = new TCHAR (0, string, true); |
|---|
| 1072 | | int byteCount = buffer.length () * TCHAR.sizeof; |
|---|
| 1073 | | pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| 1074 | | OS.MoveMemory (pszText, buffer, byteCount); |
|---|
| 1075 | | int hwndCB = parent.hwndCB; |
|---|
| 1076 | | TBBUTTONINFO info2 = new TBBUTTONINFO (); |
|---|
| | 1051 | TCHAR[] buffer = StrToTCHARs (0, string, true); |
|---|
| | 1052 | int byteCount = buffer.length * TCHAR.sizeof; |
|---|
| | 1053 | pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| | 1054 | OS.MoveMemory (pszText, buffer.ptr, byteCount); |
|---|
| | 1055 | auto hwndCB = parent.hwndCB; |
|---|
| | 1056 | TBBUTTONINFO info2; |
|---|
| 1077 | 1057 | info2.cbSize = TBBUTTONINFO.sizeof; |
|---|
| 1078 | 1058 | info2.dwMask = OS.TBIF_TEXT; |
|---|
| 1079 | 1059 | info2.pszText = pszText; |
|---|
| 1080 | | success = OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, info2) !is 0; |
|---|
| | 1060 | success = OS.SendMessage (hwndCB, OS.TB_SETBUTTONINFO, id, &info2) !is 0; |
|---|
| 1081 | 1061 | } else { |
|---|
| 1082 | | MENUITEMINFO info = new MENUITEMINFO (); |
|---|
| | 1062 | MENUITEMINFO info; |
|---|
| 1083 | 1063 | info.cbSize = MENUITEMINFO.sizeof; |
|---|
| 1084 | | int hMenu = parent.handle; |
|---|
| | 1064 | auto hMenu = parent.handle; |
|---|
| 1085 | 1065 | |
|---|
| 1086 | 1066 | /* |
|---|
| … | … | |
| 1093 | 1073 | if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (4, 10)) { |
|---|
| 1094 | 1074 | info.fMask = OS.MIIM_BITMAP; |
|---|
| 1095 | | OS.GetMenuItemInfo (hMenu, id, false, info); |
|---|
| 1096 | | restoreBitmap = info.hbmpItem !is 0 || parent.foreground !is -1; |
|---|
| | 1075 | OS.GetMenuItemInfo (hMenu, id, false, &info); |
|---|
| | 1076 | restoreBitmap = info.hbmpItem !is null || parent.foreground !is -1; |
|---|
| 1097 | 1077 | } |
|---|
| 1098 | 1078 | |
|---|
| 1099 | 1079 | /* Use the character encoding for the default locale */ |
|---|
| 1100 | | TCHAR buffer = new TCHAR (0, string, true); |
|---|
| 1101 | | int byteCount = buffer.length () * TCHAR.sizeof; |
|---|
| 1102 | | pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| 1103 | | OS.MoveMemory (pszText, buffer, byteCount); |
|---|
| | 1080 | TCHAR[] buffer = StrToTCHARs (0, string, true); |
|---|
| | 1081 | int byteCount = buffer.length * TCHAR.sizeof; |
|---|
| | 1082 | pszText = cast(TCHAR*) OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| | 1083 | OS.MoveMemory (pszText, buffer.ptr, byteCount); |
|---|
| 1104 | 1084 | info.fMask = OS.MIIM_TYPE; |
|---|
| 1105 | 1085 | info.fType = widgetStyle (); |
|---|
| 1106 | 1086 | info.dwTypeData = pszText; |
|---|
| 1107 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 1087 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 1108 | 1088 | |
|---|
| 1109 | 1089 | /* |
|---|
| … | … | |
| 1124 | 1104 | } |
|---|
| 1125 | 1105 | } |
|---|
| 1126 | | success = OS.SetMenuItemInfo (hMenu, id, false, info); |
|---|
| | 1106 | success = cast(bool) OS.SetMenuItemInfo (hMenu, id, false, &info); |
|---|
| 1127 | 1107 | } |
|---|
| 1128 | 1108 | } |
|---|
| 1129 | 1109 | } |
|---|
| 1130 | | if (pszText !is 0) OS.HeapFree (hHeap, 0, pszText); |
|---|
| | 1110 | if (pszText !is null) OS.HeapFree (hHeap, 0, pszText); |
|---|
| 1131 | 1111 | if (!success) error (DWT.ERROR_CANNOT_SET_TEXT); |
|---|
| 1132 | 1112 | parent.redraw (); |
|---|
| … | … | |
| 1165 | 1145 | setInputState (event, DWT.Selection); |
|---|
| 1166 | 1146 | postEvent (DWT.Selection, event); |
|---|
| 1167 | | return null; |
|---|
| | 1147 | return LRESULT.NULL; |
|---|
| 1168 | 1148 | } |
|---|
| 1169 | 1149 | |
|---|
| 1170 | 1150 | LRESULT wmDrawChild (int wParam, int lParam) { |
|---|
| 1171 | | DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT (); |
|---|
| 1172 | | OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof); |
|---|
| | 1151 | DRAWITEMSTRUCT* struct_ = cast(DRAWITEMSTRUCT*)lParam; |
|---|
| | 1152 | //OS.MoveMemory (struct_, lParam, DRAWITEMSTRUCT.sizeof); |
|---|
| 1173 | 1153 | if (image !is null) { |
|---|
| 1174 | 1154 | GCData data = new GCData(); |
|---|
| 1175 | 1155 | data.device = display; |
|---|
| 1176 | | GC gc = GC.win32_new (struct.hDC, data); |
|---|
| | 1156 | GC gc = GC.win32_new (struct_.hDC, data); |
|---|
| 1177 | 1157 | /* |
|---|
| 1178 | 1158 | * Bug in Windows. When a bitmap is included in the |
|---|
| … | … | |
| 1181 | 1161 | * the item is in a menu bar. |
|---|
| 1182 | 1162 | */ |
|---|
| 1183 | | int x = (parent.style & DWT.BAR) !is 0 ? MARGIN_WIDTH * 2 : struct.left; |
|---|
| | 1163 | int x = (parent.style & DWT.BAR) !is 0 ? MARGIN_WIDTH * 2 : struct_.rcItem.left; |
|---|
| 1184 | 1164 | Image image = getEnabled () ? this.image : new Image (display, this.image, DWT.IMAGE_DISABLE); |
|---|
| 1185 | | gc.drawImage (image, x, struct.top + MARGIN_HEIGHT); |
|---|
| | 1165 | gc.drawImage (image, x, struct_.rcItem.top + MARGIN_HEIGHT); |
|---|
| 1186 | 1166 | if (this.image !is image) image.dispose (); |
|---|
| 1187 | 1167 | gc.dispose (); |
|---|
| 1188 | 1168 | } |
|---|
| 1189 | | if (parent.foreground !is -1) OS.SetTextColor (struct.hDC, parent.foreground); |
|---|
| 1190 | | return null; |
|---|
| | 1169 | if (parent.foreground !is -1) OS.SetTextColor (struct_.hDC, parent.foreground); |
|---|
| | 1170 | return LRESULT.NULL; |
|---|
| 1191 | 1171 | } |
|---|
| 1192 | 1172 | |
|---|
| 1193 | 1173 | LRESULT wmMeasureChild (int wParam, int lParam) { |
|---|
| 1194 | | MEASUREITEMSTRUCT struct = new MEASUREITEMSTRUCT (); |
|---|
| 1195 | | OS.MoveMemory (struct, lParam, MEASUREITEMSTRUCT.sizeof); |
|---|
| | 1174 | MEASUREITEMSTRUCT* struct_ = cast(MEASUREITEMSTRUCT*)lParam; |
|---|
| | 1175 | //OS.MoveMemory (struct_, lParam, MEASUREITEMSTRUCT.sizeof); |
|---|
| 1196 | 1176 | int width = 0, height = 0; |
|---|
| 1197 | 1177 | if (image !is null) { |
|---|
| … | … | |
| 1210 | 1190 | * the width of the widest bitmap in WM_MEASURECHILD. |
|---|
| 1211 | 1191 | */ |
|---|
| 1212 | | MENUINFO lpcmi = new MENUINFO (); |
|---|
| | 1192 | MENUINFO lpcmi; |
|---|
| 1213 | 1193 | lpcmi.cbSize = MENUINFO.sizeof; |
|---|
| 1214 | 1194 | lpcmi.fMask = OS.MIM_STYLE; |
|---|
| 1215 | | int hMenu = parent.handle; |
|---|
| 1216 | | OS.GetMenuInfo (hMenu, lpcmi); |
|---|
| | 1195 | auto hMenu = parent.handle; |
|---|
| | 1196 | OS.GetMenuInfo (hMenu, &lpcmi); |
|---|
| 1217 | 1197 | if ((lpcmi.dwStyle & OS.MNS_CHECKORBMP) is 0) { |
|---|
| 1218 | 1198 | MenuItem [] items = parent.getItems (); |
|---|
| … | … | |
| 1227 | 1207 | } |
|---|
| 1228 | 1208 | if (width !is 0 || height !is 0) { |
|---|
| 1229 | | struct.itemWidth = width + MARGIN_WIDTH * 2; |
|---|
| 1230 | | struct.itemHeight = height + MARGIN_HEIGHT * 2; |
|---|
| 1231 | | OS.MoveMemory (lParam, struct, MEASUREITEMSTRUCT.sizeof); |
|---|
| 1232 | | } |
|---|
| 1233 | | return null; |
|---|
| 1234 | | } |
|---|
| 1235 | | |
|---|
| 1236 | | } |
|---|
| 1237 | | ++/ |
|---|
| | 1209 | struct_.itemWidth = width + MARGIN_WIDTH * 2; |
|---|
| | 1210 | struct_.itemHeight = height + MARGIN_HEIGHT * 2; |
|---|
| | 1211 | //OS.MoveMemory (lParam, struct_, MEASUREITEMSTRUCT.sizeof); |
|---|
| | 1212 | } |
|---|
| | 1213 | return LRESULT.NULL; |
|---|
| | 1214 | } |
|---|
| | 1215 | |
|---|
| | 1216 | } |
|---|
| | 1217 | |
|---|