summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java411
1 files changed, 82 insertions, 329 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
index e4dd73c62a..7f13cb1678 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Caret.java
@@ -7,83 +7,46 @@ package org.eclipse.swt.widgets;
* http://www.eclipse.org/legal/cpl-v10.html
*/
-import org.eclipse.swt.internal.carbon.*;
+import org.eclipse.swt.internal.carbon.OS;
+import org.eclipse.swt.internal.carbon.RGBColor;
+import org.eclipse.swt.internal.carbon.Rect;
+
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 /*final*/ class Caret extends Widget {
+public class Caret extends Widget {
Canvas parent;
- Image image;
int x, y, width, height;
- boolean moved, resized;
boolean isVisible, isShowing;
- int blinkRate = (OS.GetCaretTime() * 1000) / 60;
- Font font;
-
-/**
- * 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
- */
+ int blinkRate;
+ Image image;
+
public Caret (Canvas parent, int style) {
super (parent, style);
this.parent = parent;
- createWidget (0);
+ createWidget ();
}
+
boolean blinkCaret () {
if (!isVisible) return true;
if (!isShowing) return showCaret ();
if (blinkRate == 0) return true;
return hideCaret ();
}
-void createWidget (int index) {
- super.createWidget (index);
+
+void createWidget () {
+ super.createWidget ();
+ Display display = parent.getDisplay ();
+ blinkRate = display.getCaretBlinkTime ();
isVisible = true;
if (parent.getCaret () == null) {
parent.setCaret (this);
}
}
+
boolean drawCaret () {
if (parent == null) return false;
if (parent.isDisposed ()) return false;
- int handle = parent.handle;
int nWidth = width, nHeight = height;
if (image != null) {
Rectangle rect = image.getBounds ();
@@ -91,127 +54,70 @@ boolean drawCaret () {
nHeight = rect.height;
}
if (nWidth <= 0) nWidth = 2;
-
- int clipRgn= OS.NewRgn();
- MacUtil.getVisibleRegion(parent.handle, clipRgn, true);
-
- MacRect bounds= new MacRect();
- OS.GetControlBounds(parent.handle, bounds.getData());
- bounds= new MacRect(x+bounds.getX(), y+bounds.getY(), nWidth, nHeight);
-
- int caretRgn= OS.NewRgn();
- OS.RectRgn(caretRgn, bounds.getData());
- OS.SectRgn(caretRgn, clipRgn, caretRgn);
-
- if (!OS.EmptyRgn(caretRgn)) {
- int port= OS.GetPort();
- OS.SetPortWindowPort(OS.GetControlOwner(handle));
- OS.InvertRgn(caretRgn);
- OS.SetPort(port);
- }
-
- OS.DisposeRgn(clipRgn);
- OS.DisposeRgn(caretRgn);
-
+ int parentHandle = parent.handle;
+ int window = OS.GetControlOwner (parentHandle);
+ int port = OS.GetWindowPort (window);
+ int [] currentPort = new int [1];
+ OS.GetPort (currentPort);
+ OS.SetPort (port);
+ int oldClip = OS.NewRgn ();
+ int visibleRgn = getVisibleRegion (parentHandle);
+ OS.GetClip (oldClip);
+ OS.SetClip (visibleRgn);
+ Rect rect = new Rect ();
+ OS.GetControlBounds (parentHandle, rect);
+ int left = rect.left + x;
+ int top = rect.top + y;
+ OS.SetRect(rect, (short) left, (short) top, (short) (left + nWidth), (short) (top + nHeight));
+ RGBColor color = new RGBColor ();
+ color.red = (short) 0xFFFF;
+ color.green = (short) 0xFFFF;
+ color.blue = (short) 0xFFFF;
+ OS.RGBBackColor (color);
+ OS.InvertRect (rect);
+ OS.SetClip (oldClip);
+ OS.DisposeRgn (visibleRgn);
+ OS.DisposeRgn (oldClip);
+ OS.SetPort (currentPort [0]);
return true;
}
-/**
- * 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 ();
- rect.x= x;
- rect.y= y;
- return rect;
+ return new Rectangle (x, y, rect.width, rect.height);
}
return new Rectangle (x, y, width, height);
}
-/**
-* Gets the Display.
-*/
+
public Display getDisplay () {
Composite parent = this.parent;
if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
return parent.getDisplay ();
}
-/**
- * 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) return font;
return parent.getFont ();
}
-/**
- * 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) {
@@ -220,284 +126,131 @@ public Point getSize () {
}
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 hideCaret () {
- Display display = getDisplay ();
- if (display.currentCaret != this) return false;
if (!isShowing) return true;
isShowing = false;
return drawCaret ();
}
-/**
- * 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 () && parent.hasFocus ();
}
+
boolean isFocusCaret () {
Display display = getDisplay ();
return this == display.currentCaret;
}
+
void killFocus () {
Display display = getDisplay ();
if (display.currentCaret != this) return;
- if (isVisible) hideCaret ();
display.setCurrentCaret (null);
+ if (isVisible) hideCaret ();
}
+
void releaseChild () {
super.releaseChild ();
if (this == parent.getCaret ()) parent.setCaret (null);
}
+
void releaseWidget () {
super.releaseWidget ();
Display display = getDisplay ();
if (display.currentCaret == this) {
- if (isVisible) hideCaret ();
+ hideCaret ();
display.setCurrentCaret (null);
}
parent = null;
image = null;
}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height 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 setBounds (int x, int y, int width, int height) {
checkWidget();
- boolean samePosition, sameExtent;
- samePosition = (this.x == x) && (this.y == y);
- sameExtent = (this.width == width) && (this.height == height);
- if ((samePosition) && (sameExtent)) return;
- if (isShowing) hideCaret ();
+ if (this.x == x && this.y == y && this.width == width && this.height == height) return;
+ boolean isFocus = isFocusCaret ();
+ if (isFocus) hideCaret ();
this.x = x; this.y = y;
this.width = width; this.height = height;
- if (sameExtent) {
- moved = true;
- if (isVisible ()) {
- moved = false;
- parent.updateCaret ();
- }
- } else {
- resized = true;
- if (isVisible ()) {
- moved = false;
- parent.updateCaret ();
- resized = false;
- }
- }
- if (isShowing) showCaret ();
+// parent.updateCaret ();
+ if (isFocus) showCaret ();
}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- *
- * @param rect the new bounds 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 setBounds (Rectangle rect) {
checkWidget();
if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
setBounds (rect.x, rect.y, rect.width, rect.height);
}
+
void setFocus () {
Display display = getDisplay ();
if (display.currentCaret == this) return;
display.setCurrentCaret (this);
if (isVisible) showCaret ();
}
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font 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 setFont (Font font) {
checkWidget();
if (font != null && font.isDisposed ()) {
error (SWT.ERROR_INVALID_ARGUMENT);
}
- this.font = font;
}
-/**
- * Sets the image that the receiver will use to paint the caret
- * to the image specified by the argument, or to the default
- * which is a filled rectangle if the argument is null
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image 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 setImage (Image image) {
checkWidget();
if (image != null && image.isDisposed ()) {
error (SWT.ERROR_INVALID_ARGUMENT);
}
- if (isShowing) hideCaret ();
+ boolean isFocus = isFocusCaret ();
+ if (isFocus) hideCaret ();
this.image = image;
- if (isShowing) showCaret ();
+ if (isFocus) showCaret ();
}
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @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();
setBounds (x, y, width, height);
}
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location 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 (Point location) {
checkWidget();
if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
setLocation (location.x, location.y);
}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height 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 setSize (int width, int height) {
checkWidget();
setBounds (x, y, width, height);
}
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- * @param height the new height 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>
- */
+
public void setSize (Point size) {
checkWidget();
if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
setSize (size.x, size.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 (visible == isVisible) return;
- if (isVisible = visible) {
+ isVisible = visible;
+ if (!isFocusCaret ()) return;
+ if (isVisible) {
showCaret ();
} else {
hideCaret ();
}
}
+
boolean showCaret () {
- if (getDisplay ().currentCaret != this) return false;
if (isShowing) return true;
isShowing = true;
return drawCaret ();
}
+
}