?? combo.java
字號:
* @param index the index for the item * * @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_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> * </ul> */public void remove (int index) { checkWidget (); int length = OS.GetWindowTextLength (handle); int code = OS.SendMessage (handle, OS.CB_DELETESTRING, index, 0); if (code == OS.CB_ERR) { int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED); error (SWT.ERROR_INVALID_RANGE); } if (length != OS.GetWindowTextLength (handle)) { /* * It is possible (but unlikely), that application * code could have disposed the widget in the modify * event. If this happens, just return. */ sendEvent (SWT.Modify); if (isDisposed ()) return; } /* * Bug in Windows. When the combo box is read only * with exactly one item that is currently selected * and that item is removed, the combo box does not * redraw to clear the text area. The fix is to * force a redraw. */ if ((style & SWT.READ_ONLY) != 0) { int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (count == 0) OS.InvalidateRect (handle, null, false); }}/** * Removes the items from the receiver's list which are * between the given zero-relative start and end * indices (inclusive). * * @param start the start of the range * @param end the end of the range * * @exception IllegalArgumentException <ul> * <li>ERROR_INVALID_RANGE - if either the start or end are 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_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> * </ul> */public void remove (int start, int end) { checkWidget (); if (start > end) return; int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (!(0 <= start && start <= end && end < count)) { error (SWT.ERROR_INVALID_RANGE); } int length = OS.GetWindowTextLength (handle); for (int i=start; i<=end; i++) { int result = OS.SendMessage (handle, OS.CB_DELETESTRING, start, 0); if (result == OS.CB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED); } if (length != OS.GetWindowTextLength (handle)) { /* * It is possible (but unlikely), that application * code could have disposed the widget in the modify * event. If this happens, just return. */ sendEvent (SWT.Modify); if (isDisposed ()) return; } /* * Bug in Windows. When the combo box is read only * with exactly one item that is currently selected * and that item is removed, the combo box does not * redraw to clear the text area. The fix is to * force a redraw. */ if ((style & SWT.READ_ONLY) != 0) { count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (count == 0) OS.InvalidateRect (handle, null, false); }}/** * Searches the receiver's list starting at the first item * until an item is found that is equal to the argument, * and removes that item from the list. * * @param string the item to remove * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the string is null</li> * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</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_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> * </ul> */public void remove (String string) { int index = indexOf (string, 0); if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT); remove (index);}/** * Removes all of the items from the receiver's list. * <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> */public void removeAll () { checkWidget (); OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0); sendEvent (SWT.Modify); // widget could be disposed at this point}/** * Removes the listener from the collection of listeners who will * be notified when the receiver's text is modified. * * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener 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> * * @see ModifyListener * @see #addModifyListener */public void removeModifyListener (ModifyListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Modify, listener); }/** * Removes the listener from the collection of listeners who will * be notified when the receiver's selection changes. * * @param listener the listener which should no longer be notified * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the listener 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> * * @see SelectionListener * @see #addSelectionListener */public void removeSelectionListener (SelectionListener listener) { checkWidget (); if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); if (eventTable == null) return; eventTable.unhook (SWT.Selection, listener); eventTable.unhook (SWT.DefaultSelection,listener); }/** * Selects the item at the given zero-relative index in the receiver's * list. If the item at the index was already selected, it remains * selected. Indices that are out of range are ignored. * * @param index the index of the item to select * * @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 select (int index) { checkWidget (); int count = OS.SendMessage (handle, OS.CB_GETCOUNT, 0, 0); if (0 <= index && index < count) { int selection = OS.SendMessage (handle, OS.CB_GETCURSEL, 0, 0); int code = OS.SendMessage (handle, OS.CB_SETCURSEL, index, 0); if (code != OS.CB_ERR && code != selection) { sendEvent (SWT.Modify); // widget could be disposed at this point } }}void setBackgroundPixel (int pixel) { if (background == pixel) return; super.setBackgroundPixel (pixel); int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText != 0) OS.InvalidateRect (hwndText, null, true); int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);}void setBounds (int x, int y, int width, int height, int flags) { /* * Feature in Windows. If the combo box has the CBS_DROPDOWN * or CBS_DROPDOWNLIST style, Windows uses the height that the * programmer sets in SetWindowPos () to control height of the * drop down list. When the width is non-zero, Windows remembers * this value and sets the height to be the height of the text * field part of the combo box. If the width is zero, Windows * allows the height to have any value. Therefore, when the * programmer sets and then queries the height, the values can * be different depending on the width. The problem occurs when * the programmer uses computeSize () to determine the preferred * height (always the height of the text field) and then uses * this value to set the height of the combo box. The result * is a combo box with a zero size drop down list. The fix, is * to always set the height to show a fixed number of combo box * items and ignore the height value that the programmer supplies. */ if ((style & SWT.DROP_DOWN) != 0) { int textHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, -1, 0); int itemHeight = OS.SendMessage (handle, OS.CB_GETITEMHEIGHT, 0, 0); height = textHeight + 6 + (itemHeight * visibleCount) + 2; /* * Feature in Windows. When a drop down combo box is resized, * the combo box resizes the height of the text field and uses * the height provided in SetWindowPos () to determine the height * of the drop down list. For some reason, the combo box redraws * the whole area, not just the text field. The fix is to set the * SWP_NOSIZE bits when the height of text field and the drop down * list is the same as the requested height. * * NOTE: Setting the width of a combo box to zero does not update * the width of the drop down control rect. If the width of the * combo box is zero, then do not set SWP_NOSIZE. */ RECT rect = new RECT (); OS.GetWindowRect (handle, rect); if (rect.right - rect.left != 0) { if (OS.SendMessage (handle, OS.CB_GETDROPPEDCONTROLRECT, 0, rect) != 0) { int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top; if (oldWidth == width && oldHeight == height) flags |= OS.SWP_NOSIZE; } } SetWindowPos (handle, 0, x, y, width, height, flags); return; } /* * Bug in Windows. If the combo box has the CBS_SIMPLE style, * the list portion of the combo box is not redrawn when the * combo box is resized. The fix is to force a redraw when * the size has changed. */ if (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0 || !OS.IsWindowVisible (handle)) { super.setBounds (x, y, width, height, flags); return; } RECT rect = new RECT (); OS.GetWindowRect (handle, rect); super.setBounds (x, y, width, height, flags); int oldWidth = rect.right - rect.left, oldHeight = rect.bottom - rect.top; if (oldWidth != width || oldHeight != height) { if (OS.IsWinCE) { int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText != 0) OS.InvalidateRect (hwndText, null, true); int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndList != 0) OS.InvalidateRect (hwndList, null, true); } else { int uFlags = OS.RDW_ERASE | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN; OS.RedrawWindow (handle, null, 0, uFlags); } }}void setForegroundPixel (int pixel) { if (foreground == pixel) return; super.setForegroundPixel (pixel); int hwndText = OS.GetDlgItem (handle, CBID_EDIT); if (hwndText != 0) OS.InvalidateRect (hwndText, null, true); int hwndList = OS.GetDlgItem (handle, CBID_LIST); if (hwndList != 0) OS.InvalidateRect (hwndList, null, true);}/** * Sets the text of the item in the receiver's list at the given * zero-relative index to the string argument. This is equivalent * to <code>remove</code>'ing the old item at the index, and then * <code>add</code>'ing the new item at that index. * * @param index the index for the item * @param string the new text for the item * * @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> * <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> * @exception SWTError <ul> * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li> * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li> * </ul> */public void setItem (int index, String string) { checkWidget (); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); remove (index); /* * It is possible (but unlikely), that application * code could have disposed the widget in the modify * event that might be sent when the index is removed. * If this happens, just exit. */ if (isDisposed ()) return; add (string, index);}/** * Sets the receiver's list to be the given array of items. * * @param items the array of items * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the items array 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> * @exception SWTError <ul> * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> * </ul> */public void setItems (String [] items) { checkWidget (); if (items == null) error (SWT.ERROR_NULL_ARGUMENT); OS.SendMessage (handle, OS.CB_RESETCONTENT, 0, 0); int codePage = getCodePage (); for (int i=0; i<items.length; i++) { String string = items [i]; TCHAR buffer = new TCHAR (codePage, string, true); int code = OS.SendMessage (handle, OS.CB_ADDSTRING, 0, buffer); if (code == OS.CB_ERR) error (SWT.ERROR_ITEM_NOT_ADDED); if (code == OS.CB_ERRSPACE) error (SWT.ERROR_ITEM_NOT_ADDED); } // widget could be disposed at this point sendEvent (SWT.Modify);}/** * Sets the orientation of the receiver, which must be one * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. * <p> * * @param orientation new 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 void setOrientation (int orientation) { checkWidget(); if (OS.IsWinCE) return; if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return; int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; if ((orientation & flags) == 0 || (orientation & flags) == flags) return; style &= ~flags; style |= orientation & flags; int bits = OS.GetWindowLong (handle, OS.GWL_EXSTYLE); if ((style & SWT.RIGHT_TO_LEFT) != 0) { style |= SWT.MIRRORED; bits |= OS.WS_EX_LAYOUTRTL; } else { style &= ~SWT.MIRRORED; bits &= ~OS.WS_EX_LAYOUTRTL; } OS.SetWindowLong (handle, OS.GWL_EXSTYLE, bits); int hwndText = 0, hwndList = 0; COMBOBOXINFO pcbi = new COMBOBOXINFO (); pcbi.cbSize = COMBOBOXINFO.sizeof; if (OS.GetComboBoxInfo (handle, pcbi)) { hwndText = pcbi.hwndItem; hwndList = pcbi.hwndList; } if (hwndText != 0) { int bits0 = OS.GetWindowLong (hwndText, OS.GWL_EXSTYLE); int bits1 = OS.GetWindowLong (hwndText, OS.GWL_STYLE); if ((style & SWT.RIGHT_TO_LEFT) != 0) { bits0 |= OS.WS_EX_RIGHT | OS.WS_EX_RTLREADING; bits1 |= OS.ES_RIGHT; } else { bits0 &= ~(OS.WS_EX_RIGHT | OS.WS_EX_RTLREADING); bits1 &= ~OS.ES_RIGHT; } OS.SetWindowLong (hwndText, OS.GWL_EXSTYLE, bits0); OS.SetWindowLong (hwndText, OS.GWL_STYLE, bits1); /* * Bug in Windows. For some reason, the single line text field * portion of the combo box does not redraw to reflect the new
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -