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

📄 label.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	* the bitmap or icon.  Any attempt to set alignment bits	* such as SS_CENTER cause the label to display text.  The	* fix is to disallow alignment.	*	* NOTE: SS_BITMAP and SS_ICON are not single bit	* masks so it is necessary to test for all of the	* bits in these masks.	*/	if ((bits & OS.SS_BITMAP) == OS.SS_BITMAP) return;	if ((bits & OS.SS_ICON) == OS.SS_ICON) return;	bits &= ~(OS.SS_LEFTNOWORDWRAP | OS.SS_CENTER | OS.SS_RIGHT);	if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) {		bits |= OS.SS_LEFTNOWORDWRAP;	}	if ((style & SWT.CENTER) != 0) bits |= OS.SS_CENTER;	if ((style & SWT.RIGHT) != 0) bits |= OS.SS_RIGHT;	OS.SetWindowLong (handle, OS.GWL_STYLE, bits);	OS.InvalidateRect (handle, null, true);}/** * Sets the receiver's image to the argument, which may be * null indicating that no image should be displayed. * * @param image the image to display on the receiver (may be null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</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 setImage (Image image) {	checkWidget ();	if ((style & SWT.SEPARATOR) != 0) return;	int hImage = 0, imageBits = 0, fImageType = 0;	if (image != null) {		if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);		hImage = image.handle;		switch (image.type) {			case SWT.BITMAP:				imageBits = OS.SS_BITMAP;				fImageType = OS.IMAGE_BITMAP;				break;			case SWT.ICON:				imageBits = OS.SS_ICON;				fImageType = OS.IMAGE_ICON;				break;			default:				return;		}	}	this.image = image;	RECT rect = new RECT ();	OS.GetWindowRect (handle, rect);	int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE);	int oldBits = newBits;	newBits &= ~(OS.SS_BITMAP | OS.SS_ICON);	newBits |= imageBits | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE;	if (newBits != oldBits) {		OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);	}	OS.SendMessage (handle, OS.STM_SETIMAGE, fImageType, hImage);	/*	* Feature in Windows.  When STM_SETIMAGE is used to set the	* image for a static control, Windows either streches the image	* to fit the control or shrinks the control to fit the image.	* While not stricly wrong, neither of these is desirable.	* The fix is to stop Windows from stretching the image by	* using SS_REALSIZEIMAGE and SS_CENTERIMAGE, allow Windows	* to shrink the control, and then restore the control to the	* original size.	*/	int flags = OS.SWP_NOZORDER | OS.SWP_DRAWFRAME | OS.SWP_NOACTIVATE | OS.SWP_NOMOVE;	SetWindowPos (handle, 0, 0, 0, rect.right - rect.left, rect.bottom - rect.top, flags);	OS.InvalidateRect (handle, null, true);}/** * Sets the receiver's text. * <p> * This method sets the widget label.  The label may include * the mnemonic character and line delimiters. * </p> * <p> * Mnemonics are indicated by an '&amp' that causes the next * character to be the mnemonic.  When the user presses a * key sequence that matches the mnemonic, focus is assigned * to the control that follows the label. On most platforms, * the mnemonic appears underlined but may be emphasised in a * platform specific manner.  The mnemonic indicator character *'&amp' can be escaped by doubling it in the string, causing * a single '&amp' to be displayed. * </p> *  * @param string the new text * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the text 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.SEPARATOR) != 0) return;	/*	* Feature in Windows.  For some reason, SetWindowText() for	* static controls redraws the control, even when the text has	* has not changed.  The fix is to check for this case and do	* nothing.	*/	if (string.equals (text)) return;	text = string;	int newBits = OS.GetWindowLong (handle, OS.GWL_STYLE), oldBits = newBits;	newBits &= ~(OS.SS_BITMAP | OS.SS_ICON | OS.SS_REALSIZEIMAGE | OS.SS_CENTERIMAGE);	if ((style & SWT.LEFT) != 0 && (style & SWT.WRAP) == 0) newBits |= OS.SS_LEFTNOWORDWRAP;	if ((style & SWT.CENTER) != 0) newBits |= OS.SS_CENTER;	if ((style & SWT.RIGHT) != 0) newBits |= OS.SS_RIGHT;	if (newBits != oldBits) {		/*		* Bug in Windows.  When the style of a label is SS_BITMAP		* or SS_ICON, the label does not remember the font that is		* set in WM_SETFONT.  The fix is to remember the font and		* return the font in WM_GETFONT and to reset the font when		* the style is changed from SS_BITMAP or SS_ICON to a style		* that displays text.		*/		int hFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);		OS.SetWindowLong (handle, OS.GWL_STYLE, newBits);		if (hFont != 0) OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0);	}	string = Display.withCrLf (string);	TCHAR buffer = new TCHAR (getCodePage (), string, true);	OS.SetWindowText (handle, buffer);}/** Not currently used.*/void setWrap (boolean wrap) {	int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);	if ((bits & (OS.SS_RIGHT | OS.SS_CENTER)) != 0) return;	bits &= ~OS.SS_LEFTNOWORDWRAP;	if (!wrap) bits |= OS.SS_LEFTNOWORDWRAP;	OS.SetWindowLong (handle, OS.GWL_STYLE, bits);	OS.InvalidateRect (handle, null, true);}int widgetExtStyle () {	int bits = super.widgetExtStyle () & ~OS.WS_EX_CLIENTEDGE;	if ((style & SWT.BORDER) != 0) return bits | OS.WS_EX_STATICEDGE;	return bits;}int widgetStyle () {	int bits = super.widgetStyle () | OS.SS_NOTIFY;	if ((style & SWT.SEPARATOR) != 0) return bits | OS.SS_OWNERDRAW;	if ((style & SWT.CENTER) != 0) return bits | OS.SS_CENTER;	if ((style & SWT.RIGHT) != 0) return bits | OS.SS_RIGHT;	if ((style & SWT.WRAP) != 0) return bits | OS.SS_LEFT;	return bits | OS.SS_LEFTNOWORDWRAP;}TCHAR windowClass () {	return LabelClass;}int windowProc () {	return LabelProc;}LRESULT WM_ERASEBKGND (int wParam, int lParam) {	LRESULT result = super.WM_ERASEBKGND (wParam, lParam);	if (result != null) return result;	if ((style & SWT.SEPARATOR) != 0) return LRESULT.ONE;	/*	* Bug in Windows.  When a label has the SS_BITMAP	* or SS_ICON style, the label does not draw the	* background.  The fix is to draw the background	* when the label is showing a bitmap or icon.	*	* NOTE: SS_BITMAP and SS_ICON are not single bit	* masks so it is necessary to test for all of the	* bits in these masks.	*/	int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);	boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;	boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;	if (isBitmap || isIcon) {		drawBackground (wParam);		return LRESULT.ONE;	}	return result;}LRESULT WM_GETFONT (int wParam, int lParam) {	LRESULT result = super.WM_GETFONT (wParam, lParam);	if (result != null) return result;	/*	* Bug in Windows.  When the style of a label is SS_BITMAP	* or SS_ICON, the label does not remember the font that is	* set in WM_SETFONT.  The fix is to remember the font and	* return the font in WM_GETFONT.	*/	if (font == 0) font = defaultFont ();	return new LRESULT (font);}LRESULT WM_SETFONT (int wParam, int lParam) {	/*	* Bug in Windows.  When the style of a label is SS_BITMAP	* or SS_ICON, the label does not remember the font that is	* set in WM_SETFONT.  The fix is to remember the font and	* return the font in WM_GETFONT.	*/	return super.WM_SETFONT (font = wParam, lParam);}LRESULT WM_SIZE (int wParam, int lParam) {	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 ((style & SWT.SEPARATOR) != 0) {		OS.InvalidateRect (handle, null, true);		return result;	}		/*	* Bug in Windows.  For some reason, a label with	* SS_BITMAP or SS_ICON and SS_CENTER does not redraw	* properly when resized.  Only the new area is drawn	* and the old area is not cleared.  The fix is to	* force the redraw.	*	* NOTE: SS_BITMAP and SS_ICON are not single bit	* masks so it is necessary to test for all of the	* bits in these masks.	*/	int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);	boolean isBitmap = (bits & OS.SS_BITMAP) == OS.SS_BITMAP;	boolean isIcon = (bits & OS.SS_ICON) == OS.SS_ICON;	if (isBitmap || isIcon) {		OS.InvalidateRect (handle, null, true);		return result;	}			/*	* Bug in Windows.  For some reason, a label with	* style SS_LEFT, SS_CENTER or SS_RIGHT does not	* redraw the text in the new position when resized.	* Note that SS_LEFTNOWORDWRAP does not have the	* problem.  The fix is to force the redraw.	*/	if ((style & (SWT.WRAP | SWT.CENTER | SWT.RIGHT)) != 0) {		OS.InvalidateRect (handle, null, true);		return result;	}		return result;}LRESULT wmDrawChild (int wParam, int lParam) {	DRAWITEMSTRUCT struct = new DRAWITEMSTRUCT ();	OS.MoveMemory (struct, lParam, DRAWITEMSTRUCT.sizeof);	drawBackground (struct.hDC);	if ((style & SWT.SHADOW_NONE) != 0) return null;	RECT rect = new RECT ();	int lineWidth = OS.GetSystemMetrics (OS.SM_CXBORDER);	int flags = OS.EDGE_ETCHED;	if ((style & SWT.SHADOW_IN) != 0) flags = OS.EDGE_SUNKEN;	if ((style & SWT.HORIZONTAL) != 0) {		int bottom = struct.top + Math.max (lineWidth * 2, (struct.bottom - struct.top) / 2);		OS.SetRect (rect, struct.left, struct.top, struct.right, bottom);		OS.DrawEdge (struct.hDC, rect, flags, OS.BF_BOTTOM);	} else {		int right = struct.left + Math.max (lineWidth * 2, (struct.right - struct.left) / 2);		OS.SetRect (rect, struct.left, struct.top, right, struct.bottom);		OS.DrawEdge (struct.hDC, rect, flags, OS.BF_RIGHT);	}	return null;}}

⌨️ 快捷键说明

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