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

📄 table.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
 * * @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 ();	/*	* An index of -1 will apply the change to all	* items.  Ensure that index is greater than -1.	*/	if (index < 0) return;	LVITEM lvItem = new LVITEM ();	lvItem.stateMask = OS.LVIS_SELECTED;	ignoreSelect = true;	OS.SendMessage (handle, OS.LVM_SETITEMSTATE, index, lvItem);	ignoreSelect = false;}/** * 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.  The range of the * indices is inclusive. Indices that are out of range are ignored. * * @param start the start index of the items to deselect * @param end the end index of the items 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 start, int end) {	checkWidget ();	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	if (start == 0 && end == count - 1) {		deselectAll ();	} else {		LVITEM lvItem = new LVITEM ();		lvItem.stateMask = OS.LVIS_SELECTED;		/*		* An index of -1 will apply the change to all		* items.  Ensure that indices are greater than -1.		*/		start = Math.max (0, start);		for (int i=start; i<=end; i++) {			ignoreSelect = true;			OS.SendMessage (handle, OS.LVM_SETITEMSTATE, i, lvItem);			ignoreSelect = false;		}	}}/** * Deselects all selected items in the receiver. * * @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 deselectAll () {	checkWidget ();	LVITEM lvItem = new LVITEM ();	lvItem.mask = OS.LVIF_STATE;	lvItem.stateMask = OS.LVIS_SELECTED;	ignoreSelect = true;	OS.SendMessage (handle, OS.LVM_SETITEMSTATE, -1, lvItem);	ignoreSelect = false;}void destroyItem (TableColumn column) {	int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);	int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	int index = 0;	while (index < columnCount) {		if (columns [index] == column) break;		index++;	}	boolean first = false;	if (index == 0) {		first = true;		if (columnCount > 1) {			index = 1;			int cchTextMax = 1024;			int hHeap = OS.GetProcessHeap ();			int byteCount = cchTextMax * TCHAR.sizeof;			int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount);			LVCOLUMN lvColumn = new LVCOLUMN ();			lvColumn.mask = OS.LVCF_TEXT | OS.LVCF_WIDTH;			lvColumn.pszText = pszText;			lvColumn.cchTextMax = cchTextMax;			OS.SendMessage (handle, OS.LVM_GETCOLUMN, 1, 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 {			int hHeap = OS.GetProcessHeap ();			int pszText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof);			LVCOLUMN lvColumn = new LVCOLUMN ();			lvColumn.mask = OS.LVCF_TEXT;			lvColumn.pszText = pszText;			OS.SendMessage (handle, OS.LVM_SETCOLUMN, 0, lvColumn);			if (pszText != 0) OS.HeapFree (hHeap, 0, pszText);		}		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;			int itemCount = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);			for (int i=0; i<itemCount; i++) {				lvItem.iItem = i;				OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);			}		}	}	if (columnCount > 1) {		if (OS.SendMessage (handle, OS.LVM_DELETECOLUMN, index, 0) == 0) {			error (SWT.ERROR_ITEM_NOT_REMOVED);		}	}	if (first) index = 0;	System.arraycopy (columns, index + 1, columns, index, --columnCount - index);	columns [columnCount] = null;	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) {				if (columnCount == 0) {					item.strings = null;				} else {					if (index == 0) item.text = strings [1];					String [] temp = new String [columnCount];					System.arraycopy (strings, 0, temp, 0, index);					System.arraycopy (strings, index + 1, temp, index, columnCount - index);					item.strings = temp;				}			}			Image [] images = item.images;			if (images != null) {				if (columnCount == 0) {					item.images = null;				} else {					if (index == 0) item.image = images [1];					Image [] temp = new Image [columnCount];					System.arraycopy (images, 0, temp, 0, index);					System.arraycopy (images, index + 1, temp, index, columnCount - index);					item.images = temp;				}			}			if (item.cellBackground != null) {				if (columnCount == 0) {					item.cellBackground = null;				} else {					int [] cellBackground = item.cellBackground;					int [] temp = new int [columnCount];					System.arraycopy (cellBackground, 0, temp, 0, index);					System.arraycopy (cellBackground, index + 1, temp, index, columnCount - index);					item.cellBackground = temp;				}			}			if (item.cellForeground != null) {				if (columnCount == 0) {					item.cellForeground = null;				} else {					int [] cellForeground = item.cellForeground;					int [] temp = new int [columnCount];					System.arraycopy (cellForeground, 0, temp, 0, index);					System.arraycopy (cellForeground, index + 1, temp, index, columnCount - index);					item.cellForeground = temp;				}			}			if (item.cellFont != null) {				if (columnCount == 0) {					item.cellFont = null;				} else {					int [] cellFont = item.cellFont;					int [] temp = new int [columnCount];					System.arraycopy (cellFont, 0, temp, 0, index);					System.arraycopy (cellFont, index + 1, temp, index, columnCount - index);					item.cellFont = temp;				}			}		}	}	if (columnCount == 0) setScrollWidth (null, true);}void destroyItem (TableItem item) {	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	int index = 0;	while (index < count) {		if (items [index] == item) break;		index++;	}	if (index == count) return;	ignoreSelect = ignoreShrink = true;	int code = OS.SendMessage (handle, OS.LVM_DELETEITEM, index, 0);	ignoreSelect = ignoreShrink = false;	if (code == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);	System.arraycopy (items, index + 1, items, index, --count - index);	items [count] = null;	if (count == 0) {		if (imageList != null) {			int hwndHeader =  OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);			int columnCount = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);			if (columnCount == 1 && columns [0] == null) columnCount = 0;			int i = 0;			while (i < columnCount) {				TableColumn column = columns [i];				if (column.getImage () != null) break;				i++;			}			if (i == columnCount) {				OS.SendMessage (handle, OS.LVM_SETIMAGELIST, OS.LVSIL_SMALL, 0);				display.releaseImageList (imageList);				imageList = null;			}		}		customDraw = false;		items = new TableItem [4];	}}void fixCheckboxImageList () {	/*	* Bug in Windows.  When the state image list is larger than the	* image list, Windows incorrectly positions the state images.  When	* the table is scrolled, Windows draws garbage.  The fix is to force	* the state image list to be the same size as the image list.	*/	if ((style & SWT.CHECK) == 0) return;	int hImageList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_SMALL, 0);	if (hImageList == 0) return;	int [] cx = new int [1], cy = new int [1];	OS.ImageList_GetIconSize (hImageList, cx, cy);	int hOldStateList = OS.SendMessage (handle, OS.LVM_GETIMAGELIST, OS.LVSIL_STATE, 0);	if (hOldStateList == 0) return;	int [] stateCx = new int [1], stateCy = new int [1];	OS.ImageList_GetIconSize (hOldStateList, stateCx, stateCy);	if (cx [0] == stateCx [0] && cy [0] == stateCy [0]) return;	setCheckboxImageList (cx [0], cy [0]);}int getBackgroundPixel () {	return OS.SendMessage (handle, OS.LVM_GETBKCOLOR, 0, 0);}/** * Returns the column at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * If no <code>TableColumn</code>s were created by the programmer, * this method will throw <code>ERROR_INVALID_RANGE</code> despite * the fact that a single column of data may be visible in the table. * This occurs when the programmer uses the table like a list, adding * items but never creating a column. * * @param index the index of the column to return * @return the column 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> */public TableColumn getColumn (int index) {	checkWidget ();	int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);	int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	if (count == 1 && columns [0] == null) count = 0;	if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);	return columns [index];}/** * Returns the number of columns contained in the receiver. * If no <code>TableColumn</code>s were created by the programmer, * this value is zero, despite the fact that visually, one column * of items is may be visible. This occurs when the programmer uses * the table like a list, adding items but never creating a column. * * @return the number of columns * * @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 getColumnCount () {	checkWidget ();	int hwndHeader = OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);	int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	if (count == 1 && columns [0] == null) count = 0;	return count;}/** * Returns an array of <code>TableColumn</code>s which are the * columns in the receiver. If no <code>TableColumn</code>s were * created by the programmer, the array is empty, despite the fact * that visually, one column of items may be visible. This occurs * when the programmer uses the table like a list, adding items but * never creating a column. * <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 * * @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 TableColumn [] getColumns () {	checkWidget ();	int hwndHeader =  OS.SendMessage (handle, OS.LVM_GETHEADER, 0, 0);	int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	if (count == 1 && columns [0] == null) count = 0;	TableColumn [] result = new TableColumn [count];	System.arraycopy (columns, 0, result, 0, count);	return result;}/** Not currently used.*/int getFocusIndex () {//	checkWidget ();	return OS.SendMessage (handle, OS.LVM_GETNEXTITEM, -1, OS.LVNI_FOCUSED);}int getForegroundPixel () {	int pixel = OS.SendMessage (handle, OS.LVM_GETTEXTCOLOR, 0, 0);	/*	* The Windows table control uses CLR_DEFAULT to indicate	* that it is using the default foreground color.  This	* is undocumented.	*/	if (pixel == OS.CLR_DEFAULT) return OS.GetSysColor (OS.COLOR_WINDOWTEXT);	return pixel;}/** * Returns the width in pixels of a grid line. * * @return the width of a grid line in pixels *  * @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 getGridLineWidth () {	checkWidget ();	return 1;}

⌨️ 快捷键说明

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