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

📄 menu.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, this method * may still indicate that it is considered visible even though * it may not actually be showing. * </p> * * @return the receiver's visibility state * * @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 boolean getVisible () {	checkWidget ();	if ((style & SWT.BAR) != 0) {		return this == parent.menuShell ().menuBar;	}	if ((style & SWT.POP_UP) != 0) {		Menu [] popups = display.popups;		if (popups == null) return false;		for (int i=0; i<popups.length; i++) {			if (popups [i] == this) return true;		}	}	return this == getShell ().activeMenu;}int imageIndex (Image image) {	if (hwndCB == 0 || image == null) return OS.I_IMAGENONE;	if (imageList == null) {		int hOldList = OS.SendMessage (hwndCB, OS.TB_GETIMAGELIST, 0, 0);		if (hOldList != 0) OS.ImageList_Destroy (hOldList);		Rectangle bounds = image.getBounds ();		imageList = display.getImageList (new Point (bounds.width, bounds.height));		int index = imageList.indexOf (image);		if (index == -1) index = imageList.add (image);		int hImageList = imageList.getHandle ();		OS.SendMessage (hwndCB, OS.TB_SETIMAGELIST, 0, hImageList);		return index;	}	int index = imageList.indexOf (image);	if (index != -1) return index;	return imageList.add (image);}/** * 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 string 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 int indexOf (MenuItem item) {	checkWidget ();	if (item == null) error (SWT.ERROR_NULL_ARGUMENT);	if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);	if (item.parent != this) return -1;	if ((OS.IsPPC || OS.IsSP) && hwndCB != 0) {		if (OS.IsPPC) {			return OS.SendMessage (hwndCB, OS.TB_COMMANDTOINDEX, item.id, 0);		}		if (OS.IsSP) {			if (item.id == id0) return 0;			if (item.id == id1) return 1;			return -1;		}	}	int index = 0;	MENUITEMINFO info = new MENUITEMINFO ();	info.cbSize = MENUITEMINFO.sizeof;	info.fMask = OS.MIIM_DATA;	while (OS.GetMenuItemInfo (handle, index, true, info)) {		if (info.dwItemData == item.id) return index;		index++;	}	return -1;}/** * Returns <code>true</code> if the receiver is enabled and all * of the receiver's ancestors are enabled, and <code>false</code> * otherwise. A disabled control is typically not selectable from the * user interface and draws with an inactive or "grayed" look. * * @return the receiver's enabled state * * @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 #getEnabled */public boolean isEnabled () {	checkWidget ();	Menu parentMenu = getParentMenu ();	if (parentMenu == null) return getEnabled ();	return getEnabled () && parentMenu.isEnabled ();}/** * Returns <code>true</code> if the receiver is visible and all * of the receiver's ancestors are visible and <code>false</code> * otherwise. * * @return the receiver's visibility state * * @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 #getVisible */public boolean isVisible () {	checkWidget ();	return getVisible ();}void redraw () {	if ((style & SWT.BAR) != 0) {		display.addBar (this);	} else {		update ();	}}void releaseChild () {	super.releaseChild ();	if (cascade != null) cascade.releaseMenu ();	if ((style & SWT.BAR) != 0) {		display.removeBar (this);		if (this == parent.menuBar) {			parent.setMenuBar (null);		}	} else {		if ((style & SWT.POP_UP) != 0) {			display.removePopup (this);		}	}}void releaseHandle () {	super.releaseHandle ();	handle = hwndCB = 0;}void releaseWidget () {	MenuItem [] items = getItems ();	for (int i=0; i<items.length; i++) {		MenuItem item = items [i];		if (!item.isDisposed ()) {			if (OS.IsPPC && hwndCB != 0) {				item.dispose ();			} else {				item.releaseResources ();			}		}	}	if (OS.IsPPC && hwndCB != 0) {		if (imageList != null) {			OS.SendMessage (hwndCB, OS.TB_SETIMAGELIST, 0, 0);			display.releaseToolImageList (imageList);			imageList = null;		}	}	super.releaseWidget ();	if (parent != null) parent.removeMenu (this);	parent = null;	cascade = null;}/** * Removes the listener from the collection of listeners who will * be notified when the help events are generated for the control. * * @param listener the listener which should 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 HelpListener * @see #addHelpListener */public void removeHelpListener (HelpListener listener) {	checkWidget ();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) return;	eventTable.unhook (SWT.Help, listener);}/** * Removes the listener from the collection of listeners who will * be notified when the menu events are generated for the control. * * @param listener the listener which should 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 MenuListener * @see #addMenuListener */public void removeMenuListener (MenuListener listener) {	checkWidget ();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) return;	eventTable.unhook (SWT.Hide, listener);	eventTable.unhook (SWT.Show, listener);}/** * Sets the default menu item to the argument or removes * the default emphasis when the argument is <code>null</code>. *  * @param item the default menu item or null * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the menu 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 void setDefaultItem (MenuItem item) {	checkWidget ();	int newID = -1;	if (item != null) {		if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);		if (item.parent != this) return;		newID = item.id;	}	if (OS.IsWinCE) return;	int oldID = OS.GetMenuDefaultItem (handle, OS.MF_BYCOMMAND, OS.GMDI_USEDISABLED);	if (newID == oldID) return;	OS.SetMenuDefaultItem (handle, newID, OS.MF_BYCOMMAND);	redraw ();}/** * Enables the receiver if the argument is <code>true</code>, * and disables it otherwise. A disabled control is typically * not selectable from the user interface and draws with an * inactive or "grayed" look. * * @param enabled the new enabled state * * @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 setEnabled (boolean enabled) {	checkWidget ();	state &= ~DISABLED;	if (!enabled) state |= DISABLED;}/** * Sets the receiver's location to the point specified by * the arguments which are relative to the display. * <p> * Note:  This is different from most widgets where the * location of the widget is relative to the parent. * </p> * * @param x the new x coordinate for the receiver * @param y the new y coordinate for 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 setLocation (int x, int y) {	checkWidget ();	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;	this.x = x;	this.y = y;	hasLocation = true;}/** * Sets the receiver's location to the point specified by * the arguments which are relative to the display. * <p> * Note:  This is different from most widgets where the * location of the widget is relative to the parent. * </p> * * @param location the new location for the receiver * * @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> *  * @since 2.1 */public void setLocation (Point location) {	checkWidget ();	if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	setLocation (location.x, location.y);}/** * Marks the receiver as visible if the argument is <code>true</code>, * and marks it invisible otherwise.  * <p> * If one of the receiver's ancestors is not visible or some * other condition makes the receiver not visible, marking * it visible may not actually cause it to be displayed. * </p> * * @param visible the new visibility state * * @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 setVisible (boolean visible) {	checkWidget ();	if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;	if (visible) {		display.addPopup (this);	} else {		display.removePopup (this);		_setVisible (false);	}}void update () {	if (OS.IsPPC || OS.IsSP) return;	if (OS.IsHPC) {		/*		* Each time a menu has been modified, the command menu bar		* must be redrawn or it won't update properly.  For example,		* a submenu will not drop down.		*/		Menu menuBar = parent.menuBar;		if (menuBar != null) {			Menu menu = this;			while (menu != null && menu != menuBar) {				menu = menu.getParentMenu ();			}			if (menu == menuBar) {				OS.CommandBar_DrawMenuBar (menuBar.hwndCB, 0);				OS.CommandBar_Show (menuBar.hwndCB, true);			}		}		return;	}	if (OS.IsWinCE) return;	if ((style & SWT.BAR) != 0) {		if (this == parent.menuBar) OS.DrawMenuBar (parent.handle);		return;	}	if ((OS.WIN32_MAJOR << 16 | OS.WIN32_MINOR) < (4 << 16 | 10)) {		return;	}	boolean hasCheck = false, hasImage = false;	MenuItem [] items = getItems ();	for (int i=0; i<items.length; i++) {		MenuItem item = items [i];		if (item.image != null) {			if ((hasImage = true) && hasCheck) break;		}		if ((item.style & (SWT.CHECK | SWT.RADIO)) != 0) {			if ((hasCheck = true) && hasImage) break;		}	}		/*	* Bug in Windows.  If a menu contains items that have	* images and can be checked, Windows does not include	* the width of the image and the width of the check when	* computing the width of the menu.  When the longest item	* does not have an image, the label and the accelerator	* text can overlap.  The fix is to use SetMenuItemInfo()	* to indicate that all items have a bitmap and then include	* the width of the widest bitmap in WM_MEASURECHILD.	* 	* NOTE:  This work around causes problems on Windows 98.	* Under certain circumstances that have yet to be isolated,	* some menus can become huge and blank.  For now, do not	* run the code on Windows 98.	*/		if (!OS.IsWin95) {		MENUITEMINFO info = new MENUITEMINFO ();		info.cbSize = MENUITEMINFO.sizeof;		info.fMask = OS.MIIM_BITMAP;		for (int i=0; i<items.length; i++) {			MenuItem item = items [i];			if ((style & SWT.SEPARATOR) == 0) {				if (item.image == null) {					info.hbmpItem = hasImage ? OS.HBMMENU_CALLBACK : 0;					OS.SetMenuItemInfo (handle, item.id, false, info);				}			}		}	}	/* Update the menu to hide or show the space for bitmaps */	MENUINFO lpcmi = new MENUINFO ();	lpcmi.cbSize = MENUINFO.sizeof;	lpcmi.fMask = OS.MIM_STYLE;	OS.GetMenuInfo (handle, lpcmi);	if (hasImage && !hasCheck) {		lpcmi.dwStyle |= OS.MNS_CHECKORBMP;	} else {		lpcmi.dwStyle &= ~OS.MNS_CHECKORBMP;	}	OS.SetMenuInfo (handle, lpcmi);}}

⌨️ 快捷键说明

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