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

📄 coolitem.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html *  * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.widgets;import org.eclipse.swt.internal.win32.*;import org.eclipse.swt.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.events.*;/** * Instances of this class are selectable user interface * objects that represent the dynamically positionable * areas of a <code>CoolBar</code>. * <dl> * <dt><b>Styles:</b></dt> * <dd>DROP_DOWN</dd> * <dt><b>Events:</b></dt> * <dd>Selection</dd> * </dl> * <p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */public class CoolItem extends Item {	CoolBar parent;	Control control;	int id;	boolean ideal, minimum;/** * Constructs a new instance of this class given its parent * (which must be a <code>CoolBar</code>) and a style value * describing its behavior and appearance. The item is added * to the end of the items maintained by its parent. * <p> * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together  * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> * * @see SWT#DROP_DOWN * @see Widget#checkSubclass * @see Widget#getStyle */public CoolItem (CoolBar parent, int style) {	super (parent, style);	this.parent = parent;	parent.createItem (this, parent.getItemCount ());}/** * Constructs a new instance of this class given its parent * (which must be a <code>CoolBar</code>), a style value * describing its behavior and appearance, and the index * at which to place it in the items maintained by its parent. * <p> * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together  * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * @param index the index at which to store the receiver in its parent * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> * * @see SWT#DROP_DOWN * @see Widget#checkSubclass * @see Widget#getStyle */public CoolItem (CoolBar parent, int style, int index) {	super (parent, style);	this.parent = parent;	parent.createItem (this, index);}/** * Adds the listener to the collection of listeners that will * be notified when the control is selected, by sending it one * of the messages defined in the <code>SelectionListener</code> * interface. * <p> * If <code>widgetSelected</code> is called when the mouse is over * the drop-down arrow (or 'chevron') portion of the cool item, * the event object detail field contains the value <code>SWT.ARROW</code>, * and the x and y fields in the event object represent the point at * the bottom left of the chevron, where the menu should be popped up. * <code>widgetDefaultSelected</code> is not called. * </p> * * @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 SelectionListener * @see #removeSelectionListener * @see SelectionEvent *  * @since 2.0 */public void addSelectionListener(SelectionListener listener) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	TypedListener typedListener = new TypedListener (listener);	addListener (SWT.Selection,typedListener);	addListener (SWT.DefaultSelection,typedListener);}protected void checkSubclass () {	if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);}/** * Returns the preferred size of the receiver. * <p> * The <em>preferred size</em> of a <code>CoolItem</code> is the size that * it would best be displayed at. The width hint and height hint arguments * allow the caller to ask the instance questions such as "Given a particular * width, how high does it need to be to show all of the contents?" * To indicate that the caller does not wish to constrain a particular  * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint.  * </p> * * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) * @return the preferred size * * @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 Layout * @see #getBounds * @see #getSize * @see CoolBar#getBorderWidth * @see CoolBar#computeTrim * @see CoolBar#getClientArea */public Point computeSize (int wHint, int hHint) {	checkWidget ();	int index = parent.indexOf (this);	if (index == -1) return new Point (0, 0);	int width = wHint, height = hHint;	if (wHint == SWT.DEFAULT) width = 32;	if (hHint == SWT.DEFAULT) height = 32;	width += parent.getMargin (index);	return new Point (width, height);}/** * Returns a rectangle describing the receiver's size and location * relative to its parent. * * @return the receiver's bounding rectangle * * @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 Rectangle getBounds () {	checkWidget ();	int index = parent.indexOf (this);	if (index == -1) return new Rectangle (0, 0, 0, 0);	int hwnd = parent.handle;	RECT rect = new RECT ();	OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);	if (OS.COMCTL32_MAJOR >= 6) {		MARGINS margins = new MARGINS ();		OS.SendMessage (hwnd, OS.RB_GETBANDMARGINS, 0, margins);		rect.left -= margins.cxLeftWidth;		rect.right += margins.cxRightWidth;	}	if (!parent.isLastItemOfRow (index)) {		rect.right += (parent.style & SWT.FLAT) == 0 ? CoolBar.SEPARATOR_WIDTH : 0;	}	int width = rect.right - rect.left;	int height = rect.bottom - rect.top;	return new Rectangle (rect.left, rect.top, width, height);}/** Not currently used.*/Rectangle getClientArea () {	checkWidget ();	int index = parent.indexOf (this);	if (index == -1) return new Rectangle (0, 0, 0, 0);	int hwnd = parent.handle;	RECT insetRect = new RECT ();	OS.SendMessage (hwnd, OS.RB_GETBANDBORDERS, index, insetRect);	RECT rect = new RECT ();	OS.SendMessage (hwnd, OS.RB_GETRECT, index, rect);	int x = rect.left + insetRect.left;	int y = rect.top;	int width = rect.right - rect.left - insetRect.left;	int height = rect.bottom - rect.top;	if ((parent.style & SWT.FLAT) == 0) {		y += insetRect.top;		width -= insetRect.right;		height -= insetRect.top + insetRect.bottom; 	}	if (index == 0) {		REBARBANDINFO rbBand = new REBARBANDINFO ();		rbBand.cbSize = REBARBANDINFO.sizeof;		rbBand.fMask = OS.RBBIM_HEADERSIZE;		OS.SendMessage (hwnd, OS.RB_GETBANDINFO, index, rbBand);		width = width - rbBand.cxHeader + 1;	}	return new Rectangle (x, y, width, height);}/** * Returns the control that is associated with the receiver. * * @return the control that is contained by 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 Control getControl () {	checkWidget ();	return control;}/** * Returns the receiver's parent, which must be a <code>CoolBar</code>. * * @return the receiver's parent * * @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 CoolBar getParent () {	checkWidget ();	return parent;}void releaseChild () {	super.releaseChild ();	parent.destroyItem (this);}void releaseWidget () {	super.releaseWidget ();	control = null;	parent = null;}/** * Sets the control that is associated with the receiver * to the argument. * * @param control the new control that will be contained by the receiver * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li>  *    <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</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 setControl (Control control) {	checkWidget ();	if (control != null) {		if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);		if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT);	}	int index = parent.indexOf (this);	if (index == -1) return;	if (this.control != null && this.control.isDisposed ()) {		this.control = null;	}	Control oldControl = this.control, newControl = control;	int hwnd = parent.handle;	int hwndChild = 0;	if (newControl != null) hwndChild = control.handle;	REBARBANDINFO rbBand = new REBARBANDINFO ();	rbBand.cbSize = REBARBANDINFO.sizeof;	rbBand.fMask = OS.RBBIM_CHILD;	rbBand.hwndChild = hwndChild;	this.control = newControl;	/*	* Feature in Windows.  When Windows sets the rebar band child,	* it makes the new child visible and hides the old child and	* moves the new child to the top of the Z-order.  The fix is	* to save and restore the visibility and Z-order.	*/	

⌨️ 快捷键说明

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