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

📄 toolbar.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);			display.releaseToolImageList (imageList);		}		if (hotImageList != null) {			OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);			display.releaseToolHotImageList (hotImageList);		}		if (disabledImageList != null) {			OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);			display.releaseToolDisabledImageList (disabledImageList);		}		imageList = hotImageList = disabledImageList = null;		items = new ToolItem [4];	}	if ((style & SWT.VERTICAL) != 0) setRows (count - 1);	layoutItems ();}ImageList getDisabledImageList () {	return disabledImageList;}ImageList getHotImageList () {	return hotImageList;}ImageList getImageList () {	return imageList;}/** * Returns the item at the given, zero-relative index in the * receiver. Throws an exception if the index is out of range. * * @param index the index of the item to return * @return the item 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 ToolItem getItem (int index) {	checkWidget ();	int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);	if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);		TBBUTTON lpButton = new TBBUTTON ();	int result = OS.SendMessage (handle, OS.TB_GETBUTTON, index, lpButton);	if (result == 0) error (SWT.ERROR_CANNOT_GET_ITEM);	return items [lpButton.idCommand];}/** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the * coordinate system of the receiver. * * @param point the point used to locate the item * @return the item at the given point * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the point 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 ToolItem getItem (Point point) {	checkWidget ();	if (point == null) error (SWT.ERROR_NULL_ARGUMENT);	ToolItem [] items = getItems ();	for (int i=0; i<items.length; i++) {		Rectangle rect = items [i].getBounds ();		if (rect.contains (point)) return items [i];	}	return null;}/** * 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> */public int getItemCount () {	checkWidget ();	return OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);}/** * Returns an array of <code>ToolItem</code>s which are the items * in the receiver.  * <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 ToolItem [] getItems () {	checkWidget ();	int count = OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);	TBBUTTON lpButton = new TBBUTTON ();	ToolItem [] result = new ToolItem [count];	for (int i=0; i<count; i++) {		OS.SendMessage (handle, OS.TB_GETBUTTON, i, lpButton);		result [i] = items [lpButton.idCommand];	}	return result;}/** * Returns the number of rows in the receiver. When * the receiver has the <code>WRAP</code> style, the * number of rows can be greater than one.  Otherwise, * the number of rows is always one. * * @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> */public int getRowCount () {	checkWidget ();	if ((style & SWT.VERTICAL) != 0) {		return OS.SendMessage (handle, OS.TB_BUTTONCOUNT, 0, 0);	}	return OS.SendMessage (handle, OS.TB_GETROWS, 0, 0);}/** * Searches the receiver's list 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 index of the item * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the tool item is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the tool item has been 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 (ToolItem item) {	checkWidget ();	if (item == null) error (SWT.ERROR_NULL_ARGUMENT);	if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);	return OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, item.id, 0);}void layoutItems () {	for (int i=0; i<items.length; i++) {		ToolItem item = items [i];		if (item != null) item.resizeControl ();	}}boolean mnemonicHit (char ch) {	int key = Display.wcsToMbcs (ch);	int [] id = new int [1];	if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {		return false;	}	if ((style & SWT.FLAT) != 0 && !setTabGroupFocus ()) return false;	int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0);	if (index == -1) return false;	OS.SendMessage (handle, OS.TB_SETHOTITEM, index, 0);	items [id [0]].click (false);	return true;}boolean mnemonicMatch (char ch) {	int key = Display.wcsToMbcs (ch);	int [] id = new int [1];	if (OS.SendMessage (handle, OS.TB_MAPACCELERATOR, key, id) == 0) {		return false;	}	/*	* Feature in Windows.  TB_MAPACCELERATOR matches either the mnemonic	* character or the first character in a tool item.  This behavior is	* undocumented and unwanted.  The fix is to ensure that the tool item	* contains a mnemonic when TB_MAPACCELERATOR returns true.	*/	int index = OS.SendMessage (handle, OS.TB_COMMANDTOINDEX, id [0], 0);	if (index == -1) return false;	return findMnemonic (items [id [0]].text) != '\0';}void releaseWidget () {	for (int i=0; i<items.length; i++) {		ToolItem item = items [i];		if (item != null && !item.isDisposed ()) {			item.releaseImages ();			item.releaseResources ();		}	}	items = null;	if (imageList != null) {		OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, 0);		display.releaseToolImageList (imageList);	}	if (hotImageList != null) {		OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, 0);		display.releaseToolHotImageList (hotImageList);	}	if (disabledImageList != null) {		OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, 0);		display.releaseToolDisabledImageList (disabledImageList);	}	imageList = hotImageList = disabledImageList = null;	super.releaseWidget ();}void removeControl (Control control) {	super.removeControl (control);	for (int i=0; i<items.length; i++) {		ToolItem item = items [i];		if (item != null && item.control == control) {			item.setControl (null);		}	}}void setBounds (int x, int y, int width, int height, int flags) {	/*	* Feature in Windows.  For some reason, when a tool bar is	* repositioned more than once using DeferWindowPos () into	* the same HDWP, the toolbar redraws more than once, defeating	* the puropse of DeferWindowPos ().  The fix is to end the	* defered positioning before the next tool bar is added,	* ensuring that only one tool bar position is deferred at	* any given time.	*/	if (parent.lpwp != null) {		if (drawCount == 0 && OS.IsWindowVisible (handle)) {			parent.setResizeChildren (false);			parent.setResizeChildren (true);		}	}	super.setBounds (x, y, width, height, flags);}void setDefaultFont () {	super.setDefaultFont ();	OS.SendMessage (handle, OS.TB_SETBITMAPSIZE, 0, 0);	OS.SendMessage (handle, OS.TB_SETBUTTONSIZE, 0, 0);}void setDisabledImageList (ImageList imageList) {	if (disabledImageList == imageList) return;	int hImageList = 0;	if ((disabledImageList = imageList) != null) {		hImageList = disabledImageList.getHandle ();	}	OS.SendMessage (handle, OS.TB_SETDISABLEDIMAGELIST, 0, hImageList);}public void setFont (Font font) {	checkWidget ();	super.setFont (font);	/*	* Bug in Windows.  When WM_SETFONT is sent to a tool bar	* that contains only separators, causes the bitmap and button	* sizes to be set.  The fix is to reset these sizes after the font	* has been changed when the tool bar contains only separators.	*/	int index = 0;	int mask = SWT.PUSH | SWT.CHECK | SWT.RADIO | SWT.DROP_DOWN;	while (index < items.length) {		ToolItem item = items [index];		if (item != null && (item.style & mask) != 0) break;				index++;	}	if (index == items.length) {		OS.SendMessage (handle, OS.TB_SETBITMAPSIZE, 0, 0);		OS.SendMessage (handle, OS.TB_SETBUTTONSIZE, 0, 0);	}	layoutItems ();}void setHotImageList (ImageList imageList) {	if (hotImageList == imageList) return;	int hImageList = 0;	if ((hotImageList = imageList) != null) {		hImageList = hotImageList.getHandle ();	}	OS.SendMessage (handle, OS.TB_SETHOTIMAGELIST, 0, hImageList);}void setImageList (ImageList imageList) {	if (this.imageList == imageList) return;	int hImageList = 0;	if ((this.imageList = imageList) != null) {		hImageList = imageList.getHandle ();	}	OS.SendMessage (handle, OS.TB_SETIMAGELIST, 0, hImageList);}public boolean setParent (Composite parent) {	checkWidget ();	if (!super.setParent (parent)) return false;	OS.SendMessage (handle, OS.TB_SETPARENT, parent.handle, 0);	return true;}void setRows (int count) {	if ((style & SWT.VERTICAL) != 0) {		/*		* Feature in Windows.  When the TB_SETROWS is used to set the		* number of rows in a tool bar, the tool bar is resized to show		* the items.  This is unexpected.  The fix is to save and restore		* the current size of the tool bar.		*/		RECT rect = new RECT ();		OS.GetWindowRect (handle, rect);		OS.MapWindowPoints (0, parent.handle, rect, 2);		ignoreResize = true;		/*		* Feature in Windows.  When the last button in a tool bar has the

⌨️ 快捷键说明

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