⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 combo.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		* style bits.  The fix is to force the widget to be resized by		* temporarily shrinking and then growing the width and height.		*/		RECT rect = new RECT ();		OS.GetWindowRect (hwndText, rect);		int width = rect.right - rect.left, height = rect.bottom - rect.top;		OS.GetWindowRect (handle, rect);		int widthCombo = rect.right - rect.left, heightCombo = rect.bottom - rect.top;		int uFlags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_NOACTIVATE;		SetWindowPos (hwndText, 0, 0, 0, width - 1, height - 1, uFlags);		SetWindowPos (handle, 0, 0, 0, widthCombo - 1, heightCombo - 1, uFlags);		SetWindowPos (hwndText, 0, 0, 0, width, height, uFlags);		SetWindowPos (handle, 0, 0, 0, widthCombo, heightCombo, uFlags);		OS.InvalidateRect (handle, null, true);	}		if (hwndList != 0) {		int exStyle = OS.GetWindowLong (hwndList, OS.GWL_EXSTYLE);				if ((style & SWT.RIGHT_TO_LEFT) != 0) {			exStyle |= OS.WS_EX_LAYOUTRTL;		} else {			exStyle &= ~OS.WS_EX_LAYOUTRTL;		}		OS.SetWindowLong (hwndList, OS.GWL_EXSTYLE, exStyle);	}}/** * Sets the selection in the receiver's text field to the * range specified by the argument whose x coordinate is the * start of the selection and whose y coordinate is the end * of the selection.  * * @param selection a point representing the new selection start and end * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the point is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setSelection (Point selection) {	checkWidget ();	if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);	int bits = selection.x | (selection.y << 16);	OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, bits);}/** * Sets the contents of the receiver's text field to the * given string. * <p> * Note: The text field in a <code>Combo</code> is typically * only capable of displaying a single line of text. Thus, * setting the text to a string containing line breaks or * other special characters will probably cause it to  * display incorrectly. * </p> * * @param string the new text * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the string is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setText (String string) {	checkWidget ();	if (string == null) error (SWT.ERROR_NULL_ARGUMENT);	if ((style & SWT.READ_ONLY) != 0) {		int index = indexOf (string);		if (index != -1) select (index);		return;	}	TCHAR buffer = new TCHAR (getCodePage (), string, true);	if (OS.SetWindowText (handle, buffer)) {		sendEvent (SWT.Modify);		// widget could be disposed at this point	}}/** * Sets the maximum number of characters that the receiver's * text field is capable of holding to be the argument. * * @param limit new text limit * * @exception IllegalArgumentException <ul> *    <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public void setTextLimit (int limit) {	checkWidget ();	if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO);	OS.SendMessage (handle, OS.CB_LIMITTEXT, limit, 0);}/** * Sets the number of items that are visible in the drop * down portion of the receiver's list. * * @param count the new number of items to be visible * * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @since 3.0 */public void setVisibleItemCount (int count) {	checkWidget ();	if (count < 0) return;	visibleCount = count;	if ((style & SWT.DROP_DOWN) != 0) {		forceResize ();		RECT rect = new RECT ();		OS.GetWindowRect (handle, rect);		int flags = OS.SWP_NOMOVE | OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE;		setBounds (0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);	}}void subclass () {	super.subclass ();	int newProc = display.windowProc;	int hwndText = OS.GetDlgItem (handle, CBID_EDIT);	if (hwndText != 0) {		OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, newProc);	}	int hwndList = OS.GetDlgItem (handle, CBID_LIST);	if (hwndList != 0) {			OS.SetWindowLong (hwndList, OS.GWL_WNDPROC, newProc);	}}boolean translateTraversal (MSG msg) {	/*	* When the combo box is dropped down, allow return	* to select an item in the list and escape to close	* the combo box.	*/	switch (msg.wParam) {		case OS.VK_RETURN:		case OS.VK_ESCAPE:			if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {				return false;			}	}	return super.translateTraversal (msg);}boolean traverseEscape () {	if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) != 0) {		OS.SendMessage (handle, OS.CB_SHOWDROPDOWN, 0, 0);		return true;	}	return super.traverseEscape ();}void unsubclass () {	super.unsubclass ();	int hwndText = OS.GetDlgItem (handle, CBID_EDIT);	if (hwndText != 0 && EditProc != 0) {		OS.SetWindowLong (hwndText, OS.GWL_WNDPROC, EditProc);	}	int hwndList = OS.GetDlgItem (handle, CBID_LIST);	if (hwndList != 0 && ListProc != 0) {		OS.SetWindowLong (hwndList, OS.GWL_WNDPROC, ListProc);	}}int widgetExtStyle () {	return super.widgetExtStyle () & ~OS.WS_EX_NOINHERITLAYOUT;}int widgetStyle () {	int bits = super.widgetStyle () | OS.CBS_AUTOHSCROLL | OS.CBS_NOINTEGRALHEIGHT | OS.WS_VSCROLL;	if ((style & SWT.SIMPLE) != 0) return bits | OS.CBS_SIMPLE;	if ((style & SWT.READ_ONLY) != 0) return bits | OS.CBS_DROPDOWNLIST;	return bits | OS.CBS_DROPDOWN;}TCHAR windowClass () {	return ComboClass;}int windowProc () {	return ComboProc;}int windowProc (int hwnd, int msg, int wParam, int lParam) {	if (handle == 0) return 0;	if (hwnd != handle) {		int hwndText = OS.GetDlgItem (handle, CBID_EDIT);		int hwndList = OS.GetDlgItem (handle, CBID_LIST);		if ((hwndText != 0 && hwnd == hwndText) || (hwndList != 0 && hwnd == hwndList)) {			LRESULT result = null;			switch (msg) {				case OS.WM_CHAR:		result = WM_CHAR (wParam, lParam); break;				case OS.WM_IME_CHAR:	result = WM_IME_CHAR (wParam, lParam); break;				case OS.WM_KEYDOWN:		result = WM_KEYDOWN (wParam, lParam); break;				case OS.WM_KEYUP:		result = WM_KEYUP (wParam, lParam); break;				case OS.WM_SYSCHAR:		result = WM_SYSCHAR (wParam, lParam); break;				case OS.WM_SYSKEYDOWN:	result = WM_SYSKEYDOWN (wParam, lParam); break;				case OS.WM_SYSKEYUP:	result = WM_SYSKEYUP (wParam, lParam); break;				case OS.WM_CONTEXTMENU:					/* Pretend the WM_CONTEXTMENU was sent to the combo box */					result = WM_CONTEXTMENU (handle, lParam); break;			}			if (result != null) return result.value;			int windowProc = hwnd == hwndText ? EditProc : ListProc;			return OS.CallWindowProc (windowProc, hwnd, msg, wParam, lParam);		}	}		return super.windowProc (hwnd, msg, wParam, lParam);}LRESULT WM_CHAR (int wParam, int lParam) {	if (ignoreCharacter) return null;	LRESULT result = super.WM_CHAR (wParam, lParam);	if (result != null) return result;	/*	* Feature in Windows.  For some reason, when the	* widget is a single line text widget, when the	* user presses tab, return or escape, Windows beeps.	* The fix is to look for these keys and not call	* the window proc.	* 	* NOTE: This only happens when the drop down list	* is not visible.	*/	switch (wParam) {		case OS.VK_TAB: return LRESULT.ZERO;		case OS.VK_RETURN:			postEvent (SWT.DefaultSelection);			// FALL THROUGH		case OS.VK_ESCAPE: 			if (OS.SendMessage (handle, OS.CB_GETDROPPEDSTATE, 0, 0) == 0) {				return LRESULT.ZERO;			}	}	return result;}LRESULT WM_CTLCOLOR (int wParam, int lParam) {	return wmColorChild (wParam, lParam);}LRESULT WM_GETDLGCODE (int wParam, int lParam) {	int code = callWindowProc (OS.WM_GETDLGCODE, wParam, lParam);	return new LRESULT (code | OS.DLGC_WANTARROWS);}LRESULT WM_IME_CHAR (int wParam, int lParam) {	/* Process a DBCS character */	Display display = this.display;	display.lastKey = 0;	display.lastAscii = wParam;	display.lastVirtual = display.lastNull = display.lastDead = false;	if (!sendKeyEvent (SWT.KeyDown, OS.WM_IME_CHAR, wParam, lParam)) {		return LRESULT.ZERO;	}	/*	* Feature in Windows.  The Windows text widget uses	* two 2 WM_CHAR's to process a DBCS key instead of	* using WM_IME_CHAR.  The fix is to allow the text	* widget to get the WM_CHAR's but ignore sending	* them to the application.	*/	ignoreCharacter = true;	int result = callWindowProc (OS.WM_IME_CHAR, wParam, lParam);	MSG msg = new MSG ();	int flags = OS.PM_REMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;	while (OS.PeekMessage (msg, handle, OS.WM_CHAR, OS.WM_CHAR, flags)) {		OS.TranslateMessage (msg);		OS.DispatchMessage (msg);	}	ignoreCharacter = false;		sendKeyEvent (SWT.KeyUp, OS.WM_IME_CHAR, wParam, lParam);	// widget could be disposed at this point	display.lastKey = display.lastAscii = 0;	return new LRESULT (result);}LRESULT WM_KILLFOCUS (int wParam, int lParam) {	/*	* Return NULL - Focus notification is	* done in WM_COMMAND by CBN_KILLFOCUS.	*/	return null;}LRESULT WM_SETFOCUS (int wParam, int lParam) {	/*	* Return NULL - Focus notification is	* done by WM_COMMAND with CBN_SETFOCUS.	*/	return null;}LRESULT WM_SIZE (int wParam, int lParam) {		/*	* Feature in Windows.  When an editable drop down combo box	* contains text that does not correspond to an item in the	* list, when the widget is resized, it selects the closest	* match from the list.  The fix is to remember the original	* text and reset it after the widget is resized.	*/	if ((style & SWT.READ_ONLY) != 0 || (style & SWT.DROP_DOWN) == 0) {		return super.WM_SIZE (wParam, lParam);	}	int index = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);	boolean redraw = false;	TCHAR buffer = null;	int [] start = null, end = null;	if (index == OS.CB_ERR) {		int length = OS.GetWindowTextLength (handle);		if (length != 0) {			buffer = new TCHAR (getCodePage (), length + 1);			OS.GetWindowText (handle, buffer, length + 1);			start = new int [1];  end = new int [1];			OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end);			redraw = drawCount == 0 && OS.IsWindowVisible (handle);			if (redraw) setRedraw (false);		}	}	LRESULT result = super.WM_SIZE (wParam, lParam);	/*	* It is possible (but unlikely), that application	* code could have disposed the widget in the resize	* event.  If this happens, end the processing of the	* Windows message by returning the result of the	* WM_SIZE message.	*/	if (isDisposed ()) return result;	if (buffer != null) {		OS.SetWindowText (handle, buffer);		int bits = start [0] | (end [0] << 16);		OS.SendMessage (handle, OS.CB_SETEDITSEL, 0, bits);		if (redraw) setRedraw (true);	}	return result; }LRESULT wmCommandChild (int wParam, int lParam) {	int code = wParam >> 16;	switch (code) {		case OS.CBN_EDITCHANGE:			/*			* Feature in Windows.  If the combo box list selection is			* queried using CB_GETCURSEL before the WM_COMMAND (with			* CBM_EDITCHANGE) returns, CB_GETCURSEL returns the previous			* selection in the list.  It seems that the combo box sends			* the WM_COMMAND before it makes the selection in the list box			* match the entry field.  The fix is remember that no selection			* in the list should exist in this case.			*/			noSelection = true;			/*			* It is possible (but unlikely), that application			* code could have disposed the widget in the modify			* event.  If this happens, end the processing of the			* Windows message by returning zero as the result of			* the window proc.			*/			sendEvent (SWT.Modify);			if (isDisposed ()) return LRESULT.ZERO;			noSelection = false;			break;		case OS.CBN_SELCHANGE:			/*			* Feature in Windows.  If the text in an editable combo box			* is queried using GetWindowText () before the WM_COMMAND			* (with CBM_SELCHANGE) returns, GetWindowText () returns is			* the previous text in the combo box.  It seems that the combo			* box sends the WM_COMMAND before it updates the text field to			* match the list selection.  The fix is to force the text field			* to match the list selection by re-selecting the list item.			*/			int index = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);			if (index != OS.CB_ERR) OS.SendMessage (handle, OS.CB_SETCURSEL, index, 0);			/*			* It is possible (but unlikely), that application			* code could have disposed the widget in the modify			* event.  If this happens, end the processing of the			* Windows message by returning zero as the result of			* the window proc.			*/			sendEvent (SWT.Modify);			if (isDisposed ()) return LRESULT.ZERO;			postEvent (SWT.Selection);			break;		case OS.CBN_SETFOCUS:		case OS.CBN_KILLFOCUS:			/*			* It is possible (but unlikely), that application			* code could have disposed the widget in the focus			* event.  If this happens, end the processing of the			* Windows message by returning zero as the result of			* the window proc.			*/			sendFocusEvent (code == OS.CBN_SETFOCUS ? SWT.FocusIn : SWT.FocusOut, -1);			if (isDisposed ()) return LRESULT.ZERO;			break;	}	return super.wmCommandChild (wParam, lParam);}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -