?? combo.java
字號:
* Cuts the selected text. * <p> * The current selection is first copied to the * clipboard and then deleted from the widget. * </p> * * @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 */public void cut () { checkWidget (); OS.SendMessage (handle, OS.WM_CUT, 0, 0);}int defaultBackground () { return OS.GetSysColor (OS.COLOR_WINDOW);}void deregister () { super.deregister (); int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText != 0) display.removeControl (hwndText); int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndList != 0) display.removeControl (hwndList);}/** * Deselects the item at the given zero-relative index in the receiver's * list. If the item at the index was already deselected, it remains * deselected. Indices that are out of range are ignored. * * @param index the index of the item to deselect * * @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 deselect (int index) { checkWidget (); int selection = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0); if (index != selection) return; OS.SendMessage (handle, OS.CB_SETCURSEL, -1, 0); sendEvent (SWT.Modify); // widget could be disposed at this point}/** * Deselects all selected items in the receiver's list. * <p> * Note: To clear the selection in the receiver's text field, * use <code>clearSelection()</code>. * </p> * * @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> * * @see #clearSelection */public void deselectAll () { checkWidget (); OS.SendMessage (handle, OS.CB_SETCURSEL, -1, 0); sendEvent (SWT.Modify); // widget could be disposed at this point}/** * Returns the item at the given, zero-relative index in the * receiver's list. Throws an exception if the index is out * of range. * * @param index the index of the item to return * @return the item at the given index * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</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> * @exception SWTError <ul> * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> * </ul> */public String getItem (int index) { checkWidget (); int length = OS.SendMessage (handle, OS.CB_GETLBTEXTLEN, index, 0); if (length != OS.CB_ERR) { TCHAR buffer = new TCHAR (getCodePage (), length + 1); int result = OS.SendMessage (handle, OS.CB_GETLBTEXT, index, buffer); if (result != OS.CB_ERR) return buffer.toString (0, length); } int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (0 <= index && index < count) error (SWT.ERROR_CANNOT_GET_ITEM); error (SWT.ERROR_INVALID_RANGE); return null;}/** * Returns the number of items contained in the receiver's list. * * @return the number of items * * @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> * @exception SWTError <ul> * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> * </ul> */public int getItemCount () { checkWidget (); int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (count == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_COUNT); return count;}/** * Returns the height of the area which would be used to * display <em>one</em> of the items in the receiver's list. * * @return the height of one item * * @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> * @exception SWTError <ul> * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> * </ul> */public int getItemHeight () { checkWidget (); int result = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0); if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT); return result;}/** * Returns an array of <code>String</code>s which are the items * in the receiver's list. * <p> * Note: This is not the actual structure used by the receiver * to maintain its list of items, so modifying the array will * not affect the receiver. * </p> * * @return the items in the receiver's list * * @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> * @exception SWTError <ul> * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> * </ul> */public String [] getItems () { checkWidget (); int count = getItemCount (); String [] result = new String [count]; for (int i=0; i<count; i++) result [i] = getItem (i); return result;}String getNameText () { return getText ();}/** * 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);}/** * Returns a <code>Point</code> whose x coordinate is the start * of the selection in the receiver's text field, and whose y * coordinate is the end of the selection. The returned values * are zero-relative. An "empty" selection as indicated by * the the x and y coordinates having the same value. * * @return a point representing the selection start and end * * @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 (); if ((style & SWT.DROP_DOWN) != 0 && (style & SWT.READ_ONLY) != 0) { return new Point (0, OS.GetWindowTextLength (handle)); } int [] start = new int [1], end = new int [1]; OS.SendMessage (handle, OS.CB_GETEDITSEL, start, end); return new Point (start [0], end [0]);}/** * Returns the zero-relative index of the item which is currently * selected in the receiver's list, or -1 if no item is selected. * * @return the index of the selected item * * @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 getSelectionIndex () { checkWidget (); if (noSelection) return -1; return OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0);}/** * Returns a string containing a copy of the contents of the * receiver's text field. * * @return the receiver's 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 getText () { checkWidget (); int length = OS.GetWindowTextLength (handle); if (length == 0) return ""; TCHAR buffer = new TCHAR (getCodePage (), length + 1); OS.GetWindowText (handle, buffer, length + 1); return buffer.toString (0, length);}/** * Returns the height of the receivers's text field. * * @return the text height * * @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> * @exception SWTError <ul> * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> * </ul> */public int getTextHeight () { checkWidget (); int result = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0); if (result == OS.CB_ERR) error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT); return result + 6;}/** * Returns the maximum number of characters that the receiver's * text field is capable of holding. If this has not been changed * by <code>setTextLimit()</code>, it will be the constant * <code>Combo.LIMIT</code>. * * @return the text limit * * @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 getTextLimit () { checkWidget (); int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText == 0) return LIMIT; return OS.SendMessage (hwndText, OS.EM_GETLIMITTEXT, 0, 0);}/** * Gets the number of items that are visible in the drop * down portion of the receiver's list. * * @return the number of items that are 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 int getVisibleItemCount () { checkWidget (); return visibleCount;}boolean hasFocus () { int hwndFocus = OS.GetFocus (); if (hwndFocus == handle) return true; if (hwndFocus == 0) return false; int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndFocus == hwndText) return true; int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndFocus == hwndList) return true; return false;}/** * Searches the receiver's list starting at the first item * (index 0) until an item is found that is equal to the * argument, and returns the index of that item. If no item * is found, returns -1. * * @param string the search item * @return the index of the item * * @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 int indexOf (String string) { return indexOf (string, 0);}/** * Searches the receiver's list starting at the given, * zero-relative index until an item is found that is equal * to the argument, and returns the index of that item. If * no item is found or the starting index is out of range, * returns -1. * * @param string the search item * @param start the zero-relative index at which to begin the search * @return the index of the item * * @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 int indexOf (String string, int start) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); /* * Bug in Windows. For some reason, CB_FINDSTRINGEXACT * will not find empty strings even though it is legal * to insert an empty string into a combo. The fix is * to search the combo, an item at a time. */ if (string.length () == 0) { int count = getItemCount (); for (int i=start; i<count; i++) { if (string.equals (getItem (i))) return i; } return -1; } /* Use CB_FINDSTRINGEXACT to search for the item */ int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (!(0 <= start && start < count)) return -1; int index = start - 1, last = 0; TCHAR buffer = new TCHAR (getCodePage (), string, true); do { index = OS.SendMessage (handle, OS.CB_FINDSTRINGEXACT, last = index, buffer); if (index == OS.CB_ERR || index <= last) return -1; } while (!string.equals (getItem (index))); return index;}/** * Pastes text from clipboard. * <p> * The selected text is deleted from the widget * and new text inserted from the clipboard. * </p> * * @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 */public void paste () { checkWidget (); OS.SendMessage (handle, OS.WM_PASTE, 0, 0);}void register () { super.register (); int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText != 0) display.addControl (hwndText, this); int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndList != 0) display.addControl (hwndList, this);}/** * Removes the item from the receiver's list at the given * zero-relative index. *
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -