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

📄 text.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
int defaultBackground () {	return OS.GetSysColor (OS.COLOR_WINDOW);}void fixAlignment () {	/*	* Feature in Windows.  When the edit control is not	* mirrored, it uses WS_EX_RIGHT, WS_EX_RTLREADING and	* WS_EX_LEFTSCROLLBAR to give the control a right to	* left appearance.  This causes the control to be lead	* aligned no matter what alignment was specified by	* the programmer.  For example, setting ES_RIGHT and	* WS_EX_LAYOUTRTL should cause the contents of the	* control to be left (trail) aligned in a mirrored world.	* When the orientation is changed by the user or	* specified by the programmer, WS_EX_RIGHT conflicts	* with the mirrored alignment.  The fix is to clear	* or set WS_EX_RIGHT to achieve the correct alignment	* according to the orientation and mirroring.	*/	if ((style & SWT.MIRRORED) != 0) return;	int bits0 = OS.GetWindowLong (handle, OS.GWL_EXSTYLE);	int bits1 = OS.GetWindowLong (handle, OS.GWL_STYLE);	if ((style & SWT.LEFT_TO_RIGHT) != 0) {		/*		* Bug in Windows 98. When the edit control is created		* with the style ES_RIGHT it automatically sets the 		* WS_EX_LEFTSCROLLBAR bit.  The fix is to clear the		* bit when the orientation of the control is left		* to right.		*/		bits0 &= ~OS.WS_EX_LEFTSCROLLBAR;		if ((style & SWT.RIGHT) != 0) {			bits0 |= OS.WS_EX_RIGHT;			bits1 |= OS.ES_RIGHT;		}		if ((style & SWT.LEFT) != 0) {			bits0 &= ~OS.WS_EX_RIGHT;			bits1 &= ~OS.ES_RIGHT;		}	} else {		if ((style & SWT.RIGHT) != 0) {			bits0 &= ~OS.WS_EX_RIGHT;			bits1 &= ~OS.ES_RIGHT;		}		if ((style & SWT.LEFT) != 0) {			bits0 |= OS.WS_EX_RIGHT;			bits1 |= OS.ES_RIGHT;		}	}	if ((style & SWT.CENTER) != 0) {		bits1 |= OS.ES_CENTER;	}		OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits0);	OS.SetWindowLong (handle, OS.GWL_STYLE, bits1);}public int getBorderWidth () {	checkWidget ();	/*	* Feature in Windows 2000 and XP.  Despite the fact that WS_BORDER	* is set when the edit control is created, the style bit is cleared.	* The fix is to avoid the check for WS_BORDER and use the SWT widget	* style bits instead.	*///	if ((style & SWT.BORDER) != 0 && (style & SWT.FLAT) != 0) {//		return OS.GetSystemMetrics (OS.SM_CXBORDER);//	}	return super.getBorderWidth ();}/** * Gets the line number of the caret. * <p> * The line number of the caret is returned. * </p> * * @return the line number * * @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 int getCaretLineNumber () {	checkWidget ();	return OS.SendMessage (handle, OS.EM_LINEFROMCHAR, -1, 0);}/** * Gets the location the caret. * <p> * The location of the caret is returned. * </p> * * @return a point, the location of the caret * * @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 Point getCaretLocation () {	checkWidget ();	/*	* Bug in Windows.  For some reason, Windows is unable	* to return the pixel coordinates of the last character	* in the widget.  The fix is to temporarily insert a	* space, query the coordinates and delete the space.	* The selection is always an i-beam in this case because	* this is the only time the start of the selection can	* be equal to the last character position in the widget.	* If EM_POSFROMCHAR fails for any other reason, return	* pixel coordinates (0,0). 	*/	int [] start = new int [1];	OS.SendMessage (handle, OS.EM_GETSEL, start, (int []) null);	int pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);	if (pos == -1) {		pos = 0;		if (start [0] >= OS.GetWindowTextLength (handle)) {			int cp = getCodePage ();			/*			* Feature in Windows.  When an edit control with ES_MULTILINE			* style that does not have the WS_VSCROLL style is full (i.e.			* there is no space at the end to draw any more characters),			* EM_REPLACESEL sends a WM_CHAR with a backspace character			* to remove any further text that is added.  This is an			* implementation detail of the edit control that is unexpected			* and can cause endless recursion when EM_REPLACESEL is sent			* from a WM_CHAR handler.  The fix is to ignore calling the			* handler from WM_CHAR.			*/			ignoreCharacter = ignoreModify = true;			OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, " ", true));			pos = OS.SendMessage (handle, OS.EM_POSFROMCHAR, start [0], 0);			OS.SendMessage (handle, OS.EM_SETSEL, start [0], start [0] + 1);			OS.SendMessage (handle, OS.EM_REPLACESEL, 0, new TCHAR (cp, "", true));			ignoreCharacter = ignoreModify = false;		}	}	return new Point ((short) (pos & 0xFFFF), (short) (pos >> 16));}/** * Gets the position of the caret. * <p> * The character position of the caret is returned. * </p> * * @return the position of the caret * * @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 int getCaretPosition () {	checkWidget ();	int [] start = new int [1], end = new int [1];	OS.SendMessage (handle, OS.EM_GETSEL, start, end);	int startLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, start [0], 0);	int caretPos = OS.SendMessage (handle, OS.EM_LINEINDEX, -1, 0);	int caretLine = OS.SendMessage (handle, OS.EM_LINEFROMCHAR, caretPos, 0);	int caret = end [0];	if (caretLine == startLine) caret = start [0];	if (OS.IsDBLocale) caret = mbcsToWcsPos (caret);	return caret;}/** * Gets the number of characters. * * @return number of characters in the widget * * @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 int getCharCount () {	checkWidget ();	int length = OS.GetWindowTextLength (handle);	if (OS.IsDBLocale) length = mbcsToWcsPos (length);	return length;}String getClipboardText () {	String string = "";	if (OS.OpenClipboard (0)) {		int hMem = OS.GetClipboardData (OS.IsUnicode ? OS.CF_UNICODETEXT : OS.CF_TEXT);		if (hMem != 0) {			/* Ensure byteCount is a multiple of 2 bytes on UNICODE platforms */			int byteCount = OS.GlobalSize (hMem) / TCHAR.sizeof * TCHAR.sizeof;			int ptr = OS.GlobalLock (hMem);			if (ptr != 0) {				/* Use the character encoding for the default locale */				TCHAR buffer = new TCHAR (0, byteCount / TCHAR.sizeof);				OS.MoveMemory (buffer, ptr, byteCount);				string = buffer.toString (0, buffer.strlen ());				OS.GlobalUnlock (hMem);			}		}		OS.CloseClipboard ();	}	return string;}/** * Gets the double click enabled flag. * <p> * The double click flag enables or disables the * default action of the text widget when the user * double clicks. * </p> *  * @return whether or not double click is enabled * * @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 boolean getDoubleClickEnabled () {	checkWidget ();	return doubleClick;}/** * Gets the echo character. * <p> * The echo character is the character that is * displayed when the user enters text or the * text is changed by the programmer. * </p> *  * @return the echo character * * @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 char getEchoChar () {	checkWidget ();	char echo = (char) OS.SendMessage (handle, OS.EM_GETPASSWORDCHAR, 0, 0);	if (echo != 0 && (echo = Display.mbcsToWcs (echo, getCodePage ())) == 0) echo = '*';	return echo;}/** * Gets the editable state. * * @return whether or not the reciever is editable *  * @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 boolean getEditable () {	checkWidget ();	int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);	return (bits & OS.ES_READONLY) == 0;}/** * Gets the number of lines. * * @return the number of lines in the widget * * @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 int getLineCount () {	checkWidget ();	return OS.SendMessage (handle, OS.EM_GETLINECOUNT, 0, 0);}/** * Gets the line delimiter. * * @return a string that is the line delimiter * * @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 String getLineDelimiter () {	checkWidget ();	return DELIMITER;}/** * Gets the height of a line. * * @return the height of a row of text * * @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 int getLineHeight () {	checkWidget ();	int newFont, oldFont = 0;	int hDC = OS.GetDC (handle);	newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);	if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);	TEXTMETRIC tm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW () : new TEXTMETRICA ();	OS.GetTextMetrics (hDC, tm);	if (newFont != 0) OS.SelectObject (hDC, oldFont);	OS.ReleaseDC (handle, hDC);	return tm.tmHeight;}/** * Returns the orientation of the receiver. * * @return the orientation style *  * @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 2.1.2 */public int getOrientation () {	checkWidget();	return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);}/** * Gets the position of the selected text. * <p> * Indexing is zero based.  The range of * a selection is from 0..N where N is * the number of characters in the widget. * </p> *  * @return the start and end of the selection * * @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 Point getSelection () {	checkWidget ();	int [] start = new int [1], end = new int [1];	OS.SendMessage (handle, OS.EM_GETSEL, start, end);	if (OS.IsDBLocale) {		start [0] = mbcsToWcsPos (start [0]);		end [0] = mbcsToWcsPos (end [0]);	}	return new Point (start [0], end [0]);}/** * Gets the number of selected characters. * * @return the number of selected characters. * * @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 int getSelectionCount () {	checkWidget ();	Point selection = getSelection ();	return selection.y - selection.x;}/** * Gets the selected text. * * @return the selected text *  * @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 String getSelectionText () {	checkWidget ();	/*	* NOTE: The current implementation uses substring ()	* which can reference a potentially large character	* array.	*/	Point selection = getSelection ();	return getText ().substring (selection.x, selection.y);}/** * Gets the number of tabs. * <p> * Tab stop spacing is specified in terms of the

⌨️ 快捷键说明

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