?? list.java
字號:
setScrollWidth (newWidth, false); } if (topCount > 0) { topIndex -= topCount; OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0); } if (i < newIndices.length) error (SWT.ERROR_ITEM_NOT_REMOVED);}/** * Removes the item from the receiver at the given * zero-relative index. * * @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 (); TCHAR buffer = null; if ((style & SWT.H_SCROLL) != 0) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, index, 0); if (length == OS.LB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED); buffer = new TCHAR (getCodePage (), length + 1); int result = OS.SendMessage (handle, OS.LB_GETTEXT, index, buffer); if (result == OS.LB_ERR) error (SWT.ERROR_ITEM_NOT_REMOVED); } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); int result = OS.SendMessage (handle, OS.LB_DELETESTRING, index, 0); if (result == OS.LB_ERR) { int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (0 <= index && index < count) error (SWT.ERROR_ITEM_NOT_REMOVED); error (SWT.ERROR_INVALID_RANGE); } if ((style & SWT.H_SCROLL) != 0) setScrollWidth (buffer, false); if (index < topIndex) { OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex - 1, 0); }}/** * Removes the items from the receiver 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.LB_GETCOUNT, 0, 0); if (!(0 <= start && start <= end && end < count)) { error (SWT.ERROR_INVALID_RANGE); } if (start == 0 && end == count - 1) { removeAll (); return; } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); RECT rect = null; int hDC = 0, oldFont = 0, newFont = 0, newWidth = 0; if ((style & SWT.H_SCROLL) != 0) { rect = new RECT (); hDC = OS.GetDC (handle); newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0); if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont); } int cp = getCodePage (); int index = start; int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX; while (index <= end) { TCHAR buffer = null; if ((style & SWT.H_SCROLL) != 0) { int length = OS.SendMessage (handle, OS.LB_GETTEXTLEN, start, 0); if (length == OS.LB_ERR) break; buffer = new TCHAR (cp, length + 1); int result = OS.SendMessage (handle, OS.LB_GETTEXT, start, buffer); if (result == OS.LB_ERR) break; } int result = OS.SendMessage (handle, OS.LB_DELETESTRING, start, 0); if (result == OS.LB_ERR) break; if ((style & SWT.H_SCROLL) != 0) { OS.DrawText (hDC, buffer, -1, rect, flags); newWidth = Math.max (newWidth, rect.right - rect.left); } index++; } if ((style & SWT.H_SCROLL) != 0) { if (newFont != 0) OS.SelectObject (hDC, oldFont); OS.ReleaseDC (handle, hDC); setScrollWidth (newWidth, false); } if (end < topIndex) { topIndex -= end - start + 1; OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0); } if (index <= end) error (SWT.ERROR_ITEM_NOT_REMOVED);}/** * 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) { checkWidget (); int index = indexOf (string, 0); if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT); remove (index);}/** * Removes all of the items from the receiver. * <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.LB_RESETCONTENT, 0, 0); if ((style & SWT.H_SCROLL) != 0) { OS.SendMessage (handle, OS.LB_SETHORIZONTALEXTENT, 0, 0); }}/** * 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 items at the given zero-relative indices in the receiver. * The current selection is not cleared before the new items are selected. * <p> * If the item at a given index is not selected, it is selected. * If the item at a given index was already selected, it remains selected. * Indices that are out of range and duplicate indices are ignored. * If the receiver is single-select and multiple indices are specified, * then all indices are ignored. * * @param indices the array of indices for the items to select * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the array of indices 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 List#setSelection(int[]) */public void select (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); int length = indices.length; if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; select (indices, false);}void select (int [] indices, boolean scroll) { int i = 0; while (i < indices.length) { int index = indices [i]; if (index != -1) { select (index, false); } i++; } if (scroll) showSelection ();}/** * 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 (); select (index, false);}void select (int index, boolean scroll) { if (index < 0) return; int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (index >= count) return; if (scroll) { if ((style & SWT.SINGLE) != 0) { OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0); } else { OS.SendMessage (handle, OS.LB_SETSEL, 1, index); } return; } int topIndex = OS.SendMessage (handle, OS.LB_GETTOPINDEX, 0, 0); RECT itemRect = new RECT (), selectedRect = null; OS.SendMessage (handle, OS.LB_GETITEMRECT, index, itemRect); boolean redraw = drawCount == 0 && OS.IsWindowVisible (handle); if (redraw) { OS.UpdateWindow (handle); OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); } int focusIndex = -1; if ((style & SWT.SINGLE) != 0) { int oldIndex = OS.SendMessage (handle, OS.LB_GETCURSEL, 0, 0); if (oldIndex != -1) { selectedRect = new RECT (); OS.SendMessage (handle, OS.LB_GETITEMRECT, oldIndex, selectedRect); } OS.SendMessage (handle, OS.LB_SETCURSEL, index, 0); } else { focusIndex = OS.SendMessage (handle, OS.LB_GETCARETINDEX, 0, 0); OS.SendMessage (handle, OS.LB_SETSEL, 1, index); } if ((style & SWT.MULTI) != 0) { if (focusIndex != -1) { OS.SendMessage (handle, OS.LB_SETCARETINDEX, focusIndex, 0); } } OS.SendMessage (handle, OS.LB_SETTOPINDEX, topIndex, 0); if (redraw) { OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); OS.ValidateRect (handle, null); OS.InvalidateRect (handle, itemRect, true); if (selectedRect != null) { OS.InvalidateRect (handle, selectedRect, true); } }}/** * Selects the items in the range specified by the given zero-relative * indices in the receiver. The range of indices is inclusive. * The current selection is not cleared before the new items are selected. * <p> * If an item in the given range is not selected, it is selected. * If an item in the given range was already selected, it remains selected. * Indices that are out of range are ignored and no items will be selected * if start is greater than end. * If the receiver is single-select and there is more than one item in the * given range, then all indices are ignored. * * @param start the start of the range * @param end the end of the range * * @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 List#setSelection(int,int) */public void select (int start, int end) { checkWidget (); if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (count == 0 || start >= count) return; start = Math.max (0, start); end = Math.min (end, count - 1); if ((style & SWT.SINGLE) != 0) { select (start, false); } else { select (start, end, false); }}void select (int start, int end, boolean scroll) { /* * Note that when start = end, LB_SELITEMRANGEEX * deselects the item. */ if (start == end) { select (start, scroll); return; } OS.SendMessage (handle, OS.LB_SELITEMRANGEEX, start, end); if (scroll) showSelection ();} /** * Selects all of the items in the receiver. * <p> * If the receiver is single-select, do nothing. * * @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 selectAll () { checkWidget (); if ((style & SWT.SINGLE) != 0) return; OS.SendMessage (handle, OS.LB_SETSEL, 1, -1);}void setBounds (int x, int y, int width, int height, int flags) { /* * Bug in Windows. If the receiver is scrolled horizontally * and is resized, the list does not redraw properly. The fix * is to redraw the control when resizing is not deferred and * the new size is different from the previous size. */ if (parent.lpwp != null || (flags & OS.SWP_NOSIZE) != 0) { super.setBounds (x, y, width, height, flags); return; } RECT rect = new RECT (); OS.GetWindowRect (handle, rect); int oldWidth = rect.right - rect.left; int oldHeight = rect.bottom - rect.top; super.setBounds (x, y, width, height, flags); if (oldWidth == width && oldHeight == height) return; SCROLLINFO info = new SCROLLINFO (); info.cbSize = SCROLLINFO.sizeof; info.fMask = OS.SIF_POS; if (!OS.GetScrollInfo (handle, OS.SB_HORZ, info)) return; if (info.nPos != 0) OS.InvalidateRect (handle, null, true);}void setFocusIndex (int index) {// checkWidget (); int count = OS.SendMessage (handle, OS.LB_GETCOUNT, 0, 0); if (!(0 <= index && index < count)) return; OS.SendMessage (handle, OS.LB_SETCARETINDEX, index, 0);}public void setFont (Font font) { checkWidget (); super.setFont (font); if ((style & SWT.H_SCROLL) != 0) setScrollWidth ();}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -