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

📄 coolbar.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 * * @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 CoolItem getItem (int index) {	checkWidget ();	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_ID;	OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);	return items [rbBand.wID];}/** * Returns the number of items contained in the receiver. * * @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 ();	return OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);}/** * Returns an array of zero-relative ints that map * the creation order of the receiver's items to the * order in which they are currently being displayed. * <p> * Specifically, the indices of the returned array represent * the current visual order of the items, and the contents * of the array represent the creation order of the items. * </p><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 current visual order of the receiver's 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_ITEM - if the operation fails because of an operating system failure</li> * </ul> */public int [] getItemOrder () {	checkWidget ();	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	int [] indices = new int [count];	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_ID;	for (int i=0; i<count; i++) {		OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);		CoolItem item = items [rbBand.wID];		int index = 0;		while (index<originalItems.length) {			if (originalItems [index] == item) break;			index++;		}		if (index == originalItems.length) error (SWT.ERROR_CANNOT_GET_ITEM);		indices [i] = index;	}	return indices;}/** * Returns an array of <code>CoolItem</code>s in the order * in which they are currently being displayed. * <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 receiver's items in their current visual order * * @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 CoolItem [] getItems () {	checkWidget ();	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	CoolItem [] result = new CoolItem [count];	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_ID;	for (int i=0; i<count; i++) {		OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);		result [i] = items [rbBand.wID];	}	return result;}/** * Returns an array of points whose x and y coordinates describe * the widths and heights (respectively) of the items in the receiver * in the order in which they are currently being displayed. * * @return the receiver's item sizes in their current visual order * * @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 [] getItemSizes () {	checkWidget ();		int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	Point [] sizes = new Point [count];	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_CHILDSIZE;	int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0;	MARGINS margins = new MARGINS ();	for (int i=0; i<count; i++) {		RECT rect = new RECT ();		OS.SendMessage (handle, OS.RB_GETRECT, i, rect);		OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);		if (OS.COMCTL32_MAJOR >= 6) {			OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins);			rect.left -= margins.cxLeftWidth;			rect.right += margins.cxRightWidth;		}		if (!isLastItemOfRow(i)) rect.right += separator;		sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild);	}	return sizes;}int getLastIndexOfRow (int index) {	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	if (count == 0) return -1;	REBARBANDINFO rbBand = new REBARBANDINFO ();		rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_STYLE;	for (int i=index + 1; i<count; i++) {		OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand);		if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) {			return i - 1;		}	}	return count - 1;}boolean isLastItemOfRow (int index) {	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	if (index + 1 == count) return true;	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_STYLE;	OS.SendMessage (handle, OS.RB_GETBANDINFO, index + 1, rbBand);	return (rbBand.fStyle & OS.RBBS_BREAK) != 0;}/** * Returns whether or not the receiver is 'locked'. When a coolbar * is locked, its items cannot be repositioned. * * @return true if the coolbar is locked, false otherwise * * @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.0 */public boolean getLocked () {	checkWidget ();	return locked;}/** * Returns an array of ints that describe the zero-relative * indices of any item(s) in the receiver that will begin on * a new row. The 0th visible item always begins the first row, * therefore it does not count as a wrap index. * * @return an array containing the receiver's wrap indices, or an empty array if all items are in one row * * @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 [] getWrapIndices () {	checkWidget ();	CoolItem [] items = getItems ();	int [] indices = new int [items.length];	int count = 0;	for (int i=0; i<items.length; i++) {		if (items [i].getWrap ()) indices [count++] = i;		}	int [] result = new int [count];	System.arraycopy (indices, 0, result, 0, count);	return result;}/** * Searches the receiver's items in the order they are currently * being displayed, 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 item the search item * @return the visual order index of the search item, or -1 if the item is not found * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the item is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the item is disposed</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 (CoolItem item) {	checkWidget ();	if (item == null) error (SWT.ERROR_NULL_ARGUMENT);	if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);	return OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0);}void resizeToPreferredWidth (int index) {	/*	* Bug in Windows.  When RB_GETBANDBORDERS is sent	* with an index out of range, Windows GP's.  The	* fix is to ensure the index is in range.	*/	int count = OS.SendMessage(handle, OS.RB_GETBANDCOUNT, 0, 0);	if (0 <= index && index < count) {		REBARBANDINFO rbBand = new REBARBANDINFO();		rbBand.cbSize = REBARBANDINFO.sizeof;		rbBand.fMask = OS.RBBIM_IDEALSIZE;		OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand);		RECT rect = new RECT ();		OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect);		rbBand.cx = rbBand.cxIdeal + rect.left;		if ((style & SWT.FLAT) == 0) rbBand.cx += rect.right;		rbBand.fMask = OS.RBBIM_SIZE;		OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);	}}void resizeToMaximumWidth (int index) {	REBARBANDINFO rbBand = new REBARBANDINFO();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_SIZE;	rbBand.cx = MAX_WIDTH;	OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand);}	void releaseWidget () {	for (int i=0; i<items.length; i++) {		CoolItem item = items [i];		if (item != null && !item.isDisposed ()) {			item.releaseResources ();		}	}	items = null;	super.releaseWidget();}void removeControl (Control control) {	super.removeControl (control);	for (int i=0; i<items.length; i++) {		CoolItem item = items [i];		if (item != null && item.control == control) {			item.setControl (null);		}	}}void setBackgroundPixel (int pixel) {	if (background == pixel) return;	background = pixel;	if (pixel == -1) pixel = defaultBackground ();	OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel);	setItemColors (OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel);	/*	* Feature in Windows.  For some reason, Windows	* does not fully erase the coolbar area and coolbar	* items when you set the background.  The fix is	* to invalidate the coolbar area.	*/	if (!OS.IsWindowVisible (handle)) return;	if (OS.IsWinCE) {		OS.InvalidateRect (handle, null, true);	} else {		int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN;		OS.RedrawWindow (handle, null, 0, flags);	}}void setForegroundPixel (int pixel) {	if (foreground == pixel) return;	foreground = pixel;	if (pixel == -1) pixel = defaultForeground ();	OS.SendMessage (handle, OS.RB_SETTEXTCOLOR, 0, pixel);	setItemColors (pixel, OS.SendMessage (handle, OS.RB_GETBKCOLOR, 0, 0));}void setItemColors (int foreColor, int backColor) {	int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0);	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_COLORS;	rbBand.clrFore = foreColor;	rbBand.clrBack = backColor;	for (int i=0; i<count; i++) {		OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand);	}}/** * Sets the receiver's item order, wrap indices, and item sizes * all at once. This method is typically used to restore the * displayed state of the receiver to a previously stored state. * <p> * The item order is the order in which the items in the receiver * should be displayed, given in terms of the zero-relative ordering * of when the items were added. * </p><p> * The wrap indices are the indices of all item(s) in the receiver * that will begin on a new row. The indices are given in the order * specified by the item order. The 0th item always begins the first * row, therefore it does not count as a wrap index. If wrap indices * is null or empty, the items will be placed on one line. * </p><p> * The sizes are specified in an array of points whose x and y * coordinates describe the new widths and heights (respectively) * of the receiver's items in the order specified by the item order. * </p> * * @param itemOrder an array of indices that describe the new order to display the items in * @param wrapIndices an array of wrap indices, or null * @param sizes an array containing the new sizes for each of the receiver's items in visual order * * @exception SWTException <ul>

⌨️ 快捷键说明

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