1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.graphics.*; 17 import org.eclipse.swt.events.*; 18 19 115 public class Shell extends Decorations { 116 Menu activeMenu; 117 ToolTip [] toolTips; 118 int hIMC, hwndMDIClient, lpstrTip, toolTipHandle, balloonTipHandle; 119 int minWidth = SWT.DEFAULT, minHeight = SWT.DEFAULT; 120 int [] brushes; 121 boolean showWithParent; 122 String toolTitle, balloonTitle; 123 int toolIcon, balloonIcon; 124 int windowProc; 125 Control lastActive, lockToolTipControl; 126 SHACTIVATEINFO psai; 127 Region region; 128 static int ToolTipProc; 129 static final int DialogProc; 130 static final TCHAR DialogClass = new TCHAR (0, OS.IsWinCE ? "Dialog" : "#32770", true); 131 final static int [] SYSTEM_COLORS = { 132 OS.COLOR_BTNFACE, 133 OS.COLOR_WINDOW, 134 OS.COLOR_BTNTEXT, 135 OS.COLOR_WINDOWTEXT, 136 OS.COLOR_HIGHLIGHT, 137 OS.COLOR_SCROLLBAR, 138 }; 139 final static int BRUSHES_SIZE = 32; 140 static { 141 WNDCLASS lpWndClass = new WNDCLASS (); 142 OS.GetClassInfo (0, DialogClass, lpWndClass); 143 DialogProc = lpWndClass.lpfnWndProc; 144 } 145 146 155 public Shell () { 156 this ((Display) null); 157 } 158 159 194 public Shell (int style) { 195 this ((Display) null, style); 196 } 197 198 217 public Shell (Display display) { 218 this (display, OS.IsWinCE ? SWT.NONE : SWT.SHELL_TRIM); 219 } 220 221 264 public Shell (Display display, int style) { 265 this (display, null, style, 0, false); 266 } 267 268 Shell (Display display, Shell parent, int style, int handle, boolean embedded) { 269 super (); 270 checkSubclass (); 271 if (display == null) display = Display.getCurrent (); 272 if (display == null) display = Display.getDefault (); 273 if (!display.isValidThread ()) { 274 error (SWT.ERROR_THREAD_INVALID_ACCESS); 275 } 276 if (parent != null && parent.isDisposed ()) { 277 error (SWT.ERROR_INVALID_ARGUMENT); 278 } 279 this.style = checkStyle (style); 280 this.parent = parent; 281 this.display = display; 282 this.handle = handle; 283 if (handle != 0 && !embedded) { 284 state |= FOREIGN_HANDLE; 285 } 286 createWidget (); 287 } 288 289 311 public Shell (Shell parent) { 312 this (parent, OS.IsWinCE ? SWT.NONE : SWT.DIALOG_TRIM); 313 } 314 315 362 public Shell (Shell parent, int style) { 363 this (parent != null ? parent.display : null, parent, style, 0, false); 364 } 365 366 380 public static Shell win32_new (Display display, int handle) { 381 return new Shell (display, null, SWT.NO_TRIM, handle, true); 382 } 383 384 public static Shell internal_new (Display display, int handle) { 385 return new Shell (display, null, SWT.NO_TRIM, handle, false); 386 } 387 388 static int checkStyle (int style) { 389 style = Decorations.checkStyle (style); 390 int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL; 391 int bits = style & ~mask; 392 if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL; 393 if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL; 394 if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL; 395 return bits; 396 } 397 398 417 public void addShellListener (ShellListener listener) { 418 checkWidget (); 419 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 420 TypedListener typedListener = new TypedListener (listener); 421 addListener (SWT.Close,typedListener); 422 addListener (SWT.Iconify,typedListener); 423 addListener (SWT.Deiconify,typedListener); 424 addListener (SWT.Activate, typedListener); 425 addListener (SWT.Deactivate, typedListener); 426 } 427 428 int balloonTipHandle () { 429 if (balloonTipHandle == 0) createBalloonTipHandle (); 430 return balloonTipHandle; 431 } 432 433 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 434 if (handle == 0) return 0; 435 if (hwnd == toolTipHandle || hwnd == balloonTipHandle) { 436 return OS.CallWindowProc (ToolTipProc, hwnd, msg, wParam, lParam); 437 } 438 if (hwndMDIClient != 0) { 439 return OS.DefFrameProc (hwnd, hwndMDIClient, msg, wParam, lParam); 440 } 441 if (windowProc != 0) { 442 return OS.CallWindowProc (windowProc, hwnd, msg, wParam, lParam); 443 } 444 if ((style & SWT.TOOL) != 0) { 445 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE; 446 if ((style & trim) == 0) return OS.DefWindowProc (hwnd, msg, wParam, lParam); 447 } 448 if (parent != null) { 449 switch (msg) { 450 case OS.WM_KILLFOCUS: 451 case OS.WM_SETFOCUS: 452 return OS.DefWindowProc (hwnd, msg, wParam, lParam); 453 } 454 return OS.CallWindowProc (DialogProc, hwnd, msg, wParam, lParam); 455 } 456 return OS.DefWindowProc (hwnd, msg, wParam, lParam); 457 } 458 459 474 public void close () { 475 checkWidget (); 476 closeWidget (); 477 } 478 479 void createBalloonTipHandle () { 480 balloonTipHandle = OS.CreateWindowEx ( 481 0, 482 new TCHAR (0, OS.TOOLTIPS_CLASS, true), 483 null, 484 OS.TTS_ALWAYSTIP | OS.TTS_BALLOON, 485 OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0, 486 handle, 487 0, 488 OS.GetModuleHandle (null), 489 null); 490 if (balloonTipHandle == 0) error (SWT.ERROR_NO_HANDLES); 491 if (ToolTipProc == 0) { 492 ToolTipProc = OS.GetWindowLong (balloonTipHandle, OS.GWL_WNDPROC); 493 } 494 501 OS.SendMessage (balloonTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF); 502 display.addControl (balloonTipHandle, this); 503 OS.SetWindowLong (balloonTipHandle, OS.GWL_WNDPROC, display.windowProc); 504 } 505 506 void createHandle () { 507 boolean embedded = handle != 0 && (state & FOREIGN_HANDLE) == 0; 508 509 517 520 if (handle == 0 || embedded) { 522 super.createHandle (); 523 } else { 524 state |= CANVAS; 525 if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) { 526 state |= THEME_BACKGROUND; 527 } 528 windowProc = OS.GetWindowLong (handle, OS.GWL_WNDPROC); 529 } 530 531 534 536 if (!embedded) { 537 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 538 bits &= ~(OS.WS_OVERLAPPED | OS.WS_CAPTION); 539 if (!OS.IsWinCE) bits |= OS.WS_POPUP; 540 if ((style & SWT.TITLE) != 0) bits |= OS.WS_CAPTION; 541 if ((style & SWT.NO_TRIM) == 0) { 542 if ((style & (SWT.BORDER | SWT.RESIZE)) == 0) bits |= OS.WS_BORDER; 543 } 544 551 OS.SetWindowLong (handle, OS.GWL_STYLE, bits); 552 int flags = OS.SWP_DRAWFRAME | OS.SWP_NOMOVE | OS.SWP_NOSIZE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE; 553 SetWindowPos (handle, 0, 0, 0, 0, 0, flags); 554 if (OS.IsWinCE) _setMaximized (true); 555 if (OS.IsPPC) { 556 psai = new SHACTIVATEINFO (); 557 psai.cbSize = SHACTIVATEINFO.sizeof; 558 } 559 } 560 if (OS.IsDBLocale) { 561 hIMC = OS.ImmCreateContext (); 562 if (hIMC != 0) OS.ImmAssociateContext (handle, hIMC); 563 } 564 } 565 566 void createToolTip (ToolTip toolTip) { 567 int id = 0; 568 if (toolTips == null) toolTips = new ToolTip [4]; 569 while (id < toolTips.length && toolTips [id] != null) id++; 570 if (id == toolTips.length) { 571 ToolTip [] newToolTips = new ToolTip [toolTips.length + 4]; 572 System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length); 573 toolTips = newToolTips; 574 } 575 toolTips [id] = toolTip; 576 toolTip.id = id + Display.ID_START; 577 if (OS.IsWinCE) return; 578 TOOLINFO lpti = new TOOLINFO (); 579 lpti.cbSize = TOOLINFO.sizeof; 580 lpti.hwnd = handle; 581 lpti.uId = toolTip.id; 582 lpti.uFlags = OS.TTF_TRACK; 583 lpti.lpszText = OS.LPSTR_TEXTCALLBACK; 584 OS.SendMessage (toolTip.hwndToolTip (), OS.TTM_ADDTOOL, 0, lpti); 585 } 586 587 void createToolTipHandle () { 588 toolTipHandle = OS.CreateWindowEx ( 589 0, 590 new TCHAR (0, OS.TOOLTIPS_CLASS, true), 591 null, 592 OS.TTS_ALWAYSTIP, 593 OS.CW_USEDEFAULT, 0, OS.CW_USEDEFAULT, 0, 594 handle, 595 0, 596 OS.GetModuleHandle (null), 597 null); 598 if (toolTipHandle == 0) error (SWT.ERROR_NO_HANDLES); 599 if (ToolTipProc == 0) { 600 ToolTipProc = OS.GetWindowLong (toolTipHandle, OS.GWL_WNDPROC); 601 } 602 609 OS.SendMessage (toolTipHandle, OS.TTM_SETMAXTIPWIDTH, 0, 0x7FFF); 610 display.addControl (toolTipHandle, this); 611 OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, display.windowProc); 612 } 613 614 void deregister () { 615 super.deregister (); 616 if (toolTipHandle != 0) display.removeControl (toolTipHandle); 617 if (balloonTipHandle != 0) display.removeControl (balloonTipHandle); 618 } 619 620 void destroyToolTip (ToolTip toolTip) { 621 if (toolTips == null) return; 622 toolTips [toolTip.id - Display.ID_START] = null; 623 if (OS.IsWinCE) return; 624 if (balloonTipHandle != 0) { 625 TOOLINFO lpti = new TOOLINFO (); 626 lpti.cbSize = TOOLINFO.sizeof; 627 lpti.uId = toolTip.id; 628 lpti.hwnd = handle; 629 OS.SendMessage (balloonTipHandle, OS.TTM_DELTOOL, 0, lpti); 630 } 631 toolTip.id = -1; 632 } 633 634 void destroyWidget () { 635 fixActiveShell (); 636 super.destroyWidget (); 637 } 638 639 public void dispose () { 640 646 super.dispose (); 654 } 657 658 void enableWidget (boolean enabled) { 659 if (enabled) { 660 state &= ~DISABLED; 661 } else { 662 state |= DISABLED; 663 } 664 if (Display.TrimEnabled) { 665 if (isActive ()) setItemEnabled (OS.SC_CLOSE, enabled); 666 } else { 667 OS.EnableWindow (handle, enabled); 668 } 669 } 670 671 int findBrush (int value, int lbStyle) { 672 if (lbStyle == OS.BS_SOLID) { 673 for (int i=0; i<SYSTEM_COLORS.length; i++) { 674 if (value == OS.GetSysColor (SYSTEM_COLORS [i])) { 675 return OS.GetSysColorBrush (SYSTEM_COLORS [i]); 676 } 677 } 678 } 679 if (brushes == null) brushes = new int [BRUSHES_SIZE]; 680 LOGBRUSH logBrush = new LOGBRUSH (); 681 for (int i=0; i<brushes.length; i++) { 682 int hBrush = brushes [i]; 683 if (hBrush == 0) break; 684 OS.GetObject (hBrush, LOGBRUSH.sizeof, logBrush); 685 switch (logBrush.lbStyle) { 686 case OS.BS_SOLID: 687 if (lbStyle == OS.BS_SOLID) { 688 if (logBrush.lbColor == value) return hBrush; 689 } 690 break; 691 case OS.BS_PATTERN: 692 if (lbStyle == OS.BS_PATTERN) { 693 if (logBrush.lbHatch == value) return hBrush; 694 } 695 break; 696 } 697 } 698 int length = brushes.length; 699 int hBrush = brushes [--length]; 700 if (hBrush != 0) OS.DeleteObject (hBrush); 701 System.arraycopy (brushes, 0, brushes, 1, length); 702 switch (lbStyle) { 703 case OS.BS_SOLID: 704 hBrush = OS.CreateSolidBrush (value); 705 break; 706 case OS.BS_PATTERN: 707 hBrush = OS.CreatePatternBrush (value); 708 break; 709 } 710 return brushes [0] = hBrush; 711 } 712 713 Control findBackgroundControl () { 714 return background != -1 || backgroundImage != null ? this : null; 715 } 716 717 Cursor findCursor () { 718 return cursor; 719 } 720 721 Control findThemeControl () { 722 return null; 723 } 724 725 ToolTip findToolTip (int id) { 726 if (toolTips == null) return null; 727 id = id - Display.ID_START; 728 return 0 <= id && id < toolTips.length ? toolTips [id] : null; 729 } 730 731 void fixActiveShell () { 732 741 int hwndParent = OS.GetParent (handle); 742 if (hwndParent != 0 && handle == OS.GetActiveWindow ()) { 743 if (!OS.IsWindowEnabled (hwndParent) && OS.IsWindowVisible (hwndParent)) { 744 OS.SetActiveWindow (hwndParent); 745 } 746 } 747 } 748 749 void fixShell (Shell newShell, Control control) { 750 if (this == newShell) return; 751 if (control == lastActive) setActiveControl (null); 752 String toolTipText = control.toolTipText; 753 if (toolTipText != null) { 754 control.setToolTipText (this, null); 755 control.setToolTipText (newShell, toolTipText); 756 } 757 } 758 759 void fixToolTip () { 760 771 if (OS.COMCTL32_MAJOR >= 6) { 772 if (toolTipHandle == 0) return; 773 TOOLINFO lpti = new TOOLINFO (); 774 lpti.cbSize = TOOLINFO.sizeof; 775 if (OS.SendMessage (toolTipHandle, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) { 776 if ((lpti.uFlags & OS.TTF_IDISHWND) != 0) { 777 OS.SendMessage (toolTipHandle, OS.TTM_DELTOOL, 0, lpti); 778 OS.SendMessage (toolTipHandle, OS.TTM_ADDTOOL, 0, lpti); 779 } 780 } 781 } 782 } 783 784 805 public void forceActive () { 806 checkWidget (); 807 if(!isVisible()) return; 808 OS.SetForegroundWindow (handle); 809 } 810 811 void forceResize () { 812 813 } 814 815 public Rectangle getBounds () { 816 checkWidget (); 817 if (!OS.IsWinCE) { 818 if (OS.IsIconic (handle)) return super.getBounds (); 819 } 820 RECT rect = new RECT (); 821 OS.GetWindowRect (handle, rect); 822 int width = rect.right - rect.left; 823 int height = rect.bottom - rect.top; 824 return new Rectangle (rect.left, rect.top, width, height); 825 } 826 827 ToolTip getCurrentToolTip () { 828 if (toolTipHandle != 0) { 829 ToolTip tip = getCurrentToolTip (toolTipHandle); 830 if (tip != null) return tip; 831 } 832 if (balloonTipHandle != 0) { 833 ToolTip tip = getCurrentToolTip (balloonTipHandle); 834 if (tip != null) return tip; 835 } 836 return null; 837 } 838 839 ToolTip getCurrentToolTip (int hwndToolTip) { 840 if (hwndToolTip == 0) return null; 841 if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) { 842 TOOLINFO lpti = new TOOLINFO (); 843 lpti.cbSize = TOOLINFO.sizeof; 844 if (OS.SendMessage (hwndToolTip, OS.TTM_GETCURRENTTOOL, 0, lpti) != 0) { 845 if ((lpti.uFlags & OS.TTF_IDISHWND) == 0) return findToolTip (lpti.uId); 846 } 847 } 848 return null; 849 } 850 851 public boolean getEnabled () { 852 checkWidget (); 853 return (state & DISABLED) == 0; 854 } 855 856 873 public int getImeInputMode () { 874 checkWidget (); 875 if (!OS.IsDBLocale) return 0; 876 int hIMC = OS.ImmGetContext (handle); 877 int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1]; 878 boolean open = OS.ImmGetOpenStatus (hIMC); 879 if (open) open = OS.ImmGetConversionStatus (hIMC, lpfdwConversion, lpfdwSentence); 880 OS.ImmReleaseContext (handle, hIMC); 881 if (!open) return SWT.NONE; 882 int result = 0; 883 if ((lpfdwConversion [0] & OS.IME_CMODE_ROMAN) != 0) result |= SWT.ROMAN; 884 if ((lpfdwConversion [0] & OS.IME_CMODE_FULLSHAPE) != 0) result |= SWT.DBCS; 885 if ((lpfdwConversion [0] & OS.IME_CMODE_KATAKANA) != 0) return result | SWT.PHONETIC; 886 if ((lpfdwConversion [0] & OS.IME_CMODE_NATIVE) != 0) return result | SWT.NATIVE; 887 return result | SWT.ALPHA; 888 } 889 890 public Point getLocation () { 891 checkWidget (); 892 if (!OS.IsWinCE) { 893 if (OS.IsIconic (handle)) { 894 return super.getLocation (); 895 } 896 } 897 RECT rect = new RECT (); 898 OS.GetWindowRect (handle, rect); 899 return new Point (rect.left, rect.top); 900 } 901 902 917 public Point getMinimumSize () { 918 checkWidget (); 919 int width = Math.max (0, minWidth); 920 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; 921 if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { 922 width = Math.max (width, OS.GetSystemMetrics (OS.SM_CXMINTRACK)); 923 } 924 int height = Math.max (0, minHeight); 925 if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { 926 if ((style & SWT.RESIZE) != 0) { 927 height = Math.max (height, OS.GetSystemMetrics (OS.SM_CYMINTRACK)); 928 } else { 929 RECT rect = new RECT (); 930 int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); 931 int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); 932 OS.AdjustWindowRectEx (rect, bits1, false, bits2); 933 height = Math.max (height, rect.bottom - rect.top); 934 } 935 } 936 return new Point (width, height); 937 } 938 939 953 public Region getRegion () { 954 checkWidget (); 955 return region; 956 } 957 958 public Shell getShell () { 959 checkWidget (); 960 return this; 961 } 962 963 public Point getSize () { 964 checkWidget (); 965 if (!OS.IsWinCE) { 966 if (OS.IsIconic (handle)) return super.getSize (); 967 } 968 RECT rect = new RECT (); 969 OS.GetWindowRect (handle, rect); 970 int width = rect.right - rect.left; 971 int height = rect.bottom - rect.top; 972 return new Point (width, height); 973 } 974 975 986 public Shell [] getShells () { 987 checkWidget (); 988 int count = 0; 989 Shell [] shells = display.getShells (); 990 for (int i=0; i<shells.length; i++) { 991 Control shell = shells [i]; 992 do { 993 shell = shell.parent; 994 } while (shell != null && shell != this); 995 if (shell == this) count++; 996 } 997 int index = 0; 998 Shell [] result = new Shell [count]; 999 for (int i=0; i<shells.length; i++) { 1000 Control shell = shells [i]; 1001 do { 1002 shell = shell.parent; 1003 } while (shell != null && shell != this); 1004 if (shell == this) { 1005 result [index++] = shells [i]; 1006 } 1007 } 1008 return result; 1009} 1010 1011Composite findDeferredControl () { 1012 return layoutCount > 0 ? this : null; 1013} 1014 1015public boolean isEnabled () { 1016 checkWidget (); 1017 return getEnabled (); 1018} 1019 1020public boolean isVisible () { 1021 checkWidget (); 1022 return getVisible (); 1023} 1024 1025int hwndMDIClient () { 1026 if (hwndMDIClient == 0) { 1027 int widgetStyle = OS.MDIS_ALLCHILDSTYLES | OS.WS_CHILD | OS.WS_CLIPCHILDREN | OS.WS_CLIPSIBLINGS; 1028 hwndMDIClient = OS.CreateWindowEx ( 1029 0, 1030 new TCHAR (0, "MDICLIENT", true), 1031 null, 1032 widgetStyle, 1033 0, 0, 0, 0, 1034 handle, 1035 0, 1036 OS.GetModuleHandle (null), 1037 new CREATESTRUCT ()); 1038 } 1040 return hwndMDIClient; 1041} 1042 1043 1064public void open () { 1065 checkWidget (); 1066 STARTUPINFO lpStartUpInfo = Display.lpStartupInfo; 1067 if (lpStartUpInfo == null || (lpStartUpInfo.dwFlags & OS.STARTF_USESHOWWINDOW) == 0) { 1068 bringToTop (); 1069 if (isDisposed ()) return; 1070 } 1071 1078 if (OS.IsWinCE) OS.SetForegroundWindow (handle); 1079 OS.SendMessage (handle, OS.WM_CHANGEUISTATE, OS.UIS_INITIALIZE, 0); 1080 setVisible (true); 1081 if (isDisposed ()) return; 1082 1096 MSG msg = new MSG (); 1097 int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_SENDMESSAGE; 1098 OS.PeekMessage (msg, 0, 0, 0, flags); 1099 if (!restoreFocus () && !traverseGroup (true)) setFocus (); 1100} 1101 1102void register () { 1103 super.register (); 1104 if (toolTipHandle != 0) display.addControl (toolTipHandle, this); 1105 if (balloonTipHandle != 0) display.addControl (balloonTipHandle, this); 1106} 1107 1108void releaseBrushes () { 1109 if (brushes != null) { 1110 for (int i=0; i<brushes.length; i++) { 1111 if (brushes [i] != 0) OS.DeleteObject (brushes [i]); 1112 } 1113 } 1114 brushes = null; 1115} 1116 1117void releaseChildren (boolean destroy) { 1118 Shell [] shells = getShells (); 1119 for (int i=0; i<shells.length; i++) { 1120 Shell shell = shells [i]; 1121 if (shell != null && !shell.isDisposed ()) { 1122 shell.release (false); 1123 } 1124 } 1125 if (toolTips != null) { 1126 for (int i=0; i<toolTips.length; i++) { 1127 ToolTip toolTip = toolTips [i]; 1128 if (toolTip != null && !toolTip.isDisposed ()) { 1129 toolTip.release (false); 1130 } 1131 } 1132 } 1133 toolTips = null; 1134 super.releaseChildren (destroy); 1135} 1136 1137void releaseHandle () { 1138 super.releaseHandle (); 1139 hwndMDIClient = 0; 1140} 1141 1142void releaseParent () { 1143 1144} 1145 1146void releaseWidget () { 1147 super.releaseWidget (); 1148 releaseBrushes (); 1149 activeMenu = null; 1150 display.clearModal (this); 1151 if (lpstrTip != 0) { 1152 int hHeap = OS.GetProcessHeap (); 1153 OS.HeapFree (hHeap, 0, lpstrTip); 1154 } 1155 lpstrTip = 0; 1156 toolTipHandle = balloonTipHandle = 0; 1157 if (OS.IsDBLocale) { 1158 if (hIMC != 0) OS.ImmDestroyContext (hIMC); 1159 } 1160 lastActive = null; 1161 region = null; 1162 toolTitle = balloonTitle = null; 1163 lockToolTipControl = null; 1164} 1165 1166void removeMenu (Menu menu) { 1167 super.removeMenu (menu); 1168 if (menu == activeMenu) activeMenu = null; 1169} 1170 1171 1188public void removeShellListener (ShellListener listener) { 1189 checkWidget (); 1190 if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); 1191 if (eventTable == null) return; 1192 eventTable.unhook (SWT.Close, listener); 1193 eventTable.unhook (SWT.Iconify,listener); 1194 eventTable.unhook (SWT.Deiconify,listener); 1195 eventTable.unhook (SWT.Activate, listener); 1196 eventTable.unhook (SWT.Deactivate, listener); 1197} 1198 1199LRESULT selectPalette (int hPalette) { 1200 int hDC = OS.GetDC (handle); 1201 int hOld = OS.SelectPalette (hDC, hPalette, false); 1202 int result = OS.RealizePalette (hDC); 1203 if (result > 0) { 1204 OS.InvalidateRect (handle, null, true); 1205 } else { 1206 OS.SelectPalette (hDC, hOld, true); 1207 OS.RealizePalette (hDC); 1208 } 1209 OS.ReleaseDC (handle, hDC); 1210 return (result > 0) ? LRESULT.ONE : LRESULT.ZERO; 1211} 1212 1213 1234public void setActive () { 1235 checkWidget (); 1236 if (!isVisible ()) return; 1237 bringToTop (); 1238 } 1240 1241void setActiveControl (Control control) { 1242 if (control != null && control.isDisposed ()) control = null; 1243 if (lastActive != null && lastActive.isDisposed ()) lastActive = null; 1244 if (lastActive == control) return; 1245 1246 1251 Control [] activate = (control == null) ? new Control [0] : control.getPath (); 1252 Control [] deactivate = (lastActive == null) ? new Control [0] : lastActive.getPath (); 1253 lastActive = control; 1254 int index = 0, length = Math.min (activate.length, deactivate.length); 1255 while (index < length) { 1256 if (activate [index] != deactivate [index]) break; 1257 index++; 1258 } 1259 1260 1266 for (int i=deactivate.length-1; i>=index; --i) { 1267 if (!deactivate [i].isDisposed ()) { 1268 deactivate [i].sendEvent (SWT.Deactivate); 1269 } 1270 } 1271 for (int i=activate.length-1; i>=index; --i) { 1272 if (!activate [i].isDisposed ()) { 1273 activate [i].sendEvent (SWT.Activate); 1274 } 1275 } 1276} 1277 1278void setBounds (int x, int y, int width, int height, int flags, boolean defer) { 1279 super.setBounds (x, y, width, height, flags, false); 1280} 1281 1282public void setEnabled (boolean enabled) { 1283 checkWidget (); 1284 if (((state & DISABLED) == 0) == enabled) return; 1285 super.setEnabled (enabled); 1286 if (enabled && handle == OS.GetActiveWindow ()) { 1287 if (!restoreFocus ()) traverseGroup (true); 1288 } 1289} 1290 1291 1307public void setImeInputMode (int mode) { 1308 checkWidget (); 1309 if (!OS.IsDBLocale) return; 1310 boolean imeOn = mode != SWT.NONE && mode != SWT.ROMAN; 1311 int hIMC = OS.ImmGetContext (handle); 1312 OS.ImmSetOpenStatus (hIMC, imeOn); 1313 if (imeOn) { 1314 int [] lpfdwConversion = new int [1], lpfdwSentence = new int [1]; 1315 if (OS.ImmGetConversionStatus (hIMC, lpfdwConversion, lpfdwSentence)) { 1316 int newBits = 0; 1317 int oldBits = OS.IME_CMODE_NATIVE | OS.IME_CMODE_KATAKANA; 1318 if ((mode & SWT.PHONETIC) != 0) { 1319 newBits = OS.IME_CMODE_KATAKANA | OS.IME_CMODE_NATIVE; 1320 oldBits = 0; 1321 } else { 1322 if ((mode & SWT.NATIVE) != 0) { 1323 newBits = OS.IME_CMODE_NATIVE; 1324 oldBits = OS.IME_CMODE_KATAKANA; 1325 } 1326 } 1327 if ((mode & SWT.DBCS) != 0) { 1328 newBits |= OS.IME_CMODE_FULLSHAPE; 1329 } else { 1330 oldBits |= OS.IME_CMODE_FULLSHAPE; 1331 } 1332 if ((mode & SWT.ROMAN) != 0) { 1333 newBits |= OS.IME_CMODE_ROMAN; 1334 } else { 1335 oldBits |= OS.IME_CMODE_ROMAN; 1336 } 1337 lpfdwConversion [0] |= newBits; lpfdwConversion [0] &= ~oldBits; 1338 OS.ImmSetConversionStatus (hIMC, lpfdwConversion [0], lpfdwSentence [0]); 1339 } 1340 } 1341 OS.ImmReleaseContext (handle, hIMC); 1342} 1343 1344 1359public void setMinimumSize (int width, int height) { 1360 checkWidget (); 1361 int widthLimit = 0, heightLimit = 0; 1362 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; 1363 if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { 1364 widthLimit = OS.GetSystemMetrics (OS.SM_CXMINTRACK); 1365 if ((style & SWT.RESIZE) != 0) { 1366 heightLimit = OS.GetSystemMetrics (OS.SM_CYMINTRACK); 1367 } else { 1368 RECT rect = new RECT (); 1369 int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); 1370 int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); 1371 OS.AdjustWindowRectEx (rect, bits1, false, bits2); 1372 heightLimit = rect.bottom - rect.top; 1373 } 1374 } 1375 minWidth = Math.max (widthLimit, width); 1376 minHeight = Math.max (heightLimit, height); 1377 Point size = getSize (); 1378 int newWidth = Math.max (size.x, minWidth); 1379 int newHeight = Math.max (size.y, minHeight); 1380 if (minWidth <= widthLimit) minWidth = SWT.DEFAULT; 1381 if (minHeight <= heightLimit) minHeight = SWT.DEFAULT; 1382 if (newWidth != size.x || newHeight != size.y) setSize (newWidth, newHeight); 1383} 1384 1385 1402public void setMinimumSize (Point size) { 1403 checkWidget (); 1404 if (size == null) error (SWT.ERROR_NULL_ARGUMENT); 1405 setMinimumSize (size.x, size.y); 1406} 1407 1408void setItemEnabled (int cmd, boolean enabled) { 1409 int hMenu = OS.GetSystemMenu (handle, false); 1410 if (hMenu == 0) return; 1411 int flags = OS.MF_ENABLED; 1412 if (!enabled) flags = OS.MF_DISABLED | OS.MF_GRAYED; 1413 OS.EnableMenuItem (hMenu, cmd, OS.MF_BYCOMMAND | flags); 1414} 1415 1416void setParent () { 1417 1418} 1419 1420 1440public void setRegion (Region region) { 1441 checkWidget (); 1442 if ((style & SWT.NO_TRIM) == 0) return; 1443 if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); 1444 int hRegion = 0; 1445 if (region != null) { 1446 hRegion = OS.CreateRectRgn (0, 0, 0, 0); 1447 OS.CombineRgn (hRegion, region.handle, hRegion, OS.RGN_OR); 1448 } 1449 OS.SetWindowRgn (handle, hRegion, true); 1450 this.region = region; 1451} 1452 1453void setToolTipText (int hwnd, String text) { 1454 if (OS.IsWinCE) return; 1455 TOOLINFO lpti = new TOOLINFO (); 1456 lpti.cbSize = TOOLINFO.sizeof; 1457 lpti.hwnd = handle; 1458 lpti.uId = hwnd; 1459 int hwndToolTip = toolTipHandle (); 1460 if (text == null) { 1461 OS.SendMessage (hwndToolTip, OS.TTM_DELTOOL, 0, lpti); 1462 } else { 1463 if (OS.SendMessage (hwndToolTip, OS.TTM_GETTOOLINFO, 0, lpti) != 0) { 1464 OS.SendMessage (hwndToolTip, OS.TTM_UPDATE, 0, 0); 1465 } else { 1466 lpti.uFlags = OS.TTF_IDISHWND | OS.TTF_SUBCLASS; 1467 lpti.lpszText = OS.LPSTR_TEXTCALLBACK; 1468 OS.SendMessage (hwndToolTip, OS.TTM_ADDTOOL, 0, lpti); 1469 } 1470 } 1471} 1472 1473void setToolTipText (NMTTDISPINFO lpnmtdi, byte [] buffer) { 1474 1480 if (!hasCursor ()) return; 1481 int hHeap = OS.GetProcessHeap (); 1482 if (lpstrTip != 0) OS.HeapFree (hHeap, 0, lpstrTip); 1483 int byteCount = buffer.length; 1484 lpstrTip = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 1485 OS.MoveMemory (lpstrTip, buffer, byteCount); 1486 lpnmtdi.lpszText = lpstrTip; 1487} 1488 1489void setToolTipText (NMTTDISPINFO lpnmtdi, char [] buffer) { 1490 1496 if (!hasCursor ()) return; 1497 int hHeap = OS.GetProcessHeap (); 1498 if (lpstrTip != 0) OS.HeapFree (hHeap, 0, lpstrTip); 1499 int byteCount = buffer.length * 2; 1500 lpstrTip = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); 1501 OS.MoveMemory (lpstrTip, buffer, byteCount); 1502 lpnmtdi.lpszText = lpstrTip; 1503} 1504 1505void setToolTipTitle (int hwndToolTip, String text, int icon) { 1506 1522 if (hwndToolTip != toolTipHandle && hwndToolTip != balloonTipHandle) { 1523 return; 1524 } 1525 if (hwndToolTip == toolTipHandle) { 1526 if (text == toolTitle || (toolTitle != null && toolTitle.equals (text))) { 1527 if (icon == toolIcon) return; 1528 } 1529 toolTitle = text; 1530 toolIcon = icon; 1531 } else { 1532 if (hwndToolTip == balloonTipHandle) { 1533 if (text == balloonTitle || (balloonTitle != null && balloonTitle.equals (text))) { 1534 if (icon == toolIcon) return; 1535 } 1536 balloonTitle = text; 1537 balloonIcon = icon; 1538 } 1539 } 1540 if (text != null) { 1541 TCHAR pszTitle = new TCHAR (getCodePage (), text, true); 1542 OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, icon, pszTitle); 1543 } else { 1544 OS.SendMessage (hwndToolTip, OS.TTM_SETTITLE, 0, 0); 1545 } 1546} 1547 1548public void setVisible (boolean visible) { 1549 checkWidget (); 1550 if (drawCount != 0) { 1551 if (((state & HIDDEN) == 0) == visible) return; 1552 } else { 1553 if (visible == OS.IsWindowVisible (handle)) return; 1554 } 1555 1556 1565 int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; 1566 if ((style & mask) != 0) { 1567 if (visible) { 1568 display.setModalShell (this); 1569 Control control = display._getFocusControl (); 1570 if (control != null && !control.isActive ()) { 1571 bringToTop (); 1572 if (isDisposed ()) return; 1573 } 1574 int hwndShell = OS.GetActiveWindow (); 1575 if (hwndShell == 0) { 1576 if (parent != null) hwndShell = parent.handle; 1577 } 1578 if (hwndShell != 0) { 1579 OS.SendMessage (hwndShell, OS.WM_CANCELMODE, 0, 0); 1580 } 1581 OS.ReleaseCapture (); 1582 } else { 1583 display.clearModal (this); 1584 } 1585 } else { 1586 updateModal (); 1587 } 1588 1589 1595 if (showWithParent && !visible) { 1596 if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, false); 1597 } 1598 if (!visible) fixActiveShell (); 1599 super.setVisible (visible); 1600 if (isDisposed ()) return; 1601 if (showWithParent == visible) return; 1602 showWithParent = visible; 1603 if (visible) { 1604 if (!OS.IsWinCE) OS.ShowOwnedPopups (handle, true); 1605 } 1606} 1607 1608void subclass () { 1609 super.subclass (); 1610 if (ToolTipProc != 0) { 1611 int newProc = display.windowProc; 1612 if (toolTipHandle != 0) { 1613 OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, newProc); 1614 } 1615 if (balloonTipHandle != 0) { 1616 OS.SetWindowLong (balloonTipHandle, OS.GWL_WNDPROC, newProc); 1617 } 1618 } 1619} 1620 1621int toolTipHandle () { 1622 if (toolTipHandle == 0) createToolTipHandle (); 1623 return toolTipHandle; 1624} 1625 1626boolean translateAccelerator (MSG msg) { 1627 if (!isEnabled () || !isActive ()) return false; 1628 if (menuBar != null && !menuBar.isEnabled ()) return false; 1629 return translateMDIAccelerator (msg) || translateMenuAccelerator (msg); 1630} 1631 1632boolean traverseEscape () { 1633 if (parent == null) return false; 1634 if (!isVisible () || !isEnabled ()) return false; 1635 close (); 1636 return true; 1637} 1638 1639void unsubclass () { 1640 super.unsubclass (); 1641 if (ToolTipProc != 0) { 1642 if (toolTipHandle != 0) { 1643 OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, ToolTipProc); 1644 } 1645 if (toolTipHandle != 0) { 1646 OS.SetWindowLong (toolTipHandle, OS.GWL_WNDPROC, ToolTipProc); 1647 } 1648 } 1649} 1650 1651void updateModal () { 1652 if (Display.TrimEnabled) { 1653 setItemEnabled (OS.SC_CLOSE, isActive ()); 1654 } else { 1655 OS.EnableWindow (handle, isActive ()); 1656 } 1657} 1658 1659CREATESTRUCT widgetCreateStruct () { 1660 return null; 1661} 1662 1663int widgetParent () { 1664 if (handle != 0) return handle; 1665 return parent != null ? parent.handle : 0; 1666} 1667 1668int widgetExtStyle () { 1669 int bits = super.widgetExtStyle () & ~OS.WS_EX_MDICHILD; 1670 if ((style & SWT.TOOL) != 0) bits |= OS.WS_EX_TOOLWINDOW; 1671 1672 1678 if (!OS.IsWinCE) { 1679 if (parent == null) { 1680 if ((style & SWT.ON_TOP) != 0) { 1681 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; 1682 if ((style & SWT.NO_TRIM) != 0 || (style & trim) == 0) { 1683 bits |= OS.WS_EX_TOOLWINDOW; 1684 } 1685 } 1686 } 1687 } 1688 1689 1701 if (parent != null) { 1702 if (OS.IsWin95) return bits; 1703 if (OS.WIN32_VERSION < OS.VERSION (4, 10)) { 1704 return bits; 1705 } 1706 } 1707 if ((style & SWT.ON_TOP) != 0) bits |= OS.WS_EX_TOPMOST; 1708 return bits; 1709} 1710 1711TCHAR windowClass () { 1712 if (OS.IsSP) return DialogClass; 1713 if ((style & SWT.TOOL) != 0) { 1714 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE; 1715 if ((style & trim) == 0) return display.windowShadowClass; 1716 } 1717 return parent != null ? DialogClass : super.windowClass (); 1718} 1719 1720int windowProc () { 1721 if (windowProc != 0) return windowProc; 1722 if (OS.IsSP) return DialogProc; 1723 if ((style & SWT.TOOL) != 0) { 1724 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.BORDER | SWT.RESIZE; 1725 if ((style & trim) == 0) super.windowProc (); 1726 } 1727 return parent != null ? DialogProc : super.windowProc (); 1728} 1729 1730int windowProc (int hwnd, int msg, int wParam, int lParam) { 1731 if (handle == 0) return 0; 1732 if (hwnd == toolTipHandle || hwnd == balloonTipHandle) { 1733 switch (msg) { 1734 case OS.WM_TIMER: { 1735 if (wParam != ToolTip.TIMER_ID) break; 1736 ToolTip tip = getCurrentToolTip (hwnd); 1737 if (tip != null && tip.autoHide) { 1738 tip.setVisible (false); 1739 } 1740 break; 1741 } 1742 case OS.WM_LBUTTONDOWN: { 1743 ToolTip tip = getCurrentToolTip (hwnd); 1744 if (tip != null) { 1745 tip.setVisible (false); 1746 tip.postEvent (SWT.Selection); 1747 } 1748 break; 1749 } 1750 } 1751 return callWindowProc (hwnd, msg, wParam, lParam); 1752 } 1753 return super.windowProc (hwnd, msg, wParam, lParam); 1754} 1755 1756int widgetStyle () { 1757 int bits = super.widgetStyle (); 1758 if (handle != 0) return bits | OS.WS_CHILD; 1759 bits &= ~OS.WS_CHILD; 1760 1774 if (OS.IsWinCE) { 1775 if (OS.IsSP) return bits | OS.WS_POPUP; 1776 return parent == null ? bits : bits | OS.WS_POPUP; 1777 } 1778 1779 1792 return bits | OS.WS_OVERLAPPED | OS.WS_CAPTION; 1793} 1794 1795LRESULT WM_ACTIVATE (int wParam, int lParam) { 1796 if (OS.IsPPC) { 1797 1801 if (hooks (SWT.HardKeyDown) || hooks (SWT.HardKeyUp)) { 1802 int fActive = wParam & 0xFFFF; 1803 int hwnd = fActive != 0 ? handle : 0; 1804 for (int bVk=OS.VK_APP1; bVk<=OS.VK_APP6; bVk++) { 1805 OS.SHSetAppKeyWndAssoc ((byte) bVk, hwnd); 1806 } 1807 } 1808 1809 if ((wParam & 0xFFFF) != 0) { 1810 OS.SHSipPreference (handle, psai.fSipUp == 0 ? OS.SIP_DOWN : OS.SIP_UP); 1811 } 1812 } 1813 1814 1823 if (OS.WIN32_VERSION >= OS.VERSION (5, 1)) { 1824 if ((wParam & 0xFFFF) == 0 && OS.IsDBLocale && hIMC != 0) { 1825 if (OS.ImmGetOpenStatus(hIMC)) { 1826 OS.ImmSetOpenStatus (hIMC, false); 1827 OS.ImmSetOpenStatus (hIMC, true); 1828 } 1829 } 1830 } 1831 1832 1833 LRESULT result = super.WM_ACTIVATE (wParam, lParam); 1834 if ((wParam & 0xFFFF) == 0) { 1835 if (lParam == 0 || (lParam != toolTipHandle && lParam != balloonTipHandle)) { 1836 ToolTip tip = getCurrentToolTip (); 1837 if (tip != null) tip.setVisible (false); 1838 } 1839 } 1840 return parent != null ? LRESULT.ZERO : result; 1841} 1842 1843LRESULT WM_COMMAND (int wParam, int lParam) { 1844 if (OS.IsPPC) { 1845 1850 int loWord = wParam & 0xFFFF; 1851 if (loWord == OS.IDOK && (lParam == 0 || lParam == handle)) { 1852 OS.PostMessage (handle, OS.WM_CLOSE, 0, 0); 1853 return LRESULT.ZERO; 1854 } 1855 } 1856 1866 if (OS.IsPPC || OS.IsSP) { 1867 if (menuBar != null) { 1868 int hwndCB = menuBar.hwndCB; 1869 if (lParam != 0 && hwndCB != 0) { 1870 if (lParam == hwndCB) { 1871 return super.WM_COMMAND (wParam, 0); 1872 } else { 1873 int hwndChild = OS.GetWindow (hwndCB, OS.GW_CHILD); 1874 if (lParam == hwndChild) return super.WM_COMMAND (wParam, 0); 1875 } 1876 } 1877 } 1878 } 1879 return super.WM_COMMAND (wParam, lParam); 1880} 1881 1882LRESULT WM_DESTROY (int wParam, int lParam) { 1883 LRESULT result = super.WM_DESTROY (wParam, lParam); 1884 1890 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 1891 if ((bits & OS.WS_CHILD) != 0) { 1892 releaseParent (); 1893 release (false); 1894 } 1895 return result; 1896} 1897 1898LRESULT WM_ERASEBKGND (int wParam, int lParam) { 1899 LRESULT result = super.WM_ERASEBKGND (wParam, lParam); 1900 if (result != null) return result; 1901 1909 if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) { 1910 drawBackground (wParam); 1911 return LRESULT.ONE; 1912 } 1913 return result; 1914} 1915 1916LRESULT WM_ENTERIDLE (int wParam, int lParam) { 1917 LRESULT result = super.WM_ENTERIDLE (wParam, lParam); 1918 if (result != null) return result; 1919 if (OS.IsWinCE && display.runMessages) { 1920 if (display.runAsyncMessages (true)) display.wakeThread (); 1921 } 1922 return result; 1923} 1924 1925LRESULT WM_GETMINMAXINFO (int wParam, int lParam) { 1926 LRESULT result = super.WM_GETMINMAXINFO (wParam, lParam); 1927 if (result != null) return result; 1928 if (minWidth != SWT.DEFAULT || minHeight != SWT.DEFAULT) { 1929 MINMAXINFO info = new MINMAXINFO (); 1930 OS.MoveMemory (info, lParam, MINMAXINFO.sizeof); 1931 if (minWidth != SWT.DEFAULT) info.ptMinTrackSize_x = minWidth; 1932 if (minHeight != SWT.DEFAULT) info.ptMinTrackSize_y = minHeight; 1933 OS.MoveMemory (lParam, info, MINMAXINFO.sizeof); 1934 return LRESULT.ZERO; 1935 } 1936 return result; 1937} 1938 1939LRESULT WM_MOUSEACTIVATE (int wParam, int lParam) { 1940 LRESULT result = super.WM_MOUSEACTIVATE (wParam, lParam); 1941 if (result != null) return result; 1942 1943 1948 int hittest = (short) (lParam & 0xFFFF); 1949 switch (hittest) { 1950 case OS.HTERROR: 1951 case OS.HTTRANSPARENT: 1952 case OS.HTNOWHERE: 1953 break; 1954 default: { 1955 Control control = display._getFocusControl (); 1956 if (control != null) { 1957 Decorations decorations = control.menuShell (); 1958 if (decorations.getShell () == this && decorations != this) { 1959 display.ignoreRestoreFocus = true; 1960 display.lastHittest = hittest; 1961 display.lastHittestControl = null; 1962 if (hittest == OS.HTMENU || hittest == OS.HTSYSMENU) { 1963 display.lastHittestControl = control; 1964 return null; 1965 } 1966 if (OS.IsWin95 && hittest == OS.HTCAPTION) { 1967 display.lastHittestControl = control; 1968 } 1969 return new LRESULT (OS.MA_NOACTIVATE); 1970 } 1971 } 1972 } 1973 } 1974 if (hittest == OS.HTMENU) return null; 1975 1976 1988 POINT pt = new POINT (); 1989 if (!OS.GetCursorPos (pt)) { 1990 int pos = OS.GetMessagePos (); 1991 pt.x = (short) (pos & 0xFFFF); 1992 pt.y = (short) (pos >> 16); 1993 } 1994 int hwnd = OS.WindowFromPoint (pt); 1995 if (hwnd == 0) return null; 1996 Control control = display.findControl (hwnd); 1997 1998 2004 if (control != null && (control.state & CANVAS) != 0) { 2005 if ((control.style & SWT.NO_FOCUS) != 0) { 2006 int bits = SWT.ON_TOP | SWT.NO_FOCUS; 2007 if ((style & bits) == bits) { 2008 if (hittest == OS.HTBORDER || hittest == OS.HTCLIENT) { 2009 return new LRESULT (OS.MA_NOACTIVATE); 2010 } 2011 } 2012 } 2013 } 2014 2015 setActiveControl (control); 2016 return null; 2017} 2018 2019LRESULT WM_MOVE (int wParam, int lParam) { 2020 LRESULT result = super.WM_MOVE (wParam, lParam); 2021 if (result != null) return result; 2022 ToolTip tip = getCurrentToolTip (); 2023 if (tip != null) tip.setVisible (false); 2024 return result; 2025} 2026 2027LRESULT WM_NCACTIVATE (int wParam, int lParam) { 2028 Display display = this.display; 2029 LRESULT result = super.WM_NCACTIVATE (wParam, lParam); 2030 if (display.isXMouseActive ()) { 2031 if (lockToolTipControl != null) { 2032 if (OS.GetAsyncKeyState (OS.VK_LBUTTON) < 0) return result; 2033 if (OS.GetAsyncKeyState (OS.VK_MBUTTON) < 0) return result; 2034 if (OS.GetAsyncKeyState (OS.VK_RBUTTON) < 0) return result; 2035 if (OS.GetAsyncKeyState (OS.VK_XBUTTON1) < 0) return result; 2036 if (OS.GetAsyncKeyState (OS.VK_XBUTTON2) < 0) return result; 2037 return LRESULT.ZERO; 2038 } 2039 } 2040 return result; 2041} 2042 2043LRESULT WM_NCHITTEST (int wParam, int lParam) { 2044 if (!OS.IsWindowEnabled (handle)) return null; 2045 if (!isEnabled () || !isActive ()) { 2046 if (!Display.TrimEnabled) return new LRESULT (OS.HTNOWHERE); 2047 int hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); 2048 if (hittest == OS.HTCLIENT || hittest == OS.HTMENU) hittest = OS.HTBORDER; 2049 return new LRESULT (hittest); 2050 } 2051 if (menuBar != null && !menuBar.getEnabled ()) { 2052 int hittest = callWindowProc (handle, OS.WM_NCHITTEST, wParam, lParam); 2053 if (hittest == OS.HTMENU) hittest = OS.HTBORDER; 2054 return new LRESULT (hittest); 2055 } 2056 return null; 2057} 2058 2059LRESULT WM_NCLBUTTONDOWN (int wParam, int lParam) { 2060 LRESULT result = super.WM_NCLBUTTONDOWN (wParam, lParam); 2061 if (result != null) return result; 2062 2069 if (!display.ignoreRestoreFocus) return result; 2070 Display display = this.display; 2071 int hwndActive = 0; 2072 boolean fixActive = OS.IsWin95 && display.lastHittest == OS.HTCAPTION; 2073 if (fixActive) hwndActive = OS.SetActiveWindow (handle); 2074 display.lockActiveWindow = true; 2075 int code = callWindowProc (handle, OS.WM_NCLBUTTONDOWN, wParam, lParam); 2076 display.lockActiveWindow = false; 2077 if (fixActive) OS.SetActiveWindow (hwndActive); 2078 Control focusControl = display.lastHittestControl; 2079 if (focusControl != null && !focusControl.isDisposed ()) { 2080 focusControl.setFocus (); 2081 } 2082 display.lastHittestControl = null; 2083 display.ignoreRestoreFocus = false; 2084 return new LRESULT (code); 2085} 2086 2087LRESULT WM_PALETTECHANGED (int wParam, int lParam) { 2088 if (wParam != handle) { 2089 int hPalette = display.hPalette; 2090 if (hPalette != 0) return selectPalette (hPalette); 2091 } 2092 return super.WM_PALETTECHANGED (wParam, lParam); 2093} 2094 2095LRESULT WM_QUERYNEWPALETTE (int wParam, int lParam) { 2096 int hPalette = display.hPalette; 2097 if (hPalette != 0) return selectPalette (hPalette); 2098 return super.WM_QUERYNEWPALETTE (wParam, lParam); 2099} 2100 2101LRESULT WM_SETCURSOR (int wParam, int lParam) { 2102 2110 int msg = (short) (lParam >> 16); 2111 if (msg == OS.WM_LBUTTONDOWN) { 2112 if (!Display.TrimEnabled) { 2113 Shell modalShell = display.getModalShell (); 2114 if (modalShell != null && !isActive ()) { 2115 int hwndModal = modalShell.handle; 2116 if (OS.IsWindowEnabled (hwndModal)) { 2117 OS.SetActiveWindow (hwndModal); 2118 } 2119 } 2120 } 2121 if (!OS.IsWindowEnabled (handle)) { 2122 if (!OS.IsWinCE) { 2123 int hwndPopup = OS.GetLastActivePopup (handle); 2124 if (hwndPopup != 0 && hwndPopup != handle) { 2125 if (display.getControl (hwndPopup) == null) { 2126 if (OS.IsWindowEnabled (hwndPopup)) { 2127 OS.SetActiveWindow (hwndPopup); 2128 } 2129 } 2130 } 2131 } 2132 } 2133 } 2134 2145 int hitTest = (short) (lParam & 0xFFFF); 2146 if (hitTest == OS.HTERROR) { 2147 if (!getEnabled ()) { 2148 Control control = display.getControl (wParam); 2149 if (control == this && cursor != null) { 2150 POINT pt = new POINT (); 2151 int pos = OS.GetMessagePos (); 2152 pt.x = (short) (pos & 0xFFFF); 2153 pt.y = (short) (pos >> 16); 2154 OS.ScreenToClient (handle, pt); 2155 RECT rect = new RECT (); 2156 OS.GetClientRect (handle, rect); 2157 if (OS.PtInRect (rect, pt)) { 2158 OS.SetCursor (cursor.handle); 2159 switch (msg) { 2160 case OS.WM_LBUTTONDOWN: 2161 case OS.WM_RBUTTONDOWN: 2162 case OS.WM_MBUTTONDOWN: 2163 case OS.WM_XBUTTONDOWN: 2164 OS.MessageBeep (OS.MB_OK); 2165 } 2166 return LRESULT.ONE; 2167 } 2168 } 2169 } 2170 } 2171 return super.WM_SETCURSOR (wParam, lParam); 2172} 2173 2174LRESULT WM_SETTINGCHANGE (int wParam, int lParam) { 2175 LRESULT result = super.WM_SETTINGCHANGE (wParam, lParam); 2176 if (result != null) return result; 2177 if (OS.IsPPC) { 2178 if (wParam == OS.SPI_SETSIPINFO) { 2179 2185 if ((style & SWT.RESIZE) != 0) { 2186 OS.SHHandleWMSettingChange (handle, wParam, lParam, psai); 2187 return LRESULT.ZERO; 2188 } else { 2189 SIPINFO pSipInfo = new SIPINFO (); 2190 pSipInfo.cbSize = SIPINFO.sizeof; 2191 OS.SipGetInfo (pSipInfo); 2192 psai.fSipUp = pSipInfo.fdwFlags & OS.SIPF_ON; 2193 } 2194 } 2195 } 2196 return result; 2197} 2198 2199LRESULT WM_SHOWWINDOW (int wParam, int lParam) { 2200 LRESULT result = super.WM_SHOWWINDOW (wParam, lParam); 2201 if (result != null) return result; 2202 2210 if (lParam == OS.SW_PARENTOPENING) { 2211 Control control = this; 2212 while (control != null) { 2213 Shell shell = control.getShell (); 2214 if (!shell.showWithParent) return LRESULT.ZERO; 2215 control = control.parent; 2216 } 2217 } 2218 return result; 2219} 2220 2221LRESULT WM_SYSCOMMAND (int wParam, int lParam) { 2222 LRESULT result = super.WM_SYSCOMMAND (wParam, lParam); 2223 if (result != null) return result; 2224 2241 if (OS.IsWinNT) { 2242 int cmd = wParam & 0xFFF0; 2243 switch (cmd) { 2244 case OS.SC_MINIMIZE: 2245 long memory = Runtime.getRuntime ().totalMemory (); 2246 if (memory >= 32 * 1024 * 1024) { 2247 OS.ShowWindow (handle, OS.SW_SHOWMINIMIZED); 2248 return LRESULT.ZERO; 2249 } 2250 } 2251 } 2252 return result; 2253} 2254 2255LRESULT WM_WINDOWPOSCHANGING (int wParam, int lParam) { 2256 LRESULT result = super.WM_WINDOWPOSCHANGING (wParam,lParam); 2257 if (result != null) return result; 2258 WINDOWPOS lpwp = new WINDOWPOS (); 2259 OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof); 2260 if ((lpwp.flags & OS.SWP_NOSIZE) == 0) { 2261 lpwp.cx = Math.max (lpwp.cx, minWidth); 2262 int trim = SWT.TITLE | SWT.CLOSE | SWT.MIN | SWT.MAX; 2263 if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { 2264 lpwp.cx = Math.max (lpwp.cx, OS.GetSystemMetrics (OS.SM_CXMINTRACK)); 2265 } 2266 lpwp.cy = Math.max (lpwp.cy, minHeight); 2267 if ((style & SWT.NO_TRIM) == 0 && (style & trim) != 0) { 2268 if ((style & SWT.RESIZE) != 0) { 2269 lpwp.cy = Math.max (lpwp.cy, OS.GetSystemMetrics (OS.SM_CYMINTRACK)); 2270 } else { 2271 RECT rect = new RECT (); 2272 int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE); 2273 int bits2 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); 2274 OS.AdjustWindowRectEx (rect, bits1, false, bits2); 2275 lpwp.cy = Math.max (lpwp.cy, rect.bottom - rect.top); 2276 } 2277 } 2278 OS.MoveMemory (lParam, lpwp, WINDOWPOS.sizeof); 2279 } 2280 return result; 2281} 2282} 2283 | Popular Tags |