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

📄 caret.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.*;/** * Instances of this class provide an i-beam that is typically used * as the insertion point for text. * <dl> * <dt><b>Styles:</b></dt> * <dd>(none)</dd> * <dt><b>Events:</b></dt> * <dd>(none)</dd> * </dl> * <p> * IMPORTANT: This class is intended to be subclassed <em>only</em> * within the SWT implementation. * </p> */public class Caret extends Widget {	Canvas parent;	int x, y, width, height;	boolean moved, resized;	boolean isVisible;	Image image;	Font font;	LOGFONT oldFont;/** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. * <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 * @see Widget#checkSubclass * @see Widget#getStyle */public Caret (Canvas parent, int style) {	super (parent, style);	this.parent = parent;	createWidget ();}void createWidget () {	isVisible = true;	if (parent.getCaret () == null) {		parent.setCaret (this);	}}int defaultFont () {	int hwnd = parent.handle;	int hwndIME = OS.ImmGetDefaultIMEWnd (hwnd);	int hFont = 0;	if (hwndIME != 0) {		hFont = OS.SendMessage (hwndIME, OS.WM_GETFONT, 0, 0);	} else {		hFont = OS.SendMessage (hwnd, OS.WM_GETFONT, 0, 0);	}	if (hFont == 0) return parent.defaultFont ();	return hFont;}/** * Returns a rectangle describing the receiver's size and location * relative to its parent (or its display if its parent is null). * * @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();	if (image != null) {		Rectangle rect = image.getBounds ();		return new Rectangle (x, y, rect.width, rect.height);	}	return new Rectangle (x, y, width, height);}/** * Returns the font that the receiver will use to paint textual information. * * @return the receiver's font * * @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 Font getFont () {	checkWidget();	if (font == null) {		int hFont = defaultFont ();		return Font.win32_new (display, hFont);	}	return font;}/** * Returns the image that the receiver will use to paint the caret. * * @return the receiver's image * * @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 Image getImage () {	checkWidget();	return image;}/** * Returns a point describing the receiver's location relative * to its parent (or its display if its parent is null). * * @return the receiver's location * * @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 getLocation () {	checkWidget();	return new Point (x, y);}/** * Returns the receiver's parent, which must be a <code>Canvas</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 Canvas getParent () {	checkWidget();	return parent;}/** * Returns a point describing the receiver's size. * * @return the receiver's 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> */public Point getSize () {	checkWidget();	if (image != null) {		Rectangle rect = image.getBounds ();		return new Point (rect.width, rect.height);	}	return new Point (width, height);}/** * Returns <code>true</code> if the receiver is visible, and * <code>false</code> otherwise. * <p> * 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();	return isVisible;}boolean hasFocus () {	return parent.handle == OS.GetFocus ();}boolean isFocusCaret () {	return parent.caret == this && hasFocus ();}/** * 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 isVisible && parent.isVisible () && hasFocus ();}void killFocus () {	OS.DestroyCaret ();	if (font != null) restoreIMEFont ();}void move () {	moved = false;	if (!OS.SetCaretPos (x, y)) return;	if (OS.IsDBLocale) {		POINT ptCurrentPos = new POINT ();		if (!OS.GetCaretPos (ptCurrentPos)) return;		COMPOSITIONFORM lpCompForm = new COMPOSITIONFORM ();		lpCompForm.dwStyle = OS.CFS_POINT;		lpCompForm.x = ptCurrentPos.x;		lpCompForm.y = ptCurrentPos.y;		int hwnd = parent.handle;		int hIMC = OS.ImmGetContext (hwnd);		OS.ImmSetCompositionWindow (hIMC, lpCompForm);		OS.ImmReleaseContext (hwnd, hIMC);	}}void releaseChild () {	super.releaseChild ();	if (this == parent.getCaret ()) parent.setCaret (null);}void releaseWidget () {	super.releaseWidget ();	parent = null;

⌨️ 快捷键说明

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