?? table.java
字號:
TableItem item = items [i]; if (item != null) { cleared = true; item.clear (); /* * Bug in Windows. Despite the fact that every item in the * table always has LPSTR_TEXTCALLBACK, Windows caches the * bounds for the selected items. This means that * when you change the string to be something else, Windows * correctly asks you for the new string but when the item * is selected, the selection draws using the bounds of the * previous item. The fix is to reset LPSTR_TEXTCALLBACK * even though it has not changed, causing Windows to flush * cached bounds. */ if ((style & SWT.VIRTUAL) == 0 && item.cached) { if (lvItem == null) { lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; } lvItem.iItem = i; OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem); item.cached = false; } } } if (cleared) { if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) { OS.SendMessage (handle, OS.LVM_REDRAWITEMS, 0, count - 1); } setScrollWidth (null, false); }}public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); if (fixScrollWidth) setScrollWidth (null, true); int bits = 0; if (wHint != SWT.DEFAULT) { bits |= wHint & 0xFFFF; } else { int width = 0; int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0); for (int i=0; i<count; i++) { width += OS.SendMessage (handle, OS.LVM_GETCOLUMNWIDTH, i, 0); } bits |= width & 0xFFFF; } if (hHint != SWT.DEFAULT) bits |= hHint << 16; int result = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, -1, bits); int width = result & 0xFFFF, height = result >> 16; /* * Feature in Windows. The height returned by LVM_APPROXIMATEVIEWRECT * includes the trim plus the height of the items plus one extra row. * The fix is to subtract the height of one row from the result height. */ int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0); int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); height -= (oneItem >> 16) - (empty >> 16); if (width == 0) width = DEFAULT_WIDTH; if (height == 0) height = DEFAULT_HEIGHT; if (wHint != SWT.DEFAULT) width = wHint; if (hHint != SWT.DEFAULT) height = hHint; int border = getBorderWidth (); width += border * 2; height += border * 2; if ((style & SWT.V_SCROLL) != 0) { width += OS.GetSystemMetrics (OS.SM_CXVSCROLL); } if ((style & SWT.H_SCROLL) != 0) { height += OS.GetSystemMetrics (OS.SM_CYHSCROLL); } return new Point (width, height);}void createHandle () { super.createHandle (); state &= ~CANVAS; /* * This code is intentionally commented. According to * the documentation, setting the default item size is * supposed to improve performance. By experimentation, * this does not seem to have much of an effect. */ // OS.SendMessage (handle, OS.LVM_SETITEMCOUNT, 1024 * 2, 0); /* Set the checkbox image list */ if ((style & SWT.CHECK) != 0) { int empty = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 0, 0); int oneItem = OS.SendMessage (handle, OS.LVM_APPROXIMATEVIEWRECT, 1, 0); int width = (oneItem >> 16) - (empty >> 16), height = width; setCheckboxImageList (width, height); OS.SendMessage (handle, OS. LVM_SETCALLBACKMASK, OS.LVIS_STATEIMAGEMASK, 0); } /* * Feature in Windows. When the control is created, * it does not use the default system font. A new HFONT * is created and destroyed when the control is destroyed. * This means that a program that queries the font from * this control, uses the font in another control and then * destroys this control will have the font unexpectedly * destroyed in the other control. The fix is to assign * the font ourselves each time the control is created. * The control will not destroy a font that it did not * create. */ int hFont = OS.GetStockObject (OS.SYSTEM_FONT); OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); /* * Bug in Windows. When the first column is inserted * without setting the header text, Windows will never * allow the header text for the first column to be set. * The fix is to set the text to an empty string when * the column is inserted. */ LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_TEXT; int hHeap = OS.GetProcessHeap (); int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof); lvColumn.pszText = pszText; OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 0, lvColumn); OS.HeapFree (hHeap, 0, pszText); /* Set the extended style bits */ int bits = OS.LVS_EX_SUBITEMIMAGES | OS.LVS_EX_LABELTIP; if ((style & SWT.FULL_SELECTION) != 0) bits |= OS.LVS_EX_FULLROWSELECT; OS.SendMessage (handle, OS.LVM_SETEXTENDEDLISTVIEWSTYLE, bits, bits); /* * Feature in Windows. Windows does not explicitly set the orientation of * the header. Instead, the orientation is inherited when WS_EX_LAYOUTRTL * is specified for the table. This means that when both WS_EX_LAYOUTRTL * and WS_EX_NOINHERITLAYOUT are specified for the table, the header will * not be oriented correctly. The fix is to explicitly set the orientation * for the header. * * NOTE: WS_EX_LAYOUTRTL is not supported on Windows NT. */ if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) return; if ((style & SWT.RIGHT_TO_LEFT) != 0) { int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int exStyle = OS.GetWindowLong (hwndHeader, OS.GWL_EXSTYLE); OS.SetWindowLong (hwndHeader, OS.GWL_EXSTYLE, exStyle | OS.WS_EX_LAYOUTRTL); }}void createItem (TableColumn column, int index) { int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0); int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0); int columnCount = count + 1; if (count == 1 && columns [0] == null) count = 0; if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); if (count == columns.length) { TableColumn [] newColumns = new TableColumn [columns.length + 4]; System.arraycopy (columns, 0, newColumns, 0, columns.length); columns = newColumns; } int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); for (int i=0; i<itemCount; i++) { TableItem item = items [i]; if (item != null) { String [] strings = item.strings; if (strings != null) { String [] temp = new String [columnCount]; System.arraycopy (strings, 0, temp, 0, index); System.arraycopy (strings, index, temp, index+1, columnCount-index-1); item.strings = temp; } Image [] images = item.images; if (images != null) { Image [] temp = new Image [columnCount]; System.arraycopy (images, 0, temp, 0, index); System.arraycopy (images, index, temp, index+1, columnCount-index-1); item.images = temp; } if (index == 0) { if (count != 0) { if (strings == null) { item.strings = new String [columnCount]; item.strings [1] = item.text; } item.text = ""; if (images == null) { item.images = new Image [columnCount]; item.images [1] = item.image; } item.image = null; } } if (item.cellBackground != null) { int [] cellBackground = item.cellBackground; int [] temp = new int [columnCount]; System.arraycopy (cellBackground, 0, temp, 0, index); System.arraycopy (cellBackground, index, temp, index+1, columnCount-index-1); temp [index] = -1; item.cellBackground = temp; } if (item.cellForeground != null) { int [] cellForeground = item.cellForeground; int [] temp = new int [columnCount]; System.arraycopy (cellForeground, 0, temp, 0, index); System.arraycopy (cellForeground, index, temp, index+1, columnCount-index-1); temp [index] = -1; item.cellForeground = temp; } if (item.cellFont != null) { int [] cellFont = item.cellFont; int [] temp = new int [columnCount]; System.arraycopy (cellFont, 0, temp, 0, index); System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); temp [index] = -1; item.cellFont = temp; } } } /* * Insert the column into the columns array before inserting * it into the widget so that the column will be present when * any callbacks are issued as a result of LVM_INSERTCOLUMN * or LVM_SETCOLUMN. */ System.arraycopy (columns, index, columns, index + 1, count - index); columns [index] = column; if (index == 0) { if (count > 0) { LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_WIDTH; OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, 1, lvColumn); OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, lvColumn); int width = lvColumn.cx; int cchTextMax = 1024; int hHeap = OS.GetProcessHeap (); int byteCount = cchTextMax * TCHAR.sizeof; int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_IMAGE | OS.LVCF_WIDTH | OS.LVCF_FMT; lvColumn.pszText = pszText; lvColumn.cchTextMax = cchTextMax; OS.SendMessage (handle, OS.LVM_GETCOLUMN, 0, lvColumn); OS.SendMessage (handle, OS.LVM_SETCOLUMN, 1, lvColumn); lvColumn.fmt = OS.LVCFMT_IMAGE; lvColumn.cx = width; lvColumn.iImage = OS.I_IMAGENONE; lvColumn.pszText = lvColumn.cchTextMax = 0; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); lvColumn.mask = OS.LVCF_FMT; lvColumn.fmt = OS.LVCFMT_LEFT; OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn); if (pszText != 0) OS.HeapFree (hHeap, 0, pszText); } else { OS.SendMessage (handle, OS.LVM_SETCOLUMNWIDTH, 0, 0); } if ((parent.style & SWT.VIRTUAL) == 0) { LVITEM lvItem = new LVITEM (); lvItem.mask = OS.LVIF_TEXT | OS.LVIF_IMAGE; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; lvItem.iImage = OS.I_IMAGECALLBACK; for (int i=0; i<itemCount; i++) { lvItem.iItem = i; OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem); } } } else { int fmt = OS.LVCFMT_LEFT; if ((column.style & SWT.CENTER) == SWT.CENTER) fmt = OS.LVCFMT_CENTER; if ((column.style & SWT.RIGHT) == SWT.RIGHT) fmt = OS.LVCFMT_RIGHT; LVCOLUMN lvColumn = new LVCOLUMN (); lvColumn.mask = OS.LVCF_WIDTH | OS.LVCF_FMT; lvColumn.fmt = fmt; OS.SendMessage (handle, OS.LVM_INSERTCOLUMN, index, lvColumn); }}void createItem (TableItem item, int index) { int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0); if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); if (count == items.length) { /* * Grow the array faster when redraw is off or the * table is not visible. When the table is painted, * the items array is resized to be smaller to reduce * memory usage. */ boolean small = drawCount == 0 && OS.IsWindowVisible (handle); int length = small ? items.length + 4 : Math.max (4, items.length * 3 / 2); TableItem [] newItems = new TableItem [length]; System.arraycopy (items, 0, newItems, 0, items.length); items = newItems; } LVITEM lvItem = new LVITEM (); lvItem.iItem = index; lvItem.pszText = OS.LPSTR_TEXTCALLBACK; lvItem.mask |= OS.LVIF_TEXT; /* * Bug in Windows. Despite the fact that the image list * index has never been set for the item, Windows always * assumes that the image index for the item is valid. * When an item is inserted, the image index is zero. * Therefore, when the first image is inserted and is * assigned image index zero, every item draws with this * image. The fix is to set the image index when the * the item is created. */ lvItem.iImage = OS.I_IMAGECALLBACK; lvItem.mask |= OS.LVIF_IMAGE; /* Insert the item */ ignoreSelect = true; int result = OS.SendMessage (handle, OS.LVM_INSERTITEM, 0, lvItem); ignoreSelect = false; if (result == -1) error (SWT.ERROR_ITEM_NOT_ADDED); System.arraycopy (items, index, items, index + 1, count - index); items [index] = item;}void createWidget () { super.createWidget (); items = new TableItem [4]; columns = new TableColumn [4];}int defaultBackground () { return OS.GetSysColor (OS.COLOR_WINDOW);}/** * Deselects the items at the given zero-relative indices in the receiver. * If the item at the given zero-relative index in the receiver * is selected, it is deselected. If the item at the index * was not selected, it remains deselected. Indices that are out * of range and duplicate indices are ignored. * * @param indices the array of indices for the items to deselect * * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT - if the set 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> */public void deselect (int [] indices) { checkWidget (); if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); if (indices.length == 0) return; LVITEM lvItem = new LVITEM (); lvItem.stateMask = OS.LVIS_SELECTED; for (int i=0; i<indices.length; i++) { /* * An index of -1 will apply the change to all * items. Ensure that indices are greater than -1. */ if (indices [i] >= 0) { ignoreSelect = true; OS.SendMessage (handle, OS.LVM_SETITEMSTATE, indices [i], lvItem); ignoreSelect = false; } }}/** * Deselects the item at the given zero-relative index in the receiver. * 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
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -